Minor Changes
-
#1340
3cbe776Thanks @threepointone! - Align Think lifecycle hooks with the AI SDK and fix latent bugs around tool-call hooks and extension dispatch.Lifecycle hook context types are now derived from the AI SDK (resolves #1339).
StepContext,ChunkContext,ToolCallContext, andToolCallResultContextare derived fromStepResult,TextStreamPart, andTypedToolCallso users get full typed access toreasoning,sources,files,providerMetadata(where Anthropic cache tokens live),request/response, etc., instead ofunknown. The relevant AI SDK types are re-exported from@cloudflare/think.beforeToolCall/afterToolCallnow fire with correct timing.beforeToolCallruns before the tool'sexecute(Think wraps every tool'sexecute), andafterToolCallruns after withdurationMsand a discriminatedsuccess/output/erroroutcome (backed byexperimental_onToolCallFinish).ToolCallDecisionis now functional. Returning{ action: "block", reason },{ action: "substitute", output }, or{ action: "allow", input }frombeforeToolCallactually intercepts execution.Extension hook dispatch.
ExtensionManifest.hooksclaimed support forbeforeToolCall/afterToolCall/onStepFinish/onChunkbut Think only ever dispatchedbeforeTurn. All five hooks now dispatch to subscribed extensions with JSON-safe snapshots. Extension hook handlers also receive(snapshot, host)(symmetric with toolexecute); previously only tool executes got the host bridge.Breaking renames (per AI SDK conventions):
ToolCallContext.args→input,ToolCallResultContext.args→input,ToolCallResultContext.result→output.afterToolCallis now a discriminated union — readoutputonly whenctx.success === true, anderrorwhenctx.success === false. Equivalent renames onToolCallDecision.See docs/think/lifecycle-hooks.md for the full hook reference.
Patch Changes
- #1340
3cbe776Thanks @threepointone! - Fix_wrapToolsWithDecisiontoawait originalExecute(...)before checking forSymbol.asyncIterator. The previous code missedPromise<AsyncIterable>returns from plain async functions (async function execute(...) { return makeIter(); }) —Symbol.asyncIterator in promiseis always false, the collapse logic was skipped, and the AI SDK ended up treating the iterator instance itself as the final output value (which the wrapper's own comment warned about). Both sync-returned-iterable and async-returned-iterable cases are now covered, with regression tests for each.