@cloudflare/think 0.10.0 → 0.11.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.
- package/README.md +73 -17
- package/dist/{chat-sdk-Bb93yaZh.js → chat-sdk-D6cUghsQ.js} +33 -8
- package/dist/chat-sdk-D6cUghsQ.js.map +1 -0
- package/dist/cli/index.js +224 -55
- package/dist/cli/index.js.map +1 -1
- package/dist/{codegen-CuPdJRpV.js → codegen-DlA2QQuU.js} +6 -38
- package/dist/codegen-DlA2QQuU.js.map +1 -0
- package/dist/{config-D512sQYg.d.ts → config-CD7hqncK.d.ts} +5 -5
- package/dist/extensions/index.js +1 -1
- package/dist/fetch-By3eIQ-a.d.ts +147 -0
- package/dist/framework/index.d.ts +17 -62
- package/dist/framework/index.js +3 -57
- package/dist/{think-i1Pkgb1R.d.ts → index-CR4-ffm_.d.ts} +1734 -736
- package/dist/{manager-BPndMP_6.js → manager-CSk5htym.js} +7 -7
- package/dist/{manager-BPndMP_6.js.map → manager-CSk5htym.js.map} +1 -1
- package/dist/{manifest-CpB-xngB.d.ts → manifest-DK5HuGga.d.ts} +16 -18
- package/dist/messengers/index.d.ts +59 -55
- package/dist/messengers/index.js +2 -2
- package/dist/messengers/telegram.d.ts +4 -4
- package/dist/messengers/telegram.js +1 -1
- package/dist/react.d.ts +79 -0
- package/dist/react.js +28 -0
- package/dist/react.js.map +1 -0
- package/dist/server-entry.d.ts +1 -1
- package/dist/server-entry.js +1 -1
- package/dist/server-entry.js.map +1 -1
- package/dist/studio/assets/{angular-html-z-TUogET.js → angular-html-D27LthTc.js} +1 -1
- package/dist/studio/assets/{angular-ts-DMGuEVeg.js → angular-ts-DtNL2gQ7.js} +1 -1
- package/dist/studio/assets/{apl-KvrEROqd.js → apl-BgEcDqM0.js} +1 -1
- package/dist/studio/assets/{astro-Bm_woEti.js → astro-CstbRF9e.js} +1 -1
- package/dist/studio/assets/{blade-BdCF3r89.js → blade-CLG-7epG.js} +1 -1
- package/dist/studio/assets/{c-CDqDtkvZ.js → c-CssQqwxO.js} +1 -1
- package/dist/studio/assets/{cobol-CeFM1vZz.js → cobol-CjmzHCjg.js} +1 -1
- package/dist/studio/assets/{coffee-2ed6LBym.js → coffee-B_rqYPkp.js} +1 -1
- package/dist/studio/assets/{cpp-Dj3nX0J4.js → cpp-5YyZJlb7.js} +1 -1
- package/dist/studio/assets/{crystal-BsIYZMQ3.js → crystal-D7uKze0i.js} +1 -1
- package/dist/studio/assets/{css-B48fnuoH.js → css-k9oPgg7G.js} +1 -1
- package/dist/studio/assets/{edge-C7qt1aza.js → edge-CGgsSt0x.js} +1 -1
- package/dist/studio/assets/{elixir-CiTmwoQ3.js → elixir-BX_d5Evo.js} +1 -1
- package/dist/studio/assets/{elm-exDZ-PRY.js → elm-DENxDm5e.js} +1 -1
- package/dist/studio/assets/{erb-3fmfgt-Q.js → erb-DvYOup03.js} +1 -1
- package/dist/studio/assets/{git-rebase-75I-C7zW.js → git-rebase-BsAdTS5A.js} +1 -1
- package/dist/studio/assets/{glimmer-js-JjRzYRv8.js → glimmer-js-e0h98Z67.js} +1 -1
- package/dist/studio/assets/{glimmer-ts-DcC_g6bi.js → glimmer-ts-C9s5Kv8m.js} +1 -1
- package/dist/studio/assets/{glsl-CHo__hpu.js → glsl-CCiyeTRs.js} +1 -1
- package/dist/studio/assets/{graphql-J3cHpSdo.js → graphql-BRtHwsqk.js} +1 -1
- package/dist/studio/assets/{hack-or1FCnPg.js → hack-Dnt0QXHh.js} +1 -1
- package/dist/studio/assets/{haml-uv3vtlo6.js → haml-EXGmzuB1.js} +1 -1
- package/dist/studio/assets/{handlebars--xrOP0sp.js → handlebars-CzyBIDJE.js} +1 -1
- package/dist/studio/assets/{highlighted-body-OFNGDK62-D5UBAw6b.js → highlighted-body-OFNGDK62-CQUFKLNu.js} +1 -1
- package/dist/studio/assets/{html-CWnTqWKh.js → html-BAT8b_VM.js} +1 -1
- package/dist/studio/assets/{html-derivative-DWyLco-z.js → html-derivative-7tkS-r6F.js} +1 -1
- package/dist/studio/assets/{http-BGB8mLqf.js → http-Cgka02Qq.js} +1 -1
- package/dist/studio/assets/{hurl-BWdvIVUG.js → hurl-Cbkh8WEw.js} +1 -1
- package/dist/studio/assets/index-D6n8vpkp.js +390 -0
- package/dist/studio/assets/index-DkGWw6ES.css +2 -0
- package/dist/studio/assets/{java-BqyrPpKF.js → java-DrRKiUno.js} +1 -1
- package/dist/studio/assets/{javascript-D8Aej0xg.js → javascript-9LAnHOxD.js} +1 -1
- package/dist/studio/assets/{jinja-SIORrXov.js → jinja-CqRt4prs.js} +1 -1
- package/dist/studio/assets/{jison-B2T4v51n.js → jison-BX-IOQpJ.js} +1 -1
- package/dist/studio/assets/{json-BFdVRj9r.js → json-dOrE-En8.js} +1 -1
- package/dist/studio/assets/{jsx-w4r1xieS.js → jsx-BSTPfqWX.js} +1 -1
- package/dist/studio/assets/{julia-BFBtDmmM.js → julia-Dvz-BPmf.js} +1 -1
- package/dist/studio/assets/{just-CjAPsU_y.js → just-BHQm0Atq.js} +1 -1
- package/dist/studio/assets/{latex-CghDKqKz.js → latex-CxdhxuXv.js} +1 -1
- package/dist/studio/assets/{liquid-Cp9loVkE.js → liquid-D-hM-Q_F.js} +1 -1
- package/dist/studio/assets/{lua-HNnIDxnY.js → lua-5qtqjLHq.js} +1 -1
- package/dist/studio/assets/{marko-BXT10Apm.js → marko-5FJaM2co.js} +1 -1
- package/dist/studio/assets/{mdc-CaiOz4_A.js → mdc-BhYW7lCG.js} +1 -1
- package/dist/studio/assets/mermaid-GHXKKRXX-CWM2EB-u.js +1 -0
- package/dist/studio/assets/{nginx-DgYZ5SY9.js → nginx-rtAXrRye.js} +1 -1
- package/dist/studio/assets/{nim-CAMVX-MV.js → nim-DQSmaN9U.js} +1 -1
- package/dist/studio/assets/{perl-Dc6Wp7SD.js → perl-B54AdcaE.js} +1 -1
- package/dist/studio/assets/{php-DgLi8LNU.js → php-DpvTxCny.js} +1 -1
- package/dist/studio/assets/{pug-ZHFv4Vgd.js → pug-Cyffw0Ho.js} +1 -1
- package/dist/studio/assets/{qml-DU62cSZp.js → qml-CxRetSkO.js} +1 -1
- package/dist/studio/assets/{r-BwU69RSh.js → r-CXWRxrXc.js} +1 -1
- package/dist/studio/assets/{razor-BUgi_XZM.js → razor-BJzI-zc9.js} +1 -1
- package/dist/studio/assets/{regexp-DuNhqfkW.js → regexp-dqxdfrnE.js} +1 -1
- package/dist/studio/assets/{rst-BB3BeaSy.js → rst-BW7eKYj4.js} +1 -1
- package/dist/studio/assets/{ruby-T0tkEfUZ.js → ruby-D5Npyj8-.js} +1 -1
- package/dist/studio/assets/{sas-CMhZa3S0.js → sas-DZLppjul.js} +1 -1
- package/dist/studio/assets/{scss-DtXjZ3vZ.js → scss-CbqoxyAe.js} +1 -1
- package/dist/studio/assets/{shellscript-BESt-FLs.js → shellscript-CFHqBeXu.js} +1 -1
- package/dist/studio/assets/{shellsession-8irtvYxL.js → shellsession-CbZDA4Bf.js} +1 -1
- package/dist/studio/assets/{soy-CIvhOgLR.js → soy-PImjtV58.js} +1 -1
- package/dist/studio/assets/{sql-obAOXh1G.js → sql-DhGo8urW.js} +1 -1
- package/dist/studio/assets/{stata-D3OCK8xW.js → stata-CjHWbU2v.js} +1 -1
- package/dist/studio/assets/{surrealql-Dk_bguB0.js → surrealql-o8Qr4t56.js} +1 -1
- package/dist/studio/assets/{svelte-C0-KQt-t.js → svelte-DlSIyEV1.js} +1 -1
- package/dist/studio/assets/{templ-lg4nvF9H.js → templ-qizfwU1w.js} +1 -1
- package/dist/studio/assets/{tex-BNcQSX7R.js → tex-Ca7T661H.js} +1 -1
- package/dist/studio/assets/{ts-tags-AgW9jVv0.js → ts-tags-DUmjLkgl.js} +1 -1
- package/dist/studio/assets/{tsx-CL8XyR3d.js → tsx-CfwgIqHW.js} +1 -1
- package/dist/studio/assets/{twig-VkSbsH0Y.js → twig-D7NAYUBY.js} +1 -1
- package/dist/studio/assets/{typescript-BfD1znAG.js → typescript-Bbz9oX-P.js} +1 -1
- package/dist/studio/assets/{vue-html-w3sbjuft.js → vue-html-CcxTb_Jn.js} +1 -1
- package/dist/studio/assets/{vue-gv_2i8Vk.js → vue-vYpz06zQ.js} +1 -1
- package/dist/studio/assets/{vue-vine-C9sgcRlL.js → vue-vine-DW4RqCKF.js} +1 -1
- package/dist/studio/assets/{xml-nNPxMKnG.js → xml-R4LZ_u4f.js} +1 -1
- package/dist/studio/assets/{xsl-C7iHP36x.js → xsl-CS-xzp3L.js} +1 -1
- package/dist/studio/assets/{yaml-Cq3YaG6o.js → yaml-CqDWbYXd.js} +1 -1
- package/dist/studio/index.html +2 -2
- package/dist/think.d.ts +3 -2
- package/dist/think.js +8406 -2
- package/dist/think.js.map +1 -0
- package/dist/tools/extensions.js +1 -1
- package/dist/tools/fetch.d.ts +22 -0
- package/dist/tools/fetch.js +646 -0
- package/dist/tools/fetch.js.map +1 -0
- package/dist/tools/workspace.js +2 -2
- package/dist/tools/workspace.js.map +1 -1
- package/dist/{types-codegen-B6c5KpYH.js → types-codegen-C-9yeFao.js} +9 -33
- package/dist/types-codegen-C-9yeFao.js.map +1 -0
- package/dist/vite.d.ts +5 -5
- package/dist/vite.js +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/actions.md +297 -0
- package/docs/channels.md +185 -0
- package/docs/client-tools.md +233 -0
- package/docs/getting-started.md +314 -0
- package/docs/index.md +1324 -0
- package/docs/lifecycle-hooks.md +850 -0
- package/docs/messengers.md +197 -0
- package/docs/programmatic-submissions.md +206 -0
- package/docs/sub-agents.md +524 -0
- package/docs/tools.md +582 -0
- package/docs/workflows.md +217 -0
- package/package.json +50 -17
- package/dist/chat-sdk-Bb93yaZh.js.map +0 -1
- package/dist/codegen-CuPdJRpV.js.map +0 -1
- package/dist/framework/index.js.map +0 -1
- package/dist/studio/assets/index-Cbb3GlZY.js +0 -496
- package/dist/studio/assets/index-DN9_cL01.css +0 -2
- package/dist/studio/assets/mermaid-GHXKKRXX-I2ZcYo7k.js +0 -1
- package/dist/think-BYZXQ-vm.js +0 -6513
- package/dist/think-BYZXQ-vm.js.map +0 -1
- package/dist/types-codegen-B6c5KpYH.js.map +0 -1
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
D as createWorkspaceTools,
|
|
7
7
|
h as WorkspaceLike
|
|
8
8
|
} from "./workspace-BZXdZcuw.js";
|
|
9
|
+
import { t as CreateFetchToolsOptions } from "./fetch-By3eIQ-a.js";
|
|
9
10
|
import {
|
|
11
|
+
FlexibleSchema,
|
|
12
|
+
InferSchema,
|
|
13
|
+
InferToolOutput,
|
|
10
14
|
LanguageModel,
|
|
11
15
|
ModelMessage,
|
|
12
16
|
PrepareStepFunction,
|
|
@@ -35,6 +39,11 @@ import {
|
|
|
35
39
|
} from "agents/skills";
|
|
36
40
|
import {
|
|
37
41
|
Agent,
|
|
42
|
+
AgentToolLifecycleResult,
|
|
43
|
+
AgentToolMilestone,
|
|
44
|
+
AgentToolProgress,
|
|
45
|
+
AgentToolProgressSnapshot,
|
|
46
|
+
AgentToolRunInfo,
|
|
38
47
|
FiberContext,
|
|
39
48
|
FiberContext as FiberContext$1,
|
|
40
49
|
FiberRecoveryContext,
|
|
@@ -60,6 +69,7 @@ import {
|
|
|
60
69
|
ClientToolSchema,
|
|
61
70
|
MessageConcurrency,
|
|
62
71
|
MessageConcurrency as MessageConcurrency$1,
|
|
72
|
+
OrphanPersistStore,
|
|
63
73
|
ResolvedChatRecoveryConfig,
|
|
64
74
|
ResumableStream,
|
|
65
75
|
SaveMessagesOptions,
|
|
@@ -69,7 +79,9 @@ import {
|
|
|
69
79
|
} from "agents/chat";
|
|
70
80
|
import {
|
|
71
81
|
Session,
|
|
72
|
-
Session as Session$1
|
|
82
|
+
Session as Session$1,
|
|
83
|
+
SessionMessage,
|
|
84
|
+
SessionMessage as SessionMessage$1
|
|
73
85
|
} from "agents/experimental/memory/session";
|
|
74
86
|
import { Workspace as Workspace$1 } from "@cloudflare/shell";
|
|
75
87
|
import {
|
|
@@ -115,500 +127,439 @@ interface MediaEvictionConfig {
|
|
|
115
127
|
maxRowsPerPass?: number;
|
|
116
128
|
}
|
|
117
129
|
//#endregion
|
|
118
|
-
//#region src/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
//#region src/channels/index.d.ts
|
|
131
|
+
/** Surface family for a channel. Drives the default ingress/delivery wiring. */
|
|
132
|
+
type ChannelKind = "messenger" | "web" | "voice" | "custom";
|
|
133
|
+
/** A channel's capabilities are the same shape as a messenger's. */
|
|
134
|
+
type ChannelCapabilities = MessengerCapabilities;
|
|
135
|
+
/** A channel's delivery policy is the same shape as a messenger's. */
|
|
136
|
+
type ChannelDeliveryPolicy = MessengerDeliveryPolicy;
|
|
137
|
+
/** Where a channel posts replies/notices. */
|
|
138
|
+
type ChannelDeliverySurface = MessengerDeliverySurface;
|
|
139
|
+
/**
|
|
140
|
+
* How events arrive for a channel. A discriminated union so `web`/`voice` do
|
|
141
|
+
* not have to invent webhook fields they don't use. The `webhook` transport is
|
|
142
|
+
* exactly today's messenger ingress (a full {@link MessengerDefinition}).
|
|
143
|
+
*/
|
|
144
|
+
type ChannelIngress =
|
|
145
|
+
| ({
|
|
146
|
+
transport: "webhook";
|
|
147
|
+
} & MessengerDefinition)
|
|
148
|
+
| {
|
|
149
|
+
transport: "websocket";
|
|
150
|
+
}
|
|
151
|
+
| {
|
|
152
|
+
transport: "voice";
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Turn-scoped context the runtime sets when a turn resolves to a channel. For
|
|
156
|
+
* `kind: "messenger"` it wraps the existing {@link MessengerContext}.
|
|
157
|
+
*/
|
|
158
|
+
interface ChannelContext {
|
|
159
|
+
channelId: string;
|
|
160
|
+
kind: ChannelKind;
|
|
161
|
+
capabilities?: ChannelCapabilities;
|
|
162
|
+
messenger?: MessengerContext;
|
|
163
|
+
thread?: string;
|
|
131
164
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
165
|
+
/**
|
|
166
|
+
* The public channel contract — the generalization of a messenger: an ingress,
|
|
167
|
+
* a delivery surface, capabilities, conversation routing, a delivery policy, and
|
|
168
|
+
* (new) per-channel policy.
|
|
169
|
+
*/
|
|
170
|
+
interface ChannelDefinition {
|
|
171
|
+
kind: ChannelKind;
|
|
172
|
+
capabilities?: ChannelCapabilities;
|
|
173
|
+
conversation?: MessengerConversationMode | MessengerConversationResolver;
|
|
174
|
+
delivery?: ChannelDeliveryPolicy;
|
|
175
|
+
/** Per-channel instructions, prepended to the system prompt for this channel. */
|
|
176
|
+
instructions?: string | ((ctx: ChannelContext) => string | Promise<string>);
|
|
177
|
+
/** Narrow the assembled tool set for this channel. */
|
|
178
|
+
tools?: (all: ToolSet) => ToolSet;
|
|
179
|
+
/** Per-channel cap on model steps for a turn. */
|
|
180
|
+
maxTurns?: number;
|
|
181
|
+
ingress: ChannelIngress;
|
|
142
182
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
channelName?: string;
|
|
183
|
+
type ThinkChannels = Record<string, ChannelDefinition>;
|
|
184
|
+
type NormalizedChannelDefinition = ChannelDefinition & {
|
|
146
185
|
id: string;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
186
|
+
};
|
|
187
|
+
/** Wrap a {@link MessengerDefinition} as a `kind: "messenger"` channel. */
|
|
188
|
+
declare function messengerChannel(
|
|
189
|
+
definition: MessengerDefinition
|
|
190
|
+
): ChannelDefinition;
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/think.d.ts
|
|
193
|
+
type ChatRecoveryRetryData = {
|
|
194
|
+
targetUserId?: string;
|
|
195
|
+
originalRequestId?: string;
|
|
196
|
+
incidentId?: string;
|
|
197
|
+
lastBody?: Record<string, unknown> | null;
|
|
198
|
+
lastClientTools?: ClientToolSchema[] | null;
|
|
199
|
+
recoveredRequestId?: string;
|
|
200
|
+
};
|
|
201
|
+
type ChatRecoveryContinueData = {
|
|
202
|
+
targetAssistantId?: string;
|
|
203
|
+
originalRequestId?: string;
|
|
204
|
+
incidentId?: string;
|
|
205
|
+
lastBody?: Record<string, unknown> | null;
|
|
206
|
+
lastClientTools?: ClientToolSchema[] | null;
|
|
207
|
+
recoveredRequestId?: string;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* A best-effort internal `onStart` step that failed on this wake and was
|
|
211
|
+
* skipped so the agent could still come up (#1710).
|
|
212
|
+
*
|
|
213
|
+
* - `transcript-hydration` — reading the persisted conversation into the
|
|
214
|
+
* in-memory message cache failed (e.g. `SQLITE_NOMEM` on an oversized,
|
|
215
|
+
* media-heavy transcript). The agent starts with an empty in-memory view;
|
|
216
|
+
* persisted history is untouched and the next safe-boundary sync retries.
|
|
217
|
+
* - `scheduled-task-reconcile` — declarative scheduled tasks were not
|
|
218
|
+
* reconciled on this wake; the next successful wake reconciles them.
|
|
219
|
+
* - `durable-work-recovery` — pending submissions / workflow notifications
|
|
220
|
+
* were not recovered or drained on this wake.
|
|
221
|
+
*/
|
|
222
|
+
interface OnStartDegradation {
|
|
223
|
+
step:
|
|
224
|
+
| "transcript-hydration"
|
|
225
|
+
| "scheduled-task-reconcile"
|
|
226
|
+
| "durable-work-recovery";
|
|
227
|
+
error: unknown;
|
|
150
228
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
text: string;
|
|
229
|
+
/**
|
|
230
|
+
* Callback interface for streaming chat events from a Think sub-agent.
|
|
231
|
+
*
|
|
232
|
+
* Designed to work across the sub-agent RPC boundary — implement as
|
|
233
|
+
* an RpcTarget in the parent agent and pass to `chat()`.
|
|
234
|
+
*/
|
|
235
|
+
interface ChatStartEvent {
|
|
236
|
+
requestId: string;
|
|
160
237
|
}
|
|
161
|
-
interface
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
238
|
+
interface StreamCallback {
|
|
239
|
+
onStart(event: ChatStartEvent): void | Promise<void>;
|
|
240
|
+
onEvent(json: string): void | Promise<void>;
|
|
241
|
+
onDone(): void | Promise<void>;
|
|
242
|
+
onError(error: string): void | Promise<void>;
|
|
243
|
+
/**
|
|
244
|
+
* The current attempt was interrupted (a stream-stall watchdog abort routed
|
|
245
|
+
* into bounded recovery, #1626) and its final outcome will NOT arrive through
|
|
246
|
+
* this callback. One of two things is true:
|
|
247
|
+
* - a scheduled continuation — running in a LATER isolate invocation, without
|
|
248
|
+
* this callback — will produce the answer (delivered to other channels,
|
|
249
|
+
* e.g. WebSocket connections), OR
|
|
250
|
+
* - the recovery budget was exhausted, so the turn was already terminalized
|
|
251
|
+
* out-of-band (the configured `terminalMessage` + `onExhausted`) and is
|
|
252
|
+
* terminally over — there is NO continuation to come.
|
|
253
|
+
*
|
|
254
|
+
* This is NOT `onDone` (this attempt did not complete) and NOT `onError` (the
|
|
255
|
+
* raw stall is not surfaced as a terminal error here); without it the contract
|
|
256
|
+
* `onStart → onEvent* → (onDone | onError)` is silently abandoned and a
|
|
257
|
+
* consumer that treats the clean resolve as success finalizes a truncated
|
|
258
|
+
* partial.
|
|
259
|
+
*
|
|
260
|
+
* Consumers should AVOID finalizing the partial on this signal — surface a
|
|
261
|
+
* "recovering…" / "interrupted, please retry" state, or re-attach via a
|
|
262
|
+
* durable channel — but must ALSO NOT block indefinitely waiting for a
|
|
263
|
+
* continuation: per the exhausted case above, one may never come. Optional →
|
|
264
|
+
* defaults to a no-op, so this is fully backward-compatible.
|
|
265
|
+
*
|
|
266
|
+
* Note: a deploy/eviction interruption kills the isolate (and this callback)
|
|
267
|
+
* before this can fire — the caller observes a transport break instead. This
|
|
268
|
+
* fires only for an in-isolate interruption (the stall→recovery path).
|
|
269
|
+
*/
|
|
270
|
+
onInterrupted?(): void | Promise<void>;
|
|
167
271
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
272
|
+
/**
|
|
273
|
+
* Minimal interface for the result of the inference loop.
|
|
274
|
+
* The AI SDK's `streamText()` result satisfies this interface.
|
|
275
|
+
*/
|
|
276
|
+
interface StreamableResult {
|
|
277
|
+
toUIMessageStream(options?: {
|
|
278
|
+
sendReasoning?: boolean;
|
|
279
|
+
onError?: (error: unknown) => string;
|
|
280
|
+
}): AsyncIterable<unknown>;
|
|
281
|
+
output?: PromiseLike<unknown>;
|
|
175
282
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Options for a chat turn (sub-agent RPC entry point).
|
|
285
|
+
*/
|
|
286
|
+
interface ChatOptions {
|
|
287
|
+
signal?: AbortSignal;
|
|
288
|
+
/**
|
|
289
|
+
* Client-defined tool schemas to expose to the model for this turn, mirroring
|
|
290
|
+
* the `clientTools` carried over the WebSocket chat protocol. Use this when a
|
|
291
|
+
* parent agent delegates to a Think sub-agent over RPC but the sub-agent still
|
|
292
|
+
* needs access to tools the client (or parent) defines at runtime.
|
|
293
|
+
*
|
|
294
|
+
* On their own these are execute-less — the model's call surfaces as a tool
|
|
295
|
+
* call through the stream callback. Provide {@link ChatOptions.onClientToolCall}
|
|
296
|
+
* to also resolve those calls inline so the turn can continue to completion.
|
|
297
|
+
*/
|
|
298
|
+
clientTools?: ClientToolSchema[];
|
|
299
|
+
/**
|
|
300
|
+
* Executes a client tool call and returns its output, completing the
|
|
301
|
+
* round trip for {@link ChatOptions.clientTools} within the same turn.
|
|
302
|
+
*
|
|
303
|
+
* Without this, a client-tool call has no result and the turn ends with a
|
|
304
|
+
* dangling tool call (the RPC stream callback has no inbound result channel).
|
|
305
|
+
* With it, the model can call a client tool, receive the result, and keep
|
|
306
|
+
* going — the same multi-step behavior the WebSocket path gets from
|
|
307
|
+
* `cf_agent_tool_result` messages.
|
|
308
|
+
*/
|
|
309
|
+
onClientToolCall?: ClientToolExecutor;
|
|
310
|
+
/** Channel id this turn belongs to. See {@link RunTurnBase.channel}. */
|
|
311
|
+
channel?: string;
|
|
185
312
|
}
|
|
186
|
-
|
|
187
|
-
|
|
313
|
+
/** Input accepted by {@link Think.runTurn}. */
|
|
314
|
+
type TurnInputMessages =
|
|
315
|
+
| string
|
|
316
|
+
| UIMessage
|
|
317
|
+
| UIMessage[]
|
|
318
|
+
| ((current: UIMessage[]) => UIMessage[] | Promise<UIMessage[]>);
|
|
319
|
+
/** Shared base for {@link RunTurnOptions}; only `input` is common across modes. */
|
|
320
|
+
interface RunTurnBase {
|
|
321
|
+
input?: TurnInputMessages;
|
|
322
|
+
/**
|
|
323
|
+
* Channel id this turn belongs to (resolved against `configureChannels()` /
|
|
324
|
+
* `getMessengers()`). Sets the turn-scoped channel context and is persisted on
|
|
325
|
+
* the user message so a recovered/continued turn re-resolves it. Defaults to
|
|
326
|
+
* the implicit `web` channel.
|
|
327
|
+
*/
|
|
328
|
+
channel?: string;
|
|
188
329
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
declare function toMessengerUserMessage(event: MessengerEvent): UIMessage;
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region src/messengers/delivery.d.ts
|
|
198
|
-
declare const MESSENGER_REPLY_FIBER_NAME = "think:messenger-reply";
|
|
199
|
-
declare const EMPTY_MESSENGER_RESPONSE =
|
|
200
|
-
"I couldn't produce a text response. Please try again.";
|
|
201
|
-
declare const ERROR_MESSENGER_RESPONSE =
|
|
202
|
-
"Sorry, I couldn't answer that right now. Please try again.";
|
|
203
|
-
declare const INTERRUPTED_MESSENGER_RESPONSE =
|
|
204
|
-
"Sorry, my reply was interrupted. Please send your message again if you'd like me to retry.";
|
|
205
|
-
interface TextStreamCallbackOptions {
|
|
206
|
-
onVisibleStart?: () => Promise<void> | void;
|
|
207
|
-
visibleSoftLimit?: number;
|
|
330
|
+
/** Options for {@link Think.runTurn} with `mode: "wait"` (the default). */
|
|
331
|
+
interface RunTurnWait extends RunTurnBase {
|
|
332
|
+
mode?: "wait";
|
|
333
|
+
continuation?: boolean;
|
|
334
|
+
body?: Record<string, unknown>;
|
|
335
|
+
signal?: AbortSignal;
|
|
208
336
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
private closed;
|
|
216
|
-
private interrupted;
|
|
217
|
-
private error?;
|
|
218
|
-
private text;
|
|
219
|
-
private visibleClosed;
|
|
220
|
-
private visibleLimitReachedValue;
|
|
221
|
-
private visibleStarted;
|
|
222
|
-
private visibleTextValue;
|
|
223
|
-
constructor(options?: TextStreamCallbackOptions);
|
|
224
|
-
onStart(event: ChatStartEvent): void;
|
|
225
|
-
onEvent(json: string): void;
|
|
226
|
-
onDone(): void;
|
|
227
|
-
onError(error: string): void;
|
|
228
|
-
onInterrupted(): void;
|
|
229
|
-
wasInterrupted(): boolean;
|
|
230
|
-
close(): void;
|
|
231
|
-
fail(error: unknown): void;
|
|
232
|
-
hasText(): boolean;
|
|
233
|
-
remainingText(): string;
|
|
234
|
-
requestId(): string | undefined;
|
|
235
|
-
textSoFar(): string;
|
|
236
|
-
visibleLimitReached(): boolean;
|
|
237
|
-
visibleText(): string;
|
|
238
|
-
stream(): AsyncIterable<string>;
|
|
239
|
-
private pushVisibleText;
|
|
240
|
-
private wake;
|
|
241
|
-
private markVisibleStarted;
|
|
337
|
+
/** Options for {@link Think.runTurn} with `mode: "submit"`. */
|
|
338
|
+
interface RunTurnSubmit extends RunTurnBase {
|
|
339
|
+
mode: "submit";
|
|
340
|
+
submissionId?: string;
|
|
341
|
+
idempotencyKey?: string;
|
|
342
|
+
metadata?: Record<string, unknown>;
|
|
242
343
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
344
|
+
/** Options for {@link Think.runTurn} with `mode: "stream"`. */
|
|
345
|
+
interface RunTurnStream extends RunTurnBase {
|
|
346
|
+
mode: "stream";
|
|
347
|
+
callback: StreamCallback;
|
|
348
|
+
clientTools?: ClientToolSchema[];
|
|
349
|
+
onClientToolCall?: ClientToolExecutor;
|
|
350
|
+
signal?: AbortSignal;
|
|
250
351
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
post(
|
|
284
|
-
message:
|
|
285
|
-
| string
|
|
286
|
-
| {
|
|
287
|
-
markdown: string;
|
|
288
|
-
}
|
|
289
|
-
| AsyncIterable<string>
|
|
290
|
-
): Promise<unknown>;
|
|
291
|
-
startTyping?(status?: string): Promise<void>;
|
|
292
|
-
}
|
|
293
|
-
interface MessengerDeliveryPolicy {
|
|
294
|
-
emptyResponseText?: string;
|
|
295
|
-
errorResponseText?: string;
|
|
296
|
-
interruptedResponseText?: string;
|
|
297
|
-
isExpectedDeliveryCompletion?(
|
|
298
|
-
error: unknown,
|
|
299
|
-
callback: TextStreamCallback
|
|
300
|
-
): boolean;
|
|
301
|
-
splitText?(text: string): string[];
|
|
302
|
-
visibleSoftLimit?: number;
|
|
303
|
-
}
|
|
304
|
-
interface DeliverMessengerReplyOptions {
|
|
305
|
-
checkpoint?: (snapshot: MessengerReplySnapshot) => Promise<void> | void;
|
|
306
|
-
event: MessengerEvent;
|
|
307
|
-
fiber?: FiberContext;
|
|
308
|
-
policy?: MessengerDeliveryPolicy;
|
|
309
|
-
snapshotEvent?: MessengerEvent;
|
|
310
|
-
snapshotThread?: unknown;
|
|
311
|
-
surface: MessengerDeliverySurface;
|
|
312
|
-
target: MessengerDeliveryTarget;
|
|
313
|
-
userMessage?: UIMessage;
|
|
352
|
+
type RunTurnOptions = RunTurnWait | RunTurnSubmit | RunTurnStream;
|
|
353
|
+
/** Result of {@link Think.runTurn} in `mode: "wait"`. */
|
|
354
|
+
type TurnResult = SaveMessagesResult & {
|
|
355
|
+
message?: SessionMessage;
|
|
356
|
+
continuation: boolean;
|
|
357
|
+
};
|
|
358
|
+
declare const ACTION_BRAND: unique symbol;
|
|
359
|
+
type ActionKind =
|
|
360
|
+
| "server"
|
|
361
|
+
| "client"
|
|
362
|
+
| "approval-gated"
|
|
363
|
+
| "durable-pause"
|
|
364
|
+
| "delegated-agent";
|
|
365
|
+
interface ActionContext {
|
|
366
|
+
/** The agent instance currently executing the action. */
|
|
367
|
+
agent: Think;
|
|
368
|
+
env: Cloudflare.Env;
|
|
369
|
+
/** Current turn request id. */
|
|
370
|
+
requestId: string;
|
|
371
|
+
toolCallId: string;
|
|
372
|
+
/** Model messages visible to the tool call. */
|
|
373
|
+
messages: ReadonlyArray<ModelMessage>;
|
|
374
|
+
/** Combined action timeout and turn abort signal. */
|
|
375
|
+
signal: AbortSignal;
|
|
376
|
+
/**
|
|
377
|
+
* Record an advisory delivery hint for this turn's final reply (voice note,
|
|
378
|
+
* card, email draft, ...). Does not change the model-visible tool output.
|
|
379
|
+
* No-op for approval/permission/idempotency policy evaluation and for
|
|
380
|
+
* durable-pause approved-action resumes (their reply is delivered by a
|
|
381
|
+
* later continuation turn in v1).
|
|
382
|
+
*/
|
|
383
|
+
attachReply(attachment: ReplyAttachment): void;
|
|
314
384
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
type
|
|
322
|
-
| "action"
|
|
323
|
-
| "direct-message"
|
|
324
|
-
| "mention"
|
|
325
|
-
| "subscribed-thread";
|
|
326
|
-
type MessengerConversationMode = "self" | "thread";
|
|
327
|
-
type MessengerConversationTarget =
|
|
385
|
+
/**
|
|
386
|
+
* The attachment shape accepted by {@link ActionContext.attachReply}. An open
|
|
387
|
+
* union: the named variants give autocomplete for common channels, and the
|
|
388
|
+
* trailing `{ type: string; [k]: unknown }` keeps it extensible. Advisory only
|
|
389
|
+
* — surfaces that don't recognize a `type` ignore it.
|
|
390
|
+
*/
|
|
391
|
+
type ReplyAttachment =
|
|
328
392
|
| {
|
|
329
|
-
|
|
393
|
+
type: "voice_note";
|
|
330
394
|
}
|
|
331
395
|
| {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
396
|
+
type: "email_draft";
|
|
397
|
+
subject?: string;
|
|
398
|
+
to?: string[];
|
|
399
|
+
}
|
|
400
|
+
| {
|
|
401
|
+
type: "card";
|
|
402
|
+
payload: unknown;
|
|
403
|
+
}
|
|
404
|
+
| {
|
|
405
|
+
type: string;
|
|
406
|
+
[k: string]: unknown;
|
|
335
407
|
};
|
|
336
|
-
type
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
408
|
+
type ActionApprovalPolicy<Input> =
|
|
409
|
+
| boolean
|
|
410
|
+
| ((args: {
|
|
411
|
+
input: Input;
|
|
412
|
+
ctx: ActionContext;
|
|
413
|
+
}) => boolean | Promise<boolean>);
|
|
414
|
+
type ActionPermissionSpec<Input> =
|
|
415
|
+
| readonly string[]
|
|
416
|
+
| ((args: {
|
|
417
|
+
input: Input;
|
|
418
|
+
ctx: ActionContext;
|
|
419
|
+
}) => readonly string[] | Promise<readonly string[]>);
|
|
420
|
+
type ActionIdempotencyKey<Input> =
|
|
421
|
+
| string
|
|
422
|
+
| ((args: { input: Input; ctx: ActionContext }) => string | Promise<string>);
|
|
423
|
+
type ActionAuthorizationDecision =
|
|
424
|
+
| boolean
|
|
425
|
+
| {
|
|
426
|
+
allowed: boolean;
|
|
427
|
+
reason?: string;
|
|
428
|
+
grantedPermissions?: readonly string[];
|
|
429
|
+
};
|
|
430
|
+
interface ActionAuthorizationContext {
|
|
431
|
+
requestId: string;
|
|
432
|
+
toolCallId: string;
|
|
433
|
+
action: string;
|
|
434
|
+
kind: ActionKind;
|
|
435
|
+
input: unknown;
|
|
436
|
+
requiredPermissions: readonly string[];
|
|
437
|
+
grantedPermissions?: readonly string[];
|
|
438
|
+
messages: ReadonlyArray<ModelMessage>;
|
|
439
|
+
agent: Think;
|
|
440
|
+
env: Cloudflare.Env;
|
|
368
441
|
}
|
|
369
|
-
interface
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
442
|
+
interface ActionApprovalDescriptor {
|
|
443
|
+
requestId: string;
|
|
444
|
+
toolCallId: string;
|
|
445
|
+
action: string;
|
|
446
|
+
summary: string;
|
|
447
|
+
input: unknown;
|
|
448
|
+
permissions: string[];
|
|
449
|
+
risk?: "low" | "medium" | "high";
|
|
450
|
+
kind: "approval-gated" | "durable-pause";
|
|
374
451
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
452
|
+
/**
|
|
453
|
+
* A single approval awaiting a human decision, unified across pause backends so
|
|
454
|
+
* dashboards/voice/messenger can list and reconcile everything pending with one
|
|
455
|
+
* call. `source: "action"` is a parked `kind: "durable-pause"` action;
|
|
456
|
+
* `source: "codemode"` is a paused `execute`-tool execution. Both resolve via
|
|
457
|
+
* {@link Think.approveExecution} / {@link Think.rejectExecution}.
|
|
458
|
+
*/
|
|
459
|
+
interface PendingApproval {
|
|
460
|
+
executionId: string;
|
|
461
|
+
source: "action" | "codemode";
|
|
462
|
+
descriptor: ActionApprovalDescriptor;
|
|
381
463
|
}
|
|
382
|
-
interface
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
464
|
+
interface ActionConfig<
|
|
465
|
+
InputSchema extends FlexibleSchema = FlexibleSchema,
|
|
466
|
+
Output = unknown
|
|
467
|
+
> {
|
|
468
|
+
/** Defaults to the registration key when returned from getActions(). */
|
|
469
|
+
name?: string;
|
|
470
|
+
description: string;
|
|
471
|
+
inputSchema: InputSchema;
|
|
472
|
+
/** Reserved metadata; output validation is not enforced yet. */
|
|
473
|
+
outputSchema?: FlexibleSchema<Output>;
|
|
474
|
+
/**
|
|
475
|
+
* Stable key used to replay settled action results without re-running side
|
|
476
|
+
* effects. Use domain identifiers that survive recovery retries (for example,
|
|
477
|
+
* an order id or inbound event id); avoid request ids, timestamps, and random
|
|
478
|
+
* values.
|
|
479
|
+
*/
|
|
480
|
+
idempotencyKey?: ActionIdempotencyKey<InferSchema<InputSchema>>;
|
|
481
|
+
permissions?: ActionPermissionSpec<InferSchema<InputSchema>>;
|
|
482
|
+
approval?: ActionApprovalPolicy<InferSchema<InputSchema>>;
|
|
483
|
+
approvalSummary?: string;
|
|
484
|
+
approvalRisk?: "low" | "medium" | "high";
|
|
485
|
+
timeoutMs?: number;
|
|
486
|
+
kind?: ActionKind;
|
|
487
|
+
execute(
|
|
488
|
+
input: InferSchema<InputSchema>,
|
|
489
|
+
ctx: ActionContext
|
|
490
|
+
): Promise<Output> | Output;
|
|
396
491
|
}
|
|
397
|
-
interface
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
className: string;
|
|
404
|
-
name: string;
|
|
405
|
-
}>;
|
|
406
|
-
startFiber(
|
|
407
|
-
name: string,
|
|
408
|
-
fn: (ctx: FiberContext) => Promise<void>,
|
|
409
|
-
options?: StartFiberOptions
|
|
410
|
-
): Promise<MessengerFiberStartResult>;
|
|
411
|
-
resolveFiber(id: string, result: FiberRecoveryResult): Promise<boolean>;
|
|
412
|
-
subAgent<T extends Agent>(
|
|
413
|
-
agentClass: SubAgentClass<T>,
|
|
414
|
-
name: string
|
|
415
|
-
): Promise<SubAgentStub<T>>;
|
|
492
|
+
interface Action<
|
|
493
|
+
InputSchema extends FlexibleSchema = FlexibleSchema,
|
|
494
|
+
Output = unknown
|
|
495
|
+
> {
|
|
496
|
+
readonly [ACTION_BRAND]: true;
|
|
497
|
+
readonly config: ActionConfig<InputSchema, Output>;
|
|
416
498
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
499
|
+
declare function action<
|
|
500
|
+
const InputSchema extends FlexibleSchema,
|
|
501
|
+
Output = unknown
|
|
502
|
+
>(config: ActionConfig<InputSchema, Output>): Action<InputSchema, Output>;
|
|
503
|
+
declare function isAction(value: unknown): value is Action;
|
|
504
|
+
type TurnTrigger =
|
|
505
|
+
| "ws-chat"
|
|
506
|
+
| "rpc"
|
|
507
|
+
| "programmatic"
|
|
508
|
+
| "submission"
|
|
509
|
+
| "scheduled"
|
|
510
|
+
| "agent-tool"
|
|
511
|
+
| "auto-continuation"
|
|
512
|
+
| "recovery-continue"
|
|
513
|
+
| "recovery-retry";
|
|
514
|
+
/** Options for {@link Think.addMessages}. */
|
|
515
|
+
interface AddMessagesOptions {
|
|
516
|
+
/**
|
|
517
|
+
* Parent to attach the first message under. Omitted (`undefined`) attaches to
|
|
518
|
+
* the latest committed leaf at call time; `null` attaches at the root. An
|
|
519
|
+
* explicit id that does not exist throws (fail fast rather than silently
|
|
520
|
+
* misattaching). Subsequent messages in an array chain under the previous one.
|
|
521
|
+
*/
|
|
522
|
+
parentId?: string | null;
|
|
523
|
+
/**
|
|
524
|
+
* `"append"` (default) inserts new rows, idempotent by message id.
|
|
525
|
+
* `"upsert"` inserts, or updates in place when the id already exists (in which
|
|
526
|
+
* case `parentId` is ignored — re-parenting is not supported).
|
|
527
|
+
*
|
|
528
|
+
* Idempotency is by id against the whole session tree, not just the target
|
|
529
|
+
* path: if a message id already exists *anywhere* in history, `"append"` is a
|
|
530
|
+
* no-op for it (no new row, no re-parent) and `"upsert"` updates it in place
|
|
531
|
+
* wherever it lives. In both modes the next message in the array chains under
|
|
532
|
+
* that existing id, so passing already-present ids mid-array threads new
|
|
533
|
+
* messages onto the existing branch rather than forking a new one.
|
|
534
|
+
*/
|
|
535
|
+
mode?: "append" | "upsert";
|
|
536
|
+
/**
|
|
537
|
+
* Broadcast the change to connected clients. Default `true`. Has no effect
|
|
538
|
+
* when called from inside an active turn (e.g. a tool `execute`), where the
|
|
539
|
+
* live view is intentionally not touched until the next turn's sync.
|
|
540
|
+
*/
|
|
541
|
+
broadcast?: boolean;
|
|
422
542
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
private definitionForThreadId;
|
|
444
|
-
private hasUniqueProvider;
|
|
445
|
-
private shardThread;
|
|
446
|
-
private shardStateKey;
|
|
447
|
-
private reviveChatObject;
|
|
448
|
-
private toEvent;
|
|
449
|
-
}
|
|
450
|
-
declare function normalizeMessengers(
|
|
451
|
-
messengers: ThinkMessengers
|
|
452
|
-
): NormalizedMessengerDefinition[];
|
|
453
|
-
declare function defaultConversationName(event: MessengerEvent): string;
|
|
454
|
-
declare function idempotencyKeyForEvent(event: MessengerEvent): string;
|
|
455
|
-
declare function defaultChatSdkEvent(
|
|
456
|
-
definition: NormalizedMessengerDefinition,
|
|
457
|
-
input: ChatSdkMessengerEventInput
|
|
458
|
-
): MessengerEvent;
|
|
459
|
-
declare function toMessengerThread(thread: Thread): MessengerThread;
|
|
460
|
-
declare function toMessengerMessage(message: Message): MessengerMessage;
|
|
461
|
-
declare function toMessengerAuthor(author: Author): MessengerAuthor;
|
|
462
|
-
declare function toMessengerAttachment(
|
|
463
|
-
attachment: Attachment
|
|
464
|
-
): MessengerAttachment;
|
|
465
|
-
//#endregion
|
|
466
|
-
//#region src/think.d.ts
|
|
467
|
-
type ChatRecoveryRetryData = {
|
|
468
|
-
targetUserId?: string;
|
|
469
|
-
originalRequestId?: string;
|
|
470
|
-
incidentId?: string;
|
|
471
|
-
lastBody?: Record<string, unknown> | null;
|
|
472
|
-
lastClientTools?: ClientToolSchema[] | null;
|
|
473
|
-
recoveredRequestId?: string;
|
|
474
|
-
};
|
|
475
|
-
type ChatRecoveryContinueData = {
|
|
476
|
-
targetAssistantId?: string;
|
|
477
|
-
originalRequestId?: string;
|
|
478
|
-
incidentId?: string;
|
|
479
|
-
lastBody?: Record<string, unknown> | null;
|
|
480
|
-
lastClientTools?: ClientToolSchema[] | null;
|
|
481
|
-
recoveredRequestId?: string;
|
|
482
|
-
};
|
|
483
|
-
/**
|
|
484
|
-
* A best-effort internal `onStart` step that failed on this wake and was
|
|
485
|
-
* skipped so the agent could still come up (#1710).
|
|
486
|
-
*
|
|
487
|
-
* - `transcript-hydration` — reading the persisted conversation into the
|
|
488
|
-
* in-memory message cache failed (e.g. `SQLITE_NOMEM` on an oversized,
|
|
489
|
-
* media-heavy transcript). The agent starts with an empty in-memory view;
|
|
490
|
-
* persisted history is untouched and the next safe-boundary sync retries.
|
|
491
|
-
* - `scheduled-task-reconcile` — declarative scheduled tasks were not
|
|
492
|
-
* reconciled on this wake; the next successful wake reconciles them.
|
|
493
|
-
* - `durable-work-recovery` — pending submissions / workflow notifications
|
|
494
|
-
* were not recovered or drained on this wake.
|
|
495
|
-
*/
|
|
496
|
-
interface OnStartDegradation {
|
|
497
|
-
step:
|
|
498
|
-
| "transcript-hydration"
|
|
499
|
-
| "scheduled-task-reconcile"
|
|
500
|
-
| "durable-work-recovery";
|
|
501
|
-
error: unknown;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Callback interface for streaming chat events from a Think sub-agent.
|
|
505
|
-
*
|
|
506
|
-
* Designed to work across the sub-agent RPC boundary — implement as
|
|
507
|
-
* an RpcTarget in the parent agent and pass to `chat()`.
|
|
508
|
-
*/
|
|
509
|
-
interface ChatStartEvent {
|
|
510
|
-
requestId: string;
|
|
511
|
-
}
|
|
512
|
-
interface StreamCallback {
|
|
513
|
-
onStart(event: ChatStartEvent): void | Promise<void>;
|
|
514
|
-
onEvent(json: string): void | Promise<void>;
|
|
515
|
-
onDone(): void | Promise<void>;
|
|
516
|
-
onError(error: string): void | Promise<void>;
|
|
517
|
-
/**
|
|
518
|
-
* The current attempt was interrupted (a stream-stall watchdog abort routed
|
|
519
|
-
* into bounded recovery, #1626) and its final outcome will NOT arrive through
|
|
520
|
-
* this callback. One of two things is true:
|
|
521
|
-
* - a scheduled continuation — running in a LATER isolate invocation, without
|
|
522
|
-
* this callback — will produce the answer (delivered to other channels,
|
|
523
|
-
* e.g. WebSocket connections), OR
|
|
524
|
-
* - the recovery budget was exhausted, so the turn was already terminalized
|
|
525
|
-
* out-of-band (the configured `terminalMessage` + `onExhausted`) and is
|
|
526
|
-
* terminally over — there is NO continuation to come.
|
|
527
|
-
*
|
|
528
|
-
* This is NOT `onDone` (this attempt did not complete) and NOT `onError` (the
|
|
529
|
-
* raw stall is not surfaced as a terminal error here); without it the contract
|
|
530
|
-
* `onStart → onEvent* → (onDone | onError)` is silently abandoned and a
|
|
531
|
-
* consumer that treats the clean resolve as success finalizes a truncated
|
|
532
|
-
* partial.
|
|
533
|
-
*
|
|
534
|
-
* Consumers should AVOID finalizing the partial on this signal — surface a
|
|
535
|
-
* "recovering…" / "interrupted, please retry" state, or re-attach via a
|
|
536
|
-
* durable channel — but must ALSO NOT block indefinitely waiting for a
|
|
537
|
-
* continuation: per the exhausted case above, one may never come. Optional →
|
|
538
|
-
* defaults to a no-op, so this is fully backward-compatible.
|
|
539
|
-
*
|
|
540
|
-
* Note: a deploy/eviction interruption kills the isolate (and this callback)
|
|
541
|
-
* before this can fire — the caller observes a transport break instead. This
|
|
542
|
-
* fires only for an in-isolate interruption (the stall→recovery path).
|
|
543
|
-
*/
|
|
544
|
-
onInterrupted?(): void | Promise<void>;
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Minimal interface for the result of the inference loop.
|
|
548
|
-
* The AI SDK's `streamText()` result satisfies this interface.
|
|
549
|
-
*/
|
|
550
|
-
interface StreamableResult {
|
|
551
|
-
toUIMessageStream(options?: {
|
|
552
|
-
sendReasoning?: boolean;
|
|
553
|
-
}): AsyncIterable<unknown>;
|
|
554
|
-
output?: PromiseLike<unknown>;
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* Options for a chat turn (sub-agent RPC entry point).
|
|
558
|
-
*/
|
|
559
|
-
interface ChatOptions {
|
|
560
|
-
signal?: AbortSignal;
|
|
561
|
-
/**
|
|
562
|
-
* Client-defined tool schemas to expose to the model for this turn, mirroring
|
|
563
|
-
* the `clientTools` carried over the WebSocket chat protocol. Use this when a
|
|
564
|
-
* parent agent delegates to a Think sub-agent over RPC but the sub-agent still
|
|
565
|
-
* needs access to tools the client (or parent) defines at runtime.
|
|
566
|
-
*
|
|
567
|
-
* On their own these are execute-less — the model's call surfaces as a tool
|
|
568
|
-
* call through the stream callback. Provide {@link ChatOptions.onClientToolCall}
|
|
569
|
-
* to also resolve those calls inline so the turn can continue to completion.
|
|
570
|
-
*/
|
|
571
|
-
clientTools?: ClientToolSchema[];
|
|
572
|
-
/**
|
|
573
|
-
* Executes a client tool call and returns its output, completing the
|
|
574
|
-
* round trip for {@link ChatOptions.clientTools} within the same turn.
|
|
575
|
-
*
|
|
576
|
-
* Without this, a client-tool call has no result and the turn ends with a
|
|
577
|
-
* dangling tool call (the RPC stream callback has no inbound result channel).
|
|
578
|
-
* With it, the model can call a client tool, receive the result, and keep
|
|
579
|
-
* going — the same multi-step behavior the WebSocket path gets from
|
|
580
|
-
* `cf_agent_tool_result` messages.
|
|
581
|
-
*/
|
|
582
|
-
onClientToolCall?: ClientToolExecutor;
|
|
583
|
-
}
|
|
584
|
-
/** Options for {@link Think.addMessages}. */
|
|
585
|
-
interface AddMessagesOptions {
|
|
586
|
-
/**
|
|
587
|
-
* Parent to attach the first message under. Omitted (`undefined`) attaches to
|
|
588
|
-
* the latest committed leaf at call time; `null` attaches at the root. An
|
|
589
|
-
* explicit id that does not exist throws (fail fast rather than silently
|
|
590
|
-
* misattaching). Subsequent messages in an array chain under the previous one.
|
|
591
|
-
*/
|
|
592
|
-
parentId?: string | null;
|
|
593
|
-
/**
|
|
594
|
-
* `"append"` (default) inserts new rows, idempotent by message id.
|
|
595
|
-
* `"upsert"` inserts, or updates in place when the id already exists (in which
|
|
596
|
-
* case `parentId` is ignored — re-parenting is not supported).
|
|
597
|
-
*
|
|
598
|
-
* Idempotency is by id against the whole session tree, not just the target
|
|
599
|
-
* path: if a message id already exists *anywhere* in history, `"append"` is a
|
|
600
|
-
* no-op for it (no new row, no re-parent) and `"upsert"` updates it in place
|
|
601
|
-
* wherever it lives. In both modes the next message in the array chains under
|
|
602
|
-
* that existing id, so passing already-present ids mid-array threads new
|
|
603
|
-
* messages onto the existing branch rather than forking a new one.
|
|
604
|
-
*/
|
|
605
|
-
mode?: "append" | "upsert";
|
|
606
|
-
/**
|
|
607
|
-
* Broadcast the change to connected clients. Default `true`. Has no effect
|
|
608
|
-
* when called from inside an active turn (e.g. a tool `execute`), where the
|
|
609
|
-
* live view is intentionally not touched until the next turn's sync.
|
|
610
|
-
*/
|
|
611
|
-
broadcast?: boolean;
|
|
543
|
+
/** Options for {@link Think.deliverNotice}. */
|
|
544
|
+
interface DeliverNoticeOptions {
|
|
545
|
+
/**
|
|
546
|
+
* Target channel id. Defaults to the active turn's channel, else `"web"`.
|
|
547
|
+
*/
|
|
548
|
+
channel?: string;
|
|
549
|
+
/**
|
|
550
|
+
* Also record the notice in the model-visible transcript so the next turn
|
|
551
|
+
* knows it was said. Default `false`. For the `web` channel the note is always
|
|
552
|
+
* appended to the transcript (its only render path); `informModel` then only
|
|
553
|
+
* controls the phrasing.
|
|
554
|
+
*/
|
|
555
|
+
informModel?: boolean;
|
|
556
|
+
/** Delivery kind for the wire tag. Default `"notice"`. */
|
|
557
|
+
kind?: DeliveryKind;
|
|
558
|
+
/**
|
|
559
|
+
* Conversation/thread hint, required for out-of-turn delivery to a
|
|
560
|
+
* multi-thread messenger channel.
|
|
561
|
+
*/
|
|
562
|
+
thread?: string;
|
|
612
563
|
}
|
|
613
564
|
type AgentToolChildRunStatus =
|
|
614
565
|
| "starting"
|
|
@@ -626,6 +577,7 @@ type AgentToolRunInspection<Output = unknown> = {
|
|
|
626
577
|
error?: string;
|
|
627
578
|
startedAt: number;
|
|
628
579
|
completedAt?: number;
|
|
580
|
+
progress?: AgentToolProgressSnapshot;
|
|
629
581
|
};
|
|
630
582
|
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
631
583
|
type Hour = `0${Digit}` | `1${Digit}` | "20" | "21" | "22" | "23";
|
|
@@ -682,9 +634,11 @@ type ThinkScheduledTask =
|
|
|
682
634
|
timezone?: string;
|
|
683
635
|
});
|
|
684
636
|
type ThinkScheduledTasks = Record<string, ThinkScheduledTask>;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
637
|
+
type ActionLedgerRetentionConfig = {
|
|
638
|
+
settledMs: number | false;
|
|
639
|
+
pendingMs: number | false;
|
|
640
|
+
maxSweepRows: number;
|
|
641
|
+
};
|
|
688
642
|
type DeclaredScheduledTaskPayload = {
|
|
689
643
|
taskId: string;
|
|
690
644
|
scheduleHash: string;
|
|
@@ -704,7 +658,11 @@ type ThinkSubmissionStatus =
|
|
|
704
658
|
type SubmitMessagesOptions = {
|
|
705
659
|
submissionId?: string;
|
|
706
660
|
idempotencyKey?: string;
|
|
707
|
-
metadata?: Record<
|
|
661
|
+
metadata?: Record<
|
|
662
|
+
string,
|
|
663
|
+
unknown
|
|
664
|
+
> /** Channel id this submission belongs to. See {@link RunTurnBase.channel}. */;
|
|
665
|
+
channel?: string;
|
|
708
666
|
};
|
|
709
667
|
type ThinkWorkflowPromptContext = {
|
|
710
668
|
workflow: {
|
|
@@ -1031,7 +989,9 @@ type StepConfig<TOOLS extends ToolSet = ToolSet> = PrepareStepResult<TOOLS>;
|
|
|
1031
989
|
* - `messages` — conversation messages visible at tool execution time
|
|
1032
990
|
* - `abortSignal` — signal that aborts if the turn is cancelled
|
|
1033
991
|
*
|
|
1034
|
-
* Pass an explicit `TOOLS` generic for full input typing
|
|
992
|
+
* Pass an explicit `TOOLS` generic for full input typing. With a concrete
|
|
993
|
+
* tool set, narrowing on `ctx.toolName` narrows `ctx.input` to that tool's
|
|
994
|
+
* input shape:
|
|
1035
995
|
*
|
|
1036
996
|
* ```ts
|
|
1037
997
|
* import type { ToolCallContext } from "@cloudflare/think";
|
|
@@ -1039,18 +999,43 @@ type StepConfig<TOOLS extends ToolSet = ToolSet> = PrepareStepResult<TOOLS>;
|
|
|
1039
999
|
*
|
|
1040
1000
|
* beforeToolCall(ctx: ToolCallContext<typeof tools>) {
|
|
1041
1001
|
* if (ctx.toolName === "search") {
|
|
1042
|
-
* ctx.input.query; // typed
|
|
1002
|
+
* ctx.input.query; // typed as string
|
|
1043
1003
|
* }
|
|
1044
1004
|
* }
|
|
1045
1005
|
* ```
|
|
1046
1006
|
*/
|
|
1047
|
-
type ToolCallContext<TOOLS extends ToolSet = ToolSet> =
|
|
1007
|
+
type ToolCallContext<TOOLS extends ToolSet = ToolSet> = PerToolCall<TOOLS> &
|
|
1008
|
+
ToolCallContextExtras;
|
|
1009
|
+
/** Per-call event extras attached to every {@link ToolCallContext}. */
|
|
1010
|
+
type ToolCallContextExtras = {
|
|
1048
1011
|
/** Zero-based index of the current step where this tool call occurs. */ readonly stepNumber:
|
|
1049
1012
|
| number
|
|
1050
1013
|
| undefined /** The conversation messages available at tool execution time. */;
|
|
1051
1014
|
readonly messages: ReadonlyArray<ModelMessage> /** Signal for cancelling the operation. */;
|
|
1052
1015
|
readonly abortSignal: AbortSignal | undefined;
|
|
1053
1016
|
};
|
|
1017
|
+
/**
|
|
1018
|
+
* The `TypedToolCall<TOOLS>` union, re-keyed so that discriminating on
|
|
1019
|
+
* `toolName` narrows `input` per tool.
|
|
1020
|
+
*
|
|
1021
|
+
* The AI SDK's `TypedToolCall` includes a `DynamicToolCall` arm whose
|
|
1022
|
+
* `toolName: string` / `input: unknown` overlaps every static tool name —
|
|
1023
|
+
* leaving it in the union collapses `ctx.input` to `unknown` even after a
|
|
1024
|
+
* `toolName` check. When an explicit `TOOLS` generic is passed (so the keys
|
|
1025
|
+
* are a literal union), we distribute over those keys and drop the dynamic
|
|
1026
|
+
* arm so narrowing works. With the default `ToolSet` (keys are `string`) we
|
|
1027
|
+
* fall back to the raw union, preserving the prior loose behavior.
|
|
1028
|
+
*/
|
|
1029
|
+
type PerToolCall<TOOLS extends ToolSet> = string extends keyof TOOLS
|
|
1030
|
+
? TypedToolCall<TOOLS>
|
|
1031
|
+
: {
|
|
1032
|
+
[K in keyof TOOLS]: Extract<
|
|
1033
|
+
TypedToolCall<TOOLS>,
|
|
1034
|
+
{
|
|
1035
|
+
toolName: K;
|
|
1036
|
+
}
|
|
1037
|
+
>;
|
|
1038
|
+
}[keyof TOOLS];
|
|
1054
1039
|
/**
|
|
1055
1040
|
* Decision returned by `beforeToolCall` to control tool execution.
|
|
1056
1041
|
* Return void/undefined to allow execution with original input.
|
|
@@ -1086,41 +1071,58 @@ type ToolCallDecision =
|
|
|
1086
1071
|
* - `messages` — conversation messages visible at tool execution time
|
|
1087
1072
|
* - `durationMs` — wall-clock execution time in milliseconds
|
|
1088
1073
|
* - `success`/`output`/`error` — discriminated outcome:
|
|
1089
|
-
* - on success: `success: true`, `output
|
|
1074
|
+
* - on success: `success: true`, `output` typed per tool
|
|
1090
1075
|
* - on failure: `success: false`, `error: unknown`
|
|
1091
1076
|
*
|
|
1092
|
-
* Pass an explicit `TOOLS` generic for full input typing
|
|
1077
|
+
* Pass an explicit `TOOLS` generic for full input **and** output typing.
|
|
1078
|
+
* On the success branch, narrowing on `ctx.toolName` narrows `ctx.output`
|
|
1079
|
+
* to that tool's inferred output type (dynamic tools stay `unknown`):
|
|
1093
1080
|
*
|
|
1094
1081
|
* ```ts
|
|
1095
1082
|
* import type { ToolCallResultContext } from "@cloudflare/think";
|
|
1096
1083
|
* import type { tools } from "./my-tools";
|
|
1097
1084
|
*
|
|
1098
1085
|
* afterToolCall(ctx: ToolCallResultContext<typeof tools>) {
|
|
1099
|
-
* if (ctx.success) {
|
|
1100
|
-
*
|
|
1101
|
-
* } else {
|
|
1102
|
-
* console.error(`${ctx.toolName} failed:`, ctx.error);
|
|
1086
|
+
* if (ctx.toolName === "search" && ctx.success) {
|
|
1087
|
+
* ctx.output.results; // typed as the `search` tool's output
|
|
1103
1088
|
* }
|
|
1104
1089
|
* }
|
|
1105
1090
|
* ```
|
|
1106
1091
|
*/
|
|
1107
1092
|
type ToolCallResultContext<TOOLS extends ToolSet = ToolSet> =
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1093
|
+
string extends keyof TOOLS
|
|
1094
|
+
? TypedToolCall<TOOLS> & ToolCallResultBase & ToolCallOutcome<unknown>
|
|
1095
|
+
: {
|
|
1096
|
+
[K in keyof TOOLS]: Extract<
|
|
1097
|
+
TypedToolCall<TOOLS>,
|
|
1098
|
+
{
|
|
1099
|
+
toolName: K;
|
|
1100
|
+
}
|
|
1101
|
+
> &
|
|
1102
|
+
ToolCallResultBase &
|
|
1103
|
+
ToolCallOutcome<InferToolOutput<TOOLS[K]>>;
|
|
1104
|
+
}[keyof TOOLS];
|
|
1105
|
+
/** Per-call extras attached to every {@link ToolCallResultContext}. */
|
|
1106
|
+
type ToolCallResultBase = {
|
|
1107
|
+
readonly stepNumber: number | undefined;
|
|
1108
|
+
readonly messages: ReadonlyArray<ModelMessage> /** Wall-clock execution time in milliseconds. */;
|
|
1109
|
+
readonly durationMs: number;
|
|
1110
|
+
};
|
|
1111
|
+
/**
|
|
1112
|
+
* The discriminated success/failure outcome of a tool call. On success the
|
|
1113
|
+
* `output` is typed (`O`); on failure the `error` is `unknown`.
|
|
1114
|
+
*/
|
|
1115
|
+
type ToolCallOutcome<O> =
|
|
1116
|
+
| {
|
|
1117
|
+
readonly success: true;
|
|
1118
|
+
readonly output: O;
|
|
1119
|
+
readonly error?: never;
|
|
1120
|
+
}
|
|
1121
|
+
| {
|
|
1122
|
+
readonly success: false;
|
|
1123
|
+
readonly output?: never;
|
|
1124
|
+
readonly error: unknown;
|
|
1125
|
+
};
|
|
1124
1126
|
/**
|
|
1125
1127
|
* Context passed to the `onStepFinish` hook after each step completes.
|
|
1126
1128
|
*
|
|
@@ -1188,6 +1190,7 @@ declare class Think<
|
|
|
1188
1190
|
};
|
|
1189
1191
|
private _skillRegistry;
|
|
1190
1192
|
private _loggedSkillWarnings;
|
|
1193
|
+
private _loggedProtocolWarnings;
|
|
1191
1194
|
/**
|
|
1192
1195
|
* Controls how overlapping user submit requests behave while another
|
|
1193
1196
|
* chat turn is already active or queued.
|
|
@@ -1295,7 +1298,21 @@ declare class Think<
|
|
|
1295
1298
|
*/
|
|
1296
1299
|
getOnStartDegradations(): ReadonlyArray<OnStartDegradation>;
|
|
1297
1300
|
private _activeMessengerContext?;
|
|
1301
|
+
/**
|
|
1302
|
+
* Turn-scoped channel context (superset of `_activeMessengerContext`). Set on
|
|
1303
|
+
* both the queue and submit admission paths via `_withChannelContext`, read by
|
|
1304
|
+
* `deliverNotice` and per-channel policy. Save/restore keeps nested turns safe.
|
|
1305
|
+
*/
|
|
1306
|
+
private _activeChannelContext?;
|
|
1307
|
+
/**
|
|
1308
|
+
* Live delivery surface for the active turn, bound by `deliverMessengerReply`
|
|
1309
|
+
* so `deliverNotice` can post to the originating channel mid-turn. Save/restore
|
|
1310
|
+
* keeps nested turns safe.
|
|
1311
|
+
*/
|
|
1312
|
+
private _activeDeliverySurface?;
|
|
1298
1313
|
private _messengerRuntime?;
|
|
1314
|
+
/** Resolved channel registry (implicit web + configureChannels + messengers). */
|
|
1315
|
+
private _channels?;
|
|
1299
1316
|
/**
|
|
1300
1317
|
* WorkerLoader binding for sandboxed extensions.
|
|
1301
1318
|
* Set this to enable `getExtensions()` and dynamic extension loading.
|
|
@@ -1344,6 +1361,22 @@ declare class Think<
|
|
|
1344
1361
|
workspaceBash:
|
|
1345
1362
|
| boolean
|
|
1346
1363
|
| NonNullable<Parameters<typeof createWorkspaceTools>[1]>["bash"];
|
|
1364
|
+
/**
|
|
1365
|
+
* Opt-in HTTP fetch tools. Disabled by default — set to a config object to
|
|
1366
|
+
* register a generic `fetch_url` tool (when `allowlist` is provided) and one
|
|
1367
|
+
* `fetch_<name>` tool per `bindings` target. Read-only (GET), allowlisted,
|
|
1368
|
+
* and bounded; see {@link createFetchTools}.
|
|
1369
|
+
*
|
|
1370
|
+
* The workspace and an observability hook are injected automatically, so omit
|
|
1371
|
+
* `workspace`/`onEvent` here. This property is evaluated at construction, so
|
|
1372
|
+
* use it for static config — for per-tenant/dynamic allowlists call
|
|
1373
|
+
* `createFetchTools()` inside `getTools()` instead (it runs every turn).
|
|
1374
|
+
*
|
|
1375
|
+
* ```ts
|
|
1376
|
+
* fetchTools = { allowlist: ["https://developers.cloudflare.com/**"] };
|
|
1377
|
+
* ```
|
|
1378
|
+
*/
|
|
1379
|
+
fetchTools: false | Omit<CreateFetchToolsOptions, "workspace" | "onEvent">;
|
|
1347
1380
|
constructor(ctx: DurableObjectState, env: Env);
|
|
1348
1381
|
/**
|
|
1349
1382
|
* Conversation history as Think's live in-memory view.
|
|
@@ -1379,31 +1412,12 @@ declare class Think<
|
|
|
1379
1412
|
* footprint over time, so the steady-state read size converges down.
|
|
1380
1413
|
*/
|
|
1381
1414
|
private _readMessagesFromStorage;
|
|
1382
|
-
/**
|
|
1383
|
-
* Normalize a tool part's `input` into something the provider will accept.
|
|
1384
|
-
*
|
|
1385
|
-
* Malformed shapes 400 modern providers and persist forever once written:
|
|
1386
|
-
* a stringified-JSON `input` (e.g. `'{"prompt":"a cat"}'` instead of the
|
|
1387
|
-
* object), and any non-object `input` — `null`, `undefined`, `""`, an array,
|
|
1388
|
-
* or a primitive — on a settled or interrupted tool call (Anthropic rejects
|
|
1389
|
-
* a `tool_use` block whose `input` is not an object). We parse the former and
|
|
1390
|
-
* default the latter to an empty object so the tool-call/tool-result pair
|
|
1391
|
-
* stays valid. Delegates to the shared `normalizeToolInput` so the read-side
|
|
1392
|
-
* repair and the write-side accumulator guard enforce the same invariant.
|
|
1393
|
-
*/
|
|
1394
|
-
private _normalizeToolInput;
|
|
1395
1415
|
/**
|
|
1396
1416
|
* Whether a tool part already has a settled result the provider accepts, so
|
|
1397
|
-
* it must NOT be re-repaired into an errored result.
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1400
|
-
*
|
|
1401
|
-
* terminal states: `convertToModelMessages` emits a `tool-result` for
|
|
1402
|
-
* `output-available`, `output-error`, AND `output-denied` (a user-denied
|
|
1403
|
-
* approval — its denial reason becomes the tool-result). Omitting any of
|
|
1404
|
-
* these makes repair re-flip the part every turn — clobbering a real
|
|
1405
|
-
* `errorText`/denial with the generic "interrupted" message — and makes the
|
|
1406
|
-
* backstop falsely drop a valid call.
|
|
1417
|
+
* it must NOT be re-repaired into an errored result. Delegates to the shared
|
|
1418
|
+
* `agents/chat` primitive so the repair pass and the backstop detector
|
|
1419
|
+
* (`_incompleteToolCallIds`) share the single source of truth for terminal
|
|
1420
|
+
* tool states.
|
|
1407
1421
|
*/
|
|
1408
1422
|
private _toolPartHasSettledResult;
|
|
1409
1423
|
/**
|
|
@@ -1539,9 +1553,21 @@ declare class Think<
|
|
|
1539
1553
|
private _upsertCachedMessage;
|
|
1540
1554
|
/** Patch a message that is already present in the live cache. */
|
|
1541
1555
|
private _patchCachedMessage;
|
|
1556
|
+
/** Sanitize + row-size-compact a message before it touches storage. */
|
|
1557
|
+
private _rowSafe;
|
|
1542
1558
|
private _appendMessageToHistory;
|
|
1543
1559
|
private _updateMessageInHistory;
|
|
1544
1560
|
private _upsertMessageInHistory;
|
|
1561
|
+
/**
|
|
1562
|
+
* The orphan-persist store adapter — orphan-persist steps **(c)/(d)** route
|
|
1563
|
+
* their write through this shared `OrphanPersistStore` seam (the
|
|
1564
|
+
* `SessionProvider` write-subset). Delegates to `this.session` with `_rowSafe`
|
|
1565
|
+
* applied at the write boundary (sanitize + row-size cap), exactly as Think's
|
|
1566
|
+
* other Session call sites do. The `SessionMessage → UIMessage` read cast is
|
|
1567
|
+
* confined here, matching those call sites.
|
|
1568
|
+
* @internal
|
|
1569
|
+
*/
|
|
1570
|
+
protected _orphanStore(): OrphanPersistStore;
|
|
1545
1571
|
private _clearHistory;
|
|
1546
1572
|
/** Append a message while keeping Think's live message cache coherent. */
|
|
1547
1573
|
protected appendMessageToHistory(
|
|
@@ -1556,11 +1582,24 @@ declare class Think<
|
|
|
1556
1582
|
private _turnQueue;
|
|
1557
1583
|
protected _resumableStream: ResumableStream;
|
|
1558
1584
|
private _pendingResumeConnections;
|
|
1585
|
+
/** Lazily-built shared resume-handshake driver (Tier-2). */
|
|
1586
|
+
private _resumeHandshakeInstance;
|
|
1559
1587
|
private _lastClientTools;
|
|
1560
1588
|
private _lastBody;
|
|
1561
1589
|
private _continuation;
|
|
1562
|
-
|
|
1563
|
-
|
|
1590
|
+
/**
|
|
1591
|
+
* Accepted-but-not-yet-streamed turns and the connections parked waiting for
|
|
1592
|
+
* one (#1784). See {@link ResumeHandshake} `preStream`.
|
|
1593
|
+
*
|
|
1594
|
+
* HIBERNATION INVARIANT: in-memory only, NOT persisted. Safe because the
|
|
1595
|
+
* pre-stream window cannot overlap hibernation — a turn between `begin()` and
|
|
1596
|
+
* stream start is an unresolved `onMessage` handler promise that pins the DO,
|
|
1597
|
+
* so eviction only happens once a durable stream exists (resumed via
|
|
1598
|
+
* `ResumableStream`) or the turn finished. Breaks if a pre-stream wait is ever
|
|
1599
|
+
* moved onto a durable alarm that releases the DO; if so, persist this state.
|
|
1600
|
+
*/
|
|
1601
|
+
private _preStream;
|
|
1602
|
+
private _autoContinuation;
|
|
1564
1603
|
private _insideResponseHook;
|
|
1565
1604
|
private _insideInferenceLoop;
|
|
1566
1605
|
private _pendingInteractionPromise;
|
|
@@ -1586,6 +1625,8 @@ declare class Think<
|
|
|
1586
1625
|
private _submissionTableEnsured;
|
|
1587
1626
|
private _workflowNotificationTableEnsured;
|
|
1588
1627
|
private _declaredScheduledTasksTableEnsured;
|
|
1628
|
+
private _actionLedgerTableEnsured;
|
|
1629
|
+
private _actionPendingTableEnsured;
|
|
1589
1630
|
private _drainingSubmissions;
|
|
1590
1631
|
private _drainingWorkflowNotifications;
|
|
1591
1632
|
private _submissionAbortControllers;
|
|
@@ -1603,6 +1644,37 @@ declare class Think<
|
|
|
1603
1644
|
* outcome is cached.
|
|
1604
1645
|
*/
|
|
1605
1646
|
private _agentToolRunForRequest;
|
|
1647
|
+
/**
|
|
1648
|
+
* Re-bind this facet's in-flight agent-tool child run to the CURRENT turn's
|
|
1649
|
+
* request id.
|
|
1650
|
+
*
|
|
1651
|
+
* When this facet is itself running as an agent-tool child and its turn is
|
|
1652
|
+
* interrupted (e.g. a deploy evicts it mid-run), the recovery continuation
|
|
1653
|
+
* (`continueLastTurn` / `_retryLastUserTurn`) mints a NEW request id. The
|
|
1654
|
+
* `cf_agent_tool_child_runs.request_id` column — and the in-memory attribution
|
|
1655
|
+
* map — still point at the pre-eviction turn, so `broadcast` can no longer
|
|
1656
|
+
* attribute the recovered turn's frames to the run. The parent's re-attach
|
|
1657
|
+
* tail then sees no forwarded chunks, its no-progress budget elapses, and it
|
|
1658
|
+
* abandons a healthy, still-advancing child as `interrupted`
|
|
1659
|
+
* (`agentToolReattachNoProgressTimeoutMs`). Re-binding the row to the recovery
|
|
1660
|
+
* turn's request id keeps frame attribution alive across recovery so the
|
|
1661
|
+
* parent re-attaches and follows the child to its real terminal.
|
|
1662
|
+
*
|
|
1663
|
+
* Safe to call on EVERY recovery continuation:
|
|
1664
|
+
* - Facets that never ran as an agent-tool child have no
|
|
1665
|
+
* `cf_agent_tool_child_runs` table → the guarded SELECT throws → no-op.
|
|
1666
|
+
* - A facet whose run already settled has no `starting`/`running` row → no-op.
|
|
1667
|
+
* - A child DO is addressed by its `runId` (`subAgent(cls, runId)`), so it
|
|
1668
|
+
* owns AT MOST ONE child-run row for its whole lifetime and is never reused
|
|
1669
|
+
* as a top-level chat agent — the single active row is unambiguously this
|
|
1670
|
+
* recovery's run. The `ORDER BY started_at DESC LIMIT 1` is defensive
|
|
1671
|
+
* belt-and-suspenders for that invariant.
|
|
1672
|
+
*
|
|
1673
|
+
* Uses the same `status IN ('starting','running')` active-run predicate as
|
|
1674
|
+
* `_agentToolRunForRequest` and the ai-chat counterpart (see the lifecycle
|
|
1675
|
+
* invariant note there).
|
|
1676
|
+
*/
|
|
1677
|
+
private _rebindAgentToolChildRunRequestId;
|
|
1606
1678
|
alarm(): Promise<void>;
|
|
1607
1679
|
/**
|
|
1608
1680
|
* Persist an arbitrary JSON-serializable configuration object for this
|
|
@@ -1646,8 +1718,19 @@ declare class Think<
|
|
|
1646
1718
|
getSystemPrompt(): string;
|
|
1647
1719
|
/** Return the tools available to the assistant. */
|
|
1648
1720
|
getTools(): ToolSet;
|
|
1721
|
+
/** Return action descriptors compiled into tools for the assistant. */
|
|
1722
|
+
getActions(): Record<string, Action> | Promise<Record<string, Action>>;
|
|
1649
1723
|
/** Return messenger integrations that should be routed through this Think agent. */
|
|
1650
1724
|
getMessengers(): ThinkMessengers;
|
|
1725
|
+
/**
|
|
1726
|
+
* Return the channels for this agent. Wraps (does not supersede)
|
|
1727
|
+
* {@link getMessengers}: the implicit `web` channel is always present, each
|
|
1728
|
+
* messenger from `getMessengers()` is absorbed as a `kind: "messenger"`
|
|
1729
|
+
* channel, and these entries add `web`/`voice`/`custom` surfaces plus
|
|
1730
|
+
* per-channel policy. A channel id that collides with a `getMessengers()` id
|
|
1731
|
+
* is an error.
|
|
1732
|
+
*/
|
|
1733
|
+
configureChannels(): ThinkChannels | Promise<ThinkChannels>;
|
|
1651
1734
|
getMessengerContext(): MessengerContext | undefined;
|
|
1652
1735
|
chatWithMessengerContext(
|
|
1653
1736
|
userMessage: string | UIMessage,
|
|
@@ -1655,7 +1738,65 @@ declare class Think<
|
|
|
1655
1738
|
context: MessengerContext,
|
|
1656
1739
|
options?: ChatOptions
|
|
1657
1740
|
): Promise<void>;
|
|
1658
|
-
|
|
1741
|
+
/**
|
|
1742
|
+
* Bind the live messenger delivery surface for the active turn so
|
|
1743
|
+
* `deliverNotice` can post to the originating channel while a messenger turn
|
|
1744
|
+
* is running. Returns a restore function; save/restore keeps nested turns
|
|
1745
|
+
* safe. Called by `deliverMessengerReply`.
|
|
1746
|
+
*/
|
|
1747
|
+
bindActiveDeliverySurface(surface: MessengerDeliverySurface): () => void;
|
|
1748
|
+
/**
|
|
1749
|
+
* The channel context for the active turn, if the turn resolved to a channel.
|
|
1750
|
+
* Readable from tools/hooks during a turn (e.g. to branch on `kind`).
|
|
1751
|
+
*/
|
|
1752
|
+
get activeChannel(): ChannelContext | undefined;
|
|
1753
|
+
/** Resolve a channel id to a turn-scoped {@link ChannelContext}, if registered. */
|
|
1754
|
+
private _resolveChannelContext;
|
|
1755
|
+
/**
|
|
1756
|
+
* Run `fn` with the turn-scoped channel context set for `channel`. No-op (just
|
|
1757
|
+
* runs `fn`) when the channel is unset or unregistered. Save/restore keeps
|
|
1758
|
+
* nested turns safe — mirrors `chatWithMessengerContext`.
|
|
1759
|
+
*/
|
|
1760
|
+
private _withChannelContext;
|
|
1761
|
+
/**
|
|
1762
|
+
* Stamp the channel id onto user messages so a recovered/continued turn can
|
|
1763
|
+
* re-resolve the channel from durable history.
|
|
1764
|
+
*/
|
|
1765
|
+
private _stampChannel;
|
|
1766
|
+
/** The channel stamped on the latest user message in the given list, if any. */
|
|
1767
|
+
private _channelFromMessages;
|
|
1768
|
+
/** Re-resolve the channel for a continuation from the latest user message. */
|
|
1769
|
+
private _channelFromLatestUserMessage;
|
|
1770
|
+
/**
|
|
1771
|
+
* Deliver a no-turn, channel-routed message — a deterministic status, fallback,
|
|
1772
|
+
* or notice — straight to the channel's delivery surface WITHOUT invoking the
|
|
1773
|
+
* model and WITHOUT opening a recovery incident.
|
|
1774
|
+
*
|
|
1775
|
+
* Routing precedence for the target channel: explicit `options.channel` → the
|
|
1776
|
+
* active turn's channel → `"web"`. The `web` channel renders via the transcript
|
|
1777
|
+
* (its only client render path), so a web notice is always transcript-visible;
|
|
1778
|
+
* messenger/voice deliver out of band and only touch the transcript when
|
|
1779
|
+
* `informModel: true`.
|
|
1780
|
+
*
|
|
1781
|
+
* Like `addMessages`, this bypasses the turn queue and is safe to call from
|
|
1782
|
+
* inside a tool `execute` without deadlocking.
|
|
1783
|
+
*/
|
|
1784
|
+
deliverNotice(
|
|
1785
|
+
text:
|
|
1786
|
+
| string
|
|
1787
|
+
| {
|
|
1788
|
+
markdown: string;
|
|
1789
|
+
},
|
|
1790
|
+
options?: DeliverNoticeOptions
|
|
1791
|
+
): Promise<void>;
|
|
1792
|
+
/**
|
|
1793
|
+
* The active turn's channel id, if any. Prefers the turn-scoped channel
|
|
1794
|
+
* context, then the active messenger turn's id; web turns have none, so
|
|
1795
|
+
* `deliverNotice` defaults to `"web"`.
|
|
1796
|
+
*/
|
|
1797
|
+
private _activeChannelId;
|
|
1798
|
+
private _noticeMessage;
|
|
1799
|
+
private _initializeChannels;
|
|
1659
1800
|
/** Return code-declared scheduled tasks for this agent. */
|
|
1660
1801
|
getScheduledTasks(): ThinkScheduledTasks | Promise<ThinkScheduledTasks>;
|
|
1661
1802
|
/**
|
|
@@ -1674,6 +1815,36 @@ declare class Think<
|
|
|
1674
1815
|
private _buildThinkCapabilityBlock;
|
|
1675
1816
|
/** Maximum number of tool-call steps per turn. Override via property or per-turn via TurnConfig. */
|
|
1676
1817
|
maxSteps: number;
|
|
1818
|
+
/**
|
|
1819
|
+
* Retention window for settled action ledger rows. Deleting a row ends the
|
|
1820
|
+
* idempotency guarantee for that key, so increase these windows for side
|
|
1821
|
+
* effects whose downstream idempotency horizon is longer. Set a status to
|
|
1822
|
+
* `false` to disable sweeping it.
|
|
1823
|
+
*/
|
|
1824
|
+
actionLedgerRetention: ActionLedgerRetentionConfig;
|
|
1825
|
+
/**
|
|
1826
|
+
* Lease window after which a durable `pending` action ledger row is assumed
|
|
1827
|
+
* abandoned (its executor isolate died) and may be reclaimed and re-run.
|
|
1828
|
+
* Reclaim re-runs `execute`, so it only applies to actions that declare an
|
|
1829
|
+
* explicit `idempotencyKey` — that key is the developer's assertion that the
|
|
1830
|
+
* keyed side effect is safe to retry. Fallback `tool:${toolCallId}` keys are
|
|
1831
|
+
* never reclaimed. Set to `false` to disable stale-pending reclaim entirely
|
|
1832
|
+
* (a stale row then blocks forever with `ActionPendingError`, the old
|
|
1833
|
+
* behavior). This is a retry lease, not a retention window: retention answers
|
|
1834
|
+
* "when may we delete old rows?"; the lease answers "when may we assume the
|
|
1835
|
+
* previous executor died and retry safely?". Keep `actionLedgerRetention.pendingMs`
|
|
1836
|
+
* well above this lease so reclaim happens before a sweep deletes the row.
|
|
1837
|
+
*/
|
|
1838
|
+
actionLedgerPendingRetryLeaseMs: number | false;
|
|
1839
|
+
/**
|
|
1840
|
+
* Retention window for abandoned durable-pause approval rows — a
|
|
1841
|
+
* `kind: "durable-pause"` action that parked but was never approved or
|
|
1842
|
+
* rejected. Deleting a row makes that approval permanently unresolvable, so
|
|
1843
|
+
* default generously: "approve days later from a dashboard" is the use case.
|
|
1844
|
+
* Set to `false` to disable sweeping. Rows are deleted promptly on
|
|
1845
|
+
* approve/reject regardless; this only bounds truly abandoned pauses.
|
|
1846
|
+
*/
|
|
1847
|
+
actionPendingApprovalTtlMs: number | false;
|
|
1677
1848
|
/**
|
|
1678
1849
|
* Whether reasoning chunks are sent to chat clients by default. Override
|
|
1679
1850
|
* per turn by returning `sendReasoning` from `beforeTurn`.
|
|
@@ -1743,6 +1914,20 @@ declare class Think<
|
|
|
1743
1914
|
* Turns are serialized, so a single value is safe.
|
|
1744
1915
|
*/
|
|
1745
1916
|
private _activeTurnTools;
|
|
1917
|
+
private _activeTurnActionMetadata;
|
|
1918
|
+
private _activeTurnAuthorization;
|
|
1919
|
+
private _activeTurnActionApprovalDescriptors;
|
|
1920
|
+
private _activeTurnApprovedActionInputs;
|
|
1921
|
+
private _activeActionLedgerExecutions;
|
|
1922
|
+
/**
|
|
1923
|
+
* Advisory reply attachments recorded by actions during the current admitted
|
|
1924
|
+
* turn (see `ctx.attachReply`). Single-slot because turns are serialized.
|
|
1925
|
+
* Reset at turn start in `_runInsideAdmittedTurnBody`; intentionally not
|
|
1926
|
+
* cleared at turn end so `onChatResponse` and `replyAttachments()` can read
|
|
1927
|
+
* it — the next turn's reset overwrites it.
|
|
1928
|
+
*/
|
|
1929
|
+
private _activeTurnReplyAttachments;
|
|
1930
|
+
private _activeTurnReplyAttachmentsRequestId;
|
|
1746
1931
|
/**
|
|
1747
1932
|
* Number of times the proactive guard has compacted within the current
|
|
1748
1933
|
* `_runInferenceLoop` (reset at the top of each run). Capped at
|
|
@@ -1824,6 +2009,40 @@ declare class Think<
|
|
|
1824
2009
|
* ```
|
|
1825
2010
|
*/
|
|
1826
2011
|
beforeTurn(_ctx: TurnContext): TurnConfig | void | Promise<TurnConfig | void>;
|
|
2012
|
+
/**
|
|
2013
|
+
* Authorize action permissions for the current turn. Returning `true` grants
|
|
2014
|
+
* all action permissions. Returning `grantedPermissions` limits the default
|
|
2015
|
+
* `authorizeAction` implementation to that permission set.
|
|
2016
|
+
*/
|
|
2017
|
+
authorizeTurn(
|
|
2018
|
+
_ctx: TurnContext
|
|
2019
|
+
): ActionAuthorizationDecision | Promise<ActionAuthorizationDecision>;
|
|
2020
|
+
/**
|
|
2021
|
+
* Authorize a single action call after its model input and required
|
|
2022
|
+
* permissions are known. Override this for app-specific policy; the default
|
|
2023
|
+
* implementation enforces the grant returned from `authorizeTurn`.
|
|
2024
|
+
*/
|
|
2025
|
+
authorizeAction(
|
|
2026
|
+
ctx: ActionAuthorizationContext
|
|
2027
|
+
): ActionAuthorizationDecision | Promise<ActionAuthorizationDecision>;
|
|
2028
|
+
/**
|
|
2029
|
+
* Enrich the approval descriptor shown in approval UIs for a paused codemode
|
|
2030
|
+
* `execute` execution. The default descriptor is derived from the first
|
|
2031
|
+
* pending action as `connector.method` with its args as the input; override
|
|
2032
|
+
* here to supply a human summary, the permissions it consumes, or a risk
|
|
2033
|
+
* level (returned fields are merged over the derived defaults).
|
|
2034
|
+
*
|
|
2035
|
+
* Not called for `kind: "durable-pause"` actions — those carry their own
|
|
2036
|
+
* descriptor from the `action()` config. Default returns `undefined` (use the
|
|
2037
|
+
* derived descriptor).
|
|
2038
|
+
*/
|
|
2039
|
+
describePausedExecution(
|
|
2040
|
+
_pending: import("@cloudflare/codemode").PendingAction[],
|
|
2041
|
+
_ctx: {
|
|
2042
|
+
requestId: string;
|
|
2043
|
+
toolCallId: string;
|
|
2044
|
+
}
|
|
2045
|
+
): Partial<ActionApprovalDescriptor> | undefined;
|
|
1827
2046
|
/**
|
|
1828
2047
|
* Called before each AI SDK step in the agentic loop. Backed by
|
|
1829
2048
|
* `streamText({ prepareStep })`.
|
|
@@ -2068,6 +2287,36 @@ declare class Think<
|
|
|
2068
2287
|
protected _transformInferenceResult(
|
|
2069
2288
|
result: StreamableResult
|
|
2070
2289
|
): StreamableResult;
|
|
2290
|
+
private _normalizeActionAuthorization;
|
|
2291
|
+
private _emitActionLedgerEvent;
|
|
2292
|
+
private _emitChannelEvent;
|
|
2293
|
+
private _approvedActionInputsFromTranscript;
|
|
2294
|
+
private _resolveActionPermissions;
|
|
2295
|
+
private _actionContextWithoutReply;
|
|
2296
|
+
private _authorizeActionCall;
|
|
2297
|
+
private _compileActionTools;
|
|
2298
|
+
private _actionToTool;
|
|
2299
|
+
/**
|
|
2300
|
+
* Run an action's `execute` through the action ledger: same-isolate
|
|
2301
|
+
* coalescing, durable claim/replay, settle-on-success, release-on-failure.
|
|
2302
|
+
* Shared by the inline server-action path and the durable-pause-on-approve
|
|
2303
|
+
* path so an action's side effect is replay-safe regardless of how it is
|
|
2304
|
+
* dispatched. `runAction` must already apply timeout/abort and
|
|
2305
|
+
* `prepareActionOutputForModel`.
|
|
2306
|
+
*/
|
|
2307
|
+
private _runLedgeredAction;
|
|
2308
|
+
/**
|
|
2309
|
+
* Park a `kind: "durable-pause"` action for human approval. Persists a
|
|
2310
|
+
* compaction-safe pending row (action name + model input + approval
|
|
2311
|
+
* descriptor) so the approval survives history compaction, deploys, and
|
|
2312
|
+
* isolate eviction, then returns the minimal model-visible paused output.
|
|
2313
|
+
*
|
|
2314
|
+
* The action's `execute` does NOT run here — it runs later in
|
|
2315
|
+
* `approveExecution` via `_runLedgeredAction`, so the side effect is gated on
|
|
2316
|
+
* human approval AND remains replay-safe. The rich descriptor lives on the
|
|
2317
|
+
* row and on the transcript part, never embedded in the model-visible output.
|
|
2318
|
+
*/
|
|
2319
|
+
private _parkDurablePauseAction;
|
|
2071
2320
|
/** Default hook timeout in milliseconds. */
|
|
2072
2321
|
hookTimeout: number;
|
|
2073
2322
|
/**
|
|
@@ -2116,16 +2365,30 @@ declare class Think<
|
|
|
2116
2365
|
*
|
|
2117
2366
|
* **Streaming tools (AsyncIterable):** the AI SDK supports tools whose
|
|
2118
2367
|
* `execute` returns `AsyncIterable<output>` to emit preliminary
|
|
2119
|
-
* results before a final value.
|
|
2120
|
-
*
|
|
2121
|
-
* a
|
|
2122
|
-
*
|
|
2123
|
-
*
|
|
2124
|
-
*
|
|
2125
|
-
*
|
|
2126
|
-
*
|
|
2368
|
+
* results before a final value. The canonical form is an async
|
|
2369
|
+
* generator (`async function* execute(...)`), where calling `execute`
|
|
2370
|
+
* synchronously returns a direct `AsyncIterable`. For that form Think
|
|
2371
|
+
* preserves preliminary streaming: the wrapper is itself an async
|
|
2372
|
+
* generator that `await`s `beforeToolCall` and then yields every
|
|
2373
|
+
* chunk through unchanged. Non-streaming tools keep a scalar wrapper
|
|
2374
|
+
* so they never emit a synthetic `preliminary` tool-result chunk.
|
|
2375
|
+
*
|
|
2376
|
+
* The non-canonical `async function execute(...) { return makeIter(); }`
|
|
2377
|
+
* form returns a `Promise<AsyncIterable>`, which does not stream even
|
|
2378
|
+
* in the raw AI SDK (it would surface the iterator object as the final
|
|
2379
|
+
* output). Think collapses it to the last yielded value instead. If
|
|
2380
|
+
* you need preliminary streaming, use an `async function*` `execute`.
|
|
2127
2381
|
*/
|
|
2128
2382
|
private _wrapToolsWithDecision;
|
|
2383
|
+
/**
|
|
2384
|
+
* Shared `beforeToolCall` resolution for both the scalar and streaming
|
|
2385
|
+
* tool wrappers (see {@link _wrapToolsWithDecision}). Builds the
|
|
2386
|
+
* `ToolCallContext`, consults the subclass `beforeToolCall` hook,
|
|
2387
|
+
* dispatches the extension observation snapshot, and resolves the
|
|
2388
|
+
* returned `ToolCallDecision` into either "run `execute` with this
|
|
2389
|
+
* input" or "short-circuit with this output".
|
|
2390
|
+
*/
|
|
2391
|
+
private _resolveToolCallDecision;
|
|
2129
2392
|
private _pipelineExtensionToolCallStart;
|
|
2130
2393
|
private _pipelineExtensionToolCallFinish;
|
|
2131
2394
|
private _pipelineExtensionStepFinish;
|
|
@@ -2154,31 +2417,163 @@ declare class Think<
|
|
|
2154
2417
|
_hostGetSessionInfo(): Promise<{
|
|
2155
2418
|
messageCount: number;
|
|
2156
2419
|
}>;
|
|
2420
|
+
private _admitTurn;
|
|
2421
|
+
private _assertNotInsideAdmittedTurn;
|
|
2422
|
+
private _runInsideAdmittedTurnBody;
|
|
2157
2423
|
/**
|
|
2158
2424
|
* Run a chat turn: persist the user message, run the agentic loop,
|
|
2159
2425
|
* stream UIMessageChunk events via callback, and persist the
|
|
2160
2426
|
* assistant's response.
|
|
2161
2427
|
*
|
|
2162
|
-
* @param userMessage The user's message
|
|
2428
|
+
* @param userMessage The user's message(s), or a callback that derives them
|
|
2429
|
+
* from the in-queue transcript.
|
|
2163
2430
|
* @param callback Streaming callback (typically an RpcTarget from the parent)
|
|
2164
2431
|
* @param options Optional chat options (e.g. AbortSignal)
|
|
2165
2432
|
*/
|
|
2166
2433
|
chat(
|
|
2167
|
-
userMessage:
|
|
2434
|
+
userMessage: TurnInputMessages,
|
|
2168
2435
|
callback: StreamCallback,
|
|
2169
2436
|
options?: ChatOptions
|
|
2170
2437
|
): Promise<void>;
|
|
2438
|
+
/**
|
|
2439
|
+
* Unified turn admission API (Turns RFC, step 2).
|
|
2440
|
+
*
|
|
2441
|
+
* Thin facade over {@link Think.saveMessages}, {@link Think.continueLastTurn},
|
|
2442
|
+
* {@link Think.submitMessages}, and {@link Think.chat}. Each `mode` delegates
|
|
2443
|
+
* to the matching backing method with a narrowed option surface; the full
|
|
2444
|
+
* unified superset lands with `_admitTurn` (step 3).
|
|
2445
|
+
*
|
|
2446
|
+
* - `mode: "wait"` (default) — blocking turn; returns {@link TurnResult}.
|
|
2447
|
+
* - `mode: "submit"` — durable queued turn; returns {@link SubmitMessagesResult}.
|
|
2448
|
+
* - `mode: "stream"` — RPC-style streaming; returns `Promise<void>`.
|
|
2449
|
+
*
|
|
2450
|
+
* **Re-entrancy.** Calling `mode: "wait"` or `continuation: true` from inside
|
|
2451
|
+
* an active turn (a tool `execute`, a lifecycle hook) deadlocks on the turn
|
|
2452
|
+
* queue — identical to calling {@link Think.saveMessages} or
|
|
2453
|
+
* {@link Think.continueLastTurn} from there. Prefer `mode: "submit"` or
|
|
2454
|
+
* {@link Think.addMessages} instead. Precise nested-call detection is deferred
|
|
2455
|
+
* to `_admitTurn` (step 3).
|
|
2456
|
+
*
|
|
2457
|
+
* **Empty input (`wait`).** String, single-message, and array inputs that
|
|
2458
|
+
* normalize to an empty list short-circuit to `{ status: "skipped" }` without
|
|
2459
|
+
* running inference. A function `input` that resolves to `[]` at run time is
|
|
2460
|
+
* not pre-checked (the function must see the in-queue transcript); step 3's
|
|
2461
|
+
* `_admitTurn` centralizes empty-skip inside the queue.
|
|
2462
|
+
*
|
|
2463
|
+
* @experimental
|
|
2464
|
+
*/
|
|
2465
|
+
runTurn(options: RunTurnWait): Promise<TurnResult>;
|
|
2466
|
+
runTurn(options: RunTurnSubmit): Promise<SubmitMessagesResult>;
|
|
2467
|
+
runTurn(options: RunTurnStream): Promise<void>;
|
|
2468
|
+
private _resolveRunTurnMode;
|
|
2469
|
+
private _validateRunTurnAdmission;
|
|
2470
|
+
private _userMessageFromText;
|
|
2471
|
+
private _normalizeRunTurnMessages;
|
|
2472
|
+
private _normalizeChatMessages;
|
|
2473
|
+
private _assertRunTurnSubmitInput;
|
|
2474
|
+
private _enrichTurnResult;
|
|
2475
|
+
private _runTurnWait;
|
|
2476
|
+
private _runTurnSubmit;
|
|
2477
|
+
private _runTurnStream;
|
|
2171
2478
|
/** Get the conversation history as UIMessage[]. */
|
|
2172
2479
|
getMessages(): Promise<UIMessage[]>;
|
|
2173
2480
|
/** Clear all messages from storage. */
|
|
2174
2481
|
clearMessages(): Promise<void>;
|
|
2175
2482
|
private _ensureAgentToolChildRunTable;
|
|
2483
|
+
private _persistAgentToolMilestone;
|
|
2484
|
+
private _readAgentToolMilestones;
|
|
2176
2485
|
private _addAgentToolChildRunColumnIfMissing;
|
|
2177
2486
|
private _readAgentToolChildRun;
|
|
2178
2487
|
private _inspectionFromChildRow;
|
|
2488
|
+
/**
|
|
2489
|
+
* Rebuild the latest progress snapshot persisted by `reportProgress` from a
|
|
2490
|
+
* child run row, or `undefined` if the child never reported progress.
|
|
2491
|
+
*/
|
|
2492
|
+
private static _progressSnapshotFromRow;
|
|
2179
2493
|
protected formatAgentToolInput(input: unknown): UIMessage;
|
|
2494
|
+
private _agentToolProgressEmitterInstance;
|
|
2495
|
+
private get _agentToolProgressEmitter();
|
|
2496
|
+
reportProgress<T = unknown>(
|
|
2497
|
+
progress: AgentToolProgress<T>,
|
|
2498
|
+
options?: {
|
|
2499
|
+
persist?: boolean;
|
|
2500
|
+
}
|
|
2501
|
+
): Promise<void>;
|
|
2180
2502
|
protected getAgentToolOutput(_runId: string): unknown;
|
|
2181
2503
|
protected getAgentToolSummary(runId: string, output: unknown): string;
|
|
2504
|
+
/**
|
|
2505
|
+
* Format the message injected back into the chat when a `detached:
|
|
2506
|
+
* { notify: true }` run finishes. Override to customize the prose (or return
|
|
2507
|
+
* an empty string to suppress the notification for a given outcome). The
|
|
2508
|
+
* default announces the terminal status and any summary/error so the model
|
|
2509
|
+
* has enough context to react.
|
|
2510
|
+
*/
|
|
2511
|
+
protected formatDetachedCompletion(
|
|
2512
|
+
run: AgentToolRunInfo,
|
|
2513
|
+
result: AgentToolLifecycleResult
|
|
2514
|
+
): string;
|
|
2515
|
+
/**
|
|
2516
|
+
* Serialize detached terminal delivery against the chat turn queue. A
|
|
2517
|
+
* fast-path push or backbone tick can land mid-turn, and an `onFinish` that
|
|
2518
|
+
* mutates state (`setState`, `submitMessages`, a follow-up `runAgentTool`)
|
|
2519
|
+
* running concurrently with an active LLM turn is a data race. Those paths
|
|
2520
|
+
* never run synchronously inside a turn body (they fire from `waitUntil` / a
|
|
2521
|
+
* scheduled alarm), so enqueuing on the turn queue runs the delivery strictly
|
|
2522
|
+
* between turns without risk of self-deadlock.
|
|
2523
|
+
*
|
|
2524
|
+
* An explicit `cancelAgentTool` (`serialize` unset) may be invoked from inside
|
|
2525
|
+
* the very turn that triggers it, where enqueuing WOULD self-deadlock, so it
|
|
2526
|
+
* runs inline in the caller's (or a fresh) `agentContext` instead. The Think
|
|
2527
|
+
* `notify` convenience is unaffected either way: it delivers via
|
|
2528
|
+
* `submitMessages`, which already serializes FIFO behind any active turn.
|
|
2529
|
+
*/
|
|
2530
|
+
protected _runDetachedDelivery(
|
|
2531
|
+
invoke: () => Promise<void>,
|
|
2532
|
+
options?: {
|
|
2533
|
+
serialize?: boolean;
|
|
2534
|
+
}
|
|
2535
|
+
): Promise<void>;
|
|
2536
|
+
/**
|
|
2537
|
+
* Targeted completion hook for `detached: { notify: true }`. Auto-wired by
|
|
2538
|
+
* `runAgentTool` (resolved by name so the base Agent stays decoupled from the
|
|
2539
|
+
* chat layer). Injects the formatted completion as a programmatic turn so the
|
|
2540
|
+
* model reacts to the background result. Idempotent per run + status, so an
|
|
2541
|
+
* exactly-once finish — or a soft give-up followed by a real completion —
|
|
2542
|
+
* never injects a duplicate, while a give-up and a later real completion are
|
|
2543
|
+
* surfaced as two distinct turns.
|
|
2544
|
+
*/
|
|
2545
|
+
_cfDetachedNotifyFinish(
|
|
2546
|
+
run: AgentToolRunInfo,
|
|
2547
|
+
result: AgentToolLifecycleResult
|
|
2548
|
+
): Promise<void>;
|
|
2549
|
+
/**
|
|
2550
|
+
* Format the synthetic message injected when a `detached: { onMilestones }`
|
|
2551
|
+
* milestone is reached. Override to customize the prose (or return an empty
|
|
2552
|
+
* string to suppress a given milestone). The default announces the milestone
|
|
2553
|
+
* name and any structured data so the model can react in-conversation before
|
|
2554
|
+
* the run finishes.
|
|
2555
|
+
*/
|
|
2556
|
+
protected formatDetachedMilestone(
|
|
2557
|
+
run: AgentToolRunInfo,
|
|
2558
|
+
milestone: AgentToolMilestone
|
|
2559
|
+
): string;
|
|
2560
|
+
/**
|
|
2561
|
+
* Targeted milestone hook for `detached: { onMilestones }`. Idempotent per run
|
|
2562
|
+
* + milestone NAME (not sequence — a name surfaces at most once even if
|
|
2563
|
+
* re-emitted), so the warm tail and the backbone reconcile converge. Fired
|
|
2564
|
+
* from both paths.
|
|
2565
|
+
*
|
|
2566
|
+
* - `"narrate"` (default): a synthetic **assistant** message injected directly
|
|
2567
|
+
* — no model turn — using a deterministic message id for idempotency
|
|
2568
|
+
* (`addMessages` is a no-op for an id already in history).
|
|
2569
|
+
* - `"react"`: a **user-role** turn so the model responds to the milestone
|
|
2570
|
+
* (idempotency via `submitMessages` + UNIQUE idempotency key).
|
|
2571
|
+
*/
|
|
2572
|
+
protected _deliverDetachedMilestone(
|
|
2573
|
+
run: AgentToolRunInfo,
|
|
2574
|
+
milestone: AgentToolMilestone,
|
|
2575
|
+
mode: "react" | "narrate"
|
|
2576
|
+
): Promise<void>;
|
|
2182
2577
|
startAgentToolRun(
|
|
2183
2578
|
input: unknown,
|
|
2184
2579
|
options: {
|
|
@@ -2250,6 +2645,58 @@ declare class Think<
|
|
|
2250
2645
|
*/
|
|
2251
2646
|
private _hasRecoveredAgentToolAssistantTurn;
|
|
2252
2647
|
private _getAgentToolFinalText;
|
|
2648
|
+
private _ensureActionLedgerTable;
|
|
2649
|
+
private _readActionLedgerRow;
|
|
2650
|
+
/**
|
|
2651
|
+
* Claim a ledger key for execution. Read-then-write with no `await` between
|
|
2652
|
+
* the read and any write, so within the single DO isolate two claims cannot
|
|
2653
|
+
* interleave — the same race-free idiom documented on
|
|
2654
|
+
* {@link _claimActionPendingRow}. The only way a durable `pending` row
|
|
2655
|
+
* outlives its writer is a crashed prior isolate, which has no live writer to
|
|
2656
|
+
* race; that is the row a stale reclaim safely re-runs.
|
|
2657
|
+
*/
|
|
2658
|
+
private _claimActionLedgerRow;
|
|
2659
|
+
private _settleActionLedgerRow;
|
|
2660
|
+
private _releaseActionLedgerRow;
|
|
2661
|
+
private _resolveActionLedgerKey;
|
|
2662
|
+
private _actionInputHash;
|
|
2663
|
+
private _actionLedgerRetentionForStatus;
|
|
2664
|
+
private _deleteActionLedgerRows;
|
|
2665
|
+
private _sweepActionLedgerStatus;
|
|
2666
|
+
private _sweepActionLedger;
|
|
2667
|
+
private _emitActionReplyEvent;
|
|
2668
|
+
/**
|
|
2669
|
+
* Record an advisory reply attachment for the active turn. Advisory: a
|
|
2670
|
+
* non-object, a missing/non-string `type`, or exceeding the per-turn cap is
|
|
2671
|
+
* silently ignored. The attachment is JSON-normalized to a safe copy so a
|
|
2672
|
+
* later mutation of the caller's object can't corrupt it and downstream
|
|
2673
|
+
* persistence/RPC can't choke on bigint/circular values.
|
|
2674
|
+
*/
|
|
2675
|
+
private _recordReplyAttachment;
|
|
2676
|
+
private _cloneReplyAttachment;
|
|
2677
|
+
/**
|
|
2678
|
+
* Advisory reply attachments recorded during a turn via `ctx.attachReply`.
|
|
2679
|
+
* Returns deep copies. With no `requestId`, returns the most recent turn's
|
|
2680
|
+
* attachments; with a `requestId`, returns them only if they belong to that
|
|
2681
|
+
* turn (else `[]`).
|
|
2682
|
+
*/
|
|
2683
|
+
replyAttachments(requestId?: string): ReplyAttachment[];
|
|
2684
|
+
private _emitActionPauseEvent;
|
|
2685
|
+
private _ensureActionPendingTable;
|
|
2686
|
+
private _readActionPendingRow;
|
|
2687
|
+
private _insertActionPendingRow;
|
|
2688
|
+
/**
|
|
2689
|
+
* Atomically claim a pending-approval row for resolution: read it, then
|
|
2690
|
+
* delete it. SQLite calls are synchronous and there is no `await` between the
|
|
2691
|
+
* read and the delete, so within the single DO isolate this is race-free — a
|
|
2692
|
+
* concurrent `approveExecution`/`rejectExecution` for the same id can only run
|
|
2693
|
+
* at an await boundary, by which point the row is already gone (it sees
|
|
2694
|
+
* `null` → "already resolved"). The returned row is the caller's to resolve.
|
|
2695
|
+
*/
|
|
2696
|
+
private _claimActionPendingRow;
|
|
2697
|
+
private _listActionPendingRows;
|
|
2698
|
+
private _deleteActionPendingRows;
|
|
2699
|
+
private _sweepActionPendingApprovals;
|
|
2253
2700
|
private _ensureDeclaredScheduledTasksTable;
|
|
2254
2701
|
private _readDeclaredScheduledTaskRow;
|
|
2255
2702
|
private _listDeclaredScheduledTaskRows;
|
|
@@ -2312,6 +2759,7 @@ declare class Think<
|
|
|
2312
2759
|
_drainThinkSubmissions(): Promise<void>;
|
|
2313
2760
|
private _drainSubmissions;
|
|
2314
2761
|
private _runSubmission;
|
|
2762
|
+
private _executeSubmission;
|
|
2315
2763
|
private _getSubmissionFinalStatus;
|
|
2316
2764
|
private _markPendingSubmissionsSkipped;
|
|
2317
2765
|
private _emitSkippedSubmissions;
|
|
@@ -2425,7 +2873,10 @@ declare class Think<
|
|
|
2425
2873
|
*/
|
|
2426
2874
|
protected continueLastTurn(
|
|
2427
2875
|
body?: Record<string, unknown>,
|
|
2428
|
-
options?: SaveMessagesOptions
|
|
2876
|
+
options?: SaveMessagesOptions & {
|
|
2877
|
+
trigger?: TurnTrigger;
|
|
2878
|
+
channel?: string;
|
|
2879
|
+
}
|
|
2429
2880
|
): Promise<SaveMessagesResult>;
|
|
2430
2881
|
private _retryLastUserTurn;
|
|
2431
2882
|
private _setupProtocolHandlers;
|
|
@@ -2493,6 +2944,17 @@ declare class Think<
|
|
|
2493
2944
|
* stored chunk, so it needs no separate stamping.
|
|
2494
2945
|
*/
|
|
2495
2946
|
private _alignStreamStartId;
|
|
2947
|
+
private _annotateActionApprovalChunk;
|
|
2948
|
+
/**
|
|
2949
|
+
* Build the approval descriptor for a paused tool output, the single source
|
|
2950
|
+
* of truth for rendering a pending approval. Durable-pause actions read the
|
|
2951
|
+
* descriptor persisted on their pending row (resolved permissions, survives
|
|
2952
|
+
* compaction); codemode pauses derive `connector.method` from the first
|
|
2953
|
+
* pending action and let {@link describePausedExecution} enrich it. Returns
|
|
2954
|
+
* `undefined` for non-paused outputs or when no descriptor can be built.
|
|
2955
|
+
*/
|
|
2956
|
+
private _descriptorForPausedOutput;
|
|
2957
|
+
private _applyActionApprovalDescriptorToParts;
|
|
2496
2958
|
private _streamResultToRpcCallback;
|
|
2497
2959
|
/**
|
|
2498
2960
|
* Whether storing this chunk should immediately flush the resumable-stream
|
|
@@ -2515,15 +2977,22 @@ declare class Think<
|
|
|
2515
2977
|
* step, never an already-completed tool call).
|
|
2516
2978
|
*/
|
|
2517
2979
|
private _storeChunkDurably;
|
|
2980
|
+
/** Per-isolate throttle for crediting recovery progress from mid-segment
|
|
2981
|
+
* streaming-content deltas (the shared `agents/chat` rule); reset per isolate
|
|
2982
|
+
* so the first delta after a restart always credits. */
|
|
2983
|
+
private _streamProgressCredit;
|
|
2984
|
+
private _streamResult;
|
|
2518
2985
|
/**
|
|
2519
|
-
*
|
|
2520
|
-
*
|
|
2521
|
-
*
|
|
2522
|
-
*
|
|
2523
|
-
*
|
|
2986
|
+
* Single source of Think's strip + empty-skip persistence rule. Strips the
|
|
2987
|
+
* internal final-answer parts and returns the message to persist (the stripped
|
|
2988
|
+
* copy, or the original when nothing was stripped), or `null` when stripping
|
|
2989
|
+
* leaves nothing user-facing (only structural `step-start` markers, or
|
|
2990
|
+
* nothing) — in which case the caller skips persistence so a structured
|
|
2991
|
+
* workflow turn does not leave an empty assistant message in the conversation.
|
|
2992
|
+
* Shared by `_persistAssistantMessage` and the orphan-persist path so the rule
|
|
2993
|
+
* cannot drift between the live and recovery writes.
|
|
2524
2994
|
*/
|
|
2525
|
-
private
|
|
2526
|
-
private _streamResult;
|
|
2995
|
+
private _strippedForPersist;
|
|
2527
2996
|
private _persistAssistantMessage;
|
|
2528
2997
|
/**
|
|
2529
2998
|
* Remove parts belonging to Think's internal structured-output final-answer
|
|
@@ -2588,6 +3057,17 @@ declare class Think<
|
|
|
2588
3057
|
pendingExecutions(
|
|
2589
3058
|
executionId?: string
|
|
2590
3059
|
): Promise<import("@cloudflare/codemode").PendingAction[]>;
|
|
3060
|
+
/**
|
|
3061
|
+
* List everything awaiting human approval — parked `kind: "durable-pause"`
|
|
3062
|
+
* actions and paused codemode executions — each carrying its
|
|
3063
|
+
* {@link ActionApprovalDescriptor}. The unified, descriptor-first view a
|
|
3064
|
+
* dashboard, voice backend, or messenger reconciles against; resolve any of
|
|
3065
|
+
* them via {@link approveExecution} / {@link rejectExecution}. Pass an
|
|
3066
|
+
* `executionId` to scope to one.
|
|
3067
|
+
*
|
|
3068
|
+
* Client-callable.
|
|
3069
|
+
*/
|
|
3070
|
+
pendingApprovals(executionId?: string): Promise<PendingApproval[]>;
|
|
2591
3071
|
/**
|
|
2592
3072
|
* Approve a paused execution and resume it. The run continues from where
|
|
2593
3073
|
* it stopped (replaying logged work, executing the approved call); the
|
|
@@ -2602,6 +3082,26 @@ declare class Think<
|
|
|
2602
3082
|
* Client-callable.
|
|
2603
3083
|
*/
|
|
2604
3084
|
approveExecution(executionId: string): Promise<unknown>;
|
|
3085
|
+
/**
|
|
3086
|
+
* Approve a parked `kind: "durable-pause"` action and run its `execute`.
|
|
3087
|
+
*
|
|
3088
|
+
* Claim-by-delete makes this idempotent across tabs/recovery: only the caller
|
|
3089
|
+
* that removes the row runs the action; a racing approve/reject sees no row
|
|
3090
|
+
* and reports "already resolved". Authorization happened at PAUSE time — the
|
|
3091
|
+
* human approval is the authority now, so we do not re-authorize (the turn
|
|
3092
|
+
* context that `authorizeAction` needs is gone). The action runs through the
|
|
3093
|
+
* ledger so its side effect stays replay-safe, the outcome replaces the
|
|
3094
|
+
* paused transcript part, and the chat continues even with no socket open.
|
|
3095
|
+
*/
|
|
3096
|
+
private _approveActionPause;
|
|
3097
|
+
/** Resolve a registered action by its resolved name (config.name ?? key). */
|
|
3098
|
+
private _findRegisteredAction;
|
|
3099
|
+
/**
|
|
3100
|
+
* Run a just-approved durable-pause action's `execute` through the ledger.
|
|
3101
|
+
* Mirrors the inline `_actionToTool` execute wrapper (timeout, abort race,
|
|
3102
|
+
* model-output prep) MINUS authorization — that was settled at pause time.
|
|
3103
|
+
*/
|
|
3104
|
+
private _runApprovedActionPause;
|
|
2605
3105
|
/**
|
|
2606
3106
|
* Reject a paused execution's pending action, ending the run. The
|
|
2607
3107
|
* transcript's paused output is replaced with
|
|
@@ -2611,6 +3111,13 @@ declare class Think<
|
|
|
2611
3111
|
* Client-callable.
|
|
2612
3112
|
*/
|
|
2613
3113
|
rejectExecution(executionId: string, reason?: string): Promise<unknown>;
|
|
3114
|
+
/**
|
|
3115
|
+
* Reject a parked `kind: "durable-pause"` action. Claim-by-delete consumes
|
|
3116
|
+
* the pending row (idempotent across tabs/recovery), the action's `execute`
|
|
3117
|
+
* never runs, and the paused transcript part is replaced with a `rejected`
|
|
3118
|
+
* outcome so the model can adapt or explain.
|
|
3119
|
+
*/
|
|
3120
|
+
private _rejectActionPause;
|
|
2614
3121
|
/**
|
|
2615
3122
|
* Replace a paused execute-tool output in the transcript with the
|
|
2616
3123
|
* execution's new outcome and kick the auto-continuation so the model sees
|
|
@@ -2639,6 +3146,14 @@ declare class Think<
|
|
|
2639
3146
|
private _findExecutionToolCall;
|
|
2640
3147
|
private _applyToolUpdateToMessages;
|
|
2641
3148
|
protected hasPendingInteraction(): boolean;
|
|
3149
|
+
/**
|
|
3150
|
+
* `true` when an auto-continuation is armed but has not yet fired (#1650): a
|
|
3151
|
+
* pending continuation that has not entered its turn (`!pastCoalesce`) whose
|
|
3152
|
+
* coalesce timer is still pending or whose completeness drain is in progress.
|
|
3153
|
+
* Mirrors `@cloudflare/ai-chat`'s `_hasArmedContinuation`, consuming the shared
|
|
3154
|
+
* controller's `isArmed()`.
|
|
3155
|
+
*/
|
|
3156
|
+
private _hasArmedContinuation;
|
|
2642
3157
|
protected waitUntilStable(options?: { timeout?: number }): Promise<boolean>;
|
|
2643
3158
|
private _awaitWithDeadline;
|
|
2644
3159
|
private _messageHasPendingInteraction;
|
|
@@ -2651,8 +3166,6 @@ declare class Think<
|
|
|
2651
3166
|
* ever post its result.
|
|
2652
3167
|
*/
|
|
2653
3168
|
private _clientResolvableToolNames;
|
|
2654
|
-
/** Extract a tool part's name from its `tool-<name>` / `dynamic-tool` shape. */
|
|
2655
|
-
private _toolPartName;
|
|
2656
3169
|
/**
|
|
2657
3170
|
* Whether a part is still awaiting a CLIENT interaction that can genuinely
|
|
2658
3171
|
* arrive after a restart, so `waitUntilStable` must keep waiting for it:
|
|
@@ -2675,8 +3188,6 @@ declare class Think<
|
|
|
2675
3188
|
*/
|
|
2676
3189
|
private _partAwaitsClientInteraction;
|
|
2677
3190
|
private _resolveChatRecoveryConfig;
|
|
2678
|
-
private _chatRecoveryIncidentId;
|
|
2679
|
-
private _chatRecoveryIncidentKey;
|
|
2680
3191
|
/**
|
|
2681
3192
|
* Monotonic forward-progress signal for recovery budget resets.
|
|
2682
3193
|
*
|
|
@@ -2692,12 +3203,13 @@ declare class Think<
|
|
|
2692
3203
|
*/
|
|
2693
3204
|
private _chatRecoveryProgressMarker;
|
|
2694
3205
|
/** Advance the durable recovery-progress counter. Called from
|
|
2695
|
-
* `_storeChunkDurably` when
|
|
2696
|
-
* immune forward progress).
|
|
3206
|
+
* `_storeChunkDurably` when a stored chunk credits forward progress under the
|
|
3207
|
+
* shared rule (real, reconnect-immune forward progress). The increment lives
|
|
3208
|
+
* in the shared engine (agents/chat); this is the package binding. */
|
|
2697
3209
|
private _bumpChatRecoveryProgress;
|
|
2698
|
-
/**
|
|
2699
|
-
* isolate so the first forwarded chunk after a restart always credits
|
|
2700
|
-
private
|
|
3210
|
+
/** Per-isolate N9 throttle gate (shared `agents/chat` helper); reset per
|
|
3211
|
+
* isolate so the first forwarded chunk after a restart always credits. */
|
|
3212
|
+
private _agentToolStreamProgress;
|
|
2701
3213
|
/**
|
|
2702
3214
|
* N9: forwarding a sub-agent's chunks IS forward progress for this parent
|
|
2703
3215
|
* turn, so credit the parent's recovery progress marker — otherwise a parent
|
|
@@ -2708,10 +3220,15 @@ declare class Think<
|
|
|
2708
3220
|
* Throttled (and reset per isolate) so we never write storage per token.
|
|
2709
3221
|
*/
|
|
2710
3222
|
protected _onAgentToolStreamProgress(): Promise<void>;
|
|
2711
|
-
/** Sweep recovery incidents that have been inactive past the TTL. */
|
|
2712
|
-
private _sweepStaleChatRecoveryIncidents;
|
|
2713
3223
|
private _beginChatRecoveryIncident;
|
|
2714
|
-
|
|
3224
|
+
/**
|
|
3225
|
+
* Lazily-built shared recovery engine. The adapter arrows capture `this`, so a
|
|
3226
|
+
* single cached instance is correct across calls (and across future engine
|
|
3227
|
+
* methods).
|
|
3228
|
+
*/
|
|
3229
|
+
private _chatRecoveryEngineInstance?;
|
|
3230
|
+
private _chatRecoveryEngine;
|
|
3231
|
+
private _updateChatRecoveryIncident;
|
|
2715
3232
|
private _exhaustChatRecovery;
|
|
2716
3233
|
/**
|
|
2717
3234
|
* Route a stream-stall watchdog abort into bounded recovery instead of a
|
|
@@ -2740,6 +3257,31 @@ declare class Think<
|
|
|
2740
3257
|
protected _handleInternalFiberRecovery(
|
|
2741
3258
|
ctx: FiberRecoveryContext
|
|
2742
3259
|
): Promise<boolean>;
|
|
3260
|
+
/**
|
|
3261
|
+
* Resolve the orphaned stream + its terminal status for a recovered chat turn.
|
|
3262
|
+
* Drives BOTH the wake path (full result) and the give-up terminalization
|
|
3263
|
+
* (which reads only `.streamId`; the terminal banner still fires when
|
|
3264
|
+
* `streamId` is `""` — `_exhaustChatRecovery` does not require a stream).
|
|
3265
|
+
* Prefers the newest durable stream row keyed by the recovery-root request id;
|
|
3266
|
+
* falls back to the live active stream.
|
|
3267
|
+
*/
|
|
3268
|
+
private _resolveThinkRecoveryStream;
|
|
3269
|
+
/**
|
|
3270
|
+
* Classify a recovered turn as `retry` or `continue`. A pre-stream turn with no
|
|
3271
|
+
* partial re-runs its user message (`retryTargetUserId`), unless the stream is
|
|
3272
|
+
* already terminal — a terminal stream is never retried (it completed), only
|
|
3273
|
+
* its submission is reconciled in dispatch.
|
|
3274
|
+
*/
|
|
3275
|
+
private _classifyRecoveredThinkTurn;
|
|
3276
|
+
/**
|
|
3277
|
+
* The retry/continue/skip decision for a recovered chat turn, run after the
|
|
3278
|
+
* partial is persisted and the stream completed. Owns `Think`'s substrate
|
|
3279
|
+
* behavior the engine frame stays out of: a terminal stream reconciles the
|
|
3280
|
+
* durable submission (and is never retried/continued), and a `continue: false`
|
|
3281
|
+
* abandonment marks the submission interrupted + records a terminal status +
|
|
3282
|
+
* broadcasts so a reconnecting client is not frozen.
|
|
3283
|
+
*/
|
|
3284
|
+
private _dispatchRecoveredThinkTurn;
|
|
2743
3285
|
private _recoverablePreStreamUserId;
|
|
2744
3286
|
private _hasPersistedRecoveredAssistant;
|
|
2745
3287
|
/**
|
|
@@ -2750,10 +3292,6 @@ declare class Think<
|
|
|
2750
3292
|
* an earlier attempt already saved.
|
|
2751
3293
|
*/
|
|
2752
3294
|
private _shouldPersistOrphanedPartial;
|
|
2753
|
-
/** Whether a reconstructed partial carries any settled (provider-accepted)
|
|
2754
|
-
* tool result — the completed, often non-idempotent work that a
|
|
2755
|
-
* `{ persist: false }` recovery return would silently discard. */
|
|
2756
|
-
private _partialHasSettledToolResults;
|
|
2757
3295
|
/**
|
|
2758
3296
|
* Reschedule a recovery callback that timed out waiting for stable state,
|
|
2759
3297
|
* consuming one attempt. Returns `true` if rescheduled, `false` if the
|
|
@@ -2804,14 +3342,6 @@ declare class Think<
|
|
|
2804
3342
|
* reschedule / exhaustion path).
|
|
2805
3343
|
*/
|
|
2806
3344
|
private _parkRecoveryForPendingInteraction;
|
|
2807
|
-
/**
|
|
2808
|
-
* Resolve the stream id for a recovery turn so the give-up terminalization
|
|
2809
|
-
* can surface whatever partial the turn produced. Prefers the durable stream
|
|
2810
|
-
* row keyed by the recovery-root request id; falls back to the live active
|
|
2811
|
-
* stream. Returns `""` when neither is available (the terminal banner still
|
|
2812
|
-
* fires — `_exhaustChatRecovery` does not require a stream).
|
|
2813
|
-
*/
|
|
2814
|
-
private _resolveRecoveryStreamId;
|
|
2815
3345
|
/**
|
|
2816
3346
|
* Terminalize a recovery turn that is giving up — whether because the
|
|
2817
3347
|
* stable-state-timeout retry budget drained, or because the recovery
|
|
@@ -2857,6 +3387,19 @@ declare class Think<
|
|
|
2857
3387
|
* broadcast — the deferred re-run re-fires `onExhausted` + the banner
|
|
2858
3388
|
* (the terminal writes themselves are idempotent).
|
|
2859
3389
|
*/
|
|
3390
|
+
/**
|
|
3391
|
+
* Recovery continuation callbacks the alarm-boundary OOM circuit breaker may
|
|
3392
|
+
* back off / purge (#1825). See `Agent._cf_handleAlarmMemoryLimitReset`.
|
|
3393
|
+
*/
|
|
3394
|
+
protected _cf_recoveryAlarmCallbacks(): string[];
|
|
3395
|
+
/**
|
|
3396
|
+
* Seal any still-live recovery incident as an out-of-memory exhaustion when
|
|
3397
|
+
* the alarm circuit breaker trips at its strike budget (#1825). Runs at the
|
|
3398
|
+
* outermost alarm frame (post-unwind), so the terminal banner / `onExhausted`
|
|
3399
|
+
* and the sealed-incident write can land where the mid-turn give-up's writes
|
|
3400
|
+
* OOMed. Reuses the shared give-up spine via `_exhaustRecoveryGiveUp`.
|
|
3401
|
+
*/
|
|
3402
|
+
protected _cf_sealMemoryLimitedRecovery(): Promise<void>;
|
|
2860
3403
|
private _exhaustRecoveryGiveUp;
|
|
2861
3404
|
/**
|
|
2862
3405
|
* Give-up after the stable-state-timeout retry budget drained. Thin wrapper
|
|
@@ -2864,6 +3407,30 @@ declare class Think<
|
|
|
2864
3407
|
* `stable_timeout`.
|
|
2865
3408
|
*/
|
|
2866
3409
|
private _exhaustRecoveryAfterStableTimeout;
|
|
3410
|
+
/**
|
|
3411
|
+
* Apply the tight OOM-retry budget to a recovery error (#1825). Invoked from
|
|
3412
|
+
* `_handleRecoveryCallbackError`, i.e. for an OOM that is *thrown* out of a
|
|
3413
|
+
* recovery turn (typically from recovery bookkeeping or storage/SQL ops that
|
|
3414
|
+
* reject with the memory-limit-reset message after an isolate reset). An OOM
|
|
3415
|
+
* that surfaces as a returned `error` result means `continueLastTurn` already
|
|
3416
|
+
* terminalized the turn (client error frame + `onError`), so it is NOT routed
|
|
3417
|
+
* here — re-driving a terminalized turn would be wasteful and risk a second
|
|
3418
|
+
* terminal signal. `error` may be an Error or a wrapper with a `cause` chain.
|
|
3419
|
+
*
|
|
3420
|
+
* The reliable terminator is the begin-path (`evaluateChatRecoveryIncident`),
|
|
3421
|
+
* which seals once `oomAttempts` exceeds the budget; that runs before the
|
|
3422
|
+
* memory-heavy turn, in the low-memory window where writes succeed. This
|
|
3423
|
+
* method's job is to persist `oomAttempts` (small writes) so the begin path
|
|
3424
|
+
* can act on it, and to schedule a delayed re-run while under budget.
|
|
3425
|
+
*
|
|
3426
|
+
* Returns `true` when the error was an OOM and this method owns the outcome:
|
|
3427
|
+
* - under budget → a delayed re-run was scheduled (best-effort: a transient
|
|
3428
|
+
* spike may clear);
|
|
3429
|
+
* - over budget (or untrackable, or the bookkeeping itself OOMed) →
|
|
3430
|
+
* terminalized via the give-up path with `reason="out_of_memory"`.
|
|
3431
|
+
* Returns `false` for non-OOM errors so the caller proceeds normally.
|
|
3432
|
+
*/
|
|
3433
|
+
private _handleRecoveryOom;
|
|
2867
3434
|
/**
|
|
2868
3435
|
* Handle an error thrown by `_chatRecoveryContinue` / `_chatRecoveryRetry`
|
|
2869
3436
|
* after the incident was opened.
|
|
@@ -2905,6 +3472,15 @@ declare class Think<
|
|
|
2905
3472
|
private _getPartialStreamText;
|
|
2906
3473
|
private _getSubmitConcurrencyDecision;
|
|
2907
3474
|
private _completeSkippedRequest;
|
|
3475
|
+
/**
|
|
3476
|
+
* Mark an accepted turn (#1784) as settled. When `releaseParked` (the default)
|
|
3477
|
+
* and no accepted turn remains in flight and no stream is active, release every
|
|
3478
|
+
* connection parked on the pre-stream window with STREAM_RESUME_NONE. No-op once
|
|
3479
|
+
* they were flushed into STREAM_RESUMING on stream start. Skip paths pass
|
|
3480
|
+
* `releaseParked: false` so a parked client survives onto the successor turn
|
|
3481
|
+
* (see `_completeSkippedRequest`).
|
|
3482
|
+
*/
|
|
3483
|
+
private _settlePreStreamTurn;
|
|
2908
3484
|
private _rollbackDroppedSubmit;
|
|
2909
3485
|
private _scheduleAutoContinuation;
|
|
2910
3486
|
/**
|
|
@@ -2934,35 +3510,6 @@ declare class Think<
|
|
|
2934
3510
|
* to hold (event-driven) until its remaining siblings answer.
|
|
2935
3511
|
*/
|
|
2936
3512
|
private _onStreamingTurnFinalized;
|
|
2937
|
-
private _resetAutoContinuationTimer;
|
|
2938
|
-
/**
|
|
2939
|
-
* Fire an auto-continuation, but only once the model's parallel tool-call
|
|
2940
|
-
* batch is fully answered (#1649). When the model emits several tool calls in
|
|
2941
|
-
* one step the client answers each independently, so the first `autoContinue`
|
|
2942
|
-
* arrives while slower siblings are still `input-available`. Continuing then
|
|
2943
|
-
* would feed the provider an incomplete tool-result set
|
|
2944
|
-
* (`MissingToolResultsError`) or, via the transcript-repair backstop, silently
|
|
2945
|
-
* error the in-flight sibling and run a spurious extra continuation.
|
|
2946
|
-
*
|
|
2947
|
-
* The barrier is event-driven (#1650). Auto-continuation is only ever
|
|
2948
|
-
* triggered by a tool-result/approval event, so rather than wait on a fixed
|
|
2949
|
-
* timer we drain the in-flight applies, re-check, and — if the batch is still
|
|
2950
|
-
* incomplete — return WITHOUT firing and WITHOUT holding the isolate, leaving
|
|
2951
|
-
* `_continuation.pending` in place. The next sibling's result re-arms the
|
|
2952
|
-
* coalesce timer (`_scheduleAutoContinuation`) and re-runs this check; the
|
|
2953
|
-
* continuation fires once the final sibling lands. If the in-memory pending
|
|
2954
|
-
* state is lost to eviction between siblings, the final result re-creates it
|
|
2955
|
-
* from the persisted transcript and fires with a complete batch — self-healing.
|
|
2956
|
-
* A true orphan (a sibling that never arrives) simply never auto-continues,
|
|
2957
|
-
* which is correct: there is nothing valid to continue, and a later user turn
|
|
2958
|
-
* / chat recovery repairs the transcript.
|
|
2959
|
-
*
|
|
2960
|
-
* The barrier also holds while the assistant turn is still streaming (the
|
|
2961
|
-
* stream-active gate below): mid-stream the batch can still grow with tool
|
|
2962
|
-
* calls the model hasn't emitted yet, so no completeness check is meaningful.
|
|
2963
|
-
* `_onStreamingTurnFinalized` re-runs the check once the stream ends.
|
|
2964
|
-
*/
|
|
2965
|
-
private _fireAutoContinuationWhenStable;
|
|
2966
3513
|
/**
|
|
2967
3514
|
* Drain every in-flight tool-result/approval apply, including any enqueued
|
|
2968
3515
|
* while we wait, so the subsequent `_hasIncompleteToolBatch()` re-check sees
|
|
@@ -2984,6 +3531,38 @@ declare class Think<
|
|
|
2984
3531
|
private _hasIncompleteToolBatch;
|
|
2985
3532
|
private _fireAutoContinuation;
|
|
2986
3533
|
private _activateDeferredContinuation;
|
|
3534
|
+
/**
|
|
3535
|
+
* Run a continuation turn that does NOT require a live client connection.
|
|
3536
|
+
*
|
|
3537
|
+
* Used when a durable approval (a paused action or codemode execution) is
|
|
3538
|
+
* resolved via RPC from a surface with no open chat socket — e.g. an ops
|
|
3539
|
+
* dashboard, a webhook, or a voice backend approving hours/days later. The
|
|
3540
|
+
* connection-bound auto-continuation barrier (`_fireAutoContinuation`) cannot
|
|
3541
|
+
* fire without a `Connection`, so this mirrors its turn body but streams via
|
|
3542
|
+
* `broadcast` (a no-op when nobody is attached) and always persists, so a
|
|
3543
|
+
* client that reconnects later resumes the continued turn from history.
|
|
3544
|
+
*
|
|
3545
|
+
* Wrapped in `keepAliveWhile` because the resolving RPC returns before the
|
|
3546
|
+
* continuation finishes (mirrors the submission-drain pattern).
|
|
3547
|
+
*/
|
|
3548
|
+
private _runConnectionlessContinuation;
|
|
3549
|
+
/**
|
|
3550
|
+
* Render a reply attachment ({@link ReplyAttachment}) for delivery to the
|
|
3551
|
+
* active channel. Returns the text/markdown to post, or `undefined` to skip —
|
|
3552
|
+
* unknown types, or types a channel handles out of band (e.g. `voice_note`
|
|
3553
|
+
* via the voice transport). Override to customize per app/channel.
|
|
3554
|
+
*/
|
|
3555
|
+
renderAttachment(attachment: ReplyAttachment):
|
|
3556
|
+
| string
|
|
3557
|
+
| {
|
|
3558
|
+
markdown: string;
|
|
3559
|
+
}
|
|
3560
|
+
| undefined;
|
|
3561
|
+
/**
|
|
3562
|
+
* Deliver known reply attachments to the active channel (best-effort, never
|
|
3563
|
+
* fails the turn). Unknown types are ignored.
|
|
3564
|
+
*/
|
|
3565
|
+
private _renderChannelAttachments;
|
|
2987
3566
|
private _fireResponseHook;
|
|
2988
3567
|
/**
|
|
2989
3568
|
* Persist (on `error`/`interrupted`) or clear (on `completed`/`aborted`) the
|
|
@@ -3007,23 +3586,6 @@ declare class Think<
|
|
|
3007
3586
|
/** Clear the durable terminal record once a later turn supersedes it (#1645). */
|
|
3008
3587
|
private _clearChatTerminal;
|
|
3009
3588
|
private _pendingChatTerminal;
|
|
3010
|
-
/**
|
|
3011
|
-
* Replay a pending terminal outcome (#1645) over the resume handshake so a
|
|
3012
|
-
* reconnecting client surfaces it exactly like a live exhaustion. A bare
|
|
3013
|
-
* terminal frame sent on connect is dropped by the `useAgentChat` client
|
|
3014
|
-
* because it never reaches a transport stream reader; only a frame delivered
|
|
3015
|
-
* on a resumed stream becomes `useChat.error` (this is why the terminal is
|
|
3016
|
-
* NOT included in `_buildIdleConnectMessages`). So we drive `STREAM_RESUMING`
|
|
3017
|
-
* here and send the error frame once the client ACKs (see
|
|
3018
|
-
* `_replayTerminalOnAck`). Returns true if a terminal was pending.
|
|
3019
|
-
*/
|
|
3020
|
-
private _replayTerminalOnResume;
|
|
3021
|
-
/**
|
|
3022
|
-
* Deliver the pending terminal error frame on the resumed stream the client
|
|
3023
|
-
* ACKed (#1645). The record is retained (cleared only when a later turn
|
|
3024
|
-
* supersedes it) so concurrent reconnects each learn the outcome.
|
|
3025
|
-
*/
|
|
3026
|
-
private _replayTerminalOnAck;
|
|
3027
3589
|
/**
|
|
3028
3590
|
* Set or clear the live "recovering…" status for a durable chat turn (#1620).
|
|
3029
3591
|
* Persists a durable record (replayed on connect via `_buildIdleConnectMessages`)
|
|
@@ -3041,11 +3603,25 @@ declare class Think<
|
|
|
3041
3603
|
* `MSG_CHAT_RESPONSE` frame on connect is dropped by the `useAgentChat`
|
|
3042
3604
|
* client because it never reaches a transport stream reader, so it cannot
|
|
3043
3605
|
* become `useChat.error` — a failed turn would still look frozen (#1645).
|
|
3044
|
-
* The terminal outcome is instead surfaced over the resume handshake
|
|
3045
|
-
*
|
|
3046
|
-
* that lands on the stream reader.
|
|
3606
|
+
* The terminal outcome is instead surfaced over the resume handshake (the
|
|
3607
|
+
* shared {@link ResumeHandshake} drives `STREAM_RESUMING` → ACK → terminal
|
|
3608
|
+
* error frame), the only path that lands on the stream reader.
|
|
3047
3609
|
*/
|
|
3048
3610
|
private _buildIdleConnectMessages;
|
|
3611
|
+
/**
|
|
3612
|
+
* The shared resume-handshake driver (Tier-2). Lazily built; the
|
|
3613
|
+
* `ResumableStream` / `ContinuationState` / pending set are stable after
|
|
3614
|
+
* `onStart`, so a single instance threads them for the agent's lifetime. The
|
|
3615
|
+
* idle-connect payload (transcript + recovering, `_buildIdleConnectMessages`)
|
|
3616
|
+
* stays host-owned and is NOT part of the driver.
|
|
3617
|
+
*/
|
|
3618
|
+
private _resumeHandshake;
|
|
3619
|
+
/**
|
|
3620
|
+
* Notify a connection about an active stream that can be resumed — delegates
|
|
3621
|
+
* to the shared {@link ResumeHandshake}. Kept as a thin method because it is
|
|
3622
|
+
* also called proactively from onConnect and the broadcast loop. See the
|
|
3623
|
+
* driver for the #1733 double-send contract.
|
|
3624
|
+
*/
|
|
3049
3625
|
private _notifyStreamResuming;
|
|
3050
3626
|
/**
|
|
3051
3627
|
* Start a resumable stream and arm buffer cleanup. Wrapper around
|
|
@@ -3094,8 +3670,8 @@ declare class Think<
|
|
|
3094
3670
|
idempotent?: boolean;
|
|
3095
3671
|
}): Promise<void>;
|
|
3096
3672
|
/**
|
|
3097
|
-
* Alarm callback: sweep aged stream buffers,
|
|
3098
|
-
*
|
|
3673
|
+
* Alarm callback: sweep aged stream buffers, re-arming while rows remain (see
|
|
3674
|
+
* the shared {@link cleanupStreamBuffers}).
|
|
3099
3675
|
*/
|
|
3100
3676
|
_cleanupStreamBuffers(): Promise<void>;
|
|
3101
3677
|
private _persistOrphanedStream;
|
|
@@ -3104,121 +3680,543 @@ declare class Think<
|
|
|
3104
3680
|
private _broadcastMessages;
|
|
3105
3681
|
}
|
|
3106
3682
|
//#endregion
|
|
3683
|
+
//#region src/messengers/events.d.ts
|
|
3684
|
+
type MessengerEventKind =
|
|
3685
|
+
| "direct-message"
|
|
3686
|
+
| "mention"
|
|
3687
|
+
| "subscribed-message"
|
|
3688
|
+
| "action"
|
|
3689
|
+
| "delivery-event";
|
|
3690
|
+
interface MessengerAuthor {
|
|
3691
|
+
fullName?: string;
|
|
3692
|
+
isBot?: boolean | "unknown";
|
|
3693
|
+
isMe?: boolean;
|
|
3694
|
+
userId: string;
|
|
3695
|
+
userName?: string;
|
|
3696
|
+
}
|
|
3697
|
+
interface MessengerAttachment {
|
|
3698
|
+
data?: ArrayBuffer;
|
|
3699
|
+
fetch?: () => Promise<ArrayBuffer>;
|
|
3700
|
+
id?: string;
|
|
3701
|
+
mediaType?: string;
|
|
3702
|
+
name?: string;
|
|
3703
|
+
raw?: unknown;
|
|
3704
|
+
size?: number;
|
|
3705
|
+
text?: string;
|
|
3706
|
+
url?: string;
|
|
3707
|
+
}
|
|
3708
|
+
interface MessengerThread {
|
|
3709
|
+
channelId?: string;
|
|
3710
|
+
channelName?: string;
|
|
3711
|
+
id: string;
|
|
3712
|
+
isDirectMessage: boolean;
|
|
3713
|
+
providerThreadId: string;
|
|
3714
|
+
title?: string;
|
|
3715
|
+
}
|
|
3716
|
+
interface MessengerMessage {
|
|
3717
|
+
attachments: MessengerAttachment[];
|
|
3718
|
+
author: MessengerAuthor;
|
|
3719
|
+
createdAt?: Date;
|
|
3720
|
+
id: string;
|
|
3721
|
+
isMention?: boolean;
|
|
3722
|
+
providerMessageId: string;
|
|
3723
|
+
raw?: unknown;
|
|
3724
|
+
text: string;
|
|
3725
|
+
}
|
|
3726
|
+
interface MessengerAction {
|
|
3727
|
+
actionId: string;
|
|
3728
|
+
messageId?: string;
|
|
3729
|
+
raw?: unknown;
|
|
3730
|
+
user?: MessengerAuthor;
|
|
3731
|
+
value?: string;
|
|
3732
|
+
}
|
|
3733
|
+
interface MessengerCapabilities {
|
|
3734
|
+
canEditMessages?: boolean;
|
|
3735
|
+
canStream?: boolean;
|
|
3736
|
+
maxMessageLength?: number;
|
|
3737
|
+
supportsActions?: boolean;
|
|
3738
|
+
supportsAttachments?: boolean;
|
|
3739
|
+
supportsEphemeral?: boolean;
|
|
3740
|
+
}
|
|
3741
|
+
interface MessengerContext {
|
|
3742
|
+
action?: MessengerAction;
|
|
3743
|
+
author?: MessengerAuthor;
|
|
3744
|
+
capabilities: MessengerCapabilities;
|
|
3745
|
+
kind: MessengerEventKind;
|
|
3746
|
+
message?: MessengerMessage;
|
|
3747
|
+
messengerId: string;
|
|
3748
|
+
provider: string;
|
|
3749
|
+
thread: MessengerThread;
|
|
3750
|
+
}
|
|
3751
|
+
interface MessengerEvent extends MessengerContext {
|
|
3752
|
+
raw?: unknown;
|
|
3753
|
+
}
|
|
3754
|
+
declare function messengerContextFromEvent(
|
|
3755
|
+
event: MessengerEvent
|
|
3756
|
+
): MessengerContext;
|
|
3757
|
+
declare function serializableMessengerEvent(
|
|
3758
|
+
event: MessengerEvent
|
|
3759
|
+
): MessengerEvent;
|
|
3760
|
+
declare function toMessengerUserMessage(event: MessengerEvent): UIMessage;
|
|
3761
|
+
//#endregion
|
|
3762
|
+
//#region src/messengers/delivery.d.ts
|
|
3763
|
+
declare const MESSENGER_REPLY_FIBER_NAME = "think:messenger-reply";
|
|
3764
|
+
declare const EMPTY_MESSENGER_RESPONSE =
|
|
3765
|
+
"I couldn't produce a text response. Please try again.";
|
|
3766
|
+
declare const ERROR_MESSENGER_RESPONSE =
|
|
3767
|
+
"Sorry, I couldn't answer that right now. Please try again.";
|
|
3768
|
+
declare const INTERRUPTED_MESSENGER_RESPONSE =
|
|
3769
|
+
"Sorry, my reply was interrupted. Please send your message again if you'd like me to retry.";
|
|
3770
|
+
interface TextStreamCallbackOptions {
|
|
3771
|
+
onVisibleStart?: () => Promise<void> | void;
|
|
3772
|
+
visibleSoftLimit?: number;
|
|
3773
|
+
}
|
|
3774
|
+
declare class TextStreamCallback extends RpcTarget implements StreamCallback {
|
|
3775
|
+
private readonly onVisibleStart?;
|
|
3776
|
+
private readonly visibleChunks;
|
|
3777
|
+
private readonly wakeups;
|
|
3778
|
+
private readonly visibleSoftLimit?;
|
|
3779
|
+
private chatRequestId?;
|
|
3780
|
+
private closed;
|
|
3781
|
+
private interrupted;
|
|
3782
|
+
private error?;
|
|
3783
|
+
private text;
|
|
3784
|
+
private visibleClosed;
|
|
3785
|
+
private visibleLimitReachedValue;
|
|
3786
|
+
private visibleStarted;
|
|
3787
|
+
private visibleTextValue;
|
|
3788
|
+
constructor(options?: TextStreamCallbackOptions);
|
|
3789
|
+
onStart(event: ChatStartEvent): void;
|
|
3790
|
+
onEvent(json: string): void;
|
|
3791
|
+
onDone(): void;
|
|
3792
|
+
onError(error: string): void;
|
|
3793
|
+
onInterrupted(): void;
|
|
3794
|
+
wasInterrupted(): boolean;
|
|
3795
|
+
close(): void;
|
|
3796
|
+
fail(error: unknown): void;
|
|
3797
|
+
hasText(): boolean;
|
|
3798
|
+
remainingText(): string;
|
|
3799
|
+
requestId(): string | undefined;
|
|
3800
|
+
textSoFar(): string;
|
|
3801
|
+
visibleLimitReached(): boolean;
|
|
3802
|
+
visibleText(): string;
|
|
3803
|
+
stream(): AsyncIterable<string>;
|
|
3804
|
+
private pushVisibleText;
|
|
3805
|
+
private wake;
|
|
3806
|
+
private markVisibleStarted;
|
|
3807
|
+
}
|
|
3808
|
+
declare function textDeltaFromStreamChunk(json: string): string | null;
|
|
3809
|
+
type MessengerReplyStage = "accepted" | "streaming" | "completed";
|
|
3810
|
+
/**
|
|
3811
|
+
* Explicit delivery lifecycle kind, orthogonal to {@link MessengerReplyStage}.
|
|
3812
|
+
* Lets surfaces (voice/CLI especially) tell a final answer from an interim
|
|
3813
|
+
* progress note from a deterministic notice from a control command, rather than
|
|
3814
|
+
* inferring from text shape.
|
|
3815
|
+
*/
|
|
3816
|
+
type DeliveryKind = "final" | "interim" | "notice" | "command";
|
|
3817
|
+
/**
|
|
3818
|
+
* Explicit delivery lifecycle tag carried on the wire/snapshot. Orthogonal to,
|
|
3819
|
+
* and additive on top of, {@link MessengerReplyStage}: recovery still switches
|
|
3820
|
+
* on `stage`, while `kind`/`turnEnded` give non-streaming-text surfaces
|
|
3821
|
+
* (voice/CLI) an explicit signal instead of inferring from text shape.
|
|
3822
|
+
*/
|
|
3823
|
+
interface DeliveryTag {
|
|
3824
|
+
stage: MessengerReplyStage;
|
|
3825
|
+
kind: DeliveryKind;
|
|
3826
|
+
turnEnded: boolean;
|
|
3827
|
+
}
|
|
3828
|
+
/** Derive a sensible default tag from a reply stage. */
|
|
3829
|
+
declare function defaultDeliveryTag(stage: MessengerReplyStage): DeliveryTag;
|
|
3830
|
+
interface MessengerReplySnapshot {
|
|
3831
|
+
event: MessengerEvent;
|
|
3832
|
+
stage: MessengerReplyStage;
|
|
3833
|
+
tag?: DeliveryTag;
|
|
3834
|
+
thread?: unknown;
|
|
3835
|
+
type: typeof MESSENGER_REPLY_FIBER_NAME;
|
|
3836
|
+
}
|
|
3837
|
+
declare function messengerReplySnapshot(
|
|
3838
|
+
stage: MessengerReplyStage,
|
|
3839
|
+
event: MessengerEvent,
|
|
3840
|
+
thread?: unknown,
|
|
3841
|
+
tag?: DeliveryTag
|
|
3842
|
+
): MessengerReplySnapshot;
|
|
3843
|
+
declare function parseMessengerReplySnapshot(
|
|
3844
|
+
snapshot: unknown
|
|
3845
|
+
): MessengerReplySnapshot | null;
|
|
3846
|
+
declare function messengerReplyRecoveryMode(
|
|
3847
|
+
snapshot: MessengerReplySnapshot
|
|
3848
|
+
): "answer" | "apologize" | null;
|
|
3849
|
+
declare function messengerReplyFailureMode(
|
|
3850
|
+
hasStreamedText: boolean,
|
|
3851
|
+
completedModelTurn?: boolean,
|
|
3852
|
+
expectedDeliveryCompletion?: boolean
|
|
3853
|
+
): "apologize" | "error" | null;
|
|
3854
|
+
interface MessengerDeliveryTarget {
|
|
3855
|
+
cancelChat(
|
|
3856
|
+
requestId: string,
|
|
3857
|
+
reason?: string
|
|
3858
|
+
): boolean | void | Promise<boolean | void>;
|
|
3859
|
+
chat(
|
|
3860
|
+
userMessage: string | UIMessage,
|
|
3861
|
+
callback: StreamCallback
|
|
3862
|
+
): Promise<void>;
|
|
3863
|
+
chatWithMessengerContext?(
|
|
3864
|
+
userMessage: string | UIMessage,
|
|
3865
|
+
callback: StreamCallback,
|
|
3866
|
+
context: MessengerEvent
|
|
3867
|
+
): Promise<void>;
|
|
3868
|
+
/**
|
|
3869
|
+
* Bind the live delivery surface for the duration of the model turn so the
|
|
3870
|
+
* target can reach it from `deliverNotice` while a messenger turn is active.
|
|
3871
|
+
* Returns a restore function (save/restore, so nested turns are safe).
|
|
3872
|
+
*/
|
|
3873
|
+
bindActiveDeliverySurface?(surface: MessengerDeliverySurface): () => void;
|
|
3874
|
+
}
|
|
3875
|
+
interface MessengerDeliverySurface {
|
|
3876
|
+
post(
|
|
3877
|
+
message:
|
|
3878
|
+
| string
|
|
3879
|
+
| {
|
|
3880
|
+
markdown: string;
|
|
3881
|
+
}
|
|
3882
|
+
| AsyncIterable<string>
|
|
3883
|
+
): Promise<unknown>;
|
|
3884
|
+
startTyping?(status?: string): Promise<void>;
|
|
3885
|
+
}
|
|
3886
|
+
interface MessengerDeliveryPolicy {
|
|
3887
|
+
emptyResponseText?: string;
|
|
3888
|
+
errorResponseText?: string;
|
|
3889
|
+
interruptedResponseText?: string;
|
|
3890
|
+
isExpectedDeliveryCompletion?(
|
|
3891
|
+
error: unknown,
|
|
3892
|
+
callback: TextStreamCallback
|
|
3893
|
+
): boolean;
|
|
3894
|
+
splitText?(text: string): string[];
|
|
3895
|
+
visibleSoftLimit?: number;
|
|
3896
|
+
}
|
|
3897
|
+
interface DeliverMessengerReplyOptions {
|
|
3898
|
+
checkpoint?: (snapshot: MessengerReplySnapshot) => Promise<void> | void;
|
|
3899
|
+
event: MessengerEvent;
|
|
3900
|
+
fiber?: FiberContext;
|
|
3901
|
+
policy?: MessengerDeliveryPolicy;
|
|
3902
|
+
snapshotEvent?: MessengerEvent;
|
|
3903
|
+
snapshotThread?: unknown;
|
|
3904
|
+
surface: MessengerDeliverySurface;
|
|
3905
|
+
target: MessengerDeliveryTarget;
|
|
3906
|
+
userMessage?: UIMessage;
|
|
3907
|
+
}
|
|
3908
|
+
declare function deliverMessengerReply(
|
|
3909
|
+
options: DeliverMessengerReplyOptions
|
|
3910
|
+
): Promise<void>;
|
|
3911
|
+
//#endregion
|
|
3912
|
+
//#region src/messengers/chat-sdk.d.ts
|
|
3913
|
+
declare class ThinkMessengerStateAgent extends ChatSdkStateAgent {}
|
|
3914
|
+
type MessengerRespondTo =
|
|
3915
|
+
| "action"
|
|
3916
|
+
| "direct-message"
|
|
3917
|
+
| "mention"
|
|
3918
|
+
| "subscribed-thread";
|
|
3919
|
+
type MessengerConversationMode = "self" | "thread";
|
|
3920
|
+
type MessengerConversationTarget =
|
|
3921
|
+
| {
|
|
3922
|
+
target: "self";
|
|
3923
|
+
}
|
|
3924
|
+
| {
|
|
3925
|
+
agentClass?: SubAgentClass<Agent & MessengerThinkTarget>;
|
|
3926
|
+
name: string;
|
|
3927
|
+
target: "subagent";
|
|
3928
|
+
};
|
|
3929
|
+
type MessengerConversationResolver = (
|
|
3930
|
+
event: MessengerEvent
|
|
3931
|
+
) => MessengerConversationTarget | Promise<MessengerConversationTarget>;
|
|
3932
|
+
interface MessengerDefinition {
|
|
3933
|
+
adapter: Adapter;
|
|
3934
|
+
adapterName: string;
|
|
3935
|
+
capabilities?: MessengerCapabilities;
|
|
3936
|
+
conversation?: MessengerConversationMode | MessengerConversationResolver;
|
|
3937
|
+
delivery?: MessengerDeliveryPolicy;
|
|
3938
|
+
keyShard?: ChatSdkStateAdapterOptions["keyShard"];
|
|
3939
|
+
path?: string;
|
|
3940
|
+
provider: string;
|
|
3941
|
+
respondTo?: readonly MessengerRespondTo[];
|
|
3942
|
+
shardKey?: ChatSdkStateAdapterOptions["shardKey"];
|
|
3943
|
+
subscribeOnMention?: boolean;
|
|
3944
|
+
toEvent?: (
|
|
3945
|
+
input: ChatSdkMessengerEventInput
|
|
3946
|
+
) => MessengerEvent | Promise<MessengerEvent>;
|
|
3947
|
+
userName: string;
|
|
3948
|
+
verifyWebhook?:
|
|
3949
|
+
| false
|
|
3950
|
+
| ((request: Request) => boolean | Response | Promise<boolean | Response>);
|
|
3951
|
+
}
|
|
3952
|
+
type ThinkMessengers = Record<string, MessengerDefinition>;
|
|
3953
|
+
interface NormalizedMessengerDefinition extends MessengerDefinition {
|
|
3954
|
+
id: string;
|
|
3955
|
+
path: string;
|
|
3956
|
+
respondTo: readonly MessengerRespondTo[];
|
|
3957
|
+
subscribeOnMention: boolean;
|
|
3958
|
+
verifyWebhook:
|
|
3959
|
+
| false
|
|
3960
|
+
| ((request: Request) => boolean | Response | Promise<boolean | Response>);
|
|
3961
|
+
}
|
|
3962
|
+
interface ChatSdkMessengerOptions extends Omit<
|
|
3963
|
+
MessengerDefinition,
|
|
3964
|
+
"adapterName"
|
|
3965
|
+
> {
|
|
3966
|
+
adapterName?: string;
|
|
3967
|
+
}
|
|
3968
|
+
interface ChatSdkMessengerEventInput {
|
|
3969
|
+
action?: ActionEvent;
|
|
3970
|
+
eventKind: MessengerEventKind;
|
|
3971
|
+
message?: Message;
|
|
3972
|
+
raw?: unknown;
|
|
3973
|
+
thread: Thread;
|
|
3974
|
+
}
|
|
3975
|
+
interface MessengerThinkTarget {
|
|
3976
|
+
cancelChat(
|
|
3977
|
+
requestId: string,
|
|
3978
|
+
reason?: string
|
|
3979
|
+
): boolean | void | Promise<boolean | void>;
|
|
3980
|
+
chat(
|
|
3981
|
+
userMessage: string | UIMessage,
|
|
3982
|
+
callback: StreamCallback
|
|
3983
|
+
): Promise<void>;
|
|
3984
|
+
chatWithMessengerContext?(
|
|
3985
|
+
userMessage: string | UIMessage,
|
|
3986
|
+
callback: StreamCallback,
|
|
3987
|
+
context: MessengerEvent
|
|
3988
|
+
): Promise<void>;
|
|
3989
|
+
}
|
|
3990
|
+
interface MessengerThinkHost extends MessengerThinkTarget {
|
|
3991
|
+
constructor: {
|
|
3992
|
+
name: string;
|
|
3993
|
+
};
|
|
3994
|
+
name: string;
|
|
3995
|
+
parentPath: ReadonlyArray<{
|
|
3996
|
+
className: string;
|
|
3997
|
+
name: string;
|
|
3998
|
+
}>;
|
|
3999
|
+
startFiber(
|
|
4000
|
+
name: string,
|
|
4001
|
+
fn: (ctx: FiberContext) => Promise<void>,
|
|
4002
|
+
options?: StartFiberOptions
|
|
4003
|
+
): Promise<MessengerFiberStartResult>;
|
|
4004
|
+
resolveFiber(id: string, result: FiberRecoveryResult): Promise<boolean>;
|
|
4005
|
+
subAgent<T extends Agent>(
|
|
4006
|
+
agentClass: SubAgentClass<T>,
|
|
4007
|
+
name: string
|
|
4008
|
+
): Promise<SubAgentStub<T>>;
|
|
4009
|
+
}
|
|
4010
|
+
interface MessengerFiberStartResult {
|
|
4011
|
+
accepted: boolean;
|
|
4012
|
+
fiberId: string;
|
|
4013
|
+
snapshot?: unknown;
|
|
4014
|
+
status: string;
|
|
4015
|
+
}
|
|
4016
|
+
declare function chatSdkMessenger(
|
|
4017
|
+
options: ChatSdkMessengerOptions
|
|
4018
|
+
): MessengerDefinition;
|
|
4019
|
+
declare class ThinkMessengerRuntime {
|
|
4020
|
+
private readonly host;
|
|
4021
|
+
private chat?;
|
|
4022
|
+
private readonly definitionsByAdapterName;
|
|
4023
|
+
private readonly definitionsById;
|
|
4024
|
+
private readonly definitions;
|
|
4025
|
+
constructor(definitions: ThinkMessengers, host: MessengerThinkHost);
|
|
4026
|
+
get size(): number;
|
|
4027
|
+
initialize(): void;
|
|
4028
|
+
handleRequest(request: Request): Promise<Response | undefined>;
|
|
4029
|
+
handleFiberRecovery(ctx: FiberRecoveryContext): Promise<boolean>;
|
|
4030
|
+
private createChat;
|
|
4031
|
+
private enqueueReply;
|
|
4032
|
+
private answer;
|
|
4033
|
+
/**
|
|
4034
|
+
* Resolve a live delivery surface for an out-of-turn notice (e.g. a scheduled
|
|
4035
|
+
* task or webhook handler calling `deliverNotice`). Uses `chat.thread(id)` —
|
|
4036
|
+
* the chat SDK's supported "post from outside a webhook" primitive, which
|
|
4037
|
+
* returns a postable {@link ChatThread} and infers the adapter from the
|
|
4038
|
+
* thread-id prefix, so it works for every chat-sdk adapter with no per-adapter
|
|
4039
|
+
* wiring. Returns `undefined` when the channel is unregistered or no `threadId`
|
|
4040
|
+
* was supplied so the caller can fail fast.
|
|
4041
|
+
*/
|
|
4042
|
+
resolveDeliverySurface(
|
|
4043
|
+
channelId: string,
|
|
4044
|
+
threadId?: string
|
|
4045
|
+
): Promise<MessengerDeliverySurface | undefined>;
|
|
4046
|
+
private resolveTarget;
|
|
4047
|
+
private definitionForThread;
|
|
4048
|
+
private definitionForThreadId;
|
|
4049
|
+
private hasUniqueProvider;
|
|
4050
|
+
private shardThread;
|
|
4051
|
+
private shardStateKey;
|
|
4052
|
+
private reviveChatObject;
|
|
4053
|
+
private toEvent;
|
|
4054
|
+
}
|
|
4055
|
+
declare function normalizeMessengers(
|
|
4056
|
+
messengers: ThinkMessengers
|
|
4057
|
+
): NormalizedMessengerDefinition[];
|
|
4058
|
+
declare function defaultConversationName(event: MessengerEvent): string;
|
|
4059
|
+
declare function idempotencyKeyForEvent(event: MessengerEvent): string;
|
|
4060
|
+
declare function defaultChatSdkEvent(
|
|
4061
|
+
definition: NormalizedMessengerDefinition,
|
|
4062
|
+
input: ChatSdkMessengerEventInput
|
|
4063
|
+
): MessengerEvent;
|
|
4064
|
+
declare function toMessengerThread(thread: Thread): MessengerThread;
|
|
4065
|
+
declare function toMessengerMessage(message: Message): MessengerMessage;
|
|
4066
|
+
declare function toMessengerAuthor(author: Author): MessengerAuthor;
|
|
4067
|
+
declare function toMessengerAttachment(
|
|
4068
|
+
attachment: Attachment
|
|
4069
|
+
): MessengerAttachment;
|
|
4070
|
+
//#endregion
|
|
3107
4071
|
export {
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
4072
|
+
messengerContextFromEvent as $,
|
|
4073
|
+
StepResult as $t,
|
|
4074
|
+
MessengerDeliveryPolicy as A,
|
|
4075
|
+
skills as An,
|
|
4076
|
+
FiberRecoveryContext$1 as At,
|
|
4077
|
+
messengerReplyRecoveryMode as B,
|
|
4078
|
+
messengerChannel as Bn,
|
|
4079
|
+
RunTurnBase as Bt,
|
|
4080
|
+
DeliverMessengerReplyOptions as C,
|
|
4081
|
+
TurnResult as Cn,
|
|
4082
|
+
ChunkContext as Ct,
|
|
4083
|
+
ERROR_MESSENGER_RESPONSE as D,
|
|
4084
|
+
action as Dn,
|
|
4085
|
+
DeliverNoticeOptions as Dt,
|
|
4086
|
+
EMPTY_MESSENGER_RESPONSE as E,
|
|
4087
|
+
Workspace$1 as En,
|
|
4088
|
+
DeleteSubmissionsOptions as Et,
|
|
4089
|
+
TextStreamCallback as F,
|
|
4090
|
+
ChannelDeliverySurface as Fn,
|
|
4091
|
+
PrepareStepContext as Ft,
|
|
4092
|
+
MessengerAttachment as G,
|
|
4093
|
+
SaveMessagesOptions$1 as Gt,
|
|
4094
|
+
parseMessengerReplySnapshot as H,
|
|
4095
|
+
RunTurnStream as Ht,
|
|
4096
|
+
TextStreamCallbackOptions as I,
|
|
4097
|
+
ChannelIngress as In,
|
|
4098
|
+
PrepareStepFunction$1 as It,
|
|
4099
|
+
MessengerContext as J,
|
|
4100
|
+
SessionMessage$1 as Jt,
|
|
4101
|
+
MessengerAuthor as K,
|
|
4102
|
+
SaveMessagesResult$1 as Kt,
|
|
4103
|
+
defaultDeliveryTag as L,
|
|
4104
|
+
ChannelKind as Ln,
|
|
4105
|
+
PrepareStepResult$1 as Lt,
|
|
4106
|
+
MessengerDeliveryTarget as M,
|
|
4107
|
+
ChannelContext as Mn,
|
|
4108
|
+
MessageConcurrency$1 as Mt,
|
|
4109
|
+
MessengerReplySnapshot as N,
|
|
4110
|
+
ChannelDefinition as Nn,
|
|
4111
|
+
OnStartDegradation as Nt,
|
|
4112
|
+
INTERRUPTED_MESSENGER_RESPONSE as O,
|
|
4113
|
+
defaultContextOverflowClassifier as On,
|
|
4114
|
+
ExtensionConfig as Ot,
|
|
4115
|
+
MessengerReplyStage as P,
|
|
4116
|
+
ChannelDeliveryPolicy as Pn,
|
|
4117
|
+
PendingApproval as Pt,
|
|
4118
|
+
MessengerThread as Q,
|
|
4119
|
+
StepContext as Qt,
|
|
4120
|
+
deliverMessengerReply as R,
|
|
4121
|
+
NormalizedChannelDefinition as Rn,
|
|
4122
|
+
ReplyAttachment as Rt,
|
|
4123
|
+
toMessengerThread as S,
|
|
4124
|
+
TurnInputMessages as Sn,
|
|
4125
|
+
ChatStartEvent as St,
|
|
4126
|
+
DeliveryTag as T,
|
|
4127
|
+
TypedToolResult as Tn,
|
|
4128
|
+
ContextOverflowConfig as Tt,
|
|
4129
|
+
textDeltaFromStreamChunk as U,
|
|
4130
|
+
RunTurnSubmit as Ut,
|
|
4131
|
+
messengerReplySnapshot as V,
|
|
4132
|
+
MediaEvictionConfig as Vn,
|
|
4133
|
+
RunTurnOptions as Vt,
|
|
4134
|
+
MessengerAction as W,
|
|
4135
|
+
RunTurnWait as Wt,
|
|
4136
|
+
MessengerEventKind as X,
|
|
4137
|
+
SkillSource$1 as Xt,
|
|
4138
|
+
MessengerEvent as Y,
|
|
4139
|
+
SkillRunContext as Yt,
|
|
4140
|
+
MessengerMessage as Z,
|
|
4141
|
+
StepConfig as Zt,
|
|
4142
|
+
idempotencyKeyForEvent as _,
|
|
4143
|
+
ToolCallDecision as _n,
|
|
4144
|
+
ChatRecoveryContext$1 as _t,
|
|
4145
|
+
MessengerConversationTarget as a,
|
|
4146
|
+
TextStreamPart as an,
|
|
4147
|
+
ActionAuthorizationContext as at,
|
|
4148
|
+
toMessengerAuthor as b,
|
|
4149
|
+
TurnContext as bn,
|
|
4150
|
+
ChatRecoveryProgressContext as bt,
|
|
4151
|
+
MessengerThinkHost as c,
|
|
4152
|
+
ThinkScheduledTask as cn,
|
|
4153
|
+
ActionContext as ct,
|
|
4154
|
+
ThinkMessengerRuntime as d,
|
|
4155
|
+
ThinkScheduledTasks as dn,
|
|
4156
|
+
ActionPermissionSpec as dt,
|
|
4157
|
+
StopCondition$1 as en,
|
|
4158
|
+
serializableMessengerEvent as et,
|
|
4159
|
+
ThinkMessengerStateAgent as f,
|
|
4160
|
+
ThinkSubmissionInspection as fn,
|
|
4161
|
+
AddMessagesOptions as ft,
|
|
4162
|
+
defaultConversationName as g,
|
|
4163
|
+
ToolCallContext as gn,
|
|
4164
|
+
ChatRecoveryConfig$1 as gt,
|
|
4165
|
+
defaultChatSdkEvent as h,
|
|
4166
|
+
ThinkWallClockSchedule as hn,
|
|
4167
|
+
ChatOptions as ht,
|
|
4168
|
+
MessengerConversationResolver as i,
|
|
4169
|
+
SubmitMessagesResult as in,
|
|
4170
|
+
ActionApprovalPolicy as it,
|
|
4171
|
+
MessengerDeliverySurface as j,
|
|
4172
|
+
ChannelCapabilities as jn,
|
|
4173
|
+
ListSubmissionsOptions as jt,
|
|
4174
|
+
MESSENGER_REPLY_FIBER_NAME as k,
|
|
4175
|
+
isAction as kn,
|
|
4176
|
+
FiberContext$1 as kt,
|
|
4177
|
+
MessengerThinkTarget as l,
|
|
4178
|
+
ThinkScheduledTaskContext as ln,
|
|
4179
|
+
ActionIdempotencyKey as lt,
|
|
4180
|
+
chatSdkMessenger as m,
|
|
4181
|
+
ThinkTime as mn,
|
|
4182
|
+
ChatErrorContext as mt,
|
|
4183
|
+
ChatSdkMessengerOptions as n,
|
|
4184
|
+
StreamableResult as nn,
|
|
4185
|
+
Action as nt,
|
|
4186
|
+
MessengerDefinition as o,
|
|
4187
|
+
Think as on,
|
|
4188
|
+
ActionAuthorizationDecision as ot,
|
|
4189
|
+
ThinkMessengers as p,
|
|
4190
|
+
ThinkSubmissionStatus as pn,
|
|
4191
|
+
ChatErrorClassification as pt,
|
|
4192
|
+
MessengerCapabilities as q,
|
|
4193
|
+
Session$1 as qt,
|
|
4194
|
+
MessengerConversationMode as r,
|
|
4195
|
+
SubmitMessagesOptions as rn,
|
|
4196
|
+
ActionApprovalDescriptor as rt,
|
|
4197
|
+
MessengerRespondTo as s,
|
|
4198
|
+
ThinkIntervalSchedule as sn,
|
|
4199
|
+
ActionConfig as st,
|
|
4200
|
+
ChatSdkMessengerEventInput as t,
|
|
4201
|
+
StreamCallback as tn,
|
|
4202
|
+
toMessengerUserMessage as tt,
|
|
4203
|
+
NormalizedMessengerDefinition as u,
|
|
4204
|
+
ThinkScheduledTaskSchedule as un,
|
|
4205
|
+
ActionKind as ut,
|
|
4206
|
+
normalizeMessengers as v,
|
|
4207
|
+
ToolCallResultContext as vn,
|
|
4208
|
+
ChatRecoveryExhaustedContext as vt,
|
|
4209
|
+
DeliveryKind as w,
|
|
4210
|
+
TypedToolCall$1 as wn,
|
|
4211
|
+
ChunkPart as wt,
|
|
4212
|
+
toMessengerMessage as x,
|
|
4213
|
+
TurnInput as xn,
|
|
4214
|
+
ChatResponseResult$1 as xt,
|
|
4215
|
+
toMessengerAttachment as y,
|
|
4216
|
+
TurnConfig as yn,
|
|
4217
|
+
ChatRecoveryOptions$1 as yt,
|
|
4218
|
+
messengerReplyFailureMode as z,
|
|
4219
|
+
ThinkChannels as zn,
|
|
4220
|
+
ResolvedChatRecoveryConfig as zt
|
|
3223
4221
|
};
|
|
3224
|
-
//# sourceMappingURL=
|
|
4222
|
+
//# sourceMappingURL=index-CR4-ffm_.d.ts.map
|