@radaros/core 0.3.1 → 0.3.3

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/index.d.ts DELETED
@@ -1,1283 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- type MessageRole = "system" | "user" | "assistant" | "tool";
4
- interface TextPart {
5
- type: "text";
6
- text: string;
7
- }
8
- interface ImagePart {
9
- type: "image";
10
- /** Base64-encoded image data OR a URL. */
11
- data: string;
12
- mimeType?: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
13
- }
14
- interface AudioPart {
15
- type: "audio";
16
- /** Base64-encoded audio data. */
17
- data: string;
18
- mimeType?: "audio/mp3" | "audio/wav" | "audio/ogg" | "audio/webm";
19
- }
20
- interface FilePart {
21
- type: "file";
22
- /** Base64-encoded file data OR a URL. */
23
- data: string;
24
- mimeType: string;
25
- filename?: string;
26
- }
27
- type ContentPart = TextPart | ImagePart | AudioPart | FilePart;
28
- /** Convenience: plain string, or an array of multi-modal content parts. */
29
- type MessageContent = string | ContentPart[];
30
- interface ChatMessage {
31
- role: MessageRole;
32
- content: MessageContent | null;
33
- toolCalls?: ToolCall[];
34
- toolCallId?: string;
35
- name?: string;
36
- }
37
- interface ToolCall {
38
- id: string;
39
- name: string;
40
- arguments: Record<string, unknown>;
41
- }
42
- interface ToolDefinition {
43
- name: string;
44
- description: string;
45
- parameters: Record<string, unknown>;
46
- }
47
- interface TokenUsage {
48
- promptTokens: number;
49
- completionTokens: number;
50
- totalTokens: number;
51
- }
52
- interface ModelResponse {
53
- message: ChatMessage;
54
- usage: TokenUsage;
55
- finishReason: "stop" | "tool_calls" | "length" | "content_filter";
56
- raw: unknown;
57
- }
58
- type StreamChunk = {
59
- type: "text";
60
- text: string;
61
- } | {
62
- type: "tool_call_start";
63
- toolCall: {
64
- id: string;
65
- name: string;
66
- };
67
- } | {
68
- type: "tool_call_delta";
69
- toolCallId: string;
70
- argumentsDelta: string;
71
- } | {
72
- type: "tool_call_end";
73
- toolCallId: string;
74
- } | {
75
- type: "finish";
76
- finishReason: string;
77
- usage?: TokenUsage;
78
- };
79
- interface ModelConfig {
80
- temperature?: number;
81
- maxTokens?: number;
82
- topP?: number;
83
- stop?: string[];
84
- responseFormat?: "text" | "json" | {
85
- type: "json_schema";
86
- schema: Record<string, unknown>;
87
- name?: string;
88
- };
89
- /** Per-request API key override. When provided, the provider uses this key instead of the one set at construction. */
90
- apiKey?: string;
91
- }
92
- /** Extract the text content from a MessageContent value. */
93
- declare function getTextContent(content: MessageContent | null): string;
94
- /** Check if content has multi-modal parts. */
95
- declare function isMultiModal(content: MessageContent | null): content is ContentPart[];
96
-
97
- interface ModelProvider {
98
- readonly providerId: string;
99
- readonly modelId: string;
100
- generate(messages: ChatMessage[], options?: ModelConfig & {
101
- tools?: ToolDefinition[];
102
- }): Promise<ModelResponse>;
103
- stream(messages: ChatMessage[], options?: ModelConfig & {
104
- tools?: ToolDefinition[];
105
- }): AsyncGenerator<StreamChunk>;
106
- }
107
-
108
- declare class RunContext {
109
- readonly runId: string;
110
- readonly sessionId: string;
111
- readonly userId?: string;
112
- readonly metadata: Record<string, unknown>;
113
- readonly eventBus: EventBus;
114
- sessionState: Record<string, unknown>;
115
- constructor(opts: {
116
- sessionId: string;
117
- userId?: string;
118
- metadata?: Record<string, unknown>;
119
- eventBus: EventBus;
120
- sessionState?: Record<string, unknown>;
121
- runId?: string;
122
- });
123
- getState<T>(key: string): T | undefined;
124
- setState(key: string, value: unknown): void;
125
- }
126
-
127
- interface Artifact {
128
- type: string;
129
- data: unknown;
130
- mimeType?: string;
131
- }
132
- interface ToolResult {
133
- content: string;
134
- artifacts?: Artifact[];
135
- }
136
- interface ToolDef {
137
- name: string;
138
- description: string;
139
- parameters: z.ZodObject<any>;
140
- execute: (args: Record<string, unknown>, ctx: RunContext) => Promise<string | ToolResult>;
141
- /** Raw JSON Schema to send to the LLM, bypassing Zod-to-JSON conversion (used by MCP tools). */
142
- rawJsonSchema?: Record<string, unknown>;
143
- }
144
- interface ToolCallResult {
145
- toolCallId: string;
146
- toolName: string;
147
- result: string | ToolResult;
148
- error?: string;
149
- }
150
-
151
- interface StorageDriver {
152
- get<T>(namespace: string, key: string): Promise<T | null>;
153
- set<T>(namespace: string, key: string, value: T): Promise<void>;
154
- delete(namespace: string, key: string): Promise<void>;
155
- list<T>(namespace: string, prefix?: string): Promise<Array<{
156
- key: string;
157
- value: T;
158
- }>>;
159
- close(): Promise<void>;
160
- }
161
-
162
- interface MemoryConfig {
163
- storage?: StorageDriver;
164
- maxShortTermMessages?: number;
165
- enableLongTerm?: boolean;
166
- }
167
- interface MemoryEntry {
168
- key: string;
169
- summary: string;
170
- createdAt: Date;
171
- }
172
-
173
- declare class Memory {
174
- private storage;
175
- private maxShortTermMessages;
176
- private enableLongTerm;
177
- constructor(config?: MemoryConfig);
178
- addMessages(sessionId: string, messages: ChatMessage[]): Promise<void>;
179
- getMessages(sessionId: string): Promise<ChatMessage[]>;
180
- getSummaries(sessionId: string): Promise<string[]>;
181
- getContextString(sessionId: string): Promise<string>;
182
- private summarizeAndStore;
183
- clear(sessionId: string): Promise<void>;
184
- }
185
-
186
- type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
187
- interface LoggerConfig {
188
- level?: LogLevel;
189
- color?: boolean;
190
- prefix?: string;
191
- }
192
- declare class Logger {
193
- private level;
194
- private color;
195
- private prefix;
196
- constructor(config?: LoggerConfig);
197
- private c;
198
- private shouldLog;
199
- private tag;
200
- private timestamp;
201
- private log;
202
- private formatValue;
203
- debug(msg: string, data?: Record<string, unknown>): void;
204
- info(msg: string, data?: Record<string, unknown>): void;
205
- warn(msg: string, data?: Record<string, unknown>): void;
206
- error(msg: string, data?: Record<string, unknown>): void;
207
- private readonly boxWidth;
208
- private pipe;
209
- private printBoxLine;
210
- agentStart(agentName: string, input: string): void;
211
- toolCall(toolName: string, args: Record<string, unknown>): void;
212
- toolResult(toolName: string, result: string): void;
213
- agentEnd(agentName: string, output: string, usage: {
214
- promptTokens: number;
215
- completionTokens: number;
216
- totalTokens: number;
217
- }, durationMs: number): void;
218
- separator(): void;
219
- private formatDuration;
220
- }
221
-
222
- interface AgentConfig {
223
- name: string;
224
- model: ModelProvider;
225
- tools?: ToolDef[];
226
- instructions?: string | ((ctx: RunContext) => string);
227
- memory?: Memory;
228
- storage?: StorageDriver;
229
- sessionId?: string;
230
- userId?: string;
231
- addHistoryToMessages?: boolean;
232
- numHistoryRuns?: number;
233
- maxToolRoundtrips?: number;
234
- temperature?: number;
235
- structuredOutput?: z.ZodSchema;
236
- hooks?: AgentHooks;
237
- guardrails?: {
238
- input?: InputGuardrail[];
239
- output?: OutputGuardrail[];
240
- };
241
- eventBus?: EventBus;
242
- /** Logging level. Set to "debug" for tool call details, "info" for summaries, "silent" to disable. Default: "silent". */
243
- logLevel?: LogLevel;
244
- }
245
- interface RunOpts {
246
- sessionId?: string;
247
- userId?: string;
248
- metadata?: Record<string, unknown>;
249
- /** Per-request API key override passed to the model provider. */
250
- apiKey?: string;
251
- }
252
- interface RunOutput {
253
- text: string;
254
- toolCalls: ToolCallResult[];
255
- usage: TokenUsage;
256
- /** Parsed structured output if structuredOutput schema is set. */
257
- structured?: unknown;
258
- durationMs?: number;
259
- }
260
- interface AgentHooks {
261
- beforeRun?: (ctx: RunContext) => Promise<void>;
262
- afterRun?: (ctx: RunContext, output: RunOutput) => Promise<void>;
263
- onToolCall?: (ctx: RunContext, toolName: string, args: unknown) => Promise<void>;
264
- onError?: (ctx: RunContext, error: Error) => Promise<void>;
265
- }
266
- type GuardrailResult = {
267
- pass: true;
268
- } | {
269
- pass: false;
270
- reason: string;
271
- };
272
- interface InputGuardrail {
273
- name: string;
274
- validate: (input: MessageContent, ctx: RunContext) => Promise<GuardrailResult>;
275
- }
276
- interface OutputGuardrail {
277
- name: string;
278
- validate: (output: RunOutput, ctx: RunContext) => Promise<GuardrailResult>;
279
- }
280
-
281
- type AgentEventMap = {
282
- "run.start": {
283
- runId: string;
284
- agentName: string;
285
- input: string;
286
- };
287
- "run.complete": {
288
- runId: string;
289
- output: RunOutput;
290
- };
291
- "run.error": {
292
- runId: string;
293
- error: Error;
294
- };
295
- "run.stream.chunk": {
296
- runId: string;
297
- chunk: string;
298
- };
299
- "tool.call": {
300
- runId: string;
301
- toolName: string;
302
- args: unknown;
303
- };
304
- "tool.result": {
305
- runId: string;
306
- toolName: string;
307
- result: unknown;
308
- };
309
- "team.delegate": {
310
- runId: string;
311
- memberId: string;
312
- task: string;
313
- };
314
- "workflow.step": {
315
- runId: string;
316
- stepName: string;
317
- status: "start" | "done" | "error";
318
- };
319
- };
320
-
321
- type EventKey = keyof AgentEventMap;
322
- declare class EventBus {
323
- private emitter;
324
- constructor();
325
- on<K extends EventKey>(event: K, handler: (data: AgentEventMap[K]) => void): this;
326
- once<K extends EventKey>(event: K, handler: (data: AgentEventMap[K]) => void): this;
327
- off<K extends EventKey>(event: K, handler: (data: AgentEventMap[K]) => void): this;
328
- emit<K extends EventKey>(event: K, data: AgentEventMap[K]): boolean;
329
- removeAllListeners(event?: EventKey): this;
330
- }
331
-
332
- declare class Agent {
333
- readonly name: string;
334
- readonly eventBus: EventBus;
335
- readonly instructions?: string | ((ctx: RunContext) => string);
336
- private config;
337
- private sessionManager;
338
- private llmLoop;
339
- private logger;
340
- get tools(): ToolDef[];
341
- get modelId(): string;
342
- get providerId(): string;
343
- get hasStructuredOutput(): boolean;
344
- constructor(config: AgentConfig);
345
- run(input: MessageContent, opts?: RunOpts): Promise<RunOutput>;
346
- stream(input: MessageContent, opts?: RunOpts): AsyncGenerator<StreamChunk>;
347
- private buildMessages;
348
- }
349
-
350
- declare class ToolExecutor {
351
- private tools;
352
- private concurrency;
353
- constructor(tools: ToolDef[], concurrency?: number);
354
- executeAll(toolCalls: ToolCall[], ctx: RunContext): Promise<ToolCallResult[]>;
355
- private executeSingle;
356
- getToolDefinitions(): Array<{
357
- name: string;
358
- description: string;
359
- parameters: Record<string, unknown>;
360
- }>;
361
- }
362
-
363
- declare class LLMLoop {
364
- private provider;
365
- private toolExecutor;
366
- private maxToolRoundtrips;
367
- private temperature?;
368
- private maxTokens?;
369
- private structuredOutput?;
370
- private logger?;
371
- constructor(provider: ModelProvider, toolExecutor: ToolExecutor | null, options: {
372
- maxToolRoundtrips: number;
373
- temperature?: number;
374
- maxTokens?: number;
375
- structuredOutput?: z.ZodSchema;
376
- logger?: Logger;
377
- });
378
- run(messages: ChatMessage[], ctx: RunContext, apiKey?: string): Promise<RunOutput>;
379
- stream(messages: ChatMessage[], ctx: RunContext, apiKey?: string): AsyncGenerator<StreamChunk>;
380
- private extractJson;
381
- private zodToJsonSchema;
382
- }
383
-
384
- declare enum TeamMode {
385
- Coordinate = "coordinate",
386
- Route = "route",
387
- Broadcast = "broadcast",
388
- Collaborate = "collaborate"
389
- }
390
- interface TeamConfig {
391
- name: string;
392
- mode: TeamMode;
393
- model: ModelProvider;
394
- members: Agent[];
395
- instructions?: string;
396
- sessionState?: Record<string, unknown>;
397
- storage?: StorageDriver;
398
- maxRounds?: number;
399
- eventBus?: EventBus;
400
- }
401
-
402
- declare class Team {
403
- readonly name: string;
404
- readonly eventBus: EventBus;
405
- private config;
406
- constructor(config: TeamConfig);
407
- run(input: string, opts?: RunOpts): Promise<RunOutput>;
408
- stream(input: string, opts?: RunOpts): AsyncGenerator<StreamChunk>;
409
- private runCoordinateMode;
410
- private runRouteMode;
411
- private runBroadcastMode;
412
- private runCollaborateMode;
413
- private buildMemberDescriptions;
414
- private buildCoordinatorPrompt;
415
- private buildSynthesisPrompt;
416
- private parseDelegationPlan;
417
- private findMember;
418
- }
419
-
420
- type StepDef<TState> = AgentStep<TState> | FunctionStep<TState> | ConditionStep<TState> | ParallelStep<TState>;
421
- interface AgentStep<TState> {
422
- name: string;
423
- agent: Agent;
424
- inputFrom?: (state: TState) => string;
425
- }
426
- interface FunctionStep<TState> {
427
- name: string;
428
- run: (state: TState, ctx: RunContext) => Promise<Partial<TState>>;
429
- }
430
- interface ConditionStep<TState> {
431
- name: string;
432
- condition: (state: TState) => boolean;
433
- steps: StepDef<TState>[];
434
- }
435
- interface ParallelStep<TState> {
436
- name: string;
437
- parallel: StepDef<TState>[];
438
- }
439
- interface WorkflowConfig<TState extends Record<string, unknown> = Record<string, unknown>> {
440
- name: string;
441
- initialState: TState;
442
- steps: StepDef<TState>[];
443
- storage?: StorageDriver;
444
- retryPolicy?: {
445
- maxRetries: number;
446
- backoffMs: number;
447
- };
448
- eventBus?: EventBus;
449
- }
450
- interface WorkflowResult<TState> {
451
- state: TState;
452
- stepResults: StepResult[];
453
- }
454
- interface StepResult {
455
- stepName: string;
456
- status: "done" | "error" | "skipped";
457
- error?: string;
458
- durationMs: number;
459
- }
460
-
461
- declare class Workflow<TState extends Record<string, unknown> = Record<string, unknown>> {
462
- readonly name: string;
463
- readonly eventBus: EventBus;
464
- private config;
465
- private stepRunner;
466
- constructor(config: WorkflowConfig<TState>);
467
- run(opts?: {
468
- sessionId?: string;
469
- userId?: string;
470
- }): Promise<WorkflowResult<TState>>;
471
- }
472
-
473
- type ProviderFactory = (modelId: string, config?: Record<string, unknown>) => ModelProvider;
474
- declare class ModelRegistry {
475
- private factories;
476
- register(providerId: string, factory: ProviderFactory): void;
477
- resolve(providerId: string, modelId: string, config?: Record<string, unknown>): ModelProvider;
478
- has(providerId: string): boolean;
479
- }
480
- declare const registry: ModelRegistry;
481
- declare function openai(modelId: string, config?: {
482
- apiKey?: string;
483
- baseURL?: string;
484
- }): ModelProvider;
485
- declare function anthropic(modelId: string, config?: {
486
- apiKey?: string;
487
- }): ModelProvider;
488
- declare function google(modelId: string, config?: {
489
- apiKey?: string;
490
- }): ModelProvider;
491
- declare function ollama(modelId: string, config?: {
492
- host?: string;
493
- }): ModelProvider;
494
- declare function vertex(modelId: string, config?: {
495
- project?: string;
496
- location?: string;
497
- credentials?: string;
498
- }): ModelProvider;
499
-
500
- interface OpenAIConfig {
501
- apiKey?: string;
502
- baseURL?: string;
503
- }
504
- declare class OpenAIProvider implements ModelProvider {
505
- readonly providerId = "openai";
506
- readonly modelId: string;
507
- private client;
508
- private OpenAICtor;
509
- private baseURL?;
510
- private clientCache;
511
- constructor(modelId: string, config?: OpenAIConfig);
512
- private getClient;
513
- generate(messages: ChatMessage[], options?: ModelConfig & {
514
- tools?: ToolDefinition[];
515
- }): Promise<ModelResponse>;
516
- stream(messages: ChatMessage[], options?: ModelConfig & {
517
- tools?: ToolDefinition[];
518
- }): AsyncGenerator<StreamChunk>;
519
- private applyResponseFormat;
520
- private toOpenAIMessages;
521
- private partToOpenAI;
522
- private toOpenAITools;
523
- private normalizeResponse;
524
- }
525
-
526
- interface AnthropicConfig {
527
- apiKey?: string;
528
- }
529
- declare class AnthropicProvider implements ModelProvider {
530
- readonly providerId = "anthropic";
531
- readonly modelId: string;
532
- private client;
533
- private AnthropicCtor;
534
- private clientCache;
535
- constructor(modelId: string, config?: AnthropicConfig);
536
- private getClient;
537
- generate(messages: ChatMessage[], options?: ModelConfig & {
538
- tools?: ToolDefinition[];
539
- }): Promise<ModelResponse>;
540
- stream(messages: ChatMessage[], options?: ModelConfig & {
541
- tools?: ToolDefinition[];
542
- }): AsyncGenerator<StreamChunk>;
543
- private toAnthropicMessages;
544
- private partToAnthropic;
545
- private toAnthropicTools;
546
- private normalizeResponse;
547
- }
548
-
549
- interface GoogleConfig {
550
- apiKey?: string;
551
- }
552
- declare class GoogleProvider implements ModelProvider {
553
- readonly providerId = "google";
554
- readonly modelId: string;
555
- private ai;
556
- private GoogleGenAICtor;
557
- private clientCache;
558
- constructor(modelId: string, config?: GoogleConfig);
559
- private getClient;
560
- generate(messages: ChatMessage[], options?: ModelConfig & {
561
- tools?: ToolDefinition[];
562
- }): Promise<ModelResponse>;
563
- stream(messages: ChatMessage[], options?: ModelConfig & {
564
- tools?: ToolDefinition[];
565
- }): AsyncGenerator<StreamChunk>;
566
- private toGoogleMessages;
567
- private partToGoogle;
568
- private toGoogleTools;
569
- private cleanJsonSchema;
570
- private normalizeResponse;
571
- }
572
-
573
- interface OllamaConfig {
574
- host?: string;
575
- }
576
- declare class OllamaProvider implements ModelProvider {
577
- readonly providerId = "ollama";
578
- readonly modelId: string;
579
- private client;
580
- constructor(modelId: string, config?: OllamaConfig);
581
- generate(messages: ChatMessage[], options?: ModelConfig & {
582
- tools?: ToolDefinition[];
583
- }): Promise<ModelResponse>;
584
- stream(messages: ChatMessage[], options?: ModelConfig & {
585
- tools?: ToolDefinition[];
586
- }): AsyncGenerator<StreamChunk>;
587
- private toOllamaMessages;
588
- private toOllamaTools;
589
- private normalizeResponse;
590
- }
591
-
592
- interface VertexAIConfig {
593
- project?: string;
594
- location?: string;
595
- /** Service account key JSON string or path (optional — uses ADC by default). */
596
- credentials?: string;
597
- }
598
- /**
599
- * Vertex AI provider using Google's @google/genai SDK in Vertex mode.
600
- *
601
- * Authentication (in order of precedence):
602
- * 1. Explicit `project` + `location` in config
603
- * 2. GOOGLE_CLOUD_PROJECT / GOOGLE_CLOUD_LOCATION env vars
604
- * 3. Application Default Credentials (gcloud auth)
605
- */
606
- declare class VertexAIProvider implements ModelProvider {
607
- readonly providerId = "vertex";
608
- readonly modelId: string;
609
- private ai;
610
- private GoogleGenAICtor;
611
- private project;
612
- private location;
613
- constructor(modelId: string, config?: VertexAIConfig);
614
- private getClient;
615
- generate(messages: ChatMessage[], options?: ModelConfig & {
616
- tools?: ToolDefinition[];
617
- }): Promise<ModelResponse>;
618
- stream(messages: ChatMessage[], options?: ModelConfig & {
619
- tools?: ToolDefinition[];
620
- }): AsyncGenerator<StreamChunk>;
621
- private toGoogleMessages;
622
- private partToGoogle;
623
- private toGoogleTools;
624
- private cleanJsonSchema;
625
- private normalizeResponse;
626
- }
627
-
628
- declare function defineTool<T extends z.ZodObject<any>>(config: {
629
- name: string;
630
- description: string;
631
- parameters: T;
632
- execute: (args: z.infer<T>, ctx: RunContext) => Promise<string | ToolResult>;
633
- }): ToolDef;
634
-
635
- declare class InMemoryStorage implements StorageDriver {
636
- private store;
637
- private makeKey;
638
- get<T>(namespace: string, key: string): Promise<T | null>;
639
- set<T>(namespace: string, key: string, value: T): Promise<void>;
640
- delete(namespace: string, key: string): Promise<void>;
641
- list<T>(namespace: string, prefix?: string): Promise<Array<{
642
- key: string;
643
- value: T;
644
- }>>;
645
- close(): Promise<void>;
646
- }
647
-
648
- declare class SqliteStorage implements StorageDriver {
649
- private db;
650
- constructor(dbPath: string);
651
- get<T>(namespace: string, key: string): Promise<T | null>;
652
- set<T>(namespace: string, key: string, value: T): Promise<void>;
653
- delete(namespace: string, key: string): Promise<void>;
654
- list<T>(namespace: string, prefix?: string): Promise<Array<{
655
- key: string;
656
- value: T;
657
- }>>;
658
- close(): Promise<void>;
659
- }
660
-
661
- declare class PostgresStorage implements StorageDriver {
662
- private pool;
663
- constructor(connectionString: string);
664
- initialize(): Promise<void>;
665
- get<T>(namespace: string, key: string): Promise<T | null>;
666
- set<T>(namespace: string, key: string, value: T): Promise<void>;
667
- delete(namespace: string, key: string): Promise<void>;
668
- list<T>(namespace: string, prefix?: string): Promise<Array<{
669
- key: string;
670
- value: T;
671
- }>>;
672
- close(): Promise<void>;
673
- }
674
-
675
- declare class MongoDBStorage implements StorageDriver {
676
- private uri;
677
- private dbName;
678
- private collectionName;
679
- private client;
680
- private db;
681
- private collection;
682
- constructor(uri: string, dbName?: string, collectionName?: string);
683
- initialize(): Promise<void>;
684
- get<T>(namespace: string, key: string): Promise<T | null>;
685
- set<T>(namespace: string, key: string, value: T): Promise<void>;
686
- delete(namespace: string, key: string): Promise<void>;
687
- list<T>(namespace: string, prefix?: string): Promise<Array<{
688
- key: string;
689
- value: T;
690
- }>>;
691
- close(): Promise<void>;
692
- }
693
-
694
- interface VectorDocument {
695
- id: string;
696
- content: string;
697
- embedding?: number[];
698
- metadata?: Record<string, unknown>;
699
- }
700
- interface VectorSearchResult {
701
- id: string;
702
- content: string;
703
- score: number;
704
- metadata?: Record<string, unknown>;
705
- }
706
- interface VectorSearchOptions {
707
- topK?: number;
708
- filter?: Record<string, unknown>;
709
- minScore?: number;
710
- }
711
- interface EmbeddingProvider {
712
- readonly dimensions: number;
713
- embed(text: string): Promise<number[]>;
714
- embedBatch(texts: string[]): Promise<number[][]>;
715
- }
716
- interface VectorStore {
717
- /** Initialize collections/indexes. Call once before use. */
718
- initialize(): Promise<void>;
719
- /** Upsert a single document (embedding computed if not provided). */
720
- upsert(collection: string, doc: VectorDocument): Promise<void>;
721
- /** Upsert multiple documents in batch. */
722
- upsertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
723
- /** Similarity search by vector or text query. */
724
- search(collection: string, query: number[] | string, options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
725
- /** Delete a document by ID. */
726
- delete(collection: string, id: string): Promise<void>;
727
- /** Get a document by ID. */
728
- get(collection: string, id: string): Promise<VectorDocument | null>;
729
- /** Drop an entire collection. */
730
- dropCollection(collection: string): Promise<void>;
731
- /** Close connections. */
732
- close(): Promise<void>;
733
- }
734
-
735
- declare abstract class BaseVectorStore implements VectorStore {
736
- protected embedder?: EmbeddingProvider | undefined;
737
- constructor(embedder?: EmbeddingProvider | undefined);
738
- protected ensureEmbedding(doc: VectorDocument): Promise<number[]>;
739
- protected ensureQueryVector(query: number[] | string): Promise<number[]>;
740
- abstract initialize(): Promise<void>;
741
- abstract upsert(collection: string, doc: VectorDocument): Promise<void>;
742
- abstract upsertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
743
- abstract search(collection: string, query: number[] | string, options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
744
- abstract delete(collection: string, id: string): Promise<void>;
745
- abstract get(collection: string, id: string): Promise<VectorDocument | null>;
746
- abstract dropCollection(collection: string): Promise<void>;
747
- abstract close(): Promise<void>;
748
- }
749
-
750
- declare class InMemoryVectorStore extends BaseVectorStore {
751
- private collections;
752
- constructor(embedder?: EmbeddingProvider);
753
- initialize(): Promise<void>;
754
- private getCol;
755
- upsert(collection: string, doc: VectorDocument): Promise<void>;
756
- upsertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
757
- search(collection: string, query: number[] | string, options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
758
- private cosineSimilarity;
759
- delete(collection: string, id: string): Promise<void>;
760
- get(collection: string, id: string): Promise<VectorDocument | null>;
761
- dropCollection(collection: string): Promise<void>;
762
- close(): Promise<void>;
763
- }
764
-
765
- interface PgVectorConfig {
766
- connectionString: string;
767
- dimensions?: number;
768
- }
769
- declare class PgVectorStore extends BaseVectorStore {
770
- private pool;
771
- private dimensions;
772
- private initializedCollections;
773
- constructor(config: PgVectorConfig, embedder?: EmbeddingProvider);
774
- initialize(): Promise<void>;
775
- private ensureCollection;
776
- private sanitize;
777
- private toSql;
778
- upsert(collection: string, doc: VectorDocument): Promise<void>;
779
- upsertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
780
- search(collection: string, query: number[] | string, options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
781
- delete(collection: string, id: string): Promise<void>;
782
- get(collection: string, id: string): Promise<VectorDocument | null>;
783
- dropCollection(collection: string): Promise<void>;
784
- close(): Promise<void>;
785
- }
786
-
787
- interface QdrantConfig {
788
- url?: string;
789
- apiKey?: string;
790
- dimensions?: number;
791
- checkCompatibility?: boolean;
792
- }
793
- declare class QdrantVectorStore extends BaseVectorStore {
794
- private client;
795
- private dimensions;
796
- private initializedCollections;
797
- constructor(config?: QdrantConfig, embedder?: EmbeddingProvider);
798
- initialize(): Promise<void>;
799
- private ensureCollection;
800
- upsert(collection: string, doc: VectorDocument): Promise<void>;
801
- upsertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
802
- search(collection: string, query: number[] | string, options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
803
- delete(collection: string, id: string): Promise<void>;
804
- get(collection: string, id: string): Promise<VectorDocument | null>;
805
- dropCollection(collection: string): Promise<void>;
806
- close(): Promise<void>;
807
- }
808
-
809
- interface MongoDBVectorConfig {
810
- uri: string;
811
- dbName?: string;
812
- /** Atlas Search index name (must be pre-created for $vectorSearch). Defaults to "vector_index". */
813
- indexName?: string;
814
- }
815
- declare class MongoDBVectorStore extends BaseVectorStore {
816
- private client;
817
- private db;
818
- private indexName;
819
- private dbName;
820
- private useAtlas;
821
- constructor(config: MongoDBVectorConfig, embedder?: EmbeddingProvider);
822
- initialize(): Promise<void>;
823
- private col;
824
- upsert(collection: string, doc: VectorDocument): Promise<void>;
825
- upsertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
826
- search(collection: string, query: number[] | string, options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
827
- private atlasSearch;
828
- private localSearch;
829
- private buildFilter;
830
- delete(collection: string, id: string): Promise<void>;
831
- get(collection: string, id: string): Promise<VectorDocument | null>;
832
- dropCollection(collection: string): Promise<void>;
833
- close(): Promise<void>;
834
- }
835
-
836
- interface OpenAIEmbeddingConfig {
837
- apiKey?: string;
838
- baseURL?: string;
839
- model?: string;
840
- dimensions?: number;
841
- }
842
- declare class OpenAIEmbedding implements EmbeddingProvider {
843
- readonly dimensions: number;
844
- private client;
845
- private model;
846
- constructor(config?: OpenAIEmbeddingConfig);
847
- embed(text: string): Promise<number[]>;
848
- embedBatch(texts: string[]): Promise<number[][]>;
849
- }
850
-
851
- interface GoogleEmbeddingConfig {
852
- apiKey?: string;
853
- model?: string;
854
- dimensions?: number;
855
- }
856
- declare class GoogleEmbedding implements EmbeddingProvider {
857
- readonly dimensions: number;
858
- private ai;
859
- private model;
860
- constructor(config?: GoogleEmbeddingConfig);
861
- embed(text: string): Promise<number[]>;
862
- embedBatch(texts: string[]): Promise<number[][]>;
863
- }
864
-
865
- interface KnowledgeBaseConfig {
866
- /** Display name used in tool description auto-generation. */
867
- name: string;
868
- /** The underlying vector store (any backend). */
869
- vectorStore: VectorStore;
870
- /** Collection/index name inside the vector store. */
871
- collection?: string;
872
- }
873
- interface KnowledgeBaseToolConfig {
874
- /** Tool name exposed to the LLM. Defaults to `search_<collection>`. */
875
- toolName?: string;
876
- /** Custom tool description. A sensible default is generated from the KB name. */
877
- description?: string;
878
- /** Number of results to return per search. Default 5. */
879
- topK?: number;
880
- /** Minimum similarity score to include. */
881
- minScore?: number;
882
- /** Metadata filter applied to every search. */
883
- filter?: Record<string, unknown>;
884
- /** Custom formatter for search results. Defaults to numbered list with scores. */
885
- formatResults?: (results: VectorSearchResult[]) => string;
886
- }
887
- declare class KnowledgeBase {
888
- readonly name: string;
889
- readonly collection: string;
890
- private store;
891
- private initialized;
892
- constructor(config: KnowledgeBaseConfig);
893
- initialize(): Promise<void>;
894
- add(doc: VectorDocument): Promise<void>;
895
- addDocuments(docs: VectorDocument[]): Promise<void>;
896
- search(query: string, options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
897
- get(id: string): Promise<VectorDocument | null>;
898
- delete(id: string): Promise<void>;
899
- clear(): Promise<void>;
900
- close(): Promise<void>;
901
- /**
902
- * Returns a ToolDef that an Agent can use to search this knowledge base.
903
- * Plug the result directly into `Agent({ tools: [kb.asTool()] })`.
904
- */
905
- asTool(config?: KnowledgeBaseToolConfig): ToolDef;
906
- private ensureInit;
907
- }
908
-
909
- interface Session {
910
- sessionId: string;
911
- userId?: string;
912
- messages: ChatMessage[];
913
- state: Record<string, unknown>;
914
- createdAt: Date;
915
- updatedAt: Date;
916
- }
917
-
918
- declare class SessionManager {
919
- private storage;
920
- constructor(storage: StorageDriver);
921
- getOrCreate(sessionId: string, userId?: string): Promise<Session>;
922
- appendMessage(sessionId: string, msg: ChatMessage): Promise<void>;
923
- appendMessages(sessionId: string, msgs: ChatMessage[]): Promise<void>;
924
- getHistory(sessionId: string, limit?: number): Promise<ChatMessage[]>;
925
- updateState(sessionId: string, patch: Record<string, unknown>): Promise<void>;
926
- getState(sessionId: string): Promise<Record<string, unknown>>;
927
- deleteSession(sessionId: string): Promise<void>;
928
- }
929
-
930
- interface MCPToolProviderConfig {
931
- name: string;
932
- transport: "stdio" | "http";
933
- /** For stdio transport: command to spawn */
934
- command?: string;
935
- /** For stdio transport: args for the command */
936
- args?: string[];
937
- /** For stdio transport: environment variables */
938
- env?: Record<string, string>;
939
- /** For http transport: server URL */
940
- url?: string;
941
- /** For http transport: custom headers */
942
- headers?: Record<string, string>;
943
- }
944
- /**
945
- * Connects to an MCP (Model Context Protocol) server and exposes its tools
946
- * as native RadarOS ToolDef[] that any Agent can use.
947
- *
948
- * Supports stdio and HTTP (Streamable HTTP) transports.
949
- * Requires: npm install @modelcontextprotocol/sdk
950
- */
951
- declare class MCPToolProvider {
952
- readonly name: string;
953
- private config;
954
- private client;
955
- private transportInstance;
956
- private tools;
957
- private connected;
958
- constructor(config: MCPToolProviderConfig);
959
- connect(): Promise<void>;
960
- private discoverTools;
961
- private jsonSchemaToZod;
962
- /**
963
- * Returns tools from this MCP server as RadarOS ToolDef[].
964
- * Optionally filter by tool names to reduce token usage.
965
- *
966
- * @param filter - Tool names to include (without the server name prefix).
967
- * If omitted, returns all tools.
968
- *
969
- * @example
970
- * // All tools
971
- * await mcp.getTools()
972
- *
973
- * // Only specific tools (pass the original MCP tool names, not prefixed)
974
- * await mcp.getTools({ include: ["get_latest_release", "search_repositories"] })
975
- *
976
- * // Exclude specific tools
977
- * await mcp.getTools({ exclude: ["push_files", "create_repository"] })
978
- */
979
- getTools(filter?: {
980
- include?: string[];
981
- exclude?: string[];
982
- }): Promise<ToolDef[]>;
983
- /** Refresh the tool list from the MCP server. */
984
- refresh(): Promise<void>;
985
- /** Disconnect from the MCP server. */
986
- close(): Promise<void>;
987
- }
988
-
989
- /**
990
- * A2A (Agent-to-Agent) Protocol types.
991
- * Based on the A2A specification v0.2.
992
- * https://google.github.io/A2A/specification/
993
- */
994
- interface A2ATextPart {
995
- kind: "text";
996
- text: string;
997
- }
998
- interface A2AFilePart {
999
- kind: "file";
1000
- file: {
1001
- name?: string;
1002
- mimeType?: string;
1003
- bytes?: string;
1004
- uri?: string;
1005
- };
1006
- }
1007
- interface A2ADataPart {
1008
- kind: "data";
1009
- data: Record<string, unknown>;
1010
- }
1011
- type A2APart = A2ATextPart | A2AFilePart | A2ADataPart;
1012
- interface A2AMessage {
1013
- role: "user" | "agent";
1014
- parts: A2APart[];
1015
- messageId?: string;
1016
- taskId?: string;
1017
- referenceTaskIds?: string[];
1018
- metadata?: Record<string, unknown>;
1019
- }
1020
- type A2ATaskState = "submitted" | "working" | "input-required" | "completed" | "failed" | "canceled";
1021
- interface A2AArtifact {
1022
- artifactId: string;
1023
- name?: string;
1024
- description?: string;
1025
- parts: A2APart[];
1026
- metadata?: Record<string, unknown>;
1027
- }
1028
- interface A2ATask {
1029
- id: string;
1030
- sessionId?: string;
1031
- status: {
1032
- state: A2ATaskState;
1033
- message?: A2AMessage;
1034
- timestamp?: string;
1035
- };
1036
- artifacts?: A2AArtifact[];
1037
- history?: A2AMessage[];
1038
- metadata?: Record<string, unknown>;
1039
- }
1040
- interface A2ASkill {
1041
- id: string;
1042
- name: string;
1043
- description?: string;
1044
- tags?: string[];
1045
- examples?: string[];
1046
- }
1047
- interface A2AAgentCard {
1048
- name: string;
1049
- description?: string;
1050
- url: string;
1051
- version?: string;
1052
- provider?: {
1053
- organization: string;
1054
- url?: string;
1055
- };
1056
- capabilities?: {
1057
- streaming?: boolean;
1058
- pushNotifications?: boolean;
1059
- stateTransitionHistory?: boolean;
1060
- };
1061
- authentication?: {
1062
- schemes?: string[];
1063
- credentials?: string;
1064
- };
1065
- skills?: A2ASkill[];
1066
- defaultInputModes?: string[];
1067
- defaultOutputModes?: string[];
1068
- supportedInputModes?: string[];
1069
- supportedOutputModes?: string[];
1070
- }
1071
- interface A2AJsonRpcRequest {
1072
- jsonrpc: "2.0";
1073
- id: string | number;
1074
- method: string;
1075
- params?: Record<string, unknown>;
1076
- }
1077
- interface A2AJsonRpcResponse {
1078
- jsonrpc: "2.0";
1079
- id: string | number;
1080
- result?: unknown;
1081
- error?: {
1082
- code: number;
1083
- message: string;
1084
- data?: unknown;
1085
- };
1086
- }
1087
- interface A2ASendParams {
1088
- message: A2AMessage;
1089
- configuration?: {
1090
- acceptedOutputModes?: string[];
1091
- blocking?: boolean;
1092
- };
1093
- metadata?: Record<string, unknown>;
1094
- }
1095
- interface A2ATaskQueryParams {
1096
- id: string;
1097
- historyLength?: number;
1098
- }
1099
-
1100
- interface A2ARemoteAgentConfig {
1101
- url: string;
1102
- /** Custom headers for every request (e.g. auth tokens). */
1103
- headers?: Record<string, string>;
1104
- /** Override the discovered name. */
1105
- name?: string;
1106
- /** Request timeout in ms (default 60000). */
1107
- timeoutMs?: number;
1108
- }
1109
- /**
1110
- * A2ARemoteAgent wraps a remote A2A-compliant agent.
1111
- * It can be used as a tool, a Team member, or called directly.
1112
- */
1113
- declare class A2ARemoteAgent {
1114
- readonly url: string;
1115
- name: string;
1116
- instructions: string;
1117
- skills: Array<{
1118
- id: string;
1119
- name: string;
1120
- description?: string;
1121
- }>;
1122
- private headers;
1123
- private timeoutMs;
1124
- private card;
1125
- private rpcId;
1126
- get tools(): ToolDef[];
1127
- get modelId(): string;
1128
- get providerId(): string;
1129
- get hasStructuredOutput(): boolean;
1130
- constructor(config: A2ARemoteAgentConfig);
1131
- /**
1132
- * Fetch the Agent Card from /.well-known/agent.json and populate metadata.
1133
- */
1134
- discover(): Promise<A2AAgentCard>;
1135
- /**
1136
- * Synchronous run: sends message/send and returns RunOutput.
1137
- */
1138
- run(input: string, opts?: RunOpts): Promise<RunOutput>;
1139
- /**
1140
- * Streaming run: sends message/stream and yields StreamChunks from SSE.
1141
- */
1142
- stream(input: string, opts?: RunOpts): AsyncGenerator<StreamChunk>;
1143
- /**
1144
- * Wrap this remote agent as a ToolDef so it can be used by an orchestrator agent.
1145
- */
1146
- asTool(): ToolDef;
1147
- getAgentCard(): A2AAgentCard | null;
1148
- private partsToText;
1149
- }
1150
-
1151
- /**
1152
- * Base class for all RadarOS Toolkits.
1153
- * A Toolkit is a collection of related tools that share configuration.
1154
- */
1155
- declare abstract class Toolkit {
1156
- abstract readonly name: string;
1157
- /**
1158
- * Returns all tools provided by this toolkit as ToolDef[].
1159
- * Spread them into an Agent's `tools` array.
1160
- */
1161
- abstract getTools(): ToolDef[];
1162
- }
1163
-
1164
- interface WebSearchConfig {
1165
- /** Search provider: "tavily" or "serpapi". */
1166
- provider: "tavily" | "serpapi";
1167
- /** API key for the search provider. Falls back to TAVILY_API_KEY or SERPAPI_API_KEY env vars. */
1168
- apiKey?: string;
1169
- /** Max results to return per search (default 5). */
1170
- maxResults?: number;
1171
- }
1172
- /**
1173
- * Web Search Toolkit — search the web from your agent.
1174
- *
1175
- * Supports Tavily and SerpAPI backends.
1176
- *
1177
- * @example
1178
- * ```ts
1179
- * const search = new WebSearchToolkit({ provider: "tavily" });
1180
- * const agent = new Agent({ tools: [...search.getTools()] });
1181
- * ```
1182
- */
1183
- declare class WebSearchToolkit extends Toolkit {
1184
- readonly name = "websearch";
1185
- private config;
1186
- constructor(config: WebSearchConfig);
1187
- private getApiKey;
1188
- getTools(): ToolDef[];
1189
- private searchTavily;
1190
- private searchSerpApi;
1191
- }
1192
-
1193
- interface GmailConfig {
1194
- /** Path to OAuth2 credentials JSON file. Falls back to GMAIL_CREDENTIALS_PATH env var. */
1195
- credentialsPath?: string;
1196
- /** Path to saved token JSON file. Falls back to GMAIL_TOKEN_PATH env var. */
1197
- tokenPath?: string;
1198
- /** Pre-authenticated OAuth2 client (if you handle auth yourself). */
1199
- authClient?: any;
1200
- }
1201
- /**
1202
- * Gmail Toolkit — send, search, and read emails from your agent.
1203
- *
1204
- * Requires: npm install googleapis
1205
- *
1206
- * @example
1207
- * ```ts
1208
- * const gmail = new GmailToolkit({ credentialsPath: "./credentials.json", tokenPath: "./token.json" });
1209
- * const agent = new Agent({ tools: [...gmail.getTools()] });
1210
- * ```
1211
- */
1212
- declare class GmailToolkit extends Toolkit {
1213
- readonly name = "gmail";
1214
- private config;
1215
- private gmail;
1216
- constructor(config?: GmailConfig);
1217
- private getGmailClient;
1218
- getTools(): ToolDef[];
1219
- }
1220
-
1221
- interface WhatsAppConfig {
1222
- /** WhatsApp Business API access token. Falls back to WHATSAPP_ACCESS_TOKEN env var. */
1223
- accessToken?: string;
1224
- /** WhatsApp Business phone number ID. Falls back to WHATSAPP_PHONE_NUMBER_ID env var. */
1225
- phoneNumberId?: string;
1226
- /** API version (default "v22.0"). Falls back to WHATSAPP_VERSION env var. */
1227
- version?: string;
1228
- /** Default recipient WhatsApp ID. Falls back to WHATSAPP_RECIPIENT_WAID env var. */
1229
- recipientWaid?: string;
1230
- }
1231
- /**
1232
- * WhatsApp Toolkit — send messages via WhatsApp Business Cloud API (Meta).
1233
- *
1234
- * Uses the WhatsApp Cloud API directly (no Twilio).
1235
- * Setup: https://developers.facebook.com/docs/whatsapp/cloud-api/get-started
1236
- *
1237
- * @example
1238
- * ```ts
1239
- * const whatsapp = new WhatsAppToolkit({
1240
- * accessToken: "...",
1241
- * phoneNumberId: "...",
1242
- * });
1243
- * const agent = new Agent({ tools: [...whatsapp.getTools()] });
1244
- * ```
1245
- */
1246
- declare class WhatsAppToolkit extends Toolkit {
1247
- readonly name = "whatsapp";
1248
- private accessToken;
1249
- private phoneNumberId;
1250
- private version;
1251
- private recipientWaid;
1252
- constructor(config?: WhatsAppConfig);
1253
- private getBaseUrl;
1254
- private validate;
1255
- private resolveRecipient;
1256
- getTools(): ToolDef[];
1257
- }
1258
-
1259
- interface HackerNewsConfig {
1260
- /** Enable fetching top stories (default true). */
1261
- enableGetTopStories?: boolean;
1262
- /** Enable fetching user details (default true). */
1263
- enableGetUserDetails?: boolean;
1264
- }
1265
- /**
1266
- * Hacker News Toolkit — search top stories and user details from HN.
1267
- *
1268
- * No API key required — uses the public Hacker News API.
1269
- *
1270
- * @example
1271
- * ```ts
1272
- * const hn = new HackerNewsToolkit();
1273
- * const agent = new Agent({ tools: [...hn.getTools()] });
1274
- * ```
1275
- */
1276
- declare class HackerNewsToolkit extends Toolkit {
1277
- readonly name = "hackernews";
1278
- private config;
1279
- constructor(config?: HackerNewsConfig);
1280
- getTools(): ToolDef[];
1281
- }
1282
-
1283
- export { type A2AAgentCard, type A2AArtifact, type A2ADataPart, type A2AFilePart, type A2AJsonRpcRequest, type A2AJsonRpcResponse, type A2AMessage, type A2APart, A2ARemoteAgent, type A2ARemoteAgentConfig, type A2ASendParams, type A2ASkill, type A2ATask, type A2ATaskQueryParams, type A2ATaskState, type A2ATextPart, Agent, type AgentConfig, type AgentEventMap, type AgentHooks, type AgentStep, AnthropicProvider, type Artifact, type AudioPart, BaseVectorStore, type ChatMessage, type ConditionStep, type ContentPart, type EmbeddingProvider, EventBus, type FilePart, type FunctionStep, type GmailConfig, GmailToolkit, GoogleEmbedding, type GoogleEmbeddingConfig, GoogleProvider, type GuardrailResult, type HackerNewsConfig, HackerNewsToolkit, type ImagePart, InMemoryStorage, InMemoryVectorStore, type InputGuardrail, KnowledgeBase, type KnowledgeBaseConfig, type KnowledgeBaseToolConfig, LLMLoop, type LogLevel, Logger, type LoggerConfig, MCPToolProvider, type MCPToolProviderConfig, Memory, type MemoryConfig, type MemoryEntry, type MessageContent, type MessageRole, type ModelConfig, type ModelProvider, ModelRegistry, type ModelResponse, MongoDBStorage, type MongoDBVectorConfig, MongoDBVectorStore, OllamaProvider, OpenAIEmbedding, type OpenAIEmbeddingConfig, OpenAIProvider, type OutputGuardrail, type ParallelStep, type PgVectorConfig, PgVectorStore, PostgresStorage, type QdrantConfig, QdrantVectorStore, RunContext, type RunOpts, type RunOutput, type Session, SessionManager, SqliteStorage, type StepDef, type StepResult, type StorageDriver, type StreamChunk, Team, type TeamConfig, TeamMode, type TextPart, type TokenUsage, type ToolCall, type ToolCallResult, type ToolDef, type ToolDefinition, ToolExecutor, type ToolResult, Toolkit, type VectorDocument, type VectorSearchOptions, type VectorSearchResult, type VectorStore, type VertexAIConfig, VertexAIProvider, type WebSearchConfig, WebSearchToolkit, type WhatsAppConfig, WhatsAppToolkit, Workflow, type WorkflowConfig, type WorkflowResult, anthropic, defineTool, getTextContent, google, isMultiModal, ollama, openai, registry, vertex };