@aizonaai/adk 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 +283 -0
- package/dist/bin/adk-cli.js +179 -0
- package/dist/index.cjs +8084 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3198 -0
- package/dist/index.d.ts +3198 -0
- package/dist/index.js +7932 -0
- package/dist/index.js.map +1 -0
- package/examples/email-assistant/README.md +39 -0
- package/examples/email-assistant/index.ts +71 -0
- package/examples/hello-world/README.md +25 -0
- package/examples/hello-world/index.ts +31 -0
- package/examples/web-scraper/README.md +36 -0
- package/examples/web-scraper/index.ts +54 -0
- package/package.json +65 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3198 @@
|
|
|
1
|
+
import { z, ZodSchema } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Supported media types for multi-modal content */
|
|
4
|
+
type MediaType = "image/png" | "image/jpeg" | "image/gif" | "image/webp" | "image/svg+xml" | "audio/mp3" | "audio/wav" | "audio/ogg" | "audio/webm" | "audio/mpeg" | "video/mp4" | "video/webm" | "video/ogg" | "text/html" | "text/css" | "text/javascript" | "application/json" | "application/pdf";
|
|
5
|
+
/** Text content part */
|
|
6
|
+
interface TextPart {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
/** Image content part — base64 or URL */
|
|
11
|
+
interface ImagePart {
|
|
12
|
+
type: "image";
|
|
13
|
+
source: {
|
|
14
|
+
type: "base64";
|
|
15
|
+
mediaType: MediaType;
|
|
16
|
+
data: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: "url";
|
|
19
|
+
url: string;
|
|
20
|
+
detail?: "auto" | "low" | "high";
|
|
21
|
+
};
|
|
22
|
+
alt?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Audio content part — base64 or URL */
|
|
25
|
+
interface AudioPart {
|
|
26
|
+
type: "audio";
|
|
27
|
+
source: {
|
|
28
|
+
type: "base64";
|
|
29
|
+
mediaType: MediaType;
|
|
30
|
+
data: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "url";
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
durationSec?: number;
|
|
36
|
+
transcript?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Video content part — base64 or URL */
|
|
39
|
+
interface VideoPart {
|
|
40
|
+
type: "video";
|
|
41
|
+
source: {
|
|
42
|
+
type: "base64";
|
|
43
|
+
mediaType: MediaType;
|
|
44
|
+
data: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: "url";
|
|
47
|
+
url: string;
|
|
48
|
+
};
|
|
49
|
+
durationSec?: number;
|
|
50
|
+
posterUrl?: string;
|
|
51
|
+
}
|
|
52
|
+
/** UI Artifact content part — rendered in sandboxed iframe */
|
|
53
|
+
interface UIArtifactPart {
|
|
54
|
+
type: "ui_artifact";
|
|
55
|
+
artifactId: string;
|
|
56
|
+
version: number;
|
|
57
|
+
title: string;
|
|
58
|
+
kind: "html" | "react" | "svg" | "markdown" | "code";
|
|
59
|
+
content: string;
|
|
60
|
+
language?: string;
|
|
61
|
+
css?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Union of all content part types */
|
|
64
|
+
type ContentPart = TextPart | ImagePart | AudioPart | VideoPart | UIArtifactPart;
|
|
65
|
+
/** Content can be a simple string or an array of content parts */
|
|
66
|
+
type Content = string | ContentPart[];
|
|
67
|
+
|
|
68
|
+
/** Chat message role */
|
|
69
|
+
type ChatRole = "system" | "user" | "assistant" | "tool";
|
|
70
|
+
/** Tool call within a message */
|
|
71
|
+
interface ToolCall {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
input: unknown;
|
|
75
|
+
}
|
|
76
|
+
/** Tool result within a message */
|
|
77
|
+
interface ToolResult {
|
|
78
|
+
toolCallId: string;
|
|
79
|
+
name: string;
|
|
80
|
+
output: unknown;
|
|
81
|
+
isError?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** Chat message — extends platform version with tool support */
|
|
84
|
+
interface ChatMessage {
|
|
85
|
+
role: ChatRole;
|
|
86
|
+
content: Content;
|
|
87
|
+
name?: string;
|
|
88
|
+
toolCalls?: ToolCall[];
|
|
89
|
+
toolResults?: ToolResult[];
|
|
90
|
+
}
|
|
91
|
+
/** Chat completion parameters */
|
|
92
|
+
interface ChatParams {
|
|
93
|
+
messages: ChatMessage[];
|
|
94
|
+
model?: string;
|
|
95
|
+
maxTokens?: number;
|
|
96
|
+
temperature?: number;
|
|
97
|
+
topP?: number;
|
|
98
|
+
stopSequences?: string[];
|
|
99
|
+
systemPrompt?: string;
|
|
100
|
+
}
|
|
101
|
+
/** Chat completion parameters with tool support */
|
|
102
|
+
interface ChatParamsWithTools extends ChatParams {
|
|
103
|
+
tools?: LLMToolDefinition[];
|
|
104
|
+
toolChoice?: "auto" | "required" | "none" | {
|
|
105
|
+
name: string;
|
|
106
|
+
};
|
|
107
|
+
responseFormat?: ResponseFormat;
|
|
108
|
+
}
|
|
109
|
+
/** Tool definition for LLM providers */
|
|
110
|
+
interface LLMToolDefinition {
|
|
111
|
+
name: string;
|
|
112
|
+
description: string;
|
|
113
|
+
inputSchema: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
/** Response format for structured output */
|
|
116
|
+
type ResponseFormat = {
|
|
117
|
+
type: "text";
|
|
118
|
+
} | {
|
|
119
|
+
type: "json_object";
|
|
120
|
+
} | {
|
|
121
|
+
type: "json_schema";
|
|
122
|
+
schema: Record<string, unknown>;
|
|
123
|
+
name?: string;
|
|
124
|
+
};
|
|
125
|
+
/** Chat response */
|
|
126
|
+
interface ChatResponse {
|
|
127
|
+
content: string;
|
|
128
|
+
model: string;
|
|
129
|
+
providerId: string;
|
|
130
|
+
inputTokens: number;
|
|
131
|
+
outputTokens: number;
|
|
132
|
+
totalTokens: number;
|
|
133
|
+
latencyMs: number;
|
|
134
|
+
ttfbMs?: number;
|
|
135
|
+
costUsd: number;
|
|
136
|
+
finishReason: string;
|
|
137
|
+
}
|
|
138
|
+
/** Chat response with tool calls */
|
|
139
|
+
interface ChatResponseWithToolCalls extends ChatResponse {
|
|
140
|
+
toolCalls?: ToolCall[];
|
|
141
|
+
}
|
|
142
|
+
/** Text completion parameters */
|
|
143
|
+
interface CompleteParams {
|
|
144
|
+
prompt: string;
|
|
145
|
+
model?: string;
|
|
146
|
+
maxTokens?: number;
|
|
147
|
+
temperature?: number;
|
|
148
|
+
topP?: number;
|
|
149
|
+
stopSequences?: string[];
|
|
150
|
+
}
|
|
151
|
+
/** Text completion response */
|
|
152
|
+
interface CompleteResponse {
|
|
153
|
+
text: string;
|
|
154
|
+
model: string;
|
|
155
|
+
providerId: string;
|
|
156
|
+
inputTokens: number;
|
|
157
|
+
outputTokens: number;
|
|
158
|
+
totalTokens: number;
|
|
159
|
+
latencyMs: number;
|
|
160
|
+
costUsd: number;
|
|
161
|
+
finishReason: string;
|
|
162
|
+
}
|
|
163
|
+
/** Embedding parameters */
|
|
164
|
+
interface EmbedParams {
|
|
165
|
+
input: string | string[];
|
|
166
|
+
model?: string;
|
|
167
|
+
}
|
|
168
|
+
/** Embedding response */
|
|
169
|
+
interface EmbedResponse {
|
|
170
|
+
embeddings: number[][];
|
|
171
|
+
model: string;
|
|
172
|
+
providerId: string;
|
|
173
|
+
totalTokens: number;
|
|
174
|
+
latencyMs: number;
|
|
175
|
+
costUsd: number;
|
|
176
|
+
}
|
|
177
|
+
/** Stream chunk types from LLM providers */
|
|
178
|
+
type StreamChunk = {
|
|
179
|
+
type: "text_delta";
|
|
180
|
+
content: string;
|
|
181
|
+
} | {
|
|
182
|
+
type: "tool_use_start";
|
|
183
|
+
id: string;
|
|
184
|
+
name: string;
|
|
185
|
+
} | {
|
|
186
|
+
type: "tool_use_delta";
|
|
187
|
+
id: string;
|
|
188
|
+
inputJson: string;
|
|
189
|
+
} | {
|
|
190
|
+
type: "tool_use_end";
|
|
191
|
+
id: string;
|
|
192
|
+
} | {
|
|
193
|
+
type: "message_end";
|
|
194
|
+
usage: {
|
|
195
|
+
inputTokens: number;
|
|
196
|
+
outputTokens: number;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
/** Base LLM provider interface (from platform-agents) */
|
|
200
|
+
interface LLMProvider {
|
|
201
|
+
readonly providerId: string;
|
|
202
|
+
readonly displayName: string;
|
|
203
|
+
readonly isLocal: boolean;
|
|
204
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
205
|
+
complete(params: CompleteParams): Promise<CompleteResponse>;
|
|
206
|
+
embed?(params: EmbedParams): Promise<EmbedResponse>;
|
|
207
|
+
isAvailable(): boolean;
|
|
208
|
+
getModels(): string[];
|
|
209
|
+
estimateCost(inputTokens: number, outputTokens: number, model?: string): number;
|
|
210
|
+
}
|
|
211
|
+
/** Extended ADK provider interface with tool calling + streaming */
|
|
212
|
+
interface ADKLLMProvider extends LLMProvider {
|
|
213
|
+
chatWithTools(params: ChatParamsWithTools): Promise<ChatResponseWithToolCalls>;
|
|
214
|
+
chatStream(params: ChatParamsWithTools): AsyncGenerator<StreamChunk>;
|
|
215
|
+
}
|
|
216
|
+
/** Routing strategy (5 strategies from LLMRouter) */
|
|
217
|
+
type RoutingStrategy = "cost-optimized" | "latency-optimized" | "quality-optimized" | "balanced" | "fallback-chain";
|
|
218
|
+
/** Budget period for cost tracking */
|
|
219
|
+
type BudgetPeriod = "day" | "week" | "month";
|
|
220
|
+
/** Agent LLM configuration */
|
|
221
|
+
interface AgentLLMConfig {
|
|
222
|
+
agentSlug: string;
|
|
223
|
+
enabledProviders: string[];
|
|
224
|
+
strategy: RoutingStrategy;
|
|
225
|
+
budgetLimitUsd?: number;
|
|
226
|
+
budgetPeriod?: BudgetPeriod;
|
|
227
|
+
maxLatencyMs?: number;
|
|
228
|
+
fallbackChain?: string[];
|
|
229
|
+
preferredModel?: string;
|
|
230
|
+
}
|
|
231
|
+
/** Circuit breaker state per provider */
|
|
232
|
+
interface CircuitBreakerState {
|
|
233
|
+
providerId: string;
|
|
234
|
+
state: "closed" | "open" | "half-open";
|
|
235
|
+
failures: number;
|
|
236
|
+
lastFailure: number | null;
|
|
237
|
+
lastSuccess: number | null;
|
|
238
|
+
openedAt: number | null;
|
|
239
|
+
}
|
|
240
|
+
/** Provider metrics */
|
|
241
|
+
interface ProviderMetrics {
|
|
242
|
+
providerId: string;
|
|
243
|
+
totalCalls: number;
|
|
244
|
+
successCalls: number;
|
|
245
|
+
failedCalls: number;
|
|
246
|
+
avgLatencyMs: number;
|
|
247
|
+
totalCostUsd: number;
|
|
248
|
+
lastCallAt: number | null;
|
|
249
|
+
}
|
|
250
|
+
/** Provider initialization configuration */
|
|
251
|
+
interface ProviderInitConfig {
|
|
252
|
+
providerId: string;
|
|
253
|
+
apiKey?: string;
|
|
254
|
+
baseUrl?: string;
|
|
255
|
+
defaultModel?: string;
|
|
256
|
+
modelCosts?: Map<string, {
|
|
257
|
+
input: number;
|
|
258
|
+
output: number;
|
|
259
|
+
}>;
|
|
260
|
+
knownModels?: string[];
|
|
261
|
+
}
|
|
262
|
+
/** Model catalog entry */
|
|
263
|
+
interface CatalogModel {
|
|
264
|
+
modelId: string;
|
|
265
|
+
providerId: string;
|
|
266
|
+
displayName: string;
|
|
267
|
+
description: string;
|
|
268
|
+
modality: "chat" | "completion" | "embedding" | "image" | "video" | "audio" | "multimodal";
|
|
269
|
+
capabilities: ModelCapability[];
|
|
270
|
+
costPerMTInput: number;
|
|
271
|
+
costPerMTOutput: number;
|
|
272
|
+
contextWindowInput: number;
|
|
273
|
+
contextWindowOutput: number;
|
|
274
|
+
releaseDate?: string;
|
|
275
|
+
deprecatedAt?: string;
|
|
276
|
+
isPreview?: boolean;
|
|
277
|
+
aliases?: string[];
|
|
278
|
+
}
|
|
279
|
+
/** Model capability tags */
|
|
280
|
+
type ModelCapability = "text" | "code" | "vision" | "image-generation" | "video-generation" | "audio" | "embeddings" | "function-calling" | "thinking" | "streaming" | "json-mode";
|
|
281
|
+
|
|
282
|
+
type SpanType = "agent" | "llm" | "tool" | "guardrail" | "handoff" | "session" | "pipeline";
|
|
283
|
+
interface SpanEvent {
|
|
284
|
+
name: string;
|
|
285
|
+
timestamp: number;
|
|
286
|
+
data?: Record<string, unknown>;
|
|
287
|
+
}
|
|
288
|
+
interface SpanData {
|
|
289
|
+
id: string;
|
|
290
|
+
traceId: string;
|
|
291
|
+
parentSpanId?: string;
|
|
292
|
+
name: string;
|
|
293
|
+
type: SpanType;
|
|
294
|
+
startTime: number;
|
|
295
|
+
endTime?: number;
|
|
296
|
+
durationMs?: number;
|
|
297
|
+
attributes: Record<string, unknown>;
|
|
298
|
+
events: SpanEvent[];
|
|
299
|
+
status: "ok" | "error";
|
|
300
|
+
error?: string;
|
|
301
|
+
}
|
|
302
|
+
declare class Span {
|
|
303
|
+
readonly id: string;
|
|
304
|
+
readonly traceId: string;
|
|
305
|
+
readonly parentSpanId?: string;
|
|
306
|
+
readonly name: string;
|
|
307
|
+
readonly type: SpanType;
|
|
308
|
+
readonly startTime: number;
|
|
309
|
+
private _endTime?;
|
|
310
|
+
private _attributes;
|
|
311
|
+
private _events;
|
|
312
|
+
private _status;
|
|
313
|
+
private _error?;
|
|
314
|
+
constructor(traceId: string, name: string, type: SpanType, parentSpanId?: string);
|
|
315
|
+
setAttributes(attrs: Record<string, unknown>): void;
|
|
316
|
+
setAttribute(key: string, value: unknown): void;
|
|
317
|
+
addEvent(name: string, data?: Record<string, unknown>): void;
|
|
318
|
+
setError(error: string): void;
|
|
319
|
+
end(): void;
|
|
320
|
+
get durationMs(): number | undefined;
|
|
321
|
+
toJSON(): SpanData;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
interface TraceData {
|
|
325
|
+
id: string;
|
|
326
|
+
name: string;
|
|
327
|
+
startTime: number;
|
|
328
|
+
endTime?: number;
|
|
329
|
+
durationMs?: number;
|
|
330
|
+
spans: SpanData[];
|
|
331
|
+
metadata: Record<string, unknown>;
|
|
332
|
+
}
|
|
333
|
+
interface TraceExporter {
|
|
334
|
+
export(trace: TraceData): Promise<void>;
|
|
335
|
+
}
|
|
336
|
+
declare class Trace {
|
|
337
|
+
readonly id: string;
|
|
338
|
+
readonly name: string;
|
|
339
|
+
readonly startTime: number;
|
|
340
|
+
private _endTime?;
|
|
341
|
+
private _spans;
|
|
342
|
+
private _metadata;
|
|
343
|
+
constructor(name: string, metadata?: Record<string, unknown>);
|
|
344
|
+
startSpan(name: string, type: SpanType, parentSpanId?: string): Span;
|
|
345
|
+
setMetadata(key: string, value: unknown): void;
|
|
346
|
+
end(): void;
|
|
347
|
+
get durationMs(): number | undefined;
|
|
348
|
+
get spans(): Span[];
|
|
349
|
+
toJSON(): TraceData;
|
|
350
|
+
}
|
|
351
|
+
declare class Tracer {
|
|
352
|
+
private exporters;
|
|
353
|
+
private traces;
|
|
354
|
+
addExporter(exporter: TraceExporter): void;
|
|
355
|
+
startTrace(name: string, metadata?: Record<string, unknown>): Trace;
|
|
356
|
+
endAndExport(trace: Trace): Promise<void>;
|
|
357
|
+
getTraces(): Trace[];
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Stored artifact with metadata */
|
|
361
|
+
interface Artifact {
|
|
362
|
+
id: string;
|
|
363
|
+
title: string;
|
|
364
|
+
kind: "html" | "react" | "svg" | "markdown" | "code";
|
|
365
|
+
content: string;
|
|
366
|
+
css?: string;
|
|
367
|
+
language?: string;
|
|
368
|
+
version: number;
|
|
369
|
+
createdAt: number;
|
|
370
|
+
updatedAt: number;
|
|
371
|
+
agentName: string;
|
|
372
|
+
runId: string;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* In-memory artifact store. Persists artifacts created by agents
|
|
376
|
+
* during runs. Supports versioning (upsert bumps version).
|
|
377
|
+
*/
|
|
378
|
+
declare class ArtifactStore {
|
|
379
|
+
private artifacts;
|
|
380
|
+
/** Create or update an artifact from a UIArtifactPart */
|
|
381
|
+
upsert(part: UIArtifactPart, agentName: string, runId: string): Artifact;
|
|
382
|
+
/** Get a specific artifact by ID */
|
|
383
|
+
get(artifactId: string): Artifact | undefined;
|
|
384
|
+
/** Get all artifacts for a specific run */
|
|
385
|
+
getByRun(runId: string): Artifact[];
|
|
386
|
+
/** Get all stored artifacts */
|
|
387
|
+
getAll(): Artifact[];
|
|
388
|
+
/** Clear all artifacts */
|
|
389
|
+
clear(): void;
|
|
390
|
+
/** Get the number of stored artifacts */
|
|
391
|
+
get size(): number;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** Guardrail type */
|
|
395
|
+
type GuardrailType = "input" | "output" | "tool";
|
|
396
|
+
/** Severity level for guardrail results */
|
|
397
|
+
type GuardrailSeverity = "info" | "warning" | "error" | "critical";
|
|
398
|
+
/** Guardrail result */
|
|
399
|
+
interface GuardrailResult {
|
|
400
|
+
name: string;
|
|
401
|
+
type: GuardrailType;
|
|
402
|
+
passed: boolean;
|
|
403
|
+
/** If true and passed=false, immediately stop the run */
|
|
404
|
+
tripwire: boolean;
|
|
405
|
+
message?: string;
|
|
406
|
+
metadata?: Record<string, unknown>;
|
|
407
|
+
/** Severity level (default: "error" for backward compat) */
|
|
408
|
+
severity?: GuardrailSeverity;
|
|
409
|
+
/** Confidence score 0-1 */
|
|
410
|
+
score?: number;
|
|
411
|
+
}
|
|
412
|
+
/** Input guardrail — runs before LLM call */
|
|
413
|
+
interface InputGuardrail {
|
|
414
|
+
name: string;
|
|
415
|
+
type: "input";
|
|
416
|
+
/** Whether failing this guardrail should stop execution immediately */
|
|
417
|
+
tripwire: boolean;
|
|
418
|
+
execute(input: string, messages: ChatMessage[], ctx: RunContext): Promise<GuardrailResult>;
|
|
419
|
+
}
|
|
420
|
+
/** Output guardrail — runs after LLM response */
|
|
421
|
+
interface OutputGuardrail {
|
|
422
|
+
name: string;
|
|
423
|
+
type: "output";
|
|
424
|
+
tripwire: boolean;
|
|
425
|
+
execute(output: string, messages: ChatMessage[], ctx: RunContext): Promise<GuardrailResult>;
|
|
426
|
+
}
|
|
427
|
+
/** Tool guardrail — runs before tool execution */
|
|
428
|
+
interface ToolGuardrail {
|
|
429
|
+
name: string;
|
|
430
|
+
type: "tool";
|
|
431
|
+
tripwire: boolean;
|
|
432
|
+
execute(toolName: string, input: unknown, ctx: RunContext): Promise<GuardrailResult>;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Content guardrail — forward-compatible type for multi-modal content inspection.
|
|
436
|
+
* Not wired into the engine yet. Defined here for future use by guardrail authors.
|
|
437
|
+
*/
|
|
438
|
+
interface ContentGuardrail {
|
|
439
|
+
name: string;
|
|
440
|
+
type: "content";
|
|
441
|
+
tripwire: boolean;
|
|
442
|
+
execute(content: Content, messages: ChatMessage[], ctx: RunContext): Promise<GuardrailResult>;
|
|
443
|
+
}
|
|
444
|
+
/** Union of all guardrail types */
|
|
445
|
+
type Guardrail = InputGuardrail | OutputGuardrail | ToolGuardrail;
|
|
446
|
+
/** Guardrail configuration (used in AgentConfig) */
|
|
447
|
+
interface GuardrailConfig {
|
|
448
|
+
guardrail: Guardrail;
|
|
449
|
+
/** Override tripwire setting */
|
|
450
|
+
tripwire?: boolean;
|
|
451
|
+
}
|
|
452
|
+
/** Consent decision (from platform consent gate) */
|
|
453
|
+
interface ConsentDecision {
|
|
454
|
+
allowed: boolean;
|
|
455
|
+
requestId?: string;
|
|
456
|
+
status: "approved" | "rejected" | "pending" | "expired" | "auto";
|
|
457
|
+
reason?: string;
|
|
458
|
+
}
|
|
459
|
+
/** Consent request for explicit/multi-party consent */
|
|
460
|
+
interface ConsentRequest {
|
|
461
|
+
id: string;
|
|
462
|
+
agentName: string;
|
|
463
|
+
action: string;
|
|
464
|
+
consentLevel: "auto" | "notify" | "explicit" | "multi_party";
|
|
465
|
+
requiredApprovals: number;
|
|
466
|
+
currentApprovals: string[];
|
|
467
|
+
rejectedBy: string | null;
|
|
468
|
+
status: "pending" | "approved" | "rejected" | "expired";
|
|
469
|
+
createdAt: number;
|
|
470
|
+
expiresAt: number;
|
|
471
|
+
metadata?: Record<string, unknown>;
|
|
472
|
+
}
|
|
473
|
+
/** Consent handler (provided by caller for explicit consent flows) */
|
|
474
|
+
type ConsentHandler = (request: ConsentRequest) => Promise<ConsentDecision>;
|
|
475
|
+
|
|
476
|
+
/** Session state */
|
|
477
|
+
type SessionStatus = "active" | "expired" | "closed";
|
|
478
|
+
/** Session data */
|
|
479
|
+
interface Session {
|
|
480
|
+
id: string;
|
|
481
|
+
agentName: string;
|
|
482
|
+
messages: ChatMessage[];
|
|
483
|
+
metadata: Record<string, unknown>;
|
|
484
|
+
status: SessionStatus;
|
|
485
|
+
parentId?: string;
|
|
486
|
+
createdAt: Date;
|
|
487
|
+
updatedAt: Date;
|
|
488
|
+
expiresAt?: Date;
|
|
489
|
+
}
|
|
490
|
+
/** Session create options */
|
|
491
|
+
interface SessionCreateOptions {
|
|
492
|
+
agentName: string;
|
|
493
|
+
metadata?: Record<string, unknown>;
|
|
494
|
+
expiresAt?: Date;
|
|
495
|
+
}
|
|
496
|
+
/** Session update options */
|
|
497
|
+
interface SessionUpdateOptions {
|
|
498
|
+
messages?: ChatMessage[];
|
|
499
|
+
metadata?: Record<string, unknown>;
|
|
500
|
+
status?: SessionStatus;
|
|
501
|
+
}
|
|
502
|
+
/** Session backend interface — all backends implement this */
|
|
503
|
+
interface SessionBackend {
|
|
504
|
+
/** Create a new session */
|
|
505
|
+
create(options: SessionCreateOptions): Promise<Session>;
|
|
506
|
+
/** Get a session by ID */
|
|
507
|
+
get(sessionId: string): Promise<Session | null>;
|
|
508
|
+
/** Update a session */
|
|
509
|
+
update(sessionId: string, options: SessionUpdateOptions): Promise<Session>;
|
|
510
|
+
/** Append messages to a session */
|
|
511
|
+
appendMessages(sessionId: string, messages: ChatMessage[]): Promise<Session>;
|
|
512
|
+
/** Fork a session (create a copy with new ID, reference to parent) */
|
|
513
|
+
fork(sessionId: string): Promise<Session>;
|
|
514
|
+
/** Delete a session */
|
|
515
|
+
delete(sessionId: string): Promise<void>;
|
|
516
|
+
/** List sessions (optional filter) */
|
|
517
|
+
list(filter?: SessionListFilter): Promise<Session[]>;
|
|
518
|
+
}
|
|
519
|
+
/** Session list filter */
|
|
520
|
+
interface SessionListFilter {
|
|
521
|
+
agentName?: string;
|
|
522
|
+
status?: SessionStatus;
|
|
523
|
+
limit?: number;
|
|
524
|
+
offset?: number;
|
|
525
|
+
}
|
|
526
|
+
/** Context management strategy */
|
|
527
|
+
type ContextStrategy = "sliding-window" | "smart-summary" | "jit";
|
|
528
|
+
|
|
529
|
+
/** Feature definition for harness progress tracking */
|
|
530
|
+
interface ProgressFeatureConfig {
|
|
531
|
+
id: string;
|
|
532
|
+
name: string;
|
|
533
|
+
}
|
|
534
|
+
/** Harness configuration for long-running agent sessions */
|
|
535
|
+
interface HarnessConfig {
|
|
536
|
+
/** Enable progress tracking tools */
|
|
537
|
+
enableProgress?: boolean;
|
|
538
|
+
/** Enable note-taking tools */
|
|
539
|
+
enableNotes?: boolean;
|
|
540
|
+
/** Initial features to track (if enableProgress) */
|
|
541
|
+
features?: ProgressFeatureConfig[];
|
|
542
|
+
}
|
|
543
|
+
/** Run configuration — input to Runner.run() */
|
|
544
|
+
interface RunConfig {
|
|
545
|
+
/** User input message (string or multi-modal ContentPart[]) */
|
|
546
|
+
input: string | ContentPart[];
|
|
547
|
+
/** Session ID to resume (optional) */
|
|
548
|
+
sessionId?: string;
|
|
549
|
+
/** Previous messages to include (if no sessionId) */
|
|
550
|
+
messages?: ChatMessage[];
|
|
551
|
+
/** Model override for this run */
|
|
552
|
+
model?: string | ModelConfig;
|
|
553
|
+
/** Max turns override */
|
|
554
|
+
maxTurns?: number;
|
|
555
|
+
/** Abort signal for cancellation */
|
|
556
|
+
signal?: AbortSignal;
|
|
557
|
+
/** Run metadata */
|
|
558
|
+
metadata?: Record<string, unknown>;
|
|
559
|
+
/** Harness tools for long-running sessions */
|
|
560
|
+
harness?: HarnessConfig;
|
|
561
|
+
}
|
|
562
|
+
/** Run result — output from Runner.run() */
|
|
563
|
+
interface RunResult {
|
|
564
|
+
/** Text output from the agent */
|
|
565
|
+
output: string;
|
|
566
|
+
/** Multi-modal output parts (if response contains non-text content) */
|
|
567
|
+
outputParts?: ContentPart[];
|
|
568
|
+
/** Structured output (if agent has outputSchema) */
|
|
569
|
+
structuredOutput?: unknown;
|
|
570
|
+
/** Full message history */
|
|
571
|
+
messages: ChatMessage[];
|
|
572
|
+
/** Usage statistics */
|
|
573
|
+
usage: RunUsage;
|
|
574
|
+
/** Handoff chain (if multi-agent) */
|
|
575
|
+
handoffs: HandoffRecord[];
|
|
576
|
+
/** Guardrail results */
|
|
577
|
+
guardrailResults: GuardrailResult[];
|
|
578
|
+
/** Trace ID for observability */
|
|
579
|
+
traceId: string;
|
|
580
|
+
/** Session ID (if sessions enabled) */
|
|
581
|
+
sessionId?: string;
|
|
582
|
+
/** Name of the agent that produced final output */
|
|
583
|
+
finalAgent: string;
|
|
584
|
+
/** Run ID */
|
|
585
|
+
runId: string;
|
|
586
|
+
/** Total turns executed */
|
|
587
|
+
totalTurns: number;
|
|
588
|
+
/** Artifacts created during the run */
|
|
589
|
+
artifacts?: Artifact[];
|
|
590
|
+
}
|
|
591
|
+
/** Usage statistics for a run */
|
|
592
|
+
interface RunUsage {
|
|
593
|
+
inputTokens: number;
|
|
594
|
+
outputTokens: number;
|
|
595
|
+
totalCostUsd: number;
|
|
596
|
+
latencyMs: number;
|
|
597
|
+
}
|
|
598
|
+
/** Record of a handoff during a run */
|
|
599
|
+
interface HandoffRecord {
|
|
600
|
+
fromAgent: string;
|
|
601
|
+
toAgent: string;
|
|
602
|
+
reason: string;
|
|
603
|
+
turnNumber: number;
|
|
604
|
+
}
|
|
605
|
+
/** Stream events emitted during execution */
|
|
606
|
+
type StreamEvent = {
|
|
607
|
+
type: "text_delta";
|
|
608
|
+
content: string;
|
|
609
|
+
agentName: string;
|
|
610
|
+
} | {
|
|
611
|
+
type: "image_output";
|
|
612
|
+
image: ImagePart;
|
|
613
|
+
agentName: string;
|
|
614
|
+
} | {
|
|
615
|
+
type: "audio_output";
|
|
616
|
+
audio: AudioPart;
|
|
617
|
+
agentName: string;
|
|
618
|
+
} | {
|
|
619
|
+
type: "video_output";
|
|
620
|
+
video: VideoPart;
|
|
621
|
+
agentName: string;
|
|
622
|
+
} | {
|
|
623
|
+
type: "ui_artifact";
|
|
624
|
+
artifact: UIArtifactPart;
|
|
625
|
+
agentName: string;
|
|
626
|
+
} | {
|
|
627
|
+
type: "tool_call_start";
|
|
628
|
+
toolName: string;
|
|
629
|
+
agentName: string;
|
|
630
|
+
input: unknown;
|
|
631
|
+
} | {
|
|
632
|
+
type: "tool_call_end";
|
|
633
|
+
toolName: string;
|
|
634
|
+
agentName: string;
|
|
635
|
+
output: unknown;
|
|
636
|
+
} | {
|
|
637
|
+
type: "handoff";
|
|
638
|
+
fromAgent: string;
|
|
639
|
+
toAgent: string;
|
|
640
|
+
reason: string;
|
|
641
|
+
} | {
|
|
642
|
+
type: "guardrail";
|
|
643
|
+
name: string;
|
|
644
|
+
passed: boolean;
|
|
645
|
+
tripwire: boolean;
|
|
646
|
+
message?: string;
|
|
647
|
+
} | {
|
|
648
|
+
type: "turn_complete";
|
|
649
|
+
agentName: string;
|
|
650
|
+
turnNumber: number;
|
|
651
|
+
} | {
|
|
652
|
+
type: "run_complete";
|
|
653
|
+
result: RunResult;
|
|
654
|
+
} | {
|
|
655
|
+
type: "error";
|
|
656
|
+
error: string;
|
|
657
|
+
agentName: string;
|
|
658
|
+
};
|
|
659
|
+
/** Runner configuration */
|
|
660
|
+
interface RunnerConfig {
|
|
661
|
+
/** Default model for all agents */
|
|
662
|
+
defaultModel?: string | ModelConfig;
|
|
663
|
+
/** Default max turns */
|
|
664
|
+
defaultMaxTurns?: number;
|
|
665
|
+
/** Session backend */
|
|
666
|
+
sessionBackend?: SessionBackend;
|
|
667
|
+
/** Tracing configuration */
|
|
668
|
+
tracing?: TracingConfig;
|
|
669
|
+
/** Tracer instance for structured span-based tracing */
|
|
670
|
+
tracer?: Tracer;
|
|
671
|
+
/** Model context window size override (auto-detected from model catalog if not set) */
|
|
672
|
+
modelContextWindow?: number;
|
|
673
|
+
/** Model catalog for context window lookups (optional, for auto-detection) */
|
|
674
|
+
modelCatalog?: CatalogModel[];
|
|
675
|
+
/** Artifact store for A2UI artifact persistence (optional) */
|
|
676
|
+
artifactStore?: ArtifactStore;
|
|
677
|
+
/** Enable code execution mode (programmatic tool calling) */
|
|
678
|
+
enableCodeExecution?: boolean;
|
|
679
|
+
}
|
|
680
|
+
/** Tracing configuration */
|
|
681
|
+
interface TracingConfig {
|
|
682
|
+
enabled?: boolean;
|
|
683
|
+
exporter?: "console" | "langfuse" | "eventbus";
|
|
684
|
+
exporterConfig?: Record<string, unknown>;
|
|
685
|
+
}
|
|
686
|
+
/** Run context — available to agents, tools, and guardrails during execution */
|
|
687
|
+
interface RunContext {
|
|
688
|
+
/** Current run ID */
|
|
689
|
+
runId: string;
|
|
690
|
+
/** Current agent name */
|
|
691
|
+
agentName: string;
|
|
692
|
+
/** Current turn number */
|
|
693
|
+
turnNumber: number;
|
|
694
|
+
/** Session ID (if sessions enabled) */
|
|
695
|
+
sessionId?: string;
|
|
696
|
+
/** Trace ID */
|
|
697
|
+
traceId: string;
|
|
698
|
+
/** Accumulated usage */
|
|
699
|
+
usage: RunUsage;
|
|
700
|
+
/** Abort signal */
|
|
701
|
+
signal?: AbortSignal;
|
|
702
|
+
/** Run metadata */
|
|
703
|
+
metadata: Record<string, unknown>;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/** Tool context passed to tool execute functions */
|
|
707
|
+
interface ToolContext {
|
|
708
|
+
/** Current run context */
|
|
709
|
+
runContext: RunContext;
|
|
710
|
+
/** ID of the tool call (from LLM) */
|
|
711
|
+
toolCallId: string;
|
|
712
|
+
/** Agent invoking the tool */
|
|
713
|
+
agentName: string;
|
|
714
|
+
}
|
|
715
|
+
/** Pre-execute hook result */
|
|
716
|
+
interface ToolPreHookResult {
|
|
717
|
+
/** Whether to proceed with execution */
|
|
718
|
+
allow: boolean;
|
|
719
|
+
/** Modified input (if allow=true and modification needed) */
|
|
720
|
+
modifiedInput?: unknown;
|
|
721
|
+
/** Reason for blocking (if allow=false) */
|
|
722
|
+
reason?: string;
|
|
723
|
+
}
|
|
724
|
+
/** Post-execute hook result */
|
|
725
|
+
interface ToolPostHookResult {
|
|
726
|
+
/** Modified output (if modification needed) */
|
|
727
|
+
modifiedOutput?: unknown;
|
|
728
|
+
}
|
|
729
|
+
/** Tool hooks for pre/post execution */
|
|
730
|
+
interface ToolHooks {
|
|
731
|
+
preExecute?: (input: unknown, ctx: ToolContext) => Promise<ToolPreHookResult> | ToolPreHookResult;
|
|
732
|
+
postExecute?: (input: unknown, output: unknown, ctx: ToolContext) => Promise<ToolPostHookResult> | ToolPostHookResult;
|
|
733
|
+
}
|
|
734
|
+
/** Example input for a tool (shown to LLM for better accuracy) */
|
|
735
|
+
interface ToolExample {
|
|
736
|
+
/** Example input values */
|
|
737
|
+
input: Record<string, unknown>;
|
|
738
|
+
/** Description of what this example demonstrates */
|
|
739
|
+
description?: string;
|
|
740
|
+
}
|
|
741
|
+
/** Tool definition — unifies skills, MCP tools, and custom functions */
|
|
742
|
+
interface ToolDef<TInput = unknown, TOutput = unknown> {
|
|
743
|
+
/** Unique tool name */
|
|
744
|
+
name: string;
|
|
745
|
+
/** Description shown to LLM */
|
|
746
|
+
description: string;
|
|
747
|
+
/** Input schema (Zod for validation, JSON Schema for LLM) */
|
|
748
|
+
inputSchema: z.ZodSchema<TInput> | JsonSchema;
|
|
749
|
+
/** Optional output schema */
|
|
750
|
+
outputSchema?: z.ZodSchema<TOutput> | JsonSchema;
|
|
751
|
+
/** Execute function */
|
|
752
|
+
execute: (input: TInput, ctx: ToolContext) => Promise<TOutput>;
|
|
753
|
+
/** Optional pre/post execution hooks */
|
|
754
|
+
hooks?: ToolHooks;
|
|
755
|
+
/** Tool metadata */
|
|
756
|
+
metadata?: Record<string, unknown>;
|
|
757
|
+
/** If true, tool is not sent to LLM until explicitly loaded via tool_search */
|
|
758
|
+
deferLoading?: boolean;
|
|
759
|
+
/** Example inputs to improve LLM accuracy */
|
|
760
|
+
examples?: ToolExample[];
|
|
761
|
+
/** Per-tool timeout in milliseconds (default: 30000) */
|
|
762
|
+
timeoutMs?: number;
|
|
763
|
+
/** Number of retries on failure (default: 0) */
|
|
764
|
+
retries?: number;
|
|
765
|
+
}
|
|
766
|
+
/** Tool definition config (for defineTool() builder) */
|
|
767
|
+
interface ToolDefConfig<TInput = unknown, TOutput = unknown> {
|
|
768
|
+
name: string;
|
|
769
|
+
description: string;
|
|
770
|
+
inputSchema: z.ZodSchema<TInput> | JsonSchema;
|
|
771
|
+
outputSchema?: z.ZodSchema<TOutput> | JsonSchema;
|
|
772
|
+
execute: (input: TInput, ctx: ToolContext) => Promise<TOutput>;
|
|
773
|
+
hooks?: ToolHooks;
|
|
774
|
+
metadata?: Record<string, unknown>;
|
|
775
|
+
deferLoading?: boolean;
|
|
776
|
+
examples?: ToolExample[];
|
|
777
|
+
timeoutMs?: number;
|
|
778
|
+
retries?: number;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/** Tool selection strategy */
|
|
782
|
+
type ToolSelectionStrategy = "all" | "keyword" | "deferred";
|
|
783
|
+
/** Tool selection configuration */
|
|
784
|
+
interface ToolSelectionConfig {
|
|
785
|
+
/** Max tools to send to LLM per turn (default: 20) */
|
|
786
|
+
maxToolsPerTurn?: number;
|
|
787
|
+
/** Selection strategy (default: "all") */
|
|
788
|
+
strategy?: ToolSelectionStrategy;
|
|
789
|
+
/** Minimum relevance score to include (default: 0.1) */
|
|
790
|
+
minRelevance?: number;
|
|
791
|
+
/** Boost tools used in recent turns (default: true) */
|
|
792
|
+
includeRecentlyUsed?: boolean;
|
|
793
|
+
/** How many recent turns to consider for recently-used boost (default: 3) */
|
|
794
|
+
recentTurnWindow?: number;
|
|
795
|
+
/** Tool names that are never filtered out */
|
|
796
|
+
alwaysInclude?: string[];
|
|
797
|
+
}
|
|
798
|
+
/** Tool relevance score */
|
|
799
|
+
interface ToolRelevanceScore {
|
|
800
|
+
tool: ToolDef;
|
|
801
|
+
score: number;
|
|
802
|
+
reason: string;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* ToolSelector — selects relevant tools for each LLM turn.
|
|
806
|
+
*
|
|
807
|
+
* Strategies:
|
|
808
|
+
* - "all": pass through all tools (no filtering)
|
|
809
|
+
* - "keyword": extract keywords from recent messages, match against tool name + description
|
|
810
|
+
*/
|
|
811
|
+
declare class ToolSelector {
|
|
812
|
+
private config;
|
|
813
|
+
constructor(config?: ToolSelectionConfig);
|
|
814
|
+
/** Select tools relevant to the current conversation turn */
|
|
815
|
+
selectTools(allTools: ToolDef[], messages: ChatMessage[], _turnNumber: number, recentToolCalls?: string[]): ToolDef[];
|
|
816
|
+
/** Score all tools by relevance to current messages */
|
|
817
|
+
scoreTools(allTools: ToolDef[], messages: ChatMessage[], recentToolCalls?: string[]): ToolRelevanceScore[];
|
|
818
|
+
/** Extract keywords from messages */
|
|
819
|
+
private extractKeywords;
|
|
820
|
+
/** Tokenize text into words */
|
|
821
|
+
private tokenize;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/** Agent consent levels (extracted from platform-agents) */
|
|
825
|
+
type ConsentLevel = "auto" | "notify" | "explicit" | "multi_party";
|
|
826
|
+
/** Agent autonomy levels */
|
|
827
|
+
type AutonomyLevel = "autonomous" | "semi_autonomous" | "composite" | "oracle";
|
|
828
|
+
/** Model configuration for multi-provider routing */
|
|
829
|
+
interface ModelConfig {
|
|
830
|
+
provider?: string;
|
|
831
|
+
model?: string;
|
|
832
|
+
temperature?: number;
|
|
833
|
+
maxTokens?: number;
|
|
834
|
+
routingStrategy?: RoutingStrategy;
|
|
835
|
+
fallbackChain?: string[];
|
|
836
|
+
}
|
|
837
|
+
/** Handoff target definition */
|
|
838
|
+
interface HandoffTarget {
|
|
839
|
+
agent: string | AgentConfig;
|
|
840
|
+
description: string;
|
|
841
|
+
filter?: (ctx: RunContext) => boolean | Promise<boolean>;
|
|
842
|
+
}
|
|
843
|
+
/** JSON Schema type for structured output */
|
|
844
|
+
type JsonSchema = Record<string, unknown>;
|
|
845
|
+
/** Agent configuration — the core definition */
|
|
846
|
+
interface AgentConfig {
|
|
847
|
+
/** Unique agent name */
|
|
848
|
+
name: string;
|
|
849
|
+
/** System instructions — can be static or dynamic */
|
|
850
|
+
instructions: string | ((ctx: RunContext) => string | Promise<string>);
|
|
851
|
+
/** Model to use (string shorthand or full config) */
|
|
852
|
+
model?: string | ModelConfig;
|
|
853
|
+
/** Tools available to this agent */
|
|
854
|
+
tools?: ToolDef[];
|
|
855
|
+
/** Agents this agent can hand off to */
|
|
856
|
+
handoffs?: HandoffTarget[];
|
|
857
|
+
/** Structured output schema (Zod or JSON Schema) */
|
|
858
|
+
outputSchema?: z.ZodSchema | JsonSchema;
|
|
859
|
+
/** Guardrails to apply */
|
|
860
|
+
guardrails?: GuardrailConfig[];
|
|
861
|
+
/** Consent level for execution */
|
|
862
|
+
consentLevel?: ConsentLevel;
|
|
863
|
+
/** Maximum turns before stopping */
|
|
864
|
+
maxTurns?: number;
|
|
865
|
+
/** Budget limit in USD */
|
|
866
|
+
budgetLimitUsd?: number;
|
|
867
|
+
/** Agent description (for tool/handoff descriptions) */
|
|
868
|
+
description?: string;
|
|
869
|
+
/** Agent metadata */
|
|
870
|
+
metadata?: Record<string, unknown>;
|
|
871
|
+
/** Tool selection config (dynamic per-turn filtering) */
|
|
872
|
+
toolSelection?: ToolSelectionConfig;
|
|
873
|
+
/** Context management config */
|
|
874
|
+
contextConfig?: ContextConfig;
|
|
875
|
+
}
|
|
876
|
+
/** Context management configuration */
|
|
877
|
+
interface ContextConfig {
|
|
878
|
+
/** Context trimming strategy */
|
|
879
|
+
strategy?: ContextStrategy;
|
|
880
|
+
/** Fraction of model's context window to use (default: 0.85) */
|
|
881
|
+
contextBudgetRatio?: number;
|
|
882
|
+
/** Explicit fixed token budget — overrides ratio-based calculation */
|
|
883
|
+
maxContextTokens?: number;
|
|
884
|
+
/** Always keep this many recent turns verbatim (default: 4) */
|
|
885
|
+
keepRecentTurns?: number;
|
|
886
|
+
/** Cheaper model for summarization (e.g., "claude-haiku-4-5-20251001") */
|
|
887
|
+
summaryModel?: string;
|
|
888
|
+
/** Token counting strategy */
|
|
889
|
+
tokenCounterStrategy?: "character" | "tiktoken-approx" | "provider-reported";
|
|
890
|
+
}
|
|
891
|
+
/** Resolved agent info for handoffs and multi-agent scenarios */
|
|
892
|
+
interface AgentInfo {
|
|
893
|
+
name: string;
|
|
894
|
+
description?: string;
|
|
895
|
+
consentLevel: ConsentLevel;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
interface TaskSubmittedEvent {
|
|
899
|
+
taskId: string;
|
|
900
|
+
agentSlug: string;
|
|
901
|
+
skill: string;
|
|
902
|
+
title: string;
|
|
903
|
+
timestamp: number;
|
|
904
|
+
}
|
|
905
|
+
interface TaskStartedEvent {
|
|
906
|
+
taskId: string;
|
|
907
|
+
agentSlug: string;
|
|
908
|
+
skill: string;
|
|
909
|
+
timestamp: number;
|
|
910
|
+
}
|
|
911
|
+
interface TaskCompletedEvent {
|
|
912
|
+
taskId: string;
|
|
913
|
+
agentSlug: string;
|
|
914
|
+
skill: string;
|
|
915
|
+
durationMs: number;
|
|
916
|
+
output?: string;
|
|
917
|
+
timestamp: number;
|
|
918
|
+
}
|
|
919
|
+
interface TaskFailedEvent {
|
|
920
|
+
taskId: string;
|
|
921
|
+
agentSlug: string;
|
|
922
|
+
skill: string;
|
|
923
|
+
error: string;
|
|
924
|
+
durationMs: number;
|
|
925
|
+
timestamp: number;
|
|
926
|
+
}
|
|
927
|
+
interface AgentStartedEvent {
|
|
928
|
+
agentSlug: string;
|
|
929
|
+
mode: "deterministic" | "llm";
|
|
930
|
+
timestamp: number;
|
|
931
|
+
}
|
|
932
|
+
interface AgentStoppedEvent {
|
|
933
|
+
agentSlug: string;
|
|
934
|
+
reason?: string;
|
|
935
|
+
timestamp: number;
|
|
936
|
+
}
|
|
937
|
+
interface AgentErrorEvent {
|
|
938
|
+
agentSlug: string;
|
|
939
|
+
error: string;
|
|
940
|
+
taskId?: string;
|
|
941
|
+
timestamp: number;
|
|
942
|
+
}
|
|
943
|
+
interface AgentLogEvent {
|
|
944
|
+
agentSlug: string;
|
|
945
|
+
level: "debug" | "info" | "warn" | "error";
|
|
946
|
+
message: string;
|
|
947
|
+
metadata?: Record<string, unknown>;
|
|
948
|
+
taskId?: string;
|
|
949
|
+
timestamp: number;
|
|
950
|
+
}
|
|
951
|
+
interface AgentHeartbeatEvent {
|
|
952
|
+
agentSlug: string;
|
|
953
|
+
queueDepth: number;
|
|
954
|
+
activeTaskId?: string;
|
|
955
|
+
memoryMb?: number;
|
|
956
|
+
timestamp: number;
|
|
957
|
+
}
|
|
958
|
+
interface AlertCreatedEvent {
|
|
959
|
+
alertId: string;
|
|
960
|
+
agentSlug?: string;
|
|
961
|
+
severity: "info" | "warning" | "critical";
|
|
962
|
+
title: string;
|
|
963
|
+
message: string;
|
|
964
|
+
timestamp: number;
|
|
965
|
+
}
|
|
966
|
+
interface AlertResolvedEvent {
|
|
967
|
+
alertId: string;
|
|
968
|
+
resolvedBy: string;
|
|
969
|
+
timestamp: number;
|
|
970
|
+
}
|
|
971
|
+
interface LLMCallCompletedEvent {
|
|
972
|
+
callId: string;
|
|
973
|
+
providerId: string;
|
|
974
|
+
model: string;
|
|
975
|
+
agentSlug?: string;
|
|
976
|
+
taskId?: string;
|
|
977
|
+
inputTokens: number;
|
|
978
|
+
outputTokens: number;
|
|
979
|
+
costUsd: number;
|
|
980
|
+
latencyMs: number;
|
|
981
|
+
ttfbMs?: number;
|
|
982
|
+
timestamp: number;
|
|
983
|
+
}
|
|
984
|
+
interface LLMCallFailedEvent {
|
|
985
|
+
callId: string;
|
|
986
|
+
providerId: string;
|
|
987
|
+
model: string;
|
|
988
|
+
agentSlug?: string;
|
|
989
|
+
taskId?: string;
|
|
990
|
+
error: string;
|
|
991
|
+
errorCode?: string;
|
|
992
|
+
latencyMs: number;
|
|
993
|
+
timestamp: number;
|
|
994
|
+
}
|
|
995
|
+
interface LLMProviderSwitchedEvent {
|
|
996
|
+
agentSlug: string;
|
|
997
|
+
fromProviderId: string;
|
|
998
|
+
toProviderId: string;
|
|
999
|
+
reason: string;
|
|
1000
|
+
timestamp: number;
|
|
1001
|
+
}
|
|
1002
|
+
interface HealthCheckEvent {
|
|
1003
|
+
healthy: string[];
|
|
1004
|
+
unhealthy: string[];
|
|
1005
|
+
restarted: string[];
|
|
1006
|
+
staleTasks: string[];
|
|
1007
|
+
timestamp: number;
|
|
1008
|
+
}
|
|
1009
|
+
interface ModelsDiscoveredEvent {
|
|
1010
|
+
providerId: string;
|
|
1011
|
+
modelsFound: number;
|
|
1012
|
+
catalogMatches: number;
|
|
1013
|
+
errors: string[];
|
|
1014
|
+
timestamp: number;
|
|
1015
|
+
}
|
|
1016
|
+
interface RunStartedEvent {
|
|
1017
|
+
runId: string;
|
|
1018
|
+
agentName: string;
|
|
1019
|
+
sessionId?: string;
|
|
1020
|
+
traceId: string;
|
|
1021
|
+
timestamp: number;
|
|
1022
|
+
}
|
|
1023
|
+
interface RunCompletedEvent {
|
|
1024
|
+
runId: string;
|
|
1025
|
+
agentName: string;
|
|
1026
|
+
totalTurns: number;
|
|
1027
|
+
totalCostUsd: number;
|
|
1028
|
+
totalLatencyMs: number;
|
|
1029
|
+
sessionId?: string;
|
|
1030
|
+
traceId: string;
|
|
1031
|
+
timestamp: number;
|
|
1032
|
+
}
|
|
1033
|
+
interface RunFailedEvent {
|
|
1034
|
+
runId: string;
|
|
1035
|
+
agentName: string;
|
|
1036
|
+
error: string;
|
|
1037
|
+
turnNumber: number;
|
|
1038
|
+
sessionId?: string;
|
|
1039
|
+
traceId: string;
|
|
1040
|
+
timestamp: number;
|
|
1041
|
+
}
|
|
1042
|
+
interface HandoffEvent {
|
|
1043
|
+
runId: string;
|
|
1044
|
+
fromAgent: string;
|
|
1045
|
+
toAgent: string;
|
|
1046
|
+
reason: string;
|
|
1047
|
+
turnNumber: number;
|
|
1048
|
+
timestamp: number;
|
|
1049
|
+
}
|
|
1050
|
+
interface GuardrailTriggeredEvent {
|
|
1051
|
+
runId: string;
|
|
1052
|
+
guardrailName: string;
|
|
1053
|
+
type: "input" | "output" | "tool";
|
|
1054
|
+
passed: boolean;
|
|
1055
|
+
tripwire: boolean;
|
|
1056
|
+
agentName: string;
|
|
1057
|
+
severity?: string;
|
|
1058
|
+
message?: string;
|
|
1059
|
+
timestamp: number;
|
|
1060
|
+
}
|
|
1061
|
+
interface ToolExecutedEvent {
|
|
1062
|
+
runId: string;
|
|
1063
|
+
toolName: string;
|
|
1064
|
+
agentName: string;
|
|
1065
|
+
latencyMs: number;
|
|
1066
|
+
success: boolean;
|
|
1067
|
+
error?: string;
|
|
1068
|
+
timestamp: number;
|
|
1069
|
+
}
|
|
1070
|
+
interface SessionCreatedEvent {
|
|
1071
|
+
sessionId: string;
|
|
1072
|
+
agentName: string;
|
|
1073
|
+
timestamp: number;
|
|
1074
|
+
}
|
|
1075
|
+
interface SessionResumedEvent {
|
|
1076
|
+
sessionId: string;
|
|
1077
|
+
agentName: string;
|
|
1078
|
+
messageCount: number;
|
|
1079
|
+
timestamp: number;
|
|
1080
|
+
}
|
|
1081
|
+
interface ContextTrimmedEvent {
|
|
1082
|
+
runId: string;
|
|
1083
|
+
agentName: string;
|
|
1084
|
+
strategy: "sliding-window" | "smart-summary" | "jit";
|
|
1085
|
+
originalTokens: number;
|
|
1086
|
+
trimmedTokens: number;
|
|
1087
|
+
messagesRemoved: number;
|
|
1088
|
+
turnNumber: number;
|
|
1089
|
+
timestamp: number;
|
|
1090
|
+
}
|
|
1091
|
+
interface ToolsSelectedEvent {
|
|
1092
|
+
runId: string;
|
|
1093
|
+
agentName: string;
|
|
1094
|
+
totalTools: number;
|
|
1095
|
+
selectedTools: number;
|
|
1096
|
+
selectedNames: string[];
|
|
1097
|
+
strategy: "all" | "keyword" | "deferred";
|
|
1098
|
+
turnNumber: number;
|
|
1099
|
+
timestamp: number;
|
|
1100
|
+
}
|
|
1101
|
+
interface ArtifactCreatedEvent {
|
|
1102
|
+
runId: string;
|
|
1103
|
+
agentName: string;
|
|
1104
|
+
artifactId: string;
|
|
1105
|
+
title: string;
|
|
1106
|
+
kind: "html" | "react" | "svg" | "markdown" | "code";
|
|
1107
|
+
version: number;
|
|
1108
|
+
timestamp: number;
|
|
1109
|
+
}
|
|
1110
|
+
/** Full ADK event map — type-safe pub/sub */
|
|
1111
|
+
interface ADKEventMap {
|
|
1112
|
+
"task.submitted": TaskSubmittedEvent;
|
|
1113
|
+
"task.started": TaskStartedEvent;
|
|
1114
|
+
"task.completed": TaskCompletedEvent;
|
|
1115
|
+
"task.failed": TaskFailedEvent;
|
|
1116
|
+
"agent.started": AgentStartedEvent;
|
|
1117
|
+
"agent.stopped": AgentStoppedEvent;
|
|
1118
|
+
"agent.error": AgentErrorEvent;
|
|
1119
|
+
"agent.log": AgentLogEvent;
|
|
1120
|
+
"agent.heartbeat": AgentHeartbeatEvent;
|
|
1121
|
+
"alert.created": AlertCreatedEvent;
|
|
1122
|
+
"alert.resolved": AlertResolvedEvent;
|
|
1123
|
+
"llm.call.completed": LLMCallCompletedEvent;
|
|
1124
|
+
"llm.call.failed": LLMCallFailedEvent;
|
|
1125
|
+
"llm.provider.switched": LLMProviderSwitchedEvent;
|
|
1126
|
+
"health.check": HealthCheckEvent;
|
|
1127
|
+
"models.discovered": ModelsDiscoveredEvent;
|
|
1128
|
+
"run.started": RunStartedEvent;
|
|
1129
|
+
"run.completed": RunCompletedEvent;
|
|
1130
|
+
"run.failed": RunFailedEvent;
|
|
1131
|
+
handoff: HandoffEvent;
|
|
1132
|
+
"guardrail.triggered": GuardrailTriggeredEvent;
|
|
1133
|
+
"tool.executed": ToolExecutedEvent;
|
|
1134
|
+
"session.created": SessionCreatedEvent;
|
|
1135
|
+
"session.resumed": SessionResumedEvent;
|
|
1136
|
+
"context.trimmed": ContextTrimmedEvent;
|
|
1137
|
+
"tools.selected": ToolsSelectedEvent;
|
|
1138
|
+
"artifact.created": ArtifactCreatedEvent;
|
|
1139
|
+
}
|
|
1140
|
+
/** Event name type */
|
|
1141
|
+
type ADKEventName = keyof ADKEventMap;
|
|
1142
|
+
/** Event listener type */
|
|
1143
|
+
type ADKEventListener<K extends ADKEventName> = (data: ADKEventMap[K]) => void;
|
|
1144
|
+
|
|
1145
|
+
declare class ADKEventBus {
|
|
1146
|
+
private listeners;
|
|
1147
|
+
/** Subscribe to an event. Returns unsubscribe function. */
|
|
1148
|
+
on<K extends ADKEventName>(event: K, listener: ADKEventListener<K>): () => void;
|
|
1149
|
+
/** Subscribe to an event once. Auto-unsubscribes after first emit. */
|
|
1150
|
+
once<K extends ADKEventName>(event: K, listener: ADKEventListener<K>): () => void;
|
|
1151
|
+
/** Unsubscribe a specific listener. */
|
|
1152
|
+
off<K extends ADKEventName>(event: K, listener: ADKEventListener<K>): void;
|
|
1153
|
+
/** Emit an event to all listeners. */
|
|
1154
|
+
emit<K extends ADKEventName>(event: K, data: ADKEventMap[K]): void;
|
|
1155
|
+
/** Get the number of listeners for an event. */
|
|
1156
|
+
listenerCount(event: ADKEventName): number;
|
|
1157
|
+
/** Get all events with active listeners. */
|
|
1158
|
+
activeEvents(): ADKEventName[];
|
|
1159
|
+
/** Remove all listeners for all events. */
|
|
1160
|
+
removeAllListeners(): void;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/** Agent class — wraps config with utility methods */
|
|
1164
|
+
declare class Agent {
|
|
1165
|
+
readonly name: string;
|
|
1166
|
+
readonly config: Readonly<AgentConfig>;
|
|
1167
|
+
private runtimeTools;
|
|
1168
|
+
constructor(config: AgentConfig);
|
|
1169
|
+
/** Resolve instructions (handles static string or dynamic function) */
|
|
1170
|
+
getInstructions(ctx: RunContext): Promise<string>;
|
|
1171
|
+
/** Get tool definitions (config tools + runtime-injected tools) */
|
|
1172
|
+
getTools(): ToolDef[];
|
|
1173
|
+
/** Add a tool at runtime (e.g., harness tools injected by Runner) */
|
|
1174
|
+
addTool(tool: ToolDef<any, any>): void;
|
|
1175
|
+
/** Get handoff targets */
|
|
1176
|
+
getHandoffs(): HandoffTarget[];
|
|
1177
|
+
/** Get output schema (Zod or JSON Schema) */
|
|
1178
|
+
getOutputSchema(): z.ZodSchema | JsonSchema | undefined;
|
|
1179
|
+
/** Get consent level */
|
|
1180
|
+
getConsentLevel(): ConsentLevel;
|
|
1181
|
+
/** Get max turns */
|
|
1182
|
+
getMaxTurns(): number;
|
|
1183
|
+
/** Get budget limit */
|
|
1184
|
+
getBudgetLimit(): number | undefined;
|
|
1185
|
+
/** Get tool selection config */
|
|
1186
|
+
getToolSelection(): ToolSelectionConfig | undefined;
|
|
1187
|
+
/** Get context config */
|
|
1188
|
+
getContextConfig(): ContextConfig | undefined;
|
|
1189
|
+
/** Clone agent with config overrides */
|
|
1190
|
+
clone(overrides?: Partial<AgentConfig>): Agent;
|
|
1191
|
+
}
|
|
1192
|
+
/** Define an agent from config */
|
|
1193
|
+
declare function defineAgent(config: AgentConfig): Agent;
|
|
1194
|
+
|
|
1195
|
+
/** Define a tool from config */
|
|
1196
|
+
declare function defineTool<TInput = unknown, TOutput = unknown>(config: ToolDefConfig<TInput, TOutput>): ToolDef<TInput, TOutput>;
|
|
1197
|
+
|
|
1198
|
+
/** Search result from the tool registry */
|
|
1199
|
+
interface ToolSearchResult {
|
|
1200
|
+
name: string;
|
|
1201
|
+
description: string;
|
|
1202
|
+
score: number;
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* ToolRegistry — central store for all tools with BM25-style search.
|
|
1206
|
+
* Supports deferred loading: tools marked `deferLoading: true` are stored
|
|
1207
|
+
* but not returned to the LLM until explicitly loaded via search.
|
|
1208
|
+
*/
|
|
1209
|
+
declare class ToolRegistry {
|
|
1210
|
+
private tools;
|
|
1211
|
+
private loadedDeferred;
|
|
1212
|
+
/** Register a tool */
|
|
1213
|
+
register(tool: ToolDef): void;
|
|
1214
|
+
/** Register multiple tools */
|
|
1215
|
+
registerAll(tools: ToolDef[]): void;
|
|
1216
|
+
/** Get a tool by name */
|
|
1217
|
+
get(name: string): ToolDef | undefined;
|
|
1218
|
+
/** Check if a tool exists */
|
|
1219
|
+
has(name: string): boolean;
|
|
1220
|
+
/** Search tools by query using BM25-style keyword matching */
|
|
1221
|
+
search(query: string, limit?: number): ToolSearchResult[];
|
|
1222
|
+
/** Load a deferred tool (mark it as available for LLM) */
|
|
1223
|
+
load(name: string): ToolDef | undefined;
|
|
1224
|
+
/** Get all eager (non-deferred) tools */
|
|
1225
|
+
getEager(): ToolDef[];
|
|
1226
|
+
/** Get all tools that should be sent to LLM (eager + loaded deferred) */
|
|
1227
|
+
getAvailable(): ToolDef[];
|
|
1228
|
+
/** Check if a deferred tool has been loaded */
|
|
1229
|
+
isLoaded(name: string): boolean;
|
|
1230
|
+
/** Get all registered tool names */
|
|
1231
|
+
getAllNames(): string[];
|
|
1232
|
+
/** Clear all tools and loaded state */
|
|
1233
|
+
clear(): void;
|
|
1234
|
+
private tokenize;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* Create a tool_search tool bound to a specific ToolRegistry.
|
|
1239
|
+
* Agents use this to discover and load deferred tools at runtime.
|
|
1240
|
+
*/
|
|
1241
|
+
declare function createToolSearchTool(registry: ToolRegistry): ToolDef<{
|
|
1242
|
+
query: string;
|
|
1243
|
+
}, {
|
|
1244
|
+
tools: {
|
|
1245
|
+
name: string;
|
|
1246
|
+
description: string;
|
|
1247
|
+
}[];
|
|
1248
|
+
}>;
|
|
1249
|
+
|
|
1250
|
+
/** Convert a Zod schema to JSON Schema */
|
|
1251
|
+
declare function zodToJsonSchema(schema: ZodSchema): JsonSchema;
|
|
1252
|
+
/** Check if a value is a Zod schema */
|
|
1253
|
+
declare function isZodSchema(value: unknown): value is ZodSchema;
|
|
1254
|
+
/** Ensure we have a JSON Schema (convert Zod if needed) */
|
|
1255
|
+
declare function ensureJsonSchema(schema: ZodSchema | JsonSchema): JsonSchema;
|
|
1256
|
+
|
|
1257
|
+
/** Validate output against a Zod schema */
|
|
1258
|
+
declare function validateOutput<T>(output: string, schema: ZodSchema<T>): {
|
|
1259
|
+
success: true;
|
|
1260
|
+
data: T;
|
|
1261
|
+
} | {
|
|
1262
|
+
success: false;
|
|
1263
|
+
error: string;
|
|
1264
|
+
};
|
|
1265
|
+
/** Anthropic structured output: use tool_use with forced single-tool call */
|
|
1266
|
+
declare function toAnthropicToolSchema(schema: ZodSchema | JsonSchema, name?: string): {
|
|
1267
|
+
name: string;
|
|
1268
|
+
description: string;
|
|
1269
|
+
input_schema: JsonSchema;
|
|
1270
|
+
};
|
|
1271
|
+
/** OpenAI structured output: response_format with json_schema */
|
|
1272
|
+
declare function toOpenAIResponseFormat(schema: ZodSchema | JsonSchema, name?: string): {
|
|
1273
|
+
type: "json_schema";
|
|
1274
|
+
json_schema: {
|
|
1275
|
+
name: string;
|
|
1276
|
+
strict: boolean;
|
|
1277
|
+
schema: JsonSchema;
|
|
1278
|
+
};
|
|
1279
|
+
};
|
|
1280
|
+
/** Google structured output: generation_config.response_schema */
|
|
1281
|
+
declare function toGoogleSchemaFormat(schema: ZodSchema | JsonSchema): {
|
|
1282
|
+
responseMimeType: string;
|
|
1283
|
+
responseSchema: JsonSchema;
|
|
1284
|
+
};
|
|
1285
|
+
/** Convert a schema (Zod or JSON) to LLM tool definition format */
|
|
1286
|
+
declare function schemaToToolInput(schema: ZodSchema | JsonSchema): Record<string, unknown>;
|
|
1287
|
+
|
|
1288
|
+
/** Error thrown when a tripwire guardrail fails */
|
|
1289
|
+
declare class GuardrailTripwireError extends Error {
|
|
1290
|
+
readonly guardrailName: string;
|
|
1291
|
+
readonly result: GuardrailResult;
|
|
1292
|
+
constructor(guardrailName: string, result: GuardrailResult);
|
|
1293
|
+
}
|
|
1294
|
+
declare class GuardrailEngine {
|
|
1295
|
+
private eventBus?;
|
|
1296
|
+
/** Attach an ADKEventBus for guardrail audit events */
|
|
1297
|
+
setEventBus(bus: ADKEventBus): void;
|
|
1298
|
+
/**
|
|
1299
|
+
* Determine whether a guardrail result should block execution.
|
|
1300
|
+
* - info/warning: never block (soft constraints)
|
|
1301
|
+
* - critical: always block regardless of tripwire
|
|
1302
|
+
* - error (default): block only if tripwire is true (backward compatible)
|
|
1303
|
+
*/
|
|
1304
|
+
private shouldBlock;
|
|
1305
|
+
/** Emit guardrail.triggered events for each result */
|
|
1306
|
+
private emitGuardrailEvents;
|
|
1307
|
+
/** Run all input guardrails. Throws GuardrailTripwireError if a tripwire fails. */
|
|
1308
|
+
runInputGuardrails(input: string, messages: ChatMessage[], ctx: RunContext, guardrails: GuardrailConfig[]): Promise<GuardrailResult[]>;
|
|
1309
|
+
/** Run all output guardrails. Throws GuardrailTripwireError if a tripwire fails. */
|
|
1310
|
+
runOutputGuardrails(output: string, messages: ChatMessage[], ctx: RunContext, guardrails: GuardrailConfig[]): Promise<GuardrailResult[]>;
|
|
1311
|
+
/** Run tool guardrails before tool execution. Throws on tripwire failure. */
|
|
1312
|
+
runToolGuardrails(toolName: string, input: unknown, ctx: RunContext, guardrails: GuardrailConfig[]): Promise<GuardrailResult[]>;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
interface ContentFilterOptions {
|
|
1316
|
+
/** Block patterns (regex) */
|
|
1317
|
+
blockedPatterns?: RegExp[];
|
|
1318
|
+
/** Block keywords (case-insensitive) */
|
|
1319
|
+
blockedKeywords?: string[];
|
|
1320
|
+
/** Max content length */
|
|
1321
|
+
maxLength?: number;
|
|
1322
|
+
/** Whether to tripwire on failure (default: true) */
|
|
1323
|
+
tripwire?: boolean;
|
|
1324
|
+
}
|
|
1325
|
+
/** Creates a content filter guardrail (input guardrail) */
|
|
1326
|
+
declare function contentFilter(options?: ContentFilterOptions): InputGuardrail;
|
|
1327
|
+
|
|
1328
|
+
/** Creates a consent gate guardrail */
|
|
1329
|
+
declare function consentGate(level: ConsentLevel, handler?: ConsentHandler): InputGuardrail;
|
|
1330
|
+
|
|
1331
|
+
/** Creates a budget limit guardrail (checks accumulated cost after each LLM call) */
|
|
1332
|
+
declare function budgetLimit(maxUsd: number): OutputGuardrail;
|
|
1333
|
+
|
|
1334
|
+
/** Budget check data injected into RunContext.metadata.budgetCheck */
|
|
1335
|
+
interface BudgetCheckData {
|
|
1336
|
+
allowed: boolean;
|
|
1337
|
+
usagePercent: number;
|
|
1338
|
+
remainingUsd: number;
|
|
1339
|
+
}
|
|
1340
|
+
declare const budgetGateGuardrail: InputGuardrail;
|
|
1341
|
+
|
|
1342
|
+
interface TokenLimitConfig {
|
|
1343
|
+
/** Max total tokens (input + output) before triggering */
|
|
1344
|
+
maxTotalTokens?: number;
|
|
1345
|
+
/** Max cost USD before triggering */
|
|
1346
|
+
maxCostUsd?: number;
|
|
1347
|
+
/** Severity when limit exceeded (default: "warning") */
|
|
1348
|
+
severity?: GuardrailSeverity;
|
|
1349
|
+
}
|
|
1350
|
+
declare function tokenLimit(config: TokenLimitConfig): OutputGuardrail;
|
|
1351
|
+
|
|
1352
|
+
interface PIIFilterConfig {
|
|
1353
|
+
/** PII types to detect */
|
|
1354
|
+
detect?: ("email" | "phone" | "ssn" | "credit_card")[];
|
|
1355
|
+
/** Severity when PII detected (default: "warning") */
|
|
1356
|
+
severity?: GuardrailSeverity;
|
|
1357
|
+
}
|
|
1358
|
+
declare function piiFilter(config?: PIIFilterConfig): OutputGuardrail;
|
|
1359
|
+
|
|
1360
|
+
declare class Runner {
|
|
1361
|
+
private config;
|
|
1362
|
+
private turnExecutor;
|
|
1363
|
+
private provider?;
|
|
1364
|
+
private eventBus?;
|
|
1365
|
+
private tracer?;
|
|
1366
|
+
private agents;
|
|
1367
|
+
private contextManager?;
|
|
1368
|
+
private modelContextWindow?;
|
|
1369
|
+
private modelCatalog?;
|
|
1370
|
+
private tokenCounter;
|
|
1371
|
+
constructor(config?: RunnerConfig & {
|
|
1372
|
+
provider?: ADKLLMProvider;
|
|
1373
|
+
eventBus?: ADKEventBus;
|
|
1374
|
+
});
|
|
1375
|
+
/** Register an agent (for handoff resolution) */
|
|
1376
|
+
registerAgent(agent: Agent): void;
|
|
1377
|
+
/** Set the LLM provider */
|
|
1378
|
+
setProvider(provider: ADKLLMProvider): void;
|
|
1379
|
+
/** Run an agent to completion */
|
|
1380
|
+
run(agent: Agent, input: RunConfig): Promise<RunResult>;
|
|
1381
|
+
/** Stream events from an agent run — yields events during the turn loop */
|
|
1382
|
+
stream(agent: Agent, input: RunConfig): AsyncGenerator<StreamEvent>;
|
|
1383
|
+
/** Resolve context manager from agent config or runner config */
|
|
1384
|
+
private resolveContextManager;
|
|
1385
|
+
/** Resolve context budget from agent config, model catalog, or defaults */
|
|
1386
|
+
private resolveContextBudget;
|
|
1387
|
+
/** Look up model context window from catalog */
|
|
1388
|
+
private lookupModelContextWindow;
|
|
1389
|
+
/** Estimate total tokens for all tool definitions */
|
|
1390
|
+
private estimateToolTokens;
|
|
1391
|
+
/** Configure tool selection for an agent's turn executor */
|
|
1392
|
+
private configureToolSelection;
|
|
1393
|
+
/** Extract non-text content parts from the final assistant message */
|
|
1394
|
+
private extractOutputParts;
|
|
1395
|
+
/** Build harness tools (progress + notes) if configured */
|
|
1396
|
+
private buildHarnessTools;
|
|
1397
|
+
private buildHandoffTools;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/** Result of a single turn */
|
|
1401
|
+
interface TurnResult {
|
|
1402
|
+
/** New messages produced this turn (assistant response + tool results) */
|
|
1403
|
+
newMessages: ChatMessage[];
|
|
1404
|
+
/** Whether the agent has finished (no tool calls, text response) */
|
|
1405
|
+
finished: boolean;
|
|
1406
|
+
/** Text output (if finished) */
|
|
1407
|
+
output?: string;
|
|
1408
|
+
/** Handoff target (if handoff tool was called) */
|
|
1409
|
+
handoffTarget?: string;
|
|
1410
|
+
/** Handoff reason */
|
|
1411
|
+
handoffReason?: string;
|
|
1412
|
+
/** Guardrail results from this turn */
|
|
1413
|
+
guardrailResults: GuardrailResult[];
|
|
1414
|
+
}
|
|
1415
|
+
declare class TurnExecutor {
|
|
1416
|
+
private guardrailEngine;
|
|
1417
|
+
private toolSelector?;
|
|
1418
|
+
private eventBus?;
|
|
1419
|
+
private toolRegistry?;
|
|
1420
|
+
private currentTrace?;
|
|
1421
|
+
/** Set a tool selector for dynamic per-turn tool filtering */
|
|
1422
|
+
setToolSelector(selector: ToolSelector): void;
|
|
1423
|
+
/** Set event bus for observability */
|
|
1424
|
+
setEventBus(eventBus: ADKEventBus): void;
|
|
1425
|
+
/** Set tool registry for deferred tool loading */
|
|
1426
|
+
setToolRegistry(registry: ToolRegistry): void;
|
|
1427
|
+
/** Set trace for span-based tracing */
|
|
1428
|
+
setTrace(trace?: Trace): void;
|
|
1429
|
+
/**
|
|
1430
|
+
* Execute a single turn.
|
|
1431
|
+
* @param agent The current agent
|
|
1432
|
+
* @param messages All messages so far (including system)
|
|
1433
|
+
* @param provider The LLM provider to use
|
|
1434
|
+
* @param ctx The run context
|
|
1435
|
+
* @param onEvent Optional stream event callback
|
|
1436
|
+
*/
|
|
1437
|
+
executeTurn(agent: Agent, messages: ChatMessage[], provider: ADKLLMProvider, ctx: RunContext, guardrails: GuardrailConfig[], handoffToolDefs?: LLMToolDefinition[], onEvent?: (event: StreamEvent) => void): Promise<TurnResult>;
|
|
1438
|
+
/** Execute a single tool call with timeout and retry support */
|
|
1439
|
+
private executeToolCall;
|
|
1440
|
+
/** Run a promise with a timeout */
|
|
1441
|
+
private withTimeout;
|
|
1442
|
+
private buildToolDefs;
|
|
1443
|
+
/** Extract tool names from recent tool call messages */
|
|
1444
|
+
private extractRecentToolCalls;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
declare function createRunId(): string;
|
|
1448
|
+
declare function createTraceId(): string;
|
|
1449
|
+
declare function createRunContext(opts: {
|
|
1450
|
+
runId?: string;
|
|
1451
|
+
agentName: string;
|
|
1452
|
+
sessionId?: string;
|
|
1453
|
+
traceId?: string;
|
|
1454
|
+
signal?: AbortSignal;
|
|
1455
|
+
metadata?: Record<string, unknown>;
|
|
1456
|
+
}): RunContext;
|
|
1457
|
+
|
|
1458
|
+
/** Configuration for the code executor */
|
|
1459
|
+
interface CodeExecutorConfig {
|
|
1460
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
1461
|
+
timeoutMs?: number;
|
|
1462
|
+
}
|
|
1463
|
+
/** Result of code execution */
|
|
1464
|
+
interface CodeExecutionResult {
|
|
1465
|
+
success: boolean;
|
|
1466
|
+
result: unknown;
|
|
1467
|
+
error?: string;
|
|
1468
|
+
toolCallsPerformed: string[];
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* CodeExecutor — sandboxed JavaScript executor with tool bindings.
|
|
1472
|
+
* Agent code can call tools via `tools.toolName(input)` which returns a Promise.
|
|
1473
|
+
* No filesystem, network, or process access from the sandbox.
|
|
1474
|
+
*/
|
|
1475
|
+
declare class CodeExecutor {
|
|
1476
|
+
private timeoutMs;
|
|
1477
|
+
constructor(config?: CodeExecutorConfig);
|
|
1478
|
+
/**
|
|
1479
|
+
* Execute code in a sandbox with tool bindings.
|
|
1480
|
+
* @param code JavaScript code to execute
|
|
1481
|
+
* @param tools Available tools that the code can call
|
|
1482
|
+
* @param toolCtx Tool context for tool calls
|
|
1483
|
+
*/
|
|
1484
|
+
execute(code: string, tools: ToolDef[], toolCtx: ToolContext): Promise<CodeExecutionResult>;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
interface ExecuteCodeInput {
|
|
1488
|
+
code: string;
|
|
1489
|
+
description?: string;
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Create an execute_code tool that runs agent-written JavaScript
|
|
1493
|
+
* in a sandboxed environment with access to all available tools.
|
|
1494
|
+
*/
|
|
1495
|
+
declare function createExecuteCodeTool(availableTools: ToolDef[], config?: {
|
|
1496
|
+
timeoutMs?: number;
|
|
1497
|
+
}): ToolDef<ExecuteCodeInput>;
|
|
1498
|
+
|
|
1499
|
+
type ADKProviderErrorCode = "RATE_LIMITED" | "CONTEXT_LENGTH_EXCEEDED" | "INVALID_API_KEY" | "MODEL_NOT_FOUND" | "CONTENT_FILTERED" | "SERVICE_UNAVAILABLE" | "TIMEOUT" | "NETWORK_ERROR" | "INSUFFICIENT_QUOTA" | "UNKNOWN";
|
|
1500
|
+
declare class ADKProviderError extends Error {
|
|
1501
|
+
readonly code: ADKProviderErrorCode;
|
|
1502
|
+
readonly providerId: string;
|
|
1503
|
+
readonly model?: string;
|
|
1504
|
+
readonly retryable: boolean;
|
|
1505
|
+
readonly retryAfterMs?: number;
|
|
1506
|
+
readonly statusCode?: number;
|
|
1507
|
+
readonly raw?: unknown;
|
|
1508
|
+
constructor(params: {
|
|
1509
|
+
code: ADKProviderErrorCode;
|
|
1510
|
+
message: string;
|
|
1511
|
+
providerId: string;
|
|
1512
|
+
model?: string;
|
|
1513
|
+
retryable?: boolean;
|
|
1514
|
+
retryAfterMs?: number;
|
|
1515
|
+
statusCode?: number;
|
|
1516
|
+
raw?: unknown;
|
|
1517
|
+
});
|
|
1518
|
+
static rateLimited(providerId: string, retryAfterMs?: number, raw?: unknown): ADKProviderError;
|
|
1519
|
+
static contextExceeded(providerId: string, model?: string, raw?: unknown): ADKProviderError;
|
|
1520
|
+
static invalidApiKey(providerId: string, raw?: unknown): ADKProviderError;
|
|
1521
|
+
static modelNotFound(providerId: string, model: string, raw?: unknown): ADKProviderError;
|
|
1522
|
+
static contentFiltered(providerId: string, raw?: unknown): ADKProviderError;
|
|
1523
|
+
static serviceUnavailable(providerId: string, raw?: unknown): ADKProviderError;
|
|
1524
|
+
static timeout(providerId: string, raw?: unknown): ADKProviderError;
|
|
1525
|
+
static networkError(providerId: string, raw?: unknown): ADKProviderError;
|
|
1526
|
+
static insufficientQuota(providerId: string, raw?: unknown): ADKProviderError;
|
|
1527
|
+
static unknown(providerId: string, raw?: unknown): ADKProviderError;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
declare abstract class BaseProvider implements ADKLLMProvider {
|
|
1531
|
+
abstract readonly providerId: string;
|
|
1532
|
+
abstract readonly displayName: string;
|
|
1533
|
+
abstract readonly isLocal: boolean;
|
|
1534
|
+
protected apiKey?: string;
|
|
1535
|
+
protected baseUrl?: string;
|
|
1536
|
+
protected defaultModel: string;
|
|
1537
|
+
protected modelCosts: Map<string, {
|
|
1538
|
+
input: number;
|
|
1539
|
+
output: number;
|
|
1540
|
+
}>;
|
|
1541
|
+
constructor(config: ProviderInitConfig);
|
|
1542
|
+
abstract chat(params: ChatParams): Promise<ChatResponse>;
|
|
1543
|
+
abstract complete(params: CompleteParams): Promise<CompleteResponse>;
|
|
1544
|
+
abstract chatWithTools(params: ChatParamsWithTools): Promise<ChatResponseWithToolCalls>;
|
|
1545
|
+
abstract chatStream(params: ChatParamsWithTools): AsyncGenerator<StreamChunk>;
|
|
1546
|
+
embed?(_params: EmbedParams): Promise<EmbedResponse>;
|
|
1547
|
+
abstract isAvailable(): boolean;
|
|
1548
|
+
abstract getModels(): string[];
|
|
1549
|
+
abstract estimateCost(inputTokens: number, outputTokens: number, model?: string): number;
|
|
1550
|
+
/** Update model costs (for hot-update from discovery) */
|
|
1551
|
+
updateModelCosts(costs: Map<string, {
|
|
1552
|
+
input: number;
|
|
1553
|
+
output: number;
|
|
1554
|
+
}>): void;
|
|
1555
|
+
/**
|
|
1556
|
+
* Health check — sends a minimal chat request to verify provider reachability.
|
|
1557
|
+
* Subclasses can override for more specific checks (e.g., model listing).
|
|
1558
|
+
* Returns healthy status, latency, and optional error message.
|
|
1559
|
+
*/
|
|
1560
|
+
isHealthy(): Promise<{
|
|
1561
|
+
healthy: boolean;
|
|
1562
|
+
latencyMs: number;
|
|
1563
|
+
error?: string;
|
|
1564
|
+
}>;
|
|
1565
|
+
/** Normalize any thrown error into a structured ADKProviderError */
|
|
1566
|
+
protected normalizeError(err: unknown, model?: string): ADKProviderError;
|
|
1567
|
+
protected getModelCost(model?: string): {
|
|
1568
|
+
input: number;
|
|
1569
|
+
output: number;
|
|
1570
|
+
};
|
|
1571
|
+
protected calculateCost(inputTokens: number, outputTokens: number, model?: string): number;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
declare class AnthropicProvider extends BaseProvider {
|
|
1575
|
+
readonly providerId = "anthropic";
|
|
1576
|
+
readonly displayName = "Anthropic";
|
|
1577
|
+
readonly isLocal = false;
|
|
1578
|
+
constructor(config: ProviderInitConfig);
|
|
1579
|
+
isAvailable(): boolean;
|
|
1580
|
+
getModels(): string[];
|
|
1581
|
+
estimateCost(inputTokens: number, outputTokens: number, model?: string): number;
|
|
1582
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
1583
|
+
complete(params: CompleteParams): Promise<CompleteResponse>;
|
|
1584
|
+
chatWithTools(params: ChatParamsWithTools): Promise<ChatResponseWithToolCalls>;
|
|
1585
|
+
chatStream(params: ChatParamsWithTools): AsyncGenerator<StreamChunk>;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
declare class OpenAIProvider extends BaseProvider {
|
|
1589
|
+
readonly providerId: string;
|
|
1590
|
+
readonly displayName: string;
|
|
1591
|
+
readonly isLocal: boolean;
|
|
1592
|
+
constructor(config: ProviderInitConfig);
|
|
1593
|
+
isAvailable(): boolean;
|
|
1594
|
+
getModels(): string[];
|
|
1595
|
+
estimateCost(inputTokens: number, outputTokens: number, model?: string): number;
|
|
1596
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
1597
|
+
complete(params: CompleteParams): Promise<CompleteResponse>;
|
|
1598
|
+
chatWithTools(params: ChatParamsWithTools): Promise<ChatResponseWithToolCalls>;
|
|
1599
|
+
embed(params: EmbedParams): Promise<EmbedResponse>;
|
|
1600
|
+
chatStream(params: ChatParamsWithTools): AsyncGenerator<StreamChunk>;
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
declare class GoogleProvider extends BaseProvider {
|
|
1604
|
+
readonly providerId = "google";
|
|
1605
|
+
readonly displayName = "Google";
|
|
1606
|
+
readonly isLocal = false;
|
|
1607
|
+
constructor(config: ProviderInitConfig);
|
|
1608
|
+
isAvailable(): boolean;
|
|
1609
|
+
getModels(): string[];
|
|
1610
|
+
estimateCost(inputTokens: number, outputTokens: number, model?: string): number;
|
|
1611
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
1612
|
+
complete(params: CompleteParams): Promise<CompleteResponse>;
|
|
1613
|
+
chatWithTools(params: ChatParamsWithTools): Promise<ChatResponseWithToolCalls>;
|
|
1614
|
+
chatStream(params: ChatParamsWithTools): AsyncGenerator<StreamChunk>;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
declare class XAIProvider extends OpenAIProvider {
|
|
1618
|
+
readonly providerId = "xai";
|
|
1619
|
+
readonly displayName = "xAI";
|
|
1620
|
+
constructor(config: ProviderInitConfig);
|
|
1621
|
+
getModels(): string[];
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
declare class OllamaProvider extends BaseProvider {
|
|
1625
|
+
readonly providerId = "ollama";
|
|
1626
|
+
readonly displayName = "Ollama";
|
|
1627
|
+
readonly isLocal = true;
|
|
1628
|
+
private knownModels;
|
|
1629
|
+
constructor(config: ProviderInitConfig);
|
|
1630
|
+
isAvailable(): boolean;
|
|
1631
|
+
getModels(): string[];
|
|
1632
|
+
estimateCost(): number;
|
|
1633
|
+
updateKnownModels(models: string[]): void;
|
|
1634
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
1635
|
+
complete(params: CompleteParams): Promise<CompleteResponse>;
|
|
1636
|
+
chatWithTools(params: ChatParamsWithTools): Promise<ChatResponseWithToolCalls>;
|
|
1637
|
+
chatStream(params: ChatParamsWithTools): AsyncGenerator<StreamChunk>;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
declare class LMStudioProvider extends OpenAIProvider {
|
|
1641
|
+
readonly providerId = "lmstudio";
|
|
1642
|
+
readonly displayName = "LM Studio";
|
|
1643
|
+
readonly isLocal: boolean;
|
|
1644
|
+
constructor(config: ProviderInitConfig);
|
|
1645
|
+
isAvailable(): boolean;
|
|
1646
|
+
estimateCost(): number;
|
|
1647
|
+
getModels(): string[];
|
|
1648
|
+
private knownModels?;
|
|
1649
|
+
updateKnownModels(models: string[]): void;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
/** Create a provider from config. Returns null if required API key is missing for cloud providers. */
|
|
1653
|
+
declare function createProvider(config: ProviderInitConfig): ADKLLMProvider | null;
|
|
1654
|
+
|
|
1655
|
+
interface RedactOptions {
|
|
1656
|
+
/** Additional patterns to match (merged with defaults unless `patternsOnly` is set) */
|
|
1657
|
+
patterns?: RegExp[];
|
|
1658
|
+
/** Fixed replacement string — if omitted, values are partially masked */
|
|
1659
|
+
replacement?: string;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Redact sensitive information from a text string.
|
|
1663
|
+
* By default masks API keys, connection strings, emails, and JWTs.
|
|
1664
|
+
*/
|
|
1665
|
+
declare function redact(text: string, options?: RedactOptions): string;
|
|
1666
|
+
|
|
1667
|
+
declare class ADKLLMAdapter {
|
|
1668
|
+
private providers;
|
|
1669
|
+
private circuitBreakers;
|
|
1670
|
+
private metrics;
|
|
1671
|
+
private eventBus?;
|
|
1672
|
+
constructor(eventBus?: ADKEventBus);
|
|
1673
|
+
registerProvider(provider: ADKLLMProvider): void;
|
|
1674
|
+
unregisterProvider(providerId: string): void;
|
|
1675
|
+
getProvider(providerId: string): ADKLLMProvider | undefined;
|
|
1676
|
+
getAllProviders(): ADKLLMProvider[];
|
|
1677
|
+
getAvailableProviders(): ADKLLMProvider[];
|
|
1678
|
+
getCircuitState(providerId: string): CircuitBreakerState;
|
|
1679
|
+
getProviderMetrics(providerId: string): ProviderMetrics | undefined;
|
|
1680
|
+
getAllMetrics(): ProviderMetrics[];
|
|
1681
|
+
chat(providerId: string, params: ChatParams, context?: {
|
|
1682
|
+
agentSlug?: string;
|
|
1683
|
+
taskId?: string;
|
|
1684
|
+
}): Promise<ChatResponse>;
|
|
1685
|
+
chatWithTools(providerId: string, params: ChatParamsWithTools, context?: {
|
|
1686
|
+
agentSlug?: string;
|
|
1687
|
+
taskId?: string;
|
|
1688
|
+
}): Promise<ChatResponseWithToolCalls>;
|
|
1689
|
+
chatStream(providerId: string, params: ChatParamsWithTools): AsyncGenerator<StreamChunk>;
|
|
1690
|
+
complete(providerId: string, params: CompleteParams): Promise<CompleteResponse>;
|
|
1691
|
+
embed(providerId: string, params: EmbedParams): Promise<EmbedResponse>;
|
|
1692
|
+
private checkCircuitBreaker;
|
|
1693
|
+
private recordSuccess;
|
|
1694
|
+
private recordFailure;
|
|
1695
|
+
private emitCallCompleted;
|
|
1696
|
+
private emitCallFailed;
|
|
1697
|
+
reset(): void;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
declare class ADKRouter {
|
|
1701
|
+
private configs;
|
|
1702
|
+
private budgetUsage;
|
|
1703
|
+
private adapter;
|
|
1704
|
+
constructor(adapter: ADKLLMAdapter);
|
|
1705
|
+
setConfig(agentSlug: string, config: AgentLLMConfig): void;
|
|
1706
|
+
getConfig(agentSlug: string): AgentLLMConfig;
|
|
1707
|
+
route(agentSlug: string, params: ChatParamsWithTools, context?: {
|
|
1708
|
+
taskId?: string;
|
|
1709
|
+
}): Promise<ChatResponseWithToolCalls>;
|
|
1710
|
+
private selectProvider;
|
|
1711
|
+
private selectCheapest;
|
|
1712
|
+
private selectFastest;
|
|
1713
|
+
private selectHighestQuality;
|
|
1714
|
+
private selectBalanced;
|
|
1715
|
+
private selectFromChain;
|
|
1716
|
+
resetBudget(agentSlug: string): void;
|
|
1717
|
+
resetAllBudgets(): void;
|
|
1718
|
+
getBudgetUsage(agentSlug: string): number;
|
|
1719
|
+
reset(): void;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/** Create a controllable async generator from events */
|
|
1723
|
+
declare function createAsyncEventStream(): {
|
|
1724
|
+
push: (event: StreamEvent) => void;
|
|
1725
|
+
close: () => void;
|
|
1726
|
+
error: (err: Error) => void;
|
|
1727
|
+
stream: AsyncGenerator<StreamEvent>;
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
/** Encode a StreamEvent as an SSE data line */
|
|
1731
|
+
declare function encodeSSE(event: StreamEvent): string;
|
|
1732
|
+
/** Convert an AsyncGenerator<StreamEvent> to a ReadableStream<Uint8Array> for SSE */
|
|
1733
|
+
declare function streamToSSE(generator: AsyncGenerator<StreamEvent>): ReadableStream<Uint8Array>;
|
|
1734
|
+
|
|
1735
|
+
/** Minimal WebSocket interface (works with ws, browser WebSocket, etc.) */
|
|
1736
|
+
interface WSLike {
|
|
1737
|
+
send(data: string): void;
|
|
1738
|
+
close(code?: number, reason?: string): void;
|
|
1739
|
+
readyState: number;
|
|
1740
|
+
}
|
|
1741
|
+
/** Relay stream events to a WebSocket connection */
|
|
1742
|
+
declare function relayToWebSocket(generator: AsyncGenerator<StreamEvent>, ws: WSLike): Promise<void>;
|
|
1743
|
+
|
|
1744
|
+
interface BackpressureOptions {
|
|
1745
|
+
/** Max items in buffer before dropping oldest (default: 100) */
|
|
1746
|
+
bufferLimit?: number;
|
|
1747
|
+
/** SSE keepalive interval in ms (default: 15000) */
|
|
1748
|
+
keepaliveIntervalMs?: number;
|
|
1749
|
+
}
|
|
1750
|
+
declare class BackpressuredStream<T> {
|
|
1751
|
+
private options;
|
|
1752
|
+
private buffer;
|
|
1753
|
+
private resolve;
|
|
1754
|
+
private done;
|
|
1755
|
+
private keepaliveTimer;
|
|
1756
|
+
private readonly bufferLimit;
|
|
1757
|
+
constructor(options?: BackpressureOptions);
|
|
1758
|
+
/**
|
|
1759
|
+
* Push an item into the stream.
|
|
1760
|
+
* If a consumer is waiting, delivers directly.
|
|
1761
|
+
* If buffer is full, drops the oldest item (lossy backpressure).
|
|
1762
|
+
* Returns false if stream is already ended.
|
|
1763
|
+
*/
|
|
1764
|
+
push(item: T): boolean;
|
|
1765
|
+
/** Signal end-of-stream. Resolves any waiting consumer. */
|
|
1766
|
+
end(): void;
|
|
1767
|
+
/** Start an interval that calls onKeepalive periodically (for SSE `:keepalive` comments). */
|
|
1768
|
+
startKeepalive(onKeepalive: () => void): void;
|
|
1769
|
+
/** Stop the keepalive timer. */
|
|
1770
|
+
stopKeepalive(): void;
|
|
1771
|
+
/** Current number of buffered items. */
|
|
1772
|
+
get bufferSize(): number;
|
|
1773
|
+
/** True when buffer has reached its limit. */
|
|
1774
|
+
get isFull(): boolean;
|
|
1775
|
+
/** Whether the stream has been ended. */
|
|
1776
|
+
get isDone(): boolean;
|
|
1777
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
/** Create a stream adapter from an AsyncGenerator<StreamEvent> */
|
|
1781
|
+
declare function createStreamAdapter(generator: AsyncGenerator<StreamEvent>): {
|
|
1782
|
+
toSSE(): ReadableStream<Uint8Array>;
|
|
1783
|
+
toWebSocket(ws: WSLike): Promise<void>;
|
|
1784
|
+
toAsyncIterable(): AsyncIterable<StreamEvent>;
|
|
1785
|
+
};
|
|
1786
|
+
|
|
1787
|
+
/** Generate a new API key */
|
|
1788
|
+
declare function generateApiKey(type?: "live" | "test"): {
|
|
1789
|
+
key: string;
|
|
1790
|
+
hash: string;
|
|
1791
|
+
prefix: string;
|
|
1792
|
+
};
|
|
1793
|
+
/** Hash an API key (for storage — never store the raw key) */
|
|
1794
|
+
declare function hashApiKey(key: string): string;
|
|
1795
|
+
/** Parse an API key into its parts */
|
|
1796
|
+
declare function parseApiKey(key: string): {
|
|
1797
|
+
type: "live" | "test";
|
|
1798
|
+
prefix: string;
|
|
1799
|
+
hash: string;
|
|
1800
|
+
} | null;
|
|
1801
|
+
/** Validate API key format */
|
|
1802
|
+
declare function validateApiKeyFormat(key: string): boolean;
|
|
1803
|
+
|
|
1804
|
+
interface ADKApiKey {
|
|
1805
|
+
id: string;
|
|
1806
|
+
keyHash: string;
|
|
1807
|
+
type: "live" | "test";
|
|
1808
|
+
permissions: string[];
|
|
1809
|
+
active: boolean;
|
|
1810
|
+
ownerId: string;
|
|
1811
|
+
}
|
|
1812
|
+
/** Proxy router: resolves an ADK API key to underlying provider credentials */
|
|
1813
|
+
declare class ProxyRouter {
|
|
1814
|
+
private providerCredentials;
|
|
1815
|
+
constructor(providerCredentials: Map<string, string>);
|
|
1816
|
+
/**
|
|
1817
|
+
* Resolve a validated API key to provider credentials.
|
|
1818
|
+
* Returns the provider's API key and optional base URL.
|
|
1819
|
+
*/
|
|
1820
|
+
resolve(_apiKey: ADKApiKey, providerId: string): {
|
|
1821
|
+
apiKey: string;
|
|
1822
|
+
baseUrl?: string;
|
|
1823
|
+
} | null;
|
|
1824
|
+
/** Check if a provider has credentials configured */
|
|
1825
|
+
hasProvider(providerId: string): boolean;
|
|
1826
|
+
/** Get all configured provider IDs */
|
|
1827
|
+
getConfiguredProviders(): string[];
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
declare class MemorySessionBackend implements SessionBackend {
|
|
1831
|
+
private sessions;
|
|
1832
|
+
create(options: SessionCreateOptions): Promise<Session>;
|
|
1833
|
+
get(sessionId: string): Promise<Session | null>;
|
|
1834
|
+
update(sessionId: string, options: SessionUpdateOptions): Promise<Session>;
|
|
1835
|
+
appendMessages(sessionId: string, messages: ChatMessage[]): Promise<Session>;
|
|
1836
|
+
fork(sessionId: string): Promise<Session>;
|
|
1837
|
+
delete(sessionId: string): Promise<void>;
|
|
1838
|
+
list(filter?: SessionListFilter): Promise<Session[]>;
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
declare class PrismaSessionBackend implements SessionBackend {
|
|
1842
|
+
private db;
|
|
1843
|
+
constructor(db: unknown);
|
|
1844
|
+
create(options: SessionCreateOptions): Promise<Session>;
|
|
1845
|
+
get(sessionId: string): Promise<Session | null>;
|
|
1846
|
+
update(sessionId: string, options: SessionUpdateOptions): Promise<Session>;
|
|
1847
|
+
appendMessages(sessionId: string, messages: ChatMessage[]): Promise<Session>;
|
|
1848
|
+
fork(sessionId: string): Promise<Session>;
|
|
1849
|
+
delete(sessionId: string): Promise<void>;
|
|
1850
|
+
list(filter?: SessionListFilter): Promise<Session[]>;
|
|
1851
|
+
/** Convert a Prisma record to Session interface */
|
|
1852
|
+
private toSession;
|
|
1853
|
+
/** Safely parse JSON — handles both string and pre-parsed values */
|
|
1854
|
+
private parseJson;
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
/** Summarization configuration */
|
|
1858
|
+
interface SummarizationConfig {
|
|
1859
|
+
/** LLM provider for summarization */
|
|
1860
|
+
provider?: ADKLLMProvider;
|
|
1861
|
+
/** Model to use for summarization (cheap/fast model recommended) */
|
|
1862
|
+
model?: string;
|
|
1863
|
+
/** Max tokens for the summary (default: 500) */
|
|
1864
|
+
maxSummaryTokens?: number;
|
|
1865
|
+
}
|
|
1866
|
+
/** Partition result: messages to summarize vs. messages to keep */
|
|
1867
|
+
interface MessagePartition {
|
|
1868
|
+
/** Older messages to be summarized */
|
|
1869
|
+
summarize: ChatMessage[];
|
|
1870
|
+
/** Recent messages to keep verbatim */
|
|
1871
|
+
keep: ChatMessage[];
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* ContextSummarizer — summarizes older messages to reduce context size.
|
|
1875
|
+
*
|
|
1876
|
+
* Uses an LLM provider if available, otherwise falls back to extractive
|
|
1877
|
+
* summarization (first + last sentence per message).
|
|
1878
|
+
*/
|
|
1879
|
+
declare class ContextSummarizer {
|
|
1880
|
+
private config;
|
|
1881
|
+
constructor(config?: SummarizationConfig);
|
|
1882
|
+
/**
|
|
1883
|
+
* Summarize messages into a condensed context message.
|
|
1884
|
+
* Falls back to extractive summarization if no LLM provider is available.
|
|
1885
|
+
*/
|
|
1886
|
+
summarize(messages: ChatMessage[]): Promise<ChatMessage>;
|
|
1887
|
+
/**
|
|
1888
|
+
* Split messages: keep recent N turns verbatim, summarize the rest.
|
|
1889
|
+
* A "turn" is a user message + assistant response pair.
|
|
1890
|
+
*/
|
|
1891
|
+
partitionMessages(messages: ChatMessage[], keepRecentTurns: number): MessagePartition;
|
|
1892
|
+
/** LLM-powered summarization */
|
|
1893
|
+
private llmSummarize;
|
|
1894
|
+
/** Extractive fallback: first + last sentence per message */
|
|
1895
|
+
private extractiveSummarize;
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
/** Token counting strategy */
|
|
1899
|
+
type TokenCounterStrategy = "character" | "tiktoken-approx" | "provider-reported";
|
|
1900
|
+
/** Token counter configuration */
|
|
1901
|
+
interface TokenCounterConfig {
|
|
1902
|
+
strategy?: TokenCounterStrategy;
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* TokenCounter — estimates token counts without external dependencies.
|
|
1906
|
+
*
|
|
1907
|
+
* Strategies:
|
|
1908
|
+
* - "character": simple `Math.ceil(text.length / 4)` (cheapest, ~70% accuracy)
|
|
1909
|
+
* - "tiktoken-approx": BPE-approximation without external deps (~85% accuracy)
|
|
1910
|
+
* - "provider-reported": starts with tiktoken-approx, calibrates from actual provider counts
|
|
1911
|
+
*/
|
|
1912
|
+
declare class TokenCounter {
|
|
1913
|
+
private strategy;
|
|
1914
|
+
private calibrationFactor;
|
|
1915
|
+
constructor(config?: TokenCounterConfig);
|
|
1916
|
+
/** Count tokens in a text string */
|
|
1917
|
+
countText(text: string): number;
|
|
1918
|
+
/** Count tokens in a single message (content + overhead) */
|
|
1919
|
+
countMessage(msg: ChatMessage): number;
|
|
1920
|
+
/** Count tokens across multiple messages */
|
|
1921
|
+
countMessages(messages: ChatMessage[]): number;
|
|
1922
|
+
/** Count tokens for a single tool definition */
|
|
1923
|
+
countToolDef(tool: LLMToolDefinition): number;
|
|
1924
|
+
/** Count tokens for all tool definitions */
|
|
1925
|
+
countToolDefs(tools: LLMToolDefinition[]): number;
|
|
1926
|
+
/** Calibrate from actual provider-reported token count */
|
|
1927
|
+
calibrate(text: string, actualTokens: number): void;
|
|
1928
|
+
/** Get current calibration factor */
|
|
1929
|
+
getCalibrationFactor(): number;
|
|
1930
|
+
/** Estimate image tokens based on detail level */
|
|
1931
|
+
private estimateImageTokens;
|
|
1932
|
+
/** Estimate audio tokens from duration or base64 size */
|
|
1933
|
+
private estimateAudioTokens;
|
|
1934
|
+
/** Estimate video tokens from duration or base64 size */
|
|
1935
|
+
private estimateVideoTokens;
|
|
1936
|
+
/**
|
|
1937
|
+
* BPE-approximation: split on whitespace, count sub-word splits for long words,
|
|
1938
|
+
* account for punctuation. ~85% accuracy without external deps.
|
|
1939
|
+
*/
|
|
1940
|
+
private bpeApprox;
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
/** Context manager configuration */
|
|
1944
|
+
interface ContextManagerConfig {
|
|
1945
|
+
/** Token counting strategy */
|
|
1946
|
+
tokenCounterStrategy?: TokenCounterStrategy;
|
|
1947
|
+
/** Summarization config (provider, model, maxSummaryTokens) */
|
|
1948
|
+
summarization?: SummarizationConfig;
|
|
1949
|
+
/** Number of recent turns to always keep verbatim (default: 4) */
|
|
1950
|
+
keepRecentTurns?: number;
|
|
1951
|
+
}
|
|
1952
|
+
declare class ContextManager {
|
|
1953
|
+
private tokenCounter;
|
|
1954
|
+
private summarizer?;
|
|
1955
|
+
private keepRecentTurns;
|
|
1956
|
+
constructor(config?: ContextManagerConfig);
|
|
1957
|
+
/**
|
|
1958
|
+
* Trim messages to fit within a token budget.
|
|
1959
|
+
* Always preserves the system message (first) and most recent messages.
|
|
1960
|
+
*/
|
|
1961
|
+
trimToFit(messages: ChatMessage[], maxTokens: number, strategy?: ContextStrategy): Promise<ChatMessage[]>;
|
|
1962
|
+
/** Get total token count for messages */
|
|
1963
|
+
getTokenCount(messages: ChatMessage[]): number;
|
|
1964
|
+
private smartSummary;
|
|
1965
|
+
/**
|
|
1966
|
+
* JIT (Just-In-Time) strategy: keep only system prompt + last N messages.
|
|
1967
|
+
* Older messages are dropped (they can be recalled via a recall_context tool).
|
|
1968
|
+
*/
|
|
1969
|
+
private jitTrim;
|
|
1970
|
+
private slidingWindow;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
interface CompactionOptions {
|
|
1974
|
+
/** Maximum number of messages to retain */
|
|
1975
|
+
maxMessages: number;
|
|
1976
|
+
/** Compaction strategy — truncate keeps most recent messages */
|
|
1977
|
+
strategy: "truncate" | "summarize";
|
|
1978
|
+
/** Whether to always preserve the system message(s) at the start */
|
|
1979
|
+
keepSystemMessage: boolean;
|
|
1980
|
+
}
|
|
1981
|
+
/**
|
|
1982
|
+
* Compact a message array to fit within maxMessages.
|
|
1983
|
+
*
|
|
1984
|
+
* With strategy="truncate", system messages are preserved at the front
|
|
1985
|
+
* and the most recent non-system messages are kept.
|
|
1986
|
+
*
|
|
1987
|
+
* With strategy="summarize", falls back to truncate for now (future:
|
|
1988
|
+
* will insert an LLM-generated summary of trimmed messages).
|
|
1989
|
+
*/
|
|
1990
|
+
declare function compactMessages(messages: ChatMessage[], options?: Partial<CompactionOptions>): ChatMessage[];
|
|
1991
|
+
|
|
1992
|
+
/** Backend interface for pluggable persistence */
|
|
1993
|
+
interface AgenticMemoryBackend {
|
|
1994
|
+
get(key: string): Promise<string | undefined>;
|
|
1995
|
+
set(key: string, value: string): Promise<void>;
|
|
1996
|
+
delete(key: string): Promise<boolean>;
|
|
1997
|
+
list(prefix?: string): Promise<string[]>;
|
|
1998
|
+
}
|
|
1999
|
+
/** In-memory backend (default) */
|
|
2000
|
+
declare class InMemoryBackend implements AgenticMemoryBackend {
|
|
2001
|
+
private store;
|
|
2002
|
+
get(key: string): Promise<string | undefined>;
|
|
2003
|
+
set(key: string, value: string): Promise<void>;
|
|
2004
|
+
delete(key: string): Promise<boolean>;
|
|
2005
|
+
list(prefix?: string): Promise<string[]>;
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* AgenticMemory — simple persistent key-value store for agents.
|
|
2009
|
+
* Persists state across run calls when the same store instance is reused.
|
|
2010
|
+
*/
|
|
2011
|
+
declare class AgenticMemory {
|
|
2012
|
+
private backend;
|
|
2013
|
+
constructor(backend?: AgenticMemoryBackend);
|
|
2014
|
+
get(key: string): Promise<string | undefined>;
|
|
2015
|
+
set(key: string, value: string): Promise<void>;
|
|
2016
|
+
delete(key: string): Promise<boolean>;
|
|
2017
|
+
search(prefix: string): Promise<Array<{
|
|
2018
|
+
key: string;
|
|
2019
|
+
value: string;
|
|
2020
|
+
}>>;
|
|
2021
|
+
list(): Promise<string[]>;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
declare function createMemoryWriteTool(memory: AgenticMemory): ToolDef<{
|
|
2025
|
+
key: string;
|
|
2026
|
+
value: string;
|
|
2027
|
+
}>;
|
|
2028
|
+
declare function createMemoryReadTool(memory: AgenticMemory): ToolDef<{
|
|
2029
|
+
key: string;
|
|
2030
|
+
}>;
|
|
2031
|
+
declare function createMemorySearchTool(memory: AgenticMemory): ToolDef<{
|
|
2032
|
+
prefix: string;
|
|
2033
|
+
}>;
|
|
2034
|
+
|
|
2035
|
+
declare class ConsoleExporter implements TraceExporter {
|
|
2036
|
+
export(trace: TraceData): Promise<void>;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
declare class EventBusExporter implements TraceExporter {
|
|
2040
|
+
private eventBus;
|
|
2041
|
+
constructor(eventBus: ADKEventBus);
|
|
2042
|
+
export(trace: TraceData): Promise<void>;
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
interface LangfuseConfig {
|
|
2046
|
+
publicKey: string;
|
|
2047
|
+
secretKey: string;
|
|
2048
|
+
baseUrl?: string;
|
|
2049
|
+
}
|
|
2050
|
+
declare class LangfuseExporter implements TraceExporter {
|
|
2051
|
+
private config;
|
|
2052
|
+
constructor(config: LangfuseConfig);
|
|
2053
|
+
export(trace: TraceData): Promise<void>;
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
declare const HANDOFF_PREFIX = "transfer_to_";
|
|
2057
|
+
/** Record of a handoff registration */
|
|
2058
|
+
interface HandoffRegistration {
|
|
2059
|
+
from: Agent;
|
|
2060
|
+
to: Agent;
|
|
2061
|
+
description: string;
|
|
2062
|
+
filter?: (ctx: RunContext) => boolean | Promise<boolean>;
|
|
2063
|
+
}
|
|
2064
|
+
/** Manages handoff registrations and tool generation */
|
|
2065
|
+
declare class HandoffManager {
|
|
2066
|
+
private registrations;
|
|
2067
|
+
private circularGuard;
|
|
2068
|
+
/** Register a handoff from one agent to another */
|
|
2069
|
+
registerHandoff(from: Agent, to: Agent, description: string, filter?: (ctx: RunContext) => boolean | Promise<boolean>): void;
|
|
2070
|
+
/** Auto-register handoffs from an agent's config.handoffs */
|
|
2071
|
+
registerFromConfig(agent: Agent, agentMap: Map<string, Agent>): void;
|
|
2072
|
+
/** Get handoff tools for a given agent (as ToolDefs) */
|
|
2073
|
+
getHandoffTools(agent: Agent): ToolDef[];
|
|
2074
|
+
/** Get handoff LLMToolDefinitions for a given agent */
|
|
2075
|
+
getHandoffToolDefs(agent: Agent): LLMToolDefinition[];
|
|
2076
|
+
/** Execute a handoff (validates, checks circular, emits) */
|
|
2077
|
+
executeHandoff(from: Agent, to: Agent, ctx: RunContext, reason: string): Promise<void>;
|
|
2078
|
+
/** Get all registered handoffs for a given agent */
|
|
2079
|
+
getHandoffsForAgent(agent: Agent): HandoffRegistration[];
|
|
2080
|
+
/** Reset circular guard (call between runs) */
|
|
2081
|
+
resetCircularGuard(): void;
|
|
2082
|
+
/** Clear all registrations */
|
|
2083
|
+
clear(): void;
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
interface AgentAsToolConfig {
|
|
2087
|
+
/** Custom tool name (defaults to agent name) */
|
|
2088
|
+
name?: string;
|
|
2089
|
+
/** Custom description (defaults to agent description or instructions summary) */
|
|
2090
|
+
description?: string;
|
|
2091
|
+
/** Provider to use for the inner run */
|
|
2092
|
+
provider?: ADKLLMProvider;
|
|
2093
|
+
/** Max turns for the inner run */
|
|
2094
|
+
maxTurns?: number;
|
|
2095
|
+
/** Whether to return full RunResult or just output text */
|
|
2096
|
+
fullResult?: boolean;
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Wrap an Agent as a ToolDef. When another agent calls this tool,
|
|
2100
|
+
* it runs the wrapped agent as a sub-agent and returns the output.
|
|
2101
|
+
*/
|
|
2102
|
+
declare function agentAsTool(agent: Agent, config?: AgentAsToolConfig): ToolDef;
|
|
2103
|
+
|
|
2104
|
+
interface ParallelRunnerConfig {
|
|
2105
|
+
/** LLM provider to use */
|
|
2106
|
+
provider: ADKLLMProvider;
|
|
2107
|
+
}
|
|
2108
|
+
declare class ParallelRunner {
|
|
2109
|
+
private provider;
|
|
2110
|
+
constructor(config: ParallelRunnerConfig);
|
|
2111
|
+
/**
|
|
2112
|
+
* Run all agents concurrently. Returns all results.
|
|
2113
|
+
* All agents receive the same input.
|
|
2114
|
+
*/
|
|
2115
|
+
runAll(agents: Agent[], input: RunConfig): Promise<RunResult[]>;
|
|
2116
|
+
/**
|
|
2117
|
+
* Race agents. Returns the first result that completes.
|
|
2118
|
+
* Other runs are aborted.
|
|
2119
|
+
*/
|
|
2120
|
+
race(agents: Agent[], input: RunConfig): Promise<RunResult>;
|
|
2121
|
+
/**
|
|
2122
|
+
* Run agents in pipeline — output of one becomes input of the next.
|
|
2123
|
+
* The first agent gets the original input; subsequent agents get the
|
|
2124
|
+
* previous agent's output as their input.
|
|
2125
|
+
*/
|
|
2126
|
+
pipeline(agents: Agent[], input: RunConfig): Promise<RunResult>;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
/** Team consensus types */
|
|
2130
|
+
type ConsensusType = "coordinator_decides" | "majority" | "unanimous" | "weighted";
|
|
2131
|
+
/** Team configuration */
|
|
2132
|
+
interface TeamConfig {
|
|
2133
|
+
/** Team name */
|
|
2134
|
+
name: string;
|
|
2135
|
+
/** Coordinator agent — orchestrates the team */
|
|
2136
|
+
coordinator: Agent;
|
|
2137
|
+
/** Team member agents */
|
|
2138
|
+
members: Agent[];
|
|
2139
|
+
/** How decisions are made */
|
|
2140
|
+
consensusType?: ConsensusType;
|
|
2141
|
+
/** Maximum coordination rounds */
|
|
2142
|
+
maxRounds?: number;
|
|
2143
|
+
/** LLM provider */
|
|
2144
|
+
provider: ADKLLMProvider;
|
|
2145
|
+
/** Event bus (optional) */
|
|
2146
|
+
eventBus?: ADKEventBus;
|
|
2147
|
+
}
|
|
2148
|
+
/** Team execution result */
|
|
2149
|
+
interface TeamResult extends RunResult {
|
|
2150
|
+
/** Individual member results */
|
|
2151
|
+
memberResults: {
|
|
2152
|
+
agentName: string;
|
|
2153
|
+
result: RunResult;
|
|
2154
|
+
}[];
|
|
2155
|
+
/** Number of coordination rounds */
|
|
2156
|
+
rounds: number;
|
|
2157
|
+
}
|
|
2158
|
+
declare class Team {
|
|
2159
|
+
private config;
|
|
2160
|
+
constructor(config: TeamConfig);
|
|
2161
|
+
/** Run the team: coordinator delegates to members, aggregates results */
|
|
2162
|
+
run(input: RunConfig): Promise<TeamResult>;
|
|
2163
|
+
/** Stream events from a team run */
|
|
2164
|
+
stream(input: RunConfig): AsyncGenerator<StreamEvent>;
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
/** Pipeline task definition */
|
|
2168
|
+
interface PipelineTask {
|
|
2169
|
+
/** Task ID */
|
|
2170
|
+
id: string;
|
|
2171
|
+
/** Task description / instructions */
|
|
2172
|
+
description: string;
|
|
2173
|
+
/** File context (paths, diffs, etc.) */
|
|
2174
|
+
context?: string;
|
|
2175
|
+
/** Additional metadata */
|
|
2176
|
+
metadata?: Record<string, unknown>;
|
|
2177
|
+
}
|
|
2178
|
+
/** Pipeline step type */
|
|
2179
|
+
type PipelineStepType = "workspace" | "agent" | "validate" | "report";
|
|
2180
|
+
/** Pipeline step result */
|
|
2181
|
+
interface PipelineStepResult {
|
|
2182
|
+
step: PipelineStepType;
|
|
2183
|
+
success: boolean;
|
|
2184
|
+
output: string;
|
|
2185
|
+
durationMs: number;
|
|
2186
|
+
error?: string;
|
|
2187
|
+
}
|
|
2188
|
+
/** Full pipeline result */
|
|
2189
|
+
interface PipelineResult {
|
|
2190
|
+
taskId: string;
|
|
2191
|
+
success: boolean;
|
|
2192
|
+
steps: PipelineStepResult[];
|
|
2193
|
+
agentResult?: RunResult;
|
|
2194
|
+
totalDurationMs: number;
|
|
2195
|
+
output: string;
|
|
2196
|
+
}
|
|
2197
|
+
/** Pipeline configuration */
|
|
2198
|
+
interface PipelineConfig {
|
|
2199
|
+
/** LLM provider */
|
|
2200
|
+
provider: ADKLLMProvider;
|
|
2201
|
+
/** Event bus (optional) */
|
|
2202
|
+
eventBus?: ADKEventBus;
|
|
2203
|
+
/** Workspace setup function (optional — returns context string) */
|
|
2204
|
+
workspaceSetup?: (task: PipelineTask) => Promise<string>;
|
|
2205
|
+
/** Validation function (optional — returns { valid, errors }) */
|
|
2206
|
+
validator?: (output: string, task: PipelineTask) => Promise<{
|
|
2207
|
+
valid: boolean;
|
|
2208
|
+
errors: string[];
|
|
2209
|
+
}>;
|
|
2210
|
+
/** Report function (optional — generates report from results) */
|
|
2211
|
+
reporter?: (result: PipelineResult) => Promise<string>;
|
|
2212
|
+
/** Max agent turns */
|
|
2213
|
+
maxTurns?: number;
|
|
2214
|
+
}
|
|
2215
|
+
declare class ADKPipeline {
|
|
2216
|
+
private config;
|
|
2217
|
+
constructor(config: PipelineConfig);
|
|
2218
|
+
/** Execute the full pipeline */
|
|
2219
|
+
execute(agent: Agent, task: PipelineTask): Promise<PipelineResult>;
|
|
2220
|
+
private buildAgentInput;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
/** Review severity levels */
|
|
2224
|
+
type ReviewSeverity = "info" | "warning" | "error" | "critical";
|
|
2225
|
+
/** Single review comment */
|
|
2226
|
+
interface ReviewComment {
|
|
2227
|
+
file?: string;
|
|
2228
|
+
line?: number;
|
|
2229
|
+
severity: ReviewSeverity;
|
|
2230
|
+
message: string;
|
|
2231
|
+
suggestion?: string;
|
|
2232
|
+
reviewer: string;
|
|
2233
|
+
}
|
|
2234
|
+
/** Individual reviewer's result */
|
|
2235
|
+
interface ReviewerResult {
|
|
2236
|
+
reviewer: string;
|
|
2237
|
+
verdict: "approve" | "request_changes" | "comment";
|
|
2238
|
+
comments: ReviewComment[];
|
|
2239
|
+
summary: string;
|
|
2240
|
+
confidence: number;
|
|
2241
|
+
runResult: RunResult;
|
|
2242
|
+
}
|
|
2243
|
+
/** Aggregated review result */
|
|
2244
|
+
interface ReviewResult {
|
|
2245
|
+
verdict: "approve" | "request_changes" | "comment";
|
|
2246
|
+
reviewers: ReviewerResult[];
|
|
2247
|
+
comments: ReviewComment[];
|
|
2248
|
+
summary: string;
|
|
2249
|
+
totalDurationMs: number;
|
|
2250
|
+
}
|
|
2251
|
+
/** Review configuration */
|
|
2252
|
+
interface ReviewConfig {
|
|
2253
|
+
/** LLM provider */
|
|
2254
|
+
provider: ADKLLMProvider;
|
|
2255
|
+
/** Event bus (optional) */
|
|
2256
|
+
eventBus?: ADKEventBus;
|
|
2257
|
+
/** Approval threshold (fraction of reviewers that must approve: 0.0 - 1.0) */
|
|
2258
|
+
approvalThreshold?: number;
|
|
2259
|
+
/** Max turns per reviewer */
|
|
2260
|
+
maxTurns?: number;
|
|
2261
|
+
}
|
|
2262
|
+
declare class ADKReviewPipeline {
|
|
2263
|
+
private config;
|
|
2264
|
+
constructor(config: ReviewConfig);
|
|
2265
|
+
/** Run a multi-agent code review */
|
|
2266
|
+
review(diff: string, reviewers: Agent[], context?: string): Promise<ReviewResult>;
|
|
2267
|
+
private runReviewer;
|
|
2268
|
+
private parseReviewerOutput;
|
|
2269
|
+
private parseSeverity;
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
/** MCP transport type */
|
|
2273
|
+
type MCPTransport = "stdio" | "sse" | "streamable-http";
|
|
2274
|
+
/** MCP auth configuration */
|
|
2275
|
+
interface MCPAuthConfig {
|
|
2276
|
+
type: "bearer" | "basic" | "api-key";
|
|
2277
|
+
token?: string;
|
|
2278
|
+
username?: string;
|
|
2279
|
+
password?: string;
|
|
2280
|
+
apiKey?: string;
|
|
2281
|
+
headerName?: string;
|
|
2282
|
+
}
|
|
2283
|
+
/** MCP server connection config */
|
|
2284
|
+
interface MCPServerConfig {
|
|
2285
|
+
/** Server URL or command (for stdio) */
|
|
2286
|
+
serverUrl: string;
|
|
2287
|
+
/** Transport type */
|
|
2288
|
+
transport: MCPTransport;
|
|
2289
|
+
/** Auth config (optional) */
|
|
2290
|
+
authConfig?: MCPAuthConfig;
|
|
2291
|
+
/** Filter function to select which tools to expose */
|
|
2292
|
+
toolFilter?: (tool: MCPToolInfo) => boolean;
|
|
2293
|
+
/** Timeout for tool calls in ms */
|
|
2294
|
+
timeoutMs?: number;
|
|
2295
|
+
/** Specific tool names to load (name-based filter) */
|
|
2296
|
+
toolNames?: string[];
|
|
2297
|
+
/** Filter by category metadata */
|
|
2298
|
+
categories?: string[];
|
|
2299
|
+
/** Cap total tools returned */
|
|
2300
|
+
maxTools?: number;
|
|
2301
|
+
}
|
|
2302
|
+
/** MCP tool information (from server) */
|
|
2303
|
+
interface MCPToolInfo {
|
|
2304
|
+
name: string;
|
|
2305
|
+
description: string;
|
|
2306
|
+
inputSchema: JsonSchema;
|
|
2307
|
+
/** Optional category metadata */
|
|
2308
|
+
category?: string;
|
|
2309
|
+
/** Optional tags */
|
|
2310
|
+
tags?: string[];
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Connect to an MCP server and return its tools as ToolDef[].
|
|
2314
|
+
*
|
|
2315
|
+
* This is a lightweight adapter that converts MCP tool definitions
|
|
2316
|
+
* to ADK ToolDef format. For full MCP bridge features (rate limiting,
|
|
2317
|
+
* circuit breaking, output sanitization), use @aizonaai/mcp-bridge directly.
|
|
2318
|
+
*/
|
|
2319
|
+
declare function mcpServerTools(config: MCPServerConfig): Promise<ToolDef[]>;
|
|
2320
|
+
/**
|
|
2321
|
+
* Discover tool metadata from an MCP server without creating ToolDefs.
|
|
2322
|
+
* Useful for browsing available tools before selecting specific ones.
|
|
2323
|
+
*/
|
|
2324
|
+
declare function discoverMCPTools(config: MCPServerConfig): Promise<MCPToolInfo[]>;
|
|
2325
|
+
/**
|
|
2326
|
+
* Load only specific named tools from an MCP server.
|
|
2327
|
+
* Combines discovery with name-based selection in one call.
|
|
2328
|
+
*/
|
|
2329
|
+
declare function mcpSelectTools(config: MCPServerConfig, toolNames: string[]): Promise<ToolDef[]>;
|
|
2330
|
+
/**
|
|
2331
|
+
* MCPServerConnector — lightweight connector for MCP servers.
|
|
2332
|
+
* Handles discovery and invocation.
|
|
2333
|
+
*/
|
|
2334
|
+
declare class MCPServerConnector {
|
|
2335
|
+
private config;
|
|
2336
|
+
private connection;
|
|
2337
|
+
constructor(config: MCPServerConfig);
|
|
2338
|
+
/** Discover tools from the MCP server */
|
|
2339
|
+
discover(): Promise<MCPToolInfo[]>;
|
|
2340
|
+
/** Convert an MCP tool to an ADK ToolDef */
|
|
2341
|
+
toToolDef(tool: MCPToolInfo): ToolDef;
|
|
2342
|
+
/** Discover tool metadata without creating ToolDefs */
|
|
2343
|
+
discoverMetadata(): Promise<MCPToolInfo[]>;
|
|
2344
|
+
/** Create ToolDefs for only the named subset of discovered tools */
|
|
2345
|
+
selectTools(discovered: MCPToolInfo[], names: string[]): ToolDef[];
|
|
2346
|
+
/** Invoke a tool on the MCP server */
|
|
2347
|
+
invokeTool(toolName: string, input: unknown): Promise<unknown>;
|
|
2348
|
+
/** Discover tools via HTTP (SSE or streamable-http) */
|
|
2349
|
+
private discoverViaHttp;
|
|
2350
|
+
/** Invoke a tool via HTTP */
|
|
2351
|
+
private invokeViaHttp;
|
|
2352
|
+
/** Discover tools via stdio (placeholder — requires child_process) */
|
|
2353
|
+
private discoverViaStdio;
|
|
2354
|
+
/** Invoke tool via stdio (placeholder) */
|
|
2355
|
+
private invokeViaStdio;
|
|
2356
|
+
/** Build auth headers */
|
|
2357
|
+
private buildHeaders;
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
/** Voice options */
|
|
2361
|
+
type VoiceName = "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer";
|
|
2362
|
+
/** Audio format */
|
|
2363
|
+
type AudioFormat = "pcm16" | "opus";
|
|
2364
|
+
/** Voice activity detection mode */
|
|
2365
|
+
type VADMode = "server" | "client" | "off";
|
|
2366
|
+
/** Realtime provider */
|
|
2367
|
+
type RealtimeProvider = "openai";
|
|
2368
|
+
/** Realtime agent configuration */
|
|
2369
|
+
interface RealtimeAgentConfig extends AgentConfig {
|
|
2370
|
+
/** Voice to use */
|
|
2371
|
+
voice?: VoiceName;
|
|
2372
|
+
/** Audio format */
|
|
2373
|
+
audioFormat?: AudioFormat;
|
|
2374
|
+
/** VAD mode */
|
|
2375
|
+
vadMode?: VADMode;
|
|
2376
|
+
/** Realtime provider */
|
|
2377
|
+
realtimeProvider?: RealtimeProvider;
|
|
2378
|
+
/** Provider API key */
|
|
2379
|
+
apiKey?: string;
|
|
2380
|
+
/** WebSocket URL override */
|
|
2381
|
+
wsUrl?: string;
|
|
2382
|
+
}
|
|
2383
|
+
/** Realtime connection state */
|
|
2384
|
+
type RealtimeState = "disconnected" | "connecting" | "connected" | "error";
|
|
2385
|
+
/** Realtime event types */
|
|
2386
|
+
type RealtimeEvent = {
|
|
2387
|
+
type: "state_change";
|
|
2388
|
+
state: RealtimeState;
|
|
2389
|
+
} | {
|
|
2390
|
+
type: "audio";
|
|
2391
|
+
buffer: ArrayBuffer;
|
|
2392
|
+
} | {
|
|
2393
|
+
type: "text";
|
|
2394
|
+
content: string;
|
|
2395
|
+
final: boolean;
|
|
2396
|
+
} | {
|
|
2397
|
+
type: "tool_call";
|
|
2398
|
+
toolName: string;
|
|
2399
|
+
input: unknown;
|
|
2400
|
+
callId: string;
|
|
2401
|
+
} | {
|
|
2402
|
+
type: "error";
|
|
2403
|
+
message: string;
|
|
2404
|
+
};
|
|
2405
|
+
/**
|
|
2406
|
+
* RealtimeAgent — Voice-enabled agent using WebSocket realtime APIs.
|
|
2407
|
+
*
|
|
2408
|
+
* Currently supports OpenAI Realtime API.
|
|
2409
|
+
* Connect, send audio, and receive audio/text responses.
|
|
2410
|
+
*/
|
|
2411
|
+
declare class RealtimeAgent {
|
|
2412
|
+
readonly config: RealtimeAgentConfig;
|
|
2413
|
+
private state;
|
|
2414
|
+
private ws;
|
|
2415
|
+
private audioHandlers;
|
|
2416
|
+
private textHandlers;
|
|
2417
|
+
private toolCallHandlers;
|
|
2418
|
+
private eventHandlers;
|
|
2419
|
+
constructor(config: RealtimeAgentConfig);
|
|
2420
|
+
/** Get current connection state */
|
|
2421
|
+
getState(): RealtimeState;
|
|
2422
|
+
/** Connect to the realtime provider */
|
|
2423
|
+
connect(): Promise<void>;
|
|
2424
|
+
/** Disconnect from the realtime provider */
|
|
2425
|
+
disconnect(): Promise<void>;
|
|
2426
|
+
/** Send an audio buffer to the realtime session */
|
|
2427
|
+
sendAudio(buffer: ArrayBuffer): void;
|
|
2428
|
+
/** Send a text message to the realtime session */
|
|
2429
|
+
sendText(text: string): void;
|
|
2430
|
+
/** Register handler for audio output */
|
|
2431
|
+
onAudio(handler: (buffer: ArrayBuffer) => void): () => void;
|
|
2432
|
+
/** Register handler for text output */
|
|
2433
|
+
onText(handler: (text: string) => void): () => void;
|
|
2434
|
+
/** Register handler for tool calls */
|
|
2435
|
+
onToolCall(handler: (toolName: string, input: unknown) => Promise<unknown>): () => void;
|
|
2436
|
+
/** Register handler for all events */
|
|
2437
|
+
onEvent(handler: (event: RealtimeEvent) => void): () => void;
|
|
2438
|
+
private setState;
|
|
2439
|
+
private emitEvent;
|
|
2440
|
+
private sendSessionConfig;
|
|
2441
|
+
private handleMessage;
|
|
2442
|
+
private sendToolResult;
|
|
2443
|
+
private getProviderUrl;
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
/** Audio buffer configuration */
|
|
2447
|
+
interface AudioBufferConfig {
|
|
2448
|
+
/** Sample rate in Hz (default: 24000) */
|
|
2449
|
+
sampleRate?: number;
|
|
2450
|
+
/** Number of channels (default: 1, mono) */
|
|
2451
|
+
channels?: number;
|
|
2452
|
+
/** Buffer size in samples (default: 4800, 200ms at 24kHz) */
|
|
2453
|
+
bufferSize?: number;
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* AudioStreamBuffer — Manages a ring buffer for PCM16 audio data.
|
|
2457
|
+
* Used for smoothing audio playback from realtime streams.
|
|
2458
|
+
*/
|
|
2459
|
+
declare class AudioStreamBuffer {
|
|
2460
|
+
private buffer;
|
|
2461
|
+
private writePos;
|
|
2462
|
+
private readPos;
|
|
2463
|
+
private count;
|
|
2464
|
+
readonly sampleRate: number;
|
|
2465
|
+
readonly channels: number;
|
|
2466
|
+
constructor(config?: AudioBufferConfig);
|
|
2467
|
+
/** Write PCM16 samples to the buffer */
|
|
2468
|
+
write(samples: Int16Array): number;
|
|
2469
|
+
/** Read PCM16 samples from the buffer */
|
|
2470
|
+
read(numSamples: number): Int16Array;
|
|
2471
|
+
/** Number of samples available to read */
|
|
2472
|
+
get available(): number;
|
|
2473
|
+
/** Whether the buffer is empty */
|
|
2474
|
+
get isEmpty(): boolean;
|
|
2475
|
+
/** Whether the buffer is full */
|
|
2476
|
+
get isFull(): boolean;
|
|
2477
|
+
/** Duration of buffered audio in milliseconds */
|
|
2478
|
+
get durationMs(): number;
|
|
2479
|
+
/** Clear the buffer */
|
|
2480
|
+
clear(): void;
|
|
2481
|
+
}
|
|
2482
|
+
/**
|
|
2483
|
+
* Convert an ArrayBuffer (raw bytes) to Int16Array (PCM16).
|
|
2484
|
+
* Assumes little-endian 16-bit signed integer format.
|
|
2485
|
+
*/
|
|
2486
|
+
declare function pcm16FromArrayBuffer(buffer: ArrayBuffer): Int16Array;
|
|
2487
|
+
/**
|
|
2488
|
+
* Convert Int16Array (PCM16) to ArrayBuffer (raw bytes).
|
|
2489
|
+
*/
|
|
2490
|
+
declare function pcm16ToArrayBuffer(samples: Int16Array): ArrayBuffer;
|
|
2491
|
+
/**
|
|
2492
|
+
* Calculate RMS volume level from PCM16 samples.
|
|
2493
|
+
* Returns a value between 0.0 (silence) and 1.0 (max volume).
|
|
2494
|
+
*/
|
|
2495
|
+
declare function calculateVolume(samples: Int16Array): number;
|
|
2496
|
+
|
|
2497
|
+
/** A single tool definition within a skill manifest */
|
|
2498
|
+
interface SkillToolEntry {
|
|
2499
|
+
/** Tool name */
|
|
2500
|
+
name: string;
|
|
2501
|
+
/** Tool description */
|
|
2502
|
+
description: string;
|
|
2503
|
+
/** JSON Schema for tool input */
|
|
2504
|
+
inputSchema: Record<string, unknown>;
|
|
2505
|
+
/** JSON Schema for tool output (optional) */
|
|
2506
|
+
outputSchema?: Record<string, unknown>;
|
|
2507
|
+
}
|
|
2508
|
+
/** Skill manifest — the core portable definition */
|
|
2509
|
+
interface SkillManifest {
|
|
2510
|
+
/** Unique skill name (scoped to community) */
|
|
2511
|
+
name: string;
|
|
2512
|
+
/** Semver version string */
|
|
2513
|
+
version: string;
|
|
2514
|
+
/** Human-readable description */
|
|
2515
|
+
description: string;
|
|
2516
|
+
/** Category for marketplace browsing */
|
|
2517
|
+
category?: string;
|
|
2518
|
+
/** Tags for search/filter */
|
|
2519
|
+
tags?: string[];
|
|
2520
|
+
/** Tool definitions included in this skill */
|
|
2521
|
+
tools: SkillToolEntry[];
|
|
2522
|
+
/** Optional agent configuration hints (model, temperature, etc.) */
|
|
2523
|
+
agentConfig?: Record<string, unknown>;
|
|
2524
|
+
/** Other skills this skill depends on */
|
|
2525
|
+
dependencies?: string[];
|
|
2526
|
+
/** Arbitrary metadata */
|
|
2527
|
+
metadata?: Record<string, unknown>;
|
|
2528
|
+
}
|
|
2529
|
+
/** Zod schema for full skill manifest validation */
|
|
2530
|
+
declare const SkillManifestSchema: z.ZodObject<{
|
|
2531
|
+
name: z.ZodString;
|
|
2532
|
+
version: z.ZodString;
|
|
2533
|
+
description: z.ZodString;
|
|
2534
|
+
category: z.ZodOptional<z.ZodString>;
|
|
2535
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
2536
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
2537
|
+
name: z.ZodString;
|
|
2538
|
+
description: z.ZodString;
|
|
2539
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
2540
|
+
outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2541
|
+
}, "strip", z.ZodTypeAny, {
|
|
2542
|
+
name: string;
|
|
2543
|
+
description: string;
|
|
2544
|
+
inputSchema: Record<string, unknown>;
|
|
2545
|
+
outputSchema?: Record<string, unknown> | undefined;
|
|
2546
|
+
}, {
|
|
2547
|
+
name: string;
|
|
2548
|
+
description: string;
|
|
2549
|
+
inputSchema: Record<string, unknown>;
|
|
2550
|
+
outputSchema?: Record<string, unknown> | undefined;
|
|
2551
|
+
}>, "many">;
|
|
2552
|
+
agentConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2553
|
+
dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
2554
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2555
|
+
}, "strip", z.ZodTypeAny, {
|
|
2556
|
+
name: string;
|
|
2557
|
+
tools: {
|
|
2558
|
+
name: string;
|
|
2559
|
+
description: string;
|
|
2560
|
+
inputSchema: Record<string, unknown>;
|
|
2561
|
+
outputSchema?: Record<string, unknown> | undefined;
|
|
2562
|
+
}[];
|
|
2563
|
+
description: string;
|
|
2564
|
+
version: string;
|
|
2565
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2566
|
+
category?: string | undefined;
|
|
2567
|
+
tags?: string[] | undefined;
|
|
2568
|
+
agentConfig?: Record<string, unknown> | undefined;
|
|
2569
|
+
dependencies?: string[] | undefined;
|
|
2570
|
+
}, {
|
|
2571
|
+
name: string;
|
|
2572
|
+
tools: {
|
|
2573
|
+
name: string;
|
|
2574
|
+
description: string;
|
|
2575
|
+
inputSchema: Record<string, unknown>;
|
|
2576
|
+
outputSchema?: Record<string, unknown> | undefined;
|
|
2577
|
+
}[];
|
|
2578
|
+
description: string;
|
|
2579
|
+
version: string;
|
|
2580
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2581
|
+
category?: string | undefined;
|
|
2582
|
+
tags?: string[] | undefined;
|
|
2583
|
+
agentConfig?: Record<string, unknown> | undefined;
|
|
2584
|
+
dependencies?: string[] | undefined;
|
|
2585
|
+
}>;
|
|
2586
|
+
/**
|
|
2587
|
+
* Define and validate a skill manifest.
|
|
2588
|
+
* Throws if the manifest is invalid.
|
|
2589
|
+
*/
|
|
2590
|
+
declare function defineSkill(manifest: SkillManifest): SkillManifest;
|
|
2591
|
+
|
|
2592
|
+
/** Result of loading a skill */
|
|
2593
|
+
interface LoadedSkill {
|
|
2594
|
+
/** Tool definitions ready to use in an agent */
|
|
2595
|
+
tools: ToolDef[];
|
|
2596
|
+
/** Agent configuration hints from the manifest */
|
|
2597
|
+
agentConfig?: Record<string, unknown>;
|
|
2598
|
+
/** Original manifest metadata */
|
|
2599
|
+
metadata?: Record<string, unknown>;
|
|
2600
|
+
}
|
|
2601
|
+
/**
|
|
2602
|
+
* Load a skill manifest and produce ToolDef instances.
|
|
2603
|
+
*
|
|
2604
|
+
* @param manifest - A validated SkillManifest
|
|
2605
|
+
* @param toolImplementations - Optional map of tool name → execute function overrides
|
|
2606
|
+
* @returns LoadedSkill with ToolDef[] and agentConfig
|
|
2607
|
+
*/
|
|
2608
|
+
declare function loadSkill(manifest: SkillManifest, toolImplementations?: Record<string, (input: unknown, ctx: ToolContext) => Promise<unknown>>): LoadedSkill;
|
|
2609
|
+
/**
|
|
2610
|
+
* Merge tools from multiple loaded skills into a single array.
|
|
2611
|
+
* Throws if tool name collisions are detected across skills.
|
|
2612
|
+
*/
|
|
2613
|
+
declare function mergeSkillTools(...loadedSkills: LoadedSkill[]): ToolDef[];
|
|
2614
|
+
|
|
2615
|
+
/** Check if content is multi-modal (ContentPart[]) */
|
|
2616
|
+
declare function isMultiModalContent(content: Content): content is ContentPart[];
|
|
2617
|
+
/** Check if a content part is a TextPart */
|
|
2618
|
+
declare function isTextPart(part: ContentPart): part is TextPart;
|
|
2619
|
+
/** Check if a content part is an ImagePart */
|
|
2620
|
+
declare function isImagePart(part: ContentPart): part is ImagePart;
|
|
2621
|
+
/** Check if a content part is an AudioPart */
|
|
2622
|
+
declare function isAudioPart(part: ContentPart): part is AudioPart;
|
|
2623
|
+
/** Check if a content part is a VideoPart */
|
|
2624
|
+
declare function isVideoPart(part: ContentPart): part is VideoPart;
|
|
2625
|
+
/** Check if a content part is a UIArtifactPart */
|
|
2626
|
+
declare function isUIArtifactPart(part: ContentPart): part is UIArtifactPart;
|
|
2627
|
+
/**
|
|
2628
|
+
* Extract text from Content. For strings, returns as-is.
|
|
2629
|
+
* For ContentPart[], concatenates all TextPart.text values.
|
|
2630
|
+
* Non-text parts are represented as markers.
|
|
2631
|
+
*/
|
|
2632
|
+
declare function contentToString(content: Content): string;
|
|
2633
|
+
/** Alias for contentToString — backward compat with plan naming */
|
|
2634
|
+
declare const extractText: typeof contentToString;
|
|
2635
|
+
/**
|
|
2636
|
+
* Normalize content to ContentPart[].
|
|
2637
|
+
* Strings become a single TextPart.
|
|
2638
|
+
*/
|
|
2639
|
+
declare function contentToParts(content: Content): ContentPart[];
|
|
2640
|
+
/**
|
|
2641
|
+
* Count media parts by type.
|
|
2642
|
+
*/
|
|
2643
|
+
declare function countMediaParts(content: Content): {
|
|
2644
|
+
text: number;
|
|
2645
|
+
image: number;
|
|
2646
|
+
audio: number;
|
|
2647
|
+
video: number;
|
|
2648
|
+
uiArtifact: number;
|
|
2649
|
+
};
|
|
2650
|
+
|
|
2651
|
+
/**
|
|
2652
|
+
* Create the built-in `create_artifact` tool.
|
|
2653
|
+
* When an agent calls this tool, it creates a UIArtifactPart
|
|
2654
|
+
* and optionally persists it to an ArtifactStore.
|
|
2655
|
+
*/
|
|
2656
|
+
declare function createArtifactTool(store?: ArtifactStore): ToolDef;
|
|
2657
|
+
|
|
2658
|
+
/** Status of a progress feature */
|
|
2659
|
+
type FeatureStatus = "pending" | "in_progress" | "passed" | "failed";
|
|
2660
|
+
/** A tracked feature in the progress list */
|
|
2661
|
+
interface ProgressFeature {
|
|
2662
|
+
id: string;
|
|
2663
|
+
name: string;
|
|
2664
|
+
status: FeatureStatus;
|
|
2665
|
+
verifiedAt?: number;
|
|
2666
|
+
}
|
|
2667
|
+
/**
|
|
2668
|
+
* ProgressTracker — tracks feature-level progress for long-running agent sessions.
|
|
2669
|
+
* Serializable to/from JSON for cross-session persistence.
|
|
2670
|
+
*/
|
|
2671
|
+
declare class ProgressTracker {
|
|
2672
|
+
private features;
|
|
2673
|
+
/** Add a feature to track */
|
|
2674
|
+
addFeature(id: string, name: string): void;
|
|
2675
|
+
/** Add multiple features at once */
|
|
2676
|
+
addFeatures(features: Array<{
|
|
2677
|
+
id: string;
|
|
2678
|
+
name: string;
|
|
2679
|
+
}>): void;
|
|
2680
|
+
/** Update the status of a feature */
|
|
2681
|
+
updateStatus(id: string, status: FeatureStatus): boolean;
|
|
2682
|
+
/** Get the next pending feature */
|
|
2683
|
+
getNextPending(): ProgressFeature | undefined;
|
|
2684
|
+
/** Get a feature by ID */
|
|
2685
|
+
getFeature(id: string): ProgressFeature | undefined;
|
|
2686
|
+
/** Get all features */
|
|
2687
|
+
getAllFeatures(): ProgressFeature[];
|
|
2688
|
+
/** Get a summary of progress */
|
|
2689
|
+
getSummary(): {
|
|
2690
|
+
total: number;
|
|
2691
|
+
pending: number;
|
|
2692
|
+
inProgress: number;
|
|
2693
|
+
passed: number;
|
|
2694
|
+
failed: number;
|
|
2695
|
+
percentComplete: number;
|
|
2696
|
+
};
|
|
2697
|
+
/** Serialize to JSON for persistence */
|
|
2698
|
+
toJSON(): ProgressFeature[];
|
|
2699
|
+
/** Restore from serialized state */
|
|
2700
|
+
static fromJSON(data: ProgressFeature[]): ProgressTracker;
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
/** Predefined note sections */
|
|
2704
|
+
type NoteSection = "findings" | "decisions" | "todo" | "questions";
|
|
2705
|
+
/** A single note entry */
|
|
2706
|
+
interface NoteEntry {
|
|
2707
|
+
section: NoteSection;
|
|
2708
|
+
content: string;
|
|
2709
|
+
createdAt: number;
|
|
2710
|
+
}
|
|
2711
|
+
/**
|
|
2712
|
+
* NotesStore — structured note-taking for agents across sessions.
|
|
2713
|
+
* Notes are organized by section (Findings, Decisions, TODO, Questions).
|
|
2714
|
+
* Serializable to/from JSON for cross-session persistence.
|
|
2715
|
+
*/
|
|
2716
|
+
declare class NotesStore {
|
|
2717
|
+
private notes;
|
|
2718
|
+
/** Add a note to a section */
|
|
2719
|
+
addNote(section: NoteSection, content: string): void;
|
|
2720
|
+
/** Get notes from a specific section or all notes */
|
|
2721
|
+
getNotes(section?: NoteSection): NoteEntry[];
|
|
2722
|
+
/** Get note count per section */
|
|
2723
|
+
getCounts(): Record<NoteSection, number>;
|
|
2724
|
+
/** Clear all notes or notes in a specific section */
|
|
2725
|
+
clear(section?: NoteSection): void;
|
|
2726
|
+
/** Serialize to JSON for persistence */
|
|
2727
|
+
toJSON(): NoteEntry[];
|
|
2728
|
+
/** Restore from serialized state */
|
|
2729
|
+
static fromJSON(data: NoteEntry[]): NotesStore;
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
interface ProgressInput {
|
|
2733
|
+
action: "add" | "update" | "get_next" | "summary";
|
|
2734
|
+
featureId?: string;
|
|
2735
|
+
featureName?: string;
|
|
2736
|
+
status?: FeatureStatus;
|
|
2737
|
+
}
|
|
2738
|
+
declare function createProgressTool(tracker: ProgressTracker): ToolDef<ProgressInput>;
|
|
2739
|
+
|
|
2740
|
+
interface WriteNoteInput {
|
|
2741
|
+
section: NoteSection;
|
|
2742
|
+
content: string;
|
|
2743
|
+
}
|
|
2744
|
+
interface ReadNotesInput {
|
|
2745
|
+
section?: NoteSection;
|
|
2746
|
+
}
|
|
2747
|
+
declare function createWriteNoteTool(store: NotesStore): ToolDef<WriteNoteInput>;
|
|
2748
|
+
declare function createReadNotesTool(store: NotesStore): ToolDef<ReadNotesInput>;
|
|
2749
|
+
|
|
2750
|
+
/** Memory classification types (mirrors Prisma MemoryType enum) */
|
|
2751
|
+
type MemoryType = "CONVERSATION" | "FACT" | "PREFERENCE" | "SKILL_LEARNED";
|
|
2752
|
+
/** A stored memory entry */
|
|
2753
|
+
interface MemoryEntry {
|
|
2754
|
+
id: string;
|
|
2755
|
+
agentId: string;
|
|
2756
|
+
sessionId?: string;
|
|
2757
|
+
content: string;
|
|
2758
|
+
memoryType: MemoryType;
|
|
2759
|
+
importance: number;
|
|
2760
|
+
accessCount: number;
|
|
2761
|
+
lastAccessedAt?: Date;
|
|
2762
|
+
expiresAt?: Date;
|
|
2763
|
+
metadata?: Record<string, unknown>;
|
|
2764
|
+
createdAt: Date;
|
|
2765
|
+
}
|
|
2766
|
+
/** A memory entry with a relevance score from search */
|
|
2767
|
+
interface MemorySearchResult extends MemoryEntry {
|
|
2768
|
+
/** Cosine similarity score (0-1, higher = more relevant) */
|
|
2769
|
+
score: number;
|
|
2770
|
+
}
|
|
2771
|
+
/**
|
|
2772
|
+
* Memory backend interface — pluggable storage for agent memories.
|
|
2773
|
+
* Implementations must handle embedding storage and vector similarity search.
|
|
2774
|
+
*/
|
|
2775
|
+
interface MemoryBackend {
|
|
2776
|
+
/** Store a new memory with content and type */
|
|
2777
|
+
store(agentId: string, content: string, type: MemoryType, metadata?: Record<string, unknown>): Promise<MemoryEntry>;
|
|
2778
|
+
/** Search memories by semantic similarity to a query */
|
|
2779
|
+
search(agentId: string, query: string, limit?: number, threshold?: number): Promise<MemorySearchResult[]>;
|
|
2780
|
+
/** Recall a specific memory by id, incrementing access count */
|
|
2781
|
+
recall(agentId: string, memoryId: string): Promise<MemoryEntry | null>;
|
|
2782
|
+
/** Forget (delete) a specific memory */
|
|
2783
|
+
forget(agentId: string, memoryId: string): Promise<void>;
|
|
2784
|
+
/** Get the most recent memories for an agent */
|
|
2785
|
+
getRecent(agentId: string, limit: number): Promise<MemoryEntry[]>;
|
|
2786
|
+
/** Decay old memory importance scores; returns count of decayed memories */
|
|
2787
|
+
decay(agentId: string): Promise<number>;
|
|
2788
|
+
}
|
|
2789
|
+
/** Configuration for the embedding service */
|
|
2790
|
+
interface EmbeddingConfig {
|
|
2791
|
+
/** Embedding provider (e.g., "openai") */
|
|
2792
|
+
provider?: string;
|
|
2793
|
+
/** Embedding model name (e.g., "text-embedding-3-small") */
|
|
2794
|
+
model?: string;
|
|
2795
|
+
/** API key for the embedding provider */
|
|
2796
|
+
apiKey?: string;
|
|
2797
|
+
/** Base URL for the embedding API (for custom endpoints) */
|
|
2798
|
+
baseUrl?: string;
|
|
2799
|
+
/** Embedding dimensions (default depends on model) */
|
|
2800
|
+
dimensions?: number;
|
|
2801
|
+
}
|
|
2802
|
+
/** Raw embedding API response shape */
|
|
2803
|
+
interface EmbedApiResponse {
|
|
2804
|
+
embeddings: number[][];
|
|
2805
|
+
model: string;
|
|
2806
|
+
usage: {
|
|
2807
|
+
totalTokens: number;
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
declare class EmbeddingService {
|
|
2812
|
+
private readonly provider;
|
|
2813
|
+
private readonly model;
|
|
2814
|
+
private readonly apiKey?;
|
|
2815
|
+
private readonly baseUrl;
|
|
2816
|
+
private readonly dimensions;
|
|
2817
|
+
constructor(config?: EmbeddingConfig);
|
|
2818
|
+
/**
|
|
2819
|
+
* Generate embeddings for one or more texts.
|
|
2820
|
+
* If no API key is configured, falls back to hash-based pseudo-embeddings.
|
|
2821
|
+
*/
|
|
2822
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
2823
|
+
/**
|
|
2824
|
+
* Generate a single embedding for a text string.
|
|
2825
|
+
* Convenience wrapper around embed().
|
|
2826
|
+
*/
|
|
2827
|
+
embedSingle(text: string): Promise<number[]>;
|
|
2828
|
+
/** Whether the service has a real embedding provider configured */
|
|
2829
|
+
get isConfigured(): boolean;
|
|
2830
|
+
private embedOpenAI;
|
|
2831
|
+
/**
|
|
2832
|
+
* Deterministic hash-based pseudo-embedding for testing.
|
|
2833
|
+
* Produces a normalized vector of the configured dimension.
|
|
2834
|
+
* NOT suitable for production semantic search — only for
|
|
2835
|
+
* development/testing when no embedding API is available.
|
|
2836
|
+
*/
|
|
2837
|
+
private hashEmbed;
|
|
2838
|
+
/**
|
|
2839
|
+
* Create an EmbedApiResponse from raw embedding results.
|
|
2840
|
+
* Useful for callers that need the full response shape.
|
|
2841
|
+
*/
|
|
2842
|
+
embedWithResponse(texts: string[]): Promise<EmbedApiResponse>;
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
/** Configuration for the MemoryManager */
|
|
2846
|
+
interface MemoryManagerConfig {
|
|
2847
|
+
/** Default search result limit */
|
|
2848
|
+
defaultSearchLimit?: number;
|
|
2849
|
+
/** Default similarity threshold (0-1) for search results */
|
|
2850
|
+
defaultThreshold?: number;
|
|
2851
|
+
/** Maximum number of memories to inject into context */
|
|
2852
|
+
maxContextMemories?: number;
|
|
2853
|
+
/** Whether to automatically extract and store facts from conversations */
|
|
2854
|
+
autoExtract?: boolean;
|
|
2855
|
+
}
|
|
2856
|
+
declare class MemoryManager {
|
|
2857
|
+
private readonly backend;
|
|
2858
|
+
private readonly embedding;
|
|
2859
|
+
private readonly config;
|
|
2860
|
+
constructor(backend: MemoryBackend, embeddingService: EmbeddingService, config?: MemoryManagerConfig);
|
|
2861
|
+
/**
|
|
2862
|
+
* Store a new memory for an agent.
|
|
2863
|
+
* Embeds the content and persists it via the backend.
|
|
2864
|
+
*/
|
|
2865
|
+
storeMemory(agentId: string, content: string, type: MemoryType, metadata?: Record<string, unknown>): Promise<MemoryEntry>;
|
|
2866
|
+
/**
|
|
2867
|
+
* Search agent memories by semantic similarity.
|
|
2868
|
+
*/
|
|
2869
|
+
searchMemories(agentId: string, query: string, limit?: number, threshold?: number): Promise<MemorySearchResult[]>;
|
|
2870
|
+
/**
|
|
2871
|
+
* Recall a specific memory by id.
|
|
2872
|
+
*/
|
|
2873
|
+
recallMemory(agentId: string, memoryId: string): Promise<MemoryEntry | null>;
|
|
2874
|
+
/**
|
|
2875
|
+
* Forget (delete) a specific memory.
|
|
2876
|
+
*/
|
|
2877
|
+
forgetMemory(agentId: string, memoryId: string): Promise<void>;
|
|
2878
|
+
/**
|
|
2879
|
+
* Get recent memories for an agent.
|
|
2880
|
+
*/
|
|
2881
|
+
getRecentMemories(agentId: string, limit?: number): Promise<MemoryEntry[]>;
|
|
2882
|
+
/**
|
|
2883
|
+
* Search for memories relevant to the current conversation messages.
|
|
2884
|
+
* Combines the last few messages into a query and searches for matches.
|
|
2885
|
+
* Returns the top N most relevant memories for context injection.
|
|
2886
|
+
*/
|
|
2887
|
+
getContextMemories(agentId: string, currentMessages: string[]): Promise<MemorySearchResult[]>;
|
|
2888
|
+
/**
|
|
2889
|
+
* Format memory search results into a string suitable for
|
|
2890
|
+
* injection into a system or user prompt.
|
|
2891
|
+
*/
|
|
2892
|
+
formatMemoriesForPrompt(memories: MemorySearchResult[]): string;
|
|
2893
|
+
/**
|
|
2894
|
+
* Parse a conversation summary and extract key facts, preferences,
|
|
2895
|
+
* and skills learned, storing each as a separate memory.
|
|
2896
|
+
*
|
|
2897
|
+
* The extraction uses simple heuristics to classify content:
|
|
2898
|
+
* - Lines starting with "prefers" or "likes" / "dislikes" -> PREFERENCE
|
|
2899
|
+
* - Lines starting with "learned" or "can now" -> SKILL_LEARNED
|
|
2900
|
+
* - Lines that are questions or conversation flow -> CONVERSATION
|
|
2901
|
+
* - Everything else -> FACT
|
|
2902
|
+
*
|
|
2903
|
+
* Returns the list of newly created memory entries.
|
|
2904
|
+
*/
|
|
2905
|
+
extractAndStore(agentId: string, conversationSummary: string): Promise<MemoryEntry[]>;
|
|
2906
|
+
/**
|
|
2907
|
+
* Run memory importance decay for an agent.
|
|
2908
|
+
* Reduces importance scores for memories that haven't been
|
|
2909
|
+
* accessed recently, allowing less relevant memories to fade.
|
|
2910
|
+
* Returns the number of memories affected.
|
|
2911
|
+
*/
|
|
2912
|
+
runDecay(agentId: string): Promise<number>;
|
|
2913
|
+
/** Classify a line of text into a memory type using heuristics */
|
|
2914
|
+
private classifyLine;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
/**
|
|
2918
|
+
* Generic database client interface — compatible with Prisma's $queryRaw
|
|
2919
|
+
* but does not directly import from @aizona/db or @prisma/client.
|
|
2920
|
+
*/
|
|
2921
|
+
interface PgVectorDatabaseClient {
|
|
2922
|
+
$queryRaw(sql: TemplateStringsArray, ...values: unknown[]): Promise<unknown[]>;
|
|
2923
|
+
}
|
|
2924
|
+
declare class PgVectorMemoryBackend implements MemoryBackend {
|
|
2925
|
+
private readonly db;
|
|
2926
|
+
private readonly embedding;
|
|
2927
|
+
private readonly decayFactor;
|
|
2928
|
+
private readonly decayStaleDays;
|
|
2929
|
+
constructor(db: PgVectorDatabaseClient, embeddingService: EmbeddingService, options?: {
|
|
2930
|
+
decayFactor?: number;
|
|
2931
|
+
decayStaleDays?: number;
|
|
2932
|
+
});
|
|
2933
|
+
store(agentId: string, content: string, type: MemoryType, metadata?: Record<string, unknown>): Promise<MemoryEntry>;
|
|
2934
|
+
search(agentId: string, query: string, limit?: number, threshold?: number): Promise<MemorySearchResult[]>;
|
|
2935
|
+
recall(agentId: string, memoryId: string): Promise<MemoryEntry | null>;
|
|
2936
|
+
forget(agentId: string, memoryId: string): Promise<void>;
|
|
2937
|
+
getRecent(agentId: string, limit: number): Promise<MemoryEntry[]>;
|
|
2938
|
+
decay(agentId: string): Promise<number>;
|
|
2939
|
+
private rowToEntry;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
type SharedMemoryScope = "agent" | "team" | "workspace";
|
|
2943
|
+
interface SharedMemoryNamespace {
|
|
2944
|
+
namespace: string;
|
|
2945
|
+
scope: SharedMemoryScope;
|
|
2946
|
+
scopeId: string;
|
|
2947
|
+
}
|
|
2948
|
+
interface SharedMemoryEntry {
|
|
2949
|
+
key: string;
|
|
2950
|
+
value: unknown;
|
|
2951
|
+
createdAt: Date;
|
|
2952
|
+
updatedAt: Date;
|
|
2953
|
+
expiresAt?: Date;
|
|
2954
|
+
}
|
|
2955
|
+
interface SharedMemoryStore {
|
|
2956
|
+
get(ns: SharedMemoryNamespace, key: string): Promise<unknown | null>;
|
|
2957
|
+
set(ns: SharedMemoryNamespace, key: string, value: unknown, ttlMs?: number): Promise<void>;
|
|
2958
|
+
delete(ns: SharedMemoryNamespace, key: string): Promise<void>;
|
|
2959
|
+
list(ns: SharedMemoryNamespace, prefix?: string): Promise<string[]>;
|
|
2960
|
+
clear(ns: SharedMemoryNamespace): Promise<void>;
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
declare class InMemorySharedStore implements SharedMemoryStore {
|
|
2964
|
+
private store;
|
|
2965
|
+
private makeKey;
|
|
2966
|
+
get(ns: SharedMemoryNamespace, key: string): Promise<unknown | null>;
|
|
2967
|
+
set(ns: SharedMemoryNamespace, key: string, value: unknown, ttlMs?: number): Promise<void>;
|
|
2968
|
+
delete(ns: SharedMemoryNamespace, key: string): Promise<void>;
|
|
2969
|
+
list(ns: SharedMemoryNamespace, prefix?: string): Promise<string[]>;
|
|
2970
|
+
clear(ns: SharedMemoryNamespace): Promise<void>;
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
interface DecayPolicy {
|
|
2974
|
+
/** Maximum age in milliseconds before a memory entry decays */
|
|
2975
|
+
maxAgeMs: number;
|
|
2976
|
+
/** How often (ms) to run the decay sweep */
|
|
2977
|
+
checkIntervalMs: number;
|
|
2978
|
+
/** What to do with decayed entries */
|
|
2979
|
+
onDecay: "delete" | "archive";
|
|
2980
|
+
}
|
|
2981
|
+
declare class MemoryDecayManager {
|
|
2982
|
+
private store;
|
|
2983
|
+
private namespace;
|
|
2984
|
+
private policy;
|
|
2985
|
+
private timer;
|
|
2986
|
+
constructor(store: {
|
|
2987
|
+
delete(ns: unknown, key: string): Promise<void>;
|
|
2988
|
+
list(ns: unknown, prefix?: string): Promise<string[]>;
|
|
2989
|
+
}, namespace: unknown, policy: DecayPolicy);
|
|
2990
|
+
/** Start the periodic decay sweep. */
|
|
2991
|
+
start(): void;
|
|
2992
|
+
/** Stop the periodic decay sweep. */
|
|
2993
|
+
stop(): void;
|
|
2994
|
+
/**
|
|
2995
|
+
* Run a single decay sweep.
|
|
2996
|
+
*
|
|
2997
|
+
* For in-memory stores, TTL-based expiry handles cleanup automatically
|
|
2998
|
+
* during reads. This method is mainly useful for persistent stores
|
|
2999
|
+
* where we need explicit cleanup of old entries.
|
|
3000
|
+
*
|
|
3001
|
+
* Returns the number of entries that were decayed.
|
|
3002
|
+
*/
|
|
3003
|
+
runDecay(): Promise<number>;
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
/** A single evaluation test case. */
|
|
3007
|
+
interface EvalCase {
|
|
3008
|
+
/** Human-readable name for this case. */
|
|
3009
|
+
name: string;
|
|
3010
|
+
/** Input to send to the agent/executor. */
|
|
3011
|
+
input: string;
|
|
3012
|
+
/** If set, output must exactly match this string (after trim). */
|
|
3013
|
+
expectedOutput?: string;
|
|
3014
|
+
/** If set, output must match this regex pattern. */
|
|
3015
|
+
expectedOutputPattern?: RegExp;
|
|
3016
|
+
/** If set, this function determines pass/fail. */
|
|
3017
|
+
validator?: (output: string) => boolean;
|
|
3018
|
+
/** Optional agent config overrides for this case. */
|
|
3019
|
+
agentConfig?: Record<string, unknown>;
|
|
3020
|
+
/** Optional tags for filtering/grouping. */
|
|
3021
|
+
tags?: string[];
|
|
3022
|
+
}
|
|
3023
|
+
/** Result of running a single eval case. */
|
|
3024
|
+
interface EvalResult {
|
|
3025
|
+
/** Name of the eval case. */
|
|
3026
|
+
caseName: string;
|
|
3027
|
+
/** Whether the case passed. */
|
|
3028
|
+
passed: boolean;
|
|
3029
|
+
/** Actual output from the executor. */
|
|
3030
|
+
actualOutput: string;
|
|
3031
|
+
/** Expected output (if specified). */
|
|
3032
|
+
expectedOutput?: string;
|
|
3033
|
+
/** Execution duration in milliseconds. */
|
|
3034
|
+
durationMs: number;
|
|
3035
|
+
/** Error message if the executor threw. */
|
|
3036
|
+
error?: string;
|
|
3037
|
+
}
|
|
3038
|
+
/** A suite of eval cases. */
|
|
3039
|
+
interface EvalSuite {
|
|
3040
|
+
/** Suite name. */
|
|
3041
|
+
name: string;
|
|
3042
|
+
/** Optional description. */
|
|
3043
|
+
description?: string;
|
|
3044
|
+
/** The eval cases to run. */
|
|
3045
|
+
cases: EvalCase[];
|
|
3046
|
+
}
|
|
3047
|
+
/**
|
|
3048
|
+
* Define an eval suite with validation.
|
|
3049
|
+
* Throws if the suite has no name or no cases.
|
|
3050
|
+
*/
|
|
3051
|
+
declare function defineEvalSuite(config: EvalSuite): EvalSuite;
|
|
3052
|
+
/**
|
|
3053
|
+
* Run an eval suite against an executor function.
|
|
3054
|
+
* The executor receives an input string and should return the agent's output.
|
|
3055
|
+
* Cases are run sequentially to avoid overwhelming LLM providers.
|
|
3056
|
+
*/
|
|
3057
|
+
declare function runEval(suite: EvalSuite, executor: (input: string) => Promise<string>): Promise<EvalResult[]>;
|
|
3058
|
+
|
|
3059
|
+
/** Capabilities a plugin can provide */
|
|
3060
|
+
type PluginCapability = "tools" | "guardrails" | "providers" | "session-backends" | "exporters" | "transforms" | "commands" | "ui-panels" | "ui-widgets" | "ui-themes";
|
|
3061
|
+
/** UI extension slot declaration */
|
|
3062
|
+
interface UIExtensionSlot {
|
|
3063
|
+
/** Slot identifier: "dashboard.sidebar", "agent.detail.tab", "settings.panel", "marketplace.card" */
|
|
3064
|
+
slot: string;
|
|
3065
|
+
/** Display label */
|
|
3066
|
+
label: string;
|
|
3067
|
+
/** Relative path to the component within the plugin package */
|
|
3068
|
+
component: string;
|
|
3069
|
+
/** Optional icon name */
|
|
3070
|
+
icon?: string;
|
|
3071
|
+
}
|
|
3072
|
+
/** Plugin manifest — immutable metadata about the plugin */
|
|
3073
|
+
interface PluginManifest {
|
|
3074
|
+
name: string;
|
|
3075
|
+
version: string;
|
|
3076
|
+
description: string;
|
|
3077
|
+
author?: string;
|
|
3078
|
+
homepage?: string;
|
|
3079
|
+
capabilities: PluginCapability[];
|
|
3080
|
+
uiExtensions?: UIExtensionSlot[];
|
|
3081
|
+
/** JSON Schema describing the plugin's configuration shape */
|
|
3082
|
+
configSchema?: Record<string, unknown>;
|
|
3083
|
+
}
|
|
3084
|
+
/** Context provided to a plugin during activation */
|
|
3085
|
+
interface PluginContext {
|
|
3086
|
+
/** Register a tool that agents can use */
|
|
3087
|
+
registerTool(tool: ToolDef<unknown, unknown>): void;
|
|
3088
|
+
/** Register a guardrail */
|
|
3089
|
+
registerGuardrail(config: {
|
|
3090
|
+
name: string;
|
|
3091
|
+
type: "input" | "output" | "tool";
|
|
3092
|
+
handler: (...args: unknown[]) => Promise<unknown>;
|
|
3093
|
+
}): void;
|
|
3094
|
+
/** Register a trace exporter */
|
|
3095
|
+
registerExporter(exporter: {
|
|
3096
|
+
export(trace: unknown): Promise<void>;
|
|
3097
|
+
}): void;
|
|
3098
|
+
/** Access the event bus for pub/sub */
|
|
3099
|
+
getEventBus(): ADKEventBus;
|
|
3100
|
+
/** Get plugin configuration (type-safe with generic) */
|
|
3101
|
+
getConfig<T = Record<string, unknown>>(): T;
|
|
3102
|
+
/** Get plugin data directory path (for persistent storage) */
|
|
3103
|
+
getDataDir(): string;
|
|
3104
|
+
/** Log a message scoped to this plugin */
|
|
3105
|
+
log(level: "debug" | "info" | "warn" | "error", message: string, data?: Record<string, unknown>): void;
|
|
3106
|
+
}
|
|
3107
|
+
/** Lifecycle hooks for a plugin */
|
|
3108
|
+
interface PluginLifecycle {
|
|
3109
|
+
/** Called when plugin is activated. Register tools, guardrails, etc. */
|
|
3110
|
+
activate(ctx: PluginContext): Promise<void>;
|
|
3111
|
+
/** Called when plugin is deactivated. Cleanup resources. */
|
|
3112
|
+
deactivate?(): Promise<void>;
|
|
3113
|
+
/** Called when plugin config changes at runtime */
|
|
3114
|
+
onConfigChanged?(newConfig: Record<string, unknown>): Promise<void>;
|
|
3115
|
+
/** Health check — returns whether the plugin is functioning correctly */
|
|
3116
|
+
onHealthCheck?(): Promise<{
|
|
3117
|
+
healthy: boolean;
|
|
3118
|
+
details?: Record<string, unknown>;
|
|
3119
|
+
}>;
|
|
3120
|
+
}
|
|
3121
|
+
/** Complete plugin definition (manifest + lifecycle) */
|
|
3122
|
+
interface PluginDefinition {
|
|
3123
|
+
manifest: PluginManifest;
|
|
3124
|
+
lifecycle: PluginLifecycle;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
/** Define a plugin from config — validates manifest and freezes the definition */
|
|
3128
|
+
declare function definePlugin(config: {
|
|
3129
|
+
manifest: PluginManifest;
|
|
3130
|
+
activate: PluginLifecycle["activate"];
|
|
3131
|
+
deactivate?: PluginLifecycle["deactivate"];
|
|
3132
|
+
onConfigChanged?: PluginLifecycle["onConfigChanged"];
|
|
3133
|
+
onHealthCheck?: PluginLifecycle["onHealthCheck"];
|
|
3134
|
+
}): PluginDefinition;
|
|
3135
|
+
|
|
3136
|
+
type PluginStatus = "registered" | "active" | "inactive" | "error";
|
|
3137
|
+
interface PluginEntry {
|
|
3138
|
+
definition: PluginDefinition;
|
|
3139
|
+
status: PluginStatus;
|
|
3140
|
+
config: Record<string, unknown>;
|
|
3141
|
+
registeredTools: string[];
|
|
3142
|
+
registeredGuardrails: string[];
|
|
3143
|
+
registeredExporters: number;
|
|
3144
|
+
error?: string;
|
|
3145
|
+
activatedAt?: Date;
|
|
3146
|
+
}
|
|
3147
|
+
declare class PluginRegistry {
|
|
3148
|
+
private plugins;
|
|
3149
|
+
private tools;
|
|
3150
|
+
private guardrails;
|
|
3151
|
+
private exporters;
|
|
3152
|
+
private eventBus?;
|
|
3153
|
+
private dataDir;
|
|
3154
|
+
constructor(options?: {
|
|
3155
|
+
eventBus?: ADKEventBus;
|
|
3156
|
+
dataDir?: string;
|
|
3157
|
+
});
|
|
3158
|
+
/** Register a plugin definition (does not activate it) */
|
|
3159
|
+
register(definition: PluginDefinition, config?: Record<string, unknown>): void;
|
|
3160
|
+
/** Activate a registered plugin — calls its activate() lifecycle hook */
|
|
3161
|
+
activate(name: string): Promise<void>;
|
|
3162
|
+
/** Deactivate a plugin — calls deactivate() and removes all registered extensions */
|
|
3163
|
+
deactivate(name: string): Promise<void>;
|
|
3164
|
+
/** Unregister a plugin — must be deactivated first */
|
|
3165
|
+
unregister(name: string): void;
|
|
3166
|
+
/** Get a plugin entry by name */
|
|
3167
|
+
getPlugin(name: string): PluginEntry | undefined;
|
|
3168
|
+
/** List all registered plugins with their status */
|
|
3169
|
+
listPlugins(): Array<{
|
|
3170
|
+
name: string;
|
|
3171
|
+
version: string;
|
|
3172
|
+
status: PluginStatus;
|
|
3173
|
+
capabilities: PluginCapability[];
|
|
3174
|
+
}>;
|
|
3175
|
+
/** Get all tools registered by plugins (namespaced as "pluginName:toolName") */
|
|
3176
|
+
getRegisteredTools(): Map<string, ToolDef<unknown, unknown>>;
|
|
3177
|
+
/** Get all guardrails registered by plugins */
|
|
3178
|
+
getRegisteredGuardrails(): Array<{
|
|
3179
|
+
pluginName: string;
|
|
3180
|
+
config: unknown;
|
|
3181
|
+
}>;
|
|
3182
|
+
/** Get all trace exporters registered by plugins */
|
|
3183
|
+
getRegisteredExporters(): Array<{
|
|
3184
|
+
pluginName: string;
|
|
3185
|
+
exporter: unknown;
|
|
3186
|
+
}>;
|
|
3187
|
+
/** Run health check on a specific plugin */
|
|
3188
|
+
healthCheck(name: string): Promise<{
|
|
3189
|
+
healthy: boolean;
|
|
3190
|
+
details?: Record<string, unknown>;
|
|
3191
|
+
}>;
|
|
3192
|
+
/** Update config for a plugin and notify it if active */
|
|
3193
|
+
updateConfig(name: string, newConfig: Record<string, unknown>): Promise<void>;
|
|
3194
|
+
/** Create the PluginContext handed to the plugin during activation */
|
|
3195
|
+
private createContext;
|
|
3196
|
+
}
|
|
3197
|
+
|
|
3198
|
+
export { ADKEventBus, type ADKEventListener, type ADKEventMap, type ADKEventName, ADKLLMAdapter, type ADKLLMProvider, ADKPipeline, ADKProviderError, type ADKProviderErrorCode, ADKReviewPipeline, ADKRouter, Agent, type AgentConfig, type AgentErrorEvent, type AgentHeartbeatEvent, type AgentInfo, type AgentLLMConfig, type AgentLogEvent, type AgentStartedEvent, type AgentStoppedEvent, AgenticMemory, type AgenticMemoryBackend, type AlertCreatedEvent, type AlertResolvedEvent, AnthropicProvider, type Artifact, type ArtifactCreatedEvent, ArtifactStore, type AudioPart, AudioStreamBuffer, type AutonomyLevel, type BackpressureOptions, BackpressuredStream, BaseProvider, type BudgetCheckData, type BudgetPeriod, type CatalogModel, type ChatMessage, type ChatParams, type ChatParamsWithTools, type ChatResponse, type ChatResponseWithToolCalls, type ChatRole, type CircuitBreakerState, type CodeExecutionResult, CodeExecutor, type CodeExecutorConfig, type CompactionOptions, type CompleteParams, type CompleteResponse, type ConsentDecision, type ConsentHandler, type ConsentLevel, type ConsentRequest, ConsoleExporter, type Content, type ContentGuardrail, type ContentPart, type ContextConfig, ContextManager, type ContextManagerConfig, type ContextStrategy, ContextSummarizer, type ContextTrimmedEvent, type DecayPolicy, type EmbedApiResponse, type EmbedParams, type EmbedResponse, type EmbeddingConfig, EmbeddingService, type EvalCase, type EvalResult, type EvalSuite, EventBusExporter, type FeatureStatus, GoogleProvider, type Guardrail, type GuardrailConfig, GuardrailEngine, type GuardrailResult, type GuardrailSeverity, type GuardrailTriggeredEvent, GuardrailTripwireError, type GuardrailType, HANDOFF_PREFIX, type HandoffEvent, HandoffManager, type HandoffRecord, type HandoffTarget, type HealthCheckEvent, type ImagePart, InMemoryBackend, InMemorySharedStore, type InputGuardrail, type JsonSchema, type LLMCallCompletedEvent, type LLMCallFailedEvent, type LLMProvider, type LLMProviderSwitchedEvent, type LLMToolDefinition, LMStudioProvider, LangfuseExporter, type LoadedSkill, MCPServerConnector, type MediaType, type MemoryBackend, MemoryDecayManager, type MemoryEntry, MemoryManager, type MemoryManagerConfig, type MemorySearchResult, MemorySessionBackend, type MemoryType, type ModelCapability, type ModelConfig, type ModelsDiscoveredEvent, type NoteEntry, type NoteSection, NotesStore, OllamaProvider, OpenAIProvider, type OutputGuardrail, ParallelRunner, type PgVectorDatabaseClient, PgVectorMemoryBackend, type PluginCapability, type PluginContext, type PluginDefinition, type PluginLifecycle, type PluginManifest, PluginRegistry, type PluginStatus, PrismaSessionBackend, type ProgressFeature, ProgressTracker, type ProviderInitConfig, type ProviderMetrics, ProxyRouter, RealtimeAgent, type RedactOptions, type ResponseFormat, type RoutingStrategy, type RunCompletedEvent, type RunConfig, type RunContext, type RunFailedEvent, type RunResult, type RunStartedEvent, type RunUsage, Runner, type RunnerConfig, type Session, type SessionBackend, type SessionCreateOptions, type SessionCreatedEvent, type SessionListFilter, type SessionResumedEvent, type SessionStatus, type SessionUpdateOptions, type SharedMemoryEntry, type SharedMemoryNamespace, type SharedMemoryScope, type SharedMemoryStore, type SkillManifest, SkillManifestSchema, type SkillToolEntry, Span, type StreamChunk, type StreamEvent, type SummarizationConfig, type TaskCompletedEvent, type TaskFailedEvent, type TaskStartedEvent, type TaskSubmittedEvent, Team, type TextPart, TokenCounter, type TokenCounterConfig, type TokenCounterStrategy, type ToolCall, type ToolContext, type ToolDef, type ToolDefConfig, type ToolExecutedEvent, type ToolGuardrail, type ToolHooks, type ToolPostHookResult, type ToolPreHookResult, ToolRegistry, type ToolRelevanceScore, type ToolResult, type ToolSearchResult, type ToolSelectionConfig, type ToolSelectionStrategy, ToolSelector, type ToolsSelectedEvent, Trace, Tracer, type TracingConfig, TurnExecutor, type UIArtifactPart, type UIExtensionSlot, type VideoPart, XAIProvider, agentAsTool, budgetGateGuardrail, budgetLimit, calculateVolume, compactMessages, consentGate, contentFilter, contentToParts, contentToString, countMediaParts, createArtifactTool, createAsyncEventStream, createExecuteCodeTool, createMemoryReadTool, createMemorySearchTool, createMemoryWriteTool, createProgressTool, createProvider, createReadNotesTool, createRunContext, createRunId, createStreamAdapter, createToolSearchTool, createTraceId, createWriteNoteTool, defineAgent, defineEvalSuite, definePlugin, defineSkill, defineTool, discoverMCPTools, encodeSSE, ensureJsonSchema, extractText, generateApiKey, hashApiKey, isAudioPart, isImagePart, isMultiModalContent, isTextPart, isUIArtifactPart, isVideoPart, isZodSchema, loadSkill, mcpSelectTools, mcpServerTools, mergeSkillTools, parseApiKey, pcm16FromArrayBuffer, pcm16ToArrayBuffer, piiFilter, redact, relayToWebSocket, runEval, schemaToToolInput, streamToSSE, toAnthropicToolSchema, toGoogleSchemaFormat, toOpenAIResponseFormat, tokenLimit, validateApiKeyFormat, validateOutput, zodToJsonSchema };
|