@cloudflare/think 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +30 -40
  2. package/dist/{chat-sdk-BEjKXjCm.js → chat-sdk-4Nu96eDX.js} +375 -256
  3. package/dist/chat-sdk-4Nu96eDX.js.map +1 -0
  4. package/dist/extensions/index.d.ts +30 -72
  5. package/dist/extensions/index.js +45 -47
  6. package/dist/extensions/index.js.map +1 -1
  7. package/dist/{fetch-DO3uQ9py.js → fetch-BbYxtlff.js} +10 -2
  8. package/dist/fetch-BbYxtlff.js.map +1 -0
  9. package/dist/manager-B3rcb_6p.js +493 -0
  10. package/dist/manager-B3rcb_6p.js.map +1 -0
  11. package/dist/manager-CWGumyKi.d.ts +3391 -0
  12. package/dist/messengers/index.d.ts +54 -66
  13. package/dist/messengers/index.js +2 -2
  14. package/dist/messengers/telegram.d.ts +4 -4
  15. package/dist/messengers/telegram.js +1 -1
  16. package/dist/think.d.ts +2 -2
  17. package/dist/think.js +8493 -10725
  18. package/dist/think.js.map +1 -1
  19. package/dist/tools/browser.d.ts +1 -1
  20. package/dist/tools/browser.js +1 -1
  21. package/dist/tools/browser.js.map +1 -1
  22. package/dist/tools/execute.d.ts +2 -2
  23. package/dist/tools/execute.js +2 -2
  24. package/dist/tools/execute.js.map +1 -1
  25. package/dist/tools/extensions.d.ts +1 -1
  26. package/dist/tools/extensions.js +1 -1
  27. package/dist/tools/fetch.js +1 -1
  28. package/dist/workflows.d.ts +5 -2
  29. package/docs/actions.md +12 -0
  30. package/docs/channels.md +10 -4
  31. package/docs/client-tools.md +57 -27
  32. package/docs/context.md +92 -0
  33. package/docs/getting-started.md +4 -4
  34. package/docs/index.md +112 -52
  35. package/docs/lifecycle-hooks.md +10 -21
  36. package/docs/multi-chat.md +6 -6
  37. package/docs/programmatic-submissions.md +28 -10
  38. package/docs/sub-agents.md +45 -51
  39. package/docs/tools.md +41 -15
  40. package/docs/workflows.md +5 -4
  41. package/package.json +15 -10
  42. package/dist/chat-sdk-BEjKXjCm.js.map +0 -1
  43. package/dist/fetch-DO3uQ9py.js.map +0 -1
  44. package/dist/hook-proxy-DY2sBNa0.js +0 -117
  45. package/dist/hook-proxy-DY2sBNa0.js.map +0 -1
  46. package/dist/index-DDnny6kt.d.ts +0 -5847
  47. package/dist/manager-BubfmA3q.js +0 -313
  48. package/dist/manager-BubfmA3q.js.map +0 -1
  49. package/dist/manager-rze95KCk.d.ts +0 -235
@@ -41,6 +41,8 @@ interface StreamCallback {
41
41
 
42
42
  Each call ends with exactly one of `onDone`, `onError`, or `onInterrupted`. If you bridge `chat()` to an HTTP response (for example, a server-sent events stream), close the response in `onInterrupted` as well. Otherwise a stalled turn leaves the response open. The recovered answer is persisted and broadcast to WebSocket clients, not sent to this callback.
43
43
 
44
+ That holds for a call you do not cancel (see [Cancelling a sub-agent turn](#cancelling-a-sub-agent-turn)), while the parent's isolate lives. `onInterrupted` is optional: a caller that leaves it out hears nothing for an interrupted turn. If the parent restarts in the middle of a call (a deploy or another reset), the call ends with the parent and no callback follows; the child's turn is not ended by it, and the child's own recovery continues it or gives it up as for any interrupted turn. A parent that must know how it ended asks the child after its own restart.
45
+
44
46
  ### ChatOptions
45
47
 
46
48
  ```typescript
@@ -164,6 +166,10 @@ await child.chat("Long analysis task", callback, {
164
166
 
165
167
  When aborted, the partial assistant message is still persisted.
166
168
 
169
+ A turn you cancel gets no `onDone` and no `onError`, whatever reason the abort carries: `controller.abort()`, `controller.abort("moved on")` and `controller.abort(new Error("moved on"))` all end the turn `aborted`. The promise `chat()` returns resolves, and that is the signal the turn is over. A turn cancelled before it started, while it waited behind another turn, stores nothing, the user message included, and never calls the model.
170
+
171
+ If the chat is cleared while the turn waits or streams, the callback gets `onError("The chat was cleared before the turn finished.")` and nothing of the turn is stored.
172
+
167
173
  ---
168
174
 
169
175
  ## Programmatic Turns with saveMessages
@@ -177,14 +183,19 @@ async saveMessages(
177
183
  ): Promise<SaveMessagesResult>
178
184
  ```
179
185
 
180
- Returns `{ requestId, status, error? }` where `status` is `"completed"`, `"error"`, `"skipped"`, or `"aborted"`.
186
+ Returns `{ requestId, status, error?, reason? }` where `status` is `"completed"`, `"error"`, `"skipped"`, or `"aborted"`.
187
+
188
+ | `status` | When |
189
+ | ------------- | ------------------------------------------------------------------------------------------------------------ |
190
+ | `"completed"` | Turn ran to completion. |
191
+ | `"error"` | Turn started but the stream reported an error. `error` contains the stream error message when available. |
192
+ | `"skipped"` | The chat was cleared (`chat-clear`) before the turn finished, whether it was waiting or already streaming. |
193
+ | `"aborted"` | The turn did not run to completion. `reason` says why (see below). Partial assistant chunks still persisted. |
181
194
 
182
- | `status` | When |
183
- | ------------- | ------------------------------------------------------------------------------------------------------------------------- |
184
- | `"completed"` | Turn ran to completion. |
185
- | `"error"` | Turn started but the stream reported an error. `error` contains the stream error message when available. |
186
- | `"skipped"` | Turn invalidated mid-flight (e.g. by `chat-clear`); user message persisted, no model run. |
187
- | `"aborted"` | Turn cancelled before completion via `options.signal` or `chat-request-cancel`. Partial assistant chunks still persisted. |
195
+ An `aborted` result carries a `reason`:
196
+
197
+ - `"stopped"`: something stopped the turn (`options.signal`, `chat-request-cancel`, `abortAllRequests()`). No reply will follow.
198
+ - `"interrupted"`: the reply was cut off, for example by a stalled or dropped provider stream, and handed to [chat recovery](/agents/api-reference/durable-execution/). Nobody stopped it, and the reply may still arrive, because recovery continues or retries the turn on its own. Do not treat this as a user cancel.
188
199
 
189
200
  ### Static messages
190
201
 
@@ -215,11 +226,9 @@ await this.saveMessages((current) => [
215
226
 
216
227
  ### Scheduled responses
217
228
 
218
- Declared scheduled tasks are armed on the **root agent only**.
219
- `getScheduledTasks()` is usually a static declaration, so it returns the same
220
- tasks on every instance of the class — arming it on sub-agents too would fire
221
- each occurrence once per live sub-agent on top of the root. Declare the task on
222
- the root and let it fan out to sub-agents itself:
229
+ A sub-agent that declares scheduled tasks arms its own, and its root wakes it
230
+ when one is due. For a schedule that runs once and fans out, declare the task
231
+ on the root:
223
232
 
224
233
  ```typescript
225
234
  export class MyAgent extends Think<Env> {
@@ -227,7 +236,7 @@ export class MyAgent extends Think<Env> {
227
236
  /* ... */
228
237
  }
229
238
 
230
- getScheduledTasks() {
239
+ getScheduledTasks(): ThinkScheduledTasks {
231
240
  return {
232
241
  dailyReport: {
233
242
  schedule: "every day at 09:00",
@@ -250,25 +259,8 @@ export class MyAgent extends Think<Env> {
250
259
  }
251
260
  ```
252
261
 
253
- If a class genuinely declares _different_ tasks per sub-agent — for example when
254
- `getScheduledTasks()` reads per-sub-agent state — opt in with
255
- `getScheduledTasksScope()` and each sub-agent owns an independent schedule:
256
-
257
- ```typescript
258
- export class PerUserAgent extends Think<Env> {
259
- getScheduledTasksScope() {
260
- return "all" as const;
261
- }
262
-
263
- async getScheduledTasks() {
264
- const reminder = await this.getReminderForThisUser();
265
- return reminder ? { reminder } : {};
266
- }
267
- }
268
- ```
269
-
270
- A sub-agent that declares tasks without opting in logs a warning naming this
271
- hook, so an inert schedule is never silent.
262
+ For a schedule per user, give each user their own Durable Object and declare
263
+ the task there.
272
264
 
273
265
  ### Chaining from onChatResponse
274
266
 
@@ -292,10 +284,10 @@ async onChatResponse(result: ChatResponseResult) {
292
284
 
293
285
  - the inference loop's signal aborts (the same path `chat-request-cancel` takes);
294
286
  - partial chunks already streamed are persisted to the resumable stream;
295
- - `saveMessages` resolves with `{ status: "aborted" }`;
287
+ - `saveMessages` resolves with `{ status: "aborted", reason: "stopped" }`;
296
288
  - `onChatResponse` fires with `status: "aborted"`.
297
289
 
298
- If the signal is **already aborted** when `saveMessages` is called, no inference work runs.
290
+ If the signal is **already aborted** when `saveMessages` is called, or aborts while the turn waits behind another turn, the turn does not start. Nothing is stored, the model is not called, and `onChatResponse` does not fire. A stop that lands after the messages are stored and before the model is called leaves the messages in the transcript and also fires no `onChatResponse`. A stop that lands after the reply finished changes nothing: the result is `completed`.
299
291
 
300
292
  ```typescript
301
293
  class MyAgent extends Think<Env> {
@@ -384,10 +376,12 @@ protected abortRequest(requestId: string, reason?: unknown): void
384
376
  protected abortAllRequests(): void
385
377
  ```
386
378
 
387
- - **`abortRequest(id, reason?)`** — abort a specific in-flight turn by id. No-op if no controller exists for that id. Equivalent to a client `chat-request-cancel`.
388
- - **`abortAllRequests()`** — abort every in-flight controller in the registry. Used by single-purpose sub-agents that don't track ids.
379
+ - **`abortRequest(id, reason?)`** — stop the request `id`, the same as a client `chat-request-cancel` or `cancelChat(id)`: its turn if one is running or queued, and a chat recovery of it that is scheduled or running.
380
+ - **`abortAllRequests()`** — abort every turn, running or waiting in the queue. A turn that had not started ends `aborted`: it stores nothing and does not call the model. Used by single-purpose sub-agents that don't track ids.
381
+
382
+ A stop ends the turn `aborted` whatever `reason` is. The model call or a hook that waits on the turn's `abortSignal` fails with that reason, and that failure is the stop, not an error: `onChatError` is not called and clients get no error frame.
389
383
 
390
- Both methods produce the same end state as `chat-request-cancel`: inference loop terminates, partial chunks persist, the turn's `ChatResponseResult` reports `status: "aborted"`. Prefer `options.signal` on `saveMessages` / `continueLastTurn` when driving a turn programmatically — it threads the abort intent in from turn start without requiring the caller to know the id.
384
+ For a turn that is running, both methods produce the same end state as `chat-request-cancel`: inference loop terminates, partial chunks persist, the turn's `ChatResponseResult` reports `status: "aborted"`. A turn that had not started has no `ChatResponseResult`. Prefer `options.signal` on `saveMessages` / `continueLastTurn` when driving a turn programmatically — it threads the abort intent in from turn start without requiring the caller to know the id.
391
385
 
392
386
  ---
393
387
 
@@ -402,7 +396,7 @@ Every turn entry path is wrapped in `runFiber`: WebSocket chat, sub-agent `chat(
402
396
  When an interrupted chat fiber is detected after DO restart, or when the stream-stall watchdog (`chatStreamStallTimeoutMs`) aborts a live turn, Think calls the `onChatRecovery` hook:
403
397
 
404
398
  ```typescript
405
- onChatRecovery(ctx: ChatRecoveryContext): ChatRecoveryOptions | void
399
+ onChatRecovery(ctx: ChatRecoveryContext): Promise<ChatRecoveryOptions | void>
406
400
  ```
407
401
 
408
402
  ### ChatRecoveryContext
@@ -438,7 +432,7 @@ export class MyAgent extends Think<Env> {
438
432
  /* ... */
439
433
  }
440
434
 
441
- onChatRecovery(ctx: ChatRecoveryContext) {
435
+ async onChatRecovery(ctx: ChatRecoveryContext) {
442
436
  console.log(
443
437
  `Recovering turn ${ctx.requestId}, partial: ${ctx.partialText.length} chars`
444
438
  );
@@ -455,7 +449,7 @@ With `persist: true`, the partial message is saved. With `continue: true`, Think
455
449
  For pre-stream interruptions, where `ctx.streamId === ""` and `ctx.partialText === ""` but the latest persisted message is still the unanswered user message, Think retries that turn automatically unless `continue` is `false`.
456
450
 
457
451
  ```typescript
458
- onChatRecovery(ctx: ChatRecoveryContext): ChatRecoveryOptions {
452
+ async onChatRecovery(ctx: ChatRecoveryContext): Promise<ChatRecoveryOptions> {
459
453
  if (!ctx.streamId && !ctx.partialText) {
460
454
  console.log("Recovering a pre-stream interruption");
461
455
  }
@@ -466,7 +460,7 @@ onChatRecovery(ctx: ChatRecoveryContext): ChatRecoveryOptions {
466
460
  To suppress continuation for turns that have been orphaned too long to safely replay, gate on `ctx.createdAt`:
467
461
 
468
462
  ```typescript
469
- onChatRecovery(ctx: ChatRecoveryContext): ChatRecoveryOptions {
463
+ async onChatRecovery(ctx: ChatRecoveryContext): Promise<ChatRecoveryOptions> {
470
464
  if (Date.now() - ctx.createdAt > 2 * 60 * 1000) {
471
465
  return { continue: false };
472
466
  }
@@ -502,16 +496,16 @@ export class MyAgent extends Think<Env> {
502
496
  }
503
497
  ```
504
498
 
505
- | Field | Default | Description |
506
- | ------------------------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
507
- | `maxAttempts` | `10` | Attempt cap. Resets on forward progress, so it catches a tight no-progress alarm loop, not a healthy long turn. |
508
- | `stableTimeoutMs` | `10_000` | How long an attempt waits for the isolate to reach stable state before rescheduling. |
509
- | `noProgressTimeoutMs` | `300_000` (5 min) | Primary stuck-turn bound: max time without forward progress before sealing. **Resets on every progress-bearing attempt.** |
510
- | `maxRecoveryWork` | `10000` | Runaway-loop guard: max recovery work since the incident opened before a still-progressing turn is sealed (`work_budget_exceeded`), counted in durable stream segments (see [Recovery work units](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#recovery-work-units)). A generous finite backstop so a turn that keeps emitting content but never converges cannot loop forever. Raise it, or set `Infinity`, for a very long agentic turn. |
511
- | `maxInterruptedAttempts` | `5` | How many of one turn's attempts may be interrupted (their isolate died before they finished, for example a memory-limit reset or a deploy) before recovery seals with `interrupted_attempts_exceeded`. The original turn counts. Progress never resets it. Replaces `maxOomRetries`, which is still read as `maxOomRetries + 1`. |
512
- | `shouldKeepRecovering` | — | Caller policy consulted from the second attempt onward. Return `false` to stop recovery. The hook point for a token/cost budget (`ctx.work` is a durable segment count, not tokens). |
513
- | `terminalMessage` | generic message | Message shown to the user when recovery is given up on. |
514
- | `onExhausted` | — | Called once when recovery is given up on. Inspect `ctx.reason`. |
499
+ | Field | Default | Description |
500
+ | ------------------------ | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
501
+ | `maxAttempts` | `10` | Attempt cap. Resets on forward progress, so it catches a tight no-progress alarm loop, not a healthy long turn. |
502
+ | `stableTimeoutMs` | `10_000` | How long an attempt waits for the isolate to reach stable state before rescheduling. |
503
+ | `noProgressTimeoutMs` | `300_000` (5 min) | Primary stuck-turn bound: max time without forward progress before sealing. **Resets on every progress-bearing attempt.** |
504
+ | `maxRecoveryWork` | `10000` | Runaway-loop guard: max recovery work since the incident opened before a still-progressing turn is sealed (`work_budget_exceeded`), counted in units of ten stored stream chunks (see [Recovery work units](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#recovery-work-units)). A generous finite backstop so a turn that keeps emitting content but never converges cannot loop forever. Raise it, or set `Infinity`, for a very long agentic turn. |
505
+ | `maxInterruptedAttempts` | `5` | How many of one turn's attempts may be interrupted (their isolate died before they finished, for example a memory-limit reset or a deploy) before recovery seals with `interrupted_attempts_exceeded`. The original turn counts. Progress never resets it. Replaces `maxOomRetries`, which is still read as `maxOomRetries + 1`. |
506
+ | `shouldKeepRecovering` | — | Caller policy consulted from the second attempt onward. Return `false` to stop recovery. The hook point for a token/cost budget (`ctx.work` counts stored chunks, not tokens). |
507
+ | `terminalMessage` | generic message | Message shown to the user when recovery is given up on. |
508
+ | `onExhausted` | — | Called once when recovery is given up on. Inspect `ctx.reason`. |
515
509
 
516
510
  `ctx.reason` on the exhausted hook is one of: `no_progress_timeout` (stuck), `max_attempts_exceeded` (no-progress alarm loop), `work_budget_exceeded` (runaway), `interrupted_attempts_exceeded` (the turn's attempts kept dying, for example to memory-limit resets), `out_of_memory` (sealed by the alarm memory-limit breaker), `recovery_aborted` (your `shouldKeepRecovering` returned `false`), or `stable_timeout` (extreme churn). See [`chat-agents.md`](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#stream-recovery) for the full shared reference — Think and `@cloudflare/ai-chat` use the same recovery configuration.
517
511
 
package/docs/tools.md CHANGED
@@ -43,7 +43,7 @@ The default Workspace has no execution backends, so there is no `exec` tool unti
43
43
  ```typescript
44
44
  import { Think } from "@cloudflare/think";
45
45
  import { Workspace } from "@cloudflare/computer";
46
- import { WorkerJavaScriptBackend } from "@cloudflare/computer/backends/worker-javascript";
46
+ import { CodemodeBackend } from "@cloudflare/computer/backends/codemode";
47
47
  import { createGitClient } from "@cloudflare/computer/git";
48
48
  import { createGitModule } from "@cloudflare/computer/modules/git";
49
49
 
@@ -52,11 +52,10 @@ export class MyAgent extends Think<Env> {
52
52
  storage: this.ctx.storage,
53
53
  git: createGitClient(),
54
54
  backends: [
55
- new WorkerJavaScriptBackend({
56
- id: "js",
55
+ new CodemodeBackend({
57
56
  loader: this.env.LOADER,
58
57
  access: "read-write",
59
- modules: { "ws:git": createGitModule() }
58
+ modules: { "codemode:git": createGitModule() }
60
59
  })
61
60
  ]
62
61
  });
@@ -67,28 +66,27 @@ export class MyAgent extends Think<Env> {
67
66
  }
68
67
  ```
69
68
 
70
- Computer ships a JavaScript backend and a just-bash shell backend that run in Dynamic Workers, and a container backend with a full Linux userland. See the [Computer README](https://github.com/cloudflare/computer/tree/main/packages/computer#choosing-a-backend) for each backend's bindings.
69
+ Computer ships a codemode backend for JavaScript and a just-bash shell backend that run in Dynamic Workers, and a container backend with a full Linux userland. See the [Computer README](https://github.com/cloudflare/computer/tree/main/packages/computer#choosing-a-backend) for each backend's bindings.
71
70
 
72
71
  ### Calling the agent's tools from code
73
72
 
74
- Give a JavaScript backend a `ws:tools` module, and code the model runs with `exec` can import the agent's tools. Files come from `node:fs/promises`, so serve `getTools()` rather than the workspace tools:
73
+ Give a codemode backend a `codemode:tools` module, and code the model runs with `exec` can import the agent's tools. Files come from `node:fs/promises`, so serve `getTools()` rather than the workspace tools:
75
74
 
76
75
  ```typescript
77
76
  import { createToolBindings } from "@cloudflare/computer/modules/tools";
78
77
  import { forAISDKTools } from "@cloudflare/computer/tools/ai-sdk";
79
78
 
80
- new WorkerJavaScriptBackend({
81
- id: "js",
79
+ new CodemodeBackend({
82
80
  loader: this.env.LOADER,
83
81
  modules: {
84
- "ws:tools": createToolBindings(forAISDKTools(() => this.getTools()))
82
+ "codemode:tools": createToolBindings(forAISDKTools(() => this.getTools()))
85
83
  }
86
84
  });
87
85
  ```
88
86
 
89
87
  ```ts
90
88
  import { readFile } from "node:fs/promises";
91
- import { getWeather } from "ws:tools";
89
+ import { getWeather } from "codemode:tools";
92
90
 
93
91
  export default async function () {
94
92
  const cities = JSON.parse(await readFile("/workspace/cities.json", "utf8"));
@@ -98,7 +96,7 @@ export default async function () {
98
96
  }
99
97
  ```
100
98
 
101
- Tools that need approval, and tools that run in the browser, are not exported: nothing can approve or run them from code. Calls from code do not go through `beforeToolCall`. See [`ws:tools`](https://github.com/cloudflare/computer/blob/main/docs/17_isolate_javascript.md#wstools) for how calls and results work.
99
+ Tools that need approval, and tools that run in the browser, are not exported: nothing can approve or run them from code. Calls from code do not go through `beforeToolCall`. See [`codemode:tools`](https://github.com/cloudflare/computer/blob/main/docs/17_isolate_javascript.md#codemodetools) for how calls and results work.
102
100
 
103
101
  ### Changing the tools
104
102
 
@@ -257,7 +255,7 @@ See [Connecting to MCP Servers](https://github.com/cloudflare/agents/blob/main/d
257
255
 
258
256
  ## Code Execution Tool
259
257
 
260
- > **Deprecated.** Use `exec` on a JavaScript backend with `ws:tools` instead; see [Calling the agent's tools from code](#calling-the-agents-tools-from-code). `createExecuteTool` will be removed along with `@cloudflare/codemode`.
258
+ > **Deprecated.** Use `exec` on a codemode backend with `codemode:tools` instead; see [Calling the agent's tools from code](#calling-the-agents-tools-from-code). `createExecuteTool` will be removed along with `@cloudflare/codemode`.
261
259
 
262
260
  Let the LLM write and run TypeScript in a sandboxed Worker, recorded on a durable codemode runtime (abort-and-replay, human approvals, audit trail, reusable snippets). Requires `@cloudflare/codemode` and a `worker_loaders` binding.
263
261
 
@@ -491,7 +489,7 @@ export class MyAgent extends Think<Env> {
491
489
  manifest: {
492
490
  name: "math",
493
491
  version: "1.0.0",
494
- permissions: { network: false }
492
+ permissions: { network: [] }
495
493
  },
496
494
  source: `({
497
495
  tools: {
@@ -513,6 +511,8 @@ export class MyAgent extends Think<Env> {
513
511
 
514
512
  Extension tools are namespaced — `math` extension with `add` tool becomes `math_add` in the model's tool set.
515
513
 
514
+ `permissions.network` lists the hosts an extension may fetch: `api.example.com` matches that host only, `*.example.com` its subdomains. An empty list, or none, means no network at all. To enforce the list, re-export `HostBridgeLoopback` from your Worker entry (`export { HostBridgeLoopback } from "@cloudflare/think/extensions";`). Every request the extension makes then goes through it, and a request to an unlisted host or to a private or local address gets a `403`. Without the re-export the list is not enforced: an extension with any host listed can reach every host, and Think logs a warning.
515
+
516
516
  ### LLM-Driven Extensions
517
517
 
518
518
  Give the model `createExtensionTools` so it can load extensions dynamically:
@@ -553,7 +553,7 @@ getExtensions() {
553
553
  manifest: {
554
554
  name: "notes",
555
555
  version: "1.0.0",
556
- permissions: { network: false },
556
+ permissions: { network: [] },
557
557
  context: [
558
558
  { label: "scratchpad", description: "Extension scratch space", maxTokens: 500 }
559
559
  ]
@@ -563,4 +563,30 @@ getExtensions() {
563
563
  }
564
564
  ```
565
565
 
566
- The context block is registered as `notes_scratchpad` (namespaced by extension name).
566
+ The context block is registered as `notes_scratchpad` (namespaced by extension name). The extension writes it with `host.setContext()`, which needs the `context.write` permission. A block's `type` is ignored, with a warning.
567
+
568
+ ### Upgrading extensions from Think 0.24
569
+
570
+ Extensions installed under Think 0.24 load as before; their source, manifest and context blocks do not change. Two kinds of host code do:
571
+
572
+ - `ExtensionManager.getHookSubscribers()` throws. Think calls each loaded extension's hooks on every turn, so delete the call and the code that called the hooks it returned:
573
+
574
+ ```typescript
575
+ // Before (Think 0.24)
576
+ for (const { entrypoint } of manager.getHookSubscribers("beforeTurn")) {
577
+ await entrypoint.hook("beforeTurn", snapshot);
578
+ }
579
+
580
+ // After: nothing. Think runs the extension's beforeTurn hook itself.
581
+ ```
582
+
583
+ - `createBridgeProvider`, `ExtensionContextBridge` and `ExtensionWritableBridge` are no longer exported from `@cloudflare/think/extensions`. Think registers an extension's context blocks itself, and the extension's Worker no longer has a method to read a block through. If your code built a context provider over an extension with them, delete it:
584
+
585
+ ```typescript
586
+ // Before (Think 0.24)
587
+ import { createBridgeProvider } from "@cloudflare/think/extensions";
588
+ const provider = createBridgeProvider("notes", "readonly", entrypoint);
589
+
590
+ // After: nothing. Declare the block in the extension's manifest
591
+ // (`context`, as above) and Think registers it when the extension loads.
592
+ ```
package/docs/workflows.md CHANGED
@@ -118,7 +118,7 @@ a terminal error state and `step.prompt()` throws.
118
118
  - **The model must support streaming tool calls.** Think streams every turn, so
119
119
  `step.prompt()` works only with models that reliably emit a forced tool call
120
120
  while streaming. Strong tool-callers (for example OpenAI `gpt-4o-mini`,
121
- Anthropic `claude-haiku-4-5`, and Workers AI `@cf/moonshotai/kimi-k2.7-code`) are
121
+ Anthropic `claude-haiku-4-5`, and Workers AI `@cf/deepseek-ai/deepseek-v4.1-flash-1017`) are
122
122
  verified to work. Some models honor a forced `toolChoice` only on
123
123
  non-streaming requests and will reply in plain text and stop while streaming —
124
124
  for example Workers AI `@cf/meta/llama-3.3-70b-instruct-fp8-fast`. With those
@@ -136,8 +136,9 @@ Object RPC open.
136
136
  2. Think runs the submitted turn through the normal submission queue.
137
137
  3. When the submission reaches `completed`, `error`, `aborted`, or `skipped`,
138
138
  Think records a pending workflow notification.
139
- 4. Think drains the notification outbox with `sendWorkflowEvent()` and Durable
140
- Object alarms until delivery succeeds.
139
+ 4. Think sends the notification with `sendWorkflowEvent()` at once. A failed
140
+ send is retried from Durable Object alarms with backoff until it succeeds,
141
+ for up to twelve hours.
141
142
  5. `step.waitForEvent("<name>:wait", ...)` resumes the Workflow.
142
143
  6. `step.prompt()` validates the structured output or throws a typed error.
143
144
 
@@ -189,7 +190,7 @@ Use `getScheduledTasks()` for recurring prompt submissions or deterministic
189
190
  scheduled handlers:
190
191
 
191
192
  ```typescript
192
- getScheduledTasks() {
193
+ getScheduledTasks(): ThinkScheduledTasks {
193
194
  return {
194
195
  dailySummary: {
195
196
  schedule: "every day at 09:00",
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "tools"
10
10
  ],
11
11
  "type": "module",
12
- "version": "0.23.0",
12
+ "version": "0.25.0",
13
13
  "license": "MIT",
14
14
  "repository": {
15
15
  "directory": "packages/think",
@@ -23,19 +23,19 @@
23
23
  "dependencies": {
24
24
  "@ai-sdk/anthropic": "^4.0.0",
25
25
  "@ai-sdk/openai": "^4.0.0",
26
- "@cloudflare/codemode": "^0.5.6",
26
+ "@cloudflare/codemode": "^0.5.7",
27
27
  "chat": "^4.31.0",
28
28
  "workers-ai-provider": "^4.0.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@ai-sdk/react": "^4.0.0",
32
32
  "@chat-adapter/telegram": "^4.31.0",
33
- "@cloudflare/computer": "^0.8.0",
33
+ "@cloudflare/computer": "^0.10.0",
34
34
  "@testing-library/react": "^16.3.2",
35
35
  "@types/react": "^19.2.17",
36
36
  "@types/react-dom": "^19.2.3",
37
37
  "@vitejs/plugin-react": "^6.0.3",
38
- "agents": "^0.32.0",
38
+ "agents": "^0.35.0",
39
39
  "ai": "^7.0.0",
40
40
  "jsdom": "^29.1.1",
41
41
  "react": "^19.2.7",
@@ -46,8 +46,8 @@
46
46
  "peerDependencies": {
47
47
  "@ai-sdk/react": "^4.0.0",
48
48
  "@chat-adapter/telegram": "^4.29.0",
49
- "@cloudflare/computer": "^0.8.0",
50
- "agents": ">=0.28.0 <1.0.0",
49
+ "@cloudflare/computer": "^0.10.0",
50
+ "agents": ">=0.35.0 <1.0.0",
51
51
  "ai": "^7.0.0",
52
52
  "react": "^19.0.0",
53
53
  "zod": "^4.0.0"
@@ -116,6 +116,13 @@
116
116
  ],
117
117
  "nx": {
118
118
  "targets": {
119
+ "test": {
120
+ "inputs": [
121
+ "default",
122
+ "^production",
123
+ "{workspaceRoot}/design/models/traces/**/*"
124
+ ]
125
+ },
119
126
  "build": {
120
127
  "inputs": [
121
128
  "production",
@@ -134,9 +141,7 @@
134
141
  "build": "tsx ./scripts/build.ts",
135
142
  "test": "npm run test:workers && npm run test:react",
136
143
  "test:react": "vitest --run -c src/react-tests/vitest.config.ts",
137
- "test:workers": "vitest --run -c src/tests/vitest.config.ts",
138
- "test:e2e": "vitest --run -c src/e2e-tests/vitest.config.ts",
139
- "test:harness": "tsx scripts/harness-compat.ts",
140
- "test:harness:check": "tsx scripts/harness-compat.ts --check"
144
+ "test:workers": "vitest --run -c src/tests/vitest.config.ts && vitest --run -c src/tests/vitest.replay.config.ts",
145
+ "test:e2e": "vitest --run -c src/e2e-tests/vitest.config.ts"
141
146
  }
142
147
  }