@cloudflare/think 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/{index-BZKPlFcA.d.ts → index-B7zEkBBM.d.ts} +14 -12
- package/dist/messengers/index.d.ts +1 -1
- package/dist/messengers/telegram.d.ts +1 -1
- package/dist/think.d.ts +1 -1
- package/dist/think.js +50 -38
- package/dist/think.js.map +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/index.md +29 -29
- package/docs/sub-agents.md +7 -19
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -356,15 +356,15 @@ Script execution requires a Worker Loader binding:
|
|
|
356
356
|
| `fetchTools` | `false` | Opt-in allowlisted HTTP read tools (`fetch_url` + per-binding `fetch_<name>`). Set to a config object; see [Fetch tool](#fetch-tool) |
|
|
357
357
|
| `includeMcpTools` | `true` | Automatically convert connected MCP tools to AI SDK tools and merge them into model turns |
|
|
358
358
|
| `waitForMcpConnections` | `false` | Wait for MCP connections to settle before inference |
|
|
359
|
-
| `chatRecovery` |
|
|
360
|
-
| `chatStreamStallTimeoutMs` | `0` (off) |
|
|
359
|
+
| `chatRecovery` | Always on | Durable recovery configuration. See [`ChatRecoveryConfig`](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#stream-recovery) for all options and defaults |
|
|
360
|
+
| `chatStreamStallTimeoutMs` | `0` (off) | Opt-in inactivity watchdog that routes a stalled model stream into bounded recovery instead of leaving the client spinning indefinitely |
|
|
361
361
|
| `contextOverflow` | `undefined` | Opt-in mid-turn context-overflow handling: `{ reactive?, maxRetries?, proactive? }`. Requires `classifyChatError` + a session compaction function. See [Context-window overflow recovery](#context-window-overflow-recovery) |
|
|
362
362
|
|
|
363
363
|
On each turn, Think appends a small capability block to the assembled system prompt. The block is based on the tools available for that turn, so models learn about workspace tools, context-loading tools, extension tools, sandboxed execution, MCP/client tools, and delegated-agent tools only when they are actually exposed.
|
|
364
364
|
|
|
365
|
-
Think enables Durable Object eviction recovery
|
|
365
|
+
Think always enables Durable Object eviction recovery. This is separate from client resumable streaming: resumable streaming handles browser disconnect/reconnect while the object keeps running, while durable chat recovery handles turns interrupted by process restarts, deploys, or object eviction. `chatRecovery = false` is no longer supported; assign an object only to tune recovery.
|
|
366
366
|
|
|
367
|
-
`chatStreamStallTimeoutMs` is a separate, opt-in safety net for a different failure: a model stream that **parks without ever throwing** (no chunk, no error, no `done`), which otherwise leaves the client spinning forever. When set, if no UI-message-stream chunk arrives within the window the watchdog aborts the turn and a `chat:stream:stalled` observability event fires.
|
|
367
|
+
`chatStreamStallTimeoutMs` is a separate, opt-in safety net for a different failure: a model stream that **parks without ever throwing** (no chunk, no error, no `done`), which otherwise leaves the client spinning forever. When set, if no UI-message-stream chunk arrives within the window the watchdog aborts the turn and a `chat:stream:stalled` observability event fires. The stall is then routed into the **same bounded recovery path** as a deploy/eviction interruption: the settled partial is preserved and a continuation is scheduled, so a transient hang recovers automatically. A persistently hanging provider still terminalizes once the recovery budget is exhausted — and it exhausts through the **same path as deploy recovery**, so your configured `terminalMessage` is shown, `onExhausted` fires, and the `chat:recovery:exhausted` event is emitted (you do **not** get the raw `"Chat stream stalled…"` error). When the stalled turn is a sub-agent dispatched via `runAgentTool()`, a recovering stall closes the RPC stream without firing `onError`/`onDone` — the scheduled continuation owns the real terminal outcome, so the parent observes a (slightly delayed) completion rather than an error, exactly as it would for a deploy-interrupted child. It is **off by default** because it measures the gap _between_ stream chunks, which includes server-side tool execution time (no chunks flow while a tool runs) — set it comfortably above your slowest model time-to-first-token and slowest tool, e.g. `120_000`, or you will abort healthy long turns. For a turn you _know_ will invoke a slow tool, return `{ chatStreamStallTimeoutMs }` from `beforeTurn` (a `TurnConfig` field) to raise or disable (`0`) the watchdog for that one turn instead of permanently widening the global window; it auto-resets afterward.
|
|
368
368
|
|
|
369
369
|
Override `onChatRecovery(ctx)` when you need provider-specific recovery. The default behavior persists partial assistant output and continues or retries when safe:
|
|
370
370
|
|
|
@@ -1365,8 +1365,9 @@ declare class Think<
|
|
|
1365
1365
|
*/
|
|
1366
1366
|
mediaEviction: MediaEvictionConfig | boolean;
|
|
1367
1367
|
/**
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1368
|
+
* Durable chat recovery configuration. Every chat turn runs in `runFiber`,
|
|
1369
|
+
* enabling `onChatRecovery` and `this.stash()` during streaming. Assign an
|
|
1370
|
+
* object to tune recovery budgets and terminal behavior.
|
|
1370
1371
|
*
|
|
1371
1372
|
* Assign this as a class field or in the constructor — NOT in `onStart()`.
|
|
1372
1373
|
* On every wake the SDK evaluates recovery budgets (and may seal an
|
|
@@ -2941,7 +2942,9 @@ declare class Think<
|
|
|
2941
2942
|
private _startWorkflowNotificationDrain;
|
|
2942
2943
|
private _hasPendingWorkflowNotifications;
|
|
2943
2944
|
private _drainWorkflowNotifications;
|
|
2944
|
-
private
|
|
2945
|
+
private _nextWorkflowNotificationAlarm;
|
|
2946
|
+
protected _getExtensionAlarm(): number | null;
|
|
2947
|
+
private _rearmWorkflowNotificationAlarm;
|
|
2945
2948
|
inspectSubmission(
|
|
2946
2949
|
submissionId: string
|
|
2947
2950
|
): Promise<ThinkSubmissionInspection | null>;
|
|
@@ -3329,15 +3332,17 @@ declare class Think<
|
|
|
3329
3332
|
*/
|
|
3330
3333
|
private _rejectActionPause;
|
|
3331
3334
|
/**
|
|
3332
|
-
* Replace a paused execute-tool output in the transcript
|
|
3333
|
-
* execution's new outcome and kick the auto-continuation so the
|
|
3334
|
-
* it.
|
|
3335
|
+
* Replace a paused execute-tool or durable-action output in the transcript
|
|
3336
|
+
* with the execution's new outcome and kick the auto-continuation so the
|
|
3337
|
+
* model sees it.
|
|
3335
3338
|
*
|
|
3336
3339
|
* When no paused part carries `executionId` — the output was already
|
|
3337
3340
|
* replaced from another tab, or compaction summarized the part away — the
|
|
3338
3341
|
* runtime has still durably applied the approval/rejection, so the outcome
|
|
3339
|
-
* must not be dropped: it is appended as a system note
|
|
3340
|
-
* continuation still fires so the model can act on it.
|
|
3342
|
+
* must not be dropped: it is appended as a framework-authored system note,
|
|
3343
|
+
* and the continuation still fires so the model can act on it. Provider
|
|
3344
|
+
* assembly projects this narrowly identified note to ordinary user context
|
|
3345
|
+
* without changing its durable authorship.
|
|
3341
3346
|
*/
|
|
3342
3347
|
private _applyExecutionOutcome;
|
|
3343
3348
|
/**
|
|
@@ -3459,9 +3464,6 @@ declare class Think<
|
|
|
3459
3464
|
* emits `chat:recovery:exhausted`, marks the submission interrupted, and
|
|
3460
3465
|
* delivers the configured `terminalMessage`). The caller must NOT run the
|
|
3461
3466
|
* generic terminal path — the terminal UX is already delivered.
|
|
3462
|
-
* - `"disabled"` — chat recovery is off; the caller falls through to the
|
|
3463
|
-
* generic terminal error (the watchdog's original "kill the spinner"
|
|
3464
|
-
* behavior, unchanged).
|
|
3465
3467
|
*/
|
|
3466
3468
|
private _routeStallToBoundedRecovery;
|
|
3467
3469
|
protected _handleInternalFiberRecovery(
|
|
@@ -4483,4 +4485,4 @@ export {
|
|
|
4483
4485
|
ChannelDeliverySurface as zn,
|
|
4484
4486
|
PrepareStepResult$1 as zt
|
|
4485
4487
|
};
|
|
4486
|
-
//# sourceMappingURL=index-
|
|
4488
|
+
//# sourceMappingURL=index-B7zEkBBM.d.ts.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
I as TextStreamCallback,
|
|
3
3
|
n as ChatSdkMessengerOptions,
|
|
4
4
|
o as MessengerDefinition
|
|
5
|
-
} from "../index-
|
|
5
|
+
} from "../index-B7zEkBBM.js";
|
|
6
6
|
import { TelegramAdapterConfig } from "@chat-adapter/telegram";
|
|
7
7
|
|
|
8
8
|
//#region src/messengers/telegram.d.ts
|
package/dist/think.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as StepConfig, An as Workspace, At as ExtensionConfig, Bn as ChannelIngress, Bt as ReplyAttachment, Cn as TurnConfig, Ct as ChatResponseResult, Dn as TurnResult, Dt as ContextOverflowConfig, E as DeliveryTag, En as TurnInputMessages, Et as ChunkPart, Fn as ChannelCapabilities, Ft as OnStartDegradation, Gn as MediaEvictionConfig, Gt as RunTurnSubmit, Hn as NormalizedChannelDefinition, Ht as RunTurnBase, In as ChannelContext, It as PendingApproval, Jt as SaveMessagesResult, Kt as RunTurnWait, Ln as ChannelDefinition, Lt as PrepareStepContext, Mn as defaultContextOverflowClassifier, Mt as FiberRecoveryContext, Nn as isAction, Nt as ListSubmissionsOptions, On as TypedToolCall, Ot as DeleteSubmissionsOptions, Pn as skills, Pt as MessageConcurrency, Qt as SkillSource, Rn as ChannelDeliveryPolicy, Rt as PrepareStepFunction, Sn as ToolCallResultContext, St as ChatRecoveryProgressContext, T as DeliveryKind, Tn as TurnInput, Tt as ChunkContext, Un as ThinkChannels, Ut as RunTurnOptions, Vn as ChannelKind, Vt as ResolvedChatRecoveryConfig, Wn as messengerChannel, Wt as RunTurnStream, Xt as SessionMessage, Yt as Session, Zt as SkillRunContext, _n as ThinkSubmissionStatus, _t as ChatOptions, an as SubmitMessagesOptions, at as ActionApprovalDescriptor, bn as ToolCallContext, bt as ChatRecoveryExhaustedContext, cn as Think, ct as ActionAuthorizationDecision, dn as ThinkModelId, dt as ActionIdempotencyKey, en as StepContext, fn as ThinkScheduledTask, ft as ActionKind, gn as ThinkSubmissionInspection, gt as ChatErrorContext, hn as ThinkScheduledTasks, ht as ChatErrorClassification, in as StreamableResult, it as Action, jn as action, jt as FiberContext, kn as TypedToolResult, kt as DeliverNoticeOptions, ln as ThinkIntervalSchedule, lt as ActionConfig, mn as ThinkScheduledTaskSchedule, mt as AddMessagesOptions, nn as StopCondition, on as SubmitMessagesResult, ot as ActionApprovalPolicy, pn as ThinkScheduledTaskContext, pt as ActionPermissionSpec, qt as SaveMessagesOptions, rn as StreamCallback, sn as TextStreamPart, st as ActionAuthorizationContext, tn as StepResult, un as ThinkModel, ut as ActionContext, vn as ThinkTime, vt as ChatRecoveryConfig, wn as TurnContext, wt as ChatStartEvent, xn as ToolCallDecision, xt as ChatRecoveryOptions, yn as ThinkWallClockSchedule, yt as ChatRecoveryContext, zn as ChannelDeliverySurface, zt as PrepareStepResult } from "./index-
|
|
1
|
+
import { $t as StepConfig, An as Workspace, At as ExtensionConfig, Bn as ChannelIngress, Bt as ReplyAttachment, Cn as TurnConfig, Ct as ChatResponseResult, Dn as TurnResult, Dt as ContextOverflowConfig, E as DeliveryTag, En as TurnInputMessages, Et as ChunkPart, Fn as ChannelCapabilities, Ft as OnStartDegradation, Gn as MediaEvictionConfig, Gt as RunTurnSubmit, Hn as NormalizedChannelDefinition, Ht as RunTurnBase, In as ChannelContext, It as PendingApproval, Jt as SaveMessagesResult, Kt as RunTurnWait, Ln as ChannelDefinition, Lt as PrepareStepContext, Mn as defaultContextOverflowClassifier, Mt as FiberRecoveryContext, Nn as isAction, Nt as ListSubmissionsOptions, On as TypedToolCall, Ot as DeleteSubmissionsOptions, Pn as skills, Pt as MessageConcurrency, Qt as SkillSource, Rn as ChannelDeliveryPolicy, Rt as PrepareStepFunction, Sn as ToolCallResultContext, St as ChatRecoveryProgressContext, T as DeliveryKind, Tn as TurnInput, Tt as ChunkContext, Un as ThinkChannels, Ut as RunTurnOptions, Vn as ChannelKind, Vt as ResolvedChatRecoveryConfig, Wn as messengerChannel, Wt as RunTurnStream, Xt as SessionMessage, Yt as Session, Zt as SkillRunContext, _n as ThinkSubmissionStatus, _t as ChatOptions, an as SubmitMessagesOptions, at as ActionApprovalDescriptor, bn as ToolCallContext, bt as ChatRecoveryExhaustedContext, cn as Think, ct as ActionAuthorizationDecision, dn as ThinkModelId, dt as ActionIdempotencyKey, en as StepContext, fn as ThinkScheduledTask, ft as ActionKind, gn as ThinkSubmissionInspection, gt as ChatErrorContext, hn as ThinkScheduledTasks, ht as ChatErrorClassification, in as StreamableResult, it as Action, jn as action, jt as FiberContext, kn as TypedToolResult, kt as DeliverNoticeOptions, ln as ThinkIntervalSchedule, lt as ActionConfig, mn as ThinkScheduledTaskSchedule, mt as AddMessagesOptions, nn as StopCondition, on as SubmitMessagesResult, ot as ActionApprovalPolicy, pn as ThinkScheduledTaskContext, pt as ActionPermissionSpec, qt as SaveMessagesOptions, rn as StreamCallback, sn as TextStreamPart, st as ActionAuthorizationContext, tn as StepResult, un as ThinkModel, ut as ActionContext, vn as ThinkTime, vt as ChatRecoveryConfig, wn as TurnContext, wt as ChatStartEvent, xn as ToolCallDecision, xt as ChatRecoveryOptions, yn as ThinkWallClockSchedule, yt as ChatRecoveryContext, zn as ChannelDeliverySurface, zt as PrepareStepResult } from "./index-B7zEkBBM.js";
|
|
2
2
|
import { h as WorkspaceLike } from "./workspace-DxZQSbko.js";
|
|
3
3
|
import { a as FetchResponseMode, i as FetchRedirectPolicy, n as FetchBindingTarget, o as FetchResult, r as FetchErrorCode, s as FetchToolEvent, t as CreateFetchToolsOptions } from "./fetch-By3eIQ-a.js";
|
|
4
4
|
export { Action, ActionApprovalDescriptor, ActionApprovalPolicy, ActionAuthorizationContext, ActionAuthorizationDecision, ActionConfig, ActionContext, ActionIdempotencyKey, ActionKind, ActionPermissionSpec, AddMessagesOptions, type ChannelCapabilities, type ChannelContext, type ChannelDefinition, type ChannelDeliveryPolicy, type ChannelDeliverySurface, type ChannelIngress, type ChannelKind, ChatErrorClassification, ChatErrorContext, ChatOptions, type ChatRecoveryConfig, type ChatRecoveryContext, type ChatRecoveryExhaustedContext, type ChatRecoveryOptions, type ChatRecoveryProgressContext, type ChatResponseResult, ChatStartEvent, ChunkContext, ChunkPart, ContextOverflowConfig, type CreateFetchToolsOptions, DeleteSubmissionsOptions, DeliverNoticeOptions, type DeliveryKind, type DeliveryTag, ExtensionConfig, type FetchBindingTarget, type FetchErrorCode, type FetchRedirectPolicy, type FetchResponseMode, type FetchResult, type FetchToolEvent, type FiberContext, type FiberRecoveryContext, ListSubmissionsOptions, type MediaEvictionConfig, type MessageConcurrency, type NormalizedChannelDefinition, OnStartDegradation, PendingApproval, PrepareStepContext, type PrepareStepFunction, type PrepareStepResult, ReplyAttachment, type ResolvedChatRecoveryConfig, RunTurnBase, RunTurnOptions, RunTurnStream, RunTurnSubmit, RunTurnWait, type SaveMessagesOptions, type SaveMessagesResult, Session, type SessionMessage, type SkillRunContext, type SkillSource, StepConfig, StepContext, type StepResult, type StopCondition, StreamCallback, StreamableResult, SubmitMessagesOptions, SubmitMessagesResult, type TextStreamPart, Think, type ThinkChannels, ThinkIntervalSchedule, ThinkModel, ThinkModelId, ThinkScheduledTask, ThinkScheduledTaskContext, ThinkScheduledTaskSchedule, ThinkScheduledTasks, ThinkSubmissionInspection, ThinkSubmissionStatus, ThinkTime, ThinkWallClockSchedule, ToolCallContext, ToolCallDecision, ToolCallResultContext, TurnConfig, TurnContext, TurnInput, TurnInputMessages, TurnResult, type TypedToolCall, type TypedToolResult, Workspace, type WorkspaceLike, action, defaultContextOverflowClassifier, isAction, messengerChannel, skills };
|
package/dist/think.js
CHANGED
|
@@ -805,6 +805,22 @@ const THINK_WORKFLOW_PROMPT_METADATA_KEY = "__thinkWorkflowPrompt";
|
|
|
805
805
|
* client-supplied messages at intake so a client can never forge them.
|
|
806
806
|
*/
|
|
807
807
|
const RESERVED_MESSAGE_METADATA_KEYS = ["channel", "turnMetadata"];
|
|
808
|
+
/** Stable id prefix for fallback notes that preserve orphaned execution outcomes. */
|
|
809
|
+
const EXECUTION_OUTCOME_MESSAGE_PREFIX = "exec-outcome-";
|
|
810
|
+
/**
|
|
811
|
+
* Present framework-authored execution outcome notes to providers as user
|
|
812
|
+
* context. Think persists these notes as system messages so clients and
|
|
813
|
+
* recovery do not mistake them for human input, but AI SDK v7 and strict
|
|
814
|
+
* providers reject system messages in arbitrary transcript
|
|
815
|
+
* positions. The provider-only projection leaves current and legacy session
|
|
816
|
+
* history unchanged.
|
|
817
|
+
*/
|
|
818
|
+
function toProviderSafeExecutionOutcomeMessage(message) {
|
|
819
|
+
return message.role === "system" && message.id.startsWith(EXECUTION_OUTCOME_MESSAGE_PREFIX) ? {
|
|
820
|
+
...message,
|
|
821
|
+
role: "user"
|
|
822
|
+
} : message;
|
|
823
|
+
}
|
|
808
824
|
/**
|
|
809
825
|
* Reserved name for the synthetic tool a workflow `step.prompt` turn uses to
|
|
810
826
|
* deliver its structured final answer. The agent runs a full multi-step,
|
|
@@ -2460,7 +2476,7 @@ var Think = class Think extends Agent {
|
|
|
2460
2476
|
* head through the exact same pipeline.
|
|
2461
2477
|
*/
|
|
2462
2478
|
async _assembleModelMessages(tools) {
|
|
2463
|
-
const truncated = truncateOlderMessages(await this._repairTranscriptForProvider(this.messages));
|
|
2479
|
+
const truncated = truncateOlderMessages((await this._repairTranscriptForProvider(this.messages)).map(toProviderSafeExecutionOutcomeMessage));
|
|
2464
2480
|
const incompleteAfterRepair = this._incompleteToolCallIds(truncated);
|
|
2465
2481
|
if (incompleteAfterRepair.length > 0) {
|
|
2466
2482
|
console.warn(`[Think] ${incompleteAfterRepair.length} incomplete tool call(s) survived transcript repair and will be dropped by ignoreIncompleteToolCalls: ${incompleteAfterRepair.join(", ")}. This indicates a gap in _repairToolTranscriptParts.`);
|
|
@@ -3680,8 +3696,7 @@ var Think = class Think extends Agent {
|
|
|
3680
3696
|
return;
|
|
3681
3697
|
}
|
|
3682
3698
|
};
|
|
3683
|
-
|
|
3684
|
-
else await chatBody();
|
|
3699
|
+
await this._runChatRecoveryFiber(requestId, false, chatBody);
|
|
3685
3700
|
}
|
|
3686
3701
|
});
|
|
3687
3702
|
} finally {
|
|
@@ -5277,7 +5292,7 @@ var Think = class Think extends Agent {
|
|
|
5277
5292
|
if (!this._hasPendingWorkflowNotifications()) return;
|
|
5278
5293
|
this.keepAliveWhile(() => this._drainWorkflowNotifications()).catch((error) => {
|
|
5279
5294
|
console.error("[Think] Failed to drain workflow notifications", error);
|
|
5280
|
-
this.
|
|
5295
|
+
this._rearmWorkflowNotificationAlarm();
|
|
5281
5296
|
});
|
|
5282
5297
|
}
|
|
5283
5298
|
_hasPendingWorkflowNotifications() {
|
|
@@ -5330,22 +5345,26 @@ var Think = class Think extends Agent {
|
|
|
5330
5345
|
} finally {
|
|
5331
5346
|
this._drainingWorkflowNotifications = false;
|
|
5332
5347
|
}
|
|
5333
|
-
await this.
|
|
5348
|
+
await this._rearmWorkflowNotificationAlarm();
|
|
5334
5349
|
}
|
|
5335
|
-
|
|
5350
|
+
_nextWorkflowNotificationAlarm() {
|
|
5336
5351
|
this._ensureWorkflowNotificationTable();
|
|
5337
5352
|
const pending = this.sql`
|
|
5338
|
-
SELECT attempts
|
|
5353
|
+
SELECT attempts, updated_at
|
|
5339
5354
|
FROM cf_think_workflow_notifications
|
|
5340
5355
|
WHERE delivered_at IS NULL
|
|
5341
5356
|
ORDER BY created_at ASC, notification_id ASC
|
|
5342
5357
|
LIMIT 1
|
|
5343
5358
|
`;
|
|
5344
|
-
if (!pending[0]) return;
|
|
5359
|
+
if (!pending[0]) return null;
|
|
5345
5360
|
const delayMs = Math.min(300 * 1e3, 1e3 * 2 ** Math.min(pending[0].attempts, 8));
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5361
|
+
return Math.max(pending[0].updated_at + delayMs, Date.now() + 1);
|
|
5362
|
+
}
|
|
5363
|
+
_getExtensionAlarm() {
|
|
5364
|
+
return this._nextWorkflowNotificationAlarm();
|
|
5365
|
+
}
|
|
5366
|
+
_rearmWorkflowNotificationAlarm() {
|
|
5367
|
+
return this.lifecycle.rearmAlarm();
|
|
5349
5368
|
}
|
|
5350
5369
|
async inspectSubmission(submissionId) {
|
|
5351
5370
|
const row = this._readSubmission(submissionId);
|
|
@@ -5930,8 +5949,7 @@ var Think = class Think extends Agent {
|
|
|
5930
5949
|
return;
|
|
5931
5950
|
}
|
|
5932
5951
|
};
|
|
5933
|
-
|
|
5934
|
-
else await programmaticBody();
|
|
5952
|
+
await this._runChatRecoveryFiber(requestId, false, programmaticBody);
|
|
5935
5953
|
} finally {
|
|
5936
5954
|
if (abortSignal?.aborted) wasAborted = true;
|
|
5937
5955
|
detachExternal();
|
|
@@ -6015,8 +6033,7 @@ var Think = class Think extends Agent {
|
|
|
6015
6033
|
error = streamResult.error;
|
|
6016
6034
|
}
|
|
6017
6035
|
};
|
|
6018
|
-
|
|
6019
|
-
else await continueTurnBody();
|
|
6036
|
+
await this._runChatRecoveryFiber(requestId, true, continueTurnBody);
|
|
6020
6037
|
} finally {
|
|
6021
6038
|
if (abortSignal?.aborted) wasAborted = true;
|
|
6022
6039
|
detachExternal();
|
|
@@ -6080,8 +6097,7 @@ var Think = class Think extends Agent {
|
|
|
6080
6097
|
error = streamResult.error;
|
|
6081
6098
|
}
|
|
6082
6099
|
};
|
|
6083
|
-
|
|
6084
|
-
else await retryTurnBody();
|
|
6100
|
+
await this._runChatRecoveryFiber(requestId, false, retryTurnBody);
|
|
6085
6101
|
} finally {
|
|
6086
6102
|
if (abortSignal?.aborted) wasAborted = true;
|
|
6087
6103
|
detachExternal();
|
|
@@ -6369,8 +6385,7 @@ var Think = class Think extends Agent {
|
|
|
6369
6385
|
return;
|
|
6370
6386
|
}
|
|
6371
6387
|
};
|
|
6372
|
-
|
|
6373
|
-
else await chatTurnBody();
|
|
6388
|
+
await this._runChatRecoveryFiber(requestId, false, chatTurnBody);
|
|
6374
6389
|
}
|
|
6375
6390
|
})).status === "stale") this._broadcastChat({
|
|
6376
6391
|
type: MSG_CHAT_RESPONSE,
|
|
@@ -7466,15 +7481,17 @@ var Think = class Think extends Agent {
|
|
|
7466
7481
|
return output;
|
|
7467
7482
|
}
|
|
7468
7483
|
/**
|
|
7469
|
-
* Replace a paused execute-tool output in the transcript
|
|
7470
|
-
* execution's new outcome and kick the auto-continuation so the
|
|
7471
|
-
* it.
|
|
7484
|
+
* Replace a paused execute-tool or durable-action output in the transcript
|
|
7485
|
+
* with the execution's new outcome and kick the auto-continuation so the
|
|
7486
|
+
* model sees it.
|
|
7472
7487
|
*
|
|
7473
7488
|
* When no paused part carries `executionId` — the output was already
|
|
7474
7489
|
* replaced from another tab, or compaction summarized the part away — the
|
|
7475
7490
|
* runtime has still durably applied the approval/rejection, so the outcome
|
|
7476
|
-
* must not be dropped: it is appended as a system note
|
|
7477
|
-
* continuation still fires so the model can act on it.
|
|
7491
|
+
* must not be dropped: it is appended as a framework-authored system note,
|
|
7492
|
+
* and the continuation still fires so the model can act on it. Provider
|
|
7493
|
+
* assembly projects this narrowly identified note to ordinary user context
|
|
7494
|
+
* without changing its durable authorship.
|
|
7478
7495
|
*/
|
|
7479
7496
|
async _applyExecutionOutcome(executionId, output) {
|
|
7480
7497
|
const toolCallId = this._findPausedExecutionToolCall(executionId);
|
|
@@ -7486,12 +7503,13 @@ var Think = class Think extends Agent {
|
|
|
7486
7503
|
} catch {
|
|
7487
7504
|
summary = String(output);
|
|
7488
7505
|
}
|
|
7506
|
+
const outcomeSource = executionId.startsWith(ACTION_PAUSE_ID_PREFIX) ? "durable action" : "execute tool";
|
|
7489
7507
|
await this._appendMessageToHistory({
|
|
7490
|
-
id:
|
|
7508
|
+
id: `${EXECUTION_OUTCOME_MESSAGE_PREFIX}${executionId}-${crypto.randomUUID()}`,
|
|
7491
7509
|
role: "system",
|
|
7492
7510
|
parts: [{
|
|
7493
7511
|
type: "text",
|
|
7494
|
-
text: `[
|
|
7512
|
+
text: `[${outcomeSource}] The paused execution "${executionId}" was resolved, but its tool call is no longer in the transcript (it may have been compacted). Outcome: ${summary}`
|
|
7495
7513
|
}]
|
|
7496
7514
|
});
|
|
7497
7515
|
} else await this._enqueueInteractionApply(() => this._applyToolUpdateToMessages(pausedExecutionUpdate(toolCallId, executionId, output)));
|
|
@@ -7773,12 +7791,8 @@ var Think = class Think extends Agent {
|
|
|
7773
7791
|
* emits `chat:recovery:exhausted`, marks the submission interrupted, and
|
|
7774
7792
|
* delivers the configured `terminalMessage`). The caller must NOT run the
|
|
7775
7793
|
* generic terminal path — the terminal UX is already delivered.
|
|
7776
|
-
* - `"disabled"` — chat recovery is off; the caller falls through to the
|
|
7777
|
-
* generic terminal error (the watchdog's original "kill the spinner"
|
|
7778
|
-
* behavior, unchanged).
|
|
7779
7794
|
*/
|
|
7780
7795
|
async _routeStallToBoundedRecovery(input) {
|
|
7781
|
-
if (!this._resolveChatRecoveryConfig().enabled) return "disabled";
|
|
7782
7796
|
const recoveryRootRequestId = this._activeChatRecoveryRootRequestId ?? input.requestId;
|
|
7783
7797
|
const latestUserMessageId = [...this.messages].reverse().find((m) => m.role === "user")?.id ?? null;
|
|
7784
7798
|
const { incident, config, exhausted } = await this._beginChatRecoveryIncident({
|
|
@@ -7944,13 +7958,13 @@ var Think = class Think extends Agent {
|
|
|
7944
7958
|
});
|
|
7945
7959
|
else if (options.continue === false && !streamIsTerminal) {
|
|
7946
7960
|
await this._updateChatRecoveryIncident(incident.incidentId, "skipped", "continue_disabled");
|
|
7947
|
-
const
|
|
7948
|
-
await this._markRecoveredSubmissionInterrupted(recoveryRootRequestId,
|
|
7949
|
-
await this._recordTerminalChatStatus("interrupted", requestId,
|
|
7961
|
+
const declinedMessage = "Submission was interrupted and automatic continuation was declined.";
|
|
7962
|
+
await this._markRecoveredSubmissionInterrupted(recoveryRootRequestId, declinedMessage);
|
|
7963
|
+
await this._recordTerminalChatStatus("interrupted", requestId, declinedMessage);
|
|
7950
7964
|
this._broadcastChat({
|
|
7951
7965
|
type: MSG_CHAT_RESPONSE,
|
|
7952
7966
|
id: requestId,
|
|
7953
|
-
body:
|
|
7967
|
+
body: declinedMessage,
|
|
7954
7968
|
done: true,
|
|
7955
7969
|
error: true
|
|
7956
7970
|
});
|
|
@@ -8496,8 +8510,7 @@ var Think = class Think extends Agent {
|
|
|
8496
8510
|
streamed = true;
|
|
8497
8511
|
}
|
|
8498
8512
|
};
|
|
8499
|
-
|
|
8500
|
-
else await continuationBody();
|
|
8513
|
+
await this._runChatRecoveryFiber(requestId, true, continuationBody);
|
|
8501
8514
|
} finally {
|
|
8502
8515
|
this._aborts.remove(requestId);
|
|
8503
8516
|
if (!streamed) this._continuation.sendResumeNone();
|
|
@@ -8553,8 +8566,7 @@ var Think = class Think extends Agent {
|
|
|
8553
8566
|
}));
|
|
8554
8567
|
if (result) await this._streamResult(requestId, result, abortSignal, { continuation: true });
|
|
8555
8568
|
};
|
|
8556
|
-
|
|
8557
|
-
else await continuationBody();
|
|
8569
|
+
await this._runChatRecoveryFiber(requestId, true, continuationBody);
|
|
8558
8570
|
}
|
|
8559
8571
|
});
|
|
8560
8572
|
} catch (error) {
|