Patch Changes
-
ca510d4Thanks @threepointone! - Tighten theagentspeer dependency floor from>=0.8.7to>=0.11.7to reflect the current monorepo set we actually test against. Upper bound (<1.0.0) is unchanged.No runtime change in
@cloudflare/ai-chatitself. The visible effect for consumers: pairing the latest@cloudflare/ai-chatwith a staleagents(<0.11.7) now produces a peer warning where it previously did not. That's the intended signal —agentsversions older than 0.11.7 are no longer tested against this@cloudflare/ai-chat. -
#1411
2fa68beThanks @threepointone! - Addoptions.signaltoAIChatAgent.saveMessagesandcontinueLastTurnfor external cancellation of programmatic turns, plus protectedabortRequest(id)/abortAllRequests()methods (#1406).saveMessagesandcontinueLastTurnaccept a secondSaveMessagesOptionsargument:const result = await this.saveMessages(messages, { signal: controller.signal, }); if (result.status === "aborted") { // Inference loop terminated mid-stream; partial chunks persisted. }
The signal is linked to AIChatAgent's per-turn
AbortControllerand produces the same end state as achat-request-cancelWebSocket message: the inference loop's signal aborts, partial chunks persist, the result reportsstatus: "aborted", andonChatResponsefires with the same status. Pre-aborted signals short-circuit before any model work runs. Listeners are detached cleanly when the turn finishes, so the same long-lived signal can be passed to many turns without leaking.abortRequest(id, reason?)andabortAllRequests()are protected entry points for subclasses that want to cancel turns without tracking ids.SaveMessagesResult.statusnow includes"aborted"alongside"completed"and"skipped". Existing callers that only switch on"completed"are unaffected.Limitations.
AbortSignalcannot cross Durable Object RPC. Construct the controller inside the DO that callssaveMessages.- The signal lives in memory only. If the DO hibernates mid-turn and
chatRecoveryis enabled, the recovered turn runs without the original signal.
See
cloudflare/agents#1406for the motivating use case.