@witqq/agent-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +310 -0
- package/dist/backends/claude.cjs +718 -0
- package/dist/backends/claude.cjs.map +1 -0
- package/dist/backends/claude.d.cts +118 -0
- package/dist/backends/claude.d.ts +118 -0
- package/dist/backends/claude.js +714 -0
- package/dist/backends/claude.js.map +1 -0
- package/dist/backends/copilot.cjs +651 -0
- package/dist/backends/copilot.cjs.map +1 -0
- package/dist/backends/copilot.d.cts +121 -0
- package/dist/backends/copilot.d.ts +121 -0
- package/dist/backends/copilot.js +647 -0
- package/dist/backends/copilot.js.map +1 -0
- package/dist/backends/vercel-ai.cjs +620 -0
- package/dist/backends/vercel-ai.cjs.map +1 -0
- package/dist/backends/vercel-ai.d.cts +99 -0
- package/dist/backends/vercel-ai.d.ts +99 -0
- package/dist/backends/vercel-ai.js +615 -0
- package/dist/backends/vercel-ai.js.map +1 -0
- package/dist/index.cjs +505 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +444 -0
- package/dist/index.d.ts +444 -0
- package/dist/index.js +453 -0
- package/dist/index.js.map +1 -0
- package/dist/types-JVBEqeDw.d.cts +288 -0
- package/dist/types-JVBEqeDw.d.ts +288 -0
- package/package.json +110 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Pluggable store for persisting permission (scope) decisions across runs. */
|
|
4
|
+
interface IPermissionStore {
|
|
5
|
+
/** Check if tool is already approved */
|
|
6
|
+
isApproved(toolName: string): Promise<boolean>;
|
|
7
|
+
/** Store an approval decision */
|
|
8
|
+
approve(toolName: string, scope: PermissionScope): Promise<void>;
|
|
9
|
+
/** Revoke approval for a tool */
|
|
10
|
+
revoke(toolName: string): Promise<void>;
|
|
11
|
+
/** Clear all approvals */
|
|
12
|
+
clear(): Promise<void>;
|
|
13
|
+
/** Dispose resources */
|
|
14
|
+
dispose(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** In-memory store — approvals live until process exits (or dispose). */
|
|
17
|
+
declare class InMemoryPermissionStore implements IPermissionStore {
|
|
18
|
+
private approvals;
|
|
19
|
+
isApproved(toolName: string): Promise<boolean>;
|
|
20
|
+
approve(toolName: string, scope: PermissionScope): Promise<void>;
|
|
21
|
+
revoke(toolName: string): Promise<void>;
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
dispose(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/** File-backed store — reads/writes a JSON file for persistent approvals. */
|
|
26
|
+
declare class FilePermissionStore implements IPermissionStore {
|
|
27
|
+
private readonly filePath;
|
|
28
|
+
constructor(filePath: string);
|
|
29
|
+
isApproved(toolName: string): Promise<boolean>;
|
|
30
|
+
approve(toolName: string, scope: PermissionScope): Promise<void>;
|
|
31
|
+
revoke(toolName: string): Promise<void>;
|
|
32
|
+
clear(): Promise<void>;
|
|
33
|
+
dispose(): Promise<void>;
|
|
34
|
+
private readFile;
|
|
35
|
+
private writeFileAtomic;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Composes multiple stores — checks in order, routes writes by scope.
|
|
39
|
+
*
|
|
40
|
+
* - "session" → sessionStore (in-memory)
|
|
41
|
+
* - "project" → projectStore (file-based in project directory)
|
|
42
|
+
* - "always" → userStore (file-based in user home)
|
|
43
|
+
*/
|
|
44
|
+
declare class CompositePermissionStore implements IPermissionStore {
|
|
45
|
+
private readonly sessionStore;
|
|
46
|
+
private readonly projectStore;
|
|
47
|
+
private readonly userStore;
|
|
48
|
+
constructor(sessionStore: IPermissionStore, projectStore: IPermissionStore, userStore?: IPermissionStore);
|
|
49
|
+
isApproved(toolName: string): Promise<boolean>;
|
|
50
|
+
approve(toolName: string, scope: PermissionScope): Promise<void>;
|
|
51
|
+
revoke(toolName: string): Promise<void>;
|
|
52
|
+
clear(): Promise<void>;
|
|
53
|
+
dispose(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/** Create a default composite store with separate project and user-level persistence. */
|
|
56
|
+
declare function createDefaultPermissionStore(projectDir?: string): CompositePermissionStore;
|
|
57
|
+
|
|
58
|
+
/** JSON-serializable value used for tool arguments and results */
|
|
59
|
+
type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
60
|
+
[key: string]: JSONValue;
|
|
61
|
+
};
|
|
62
|
+
/** Message content — plain string or array of text/image parts */
|
|
63
|
+
type MessageContent = string | Array<ContentPart>;
|
|
64
|
+
/** Individual content part within a multi-part message */
|
|
65
|
+
type ContentPart = {
|
|
66
|
+
type: "text";
|
|
67
|
+
text: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: "image";
|
|
70
|
+
data: string;
|
|
71
|
+
mimeType: string;
|
|
72
|
+
};
|
|
73
|
+
/** What the LLM sees — name, description, schema. Passed to all backends. */
|
|
74
|
+
interface ToolDeclaration<TParams = unknown> {
|
|
75
|
+
name: string;
|
|
76
|
+
description: string;
|
|
77
|
+
parameters: z.ZodType<TParams>;
|
|
78
|
+
needsApproval?: boolean;
|
|
79
|
+
metadata?: {
|
|
80
|
+
category?: string;
|
|
81
|
+
icon?: string;
|
|
82
|
+
tags?: string[];
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Full tool with execute function. Required for API-based backends.
|
|
86
|
+
* CLI backends extract declaration; execute map held internally. */
|
|
87
|
+
interface ToolDefinition<TParams = unknown> extends ToolDeclaration<TParams> {
|
|
88
|
+
execute: (params: TParams) => Promise<JSONValue> | JSONValue;
|
|
89
|
+
}
|
|
90
|
+
/** A tool call made by the LLM during execution */
|
|
91
|
+
interface ToolCall {
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
args: JSONValue;
|
|
95
|
+
}
|
|
96
|
+
/** Result of executing a tool call */
|
|
97
|
+
interface ToolResult {
|
|
98
|
+
toolCallId: string;
|
|
99
|
+
name: string;
|
|
100
|
+
result: JSONValue;
|
|
101
|
+
isError?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/** Conversation message — discriminated union on `role` */
|
|
104
|
+
type Message = {
|
|
105
|
+
role: "user";
|
|
106
|
+
content: MessageContent;
|
|
107
|
+
} | {
|
|
108
|
+
role: "assistant";
|
|
109
|
+
content: MessageContent;
|
|
110
|
+
toolCalls?: ToolCall[];
|
|
111
|
+
} | {
|
|
112
|
+
role: "tool";
|
|
113
|
+
content?: string;
|
|
114
|
+
toolResults: ToolResult[];
|
|
115
|
+
} | {
|
|
116
|
+
role: "system";
|
|
117
|
+
content: string;
|
|
118
|
+
};
|
|
119
|
+
/** Scope for "remember this decision" */
|
|
120
|
+
type PermissionScope = "once" | "session" | "project" | "always";
|
|
121
|
+
/** What the permission callback receives */
|
|
122
|
+
interface PermissionRequest {
|
|
123
|
+
toolName: string;
|
|
124
|
+
toolArgs: Record<string, unknown>;
|
|
125
|
+
/** SDK-suggested scope (from Claude CLI's suggestions) */
|
|
126
|
+
suggestedScope?: PermissionScope;
|
|
127
|
+
/** Original SDK permission request (for pass-through) */
|
|
128
|
+
rawSDKRequest?: unknown;
|
|
129
|
+
}
|
|
130
|
+
/** What the permission callback returns */
|
|
131
|
+
interface PermissionDecision {
|
|
132
|
+
allowed: boolean;
|
|
133
|
+
/** How long to remember this decision */
|
|
134
|
+
scope?: PermissionScope;
|
|
135
|
+
/** Modified tool arguments (tool args may be altered by user) */
|
|
136
|
+
modifiedInput?: Record<string, unknown>;
|
|
137
|
+
/** Denial reason (if denied) */
|
|
138
|
+
reason?: string;
|
|
139
|
+
}
|
|
140
|
+
/** Permission callback signature */
|
|
141
|
+
type PermissionCallback = (request: PermissionRequest, signal: AbortSignal) => Promise<PermissionDecision>;
|
|
142
|
+
/** Request for user input — separate from permissions */
|
|
143
|
+
interface UserInputRequest {
|
|
144
|
+
question: string;
|
|
145
|
+
choices?: string[];
|
|
146
|
+
/** Whether to allow freeform text input (default: true) */
|
|
147
|
+
allowFreeform?: boolean;
|
|
148
|
+
}
|
|
149
|
+
/** Response from user to an input request */
|
|
150
|
+
interface UserInputResponse {
|
|
151
|
+
answer: string;
|
|
152
|
+
/** true if user typed a custom answer instead of selecting a choice */
|
|
153
|
+
wasFreeform: boolean;
|
|
154
|
+
/** Index of selected choice (if choice was selected) */
|
|
155
|
+
selectedChoiceIndex?: number;
|
|
156
|
+
}
|
|
157
|
+
/** Hooks for supervisor/UI to intercept agent actions */
|
|
158
|
+
interface SupervisorHooks {
|
|
159
|
+
onPermission?: PermissionCallback;
|
|
160
|
+
onAskUser?: (request: UserInputRequest, signal: AbortSignal) => Promise<UserInputResponse>;
|
|
161
|
+
}
|
|
162
|
+
/** Configuration for typed structured output from LLM */
|
|
163
|
+
interface StructuredOutputConfig<T = unknown> {
|
|
164
|
+
schema: z.ZodType<T>;
|
|
165
|
+
name?: string;
|
|
166
|
+
description?: string;
|
|
167
|
+
}
|
|
168
|
+
/** Events emitted during streaming agent execution */
|
|
169
|
+
type AgentEvent = {
|
|
170
|
+
type: "text_delta";
|
|
171
|
+
text: string;
|
|
172
|
+
} | {
|
|
173
|
+
type: "tool_call_start";
|
|
174
|
+
toolName: string;
|
|
175
|
+
args: JSONValue;
|
|
176
|
+
} | {
|
|
177
|
+
type: "tool_call_end";
|
|
178
|
+
toolName: string;
|
|
179
|
+
result: JSONValue;
|
|
180
|
+
} | {
|
|
181
|
+
type: "permission_request";
|
|
182
|
+
request: PermissionRequest;
|
|
183
|
+
} | {
|
|
184
|
+
type: "permission_response";
|
|
185
|
+
toolName: string;
|
|
186
|
+
decision: PermissionDecision;
|
|
187
|
+
} | {
|
|
188
|
+
type: "ask_user";
|
|
189
|
+
request: UserInputRequest;
|
|
190
|
+
} | {
|
|
191
|
+
type: "ask_user_response";
|
|
192
|
+
answer: string;
|
|
193
|
+
} | {
|
|
194
|
+
type: "thinking_start";
|
|
195
|
+
} | {
|
|
196
|
+
type: "thinking_end";
|
|
197
|
+
} | {
|
|
198
|
+
type: "usage_update";
|
|
199
|
+
promptTokens: number;
|
|
200
|
+
completionTokens: number;
|
|
201
|
+
} | {
|
|
202
|
+
type: "error";
|
|
203
|
+
error: string;
|
|
204
|
+
recoverable: boolean;
|
|
205
|
+
} | {
|
|
206
|
+
type: "done";
|
|
207
|
+
finalOutput: string | null;
|
|
208
|
+
structuredOutput?: unknown;
|
|
209
|
+
};
|
|
210
|
+
/** Options passed to agent.run() / agent.stream() */
|
|
211
|
+
interface RunOptions {
|
|
212
|
+
/** AbortSignal for cancellation */
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
/** Arbitrary context passed to the agent run */
|
|
215
|
+
context?: Record<string, unknown>;
|
|
216
|
+
}
|
|
217
|
+
/** LLM model parameters */
|
|
218
|
+
interface ModelParams {
|
|
219
|
+
temperature?: number;
|
|
220
|
+
maxTokens?: number;
|
|
221
|
+
topP?: number;
|
|
222
|
+
stopSequences?: string[];
|
|
223
|
+
}
|
|
224
|
+
/** Timeout configuration for agent operations */
|
|
225
|
+
interface TimeoutConfig {
|
|
226
|
+
/** Max time for entire agent run (ms) */
|
|
227
|
+
total?: number;
|
|
228
|
+
/** Max time for a single tool execution (ms) */
|
|
229
|
+
perTool?: number;
|
|
230
|
+
/** Max time for a single LLM request (ms) */
|
|
231
|
+
perLLMRequest?: number;
|
|
232
|
+
}
|
|
233
|
+
/** Error handling strategy configuration */
|
|
234
|
+
interface ErrorHandlingConfig {
|
|
235
|
+
/** What to do when a tool throws */
|
|
236
|
+
onToolError?: "fail" | "continue" | "ask-llm";
|
|
237
|
+
/** Retry config for transient LLM failures */
|
|
238
|
+
retryLLM?: {
|
|
239
|
+
maxAttempts: number;
|
|
240
|
+
backoffMs: number;
|
|
241
|
+
};
|
|
242
|
+
/** Global error callback for monitoring */
|
|
243
|
+
onError?: (error: Error, context: {
|
|
244
|
+
phase: "tool" | "llm" | "permission" | "ask-user";
|
|
245
|
+
}) => void;
|
|
246
|
+
}
|
|
247
|
+
/** Configuration for creating an agent */
|
|
248
|
+
interface AgentConfig {
|
|
249
|
+
model?: string;
|
|
250
|
+
modelParams?: ModelParams;
|
|
251
|
+
systemPrompt: string;
|
|
252
|
+
tools: ToolDefinition[];
|
|
253
|
+
supervisor?: SupervisorHooks;
|
|
254
|
+
maxTurns?: number;
|
|
255
|
+
timeout?: TimeoutConfig;
|
|
256
|
+
errorHandling?: ErrorHandlingConfig;
|
|
257
|
+
/** Pluggable store for persisting permission scope decisions across runs */
|
|
258
|
+
permissionStore?: IPermissionStore;
|
|
259
|
+
}
|
|
260
|
+
/** Result of an agent run, generic over structured output type T */
|
|
261
|
+
interface AgentResult<T = void> {
|
|
262
|
+
output: string | null;
|
|
263
|
+
structuredOutput: T extends void ? undefined : T;
|
|
264
|
+
toolCalls: Array<{
|
|
265
|
+
toolName: string;
|
|
266
|
+
args: JSONValue;
|
|
267
|
+
result: JSONValue;
|
|
268
|
+
approved: boolean;
|
|
269
|
+
}>;
|
|
270
|
+
messages: Message[];
|
|
271
|
+
usage?: {
|
|
272
|
+
promptTokens: number;
|
|
273
|
+
completionTokens: number;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/** Agent lifecycle state */
|
|
277
|
+
type AgentState = "idle" | "running" | "streaming" | "disposed";
|
|
278
|
+
/** Core agent interface — run prompts, stream events, manage lifecycle */
|
|
279
|
+
interface IAgent {
|
|
280
|
+
run(prompt: MessageContent, options?: RunOptions): Promise<AgentResult>;
|
|
281
|
+
runWithContext(messages: Message[], options?: RunOptions): Promise<AgentResult>;
|
|
282
|
+
runStructured<T>(prompt: MessageContent, schema: StructuredOutputConfig<T>, options?: RunOptions): Promise<AgentResult<T>>;
|
|
283
|
+
stream(prompt: MessageContent, options?: RunOptions): AsyncIterable<AgentEvent>;
|
|
284
|
+
abort(): void;
|
|
285
|
+
getState(): AgentState;
|
|
286
|
+
getConfig(): Readonly<AgentConfig>;
|
|
287
|
+
/** Release resources. After dispose(), agent must not be used. */
|
|
288
|
+
dispose(): void;
|
|
289
|
+
}
|
|
290
|
+
/** Model metadata returned by listModels() */
|
|
291
|
+
interface ModelInfo {
|
|
292
|
+
id: string;
|
|
293
|
+
name?: string;
|
|
294
|
+
provider?: string;
|
|
295
|
+
}
|
|
296
|
+
/** Result of backend validation check */
|
|
297
|
+
interface ValidationResult {
|
|
298
|
+
valid: boolean;
|
|
299
|
+
errors: string[];
|
|
300
|
+
}
|
|
301
|
+
/** Backend service interface — creates agents, lists models, validates config */
|
|
302
|
+
interface IAgentService {
|
|
303
|
+
readonly name: string;
|
|
304
|
+
createAgent(config: AgentConfig): IAgent;
|
|
305
|
+
listModels(): Promise<ModelInfo[]>;
|
|
306
|
+
validate(): Promise<ValidationResult>;
|
|
307
|
+
dispose(): Promise<void>;
|
|
308
|
+
}
|
|
309
|
+
/** Options for Copilot CLI backend */
|
|
310
|
+
interface CopilotBackendOptions {
|
|
311
|
+
cliPath?: string;
|
|
312
|
+
workingDirectory?: string;
|
|
313
|
+
githubToken?: string;
|
|
314
|
+
useLoggedInUser?: boolean;
|
|
315
|
+
}
|
|
316
|
+
/** Options for Claude CLI backend */
|
|
317
|
+
interface ClaudeBackendOptions {
|
|
318
|
+
cliPath?: string;
|
|
319
|
+
workingDirectory?: string;
|
|
320
|
+
maxTurns?: number;
|
|
321
|
+
}
|
|
322
|
+
/** Options for Vercel AI SDK backend */
|
|
323
|
+
interface VercelAIBackendOptions {
|
|
324
|
+
apiKey: string;
|
|
325
|
+
provider?: string;
|
|
326
|
+
baseUrl?: string;
|
|
327
|
+
}
|
|
328
|
+
/** Type guard: checks if a ToolDeclaration has an execute function (i.e., is a ToolDefinition) */
|
|
329
|
+
declare function isToolDefinition(tool: ToolDeclaration): tool is ToolDefinition;
|
|
330
|
+
/** Type guard: checks if MessageContent is plain string */
|
|
331
|
+
declare function isTextContent(content: MessageContent): content is string;
|
|
332
|
+
/** Type guard: checks if MessageContent is multi-part array */
|
|
333
|
+
declare function isMultiPartContent(content: MessageContent): content is ContentPart[];
|
|
334
|
+
/** Extract text from MessageContent regardless of format */
|
|
335
|
+
declare function getTextContent(content: MessageContent): string;
|
|
336
|
+
|
|
337
|
+
/** Base error class for agent-sdk */
|
|
338
|
+
declare class AgentSDKError extends Error {
|
|
339
|
+
constructor(message: string, options?: ErrorOptions);
|
|
340
|
+
}
|
|
341
|
+
/** Thrown when agent.run() is called while already running (M8 re-entrancy guard) */
|
|
342
|
+
declare class ReentrancyError extends AgentSDKError {
|
|
343
|
+
constructor();
|
|
344
|
+
}
|
|
345
|
+
/** Thrown when an operation is attempted on a disposed agent/service */
|
|
346
|
+
declare class DisposedError extends AgentSDKError {
|
|
347
|
+
constructor(entity: string);
|
|
348
|
+
}
|
|
349
|
+
/** Thrown when a backend is not found in the registry */
|
|
350
|
+
declare class BackendNotFoundError extends AgentSDKError {
|
|
351
|
+
constructor(backend: string);
|
|
352
|
+
}
|
|
353
|
+
/** Thrown when a backend is already registered */
|
|
354
|
+
declare class BackendAlreadyRegisteredError extends AgentSDKError {
|
|
355
|
+
constructor(backend: string);
|
|
356
|
+
}
|
|
357
|
+
/** Thrown when subprocess management fails */
|
|
358
|
+
declare class SubprocessError extends AgentSDKError {
|
|
359
|
+
constructor(message: string, options?: ErrorOptions);
|
|
360
|
+
}
|
|
361
|
+
/** Thrown when a required peer dependency is not installed */
|
|
362
|
+
declare class DependencyError extends AgentSDKError {
|
|
363
|
+
readonly packageName: string;
|
|
364
|
+
constructor(packageName: string);
|
|
365
|
+
}
|
|
366
|
+
/** Thrown when an agent run is aborted */
|
|
367
|
+
declare class AbortError extends AgentSDKError {
|
|
368
|
+
constructor();
|
|
369
|
+
}
|
|
370
|
+
/** Thrown when a tool execution fails */
|
|
371
|
+
declare class ToolExecutionError extends AgentSDKError {
|
|
372
|
+
readonly toolName: string;
|
|
373
|
+
constructor(toolName: string, message: string, options?: ErrorOptions);
|
|
374
|
+
}
|
|
375
|
+
/** Thrown when structured output parsing fails */
|
|
376
|
+
declare class StructuredOutputError extends AgentSDKError {
|
|
377
|
+
constructor(message: string, options?: ErrorOptions);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Factory function that creates a backend service from options */
|
|
381
|
+
type BackendFactory<TOptions = unknown> = (options: TOptions) => IAgentService | Promise<IAgentService>;
|
|
382
|
+
/** Map of built-in backend names to their options types */
|
|
383
|
+
interface BackendOptionsMap {
|
|
384
|
+
copilot: CopilotBackendOptions;
|
|
385
|
+
claude: ClaudeBackendOptions;
|
|
386
|
+
"vercel-ai": VercelAIBackendOptions;
|
|
387
|
+
}
|
|
388
|
+
/** All known backend names (built-in + custom) */
|
|
389
|
+
type BuiltinBackendName = keyof BackendOptionsMap;
|
|
390
|
+
/** Register a custom backend factory */
|
|
391
|
+
declare function registerBackend<TOptions = unknown>(name: string, factory: BackendFactory<TOptions>): void;
|
|
392
|
+
/** Unregister a backend (primarily for testing) */
|
|
393
|
+
declare function unregisterBackend(name: string): boolean;
|
|
394
|
+
/** Check if a backend is registered */
|
|
395
|
+
declare function hasBackend(name: string): boolean;
|
|
396
|
+
/** List all registered backend names */
|
|
397
|
+
declare function listBackends(): string[];
|
|
398
|
+
/** Reset registry to initial state (for testing) */
|
|
399
|
+
declare function resetRegistry(): void;
|
|
400
|
+
/** Create a backend service with type-safe options */
|
|
401
|
+
declare function createAgentService<K extends BuiltinBackendName>(name: K, options: BackendOptionsMap[K]): Promise<IAgentService>;
|
|
402
|
+
declare function createAgentService(name: string, options: unknown): Promise<IAgentService>;
|
|
403
|
+
|
|
404
|
+
/** Abstract base agent with shared lifecycle logic.
|
|
405
|
+
* Concrete backends extend this and implement the protected _run/_stream methods. */
|
|
406
|
+
declare abstract class BaseAgent implements IAgent {
|
|
407
|
+
protected state: AgentState;
|
|
408
|
+
protected abortController: AbortController | null;
|
|
409
|
+
protected readonly config: AgentConfig;
|
|
410
|
+
constructor(config: AgentConfig);
|
|
411
|
+
run(prompt: MessageContent, options?: RunOptions): Promise<AgentResult>;
|
|
412
|
+
runWithContext(messages: Message[], options?: RunOptions): Promise<AgentResult>;
|
|
413
|
+
runStructured<T>(prompt: MessageContent, schema: StructuredOutputConfig<T>, options?: RunOptions): Promise<AgentResult<T>>;
|
|
414
|
+
stream(prompt: MessageContent, options?: RunOptions): AsyncIterable<AgentEvent>;
|
|
415
|
+
abort(): void;
|
|
416
|
+
getState(): AgentState;
|
|
417
|
+
getConfig(): Readonly<AgentConfig>;
|
|
418
|
+
/** Mark agent as disposed. Override to add cleanup. */
|
|
419
|
+
dispose(): void;
|
|
420
|
+
/** Execute a blocking run. Backend implements the actual LLM call. */
|
|
421
|
+
protected abstract executeRun(messages: Message[], options: RunOptions | undefined, signal: AbortSignal): Promise<AgentResult>;
|
|
422
|
+
/** Execute a structured output run. Backend implements parsing. */
|
|
423
|
+
protected abstract executeRunStructured<T>(messages: Message[], schema: StructuredOutputConfig<T>, options: RunOptions | undefined, signal: AbortSignal): Promise<AgentResult<T>>;
|
|
424
|
+
/** Execute a streaming run. Backend yields events. */
|
|
425
|
+
protected abstract executeStream(messages: Message[], options: RunOptions | undefined, signal: AbortSignal): AsyncIterable<AgentEvent>;
|
|
426
|
+
protected guardReentrancy(): void;
|
|
427
|
+
protected guardDisposed(): void;
|
|
428
|
+
/** Throw AbortError if signal is already aborted */
|
|
429
|
+
protected checkAbort(signal: AbortSignal): void;
|
|
430
|
+
private createAbortController;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** Convert a Zod schema to JSON Schema.
|
|
434
|
+
* Uses zod's built-in jsonSchema() if available, falls back to _def extraction. */
|
|
435
|
+
declare function zodToJsonSchema(schema: z.ZodType): Record<string, unknown>;
|
|
436
|
+
|
|
437
|
+
/** Convert our Message[] to a flat prompt string (for CLIs that accept text) */
|
|
438
|
+
declare function messagesToPrompt(messages: Message[]): string;
|
|
439
|
+
/** Convert MessageContent to plain text */
|
|
440
|
+
declare function contentToText(content: MessageContent): string;
|
|
441
|
+
/** Build a system prompt with optional structured output instruction */
|
|
442
|
+
declare function buildSystemPrompt(base: string, schemaInstruction?: string): string;
|
|
443
|
+
|
|
444
|
+
export { AbortError, type AgentConfig, type AgentEvent, type AgentResult, AgentSDKError, type AgentState, BackendAlreadyRegisteredError, type BackendFactory, BackendNotFoundError, type BackendOptionsMap, BaseAgent, type BuiltinBackendName, type ClaudeBackendOptions, CompositePermissionStore, type ContentPart, type CopilotBackendOptions, DependencyError, DisposedError, type ErrorHandlingConfig, FilePermissionStore, type IAgent, type IAgentService, type IPermissionStore, InMemoryPermissionStore, type JSONValue, type Message, type MessageContent, type ModelInfo, type ModelParams, type PermissionCallback, type PermissionDecision, type PermissionRequest, type PermissionScope, ReentrancyError, type RunOptions, type StructuredOutputConfig, StructuredOutputError, SubprocessError, type SupervisorHooks, type TimeoutConfig, type ToolCall, type ToolDeclaration, type ToolDefinition, ToolExecutionError, type ToolResult, type UserInputRequest, type UserInputResponse, type ValidationResult, type VercelAIBackendOptions, buildSystemPrompt, contentToText, createAgentService, createDefaultPermissionStore, getTextContent, hasBackend, isMultiPartContent, isTextContent, isToolDefinition, listBackends, messagesToPrompt, registerBackend, resetRegistry, unregisterBackend, zodToJsonSchema };
|