@cloudflare/think 0.22.0 → 0.23.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 +67 -103
- package/dist/extensions/index.d.ts +4 -14
- package/dist/extensions/index.js +1 -14
- package/dist/extensions/index.js.map +1 -1
- package/dist/{index-BFK9bpzz.d.ts → index-DDnny6kt.d.ts} +188 -72
- package/dist/{manager-dOcdCX4u.d.ts → manager-rze95KCk.d.ts} +1 -2
- package/dist/messengers/index.d.ts +1 -1
- package/dist/messengers/telegram.d.ts +1 -1
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/think.d.ts +2 -2
- package/dist/think.js +84 -71
- package/dist/think.js.map +1 -1
- package/dist/tools/extensions.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/index.md +97 -92
- package/docs/lifecycle-hooks.md +13 -13
- package/docs/multi-chat.md +7 -6
- package/docs/tools.md +2 -2
- package/package.json +3 -3
package/dist/think.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
1
2
|
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, r as _assertClassBrand, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-DwGJfC3w.js";
|
|
2
3
|
import { n as sanitizeName, r as _classPrivateMethodInitSpec, t as ExtensionManager } from "./manager-BubfmA3q.js";
|
|
3
4
|
import { n as WorkspaceFiles, r as resolveWorkspacePath, t as createFetchTools } from "./fetch-DO3uQ9py.js";
|
|
@@ -11,14 +12,38 @@ import { wrapAISDK } from "agents/observability/ai";
|
|
|
11
12
|
import { createWorkersAI } from "workers-ai-provider";
|
|
12
13
|
import { anthropic } from "workers-ai-provider/anthropic";
|
|
13
14
|
import { openai } from "workers-ai-provider/openai";
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
15
|
+
import { DEFAULT_WORKSPACE_SKILLS_ROOT, InvalidSkillResourcePathError, SkillParseError, SkillResourceNotFoundError, SkillSourceError, UnknownSkillError, formatSkill, formatSkillDiagnostic, formatSkillDiagnostic as formatSkillDiagnostic$1, fromManifest, isModelInvocable, loadSkillCatalog, loadSkillCatalog as loadSkillCatalog$1, manifest, parseSkill, parseSkillName, parseSkillResourcePath, r2, renderSkillResource, workspace } from "agents/skills";
|
|
16
|
+
import { runner } from "agents/skills/runner";
|
|
17
|
+
import { createSkillTools } from "agents/skills/tools/ai-sdk";
|
|
16
18
|
import { Agent, __DO_NOT_USE_WILL_BREAK__agentContext, __DO_NOT_USE_WILL_BREAK__withInvocationScope, callable, getCurrentAgent, isDurableObjectCodeUpdateReset, isDurableObjectMemoryLimitReset, isPlatformTransientError } from "agents";
|
|
17
19
|
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
20
|
import { Sessions, isCompactionMessage } from "agents/sessions";
|
|
19
21
|
import { AgentContextProvider, ContextBlocks } from "agents/context";
|
|
20
22
|
import { Workspace } from "@cloudflare/computer";
|
|
21
23
|
import { createAITools } from "@cloudflare/computer/tools/ai-sdk";
|
|
24
|
+
//#region src/skills.ts
|
|
25
|
+
var skills_exports = /* @__PURE__ */ __exportAll({
|
|
26
|
+
DEFAULT_WORKSPACE_SKILLS_ROOT: () => DEFAULT_WORKSPACE_SKILLS_ROOT,
|
|
27
|
+
InvalidSkillResourcePathError: () => InvalidSkillResourcePathError,
|
|
28
|
+
SkillParseError: () => SkillParseError,
|
|
29
|
+
SkillResourceNotFoundError: () => SkillResourceNotFoundError,
|
|
30
|
+
SkillSourceError: () => SkillSourceError,
|
|
31
|
+
UnknownSkillError: () => UnknownSkillError,
|
|
32
|
+
formatSkill: () => formatSkill,
|
|
33
|
+
formatSkillDiagnostic: () => formatSkillDiagnostic$1,
|
|
34
|
+
fromManifest: () => fromManifest,
|
|
35
|
+
isModelInvocable: () => isModelInvocable,
|
|
36
|
+
loadSkillCatalog: () => loadSkillCatalog$1,
|
|
37
|
+
manifest: () => manifest,
|
|
38
|
+
parseSkill: () => parseSkill,
|
|
39
|
+
parseSkillName: () => parseSkillName,
|
|
40
|
+
parseSkillResourcePath: () => parseSkillResourcePath,
|
|
41
|
+
r2: () => r2,
|
|
42
|
+
renderSkillResource: () => renderSkillResource,
|
|
43
|
+
runner: () => runner,
|
|
44
|
+
workspace: () => workspace
|
|
45
|
+
});
|
|
46
|
+
//#endregion
|
|
22
47
|
//#region src/session.ts
|
|
23
48
|
var _handle = /* @__PURE__ */ new WeakMap();
|
|
24
49
|
var _context = /* @__PURE__ */ new WeakMap();
|
|
@@ -505,7 +530,7 @@ function resolveChannels(configured, messengers) {
|
|
|
505
530
|
* Configuration overrides:
|
|
506
531
|
* - getModel() — return a model id string (resolved via the
|
|
507
532
|
* built-in workers-ai-provider) or a LanguageModel
|
|
508
|
-
* - getSystemPrompt() —
|
|
533
|
+
* - getSystemPrompt() — instructions at the top of the system prompt
|
|
509
534
|
* - getTools() — return the ToolSet for the agentic loop
|
|
510
535
|
* - maxSteps — max tool-call rounds per turn (default: 10)
|
|
511
536
|
* - configureSession() — compaction and search policy
|
|
@@ -765,6 +790,8 @@ function keepResolvedPauses(incoming, serverMessages) {
|
|
|
765
790
|
function isLocalWorkspace(workspace) {
|
|
766
791
|
return "ready" in workspace && typeof workspace.ready === "function" && "stub" in workspace && typeof workspace.stub === "function";
|
|
767
792
|
}
|
|
793
|
+
/** Context block label for the skills catalog. */
|
|
794
|
+
const SKILLS_CONTEXT_LABEL = "think_skills";
|
|
768
795
|
const ACTION_PENDING_SWEEP_INTERVAL_MS = 3600 * 1e3;
|
|
769
796
|
const ACTION_PENDING_LAST_SWEPT_KEY = "cf_think_action_pending_approvals:last_swept_at";
|
|
770
797
|
/** Prefix for durable-pause action execution ids (vs codemode execution ids). */
|
|
@@ -1560,8 +1587,8 @@ var Think = class Think extends Agent {
|
|
|
1560
1587
|
this.waitForMcpConnections = false;
|
|
1561
1588
|
this.storeMessages = false;
|
|
1562
1589
|
this.storeTools = false;
|
|
1563
|
-
this.
|
|
1564
|
-
this.
|
|
1590
|
+
this._skillSources = [];
|
|
1591
|
+
this._skillCatalog = null;
|
|
1565
1592
|
this._loggedSkillWarnings = /* @__PURE__ */ new Set();
|
|
1566
1593
|
this._loggedProtocolWarnings = /* @__PURE__ */ new Set();
|
|
1567
1594
|
this.messageConcurrency = "queue";
|
|
@@ -2466,9 +2493,11 @@ var Think = class Think extends Agent {
|
|
|
2466
2493
|
}) : this._defaultProvider(model, gateway && { gateway });
|
|
2467
2494
|
}
|
|
2468
2495
|
/**
|
|
2469
|
-
* Return the
|
|
2470
|
-
*
|
|
2471
|
-
* always
|
|
2496
|
+
* Return the instructions at the top of the system prompt.
|
|
2497
|
+
*
|
|
2498
|
+
* An override always comes first, followed by the context blocks from
|
|
2499
|
+
* `configureContext()`, skills, and extensions. Think's default text is
|
|
2500
|
+
* used only when the agent overrides nothing and has no context blocks.
|
|
2472
2501
|
*/
|
|
2473
2502
|
getSystemPrompt() {
|
|
2474
2503
|
return [
|
|
@@ -2479,6 +2508,18 @@ var Think = class Think extends Agent {
|
|
|
2479
2508
|
"Be direct and useful in your final response: summarize the outcome, mention important files or commands, and call out real blockers or risks."
|
|
2480
2509
|
].join("\n\n");
|
|
2481
2510
|
}
|
|
2511
|
+
/**
|
|
2512
|
+
* The base system prompt for a turn: an overridden `getSystemPrompt()`,
|
|
2513
|
+
* then the frozen context blocks. Think's default `getSystemPrompt()` is
|
|
2514
|
+
* only a fallback for an agent with no context blocks.
|
|
2515
|
+
*
|
|
2516
|
+
* @internal Exposed to subclasses for tests.
|
|
2517
|
+
*/
|
|
2518
|
+
async _buildBaseSystemPrompt() {
|
|
2519
|
+
const blocks = await this.context.freezeSystemPrompt();
|
|
2520
|
+
if (!isMethodOverridden(this, "getSystemPrompt")) return blocks || this.getSystemPrompt();
|
|
2521
|
+
return [this.getSystemPrompt(), blocks].filter((part) => part.trim().length > 0).join("\n\n");
|
|
2522
|
+
}
|
|
2482
2523
|
/** Return the tools available to the assistant. */
|
|
2483
2524
|
getTools() {
|
|
2484
2525
|
return {};
|
|
@@ -3083,14 +3124,20 @@ var Think = class Think extends Agent {
|
|
|
3083
3124
|
/**
|
|
3084
3125
|
* Return Agent Skills sources for this Think agent.
|
|
3085
3126
|
*
|
|
3086
|
-
*
|
|
3127
|
+
* A skill is a directory with a `SKILL.md` file, as defined by
|
|
3128
|
+
* https://agentskills.io. Keep skills as files in the agent's Workspace
|
|
3129
|
+
* and they become available as soon as they are written:
|
|
3087
3130
|
*
|
|
3088
3131
|
* ```typescript
|
|
3089
|
-
*
|
|
3132
|
+
* getSkills() {
|
|
3133
|
+
* return [skills.workspace(this.workspace)]; // /workspace/.agents/skills
|
|
3134
|
+
* }
|
|
3090
3135
|
* ```
|
|
3091
3136
|
*
|
|
3092
|
-
*
|
|
3093
|
-
*
|
|
3137
|
+
* `skills.r2()` reads skills from an R2 bucket and `skills.manifest()`
|
|
3138
|
+
* defines them in code. Sources are applied in order; the first source to
|
|
3139
|
+
* provide a skill name wins, and later collisions are skipped with a
|
|
3140
|
+
* logged warning. Sources are listed again before every turn.
|
|
3094
3141
|
*/
|
|
3095
3142
|
getSkills() {
|
|
3096
3143
|
return [];
|
|
@@ -3099,67 +3146,40 @@ var Think = class Think extends Agent {
|
|
|
3099
3146
|
try {
|
|
3100
3147
|
const sources = await this.getSkills();
|
|
3101
3148
|
if (sources.length === 0) return;
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
if (!this._loggedSkillWarnings.has(warning)) {
|
|
3105
|
-
this._loggedSkillWarnings.add(warning);
|
|
3106
|
-
console.warn(`[think] ${warning}`);
|
|
3107
|
-
}
|
|
3108
|
-
}
|
|
3109
|
-
const registry = new SkillRegistry(sources, this.getSkillScriptRunner());
|
|
3110
|
-
await registry.load();
|
|
3111
|
-
this._logSkillWarnings(registry);
|
|
3112
|
-
this._skillRegistry = registry;
|
|
3113
|
-
await this._configureSkillWorkspace(registry);
|
|
3149
|
+
this._skillSources = sources;
|
|
3150
|
+
await this._loadSkillCatalog();
|
|
3114
3151
|
await this.context.addBlock({
|
|
3115
|
-
label:
|
|
3152
|
+
label: SKILLS_CONTEXT_LABEL,
|
|
3116
3153
|
description: "Think skills: available skill catalog",
|
|
3117
|
-
|
|
3154
|
+
whenChanged: "remind",
|
|
3155
|
+
provider: { get: async () => this._skillCatalog?.prompt() ?? "No skills are available." }
|
|
3118
3156
|
});
|
|
3119
|
-
if ((this._skillsFingerprint ??= this._configGet("skillsFingerprint") ?? null) !== registry.fingerprint) {
|
|
3120
|
-
await this.context.refreshSystemPrompt();
|
|
3121
|
-
this._configSet("skillsFingerprint", registry.fingerprint);
|
|
3122
|
-
this._skillsFingerprint = registry.fingerprint;
|
|
3123
|
-
}
|
|
3124
3157
|
} catch (error) {
|
|
3125
3158
|
console.warn(`[think] Failed to initialize skills; continuing without them: ${error instanceof Error ? error.message : String(error)}`);
|
|
3126
3159
|
}
|
|
3127
3160
|
}
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
const
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
await registry.useWorkspace(workspace, this.skillWorkspace);
|
|
3135
|
-
return;
|
|
3136
|
-
}
|
|
3137
|
-
const seeded = await registry.seedWorkspace(workspace, this.skillWorkspace);
|
|
3138
|
-
for (const warning of seeded.warnings) {
|
|
3139
|
-
if (this._loggedSkillWarnings.has(warning)) continue;
|
|
3140
|
-
this._loggedSkillWarnings.add(warning);
|
|
3141
|
-
console.warn(`[think] ${warning}`);
|
|
3142
|
-
}
|
|
3143
|
-
if (seeded.skipped === 0) this._configSet(key, registry.fingerprint);
|
|
3144
|
-
} catch (error) {
|
|
3145
|
-
console.warn(`[think] Failed to seed skills into the workspace; source-backed skill tools remain available: ${error instanceof Error ? error.message : String(error)}`);
|
|
3146
|
-
}
|
|
3161
|
+
/** Load the catalog from every source and log new diagnostics. */
|
|
3162
|
+
async _loadSkillCatalog() {
|
|
3163
|
+
const catalog = await loadSkillCatalog(this._skillSources, { previous: this._skillCatalog ?? void 0 });
|
|
3164
|
+
for (const diagnostic of catalog.diagnostics) this._warnSkillsOnce(formatSkillDiagnostic(diagnostic));
|
|
3165
|
+
this._skillCatalog = catalog;
|
|
3166
|
+
return catalog;
|
|
3147
3167
|
}
|
|
3148
3168
|
/**
|
|
3149
|
-
* Log
|
|
3150
|
-
*
|
|
3151
|
-
* the same warning is not repeated on every turn.
|
|
3169
|
+
* Log a skills warning once per object lifetime, so a new problem after a
|
|
3170
|
+
* deploy still surfaces while the same warning is not repeated every turn.
|
|
3152
3171
|
*/
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
console.warn(`[think] ${warning}`);
|
|
3158
|
-
}
|
|
3172
|
+
_warnSkillsOnce(warning) {
|
|
3173
|
+
if (this._loggedSkillWarnings.has(warning)) return;
|
|
3174
|
+
this._loggedSkillWarnings.add(warning);
|
|
3175
|
+
console.warn(`[think] ${warning}`);
|
|
3159
3176
|
}
|
|
3160
3177
|
/**
|
|
3161
3178
|
* Return an optional runner that enables the `run_skill_script` tool.
|
|
3162
3179
|
*
|
|
3180
|
+
* Prefer keeping skills in the Workspace and letting the agent run their
|
|
3181
|
+
* scripts with its shell tools.
|
|
3182
|
+
*
|
|
3163
3183
|
* @experimental Skill script execution is experimental and may change
|
|
3164
3184
|
* before stabilizing.
|
|
3165
3185
|
*/
|
|
@@ -3167,16 +3187,9 @@ var Think = class Think extends Agent {
|
|
|
3167
3187
|
return null;
|
|
3168
3188
|
}
|
|
3169
3189
|
async _refreshSkillsIfChanged() {
|
|
3170
|
-
if (!this.
|
|
3190
|
+
if (!this._skillCatalog) return;
|
|
3171
3191
|
try {
|
|
3172
|
-
await this.
|
|
3173
|
-
this._logSkillWarnings(this._skillRegistry);
|
|
3174
|
-
await this._configureSkillWorkspace(this._skillRegistry);
|
|
3175
|
-
if ((this._skillsFingerprint ??= this._configGet("skillsFingerprint") ?? null) !== this._skillRegistry.fingerprint) {
|
|
3176
|
-
await this.context.refreshSystemPrompt();
|
|
3177
|
-
this._configSet("skillsFingerprint", this._skillRegistry.fingerprint);
|
|
3178
|
-
this._skillsFingerprint = this._skillRegistry.fingerprint;
|
|
3179
|
-
}
|
|
3192
|
+
await this._loadSkillCatalog();
|
|
3180
3193
|
} catch (error) {
|
|
3181
3194
|
console.warn(`[think] Failed to refresh skills; using last known catalog: ${error instanceof Error ? error.message : String(error)}`);
|
|
3182
3195
|
}
|
|
@@ -3787,7 +3800,7 @@ var Think = class Think extends Agent {
|
|
|
3787
3800
|
const extensionTools = this.extensionManager?.getTools() ?? {};
|
|
3788
3801
|
await this._refreshSkillsIfChanged();
|
|
3789
3802
|
const contextTools = await this.context.tools();
|
|
3790
|
-
const skillTools = this.
|
|
3803
|
+
const skillTools = this._skillCatalog ? createSkillTools(this._skillCatalog, { scriptRunner: this.getSkillScriptRunner() }) : {};
|
|
3791
3804
|
const clientToolSet = createToolsFromClientSchemas(input.clientTools, input.clientToolExecutor ? { execute: input.clientToolExecutor } : void 0);
|
|
3792
3805
|
let tools = {
|
|
3793
3806
|
...workspaceTools,
|
|
@@ -3804,7 +3817,7 @@ var Think = class Think extends Agent {
|
|
|
3804
3817
|
const channelDefinition = channelContext ? this._channels?.get(channelContext.channelId) : void 0;
|
|
3805
3818
|
if (channelDefinition?.tools) tools = channelDefinition.tools(tools);
|
|
3806
3819
|
const channelInstructions = channelDefinition?.instructions && channelContext ? typeof channelDefinition.instructions === "function" ? await channelDefinition.instructions(channelContext) : channelDefinition.instructions : void 0;
|
|
3807
|
-
const rawBaseSystem = await this.
|
|
3820
|
+
const rawBaseSystem = await this._buildBaseSystemPrompt();
|
|
3808
3821
|
const baseSystem = channelInstructions ? `${channelInstructions}\n\n${rawBaseSystem}` : rawBaseSystem;
|
|
3809
3822
|
const system = this._systemPromptForTurn(baseSystem, tools);
|
|
3810
3823
|
this._turnContextReminder = await this.context.reminder();
|
|
@@ -11286,6 +11299,6 @@ for (const method of [
|
|
|
11286
11299
|
Think.prototype.rejectExecution
|
|
11287
11300
|
]) callable()(method, void 0);
|
|
11288
11301
|
//#endregion
|
|
11289
|
-
export { ThinkSession as Session, ThinkSession, Think, action, defaultContextOverflowClassifier, isAction, messengerChannel, skills };
|
|
11302
|
+
export { ThinkSession as Session, ThinkSession, Think, action, defaultContextOverflowClassifier, isAction, messengerChannel, skills_exports as skills };
|
|
11290
11303
|
|
|
11291
11304
|
//# sourceMappingURL=think.js.map
|