@cloudflare/think 0.9.0 → 0.9.1

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.
@@ -2411,6 +2411,19 @@ declare class Think<
2411
2411
  */
2412
2412
  protected abortAllRequests(): void;
2413
2413
  private _handleClear;
2414
+ /**
2415
+ * Stamp the allocated assistant id onto a new turn's `start` chunk so a chat
2416
+ * client builds the live-streamed message under the SAME id this agent
2417
+ * persists under. Providers that emit no `start.messageId` (e.g. Workers AI)
2418
+ * otherwise leave the client to generate its own id; the live stream and the
2419
+ * persisted message broadcast then can't reconcile by id, and the originating
2420
+ * tab briefly renders the turn twice before collapsing. Mirrors the fix in
2421
+ * `@cloudflare/ai-chat`. Continuations are skipped — they reuse the existing
2422
+ * assistant message via the `continuation` frame flag, so the id must not
2423
+ * change mid-message. The orphan-recovery path inherits the id from the
2424
+ * stored chunk, so it needs no separate stamping.
2425
+ */
2426
+ private _alignStreamStartId;
2414
2427
  private _streamResultToRpcCallback;
2415
2428
  /**
2416
2429
  * Whether storing this chunk should immediately flush the resumable-stream
@@ -3138,4 +3151,4 @@ export {
3138
3151
  Think as z,
3139
3152
  MessengerReplyStage as zt
3140
3153
  };
3141
- //# sourceMappingURL=think-Cike7VBF.d.ts.map
3154
+ //# sourceMappingURL=think-CwxWGsX1.d.ts.map
package/dist/think.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as TurnContext, A as StepConfig, B as ThinkIntervalSchedule, C as PrepareStepResult, D as Session, E as SaveMessagesResult, F as StreamableResult, G as ThinkSubmissionInspection, H as ThinkScheduledTaskContext, I as SubmitMessagesOptions, J as ThinkWallClockSchedule, K as ThinkSubmissionStatus, L as SubmitMessagesResult, M as StepResult, N as StopCondition, O as SkillRunContext, P as StreamCallback, Q as TurnConfig, R as TextStreamPart, S as PrepareStepFunction, T as SaveMessagesOptions, U as ThinkScheduledTaskSchedule, V as ThinkScheduledTask, W as ThinkScheduledTasks, X as ToolCallDecision, Y as ToolCallContext, Z as ToolCallResultContext, _ as FiberRecoveryContext, a as ChatRecoveryContext, at as defineScheduledTasks, b as OnStartDegradation, c as ChatRecoveryProgressContext, d as ChunkContext, et as TurnInput, f as ChunkPart, g as FiberContext, h as ExtensionConfig, i as ChatRecoveryConfig, it as defaultContextOverflowClassifier, j as StepContext, k as SkillSource, l as ChatResponseResult, m as DeleteSubmissionsOptions, n as ChatErrorContext, nt as TypedToolResult, o as ChatRecoveryExhaustedContext, on as MediaEvictionConfig, ot as skills, p as ContextOverflowConfig, q as ThinkTime, r as ChatOptions, rt as Workspace, s as ChatRecoveryOptions, t as ChatErrorClassification, tt as TypedToolCall, u as ChatStartEvent, v as ListSubmissionsOptions, w as ResolvedChatRecoveryConfig, x as PrepareStepContext, y as MessageConcurrency, z as Think } from "./think-Cike7VBF.js";
1
+ import { $ as TurnContext, A as StepConfig, B as ThinkIntervalSchedule, C as PrepareStepResult, D as Session, E as SaveMessagesResult, F as StreamableResult, G as ThinkSubmissionInspection, H as ThinkScheduledTaskContext, I as SubmitMessagesOptions, J as ThinkWallClockSchedule, K as ThinkSubmissionStatus, L as SubmitMessagesResult, M as StepResult, N as StopCondition, O as SkillRunContext, P as StreamCallback, Q as TurnConfig, R as TextStreamPart, S as PrepareStepFunction, T as SaveMessagesOptions, U as ThinkScheduledTaskSchedule, V as ThinkScheduledTask, W as ThinkScheduledTasks, X as ToolCallDecision, Y as ToolCallContext, Z as ToolCallResultContext, _ as FiberRecoveryContext, a as ChatRecoveryContext, at as defineScheduledTasks, b as OnStartDegradation, c as ChatRecoveryProgressContext, d as ChunkContext, et as TurnInput, f as ChunkPart, g as FiberContext, h as ExtensionConfig, i as ChatRecoveryConfig, it as defaultContextOverflowClassifier, j as StepContext, k as SkillSource, l as ChatResponseResult, m as DeleteSubmissionsOptions, n as ChatErrorContext, nt as TypedToolResult, o as ChatRecoveryExhaustedContext, on as MediaEvictionConfig, ot as skills, p as ContextOverflowConfig, q as ThinkTime, r as ChatOptions, rt as Workspace, s as ChatRecoveryOptions, t as ChatErrorClassification, tt as TypedToolCall, u as ChatStartEvent, v as ListSubmissionsOptions, w as ResolvedChatRecoveryConfig, x as PrepareStepContext, y as MessageConcurrency, z as Think } from "./think-CwxWGsX1.js";
2
2
  import { h as WorkspaceLike } from "./workspace-BZXdZcuw.js";
3
3
  export { ChatErrorClassification, ChatErrorContext, ChatOptions, type ChatRecoveryConfig, type ChatRecoveryContext, type ChatRecoveryExhaustedContext, type ChatRecoveryOptions, type ChatRecoveryProgressContext, type ChatResponseResult, ChatStartEvent, ChunkContext, ChunkPart, ContextOverflowConfig, DeleteSubmissionsOptions, ExtensionConfig, type FiberContext, type FiberRecoveryContext, ListSubmissionsOptions, type MediaEvictionConfig, type MessageConcurrency, OnStartDegradation, PrepareStepContext, type PrepareStepFunction, type PrepareStepResult, type ResolvedChatRecoveryConfig, type SaveMessagesOptions, type SaveMessagesResult, Session, type SkillRunContext, type SkillSource, StepConfig, StepContext, type StepResult, type StopCondition, StreamCallback, StreamableResult, SubmitMessagesOptions, SubmitMessagesResult, type TextStreamPart, Think, ThinkIntervalSchedule, ThinkScheduledTask, ThinkScheduledTaskContext, ThinkScheduledTaskSchedule, ThinkScheduledTasks, ThinkSubmissionInspection, ThinkSubmissionStatus, ThinkTime, ThinkWallClockSchedule, ToolCallContext, ToolCallDecision, ToolCallResultContext, TurnConfig, TurnContext, TurnInput, type TypedToolCall, type TypedToolResult, Workspace, type WorkspaceLike, defaultContextOverflowClassifier, defineScheduledTasks, skills };
package/dist/think.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as defineScheduledTasks, i as defaultContextOverflowClassifier, n as Think, o as skills, r as Workspace, t as Session } from "./think-CK0xW_QY.js";
1
+ import { a as defineScheduledTasks, i as defaultContextOverflowClassifier, n as Think, o as skills, r as Workspace, t as Session } from "./think-2nHHEcY3.js";
2
2
  export { Session, Think, Workspace, defaultContextOverflowClassifier, defineScheduledTasks, skills };
@@ -1,20 +1,48 @@
1
1
  import { ToolSet } from "ai";
2
+ import {
3
+ QuickAction,
4
+ QuickActionBinary,
5
+ QuickActionBinding,
6
+ QuickActionCommonOptions,
7
+ QuickActionExtractInput,
8
+ QuickActionInput,
9
+ QuickActionPage,
10
+ QuickActionScrapeInput,
11
+ QuickActionScrapeResult,
12
+ QuickActionScreenshotInput,
13
+ QuickActionSnapshot,
14
+ browserContent,
15
+ browserExtract,
16
+ browserLinks,
17
+ browserMarkdown,
18
+ browserPdf,
19
+ browserScrape,
20
+ browserScreenshot,
21
+ browserSnapshot,
22
+ runQuickAction
23
+ } from "agents/browser";
2
24
  import {
3
25
  BrowserRuntime,
4
26
  CreateBrowserToolsOptions,
5
- createBrowserRuntime
27
+ CreateQuickActionToolsOptions,
28
+ QuickActionToolName,
29
+ createBrowserRuntime,
30
+ createQuickActionTools
6
31
  } from "agents/browser/ai";
7
32
 
8
33
  //#region src/tools/browser.d.ts
9
34
  /**
10
35
  * Create browser automation tools for Think agents.
11
36
  *
12
- * Returns a `ToolSet` with a single durable `browser_execute` tool backed by
13
- * a codemode runtime: the model writes TypeScript against the `cdp`
14
- * connector (`cdp.send`, `cdp.attachToTarget`, `cdp.spec`, …). Executions
15
- * are recorded for abort-and-replay, and browser sessions are keyed by
16
- * execution — they survive pauses and, in `reuse`/`dynamic` session modes,
17
- * span executions.
37
+ * Returns the durable `browser_execute` tool backed by a codemode runtime —
38
+ * the model writes TypeScript against the `cdp` connector (`cdp.send`,
39
+ * `cdp.attachToTarget`, `cdp.spec`, …); executions are recorded for
40
+ * abort-and-replay, and browser sessions are keyed by execution (they survive
41
+ * pauses and, in `reuse`/`dynamic` modes, span executions) — plus the stateless
42
+ * {@link createQuickActionTools | Quick Action} tools (`browser_markdown`,
43
+ * `browser_extract`, …) by default whenever a `browser` binding is present.
44
+ * Pass `quickActions: false` to omit them, or use `createQuickActionTools`
45
+ * directly for the stateless tools alone (no Worker Loader required).
18
46
  *
19
47
  * Setup checklist:
20
48
  *
@@ -35,7 +63,7 @@ import {
35
63
  *
36
64
  * export class MyAgent extends Think<Env> {
37
65
  * getModel() {
38
- * return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.6");
66
+ * return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.7-code");
39
67
  * }
40
68
  *
41
69
  * getTools() {
@@ -58,7 +86,30 @@ declare function createBrowserTools(
58
86
  export {
59
87
  type BrowserRuntime,
60
88
  type CreateBrowserToolsOptions,
89
+ type CreateQuickActionToolsOptions,
90
+ type QuickAction,
91
+ type QuickActionBinary,
92
+ type QuickActionBinding,
93
+ type QuickActionCommonOptions,
94
+ type QuickActionExtractInput,
95
+ type QuickActionInput,
96
+ type QuickActionPage,
97
+ type QuickActionScrapeInput,
98
+ type QuickActionScrapeResult,
99
+ type QuickActionScreenshotInput,
100
+ type QuickActionSnapshot,
101
+ type QuickActionToolName,
102
+ browserContent,
103
+ browserExtract,
104
+ browserLinks,
105
+ browserMarkdown,
106
+ browserPdf,
107
+ browserScrape,
108
+ browserScreenshot,
109
+ browserSnapshot,
61
110
  createBrowserRuntime,
62
- createBrowserTools
111
+ createBrowserTools,
112
+ createQuickActionTools,
113
+ runQuickAction
63
114
  };
64
115
  //# sourceMappingURL=browser.d.ts.map
@@ -1,14 +1,18 @@
1
- import { createBrowserRuntime, createBrowserTools as createBrowserTools$1 } from "agents/browser/ai";
1
+ import { browserContent, browserExtract, browserLinks, browserMarkdown, browserPdf, browserScrape, browserScreenshot, browserSnapshot, runQuickAction } from "agents/browser";
2
+ import { createBrowserRuntime, createBrowserTools as createBrowserTools$1, createQuickActionTools } from "agents/browser/ai";
2
3
  //#region src/tools/browser.ts
3
4
  /**
4
5
  * Create browser automation tools for Think agents.
5
6
  *
6
- * Returns a `ToolSet` with a single durable `browser_execute` tool backed by
7
- * a codemode runtime: the model writes TypeScript against the `cdp`
8
- * connector (`cdp.send`, `cdp.attachToTarget`, `cdp.spec`, …). Executions
9
- * are recorded for abort-and-replay, and browser sessions are keyed by
10
- * execution — they survive pauses and, in `reuse`/`dynamic` session modes,
11
- * span executions.
7
+ * Returns the durable `browser_execute` tool backed by a codemode runtime —
8
+ * the model writes TypeScript against the `cdp` connector (`cdp.send`,
9
+ * `cdp.attachToTarget`, `cdp.spec`, …); executions are recorded for
10
+ * abort-and-replay, and browser sessions are keyed by execution (they survive
11
+ * pauses and, in `reuse`/`dynamic` modes, span executions) — plus the stateless
12
+ * {@link createQuickActionTools | Quick Action} tools (`browser_markdown`,
13
+ * `browser_extract`, …) by default whenever a `browser` binding is present.
14
+ * Pass `quickActions: false` to omit them, or use `createQuickActionTools`
15
+ * directly for the stateless tools alone (no Worker Loader required).
12
16
  *
13
17
  * Setup checklist:
14
18
  *
@@ -29,7 +33,7 @@ import { createBrowserRuntime, createBrowserTools as createBrowserTools$1 } from
29
33
  *
30
34
  * export class MyAgent extends Think<Env> {
31
35
  * getModel() {
32
- * return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.6");
36
+ * return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.7-code");
33
37
  * }
34
38
  *
35
39
  * getTools() {
@@ -49,6 +53,6 @@ function createBrowserTools(options) {
49
53
  return createBrowserTools$1(options);
50
54
  }
51
55
  //#endregion
52
- export { createBrowserRuntime, createBrowserTools };
56
+ export { browserContent, browserExtract, browserLinks, browserMarkdown, browserPdf, browserScrape, browserScreenshot, browserSnapshot, createBrowserRuntime, createBrowserTools, createQuickActionTools, runQuickAction };
53
57
 
54
58
  //# sourceMappingURL=browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","names":["createBrowserToolsForAi"],"sources":["../../src/tools/browser.ts"],"sourcesContent":["import type { ToolSet } from \"ai\";\nimport {\n createBrowserRuntime,\n createBrowserTools as createBrowserToolsForAi,\n type BrowserRuntime,\n type CreateBrowserToolsOptions\n} from \"agents/browser/ai\";\n\nexport {\n createBrowserRuntime,\n type BrowserRuntime,\n type CreateBrowserToolsOptions\n};\n\n/**\n * Create browser automation tools for Think agents.\n *\n * Returns a `ToolSet` with a single durable `browser_execute` tool backed by\n * a codemode runtime: the model writes TypeScript against the `cdp`\n * connector (`cdp.send`, `cdp.attachToTarget`, `cdp.spec`, …). Executions\n * are recorded for abort-and-replay, and browser sessions are keyed by\n * execution — they survive pauses and, in `reuse`/`dynamic` session modes,\n * span executions.\n *\n * Setup checklist:\n *\n * - `\"browser\": { \"binding\": \"BROWSER\" }` in wrangler.jsonc\n * - `\"worker_loaders\": [{ \"binding\": \"LOADER\" }]` in wrangler.jsonc\n * - export the runtime class from your worker entry:\n * `export { CodemodeRuntime } from \"@cloudflare/codemode\"`\n * (the `@cloudflare/codemode/vite` plugin does this automatically)\n *\n * Use {@link createBrowserRuntime} instead when you also need the runtime\n * handle (approvals, audit, `expirePaused`) or the connector's host-side\n * session helpers (`sessionInfo`, `closeSession`, `sweep`).\n *\n * @example\n * ```ts\n * import { Think } from \"@cloudflare/think\";\n * import { createBrowserTools } from \"@cloudflare/think/tools/browser\";\n *\n * export class MyAgent extends Think<Env> {\n * getModel() {\n * return createWorkersAI({ binding: this.env.AI })(\"@cf/moonshotai/kimi-k2.6\");\n * }\n *\n * getTools() {\n * return {\n * ...createBrowserTools({\n * ctx: this.ctx,\n * browser: this.env.BROWSER,\n * loader: this.env.LOADER,\n * session: { mode: \"dynamic\" }\n * }),\n * };\n * }\n * }\n * ```\n */\nexport function createBrowserTools(\n options: CreateBrowserToolsOptions\n): ToolSet {\n return createBrowserToolsForAi(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,mBACd,SACS;CACT,OAAOA,qBAAwB,OAAO;AACxC"}
1
+ {"version":3,"file":"browser.js","names":["createBrowserToolsForAi"],"sources":["../../src/tools/browser.ts"],"sourcesContent":["import type { ToolSet } from \"ai\";\nimport {\n createBrowserRuntime,\n createBrowserTools as createBrowserToolsForAi,\n createQuickActionTools,\n type BrowserRuntime,\n type CreateBrowserToolsOptions,\n type CreateQuickActionToolsOptions,\n type QuickActionToolName\n} from \"agents/browser/ai\";\n\nexport {\n createBrowserRuntime,\n type BrowserRuntime,\n type CreateBrowserToolsOptions\n};\n\n// Stateless Quick Action tools — re-exported so a Think agent can expose them\n// from `getTools()` with a single import, including the loader-free path\n// (`createQuickActionTools`) that needs only the `browser` binding.\nexport {\n createQuickActionTools,\n type CreateQuickActionToolsOptions,\n type QuickActionToolName\n};\nexport {\n browserContent,\n browserExtract,\n browserLinks,\n browserMarkdown,\n browserPdf,\n browserScrape,\n browserScreenshot,\n browserSnapshot,\n runQuickAction,\n type QuickAction,\n type QuickActionBinary,\n type QuickActionBinding,\n type QuickActionCommonOptions,\n type QuickActionExtractInput,\n type QuickActionInput,\n type QuickActionPage,\n type QuickActionScrapeInput,\n type QuickActionScrapeResult,\n type QuickActionScreenshotInput,\n type QuickActionSnapshot\n} from \"agents/browser\";\n\n/**\n * Create browser automation tools for Think agents.\n *\n * Returns the durable `browser_execute` tool backed by a codemode runtime —\n * the model writes TypeScript against the `cdp` connector (`cdp.send`,\n * `cdp.attachToTarget`, `cdp.spec`, …); executions are recorded for\n * abort-and-replay, and browser sessions are keyed by execution (they survive\n * pauses and, in `reuse`/`dynamic` modes, span executions) — plus the stateless\n * {@link createQuickActionTools | Quick Action} tools (`browser_markdown`,\n * `browser_extract`, …) by default whenever a `browser` binding is present.\n * Pass `quickActions: false` to omit them, or use `createQuickActionTools`\n * directly for the stateless tools alone (no Worker Loader required).\n *\n * Setup checklist:\n *\n * - `\"browser\": { \"binding\": \"BROWSER\" }` in wrangler.jsonc\n * - `\"worker_loaders\": [{ \"binding\": \"LOADER\" }]` in wrangler.jsonc\n * - export the runtime class from your worker entry:\n * `export { CodemodeRuntime } from \"@cloudflare/codemode\"`\n * (the `@cloudflare/codemode/vite` plugin does this automatically)\n *\n * Use {@link createBrowserRuntime} instead when you also need the runtime\n * handle (approvals, audit, `expirePaused`) or the connector's host-side\n * session helpers (`sessionInfo`, `closeSession`, `sweep`).\n *\n * @example\n * ```ts\n * import { Think } from \"@cloudflare/think\";\n * import { createBrowserTools } from \"@cloudflare/think/tools/browser\";\n *\n * export class MyAgent extends Think<Env> {\n * getModel() {\n * return createWorkersAI({ binding: this.env.AI })(\"@cf/moonshotai/kimi-k2.7-code\");\n * }\n *\n * getTools() {\n * return {\n * ...createBrowserTools({\n * ctx: this.ctx,\n * browser: this.env.BROWSER,\n * loader: this.env.LOADER,\n * session: { mode: \"dynamic\" }\n * }),\n * };\n * }\n * }\n * ```\n */\nexport function createBrowserTools(\n options: CreateBrowserToolsOptions\n): ToolSet {\n return createBrowserToolsForAi(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,mBACd,SACS;CACT,OAAOA,qBAAwB,OAAO;AACxC"}
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as readWranglerConfig, c as createThinkWorkerConfig, d as diagnoseThinkWorkerConfig, l as createThinkWorkerDefaults, m as summarizeThinkManifest, o as resolveThinkManifest, p as mergeThinkWorkerConfig, s as watchWranglerConfigFiles, t as applyUserBindingNames } from "./project-D1o1-3dN.js";
2
- import { a as generateThinkRouterModule, i as generateThinkManifestModule, n as generateThinkConfigModule, o as generateThinkServerEntryModule, r as generateThinkEntry, t as generateThinkAgentsModule } from "./codegen-KnFnKp0C.js";
1
+ import { a as readWranglerConfig, c as createThinkWorkerConfig, d as diagnoseThinkWorkerConfig, l as createThinkWorkerDefaults, m as summarizeThinkManifest, o as resolveThinkManifest, p as mergeThinkWorkerConfig, s as watchWranglerConfigFiles, t as applyUserBindingNames } from "./project-BHurFdu4.js";
2
+ import { a as generateThinkRouterModule, i as generateThinkManifestModule, n as generateThinkConfigModule, o as generateThinkServerEntryModule, r as generateThinkEntry, t as generateThinkAgentsModule } from "./codegen-CuPdJRpV.js";
3
3
  import agents from "agents/vite";
4
4
  //#region src/framework/virtual.ts
5
5
  function createVirtualModule(id) {
@@ -1,4 +1,4 @@
1
- import { K as ThinkSubmissionStatus, z as Think } from "./think-Cike7VBF.js";
1
+ import { K as ThinkSubmissionStatus, z as Think } from "./think-CwxWGsX1.js";
2
2
  import { ZodObject, z } from "zod";
3
3
  import { WorkflowEvent, WorkflowSleepDuration } from "cloudflare:workers";
4
4
  import {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "tools"
10
10
  ],
11
11
  "type": "module",
12
- "version": "0.9.0",
12
+ "version": "0.9.1",
13
13
  "license": "MIT",
14
14
  "repository": {
15
15
  "directory": "packages/think",
@@ -24,7 +24,7 @@
24
24
  "think": "dist/cli/index.js"
25
25
  },
26
26
  "dependencies": {
27
- "@cloudflare/codemode": "^0.4.0",
27
+ "@cloudflare/codemode": "^0.4.1",
28
28
  "@cloudflare/shell": "^0.4.0",
29
29
  "aywson": "^0.0.16",
30
30
  "chat": "^4.30.0",