Commit c58b401
feat: hoist useAgentChat into agents/chat/react with product wrappers (#1801)
* feat: hoist useAgentChat into agents/chat/react with product wrappers
Move the canonical `useAgentChat` implementation, WebSocket chat transport,
and chat wire types out of `@cloudflare/ai-chat` and into a new shared
`agents/chat/react` entry. `@cloudflare/ai-chat/react` and the new
`@cloudflare/think/react` become thin wrappers over this shared core, so
Think apps no longer need to depend on `@cloudflare/ai-chat` just to get the
React hook.
Why
---
Using `useAgentChat` from `@cloudflare/ai-chat` against a Think server was
awkward and behaviorally divergent. The biggest footgun was `setMessages`:
`AIChatAgent` persists a client-pushed flat transcript, while Think is
server-authoritative and silently ignores it. Apps had to pull in an
unrelated package and still got surprising behavior.
What changed
------------
- agents: add `agents/chat/react` exposing `useAgentChat`,
`WebSocketChatTransport`, and shared chat wire types
(`MessageType`, `OutgoingMessage`, `IncomingMessage`). Add a new
`syncMessagesToServer` option (default `true`) so server-authoritative
hosts can keep `setMessages` local-only. `@ai-sdk/react` is added as an
optional peer dependency (only the chat/react subpath needs it).
- ai-chat: `react.tsx`, `types.ts`, and `ws-chat-transport.ts` are now
thin re-export shims over `agents/chat/react`. Public API and behavior
are unchanged for existing consumers.
- think: add `@cloudflare/think/react`, a Think-tuned wrapper that hardcodes
`syncMessagesToServer: false` (and omits it from its option type), so
`setMessages` stays a local view update. A dev-only warn-once covers plain
JS callers that pass the option anyway.
- think (server): warn once (dev only) when Think receives a client-pushed
`CF_AGENT_CHAT_MESSAGES` frame, naming `@cloudflare/think/react` and
`clearHistory()` as the fix. This is behavior-triggered, so it only fires
when an app actually hits the divergence (e.g. the ai-chat hook against a
Think server).
- docs/examples/starters: migrate all Think-backed clients to import the
hook from `@cloudflare/think/react` and drop the now-unnecessary
`@cloudflare/ai-chat` dependency. AIChatAgent-backed examples are
unchanged. Document that `setMessages` is display-only on Think.
Changesets: agents (minor), @cloudflare/think (minor),
@cloudflare/ai-chat (patch).
Co-authored-by: Cursor <cursoragent@cursor.com>
* test(think-cli): assert basic template marker after ai-chat removal
The starter migration dropped `@cloudflare/ai-chat` from the basic Think
template, so the CLI scaffold test's dependency assertion was stale. Assert
on `@cloudflare/kumo` instead — still a full-starter-only marker that
distinguishes a template scaffold from an augment.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Sunil Pai <18808+threepointone@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 3c2afc9 commit c58b401
60 files changed
Lines changed: 3762 additions & 3531 deletions
File tree
- .changeset
- docs/think
- examples
- agent-skills
- src
- agents-as-tools
- src
- assistant
- src
- browser-live-view
- src
- chat-sdk-messenger
- src
- context-overflow-recovery
- src
- deploy-churn
- src
- think-chat-sdk
- src
- experimental/session-skills
- src
- packages
- agents
- scripts
- src/chat
- ai-chat/src
- react-tests
- think
- scripts
- src
- cli-tests
- react-tests
- studio/src/views
- think-starters
- basic
- src
- business-workflow
- src
- coding-agent
- src
- customer-support
- src
- personal-assistant
- src
- webhook-agent
- src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
587 | | - | |
| 587 | + | |
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
0 commit comments