@cloudflare/think 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -1
- package/dist/{chat-sdk-B77QwYuj.js → chat-sdk-BEjKXjCm.js} +333 -67
- package/dist/chat-sdk-BEjKXjCm.js.map +1 -0
- package/dist/{hook-proxy-Dogs9wbj.js → hook-proxy-DY2sBNa0.js} +8 -3
- package/dist/hook-proxy-DY2sBNa0.js.map +1 -0
- package/dist/{index-CJ--4uax.d.ts → index-DwPAhQRQ.d.ts} +1096 -283
- package/dist/messengers/index.d.ts +60 -56
- package/dist/messengers/index.js +2 -2
- package/dist/messengers/telegram.d.ts +11 -4
- package/dist/messengers/telegram.js +3 -1
- package/dist/messengers/telegram.js.map +1 -1
- package/dist/react.d.ts +4 -0
- package/dist/react.js.map +1 -1
- package/dist/think.d.ts +2 -2
- package/dist/think.js +2498 -821
- package/dist/think.js.map +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/actions.md +36 -11
- package/docs/channels.md +15 -2
- package/docs/index.md +107 -12
- package/docs/lifecycle-hooks.md +113 -62
- package/docs/messengers.md +93 -1
- package/docs/multi-chat.md +614 -0
- package/docs/programmatic-submissions.md +45 -0
- package/docs/sub-agents.md +61 -20
- package/docs/tools.md +4 -1
- package/docs/workflows.md +5 -0
- package/package.json +7 -7
- package/dist/chat-sdk-B77QwYuj.js.map +0 -1
- package/dist/hook-proxy-Dogs9wbj.js.map +0 -1
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
StopCondition as StopCondition$1,
|
|
24
24
|
StreamTextOnChunkCallback,
|
|
25
25
|
TextStreamPart,
|
|
26
|
+
TextStreamPart as TextStreamPart$1,
|
|
26
27
|
ToolSet,
|
|
27
28
|
TypedToolCall,
|
|
28
29
|
TypedToolCall as TypedToolCall$1,
|
|
@@ -67,6 +68,7 @@ import {
|
|
|
67
68
|
ChatRecoveryProgressContext,
|
|
68
69
|
ChatResponseResult,
|
|
69
70
|
ChatResponseResult as ChatResponseResult$1,
|
|
71
|
+
ChatTurnOutcome,
|
|
70
72
|
ClientToolExecutor,
|
|
71
73
|
ClientToolSchema,
|
|
72
74
|
MessageConcurrency,
|
|
@@ -108,12 +110,13 @@ import {
|
|
|
108
110
|
Adapter,
|
|
109
111
|
Attachment,
|
|
110
112
|
Author,
|
|
113
|
+
ConcurrencyConfig,
|
|
114
|
+
ConcurrencyStrategy,
|
|
111
115
|
Message,
|
|
112
116
|
Thread
|
|
113
117
|
} from "chat";
|
|
114
118
|
import { ChatSdkStateAdapterOptions, ChatSdkStateAgent } from "agents/chat-sdk";
|
|
115
119
|
import { RpcTarget } from "cloudflare:workers";
|
|
116
|
-
import { LifecycleJobContext, LifecycleJobOutcome } from "agents/lifecycle";
|
|
117
120
|
import { Streams } from "agents/streams";
|
|
118
121
|
|
|
119
122
|
//#region src/session.d.ts
|
|
@@ -349,8 +352,15 @@ declare function messengerChannel(
|
|
|
349
352
|
//#region src/think.d.ts
|
|
350
353
|
type ChatRecoveryRetryData = {
|
|
351
354
|
targetUserId?: string;
|
|
355
|
+
/**
|
|
356
|
+
* Set when the interrupted turn regenerated `targetUserId`: the leaf the new
|
|
357
|
+
* response branches beside. The retry answers `targetUserId` as a sibling
|
|
358
|
+
* branch, and only while this is still the leaf.
|
|
359
|
+
*/
|
|
360
|
+
regeneratedLeafId?: string;
|
|
352
361
|
originalRequestId?: string;
|
|
353
362
|
incidentId?: string;
|
|
363
|
+
originMessageIds?: string[];
|
|
354
364
|
lastBody?: Record<string, unknown> | null;
|
|
355
365
|
lastClientTools?: ClientToolSchema[] | null;
|
|
356
366
|
recoveredRequestId?: string;
|
|
@@ -359,6 +369,7 @@ type ChatRecoveryContinueData = {
|
|
|
359
369
|
targetAssistantId?: string;
|
|
360
370
|
originalRequestId?: string;
|
|
361
371
|
incidentId?: string;
|
|
372
|
+
originMessageIds?: string[];
|
|
362
373
|
lastBody?: Record<string, unknown> | null;
|
|
363
374
|
lastClientTools?: ClientToolSchema[] | null;
|
|
364
375
|
recoveredRequestId?: string;
|
|
@@ -423,9 +434,43 @@ interface StreamCallback {
|
|
|
423
434
|
* Note: a deploy/eviction interruption kills the isolate (and this callback)
|
|
424
435
|
* before this can fire — the caller observes a transport break instead. This
|
|
425
436
|
* fires only for an in-isolate interruption (the stall→recovery path).
|
|
437
|
+
*
|
|
438
|
+
* `info.deliversRecoveredReply` is true when the interrupted turn was a
|
|
439
|
+
* messenger turn and this agent will post the recovered answer (or the
|
|
440
|
+
* interrupted apology, if recovery gives up) to the messenger thread itself.
|
|
426
441
|
*/
|
|
427
|
-
onInterrupted?(): void | Promise<void>;
|
|
442
|
+
onInterrupted?(info?: ChatInterruptedInfo): void | Promise<void>;
|
|
443
|
+
}
|
|
444
|
+
interface ChatInterruptedInfo {
|
|
445
|
+
deliversRecoveredReply?: boolean;
|
|
428
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Produces server-authored assistant-message metadata from AI SDK stream parts.
|
|
449
|
+
* Forwarded to the AI SDK `toUIMessageStream` so a Think turn can stamp
|
|
450
|
+
* structured metadata onto the assistant message it persists. Called for every
|
|
451
|
+
* stream part; use `part.type` to choose when to return metadata (`start` and
|
|
452
|
+
* `finish` are the conventional points). Each non-`undefined` return is
|
|
453
|
+
* shallow-merged into the message's metadata. The return value is broadcast to
|
|
454
|
+
* clients and persisted, so it must be
|
|
455
|
+
* JSON-serializable and must not carry server-only secrets.
|
|
456
|
+
*
|
|
457
|
+
* `continuation` is true when the turn continues an earlier one (a recovery
|
|
458
|
+
* continuation or an auto-continue after a tool result). A recovery
|
|
459
|
+
* continuation streams into the interrupted assistant message, so its `start`
|
|
460
|
+
* part cannot overwrite keys that message already has: a `createdAt` stamped
|
|
461
|
+
* on the original `start` survives. Keys the continuation's `start` adds, and
|
|
462
|
+
* everything from later parts, merge as usual.
|
|
463
|
+
*
|
|
464
|
+
* The `Metadata` parameter defaults to the opaque `Record<string, unknown>` used
|
|
465
|
+
* everywhere metadata rides today; it is the seam a future typed-metadata story
|
|
466
|
+
* (issue #1676) narrows without a breaking change.
|
|
467
|
+
*/
|
|
468
|
+
type MessageMetadataCallback<
|
|
469
|
+
Metadata extends Record<string, unknown> = Record<string, unknown>
|
|
470
|
+
> = (options: {
|
|
471
|
+
part: TextStreamPart<ToolSet>;
|
|
472
|
+
continuation: boolean;
|
|
473
|
+
}) => Metadata | undefined;
|
|
429
474
|
/**
|
|
430
475
|
* Minimal interface for the result of the inference loop.
|
|
431
476
|
* The AI SDK's `streamText()` result satisfies this interface.
|
|
@@ -493,8 +538,9 @@ interface RunTurnBase {
|
|
|
493
538
|
/**
|
|
494
539
|
* Channel id this turn belongs to (resolved against `configureChannels()` /
|
|
495
540
|
* `getMessengers()`). Sets the turn-scoped channel context and is persisted on
|
|
496
|
-
* the user message so a recovered/continued turn re-resolves it.
|
|
497
|
-
*
|
|
541
|
+
* the user message so a recovered/continued turn re-resolves it. Omit it to
|
|
542
|
+
* run without a channel context. (WebSocket chat turns always run on the
|
|
543
|
+
* implicit `web` channel.)
|
|
498
544
|
*/
|
|
499
545
|
channel?: string;
|
|
500
546
|
}
|
|
@@ -523,7 +569,13 @@ interface RunTurnStream extends RunTurnBase {
|
|
|
523
569
|
type RunTurnOptions = RunTurnWait | RunTurnSubmit | RunTurnStream;
|
|
524
570
|
/** Result of {@link Think.runTurn} in `mode: "wait"`. */
|
|
525
571
|
type TurnResult = SaveMessagesResult & {
|
|
526
|
-
message?: SessionMessage;
|
|
572
|
+
/** Persisted assistant produced by this completed turn; absent otherwise. */ message?: SessionMessage;
|
|
573
|
+
/**
|
|
574
|
+
* Parsed structured output when the turn's `TurnConfig.output` produced
|
|
575
|
+
* one. A structured output that fails to parse ends the turn with
|
|
576
|
+
* `status: "error"`.
|
|
577
|
+
*/
|
|
578
|
+
output?: unknown;
|
|
527
579
|
continuation: boolean;
|
|
528
580
|
};
|
|
529
581
|
declare const ACTION_BRAND: unique symbol;
|
|
@@ -632,6 +684,14 @@ interface PendingApproval {
|
|
|
632
684
|
source: "action" | "codemode";
|
|
633
685
|
descriptor: ActionApprovalDescriptor;
|
|
634
686
|
}
|
|
687
|
+
interface RejectExecutionOptions {
|
|
688
|
+
/**
|
|
689
|
+
* Whether Think starts a model continuation after recording the rejection.
|
|
690
|
+
* Defaults to `true`. Set this to `false` when the caller wants the
|
|
691
|
+
* conversation to remain paused until a later user turn.
|
|
692
|
+
*/
|
|
693
|
+
autoContinue?: boolean;
|
|
694
|
+
}
|
|
635
695
|
interface ActionConfig<
|
|
636
696
|
InputSchema extends FlexibleSchema = FlexibleSchema,
|
|
637
697
|
Output = unknown
|
|
@@ -672,6 +732,7 @@ declare function action<
|
|
|
672
732
|
Output = unknown
|
|
673
733
|
>(config: ActionConfig<InputSchema, Output>): Action<InputSchema, Output>;
|
|
674
734
|
declare function isAction(value: unknown): value is Action;
|
|
735
|
+
/** What admitted a turn. Exposed on {@link ActiveTurn} and {@link TurnContext}. */
|
|
675
736
|
type TurnTrigger =
|
|
676
737
|
| "ws-chat"
|
|
677
738
|
| "rpc"
|
|
@@ -856,11 +917,47 @@ type ThinkSubmissionInspection = {
|
|
|
856
917
|
metadata?: Record<string, unknown>;
|
|
857
918
|
createdAt: number;
|
|
858
919
|
startedAt?: number;
|
|
859
|
-
completedAt?: number
|
|
920
|
+
completedAt?: number /** Id of the assistant message this submission's turn persisted. */;
|
|
921
|
+
messageId?: string;
|
|
860
922
|
};
|
|
861
923
|
type SubmitMessagesResult = ThinkSubmissionInspection & {
|
|
862
924
|
accepted: boolean;
|
|
863
925
|
};
|
|
926
|
+
type WaitForSubmissionOptions = {
|
|
927
|
+
/**
|
|
928
|
+
* Stop waiting after this many milliseconds and return the submission as it
|
|
929
|
+
* is then, still `pending` or `running`, or `null` if it was deleted.
|
|
930
|
+
*/
|
|
931
|
+
timeoutMs?: number;
|
|
932
|
+
};
|
|
933
|
+
/** What {@link Think.cancelSubmission} did. */
|
|
934
|
+
type CancelSubmissionResult =
|
|
935
|
+
| {
|
|
936
|
+
/** No submission has this id. */ outcome: "not_found";
|
|
937
|
+
submissionId: string;
|
|
938
|
+
}
|
|
939
|
+
| {
|
|
940
|
+
/** The submission had already finished; nothing changed. */ outcome: "already_terminal";
|
|
941
|
+
submissionId: string;
|
|
942
|
+
submission: ThinkSubmissionInspection;
|
|
943
|
+
}
|
|
944
|
+
| {
|
|
945
|
+
/** The submission is now `aborted`. */ outcome: "cancelled";
|
|
946
|
+
submissionId: string;
|
|
947
|
+
/**
|
|
948
|
+
* `"pending"`: removed before its turn started. `"running"`: its turn
|
|
949
|
+
* had been claimed and was signalled to abort; side effects already
|
|
950
|
+
* under way may still finish.
|
|
951
|
+
*/
|
|
952
|
+
previousStatus: "pending" | "running";
|
|
953
|
+
/**
|
|
954
|
+
* Whether any of the submission's messages were written to the
|
|
955
|
+
* conversation when it was cancelled. A claimed submission can still be
|
|
956
|
+
* `false` when it is cancelled before its turn applies them.
|
|
957
|
+
*/
|
|
958
|
+
messagesApplied: boolean;
|
|
959
|
+
submission: ThinkSubmissionInspection;
|
|
960
|
+
};
|
|
864
961
|
type ListSubmissionsOptions = {
|
|
865
962
|
status?: ThinkSubmissionStatus | ThinkSubmissionStatus[];
|
|
866
963
|
limit?: number;
|
|
@@ -870,6 +967,17 @@ type DeleteSubmissionsOptions = {
|
|
|
870
967
|
completedBefore?: Date;
|
|
871
968
|
limit?: number;
|
|
872
969
|
};
|
|
970
|
+
/** Payload of one queued workflow notification. */
|
|
971
|
+
type WorkflowNotificationPayload = {
|
|
972
|
+
workflowName: string;
|
|
973
|
+
workflowId: string;
|
|
974
|
+
event: {
|
|
975
|
+
type: string;
|
|
976
|
+
payload: unknown;
|
|
977
|
+
} /** Failed deliveries so far; drives the retry backoff. */;
|
|
978
|
+
attempts?: number /** Epoch ms of the first failed delivery; bounds the retry window. */;
|
|
979
|
+
firstFailedAt?: number;
|
|
980
|
+
};
|
|
873
981
|
/**
|
|
874
982
|
* A chat turn request. Built automatically by each entry path
|
|
875
983
|
* (WebSocket, chat(), saveMessages, auto-continuation) and passed
|
|
@@ -900,16 +1008,54 @@ interface TurnInput {
|
|
|
900
1008
|
interface TurnContext {
|
|
901
1009
|
/** Assembled system prompt (from context blocks or getSystemPrompt fallback). */
|
|
902
1010
|
system: string;
|
|
903
|
-
/**
|
|
1011
|
+
/**
|
|
1012
|
+
* Assembled model messages (truncated, pruned). When a `whenChanged:
|
|
1013
|
+
* "remind"` context block has changed since the prompt froze, its current
|
|
1014
|
+
* value rides at the end, inside the last user message when there is one.
|
|
1015
|
+
*/
|
|
904
1016
|
messages: ModelMessage[];
|
|
905
1017
|
/** Merged tool set (workspace + getTools + session + MCP + client + caller). */
|
|
906
1018
|
tools: ToolSet;
|
|
907
|
-
/**
|
|
1019
|
+
/**
|
|
1020
|
+
* The language model from getModel(), resolved on first read — a
|
|
1021
|
+
* `beforeTurn` that returns its own `model` without reading this never
|
|
1022
|
+
* resolves the default.
|
|
1023
|
+
*/
|
|
908
1024
|
model: LanguageModel;
|
|
909
1025
|
/** Whether this is a continuation turn. */
|
|
910
1026
|
continuation: boolean;
|
|
911
1027
|
/** Custom body fields from the client request. */
|
|
912
1028
|
body?: Record<string, unknown>;
|
|
1029
|
+
/**
|
|
1030
|
+
* The request this turn runs for: the same id `beforePersist`,
|
|
1031
|
+
* `onChatResponse` and `onChatError` see. Undefined for inference that runs
|
|
1032
|
+
* outside an admitted turn.
|
|
1033
|
+
*/
|
|
1034
|
+
requestId?: string;
|
|
1035
|
+
/** What admitted this turn. Undefined outside an admitted turn. */
|
|
1036
|
+
trigger?: TurnTrigger;
|
|
1037
|
+
/**
|
|
1038
|
+
* Aborts when the turn is cancelled. Pass it to any I/O `beforeTurn` awaits
|
|
1039
|
+
* so a stopped turn does not wait for it to finish.
|
|
1040
|
+
*/
|
|
1041
|
+
abortSignal?: AbortSignal;
|
|
1042
|
+
/**
|
|
1043
|
+
* The messenger thread this turn answers, fixed when the turn was admitted.
|
|
1044
|
+
* Unlike {@link Think.getMessengerContext}, it never falls back to another
|
|
1045
|
+
* turn's message.
|
|
1046
|
+
*/
|
|
1047
|
+
messenger?: MessengerContext;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* The turn currently running on this agent. See {@link Think.activeTurn}.
|
|
1051
|
+
*/
|
|
1052
|
+
interface ActiveTurn {
|
|
1053
|
+
/** Request id shared by every hook, tool call and event of this turn. */
|
|
1054
|
+
requestId: string;
|
|
1055
|
+
trigger: TurnTrigger;
|
|
1056
|
+
continuation: boolean;
|
|
1057
|
+
/** Channel the turn resolved to, when it has one. */
|
|
1058
|
+
channel?: string;
|
|
913
1059
|
}
|
|
914
1060
|
/**
|
|
915
1061
|
* Configuration returned by the `beforeTurn` hook to override defaults.
|
|
@@ -946,6 +1092,17 @@ interface TurnConfig {
|
|
|
946
1092
|
* for this turn. Defaults to the instance-level `sendReasoning` setting.
|
|
947
1093
|
*/
|
|
948
1094
|
sendReasoning?: boolean;
|
|
1095
|
+
/**
|
|
1096
|
+
* Produces server-authored assistant-message metadata for this turn — the
|
|
1097
|
+
* write path that lets a turn attach structured metadata (e.g. a `createdAt`
|
|
1098
|
+
* timestamp) to the assistant message Think persists, matching the AI SDK
|
|
1099
|
+
* `messageMetadata` callback base `AIChatAgent` + `streamText` already accept.
|
|
1100
|
+
* Overrides the instance-level {@link Think.messageMetadata} for this turn.
|
|
1101
|
+
* Configure from a Think subclass; sandboxed extensions cannot send functions
|
|
1102
|
+
* over RPC. See {@link MessageMetadataCallback} for when it is called and the
|
|
1103
|
+
* serialization constraints on its return value.
|
|
1104
|
+
*/
|
|
1105
|
+
messageMetadata?: MessageMetadataCallback;
|
|
949
1106
|
/**
|
|
950
1107
|
* Override the stream-stall inactivity watchdog timeout for THIS turn only
|
|
951
1108
|
* (ms; `0` disables it for this turn). Defaults to the instance-level
|
|
@@ -1035,8 +1192,10 @@ interface TurnConfig {
|
|
|
1035
1192
|
*
|
|
1036
1193
|
* - `context_overflow` — the prompt exceeded the model's context window
|
|
1037
1194
|
* (Anthropic `"prompt is too long"`, OpenAI `context_length_exceeded`, …).
|
|
1038
|
-
*
|
|
1039
|
-
* - `rate_limit` / `transient` —
|
|
1195
|
+
* Think compacts and retries when `contextOverflow.reactive` is enabled.
|
|
1196
|
+
* - `rate_limit` / `transient` — a stream error worth retrying (a 429, a
|
|
1197
|
+
* dropped connection). Think routes the turn into bounded chat recovery, like
|
|
1198
|
+
* a stream stall, and schedules the continuation with exponential backoff.
|
|
1040
1199
|
* - `fatal` — unrecoverable; surface terminally.
|
|
1041
1200
|
* - `unknown` — default; Think applies its existing terminal behavior.
|
|
1042
1201
|
*/
|
|
@@ -1137,6 +1296,12 @@ interface ChatErrorContext {
|
|
|
1137
1296
|
requestId?: string;
|
|
1138
1297
|
stage: "parse" | "persist" | "turn" | "stream" | "recovery" | "transcript";
|
|
1139
1298
|
messagesPersisted?: boolean;
|
|
1299
|
+
/**
|
|
1300
|
+
* `true` when the failed turn was a server-started continuation (for
|
|
1301
|
+
* example after a tool approval or a client tool result) rather than a
|
|
1302
|
+
* turn a client or caller submitted.
|
|
1303
|
+
*/
|
|
1304
|
+
continuation?: boolean;
|
|
1140
1305
|
/**
|
|
1141
1306
|
* App-provided semantic classification (from `classifyChatError`), when
|
|
1142
1307
|
* known. Lets `onChatError` overrides and observers distinguish e.g. a
|
|
@@ -1220,6 +1385,11 @@ type ToolCallContextExtras = {
|
|
|
1220
1385
|
| undefined /** The conversation messages available at tool execution time. */;
|
|
1221
1386
|
readonly messages: ReadonlyArray<ModelMessage> /** Signal for cancelling the operation. */;
|
|
1222
1387
|
readonly abortSignal: AbortSignal | undefined;
|
|
1388
|
+
/**
|
|
1389
|
+
* Request id of the turn making this call, matching `TurnContext.requestId`
|
|
1390
|
+
* and `onChatResponse`. Undefined outside an admitted turn.
|
|
1391
|
+
*/
|
|
1392
|
+
readonly requestId?: string;
|
|
1223
1393
|
};
|
|
1224
1394
|
/**
|
|
1225
1395
|
* The `TypedToolCall<TOOLS>` union, re-keyed so that discriminating on
|
|
@@ -1315,7 +1485,8 @@ type ToolCallResultBase = {
|
|
|
1315
1485
|
readonly stepNumber: number | undefined;
|
|
1316
1486
|
readonly messages: ReadonlyArray<ModelMessage> /** Wall-clock execution time in milliseconds. */;
|
|
1317
1487
|
readonly toolExecutionMs: number /** @deprecated Prefer `toolExecutionMs`. */;
|
|
1318
|
-
readonly durationMs: number;
|
|
1488
|
+
readonly durationMs: number /** Request id of the turn that made this call; see `ToolCallContext`. */;
|
|
1489
|
+
readonly requestId?: string;
|
|
1319
1490
|
};
|
|
1320
1491
|
/**
|
|
1321
1492
|
* The discriminated success/failure outcome of a tool call. On success the
|
|
@@ -1418,10 +1589,18 @@ type ThinkModel = LanguageModel | ThinkModelId;
|
|
|
1418
1589
|
declare class Think<
|
|
1419
1590
|
Env extends Cloudflare.Env = Cloudflare.Env,
|
|
1420
1591
|
State = unknown,
|
|
1421
|
-
Props extends
|
|
1592
|
+
Props extends object = object
|
|
1422
1593
|
> extends Agent<Env, State, Props> {
|
|
1423
1594
|
#private;
|
|
1424
1595
|
private _activeChatRecoveryRootRequestId;
|
|
1596
|
+
/**
|
|
1597
|
+
* The originating user message ids of the active recovery chain (#2280),
|
|
1598
|
+
* carried in the recovery payload because the successor turn runs under a
|
|
1599
|
+
* fresh request id. Scoped to the recovery callback's async context, so a
|
|
1600
|
+
* concurrent client request never inherits them.
|
|
1601
|
+
*/
|
|
1602
|
+
private _chatRecoveryOriginIdsScope;
|
|
1603
|
+
private get _activeChatRecoveryOriginIds();
|
|
1425
1604
|
private static readonly CONFIG_KEYS;
|
|
1426
1605
|
/**
|
|
1427
1606
|
* Whether Think automatically converts connected MCP tools to AI SDK tools
|
|
@@ -1471,6 +1650,16 @@ declare class Think<
|
|
|
1471
1650
|
* @default "queue"
|
|
1472
1651
|
*/
|
|
1473
1652
|
messageConcurrency: MessageConcurrency;
|
|
1653
|
+
/**
|
|
1654
|
+
* How the Chat SDK handles messages that arrive in a messenger thread while
|
|
1655
|
+
* the agent is still answering, or before it starts. Accepts any Chat SDK
|
|
1656
|
+
* `concurrency` value: `"queue"`, `"debounce"`, `"burst"`, `"concurrent"`,
|
|
1657
|
+
* `"drop"`, or a `ConcurrencyConfig`. One setting covers every messenger on
|
|
1658
|
+
* the agent. Set it as a class field: it is read before `onStart` runs.
|
|
1659
|
+
*
|
|
1660
|
+
* @default { strategy: "burst", debounceMs: 600 }
|
|
1661
|
+
*/
|
|
1662
|
+
messengerConcurrency: MessengerConcurrency;
|
|
1474
1663
|
/**
|
|
1475
1664
|
* Byte budget for hydrating the persisted transcript into the in-memory
|
|
1476
1665
|
* message cache (`this.messages`).
|
|
@@ -1500,6 +1689,11 @@ declare class Think<
|
|
|
1500
1689
|
* non-positive value) to disable windowing and always hydrate the full
|
|
1501
1690
|
* transcript.
|
|
1502
1691
|
*
|
|
1692
|
+
* Once the transcript exceeds the budget, the hydrated window's start
|
|
1693
|
+
* slides forward as messages are added, which rewrites the start of the
|
|
1694
|
+
* prompt and defeats provider prompt caching (and the step alignment of
|
|
1695
|
+
* `truncationStep`) until the transcript fits again.
|
|
1696
|
+
*
|
|
1503
1697
|
* @default 32 * 1024 * 1024
|
|
1504
1698
|
*/
|
|
1505
1699
|
hydrationByteBudget: number;
|
|
@@ -1521,9 +1715,13 @@ declare class Think<
|
|
|
1521
1715
|
* `false` keeps aged media in the conversation, so the model keeps seeing
|
|
1522
1716
|
* it. It does NOT change where Sessions keeps the bytes.
|
|
1523
1717
|
*
|
|
1524
|
-
*
|
|
1525
|
-
*
|
|
1526
|
-
*
|
|
1718
|
+
* Eviction only rewrites messages below the stepped read-time truncation
|
|
1719
|
+
* cutoff (see `truncationStep`), moved back whole steps until at least
|
|
1720
|
+
* `keepRecentMessages` messages stay above it. It therefore never rewrites
|
|
1721
|
+
* a message the model still replays at full fidelity, and it changes the
|
|
1722
|
+
* cached prompt prefix at most once per truncation step rather than every
|
|
1723
|
+
* turn. The media of up to `keepRecentMessages + truncationStep - 1`
|
|
1724
|
+
* recent messages can stay in context.
|
|
1527
1725
|
*
|
|
1528
1726
|
* @default true
|
|
1529
1727
|
*/
|
|
@@ -1574,13 +1772,20 @@ declare class Think<
|
|
|
1574
1772
|
* e.g. via a health RPC — without subclassing.
|
|
1575
1773
|
*/
|
|
1576
1774
|
getOnStartDegradations(): ReadonlyArray<OnStartDegradation>;
|
|
1577
|
-
private _activeMessengerContext?;
|
|
1578
1775
|
/**
|
|
1579
1776
|
* Turn-scoped channel context (superset of `_activeMessengerContext`). Set on
|
|
1580
1777
|
* both the queue and submit admission paths via `_withChannelContext`, read by
|
|
1581
1778
|
* `deliverNotice` and per-channel policy. Save/restore keeps nested turns safe.
|
|
1582
1779
|
*/
|
|
1583
1780
|
private _activeChannelContext?;
|
|
1781
|
+
/**
|
|
1782
|
+
* Channel of the latest queue turn that ran inference, which a continuation
|
|
1783
|
+
* without an explicit channel extends. Cleared by `resetTurnState`. Differs from the latest user message's
|
|
1784
|
+
* channel when a WebSocket regeneration reuses a message another channel
|
|
1785
|
+
* stored, or a continuation ran on an explicit channel. In memory only:
|
|
1786
|
+
* after an eviction, continuations fall back to history.
|
|
1787
|
+
*/
|
|
1788
|
+
private _lastTurnChannel?;
|
|
1584
1789
|
/**
|
|
1585
1790
|
* Live delivery surface for the active turn, bound by `deliverMessengerReply`
|
|
1586
1791
|
* so `deliverNotice` can post to the originating channel mid-turn. Save/restore
|
|
@@ -1731,10 +1936,21 @@ declare class Think<
|
|
|
1731
1936
|
* the next one. A returned tool part MUST carry a settled result
|
|
1732
1937
|
* (`output-available` / `output-error` / `output-denied` or an
|
|
1733
1938
|
* `output`/`result` field); returning a non-tool part (e.g. text) is fine.
|
|
1939
|
+
*
|
|
1940
|
+
* It also receives an approved call that never ran (state still
|
|
1941
|
+
* `approval-responded`) once a later turn moves past it without a
|
|
1942
|
+
* continuation executing it.
|
|
1734
1943
|
*/
|
|
1735
1944
|
protected repairInterruptedToolPart(
|
|
1736
1945
|
part: UIMessage["parts"][number]
|
|
1737
1946
|
): UIMessage["parts"][number];
|
|
1947
|
+
/**
|
|
1948
|
+
* Whether the inference being prepared may repair `approval-responded`
|
|
1949
|
+
* parts: it is not a continuation, and no continuation is waiting to run
|
|
1950
|
+
* them.
|
|
1951
|
+
*/
|
|
1952
|
+
private _repairApprovalRespondedThisTurn;
|
|
1953
|
+
private _mayRepairApprovalResponded;
|
|
1738
1954
|
private _repairToolTranscriptParts;
|
|
1739
1955
|
private _repairTranscriptForProvider;
|
|
1740
1956
|
/**
|
|
@@ -1753,7 +1969,6 @@ declare class Think<
|
|
|
1753
1969
|
*/
|
|
1754
1970
|
private _runBestEffortOnStartStep;
|
|
1755
1971
|
private _mediaEvictionRunning;
|
|
1756
|
-
private _mediaEvictionScheduled;
|
|
1757
1972
|
/**
|
|
1758
1973
|
* A request that arrived while a pass was running. That pass read its
|
|
1759
1974
|
* candidates before the request's append landed, so the request is kept
|
|
@@ -1785,15 +2000,22 @@ declare class Think<
|
|
|
1785
2000
|
*/
|
|
1786
2001
|
private _agedRowsHiddenFromCache;
|
|
1787
2002
|
/**
|
|
1788
|
-
*
|
|
2003
|
+
* Queue a bounded media-eviction pass (see `mediaEviction`).
|
|
1789
2004
|
*
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
1794
|
-
*
|
|
2005
|
+
* The pass is one queue item with a stable id, so repeated requests
|
|
2006
|
+
* coalesce and the pass runs from the alarm loop, never inside the
|
|
2007
|
+
* request or the `blockConcurrencyWhile` cache refresh that asked for it.
|
|
2008
|
+
* A request that lands while a pass is running is re-evaluated once the
|
|
2009
|
+
* pass ends, so media aged by an append during the pass is not left until
|
|
2010
|
+
* the next one. `_evictAgedMediaBestEffort` swallows its own failures, so
|
|
2011
|
+
* a bad pass can never brick the object.
|
|
1795
2012
|
*/
|
|
1796
2013
|
private _scheduleMediaEvictionPass;
|
|
2014
|
+
/**
|
|
2015
|
+
* Run one media-eviction pass.
|
|
2016
|
+
* @internal Queue callback.
|
|
2017
|
+
*/
|
|
2018
|
+
_cfEvictAgedMedia(): Promise<void>;
|
|
1797
2019
|
/**
|
|
1798
2020
|
* Remove aged media from the conversation, leaving a Workspace pointer the
|
|
1799
2021
|
* agent can read back.
|
|
@@ -1805,9 +2027,10 @@ declare class Think<
|
|
|
1805
2027
|
* once the rewritten row is stored, its Sessions attachment reference is
|
|
1806
2028
|
* gone and the blob is reaped, so the bytes live in exactly one place.
|
|
1807
2029
|
*
|
|
1808
|
-
* The aged cutoff is
|
|
1809
|
-
* `
|
|
1810
|
-
* are never rewritten, whatever the configuration
|
|
2030
|
+
* The aged cutoff is {@link mediaEvictionCutoff}: the stepped truncation
|
|
2031
|
+
* cutoff, kept at least `keepRecentMessages` back. Messages the model still
|
|
2032
|
+
* replays at full fidelity are never rewritten, whatever the configuration
|
|
2033
|
+
* says, and the cutoff moves only once per truncation step.
|
|
1811
2034
|
*
|
|
1812
2035
|
* Best-effort: failures are logged and the next pass retries. When a pass
|
|
1813
2036
|
* stops at `maxRowsPerPass` having made progress, the next one is scheduled
|
|
@@ -1871,16 +2094,15 @@ declare class Think<
|
|
|
1871
2094
|
* `MODEL_RECENT_WINDOW`; `getHistory()` still reads the full path.
|
|
1872
2095
|
*/
|
|
1873
2096
|
private _syncMessages;
|
|
1874
|
-
/** Patch
|
|
1875
|
-
private
|
|
2097
|
+
/** Patch a message that is already present in the live cache. */
|
|
2098
|
+
private _patchCachedMessage;
|
|
1876
2099
|
/**
|
|
1877
|
-
*
|
|
1878
|
-
*
|
|
1879
|
-
*
|
|
1880
|
-
*
|
|
1881
|
-
* row, so a fruitless eviction pass no longer stands.
|
|
2100
|
+
* An update that enlarges a cached message (a tool result landing on it)
|
|
2101
|
+
* grows the cache exactly as an append does, so it is charged against the
|
|
2102
|
+
* hydration budget the same way; and it may have put an inline payload on
|
|
2103
|
+
* an aged row, so a fruitless eviction pass no longer stands.
|
|
1882
2104
|
*/
|
|
1883
|
-
private
|
|
2105
|
+
private _noteCachedReplacement;
|
|
1884
2106
|
private _appendMessageToHistory;
|
|
1885
2107
|
private _updateMessageInHistory;
|
|
1886
2108
|
private _upsertMessageInHistory;
|
|
@@ -1929,6 +2151,8 @@ declare class Think<
|
|
|
1929
2151
|
private _pendingInteractionPromise;
|
|
1930
2152
|
private _interactionApplyTail;
|
|
1931
2153
|
private _streamingAssistant;
|
|
2154
|
+
private _deferredResolvedPauses;
|
|
2155
|
+
private _deferredResolvedPausesLoad;
|
|
1932
2156
|
private _submitConcurrency;
|
|
1933
2157
|
private static MESSAGE_DEBOUNCE_MS;
|
|
1934
2158
|
private _agentToolForwarders;
|
|
@@ -1937,6 +2161,8 @@ declare class Think<
|
|
|
1937
2161
|
private _agentToolLastErrors;
|
|
1938
2162
|
private _agentToolPreTurnAssistantIds;
|
|
1939
2163
|
private _agentToolLiveSequences;
|
|
2164
|
+
/** Runs started with `eventDelivery: "terminal"`: their chunks are not broadcast. */
|
|
2165
|
+
private _agentToolTerminalOnlyRuns;
|
|
1940
2166
|
/**
|
|
1941
2167
|
* Request id → run id for in-flight agent-tool turns (null = resolved as
|
|
1942
2168
|
* not an agent-tool turn, cached so unrelated turns don't re-query SQLite
|
|
@@ -1947,19 +2173,24 @@ declare class Think<
|
|
|
1947
2173
|
*/
|
|
1948
2174
|
private _agentToolRunsByRequestId;
|
|
1949
2175
|
private _submissionTableEnsured;
|
|
1950
|
-
private _workflowNotificationTableEnsured;
|
|
1951
2176
|
private _declaredScheduledTasksTableEnsured;
|
|
2177
|
+
private _warnedFacetScheduledTasksDisarmed;
|
|
1952
2178
|
private _actionLedgerTableEnsured;
|
|
1953
2179
|
private _actionPendingTableEnsured;
|
|
1954
|
-
private _drainingSubmissions;
|
|
1955
|
-
private _drainingWorkflowNotifications;
|
|
1956
2180
|
private _submissionAbortControllers;
|
|
2181
|
+
private _submissionsApplyingMessages;
|
|
1957
2182
|
private _programmaticStreamErrors;
|
|
1958
2183
|
protected static submissionRecoveryStaleMs: number;
|
|
1959
2184
|
broadcast(
|
|
1960
2185
|
msg: string | ArrayBuffer | ArrayBufferView,
|
|
1961
2186
|
without?: string[]
|
|
1962
2187
|
): void;
|
|
2188
|
+
/**
|
|
2189
|
+
* Durably record a run's stream error on its still-open child-run row, so a
|
|
2190
|
+
* stale-row reconcile after an eviction (before the finalizer seals `error`)
|
|
2191
|
+
* still sees the failure. Leaves `status` to the finalizer / reconcile.
|
|
2192
|
+
*/
|
|
2193
|
+
private _recordAgentToolStreamError;
|
|
1963
2194
|
/**
|
|
1964
2195
|
* Resolve the agent-tool run whose turn owns a request id, or null when the
|
|
1965
2196
|
* request is not an agent-tool turn. Falls back to the persisted child-run
|
|
@@ -1986,7 +2217,7 @@ declare class Think<
|
|
|
1986
2217
|
*
|
|
1987
2218
|
* Safe to call on EVERY recovery continuation:
|
|
1988
2219
|
* - Facets that never ran as an agent-tool child have no
|
|
1989
|
-
* `cf_agent_tool_child_runs` table → the
|
|
2220
|
+
* `cf_agent_tool_child_runs` table → no-op (the table is not created).
|
|
1990
2221
|
* - A facet whose run already settled has no `starting`/`running` row → no-op.
|
|
1991
2222
|
* - A child DO is addressed by its `runId` (`subAgent(cls, runId)`), so it
|
|
1992
2223
|
* owns AT MOST ONE child-run row for its whole lifetime and is never reused
|
|
@@ -1999,7 +2230,6 @@ declare class Think<
|
|
|
1999
2230
|
* invariant note there).
|
|
2000
2231
|
*/
|
|
2001
2232
|
private _rebindAgentToolChildRunRequestId;
|
|
2002
|
-
alarm(): Promise<void>;
|
|
2003
2233
|
/**
|
|
2004
2234
|
* Persist an arbitrary JSON-serializable configuration object for this
|
|
2005
2235
|
* agent instance. Stored in the Think-private `think_config` table —
|
|
@@ -2084,6 +2314,22 @@ declare class Think<
|
|
|
2084
2314
|
* lifetime of the agent (the default `this.env.AI` always is).
|
|
2085
2315
|
*/
|
|
2086
2316
|
private _defaultProvider?;
|
|
2317
|
+
/**
|
|
2318
|
+
* Return AI Gateway options for a string model resolved by the default
|
|
2319
|
+
* provider. Called on every {@link resolveModel} call: once per turn for the
|
|
2320
|
+
* default model (skipped when `beforeTurn` returns its own `model` without
|
|
2321
|
+
* reading `ctx.model`), plus once for each string `model` override returned
|
|
2322
|
+
* from `beforeTurn` or `beforeStep`. It can read {@link activeTurn}, the
|
|
2323
|
+
* messenger context, or agent state. Use it to pick a gateway `id` and to
|
|
2324
|
+
* attach `metadata`, which AI Gateway records on the request log as
|
|
2325
|
+
* `cf-aig-metadata`. It must return synchronously; a returned Promise is
|
|
2326
|
+
* rejected with an error.
|
|
2327
|
+
*
|
|
2328
|
+
* Defaults to `undefined`: catalog slugs use the account's `default`
|
|
2329
|
+
* gateway, and `@cf/...` ids call Workers AI without a gateway. Not called
|
|
2330
|
+
* for a model that is already a `LanguageModel`.
|
|
2331
|
+
*/
|
|
2332
|
+
getGateway(_model: string): GatewayOptions | undefined;
|
|
2087
2333
|
/**
|
|
2088
2334
|
* Resolve a model value into a concrete AI SDK `LanguageModel`.
|
|
2089
2335
|
*
|
|
@@ -2116,12 +2362,22 @@ declare class Think<
|
|
|
2116
2362
|
*/
|
|
2117
2363
|
configureChannels(): ThinkChannels | Promise<ThinkChannels>;
|
|
2118
2364
|
getMessengerContext(): MessengerContext | undefined;
|
|
2365
|
+
private _activeMessengerContext;
|
|
2119
2366
|
chatWithMessengerContext(
|
|
2120
2367
|
userMessage: string | UIMessage,
|
|
2121
2368
|
callback: StreamCallback,
|
|
2122
2369
|
context: MessengerContext,
|
|
2123
2370
|
options?: ChatOptions
|
|
2124
2371
|
): Promise<void>;
|
|
2372
|
+
/**
|
|
2373
|
+
* The turn currently running on this agent, readable from `beforeTurn`,
|
|
2374
|
+
* `beforeToolCall`, tool `execute`, `onChatResponse` and anything they call.
|
|
2375
|
+
* Undefined outside a turn, including from code a turn scheduled to run
|
|
2376
|
+
* later.
|
|
2377
|
+
*/
|
|
2378
|
+
get activeTurn(): ActiveTurn | undefined;
|
|
2379
|
+
/** The admitted-turn store of the turn running now, if the caller is in it. */
|
|
2380
|
+
private _activeAdmittedTurn;
|
|
2125
2381
|
/**
|
|
2126
2382
|
* Bind the live messenger delivery surface for the active turn so
|
|
2127
2383
|
* `deliverNotice` can post to the originating channel while a messenger turn
|
|
@@ -2132,6 +2388,8 @@ declare class Think<
|
|
|
2132
2388
|
/**
|
|
2133
2389
|
* The channel context for the active turn, if the turn resolved to a channel.
|
|
2134
2390
|
* Readable from tools/hooks during a turn (e.g. to branch on `kind`).
|
|
2391
|
+
* Undefined outside a turn, like {@link activeTurn} — including from work a
|
|
2392
|
+
* turn left behind that runs while a later turn holds another channel.
|
|
2135
2393
|
*/
|
|
2136
2394
|
get activeChannel(): ChannelContext | undefined;
|
|
2137
2395
|
/**
|
|
@@ -2164,6 +2422,7 @@ declare class Think<
|
|
|
2164
2422
|
private _turnMetadataFromMessages;
|
|
2165
2423
|
/** Re-resolve the channel for a continuation from the latest user message. */
|
|
2166
2424
|
private _channelFromLatestUserMessage;
|
|
2425
|
+
private _channelForAutoContinuation;
|
|
2167
2426
|
/**
|
|
2168
2427
|
* Deliver a no-turn, channel-routed message — a deterministic status, fallback,
|
|
2169
2428
|
* or notice — straight to the channel's delivery surface WITHOUT invoking the
|
|
@@ -2186,6 +2445,24 @@ declare class Think<
|
|
|
2186
2445
|
},
|
|
2187
2446
|
options?: DeliverNoticeOptions
|
|
2188
2447
|
): Promise<void>;
|
|
2448
|
+
/**
|
|
2449
|
+
* Post a recovered messenger reply, or the interrupted apology, to a thread.
|
|
2450
|
+
* Called by a conversation sub-agent (or this agent) once chat recovery of
|
|
2451
|
+
* an interrupted messenger turn settles; only the host holds the messenger
|
|
2452
|
+
* runtime (#2106).
|
|
2453
|
+
*
|
|
2454
|
+
* @internal
|
|
2455
|
+
*/
|
|
2456
|
+
_cf_deliverRecoveredMessengerReply(input: {
|
|
2457
|
+
messengerId: string;
|
|
2458
|
+
threadId: string;
|
|
2459
|
+
outcome: "completed" | "interrupted";
|
|
2460
|
+
text?: string;
|
|
2461
|
+
partialPosted?: boolean;
|
|
2462
|
+
chunk: number;
|
|
2463
|
+
}): Promise<{
|
|
2464
|
+
chunks: number;
|
|
2465
|
+
}>;
|
|
2189
2466
|
/**
|
|
2190
2467
|
* The active turn's channel id, if any. Prefers the turn-scoped channel
|
|
2191
2468
|
* context, then the active messenger turn's id; web turns have none, so
|
|
@@ -2196,6 +2473,26 @@ declare class Think<
|
|
|
2196
2473
|
private _initializeChannels;
|
|
2197
2474
|
/** Return code-declared scheduled tasks for this agent. */
|
|
2198
2475
|
getScheduledTasks(): ThinkScheduledTasks | Promise<ThinkScheduledTasks>;
|
|
2476
|
+
/**
|
|
2477
|
+
* Return which instances of this class arm the declared scheduled tasks.
|
|
2478
|
+
*
|
|
2479
|
+
* `"root"` (the default) arms them only on the top-level agent. Because
|
|
2480
|
+
* `getScheduledTasks()` is usually a static code declaration, it returns the
|
|
2481
|
+
* same tasks on every instance — so without this scope an agent that also
|
|
2482
|
+
* has sub-agents would arm one private copy per live facet and dispatch each
|
|
2483
|
+
* occurrence once per facet on top of the root (#1877).
|
|
2484
|
+
*
|
|
2485
|
+
* Return `"all"` to arm on facets as well. That is only correct when
|
|
2486
|
+
* `getScheduledTasks()` genuinely varies per facet (for example when it
|
|
2487
|
+
* reads per-facet state), since each facet then owns an independent
|
|
2488
|
+
* schedule.
|
|
2489
|
+
*
|
|
2490
|
+
* The value must be stable across wakes. Reporting `"root"` on a facet that
|
|
2491
|
+
* previously armed cancels its occurrences, so a scope that flickers with
|
|
2492
|
+
* request-scoped or not-yet-loaded state will repeatedly tear down and
|
|
2493
|
+
* re-create that facet's schedule.
|
|
2494
|
+
*/
|
|
2495
|
+
getScheduledTasksScope(): "root" | "all" | Promise<"root" | "all">;
|
|
2199
2496
|
/**
|
|
2200
2497
|
* Reconcile code-declared scheduled tasks immediately.
|
|
2201
2498
|
* Static declarations are reconciled on startup automatically; call this
|
|
@@ -2213,6 +2510,12 @@ declare class Think<
|
|
|
2213
2510
|
* it — the definition's `recover` callback hands the interruption to the
|
|
2214
2511
|
* shared ChatRecoveryEngine instead.
|
|
2215
2512
|
*/
|
|
2513
|
+
/**
|
|
2514
|
+
* Start time and latest `stash()` data of each chat turn running in this
|
|
2515
|
+
* isolate, keyed by request id. A stream stall is recovered while the turn is
|
|
2516
|
+
* still live, so `onChatRecovery` reads these instead of a fiber snapshot.
|
|
2517
|
+
*/
|
|
2518
|
+
private readonly _liveChatRecoveryTurns;
|
|
2216
2519
|
private readonly _liveChatTurnClosures;
|
|
2217
2520
|
/**
|
|
2218
2521
|
* Register the shared chat-turn Task definition (see
|
|
@@ -2258,10 +2561,25 @@ declare class Think<
|
|
|
2258
2561
|
accepted: boolean;
|
|
2259
2562
|
}>;
|
|
2260
2563
|
private _runChatRecoveryFiber;
|
|
2564
|
+
private _runWrappedChatRecoveryFiber;
|
|
2261
2565
|
private _systemPromptForTurn;
|
|
2262
2566
|
private _buildThinkCapabilityBlock;
|
|
2263
2567
|
/** Maximum number of tool-call steps per turn. Override via property or per-turn via TurnConfig. */
|
|
2264
2568
|
maxSteps: number;
|
|
2569
|
+
/**
|
|
2570
|
+
* Read-time truncation moves its cutoff once every this many messages, so
|
|
2571
|
+
* the provider's cached prompt prefix survives the turns in between. Up to
|
|
2572
|
+
* `truncationStep + 3` recent messages stay at full fidelity. Set it to `1`
|
|
2573
|
+
* to cut every turn, which keeps the fewest full-fidelity messages for
|
|
2574
|
+
* models with a small context window. `Infinity` never moves the cutoff, so
|
|
2575
|
+
* read-time truncation is off and every message stays at full fidelity;
|
|
2576
|
+
* media eviction then keeps exactly `keepRecentMessages` and rewrites the
|
|
2577
|
+
* prefix whenever a message ages out. Other non-finite or non-positive
|
|
2578
|
+
* values behave like `1`.
|
|
2579
|
+
*
|
|
2580
|
+
* @default 8
|
|
2581
|
+
*/
|
|
2582
|
+
truncationStep: number;
|
|
2265
2583
|
/**
|
|
2266
2584
|
* Retention window for settled action ledger rows. Deleting a row ends the
|
|
2267
2585
|
* idempotency guarantee for that key, so increase these windows for side
|
|
@@ -2297,6 +2615,16 @@ declare class Think<
|
|
|
2297
2615
|
* per turn by returning `sendReasoning` from `beforeTurn`.
|
|
2298
2616
|
*/
|
|
2299
2617
|
sendReasoning: boolean;
|
|
2618
|
+
/**
|
|
2619
|
+
* Default writer for server-authored assistant-message metadata, applied to
|
|
2620
|
+
* every turn. Override (or supply) per turn by returning `messageMetadata`
|
|
2621
|
+
* from `beforeTurn` ({@link TurnConfig.messageMetadata}). Set this when the
|
|
2622
|
+
* metadata is turn-independent — e.g. stamping a `createdAt` timestamp on
|
|
2623
|
+
* every assistant message — so callers need not repeat it in `beforeTurn`.
|
|
2624
|
+
* See {@link MessageMetadataCallback} for when it is called and the
|
|
2625
|
+
* serialization constraints on its return value.
|
|
2626
|
+
*/
|
|
2627
|
+
messageMetadata?: MessageMetadataCallback;
|
|
2300
2628
|
/**
|
|
2301
2629
|
* Inactivity watchdog for the streaming read loop, in milliseconds.
|
|
2302
2630
|
*
|
|
@@ -2354,6 +2682,14 @@ declare class Think<
|
|
|
2354
2682
|
* are serialized, so a single value is safe.
|
|
2355
2683
|
*/
|
|
2356
2684
|
private _turnModelMessageBaseline;
|
|
2685
|
+
/** The context reminder the current turn was assembled with. */
|
|
2686
|
+
private _turnContextReminder;
|
|
2687
|
+
/**
|
|
2688
|
+
* The last message the current turn's model history reaches, when that is
|
|
2689
|
+
* not the leaf: a regeneration answers its parent user message, so the
|
|
2690
|
+
* response it replaces (a stored sibling branch) stays out of the prompt.
|
|
2691
|
+
*/
|
|
2692
|
+
private _turnHistoryLeafId;
|
|
2357
2693
|
/**
|
|
2358
2694
|
* The assembled tool set for the current turn, captured in
|
|
2359
2695
|
* `_runInferenceLoop`. The proactive guard reuses it to convert the
|
|
@@ -2671,15 +3007,16 @@ declare class Think<
|
|
|
2671
3007
|
* knowledge into core. The app does know its provider/model, so it owns the
|
|
2672
3008
|
* mapping — the same split Think already uses for `tokenCounter`.
|
|
2673
3009
|
*
|
|
2674
|
-
*
|
|
2675
|
-
*
|
|
2676
|
-
*
|
|
2677
|
-
*
|
|
2678
|
-
* classification
|
|
2679
|
-
*
|
|
2680
|
-
*
|
|
2681
|
-
*
|
|
2682
|
-
* `void
|
|
3010
|
+
* Think consults it when a turn's stream errors. Return `"context_overflow"`
|
|
3011
|
+
* to run the compact-and-retry backstop (only when `contextOverflow.reactive`
|
|
3012
|
+
* is enabled); if recovery cannot save the turn, that classification is
|
|
3013
|
+
* surfaced on the terminal `onChatError` call via
|
|
3014
|
+
* {@link ChatErrorContext.classification}. Return `"transient"` or
|
|
3015
|
+
* `"rate_limit"` to route the turn into bounded chat recovery (the same path
|
|
3016
|
+
* as a stream stall: `onChatRecovery`, `chatRecovery.maxAttempts`, then the
|
|
3017
|
+
* exhaustion message), with the continuation delayed by exponential backoff.
|
|
3018
|
+
* Returning `void`, `"fatal"`, or `"unknown"` keeps the existing terminal
|
|
3019
|
+
* behavior.
|
|
2683
3020
|
*
|
|
2684
3021
|
* The argument may be an `Error`, an AI SDK `APICallError` (with
|
|
2685
3022
|
* `statusCode`/`responseBody`), or — for in-stream provider errors that
|
|
@@ -2706,12 +3043,28 @@ declare class Think<
|
|
|
2706
3043
|
_ctx?: ChatErrorContext
|
|
2707
3044
|
): ChatErrorClassification | void;
|
|
2708
3045
|
/**
|
|
2709
|
-
*
|
|
2710
|
-
*
|
|
2711
|
-
*
|
|
2712
|
-
|
|
3046
|
+
* The app's `classifyChatError` verdict for a stream error (thrown or
|
|
3047
|
+
* surfaced as an in-stream error string). Call once per error: the hook may
|
|
3048
|
+
* be stateful or have side effects.
|
|
3049
|
+
*/
|
|
3050
|
+
private _classifyStreamError;
|
|
3051
|
+
/**
|
|
3052
|
+
* Whether a classified stream error should trigger the opt-in
|
|
3053
|
+
* compact-and-retry backstop. Centralized so both stream consumers
|
|
3054
|
+
* (WebSocket + RPC) decide identically.
|
|
2713
3055
|
*/
|
|
2714
3056
|
private _isRecoverableContextOverflow;
|
|
3057
|
+
/**
|
|
3058
|
+
* The `"transient"` or `"rate_limit"` class the app assigned a stream
|
|
3059
|
+
* error, else `undefined`. Such errors route into bounded chat recovery like
|
|
3060
|
+
* a stream stall instead of terminalizing the turn (#2085). Without a
|
|
3061
|
+
* `classifyChatError` override nothing is transient, so today's terminal
|
|
3062
|
+
* behavior is unchanged. A Durable Object reset is never transient here: the
|
|
3063
|
+
* restart's own recovery owns the turn.
|
|
3064
|
+
*/
|
|
3065
|
+
private _transientStreamClassification;
|
|
3066
|
+
/** The provider `Retry-After` to honor for a rate-limited stream error. */
|
|
3067
|
+
private _streamErrorRetryAfter;
|
|
2715
3068
|
/**
|
|
2716
3069
|
* Compact the session in response to a context overflow (reactive backstop or
|
|
2717
3070
|
* proactive guard). Returns whether history was actually shortened — a no-op
|
|
@@ -2732,6 +3085,14 @@ declare class Think<
|
|
|
2732
3085
|
*/
|
|
2733
3086
|
private _finalizeContextOverflowError;
|
|
2734
3087
|
private _initializeExtensions;
|
|
3088
|
+
/**
|
|
3089
|
+
* The repaired history the current turn's model request is built from: the
|
|
3090
|
+
* active path, cut at `_turnHistoryLeafId` when one is set. A leaf off the
|
|
3091
|
+
* cached path (another branch, or outside a windowed cache) is read from
|
|
3092
|
+
* storage. The cut comes before repair so messages past the leaf, which the
|
|
3093
|
+
* request never sees, are not rewritten.
|
|
3094
|
+
*/
|
|
3095
|
+
private _turnHistory;
|
|
2735
3096
|
/**
|
|
2736
3097
|
* Assemble provider-ready model messages from the current session history:
|
|
2737
3098
|
* repair the transcript, truncate older messages, drop any still-incomplete
|
|
@@ -2778,7 +3139,8 @@ declare class Think<
|
|
|
2778
3139
|
/**
|
|
2779
3140
|
* The single convergence point for all chat turn entry paths.
|
|
2780
3141
|
* Merges tools, assembles context, fires lifecycle hooks, wraps tools
|
|
2781
|
-
* for interception, and calls streamText.
|
|
3142
|
+
* for interception, and calls streamText. `historyLeafId` cuts the model
|
|
3143
|
+
* history at that message (see `_turnHistoryLeafId`).
|
|
2782
3144
|
*/
|
|
2783
3145
|
private _runInferenceLoop;
|
|
2784
3146
|
private _prepareInferenceInvocation;
|
|
@@ -2950,8 +3312,10 @@ declare class Think<
|
|
|
2950
3312
|
* an active turn (a tool `execute`, a lifecycle hook) deadlocks on the turn
|
|
2951
3313
|
* queue — identical to calling {@link Think.saveMessages} or
|
|
2952
3314
|
* {@link Think.continueLastTurn} from there. Prefer `mode: "submit"` or
|
|
2953
|
-
* {@link Think.addMessages} instead.
|
|
2954
|
-
*
|
|
3315
|
+
* {@link Think.addMessages} instead. A submitted turn runs only after the
|
|
3316
|
+
* current turn ends, so {@link Think.waitForSubmission} on it from inside
|
|
3317
|
+
* the turn throws rather than deadlocking. Precise nested-call detection is
|
|
3318
|
+
* deferred to `_admitTurn` (step 3).
|
|
2955
3319
|
*
|
|
2956
3320
|
* **Empty input (`wait`).** String, single-message, and array inputs that
|
|
2957
3321
|
* normalize to an empty list short-circuit to `{ status: "skipped" }` without
|
|
@@ -3077,6 +3441,7 @@ declare class Think<
|
|
|
3077
3441
|
input: unknown,
|
|
3078
3442
|
options: {
|
|
3079
3443
|
runId: string;
|
|
3444
|
+
eventDelivery?: "full" | "terminal";
|
|
3080
3445
|
}
|
|
3081
3446
|
): Promise<AgentToolRunInspection>;
|
|
3082
3447
|
cancelAgentToolRun(runId: string, reason?: unknown): Promise<void>;
|
|
@@ -3088,7 +3453,12 @@ declare class Think<
|
|
|
3088
3453
|
* completed recovery deletes its incident.
|
|
3089
3454
|
*/
|
|
3090
3455
|
private _classifyAgentToolChildRecovery;
|
|
3091
|
-
inspectAgentToolRun(
|
|
3456
|
+
inspectAgentToolRun(
|
|
3457
|
+
runId: string,
|
|
3458
|
+
options?: {
|
|
3459
|
+
reconcile?: boolean;
|
|
3460
|
+
}
|
|
3461
|
+
): Promise<AgentToolRunInspection | null>;
|
|
3092
3462
|
private _isStaleAgentToolChildRun;
|
|
3093
3463
|
/**
|
|
3094
3464
|
* Reconcile a stale (post-eviction) child run row from the child's own
|
|
@@ -3127,6 +3497,16 @@ declare class Think<
|
|
|
3127
3497
|
afterSequence?: number;
|
|
3128
3498
|
}
|
|
3129
3499
|
): Promise<AgentToolStoredChunk[]>;
|
|
3500
|
+
/**
|
|
3501
|
+
* After this DO restarts, `_agentToolLiveSequences` is cold while the stored
|
|
3502
|
+
* backlog sits at N, and a chat-recovery resume re-attaches via
|
|
3503
|
+
* `tailAgentToolRun` without re-running `startAgentToolRun` (which seeds the
|
|
3504
|
+
* counter). Unseeded, the broadcast snoop numbers the recovered turn's chunks
|
|
3505
|
+
* from 0 and the tail's high-water dedupe drops them. Seeds only a
|
|
3506
|
+
* non-terminal run, so a terminal one doesn't re-heat the broadcast
|
|
3507
|
+
* idle-guard; a warm counter is authoritative. Returns whether it seeded.
|
|
3508
|
+
*/
|
|
3509
|
+
private _seedAgentToolLiveSequence;
|
|
3130
3510
|
tailAgentToolRun(
|
|
3131
3511
|
runId: string,
|
|
3132
3512
|
options?: {
|
|
@@ -3203,9 +3583,30 @@ declare class Think<
|
|
|
3203
3583
|
private _normalizeDeclaredScheduledTasks;
|
|
3204
3584
|
private _declaredScheduledTasksForNow;
|
|
3205
3585
|
private _declaredScheduleOwnerKey;
|
|
3586
|
+
/**
|
|
3587
|
+
* Whether this instance arms the declared scheduled tasks.
|
|
3588
|
+
*
|
|
3589
|
+
* The root always arms. Facets only arm when the class opts in via
|
|
3590
|
+
* `getScheduledTasksScope()`; see that hook for why root-only is the
|
|
3591
|
+
* default (#1877). `parentPath` is hydrated before the reconcile step of
|
|
3592
|
+
* `onStart` — persisted by `_cf_initAsFacet` on a facet's first boot, and
|
|
3593
|
+
* restored from storage by the base agent on every later wake.
|
|
3594
|
+
*/
|
|
3595
|
+
private _declaredScheduledTasksArmedHere;
|
|
3206
3596
|
private _declaredScheduleValidationError;
|
|
3207
3597
|
private _nextDeclaredScheduleTimeForConfig;
|
|
3208
3598
|
private _reconcileDeclaredScheduledTasks;
|
|
3599
|
+
/**
|
|
3600
|
+
* Warn once when a sub-agent declares tasks it will not arm.
|
|
3601
|
+
*
|
|
3602
|
+
* Two populations need this, and only one of them leaves a trace. A facet
|
|
3603
|
+
* upgrading from the pre-#1877 default has rows to prune, so `armedCount`
|
|
3604
|
+
* is non-zero. A facet declaring tasks for the first time under the root
|
|
3605
|
+
* default never armed anything, so the only way to tell it apart from a
|
|
3606
|
+
* class that declares nothing is to ask — otherwise its schedule is
|
|
3607
|
+
* silently inert, which is the failure mode #1877 was filed about.
|
|
3608
|
+
*/
|
|
3609
|
+
private _warnFacetScheduledTasksDisarmed;
|
|
3209
3610
|
private _scheduleDeclaredTaskOccurrence;
|
|
3210
3611
|
private _scheduleDeclaredTaskOccurrenceAt;
|
|
3211
3612
|
private _advanceDeclaredScheduledTask;
|
|
@@ -3214,7 +3615,6 @@ declare class Think<
|
|
|
3214
3615
|
payload: DeclaredScheduledTaskPayload
|
|
3215
3616
|
): Promise<void>;
|
|
3216
3617
|
private _ensureSubmissionTable;
|
|
3217
|
-
private _ensureWorkflowNotificationTable;
|
|
3218
3618
|
private _readSubmission;
|
|
3219
3619
|
private _readSubmissionByIdempotencyKey;
|
|
3220
3620
|
private _normalizeStatusFilter;
|
|
@@ -3227,29 +3627,74 @@ declare class Think<
|
|
|
3227
3627
|
private _serializeMetadata;
|
|
3228
3628
|
private _readWorkflowPromptContext;
|
|
3229
3629
|
private _emitSubmissionStatus;
|
|
3630
|
+
private _resolveSubmissionWaiters;
|
|
3631
|
+
private _submissionWaiters;
|
|
3632
|
+
/**
|
|
3633
|
+
* Submissions whose row is terminal but whose `onSubmissionStatus` has not
|
|
3634
|
+
* finished. `waitForSubmission` keeps waiting for these.
|
|
3635
|
+
*/
|
|
3636
|
+
private _terminalStatusEmits;
|
|
3637
|
+
/** Waiters of a submission deleted while its terminal emit was in flight. */
|
|
3638
|
+
private _waitersHeldForDeletedEmit;
|
|
3639
|
+
/**
|
|
3640
|
+
* Resolve once the submission reaches a terminal status (`completed`,
|
|
3641
|
+
* `aborted`, `skipped` or `error`), after `onSubmissionStatus` has run for
|
|
3642
|
+
* it. Resolves immediately for a submission that already finished, and with
|
|
3643
|
+
* `null` for an unknown id. An `error` status resolves rather than rejects;
|
|
3644
|
+
* read `status` and `error` from the result.
|
|
3645
|
+
*
|
|
3646
|
+
* The wait lives in this object's memory, so it rejects if the object
|
|
3647
|
+
* restarts. The submission itself is durable: call again to keep waiting.
|
|
3648
|
+
*
|
|
3649
|
+
* Throws when called from inside a turn (a tool `execute`, a lifecycle
|
|
3650
|
+
* hook) or from `onSubmissionStatus` for a submission that has not
|
|
3651
|
+
* finished: a submission only runs once the current turn frees the turn
|
|
3652
|
+
* queue, and its status settles only after the hook returns, so the wait
|
|
3653
|
+
* could never resolve. Return the submission id and wait from outside the
|
|
3654
|
+
* turn instead.
|
|
3655
|
+
*/
|
|
3656
|
+
waitForSubmission(
|
|
3657
|
+
submissionId: string,
|
|
3658
|
+
options?: WaitForSubmissionOptions
|
|
3659
|
+
): Promise<ThinkSubmissionInspection | null>;
|
|
3230
3660
|
protected onSubmissionStatus(
|
|
3231
3661
|
_submission: ThinkSubmissionInspection
|
|
3232
3662
|
): void | Promise<void>;
|
|
3233
|
-
private _enqueueWorkflowNotification;
|
|
3234
|
-
private _insertWorkflowNotification;
|
|
3235
|
-
private _recoverWorkflowNotifications;
|
|
3236
|
-
private _startWorkflowNotificationDrain;
|
|
3237
|
-
private _hasPendingWorkflowNotifications;
|
|
3238
|
-
private _drainWorkflowNotifications;
|
|
3239
|
-
private _nextWorkflowNotificationAlarm;
|
|
3240
3663
|
/**
|
|
3241
|
-
*
|
|
3242
|
-
*
|
|
3664
|
+
* Queue the workflow event for a submission that just went terminal.
|
|
3665
|
+
*
|
|
3666
|
+
* The item is written synchronously (the Lifecycle has started whenever a
|
|
3667
|
+
* submission transitions), so call this in the same synchronous block as
|
|
3668
|
+
* the terminal status write: the two commit together and no recovery scan
|
|
3669
|
+
* is needed. A repeated push for the same submission and event type
|
|
3670
|
+
* replaces the pending item rather than duplicating it.
|
|
3243
3671
|
*/
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3672
|
+
private _insertWorkflowNotification;
|
|
3673
|
+
/** Queue the workflow event for a row that a caller just made terminal. */
|
|
3674
|
+
private _enqueueTerminalWorkflowNotification;
|
|
3675
|
+
/**
|
|
3676
|
+
* Deliver one workflow notification. Runs from the queue on first
|
|
3677
|
+
* delivery; a failed delivery schedules this same callback again with
|
|
3678
|
+
* exponential backoff (2s doubling, capped at ten minutes) so a
|
|
3679
|
+
* temporarily unreachable workflow still gets its terminal event. Once
|
|
3680
|
+
* the first failure is twelve hours old delivery gives up by throwing:
|
|
3681
|
+
* the dispatching capability reports it through its error event and the
|
|
3682
|
+
* Agent's `onError`.
|
|
3683
|
+
* @internal Queue and schedule callback.
|
|
3684
|
+
*/
|
|
3685
|
+
_cfDeliverWorkflowNotification(
|
|
3686
|
+
payload: WorkflowNotificationPayload
|
|
3687
|
+
): Promise<void>;
|
|
3248
3688
|
/**
|
|
3249
|
-
*
|
|
3250
|
-
*
|
|
3689
|
+
* Move undelivered rows of the retired `cf_think_workflow_notifications`
|
|
3690
|
+
* outbox into the queue and drop the table. Idempotent: a missing table
|
|
3691
|
+
* means a fresh object or a completed migration.
|
|
3692
|
+
*
|
|
3693
|
+
* TEMPORARY: one-shot upgrade path for objects that were mid-delivery when
|
|
3694
|
+
* this release landed. Remove in the next minor release, once every
|
|
3695
|
+
* deployed object has started on this version and migrated.
|
|
3251
3696
|
*/
|
|
3252
|
-
private
|
|
3697
|
+
private _migrateLegacyWorkflowNotifications;
|
|
3253
3698
|
inspectSubmission(
|
|
3254
3699
|
submissionId: string
|
|
3255
3700
|
): Promise<ThinkSubmissionInspection | null>;
|
|
@@ -3257,19 +3702,34 @@ declare class Think<
|
|
|
3257
3702
|
options?: ListSubmissionsOptions
|
|
3258
3703
|
): Promise<ThinkSubmissionInspection[]>;
|
|
3259
3704
|
deleteSubmission(submissionId: string): Promise<boolean>;
|
|
3705
|
+
private _releaseDeletedSubmissionWaiters;
|
|
3260
3706
|
deleteSubmissions(options?: DeleteSubmissionsOptions): Promise<number>;
|
|
3261
3707
|
private _listTerminalSubmissionRowsForDelete;
|
|
3262
3708
|
private _isTerminalSubmissionStatus;
|
|
3263
|
-
cancelSubmission(
|
|
3709
|
+
cancelSubmission(
|
|
3710
|
+
submissionId: string,
|
|
3711
|
+
reason?: unknown
|
|
3712
|
+
): Promise<CancelSubmissionResult>;
|
|
3264
3713
|
submitMessages(
|
|
3265
3714
|
messages: UIMessage[],
|
|
3266
3715
|
options?: SubmitMessagesOptions
|
|
3267
3716
|
): Promise<SubmitMessagesResult>;
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3717
|
+
/**
|
|
3718
|
+
* Queue the run of one pending submission. Idempotent: the stable id
|
|
3719
|
+
* replaces an item already queued for the submission in place, keeping
|
|
3720
|
+
* its FIFO slot, and re-arms the physical alarm so a lost alarm recovers.
|
|
3721
|
+
*/
|
|
3722
|
+
private _queueSubmissionRun;
|
|
3723
|
+
/** Queue a run for every pending submission that has none. */
|
|
3724
|
+
private _queuePendingSubmissionRuns;
|
|
3725
|
+
/**
|
|
3726
|
+
* Run one pending submission. Runs on the Lifecycle alarm loop through the
|
|
3727
|
+
* Queue capability, one item at a time in submission order; a row that is
|
|
3728
|
+
* no longer pending (cancelled, skipped, or claimed by an overlapping
|
|
3729
|
+
* dispatch) is a no-op.
|
|
3730
|
+
* @internal Queue callback.
|
|
3731
|
+
*/
|
|
3732
|
+
_cfRunSubmission(payload: { submissionId: string }): Promise<void>;
|
|
3273
3733
|
private _executeSubmission;
|
|
3274
3734
|
private _getSubmissionFinalStatus;
|
|
3275
3735
|
private _markPendingSubmissionsSkipped;
|
|
@@ -3284,7 +3744,7 @@ declare class Think<
|
|
|
3284
3744
|
private _recoverableChatTurnTaskCreatedAt;
|
|
3285
3745
|
private _hasRecoverableChatTurn;
|
|
3286
3746
|
private _hasFreshRecoverableSubmissionEvidence;
|
|
3287
|
-
private
|
|
3747
|
+
private _hasScheduledChatRecovery;
|
|
3288
3748
|
/**
|
|
3289
3749
|
* Inject messages and trigger a model turn — without a WebSocket request.
|
|
3290
3750
|
*
|
|
@@ -3380,7 +3840,8 @@ declare class Think<
|
|
|
3380
3840
|
* (Phase 4), "generate more" buttons, and self-correction.
|
|
3381
3841
|
*
|
|
3382
3842
|
* Note: this creates a new message, not an append to the existing one.
|
|
3383
|
-
*
|
|
3843
|
+
* Recovery continuations (`trigger: "recovery-continue"`) are the exception:
|
|
3844
|
+
* they stream into the interrupted assistant message so it stays one message.
|
|
3384
3845
|
*
|
|
3385
3846
|
* Returns early with `status: "skipped"` if there is no assistant message
|
|
3386
3847
|
* to continue from.
|
|
@@ -3395,6 +3856,7 @@ declare class Think<
|
|
|
3395
3856
|
channel?: string;
|
|
3396
3857
|
}
|
|
3397
3858
|
): Promise<SaveMessagesResult>;
|
|
3859
|
+
private _continueLastTurn;
|
|
3398
3860
|
private _retryLastUserTurn;
|
|
3399
3861
|
private _setupProtocolHandlers;
|
|
3400
3862
|
private _handleProtocolEvent;
|
|
@@ -3431,6 +3893,17 @@ declare class Think<
|
|
|
3431
3893
|
* without requiring the caller to know the id.
|
|
3432
3894
|
*/
|
|
3433
3895
|
cancelChat(requestId: string, reason?: string): void;
|
|
3896
|
+
/**
|
|
3897
|
+
* A cancel can land while the turn's recovery is waiting out its backoff,
|
|
3898
|
+
* with nothing in flight to abort: cancel the scheduled recovery instead,
|
|
3899
|
+
* so the queued callback bails when it fires.
|
|
3900
|
+
*/
|
|
3901
|
+
private _cancelScheduledRecovery;
|
|
3902
|
+
/**
|
|
3903
|
+
* Whether the user cancelled this recovery while it was scheduled. A
|
|
3904
|
+
* submission the recovery owned settles as `aborted`.
|
|
3905
|
+
*/
|
|
3906
|
+
private _recoveryCancelled;
|
|
3434
3907
|
/** Abort every in-flight chat turn on this agent. */
|
|
3435
3908
|
cancelAllChats(): void;
|
|
3436
3909
|
protected abortRequest(requestId: string, reason?: unknown): void;
|
|
@@ -3506,6 +3979,7 @@ declare class Think<
|
|
|
3506
3979
|
* cannot drift between the live and recovery writes.
|
|
3507
3980
|
*/
|
|
3508
3981
|
private _strippedForPersist;
|
|
3982
|
+
/** Resolves to `false` when stripping left nothing to persist. */
|
|
3509
3983
|
private _persistAssistantMessage;
|
|
3510
3984
|
/**
|
|
3511
3985
|
* The cutover: persist the finished turn's assistant message, settle its
|
|
@@ -3519,9 +3993,25 @@ declare class Think<
|
|
|
3519
3993
|
* Whether this turn's stream rows can go with its cutover. An agent-tool
|
|
3520
3994
|
* child turn keeps them: the parent tails the stored chunks after the
|
|
3521
3995
|
* child completes (`getAgentToolChunks`), so the rows are reclaimed by
|
|
3522
|
-
* the child's next `start()` instead, as `AIChatAgent` does.
|
|
3523
|
-
|
|
3524
|
-
|
|
3996
|
+
* the child's next `start()` instead, as `AIChatAgent` does. A running
|
|
3997
|
+
* submission needs no stream evidence: its durable outcome stamp commits
|
|
3998
|
+
* in the same transaction as this cutover.
|
|
3999
|
+
*/
|
|
4000
|
+
private _streamCutoverOptions;
|
|
4001
|
+
/** Write only inside the transaction that settles this exact request's stream. */
|
|
4002
|
+
private _recordSubmissionTurnResult;
|
|
4003
|
+
private _recordSubmissionMessage;
|
|
4004
|
+
/**
|
|
4005
|
+
* Cancellation settles a submission as `aborted` before the stream persists
|
|
4006
|
+
* its partial; link that message without touching the terminal status. A
|
|
4007
|
+
* row that never started (a reused submission id cancelled while queued)
|
|
4008
|
+
* cannot own the partial.
|
|
4009
|
+
*/
|
|
4010
|
+
private _recordAbortedSubmissionMessage;
|
|
4011
|
+
/** Empty/stripped messages have the same atomic outcome cutover as messages. */
|
|
4012
|
+
private _finalizeSubmissionStream;
|
|
4013
|
+
/** Keep overflow chunks for consumers, but never call that segment an answer. */
|
|
4014
|
+
private _completeSubmissionRetryStream;
|
|
3525
4015
|
/**
|
|
3526
4016
|
* Remove parts belonging to Think's internal structured-output final-answer
|
|
3527
4017
|
* tool (`think_final_answer`, or a collision-suffixed variant) from a UI
|
|
@@ -3556,16 +4046,19 @@ declare class Think<
|
|
|
3556
4046
|
*/
|
|
3557
4047
|
private _serverTranscriptForReconcile;
|
|
3558
4048
|
/**
|
|
3559
|
-
* Persist an incoming message after reconciliation
|
|
3560
|
-
*
|
|
3561
|
-
*
|
|
3562
|
-
* instead of inserting an orphan duplicate.
|
|
4049
|
+
* Persist an incoming message after batch reconciliation has resolved
|
|
4050
|
+
* assistant IDs (one-to-one against server rows) and merged any
|
|
4051
|
+
* server-owned tool outputs.
|
|
3563
4052
|
*
|
|
3564
4053
|
* A message whose stored form is what the server already holds is skipped
|
|
3565
4054
|
* outright. The client posts its whole transcript on every request, so
|
|
3566
4055
|
* without this every prior message would cost Sessions an existence read
|
|
3567
4056
|
* plus a full-row compare (and, for media, a decode and hash of every
|
|
3568
4057
|
* payload) per turn — reads spent discovering nothing changed.
|
|
4058
|
+
*
|
|
4059
|
+
* Reserved metadata (`channel`, `turnMetadata`) is server-owned. The client's
|
|
4060
|
+
* copy is ignored, a stored row keeps its own, and a new user message gets
|
|
4061
|
+
* `channel` when the caller supplies one.
|
|
3569
4062
|
*/
|
|
3570
4063
|
private _persistIncomingMessage;
|
|
3571
4064
|
/**
|
|
@@ -3672,10 +4165,16 @@ declare class Think<
|
|
|
3672
4165
|
* transcript's paused output is replaced with
|
|
3673
4166
|
* `{ status: "rejected", executionId, reason }` and the chat
|
|
3674
4167
|
* auto-continues so the model can adapt (or explain) instead of erroring.
|
|
4168
|
+
* Pass `{ autoContinue: false }` to record the rejection without starting a
|
|
4169
|
+
* model continuation.
|
|
3675
4170
|
*
|
|
3676
4171
|
* Client-callable.
|
|
3677
4172
|
*/
|
|
3678
|
-
rejectExecution(
|
|
4173
|
+
rejectExecution(
|
|
4174
|
+
executionId: string,
|
|
4175
|
+
reason?: string,
|
|
4176
|
+
options?: RejectExecutionOptions
|
|
4177
|
+
): Promise<unknown>;
|
|
3679
4178
|
/**
|
|
3680
4179
|
* Reject a parked `kind: "durable-pause"` action. Claim-by-delete consumes
|
|
3681
4180
|
* the pending row (idempotent across tabs/recovery), the action's `execute`
|
|
@@ -3698,19 +4197,40 @@ declare class Think<
|
|
|
3698
4197
|
*/
|
|
3699
4198
|
private _applyExecutionOutcome;
|
|
3700
4199
|
/**
|
|
3701
|
-
* Find the tool part
|
|
3702
|
-
*
|
|
3703
|
-
*
|
|
3704
|
-
*/
|
|
3705
|
-
private _findPausedExecutionToolCall;
|
|
3706
|
-
/**
|
|
3707
|
-
* Find the tool part carrying `executionId` in its output. With
|
|
4200
|
+
* Find the tool part carrying `executionId` in its output — in the in-flight
|
|
4201
|
+
* streaming accumulator first (an approval can land while a new turn
|
|
4202
|
+
* streams), then the in-memory transcript, newest message first. With
|
|
3708
4203
|
* `pausedOnly`, only a still-paused output matches — used to locate the
|
|
3709
4204
|
* part an approval outcome should replace. Without it, any settled output
|
|
3710
4205
|
* matches — used to distinguish "already resolved elsewhere" from "the
|
|
3711
4206
|
* part is gone from the transcript" (e.g. compacted away).
|
|
3712
4207
|
*/
|
|
3713
4208
|
private _findExecutionToolCall;
|
|
4209
|
+
/**
|
|
4210
|
+
* {@link _findExecutionToolCall}, falling back to storage when the hydrated
|
|
4211
|
+
* window does not cover the whole transcript, so a long-lived pause is
|
|
4212
|
+
* still resolved in place.
|
|
4213
|
+
*/
|
|
4214
|
+
private _findExecutionToolCallDurably;
|
|
4215
|
+
/**
|
|
4216
|
+
* Text and reasoning the model wrote after a paused tool result were written
|
|
4217
|
+
* against the pending state ("once approved, ..."). Once the pause resolves
|
|
4218
|
+
* they contradict the result, so drop them before the continuation reads the
|
|
4219
|
+
* transcript. Tool, file, and other parts after the pause stay.
|
|
4220
|
+
*
|
|
4221
|
+
* While the turn that paused is still streaming, its accumulator owns the
|
|
4222
|
+
* message and appends deltas to the last text part, so parts cannot be
|
|
4223
|
+
* removed underneath it. The drop is deferred to the next inference, which
|
|
4224
|
+
* is queued behind that turn and runs after it persists.
|
|
4225
|
+
*
|
|
4226
|
+
* The resolved pause stays recorded (see `_rememberResolvedPause`) until
|
|
4227
|
+
* the drop has been applied.
|
|
4228
|
+
*/
|
|
4229
|
+
private _dropGenerationAfterResolvedPause;
|
|
4230
|
+
private _loadResolvedPauses;
|
|
4231
|
+
private _rememberResolvedPause;
|
|
4232
|
+
private _forgetResolvedPause;
|
|
4233
|
+
private _flushDeferredResolvedPauses;
|
|
3714
4234
|
private _applyToolUpdateToMessages;
|
|
3715
4235
|
/**
|
|
3716
4236
|
* The persisted message that owns `toolCallId`, read as one row — or
|
|
@@ -3832,26 +4352,69 @@ declare class Think<
|
|
|
3832
4352
|
* Route a stream-stall watchdog abort into bounded recovery instead of a
|
|
3833
4353
|
* terminal error (#1626). A stall happens inside a LIVE isolate (no DO
|
|
3834
4354
|
* restart), so the normal restart-detected recovery path never runs — we
|
|
3835
|
-
* open/advance a recovery incident here and schedule
|
|
3836
|
-
*
|
|
3837
|
-
* as deploy/eviction recovery. A
|
|
3838
|
-
*
|
|
3839
|
-
*
|
|
3840
|
-
*
|
|
4355
|
+
* open/advance a recovery incident here and schedule recovery, reusing the
|
|
4356
|
+
* SAME budget (`maxAttempts` + wall-clock window + progress-aware reset) and
|
|
4357
|
+
* the same `onChatRecovery` decision as deploy/eviction recovery (#2042). A
|
|
4358
|
+
* transient hang recovers; a persistently hanging provider exhausts the
|
|
4359
|
+
* budget. Idempotency matches deploy recovery: settled tool results are
|
|
4360
|
+
* durable and won't re-run, but a tool that was mid-execution when the stall
|
|
4361
|
+
* fired re-runs on the continuation.
|
|
4362
|
+
*
|
|
4363
|
+
* A stall before the first assistant chunk leaves the user's message as the
|
|
4364
|
+
* leaf, so there is nothing to continue: it schedules a retry of that user
|
|
4365
|
+
* turn instead (#1941).
|
|
4366
|
+
*
|
|
4367
|
+
* `persistPartial` saves the settled partial and resolves to its message id
|
|
4368
|
+
* (or `undefined` when nothing was saved). It runs unless `onChatRecovery`
|
|
4369
|
+
* returns `persist: false` and the partial holds no settled tool results.
|
|
3841
4370
|
*
|
|
3842
4371
|
* Returns:
|
|
3843
|
-
* - `"scheduled"` —
|
|
4372
|
+
* - `"scheduled"` — recovery was scheduled; the caller suppresses the
|
|
3844
4373
|
* terminal error and closes the stream cleanly.
|
|
3845
4374
|
* - `"exhausted"` — the budget is spent; this routes through the SAME
|
|
3846
4375
|
* `_exhaustChatRecovery` path as deploy recovery (fires `onExhausted`,
|
|
3847
4376
|
* emits `chat:recovery:exhausted`, marks the submission interrupted, and
|
|
3848
|
-
* delivers the configured `terminalMessage`).
|
|
3849
|
-
*
|
|
4377
|
+
* delivers the configured `terminalMessage`).
|
|
4378
|
+
* - `"declined"` — `onChatRecovery` returned `continue: false`; the turn is
|
|
4379
|
+
* marked interrupted and the declined message is delivered.
|
|
4380
|
+
* - `"failed"` — `onChatRecovery` threw; the incident is marked `failed` and
|
|
4381
|
+
* the caller runs its generic terminal error path.
|
|
4382
|
+
*
|
|
4383
|
+
* For `"exhausted"` and `"declined"` the terminal UX is already delivered, so
|
|
4384
|
+
* the caller must NOT run the generic terminal path.
|
|
3850
4385
|
*/
|
|
3851
4386
|
private _routeStallToBoundedRecovery;
|
|
4387
|
+
/**
|
|
4388
|
+
* {@link _routeStallToBoundedRecovery} for a stream consumer's `catch`: a
|
|
4389
|
+
* routing failure (e.g. a rejected incident write) degrades to `"failed"`,
|
|
4390
|
+
* so the caller still delivers its terminal error frame.
|
|
4391
|
+
*/
|
|
4392
|
+
private _routeStreamInterruption;
|
|
4393
|
+
/**
|
|
4394
|
+
* Submissions whose turn scheduled recovery: the recovery completes them,
|
|
4395
|
+
* so the submission runner must leave them `running`.
|
|
4396
|
+
*/
|
|
4397
|
+
private _recoveryOwnedSubmissions;
|
|
4398
|
+
private _claimSubmissionForRecovery;
|
|
4399
|
+
/**
|
|
4400
|
+
* Incidents marked `failed` only for observability while the platform
|
|
4401
|
+
* re-runs the same recovery attempt; their messenger reply stays pending.
|
|
4402
|
+
*/
|
|
4403
|
+
private _deferringRecoveryIncidents;
|
|
4404
|
+
/** Incidents whose running recovery attempt scheduled the next attempt. */
|
|
4405
|
+
private _rescheduledRecoveryIncidents;
|
|
4406
|
+
private _takeRecoveryReschedule;
|
|
4407
|
+
private _latestUserLeafId;
|
|
3852
4408
|
protected _handleInternalFiberRecovery(
|
|
3853
4409
|
ctx: FiberRecoveryContext
|
|
3854
4410
|
): Promise<boolean>;
|
|
4411
|
+
/**
|
|
4412
|
+
* A turn that owes its response hook and already persisted its message
|
|
4413
|
+
* finished: its stream rows may be gone with the cutover, so recovery would
|
|
4414
|
+
* otherwise re-run it. Fire the owed hook and settle the submission instead.
|
|
4415
|
+
*/
|
|
4416
|
+
private _settlePersistedChatTurn;
|
|
4417
|
+
private _recoverChatFiber;
|
|
3855
4418
|
/**
|
|
3856
4419
|
* Resolve the orphaned stream + its terminal status for a recovered chat turn.
|
|
3857
4420
|
* Drives BOTH the wake path (full result) and the give-up terminalization
|
|
@@ -3862,10 +4425,16 @@ declare class Think<
|
|
|
3862
4425
|
*/
|
|
3863
4426
|
private _resolveThinkRecoveryStream;
|
|
3864
4427
|
/**
|
|
3865
|
-
* Classify a recovered turn as `retry` or `continue`. A
|
|
3866
|
-
* partial re-runs its user message (`retryTargetUserId`), unless
|
|
3867
|
-
* already terminal — a terminal stream is never retried (it
|
|
3868
|
-
* its submission is reconciled in dispatch.
|
|
4428
|
+
* Classify a recovered turn as `retry` or `continue`. A turn that left no
|
|
4429
|
+
* persisted partial re-runs its user message (`retryTargetUserId`), unless
|
|
4430
|
+
* the stream is already terminal — a terminal stream is never retried (it
|
|
4431
|
+
* completed), only its submission is reconciled in dispatch.
|
|
4432
|
+
*
|
|
4433
|
+
* The stream row is opened before inference, so an interrupted turn can
|
|
4434
|
+
* have a stream id and still nothing to continue from; what decides retry is
|
|
4435
|
+
* the absence of persisted content and a leaf that is still the turn's user
|
|
4436
|
+
* message. Mirrors `AIChatAgent`'s empty-partial new-turn rule (#1691): a
|
|
4437
|
+
* `continue` here would find no assistant message and skip the turn.
|
|
3869
4438
|
*/
|
|
3870
4439
|
private _classifyRecoveredThinkTurn;
|
|
3871
4440
|
/**
|
|
@@ -4051,7 +4620,7 @@ declare class Think<
|
|
|
4051
4620
|
* down, so it throws too, burns the in-process retry budget inside the
|
|
4052
4621
|
* same reset window, and the row is consumed milliseconds before storage
|
|
4053
4622
|
* recovers. The submission is deliberately left `running` — the deferred
|
|
4054
|
-
* re-run reads it via `
|
|
4623
|
+
* re-run reads it via `_readRunningSubmissionForRecovery`, so marking it
|
|
4055
4624
|
* terminal here would turn the preserved row into a guaranteed
|
|
4056
4625
|
* `submission_not_running` no-op skip (a self-defeating defer).
|
|
4057
4626
|
* - Any OTHER (application) error is terminalized through the give-up path
|
|
@@ -4063,13 +4632,33 @@ declare class Think<
|
|
|
4063
4632
|
* send something new).
|
|
4064
4633
|
*/
|
|
4065
4634
|
private _handleRecoveryCallbackError;
|
|
4635
|
+
/**
|
|
4636
|
+
* Keep the recovery callback as owner until a chat Task or facet fiber is durably
|
|
4637
|
+
* accepted. At acceptance, move the running submission to the successor's
|
|
4638
|
+
* request identity before signaling handoff. If an override never starts a
|
|
4639
|
+
* durable successor, the signal stays inert and the callback owns the work
|
|
4640
|
+
* until the override returns.
|
|
4641
|
+
*/
|
|
4642
|
+
private _runRecoveredTurnAfterAcceptance;
|
|
4643
|
+
/**
|
|
4644
|
+
* The workflow prompt of the submission a recovery turn is completing. A
|
|
4645
|
+
* structured prompt must re-arm its final-answer tool on the recovered turn,
|
|
4646
|
+
* or the turn can never produce the output the workflow waits for.
|
|
4647
|
+
*/
|
|
4648
|
+
private _recoveredWorkflowPrompt;
|
|
4066
4649
|
_chatRecoveryRetry(data?: ChatRecoveryRetryData): Promise<void>;
|
|
4067
4650
|
protected _chatRecoveryRetryDetached(
|
|
4068
4651
|
data?: ChatRecoveryRetryData,
|
|
4069
4652
|
onTurnStarted?: () => void
|
|
4070
4653
|
): Promise<void>;
|
|
4071
|
-
|
|
4072
|
-
|
|
4654
|
+
/**
|
|
4655
|
+
* Recovery payloads retain the original submission/root identity while
|
|
4656
|
+
* request_id follows the accepted successor. Match both so released payloads,
|
|
4657
|
+
* redeferred callbacks, and exhaustion can still locate the running row.
|
|
4658
|
+
* Exact submission identity wins even when terminal: a redelivery must not
|
|
4659
|
+
* fall through to another submission whose successor request collides.
|
|
4660
|
+
*/
|
|
4661
|
+
private _readRunningSubmissionForRecovery;
|
|
4073
4662
|
private _markRecoveredSubmissionInterrupted;
|
|
4074
4663
|
private _completeRecoveredSubmission;
|
|
4075
4664
|
protected onChatRecovery(
|
|
@@ -4122,6 +4711,12 @@ declare class Think<
|
|
|
4122
4711
|
* to hold (event-driven) until its remaining siblings answer.
|
|
4123
4712
|
*/
|
|
4124
4713
|
private _onStreamingTurnFinalized;
|
|
4714
|
+
/**
|
|
4715
|
+
* A pause resolved without a continuation while its turn was streaming; its
|
|
4716
|
+
* deferred drop runs when that turn finalizes instead of at the next
|
|
4717
|
+
* inference.
|
|
4718
|
+
*/
|
|
4719
|
+
private _flushResolvedPausesOnFinalize;
|
|
4125
4720
|
/**
|
|
4126
4721
|
* Drain every in-flight tool-result/approval apply, including any enqueued
|
|
4127
4722
|
* while we wait, so the subsequent `_hasIncompleteToolBatch()` re-check sees
|
|
@@ -4142,22 +4737,37 @@ declare class Think<
|
|
|
4142
4737
|
*/
|
|
4143
4738
|
private _hasIncompleteToolBatch;
|
|
4144
4739
|
private _fireAutoContinuation;
|
|
4740
|
+
/**
|
|
4741
|
+
* Report a continuation turn that failed before it streamed, the way a
|
|
4742
|
+
* failed client turn is reported: `onChatError`, `chat:request:failed`, a
|
|
4743
|
+
* recorded terminal status, `onChatResponse` for the assistant message it
|
|
4744
|
+
* would have extended, and an error frame. Aborts and Durable Object resets
|
|
4745
|
+
* are left to their own paths.
|
|
4746
|
+
*
|
|
4747
|
+
* @returns Whether the failure was reported.
|
|
4748
|
+
*/
|
|
4749
|
+
private _reportContinuationFailure;
|
|
4145
4750
|
private _activateDeferredContinuation;
|
|
4146
4751
|
/**
|
|
4147
|
-
*
|
|
4752
|
+
* Queue a continuation turn that does NOT require a live client connection.
|
|
4148
4753
|
*
|
|
4149
4754
|
* Used when a durable approval (a paused action or codemode execution) is
|
|
4150
4755
|
* resolved via RPC from a surface with no open chat socket — e.g. an ops
|
|
4151
4756
|
* dashboard, a webhook, or a voice backend approving hours/days later. The
|
|
4152
|
-
*
|
|
4153
|
-
*
|
|
4154
|
-
*
|
|
4155
|
-
*
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4757
|
+
* item is durable, so the turn still runs if the object leaves memory
|
|
4758
|
+
* before the alarm fires; the last request body and client tools it needs
|
|
4759
|
+
* are persisted config, restored on start. Approvals landing while one
|
|
4760
|
+
* continuation is pending or running coalesce onto the single item.
|
|
4761
|
+
*/
|
|
4762
|
+
private _queueConnectionlessContinuation;
|
|
4763
|
+
/**
|
|
4764
|
+
* Run one connection-less continuation turn. Mirrors the connection-bound
|
|
4765
|
+
* auto-continuation turn body but streams via `broadcast` (a no-op when
|
|
4766
|
+
* nobody is attached) and always persists, so a client that reconnects
|
|
4767
|
+
* later resumes the continued turn from history.
|
|
4768
|
+
* @internal Queue callback.
|
|
4159
4769
|
*/
|
|
4160
|
-
|
|
4770
|
+
_cfRunConnectionlessContinuation(): Promise<void>;
|
|
4161
4771
|
/**
|
|
4162
4772
|
* Render a reply attachment ({@link ReplyAttachment}) for delivery to the
|
|
4163
4773
|
* active channel. Returns the text/markdown to post, or `undefined` to skip —
|
|
@@ -4176,6 +4786,76 @@ declare class Think<
|
|
|
4176
4786
|
*/
|
|
4177
4787
|
private _renderChannelAttachments;
|
|
4178
4788
|
private _fireResponseHook;
|
|
4789
|
+
/**
|
|
4790
|
+
* Fire a live turn's response hook, then drop its pending marker. When the
|
|
4791
|
+
* bookkeeping before `onChatResponse` throws (attachment delivery, the
|
|
4792
|
+
* terminal-status write), the hook has not run: the marker is kept, with
|
|
4793
|
+
* this outcome, so the next start replays it.
|
|
4794
|
+
*/
|
|
4795
|
+
private _fireLiveResponseHook;
|
|
4796
|
+
/** Request ids whose response hook the live turn still owes. */
|
|
4797
|
+
private _responseHooksInFlight;
|
|
4798
|
+
private _pendingResponseHookReplay;
|
|
4799
|
+
/**
|
|
4800
|
+
* Record, before the assistant message is persisted, that this turn owes
|
|
4801
|
+
* `onChatResponse`, so a reset between the persist and the hook replays it.
|
|
4802
|
+
*/
|
|
4803
|
+
private _rememberPendingResponseHook;
|
|
4804
|
+
private _forgetPendingResponseHook;
|
|
4805
|
+
/**
|
|
4806
|
+
* Fire the response hooks a reset interrupted. A hook whose message never
|
|
4807
|
+
* persisted is dropped: that turn is recovered, and fires, on its own.
|
|
4808
|
+
*/
|
|
4809
|
+
private _replayPendingResponseHooks;
|
|
4810
|
+
private _replayPendingResponseHooksNow;
|
|
4811
|
+
/** Request ids whose interruption handed messenger delivery to recovery. */
|
|
4812
|
+
private _messengerRecoveryClaims;
|
|
4813
|
+
/**
|
|
4814
|
+
* An interrupted messenger turn that recovery will continue: record where
|
|
4815
|
+
* the recovered answer goes before the continuation is scheduled, so the
|
|
4816
|
+
* messenger delivery can skip its apology (#2106). A continuation attempt
|
|
4817
|
+
* of the same incident keeps the existing record.
|
|
4818
|
+
*/
|
|
4819
|
+
private _claimMessengerRecoveryDelivery;
|
|
4820
|
+
/**
|
|
4821
|
+
* Durably record a messenger reply's outcome before its recovery incident
|
|
4822
|
+
* settles: once the incident is terminal, nothing re-emits the event that
|
|
4823
|
+
* would settle the reply after a reset. The recovered text is read before
|
|
4824
|
+
* any await, so a later turn cannot replace it.
|
|
4825
|
+
*/
|
|
4826
|
+
private _stageMessengerRecoveryOutcome;
|
|
4827
|
+
private _recoveredReplyText;
|
|
4828
|
+
/** Incidents whose messenger reply is being delivered by this isolate. */
|
|
4829
|
+
private _settlingMessengerRecoveries;
|
|
4830
|
+
private _settleMessengerRecovery;
|
|
4831
|
+
/** The latest delivery of each recovered reply key, in call order. */
|
|
4832
|
+
private _messengerRecoveryDeliveries;
|
|
4833
|
+
/**
|
|
4834
|
+
* Deliver a recovered reply after any delivery of the same key already
|
|
4835
|
+
* running in this isolate: startup replay, live settlement and scheduled
|
|
4836
|
+
* retries interleave across awaits, and each must see the cursor the
|
|
4837
|
+
* previous one advanced.
|
|
4838
|
+
*/
|
|
4839
|
+
private _deliverMessengerRecovery;
|
|
4840
|
+
/**
|
|
4841
|
+
* Post a settled recovered reply, one post at a time, then drop its record.
|
|
4842
|
+
* Each post goes out at most once: the cursor advances before it, and a
|
|
4843
|
+
* rejected post may still have landed (a timeout after the platform
|
|
4844
|
+
* accepted it), so the retry resumes with the next post.
|
|
4845
|
+
*/
|
|
4846
|
+
private _postMessengerRecovery;
|
|
4847
|
+
/** Retry a recovered messenger reply whose live delivery failed. */
|
|
4848
|
+
private _retryMessengerRecoveryDeliveryLater;
|
|
4849
|
+
/**
|
|
4850
|
+
* Retry delivering a recovered messenger reply (see
|
|
4851
|
+
* {@link _retryMessengerRecoveryDeliveryLater}).
|
|
4852
|
+
* @internal Schedule callback.
|
|
4853
|
+
*/
|
|
4854
|
+
_cfRetryMessengerRecoveryDelivery(payload: {
|
|
4855
|
+
key: string;
|
|
4856
|
+
attempts: number;
|
|
4857
|
+
}): Promise<void>;
|
|
4858
|
+
private _replayMessengerRecoveryDeliveries;
|
|
4179
4859
|
/**
|
|
4180
4860
|
* Persist (on `error`/`interrupted`) or clear (on `completed`/`aborted`) the
|
|
4181
4861
|
* durable terminal record so it can be replayed to clients on reconnect, and
|
|
@@ -4253,26 +4933,55 @@ declare class Think<
|
|
|
4253
4933
|
requestId: string,
|
|
4254
4934
|
options?: {
|
|
4255
4935
|
messageId?: string;
|
|
4936
|
+
parentMessageId?: string;
|
|
4937
|
+
continuation?: boolean;
|
|
4256
4938
|
}
|
|
4257
4939
|
): string;
|
|
4258
4940
|
/** Mark a resumable stream completed (settled now, rows kept until reclaim). */
|
|
4259
|
-
protected _completeResumableStream(
|
|
4941
|
+
protected _completeResumableStream(
|
|
4942
|
+
streamId: string,
|
|
4943
|
+
outcome?: ChatTurnOutcome
|
|
4944
|
+
): void;
|
|
4945
|
+
/**
|
|
4946
|
+
* A connection offered the stream that never ACKed (`resume: false`, or
|
|
4947
|
+
* gone quiet) must still get the terminal frame and every later broadcast.
|
|
4948
|
+
*/
|
|
4949
|
+
private _afterResumableStreamEnded;
|
|
4260
4950
|
/**
|
|
4261
4951
|
* The producer finished; leave the row for the cutover that persists the
|
|
4262
4952
|
* assistant message (`_persistAssistantMessageWithCutover`). Every path
|
|
4263
4953
|
* that calls this must end in that cutover or `finalizePending()`.
|
|
4264
4954
|
*/
|
|
4265
|
-
protected _finishResumableStream(
|
|
4955
|
+
protected _finishResumableStream(
|
|
4956
|
+
streamId: string,
|
|
4957
|
+
outcome?: ChatTurnOutcome
|
|
4958
|
+
): void;
|
|
4266
4959
|
/** Mark a resumable stream errored. */
|
|
4267
|
-
protected _errorResumableStream(streamId: string): void;
|
|
4960
|
+
protected _errorResumableStream(streamId: string, requestId?: string): void;
|
|
4268
4961
|
/**
|
|
4269
4962
|
* @deprecated Streams are reclaimed at cutover and on the next stream
|
|
4270
4963
|
* start; no alarm is armed any more. Kept so a cleanup alarm persisted by
|
|
4271
4964
|
* an earlier version still resolves to a callback when it fires.
|
|
4272
4965
|
*/
|
|
4273
4966
|
_cleanupStreamBuffers(): Promise<void>;
|
|
4967
|
+
/**
|
|
4968
|
+
* The message an orphaned stream's assistant message branches from, so the
|
|
4969
|
+
* reconstructed message lands where the live turn would have persisted it:
|
|
4970
|
+
* a regeneration beside the response it replaces, not under it. Undefined
|
|
4971
|
+
* for a turn that appends to the latest leaf, and on an `agents` release
|
|
4972
|
+
* that does not record the parent.
|
|
4973
|
+
*/
|
|
4974
|
+
private _orphanParentId;
|
|
4274
4975
|
private _persistOrphanedStream;
|
|
4275
4976
|
private _broadcastChat;
|
|
4977
|
+
/**
|
|
4978
|
+
* User message ids a WebSocket chat request originated from (#2280), keyed
|
|
4979
|
+
* by request id while the request is handled. After that (or after a
|
|
4980
|
+
* restart) the request's stream metadata is the fallback.
|
|
4981
|
+
*/
|
|
4982
|
+
private _requestOriginMessageIds;
|
|
4983
|
+
private _originMessageIdsFor;
|
|
4984
|
+
private _withOriginMessageIds;
|
|
4276
4985
|
private _broadcast;
|
|
4277
4986
|
private _broadcastMessages;
|
|
4278
4987
|
}
|
|
@@ -4351,11 +5060,24 @@ interface MessengerContext {
|
|
|
4351
5060
|
message?: MessengerMessage;
|
|
4352
5061
|
messengerId: string;
|
|
4353
5062
|
provider: string;
|
|
5063
|
+
/**
|
|
5064
|
+
* Earlier messages folded into this event, oldest first. A quick run of
|
|
5065
|
+
* messages in one thread is answered once, for its newest message (the Chat
|
|
5066
|
+
* SDK `burst` concurrency strategy); the rest arrive here. They are part of
|
|
5067
|
+
* this turn's input: the model-facing user message renders them before
|
|
5068
|
+
* `message`, and their attachments are listed with its own.
|
|
5069
|
+
*/
|
|
5070
|
+
skipped?: MessengerMessage[];
|
|
4354
5071
|
thread: MessengerThread;
|
|
4355
5072
|
}
|
|
4356
5073
|
interface MessengerEvent extends MessengerContext {
|
|
4357
5074
|
raw?: unknown;
|
|
4358
5075
|
}
|
|
5076
|
+
/**
|
|
5077
|
+
* The context persisted on a messenger turn's user message. Built from the
|
|
5078
|
+
* serializable form of the event, so raw platform payloads and attachment
|
|
5079
|
+
* bytes are never stored and a live turn matches its recovered replay.
|
|
5080
|
+
*/
|
|
4359
5081
|
declare function messengerContextFromEvent(
|
|
4360
5082
|
event: MessengerEvent
|
|
4361
5083
|
): MessengerContext;
|
|
@@ -4389,10 +5111,16 @@ declare const ERROR_MESSENGER_RESPONSE =
|
|
|
4389
5111
|
declare const INTERRUPTED_MESSENGER_RESPONSE =
|
|
4390
5112
|
"Sorry, my reply was interrupted. Please send your message again if you'd like me to retry.";
|
|
4391
5113
|
interface TextStreamCallbackOptions {
|
|
5114
|
+
/**
|
|
5115
|
+
* Streamed as the reply when a turn completes without text, so surfaces that
|
|
5116
|
+
* wait for the first chunk before posting never post an empty message.
|
|
5117
|
+
*/
|
|
5118
|
+
emptyText?: string;
|
|
4392
5119
|
onVisibleStart?: () => Promise<void> | void;
|
|
4393
5120
|
visibleSoftLimit?: number;
|
|
4394
5121
|
}
|
|
4395
5122
|
declare class TextStreamCallback extends RpcTarget implements StreamCallback {
|
|
5123
|
+
private readonly emptyText?;
|
|
4396
5124
|
private readonly onVisibleStart?;
|
|
4397
5125
|
private readonly textSegmentJoiner;
|
|
4398
5126
|
private readonly visibleChunks;
|
|
@@ -4401,6 +5129,7 @@ declare class TextStreamCallback extends RpcTarget implements StreamCallback {
|
|
|
4401
5129
|
private chatRequestId?;
|
|
4402
5130
|
private closed;
|
|
4403
5131
|
private interrupted;
|
|
5132
|
+
private recoveredReplyDelivered;
|
|
4404
5133
|
private error?;
|
|
4405
5134
|
private text;
|
|
4406
5135
|
private visibleClosed;
|
|
@@ -4412,11 +5141,20 @@ declare class TextStreamCallback extends RpcTarget implements StreamCallback {
|
|
|
4412
5141
|
onEvent(json: string): void;
|
|
4413
5142
|
onDone(): void;
|
|
4414
5143
|
onError(error: string): void;
|
|
4415
|
-
onInterrupted(): void;
|
|
5144
|
+
onInterrupted(info?: ChatInterruptedInfo): void;
|
|
4416
5145
|
wasInterrupted(): boolean;
|
|
5146
|
+
/** Whether the target posts the recovered reply to the thread itself. */
|
|
5147
|
+
targetDeliversRecoveredReply(): boolean;
|
|
5148
|
+
/** Ends a completed turn, streaming `emptyText` if it produced no text. */
|
|
5149
|
+
complete(): void;
|
|
4417
5150
|
close(): void;
|
|
4418
5151
|
fail(error: unknown): void;
|
|
4419
5152
|
hasText(): boolean;
|
|
5153
|
+
/**
|
|
5154
|
+
* Resolves `true` once there is visible text to post, or `false` when the
|
|
5155
|
+
* stream ends without any, so a caller can avoid posting an empty reply.
|
|
5156
|
+
*/
|
|
5157
|
+
hasVisibleOutput(): Promise<boolean>;
|
|
4420
5158
|
remainingText(): string;
|
|
4421
5159
|
requestId(): string | undefined;
|
|
4422
5160
|
textSoFar(): string;
|
|
@@ -4513,6 +5251,13 @@ interface MessengerDeliveryPolicy {
|
|
|
4513
5251
|
callback: TextStreamCallback
|
|
4514
5252
|
): boolean;
|
|
4515
5253
|
splitText?(text: string): string[];
|
|
5254
|
+
/**
|
|
5255
|
+
* How often, in milliseconds, the typing indicator is re-sent until the
|
|
5256
|
+
* reply's first text is posted. Platforms expire the indicator after a few
|
|
5257
|
+
* seconds. `0` sends it once.
|
|
5258
|
+
* @default 4000
|
|
5259
|
+
*/
|
|
5260
|
+
typingRefreshMs?: number;
|
|
4516
5261
|
visibleSoftLimit?: number;
|
|
4517
5262
|
}
|
|
4518
5263
|
interface DeliverMessengerReplyOptions {
|
|
@@ -4579,6 +5324,9 @@ interface MessengerDefinition {
|
|
|
4579
5324
|
| ((request: Request) => boolean | Response | Promise<boolean | Response>);
|
|
4580
5325
|
}
|
|
4581
5326
|
type ThinkMessengers = Record<string, MessengerDefinition>;
|
|
5327
|
+
/** The Chat SDK `concurrency` setting for a Think agent's messengers. */
|
|
5328
|
+
type MessengerConcurrency = ConcurrencyStrategy | ConcurrencyConfig;
|
|
5329
|
+
declare const DEFAULT_MESSENGER_CONCURRENCY: MessengerConcurrency;
|
|
4582
5330
|
interface NormalizedMessengerDefinition extends MessengerDefinition {
|
|
4583
5331
|
id: string;
|
|
4584
5332
|
path: string;
|
|
@@ -4599,6 +5347,14 @@ interface ChatSdkMessengerEventInput {
|
|
|
4599
5347
|
eventKind: MessengerEventKind;
|
|
4600
5348
|
message?: Message;
|
|
4601
5349
|
raw?: unknown;
|
|
5350
|
+
/**
|
|
5351
|
+
* Earlier messages the Chat SDK's concurrency strategy folded into this one,
|
|
5352
|
+
* oldest first (`MessageContext.skipped`). The runtime's `burst` strategy
|
|
5353
|
+
* answers only the newest message of a quick run and reports the rest here.
|
|
5354
|
+
* {@link defaultChatSdkEvent} carries them on the event's `skipped` so they
|
|
5355
|
+
* reach the model; a custom `toEvent` that ignores them drops them.
|
|
5356
|
+
*/
|
|
5357
|
+
skipped?: readonly Message[];
|
|
4602
5358
|
thread: Thread;
|
|
4603
5359
|
}
|
|
4604
5360
|
interface MessengerThinkTarget {
|
|
@@ -4647,6 +5403,8 @@ interface MessengerThinkHost extends MessengerThinkTarget {
|
|
|
4647
5403
|
agentClass: SubAgentClass<T>,
|
|
4648
5404
|
name: string
|
|
4649
5405
|
): Promise<SubAgentStub<T>>;
|
|
5406
|
+
/** Keep the host alive while background messenger work runs. */
|
|
5407
|
+
keepAliveWhile?<T>(fn: () => Promise<T>): Promise<T>;
|
|
4650
5408
|
}
|
|
4651
5409
|
interface MessengerFiberStartResult {
|
|
4652
5410
|
accepted: boolean;
|
|
@@ -4669,7 +5427,14 @@ declare class ThinkMessengerRuntime {
|
|
|
4669
5427
|
private readonly definitionsByAdapterName;
|
|
4670
5428
|
private readonly definitionsById;
|
|
4671
5429
|
private readonly definitions;
|
|
4672
|
-
|
|
5430
|
+
private readonly concurrency;
|
|
5431
|
+
constructor(
|
|
5432
|
+
definitions: ThinkMessengers,
|
|
5433
|
+
host: MessengerThinkHost,
|
|
5434
|
+
options?: {
|
|
5435
|
+
concurrency?: MessengerConcurrency;
|
|
5436
|
+
}
|
|
5437
|
+
);
|
|
4673
5438
|
get size(): number;
|
|
4674
5439
|
initialize(): void;
|
|
4675
5440
|
handleRequest(request: Request): Promise<Response | undefined>;
|
|
@@ -4686,8 +5451,25 @@ declare class ThinkMessengerRuntime {
|
|
|
4686
5451
|
persistRecoverySnapshot?: (
|
|
4687
5452
|
snapshot: ReturnType<typeof messengerReplySnapshot>
|
|
4688
5453
|
) => Promise<void> | void;
|
|
5454
|
+
/**
|
|
5455
|
+
* Whether the caller replays this recovery after it throws `error`.
|
|
5456
|
+
* Messages queued behind the reply are drained only once it settles,
|
|
5457
|
+
* so they are never answered ahead of it. Default: no replay.
|
|
5458
|
+
*/
|
|
5459
|
+
retriesAfter?: (error: unknown) => boolean;
|
|
4689
5460
|
}
|
|
4690
5461
|
): Promise<boolean>;
|
|
5462
|
+
private recoverReply;
|
|
5463
|
+
/**
|
|
5464
|
+
* Messages queued behind a reply are drained only by the Chat SDK handler
|
|
5465
|
+
* holding the thread lock. When the isolate running that reply dies, the
|
|
5466
|
+
* queue is stranded until another message arrives, so recovery drains it:
|
|
5467
|
+
* once the dead holder's lock expires, take the lock and hand the queue to
|
|
5468
|
+
* the SDK's own drain. A live holder drains the queue itself, which ends
|
|
5469
|
+
* the wait.
|
|
5470
|
+
*/
|
|
5471
|
+
private drainQueuedMessagesInBackground;
|
|
5472
|
+
private drainQueuedMessages;
|
|
4691
5473
|
private createChat;
|
|
4692
5474
|
/** Whether this isolate still holds the live closure for one reply. */
|
|
4693
5475
|
hasLiveReply(nonce: string): boolean;
|
|
@@ -4715,13 +5497,35 @@ declare class ThinkMessengerRuntime {
|
|
|
4715
5497
|
channelId: string,
|
|
4716
5498
|
threadId?: string
|
|
4717
5499
|
): Promise<MessengerDeliverySurface | undefined>;
|
|
5500
|
+
/**
|
|
5501
|
+
* Post what chat recovery produced for an interrupted messenger turn: the
|
|
5502
|
+
* text the thread has not seen yet, or the interrupted apology when
|
|
5503
|
+
* recovery gave up. The reply may span several posts; this posts only post
|
|
5504
|
+
* number `chunk` (skipped when out of range) and returns how many there
|
|
5505
|
+
* are, so the caller can checkpoint between posts.
|
|
5506
|
+
*/
|
|
5507
|
+
deliverRecoveredReply(input: {
|
|
5508
|
+
messengerId: string;
|
|
5509
|
+
threadId: string;
|
|
5510
|
+
outcome: "completed" | "interrupted";
|
|
5511
|
+
text?: string;
|
|
5512
|
+
partialPosted?: boolean;
|
|
5513
|
+
chunk: number;
|
|
5514
|
+
}): Promise<{
|
|
5515
|
+
chunks: number;
|
|
5516
|
+
}>;
|
|
4718
5517
|
private resolveTarget;
|
|
4719
5518
|
private definitionForThread;
|
|
4720
5519
|
private definitionForThreadId;
|
|
4721
5520
|
private hasUniqueProvider;
|
|
4722
5521
|
private shardThread;
|
|
4723
5522
|
private shardStateKey;
|
|
4724
|
-
|
|
5523
|
+
/**
|
|
5524
|
+
* `ThreadImpl.fromJSON` (what `chat.reviver()` calls) builds the thread
|
|
5525
|
+
* without the Chat's streaming config, so a recovered reply would fall back to
|
|
5526
|
+
* the `"..."` placeholder. Rebuild it from the same fields with that config.
|
|
5527
|
+
*/
|
|
5528
|
+
private reviveThread;
|
|
4725
5529
|
private toEvent;
|
|
4726
5530
|
}
|
|
4727
5531
|
declare function normalizeMessengers(
|
|
@@ -4759,162 +5563,171 @@ declare function toMessengerAttachment(
|
|
|
4759
5563
|
): MessengerAttachment;
|
|
4760
5564
|
//#endregion
|
|
4761
5565
|
export {
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
5566
|
+
MessengerEventKind as $,
|
|
5567
|
+
messengerChannel as $n,
|
|
5568
|
+
RunTurnWait as $t,
|
|
5569
|
+
ERROR_MESSENGER_RESPONSE as A,
|
|
5570
|
+
TurnConfig as An,
|
|
5571
|
+
ChunkContext as At,
|
|
5572
|
+
defaultDeliveryTag as B,
|
|
5573
|
+
action as Bn,
|
|
5574
|
+
MessageMetadataCallback as Bt,
|
|
5575
|
+
toMessengerAuthor as C,
|
|
5576
|
+
ThinkSubmissionInspection as Cn,
|
|
5577
|
+
ChatRecoveryConfig$1 as Ct,
|
|
5578
|
+
DeliveryKind as D,
|
|
5579
|
+
ToolCallContext as Dn,
|
|
5580
|
+
ChatRecoveryProgressContext as Dt,
|
|
5581
|
+
DeliverMessengerReplyOptions as E,
|
|
5582
|
+
ThinkWallClockSchedule as En,
|
|
5583
|
+
ChatRecoveryOptions$1 as Et,
|
|
5584
|
+
MessengerDeliveryTarget as F,
|
|
5585
|
+
TurnTrigger as Fn,
|
|
5586
|
+
ExtensionConfig as Ft,
|
|
5587
|
+
parseMessengerReplySnapshot as G,
|
|
5588
|
+
ChannelContext as Gn,
|
|
5589
|
+
PrepareStepResult$1 as Gt,
|
|
5590
|
+
messengerReplyFailureMode as H,
|
|
5591
|
+
isAction as Hn,
|
|
5592
|
+
PendingApproval as Ht,
|
|
5593
|
+
MessengerReplySnapshot as I,
|
|
5594
|
+
TypedToolCall$1 as In,
|
|
5595
|
+
FiberContext$1 as It,
|
|
5596
|
+
MessengerAttachment as J,
|
|
5597
|
+
ChannelDeliverySurface as Jn,
|
|
5598
|
+
ResolvedChatRecoveryConfig as Jt,
|
|
5599
|
+
ChannelSpeakerLabel as K,
|
|
5600
|
+
ChannelDefinition as Kn,
|
|
5601
|
+
RejectExecutionOptions as Kt,
|
|
5602
|
+
MessengerReplyStage as L,
|
|
5603
|
+
TypedToolResult as Ln,
|
|
5604
|
+
FiberRecoveryContext$1 as Lt,
|
|
5605
|
+
MESSENGER_REPLY_FIBER_NAME as M,
|
|
5606
|
+
TurnInput as Mn,
|
|
5607
|
+
ContextOverflowConfig as Mt,
|
|
5608
|
+
MessengerDeliveryPolicy as N,
|
|
5609
|
+
TurnInputMessages as Nn,
|
|
5610
|
+
DeleteSubmissionsOptions as Nt,
|
|
5611
|
+
DeliveryTag as O,
|
|
5612
|
+
ToolCallDecision as On,
|
|
5613
|
+
ChatResponseResult$1 as Ot,
|
|
5614
|
+
MessengerDeliverySurface as P,
|
|
5615
|
+
TurnResult as Pn,
|
|
5616
|
+
DeliverNoticeOptions as Pt,
|
|
5617
|
+
MessengerEvent as Q,
|
|
5618
|
+
ThinkChannels as Qn,
|
|
5619
|
+
RunTurnSubmit as Qt,
|
|
5620
|
+
TextStreamCallback as R,
|
|
5621
|
+
WaitForSubmissionOptions as Rn,
|
|
5622
|
+
ListSubmissionsOptions as Rt,
|
|
5623
|
+
toMessengerAttachment as S,
|
|
5624
|
+
ThinkScheduledTasks as Sn,
|
|
5625
|
+
ChatOptions as St,
|
|
5626
|
+
toMessengerThread as T,
|
|
5627
|
+
ThinkTime as Tn,
|
|
5628
|
+
ChatRecoveryExhaustedContext as Tt,
|
|
5629
|
+
messengerReplyRecoveryMode as U,
|
|
5630
|
+
skills as Un,
|
|
5631
|
+
PrepareStepContext as Ut,
|
|
5632
|
+
deliverMessengerReply as V,
|
|
5633
|
+
defaultContextOverflowClassifier as Vn,
|
|
5634
|
+
OnStartDegradation as Vt,
|
|
5635
|
+
messengerReplySnapshot as W,
|
|
5636
|
+
ChannelCapabilities as Wn,
|
|
5637
|
+
PrepareStepFunction$1 as Wt,
|
|
5638
|
+
MessengerCapabilities as X,
|
|
5639
|
+
ChannelKind as Xn,
|
|
5640
|
+
RunTurnOptions as Xt,
|
|
5641
|
+
MessengerAuthor as Y,
|
|
5642
|
+
ChannelIngress as Yn,
|
|
5643
|
+
RunTurnBase as Yt,
|
|
5644
|
+
MessengerContext as Z,
|
|
5645
|
+
NormalizedChannelDefinition as Zn,
|
|
5646
|
+
RunTurnStream as Zt,
|
|
5647
|
+
defaultChatSdkEvent as _,
|
|
5648
|
+
ThinkModel as _n,
|
|
5649
|
+
AddMessagesOptions as _t,
|
|
5650
|
+
MessengerConversationMode as a,
|
|
5651
|
+
SkillWorkspaceSeedOptions$1 as an,
|
|
5652
|
+
toMessengerUserMessage as at,
|
|
5653
|
+
normalizeMessengers as b,
|
|
5654
|
+
ThinkScheduledTaskContext as bn,
|
|
5655
|
+
ChatErrorContext as bt,
|
|
5656
|
+
MessengerDefinition as c,
|
|
5657
|
+
StepResult as cn,
|
|
5658
|
+
ActionApprovalPolicy as ct,
|
|
5659
|
+
MessengerThinkTarget as d,
|
|
5660
|
+
StreamableResult as dn,
|
|
5661
|
+
ActionConfig as dt,
|
|
5662
|
+
SaveMessagesOptions$1 as en,
|
|
5663
|
+
MediaEvictionConfig as er,
|
|
5664
|
+
MessengerMessage as et,
|
|
5665
|
+
NormalizedMessengerDefinition as f,
|
|
5666
|
+
SubmitMessagesOptions as fn,
|
|
5667
|
+
ActionContext as ft,
|
|
5668
|
+
chatSdkMessenger as g,
|
|
5669
|
+
ThinkIntervalSchedule as gn,
|
|
5670
|
+
ActiveTurn as gt,
|
|
5671
|
+
ThinkMessengers as h,
|
|
5672
|
+
Think as hn,
|
|
5673
|
+
ActionPermissionSpec as ht,
|
|
5674
|
+
MessengerConcurrency as i,
|
|
5675
|
+
SkillSource$1 as in,
|
|
5676
|
+
ThinkSession as ir,
|
|
5677
|
+
serializableMessengerEvent as it,
|
|
5678
|
+
INTERRUPTED_MESSENGER_RESPONSE as j,
|
|
5679
|
+
TurnContext as jn,
|
|
5680
|
+
ChunkPart as jt,
|
|
5681
|
+
EMPTY_MESSENGER_RESPONSE as k,
|
|
5682
|
+
ToolCallResultContext as kn,
|
|
5683
|
+
ChatStartEvent as kt,
|
|
5684
|
+
MessengerRespondTo as l,
|
|
5685
|
+
StopCondition$1 as ln,
|
|
5686
|
+
ActionAuthorizationContext as lt,
|
|
5687
|
+
ThinkMessengerStateAgent as m,
|
|
5688
|
+
TextStreamPart$1 as mn,
|
|
5689
|
+
ActionKind as mt,
|
|
4880
5690
|
ChatSdkMessengerOptions as n,
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
5691
|
+
SessionMessage$1 as nn,
|
|
5692
|
+
CompactionErrorHandler as nr,
|
|
5693
|
+
messengerContextFromEvent as nt,
|
|
5694
|
+
MessengerConversationResolver as o,
|
|
5695
|
+
StepConfig as on,
|
|
5696
|
+
Action as ot,
|
|
5697
|
+
ThinkMessengerRuntime as p,
|
|
5698
|
+
SubmitMessagesResult as pn,
|
|
5699
|
+
ActionIdempotencyKey as pt,
|
|
5700
|
+
MessengerAction as q,
|
|
5701
|
+
ChannelDeliveryPolicy as qn,
|
|
5702
|
+
ReplyAttachment as qt,
|
|
5703
|
+
DEFAULT_MESSENGER_CONCURRENCY as r,
|
|
5704
|
+
SkillRunContext as rn,
|
|
5705
|
+
SessionContextOptions as rr,
|
|
5706
|
+
resolveChannelSpeakerLabel as rt,
|
|
5707
|
+
MessengerConversationTarget as s,
|
|
5708
|
+
StepContext as sn,
|
|
5709
|
+
ActionApprovalDescriptor as st,
|
|
4898
5710
|
ChatSdkMessengerEventInput as t,
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
5711
|
+
SaveMessagesResult$1 as tn,
|
|
5712
|
+
CompactAfterOptions as tr,
|
|
5713
|
+
MessengerThread as tt,
|
|
5714
|
+
MessengerThinkHost as u,
|
|
5715
|
+
StreamCallback as un,
|
|
5716
|
+
ActionAuthorizationDecision as ut,
|
|
5717
|
+
defaultConversationName as v,
|
|
5718
|
+
ThinkModelId as vn,
|
|
5719
|
+
CancelSubmissionResult as vt,
|
|
5720
|
+
toMessengerMessage as w,
|
|
5721
|
+
ThinkSubmissionStatus as wn,
|
|
5722
|
+
ChatRecoveryContext$1 as wt,
|
|
5723
|
+
resolveSelfMention as x,
|
|
5724
|
+
ThinkScheduledTaskSchedule as xn,
|
|
5725
|
+
ChatInterruptedInfo as xt,
|
|
5726
|
+
idempotencyKeyForEvent as y,
|
|
5727
|
+
ThinkScheduledTask as yn,
|
|
5728
|
+
ChatErrorClassification as yt,
|
|
5729
|
+
TextStreamCallbackOptions as z,
|
|
5730
|
+
Workspace$1 as zn,
|
|
5731
|
+
MessageConcurrency$1 as zt
|
|
4919
5732
|
};
|
|
4920
|
-
//# sourceMappingURL=index-
|
|
5733
|
+
//# sourceMappingURL=index-DwPAhQRQ.d.ts.map
|