@zhivex-ai/core 0.4.0 → 0.5.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/dist/agent-approval.d.ts +6 -0
- package/dist/agent-approval.d.ts.map +1 -0
- package/dist/agent-approval.js +38 -0
- package/dist/agent-approval.js.map +1 -0
- package/dist/agent-handoff.d.ts +11 -0
- package/dist/agent-handoff.d.ts.map +1 -0
- package/dist/agent-handoff.js +20 -0
- package/dist/agent-handoff.js.map +1 -0
- package/dist/agent-store.d.ts +20 -0
- package/dist/agent-store.d.ts.map +1 -0
- package/dist/agent-store.js +252 -0
- package/dist/agent-store.js.map +1 -0
- package/dist/agent.d.ts +8 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +701 -0
- package/dist/agent.js.map +1 -0
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -1
- package/dist/generate-text.d.ts.map +1 -1
- package/dist/generate-text.js +87 -9
- package/dist/generate-text.js.map +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/live-agent.d.ts +3 -0
- package/dist/live-agent.d.ts.map +1 -0
- package/dist/live-agent.js +565 -0
- package/dist/live-agent.js.map +1 -0
- package/dist/mcp.d.ts +40 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +167 -0
- package/dist/mcp.js.map +1 -0
- package/dist/messages.d.ts +9 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +55 -0
- package/dist/messages.js.map +1 -1
- package/dist/observability.d.ts +51 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +276 -0
- package/dist/observability.js.map +1 -0
- package/dist/realtime.d.ts +52 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +304 -0
- package/dist/realtime.js.map +1 -0
- package/dist/stream.d.ts +5 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +1 -0
- package/dist/stream.js.map +1 -1
- package/dist/tool-registry.d.ts +17 -0
- package/dist/tool-registry.d.ts.map +1 -0
- package/dist/tool-registry.js +74 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/types.d.ts +589 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/ui.d.ts +4 -2
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +47 -0
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -55,7 +55,12 @@ export interface ToolResultPart {
|
|
|
55
55
|
type: "tool-result";
|
|
56
56
|
toolResult: ToolExecutionResult;
|
|
57
57
|
}
|
|
58
|
-
export
|
|
58
|
+
export interface ProviderDataPart {
|
|
59
|
+
type: "provider-data";
|
|
60
|
+
provider: string;
|
|
61
|
+
data: JsonValue;
|
|
62
|
+
}
|
|
63
|
+
export type ContentPart = TextPart | ImagePart | FilePart | ToolCallPart | ToolResultPart | ProviderDataPart;
|
|
59
64
|
export interface ModelMessage {
|
|
60
65
|
role: MessageRole;
|
|
61
66
|
parts: ContentPart[];
|
|
@@ -74,7 +79,27 @@ export interface ModelCapabilities {
|
|
|
74
79
|
embeddings: boolean;
|
|
75
80
|
reasoning: boolean;
|
|
76
81
|
webSearch: boolean;
|
|
77
|
-
|
|
82
|
+
realtime?: {
|
|
83
|
+
sessions: boolean;
|
|
84
|
+
audioInput: boolean;
|
|
85
|
+
audioOutput: boolean;
|
|
86
|
+
tools: boolean;
|
|
87
|
+
browserTokens: boolean;
|
|
88
|
+
};
|
|
89
|
+
agentCapabilities?: AgentCapabilities;
|
|
90
|
+
}
|
|
91
|
+
export interface AgentCapabilities {
|
|
92
|
+
supportTier: AgentSupportTier;
|
|
93
|
+
toolChoiceNone: boolean;
|
|
94
|
+
approvalRequests: boolean;
|
|
95
|
+
hostedWebSearch: boolean;
|
|
96
|
+
hostedFileSearch: boolean;
|
|
97
|
+
remoteMcp: boolean;
|
|
98
|
+
computerUse: boolean;
|
|
99
|
+
codeExecution: boolean;
|
|
100
|
+
toolsets: boolean;
|
|
101
|
+
}
|
|
102
|
+
export type AgentSupportTier = "tier-a" | "tier-b" | "tier-c";
|
|
78
103
|
export interface RetryOptions {
|
|
79
104
|
abortSignal?: AbortSignal;
|
|
80
105
|
timeoutMs?: number;
|
|
@@ -109,6 +134,11 @@ export interface StreamToolResultEvent {
|
|
|
109
134
|
type: "tool-result";
|
|
110
135
|
toolResult: ToolExecutionResult;
|
|
111
136
|
}
|
|
137
|
+
export interface StreamProviderDataEvent {
|
|
138
|
+
type: "provider-data";
|
|
139
|
+
provider: string;
|
|
140
|
+
data: JsonValue;
|
|
141
|
+
}
|
|
112
142
|
export interface StreamFinishEvent {
|
|
113
143
|
type: "finish";
|
|
114
144
|
finishReason?: FinishReason;
|
|
@@ -119,7 +149,34 @@ export interface StreamErrorEvent {
|
|
|
119
149
|
type: "error";
|
|
120
150
|
error: Error;
|
|
121
151
|
}
|
|
122
|
-
export type StreamEvent = StreamTextDeltaEvent | StreamToolCallEvent | StreamToolResultEvent | StreamFinishEvent | StreamErrorEvent;
|
|
152
|
+
export type StreamEvent = StreamTextDeltaEvent | StreamToolCallEvent | StreamToolResultEvent | StreamProviderDataEvent | StreamFinishEvent | StreamErrorEvent;
|
|
153
|
+
export interface AgentRunStartEvent {
|
|
154
|
+
type: "agent-run-start";
|
|
155
|
+
currentStep: number;
|
|
156
|
+
maxSteps: number;
|
|
157
|
+
}
|
|
158
|
+
export interface AgentStepStartEvent {
|
|
159
|
+
type: "agent-step-start";
|
|
160
|
+
stepIndex: number;
|
|
161
|
+
}
|
|
162
|
+
export interface AgentStepFinishEvent {
|
|
163
|
+
type: "agent-step-finish";
|
|
164
|
+
step: AgentStep;
|
|
165
|
+
}
|
|
166
|
+
export interface AgentApprovalRequestEvent {
|
|
167
|
+
type: "agent-approval-request";
|
|
168
|
+
approval: AgentApprovalRequest;
|
|
169
|
+
}
|
|
170
|
+
export interface AgentApprovalResolvedEvent {
|
|
171
|
+
type: "agent-approval-resolved";
|
|
172
|
+
approval: AgentApprovalResponse;
|
|
173
|
+
}
|
|
174
|
+
export interface AgentRunFinishEvent {
|
|
175
|
+
type: "agent-run-finish";
|
|
176
|
+
status: AgentStatus;
|
|
177
|
+
state: AgentRunState;
|
|
178
|
+
}
|
|
179
|
+
export type AgentStreamEvent = StreamEvent | AgentRunStartEvent | AgentStepStartEvent | AgentStepFinishEvent | AgentApprovalRequestEvent | AgentApprovalResolvedEvent | AgentRunFinishEvent;
|
|
123
180
|
export interface StreamObjectDeltaEvent {
|
|
124
181
|
type: "object-delta";
|
|
125
182
|
textDelta: string;
|
|
@@ -235,6 +292,125 @@ export interface SpeechModel<TProviderOptions extends ProviderOptions = Provider
|
|
|
235
292
|
readonly capabilities: ModelCapabilities;
|
|
236
293
|
generateSpeech(input: SpeechModelInput<TProviderOptions>): Promise<SpeechResult>;
|
|
237
294
|
}
|
|
295
|
+
export interface AudioFrame {
|
|
296
|
+
data: string | Uint8Array | ArrayBuffer;
|
|
297
|
+
mediaType: string;
|
|
298
|
+
sampleRateHz?: number;
|
|
299
|
+
channels?: number;
|
|
300
|
+
isFinal?: boolean;
|
|
301
|
+
}
|
|
302
|
+
export interface RealtimeConnectOptions {
|
|
303
|
+
timeoutMs?: number;
|
|
304
|
+
signal?: AbortSignal;
|
|
305
|
+
subprotocols?: string[];
|
|
306
|
+
}
|
|
307
|
+
export interface RealtimeSessionConfig {
|
|
308
|
+
instructions?: string;
|
|
309
|
+
voice?: string;
|
|
310
|
+
tools?: ToolCollection;
|
|
311
|
+
toolChoice?: ToolChoice;
|
|
312
|
+
inputAudioMediaType?: string;
|
|
313
|
+
outputAudioMediaType?: string;
|
|
314
|
+
inputSampleRateHz?: number;
|
|
315
|
+
outputSampleRateHz?: number;
|
|
316
|
+
channels?: number;
|
|
317
|
+
turnDetection?: Record<string, unknown> | null;
|
|
318
|
+
providerOptions?: ProviderOptions;
|
|
319
|
+
metadata?: Record<string, JsonValue>;
|
|
320
|
+
autoResponse?: boolean;
|
|
321
|
+
}
|
|
322
|
+
export interface RealtimeTokenResult {
|
|
323
|
+
value: string;
|
|
324
|
+
expiresAtMs?: number;
|
|
325
|
+
rawResponse?: unknown;
|
|
326
|
+
}
|
|
327
|
+
export interface RealtimeSessionStartedEvent {
|
|
328
|
+
type: "realtime-start";
|
|
329
|
+
sessionId?: string;
|
|
330
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
331
|
+
}
|
|
332
|
+
export interface RealtimeTextDeltaEvent {
|
|
333
|
+
type: "realtime-text-delta";
|
|
334
|
+
textDelta: string;
|
|
335
|
+
itemId?: string;
|
|
336
|
+
responseId?: string;
|
|
337
|
+
role?: "assistant";
|
|
338
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
339
|
+
}
|
|
340
|
+
export interface RealtimeAudioOutputEvent {
|
|
341
|
+
type: "realtime-audio-output";
|
|
342
|
+
audio: Uint8Array;
|
|
343
|
+
mediaType: string;
|
|
344
|
+
sampleRateHz?: number;
|
|
345
|
+
channels?: number;
|
|
346
|
+
itemId?: string;
|
|
347
|
+
responseId?: string;
|
|
348
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
349
|
+
}
|
|
350
|
+
export interface RealtimeTranscriptEvent {
|
|
351
|
+
type: "realtime-transcript";
|
|
352
|
+
text: string;
|
|
353
|
+
role: "user" | "assistant";
|
|
354
|
+
isFinal: boolean;
|
|
355
|
+
itemId?: string;
|
|
356
|
+
responseId?: string;
|
|
357
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
358
|
+
}
|
|
359
|
+
export interface RealtimeToolCallEvent {
|
|
360
|
+
type: "realtime-tool-call";
|
|
361
|
+
toolCall: ToolCall;
|
|
362
|
+
}
|
|
363
|
+
export interface RealtimeToolResultEvent {
|
|
364
|
+
type: "realtime-tool-result";
|
|
365
|
+
toolResult: ToolExecutionResult;
|
|
366
|
+
}
|
|
367
|
+
export interface RealtimeResponseCompleteEvent {
|
|
368
|
+
type: "realtime-response-complete";
|
|
369
|
+
reason?: string;
|
|
370
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
371
|
+
}
|
|
372
|
+
export interface RealtimeSessionResumptionEvent {
|
|
373
|
+
type: "realtime-session-resumption";
|
|
374
|
+
handle?: string;
|
|
375
|
+
resumable?: boolean;
|
|
376
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
377
|
+
}
|
|
378
|
+
export interface RealtimeGoAwayEvent {
|
|
379
|
+
type: "realtime-go-away";
|
|
380
|
+
timeLeftMs?: number;
|
|
381
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
382
|
+
}
|
|
383
|
+
export interface RealtimeSessionEndedEvent {
|
|
384
|
+
type: "realtime-end";
|
|
385
|
+
reason?: string;
|
|
386
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
387
|
+
}
|
|
388
|
+
export interface RealtimeErrorEvent {
|
|
389
|
+
type: "realtime-error";
|
|
390
|
+
error?: Error;
|
|
391
|
+
message?: string;
|
|
392
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
393
|
+
}
|
|
394
|
+
export type RealtimeEvent = RealtimeSessionStartedEvent | RealtimeTextDeltaEvent | RealtimeAudioOutputEvent | RealtimeTranscriptEvent | RealtimeToolCallEvent | RealtimeToolResultEvent | RealtimeResponseCompleteEvent | RealtimeSessionResumptionEvent | RealtimeGoAwayEvent | RealtimeSessionEndedEvent | RealtimeErrorEvent;
|
|
395
|
+
export interface RealtimeSession {
|
|
396
|
+
readonly provider: string;
|
|
397
|
+
readonly modelId: string;
|
|
398
|
+
readonly capabilities: ModelCapabilities;
|
|
399
|
+
readonly config: RealtimeSessionConfig;
|
|
400
|
+
sendAudio(frame: AudioFrame): Promise<void>;
|
|
401
|
+
sendText(text: string): Promise<void>;
|
|
402
|
+
sendToolResult(result: ToolExecutionResult): Promise<void>;
|
|
403
|
+
update(config: Partial<RealtimeSessionConfig>): Promise<void>;
|
|
404
|
+
eventStream(): AsyncIterable<RealtimeEvent>;
|
|
405
|
+
close(): Promise<void>;
|
|
406
|
+
}
|
|
407
|
+
export interface RealtimeModel {
|
|
408
|
+
readonly provider: string;
|
|
409
|
+
readonly modelId: string;
|
|
410
|
+
readonly capabilities: ModelCapabilities;
|
|
411
|
+
connect(config?: RealtimeSessionConfig, options?: RealtimeConnectOptions): Promise<RealtimeSession>;
|
|
412
|
+
createBrowserToken?(config?: RealtimeSessionConfig, options?: RealtimeConnectOptions): Promise<RealtimeTokenResult>;
|
|
413
|
+
}
|
|
238
414
|
export interface GroundedLanguageModel<TProviderOptions extends ProviderOptions = ProviderOptions> {
|
|
239
415
|
readonly provider: string;
|
|
240
416
|
readonly modelId: string;
|
|
@@ -253,6 +429,7 @@ export interface ProviderAdapter {
|
|
|
253
429
|
embeddingModel?: (modelId: string) => EmbeddingModel;
|
|
254
430
|
transcriptionModel?: (modelId: string) => TranscriptionModel;
|
|
255
431
|
speechModel?: (modelId: string) => SpeechModel;
|
|
432
|
+
realtimeModel?: (modelId: string) => RealtimeModel;
|
|
256
433
|
groundedLanguageModel?: (modelId: string) => GroundedLanguageModel;
|
|
257
434
|
}
|
|
258
435
|
export type CallableProviderAdapter = ProviderAdapter & ((modelId: string) => LanguageModel);
|
|
@@ -260,16 +437,59 @@ export interface ToolDefinition<TSchema extends ZodTypeAny = ZodTypeAny, TResult
|
|
|
260
437
|
name: string;
|
|
261
438
|
description?: string;
|
|
262
439
|
schema: TSchema;
|
|
440
|
+
metadata?: Record<string, JsonValue>;
|
|
441
|
+
requiresApproval?: boolean;
|
|
263
442
|
execute: (input: z.infer<TSchema>) => Promise<TResult> | TResult;
|
|
264
443
|
}
|
|
265
|
-
export type
|
|
444
|
+
export type HostedToolClass = "web-search" | "file-search" | "remote-mcp" | "computer-use" | "code-execution" | "toolset" | "custom";
|
|
445
|
+
export interface HostedToolDefinition<TConfig extends JsonValue = JsonValue> {
|
|
446
|
+
kind: "hosted";
|
|
447
|
+
name: string;
|
|
448
|
+
provider?: string;
|
|
449
|
+
type: string;
|
|
450
|
+
config?: TConfig;
|
|
451
|
+
toolClass?: HostedToolClass;
|
|
452
|
+
requiresApproval?: boolean;
|
|
453
|
+
metadata?: Record<string, JsonValue>;
|
|
454
|
+
}
|
|
455
|
+
export type AnyToolDefinition = ToolDefinition | HostedToolDefinition;
|
|
456
|
+
export type ToolSet = Record<string, AnyToolDefinition>;
|
|
457
|
+
export interface ToolRegistryLike {
|
|
458
|
+
get(name: string): AnyToolDefinition | undefined;
|
|
459
|
+
has(name: string): boolean;
|
|
460
|
+
entries(): Iterable<[string, AnyToolDefinition]>;
|
|
461
|
+
toToolSet(): ToolSet;
|
|
462
|
+
}
|
|
463
|
+
export type ToolCollection = ToolSet | ToolRegistryLike;
|
|
464
|
+
export interface ToolApprovalRequest {
|
|
465
|
+
toolCall: ToolCall;
|
|
466
|
+
tool: ToolDefinition;
|
|
467
|
+
input: JsonValue;
|
|
468
|
+
step: number;
|
|
469
|
+
model: LanguageModel | RealtimeModel;
|
|
470
|
+
request?: ModelGenerateInput;
|
|
471
|
+
realtimeConfig?: RealtimeSessionConfig;
|
|
472
|
+
}
|
|
473
|
+
export interface ToolApprovalDecision {
|
|
474
|
+
approved: boolean;
|
|
475
|
+
reason?: string;
|
|
476
|
+
metadata?: Record<string, JsonValue>;
|
|
477
|
+
}
|
|
478
|
+
export interface ToolApprovalEvent {
|
|
479
|
+
request: ToolApprovalRequest;
|
|
480
|
+
decision: ToolApprovalDecision;
|
|
481
|
+
}
|
|
482
|
+
export type ToolApprovalPolicy = (request: ToolApprovalRequest) => ToolApprovalDecision | boolean | Promise<ToolApprovalDecision | boolean>;
|
|
483
|
+
export type ToolApprovalObserver = (event: ToolApprovalEvent) => void | Promise<void>;
|
|
266
484
|
export type ProviderOptionsOf<TModel extends LanguageModel> = TModel extends LanguageModel<infer TProviderOptions> ? TProviderOptions : ProviderOptions;
|
|
267
485
|
export type GenerateTextOptions<TModel extends LanguageModel = LanguageModel> = RetryOptions & GenerateInputSource & {
|
|
268
486
|
model: TModel;
|
|
269
487
|
system?: string;
|
|
270
|
-
tools?:
|
|
488
|
+
tools?: ToolCollection;
|
|
271
489
|
toolChoice?: ToolChoice;
|
|
272
490
|
toolExecution?: ToolExecutionOptions;
|
|
491
|
+
toolApprovalPolicy?: ToolApprovalPolicy;
|
|
492
|
+
onToolApprovalDecision?: ToolApprovalObserver;
|
|
273
493
|
maxSteps?: number;
|
|
274
494
|
temperature?: number;
|
|
275
495
|
maxTokens?: number;
|
|
@@ -290,6 +510,336 @@ export interface GenerateTextOutput {
|
|
|
290
510
|
messages: ModelMessage[];
|
|
291
511
|
toolResults: ToolExecutionResult[];
|
|
292
512
|
}
|
|
513
|
+
export type AgentStatus = "running" | "completed" | "suspended" | "failed" | "cancelled";
|
|
514
|
+
export type AgentStepStatus = "running" | "completed" | "suspended" | "failed";
|
|
515
|
+
export interface AgentStepRequest {
|
|
516
|
+
messages: ModelMessage[];
|
|
517
|
+
toolChoice?: ToolChoice;
|
|
518
|
+
toolExecution?: ToolExecutionOptions;
|
|
519
|
+
temperature?: number;
|
|
520
|
+
maxTokens?: number;
|
|
521
|
+
reasoning?: ReasoningConfig;
|
|
522
|
+
providerOptions?: ProviderOptions;
|
|
523
|
+
timeoutMs?: number;
|
|
524
|
+
maxRetries?: number;
|
|
525
|
+
retryBackoffMs?: number;
|
|
526
|
+
}
|
|
527
|
+
export interface AgentStepResponse {
|
|
528
|
+
messages: ModelMessage[];
|
|
529
|
+
text?: string;
|
|
530
|
+
finishReason?: FinishReason;
|
|
531
|
+
providerFinishReason?: string;
|
|
532
|
+
usage?: TokenUsage;
|
|
533
|
+
}
|
|
534
|
+
export interface AgentStep {
|
|
535
|
+
index: number;
|
|
536
|
+
status: AgentStepStatus;
|
|
537
|
+
startedAt?: number;
|
|
538
|
+
finishedAt?: number;
|
|
539
|
+
request: AgentStepRequest;
|
|
540
|
+
response?: AgentStepResponse;
|
|
541
|
+
toolResults: ToolExecutionResult[];
|
|
542
|
+
error?: {
|
|
543
|
+
message: string;
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
export interface AgentRunState {
|
|
547
|
+
runId: string;
|
|
548
|
+
agentId?: string;
|
|
549
|
+
parentRunId?: string;
|
|
550
|
+
provider: string;
|
|
551
|
+
modelId: string;
|
|
552
|
+
status: AgentStatus;
|
|
553
|
+
messages: ModelMessage[];
|
|
554
|
+
steps: AgentStep[];
|
|
555
|
+
toolResults: ToolExecutionResult[];
|
|
556
|
+
currentStep: number;
|
|
557
|
+
maxSteps: number;
|
|
558
|
+
outputText: string;
|
|
559
|
+
finishReason?: FinishReason;
|
|
560
|
+
providerFinishReason?: string;
|
|
561
|
+
usage?: TokenUsage;
|
|
562
|
+
pendingApprovals: AgentApprovalRequest[];
|
|
563
|
+
metadata?: Record<string, JsonValue>;
|
|
564
|
+
handoff?: AgentHandoff;
|
|
565
|
+
startedAt?: number;
|
|
566
|
+
updatedAt?: number;
|
|
567
|
+
error?: {
|
|
568
|
+
message: string;
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
export interface AgentRunStore {
|
|
572
|
+
load(runId: string): Promise<AgentRunState | undefined> | AgentRunState | undefined;
|
|
573
|
+
save(state: AgentRunState): Promise<void> | void;
|
|
574
|
+
delete?(runId: string): Promise<void> | void;
|
|
575
|
+
}
|
|
576
|
+
export interface AgentMemoryContext {
|
|
577
|
+
runId: string;
|
|
578
|
+
agentId?: string;
|
|
579
|
+
state?: AgentRunState;
|
|
580
|
+
metadata?: Record<string, JsonValue>;
|
|
581
|
+
}
|
|
582
|
+
export interface AgentMemoryStore {
|
|
583
|
+
load(context: AgentMemoryContext): Promise<ModelMessage[]> | ModelMessage[];
|
|
584
|
+
save?(context: AgentMemoryContext & {
|
|
585
|
+
state: AgentRunState;
|
|
586
|
+
}): Promise<void> | void;
|
|
587
|
+
}
|
|
588
|
+
export interface SqliteStatementLike<TResult extends Record<string, unknown> = Record<string, unknown>> {
|
|
589
|
+
run(params?: readonly unknown[] | Record<string, unknown>): unknown;
|
|
590
|
+
get(params?: readonly unknown[] | Record<string, unknown>): TResult | undefined;
|
|
591
|
+
}
|
|
592
|
+
export interface SqliteDatabaseLike {
|
|
593
|
+
exec(sql: string): unknown;
|
|
594
|
+
prepare?<TResult extends Record<string, unknown> = Record<string, unknown>>(sql: string): SqliteStatementLike<TResult>;
|
|
595
|
+
query?<TResult extends Record<string, unknown> = Record<string, unknown>>(sql: string): SqliteStatementLike<TResult>;
|
|
596
|
+
}
|
|
597
|
+
export interface SqliteAgentRunStoreOptions {
|
|
598
|
+
db: SqliteDatabaseLike;
|
|
599
|
+
tableName?: string;
|
|
600
|
+
}
|
|
601
|
+
export interface SqliteAgentMemoryStoreOptions {
|
|
602
|
+
db: SqliteDatabaseLike;
|
|
603
|
+
tableName?: string;
|
|
604
|
+
key?: (context: AgentMemoryContext) => string;
|
|
605
|
+
selectMessages?: (state: AgentRunState) => ModelMessage[];
|
|
606
|
+
}
|
|
607
|
+
export interface PostgresQueryResultLike<TResult extends Record<string, unknown> = Record<string, unknown>> {
|
|
608
|
+
rows: TResult[];
|
|
609
|
+
}
|
|
610
|
+
export interface PostgresClientLike {
|
|
611
|
+
query<TResult extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<PostgresQueryResultLike<TResult>> | PostgresQueryResultLike<TResult>;
|
|
612
|
+
}
|
|
613
|
+
export interface PostgresAgentRunStoreOptions {
|
|
614
|
+
client: PostgresClientLike;
|
|
615
|
+
tableName?: string;
|
|
616
|
+
}
|
|
617
|
+
export interface PostgresAgentMemoryStoreOptions {
|
|
618
|
+
client: PostgresClientLike;
|
|
619
|
+
tableName?: string;
|
|
620
|
+
key?: (context: AgentMemoryContext) => string;
|
|
621
|
+
selectMessages?: (state: AgentRunState) => ModelMessage[];
|
|
622
|
+
}
|
|
623
|
+
export interface AgentHandoff {
|
|
624
|
+
id: string;
|
|
625
|
+
fromRunId: string;
|
|
626
|
+
fromAgentId?: string;
|
|
627
|
+
toAgentId?: string;
|
|
628
|
+
summary: string;
|
|
629
|
+
contextMessages: ModelMessage[];
|
|
630
|
+
metadata?: Record<string, JsonValue>;
|
|
631
|
+
}
|
|
632
|
+
export interface AgentTelemetryRunStartEvent {
|
|
633
|
+
type: "run-start";
|
|
634
|
+
runId: string;
|
|
635
|
+
agentId?: string;
|
|
636
|
+
provider: string;
|
|
637
|
+
modelId: string;
|
|
638
|
+
maxSteps: number;
|
|
639
|
+
}
|
|
640
|
+
export interface AgentTelemetryStepStartEvent {
|
|
641
|
+
type: "step-start";
|
|
642
|
+
runId: string;
|
|
643
|
+
agentId?: string;
|
|
644
|
+
stepIndex: number;
|
|
645
|
+
}
|
|
646
|
+
export interface AgentTelemetryStepFinishEvent {
|
|
647
|
+
type: "step-finish";
|
|
648
|
+
runId: string;
|
|
649
|
+
agentId?: string;
|
|
650
|
+
step: AgentStep;
|
|
651
|
+
}
|
|
652
|
+
export interface AgentTelemetryApprovalRequestEvent {
|
|
653
|
+
type: "approval-request";
|
|
654
|
+
runId: string;
|
|
655
|
+
agentId?: string;
|
|
656
|
+
approval: AgentApprovalRequest;
|
|
657
|
+
}
|
|
658
|
+
export interface AgentTelemetryApprovalResolvedEvent {
|
|
659
|
+
type: "approval-resolved";
|
|
660
|
+
runId: string;
|
|
661
|
+
agentId?: string;
|
|
662
|
+
approval: AgentApprovalResponse;
|
|
663
|
+
}
|
|
664
|
+
export interface AgentTelemetryToolApprovalEvent {
|
|
665
|
+
type: "tool-approval";
|
|
666
|
+
runId: string;
|
|
667
|
+
agentId?: string;
|
|
668
|
+
toolCall: ToolCall;
|
|
669
|
+
approved: boolean;
|
|
670
|
+
reason?: string;
|
|
671
|
+
metadata?: Record<string, JsonValue>;
|
|
672
|
+
}
|
|
673
|
+
export interface AgentTelemetryMemoryLoadedEvent {
|
|
674
|
+
type: "memory-loaded";
|
|
675
|
+
runId: string;
|
|
676
|
+
agentId?: string;
|
|
677
|
+
messageCount: number;
|
|
678
|
+
}
|
|
679
|
+
export interface AgentGuardrailTrigger {
|
|
680
|
+
triggered: true;
|
|
681
|
+
reason?: string;
|
|
682
|
+
metadata?: Record<string, JsonValue>;
|
|
683
|
+
}
|
|
684
|
+
export interface AgentInputGuardrailRequest {
|
|
685
|
+
runId: string;
|
|
686
|
+
agentId?: string;
|
|
687
|
+
messages: ModelMessage[];
|
|
688
|
+
metadata?: Record<string, JsonValue>;
|
|
689
|
+
}
|
|
690
|
+
export interface AgentOutputGuardrailRequest {
|
|
691
|
+
runId: string;
|
|
692
|
+
agentId?: string;
|
|
693
|
+
state: AgentRunState;
|
|
694
|
+
output: AgentRunOutput | LiveAgentRunOutput;
|
|
695
|
+
metadata?: Record<string, JsonValue>;
|
|
696
|
+
}
|
|
697
|
+
export type AgentInputGuardrail = (request: AgentInputGuardrailRequest) => AgentGuardrailTrigger | void | Promise<AgentGuardrailTrigger | void>;
|
|
698
|
+
export type AgentOutputGuardrail = (request: AgentOutputGuardrailRequest) => AgentGuardrailTrigger | void | Promise<AgentGuardrailTrigger | void>;
|
|
699
|
+
export interface AgentTelemetryGuardrailTriggeredEvent {
|
|
700
|
+
type: "guardrail-triggered";
|
|
701
|
+
runId: string;
|
|
702
|
+
agentId?: string;
|
|
703
|
+
stage: "input" | "output";
|
|
704
|
+
reason?: string;
|
|
705
|
+
metadata?: Record<string, JsonValue>;
|
|
706
|
+
}
|
|
707
|
+
export interface AgentTelemetryStateSavedEvent {
|
|
708
|
+
type: "state-saved";
|
|
709
|
+
runId: string;
|
|
710
|
+
agentId?: string;
|
|
711
|
+
status: AgentStatus;
|
|
712
|
+
}
|
|
713
|
+
export interface AgentTelemetryHandoffEvent {
|
|
714
|
+
type: "handoff";
|
|
715
|
+
runId: string;
|
|
716
|
+
agentId?: string;
|
|
717
|
+
handoff: AgentHandoff;
|
|
718
|
+
}
|
|
719
|
+
export interface AgentTelemetryRunFinishEvent {
|
|
720
|
+
type: "run-finish";
|
|
721
|
+
runId: string;
|
|
722
|
+
agentId?: string;
|
|
723
|
+
status: AgentStatus;
|
|
724
|
+
state: AgentRunState;
|
|
725
|
+
}
|
|
726
|
+
export type AgentTelemetryEvent = AgentTelemetryRunStartEvent | AgentTelemetryStepStartEvent | AgentTelemetryStepFinishEvent | AgentTelemetryApprovalRequestEvent | AgentTelemetryApprovalResolvedEvent | AgentTelemetryToolApprovalEvent | AgentTelemetryMemoryLoadedEvent | AgentTelemetryGuardrailTriggeredEvent | AgentTelemetryStateSavedEvent | AgentTelemetryHandoffEvent | AgentTelemetryRunFinishEvent;
|
|
727
|
+
export type AgentTelemetryObserver = (event: AgentTelemetryEvent) => void | Promise<void>;
|
|
728
|
+
export interface AgentDefinition<TModel extends LanguageModel = LanguageModel> {
|
|
729
|
+
id?: string;
|
|
730
|
+
model: TModel;
|
|
731
|
+
instructions?: string;
|
|
732
|
+
tools?: ToolCollection;
|
|
733
|
+
maxSteps?: number;
|
|
734
|
+
temperature?: number;
|
|
735
|
+
maxTokens?: number;
|
|
736
|
+
reasoning?: ReasoningConfig;
|
|
737
|
+
toolExecution?: ToolExecutionOptions;
|
|
738
|
+
toolApprovalPolicy?: ToolApprovalPolicy;
|
|
739
|
+
inputGuardrails?: AgentInputGuardrail[];
|
|
740
|
+
outputGuardrails?: AgentOutputGuardrail[];
|
|
741
|
+
providerOptions?: ProviderOptionsOf<TModel>;
|
|
742
|
+
metadata?: Record<string, JsonValue>;
|
|
743
|
+
store?: AgentRunStore;
|
|
744
|
+
memory?: AgentMemoryStore;
|
|
745
|
+
onTelemetryEvent?: AgentTelemetryObserver;
|
|
746
|
+
}
|
|
747
|
+
export interface LiveAgentDefinition<TModel extends RealtimeModel = RealtimeModel> {
|
|
748
|
+
id?: string;
|
|
749
|
+
model: TModel;
|
|
750
|
+
instructions?: string;
|
|
751
|
+
tools?: ToolCollection;
|
|
752
|
+
toolChoice?: ToolChoice;
|
|
753
|
+
toolExecution?: ToolExecutionOptions;
|
|
754
|
+
toolApprovalPolicy?: ToolApprovalPolicy;
|
|
755
|
+
inputGuardrails?: AgentInputGuardrail[];
|
|
756
|
+
outputGuardrails?: AgentOutputGuardrail[];
|
|
757
|
+
providerOptions?: ProviderOptions;
|
|
758
|
+
metadata?: Record<string, JsonValue>;
|
|
759
|
+
store?: AgentRunStore;
|
|
760
|
+
memory?: AgentMemoryStore;
|
|
761
|
+
onTelemetryEvent?: AgentTelemetryObserver;
|
|
762
|
+
}
|
|
763
|
+
export interface AgentApprovalRequest {
|
|
764
|
+
provider: string;
|
|
765
|
+
id: string;
|
|
766
|
+
name: string;
|
|
767
|
+
arguments: string;
|
|
768
|
+
serverLabel?: string;
|
|
769
|
+
rawData: JsonValue;
|
|
770
|
+
}
|
|
771
|
+
export interface AgentApprovalResponse {
|
|
772
|
+
provider: string;
|
|
773
|
+
approvalRequestId: string;
|
|
774
|
+
approve: boolean;
|
|
775
|
+
id?: string;
|
|
776
|
+
reason?: string;
|
|
777
|
+
}
|
|
778
|
+
export type AgentRunInput<TModel extends LanguageModel = LanguageModel> = RetryOptions & GenerateInputSource & {
|
|
779
|
+
runId?: string;
|
|
780
|
+
state?: AgentRunState;
|
|
781
|
+
approvals?: AgentApprovalResponse[];
|
|
782
|
+
handoff?: AgentHandoff;
|
|
783
|
+
system?: string;
|
|
784
|
+
tools?: ToolCollection;
|
|
785
|
+
toolChoice?: ToolChoice;
|
|
786
|
+
toolExecution?: ToolExecutionOptions;
|
|
787
|
+
toolApprovalPolicy?: ToolApprovalPolicy;
|
|
788
|
+
maxSteps?: number;
|
|
789
|
+
temperature?: number;
|
|
790
|
+
maxTokens?: number;
|
|
791
|
+
reasoning?: ReasoningConfig;
|
|
792
|
+
providerOptions?: ProviderOptionsOf<TModel>;
|
|
793
|
+
metadata?: Record<string, JsonValue>;
|
|
794
|
+
};
|
|
795
|
+
export interface AgentRunOutput {
|
|
796
|
+
status: AgentStatus;
|
|
797
|
+
outputText: string;
|
|
798
|
+
finishReason?: FinishReason;
|
|
799
|
+
providerFinishReason?: string;
|
|
800
|
+
usage?: TokenUsage;
|
|
801
|
+
messages: ModelMessage[];
|
|
802
|
+
steps: AgentStep[];
|
|
803
|
+
toolResults: ToolExecutionResult[];
|
|
804
|
+
state: AgentRunState;
|
|
805
|
+
error?: {
|
|
806
|
+
message: string;
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
export type LiveAgentRunInput = GenerateInputSource & RetryOptions & {
|
|
810
|
+
runId?: string;
|
|
811
|
+
system?: string;
|
|
812
|
+
tools?: ToolCollection;
|
|
813
|
+
toolChoice?: ToolChoice;
|
|
814
|
+
toolExecution?: ToolExecutionOptions;
|
|
815
|
+
toolApprovalPolicy?: ToolApprovalPolicy;
|
|
816
|
+
providerOptions?: ProviderOptions;
|
|
817
|
+
metadata?: Record<string, JsonValue>;
|
|
818
|
+
realtime?: RealtimeSessionConfig;
|
|
819
|
+
connectOptions?: RealtimeConnectOptions;
|
|
820
|
+
};
|
|
821
|
+
export interface LiveAgentRunOutput {
|
|
822
|
+
status: AgentStatus;
|
|
823
|
+
outputText: string;
|
|
824
|
+
messages: ModelMessage[];
|
|
825
|
+
toolResults: ToolExecutionResult[];
|
|
826
|
+
state: AgentRunState;
|
|
827
|
+
error?: {
|
|
828
|
+
message: string;
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
export interface AgentStreamResult {
|
|
832
|
+
eventStream: AsyncIterable<AgentStreamEvent>;
|
|
833
|
+
textStream: AsyncIterable<string>;
|
|
834
|
+
collect: () => Promise<AgentRunOutput>;
|
|
835
|
+
}
|
|
836
|
+
export type AgentLiveEvent = AgentStreamEvent | RealtimeEvent;
|
|
837
|
+
export interface AgentLiveStreamResult {
|
|
838
|
+
eventStream: AsyncIterable<AgentLiveEvent>;
|
|
839
|
+
textStream: AsyncIterable<string>;
|
|
840
|
+
session: Promise<RealtimeSession>;
|
|
841
|
+
collect: () => Promise<LiveAgentRunOutput>;
|
|
842
|
+
}
|
|
293
843
|
export type TranscribeAudioOptions<TModel extends TranscriptionModel = TranscriptionModel> = RetryOptions & {
|
|
294
844
|
model: TModel;
|
|
295
845
|
audio: AudioInput;
|
|
@@ -468,6 +1018,13 @@ export interface UIMessageToolResultChunk {
|
|
|
468
1018
|
role: "tool";
|
|
469
1019
|
toolResult: ToolExecutionResult;
|
|
470
1020
|
}
|
|
1021
|
+
export interface UIMessageProviderDataChunk {
|
|
1022
|
+
type: "provider-data";
|
|
1023
|
+
messageId: string;
|
|
1024
|
+
role: "assistant";
|
|
1025
|
+
provider: string;
|
|
1026
|
+
data: JsonValue;
|
|
1027
|
+
}
|
|
471
1028
|
export interface UIMessageFinishChunk {
|
|
472
1029
|
type: "finish";
|
|
473
1030
|
messageId: string;
|
|
@@ -482,7 +1039,33 @@ export interface UIMessageErrorChunk {
|
|
|
482
1039
|
message: string;
|
|
483
1040
|
};
|
|
484
1041
|
}
|
|
485
|
-
export
|
|
1042
|
+
export interface UIAgentRunStartChunk {
|
|
1043
|
+
type: "agent-run-start";
|
|
1044
|
+
currentStep: number;
|
|
1045
|
+
maxSteps: number;
|
|
1046
|
+
}
|
|
1047
|
+
export interface UIAgentStepStartChunk {
|
|
1048
|
+
type: "agent-step-start";
|
|
1049
|
+
stepIndex: number;
|
|
1050
|
+
}
|
|
1051
|
+
export interface UIAgentStepFinishChunk {
|
|
1052
|
+
type: "agent-step-finish";
|
|
1053
|
+
step: AgentStep;
|
|
1054
|
+
}
|
|
1055
|
+
export interface UIAgentApprovalRequestChunk {
|
|
1056
|
+
type: "agent-approval-request";
|
|
1057
|
+
approval: AgentApprovalRequest;
|
|
1058
|
+
}
|
|
1059
|
+
export interface UIAgentApprovalResolvedChunk {
|
|
1060
|
+
type: "agent-approval-resolved";
|
|
1061
|
+
approval: AgentApprovalResponse;
|
|
1062
|
+
}
|
|
1063
|
+
export interface UIAgentRunFinishChunk {
|
|
1064
|
+
type: "agent-run-finish";
|
|
1065
|
+
status: AgentStatus;
|
|
1066
|
+
state: AgentRunState;
|
|
1067
|
+
}
|
|
1068
|
+
export type UIMessageChunk = UIMessageTextChunk | UIMessageToolCallChunk | UIMessageToolResultChunk | UIMessageProviderDataChunk | UIMessageFinishChunk | UIMessageErrorChunk | UIAgentRunStartChunk | UIAgentStepStartChunk | UIAgentStepFinishChunk | UIAgentApprovalRequestChunk | UIAgentApprovalResolvedChunk | UIAgentRunFinishChunk;
|
|
486
1069
|
export interface EmbedInput {
|
|
487
1070
|
values: string[];
|
|
488
1071
|
}
|