@economic/agents 2.3.27 → 2.4.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/dist/index.d.mts +25 -2
- package/dist/index.mjs +55 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as JwtAuthConfig, t as routeAgentRequest } from "./route-agent-request-D2ll--nF.mjs";
|
|
2
2
|
import { Agent as Agent$1, Connection, ConnectionContext, SubAgentClass } from "agents";
|
|
3
3
|
import { ChatResponseResult, PrepareStepContext, Session, Think, ToolCallContext, ToolCallDecision, TurnConfig, TurnContext, skills } from "@cloudflare/think";
|
|
4
|
-
import { JSONValue, LanguageModel, Tool as Tool$1, UIMessage } from "ai";
|
|
4
|
+
import { JSONValue, LanguageModel, ModelMessage, Tool as Tool$1, UIMessage } from "ai";
|
|
5
5
|
import { createCompactFunction } from "agents/experimental/memory/utils";
|
|
6
6
|
import { SkillSource as SkillSource$1 } from "agents/skills";
|
|
7
7
|
|
|
@@ -34,6 +34,15 @@ type Tool<Context extends Record<string, unknown> = Record<string, unknown>, INP
|
|
|
34
34
|
declare function tool<Context extends Record<string, unknown> = Record<string, unknown>, INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any>(tool: Tool<Context, INPUT, OUTPUT>): Tool$1<INPUT, OUTPUT>;
|
|
35
35
|
//#endregion
|
|
36
36
|
//#region src/server/agents/Agent.d.ts
|
|
37
|
+
/** What the model would see on its next step — returned by {@link Agent.inspectTurn}. */
|
|
38
|
+
interface TurnSnapshot {
|
|
39
|
+
system: string;
|
|
40
|
+
tools: ToolSet;
|
|
41
|
+
activeTools: string[];
|
|
42
|
+
/** Tools provided by the framework (session/skill meta-tools, MCP), not the agent. */
|
|
43
|
+
frameworkToolNames: string[];
|
|
44
|
+
messages: ModelMessage[];
|
|
45
|
+
}
|
|
37
46
|
declare abstract class Agent<RequestContext extends Record<string, unknown> = Record<string, unknown>, UserContext extends Record<string, unknown> = Record<string, unknown>, State = unknown> extends Think<Cloudflare.Env & AgentEnv, State> {
|
|
38
47
|
protected agentType: AgentConnectionType;
|
|
39
48
|
protected clientIp?: string;
|
|
@@ -75,6 +84,19 @@ declare abstract class Agent<RequestContext extends Record<string, unknown> = Re
|
|
|
75
84
|
}>;
|
|
76
85
|
beforeToolCall(ctx: ToolCallContext): Promise<ToolCallDecision | void>;
|
|
77
86
|
getTools(): ToolSet;
|
|
87
|
+
/**
|
|
88
|
+
* Read-only: what the model would see on its next step for the given history
|
|
89
|
+
* — the assembled system prompt, the skill-gated toolset, and pruned
|
|
90
|
+
* messages. Runs no turn (nothing admitted, persisted, executed; no model
|
|
91
|
+
* call). Skill gating is derived from the history, so a history with an
|
|
92
|
+
* `activate_skill` call yields that skill's tools. For eval harnesses and
|
|
93
|
+
* prompt-preview tooling; call it inside the DO context.
|
|
94
|
+
*/
|
|
95
|
+
inspectTurn(input?: {
|
|
96
|
+
messages?: ModelMessage[];
|
|
97
|
+
requestContext?: RequestContext;
|
|
98
|
+
userContext?: UserContext;
|
|
99
|
+
}): Promise<TurnSnapshot>;
|
|
78
100
|
workspaceBash: boolean;
|
|
79
101
|
getSkillScriptRunner(): skills.SkillScriptRunner | null;
|
|
80
102
|
/**
|
|
@@ -82,6 +104,7 @@ declare abstract class Agent<RequestContext extends Record<string, unknown> = Re
|
|
|
82
104
|
* @returns The remote skills to be loaded from SKILLS_BUCKET.
|
|
83
105
|
*/
|
|
84
106
|
protected getRemoteSkills(): string[];
|
|
107
|
+
private _pruneTurnMessages;
|
|
85
108
|
private _getAuthorizedTools;
|
|
86
109
|
/**
|
|
87
110
|
* Wrap each tool's `execute` so it falls back to the current turn's tool
|
|
@@ -340,4 +363,4 @@ declare function skill<Context extends Record<string, unknown> = Record<string,
|
|
|
340
363
|
//#region src/server/index.d.ts
|
|
341
364
|
declare function getCurrentToolContext(): any;
|
|
342
365
|
//#endregion
|
|
343
|
-
export { Agent, type AgentConnectionStatus, type AgentConnectionType, type AgentEnv, Assistant, ChatAgent, type FacetStub, type LegacyChatStub, type LegacyMessageFeedback, type MigrationDeps, type Skill, type SkillSource, type Tool, type ToolContext, type ToolSet, getCurrentToolContext, migrateUserFromV1, routeAgentRequest, skill, tool };
|
|
366
|
+
export { Agent, type AgentConnectionStatus, type AgentConnectionType, type AgentEnv, Assistant, ChatAgent, type FacetStub, type LegacyChatStub, type LegacyMessageFeedback, type MigrationDeps, type Skill, type SkillSource, type Tool, type ToolContext, type ToolSet, type TurnSnapshot, getCurrentToolContext, migrateUserFromV1, routeAgentRequest, skill, tool };
|
package/dist/index.mjs
CHANGED
|
@@ -238,16 +238,7 @@ var Agent = class extends Think {
|
|
|
238
238
|
return {
|
|
239
239
|
system: await this.session.refreshSystemPrompt(),
|
|
240
240
|
model: this.getModel(this._toolContextForCurrentTurn),
|
|
241
|
-
messages:
|
|
242
|
-
messages: ctx.messages,
|
|
243
|
-
toolCalls: [{
|
|
244
|
-
type: "before-last-2-messages",
|
|
245
|
-
tools: []
|
|
246
|
-
}, {
|
|
247
|
-
type: "before-last-5-messages",
|
|
248
|
-
tools: ["activate_skill"]
|
|
249
|
-
}]
|
|
250
|
-
}),
|
|
241
|
+
messages: this._pruneTurnMessages(ctx.messages),
|
|
251
242
|
tools: this._withTurnContextFallback(tools),
|
|
252
243
|
activeTools,
|
|
253
244
|
experimental_transform: buildSourcesTransform(),
|
|
@@ -301,6 +292,48 @@ var Agent = class extends Think {
|
|
|
301
292
|
getTools() {
|
|
302
293
|
return {};
|
|
303
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Read-only: what the model would see on its next step for the given history
|
|
297
|
+
* — the assembled system prompt, the skill-gated toolset, and pruned
|
|
298
|
+
* messages. Runs no turn (nothing admitted, persisted, executed; no model
|
|
299
|
+
* call). Skill gating is derived from the history, so a history with an
|
|
300
|
+
* `activate_skill` call yields that skill's tools. For eval harnesses and
|
|
301
|
+
* prompt-preview tooling; call it inside the DO context.
|
|
302
|
+
*/
|
|
303
|
+
async inspectTurn(input = {}) {
|
|
304
|
+
const messages = input.messages ?? [];
|
|
305
|
+
await this.__unsafe_ensureInitialized();
|
|
306
|
+
const previousContext = this._toolContextForCurrentTurn;
|
|
307
|
+
this._toolContextForCurrentTurn = {
|
|
308
|
+
...input.requestContext ?? {},
|
|
309
|
+
_userContext: input.userContext
|
|
310
|
+
};
|
|
311
|
+
const previousAuthorizedTools = this._authorizedToolsForCurrentTurn;
|
|
312
|
+
try {
|
|
313
|
+
const system = await this.session.refreshSystemPrompt();
|
|
314
|
+
const think = this;
|
|
315
|
+
const frameworkTools = {
|
|
316
|
+
...await this.session.tools(),
|
|
317
|
+
...think._skillRegistry?.tools(),
|
|
318
|
+
...think.mcp?.getAITools?.()
|
|
319
|
+
};
|
|
320
|
+
const { tools, activeTools } = await this._getAuthorizedTools({
|
|
321
|
+
...this.getTools(),
|
|
322
|
+
...frameworkTools
|
|
323
|
+
}, this._getLastActivatedSkillName(messages));
|
|
324
|
+
const snapshotContext = this._toolContextForCurrentTurn;
|
|
325
|
+
return {
|
|
326
|
+
system,
|
|
327
|
+
tools: withFallbackToolContext(tools, () => snapshotContext),
|
|
328
|
+
activeTools,
|
|
329
|
+
frameworkToolNames: Object.keys(frameworkTools),
|
|
330
|
+
messages: this._pruneTurnMessages(messages)
|
|
331
|
+
};
|
|
332
|
+
} finally {
|
|
333
|
+
this._toolContextForCurrentTurn = previousContext;
|
|
334
|
+
this._authorizedToolsForCurrentTurn = previousAuthorizedTools;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
304
337
|
workspaceBash = false;
|
|
305
338
|
getSkillScriptRunner() {
|
|
306
339
|
if (!("LOADER" in this.env)) return null;
|
|
@@ -313,6 +346,18 @@ var Agent = class extends Think {
|
|
|
313
346
|
getRemoteSkills() {
|
|
314
347
|
return [];
|
|
315
348
|
}
|
|
349
|
+
_pruneTurnMessages(messages) {
|
|
350
|
+
return pruneMessages({
|
|
351
|
+
messages,
|
|
352
|
+
toolCalls: [{
|
|
353
|
+
type: "before-last-2-messages",
|
|
354
|
+
tools: []
|
|
355
|
+
}, {
|
|
356
|
+
type: "before-last-5-messages",
|
|
357
|
+
tools: ["activate_skill"]
|
|
358
|
+
}]
|
|
359
|
+
});
|
|
360
|
+
}
|
|
316
361
|
async _getAuthorizedTools(availableTools, activeSkillName) {
|
|
317
362
|
const tools = { ...availableTools };
|
|
318
363
|
const activeTools = Object.keys(tools);
|