@cloudflare/think 0.16.0 → 0.17.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.
- package/README.md +4 -4
- package/dist/{index-BZKPlFcA.d.ts → index-B7zEkBBM.d.ts} +14 -12
- package/dist/messengers/index.d.ts +1 -1
- package/dist/messengers/telegram.d.ts +1 -1
- package/dist/think.d.ts +1 -1
- package/dist/think.js +50 -38
- package/dist/think.js.map +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/index.md +29 -29
- package/docs/sub-agents.md +7 -19
- package/package.json +3 -3
package/dist/workflows.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _n as ThinkSubmissionStatus, cn as Think } from "./index-
|
|
1
|
+
import { _n as ThinkSubmissionStatus, cn as Think } from "./index-B7zEkBBM.js";
|
|
2
2
|
import { ZodObject, z } from "zod";
|
|
3
3
|
import { WorkflowEvent, WorkflowSleepDuration } from "cloudflare:workers";
|
|
4
4
|
import {
|
package/docs/index.md
CHANGED
|
@@ -305,9 +305,9 @@ Key behaviors:
|
|
|
305
305
|
re-submitting a known key returns the existing record with `accepted: false`
|
|
306
306
|
instead of starting a second turn. See [Programmatic
|
|
307
307
|
Submissions](./programmatic-submissions.md).
|
|
308
|
-
- **Recovery-safe.**
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
- **Recovery-safe.** The `wait`, `stream`, and drained `submit` paths all run
|
|
309
|
+
inference inside a recovery fiber, so an interrupted turn resumes after
|
|
310
|
+
eviction.
|
|
311
311
|
|
|
312
312
|
`runTurn` is exported alongside its option and result types: `RunTurnOptions`,
|
|
313
313
|
`RunTurnWait`, `RunTurnSubmit`, `RunTurnStream`, `TurnInputMessages`, and
|
|
@@ -390,30 +390,30 @@ path.
|
|
|
390
390
|
|
|
391
391
|
## Configuration Overrides
|
|
392
392
|
|
|
393
|
-
| Method / Property | Default | Description
|
|
394
|
-
| -------------------------- | -------------------------------- |
|
|
395
|
-
| `getModel()` | throws | Return a model id `string` (resolved via the bundled `workers-ai-provider` off `getAIBinding()` — a `@cf/...` id hits Workers AI, a `"provider/model"` slug routes through AI Gateway) or a `LanguageModel`
|
|
396
|
-
| `getAIBinding()` | `this.env.AI` | Workers AI binding used to resolve string models from `getModel()`
|
|
397
|
-
| `getSystemPrompt()` | `"You are a helpful assistant."` | System prompt (fallback when no context blocks)
|
|
398
|
-
| `getTools()` | `{}` | AI SDK `ToolSet` for the agentic loop
|
|
399
|
-
| `getScheduledTasks()` | `{}` | Code-declared recurring prompts or handlers
|
|
400
|
-
| `getDefaultTimezone()` | `undefined` | Default timezone for wall-clock scheduled tasks
|
|
401
|
-
| `getMessengers()` | `{}` | Messenger ingress and delivery declarations — see [Messengers](./messengers.md)
|
|
402
|
-
| `getActions()` | `{}` | Server actions (idempotency, approvals, authorization) compiled into tools — see [Actions](./actions.md)
|
|
403
|
-
| `configureChannels()` | `{}` | Per-channel policy and surfaces beyond the implicit `web` channel — see [Channels](./channels.md)
|
|
404
|
-
| `maxSteps` | `10` | Max tool-call rounds per turn
|
|
405
|
-
| `sendReasoning` | `true` | Send reasoning chunks to chat clients
|
|
406
|
-
| `configureSession()` | identity | Add context blocks, compaction, search, skills — see [Sessions](https://github.com/cloudflare/agents/blob/main/docs/agents/sessions.md)
|
|
407
|
-
| `getSkills()` | `[]` | Return Agent Skills sources for on-demand skill activation
|
|
408
|
-
| `getSkillScriptRunner()` | `null` | Enable the optional `run_skill_script` tool
|
|
409
|
-
| `workspaceBash` | `true` | Include or configure the default workspace `bash` tool
|
|
410
|
-
| `fetchTools` | `false` | Opt-in allowlisted, read-only HTTP fetch tools (`fetch_url` + per-binding `fetch_<name>`). Set to a config object; see [Fetch tool](#fetch-tool)
|
|
411
|
-
| `messageConcurrency` | `"queue"` | How overlapping submits behave — see [Client Tools](./client-tools.md)
|
|
412
|
-
| `includeMcpTools` | `true` | Automatically convert connected MCP tools to AI SDK tools and merge them into model turns
|
|
413
|
-
| `waitForMcpConnections` | `false` | Wait for MCP servers before inference
|
|
414
|
-
| `chatRecovery` |
|
|
415
|
-
| `chatStreamStallTimeoutMs` | `0` (off) | Opt-in inactivity watchdog: abort a turn whose model stream produces no chunk for this long (measures the gap between chunks, including tool execution — set above your slowest model TTFT + tool, e.g. `120_000`). Emits a `chat:stream:stalled` event;
|
|
416
|
-
| `contextOverflow` | `undefined` | Opt-in mid-turn context-overflow handling: `{ reactive?, maxRetries?, proactive? }`. Requires `classifyChatError` + a session compaction function. See [Context-window overflow recovery](#context-window-overflow-recovery).
|
|
393
|
+
| Method / Property | Default | Description |
|
|
394
|
+
| -------------------------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
395
|
+
| `getModel()` | throws | Return a model id `string` (resolved via the bundled `workers-ai-provider` off `getAIBinding()` — a `@cf/...` id hits Workers AI, a `"provider/model"` slug routes through AI Gateway) or a `LanguageModel` |
|
|
396
|
+
| `getAIBinding()` | `this.env.AI` | Workers AI binding used to resolve string models from `getModel()` |
|
|
397
|
+
| `getSystemPrompt()` | `"You are a helpful assistant."` | System prompt (fallback when no context blocks) |
|
|
398
|
+
| `getTools()` | `{}` | AI SDK `ToolSet` for the agentic loop |
|
|
399
|
+
| `getScheduledTasks()` | `{}` | Code-declared recurring prompts or handlers |
|
|
400
|
+
| `getDefaultTimezone()` | `undefined` | Default timezone for wall-clock scheduled tasks |
|
|
401
|
+
| `getMessengers()` | `{}` | Messenger ingress and delivery declarations — see [Messengers](./messengers.md) |
|
|
402
|
+
| `getActions()` | `{}` | Server actions (idempotency, approvals, authorization) compiled into tools — see [Actions](./actions.md) |
|
|
403
|
+
| `configureChannels()` | `{}` | Per-channel policy and surfaces beyond the implicit `web` channel — see [Channels](./channels.md) |
|
|
404
|
+
| `maxSteps` | `10` | Max tool-call rounds per turn |
|
|
405
|
+
| `sendReasoning` | `true` | Send reasoning chunks to chat clients |
|
|
406
|
+
| `configureSession()` | identity | Add context blocks, compaction, search, skills — see [Sessions](https://github.com/cloudflare/agents/blob/main/docs/agents/sessions.md) |
|
|
407
|
+
| `getSkills()` | `[]` | Return Agent Skills sources for on-demand skill activation |
|
|
408
|
+
| `getSkillScriptRunner()` | `null` | Enable the optional `run_skill_script` tool |
|
|
409
|
+
| `workspaceBash` | `true` | Include or configure the default workspace `bash` tool |
|
|
410
|
+
| `fetchTools` | `false` | Opt-in allowlisted, read-only HTTP fetch tools (`fetch_url` + per-binding `fetch_<name>`). Set to a config object; see [Fetch tool](#fetch-tool) |
|
|
411
|
+
| `messageConcurrency` | `"queue"` | How overlapping submits behave — see [Client Tools](./client-tools.md) |
|
|
412
|
+
| `includeMcpTools` | `true` | Automatically convert connected MCP tools to AI SDK tools and merge them into model turns |
|
|
413
|
+
| `waitForMcpConnections` | `false` | Wait for MCP servers before inference |
|
|
414
|
+
| `chatRecovery` | Always on | Durable recovery configuration. See [`ChatRecoveryConfig`](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#stream-recovery) for all options and defaults. |
|
|
415
|
+
| `chatStreamStallTimeoutMs` | `0` (off) | Opt-in inactivity watchdog: abort a turn whose model stream produces no chunk for this long (measures the gap between chunks, including tool execution — set above your slowest model TTFT + tool, e.g. `120_000`). Emits a `chat:stream:stalled` event; the stall routes into bounded recovery (see below) instead of an infinite spinner, and only terminalizes once the budget is exhausted. Override per-turn via `TurnConfig.chatStreamStallTimeoutMs` (returned from `beforeTurn`) for a turn with a known-slow tool. |
|
|
416
|
+
| `contextOverflow` | `undefined` | Opt-in mid-turn context-overflow handling: `{ reactive?, maxRetries?, proactive? }`. Requires `classifyChatError` + a session compaction function. See [Context-window overflow recovery](#context-window-overflow-recovery). |
|
|
417
417
|
|
|
418
418
|
### MCP tools exposed outside the harness
|
|
419
419
|
|
|
@@ -552,9 +552,9 @@ Network access, tools, and workspace writes are opt-in. The default timeout is
|
|
|
552
552
|
|
|
553
553
|
### Chat Recovery
|
|
554
554
|
|
|
555
|
-
Think wraps chat turns in recoverable fibers
|
|
555
|
+
Think always wraps chat turns in recoverable fibers. If the Durable Object is evicted mid-stream, Think reconstructs any buffered chunks, persists partial output, and schedules either a continuation of the assistant turn or a retry of the unanswered user turn. `chatRecovery = false` is no longer supported; assign an object only to tune recovery.
|
|
556
556
|
|
|
557
|
-
A stream-stall watchdog abort (`chatStreamStallTimeoutMs`, above) is treated as just another interruption
|
|
557
|
+
A stream-stall watchdog abort (`chatStreamStallTimeoutMs`, above) is treated as just another interruption and routes into this same bounded path. The settled partial is preserved and a continuation is scheduled, so a transient hang recovers automatically. A persistently hanging provider exhausts the budget and terminalizes through the **same** exhaustion handling as a deploy/eviction interruption: `onExhausted` fires, the `chat:recovery:exhausted` event is emitted, and the configured `terminalMessage` is shown (not a raw stall error).
|
|
558
558
|
|
|
559
559
|
Override `onChatRecovery` when you need provider-specific recovery, such as retrieving a stored OpenAI Responses result instead of issuing a new model call:
|
|
560
560
|
|
package/docs/sub-agents.md
CHANGED
|
@@ -300,14 +300,14 @@ controller.
|
|
|
300
300
|
|
|
301
301
|
Think chat recovery works in sub-agents. The underlying fiber is stored in the sub-agent's own SQLite database, and the top-level parent keeps a small index of active child fibers. When the parent alarm fires, it routes recovery checks into the owning sub-agent, so recovery runs with the sub-agent as `this` even if the child is otherwise idle. Recovered continuations can call `schedule()` inside the sub-agent — the top-level parent owns the physical alarm and routes the continuation back into the child.
|
|
302
302
|
|
|
303
|
-
The external signal lives in memory only. If the Durable Object hibernates mid-turn
|
|
303
|
+
The external signal lives in memory only. If the Durable Object hibernates mid-turn, the recovered turn runs via `continueLastTurn()` **without** the original `options.signal` — the listener was lost on eviction, and the recovery path has no way to reach back to the original caller.
|
|
304
304
|
|
|
305
305
|
In practice this means:
|
|
306
306
|
|
|
307
307
|
- A signal that aborts **after** the DO restarts has no effect on the recovered turn.
|
|
308
308
|
- Subclasses that need the recovered turn to honor a fresh signal should override `onChatRecovery` and reject continuation (`return { continue: false }`) when the original caller is gone.
|
|
309
309
|
- Recovery is best for long-lived chat sub-agents that have their own client reconnect path. Agent tools define a parent-side replay and terminal-state policy for cases where the original parent forwarding loop is gone.
|
|
310
|
-
- If the parent restarts mid-agent-tool run,
|
|
310
|
+
- If the parent restarts mid-agent-tool run, Agent Tools reattaches to the child's durable run, replays stored chunks, and waits for its real terminal result within the configured reattach budget.
|
|
311
311
|
|
|
312
312
|
See [`cloudflare/agents#1406`](https://github.com/cloudflare/agents/issues/1406) for the original motivation, and [Agent Tools](https://github.com/cloudflare/agents/blob/main/docs/agents/agent-tools.md) for the shipped orchestration API.
|
|
313
313
|
|
|
@@ -352,21 +352,9 @@ Both methods produce the same end state as `chat-request-cancel`: inference loop
|
|
|
352
352
|
|
|
353
353
|
## Chat Recovery
|
|
354
354
|
|
|
355
|
-
Think
|
|
355
|
+
Think wraps chat turns in Durable Object fibers for durable execution. When a DO is evicted mid-turn, the turn can be recovered on restart. This works for top-level agents and sub-agents; for sub-agents, the top-level parent alarm drives recovery checks back into the child facet.
|
|
356
356
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
```typescript
|
|
360
|
-
export class MyAgent extends Think<Env> {
|
|
361
|
-
chatRecovery = true;
|
|
362
|
-
|
|
363
|
-
getModel() {
|
|
364
|
-
/* ... */
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
When `chatRecovery` is `true`, every turn entry path is wrapped in `runFiber`: WebSocket chat, sub-agent `chat()` RPC, auto-continuation, `saveMessages()`, `submitMessages()` execution, and `continueLastTurn()`.
|
|
357
|
+
Every turn entry path is wrapped in `runFiber`: WebSocket chat, sub-agent `chat()` RPC, auto-continuation, `saveMessages()`, `submitMessages()` execution, and `continueLastTurn()`. Durable recovery is always enabled; use `chatRecovery` only to tune recovery budgets and terminal behavior.
|
|
370
358
|
|
|
371
359
|
### onChatRecovery
|
|
372
360
|
|
|
@@ -405,8 +393,6 @@ onChatRecovery(ctx: ChatRecoveryContext): ChatRecoveryOptions | void
|
|
|
405
393
|
|
|
406
394
|
```typescript
|
|
407
395
|
export class MyAgent extends Think<Env> {
|
|
408
|
-
chatRecovery = true;
|
|
409
|
-
|
|
410
396
|
getModel() {
|
|
411
397
|
/* ... */
|
|
412
398
|
}
|
|
@@ -449,7 +435,9 @@ onChatRecovery(ctx: ChatRecoveryContext): ChatRecoveryOptions {
|
|
|
449
435
|
|
|
450
436
|
### Recovery budgets and limits
|
|
451
437
|
|
|
452
|
-
|
|
438
|
+
Assign a `chatRecovery` object to tune how long recovery is allowed to run and when it is given up on. A turn that keeps making forward progress survives unbounded interruption — duration is not a bound — as long as it stays under the `maxRecoveryWork` backstop. Recovery is only sealed by one of the limits below.
|
|
439
|
+
|
|
440
|
+
`chatRecovery = false` is no longer supported. If automatic continuation is unsafe, return `{ continue: false }` from `onChatRecovery()`. For cancellation that must survive hibernation, store cancellation intent durably and check it in that hook. See [Controlling automatic continuation](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#controlling-automatic-continuation) for side-effect and cost guidance.
|
|
453
441
|
|
|
454
442
|
```typescript
|
|
455
443
|
export class MyAgent extends Think<Env> {
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"tools"
|
|
10
10
|
],
|
|
11
11
|
"type": "module",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.17.0",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
15
15
|
"directory": "packages/think",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@ai-sdk/react": "^4.0.0",
|
|
34
34
|
"@chat-adapter/telegram": "^4.31.0",
|
|
35
|
-
"@cloudflare/ai-chat": "^0.
|
|
35
|
+
"@cloudflare/ai-chat": "^0.11.0",
|
|
36
36
|
"@testing-library/react": "^16.3.2",
|
|
37
37
|
"@types/react": "^19.2.17",
|
|
38
38
|
"@types/react-dom": "^19.2.3",
|
|
39
39
|
"@vitejs/plugin-react": "^6.0.3",
|
|
40
|
-
"agents": "^0.
|
|
40
|
+
"agents": "^0.22.0",
|
|
41
41
|
"ai": "^7.0.0",
|
|
42
42
|
"jsdom": "^29.1.1",
|
|
43
43
|
"react": "^19.2.7",
|