zidane 1.5.2 → 1.6.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 +18 -14
- package/dist/agent-DVvuhEN-.d.ts +671 -0
- package/dist/{chunk-PRNQ7DXE.js → chunk-3K5D27BF.js} +20 -59
- package/dist/chunk-7V33E7LT.js +32 -0
- package/dist/chunk-CFLC2I7D.js +8 -0
- package/dist/{chunk-XMFQK35S.js → chunk-VRAZJES3.js} +178 -271
- package/dist/{chunk-ZH2KFHLB.js → chunk-XT7QBZ47.js} +6 -6
- package/dist/{chunk-26LIQARN.js → chunk-YTZOORAP.js} +1 -10
- package/dist/harnesses.d.ts +2 -6
- package/dist/harnesses.js +4 -6
- package/dist/index.d.ts +21 -30
- package/dist/index.js +17 -21
- package/dist/mcp.d.ts +2 -6
- package/dist/mcp.js +1 -4
- package/dist/providers.d.ts +4 -82
- package/dist/providers.js +24 -1
- package/dist/sandbox-C08DQPTu.d.ts +28 -0
- package/dist/session.d.ts +4 -193
- package/dist/session.js +1 -2
- package/dist/skills.d.ts +2 -2
- package/dist/skills.js +2 -3
- package/dist/{spawn-MUlKj85h.d.ts → spawn-DJZZ9ZWw.d.ts} +1 -2
- package/dist/tools.d.ts +5 -18
- package/dist/tools.js +3 -6
- package/dist/{types-D8fzooXc.d.ts → types-CyRzBgm0.d.ts} +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.js +0 -0
- package/dist/validation-CwSuvOKf.d.ts +11 -0
- package/package.json +12 -1
- package/dist/agent-DZDheE1c.d.ts +0 -271
- package/dist/chunk-PNKVD2UK.js +0 -26
- package/dist/chunk-QPYZR2QM.js +0 -21
- package/dist/types-CskNDruh.d.ts +0 -110
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
import { Hookable } from 'hookable';
|
|
2
|
+
import { b as ExecutionContext, c as ExecutionHandle, e as SkillsConfig, S as SkillConfig } from './types-CyRzBgm0.js';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shared types for the agent system.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type ThinkingLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high';
|
|
10
|
+
interface McpServerConfig {
|
|
11
|
+
/** Display name (used for tool namespacing) */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Transport type */
|
|
14
|
+
transport: 'stdio' | 'sse' | 'streamable-http';
|
|
15
|
+
/** For stdio: command to run */
|
|
16
|
+
command?: string;
|
|
17
|
+
/** For stdio: command arguments */
|
|
18
|
+
args?: string[];
|
|
19
|
+
/** For stdio: environment variables */
|
|
20
|
+
env?: Record<string, string>;
|
|
21
|
+
/** For sse/streamable-http: server URL */
|
|
22
|
+
url?: string;
|
|
23
|
+
/** Optional headers for HTTP transports */
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
type ToolExecutionMode = 'sequential' | 'parallel';
|
|
27
|
+
interface AgentBehavior {
|
|
28
|
+
/** Tool execution mode (default: 'sequential') */
|
|
29
|
+
toolExecution?: ToolExecutionMode;
|
|
30
|
+
/** Max agent loop iterations (default: 50) */
|
|
31
|
+
maxTurns?: number;
|
|
32
|
+
/** Max tokens per LLM response (default: 16384) */
|
|
33
|
+
maxTokens?: number;
|
|
34
|
+
/** Thinking token budget — overrides the level-based default when set */
|
|
35
|
+
thinkingBudget?: number;
|
|
36
|
+
/** JSON Schema for structured output. When set, the agent's final turn produces JSON matching this schema. */
|
|
37
|
+
schema?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
interface ImageContent {
|
|
40
|
+
type: 'image';
|
|
41
|
+
source: {
|
|
42
|
+
type: 'base64';
|
|
43
|
+
media_type: string;
|
|
44
|
+
data: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
type SessionContentBlock = {
|
|
48
|
+
type: 'text';
|
|
49
|
+
text: string;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'image';
|
|
52
|
+
mediaType: string;
|
|
53
|
+
data: string;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'tool_call';
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
input: Record<string, unknown>;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'tool_result';
|
|
61
|
+
callId: string;
|
|
62
|
+
output: string;
|
|
63
|
+
isError?: boolean;
|
|
64
|
+
} | {
|
|
65
|
+
type: 'thinking';
|
|
66
|
+
text: string;
|
|
67
|
+
};
|
|
68
|
+
interface SessionMessage {
|
|
69
|
+
role: 'user' | 'assistant';
|
|
70
|
+
content: SessionContentBlock[];
|
|
71
|
+
}
|
|
72
|
+
interface SessionTurn {
|
|
73
|
+
/** UUID — generated by the store if it provides generateTurnId, else crypto.randomUUID() */
|
|
74
|
+
id: string;
|
|
75
|
+
/** Run that produced this turn (e.g. 'run_1') */
|
|
76
|
+
runId?: string;
|
|
77
|
+
role: 'user' | 'assistant' | 'system';
|
|
78
|
+
content: SessionContentBlock[];
|
|
79
|
+
/** Token usage — only present on assistant turns */
|
|
80
|
+
usage?: TurnUsage;
|
|
81
|
+
/** Unix timestamp (Date.now()) when the turn was created */
|
|
82
|
+
createdAt: number;
|
|
83
|
+
}
|
|
84
|
+
interface AgentRunOptions {
|
|
85
|
+
model?: string;
|
|
86
|
+
prompt: string;
|
|
87
|
+
system?: string;
|
|
88
|
+
thinking?: ThinkingLevel;
|
|
89
|
+
images?: ImageContent[];
|
|
90
|
+
/** Abort signal — when triggered, the agent stops after the current turn */
|
|
91
|
+
signal?: AbortSignal;
|
|
92
|
+
/** Behavior overrides for this run (overrides agent and harness defaults) */
|
|
93
|
+
behavior?: AgentBehavior;
|
|
94
|
+
/** Tool overrides for this run. Pass {} for no tools. Omit to use harness tools. */
|
|
95
|
+
tools?: Record<string, ToolDef>;
|
|
96
|
+
}
|
|
97
|
+
interface TurnUsage {
|
|
98
|
+
input: number;
|
|
99
|
+
output: number;
|
|
100
|
+
/** Tokens written to cache (Anthropic) */
|
|
101
|
+
cacheCreation?: number;
|
|
102
|
+
/** Tokens read from cache (Anthropic) */
|
|
103
|
+
cacheRead?: number;
|
|
104
|
+
/** Thinking/reasoning tokens used */
|
|
105
|
+
thinking?: number;
|
|
106
|
+
/** Cost in USD as reported by the provider (OpenRouter) */
|
|
107
|
+
cost?: number;
|
|
108
|
+
}
|
|
109
|
+
interface AgentStats {
|
|
110
|
+
totalIn: number;
|
|
111
|
+
totalOut: number;
|
|
112
|
+
turns: number;
|
|
113
|
+
elapsed: number;
|
|
114
|
+
/** Per-turn usage breakdown */
|
|
115
|
+
turnUsage?: TurnUsage[];
|
|
116
|
+
/** Total cost in USD (sum of per-turn costs reported by provider) */
|
|
117
|
+
cost?: number;
|
|
118
|
+
/** Stats from child agents spawned during this run */
|
|
119
|
+
children?: ChildRunStats[];
|
|
120
|
+
/** Structured output from schema enforcement (only present when behavior.schema is set) */
|
|
121
|
+
output?: Record<string, unknown>;
|
|
122
|
+
}
|
|
123
|
+
interface ChildRunStats {
|
|
124
|
+
id: string;
|
|
125
|
+
task: string;
|
|
126
|
+
stats: AgentStats;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface AnthropicParams {
|
|
130
|
+
apiKey?: string;
|
|
131
|
+
access?: string;
|
|
132
|
+
refresh?: string;
|
|
133
|
+
expires?: number;
|
|
134
|
+
defaultModel?: string;
|
|
135
|
+
}
|
|
136
|
+
declare function anthropic(anthropicParams?: AnthropicParams): Provider;
|
|
137
|
+
|
|
138
|
+
interface CerebrasParams {
|
|
139
|
+
apiKey?: string;
|
|
140
|
+
defaultModel?: string;
|
|
141
|
+
}
|
|
142
|
+
declare function cerebras(params?: CerebrasParams): Provider;
|
|
143
|
+
|
|
144
|
+
interface OpenRouterParams {
|
|
145
|
+
apiKey?: string;
|
|
146
|
+
defaultModel?: string;
|
|
147
|
+
}
|
|
148
|
+
declare function openrouter(params?: OpenRouterParams): Provider;
|
|
149
|
+
|
|
150
|
+
interface ToolSpec {
|
|
151
|
+
name: string;
|
|
152
|
+
description: string;
|
|
153
|
+
input_schema: Record<string, unknown>;
|
|
154
|
+
}
|
|
155
|
+
interface ToolCall {
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
input: Record<string, unknown>;
|
|
159
|
+
}
|
|
160
|
+
interface ToolResult {
|
|
161
|
+
id: string;
|
|
162
|
+
content: string;
|
|
163
|
+
}
|
|
164
|
+
interface StreamCallbacks {
|
|
165
|
+
onText: (delta: string) => void;
|
|
166
|
+
}
|
|
167
|
+
interface TurnResult {
|
|
168
|
+
/** Full assistant turn as a SessionMessage */
|
|
169
|
+
assistantMessage: SessionMessage;
|
|
170
|
+
/** Text content blocks concatenated */
|
|
171
|
+
text: string;
|
|
172
|
+
/** Tool calls requested by the model */
|
|
173
|
+
toolCalls: ToolCall[];
|
|
174
|
+
/** Whether the model wants to stop */
|
|
175
|
+
done: boolean;
|
|
176
|
+
usage: TurnUsage;
|
|
177
|
+
}
|
|
178
|
+
interface StreamOptions {
|
|
179
|
+
model: string;
|
|
180
|
+
system: string;
|
|
181
|
+
tools: unknown[];
|
|
182
|
+
messages: SessionMessage[];
|
|
183
|
+
maxTokens: number;
|
|
184
|
+
/** Thinking/reasoning level (optional, default: off) */
|
|
185
|
+
thinking?: ThinkingLevel;
|
|
186
|
+
/** Exact thinking token budget — overrides the level-based default when set */
|
|
187
|
+
thinkingBudget?: number;
|
|
188
|
+
/** Force tool selection behavior */
|
|
189
|
+
toolChoice?: {
|
|
190
|
+
type: 'auto' | 'required' | 'tool';
|
|
191
|
+
name?: string;
|
|
192
|
+
};
|
|
193
|
+
/** Abort signal for cancellation */
|
|
194
|
+
signal?: AbortSignal;
|
|
195
|
+
}
|
|
196
|
+
interface Provider {
|
|
197
|
+
readonly name: string;
|
|
198
|
+
readonly meta: {
|
|
199
|
+
defaultModel: string;
|
|
200
|
+
} & Record<string, unknown>;
|
|
201
|
+
/** Format tool specs for this provider */
|
|
202
|
+
formatTools: (tools: ToolSpec[]) => unknown[];
|
|
203
|
+
/** Create a user message (text or with images) */
|
|
204
|
+
userMessage: (content: string, images?: ImageContent[]) => SessionMessage;
|
|
205
|
+
/** Create an assistant message (for priming) */
|
|
206
|
+
assistantMessage: (content: string) => SessionMessage;
|
|
207
|
+
/** Create a tool results message to send back */
|
|
208
|
+
toolResultsMessage: (results: ToolResult[]) => SessionMessage;
|
|
209
|
+
/** Stream a turn, calling onText for each text delta */
|
|
210
|
+
stream: (options: StreamOptions, callbacks: StreamCallbacks) => Promise<TurnResult>;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Core tools available in every basic harness (without spawn) */
|
|
214
|
+
declare const basicTools: {
|
|
215
|
+
shell: ToolDef;
|
|
216
|
+
readFile: ToolDef;
|
|
217
|
+
writeFile: ToolDef;
|
|
218
|
+
listFiles: ToolDef;
|
|
219
|
+
};
|
|
220
|
+
declare const _default: HarnessConfig;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Runtime context passed to every tool execution.
|
|
224
|
+
* Provides access to the agent's provider, abort signal, execution environment, and hooks.
|
|
225
|
+
*/
|
|
226
|
+
interface ToolContext {
|
|
227
|
+
/** The LLM provider for this agent run */
|
|
228
|
+
provider: Provider;
|
|
229
|
+
/** Abort signal — tools should check this for early termination */
|
|
230
|
+
signal: AbortSignal;
|
|
231
|
+
/** The execution context (shell, filesystem, etc.) */
|
|
232
|
+
execution: ExecutionContext;
|
|
233
|
+
/** The active execution handle for the current agent run */
|
|
234
|
+
handle: ExecutionHandle;
|
|
235
|
+
/** Agent hooks for emitting events (e.g. spawn:complete) */
|
|
236
|
+
hooks: Hookable<AgentHooks>;
|
|
237
|
+
/** The harness config for this agent (tools available to the agent) */
|
|
238
|
+
harness: HarnessConfig;
|
|
239
|
+
}
|
|
240
|
+
interface ToolDef {
|
|
241
|
+
spec: ToolSpec;
|
|
242
|
+
execute: (input: Record<string, unknown>, ctx: ToolContext) => Promise<string>;
|
|
243
|
+
}
|
|
244
|
+
type ToolMap = Map<string, ToolDef>;
|
|
245
|
+
interface HarnessConfig {
|
|
246
|
+
/** Display name for this harness */
|
|
247
|
+
name: string;
|
|
248
|
+
/** Default system prompt injected when no system is provided at run time */
|
|
249
|
+
system?: string;
|
|
250
|
+
/** Tool definitions available to the agent */
|
|
251
|
+
tools: Record<string, ToolDef>;
|
|
252
|
+
/** MCP servers to connect and expose as tools */
|
|
253
|
+
mcpServers?: McpServerConfig[];
|
|
254
|
+
/** Skills configuration at the harness level */
|
|
255
|
+
skills?: SkillsConfig;
|
|
256
|
+
/** Default behavior for agents using this harness */
|
|
257
|
+
behavior?: AgentBehavior;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Define a harness with a name, optional system prompt, and tools.
|
|
261
|
+
*/
|
|
262
|
+
declare function defineHarness(config: HarnessConfig): HarnessConfig;
|
|
263
|
+
type Harness = HarnessConfig;
|
|
264
|
+
/**
|
|
265
|
+
* A harness with no tools — for pure chat mode.
|
|
266
|
+
* Pass `tools: {}` in agent.run() or use this harness directly.
|
|
267
|
+
*/
|
|
268
|
+
declare const noTools: HarnessConfig;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* MCP (Model Context Protocol) server support.
|
|
272
|
+
*
|
|
273
|
+
* Connects to one or more MCP servers, discovers their tools,
|
|
274
|
+
* and wraps them as zidane ToolDefs for use in agent loops.
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
interface McpConnection {
|
|
278
|
+
tools: Record<string, ToolDef>;
|
|
279
|
+
close: () => Promise<void>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Convert MCP tool result content blocks to a single string.
|
|
283
|
+
* Text blocks are extracted; non-text blocks are JSON-stringified.
|
|
284
|
+
*/
|
|
285
|
+
declare function resultToString(content: unknown[]): string;
|
|
286
|
+
/**
|
|
287
|
+
* Connect to MCP servers and discover their tools.
|
|
288
|
+
*
|
|
289
|
+
* Each tool is namespaced as `mcp_{serverName}_{toolName}` to avoid
|
|
290
|
+
* collisions with harness tools or tools from other servers.
|
|
291
|
+
*
|
|
292
|
+
* @param configs - Array of MCP server configurations
|
|
293
|
+
* @param _clientFactory - Internal: override client construction for testing
|
|
294
|
+
* @param hooks - Optional agent hooks for firing mcp:connect, mcp:error, mcp:close events
|
|
295
|
+
*/
|
|
296
|
+
declare function connectMcpServers(configs: McpServerConfig[], _clientFactory?: () => Client, hooks?: Hookable<AgentHooks>): Promise<McpConnection>;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* In-memory session store.
|
|
300
|
+
* Useful for development and testing. Data is lost when the process exits.
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
declare function createMemoryStore(): SessionStore;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Canonical SessionMessage format with converters from/to Anthropic and OpenAI-compat formats.
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
declare function fromAnthropic(msg: {
|
|
310
|
+
role: string;
|
|
311
|
+
content: unknown;
|
|
312
|
+
}): SessionMessage;
|
|
313
|
+
declare function fromOpenAI(msg: {
|
|
314
|
+
role: string;
|
|
315
|
+
content: unknown;
|
|
316
|
+
}): SessionMessage;
|
|
317
|
+
declare function toAnthropic(msg: SessionMessage): {
|
|
318
|
+
role: string;
|
|
319
|
+
content: unknown;
|
|
320
|
+
};
|
|
321
|
+
declare function toOpenAI(msg: SessionMessage): {
|
|
322
|
+
role: string;
|
|
323
|
+
content: unknown;
|
|
324
|
+
};
|
|
325
|
+
declare function autoDetectAndConvert(msg: {
|
|
326
|
+
role: string;
|
|
327
|
+
content: unknown;
|
|
328
|
+
}): SessionMessage;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Remote session store via HTTP API.
|
|
332
|
+
*
|
|
333
|
+
* Expects a REST API with:
|
|
334
|
+
* GET {url}/sessions/{id} -> SessionData | 404
|
|
335
|
+
* PUT {url}/sessions/{id} -> save SessionData
|
|
336
|
+
* DELETE {url}/sessions/{id} -> delete
|
|
337
|
+
* GET {url}/sessions?agentId=&limit= -> { ids: string[] }
|
|
338
|
+
* POST {url}/sessions/{id}/turns -> append turns
|
|
339
|
+
* GET {url}/sessions/{id}/turns?from=&limit= -> SessionTurn[]
|
|
340
|
+
* PUT {url}/sessions/{id}/runs/{runId} -> update run
|
|
341
|
+
* PATCH {url}/sessions/{id} -> { status }
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
interface RemoteStoreOptions {
|
|
345
|
+
/** Base URL of the session API */
|
|
346
|
+
url: string;
|
|
347
|
+
/** Optional headers (e.g. for authentication) */
|
|
348
|
+
headers?: Record<string, string>;
|
|
349
|
+
}
|
|
350
|
+
declare function createRemoteStore(options: RemoteStoreOptions): SessionStore;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* SQLite session store using Bun's built-in bun:sqlite.
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
interface SqliteStoreOptions {
|
|
357
|
+
/** Path to the SQLite database file */
|
|
358
|
+
path: string;
|
|
359
|
+
}
|
|
360
|
+
declare function createSqliteStore(options: SqliteStoreOptions): SessionStore;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Session management for agents.
|
|
364
|
+
*
|
|
365
|
+
* A session tracks identity, turn history, and run metadata.
|
|
366
|
+
* Plug in any storage backend by implementing the SessionStore interface,
|
|
367
|
+
* or use one of the built-in stores: memory, sqlite, remote.
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
interface SessionRun {
|
|
371
|
+
id: string;
|
|
372
|
+
startedAt: number;
|
|
373
|
+
endedAt?: number;
|
|
374
|
+
prompt: string;
|
|
375
|
+
status: 'running' | 'completed' | 'aborted' | 'error';
|
|
376
|
+
turns?: number;
|
|
377
|
+
tokensIn?: number;
|
|
378
|
+
tokensOut?: number;
|
|
379
|
+
error?: string;
|
|
380
|
+
/** Per-turn usage breakdown */
|
|
381
|
+
turnUsage?: TurnUsage[];
|
|
382
|
+
/** Total usage across all turns */
|
|
383
|
+
totalUsage?: TurnUsage;
|
|
384
|
+
/** Estimated cost in USD */
|
|
385
|
+
cost?: number;
|
|
386
|
+
}
|
|
387
|
+
interface SessionData {
|
|
388
|
+
id: string;
|
|
389
|
+
agentId?: string;
|
|
390
|
+
turns: SessionTurn[];
|
|
391
|
+
runs: SessionRun[];
|
|
392
|
+
status: 'idle' | 'running' | 'completed' | 'error';
|
|
393
|
+
metadata: Record<string, unknown>;
|
|
394
|
+
createdAt: number;
|
|
395
|
+
updatedAt: number;
|
|
396
|
+
}
|
|
397
|
+
interface SessionStore {
|
|
398
|
+
/** Optional: generate a session ID server-side (e.g. Supabase UUID). */
|
|
399
|
+
generateSessionId?: () => string | Promise<string>;
|
|
400
|
+
/** Optional: generate a turn ID server-side. */
|
|
401
|
+
generateTurnId?: () => string | Promise<string>;
|
|
402
|
+
/** Load a session by ID. Returns null if not found. */
|
|
403
|
+
load: (sessionId: string) => Promise<SessionData | null>;
|
|
404
|
+
/** Save a session (create or update, full document). */
|
|
405
|
+
save: (session: SessionData) => Promise<void>;
|
|
406
|
+
/** Delete a session. */
|
|
407
|
+
delete: (sessionId: string) => Promise<void>;
|
|
408
|
+
/** List session IDs, optionally filtered. */
|
|
409
|
+
list: (filter?: {
|
|
410
|
+
agentId?: string;
|
|
411
|
+
limit?: number;
|
|
412
|
+
}) => Promise<string[]>;
|
|
413
|
+
/** Append new turns to a session (incremental, avoids full re-save). */
|
|
414
|
+
appendTurns: (sessionId: string, turns: SessionTurn[]) => Promise<void>;
|
|
415
|
+
/** Return a slice of turns for a session. */
|
|
416
|
+
getTurns: (sessionId: string, from?: number, limit?: number) => Promise<SessionTurn[]>;
|
|
417
|
+
/** Persist an updated run record (called after completeRun / abortRun / errorRun). */
|
|
418
|
+
updateRun: (sessionId: string, run: SessionRun) => Promise<void>;
|
|
419
|
+
/** Update the top-level status of a session. */
|
|
420
|
+
updateStatus: (sessionId: string, status: SessionData['status']) => Promise<void>;
|
|
421
|
+
}
|
|
422
|
+
interface Session {
|
|
423
|
+
/** Session ID */
|
|
424
|
+
readonly id: string;
|
|
425
|
+
/** Agent ID (optional label) */
|
|
426
|
+
readonly agentId?: string;
|
|
427
|
+
/** Current turn history */
|
|
428
|
+
readonly turns: SessionTurn[];
|
|
429
|
+
/** Top-level session status */
|
|
430
|
+
readonly status: SessionData['status'];
|
|
431
|
+
/** All runs in this session */
|
|
432
|
+
readonly runs: SessionRun[];
|
|
433
|
+
/** Arbitrary metadata */
|
|
434
|
+
readonly metadata: Record<string, unknown>;
|
|
435
|
+
/** Start tracking a new run */
|
|
436
|
+
startRun: (runId: string, prompt: string) => void;
|
|
437
|
+
/** Mark a run as completed */
|
|
438
|
+
completeRun: (runId: string, stats: {
|
|
439
|
+
turns: number;
|
|
440
|
+
tokensIn: number;
|
|
441
|
+
tokensOut: number;
|
|
442
|
+
turnUsage?: TurnUsage[];
|
|
443
|
+
cost?: number;
|
|
444
|
+
}) => void;
|
|
445
|
+
/** Mark a run as aborted */
|
|
446
|
+
abortRun: (runId: string) => void;
|
|
447
|
+
/** Mark a run as errored */
|
|
448
|
+
errorRun: (runId: string, error: string) => void;
|
|
449
|
+
/** Append turns to in-memory history AND persist via store.appendTurns (if store present) */
|
|
450
|
+
appendTurns: (turns: SessionTurn[]) => Promise<void>;
|
|
451
|
+
/** Replace all turns in-memory (does not persist — use save() for that) */
|
|
452
|
+
setTurns: (turns: SessionTurn[]) => void;
|
|
453
|
+
/** Update the session status in memory AND via store.updateStatus (if store present) */
|
|
454
|
+
updateStatus: (status: SessionData['status']) => Promise<void>;
|
|
455
|
+
/** Persist an updated run record via store.updateRun (if store present) */
|
|
456
|
+
updateRun: (run: SessionRun) => Promise<void>;
|
|
457
|
+
/** Generate a turn ID using store.generateTurnId if available, else crypto.randomUUID() */
|
|
458
|
+
generateTurnId: () => string | Promise<string>;
|
|
459
|
+
/** Set metadata key */
|
|
460
|
+
setMeta: (key: string, value: unknown) => void;
|
|
461
|
+
/** Persist the full session document to the store */
|
|
462
|
+
save: () => Promise<void>;
|
|
463
|
+
/** Serialize to SessionData */
|
|
464
|
+
toJSON: () => SessionData;
|
|
465
|
+
}
|
|
466
|
+
interface CreateSessionOptions {
|
|
467
|
+
/** Session ID. If omitted and store provides generateSessionId, that is used. */
|
|
468
|
+
id?: string;
|
|
469
|
+
/** Agent ID label */
|
|
470
|
+
agentId?: string;
|
|
471
|
+
/** Initial metadata */
|
|
472
|
+
metadata?: Record<string, unknown>;
|
|
473
|
+
/** Storage backend (optional, enables save/load) */
|
|
474
|
+
store?: SessionStore;
|
|
475
|
+
_data?: SessionData;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Create a new session.
|
|
479
|
+
* Async so stores that generate IDs server-side (e.g. Supabase) can be supported.
|
|
480
|
+
*/
|
|
481
|
+
declare function createSession(options?: CreateSessionOptions): Promise<Session>;
|
|
482
|
+
/**
|
|
483
|
+
* Load an existing session from a store.
|
|
484
|
+
*/
|
|
485
|
+
declare function loadSession(store: SessionStore, sessionId: string): Promise<Session | null>;
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Agent creation and state management.
|
|
489
|
+
*/
|
|
490
|
+
|
|
491
|
+
interface AgentHooks {
|
|
492
|
+
'system:before': (ctx: {
|
|
493
|
+
system: string;
|
|
494
|
+
}) => void;
|
|
495
|
+
'turn:before': (ctx: {
|
|
496
|
+
turn: number;
|
|
497
|
+
turnId: string;
|
|
498
|
+
options: StreamOptions;
|
|
499
|
+
}) => void;
|
|
500
|
+
'turn:after': (ctx: {
|
|
501
|
+
turn: number;
|
|
502
|
+
turnId: string;
|
|
503
|
+
usage: TurnUsage;
|
|
504
|
+
message: SessionTurn;
|
|
505
|
+
}) => void;
|
|
506
|
+
'stream:text': (ctx: {
|
|
507
|
+
delta: string;
|
|
508
|
+
text: string;
|
|
509
|
+
turnId: string;
|
|
510
|
+
blockIndex: number;
|
|
511
|
+
}) => void;
|
|
512
|
+
'stream:end': (ctx: {
|
|
513
|
+
text: string;
|
|
514
|
+
turnId: string;
|
|
515
|
+
blockIndex: number;
|
|
516
|
+
}) => void;
|
|
517
|
+
'tool:before': (ctx: {
|
|
518
|
+
name: string;
|
|
519
|
+
input: Record<string, unknown>;
|
|
520
|
+
}) => void;
|
|
521
|
+
'tool:after': (ctx: {
|
|
522
|
+
name: string;
|
|
523
|
+
input: Record<string, unknown>;
|
|
524
|
+
result: string;
|
|
525
|
+
}) => void;
|
|
526
|
+
'tool:error': (ctx: {
|
|
527
|
+
name: string;
|
|
528
|
+
input: Record<string, unknown>;
|
|
529
|
+
error: Error;
|
|
530
|
+
}) => void;
|
|
531
|
+
'tool:gate': (ctx: {
|
|
532
|
+
name: string;
|
|
533
|
+
input: Record<string, unknown>;
|
|
534
|
+
block: boolean;
|
|
535
|
+
reason: string;
|
|
536
|
+
}) => void;
|
|
537
|
+
'tool:transform': (ctx: {
|
|
538
|
+
name: string;
|
|
539
|
+
input: Record<string, unknown>;
|
|
540
|
+
result: string;
|
|
541
|
+
isError: boolean;
|
|
542
|
+
}) => void;
|
|
543
|
+
'context:transform': (ctx: {
|
|
544
|
+
messages: SessionMessage[];
|
|
545
|
+
}) => void;
|
|
546
|
+
'steer:inject': (ctx: {
|
|
547
|
+
message: string;
|
|
548
|
+
}) => void;
|
|
549
|
+
'spawn:complete': (ctx: ChildRunStats) => void;
|
|
550
|
+
'spawn:before': (ctx: {
|
|
551
|
+
id: string;
|
|
552
|
+
task: string;
|
|
553
|
+
}) => void;
|
|
554
|
+
'spawn:error': (ctx: {
|
|
555
|
+
id: string;
|
|
556
|
+
task: string;
|
|
557
|
+
error: Error;
|
|
558
|
+
}) => void;
|
|
559
|
+
'mcp:connect': (ctx: {
|
|
560
|
+
name: string;
|
|
561
|
+
transport: string;
|
|
562
|
+
tools: string[];
|
|
563
|
+
}) => void;
|
|
564
|
+
'mcp:error': (ctx: {
|
|
565
|
+
name: string;
|
|
566
|
+
error: Error;
|
|
567
|
+
}) => void;
|
|
568
|
+
'mcp:close': (ctx: {
|
|
569
|
+
name: string;
|
|
570
|
+
}) => void;
|
|
571
|
+
'mcp:tool:before': (ctx: {
|
|
572
|
+
server: string;
|
|
573
|
+
tool: string;
|
|
574
|
+
input: Record<string, unknown>;
|
|
575
|
+
}) => void;
|
|
576
|
+
'mcp:tool:after': (ctx: {
|
|
577
|
+
server: string;
|
|
578
|
+
tool: string;
|
|
579
|
+
input: Record<string, unknown>;
|
|
580
|
+
result: string;
|
|
581
|
+
}) => void;
|
|
582
|
+
'mcp:tool:error': (ctx: {
|
|
583
|
+
server: string;
|
|
584
|
+
tool: string;
|
|
585
|
+
input: Record<string, unknown>;
|
|
586
|
+
error: Error;
|
|
587
|
+
}) => void;
|
|
588
|
+
'skills:resolve': (ctx: {
|
|
589
|
+
skills: SkillConfig[];
|
|
590
|
+
}) => void;
|
|
591
|
+
'skills:catalog': (ctx: {
|
|
592
|
+
catalog: string;
|
|
593
|
+
skills: SkillConfig[];
|
|
594
|
+
}) => void;
|
|
595
|
+
'skills:activate': (ctx: {
|
|
596
|
+
skill: SkillConfig;
|
|
597
|
+
}) => void;
|
|
598
|
+
'usage': (ctx: {
|
|
599
|
+
turn: number;
|
|
600
|
+
turnId: string;
|
|
601
|
+
usage: TurnUsage;
|
|
602
|
+
totalIn: number;
|
|
603
|
+
totalOut: number;
|
|
604
|
+
}) => void;
|
|
605
|
+
'output': (ctx: {
|
|
606
|
+
output: Record<string, unknown>;
|
|
607
|
+
schema: Record<string, unknown>;
|
|
608
|
+
}) => void;
|
|
609
|
+
'agent:abort': (ctx: object) => void;
|
|
610
|
+
'agent:done': (ctx: AgentStats) => void;
|
|
611
|
+
'session:start': (ctx: {
|
|
612
|
+
sessionId: string;
|
|
613
|
+
runId: string;
|
|
614
|
+
prompt: string;
|
|
615
|
+
}) => void;
|
|
616
|
+
'session:end': (ctx: {
|
|
617
|
+
sessionId: string;
|
|
618
|
+
runId: string;
|
|
619
|
+
status: 'completed' | 'aborted' | 'error';
|
|
620
|
+
turnRange: [number, number];
|
|
621
|
+
}) => void;
|
|
622
|
+
'session:turns': (ctx: {
|
|
623
|
+
sessionId: string;
|
|
624
|
+
count: number;
|
|
625
|
+
}) => void;
|
|
626
|
+
'session:meta': (ctx: {
|
|
627
|
+
sessionId: string;
|
|
628
|
+
key: string;
|
|
629
|
+
value: unknown;
|
|
630
|
+
}) => void;
|
|
631
|
+
'session:save': (ctx: {
|
|
632
|
+
sessionId: string;
|
|
633
|
+
}) => void;
|
|
634
|
+
}
|
|
635
|
+
interface AgentOptions {
|
|
636
|
+
/** Harness (tools + system prompt). Defaults to a no-tools harness if omitted. */
|
|
637
|
+
harness?: HarnessConfig;
|
|
638
|
+
provider: Provider;
|
|
639
|
+
/** Agent-level behavior defaults (overridden by run-level behavior) */
|
|
640
|
+
behavior?: AgentBehavior;
|
|
641
|
+
/** Execution context: where tools run. Defaults to in-process. */
|
|
642
|
+
execution?: ExecutionContext;
|
|
643
|
+
/** MCP servers to connect and expose as tools */
|
|
644
|
+
mcpServers?: McpServerConfig[];
|
|
645
|
+
/** Session for identity, turn persistence, and run tracking */
|
|
646
|
+
session?: Session;
|
|
647
|
+
/** Skills configuration (merged with harness-level skills, agent takes precedence) */
|
|
648
|
+
skills?: SkillsConfig;
|
|
649
|
+
/** @internal */
|
|
650
|
+
_mcpConnector?: (configs: McpServerConfig[]) => Promise<McpConnection>;
|
|
651
|
+
}
|
|
652
|
+
interface Agent {
|
|
653
|
+
hooks: Hookable<AgentHooks>;
|
|
654
|
+
run: (options: AgentRunOptions) => Promise<AgentStats>;
|
|
655
|
+
abort: () => void;
|
|
656
|
+
steer: (message: string) => void;
|
|
657
|
+
followUp: (message: string) => void;
|
|
658
|
+
waitForIdle: () => Promise<void>;
|
|
659
|
+
reset: () => void;
|
|
660
|
+
/** Destroy the execution context and clean up resources */
|
|
661
|
+
destroy: () => Promise<void>;
|
|
662
|
+
readonly isRunning: boolean;
|
|
663
|
+
readonly turns: SessionTurn[];
|
|
664
|
+
readonly execution: ExecutionContext;
|
|
665
|
+
readonly handle: ExecutionHandle | null;
|
|
666
|
+
readonly session: Session | null;
|
|
667
|
+
meta: Record<string, unknown>;
|
|
668
|
+
}
|
|
669
|
+
declare function createAgent({ harness: harnessOption, provider, behavior: agentBehavior, execution, mcpServers, session, skills: agentSkills, _mcpConnector }: AgentOptions): Agent;
|
|
670
|
+
|
|
671
|
+
export { cerebras as $, type Agent as A, type TurnResult as B, type CerebrasParams as C, type TurnUsage as D, autoDetectAndConvert as E, connectMcpServers as F, createAgent as G, type Harness as H, type ImageContent as I, createMemoryStore as J, createRemoteStore as K, createSession as L, type McpConnection as M, createSqliteStore as N, type OpenRouterParams as O, type Provider as P, defineHarness as Q, type RemoteStoreOptions as R, type Session as S, type ThinkingLevel as T, fromAnthropic as U, fromOpenAI as V, loadSession as W, noTools as X, toAnthropic as Y, toOpenAI as Z, anthropic as _, type AgentBehavior as a, openrouter as a0, _default as a1, basicTools as a2, resultToString as a3, type AgentHooks as b, type AgentOptions as c, type AgentRunOptions as d, type AgentStats as e, type AnthropicParams as f, type ChildRunStats as g, type CreateSessionOptions as h, type HarnessConfig as i, type McpServerConfig as j, type SessionContentBlock as k, type SessionData as l, type SessionMessage as m, type SessionRun as n, type SessionStore as o, type SessionTurn as p, type SqliteStoreOptions as q, type StreamCallbacks as r, type StreamOptions as s, type ToolCall as t, type ToolContext as u, type ToolDef as v, type ToolExecutionMode as w, type ToolMap as x, type ToolResult as y, type ToolSpec as z };
|