Merged
Conversation
48ce786 to
0ed1522
Compare
0ed1522 to
69e1062
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
@cloudflare/ai-chat@0.5.0
Minor Changes
#1353
f834c81Thanks @threepointone! - AlignAIChatAgentgenerics and types with@cloudflare/think, plus a reference example for multi-session chat built on the sub-agent routing primitive.Propsgeneric:AIChatAgent<Env, State, Props>extendingAgent<Env, State, Props>. Subclasses now get properly typedthis.ctx.props.ChatResponseResult,ChatRecoveryContext,ChatRecoveryOptions,SaveMessagesResult, andMessageConcurrencynow live inagents/chatand are re-exported by both@cloudflare/ai-chatand@cloudflare/think. No behavior change; one place to edit when shapes evolve.ChatMessagestays the public message type: the package continues to exportChatMessage, and the public API/docs keep using that name.messagesstays a public field:messages: ChatMessage[].The full stance (AIChatAgent is first-class, production-ready, and continuing to get features; shared infrastructure should land in
agents/chatwhere both classes benefit) is captured indesign/rfc-ai-chat-maintenance.md.A new example,
examples/multi-ai-chat, demonstrates the multi-session pattern end-to-end on top of the sub-agent routing primitive: anInboxAgent owns the chat list + shared memory; each chat is anAIChatAgentfacet (this.subAgent(Chat, id)). The client addresses the active chat viauseAgent({ sub: [{ agent: "Chat", name: chatId }] })— no separate DO binding, no custom routing on the server.Inbox.onBeforeSubAgentgates withhasSubAgentas a strict registry, andChatreaches its parent viathis.parentAgent(Inbox).Patch Changes
#1358
ea229b1Thanks @threepointone! - FixuseAgentChat()crashing on first render whenagent.getHttpUrl()returns an empty string. This happened in setups where the WebSocket handshake hadn't completed by the time React rendered — most commonly when the agent is reached through a proxy or custom-routed worker — because@cloudflare/ai-chatunconditionally callednew URL(agent.getHttpUrl()). See #1356.useAgentChat()now treats a missing HTTP URL as "not ready yet":/get-messagesfetch is deferred until the URL is known, and applied exactly once when it resolves (empty chats only — existing messages are never overwritten).getInitialMessagescallbacks continue to run and are passedurl: undefinedso they can load from other sources if they don't need the socket URL.GetInitialMessagesOptions.urlis nowstring | undefined; callers that previously typedurl: stringshould widen tourl?: string.useChatinstance keeps a stableidacross the URL-arrival transition, so in-flight stream resume and chat state are preserved.No API or behavior changes for apps where the URL was already available synchronously on first render.
@cloudflare/think@0.4.0
Minor Changes
#1350
3a1140fThanks @threepointone! - AlignThinkgenerics withAgent/AIChatAgent.Thinkis nowThink<Env, State, Props>and extendsAgent<Env, State, Props>, so subclasses get properly typedthis.state,this.setState(),initialState, andthis.ctx.props. The previousConfigclass generic is removed.configure()andgetConfig()remain, but the config type is now specified at the call site via a method-level generic:This is a breaking change for anyone using the second type parameter of
Think. Update the class declaration and any directconfigure(...)/getConfig()call sites that relied on the class-levelConfigtype.agents@0.11.5
Patch Changes
#1353
f834c81Thanks @threepointone! - AlignAIChatAgentgenerics and types with@cloudflare/think, plus a reference example for multi-session chat built on the sub-agent routing primitive.Propsgeneric:AIChatAgent<Env, State, Props>extendingAgent<Env, State, Props>. Subclasses now get properly typedthis.ctx.props.ChatResponseResult,ChatRecoveryContext,ChatRecoveryOptions,SaveMessagesResult, andMessageConcurrencynow live inagents/chatand are re-exported by both@cloudflare/ai-chatand@cloudflare/think. No behavior change; one place to edit when shapes evolve.ChatMessagestays the public message type: the package continues to exportChatMessage, and the public API/docs keep using that name.messagesstays a public field:messages: ChatMessage[].The full stance (AIChatAgent is first-class, production-ready, and continuing to get features; shared infrastructure should land in
agents/chatwhere both classes benefit) is captured indesign/rfc-ai-chat-maintenance.md.A new example,
examples/multi-ai-chat, demonstrates the multi-session pattern end-to-end on top of the sub-agent routing primitive: anInboxAgent owns the chat list + shared memory; each chat is anAIChatAgentfacet (this.subAgent(Chat, id)). The client addresses the active chat viauseAgent({ sub: [{ agent: "Chat", name: chatId }] })— no separate DO binding, no custom routing on the server.Inbox.onBeforeSubAgentgates withhasSubAgentas a strict registry, andChatreaches its parent viathis.parentAgent(Inbox).#1348
0693a5fThanks @threepointone! - Bump dependencies.#1362
d901804Thanks @threepointone! - fix(mcp): capture tool title in MCP client#1355
df2023fThanks @threepointone! - External addressability for sub-agents.Clients can now reach a facet (a child DO created by
Agent#subAgent()) directly via a nested URL:New public APIs (all
@experimental):routeSubAgentRequest(req, parent, options?)— sub-agent analog ofrouteAgentRequest. For custom-routing setups where the outer URL doesn't match the default/agents/...shape.getSubAgentByName(parent, Cls, name)— sub-agent analog ofgetAgentByName. Returns a typed Proxy that round-trips typed RPC calls through the parent. RPC-only (no.fetch()); userouteSubAgentRequestfor external HTTP/WS.parseSubAgentPath(url, options?)— public URL parser used internally by the routers.SUB_PREFIX— the"sub"separator constant (not configurable; exposed for symbolic URL building).New public on
Agent:onBeforeSubAgent(req, { className, name })— overridable middleware hook, mirrorsonBeforeConnect/onBeforeRequest. ReturnsRequest | Response | voidfor short-circuit responses, request mutation, or passthrough. Default: void.parentPath/selfPath— root-first{ className, name }ancestor chains, populated at facet init time. Inductive across recursive nesting.hasSubAgent(ClsOrName, name)/listSubAgents(ClsOrName?)— parent-side introspection backed by an auto-maintained SQLite registry written bysubAgent()/deleteSubAgent(). Both accept either the class constructor or a CamelCase class name string.New public on
useAgent(React):sub?: Array<{ agent, name }>— flat root-first chain addressing a descendant facet. The hook's.agent/.namereport the leaf identity;.pathexposes the full chain.Breaking changes: none.
routeAgentRequestbehavior is unchanged when URLs don't contain/sub/.onBeforeSubAgentdefaults to permissive (forward unchanged).useAgentwithoutsubis unchanged.subAgent()/deleteSubAgent()gain registry side effects but preserve return types and failure modes. The_cf_initAsFacetsignature gained an optionalparentPathparameter.deleteSubAgent()is now idempotent — calling it for a never-spawned or already-deleted child no longer throws. Sub-agent class names equal to"Sub"are rejected (the/sub/URL separator is reserved).See
design/rfc-sub-agent-routing.mdfor the full rationale, design decisions, and edge cases. The spike atpackages/agents/src/tests/spike-sub-agent-routing.test.tsdocuments the three candidate approaches considered for cross-DO stub passthrough and why the per-call bridge won.#1346
a78bb2aThanks @threepointone! - Remove unuseddependencies,devDependencies, andpeerDependenciesfrom theagentspackage.dependencies: dropjson-schema,json-schema-to-typescript, andpicomatch. None are imported by the package;picomatchwas already pulled in transitively via@rolldown/plugin-babel.devDependencies: drop@ai-sdk/openai(only referenced in a commented-out line) and@cloudflare/workers-oauth-provider(not referenced anywhere).peerDependencies/peerDependenciesMeta: drop@ai-sdk/reactandviem.@ai-sdk/reactis already a peer of@cloudflare/ai-chat(itself an optional peer here), andviemis a regular dependency of@x402/evm, so both are supplied transitively when the relevant optional features are used.