zidane 1.8.1 → 2.1.1
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/{agent-8QBOx4_0.d.ts → agent-DFkSTVKm.d.ts} +637 -140
- package/dist/{chunk-SZA4FKW5.js → chunk-2EQT4EHD.js} +4 -3
- package/dist/{chunk-4N5ADW7A.js → chunk-AWDWJ2YJ.js} +596 -73
- package/dist/{chunk-3S377TS4.js → chunk-CDRXC7A7.js} +86 -38
- package/dist/chunk-DCYJYM3E.js +841 -0
- package/dist/chunk-HJUB63VE.js +22 -0
- package/dist/{chunk-TBC6MSVK.js → chunk-IJORSHFI.js} +97 -19
- package/dist/{chunk-FFFDQHMA.js → chunk-LNN5UTS2.js} +29 -0
- package/dist/chunk-MYWDHD7C.js +14 -0
- package/dist/{chunk-VG2E6YK3.js → chunk-PMCQOMV4.js} +4 -2
- package/dist/{chunk-EC7IRWVS.js → chunk-S3FCOMRI.js} +163 -26
- package/dist/{chunk-3RJOWJOJ.js → chunk-VUVLOTEY.js} +1 -1
- package/dist/contexts.js +1 -1
- package/dist/harnesses.d.ts +1 -2
- package/dist/harnesses.js +6 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +43 -11
- package/dist/mcp.d.ts +1 -2
- package/dist/mcp.js +3 -1
- package/dist/providers.d.ts +1 -2
- package/dist/providers.js +3 -3
- package/dist/session/sqlite.d.ts +1 -2
- package/dist/session.d.ts +1 -2
- package/dist/session.js +3 -3
- package/dist/skills-use-DWprxufr.d.ts +66 -0
- package/dist/skills.d.ts +215 -30
- package/dist/skills.js +21 -2
- package/dist/spawn-CW5GEK-T.d.ts +150 -0
- package/dist/tools.d.ts +3 -4
- package/dist/tools.js +11 -5
- package/dist/types.d.ts +2 -3
- package/dist/types.js +8 -2
- package/package.json +2 -2
- package/dist/chunk-4C6Y56CC.js +0 -390
- package/dist/chunk-CFLC2I7D.js +0 -8
- package/dist/glob-Bo0GAiKk.d.ts +0 -5
- package/dist/spawn-jjxPcNcH.d.ts +0 -99
- package/dist/types-CDI8Kmve.d.ts +0 -64
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Hookable } from 'hookable';
|
|
2
2
|
import { b as ExecutionContext, c as ExecutionHandle } from './types-BpvTmawk.js';
|
|
3
3
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
-
import { b as SkillsConfig, S as SkillConfig } from './types-CDI8Kmve.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Typed error classes for agent runs.
|
|
@@ -22,6 +21,13 @@ interface ClassifiedError {
|
|
|
22
21
|
providerCode?: string;
|
|
23
22
|
/** Optional human-readable message override. Falls back to the underlying error's message. */
|
|
24
23
|
message?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Hint that the error is transient and a retry with backoff is reasonable
|
|
26
|
+
* (e.g. 429, 5xx, truncated stream). Omitted when the provider can't decide;
|
|
27
|
+
* callers should default to "do not retry" when absent to avoid hammering
|
|
28
|
+
* terminal failures (auth, invalid request).
|
|
29
|
+
*/
|
|
30
|
+
retryable?: boolean;
|
|
25
31
|
}
|
|
26
32
|
interface TypedErrorOptions {
|
|
27
33
|
/** Provider name, always set (e.g. `anthropic`, `openrouter`) */
|
|
@@ -30,6 +36,8 @@ interface TypedErrorOptions {
|
|
|
30
36
|
providerCode?: string;
|
|
31
37
|
/** Original error from the provider SDK/HTTP layer */
|
|
32
38
|
cause?: unknown;
|
|
39
|
+
/** See {@link ClassifiedError.retryable}. */
|
|
40
|
+
retryable?: boolean;
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* Thrown when the model or provider signals that the context window was exceeded.
|
|
@@ -49,6 +57,12 @@ declare class AgentProviderError extends Error {
|
|
|
49
57
|
readonly code: "provider_error";
|
|
50
58
|
readonly provider: string;
|
|
51
59
|
readonly providerCode?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether a retry with backoff is likely to succeed. See
|
|
62
|
+
* {@link ClassifiedError.retryable}. Absent when the provider did not
|
|
63
|
+
* classify the error — callers should treat absent as "don't retry".
|
|
64
|
+
*/
|
|
65
|
+
readonly retryable?: boolean;
|
|
52
66
|
constructor(message: string, options: TypedErrorOptions);
|
|
53
67
|
}
|
|
54
68
|
/**
|
|
@@ -60,6 +74,32 @@ declare class AgentAbortedError extends Error {
|
|
|
60
74
|
cause?: unknown;
|
|
61
75
|
});
|
|
62
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Thrown (well — constructed; attach via the `tool:gate` block signal) when the
|
|
79
|
+
* union of `allowed-tools` across active skills does not permit a tool call.
|
|
80
|
+
*
|
|
81
|
+
* Produced by the allowed-tools middleware registered on `tool:gate` /
|
|
82
|
+
* `mcp:tool:gate`. The gate's `block = true` + `reason` carry the same message
|
|
83
|
+
* so consumers that don't look at this typed error still get a useful string.
|
|
84
|
+
*/
|
|
85
|
+
declare class AgentToolNotAllowedError extends Error {
|
|
86
|
+
readonly code: "tool_not_allowed";
|
|
87
|
+
/** Canonical tool name the agent tried to call. */
|
|
88
|
+
readonly toolName: string;
|
|
89
|
+
/** Aliased / wire name the LLM saw. */
|
|
90
|
+
readonly displayName: string;
|
|
91
|
+
/** Flattened union of `allowedTools` patterns across active skills. */
|
|
92
|
+
readonly allowedUnion: readonly string[];
|
|
93
|
+
/** Names of the skills currently active when the block fired. */
|
|
94
|
+
readonly activeSkills: readonly string[];
|
|
95
|
+
constructor(options: {
|
|
96
|
+
toolName: string;
|
|
97
|
+
displayName: string;
|
|
98
|
+
allowedUnion: readonly string[];
|
|
99
|
+
activeSkills: readonly string[];
|
|
100
|
+
cause?: unknown;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
63
103
|
/**
|
|
64
104
|
* Regex patterns matching common "context window exceeded" messages across providers.
|
|
65
105
|
*
|
|
@@ -91,8 +131,24 @@ interface McpServerConfig {
|
|
|
91
131
|
command?: string;
|
|
92
132
|
/** For stdio: command arguments */
|
|
93
133
|
args?: string[];
|
|
94
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* For stdio: environment variables to pass to the server process.
|
|
136
|
+
*
|
|
137
|
+
* Merged on top of the MCP SDK's default inherited environment — a safety
|
|
138
|
+
* whitelist (`PATH`, `HOME`, `LANG`, `SHELL`, `USER` on POSIX; `APPDATA`,
|
|
139
|
+
* `PATH`, ... on Win32). Setting this to `{}` no longer strips `PATH` from
|
|
140
|
+
* the child process. Set {@link McpServerConfig.strictEnv} to `true` to
|
|
141
|
+
* pass `env` verbatim with no inherited defaults.
|
|
142
|
+
*/
|
|
95
143
|
env?: Record<string, string>;
|
|
144
|
+
/**
|
|
145
|
+
* When true, {@link McpServerConfig.env} is passed verbatim to the spawned
|
|
146
|
+
* process — the MCP SDK's default inherited environment (`PATH`, `HOME`, ...)
|
|
147
|
+
* is NOT merged in. Most consumers should leave this off; the default merge
|
|
148
|
+
* prevents `spawn ENOENT` when a stdio server declares an `env` without
|
|
149
|
+
* restating `PATH`.
|
|
150
|
+
*/
|
|
151
|
+
strictEnv?: boolean;
|
|
96
152
|
/** For sse/streamable-http: server URL */
|
|
97
153
|
url?: string;
|
|
98
154
|
/** Optional headers for HTTP transports */
|
|
@@ -156,6 +212,38 @@ interface PromptDocumentPart {
|
|
|
156
212
|
/** Optional display name used in attachment headers */
|
|
157
213
|
name?: string;
|
|
158
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* A single block of structured tool-result content.
|
|
217
|
+
*
|
|
218
|
+
* MCP servers can return a mix of text, image, resource, and audio blocks. Tools
|
|
219
|
+
* return `string` for the common text-only case or `ToolResultContent[]` when they
|
|
220
|
+
* need to preserve non-text content (e.g. screenshots from a browser MCP).
|
|
221
|
+
*
|
|
222
|
+
* Providers that support native multi-part tool results (Anthropic, OpenAI Codex via
|
|
223
|
+
* pi-ai) route image blocks into their wire format verbatim; OpenAI-compat providers
|
|
224
|
+
* route them via a companion-user-message fallback when the underlying model/endpoint
|
|
225
|
+
* does not accept images inside tool-role messages.
|
|
226
|
+
*/
|
|
227
|
+
type ToolResultContent = ToolResultTextContent | ToolResultImageContent;
|
|
228
|
+
interface ToolResultTextContent {
|
|
229
|
+
type: 'text';
|
|
230
|
+
text: string;
|
|
231
|
+
}
|
|
232
|
+
interface ToolResultImageContent {
|
|
233
|
+
type: 'image';
|
|
234
|
+
/** IANA media type (e.g. `image/png`, `image/jpeg`) */
|
|
235
|
+
mediaType: string;
|
|
236
|
+
/** Base64-encoded payload */
|
|
237
|
+
data: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Lossy flattener — converts `ToolResultContent[]` (or a plain string) to a single
|
|
241
|
+
* string. Image blocks are replaced with `[image: <media> — <n> b64 bytes]` markers.
|
|
242
|
+
*
|
|
243
|
+
* Use at UI boundaries where a string is required; providers that understand
|
|
244
|
+
* structured content should route the array through without flattening.
|
|
245
|
+
*/
|
|
246
|
+
declare function toolResultToText(content: string | ToolResultContent[]): string;
|
|
159
247
|
type SessionContentBlock = {
|
|
160
248
|
type: 'text';
|
|
161
249
|
text: string;
|
|
@@ -171,7 +259,11 @@ type SessionContentBlock = {
|
|
|
171
259
|
} | {
|
|
172
260
|
type: 'tool_result';
|
|
173
261
|
callId: string;
|
|
174
|
-
|
|
262
|
+
/**
|
|
263
|
+
* Tool output — either a plain string (text-only, the common case) or a structured
|
|
264
|
+
* array of content blocks (text + image for multimodal tools such as screenshots).
|
|
265
|
+
*/
|
|
266
|
+
output: string | ToolResultContent[];
|
|
175
267
|
isError?: boolean;
|
|
176
268
|
} | {
|
|
177
269
|
type: 'thinking';
|
|
@@ -229,6 +321,18 @@ interface AgentRunOptions {
|
|
|
229
321
|
* Accepts either a single handler or an array (all handlers register).
|
|
230
322
|
*/
|
|
231
323
|
hooks?: RunHookMap;
|
|
324
|
+
/**
|
|
325
|
+
* Parent run id. Populated automatically by the `spawn` tool when the child
|
|
326
|
+
* shares the parent's session; recorded on the resulting `SessionRun` so the
|
|
327
|
+
* parent↔child run tree can be reconstructed from a persisted session.
|
|
328
|
+
*/
|
|
329
|
+
parentRunId?: string;
|
|
330
|
+
/**
|
|
331
|
+
* Zero-based subagent depth. 0 = top-level `agent.run()`, 1 = first-level
|
|
332
|
+
* child spawned by a parent agent, and so on. Used by the spawn tool to
|
|
333
|
+
* enforce `maxDepth` and to stamp `child:*` forwarded hook payloads.
|
|
334
|
+
*/
|
|
335
|
+
depth?: number;
|
|
232
336
|
}
|
|
233
337
|
/** Reason the provider gave for stopping the turn */
|
|
234
338
|
type TurnFinishReason = 'stop' | 'tool-calls' | 'length' | 'content-filter' | 'error' | 'other';
|
|
@@ -279,6 +383,24 @@ interface ChildRunStats {
|
|
|
279
383
|
id: string;
|
|
280
384
|
task: string;
|
|
281
385
|
stats: AgentStats;
|
|
386
|
+
/**
|
|
387
|
+
* Subagent depth when this child ran. 1 = direct child of the top-level
|
|
388
|
+
* agent, 2 = grandchild, etc. Useful for telemetry that wants to group
|
|
389
|
+
* runs by depth.
|
|
390
|
+
*/
|
|
391
|
+
depth?: number;
|
|
392
|
+
/**
|
|
393
|
+
* Terminal state of the child run. `'completed'` is the default. Exposed so
|
|
394
|
+
* a parent reading `stats.children` can distinguish aborted/timed-out
|
|
395
|
+
* children without re-parsing the returned string.
|
|
396
|
+
*/
|
|
397
|
+
status?: 'completed' | 'aborted' | 'timeout' | 'error';
|
|
398
|
+
/**
|
|
399
|
+
* Final structured output when the child was run with `behavior.schema`.
|
|
400
|
+
* Mirrors `AgentStats.output` but is surfaced here so the parent can read
|
|
401
|
+
* it without peeking at the nested `stats` bag.
|
|
402
|
+
*/
|
|
403
|
+
output?: Record<string, unknown>;
|
|
282
404
|
}
|
|
283
405
|
/**
|
|
284
406
|
* Base context for tool execution hooks.
|
|
@@ -329,6 +451,12 @@ interface SessionHookContext {
|
|
|
329
451
|
interface SpawnHookContext {
|
|
330
452
|
id: string;
|
|
331
453
|
task: string;
|
|
454
|
+
/**
|
|
455
|
+
* Subagent depth for the spawn. 1 = direct child of the top-level agent.
|
|
456
|
+
* Present on spawn:before/complete/error. Absent for grandchild spawns that
|
|
457
|
+
* bubble through `child:*` events (which carry their own `depth`).
|
|
458
|
+
*/
|
|
459
|
+
depth?: number;
|
|
332
460
|
}
|
|
333
461
|
/** Context for stream hooks */
|
|
334
462
|
interface StreamHookContext {
|
|
@@ -370,6 +498,12 @@ declare function anthropic(anthropicParams?: AnthropicParams): Provider;
|
|
|
370
498
|
interface CerebrasParams {
|
|
371
499
|
apiKey?: string;
|
|
372
500
|
defaultModel?: string;
|
|
501
|
+
/**
|
|
502
|
+
* Provider capability flags. Cerebras currently serves text-only OSS models
|
|
503
|
+
* (GLM, Llama-family, Qwen-family) — default: `{ vision: false, imageInToolResult: false }`.
|
|
504
|
+
* Override when routing to a vision-capable deployment.
|
|
505
|
+
*/
|
|
506
|
+
capabilities?: ProviderCapabilities;
|
|
373
507
|
}
|
|
374
508
|
/**
|
|
375
509
|
* Cerebras provider.
|
|
@@ -455,6 +589,17 @@ interface OpenAICompatParams {
|
|
|
455
589
|
authHeader?: OpenAICompatAuthHeader;
|
|
456
590
|
/** Extra headers sent with every request (e.g. referer, user-agent). */
|
|
457
591
|
extraHeaders?: Record<string, string>;
|
|
592
|
+
/**
|
|
593
|
+
* Provider-level capability flags. Routed into the message shaper and the
|
|
594
|
+
* agent loop so images in tool results + user messages are handled correctly
|
|
595
|
+
* for the underlying model.
|
|
596
|
+
*
|
|
597
|
+
* Defaults when omitted: `vision: false`, `imageInToolResult: false` — a
|
|
598
|
+
* conservative assumption matching most OSS text-only OpenAI-compat
|
|
599
|
+
* endpoints. Override when routing to a known vision-capable endpoint
|
|
600
|
+
* (e.g. OpenRouter vision models, Baseten image-capable deployments).
|
|
601
|
+
*/
|
|
602
|
+
capabilities?: ProviderCapabilities;
|
|
458
603
|
}
|
|
459
604
|
/**
|
|
460
605
|
* Factory for any OpenAI-compatible HTTP endpoint.
|
|
@@ -477,6 +622,16 @@ declare function openaiCompat(params: OpenAICompatParams): Provider;
|
|
|
477
622
|
interface OpenRouterParams {
|
|
478
623
|
apiKey?: string;
|
|
479
624
|
defaultModel?: string;
|
|
625
|
+
/**
|
|
626
|
+
* Provider capability flags. OpenRouter itself is a router — whether vision or
|
|
627
|
+
* native image-in-tool-result are supported depends on the downstream model.
|
|
628
|
+
* Default: `{ vision: true, imageInToolResult: false }` — matches the default
|
|
629
|
+
* `anthropic/claude-sonnet-4-6` model (vision-capable via companion user-message
|
|
630
|
+
* fallback since OpenRouter exposes Claude over the Chat Completions dialect).
|
|
631
|
+
*
|
|
632
|
+
* Override when routing to a known-text-only model (e.g. `meta-llama/llama-3-8b-instruct`).
|
|
633
|
+
*/
|
|
634
|
+
capabilities?: ProviderCapabilities;
|
|
480
635
|
}
|
|
481
636
|
/**
|
|
482
637
|
* OpenRouter provider.
|
|
@@ -498,7 +653,44 @@ interface ToolCall {
|
|
|
498
653
|
}
|
|
499
654
|
interface ToolResult {
|
|
500
655
|
id: string;
|
|
501
|
-
|
|
656
|
+
/**
|
|
657
|
+
* Tool output — plain string for text-only tools (the common case) or a structured
|
|
658
|
+
* array of content blocks for tools that return images or mixed content (e.g. an
|
|
659
|
+
* MCP browser server returning a screenshot).
|
|
660
|
+
*
|
|
661
|
+
* Use `toolResultToText(content)` when a downstream consumer only handles strings.
|
|
662
|
+
*/
|
|
663
|
+
content: string | ToolResultContent[];
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Provider-level capability flags used by the agent loop to route tool results
|
|
667
|
+
* and user messages appropriately.
|
|
668
|
+
*
|
|
669
|
+
* When a flag is `undefined` (omitted), the loop applies the conservative
|
|
670
|
+
* text-only default — images are stripped and replaced with a text marker so
|
|
671
|
+
* non-vision models do not confabulate about content they cannot see.
|
|
672
|
+
*/
|
|
673
|
+
interface ProviderCapabilities {
|
|
674
|
+
/**
|
|
675
|
+
* Model accepts image input anywhere (user messages and tool results).
|
|
676
|
+
*
|
|
677
|
+
* When `false`, the loop replaces image blocks with
|
|
678
|
+
* `"[image omitted — model does not support vision]"` before they reach the provider.
|
|
679
|
+
* Gives the model an honest marker instead of letting JSON-stringified base64 slip
|
|
680
|
+
* through and get confabulated over.
|
|
681
|
+
*/
|
|
682
|
+
vision?: boolean;
|
|
683
|
+
/**
|
|
684
|
+
* Provider wire format embeds images inside tool-role messages natively
|
|
685
|
+
* (Anthropic `tool_result.content` arrays, OpenAI Codex pi-ai `toolResult` blocks).
|
|
686
|
+
*
|
|
687
|
+
* When `false`, a vision-capable provider still gets images — but via a
|
|
688
|
+
* companion `user` message emitted immediately after the flattened
|
|
689
|
+
* `tool`/`tool_result` marker. This is the Claude Desktop / Cline pattern
|
|
690
|
+
* and works on any OpenAI Chat Completions endpoint that accepts image
|
|
691
|
+
* URLs in user messages.
|
|
692
|
+
*/
|
|
693
|
+
imageInToolResult?: boolean;
|
|
502
694
|
}
|
|
503
695
|
interface StreamCallbacks {
|
|
504
696
|
onText: (delta: string) => void;
|
|
@@ -538,6 +730,8 @@ interface Provider {
|
|
|
538
730
|
readonly name: string;
|
|
539
731
|
readonly meta: {
|
|
540
732
|
defaultModel: string;
|
|
733
|
+
/** Provider-level capability flags. See {@link ProviderCapabilities}. */
|
|
734
|
+
capabilities?: ProviderCapabilities;
|
|
541
735
|
} & Record<string, unknown>;
|
|
542
736
|
/** Format tool specs for this provider */
|
|
543
737
|
formatTools: (tools: ToolSpec[]) => unknown[];
|
|
@@ -568,133 +762,6 @@ interface Provider {
|
|
|
568
762
|
classifyError?: (err: unknown) => ClassifiedError | null;
|
|
569
763
|
}
|
|
570
764
|
|
|
571
|
-
/** Core tools available in every basic harness (without spawn) */
|
|
572
|
-
declare const basicTools: {
|
|
573
|
-
shell: ToolDef;
|
|
574
|
-
readFile: ToolDef;
|
|
575
|
-
writeFile: ToolDef;
|
|
576
|
-
listFiles: ToolDef;
|
|
577
|
-
};
|
|
578
|
-
declare const _default: HarnessConfig;
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Runtime context passed to every tool execution.
|
|
582
|
-
* Provides access to the agent's provider, abort signal, execution environment, and hooks.
|
|
583
|
-
*/
|
|
584
|
-
interface ToolContext {
|
|
585
|
-
/** The LLM provider for this agent run */
|
|
586
|
-
provider: Provider;
|
|
587
|
-
/** Abort signal — tools should check this for early termination */
|
|
588
|
-
signal: AbortSignal;
|
|
589
|
-
/** The execution context (shell, filesystem, etc.) */
|
|
590
|
-
execution: ExecutionContext;
|
|
591
|
-
/** The active execution handle for the current agent run */
|
|
592
|
-
handle: ExecutionHandle;
|
|
593
|
-
/** Agent hooks for emitting events (e.g. spawn:complete) */
|
|
594
|
-
hooks: Hookable<AgentHooks>;
|
|
595
|
-
/** The harness config for this agent (tools available to the agent) */
|
|
596
|
-
harness: HarnessConfig;
|
|
597
|
-
/** Turn ID that requested this tool call */
|
|
598
|
-
turnId: string;
|
|
599
|
-
/** Tool call ID from the model */
|
|
600
|
-
callId: string;
|
|
601
|
-
}
|
|
602
|
-
interface ToolDef {
|
|
603
|
-
spec: ToolSpec;
|
|
604
|
-
execute: (input: Record<string, unknown>, ctx: ToolContext) => Promise<string>;
|
|
605
|
-
}
|
|
606
|
-
type ToolMap = Map<string, ToolDef>;
|
|
607
|
-
interface HarnessConfig {
|
|
608
|
-
/** Display name for this harness */
|
|
609
|
-
name: string;
|
|
610
|
-
/** Default system prompt injected when no system is provided at run time */
|
|
611
|
-
system?: string;
|
|
612
|
-
/** Tool definitions available to the agent */
|
|
613
|
-
tools: Record<string, ToolDef>;
|
|
614
|
-
/** MCP servers to connect and expose as tools */
|
|
615
|
-
mcpServers?: McpServerConfig[];
|
|
616
|
-
/** Skills configuration at the harness level */
|
|
617
|
-
skills?: SkillsConfig;
|
|
618
|
-
/** Default behavior for agents using this harness */
|
|
619
|
-
behavior?: AgentBehavior;
|
|
620
|
-
/**
|
|
621
|
-
* Map canonical tool names to LLM-facing (aliased) names.
|
|
622
|
-
*
|
|
623
|
-
* Aliasing is **LLM-boundary-only**:
|
|
624
|
-
* - The alias is what the provider's tool spec carries, what the model calls it, and
|
|
625
|
-
* what appears in `ToolHookContext.displayName` / `McpToolHookContext.displayName`.
|
|
626
|
-
* - The canonical name is what lives in `session.turns`, `ToolHookContext.name`, and
|
|
627
|
-
* what the agent uses to look up the tool implementation. Alias changes never
|
|
628
|
-
* desync persisted history.
|
|
629
|
-
*
|
|
630
|
-
* Keys are canonical names from `tools` (or `mcp_{server}_{tool}` for MCP tools).
|
|
631
|
-
* Collisions between aliases are rejected by the loop.
|
|
632
|
-
*
|
|
633
|
-
* @example
|
|
634
|
-
* ```ts
|
|
635
|
-
* defineHarness({
|
|
636
|
-
* tools: { ...basicTools },
|
|
637
|
-
* toolAliases: { shell: 'Bash', read_file: 'Read', write_file: 'Write' },
|
|
638
|
-
* })
|
|
639
|
-
* ```
|
|
640
|
-
*
|
|
641
|
-
* @remarks Alias a tool only when the aliased name is semantically equivalent.
|
|
642
|
-
* `list_files` → `Glob` is NOT a valid alias because Glob is pattern-based.
|
|
643
|
-
*/
|
|
644
|
-
toolAliases?: Record<string, string>;
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Define a harness with a name, optional system prompt, and tools.
|
|
648
|
-
*/
|
|
649
|
-
declare function defineHarness(config: HarnessConfig): HarnessConfig;
|
|
650
|
-
type Harness = HarnessConfig;
|
|
651
|
-
/**
|
|
652
|
-
* A harness with no tools — for pure chat mode.
|
|
653
|
-
* Pass `tools: {}` in agent.run() or use this harness directly.
|
|
654
|
-
*/
|
|
655
|
-
declare const noTools: HarnessConfig;
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* MCP (Model Context Protocol) server support.
|
|
659
|
-
*
|
|
660
|
-
* Connects to one or more MCP servers, discovers their tools,
|
|
661
|
-
* and wraps them as zidane ToolDefs for use in agent loops.
|
|
662
|
-
*/
|
|
663
|
-
|
|
664
|
-
interface McpConnection {
|
|
665
|
-
tools: Record<string, ToolDef>;
|
|
666
|
-
close: () => Promise<void>;
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Normalize MCP server configs from any common shape to `McpServerConfig[]`.
|
|
670
|
-
*
|
|
671
|
-
* Accepts:
|
|
672
|
-
* - `McpServerConfig[]` — zidane native (pass-through).
|
|
673
|
-
* - `McpServerConfig` — a single config object (wrapped to a 1-element array).
|
|
674
|
-
* - `Record<string, RawShape>` — name-keyed map (common in host-SDK configs), where the key is the server name.
|
|
675
|
-
* - Mixed shapes with `type` vs `transport`, `httpUrl`/`sseUrl` vs `url`.
|
|
676
|
-
*
|
|
677
|
-
* Returns `[]` when `input` is nullish. Throws a descriptive error when the transport
|
|
678
|
-
* cannot be inferred from a given entry, or when the input shape is unsupported.
|
|
679
|
-
*/
|
|
680
|
-
declare function normalizeMcpServers(input: unknown): McpServerConfig[];
|
|
681
|
-
/**
|
|
682
|
-
* Convert MCP tool result content blocks to a single string.
|
|
683
|
-
* Text blocks are extracted; non-text blocks are JSON-stringified.
|
|
684
|
-
*/
|
|
685
|
-
declare function resultToString(content: unknown[]): string;
|
|
686
|
-
/**
|
|
687
|
-
* Connect to MCP servers and discover their tools.
|
|
688
|
-
*
|
|
689
|
-
* Each tool is namespaced as `mcp_{serverName}_{toolName}` to avoid
|
|
690
|
-
* collisions with harness tools or tools from other servers.
|
|
691
|
-
*
|
|
692
|
-
* @param configs - Array of MCP server configurations
|
|
693
|
-
* @param _clientFactory - Internal: override client construction for testing
|
|
694
|
-
* @param hooks - Optional agent hooks for firing mcp:connect, mcp:error, mcp:close events
|
|
695
|
-
*/
|
|
696
|
-
declare function connectMcpServers(configs: McpServerConfig[], _clientFactory?: () => Client, hooks?: Hookable<AgentHooks>): Promise<McpConnection>;
|
|
697
|
-
|
|
698
765
|
/**
|
|
699
766
|
* File-map session store.
|
|
700
767
|
*
|
|
@@ -835,6 +902,17 @@ interface SessionRun {
|
|
|
835
902
|
totalUsage?: TurnUsage;
|
|
836
903
|
/** Estimated cost in USD */
|
|
837
904
|
cost?: number;
|
|
905
|
+
/**
|
|
906
|
+
* The run that spawned this one, when the agent is a subagent sharing its
|
|
907
|
+
* parent's session. Undefined on top-level `agent.run()`. Consumers can walk
|
|
908
|
+
* `runs` by `parentRunId` to reconstruct the subagent tree.
|
|
909
|
+
*/
|
|
910
|
+
parentRunId?: string;
|
|
911
|
+
/**
|
|
912
|
+
* Zero-based subagent depth. 0 = top-level run, 1 = direct child, …
|
|
913
|
+
* Recorded here so hosts can query/filter by level without walking the tree.
|
|
914
|
+
*/
|
|
915
|
+
depth?: number;
|
|
838
916
|
}
|
|
839
917
|
interface SessionData {
|
|
840
918
|
id: string;
|
|
@@ -891,8 +969,15 @@ interface Session {
|
|
|
891
969
|
readonly runs: SessionRun[];
|
|
892
970
|
/** Arbitrary metadata */
|
|
893
971
|
readonly metadata: Record<string, unknown>;
|
|
894
|
-
/**
|
|
895
|
-
|
|
972
|
+
/**
|
|
973
|
+
* Start tracking a new run. `extras.parentRunId` + `extras.depth` are
|
|
974
|
+
* populated by the spawn tool when a child agent shares its parent's
|
|
975
|
+
* session; regular top-level `agent.run()` calls omit them.
|
|
976
|
+
*/
|
|
977
|
+
startRun: (runId: string, prompt?: string, extras?: {
|
|
978
|
+
parentRunId?: string;
|
|
979
|
+
depth?: number;
|
|
980
|
+
}) => void;
|
|
896
981
|
/** Mark a run as completed */
|
|
897
982
|
completeRun: (runId: string, stats: {
|
|
898
983
|
turns: number;
|
|
@@ -943,6 +1028,352 @@ declare function createSession(options?: CreateSessionOptions): Promise<Session>
|
|
|
943
1028
|
*/
|
|
944
1029
|
declare function loadSession(store: SessionStore, sessionId: string): Promise<Session | null>;
|
|
945
1030
|
|
|
1031
|
+
/**
|
|
1032
|
+
* Types for the Agent Skills system.
|
|
1033
|
+
*
|
|
1034
|
+
* Follows the Agent Skills open standard (agentskills.io/specification).
|
|
1035
|
+
* Zidane-specific metadata conventionally uses the `zidane.` key prefix
|
|
1036
|
+
* (e.g. `metadata['zidane.paths']`) to stay spec-compliant.
|
|
1037
|
+
*/
|
|
1038
|
+
interface SkillResource {
|
|
1039
|
+
/** Relative path from skill directory */
|
|
1040
|
+
path: string;
|
|
1041
|
+
/** Resource type inferred from directory */
|
|
1042
|
+
type: 'script' | 'reference' | 'asset' | 'other';
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Where the skill came from. Used for collision precedence (project beats user)
|
|
1046
|
+
* and for host SDKs to gate project-level skills on a trust check.
|
|
1047
|
+
*/
|
|
1048
|
+
type SkillSource = 'project' | 'user' | 'inline' | 'builtin';
|
|
1049
|
+
/** Severity + code for lenient-load warnings surfaced to host UIs. */
|
|
1050
|
+
interface SkillDiagnostic {
|
|
1051
|
+
severity: 'warning' | 'error';
|
|
1052
|
+
/** Stable machine-readable code (e.g. `name-mismatch-directory`). */
|
|
1053
|
+
code: string;
|
|
1054
|
+
/** Human-readable description. */
|
|
1055
|
+
message: string;
|
|
1056
|
+
/** Optional frontmatter field name the diagnostic relates to. */
|
|
1057
|
+
field?: string;
|
|
1058
|
+
}
|
|
1059
|
+
interface SkillConfig {
|
|
1060
|
+
/** Skill name: 1-64 chars, lowercase alphanumeric + hyphens */
|
|
1061
|
+
name: string;
|
|
1062
|
+
/** What the skill does and when to use it (1-1024 chars) */
|
|
1063
|
+
description: string;
|
|
1064
|
+
/** The SKILL.md body content (after YAML frontmatter) */
|
|
1065
|
+
instructions: string;
|
|
1066
|
+
/**
|
|
1067
|
+
* Where this skill was loaded from. Drives collision precedence and the
|
|
1068
|
+
* `trustProjectSkills` gate. Optional — `parseSkillFile` stamps it; raw
|
|
1069
|
+
* fixtures that omit it are treated as `'project'` by downstream readers.
|
|
1070
|
+
*/
|
|
1071
|
+
source?: SkillSource;
|
|
1072
|
+
/** Absolute path to SKILL.md (undefined for inline skills) */
|
|
1073
|
+
location?: string;
|
|
1074
|
+
/** Skill directory path for resolving relative references */
|
|
1075
|
+
baseDir?: string;
|
|
1076
|
+
/** License identifier or reference */
|
|
1077
|
+
license?: string;
|
|
1078
|
+
/** Environment requirements */
|
|
1079
|
+
compatibility?: string;
|
|
1080
|
+
/**
|
|
1081
|
+
* Flat key-value metadata bag per the spec. For Zidane-specific hints,
|
|
1082
|
+
* use the `zidane.` key prefix (e.g. `metadata['zidane.paths']`).
|
|
1083
|
+
*/
|
|
1084
|
+
metadata?: Record<string, string>;
|
|
1085
|
+
/** Pre-approved tool names (experimental per spec) */
|
|
1086
|
+
allowedTools?: string[];
|
|
1087
|
+
/** Bundled resource files discovered in the skill directory */
|
|
1088
|
+
resources?: SkillResource[];
|
|
1089
|
+
/**
|
|
1090
|
+
* Lenient-load warnings recorded during parsing. Host SDKs can surface these
|
|
1091
|
+
* as inline UI hints. Absent when no issues were found.
|
|
1092
|
+
*/
|
|
1093
|
+
diagnostics?: SkillDiagnostic[];
|
|
1094
|
+
}
|
|
1095
|
+
interface SkillsConfig {
|
|
1096
|
+
/**
|
|
1097
|
+
* Control which skills are active.
|
|
1098
|
+
* - `true` (default): all discovered skills are enabled
|
|
1099
|
+
* - `false` or `[]`: fully disable the skills system (no resolution, no catalog, no hooks)
|
|
1100
|
+
* - `string[]`: allowlist — only skills with matching names are enabled
|
|
1101
|
+
*/
|
|
1102
|
+
enabled?: boolean | string[];
|
|
1103
|
+
/** Directories to scan for SKILL.md files */
|
|
1104
|
+
scan?: string[];
|
|
1105
|
+
/** Dynamic skills written to disk at agent start, then loaded normally */
|
|
1106
|
+
write?: SkillConfig[];
|
|
1107
|
+
/** Skill names to exclude from the catalog */
|
|
1108
|
+
exclude?: string[];
|
|
1109
|
+
/** Skip default scan paths (~/.agents/skills, .zidane/skills, etc.) */
|
|
1110
|
+
skipDefaultPaths?: boolean;
|
|
1111
|
+
/**
|
|
1112
|
+
* Auto-inject `skills_use` / `skills_read` / `skills_run_script` tools
|
|
1113
|
+
* when the catalog is non-empty. Default `true`. Set `false` to opt out
|
|
1114
|
+
* (the system prompt will then instruct the model to use its file-read
|
|
1115
|
+
* tool instead).
|
|
1116
|
+
*/
|
|
1117
|
+
tool?: boolean;
|
|
1118
|
+
/**
|
|
1119
|
+
* Cap on concurrently active skills per run. Default `undefined` (unlimited).
|
|
1120
|
+
* Attempts to activate past the cap throw from `skills_use`.
|
|
1121
|
+
*/
|
|
1122
|
+
maxActive?: number;
|
|
1123
|
+
/** Script timeout for `skills_run_script`, in milliseconds. Default `60000`. */
|
|
1124
|
+
scriptTimeoutMs?: number;
|
|
1125
|
+
/**
|
|
1126
|
+
* When `false`, skills with `source: 'project'` are skipped during
|
|
1127
|
+
* resolution with a diagnostic. Default `true` (preserves existing behavior).
|
|
1128
|
+
* Useful for host SDKs handling untrusted repositories.
|
|
1129
|
+
*/
|
|
1130
|
+
trustProjectSkills?: boolean;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/** Core tools available in every basic harness (without spawn) */
|
|
1134
|
+
declare const basicTools: {
|
|
1135
|
+
shell: ToolDef;
|
|
1136
|
+
readFile: ToolDef;
|
|
1137
|
+
writeFile: ToolDef;
|
|
1138
|
+
listFiles: ToolDef;
|
|
1139
|
+
};
|
|
1140
|
+
declare const _default: HarnessConfig;
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Runtime context passed to every tool execution.
|
|
1144
|
+
* Provides access to the agent's provider, abort signal, execution environment, and hooks.
|
|
1145
|
+
*/
|
|
1146
|
+
interface ToolContext {
|
|
1147
|
+
/** The LLM provider for this agent run */
|
|
1148
|
+
provider: Provider;
|
|
1149
|
+
/** Abort signal — tools should check this for early termination */
|
|
1150
|
+
signal: AbortSignal;
|
|
1151
|
+
/** The execution context (shell, filesystem, etc.) */
|
|
1152
|
+
execution: ExecutionContext;
|
|
1153
|
+
/** The active execution handle for the current agent run */
|
|
1154
|
+
handle: ExecutionHandle;
|
|
1155
|
+
/** Agent hooks for emitting events (e.g. spawn:complete) */
|
|
1156
|
+
hooks: Hookable<AgentHooks>;
|
|
1157
|
+
/** The harness config for this agent (tools available to the agent) */
|
|
1158
|
+
harness: HarnessConfig;
|
|
1159
|
+
/** Turn ID that requested this tool call */
|
|
1160
|
+
turnId: string;
|
|
1161
|
+
/** Tool call ID from the model */
|
|
1162
|
+
callId: string;
|
|
1163
|
+
/**
|
|
1164
|
+
* The run id this tool call is part of. Populated by the agent loop when
|
|
1165
|
+
* invoking tools. Optional on the type so host code constructing contexts
|
|
1166
|
+
* by hand (tests, direct tool invocations) doesn't have to synthesize one.
|
|
1167
|
+
*
|
|
1168
|
+
* Spawn-style tools rely on this to tag child runs with `parentRunId` so
|
|
1169
|
+
* the subagent tree can be reconstructed from a persisted session.
|
|
1170
|
+
*/
|
|
1171
|
+
runId?: string;
|
|
1172
|
+
/**
|
|
1173
|
+
* The agent's session, when one was provided to `createAgent`. Tools that
|
|
1174
|
+
* want to persist their own state (or, in the case of `spawn`, inherit the
|
|
1175
|
+
* parent's session for child persistence) can read from here.
|
|
1176
|
+
*/
|
|
1177
|
+
session?: Session;
|
|
1178
|
+
/**
|
|
1179
|
+
* Subagent depth for the agent owning this tool call. 0 = top-level,
|
|
1180
|
+
* 1 = first-level child, … Used by spawn to enforce a `maxDepth` cap.
|
|
1181
|
+
* Undefined is treated as 0 by spawn.
|
|
1182
|
+
*/
|
|
1183
|
+
depth?: number;
|
|
1184
|
+
}
|
|
1185
|
+
interface ToolDef {
|
|
1186
|
+
spec: ToolSpec;
|
|
1187
|
+
/**
|
|
1188
|
+
* Execute the tool and return its output.
|
|
1189
|
+
*
|
|
1190
|
+
* Return a plain string for text-only tools (the common case). Return a
|
|
1191
|
+
* `ToolResultContent[]` when the tool produces non-text content (images, mixed
|
|
1192
|
+
* text+image) that the provider can route through natively (Anthropic
|
|
1193
|
+
* `tool_result.content` arrays, OpenAI Codex pi-ai) or through the
|
|
1194
|
+
* companion-user-message fallback (OpenAI Chat Completions).
|
|
1195
|
+
*/
|
|
1196
|
+
execute: (input: Record<string, unknown>, ctx: ToolContext) => Promise<string | ToolResultContent[]>;
|
|
1197
|
+
}
|
|
1198
|
+
type ToolMap = Map<string, ToolDef>;
|
|
1199
|
+
interface HarnessConfig {
|
|
1200
|
+
/** Display name for this harness */
|
|
1201
|
+
name: string;
|
|
1202
|
+
/** Default system prompt injected when no system is provided at run time */
|
|
1203
|
+
system?: string;
|
|
1204
|
+
/** Tool definitions available to the agent */
|
|
1205
|
+
tools: Record<string, ToolDef>;
|
|
1206
|
+
/** MCP servers to connect and expose as tools */
|
|
1207
|
+
mcpServers?: McpServerConfig[];
|
|
1208
|
+
/** Skills configuration at the harness level */
|
|
1209
|
+
skills?: SkillsConfig;
|
|
1210
|
+
/** Default behavior for agents using this harness */
|
|
1211
|
+
behavior?: AgentBehavior;
|
|
1212
|
+
/**
|
|
1213
|
+
* Map canonical tool names to LLM-facing (aliased) names.
|
|
1214
|
+
*
|
|
1215
|
+
* Aliasing is **LLM-boundary-only**:
|
|
1216
|
+
* - The alias is what the provider's tool spec carries, what the model calls it, and
|
|
1217
|
+
* what appears in `ToolHookContext.displayName` / `McpToolHookContext.displayName`.
|
|
1218
|
+
* - The canonical name is what lives in `session.turns`, `ToolHookContext.name`, and
|
|
1219
|
+
* what the agent uses to look up the tool implementation. Alias changes never
|
|
1220
|
+
* desync persisted history.
|
|
1221
|
+
*
|
|
1222
|
+
* Keys are canonical names from `tools` (or `mcp_{server}_{tool}` for MCP tools).
|
|
1223
|
+
* Collisions between aliases are rejected by the loop.
|
|
1224
|
+
*
|
|
1225
|
+
* @example
|
|
1226
|
+
* ```ts
|
|
1227
|
+
* defineHarness({
|
|
1228
|
+
* tools: { ...basicTools },
|
|
1229
|
+
* toolAliases: { shell: 'Bash', read_file: 'Read', write_file: 'Write' },
|
|
1230
|
+
* })
|
|
1231
|
+
* ```
|
|
1232
|
+
*
|
|
1233
|
+
* @remarks Alias a tool only when the aliased name is semantically equivalent.
|
|
1234
|
+
* `list_files` → `Glob` is NOT a valid alias because Glob is pattern-based.
|
|
1235
|
+
*/
|
|
1236
|
+
toolAliases?: Record<string, string>;
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Define a harness with a name, optional system prompt, and tools.
|
|
1240
|
+
*/
|
|
1241
|
+
declare function defineHarness(config: HarnessConfig): HarnessConfig;
|
|
1242
|
+
type Harness = HarnessConfig;
|
|
1243
|
+
/**
|
|
1244
|
+
* A harness with no tools — for pure chat mode.
|
|
1245
|
+
* Pass `tools: {}` in agent.run() or use this harness directly.
|
|
1246
|
+
*/
|
|
1247
|
+
declare const noTools: HarnessConfig;
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* MCP (Model Context Protocol) server support.
|
|
1251
|
+
*
|
|
1252
|
+
* Connects to one or more MCP servers, discovers their tools,
|
|
1253
|
+
* and wraps them as zidane ToolDefs for use in agent loops.
|
|
1254
|
+
*/
|
|
1255
|
+
|
|
1256
|
+
interface McpConnection {
|
|
1257
|
+
tools: Record<string, ToolDef>;
|
|
1258
|
+
close: () => Promise<void>;
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Normalize MCP server configs from any common shape to `McpServerConfig[]`.
|
|
1262
|
+
*
|
|
1263
|
+
* Accepts:
|
|
1264
|
+
* - `McpServerConfig[]` — zidane native (pass-through).
|
|
1265
|
+
* - `McpServerConfig` — a single config object (wrapped to a 1-element array).
|
|
1266
|
+
* - `Record<string, RawShape>` — name-keyed map (common in host-SDK configs), where the key is the server name.
|
|
1267
|
+
* - Mixed shapes with `type` vs `transport`, `httpUrl`/`sseUrl` vs `url`.
|
|
1268
|
+
*
|
|
1269
|
+
* Returns `[]` when `input` is nullish. Throws a descriptive error when the transport
|
|
1270
|
+
* cannot be inferred from a given entry, or when the input shape is unsupported.
|
|
1271
|
+
*/
|
|
1272
|
+
declare function normalizeMcpServers(input: unknown): McpServerConfig[];
|
|
1273
|
+
/**
|
|
1274
|
+
* Lossy flattener — converts MCP `CallToolResult.content` blocks to a single string.
|
|
1275
|
+
* Text blocks are extracted; non-text blocks are JSON-stringified.
|
|
1276
|
+
*
|
|
1277
|
+
* Prefer {@link normalizeMcpBlocks} for new code — it preserves image blocks so the
|
|
1278
|
+
* provider can route them through to the model natively (Anthropic tool_result blocks,
|
|
1279
|
+
* OpenAI companion-user-message). This function is kept for back-compat and is useful
|
|
1280
|
+
* as a logging/display helper where a single string is required.
|
|
1281
|
+
*/
|
|
1282
|
+
declare function resultToString(content: unknown[]): string;
|
|
1283
|
+
/**
|
|
1284
|
+
* Normalize MCP `CallToolResult.content` to zidane's {@link ToolResultContent[]} shape.
|
|
1285
|
+
*
|
|
1286
|
+
* Handles the four MCP content block types:
|
|
1287
|
+
* - `text` → preserved as `{type:'text', text}`
|
|
1288
|
+
* - `image` → preserved as `{type:'image', mediaType, data}` (MCP uses `mimeType`)
|
|
1289
|
+
* - `resource` with embedded text → flattened to a text block
|
|
1290
|
+
* - `resource` with embedded blob whose `mimeType` is `image/*` → flattened to an image block
|
|
1291
|
+
* - Any unrecognized block → JSON-stringified fallback text block (lossy but safe)
|
|
1292
|
+
*
|
|
1293
|
+
* Returns `null` when the input is not an array — callers should fall back to an empty
|
|
1294
|
+
* result in that case.
|
|
1295
|
+
*/
|
|
1296
|
+
declare function normalizeMcpBlocks(content: unknown): ToolResultContent[] | null;
|
|
1297
|
+
/**
|
|
1298
|
+
* Connect to MCP servers and discover their tools.
|
|
1299
|
+
*
|
|
1300
|
+
* Each tool is namespaced as `mcp_{serverName}_{toolName}` to avoid
|
|
1301
|
+
* collisions with harness tools or tools from other servers.
|
|
1302
|
+
*
|
|
1303
|
+
* @param configs - Array of MCP server configurations
|
|
1304
|
+
* @param _clientFactory - Internal: override client construction for testing
|
|
1305
|
+
* @param hooks - Optional agent hooks for firing mcp:connect, mcp:error, mcp:close events
|
|
1306
|
+
*/
|
|
1307
|
+
declare function connectMcpServers(configs: McpServerConfig[], _clientFactory?: () => Client, hooks?: Hookable<AgentHooks>): Promise<McpConnection>;
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* Per-agent skill activation state machine.
|
|
1311
|
+
*
|
|
1312
|
+
* Tracks which skills are active across a run. The three skills tools
|
|
1313
|
+
* (`skills_use` / `skills_read` / `skills_run_script`) read from this state
|
|
1314
|
+
* for gating + listing. Allowed-tools enforcement reads from it too.
|
|
1315
|
+
*
|
|
1316
|
+
* Lifecycle:
|
|
1317
|
+
* - Storage lives on the agent instance (created once in `createAgent`), but
|
|
1318
|
+
* every `run()` ends with an implicit deactivate-all pass (reason `'run-end'`)
|
|
1319
|
+
* so activation does **not** persist across run boundaries. To keep a skill
|
|
1320
|
+
* active across successive runs, call `agent.activateSkill(name)` before each
|
|
1321
|
+
* run — the explicit-activation path is idempotent.
|
|
1322
|
+
* - `agent.reset()` clears the state with reason `'reset'`.
|
|
1323
|
+
* - On session-resume, carried-forward `skills_use` tool_call blocks (in prior
|
|
1324
|
+
* assistant turns) are replayed at run-start to rehydrate state with
|
|
1325
|
+
* `via: 'resume'`.
|
|
1326
|
+
*
|
|
1327
|
+
* The caps (`maxActive` from SkillsConfig) is enforced here — returning `false`
|
|
1328
|
+
* from `activate()` when the cap is hit lets the caller surface an actionable
|
|
1329
|
+
* "max skills active" error to the model.
|
|
1330
|
+
*/
|
|
1331
|
+
|
|
1332
|
+
/** How a skill was activated. Surfaced in `skills:activate` hook ctx. */
|
|
1333
|
+
type ActivationVia = 'model' | 'explicit' | 'resume';
|
|
1334
|
+
/** Reason a skill was deactivated. Surfaced in `skills:deactivate` hook ctx. */
|
|
1335
|
+
type DeactivationReason = 'run-end' | 'explicit' | 'reset';
|
|
1336
|
+
/** A skill currently active in the state machine. */
|
|
1337
|
+
interface ActiveSkill {
|
|
1338
|
+
skill: SkillConfig;
|
|
1339
|
+
activatedAt: number;
|
|
1340
|
+
activatedVia: ActivationVia;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Per-agent skill activation state. Public read-surface is the `active()` list
|
|
1344
|
+
* and `isActive(name)` predicate; writes go through `activate()` / `deactivate()`.
|
|
1345
|
+
*/
|
|
1346
|
+
interface SkillActivationState {
|
|
1347
|
+
/** List of currently active skills in activation order. Returns a snapshot. */
|
|
1348
|
+
active: () => readonly ActiveSkill[];
|
|
1349
|
+
/** Is the skill with this canonical name currently active? */
|
|
1350
|
+
isActive: (name: string) => boolean;
|
|
1351
|
+
/** Retrieve the `ActiveSkill` record by name, or `undefined`. */
|
|
1352
|
+
get: (name: string) => ActiveSkill | undefined;
|
|
1353
|
+
/**
|
|
1354
|
+
* Mark a skill as active.
|
|
1355
|
+
* - Returns `'ok'` on a fresh activation (caller should fire `skills:activate`).
|
|
1356
|
+
* - Returns `'already-active'` if the skill was already in the set (idempotent).
|
|
1357
|
+
* - Returns `'cap-reached'` if the `maxActive` cap would be exceeded. State is unchanged.
|
|
1358
|
+
*/
|
|
1359
|
+
activate: (skill: SkillConfig, via: ActivationVia) => 'ok' | 'already-active' | 'cap-reached';
|
|
1360
|
+
/**
|
|
1361
|
+
* Mark a skill as inactive. Returns the removed `ActiveSkill` record or `undefined`
|
|
1362
|
+
* if it wasn't active. Callers fire `skills:deactivate` on removal.
|
|
1363
|
+
*/
|
|
1364
|
+
deactivate: (name: string) => ActiveSkill | undefined;
|
|
1365
|
+
/** Remove every active skill. Returns the list of removed records. */
|
|
1366
|
+
clear: () => readonly ActiveSkill[];
|
|
1367
|
+
}
|
|
1368
|
+
interface SkillActivationStateOptions {
|
|
1369
|
+
/**
|
|
1370
|
+
* Cap on concurrent activations. `undefined` (the default) disables the cap.
|
|
1371
|
+
* When set, `activate()` returns `'cap-reached'` once the set is at size `maxActive`.
|
|
1372
|
+
*/
|
|
1373
|
+
maxActive?: number;
|
|
1374
|
+
}
|
|
1375
|
+
declare function createSkillActivationState(options?: SkillActivationStateOptions): SkillActivationState;
|
|
1376
|
+
|
|
946
1377
|
/**
|
|
947
1378
|
* Agent creation and state management.
|
|
948
1379
|
*/
|
|
@@ -980,13 +1411,13 @@ interface AgentHooks {
|
|
|
980
1411
|
}) => void;
|
|
981
1412
|
'tool:before': (ctx: ToolHookContext) => void;
|
|
982
1413
|
'tool:after': (ctx: ToolHookContext & {
|
|
983
|
-
result: string;
|
|
1414
|
+
result: string | ToolResultContent[];
|
|
984
1415
|
}) => void;
|
|
985
1416
|
'tool:error': (ctx: ToolHookContext & {
|
|
986
1417
|
error: Error;
|
|
987
1418
|
}) => void;
|
|
988
1419
|
'tool:transform': (ctx: ToolHookContext & {
|
|
989
|
-
result: string;
|
|
1420
|
+
result: string | ToolResultContent[];
|
|
990
1421
|
isError: boolean;
|
|
991
1422
|
}) => void;
|
|
992
1423
|
'context:transform': (ctx: {
|
|
@@ -1000,6 +1431,45 @@ interface AgentHooks {
|
|
|
1000
1431
|
'spawn:error': (ctx: SpawnHookContext & {
|
|
1001
1432
|
error: Error;
|
|
1002
1433
|
}) => void;
|
|
1434
|
+
'child:stream:text': (ctx: StreamHookContext & {
|
|
1435
|
+
delta: string;
|
|
1436
|
+
text: string;
|
|
1437
|
+
childId: string;
|
|
1438
|
+
depth: number;
|
|
1439
|
+
}) => void;
|
|
1440
|
+
'child:stream:thinking': (ctx: StreamHookContext & {
|
|
1441
|
+
delta: string;
|
|
1442
|
+
thinking: string;
|
|
1443
|
+
childId: string;
|
|
1444
|
+
depth: number;
|
|
1445
|
+
}) => void;
|
|
1446
|
+
'child:stream:end': (ctx: StreamHookContext & {
|
|
1447
|
+
text: string;
|
|
1448
|
+
childId: string;
|
|
1449
|
+
depth: number;
|
|
1450
|
+
}) => void;
|
|
1451
|
+
'child:tool:before': (ctx: ToolHookContext & {
|
|
1452
|
+
childId: string;
|
|
1453
|
+
depth: number;
|
|
1454
|
+
}) => void;
|
|
1455
|
+
'child:tool:after': (ctx: ToolHookContext & {
|
|
1456
|
+
result: string | ToolResultContent[];
|
|
1457
|
+
childId: string;
|
|
1458
|
+
depth: number;
|
|
1459
|
+
}) => void;
|
|
1460
|
+
'child:tool:error': (ctx: ToolHookContext & {
|
|
1461
|
+
error: Error;
|
|
1462
|
+
childId: string;
|
|
1463
|
+
depth: number;
|
|
1464
|
+
}) => void;
|
|
1465
|
+
'child:turn:after': (ctx: {
|
|
1466
|
+
turn: number;
|
|
1467
|
+
turnId: string;
|
|
1468
|
+
usage: TurnUsage;
|
|
1469
|
+
message: SessionTurn;
|
|
1470
|
+
childId: string;
|
|
1471
|
+
depth: number;
|
|
1472
|
+
}) => void;
|
|
1003
1473
|
'mcp:connect': (ctx: {
|
|
1004
1474
|
name: string;
|
|
1005
1475
|
transport: string;
|
|
@@ -1018,10 +1488,10 @@ interface AgentHooks {
|
|
|
1018
1488
|
}) => void;
|
|
1019
1489
|
'mcp:tool:before': (ctx: McpToolHookContext) => void;
|
|
1020
1490
|
'mcp:tool:after': (ctx: McpToolHookContext & {
|
|
1021
|
-
result: string;
|
|
1491
|
+
result: string | ToolResultContent[];
|
|
1022
1492
|
}) => void;
|
|
1023
1493
|
'mcp:tool:transform': (ctx: McpToolHookContext & {
|
|
1024
|
-
result: string;
|
|
1494
|
+
result: string | ToolResultContent[];
|
|
1025
1495
|
}) => void;
|
|
1026
1496
|
'mcp:tool:error': (ctx: McpToolHookContext & {
|
|
1027
1497
|
error: Error;
|
|
@@ -1035,6 +1505,11 @@ interface AgentHooks {
|
|
|
1035
1505
|
}) => void;
|
|
1036
1506
|
'skills:activate': (ctx: {
|
|
1037
1507
|
skill: SkillConfig;
|
|
1508
|
+
via: ActivationVia;
|
|
1509
|
+
}) => void;
|
|
1510
|
+
'skills:deactivate': (ctx: {
|
|
1511
|
+
skill: SkillConfig;
|
|
1512
|
+
reason: DeactivationReason;
|
|
1038
1513
|
}) => void;
|
|
1039
1514
|
'usage': (ctx: {
|
|
1040
1515
|
turn: number;
|
|
@@ -1092,16 +1567,38 @@ interface Agent {
|
|
|
1092
1567
|
steer: (message: string) => void;
|
|
1093
1568
|
followUp: (message: string) => void;
|
|
1094
1569
|
waitForIdle: () => Promise<void>;
|
|
1095
|
-
|
|
1096
|
-
|
|
1570
|
+
/**
|
|
1571
|
+
* Clear the agent's in-memory state (turns, queues, skill activations).
|
|
1572
|
+
* Fires `skills:deactivate` with `reason: 'reset'` for each previously active
|
|
1573
|
+
* skill. Awaiting lets host apps observe listener rejections.
|
|
1574
|
+
*/
|
|
1575
|
+
reset: () => Promise<void>;
|
|
1576
|
+
/**
|
|
1577
|
+
* Destroy the execution context and clean up resources.
|
|
1578
|
+
* Idempotent — safe to call from both a `finally` block and a signal handler.
|
|
1579
|
+
*/
|
|
1097
1580
|
destroy: () => Promise<void>;
|
|
1581
|
+
/**
|
|
1582
|
+
* Explicitly activate a skill by name. Fires `skills:activate` with
|
|
1583
|
+
* `via: 'explicit'`. Throws if the skill isn't in the resolved catalog or
|
|
1584
|
+
* if the `maxActive` cap is reached. Idempotent — activating an already-active
|
|
1585
|
+
* skill is a no-op.
|
|
1586
|
+
*/
|
|
1587
|
+
activateSkill: (name: string) => Promise<void>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Deactivate a skill by name. Fires `skills:deactivate` with `reason: 'explicit'`.
|
|
1590
|
+
* No-op when the skill wasn't active.
|
|
1591
|
+
*/
|
|
1592
|
+
deactivateSkill: (name: string) => Promise<void>;
|
|
1098
1593
|
readonly isRunning: boolean;
|
|
1099
1594
|
readonly turns: SessionTurn[];
|
|
1100
1595
|
readonly execution: ExecutionContext;
|
|
1101
1596
|
readonly handle: ExecutionHandle | null;
|
|
1102
1597
|
readonly session: Session | null;
|
|
1598
|
+
/** Snapshot of currently active skills. */
|
|
1599
|
+
readonly activeSkills: readonly ActiveSkill[];
|
|
1103
1600
|
meta: Record<string, unknown>;
|
|
1104
1601
|
}
|
|
1105
1602
|
declare function createAgent({ harness: harnessOption, provider, behavior: agentBehavior, execution, mcpServers, session, skills: agentSkills, _mcpConnector }: AgentOptions): Agent;
|
|
1106
1603
|
|
|
1107
|
-
export { type
|
|
1604
|
+
export { type ToolDef as $, type Agent as A, type SessionContentBlock as B, CONTEXT_EXCEEDED_MESSAGE_PATTERNS as C, type SessionData as D, type SessionEndStatus as E, type SessionHookContext as F, type SessionMessage as G, type Harness as H, type ImageContent as I, type SessionRun as J, type SessionStore as K, type SessionTurn as L, type McpConnection as M, type SkillConfig as N, type OAuthRefreshHookContext as O, type PromptDocumentPart as P, type SkillResource as Q, type RemoteStoreOptions as R, type Session as S, type SkillsConfig as T, type SpawnHookContext as U, type StreamCallbacks as V, type StreamHookContext as W, type StreamOptions as X, type ThinkingLevel as Y, type ToolCall as Z, type ToolContext as _, AgentAbortedError as a, type ToolExecutionMode as a0, type ToolHookContext as a1, type ToolMap as a2, type ToolResult as a3, type ToolResultContent as a4, type ToolResultImageContent as a5, type ToolResultTextContent as a6, type ToolSpec as a7, type TurnFinishReason as a8, type TurnResult as a9, defineHarness as aA, fromAnthropic as aB, fromOpenAI as aC, loadSession as aD, mapOAIFinishReason as aE, noTools as aF, normalizeMcpBlocks as aG, normalizeMcpServers as aH, openai as aI, openaiCompat as aJ, openrouter as aK, resultToString as aL, toAnthropic as aM, toOpenAI as aN, toTypedError as aO, _default as aP, basicTools as aQ, type TurnUsage as aa, matchesContextExceeded as ab, toolResultToText as ac, type ActivationVia as ad, type ActiveSkill as ae, type DeactivationReason as af, type FileMapAdapter as ag, type FileMapStoreOptions as ah, type OpenAICompatAuthHeader as ai, OpenAICompatHttpError as aj, type OpenAICompatParams as ak, type SkillActivationState as al, type SkillActivationStateOptions as am, type SkillDiagnostic as an, type SkillSource as ao, anthropic as ap, autoDetectAndConvert as aq, cerebras as ar, classifyOpenAICompatError as as, connectMcpServers as at, createAgent as au, createFileMapStore as av, createMemoryStore as aw, createRemoteStore as ax, createSession as ay, createSkillActivationState as az, type AgentBehavior as b, AgentContextExceededError as c, type AgentHooks as d, type AgentOptions as e, AgentProviderError as f, type AgentRunOptions as g, type AgentStats as h, AgentToolNotAllowedError as i, type AnthropicParams as j, type CerebrasParams as k, type ChildRunStats as l, type ClassifiedError as m, type ClassifiedErrorKind as n, type CreateSessionOptions as o, type HarnessConfig as p, type McpServerConfig as q, type McpToolHookContext as r, type OpenAIParams as s, type OpenRouterParams as t, type PromptImagePart as u, type PromptPart as v, type PromptTextPart as w, type Provider as x, type ProviderCapabilities as y, type RunHookMap as z };
|