@evolvingmachines/sdk 0.0.2

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.
@@ -0,0 +1,2393 @@
1
+ import * as zod from 'zod';
2
+ import { z } from 'zod';
3
+ import { EventEmitter } from 'events';
4
+
5
+ /**
6
+ * ACP-inspired output types for unified agent event streaming.
7
+ * These types are independent of @agentclientprotocol/sdk.
8
+ *
9
+ * ACP schema reference:
10
+ * MANUS-API/KNOWLEDGE/acp-typescript-sdk/src/schema/types.gen.ts
11
+ * (SessionUpdate, ContentBlock, ImageContent, TextContent, ToolCall, ToolCallUpdate, Plan)
12
+ *
13
+ * INTERNAL REFERENCE - JSDoc stripped from published package.
14
+ *
15
+ * @example Event Flow
16
+ * ```
17
+ * agent_message_chunk → Text/image streaming from agent
18
+ * agent_thought_chunk → Reasoning (Codex) or thinking (Claude)
19
+ * user_message_chunk → User message echo (Gemini)
20
+ * tool_call → Tool started (status: pending/in_progress)
21
+ * tool_call_update → Tool finished (status: completed/failed)
22
+ * plan → TodoWrite updates
23
+ * ```
24
+ *
25
+ * @example UI Integration
26
+ * ```ts
27
+ * evolve.on('content', (event: OutputEvent) => {
28
+ * switch (event.update.sessionUpdate) {
29
+ * case 'agent_message_chunk':
30
+ * appendToChat(event.update.content);
31
+ * break;
32
+ * case 'tool_call':
33
+ * addToolCard(event.update.toolCallId, event.update.title);
34
+ * break;
35
+ * case 'tool_call_update':
36
+ * updateToolCard(event.update.toolCallId, event.update.status);
37
+ * break;
38
+ * }
39
+ * });
40
+ * ```
41
+ */
42
+ /**
43
+ * Tool operation category for UI grouping/icons.
44
+ *
45
+ * | Kind | Tools | Icon suggestion |
46
+ * |------|-------|-----------------|
47
+ * | read | Read, NotebookRead | 📄 |
48
+ * | edit | Edit, Write, NotebookEdit | ✏️ |
49
+ * | delete | (future) | 🗑️ |
50
+ * | move | (future) | 📦 |
51
+ * | search | Glob, Grep, LS | 🔍 |
52
+ * | execute | Bash, BashOutput, KillShell | ⚡ |
53
+ * | think | Task (subagent) | 🧠 |
54
+ * | fetch | WebFetch, WebSearch | 🌐 |
55
+ * | switch_mode | ExitPlanMode | 🔀 |
56
+ * | other | MCP tools, unknown | ❓ |
57
+ */
58
+ type ToolKind = "read" | "edit" | "delete" | "move" | "search" | "execute" | "think" | "fetch" | "switch_mode" | "other";
59
+ /**
60
+ * Tool execution lifecycle.
61
+ *
62
+ * Flow: pending → in_progress → completed|failed
63
+ *
64
+ * - pending: Tool call received, not yet executing
65
+ * - in_progress: Tool is executing (Codex command_execution)
66
+ * - completed: Tool finished successfully
67
+ * - failed: Tool errored (check content for error message)
68
+ */
69
+ type ToolCallStatus = "pending" | "in_progress" | "completed" | "failed";
70
+ /**
71
+ * Plan/Todo item status.
72
+ */
73
+ type PlanEntryStatus = "pending" | "in_progress" | "completed";
74
+ /**
75
+ * Text content block.
76
+ */
77
+ interface TextContent {
78
+ type: "text";
79
+ text: string;
80
+ }
81
+ /**
82
+ * Image content block (base64 or URL).
83
+ */
84
+ interface ImageContent {
85
+ type: "image";
86
+ /** Base64-encoded image data */
87
+ data: string;
88
+ /** MIME type (e.g., "image/png") */
89
+ mimeType: string;
90
+ /** Optional URL if image is remote */
91
+ uri?: string;
92
+ }
93
+ /**
94
+ * Diff content for file edits.
95
+ */
96
+ interface DiffContent {
97
+ type: "diff";
98
+ /** File path being edited */
99
+ path: string;
100
+ /** Original text (null for new files) */
101
+ oldText: string | null;
102
+ /** New text after edit */
103
+ newText: string;
104
+ }
105
+ /**
106
+ * Content that can appear in messages.
107
+ */
108
+ type ContentBlock = TextContent | ImageContent;
109
+ /**
110
+ * Content attached to tool calls.
111
+ * Either wrapped content or a diff.
112
+ */
113
+ type ToolCallContent = {
114
+ type: "content";
115
+ content: ContentBlock;
116
+ } | DiffContent;
117
+ /**
118
+ * File location affected by a tool call.
119
+ */
120
+ interface ToolCallLocation {
121
+ /** Absolute file path */
122
+ path: string;
123
+ /** Line number (0-indexed for Read offset) */
124
+ line?: number;
125
+ }
126
+ /**
127
+ * Todo/plan entry from TodoWrite.
128
+ */
129
+ interface PlanEntry {
130
+ /** Task description */
131
+ content: string;
132
+ /** Current status */
133
+ status: PlanEntryStatus;
134
+ /** Priority level */
135
+ priority: "high" | "medium" | "low";
136
+ }
137
+ /**
138
+ * All possible session update types.
139
+ * Discriminated union on `sessionUpdate` field.
140
+ */
141
+ type SessionUpdate = AgentMessageChunk | AgentThoughtChunk | UserMessageChunk | ToolCall | ToolCallUpdate | Plan;
142
+ /**
143
+ * Streaming text/image from agent.
144
+ * May arrive in multiple chunks - concatenate text.
145
+ */
146
+ interface AgentMessageChunk {
147
+ sessionUpdate: "agent_message_chunk";
148
+ content: ContentBlock;
149
+ }
150
+ /**
151
+ * Agent reasoning/thinking (not shown to end user by default).
152
+ * - Codex: "reasoning" item type
153
+ * - Claude: "thinking" content block
154
+ */
155
+ interface AgentThoughtChunk {
156
+ sessionUpdate: "agent_thought_chunk";
157
+ content: ContentBlock;
158
+ }
159
+ /**
160
+ * User message echo (primarily from Gemini).
161
+ */
162
+ interface UserMessageChunk {
163
+ sessionUpdate: "user_message_chunk";
164
+ content: ContentBlock;
165
+ }
166
+ /**
167
+ * Tool call started.
168
+ *
169
+ * Match with ToolCallUpdate via `toolCallId`.
170
+ *
171
+ * @example Claude Read tool
172
+ * ```json
173
+ * {
174
+ * "sessionUpdate": "tool_call",
175
+ * "toolCallId": "toolu_01ABC...",
176
+ * "title": "Read /src/index.ts (1 - 100)",
177
+ * "kind": "read",
178
+ * "status": "pending",
179
+ * "locations": [{ "path": "/src/index.ts", "line": 0 }]
180
+ * }
181
+ * ```
182
+ */
183
+ interface ToolCall {
184
+ sessionUpdate: "tool_call";
185
+ /** Unique ID to match with ToolCallUpdate */
186
+ toolCallId: string;
187
+ /** Human-readable title (e.g., "`npm install`", "Read /path/file.ts") */
188
+ title: string;
189
+ /** Tool category for UI grouping */
190
+ kind: ToolKind;
191
+ /** Execution status */
192
+ status: ToolCallStatus;
193
+ /** Original tool input parameters */
194
+ rawInput?: unknown;
195
+ /** Diff for edits, description for commands */
196
+ content?: ToolCallContent[];
197
+ /** File paths affected */
198
+ locations?: ToolCallLocation[];
199
+ }
200
+ /**
201
+ * Tool call completed/failed.
202
+ *
203
+ * Match with ToolCall via `toolCallId`.
204
+ *
205
+ * @example Successful completion
206
+ * ```json
207
+ * {
208
+ * "sessionUpdate": "tool_call_update",
209
+ * "toolCallId": "toolu_01ABC...",
210
+ * "status": "completed",
211
+ * "content": [{ "type": "content", "content": { "type": "text", "text": "..." } }]
212
+ * }
213
+ * ```
214
+ *
215
+ * @example Failed tool
216
+ * ```json
217
+ * {
218
+ * "sessionUpdate": "tool_call_update",
219
+ * "toolCallId": "toolu_01ABC...",
220
+ * "status": "failed",
221
+ * "content": [{ "type": "content", "content": { "type": "text", "text": "```\nError: ...\n```" } }]
222
+ * }
223
+ * ```
224
+ *
225
+ * @example Browser-Use MCP tool response
226
+ * The browser-use MCP tool returns a JSON string in content[].content.text:
227
+ * ```json
228
+ * {
229
+ * "sessionUpdate": "tool_call_update",
230
+ * "toolCallId": "...",
231
+ * "status": "completed",
232
+ * "content": [{
233
+ * "type": "content",
234
+ * "content": {
235
+ * "type": "text",
236
+ * "text": "{\"live_url\":\"https://...\",\"screenshot_url\":\"https://...\",\"steps\":[{\"screenshot_url\":\"https://...\"}]}"
237
+ * }
238
+ * }]
239
+ * }
240
+ * ```
241
+ * The `text` field contains a JSON string with:
242
+ * - `live_url`: URL for live browser view (VNC/noVNC)
243
+ * - `screenshot_url`: URL for screenshot image
244
+ * - `steps[].screenshot_url`: Alternative location for screenshots
245
+ */
246
+ interface ToolCallUpdate {
247
+ sessionUpdate: "tool_call_update";
248
+ /** Matches ToolCall.toolCallId */
249
+ toolCallId: string;
250
+ /** Final status */
251
+ status?: ToolCallStatus;
252
+ /** Updated title (e.g., "Exited Plan Mode") */
253
+ title?: string;
254
+ /** Output content or error message */
255
+ content?: ToolCallContent[];
256
+ /** Updated locations (rare) */
257
+ locations?: ToolCallLocation[];
258
+ }
259
+ /**
260
+ * Todo list update from TodoWrite tool.
261
+ * Replaces entire todo list on each update.
262
+ */
263
+ interface Plan {
264
+ sessionUpdate: "plan";
265
+ /** All current plan entries */
266
+ entries: PlanEntry[];
267
+ }
268
+ /**
269
+ * Top-level event emitted by Evolve 'content' event.
270
+ *
271
+ * @example
272
+ * ```ts
273
+ * evolve.on('content', (event: OutputEvent) => {
274
+ * console.log(event.sessionId, event.update.sessionUpdate);
275
+ * });
276
+ * ```
277
+ */
278
+ interface OutputEvent {
279
+ /** Session ID (from agent, may be undefined) */
280
+ sessionId?: string;
281
+ /** The session update payload */
282
+ update: SessionUpdate;
283
+ }
284
+
285
+ /** Result of a completed sandbox command */
286
+ interface SandboxCommandResult {
287
+ exitCode: number;
288
+ stdout: string;
289
+ stderr: string;
290
+ }
291
+ /** Handle to a running background process in sandbox */
292
+ interface SandboxCommandHandle {
293
+ readonly pid: number;
294
+ wait(): Promise<SandboxCommandResult>;
295
+ kill(): Promise<boolean>;
296
+ }
297
+ /** Information about a running process */
298
+ interface ProcessInfo {
299
+ pid: number;
300
+ cmd: string;
301
+ args: string[];
302
+ envs: Record<string, string>;
303
+ cwd?: string;
304
+ tag?: string;
305
+ }
306
+ /** Options for command execution */
307
+ interface SandboxRunOptions {
308
+ timeoutMs?: number;
309
+ envs?: Record<string, string>;
310
+ cwd?: string;
311
+ onStdout?: (data: string) => void;
312
+ onStderr?: (data: string) => void;
313
+ }
314
+ /** Options for spawning background processes in sandbox */
315
+ interface SandboxSpawnOptions extends SandboxRunOptions {
316
+ stdin?: boolean;
317
+ }
318
+ /** Options for creating a sandbox */
319
+ interface SandboxCreateOptions {
320
+ templateId: string;
321
+ envs?: Record<string, string>;
322
+ metadata?: Record<string, string>;
323
+ timeoutMs?: number;
324
+ workingDirectory?: string;
325
+ }
326
+ /** Command execution capabilities */
327
+ interface SandboxCommands {
328
+ run(command: string, options?: SandboxRunOptions): Promise<SandboxCommandResult>;
329
+ spawn(command: string, options?: SandboxSpawnOptions): Promise<SandboxCommandHandle>;
330
+ list(): Promise<ProcessInfo[]>;
331
+ kill(pid: number): Promise<boolean>;
332
+ }
333
+ /** File system operations */
334
+ interface SandboxFiles {
335
+ read(path: string): Promise<string | Uint8Array>;
336
+ write(path: string, content: string | Buffer | ArrayBuffer | Uint8Array): Promise<void>;
337
+ writeBatch(files: Array<{
338
+ path: string;
339
+ data: string | Buffer | ArrayBuffer | Uint8Array;
340
+ }>): Promise<void>;
341
+ makeDir(path: string): Promise<void>;
342
+ }
343
+ /** Sandbox instance */
344
+ interface SandboxInstance {
345
+ readonly sandboxId: string;
346
+ readonly commands: SandboxCommands;
347
+ readonly files: SandboxFiles;
348
+ getHost(port: number): string;
349
+ kill(): Promise<void>;
350
+ pause(): Promise<void>;
351
+ }
352
+ /** Sandbox lifecycle management - providers implement this */
353
+ interface SandboxProvider {
354
+ /** Provider type identifier (e.g., "e2b") */
355
+ readonly providerType: string;
356
+ /** Human-readable provider name for logging */
357
+ readonly name?: string;
358
+ create(options: SandboxCreateOptions): Promise<SandboxInstance>;
359
+ connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
360
+ }
361
+ /** Supported agent types (headless CLI agents only, no ACP) */
362
+ type AgentType = "claude" | "codex" | "gemini" | "qwen";
363
+ /** Agent type constants for use in code */
364
+ declare const AGENT_TYPES: {
365
+ readonly CLAUDE: "claude";
366
+ readonly CODEX: "codex";
367
+ readonly GEMINI: "gemini";
368
+ readonly QWEN: "qwen";
369
+ };
370
+ /** Workspace mode determines folder structure and system prompt */
371
+ type WorkspaceMode = "knowledge" | "swe";
372
+ /** Available skills that can be enabled */
373
+ type SkillName = "pdf" | "dev-browser" | (string & {});
374
+ /** Skills configuration for an agent */
375
+ interface SkillsConfig {
376
+ /** Source directory where skills are staged */
377
+ sourceDir: string;
378
+ /** Target directory where skills are copied for this CLI */
379
+ targetDir: string;
380
+ /** CLI flag to enable skills (e.g., "--experimental-skills") */
381
+ enableFlag?: string;
382
+ }
383
+ /** Reasoning effort for models that support it (Codex only) */
384
+ type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
385
+ /** MCP Server Configuration */
386
+ interface McpServerConfig {
387
+ command?: string;
388
+ args?: string[];
389
+ cwd?: string;
390
+ url?: string;
391
+ env?: Record<string, string>;
392
+ headers?: Record<string, string>;
393
+ bearerTokenEnvVar?: string;
394
+ httpHeaders?: Record<string, string>;
395
+ envHttpHeaders?: Record<string, string>;
396
+ envVars?: string[];
397
+ type?: "stdio" | "sse" | "http";
398
+ }
399
+ /** File map for uploads/downloads: { "filename.txt": content } */
400
+ type FileMap = Record<string, string | Buffer | ArrayBuffer | Uint8Array>;
401
+ /**
402
+ * JSON Schema object (draft-07 compatible)
403
+ *
404
+ * Use this when you want to pass a raw JSON Schema instead of a Zod schema.
405
+ * JSON Schema allows runtime validation modes via SchemaValidationOptions.
406
+ */
407
+ type JsonSchema = Record<string, unknown>;
408
+ /**
409
+ * Validation mode presets for JSON Schema validation
410
+ *
411
+ * - strict: Exact type matching, fail on any mismatch, no defaults filled
412
+ * - loose: Aggressive coercion (string↔number, null→empty values), fill defaults (default)
413
+ *
414
+ * Null handling (when schema expects string/number/boolean):
415
+ * - strict: Validation fails
416
+ * - loose: null→"" (string), null→0 (number), null→false (boolean)
417
+ *
418
+ * Note: These modes only apply to JSON Schema. Zod schemas define their own
419
+ * strictness via .passthrough(), .strip(), z.coerce, etc.
420
+ */
421
+ type ValidationMode = "strict" | "loose";
422
+ /**
423
+ * Options for JSON Schema validation (Ajv options)
424
+ *
425
+ * Either use a preset mode or provide individual options.
426
+ * Individual options override the preset if both provided.
427
+ */
428
+ interface SchemaValidationOptions {
429
+ /** Preset validation mode (applied first, then individual options override). Default: "loose" */
430
+ mode?: ValidationMode;
431
+ /** Coerce types. false=none, true=basic (string↔number), "array"=aggressive (incl. null→empty). Default: false */
432
+ coerceTypes?: boolean | "array";
433
+ /** Remove properties not in schema. true | 'all' | 'failing'. Default: false */
434
+ removeAdditional?: boolean | "all" | "failing";
435
+ /** Fill in default values from schema. Default: true */
436
+ useDefaults?: boolean;
437
+ /** Collect all errors vs stop at first. Default: true */
438
+ allErrors?: boolean;
439
+ }
440
+ /**
441
+ * Validation mode preset definitions
442
+ */
443
+ declare const VALIDATION_PRESETS: Record<ValidationMode, Required<Omit<SchemaValidationOptions, "mode">>>;
444
+ /** Configuration passed to withAgent() */
445
+ interface AgentConfig {
446
+ /** Agent type (default: "claude") */
447
+ type?: AgentType;
448
+ /** Evolve API key for gateway mode (default: EVOLVE_API_KEY env var) */
449
+ apiKey?: string;
450
+ /** Provider API key for direct mode / BYOK (default: provider env var) */
451
+ providerApiKey?: string;
452
+ /** OAuth token for Claude Max subscription (default: CLAUDE_CODE_OAUTH_TOKEN env var) */
453
+ oauthToken?: string;
454
+ /** Provider base URL for direct mode (default: provider env var or registry default) */
455
+ providerBaseUrl?: string;
456
+ /** Model to use (optional, uses agent's default if omitted) */
457
+ model?: string;
458
+ /** Reasoning effort for Codex models */
459
+ reasoningEffort?: ReasoningEffort;
460
+ /** Beta headers for Claude (Sonnet 4.5 only) */
461
+ betas?: string[];
462
+ }
463
+ /** Resolved agent config (output of resolution, not an extension of input) */
464
+ interface ResolvedAgentConfig {
465
+ type: AgentType;
466
+ apiKey: string;
467
+ baseUrl?: string;
468
+ isDirectMode: boolean;
469
+ isOAuth?: boolean;
470
+ model?: string;
471
+ reasoningEffort?: ReasoningEffort;
472
+ betas?: string[];
473
+ }
474
+ /** Options for Agent constructor */
475
+ interface AgentOptions {
476
+ /** Sandbox provider (e.g., E2B) */
477
+ sandboxProvider?: SandboxProvider;
478
+ /** Additional environment secrets */
479
+ secrets?: Record<string, string>;
480
+ /** Existing sandbox ID to connect to */
481
+ sandboxId?: string;
482
+ /** Working directory path */
483
+ workingDirectory?: string;
484
+ /** Workspace mode */
485
+ workspaceMode?: WorkspaceMode;
486
+ /** Custom system prompt (appended to workspace template in both modes) */
487
+ systemPrompt?: string;
488
+ /** Context files (uploaded to context/ folder) */
489
+ context?: FileMap;
490
+ /** Workspace files (uploaded to working directory) */
491
+ files?: FileMap;
492
+ /** MCP server configurations */
493
+ mcpServers?: Record<string, McpServerConfig>;
494
+ /** Skills to enable (e.g., ["pdf", "dev-browser"]) */
495
+ skills?: SkillName[];
496
+ /**
497
+ * Schema for structured output validation
498
+ *
499
+ * Accepts either:
500
+ * - Zod schema: z.object({ ... }) - validated with Zod's safeParse
501
+ * - JSON Schema: { type: "object", properties: { ... } } - validated with Ajv
502
+ *
503
+ * Auto-detected based on presence of .safeParse method.
504
+ */
505
+ schema?: zod.ZodType<unknown> | JsonSchema;
506
+ /**
507
+ * Validation options for JSON Schema (ignored for Zod schemas)
508
+ *
509
+ * Use preset modes or individual Ajv options.
510
+ *
511
+ * @example
512
+ * // Preset mode
513
+ * schemaOptions: { mode: 'loose' }
514
+ *
515
+ * // Individual options
516
+ * schemaOptions: { coerceTypes: true, useDefaults: true }
517
+ */
518
+ schemaOptions?: SchemaValidationOptions;
519
+ /** Session tag prefix (default: "evolve") */
520
+ sessionTagPrefix?: string;
521
+ /** Observability metadata for trace grouping (generic key-value, domain-agnostic) */
522
+ observability?: Record<string, unknown>;
523
+ /**
524
+ * Composio Tool Router configuration
525
+ * Set via withComposio() - provides access to 1000+ tools
526
+ */
527
+ composio?: ComposioSetup;
528
+ }
529
+ /** Options for run() */
530
+ interface RunOptions {
531
+ /** The prompt to send to the agent */
532
+ prompt: string;
533
+ /** Timeout in milliseconds (default: 1 hour) */
534
+ timeoutMs?: number;
535
+ /** Run in background (returns immediately, process continues) */
536
+ background?: boolean;
537
+ }
538
+ /** Options for executeCommand() */
539
+ interface ExecuteCommandOptions {
540
+ /** Timeout in milliseconds (default: 1 hour) */
541
+ timeoutMs?: number;
542
+ /** Run in background (default: false) */
543
+ background?: boolean;
544
+ }
545
+ /** Response from run() and executeCommand() */
546
+ interface AgentResponse {
547
+ /** Sandbox ID for session management */
548
+ sandboxId: string;
549
+ /** Exit code of the command */
550
+ exitCode: number;
551
+ /** Standard output */
552
+ stdout: string;
553
+ /** Standard error */
554
+ stderr: string;
555
+ }
556
+ /** Result from getOutputFiles() with optional schema validation */
557
+ interface OutputResult<T = unknown> {
558
+ /** Output files from output/ folder */
559
+ files: FileMap;
560
+ /** Parsed and validated result.json data (null if no schema or validation failed) */
561
+ data: T | null;
562
+ /** Validation or parse error message, if any */
563
+ error?: string;
564
+ /** Raw result.json string when parse or validation failed (for debugging) */
565
+ rawData?: string;
566
+ }
567
+ /** Callbacks for streaming output */
568
+ interface StreamCallbacks {
569
+ /** Called for each stdout chunk */
570
+ onStdout?: (data: string) => void;
571
+ /** Called for each stderr chunk */
572
+ onStderr?: (data: string) => void;
573
+ /** Called for each parsed content event */
574
+ onContent?: (event: OutputEvent) => void;
575
+ }
576
+ /**
577
+ * Configuration for Composio Tool Router integration
578
+ *
579
+ * Provides access to 1000+ tools (GitHub, Gmail, Slack, etc.) via MCP.
580
+ * Evidence: tool-router/quickstart.mdx
581
+ */
582
+ /** Tool filter configuration per toolkit */
583
+ type ToolsFilter = string[] | {
584
+ enable: string[];
585
+ } | {
586
+ disable: string[];
587
+ } | {
588
+ tags: string[];
589
+ };
590
+ interface ComposioConfig {
591
+ /**
592
+ * Restrict to specific toolkits
593
+ *
594
+ * @example
595
+ * toolkits: ["github", "gmail", "linear"]
596
+ */
597
+ toolkits?: string[];
598
+ /**
599
+ * Per-toolkit tool filtering
600
+ *
601
+ * @example
602
+ * tools: {
603
+ * github: ["github_create_issue", "github_list_repos"],
604
+ * gmail: { disable: ["gmail_delete_email"] },
605
+ * slack: { tags: ["readOnlyHint"] }
606
+ * }
607
+ */
608
+ tools?: Record<string, ToolsFilter>;
609
+ /**
610
+ * API keys for direct authentication (bypasses OAuth)
611
+ * For tools that support API key auth (e.g., Stripe, OpenAI)
612
+ *
613
+ * @example
614
+ * keys: { stripe: "sk_live_...", openai: "sk-..." }
615
+ */
616
+ keys?: Record<string, string>;
617
+ /**
618
+ * Custom OAuth auth config IDs for white-labeling
619
+ * Created in Composio dashboard
620
+ *
621
+ * @example
622
+ * authConfigs: { github: "ac_your_github_config" }
623
+ */
624
+ authConfigs?: Record<string, string>;
625
+ }
626
+ /**
627
+ * Composio setup for Tool Router integration
628
+ *
629
+ * Combines user identification with optional configuration.
630
+ */
631
+ interface ComposioSetup {
632
+ /** User's unique identifier for Composio session */
633
+ userId: string;
634
+ /** Optional Composio configuration */
635
+ config?: ComposioConfig;
636
+ }
637
+
638
+ /**
639
+ * Composio Auth Helpers
640
+ *
641
+ * Helper functions for managing Composio authentication in your app's UI.
642
+ * Evidence: tool-router/manually-authenticating-users.mdx
643
+ */
644
+ /**
645
+ * Result from getAuthUrl()
646
+ */
647
+ interface ComposioAuthResult {
648
+ /** OAuth/Connect Link URL to redirect user to */
649
+ url: string;
650
+ /** Connection request ID for tracking */
651
+ connectionId: string;
652
+ }
653
+ /**
654
+ * Connection status for a toolkit
655
+ */
656
+ interface ComposioConnectionStatus {
657
+ /** Toolkit slug (e.g., "github", "gmail") */
658
+ toolkit: string;
659
+ /** Whether the user has an active connection */
660
+ connected: boolean;
661
+ /** Connected account ID if connected */
662
+ accountId?: string;
663
+ }
664
+ /**
665
+ * Get OAuth URL for a toolkit
666
+ *
667
+ * Returns a Connect Link URL that you can show in your app's UI.
668
+ * User completes OAuth, then is redirected back to your app.
669
+ *
670
+ * @param userId - User's unique identifier
671
+ * @param toolkit - Toolkit slug (e.g., "github", "gmail")
672
+ * @returns Auth URL and connection ID
673
+ *
674
+ * @example
675
+ * const { url } = await getAuthUrl("user_123", "github");
676
+ * // Show button: <a href={url}>Connect GitHub</a>
677
+ */
678
+ declare function getAuthUrl(userId: string, toolkit: string): Promise<ComposioAuthResult>;
679
+ /**
680
+ * Get connection status for a user
681
+ *
682
+ * @param userId - User's unique identifier
683
+ * @param toolkit - Optional toolkit slug to check specific connection
684
+ * @returns Status map for all toolkits, or boolean if toolkit specified
685
+ *
686
+ * @example
687
+ * // Get all connections
688
+ * const status = await getStatus("user_123");
689
+ * // { github: true, gmail: false, slack: true }
690
+ *
691
+ * @example
692
+ * // Check single toolkit
693
+ * const isConnected = await getStatus("user_123", "github");
694
+ * // true
695
+ */
696
+ declare function getStatus(userId: string, toolkit?: string): Promise<Record<string, boolean> | boolean>;
697
+ /**
698
+ * Get detailed connection info for a user
699
+ *
700
+ * Returns array of connections with account IDs.
701
+ * More detailed than getStatus() - use when you need account IDs.
702
+ *
703
+ * @param userId - User's unique identifier
704
+ * @returns Array of connection statuses
705
+ *
706
+ * @example
707
+ * const connections = await getConnections("user_123");
708
+ * // [{ toolkit: "github", connected: true, accountId: "ca_..." }, ...]
709
+ */
710
+ declare function getConnections(userId: string): Promise<ComposioConnectionStatus[]>;
711
+
712
+ /**
713
+ * Unified Agent Implementation
714
+ *
715
+ * Single Agent class that uses registry lookup for agent-specific behavior.
716
+ * All agent differences are data (in registry), not code.
717
+ *
718
+ * Evidence: sdk-rewrite-v3.md Design Decisions section
719
+ */
720
+
721
+ /**
722
+ * Unified Agent class
723
+ *
724
+ * Uses registry lookup for agent-specific behavior.
725
+ * Tracks hasRun state for continue flag handling.
726
+ */
727
+ declare class Agent {
728
+ private agentConfig;
729
+ private options;
730
+ private sandbox?;
731
+ private hasRun;
732
+ private readonly workingDir;
733
+ private lastRunTimestamp?;
734
+ private readonly registry;
735
+ private sessionLogger?;
736
+ private readonly skills?;
737
+ private readonly zodSchema?;
738
+ private readonly jsonSchema?;
739
+ private readonly schemaOptions?;
740
+ private readonly compiledValidator?;
741
+ constructor(agentConfig: ResolvedAgentConfig, options?: AgentOptions);
742
+ /**
743
+ * Create Ajv validator instance with configured options
744
+ */
745
+ private createAjvValidator;
746
+ /**
747
+ * Get or create sandbox instance
748
+ */
749
+ getSandbox(): Promise<SandboxInstance>;
750
+ /**
751
+ * Build environment variables for sandbox
752
+ */
753
+ private buildEnvironmentVariables;
754
+ /**
755
+ * Agent-specific authentication setup
756
+ */
757
+ private setupAgentAuth;
758
+ /**
759
+ * Setup workspace structure and files
760
+ */
761
+ private setupWorkspace;
762
+ /**
763
+ * Setup skills for the agent
764
+ *
765
+ * Copies selected skills from source (~/.evolve/skills/) to CLI-specific directory.
766
+ * All CLIs use the same pattern: skills are auto-discovered from their target directory.
767
+ */
768
+ private setupSkills;
769
+ /**
770
+ * Upload context files to context/ folder
771
+ */
772
+ private uploadContextFiles;
773
+ /**
774
+ * Upload workspace files to working directory
775
+ */
776
+ private uploadWorkspaceFiles;
777
+ /**
778
+ * Build the CLI command for running the agent
779
+ */
780
+ private buildCommand;
781
+ /**
782
+ * Run agent with prompt
783
+ *
784
+ * Streams output via callbacks, returns final response.
785
+ */
786
+ run(options: RunOptions, callbacks?: StreamCallbacks): Promise<AgentResponse>;
787
+ /**
788
+ * Execute arbitrary command in sandbox
789
+ */
790
+ executeCommand(command: string, options?: ExecuteCommandOptions, callbacks?: StreamCallbacks): Promise<AgentResponse>;
791
+ /**
792
+ * Upload context files (to context/ folder)
793
+ */
794
+ uploadContext(files: FileMap): Promise<void>;
795
+ /**
796
+ * Upload files to working directory
797
+ */
798
+ uploadFiles(files: FileMap): Promise<void>;
799
+ /**
800
+ * Get output files from output/ folder with optional schema validation
801
+ *
802
+ * Returns files modified after the last run() call.
803
+ * If schema was provided, validates result.json and returns typed data.
804
+ *
805
+ * @param recursive - Include files in subdirectories (default: false)
806
+ */
807
+ getOutputFiles<T = unknown>(recursive?: boolean): Promise<OutputResult<T>>;
808
+ /**
809
+ * Get current session (sandbox ID)
810
+ */
811
+ getSession(): string | null;
812
+ /**
813
+ * Set session (sandbox ID) to connect to
814
+ *
815
+ * When reconnecting to an existing sandbox, we assume the agent
816
+ * may have already run commands, so we set hasRun=true to use
817
+ * the continue/resume command template instead of first-run.
818
+ */
819
+ setSession(sandboxId: string): Promise<void>;
820
+ /**
821
+ * Pause sandbox
822
+ */
823
+ pause(): Promise<void>;
824
+ /**
825
+ * Resume sandbox
826
+ */
827
+ resume(): Promise<void>;
828
+ /**
829
+ * Kill sandbox (terminates all processes)
830
+ */
831
+ kill(): Promise<void>;
832
+ /**
833
+ * Get host URL for a port
834
+ */
835
+ getHost(port: number): Promise<string>;
836
+ /**
837
+ * Get agent type
838
+ */
839
+ getAgentType(): AgentType;
840
+ /**
841
+ * Get current session tag
842
+ *
843
+ * Returns null if no session has started (run() not called yet).
844
+ */
845
+ getSessionTag(): string | null;
846
+ /**
847
+ * Get current session timestamp
848
+ *
849
+ * Returns null if no session has started (run() not called yet).
850
+ */
851
+ getSessionTimestamp(): string | null;
852
+ }
853
+
854
+ /**
855
+ * Claude JSONL → ACP-style events parser.
856
+ *
857
+ * Native schema source (@anthropic-ai/claude-agent-sdk):
858
+ * MANUS-API/KNOWLEDGE/claude-agent-sdk/cc_sdk_typescript.md
859
+ * (SDKMessage, SDKAssistantMessage, SDKPartialAssistantMessage, Tool Input/Output types)
860
+ *
861
+ * Conversion logic reference:
862
+ * MANUS-API/KNOWLEDGE/claude-code-acp/src/tools.ts
863
+ * (toolInfoFromToolUse, toolUpdateFromToolResult)
864
+ *
865
+ * ACP output schema:
866
+ * MANUS-API/KNOWLEDGE/acp-typescript-sdk/src/schema/types.gen.ts
867
+ */
868
+
869
+ /**
870
+ * Create a Claude parser instance with its own isolated cache.
871
+ * Each Evolve instance should create its own parser for proper isolation.
872
+ */
873
+ declare function createClaudeParser(): (jsonLine: string) => OutputEvent[] | null;
874
+
875
+ /**
876
+ * Codex JSONL → ACP-style events parser.
877
+ *
878
+ * Native schema: codex-rs/exec/src/exec_events.rs
879
+ * - ThreadEvent: thread.started, turn.started, turn.completed, item.started, item.updated, item.completed
880
+ * - ThreadItemDetails: AgentMessage, Reasoning, CommandExecution, FileChange, McpToolCall, WebSearch, TodoList, Error
881
+ *
882
+ * ACP output: acp-typescript-sdk/src/schema/types.gen.ts
883
+ * - SessionUpdate: agent_message_chunk, agent_thought_chunk, tool_call, tool_call_update, plan
884
+ *
885
+ * Event mapping:
886
+ * reasoning → agent_thought_chunk (exec_events.rs:134 ReasoningItem { text })
887
+ * agent_message → agent_message_chunk (exec_events.rs:129 AgentMessageItem { text })
888
+ * mcp_tool_call → tool_call/update (exec_events.rs:215 McpToolCallItem)
889
+ * command_execution → tool_call/update (exec_events.rs:151 CommandExecutionItem)
890
+ * file_change → tool_call (exec_events.rs:176 FileChangeItem)
891
+ * todo_list → plan (exec_events.rs:245 TodoListItem { items: TodoItem[] })
892
+ * web_search → tool_call (exec_events.rs:227 WebSearchItem { query })
893
+ */
894
+
895
+ /**
896
+ * Create a Codex parser instance.
897
+ */
898
+ declare function createCodexParser(): (jsonLine: string) => OutputEvent[] | null;
899
+
900
+ /**
901
+ * Gemini JSONL → ACP-style events parser.
902
+ *
903
+ * Native schema (gemini --output-format stream-json):
904
+ * gemini-cli/packages/core/src/output/types.ts
905
+ *
906
+ * Gemini events (types.ts:29-36 JsonStreamEventType):
907
+ * - "init" → types.ts:43-47 InitEvent { session_id, model }
908
+ * - "message" → types.ts:49-54 MessageEvent { role, content, delta? }
909
+ * - "tool_use" → types.ts:56-61 ToolUseEvent { tool_name, tool_id, parameters }
910
+ * - "tool_result" → types.ts:63-72 ToolResultEvent { tool_id, status, output?, error? }
911
+ * - "error" → types.ts:74-78 ErrorEvent { severity, message }
912
+ * - "result" → types.ts:91-99 ResultEvent { status, error?, stats? }
913
+ *
914
+ * ACP output: acp-typescript-sdk/src/schema/types.gen.ts:2449-2464
915
+ */
916
+
917
+ /**
918
+ * Create a Gemini parser instance.
919
+ */
920
+ declare function createGeminiParser(): (jsonLine: string) => OutputEvent[] | null;
921
+
922
+ /**
923
+ * Qwen NDJSON → ACP-style events parser.
924
+ *
925
+ * Native schema: KNOWLEDGE/qwen-code/packages/sdk-typescript/src/types/protocol.ts
926
+ * ACP schema: KNOWLEDGE/acp-typescript-sdk/src/schema/types.gen.ts
927
+ *
928
+ * Qwen NDJSON message types (protocol.ts:428-433):
929
+ * - type: "assistant" → SDKAssistantMessage (protocol.ts:102-108)
930
+ * - type: "stream_event" → SDKPartialAssistantMessage (protocol.ts:225-231)
931
+ * - type: "user" → SDKUserMessage (protocol.ts:93-100)
932
+ * - type: "system" → SDKSystemMessage (skipped)
933
+ * - type: "result" → SDKResultMessage (skipped)
934
+ *
935
+ * ContentBlock types (protocol.ts:72-76):
936
+ * - TextBlock (protocol.ts:43-48): { type: 'text', text: string }
937
+ * - ThinkingBlock (protocol.ts:49-54): { type: 'thinking', thinking: string }
938
+ * - ToolUseBlock (protocol.ts:56-62): { type: 'tool_use', id, name, input }
939
+ * - ToolResultBlock (protocol.ts:64-70): { type: 'tool_result', tool_use_id, content?, is_error? }
940
+ *
941
+ * StreamEvent types (protocol.ts:218-223):
942
+ * - message_start, content_block_start, content_block_delta, content_block_stop, message_stop
943
+ */
944
+
945
+ /**
946
+ * Stateless parser function (creates new parser per call).
947
+ * Use createQwenParser() for stateful streaming parsing.
948
+ *
949
+ * @param line - Single line of NDJSON from qwen CLI
950
+ * @returns Array of OutputEvent objects, or null if line couldn't be parsed
951
+ */
952
+ declare function parseQwenOutput(line: string): OutputEvent[] | null;
953
+
954
+ /**
955
+ * Unified Parser Entry Point
956
+ *
957
+ * Routes NDJSON lines to the appropriate agent-specific parser.
958
+ * Simple line-based parsing - no buffering needed since CLIs output complete JSON per line.
959
+ */
960
+
961
+ /** Parser function type */
962
+ type AgentParser = (jsonLine: string) => OutputEvent[] | null;
963
+ /**
964
+ * Create a parser instance for the given agent type.
965
+ * Each Evolve instance should create its own parser for proper isolation.
966
+ *
967
+ * @param agentType - The agent type to create a parser for
968
+ * @returns Parser function that takes NDJSON lines and returns OutputEvents
969
+ */
970
+ declare function createAgentParser(agentType: AgentType): AgentParser;
971
+ /**
972
+ * Parse a single NDJSON line from any agent (creates new parser per call - use createAgentParser for efficiency)
973
+ *
974
+ * @param agentType - The agent type to parse for
975
+ * @param line - Single line of NDJSON output
976
+ * @returns Array of OutputEvent objects, or null if line couldn't be parsed
977
+ */
978
+ declare function parseNdjsonLine(agentType: AgentType, line: string): OutputEvent[] | null;
979
+ /**
980
+ * Parse multiple NDJSON lines (convenience wrapper)
981
+ *
982
+ * @param agentType - The agent type to parse for
983
+ * @param output - Multi-line NDJSON output
984
+ * @returns Array of all parsed OutputEvent objects
985
+ */
986
+ declare function parseNdjsonOutput(agentType: AgentType, output: string): OutputEvent[];
987
+
988
+ /**
989
+ * Evolve events
990
+ *
991
+ * Reduced from 5 to 3:
992
+ * - stdout: Raw NDJSON lines
993
+ * - stderr: Process stderr
994
+ * - content: Parsed OutputEvent
995
+ *
996
+ * Removed: update, error (see sdk-rewrite-v3.md)
997
+ */
998
+ interface EvolveEvents {
999
+ stdout: (chunk: string) => void;
1000
+ stderr: (chunk: string) => void;
1001
+ content: (event: OutputEvent) => void;
1002
+ }
1003
+ interface EvolveConfig {
1004
+ agent?: AgentConfig;
1005
+ sandbox?: SandboxProvider;
1006
+ workingDirectory?: string;
1007
+ workspaceMode?: WorkspaceMode;
1008
+ secrets?: Record<string, string>;
1009
+ sandboxId?: string;
1010
+ systemPrompt?: string;
1011
+ context?: FileMap;
1012
+ files?: FileMap;
1013
+ mcpServers?: Record<string, McpServerConfig>;
1014
+ /** Skills to enable (e.g., ["pdf", "dev-browser"]) */
1015
+ skills?: SkillName[];
1016
+ /** Schema for structured output (Zod or JSON Schema, auto-detected) */
1017
+ schema?: z.ZodType<unknown> | JsonSchema;
1018
+ /** Validation options for JSON Schema (ignored for Zod) */
1019
+ schemaOptions?: SchemaValidationOptions;
1020
+ sessionTagPrefix?: string;
1021
+ /** Observability metadata for trace grouping (generic key-value, domain-agnostic) */
1022
+ observability?: Record<string, unknown>;
1023
+ /** Composio user ID and config */
1024
+ composio?: ComposioSetup;
1025
+ }
1026
+ /**
1027
+ * Evolve orchestrator with builder pattern
1028
+ *
1029
+ * Usage:
1030
+ * ```ts
1031
+ * const kit = new Evolve()
1032
+ * .withAgent({ type: "claude", apiKey: "sk-..." })
1033
+ * .withSandbox(e2bProvider);
1034
+ *
1035
+ * kit.on("content", (event) => console.log(event));
1036
+ *
1037
+ * await kit.run({ prompt: "Hello" });
1038
+ * ```
1039
+ */
1040
+ declare class Evolve extends EventEmitter {
1041
+ private config;
1042
+ private agent?;
1043
+ constructor();
1044
+ on<K extends keyof EvolveEvents>(event: K, listener: EvolveEvents[K]): this;
1045
+ off<K extends keyof EvolveEvents>(event: K, listener: EvolveEvents[K]): this;
1046
+ emit<K extends keyof EvolveEvents>(event: K, ...args: Parameters<EvolveEvents[K]>): boolean;
1047
+ /**
1048
+ * Configure agent type and API key.
1049
+ * If config is undefined, Evolve resolves agent from env.
1050
+ */
1051
+ withAgent(config?: AgentConfig): this;
1052
+ /**
1053
+ * Configure sandbox provider
1054
+ */
1055
+ withSandbox(provider?: SandboxProvider): this;
1056
+ /**
1057
+ * Set working directory path
1058
+ */
1059
+ withWorkingDirectory(path: string): this;
1060
+ /**
1061
+ * Set workspace mode
1062
+ * - "knowledge": Creates context/, scripts/, temp/, output/ folders
1063
+ * - "swe": Same as knowledge + repo/ folder for code repositories
1064
+ */
1065
+ withWorkspaceMode(mode: WorkspaceMode): this;
1066
+ /**
1067
+ * Add environment secrets
1068
+ */
1069
+ withSecrets(secrets: Record<string, string>): this;
1070
+ /**
1071
+ * Connect to existing session
1072
+ */
1073
+ withSession(sandboxId: string): this;
1074
+ /**
1075
+ * Set custom system prompt
1076
+ */
1077
+ withSystemPrompt(prompt: string): this;
1078
+ /**
1079
+ * Add context files (uploaded to context/ folder)
1080
+ */
1081
+ withContext(files: FileMap): this;
1082
+ /**
1083
+ * Add workspace files (uploaded to working directory)
1084
+ */
1085
+ withFiles(files: FileMap): this;
1086
+ /**
1087
+ * Configure MCP servers
1088
+ */
1089
+ withMcpServers(servers: Record<string, McpServerConfig>): this;
1090
+ /**
1091
+ * Enable skills for the agent
1092
+ *
1093
+ * Skills are specialized capabilities that extend the agent's functionality.
1094
+ * Available skills: "pdf", "dev-browser"
1095
+ *
1096
+ * @example
1097
+ * kit.withSkills(["pdf", "dev-browser"])
1098
+ */
1099
+ withSkills(skills: SkillName[]): this;
1100
+ /**
1101
+ * Set schema for structured output validation
1102
+ *
1103
+ * Accepts either:
1104
+ * - Zod schema: z.object({ ... }) - validated with Zod's safeParse
1105
+ * - JSON Schema: { type: "object", properties: { ... } } - validated with Ajv
1106
+ *
1107
+ * Auto-detected based on presence of .safeParse method.
1108
+ *
1109
+ * @param schema - Zod schema or JSON Schema object
1110
+ * @param options - Validation options for JSON Schema (ignored for Zod)
1111
+ *
1112
+ * @example
1113
+ * // Zod schema
1114
+ * kit.withSchema(z.object({ result: z.string() }))
1115
+ *
1116
+ * // JSON Schema with validation mode
1117
+ * kit.withSchema(
1118
+ * { type: "object", properties: { result: { type: "string" } } },
1119
+ * { mode: "loose" }
1120
+ * )
1121
+ */
1122
+ withSchema<T>(schema: z.ZodType<T> | JsonSchema, options?: SchemaValidationOptions): this;
1123
+ /**
1124
+ * Set session tag prefix for observability
1125
+ */
1126
+ withSessionTagPrefix(prefix: string): this;
1127
+ /**
1128
+ * @internal Set observability metadata for trace grouping.
1129
+ * Used internally by Swarm - not part of public API.
1130
+ */
1131
+ withObservability(meta: Record<string, unknown>): this;
1132
+ /**
1133
+ * Enable Composio Tool Router for 1000+ tool integrations
1134
+ *
1135
+ * Provides access to GitHub, Gmail, Slack, Notion, and 1000+ other
1136
+ * tools via a single MCP server. Handles authentication automatically.
1137
+ *
1138
+ * Evidence: tool-router/quickstart.mdx
1139
+ *
1140
+ * @param userId - Your user's unique identifier
1141
+ * @param config - Optional configuration for toolkits, API keys, and auth
1142
+ *
1143
+ * @example
1144
+ * // Basic - all tools, in-chat auth
1145
+ * kit.withComposio("user_123")
1146
+ *
1147
+ * @example
1148
+ * // Restrict to specific toolkits
1149
+ * kit.withComposio("user_123", { toolkits: ["github", "gmail"] })
1150
+ *
1151
+ * @example
1152
+ * // With API keys for direct auth
1153
+ * kit.withComposio("user_123", {
1154
+ * toolkits: ["github", "stripe"],
1155
+ * keys: { stripe: "sk_live_..." }
1156
+ * })
1157
+ *
1158
+ * @example
1159
+ * // With white-label OAuth
1160
+ * kit.withComposio("user_123", {
1161
+ * authConfigs: { github: "ac_your_oauth_config" }
1162
+ * })
1163
+ */
1164
+ withComposio(userId: string, config?: ComposioConfig): this;
1165
+ /**
1166
+ * Static helpers for Composio auth management
1167
+ *
1168
+ * Use these in your app's settings UI to manage user connections.
1169
+ *
1170
+ * Evidence: tool-router/manually-authenticating-users.mdx
1171
+ *
1172
+ * @example
1173
+ * // Get OAuth URL for "Connect GitHub" button
1174
+ * const { url } = await Evolve.composio.auth("user_123", "github");
1175
+ *
1176
+ * @example
1177
+ * // Check connection status
1178
+ * const status = await Evolve.composio.status("user_123");
1179
+ * // { github: true, gmail: false, ... }
1180
+ *
1181
+ * @example
1182
+ * // Check single toolkit
1183
+ * const isConnected = await Evolve.composio.status("user_123", "github");
1184
+ * // true | false
1185
+ */
1186
+ static composio: {
1187
+ auth: typeof getAuthUrl;
1188
+ status: typeof getStatus;
1189
+ connections: typeof getConnections;
1190
+ };
1191
+ /**
1192
+ * Initialize agent on first use
1193
+ */
1194
+ private initializeAgent;
1195
+ /**
1196
+ * Create stream callbacks based on registered listeners
1197
+ */
1198
+ private createStreamCallbacks;
1199
+ /**
1200
+ * Run agent with prompt
1201
+ */
1202
+ run({ prompt, timeoutMs, background, }: {
1203
+ prompt: string;
1204
+ timeoutMs?: number;
1205
+ background?: boolean;
1206
+ }): Promise<AgentResponse>;
1207
+ /**
1208
+ * Execute arbitrary command in sandbox
1209
+ */
1210
+ executeCommand(command: string, options?: {
1211
+ timeoutMs?: number;
1212
+ background?: boolean;
1213
+ }): Promise<AgentResponse>;
1214
+ /**
1215
+ * Upload context files (runtime - immediate upload)
1216
+ */
1217
+ uploadContext(files: FileMap): Promise<void>;
1218
+ /**
1219
+ * Upload files to workspace (runtime - immediate upload)
1220
+ */
1221
+ uploadFiles(files: FileMap): Promise<void>;
1222
+ /**
1223
+ * Get output files from output/ folder with optional schema validation
1224
+ *
1225
+ * @param recursive - Include files in subdirectories (default: false)
1226
+ */
1227
+ getOutputFiles<T = unknown>(recursive?: boolean): Promise<OutputResult<T>>;
1228
+ /**
1229
+ * Get current session (sandbox ID)
1230
+ */
1231
+ getSession(): string | null;
1232
+ /**
1233
+ * Set session to connect to
1234
+ */
1235
+ setSession(sandboxId: string): Promise<void>;
1236
+ /**
1237
+ * Pause sandbox
1238
+ */
1239
+ pause(): Promise<void>;
1240
+ /**
1241
+ * Resume sandbox
1242
+ */
1243
+ resume(): Promise<void>;
1244
+ /**
1245
+ * Kill sandbox
1246
+ */
1247
+ kill(): Promise<void>;
1248
+ /**
1249
+ * Get host URL for a port
1250
+ */
1251
+ getHost(port: number): Promise<string>;
1252
+ /**
1253
+ * Get session tag (for observability)
1254
+ *
1255
+ * Returns null if no session has started (run() not called yet).
1256
+ */
1257
+ getSessionTag(): string | null;
1258
+ /**
1259
+ * Get session timestamp (for observability)
1260
+ *
1261
+ * Returns null if no session has started (run() not called yet).
1262
+ */
1263
+ getSessionTimestamp(): string | null;
1264
+ }
1265
+
1266
+ /**
1267
+ * Retry Utility
1268
+ *
1269
+ * Generic retry with exponential backoff for Swarm operations.
1270
+ * Works with any result type that has a status field.
1271
+ * Retries on error status by default, with customizable retry conditions.
1272
+ */
1273
+ /** Any result with a status field (SwarmResult, ReduceResult, etc.) */
1274
+ interface RetryableResult {
1275
+ status: "success" | "error" | "filtered";
1276
+ error?: string;
1277
+ }
1278
+ /**
1279
+ * Per-item retry configuration.
1280
+ *
1281
+ * @example
1282
+ * ```typescript
1283
+ * // Basic retry on error
1284
+ * { maxAttempts: 3 }
1285
+ *
1286
+ * // With exponential backoff
1287
+ * { maxAttempts: 3, backoffMs: 1000, backoffMultiplier: 2 }
1288
+ *
1289
+ * // Custom retry condition (when using typed RetryConfig<SwarmResult<T>>)
1290
+ * { maxAttempts: 3, retryOn: (r) => r.status === "error" || r.error?.includes("timeout") }
1291
+ *
1292
+ * // With retry callback for observability
1293
+ * { maxAttempts: 3, onItemRetry: (idx, attempt, error) => console.log(`Item ${idx} retry ${attempt}: ${error}`) }
1294
+ * ```
1295
+ */
1296
+ interface RetryConfig<TResult extends RetryableResult = RetryableResult> {
1297
+ /** Maximum retry attempts (default: 3) */
1298
+ maxAttempts?: number;
1299
+ /** Initial backoff in ms (default: 1000) */
1300
+ backoffMs?: number;
1301
+ /** Exponential backoff multiplier (default: 2) */
1302
+ backoffMultiplier?: number;
1303
+ /** Custom retry condition (default: status === "error") */
1304
+ retryOn?: (result: TResult) => boolean;
1305
+ /** Callback invoked before each item retry attempt */
1306
+ onItemRetry?: OnItemRetryCallback;
1307
+ }
1308
+ /** Callback for item retry events */
1309
+ type OnItemRetryCallback = (itemIndex: number, attempt: number, error: string) => void;
1310
+ /**
1311
+ * Execute a function with retry and exponential backoff.
1312
+ *
1313
+ * Works with any result type that has a `status` field (SwarmResult, ReduceResult, etc.).
1314
+ *
1315
+ * @param fn - Function that receives attempt number (1-based) and returns a result
1316
+ * @param config - Retry configuration (includes optional onRetry callback)
1317
+ * @param itemIndex - Item index for callback (default: 0, used for reduce)
1318
+ * @returns Result from the function
1319
+ *
1320
+ * @example
1321
+ * ```typescript
1322
+ * const result = await executeWithRetry(
1323
+ * (attempt) => this.executeMapItem(item, prompt, index, operationId, params, timeout, attempt),
1324
+ * { maxAttempts: 3, backoffMs: 1000, onItemRetry: (idx, attempt, error) => console.log(`Item ${idx} retry ${attempt}: ${error}`) },
1325
+ * index
1326
+ * );
1327
+ * ```
1328
+ */
1329
+ declare function executeWithRetry<TResult extends RetryableResult>(fn: (attempt: number) => Promise<TResult>, config?: RetryConfig<TResult>, itemIndex?: number): Promise<TResult>;
1330
+
1331
+ /**
1332
+ * Swarm Abstractions - Type Definitions
1333
+ *
1334
+ * Functional programming for AI agents.
1335
+ * map, filter, reduce, bestOf - with AI reasoning.
1336
+ */
1337
+
1338
+ declare const SWARM_RESULT_BRAND: unique symbol;
1339
+ /** Agent override for method options (apiKey inherited from Swarm instance) */
1340
+ interface AgentOverride {
1341
+ type: AgentType;
1342
+ model?: string;
1343
+ reasoningEffort?: ReasoningEffort;
1344
+ betas?: string[];
1345
+ }
1346
+ interface SwarmConfig {
1347
+ /** Default agent for all operations (defaults to env resolution) */
1348
+ agent?: AgentConfig;
1349
+ /** Sandbox provider (defaults to E2B via E2B_API_KEY env var) */
1350
+ sandbox?: SandboxProvider;
1351
+ /** User prefix for worker tags */
1352
+ tag?: string;
1353
+ /** Max parallel sandboxes globally (default: 4) */
1354
+ concurrency?: number;
1355
+ /** Per-worker timeout in ms (default: 1 hour) */
1356
+ timeoutMs?: number;
1357
+ /** Workspace mode (default: SDK default 'knowledge') */
1358
+ workspaceMode?: WorkspaceMode;
1359
+ /** Default retry configuration for all operations (per-operation config takes precedence) */
1360
+ retry?: RetryConfig;
1361
+ /** Default MCP servers for all operations (per-operation config takes precedence) */
1362
+ mcpServers?: Record<string, McpServerConfig>;
1363
+ /** Default skills for all operations (per-operation config takes precedence) */
1364
+ skills?: SkillName[];
1365
+ /** Default Composio configuration for all operations (per-operation config takes precedence) */
1366
+ composio?: ComposioSetup;
1367
+ }
1368
+ /** Callback for bestOf candidate completion */
1369
+ type OnCandidateCompleteCallback = (itemIndex: number, candidateIndex: number, status: "success" | "error") => void;
1370
+ /** Callback for bestOf judge completion */
1371
+ type OnJudgeCompleteCallback = (itemIndex: number, winnerIndex: number, reasoning: string) => void;
1372
+ interface BestOfConfig {
1373
+ /** Number of candidates (>= 2). Required if taskAgents omitted, else inferred from taskAgents.length */
1374
+ n?: number;
1375
+ /** Evaluation criteria for judge */
1376
+ judgeCriteria: string;
1377
+ /** Optional: agents for each candidate. If provided, n defaults to taskAgents.length */
1378
+ taskAgents?: AgentOverride[];
1379
+ /** Optional: override agent for judge */
1380
+ judgeAgent?: AgentOverride;
1381
+ /** MCP servers for candidates (defaults to operation mcpServers) */
1382
+ mcpServers?: Record<string, McpServerConfig>;
1383
+ /** MCP servers for judge (defaults to mcpServers) */
1384
+ judgeMcpServers?: Record<string, McpServerConfig>;
1385
+ /** Skills for candidates (defaults to operation skills) */
1386
+ skills?: SkillName[];
1387
+ /** Skills for judge (defaults to skills) */
1388
+ judgeSkills?: SkillName[];
1389
+ /** Composio config for candidates (defaults to operation composio) */
1390
+ composio?: ComposioSetup;
1391
+ /** Composio config for judge (defaults to composio) */
1392
+ judgeComposio?: ComposioSetup;
1393
+ /** Callback when a candidate completes */
1394
+ onCandidateComplete?: OnCandidateCompleteCallback;
1395
+ /** Callback when judge completes */
1396
+ onJudgeComplete?: OnJudgeCompleteCallback;
1397
+ }
1398
+ /** Callback for verify worker completion (before verification runs) */
1399
+ type OnWorkerCompleteCallback = (itemIndex: number, attempt: number, status: "success" | "error") => void;
1400
+ /** Callback for verifier completion */
1401
+ type OnVerifierCompleteCallback = (itemIndex: number, attempt: number, passed: boolean, feedback?: string) => void;
1402
+ interface VerifyConfig {
1403
+ /** Verification criteria - what the output must satisfy */
1404
+ criteria: string;
1405
+ /** Maximum attempts with feedback (default: 3). Includes initial attempt. */
1406
+ maxAttempts?: number;
1407
+ /** Optional: override agent for verifier */
1408
+ verifierAgent?: AgentOverride;
1409
+ /** MCP servers for verifier (defaults to operation mcpServers) */
1410
+ verifierMcpServers?: Record<string, McpServerConfig>;
1411
+ /** Skills for verifier (defaults to operation skills) */
1412
+ verifierSkills?: SkillName[];
1413
+ /** Composio config for verifier (defaults to operation composio) */
1414
+ verifierComposio?: ComposioSetup;
1415
+ /** Callback invoked after each worker completion (before verification) */
1416
+ onWorkerComplete?: OnWorkerCompleteCallback;
1417
+ /** Callback invoked after each verifier completion */
1418
+ onVerifierComplete?: OnVerifierCompleteCallback;
1419
+ }
1420
+ type OperationType = "map" | "filter" | "reduce" | "bestof-cand" | "bestof-judge" | "verify";
1421
+ interface BaseMeta {
1422
+ /** Unique identifier for this operation (map/filter/reduce/bestOf call) */
1423
+ operationId: string;
1424
+ operation: OperationType;
1425
+ tag: string;
1426
+ sandboxId: string;
1427
+ /** Swarm name (from Swarm.config.tag) - identifies the swarm instance */
1428
+ swarmName?: string;
1429
+ /** Operation name (from params.name) - user-defined label for this operation */
1430
+ operationName?: string;
1431
+ /** Error retry number (1, 2, 3...) - only present when retrying after error */
1432
+ errorRetry?: number;
1433
+ /** Verify retry number (1, 2, 3...) - only present when retrying after verify failure */
1434
+ verifyRetry?: number;
1435
+ /** Candidate index (0, 1, 2...) - only present for bestOf candidates */
1436
+ candidateIndex?: number;
1437
+ /** Pipeline run identifier - only present when run via Pipeline */
1438
+ pipelineRunId?: string;
1439
+ /** Pipeline step index - only present when run via Pipeline */
1440
+ pipelineStepIndex?: number;
1441
+ }
1442
+ interface IndexedMeta extends BaseMeta {
1443
+ /** Item index in the batch (0, 1, 2...) */
1444
+ itemIndex: number;
1445
+ }
1446
+ interface ReduceMeta extends BaseMeta {
1447
+ inputCount: number;
1448
+ inputIndices: number[];
1449
+ }
1450
+ interface JudgeMeta extends BaseMeta {
1451
+ candidateCount: number;
1452
+ }
1453
+ interface VerifyMeta extends BaseMeta {
1454
+ /** Total verification attempts made */
1455
+ attempts: number;
1456
+ }
1457
+ /**
1458
+ * Result from a single worker (map, filter, bestof candidate).
1459
+ *
1460
+ * Status meanings:
1461
+ * - "success": Positive outcome (agent succeeded / condition passed)
1462
+ * - "filtered": Neutral outcome (evaluated but didn't pass condition) - filter only
1463
+ * - "error": Negative outcome (agent error)
1464
+ *
1465
+ * @typeParam T - Data type. Defaults to FileMap when no schema provided.
1466
+ */
1467
+ interface SwarmResult<T = FileMap> {
1468
+ readonly [SWARM_RESULT_BRAND]: true;
1469
+ status: "success" | "filtered" | "error";
1470
+ /** Parsed result.json if schema provided, else FileMap. Null if failed. */
1471
+ data: T | null;
1472
+ /** Output files (map/bestof) or original input files (filter) */
1473
+ files: FileMap;
1474
+ meta: IndexedMeta;
1475
+ error?: string;
1476
+ /** Raw result.json string when parse or validation failed (for debugging) */
1477
+ rawData?: string;
1478
+ /** Present when map used bestOf option. Matches BestOfResult structure (minus winner). */
1479
+ bestOf?: {
1480
+ winnerIndex: number;
1481
+ judgeReasoning: string;
1482
+ judgeMeta: JudgeMeta;
1483
+ candidates: SwarmResult<T>[];
1484
+ };
1485
+ /** Present when verify option was used. Contains verification outcome. */
1486
+ verify?: VerifyInfo;
1487
+ }
1488
+ /**
1489
+ * List of SwarmResults with helper properties.
1490
+ * Extends Array so all normal array operations work.
1491
+ *
1492
+ * Getters:
1493
+ * - `.success` - items with positive outcome
1494
+ * - `.filtered` - items that didn't pass condition (filter only)
1495
+ * - `.error` - items that encountered errors
1496
+ *
1497
+ * Chaining examples:
1498
+ * - `swarm.reduce(results.success, ...)` - forward only successful
1499
+ * - `swarm.reduce([...results.success, ...results.filtered], ...)` - forward all evaluated
1500
+ */
1501
+ declare class SwarmResultList<T = FileMap> extends Array<SwarmResult<T>> {
1502
+ /** Returns items with status "success" */
1503
+ get success(): SwarmResult<T>[];
1504
+ /** Returns items with status "filtered" (didn't pass condition) */
1505
+ get filtered(): SwarmResult<T>[];
1506
+ /** Returns items with status "error" */
1507
+ get error(): SwarmResult<T>[];
1508
+ static from<T>(results: SwarmResult<T>[]): SwarmResultList<T>;
1509
+ }
1510
+ /**
1511
+ * Result from reduce operation.
1512
+ *
1513
+ * @typeParam T - Data type. Defaults to FileMap when no schema provided.
1514
+ */
1515
+ interface ReduceResult<T = FileMap> {
1516
+ status: "success" | "error";
1517
+ data: T | null;
1518
+ files: FileMap;
1519
+ meta: ReduceMeta;
1520
+ error?: string;
1521
+ /** Raw result.json string when parse or validation failed (for debugging) */
1522
+ rawData?: string;
1523
+ /** Present when verify option was used. Contains verification outcome. */
1524
+ verify?: VerifyInfo;
1525
+ }
1526
+ /**
1527
+ * Result from bestOf operation.
1528
+ *
1529
+ * @typeParam T - Data type for candidates.
1530
+ */
1531
+ interface BestOfResult<T = FileMap> {
1532
+ winner: SwarmResult<T>;
1533
+ winnerIndex: number;
1534
+ judgeReasoning: string;
1535
+ judgeMeta: JudgeMeta;
1536
+ candidates: SwarmResult<T>[];
1537
+ }
1538
+ /** Fixed schema for bestOf judge output */
1539
+ interface JudgeDecision {
1540
+ winner: number;
1541
+ reasoning: string;
1542
+ }
1543
+ /** Fixed schema for verify output */
1544
+ interface VerifyDecision {
1545
+ passed: boolean;
1546
+ reasoning: string;
1547
+ feedback?: string;
1548
+ }
1549
+ /** Verification info attached to results when verify option used */
1550
+ interface VerifyInfo {
1551
+ passed: boolean;
1552
+ reasoning: string;
1553
+ verifyMeta: VerifyMeta;
1554
+ attempts: number;
1555
+ }
1556
+ type ItemInput = FileMap | SwarmResult<unknown>;
1557
+ type PromptFn = (files: FileMap, index: number) => string;
1558
+ type Prompt = string | PromptFn;
1559
+ /** @internal Pipeline context for observability (set by Pipeline, not user) */
1560
+ interface PipelineContext {
1561
+ pipelineRunId: string;
1562
+ pipelineStepIndex: number;
1563
+ }
1564
+ /** Parameters for map operation */
1565
+ interface MapParams<T> {
1566
+ /** Items to process (FileMaps or SwarmResults from previous operation) */
1567
+ items: ItemInput[];
1568
+ /** Task prompt (string or function(files, index) -> string) */
1569
+ prompt: Prompt;
1570
+ /** Optional operation name for observability */
1571
+ name?: string;
1572
+ /** Optional system prompt */
1573
+ systemPrompt?: string;
1574
+ /** @internal Pipeline context (set by Pipeline, not user) */
1575
+ _pipelineContext?: PipelineContext;
1576
+ /** Schema for structured output (Zod or JSON Schema) */
1577
+ schema?: z.ZodType<T> | JsonSchema;
1578
+ /** Validation options for JSON Schema (ignored for Zod) */
1579
+ schemaOptions?: SchemaValidationOptions;
1580
+ /** Optional agent override */
1581
+ agent?: AgentOverride;
1582
+ /** MCP servers override (replaces swarm default) */
1583
+ mcpServers?: Record<string, McpServerConfig>;
1584
+ /** Skills override (replaces swarm default) */
1585
+ skills?: SkillName[];
1586
+ /** Composio override (replaces swarm default) */
1587
+ composio?: ComposioSetup;
1588
+ /** Optional bestOf configuration for N candidates + judge (mutually exclusive with verify) */
1589
+ bestOf?: BestOfConfig;
1590
+ /** Optional verify configuration for LLM-as-judge quality verification with retry (mutually exclusive with bestOf) */
1591
+ verify?: VerifyConfig;
1592
+ /** Per-item retry configuration. Typed to allow retryOn access to SwarmResult fields. */
1593
+ retry?: RetryConfig<SwarmResult<T>>;
1594
+ /** Optional timeout in ms */
1595
+ timeoutMs?: number;
1596
+ }
1597
+ /** Parameters for filter operation */
1598
+ interface FilterParams<T> {
1599
+ /** Items to filter (FileMaps or SwarmResults from previous operation) */
1600
+ items: ItemInput[];
1601
+ /** Evaluation prompt - describe what to assess and how (agent outputs result.json) */
1602
+ prompt: string;
1603
+ /** Optional operation name for observability */
1604
+ name?: string;
1605
+ /** @internal Pipeline context (set by Pipeline, not user) */
1606
+ _pipelineContext?: PipelineContext;
1607
+ /** Schema for structured output (Zod or JSON Schema) */
1608
+ schema: z.ZodType<T> | JsonSchema;
1609
+ /** Validation options for JSON Schema (ignored for Zod) */
1610
+ schemaOptions?: SchemaValidationOptions;
1611
+ /** Local condition function to determine pass/fail */
1612
+ condition: (data: T) => boolean;
1613
+ /** Optional system prompt */
1614
+ systemPrompt?: string;
1615
+ /** Optional agent override */
1616
+ agent?: AgentOverride;
1617
+ /** MCP servers override (replaces swarm default) */
1618
+ mcpServers?: Record<string, McpServerConfig>;
1619
+ /** Skills override (replaces swarm default) */
1620
+ skills?: SkillName[];
1621
+ /** Composio override (replaces swarm default) */
1622
+ composio?: ComposioSetup;
1623
+ /** Optional verify configuration for LLM-as-judge quality verification with retry */
1624
+ verify?: VerifyConfig;
1625
+ /** Per-item retry configuration. Typed to allow retryOn access to SwarmResult fields. */
1626
+ retry?: RetryConfig<SwarmResult<T>>;
1627
+ /** Optional timeout in ms */
1628
+ timeoutMs?: number;
1629
+ }
1630
+ /** Parameters for reduce operation */
1631
+ interface ReduceParams<T> {
1632
+ /** Items to reduce (FileMaps or SwarmResults from previous operation) */
1633
+ items: ItemInput[];
1634
+ /** Synthesis prompt */
1635
+ prompt: string;
1636
+ /** Optional operation name for observability */
1637
+ name?: string;
1638
+ /** Optional system prompt */
1639
+ systemPrompt?: string;
1640
+ /** @internal Pipeline context (set by Pipeline, not user) */
1641
+ _pipelineContext?: PipelineContext;
1642
+ /** Schema for structured output (Zod or JSON Schema) */
1643
+ schema?: z.ZodType<T> | JsonSchema;
1644
+ /** Validation options for JSON Schema (ignored for Zod) */
1645
+ schemaOptions?: SchemaValidationOptions;
1646
+ /** Optional agent override */
1647
+ agent?: AgentOverride;
1648
+ /** MCP servers override (replaces swarm default) */
1649
+ mcpServers?: Record<string, McpServerConfig>;
1650
+ /** Skills override (replaces swarm default) */
1651
+ skills?: SkillName[];
1652
+ /** Composio override (replaces swarm default) */
1653
+ composio?: ComposioSetup;
1654
+ /** Optional verify configuration for LLM-as-judge quality verification with retry */
1655
+ verify?: VerifyConfig;
1656
+ /** Retry configuration (retries entire reduce on error). Typed to allow retryOn access to ReduceResult fields. */
1657
+ retry?: RetryConfig<ReduceResult<T>>;
1658
+ /** Optional timeout in ms */
1659
+ timeoutMs?: number;
1660
+ }
1661
+ /** Parameters for bestOf operation */
1662
+ interface BestOfParams<T> {
1663
+ /** Single item to process */
1664
+ item: ItemInput;
1665
+ /** Task prompt */
1666
+ prompt: string;
1667
+ /** Optional operation name for observability */
1668
+ name?: string;
1669
+ /** BestOf configuration (n, judgeCriteria, taskAgents, judgeAgent, mcpServers, skills, composio) */
1670
+ config: BestOfConfig;
1671
+ /** Optional system prompt */
1672
+ systemPrompt?: string;
1673
+ /** Schema for structured output (Zod or JSON Schema) */
1674
+ schema?: z.ZodType<T> | JsonSchema;
1675
+ /** Validation options for JSON Schema (ignored for Zod) */
1676
+ schemaOptions?: SchemaValidationOptions;
1677
+ /**
1678
+ * Per-candidate retry configuration. Typed to allow retryOn access to SwarmResult fields.
1679
+ * Note: Judge always uses default retryOn (status === "error"), ignoring custom retryOn.
1680
+ */
1681
+ retry?: RetryConfig<SwarmResult<T>>;
1682
+ /** Optional timeout in ms */
1683
+ timeoutMs?: number;
1684
+ }
1685
+
1686
+ /**
1687
+ * Simple semaphore for global concurrency control.
1688
+ *
1689
+ * Ensures no more than N sandboxes run concurrently across all swarm operations.
1690
+ */
1691
+ declare class Semaphore {
1692
+ private permits;
1693
+ private queue;
1694
+ constructor(max: number);
1695
+ /**
1696
+ * Execute a function under the semaphore.
1697
+ * Acquires a permit before running, releases after completion.
1698
+ */
1699
+ use<T>(fn: () => Promise<T>): Promise<T>;
1700
+ private acquire;
1701
+ private release;
1702
+ }
1703
+
1704
+ /**
1705
+ * Swarm Abstractions
1706
+ *
1707
+ * Functional programming for AI agents.
1708
+ *
1709
+ * @example
1710
+ * ```typescript
1711
+ * const swarm = new Swarm({
1712
+ * agent: { type: "claude", apiKey: "..." },
1713
+ * sandbox: createE2BProvider({ apiKey: "..." }),
1714
+ * });
1715
+ *
1716
+ * const analyses = await swarm.map({
1717
+ * items: documents,
1718
+ * prompt: "Analyze this",
1719
+ * });
1720
+ *
1721
+ * const evaluated = await swarm.filter({
1722
+ * items: analyses,
1723
+ * prompt: "Evaluate severity",
1724
+ * schema: SeveritySchema,
1725
+ * condition: r => r.severity === "critical",
1726
+ * });
1727
+ * // evaluated.success = passed condition
1728
+ * // evaluated.filtered = didn't pass condition
1729
+ * // evaluated.error = agent errors
1730
+ *
1731
+ * const report = await swarm.reduce({
1732
+ * items: evaluated.success,
1733
+ * prompt: "Create summary",
1734
+ * });
1735
+ * ```
1736
+ */
1737
+
1738
+ declare class Swarm {
1739
+ private config;
1740
+ private semaphore;
1741
+ constructor(config?: SwarmConfig);
1742
+ /**
1743
+ * Apply an agent to each item in parallel.
1744
+ */
1745
+ map<T = FileMap>(params: MapParams<T>): Promise<SwarmResultList<T>>;
1746
+ /**
1747
+ * Two-step evaluation: agent assesses each item, then local condition applies threshold.
1748
+ *
1749
+ * 1. Agent sees context files, evaluates per prompt, outputs result.json matching schema
1750
+ * 2. Condition function receives parsed data, returns true (success) or false (filtered)
1751
+ *
1752
+ * Returns ALL items with status:
1753
+ * - "success": passed condition
1754
+ * - "filtered": evaluated but didn't pass condition
1755
+ * - "error": agent error
1756
+ *
1757
+ * Use `.success` for passing items, `.filtered` for non-passing.
1758
+ */
1759
+ filter<T>(params: FilterParams<T>): Promise<SwarmResultList<T>>;
1760
+ /**
1761
+ * Synthesize many items into one.
1762
+ */
1763
+ reduce<T = FileMap>(params: ReduceParams<T>): Promise<ReduceResult<T>>;
1764
+ /**
1765
+ * Run N candidates on the same task, judge picks the best.
1766
+ */
1767
+ bestOf<T = FileMap>(params: BestOfParams<T>): Promise<BestOfResult<T>>;
1768
+ private execute;
1769
+ private executeMapItem;
1770
+ private executeMapItemWithVerify;
1771
+ private executeMapItemWithBestOf;
1772
+ private executeFilterItem;
1773
+ private executeFilterItemWithVerify;
1774
+ /**
1775
+ * Execute a single bestOf candidate.
1776
+ * Used by both standalone bestOf() and map() with bestOf option.
1777
+ */
1778
+ private executeBestOfCandidate;
1779
+ /**
1780
+ * Build judge context containing worker task info and candidate outputs.
1781
+ */
1782
+ private buildJudgeContext;
1783
+ /**
1784
+ * Execute judge to pick best candidate.
1785
+ * Returns RetryableResult-compatible type for use with executeWithRetry.
1786
+ */
1787
+ private executeBestOfJudge;
1788
+ private static readonly DEFAULT_VERIFY_MAX_ATTEMPTS;
1789
+ private static readonly VerifyDecisionSchema;
1790
+ /**
1791
+ * Build verify context containing worker task info and output to verify.
1792
+ */
1793
+ private buildVerifyContext;
1794
+ /**
1795
+ * Execute verifier to check if output meets criteria.
1796
+ */
1797
+ private executeVerify;
1798
+ /**
1799
+ * Build a retry prompt with verifier feedback.
1800
+ */
1801
+ private static buildRetryPromptWithFeedback;
1802
+ /**
1803
+ * Shared verification loop for map, filter, and reduce.
1804
+ * Runs worker function, verifies output, retries with feedback if needed.
1805
+ *
1806
+ * @param workerFn - Function that executes the worker with a given prompt, tag prefix, and attempt index
1807
+ * @param params - Common verification parameters
1808
+ * @returns Result with verify info attached
1809
+ */
1810
+ private runWithVerification;
1811
+ private generateOperationId;
1812
+ /** Convert pipeline context to observability fields */
1813
+ private pipelineContextToObservability;
1814
+ /** Extract pipeline tracking fields for meta objects */
1815
+ private pipelineContextToMeta;
1816
+ /**
1817
+ * Safely evaluate prompt (string or function).
1818
+ * Returns evaluated string or Error if function threw.
1819
+ */
1820
+ private evaluatePrompt;
1821
+ /**
1822
+ * Build evaluator context (shared by judge and verify).
1823
+ * Creates worker_task/ structure with input files, prompts, schema.
1824
+ */
1825
+ private buildEvaluatorContext;
1826
+ private isSwarmResult;
1827
+ private getFiles;
1828
+ private getIndex;
1829
+ private buildResult;
1830
+ private buildErrorResult;
1831
+ }
1832
+
1833
+ /**
1834
+ * Pipeline Types
1835
+ *
1836
+ * Fluent API for chaining Swarm operations.
1837
+ */
1838
+
1839
+ /**
1840
+ * What filter emits to the next step.
1841
+ *
1842
+ * - "success": Items that passed condition (default)
1843
+ * - "filtered": Items that failed condition
1844
+ * - "all": Both success and filtered
1845
+ */
1846
+ type EmitOption = "success" | "filtered" | "all";
1847
+ /** Base fields shared by all step types */
1848
+ interface BaseStepConfig {
1849
+ /** Step name for observability (appears in events) */
1850
+ name?: string;
1851
+ /** System prompt override */
1852
+ systemPrompt?: string;
1853
+ /** Agent override */
1854
+ agent?: AgentOverride;
1855
+ /** MCP servers override (replaces swarm default for this step) */
1856
+ mcpServers?: Record<string, McpServerConfig>;
1857
+ /** Skills override (replaces swarm default for this step) */
1858
+ skills?: SkillName[];
1859
+ /** Composio override (replaces swarm default for this step) */
1860
+ composio?: ComposioSetup;
1861
+ /** Timeout in ms */
1862
+ timeoutMs?: number;
1863
+ }
1864
+ /** Map step configuration */
1865
+ interface MapConfig<T> extends BaseStepConfig {
1866
+ /** Task prompt */
1867
+ prompt: Prompt;
1868
+ /** Schema for structured output */
1869
+ schema?: z.ZodType<T> | JsonSchema;
1870
+ /** Validation options for JSON Schema */
1871
+ schemaOptions?: SchemaValidationOptions;
1872
+ /** BestOf configuration (mutually exclusive with verify) */
1873
+ bestOf?: BestOfConfig;
1874
+ /** Verify configuration (mutually exclusive with bestOf) */
1875
+ verify?: VerifyConfig;
1876
+ /** Retry configuration */
1877
+ retry?: RetryConfig<SwarmResult<T>>;
1878
+ }
1879
+ /** Filter step configuration */
1880
+ interface FilterConfig<T> extends BaseStepConfig {
1881
+ /** Evaluation prompt */
1882
+ prompt: string;
1883
+ /** Schema for structured output (required) */
1884
+ schema: z.ZodType<T> | JsonSchema;
1885
+ /** Validation options for JSON Schema */
1886
+ schemaOptions?: SchemaValidationOptions;
1887
+ /** Condition function to determine pass/fail */
1888
+ condition: (data: T) => boolean;
1889
+ /** What to emit to next step (default: "success") */
1890
+ emit?: EmitOption;
1891
+ /** Verify configuration */
1892
+ verify?: VerifyConfig;
1893
+ /** Retry configuration */
1894
+ retry?: RetryConfig<SwarmResult<T>>;
1895
+ }
1896
+ /** Reduce step configuration */
1897
+ interface ReduceConfig<T> extends BaseStepConfig {
1898
+ /** Synthesis prompt */
1899
+ prompt: string;
1900
+ /** Schema for structured output */
1901
+ schema?: z.ZodType<T> | JsonSchema;
1902
+ /** Validation options for JSON Schema */
1903
+ schemaOptions?: SchemaValidationOptions;
1904
+ /** Verify configuration */
1905
+ verify?: VerifyConfig;
1906
+ /** Retry configuration */
1907
+ retry?: RetryConfig<ReduceResult<T>>;
1908
+ }
1909
+ /** @internal Step representation */
1910
+ type Step = {
1911
+ type: "map";
1912
+ config: MapConfig<unknown>;
1913
+ } | {
1914
+ type: "filter";
1915
+ config: FilterConfig<unknown>;
1916
+ } | {
1917
+ type: "reduce";
1918
+ config: ReduceConfig<unknown>;
1919
+ };
1920
+ /** @internal Step type literal */
1921
+ type StepType = "map" | "filter" | "reduce";
1922
+ /** Result of a single pipeline step */
1923
+ interface StepResult<T = unknown> {
1924
+ type: StepType;
1925
+ index: number;
1926
+ durationMs: number;
1927
+ results: SwarmResult<T>[] | ReduceResult<T>;
1928
+ }
1929
+ /** Final result from pipeline execution */
1930
+ interface PipelineResult<T = unknown> {
1931
+ /** Unique identifier for this pipeline run */
1932
+ pipelineRunId: string;
1933
+ steps: StepResult<unknown>[];
1934
+ output: SwarmResult<T>[] | ReduceResult<T>;
1935
+ totalDurationMs: number;
1936
+ }
1937
+ /** Step lifecycle event */
1938
+ interface StepEvent {
1939
+ type: StepType;
1940
+ index: number;
1941
+ name?: string;
1942
+ }
1943
+ /** Emitted when step starts */
1944
+ interface StepStartEvent extends StepEvent {
1945
+ itemCount: number;
1946
+ }
1947
+ /** Emitted when step completes */
1948
+ interface StepCompleteEvent extends StepEvent {
1949
+ durationMs: number;
1950
+ successCount: number;
1951
+ errorCount: number;
1952
+ filteredCount: number;
1953
+ }
1954
+ /** Emitted when step errors */
1955
+ interface StepErrorEvent extends StepEvent {
1956
+ error: Error;
1957
+ }
1958
+ /** Emitted on item retry */
1959
+ interface ItemRetryEvent {
1960
+ stepIndex: number;
1961
+ stepName?: string;
1962
+ itemIndex: number;
1963
+ attempt: number;
1964
+ error: string;
1965
+ }
1966
+ /** Emitted when verify worker completes */
1967
+ interface WorkerCompleteEvent {
1968
+ stepIndex: number;
1969
+ stepName?: string;
1970
+ itemIndex: number;
1971
+ attempt: number;
1972
+ status: "success" | "error";
1973
+ }
1974
+ /** Emitted when verifier completes */
1975
+ interface VerifierCompleteEvent {
1976
+ stepIndex: number;
1977
+ stepName?: string;
1978
+ itemIndex: number;
1979
+ attempt: number;
1980
+ passed: boolean;
1981
+ feedback?: string;
1982
+ }
1983
+ /** Emitted when bestOf candidate completes */
1984
+ interface CandidateCompleteEvent {
1985
+ stepIndex: number;
1986
+ stepName?: string;
1987
+ itemIndex: number;
1988
+ candidateIndex: number;
1989
+ status: "success" | "error";
1990
+ }
1991
+ /** Emitted when bestOf judge completes */
1992
+ interface JudgeCompleteEvent {
1993
+ stepIndex: number;
1994
+ stepName?: string;
1995
+ itemIndex: number;
1996
+ winnerIndex: number;
1997
+ reasoning: string;
1998
+ }
1999
+ /** Event handlers */
2000
+ interface PipelineEvents {
2001
+ onStepStart?: (event: StepStartEvent) => void;
2002
+ onStepComplete?: (event: StepCompleteEvent) => void;
2003
+ onStepError?: (event: StepErrorEvent) => void;
2004
+ onItemRetry?: (event: ItemRetryEvent) => void;
2005
+ onWorkerComplete?: (event: WorkerCompleteEvent) => void;
2006
+ onVerifierComplete?: (event: VerifierCompleteEvent) => void;
2007
+ onCandidateComplete?: (event: CandidateCompleteEvent) => void;
2008
+ onJudgeComplete?: (event: JudgeCompleteEvent) => void;
2009
+ }
2010
+ /** Event name mapping for chainable .on() */
2011
+ type EventName = "stepStart" | "stepComplete" | "stepError" | "itemRetry" | "workerComplete" | "verifierComplete" | "candidateComplete" | "judgeComplete";
2012
+ /** Map event name to handler type */
2013
+ type EventHandler<E extends EventName> = E extends "stepStart" ? (event: StepStartEvent) => void : E extends "stepComplete" ? (event: StepCompleteEvent) => void : E extends "stepError" ? (event: StepErrorEvent) => void : E extends "itemRetry" ? (event: ItemRetryEvent) => void : E extends "workerComplete" ? (event: WorkerCompleteEvent) => void : E extends "verifierComplete" ? (event: VerifierCompleteEvent) => void : E extends "candidateComplete" ? (event: CandidateCompleteEvent) => void : E extends "judgeComplete" ? (event: JudgeCompleteEvent) => void : never;
2014
+ /** Event name to handler type mapping (for chainable .on() style) */
2015
+ interface PipelineEventMap {
2016
+ stepStart: (event: StepStartEvent) => void;
2017
+ stepComplete: (event: StepCompleteEvent) => void;
2018
+ stepError: (event: StepErrorEvent) => void;
2019
+ itemRetry: (event: ItemRetryEvent) => void;
2020
+ workerComplete: (event: WorkerCompleteEvent) => void;
2021
+ verifierComplete: (event: VerifierCompleteEvent) => void;
2022
+ candidateComplete: (event: CandidateCompleteEvent) => void;
2023
+ judgeComplete: (event: JudgeCompleteEvent) => void;
2024
+ }
2025
+
2026
+ /**
2027
+ * Pipeline - Fluent API for Swarm Operations
2028
+ *
2029
+ * Thin wrapper over Swarm providing method chaining, timing, and events.
2030
+ *
2031
+ * @example
2032
+ * ```typescript
2033
+ * const pipeline = new Pipeline(swarm)
2034
+ * .map({ prompt: "Analyze..." })
2035
+ * .filter({ prompt: "Rate...", schema, condition: d => d.score > 7 })
2036
+ * .reduce({ prompt: "Summarize..." });
2037
+ *
2038
+ * // Run with items
2039
+ * const result = await pipeline.run(documents);
2040
+ *
2041
+ * // Reusable - run with different data
2042
+ * await pipeline.run(batch1);
2043
+ * await pipeline.run(batch2);
2044
+ * ```
2045
+ */
2046
+
2047
+ /**
2048
+ * Pipeline for chaining Swarm operations.
2049
+ *
2050
+ * Swarm is bound at construction (infrastructure).
2051
+ * Items are passed at execution (data).
2052
+ * Pipeline is immutable - each method returns a new instance.
2053
+ */
2054
+ declare class Pipeline<T = FileMap> {
2055
+ protected readonly swarm: Swarm;
2056
+ protected readonly steps: Step[];
2057
+ protected readonly events: PipelineEvents;
2058
+ constructor(swarm: Swarm, steps?: Step[], events?: PipelineEvents);
2059
+ /** Add a map step to transform items in parallel. */
2060
+ map<U>(config: MapConfig<U>): Pipeline<U>;
2061
+ /** Add a filter step to evaluate and filter items. */
2062
+ filter<U>(config: FilterConfig<U>): Pipeline<U>;
2063
+ /** Add a reduce step (terminal - no steps can follow). */
2064
+ reduce<U>(config: ReduceConfig<U>): TerminalPipeline<U>;
2065
+ /**
2066
+ * Register event handlers for step lifecycle.
2067
+ *
2068
+ * Supports two styles:
2069
+ * - Object: `.on({ onStepComplete: fn, onItemRetry: fn })`
2070
+ * - Chainable: `.on("stepComplete", fn).on("itemRetry", fn)`
2071
+ */
2072
+ on(handlers: PipelineEvents): Pipeline<T>;
2073
+ on<K extends keyof PipelineEventMap>(event: K, handler: PipelineEventMap[K]): Pipeline<T>;
2074
+ /** Execute the pipeline with the given items. */
2075
+ run(items: ItemInput[]): Promise<PipelineResult<T>>;
2076
+ private executeStep;
2077
+ private wrapRetry;
2078
+ private wrapVerify;
2079
+ private wrapBestOf;
2080
+ }
2081
+ /** Pipeline after reduce - no more steps can be added. */
2082
+ declare class TerminalPipeline<T> extends Pipeline<T> {
2083
+ constructor(swarm: Swarm, steps: Step[], events: PipelineEvents);
2084
+ /**
2085
+ * Register event handlers for step lifecycle.
2086
+ *
2087
+ * Supports two styles:
2088
+ * - Object: `.on({ onStepComplete: fn, onItemRetry: fn })`
2089
+ * - Chainable: `.on("stepComplete", fn).on("itemRetry", fn)`
2090
+ */
2091
+ on(handlers: PipelineEvents): TerminalPipeline<T>;
2092
+ on<K extends keyof PipelineEventMap>(event: K, handler: PipelineEventMap[K]): TerminalPipeline<T>;
2093
+ /** @throws Cannot add steps after reduce */
2094
+ map(): never;
2095
+ /** @throws Cannot add steps after reduce */
2096
+ filter(): never;
2097
+ /** @throws Cannot add steps after reduce */
2098
+ reduce(): never;
2099
+ }
2100
+
2101
+ /**
2102
+ * Agent Registry
2103
+ *
2104
+ * Single source of truth for agent-specific behavior.
2105
+ * All differences between agents are data, not code.
2106
+ *
2107
+ * Evidence: sdk-rewrite-v3.md Agent Registry section
2108
+ */
2109
+
2110
+ /** Model configuration */
2111
+ interface ModelInfo {
2112
+ /** Model alias (short name used with --model) */
2113
+ alias: string;
2114
+ /** Full model ID */
2115
+ modelId: string;
2116
+ /** What this model is best for */
2117
+ description: string;
2118
+ }
2119
+ /** MCP configuration for an agent */
2120
+ interface McpConfigInfo {
2121
+ /** Settings directory (e.g., "~/.claude") */
2122
+ settingsDir: string;
2123
+ /** Config filename (e.g., "settings.json" or "config.toml") */
2124
+ filename: string;
2125
+ /** Config format */
2126
+ format: "json" | "toml";
2127
+ /** Whether to use workingDir for project-level config (Claude only) */
2128
+ projectConfig?: boolean;
2129
+ }
2130
+ /** Options for building agent commands */
2131
+ interface BuildCommandOptions {
2132
+ prompt: string;
2133
+ model: string;
2134
+ isResume: boolean;
2135
+ reasoningEffort?: string;
2136
+ betas?: string[];
2137
+ isDirectMode?: boolean;
2138
+ /** Skills enabled for this run */
2139
+ skills?: string[];
2140
+ }
2141
+ interface AgentRegistryEntry {
2142
+ /** E2B template ID for sandbox creation */
2143
+ templateId: string;
2144
+ /** Environment variable name for API key */
2145
+ apiKeyEnv: string;
2146
+ /** Environment variable name for OAuth token (Claude only - Max subscription) */
2147
+ oauthEnv?: string;
2148
+ /** Environment variable name for base URL */
2149
+ baseUrlEnv: string;
2150
+ /** Default model alias */
2151
+ defaultModel: string;
2152
+ /** Available models for this agent */
2153
+ models: ModelInfo[];
2154
+ /** System prompt filename (e.g., "CLAUDE.md") */
2155
+ systemPromptFile: string;
2156
+ /** MCP configuration */
2157
+ mcpConfig: McpConfigInfo;
2158
+ /** Build the CLI command for this agent */
2159
+ buildCommand: (opts: BuildCommandOptions) => string;
2160
+ /** Extra setup step (e.g., codex login) */
2161
+ setupCommand?: string;
2162
+ /** Whether this agent uses passthrough gateway (Gemini) */
2163
+ usePassthroughGateway?: boolean;
2164
+ /** Default base URL for direct mode (only needed if provider requires specific endpoint, e.g., Qwen → Dashscope) */
2165
+ defaultBaseUrl?: string;
2166
+ /** Available beta headers for this agent (for reference) */
2167
+ availableBetas?: Record<string, string>;
2168
+ /** Skills configuration for this agent */
2169
+ skillsConfig: SkillsConfig;
2170
+ }
2171
+ /**
2172
+ * Registry of all supported agents.
2173
+ *
2174
+ * Each agent defines a buildCommand function that constructs the CLI command.
2175
+ * This is type-safe and handles conditional logic cleanly.
2176
+ */
2177
+ declare const AGENT_REGISTRY: Record<AgentType, AgentRegistryEntry>;
2178
+ /**
2179
+ * Get registry entry for an agent type
2180
+ */
2181
+ declare function getAgentConfig(agentType: AgentType): AgentRegistryEntry;
2182
+ /**
2183
+ * Check if an agent type is valid
2184
+ */
2185
+ declare function isValidAgentType(type: string): type is AgentType;
2186
+ /**
2187
+ * Expand path with ~ to /home/user
2188
+ */
2189
+ declare function expandPath(path: string): string;
2190
+ /**
2191
+ * Get MCP settings path for an agent
2192
+ */
2193
+ declare function getMcpSettingsPath(agentType: AgentType): string;
2194
+ /**
2195
+ * Get MCP settings directory for an agent
2196
+ */
2197
+ declare function getMcpSettingsDir(agentType: AgentType): string;
2198
+
2199
+ /**
2200
+ * MCP JSON Configuration Writer
2201
+ *
2202
+ * Handles MCP config for Claude, Gemini, and Qwen agents.
2203
+ * Uses registry for paths - no hardcoded values.
2204
+ *
2205
+ * Transport formats by agent:
2206
+ * - Claude: { type: "http"|"sse"|"stdio", url: "..." }
2207
+ * - Gemini: { url: "...", type: "http"|"sse" } | { command: "..." }
2208
+ * - Qwen: { httpUrl: "..." } | { url: "..." } | { command: "..." }
2209
+ */
2210
+
2211
+ /**
2212
+ * Write MCP config for Claude agent
2213
+ *
2214
+ * Claude uses two files:
2215
+ * 1. ${workingDir}/.mcp.json - project-level MCP servers
2216
+ * 2. ~/.claude/settings.json - enable project MCP servers
2217
+ */
2218
+ declare function writeClaudeMcpConfig(sandbox: SandboxInstance, workingDir: string, servers: Record<string, McpServerConfig>): Promise<void>;
2219
+ /** Write MCP config for Gemini agent */
2220
+ declare function writeGeminiMcpConfig(sandbox: SandboxInstance, servers: Record<string, McpServerConfig>): Promise<void>;
2221
+ /** Write MCP config for Qwen agent */
2222
+ declare function writeQwenMcpConfig(sandbox: SandboxInstance, servers: Record<string, McpServerConfig>): Promise<void>;
2223
+
2224
+ /**
2225
+ * MCP TOML Configuration Writer
2226
+ *
2227
+ * Handles MCP config for Codex agent which uses TOML format.
2228
+ * Uses registry for paths - no hardcoded values.
2229
+ */
2230
+
2231
+ /**
2232
+ * Write MCP config for Codex agent
2233
+ *
2234
+ * Codex stores MCP config in ~/.codex/config.toml using TOML format.
2235
+ * Format: [mcp_servers.server_name] sections
2236
+ */
2237
+ declare function writeCodexMcpConfig(sandbox: SandboxInstance, servers: Record<string, McpServerConfig>): Promise<void>;
2238
+
2239
+ /**
2240
+ * MCP Configuration Module
2241
+ *
2242
+ * Unified entry point for writing MCP server configs.
2243
+ * Routes to the appropriate writer based on agent type.
2244
+ */
2245
+
2246
+ /**
2247
+ * Write MCP server configuration for an agent
2248
+ *
2249
+ * Routes to the appropriate config writer based on agent type:
2250
+ * - Claude: JSON to ${workingDir}/.mcp.json + ~/.claude/settings.json
2251
+ * - Codex: TOML to ~/.codex/config.toml
2252
+ * - Gemini: JSON to ~/.gemini/settings.json
2253
+ * - Qwen: JSON to ~/.qwen/settings.json
2254
+ */
2255
+ declare function writeMcpConfig(agentType: AgentType, sandbox: SandboxInstance, workingDir: string, servers: Record<string, McpServerConfig>): Promise<void>;
2256
+
2257
+ /**
2258
+ * Prompt Templates
2259
+ *
2260
+ * Prompts are stored as markdown files for easy editing.
2261
+ * They are inlined at build time via tsup's text loader.
2262
+ */
2263
+
2264
+ /**
2265
+ * Workspace system prompt template (knowledge mode)
2266
+ *
2267
+ * Placeholders:
2268
+ * - {{workingDir}} - The working directory path
2269
+ */
2270
+ declare const WORKSPACE_PROMPT: string;
2271
+ /**
2272
+ * Workspace system prompt template (SWE mode - includes repo/ folder)
2273
+ *
2274
+ * Placeholders:
2275
+ * - {{workingDir}} - The working directory path
2276
+ */
2277
+ declare const WORKSPACE_SWE_PROMPT: string;
2278
+ /**
2279
+ * User system prompt wrapper template
2280
+ *
2281
+ * Placeholders:
2282
+ * - {{systemPrompt}} - The user's system prompt content
2283
+ */
2284
+ declare const SYSTEM_PROMPT: string;
2285
+ /**
2286
+ * Structured output schema prompt template (for Swarm abstractions)
2287
+ *
2288
+ * Placeholders:
2289
+ * - {{schema}} - JSON schema for the expected output
2290
+ */
2291
+ declare const SCHEMA_PROMPT: string;
2292
+ /**
2293
+ * Judge system prompt template (for Swarm best_of)
2294
+ *
2295
+ * Placeholders:
2296
+ * - {{candidateCount}} - Number of candidates
2297
+ * - {{criteria}} - Evaluation criteria
2298
+ * - {{fileTree}} - Tree view of context folders
2299
+ */
2300
+ declare const JUDGE_PROMPT: string;
2301
+ /**
2302
+ * Verify system prompt template (for Swarm verify option)
2303
+ *
2304
+ * Placeholders:
2305
+ * - {{criteria}} - Verification criteria
2306
+ * - {{fileTree}} - Tree view of context folders
2307
+ */
2308
+ declare const VERIFY_PROMPT: string;
2309
+ /**
2310
+ * Retry feedback prompt template (for Swarm verify retry)
2311
+ *
2312
+ * Replaces the user prompt when verification fails and retry is needed.
2313
+ *
2314
+ * Placeholders:
2315
+ * - {{originalPrompt}} - The original user prompt
2316
+ * - {{feedback}} - Verifier's feedback on what needs to be fixed
2317
+ */
2318
+ declare const RETRY_FEEDBACK_PROMPT: string;
2319
+ /**
2320
+ * Apply template variables to a prompt
2321
+ */
2322
+ declare function applyTemplate(template: string, variables: Record<string, string>): string;
2323
+ /**
2324
+ * Build worker system prompt
2325
+ *
2326
+ * Used by Agent class to generate the system prompt file written to sandbox.
2327
+ *
2328
+ * @param mode - "knowledge" (default) or "swe" (includes repo/ folder)
2329
+ */
2330
+ declare function buildWorkerSystemPrompt(options: {
2331
+ workingDir: string;
2332
+ systemPrompt?: string;
2333
+ schema?: z.ZodType<unknown> | Record<string, unknown>;
2334
+ mode?: "knowledge" | "swe";
2335
+ }): string;
2336
+
2337
+ /**
2338
+ * Schema Utilities
2339
+ *
2340
+ * Functions for working with Zod and JSON Schema.
2341
+ */
2342
+
2343
+ /**
2344
+ * Check if a schema is a Zod schema (has safeParse method)
2345
+ */
2346
+ declare function isZodSchema(schema: unknown): schema is z.ZodType<unknown>;
2347
+ /**
2348
+ * Convert Zod schema to JSON Schema string
2349
+ */
2350
+ declare function zodSchemaToJson(schema: z.ZodType<unknown>): string;
2351
+ /**
2352
+ * Convert JSON Schema object to formatted string
2353
+ */
2354
+ declare function jsonSchemaToString(schema: Record<string, unknown>): string;
2355
+
2356
+ /**
2357
+ * File Utilities
2358
+ *
2359
+ * Functions for reading and writing local files as FileMaps.
2360
+ */
2361
+
2362
+ /**
2363
+ * Read files from a local directory, returning a FileMap.
2364
+ *
2365
+ * @param localPath - Path to local directory
2366
+ * @param recursive - Read subdirectories recursively (default: false)
2367
+ * @returns FileMap with relative paths as keys
2368
+ *
2369
+ * @example
2370
+ * // Top-level files only (default)
2371
+ * readLocalDir('./folder')
2372
+ * // { "file.txt": Buffer }
2373
+ *
2374
+ * // Recursive - includes subdirectories
2375
+ * readLocalDir('./folder', true)
2376
+ * // { "file.txt": Buffer, "subdir/nested.txt": Buffer }
2377
+ */
2378
+ declare function readLocalDir(localPath: string, recursive?: boolean): FileMap;
2379
+ /**
2380
+ * Save a FileMap to a local directory, creating nested directories as needed.
2381
+ *
2382
+ * @param localPath - Base directory to save files to
2383
+ * @param files - FileMap to save (from getOutputFiles or other source)
2384
+ *
2385
+ * @example
2386
+ * // Save output files to local directory
2387
+ * const output = await agent.getOutputFiles(true);
2388
+ * saveLocalDir('./output', output.files);
2389
+ * // Creates: ./output/file.txt, ./output/subdir/nested.txt, etc.
2390
+ */
2391
+ declare function saveLocalDir(localPath: string, files: FileMap): void;
2392
+
2393
+ export { AGENT_REGISTRY, AGENT_TYPES, Agent, type AgentConfig, type AgentOptions, type AgentOverride, type AgentParser, type AgentRegistryEntry, type AgentResponse, type AgentType, type BaseMeta, type BestOfConfig, type BestOfParams, type BestOfResult, type CandidateCompleteEvent, type ComposioAuthResult, type ComposioConfig, type ComposioConnectionStatus, type ComposioSetup, type EmitOption, type EventHandler, type EventName, Evolve, type EvolveConfig, type EvolveEvents, type ExecuteCommandOptions, type FileMap, type FilterConfig, type FilterParams, type IndexedMeta, type ItemInput, type ItemRetryEvent, JUDGE_PROMPT, type JsonSchema, type JudgeCompleteEvent, type JudgeDecision, type JudgeMeta, type MapConfig, type MapParams, type McpConfigInfo, type McpServerConfig, type ModelInfo, type OnCandidateCompleteCallback, type OnItemRetryCallback, type OnJudgeCompleteCallback, type OnVerifierCompleteCallback, type OnWorkerCompleteCallback, type OperationType, type OutputEvent, type OutputResult, Pipeline, type PipelineContext, type PipelineEventMap, type PipelineEvents, type PipelineResult, type ProcessInfo, type Prompt, type PromptFn, RETRY_FEEDBACK_PROMPT, type ReasoningEffort, type ReduceConfig, type ReduceMeta, type ReduceParams, type ReduceResult, type RetryConfig, type RunOptions, SCHEMA_PROMPT, SWARM_RESULT_BRAND, SYSTEM_PROMPT, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxCreateOptions, type SandboxFiles, type SandboxInstance, type SandboxProvider, type SandboxRunOptions, type SandboxSpawnOptions, type SchemaValidationOptions, Semaphore, type SkillName, type SkillsConfig, type StepCompleteEvent, type StepErrorEvent, type StepEvent, type StepResult, type StepStartEvent, type StreamCallbacks, Swarm, type SwarmConfig, type SwarmResult, SwarmResultList, TerminalPipeline, type ToolsFilter, VALIDATION_PRESETS, VERIFY_PROMPT, type ValidationMode, type VerifierCompleteEvent, type VerifyConfig, type VerifyDecision, type VerifyInfo, type VerifyMeta, WORKSPACE_PROMPT, WORKSPACE_SWE_PROMPT, type WorkerCompleteEvent, type WorkspaceMode, applyTemplate, buildWorkerSystemPrompt, createAgentParser, createClaudeParser, createCodexParser, createGeminiParser, executeWithRetry, expandPath, getAgentConfig, getMcpSettingsDir, getMcpSettingsPath, isValidAgentType, isZodSchema, jsonSchemaToString, parseNdjsonLine, parseNdjsonOutput, parseQwenOutput, readLocalDir, saveLocalDir, writeClaudeMcpConfig, writeCodexMcpConfig, writeGeminiMcpConfig, writeMcpConfig, writeQwenMcpConfig, zodSchemaToJson };