@cloudflare/think 0.20.2 → 0.22.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 +60 -43
- package/dist/classPrivateFieldSet2-DwGJfC3w.js +27 -0
- package/dist/extensions/index.js +2 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/{fetch-By3eIQ-a.d.ts → fetch-CU2fC7O6.d.ts} +41 -20
- package/dist/fetch-DO3uQ9py.js +727 -0
- package/dist/fetch-DO3uQ9py.js.map +1 -0
- package/dist/{index-CmhSKa6U.d.ts → index-BFK9bpzz.d.ts} +55 -75
- package/dist/{manager-Cb3DNZgp.js → manager-BubfmA3q.js} +3 -28
- package/dist/{manager-Cb3DNZgp.js.map → manager-BubfmA3q.js.map} +1 -1
- package/dist/messengers/index.d.ts +1 -1
- package/dist/messengers/telegram.d.ts +1 -1
- package/dist/think.d.ts +3 -4
- package/dist/think.js +79 -97
- package/dist/think.js.map +1 -1
- package/dist/tools/execute.d.ts +19 -24
- package/dist/tools/execute.js +20 -40
- package/dist/tools/execute.js.map +1 -1
- package/dist/tools/extensions.d.ts +1 -1
- package/dist/tools/extensions.js +2 -2
- package/dist/tools/extensions.js.map +1 -1
- package/dist/tools/fetch.d.ts +2 -4
- package/dist/tools/fetch.js +1 -608
- package/dist/workflows.d.ts +1 -1
- package/docs/channels.md +1 -5
- package/docs/getting-started.md +4 -4
- package/docs/index.md +31 -17
- package/docs/lifecycle-hooks.md +1 -3
- package/docs/multi-chat.md +21 -60
- package/docs/sub-agents.md +13 -13
- package/docs/tools.md +73 -109
- package/package.json +7 -12
- package/dist/tools/fetch.js.map +0 -1
- package/dist/tools/workspace.d.ts +0 -60
- package/dist/tools/workspace.js +0 -869
- package/dist/tools/workspace.js.map +0 -1
- package/dist/workspace-CNeXc2vl.d.ts +0 -201
package/dist/think.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createFetchTools } from "./
|
|
1
|
+
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, r as _assertClassBrand, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-DwGJfC3w.js";
|
|
2
|
+
import { n as sanitizeName, r as _classPrivateMethodInitSpec, t as ExtensionManager } from "./manager-BubfmA3q.js";
|
|
3
|
+
import { n as WorkspaceFiles, r as resolveWorkspacePath, t as createFetchTools } from "./fetch-DO3uQ9py.js";
|
|
4
4
|
import { truncatePausedExecutionOutput } from "./tools/execute.js";
|
|
5
5
|
import { _ as MESSENGER_REPLY_FIBER_NAME, n as ThinkMessengerRuntime, t as DEFAULT_MESSENGER_CONCURRENCY } from "./chat-sdk-BEjKXjCm.js";
|
|
6
6
|
import "./messengers/index.js";
|
|
@@ -17,7 +17,8 @@ import { Agent, __DO_NOT_USE_WILL_BREAK__agentContext, __DO_NOT_USE_WILL_BREAK__
|
|
|
17
17
|
import { AbortRegistry, AgentToolProgressEmitter, AgentToolStreamProgressThrottle, AutoContinuationController, CHAT_MESSAGE_TYPES, CHAT_RECOVERY_INCIDENT_KEY_PREFIX, CHAT_RECOVERY_PROGRESS_KEY, CHAT_RECOVERY_STABLE_RETRY_DELAY_SECONDS, CHAT_RECOVERY_TASK_NAME, ChatRecoveryEngine, ChatStreamStalledError, ContinuationState, MAX_BOUND_PARAMS, PreStreamTurns, ResumableStream, ResumeHandshake, StreamAccumulator, SubmitConcurrencyController, TIMED_OUT, TurnQueue, aiSdkRecoveryCodec, applyToolUpdate, awaitWithDeadline, buildChatRecoveringFrame, buildInClauseStrings, chatRecoveryBackoffSeconds, chatRecoveryTaskRunOptions, classifyAgentToolChildRecovery, clearChatTerminal, clientResolvableToolNames, createChatFiberSnapshot, createChatRecoveryTaskDefinition, createChatStreams, createChatTurnTaskDefinition, createToolsFromClientSchemas, crossMessageToolResultUpdate, dispatchChatRecoveryToHandoff, drainInteractionApplies, enforceRowSizeLimit, hasIncompleteToolBatch, interceptAgentToolBroadcast, isDurableObjectResetError, isLateToolInputChunk, isPositionlessAgentToolChunk, iterateWithStallWatchdog, lateToolInputForwardChunks, listActiveChatRecoveryIncidents, normalizeToolInput, originMessageIds, parseProtocolMessage, partAwaitsClientInteraction, pausedExecutionUpdate, pendingChatTerminal, persistReconstructedOrphan, readChatRecoveryProgress, reconcileMessages, recordChatTerminal, repairInterruptedToolParts, resolveChatRecoveryConfig, retryAfterSeconds, runChatRecoveryExhaustion, sanitizeMessage, setChatRecovering, sweepStaleChatRecoveryIncidents, toolApprovalUpdate, toolPartHasSettledResult, toolResultUpdate, truncateOlderMessages, truncateOlderToolResults, unwrapChatFiberSnapshot, withOriginMessageIds, wrapChatFiberSnapshot } from "agents/chat";
|
|
18
18
|
import { Sessions, isCompactionMessage } from "agents/sessions";
|
|
19
19
|
import { AgentContextProvider, ContextBlocks } from "agents/context";
|
|
20
|
-
import { Workspace
|
|
20
|
+
import { Workspace } from "@cloudflare/computer";
|
|
21
|
+
import { createAITools } from "@cloudflare/computer/tools/ai-sdk";
|
|
21
22
|
//#region src/session.ts
|
|
22
23
|
var _handle = /* @__PURE__ */ new WeakMap();
|
|
23
24
|
var _context = /* @__PURE__ */ new WeakMap();
|
|
@@ -408,7 +409,7 @@ function extensionFor(mediaType) {
|
|
|
408
409
|
}
|
|
409
410
|
/** Workspace path for the n-th value evicted from a message. */
|
|
410
411
|
function evictedFilePath(messageId, index, mediaType) {
|
|
411
|
-
return `/attachments/evicted/${messageId}-${index}.${extensionFor(mediaType)}`;
|
|
412
|
+
return `/workspace/attachments/evicted/${messageId}-${index}.${extensionFor(mediaType)}`;
|
|
412
413
|
}
|
|
413
414
|
//#endregion
|
|
414
415
|
//#region src/channels/index.ts
|
|
@@ -649,10 +650,6 @@ function mediaEvictionCutoff(messageCount, keepRecentMessages, step) {
|
|
|
649
650
|
return Math.max(0, messageCount - truncationKeepRecent(messageCount, safeStep) - stepsBack * safeStep);
|
|
650
651
|
}
|
|
651
652
|
const DEFAULT_ACTION_TIMEOUT_MS = 3e4;
|
|
652
|
-
/** Whether a workspace can receive raw bytes, which skills projection needs. */
|
|
653
|
-
function hasWriteFileBytes(workspace) {
|
|
654
|
-
return typeof workspace.writeFileBytes === "function";
|
|
655
|
-
}
|
|
656
653
|
const ACTION_OUTPUT_MAX_CHARS = 2e4;
|
|
657
654
|
const MAX_REPLY_ATTACHMENTS_PER_TURN = 32;
|
|
658
655
|
const ACTION_LEDGER_SWEEP_INTERVAL_MS = 3600 * 1e3;
|
|
@@ -760,6 +757,14 @@ function keepResolvedPauses(incoming, serverMessages) {
|
|
|
760
757
|
};
|
|
761
758
|
});
|
|
762
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Whether a workspace is a Computer `Workspace` this agent owns, as opposed
|
|
762
|
+
* to a client for one another Durable Object owns. Checked by shape so a
|
|
763
|
+
* second copy of `@cloudflare/computer` in the bundle still matches.
|
|
764
|
+
*/
|
|
765
|
+
function isLocalWorkspace(workspace) {
|
|
766
|
+
return "ready" in workspace && typeof workspace.ready === "function" && "stub" in workspace && typeof workspace.stub === "function";
|
|
767
|
+
}
|
|
763
768
|
const ACTION_PENDING_SWEEP_INTERVAL_MS = 3600 * 1e3;
|
|
764
769
|
const ACTION_PENDING_LAST_SWEPT_KEY = "cf_think_action_pending_approvals:last_swept_at";
|
|
765
770
|
/** Prefix for durable-pause action execution ids (vs codemode execution ids). */
|
|
@@ -1126,20 +1131,29 @@ function parseDeclaredTaskScheduleUnchecked(rawSchedule, taskTimezone, defaultTi
|
|
|
1126
1131
|
}
|
|
1127
1132
|
throw new Error(`Unsupported schedule DSL "${rawSchedule}"`);
|
|
1128
1133
|
}
|
|
1134
|
+
const zonedPartsFormatters = /* @__PURE__ */ new Map();
|
|
1135
|
+
function getZonedPartsFormatter(timezone) {
|
|
1136
|
+
let formatter = zonedPartsFormatters.get(timezone);
|
|
1137
|
+
if (!formatter) {
|
|
1138
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
1139
|
+
timeZone: timezone,
|
|
1140
|
+
calendar: "iso8601",
|
|
1141
|
+
numberingSystem: "latn",
|
|
1142
|
+
weekday: "short",
|
|
1143
|
+
year: "numeric",
|
|
1144
|
+
month: "2-digit",
|
|
1145
|
+
day: "2-digit",
|
|
1146
|
+
hour: "2-digit",
|
|
1147
|
+
minute: "2-digit",
|
|
1148
|
+
second: "2-digit",
|
|
1149
|
+
hourCycle: "h23"
|
|
1150
|
+
});
|
|
1151
|
+
zonedPartsFormatters.set(timezone, formatter);
|
|
1152
|
+
}
|
|
1153
|
+
return formatter;
|
|
1154
|
+
}
|
|
1129
1155
|
function getZonedParts(date, timezone) {
|
|
1130
|
-
const parts =
|
|
1131
|
-
timeZone: timezone,
|
|
1132
|
-
calendar: "iso8601",
|
|
1133
|
-
numberingSystem: "latn",
|
|
1134
|
-
weekday: "short",
|
|
1135
|
-
year: "numeric",
|
|
1136
|
-
month: "2-digit",
|
|
1137
|
-
day: "2-digit",
|
|
1138
|
-
hour: "2-digit",
|
|
1139
|
-
minute: "2-digit",
|
|
1140
|
-
second: "2-digit",
|
|
1141
|
-
hourCycle: "h23"
|
|
1142
|
-
}).formatToParts(date);
|
|
1156
|
+
const parts = getZonedPartsFormatter(timezone).formatToParts(date);
|
|
1143
1157
|
const part = (type) => parts.find((entry) => entry.type === type)?.value ?? "";
|
|
1144
1158
|
return {
|
|
1145
1159
|
year: Number(part("year")),
|
|
@@ -1559,13 +1573,11 @@ var Think = class Think extends Agent {
|
|
|
1559
1573
|
_classPrivateFieldInitSpec(this, _contextBlocks, void 0);
|
|
1560
1574
|
this._cachedMessages = [];
|
|
1561
1575
|
this._onStartDegradations = [];
|
|
1562
|
-
this.workspaceBash = true;
|
|
1563
1576
|
this.fetchTools = false;
|
|
1564
1577
|
this._repairApprovalRespondedThisTurn = false;
|
|
1565
1578
|
this._mediaEvictionRunning = false;
|
|
1566
1579
|
this._mediaEvictionPending = false;
|
|
1567
1580
|
this._mediaEvictionAppendsDuringPass = 0;
|
|
1568
|
-
this._warnedEvictionUnsupported = false;
|
|
1569
1581
|
this._mediaEvictionFruitless = null;
|
|
1570
1582
|
this._lastHydration = null;
|
|
1571
1583
|
this._warnedHydrationWindowed = false;
|
|
@@ -1665,10 +1677,7 @@ var Think = class Think extends Agent {
|
|
|
1665
1677
|
const _onStart = this.onStart.bind(this);
|
|
1666
1678
|
const startThink = async (props, update) => {
|
|
1667
1679
|
await withAgentSpan(this, "initialize_think_session", "startup", { "cloudflare.agents.component": "think" }, async () => {
|
|
1668
|
-
if (!this.workspace) this.workspace = new Workspace
|
|
1669
|
-
sql: this.ctx.storage.sql,
|
|
1670
|
-
name: () => this.name
|
|
1671
|
-
});
|
|
1680
|
+
if (!this.workspace) this.workspace = new Workspace({ storage: this.ctx.storage });
|
|
1672
1681
|
this.session = await this.configureSession(new ThinkSession(this.sessions.session(), () => this.context));
|
|
1673
1682
|
_classPrivateFieldSet2(_contextBlocks, this, new ContextBlocks([...await this.configureContext(), ...this.session.internal_takePendingContext()], this.session.internal_promptStore() ?? _assertClassBrand(_Think_brand, this, _contextProvider).call(this, "_system_prompt"), (label) => _assertClassBrand(_Think_brand, this, _contextProvider).call(this, label)));
|
|
1674
1683
|
await _classPrivateFieldGet2(_contextBlocks, this).load();
|
|
@@ -1991,14 +2000,7 @@ var Think = class Think extends Agent {
|
|
|
1991
2000
|
backlogRemains: false
|
|
1992
2001
|
};
|
|
1993
2002
|
try {
|
|
1994
|
-
const
|
|
1995
|
-
if (!writeFileBytes) {
|
|
1996
|
-
if (!this._warnedEvictionUnsupported) {
|
|
1997
|
-
this._warnedEvictionUnsupported = true;
|
|
1998
|
-
console.warn("[Think] mediaEviction is enabled but the configured workspace does not implement writeFileBytes; media eviction is a no-op for this agent.");
|
|
1999
|
-
}
|
|
2000
|
-
return null;
|
|
2001
|
-
}
|
|
2003
|
+
const files = new WorkspaceFiles(this.workspace);
|
|
2002
2004
|
const stats = await this.session.getHistoryRowStats();
|
|
2003
2005
|
const aged = stats.slice(0, mediaEvictionCutoff(stats.length, config.keepRecentMessages, this.truncationStep));
|
|
2004
2006
|
let processed = 0;
|
|
@@ -2015,7 +2017,7 @@ var Think = class Think extends Agent {
|
|
|
2015
2017
|
minPartBytes: config.minPartBytes,
|
|
2016
2018
|
write: async (index, bytes, mediaType) => {
|
|
2017
2019
|
const path = evictedFilePath(message.id, index, mediaType);
|
|
2018
|
-
await
|
|
2020
|
+
await files.write(path, bytes);
|
|
2019
2021
|
return path;
|
|
2020
2022
|
}
|
|
2021
2023
|
});
|
|
@@ -2823,7 +2825,11 @@ var Think = class Think extends Agent {
|
|
|
2823
2825
|
*/
|
|
2824
2826
|
_dispatchChatRecovery(callback, data, detached) {
|
|
2825
2827
|
return dispatchChatRecoveryToHandoff({
|
|
2826
|
-
detached
|
|
2828
|
+
detached: (onTurnStarted) => this._chatRecoveryEngine().runRecoveryAttempt({
|
|
2829
|
+
callback,
|
|
2830
|
+
data,
|
|
2831
|
+
run: () => detached(onTurnStarted)
|
|
2832
|
+
}),
|
|
2827
2833
|
track: (turn) => this.lifecycle.trackAlarmWork(turn),
|
|
2828
2834
|
redefer: (dedupeKey) => this._enqueueChatRecovery(callback, data ?? {}, "redefer", CHAT_RECOVERY_STABLE_RETRY_DELAY_SECONDS, dedupeKey),
|
|
2829
2835
|
onDetachedError: (error) => console.error(`[Think] ${callback} dispatch failed`, error)
|
|
@@ -2993,7 +2999,7 @@ var Think = class Think extends Agent {
|
|
|
2993
2999
|
"read",
|
|
2994
3000
|
"write",
|
|
2995
3001
|
"edit",
|
|
2996
|
-
"
|
|
3002
|
+
"ls",
|
|
2997
3003
|
"find",
|
|
2998
3004
|
"grep",
|
|
2999
3005
|
"delete"
|
|
@@ -3122,14 +3128,6 @@ var Think = class Think extends Agent {
|
|
|
3122
3128
|
async _configureSkillWorkspace(registry) {
|
|
3123
3129
|
if (this.skillWorkspace === false) return;
|
|
3124
3130
|
const workspace = this.workspace;
|
|
3125
|
-
if (!hasWriteFileBytes(workspace)) {
|
|
3126
|
-
const warning = "skillWorkspace is enabled but the configured workspace does not implement writeFileBytes; skills stay source-backed.";
|
|
3127
|
-
if (!this._loggedSkillWarnings.has(warning)) {
|
|
3128
|
-
this._loggedSkillWarnings.add(warning);
|
|
3129
|
-
console.warn(`[think] ${warning}`);
|
|
3130
|
-
}
|
|
3131
|
-
return;
|
|
3132
|
-
}
|
|
3133
3131
|
try {
|
|
3134
3132
|
const key = "skillsWorkspaceFingerprint";
|
|
3135
3133
|
if (this._configGet(key) === registry.fingerprint) {
|
|
@@ -3776,7 +3774,7 @@ var Think = class Think extends Agent {
|
|
|
3776
3774
|
const timeout = typeof this.waitForMcpConnections === "object" ? this.waitForMcpConnections.timeout : 1e4;
|
|
3777
3775
|
await this.mcp.waitForConnections({ timeout });
|
|
3778
3776
|
}
|
|
3779
|
-
const workspaceTools =
|
|
3777
|
+
const workspaceTools = createAITools({ workspace: this.workspace });
|
|
3780
3778
|
const fetchToolSet = this.fetchTools ? createFetchTools({
|
|
3781
3779
|
...this.fetchTools,
|
|
3782
3780
|
workspace: this.workspace,
|
|
@@ -4652,18 +4650,34 @@ var Think = class Think extends Agent {
|
|
|
4652
4650
|
const { createChunkSnapshot } = await import("./hook-proxy-DY2sBNa0.js");
|
|
4653
4651
|
await this._dispatchExtensionObservation("onChunk", createChunkSnapshot(event));
|
|
4654
4652
|
}
|
|
4653
|
+
/**
|
|
4654
|
+
* Hand out an RPC stub to this agent's Workspace. `getWorkspace(stub)`
|
|
4655
|
+
* from `@cloudflare/computer` calls it to reach the Workspace from
|
|
4656
|
+
* another Worker or Durable Object, and the Worker shell backend calls it
|
|
4657
|
+
* so its isolate can reach back into the Workspace.
|
|
4658
|
+
*
|
|
4659
|
+
* Only a Workspace this agent owns can hand out a stub; a client for
|
|
4660
|
+
* another object's Workspace cannot.
|
|
4661
|
+
*/
|
|
4662
|
+
async __getWorkspaceStub() {
|
|
4663
|
+
await this.__unsafe_ensureInitialized();
|
|
4664
|
+
const workspace = this.workspace;
|
|
4665
|
+
if (!isLocalWorkspace(workspace)) throw new Error("[Think] This agent's workspace belongs to another Durable Object, so it cannot hand out a Workspace stub.");
|
|
4666
|
+
await workspace.ready();
|
|
4667
|
+
return workspace.stub();
|
|
4668
|
+
}
|
|
4655
4669
|
async _hostReadFile(path) {
|
|
4656
4670
|
await this.__unsafe_ensureInitialized();
|
|
4657
|
-
return
|
|
4671
|
+
return new WorkspaceFiles(this.workspace).readText(resolveWorkspacePath(path));
|
|
4658
4672
|
}
|
|
4659
4673
|
async _hostWriteFile(path, content) {
|
|
4660
4674
|
await this.__unsafe_ensureInitialized();
|
|
4661
|
-
await this.workspace.
|
|
4675
|
+
await new WorkspaceFiles(this.workspace).write(resolveWorkspacePath(path), content);
|
|
4662
4676
|
}
|
|
4663
4677
|
async _hostDeleteFile(path) {
|
|
4664
4678
|
await this.__unsafe_ensureInitialized();
|
|
4665
4679
|
try {
|
|
4666
|
-
await this.workspace.
|
|
4680
|
+
await new WorkspaceFiles(this.workspace).remove(resolveWorkspacePath(path));
|
|
4667
4681
|
return true;
|
|
4668
4682
|
} catch {
|
|
4669
4683
|
return false;
|
|
@@ -4671,11 +4685,11 @@ var Think = class Think extends Agent {
|
|
|
4671
4685
|
}
|
|
4672
4686
|
async _hostListFiles(dir) {
|
|
4673
4687
|
await this.__unsafe_ensureInitialized();
|
|
4674
|
-
return (await this.workspace.
|
|
4688
|
+
return (await new WorkspaceFiles(this.workspace).list(resolveWorkspacePath(dir))).map((e) => ({
|
|
4675
4689
|
name: e.name,
|
|
4676
4690
|
type: e.type,
|
|
4677
|
-
size: e.size
|
|
4678
|
-
path: e.path
|
|
4691
|
+
size: e.size,
|
|
4692
|
+
path: e.path
|
|
4679
4693
|
}));
|
|
4680
4694
|
}
|
|
4681
4695
|
async _hostGetContext(label) {
|
|
@@ -9604,6 +9618,7 @@ var Think = class Think extends Agent {
|
|
|
9604
9618
|
isAwaitingClientInteraction: () => this.hasPendingInteraction(),
|
|
9605
9619
|
listActiveIncidents: async () => (await listActiveChatRecoveryIncidents(this.ctx.storage)).map(({ incident }) => incident),
|
|
9606
9620
|
putIncident: (key, incident) => this.ctx.storage.put(key, incident),
|
|
9621
|
+
syncStorage: () => this.ctx.storage.sync(),
|
|
9607
9622
|
deleteIncident: async (key) => {
|
|
9608
9623
|
await this.ctx.storage.delete(key);
|
|
9609
9624
|
},
|
|
@@ -9707,7 +9722,8 @@ var Think = class Think extends Agent {
|
|
|
9707
9722
|
requestId: input.requestId,
|
|
9708
9723
|
recoveryRootRequestId,
|
|
9709
9724
|
latestUserMessageId,
|
|
9710
|
-
recoveryKind
|
|
9725
|
+
recoveryKind,
|
|
9726
|
+
trigger: "stalled"
|
|
9711
9727
|
});
|
|
9712
9728
|
const partialText = input.partialParts.filter((p) => p.type === "text").map((p) => p.text).join("");
|
|
9713
9729
|
if (exhausted) {
|
|
@@ -10176,49 +10192,15 @@ var Think = class Think extends Agent {
|
|
|
10176
10192
|
return this._exhaustRecoveryGiveUp(callback, data, "stable_timeout");
|
|
10177
10193
|
}
|
|
10178
10194
|
/**
|
|
10179
|
-
* Apply the tight OOM-retry budget to a recovery error (#1825). Invoked from
|
|
10180
|
-
* `_handleRecoveryCallbackError`, i.e. for an OOM that is *thrown* out of a
|
|
10181
|
-
* recovery turn (typically from recovery bookkeeping or storage/SQL ops that
|
|
10182
|
-
* reject with the memory-limit-reset message after an isolate reset). An OOM
|
|
10183
|
-
* that surfaces as a returned `error` result means `continueLastTurn` already
|
|
10184
|
-
* terminalized the turn (client error frame + `onError`), so it is NOT routed
|
|
10185
|
-
* here — re-driving a terminalized turn would be wasteful and risk a second
|
|
10186
|
-
* terminal signal. `error` may be an Error or a wrapper with a `cause` chain.
|
|
10187
|
-
*
|
|
10188
|
-
* The reliable terminator is the begin-path (`evaluateChatRecoveryIncident`),
|
|
10189
|
-
* which seals once `oomAttempts` exceeds the budget; that runs before the
|
|
10190
|
-
* memory-heavy turn, in the low-memory window where writes succeed. This
|
|
10191
|
-
* method's job is to persist `oomAttempts` (small writes) so the begin path
|
|
10192
|
-
* can act on it, and to schedule a delayed re-run while under budget.
|
|
10193
|
-
*
|
|
10194
|
-
* Returns `true` when the error was an OOM and this method owns the outcome:
|
|
10195
|
-
* - under budget → a delayed re-run was scheduled (best-effort: a transient
|
|
10196
|
-
* spike may clear);
|
|
10197
|
-
* - over budget (or untrackable, or the bookkeeping itself OOMed) →
|
|
10198
|
-
* terminalized via the give-up path with `reason="out_of_memory"`.
|
|
10199
|
-
* Returns `false` for non-OOM errors so the caller proceeds normally.
|
|
10200
|
-
*/
|
|
10201
|
-
async _handleRecoveryOom(callback, data, error) {
|
|
10202
|
-
if (!isDurableObjectMemoryLimitReset(error)) return false;
|
|
10203
|
-
let decision = "exhausted";
|
|
10204
|
-
try {
|
|
10205
|
-
decision = await this._chatRecoveryEngine().recordOomAndDecide({
|
|
10206
|
-
incidentId: data?.incidentId,
|
|
10207
|
-
callback,
|
|
10208
|
-
data,
|
|
10209
|
-
maxOomRetries: this._resolveChatRecoveryConfig().maxOomRetries
|
|
10210
|
-
});
|
|
10211
|
-
} catch (bookkeepingError) {
|
|
10212
|
-
console.error("[Think] failed to record OOM recovery attempt; terminalizing", bookkeepingError);
|
|
10213
|
-
decision = "exhausted";
|
|
10214
|
-
}
|
|
10215
|
-
if (decision === "exhausted") await this._exhaustRecoveryGiveUp(callback, data, "out_of_memory");
|
|
10216
|
-
return true;
|
|
10217
|
-
}
|
|
10218
|
-
/**
|
|
10219
10195
|
* Handle an error thrown by `_chatRecoveryContinue` / `_chatRecoveryRetry`
|
|
10220
10196
|
* after the incident was opened.
|
|
10221
10197
|
*
|
|
10198
|
+
* - A Durable Object memory-limit reset is re-thrown with no bookkeeping.
|
|
10199
|
+
* The isolate is condemned: its storage calls reject and unconfirmed
|
|
10200
|
+
* writes are discarded, so nothing written here would survive (#2613).
|
|
10201
|
+
* The attempt's `attemptsInFlight` entry stays behind, and the next
|
|
10202
|
+
* attempt counts it against `maxInterruptedAttempts` before running
|
|
10203
|
+
* anything heavy.
|
|
10222
10204
|
* - A platform transient (`isPlatformTransientError` from `agents` — a
|
|
10223
10205
|
* deploy code-update reset / script supersede, a `retryable`-flagged
|
|
10224
10206
|
* platform error, or "Network connection lost.", looking through wrappers
|
|
@@ -10243,7 +10225,7 @@ var Think = class Think extends Agent {
|
|
|
10243
10225
|
* send something new).
|
|
10244
10226
|
*/
|
|
10245
10227
|
async _handleRecoveryCallbackError(callback, data, error) {
|
|
10246
|
-
if (
|
|
10228
|
+
if (isDurableObjectMemoryLimitReset(error)) throw error;
|
|
10247
10229
|
if (isPlatformTransientError(error)) {
|
|
10248
10230
|
const message = error instanceof Error ? error.message : String(error);
|
|
10249
10231
|
const incidentId = data?.incidentId;
|
|
@@ -11304,6 +11286,6 @@ for (const method of [
|
|
|
11304
11286
|
Think.prototype.rejectExecution
|
|
11305
11287
|
]) callable()(method, void 0);
|
|
11306
11288
|
//#endregion
|
|
11307
|
-
export { ThinkSession as Session, ThinkSession, Think,
|
|
11289
|
+
export { ThinkSession as Session, ThinkSession, Think, action, defaultContextOverflowClassifier, isAction, messengerChannel, skills };
|
|
11308
11290
|
|
|
11309
11291
|
//# sourceMappingURL=think.js.map
|