@distri/core 0.2.4 → 0.2.5

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.mts CHANGED
@@ -1,14 +1,20 @@
1
- import { AgentSkill, Message, TaskStatusUpdateEvent, TaskArtifactUpdateEvent, Task, MessageSendParams, Part, Artifact } from '@a2a-js/sdk/client';
1
+ import { MessageSendParams, Message, Task, Part, AgentSkill, TaskStatusUpdateEvent, TaskArtifactUpdateEvent } from '@a2a-js/sdk/client';
2
2
  export { AgentCard, Message, MessageSendParams, Task, TaskArtifactUpdateEvent, TaskStatus, TaskStatusUpdateEvent } from '@a2a-js/sdk/client';
3
3
 
4
4
  type Role = 'user' | 'system' | 'assistant';
5
5
  interface RunStartedEvent {
6
6
  type: 'run_started';
7
- data: {};
7
+ data: {
8
+ runId?: string;
9
+ taskId?: string;
10
+ };
8
11
  }
9
12
  interface RunFinishedEvent {
10
13
  type: 'run_finished';
11
- data: {};
14
+ data: {
15
+ runId?: string;
16
+ taskId?: string;
17
+ };
12
18
  }
13
19
  interface RunErrorEvent {
14
20
  type: 'run_error';
@@ -39,13 +45,16 @@ interface TextMessageStartEvent {
39
45
  type: 'text_message_start';
40
46
  data: {
41
47
  message_id: string;
48
+ step_id: string;
42
49
  role: Role;
50
+ is_final?: boolean;
43
51
  };
44
52
  }
45
53
  interface TextMessageContentEvent {
46
54
  type: 'text_message_content';
47
55
  data: {
48
56
  message_id: string;
57
+ step_id: string;
49
58
  delta: string;
50
59
  };
51
60
  }
@@ -53,34 +62,22 @@ interface TextMessageEndEvent {
53
62
  type: 'text_message_end';
54
63
  data: {
55
64
  message_id: string;
65
+ step_id: string;
56
66
  };
57
67
  }
58
- interface ToolCallStartEvent {
59
- type: 'tool_call_start';
68
+ interface ToolExecutionStartEvent {
69
+ type: 'tool_execution_start';
60
70
  data: {
61
71
  tool_call_id: string;
62
72
  tool_call_name: string;
63
73
  parent_message_id?: string;
74
+ input?: any;
64
75
  };
65
76
  }
66
- interface ToolCallArgsEvent {
67
- type: 'tool_call_args';
68
- data: {
69
- tool_call_id: string;
70
- delta: string;
71
- };
72
- }
73
- interface ToolCallEndEvent {
74
- type: 'tool_call_end';
75
- data: {
76
- tool_call_id: string;
77
- };
78
- }
79
- interface ToolCallResultEvent {
80
- type: 'tool_call_result';
77
+ interface ToolExecutionEndEvent {
78
+ type: 'tool_execution_end';
81
79
  data: {
82
80
  tool_call_id: string;
83
- result: string;
84
81
  };
85
82
  }
86
83
  interface ToolRejectedEvent {
@@ -90,15 +87,6 @@ interface ToolRejectedEvent {
90
87
  tool_call_id?: string;
91
88
  };
92
89
  }
93
- interface TaskArtifactEvent {
94
- type: 'task_artifact';
95
- data: {
96
- artifact_id: string;
97
- artifact_type: string;
98
- resolution?: any;
99
- content?: any;
100
- };
101
- }
102
90
  interface AgentHandoverEvent {
103
91
  type: 'agent_handover';
104
92
  data: {
@@ -129,7 +117,423 @@ interface FeedbackReceivedEvent {
129
117
  feedback: string;
130
118
  };
131
119
  }
132
- type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | ToolCallResultEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | TaskArtifactEvent | AgentHandoverEvent | FeedbackReceivedEvent;
120
+ interface ToolCallsEvent {
121
+ type: 'tool_calls';
122
+ data: {
123
+ tool_calls: Array<{
124
+ tool_call_id: string;
125
+ tool_name: string;
126
+ input: any;
127
+ }>;
128
+ };
129
+ }
130
+ interface ToolResultsEvent {
131
+ type: 'tool_results';
132
+ data: {
133
+ results: Array<ToolResult>;
134
+ };
135
+ }
136
+ interface BrowserScreenshotEvent {
137
+ type: 'browser_screenshot';
138
+ data: {
139
+ image: string;
140
+ format?: string;
141
+ filename?: string;
142
+ size?: number;
143
+ timestamp_ms?: number;
144
+ };
145
+ }
146
+ interface InlineHookRequestedEvent {
147
+ type: 'inline_hook_requested';
148
+ data: {
149
+ hook_id: string;
150
+ hook: string;
151
+ context: {
152
+ agent_id: string;
153
+ thread_id: string;
154
+ task_id: string;
155
+ run_id: string;
156
+ };
157
+ timeout_ms?: number;
158
+ fire_and_forget?: boolean;
159
+ message?: any;
160
+ plan?: any;
161
+ result?: any;
162
+ };
163
+ }
164
+ type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolExecutionStartEvent | ToolExecutionEndEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | AgentHandoverEvent | FeedbackReceivedEvent | ToolCallsEvent | ToolResultsEvent | BrowserScreenshotEvent | InlineHookRequestedEvent;
165
+
166
+ type ChatCompletionRole = 'system' | 'user' | 'assistant' | 'tool';
167
+ interface ChatCompletionMessage {
168
+ role: ChatCompletionRole;
169
+ content: string;
170
+ }
171
+ type ChatCompletionResponseFormat = {
172
+ type: 'text';
173
+ } | {
174
+ type: 'json_schema';
175
+ json_schema: {
176
+ name: string;
177
+ schema: Record<string, unknown>;
178
+ strict?: boolean;
179
+ };
180
+ };
181
+ interface ChatCompletionRequest {
182
+ model?: string;
183
+ messages: ChatCompletionMessage[];
184
+ temperature?: number;
185
+ max_tokens?: number;
186
+ response_format?: ChatCompletionResponseFormat;
187
+ tools?: unknown[];
188
+ tool_choice?: 'none' | 'auto' | Record<string, unknown>;
189
+ }
190
+ interface ChatCompletionChoice {
191
+ index: number;
192
+ finish_reason?: string | null;
193
+ message: ChatCompletionMessage;
194
+ }
195
+ interface ChatCompletionResponse {
196
+ id: string;
197
+ created: number;
198
+ model: string;
199
+ object: string;
200
+ choices: ChatCompletionChoice[];
201
+ usage?: {
202
+ prompt_tokens?: number;
203
+ completion_tokens?: number;
204
+ total_tokens?: number;
205
+ };
206
+ }
207
+ /**
208
+ * Enhanced Distri Client that wraps A2AClient and adds Distri-specific features
209
+ *
210
+ * @example
211
+ * // Local development
212
+ * const client = new DistriClient({ baseUrl: 'http://localhost:3033' });
213
+ *
214
+ * // Cloud with default URL (https://api.distri.dev)
215
+ * const client = DistriClient.create();
216
+ */
217
+ declare class DistriClient {
218
+ private config;
219
+ private accessToken?;
220
+ private refreshToken?;
221
+ private tokenRefreshSkewMs;
222
+ private onTokenRefresh?;
223
+ private refreshPromise?;
224
+ private agentClients;
225
+ constructor(config: DistriClientConfig);
226
+ /**
227
+ * Create a client with default cloud configuration.
228
+ *
229
+ * @param overrides - Optional overrides for the default config
230
+ */
231
+ static create(overrides?: Partial<DistriClientConfig>): DistriClient;
232
+ /**
233
+ * Check if this client has authentication configured.
234
+ */
235
+ hasAuth(): boolean;
236
+ /**
237
+ * Check if this client is configured for local development.
238
+ */
239
+ isLocal(): boolean;
240
+ /**
241
+ * Session store: set a value (optionally with expiry)
242
+ */
243
+ setSessionValue(sessionId: string, key: string, value: unknown, expiry?: Date | string): Promise<void>;
244
+ /**
245
+ * Session store: get a single value
246
+ */
247
+ getSessionValue<T = unknown>(sessionId: string, key: string): Promise<T | null>;
248
+ /**
249
+ * Session store: get all values in a session
250
+ */
251
+ getSessionValues(sessionId: string): Promise<Record<string, unknown>>;
252
+ /**
253
+ * Session store: delete a single key
254
+ */
255
+ deleteSessionValue(sessionId: string, key: string): Promise<void>;
256
+ /**
257
+ * Session store: clear all keys in a session
258
+ */
259
+ clearSession(sessionId: string): Promise<void>;
260
+ private static readonly ADDITIONAL_PARTS_KEY;
261
+ /**
262
+ * Set additional user message parts for the next agent iteration.
263
+ * These parts will be appended to the user message in the prompt.
264
+ * @param sessionId - The thread/session ID
265
+ * @param parts - Array of DistriPart objects to append to user message
266
+ */
267
+ setAdditionalUserParts(sessionId: string, parts: DistriPart[]): Promise<void>;
268
+ /**
269
+ * Get the current additional user message parts.
270
+ * @param sessionId - The thread/session ID
271
+ * @returns Array of DistriPart objects or null if not set
272
+ */
273
+ getAdditionalUserParts(sessionId: string): Promise<DistriPart[] | null>;
274
+ /**
275
+ * Clear/delete the additional user message parts.
276
+ * @param sessionId - The thread/session ID
277
+ */
278
+ clearAdditionalUserParts(sessionId: string): Promise<void>;
279
+ /**
280
+ * Response from the token endpoint
281
+ */
282
+ static readonly TokenType: {
283
+ readonly Main: "main";
284
+ readonly Short: "short";
285
+ };
286
+ /**
287
+ * Issue an access token + refresh token for temporary authentication.
288
+ * Requires an existing authenticated session (bearer token).
289
+ *
290
+ * @returns Token response with access/refresh token strings
291
+ * @throws ApiError if not authenticated or token issuance fails
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const { access_token, refresh_token } = await client.issueToken();
296
+ * // Persist the refresh token and use access_token for requests
297
+ * ```
298
+ */
299
+ issueToken(): Promise<{
300
+ access_token: string;
301
+ refresh_token: string;
302
+ expires_at: number;
303
+ }>;
304
+ /**
305
+ * Get the current access/refresh tokens.
306
+ */
307
+ getTokens(): {
308
+ accessToken?: string;
309
+ refreshToken?: string;
310
+ };
311
+ /**
312
+ * Update the access/refresh tokens in memory.
313
+ */
314
+ setTokens(tokens: {
315
+ accessToken?: string;
316
+ refreshToken?: string;
317
+ }): void;
318
+ /**
319
+ * Start streaming speech-to-text transcription via WebSocket
320
+ */
321
+ streamingTranscription(options?: StreamingTranscriptionOptions): Promise<{
322
+ sendAudio: (audioData: ArrayBuffer) => void;
323
+ sendText: (text: string) => void;
324
+ stop: () => void;
325
+ close: () => void;
326
+ }>;
327
+ /**
328
+ * Transcribe audio blob to text using speech-to-text API
329
+ */
330
+ transcribe(audioBlob: Blob, config?: SpeechToTextConfig): Promise<string>;
331
+ getConfiguration(): Promise<ConfigurationResponse>;
332
+ updateConfiguration(configuration: DistriConfiguration): Promise<ConfigurationResponse>;
333
+ /**
334
+ * Minimal LLM helper that proxies to the Distri server using Distri messages.
335
+ */
336
+ llm(messages: DistriMessage[], tools?: unknown[], options?: LlmExecuteOptions): Promise<LLMResponse>;
337
+ /**
338
+ * Get all available agents from the Distri server
339
+ */
340
+ getAgents(): Promise<AgentDefinition[]>;
341
+ /**
342
+ * Get specific agent by ID
343
+ */
344
+ getAgent(agentId: string): Promise<AgentDefinition>;
345
+ /**
346
+ * Get or create A2AClient for an agent
347
+ */
348
+ private getA2AClient;
349
+ /**
350
+ * Send a message to an agent
351
+ */
352
+ sendMessage(agentId: string, params: MessageSendParams): Promise<Message | Task>;
353
+ /**
354
+ * Send a streaming message to an agent
355
+ */
356
+ sendMessageStream(agentId: string, params: MessageSendParams): AsyncGenerator<A2AStreamEventData>;
357
+ /**
358
+ * Get task details
359
+ */
360
+ getTask(agentId: string, taskId: string): Promise<Task>;
361
+ /**
362
+ * Cancel a task
363
+ */
364
+ cancelTask(agentId: string, taskId: string): Promise<void>;
365
+ /**
366
+ * Get threads from Distri server
367
+ */
368
+ getThreads(): Promise<DistriThread[]>;
369
+ getThread(threadId: string): Promise<DistriThread>;
370
+ /**
371
+ * Get thread messages
372
+ */
373
+ getThreadMessages(threadId: string): Promise<Message[]>;
374
+ /**
375
+ * Get messages from a thread as DistriMessage format
376
+ */
377
+ getThreadMessagesAsDistri(threadId: string): Promise<DistriMessage[]>;
378
+ /**
379
+ * Send a DistriMessage to a thread
380
+ */
381
+ sendDistriMessage(threadId: string, message: DistriMessage, context: InvokeContext): Promise<void>;
382
+ /**
383
+ * Complete an external tool call
384
+ */
385
+ completeTool(agentId: string, result: ToolResult): Promise<void>;
386
+ /**
387
+ * Complete an inline hook with a mutation payload.
388
+ */
389
+ completeInlineHook(hookId: string, mutation: any): Promise<void>;
390
+ /**
391
+ * Get the base URL for making direct requests
392
+ */
393
+ get baseUrl(): string;
394
+ private applyTokens;
395
+ private ensureAccessToken;
396
+ private refreshTokens;
397
+ private performTokenRefresh;
398
+ private isTokenExpiring;
399
+ private getTokenExpiry;
400
+ private decodeJwtPayload;
401
+ private decodeBase64Url;
402
+ private applyAuthHeader;
403
+ /**
404
+ * Enhanced fetch with retry logic
405
+ */
406
+ private fetchAbsolute;
407
+ /**
408
+ * Enhanced fetch with retry logic
409
+ */
410
+ private fetch;
411
+ /**
412
+ * Delay utility
413
+ */
414
+ private delay;
415
+ /**
416
+ * Debug logging
417
+ */
418
+ private debug;
419
+ /**
420
+ * Helper method to create A2A messages
421
+ */
422
+ static initMessage(parts: Part[] | string, role: "agent" | "user" | undefined, message: Omit<Partial<Message>, 'parts' | 'role' | 'kind'>): Message;
423
+ /**
424
+ * Create a DistriMessage instance
425
+ */
426
+ static initDistriMessage(role: DistriMessage['role'], parts: DistriPart[], id?: string, created_at?: number): DistriMessage;
427
+ /**
428
+ * Helper method to create message send parameters
429
+ */
430
+ static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any): MessageSendParams;
431
+ /**
432
+ * Create MessageSendParams from a DistriMessage using InvokeContext
433
+ */
434
+ static initDistriMessageParams(message: DistriMessage, context: InvokeContext): MessageSendParams;
435
+ }
436
+ declare function uuidv4(): string;
437
+
438
+ /**
439
+ * Configuration for Agent invoke method
440
+ */
441
+ interface InvokeConfig {
442
+ /** Configuration for the message */
443
+ configuration?: MessageSendParams['configuration'];
444
+ /** Context/thread ID */
445
+ contextId?: string;
446
+ /** Metadata for the requests */
447
+ metadata?: any;
448
+ }
449
+ /**
450
+ * Result from agent invoke
451
+ */
452
+ interface InvokeResult {
453
+ /** Final response message */
454
+ message?: Message;
455
+ /** Task if created */
456
+ task?: any;
457
+ /** Whether the response was streamed */
458
+ streamed: boolean;
459
+ }
460
+ interface ExternalToolValidationResult {
461
+ isValid: boolean;
462
+ requiredTools: string[];
463
+ providedTools: string[];
464
+ missingTools: string[];
465
+ message?: string;
466
+ }
467
+ declare class ExternalToolValidationError extends DistriError {
468
+ missingTools: string[];
469
+ requiredTools: string[];
470
+ providedTools: string[];
471
+ agentName: string;
472
+ constructor(agentName: string, result: ExternalToolValidationResult);
473
+ }
474
+ /**
475
+ * Enhanced Agent class with simple tool system following AG-UI pattern
476
+ */
477
+ declare class Agent {
478
+ private client;
479
+ private agentDefinition;
480
+ private hookHandlers;
481
+ private defaultHookHandler;
482
+ constructor(agentDefinition: AgentDefinition, client: DistriClient);
483
+ /**
484
+ * Get agent information
485
+ */
486
+ get id(): string;
487
+ get name(): string;
488
+ get description(): string | undefined;
489
+ get agentType(): string | undefined;
490
+ get iconUrl(): string | undefined;
491
+ /**
492
+ * Get the full agent definition (including backend tools)
493
+ */
494
+ getDefinition(): AgentDefinition;
495
+ /**
496
+ * Fetch messages for a thread (public method for useChat)
497
+ */
498
+ getThreadMessages(threadId: string): Promise<Message[]>;
499
+ /**
500
+ * Direct (non-streaming) invoke
501
+ */
502
+ invoke(params: MessageSendParams, tools?: DistriBaseTool[], hooks?: Record<string, HookHandler>): Promise<Message>;
503
+ /**
504
+ * Streaming invoke
505
+ */
506
+ invokeStream(params: MessageSendParams, tools?: DistriBaseTool[], hooks?: Record<string, HookHandler>): Promise<AsyncGenerator<DistriChatMessage>>;
507
+ /**
508
+ * Validate that required external tools are registered before invoking.
509
+ */
510
+ validateExternalTools(tools?: DistriBaseTool[]): ExternalToolValidationResult;
511
+ /**
512
+ * Enhance message params with tool definitions
513
+ */
514
+ private enhanceParamsWithTools;
515
+ private assertExternalTools;
516
+ private getRequiredExternalTools;
517
+ private resolveToolConfig;
518
+ private extractToolConfig;
519
+ private formatExternalToolValidationMessage;
520
+ /**
521
+ * Register multiple hooks at once.
522
+ */
523
+ registerHooks(hooks: Record<string, HookHandler>, defaultHandler?: HookHandler): void;
524
+ /**
525
+ * Create an agent instance from an agent ID
526
+ */
527
+ static create(agentIdOrDef: string | AgentDefinition, client: DistriClient): Promise<Agent>;
528
+ /**
529
+ * Complete an external tool call by sending the result back to the server
530
+ */
531
+ completeTool(result: ToolResult): Promise<void>;
532
+ /**
533
+ * List all available agents
534
+ */
535
+ static list(client: DistriClient): Promise<Agent[]>;
536
+ }
133
537
 
134
538
  /**
135
539
  * Message roles supported by Distri
@@ -142,7 +546,16 @@ interface DistriMessage {
142
546
  id: string;
143
547
  role: MessageRole;
144
548
  parts: DistriPart[];
145
- created_at?: string;
549
+ created_at: number;
550
+ step_id?: string;
551
+ is_final?: boolean;
552
+ }
553
+ interface LlmExecuteOptions {
554
+ thread_id?: string;
555
+ parent_task_id?: string;
556
+ run_id?: string;
557
+ model_settings?: any;
558
+ is_sub_task?: boolean;
146
559
  }
147
560
  interface AssistantWithToolCalls {
148
561
  id: string;
@@ -156,6 +569,36 @@ interface AssistantWithToolCalls {
156
569
  is_external: boolean;
157
570
  reason: string | null;
158
571
  }
572
+ interface UseToolsOptions {
573
+ agent?: Agent;
574
+ externalTools?: DistriBaseTool[];
575
+ executionOptions?: ToolExecutionOptions;
576
+ }
577
+ interface ToolExecutionOptions {
578
+ autoExecute?: boolean;
579
+ }
580
+ interface HookMutation {
581
+ dynamic_values: Record<string, any>;
582
+ }
583
+ interface HookContext {
584
+ agent_id: string;
585
+ thread_id: string;
586
+ task_id: string;
587
+ run_id: string;
588
+ }
589
+ interface InlineHookRequest {
590
+ hook_id: string;
591
+ hook: string;
592
+ context: HookContext;
593
+ timeout_ms?: number;
594
+ fire_and_forget?: boolean;
595
+ message?: any;
596
+ plan?: any;
597
+ result?: any;
598
+ }
599
+ interface InlineHookEventData extends InlineHookRequest {
600
+ }
601
+ type HookHandler = (req: InlineHookRequest) => Promise<HookMutation> | HookMutation;
159
602
  interface ToolResults {
160
603
  id: string;
161
604
  type: 'tool_results';
@@ -166,15 +609,6 @@ interface ToolResults {
166
609
  rejected: boolean;
167
610
  reason: string | null;
168
611
  }
169
- interface GenericArtifact {
170
- id: string;
171
- type: 'artifact';
172
- timestamp: number;
173
- data: any;
174
- artifactId: string;
175
- name: string;
176
- description: string | null;
177
- }
178
612
  interface DistriPlan {
179
613
  id: string;
180
614
  type: 'plan';
@@ -184,8 +618,33 @@ interface DistriPlan {
184
618
  }
185
619
  interface BasePlanStep {
186
620
  id: string;
187
- title: string;
188
621
  }
622
+ interface ThoughtPlanStep extends BasePlanStep {
623
+ type: 'thought';
624
+ message: string;
625
+ }
626
+ interface ActionPlanStep extends BasePlanStep {
627
+ type: 'action';
628
+ action: PlanAction;
629
+ }
630
+ interface CodePlanStep extends BasePlanStep {
631
+ type: 'code';
632
+ code: string;
633
+ language: string;
634
+ }
635
+ interface FinalResultPlanStep extends BasePlanStep {
636
+ type: 'final_result';
637
+ content: string;
638
+ tool_calls: any[];
639
+ }
640
+ interface PlanAction {
641
+ tool_name?: string;
642
+ input?: string;
643
+ prompt?: string;
644
+ context?: any[];
645
+ tool_calling_config?: any;
646
+ }
647
+ type PlanStep = ThoughtPlanStep | ActionPlanStep | CodePlanStep | FinalResultPlanStep;
189
648
  interface LlmPlanStep extends BasePlanStep {
190
649
  type: 'llm_call';
191
650
  prompt: string;
@@ -204,69 +663,51 @@ interface ReactStep extends BasePlanStep {
204
663
  thought: string;
205
664
  action: string;
206
665
  }
207
- interface FinalResultStep extends BasePlanStep {
208
- type: 'final_result';
209
- content: string;
210
- tool_calls: any[];
211
- }
212
- type PlanStep = LlmPlanStep | BatchToolCallsStep | ThoughtStep | ReactStep | FinalResultStep;
213
- type DistriArtifact = AssistantWithToolCalls | ToolResults | GenericArtifact | DistriPlan;
214
- type DistriStreamEvent = DistriMessage | DistriEvent | DistriArtifact;
666
+ type DistriStreamEvent = DistriMessage | DistriEvent;
215
667
  /**
216
668
  * Context required for constructing A2A messages from DistriMessage
217
669
  */
218
670
  interface InvokeContext {
219
671
  thread_id: string;
220
672
  run_id?: string;
673
+ task_id?: string;
221
674
  getMetadata?: () => any;
222
675
  }
223
676
  /**
224
677
  * Distri message parts - equivalent to Rust enum Part
225
678
  */
226
679
  type TextPart = {
227
- type: 'text';
228
- text: string;
680
+ part_type: 'text';
681
+ data: string;
229
682
  };
230
- type CodeObservationPart = {
231
- type: 'code_observation';
232
- thought: string;
233
- code: string;
683
+ type ToolCallPart = {
684
+ part_type: 'tool_call';
685
+ data: ToolCall;
234
686
  };
235
- type ImageUrlPart = {
236
- type: 'image_url';
237
- image: FileUrl;
687
+ type ToolResultRefPart = {
688
+ part_type: 'tool_result';
689
+ data: ToolResult;
238
690
  };
239
- type ImageBytesPart = {
240
- type: 'image_bytes';
241
- image: FileBytes;
691
+ type ImagePart = {
692
+ part_type: 'image';
693
+ data: FileType;
242
694
  };
243
- type ImagePart = ImageUrlPart | ImageBytesPart;
244
695
  type DataPart = {
245
- type: 'data';
246
- data: any;
247
- };
248
- type ToolCallPart = {
249
- type: 'tool_call';
250
- tool_call: ToolCall;
696
+ part_type: 'data';
697
+ data: object;
251
698
  };
252
- type ToolResultPart = {
253
- type: 'tool_result';
254
- tool_result: ToolResult;
255
- };
256
- type PlanPart = {
257
- type: 'plan';
258
- plan: string;
259
- };
260
- type DistriPart = TextPart | CodeObservationPart | ImagePart | DataPart | ToolCallPart | ToolResultPart | PlanPart;
699
+ type DistriPart = TextPart | ToolCallPart | ToolResultRefPart | ImagePart | DataPart;
261
700
  /**
262
701
  * File type for images
263
702
  */
264
703
  interface FileBytes {
704
+ type: 'bytes';
265
705
  mime_type: string;
266
706
  data: string;
267
707
  name?: string;
268
708
  }
269
709
  interface FileUrl {
710
+ type: 'url';
270
711
  mime_type: string;
271
712
  url: string;
272
713
  name?: string;
@@ -279,7 +720,10 @@ interface DistriBaseTool {
279
720
  name: string;
280
721
  type: 'function' | 'ui';
281
722
  description: string;
282
- input_schema: object;
723
+ parameters: object;
724
+ is_final?: boolean;
725
+ autoExecute?: boolean;
726
+ isExternal?: boolean;
283
727
  }
284
728
  interface DistriFnTool extends DistriBaseTool {
285
729
  type: 'function';
@@ -290,7 +734,7 @@ interface DistriFnTool extends DistriBaseTool {
290
734
  * Tool handler function
291
735
  */
292
736
  interface ToolHandler {
293
- (input: any): Promise<string | number | boolean | null | object>;
737
+ (input: any): Promise<string | number | boolean | null | DistriPart[] | object>;
294
738
  }
295
739
  /**
296
740
  * Tool call from agent
@@ -301,15 +745,37 @@ interface ToolCall {
301
745
  input: any;
302
746
  }
303
747
  /**
304
- * Tool result for responding to tool calls
748
+ * Tool result structure that can come from backend or frontend
305
749
  */
306
750
  interface ToolResult {
307
- tool_call_id: string;
308
- tool_name: string;
309
- result: string | number | boolean | null;
751
+ readonly tool_call_id: string;
752
+ readonly tool_name: string;
753
+ readonly parts: readonly DistriPart[];
754
+ }
755
+ /**
756
+ * Tool result data that goes inside the parts array
757
+ */
758
+ interface ToolResultData {
759
+ result: string | number | boolean | null | object;
310
760
  success: boolean;
311
761
  error?: string;
312
762
  }
763
+ declare function isArrayParts(result: any): boolean;
764
+ /**
765
+ * Type-safe helper to create a successful ToolResult
766
+ * Uses proper DistriPart structure - conversion to backend format happens in encoder
767
+ */
768
+ declare function createSuccessfulToolResult(toolCallId: string, toolName: string, result: string | number | boolean | null | object | DistriPart[]): ToolResult;
769
+ /**
770
+ * Type-safe helper to create a failed ToolResult
771
+ * Uses proper DistriPart structure - conversion to backend format happens in encoder
772
+ */
773
+ declare function createFailedToolResult(toolCallId: string, toolName: string, error: string, result?: string | number | boolean | null | object): ToolResult;
774
+ /**
775
+ * Type-safe helper to extract ToolResultData from a ToolResult
776
+ * Handles both frontend DistriPart format and backend BackendPart format
777
+ */
778
+ declare function extractToolResultData(toolResult: ToolResult): ToolResultData | null;
313
779
  /**
314
780
  * Distri-specific Agent type that wraps A2A AgentCard
315
781
  */
@@ -317,6 +783,8 @@ interface AgentDefinition {
317
783
  /** The name of the agent. */
318
784
  name: string;
319
785
  id: string;
786
+ /** Optional package identifier (workspace/plugin) that registered the agent */
787
+ package_name?: string | null;
320
788
  /** A brief description of the agent's purpose. */
321
789
  description?: string;
322
790
  /** The version of the agent. */
@@ -337,6 +805,21 @@ interface AgentDefinition {
337
805
  skills?: AgentSkill[];
338
806
  /** List of sub-agents that this agent can transfer control to */
339
807
  sub_agents?: string[];
808
+ agentType?: string;
809
+ agent_type?: string;
810
+ tools?: DistriBaseTool[];
811
+ browser_config?: BrowserAgentConfig;
812
+ }
813
+ interface BrowserAgentConfig {
814
+ enabled?: boolean;
815
+ persist_session?: boolean;
816
+ runtime?: DistriBrowserRuntimeConfig | null;
817
+ }
818
+ interface DistriBrowserRuntimeConfig {
819
+ window_size?: [number, number];
820
+ headless?: boolean;
821
+ enable_stealth_mode?: boolean;
822
+ enable_real_emulation?: boolean;
340
823
  }
341
824
  interface McpDefinition {
342
825
  /** The filter applied to the tools in this MCP definition. */
@@ -350,18 +833,31 @@ interface ModelSettings {
350
833
  model: string;
351
834
  temperature: number;
352
835
  max_tokens: number;
836
+ context_size: number;
353
837
  top_p: number;
354
838
  frequency_penalty: number;
355
839
  presence_penalty: number;
356
- max_iterations: number;
357
- provider: ModelProvider;
840
+ provider: ModelProviderConfig;
358
841
  /** Additional parameters for the agent, if any. */
359
842
  parameters?: any;
360
843
  /** The format of the response, if specified. */
361
844
  response_format?: any;
362
845
  }
363
846
  type McpServerType = 'tool' | 'agent';
364
- type ModelProvider = 'openai' | 'aigateway';
847
+ type ModelProviderName = 'openai' | 'openai_compat' | 'vllora' | string;
848
+ type ModelProviderConfig = {
849
+ name: 'openai';
850
+ } | {
851
+ name: 'openai_compat';
852
+ base_url: string;
853
+ project_id?: string;
854
+ } | {
855
+ name: 'vllora';
856
+ base_url?: string;
857
+ } | {
858
+ name: string;
859
+ [key: string]: any;
860
+ };
365
861
  /**
366
862
  * Distri Thread type for conversation management
367
863
  */
@@ -388,22 +884,121 @@ interface ChatProps {
388
884
  agent: AgentDefinition;
389
885
  onThreadUpdate?: () => void;
390
886
  }
887
+ interface SpeechToTextConfig {
888
+ model?: 'whisper-1';
889
+ language?: string;
890
+ temperature?: number;
891
+ }
892
+ interface StreamingTranscriptionOptions {
893
+ onTranscript?: (text: string, isFinal: boolean) => void;
894
+ onError?: (error: Error) => void;
895
+ onStart?: () => void;
896
+ onEnd?: () => void;
897
+ }
391
898
  /**
392
899
  * Connection Status
393
900
  */
394
901
  type ConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error';
902
+ /**
903
+ * Default base URL for the Distri cloud service
904
+ */
905
+ declare const DEFAULT_BASE_URL = "https://api.distri.dev";
395
906
  /**
396
907
  * Distri Client Configuration
397
908
  */
398
909
  interface DistriClientConfig {
910
+ /**
911
+ * Base URL of the Distri server
912
+ * Default: https://api.distri.dev
913
+ */
399
914
  baseUrl: string;
915
+ /**
916
+ * API version (currently unused)
917
+ */
400
918
  apiVersion?: string;
919
+ /**
920
+ * Request timeout in milliseconds (default: 30000)
921
+ */
401
922
  timeout?: number;
923
+ /**
924
+ * Number of retry attempts for failed requests (default: 3)
925
+ */
402
926
  retryAttempts?: number;
927
+ /**
928
+ * Delay between retry attempts in milliseconds (default: 1000)
929
+ */
403
930
  retryDelay?: number;
931
+ /**
932
+ * Enable debug logging
933
+ */
404
934
  debug?: boolean;
935
+ /**
936
+ * Custom headers to include in all requests
937
+ */
405
938
  headers?: Record<string, string>;
939
+ /**
940
+ * Request interceptor for modifying requests before sending
941
+ */
406
942
  interceptor?: (init?: RequestInit) => Promise<RequestInit | undefined>;
943
+ /**
944
+ * Access token for bearer auth (optional)
945
+ */
946
+ accessToken?: string;
947
+ /**
948
+ * Refresh token for bearer auth (optional)
949
+ */
950
+ refreshToken?: string;
951
+ /**
952
+ * Token refresh skew in milliseconds (default: 60000)
953
+ */
954
+ tokenRefreshSkewMs?: number;
955
+ /**
956
+ * Callback invoked when tokens are refreshed
957
+ */
958
+ onTokenRefresh?: (tokens: {
959
+ accessToken: string;
960
+ refreshToken: string;
961
+ }) => void;
962
+ }
963
+ interface LLMResponse {
964
+ finish_reason: string;
965
+ content: string;
966
+ tool_calls: ToolCall[];
967
+ token_usage: number;
968
+ tools?: any[];
969
+ }
970
+ interface ExternalMcpServer {
971
+ name: string;
972
+ [key: string]: any;
973
+ }
974
+ interface ServerConfig {
975
+ base_url?: string;
976
+ host?: string;
977
+ port?: number;
978
+ [key: string]: any;
979
+ }
980
+ interface DistriConfiguration {
981
+ name: string;
982
+ version: string;
983
+ description?: string;
984
+ license?: string;
985
+ working_directory?: string;
986
+ agents?: string[];
987
+ mcp_servers?: ExternalMcpServer[];
988
+ server?: ServerConfig;
989
+ model_settings?: ModelSettings;
990
+ analysis_model_settings?: ModelSettings;
991
+ keywords?: string[];
992
+ [key: string]: any;
993
+ }
994
+ interface ConfigurationMeta {
995
+ base_path: string;
996
+ overrides_path: string;
997
+ overrides_active: boolean;
998
+ }
999
+ interface ConfigurationResponse {
1000
+ configuration: DistriConfiguration;
1001
+ meta: ConfigurationMeta;
407
1002
  }
408
1003
  /**
409
1004
  * Error Types
@@ -427,183 +1022,7 @@ declare class ConnectionError extends DistriError {
427
1022
  type A2AStreamEventData = Message | TaskStatusUpdateEvent | TaskArtifactUpdateEvent | Task;
428
1023
  declare function isDistriMessage(event: DistriStreamEvent): event is DistriMessage;
429
1024
  declare function isDistriEvent(event: DistriStreamEvent): event is DistriEvent;
430
- declare function isDistriPlan(event: DistriStreamEvent): event is DistriPlan;
431
- declare function isDistriArtifact(event: DistriStreamEvent): event is DistriArtifact;
432
- type DistriChatMessage = DistriEvent | DistriMessage | DistriArtifact;
433
-
434
- /**
435
- * Enhanced Distri Client that wraps A2AClient and adds Distri-specific features
436
- */
437
- declare class DistriClient {
438
- private config;
439
- private agentClients;
440
- constructor(config: DistriClientConfig);
441
- /**
442
- * Get all available agents from the Distri server
443
- */
444
- getAgents(): Promise<AgentDefinition[]>;
445
- /**
446
- * Get specific agent by ID
447
- */
448
- getAgent(agentId: string): Promise<AgentDefinition>;
449
- /**
450
- * Get or create A2AClient for an agent
451
- */
452
- private getA2AClient;
453
- /**
454
- * Send a message to an agent
455
- */
456
- sendMessage(agentId: string, params: MessageSendParams): Promise<Message | Task>;
457
- /**
458
- * Send a streaming message to an agent
459
- */
460
- sendMessageStream(agentId: string, params: MessageSendParams): AsyncGenerator<A2AStreamEventData>;
461
- /**
462
- * Get task details
463
- */
464
- getTask(agentId: string, taskId: string): Promise<Task>;
465
- /**
466
- * Cancel a task
467
- */
468
- cancelTask(agentId: string, taskId: string): Promise<void>;
469
- /**
470
- * Get threads from Distri server
471
- */
472
- getThreads(): Promise<DistriThread[]>;
473
- getThread(threadId: string): Promise<DistriThread>;
474
- /**
475
- * Get thread messages
476
- */
477
- getThreadMessages(threadId: string): Promise<Message[]>;
478
- /**
479
- * Get messages from a thread as DistriMessage format
480
- */
481
- getThreadMessagesAsDistri(threadId: string): Promise<DistriMessage[]>;
482
- /**
483
- * Send a DistriMessage to a thread
484
- */
485
- sendDistriMessage(threadId: string, message: DistriMessage, context: InvokeContext): Promise<void>;
486
- /**
487
- * Get the base URL for making direct requests
488
- */
489
- get baseUrl(): string;
490
- /**
491
- * Enhanced fetch with retry logic
492
- */
493
- private fetchAbsolute;
494
- /**
495
- * Enhanced fetch with retry logic
496
- */
497
- private fetch;
498
- /**
499
- * Delay utility
500
- */
501
- private delay;
502
- /**
503
- * Debug logging
504
- */
505
- private debug;
506
- /**
507
- * Helper method to create A2A messages
508
- */
509
- static initMessage(parts: Part[] | string, role: "agent" | "user" | undefined, message: Omit<Partial<Message>, 'parts' | 'role' | 'kind'>): Message;
510
- /**
511
- * Create a DistriMessage instance
512
- */
513
- static initDistriMessage(role: DistriMessage['role'], parts: DistriPart[], id?: string, created_at?: string): DistriMessage;
514
- /**
515
- * Helper method to create message send parameters
516
- */
517
- static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any): MessageSendParams;
518
- /**
519
- * Create MessageSendParams from a DistriMessage using InvokeContext
520
- */
521
- static initDistriMessageParams(message: DistriMessage, context: InvokeContext): MessageSendParams;
522
- }
523
- declare function uuidv4(): string;
524
-
525
- /**
526
- * Configuration for Agent invoke method
527
- */
528
- interface InvokeConfig {
529
- /** Configuration for the message */
530
- configuration?: MessageSendParams['configuration'];
531
- /** Context/thread ID */
532
- contextId?: string;
533
- /** Metadata for the requests */
534
- metadata?: any;
535
- }
536
- /**
537
- * Result from agent invoke
538
- */
539
- interface InvokeResult {
540
- /** Final response message */
541
- message?: Message;
542
- /** Task if created */
543
- task?: any;
544
- /** Whether the response was streamed */
545
- streamed: boolean;
546
- }
547
- /**
548
- * Enhanced Agent class with simple tool system following AG-UI pattern
549
- */
550
- declare class Agent {
551
- private client;
552
- private agentDefinition;
553
- private tools;
554
- constructor(agentDefinition: AgentDefinition, client: DistriClient);
555
- /**
556
- * Add a tool to the agent (AG-UI style)
557
- */
558
- registerTool(tool: DistriBaseTool): void;
559
- /**
560
- * Add multiple tools at once
561
- */
562
- registerTools(tools: DistriBaseTool[]): void;
563
- /**
564
- * Remove a tool
565
- */
566
- unregisterTool(toolName: string): void;
567
- /**
568
- * Get all registered tools
569
- */
570
- getTools(): DistriBaseTool[];
571
- /**
572
- * Check if a tool is registered
573
- */
574
- hasTool(toolName: string): boolean;
575
- /**
576
- * Get agent information
577
- */
578
- get id(): string;
579
- get name(): string;
580
- get description(): string | undefined;
581
- get iconUrl(): string | undefined;
582
- /**
583
- * Fetch messages for a thread (public method for useChat)
584
- */
585
- getThreadMessages(threadId: string): Promise<Message[]>;
586
- /**
587
- * Direct (non-streaming) invoke
588
- */
589
- invoke(params: MessageSendParams): Promise<Message>;
590
- /**
591
- * Streaming invoke
592
- */
593
- invokeStream(params: MessageSendParams): Promise<AsyncGenerator<DistriChatMessage>>;
594
- /**
595
- * Enhance message params with tool definitions
596
- */
597
- private enhanceParamsWithTools;
598
- /**
599
- * Create an agent instance from an agent ID
600
- */
601
- static create(agentIdOrDef: string | AgentDefinition, client: DistriClient): Promise<Agent>;
602
- /**
603
- * List all available agents
604
- */
605
- static list(client: DistriClient): Promise<Agent[]>;
606
- }
1025
+ type DistriChatMessage = DistriEvent | DistriMessage;
607
1026
 
608
1027
  /**
609
1028
  * Converts an A2A Message to a DistriMessage
@@ -613,10 +1032,6 @@ declare function convertA2AMessageToDistri(a2aMessage: Message): DistriMessage;
613
1032
  * Converts A2A status-update events to DistriEvent based on metadata type
614
1033
  */
615
1034
  declare function convertA2AStatusUpdateToDistri(statusUpdate: any): DistriEvent | null;
616
- /**
617
- * Converts A2A artifacts to DistriArtifact, DistriPlan, or DistriMessage based on content
618
- */
619
- declare function convertA2AArtifactToDistri(artifact: Artifact): DistriArtifact | DistriMessage | null;
620
1035
  /**
621
1036
  * Enhanced decoder for A2A stream events that properly handles all event types
622
1037
  */
@@ -624,7 +1039,7 @@ declare function decodeA2AStreamEvent(event: any): DistriChatMessage | null;
624
1039
  /**
625
1040
  * Process A2A stream data (like from stream.json) and convert to DistriMessage/DistriEvent/DistriArtifact array
626
1041
  */
627
- declare function processA2AStreamData(streamData: any[]): (DistriMessage | DistriEvent | DistriArtifact)[];
1042
+ declare function processA2AStreamData(streamData: any[]): (DistriMessage | DistriEvent)[];
628
1043
  /**
629
1044
  * Process A2A messages.json data and convert to DistriMessage array
630
1045
  */
@@ -654,4 +1069,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
654
1069
  */
655
1070
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
656
1071
 
657
- export { A2AProtocolError, type A2AStreamEventData, Agent, type AgentDefinition, type AgentHandoverEvent, ApiError, type AssistantWithToolCalls, type BasePlanStep, type BatchToolCallsStep, type ChatProps, type CodeObservationPart, ConnectionError, type ConnectionStatus, type DataPart, type DistriArtifact, type DistriBaseTool, type DistriChatMessage, DistriClient, type DistriClientConfig, DistriError, type DistriEvent, type DistriFnTool, type DistriMessage, type DistriPart, type DistriPlan, type DistriStreamEvent, type DistriThread, type FeedbackReceivedEvent, type FileBytes, type FileType, type FileUrl, type FinalResultStep, type GenericArtifact, type ImageBytesPart, type ImagePart, type ImageUrlPart, type InvokeConfig, type InvokeContext, type InvokeResult, type LlmPlanStep, type McpDefinition, type McpServerType, type MessageRole, type ModelProvider, type ModelSettings, type PlanFinishedEvent, type PlanPart, type PlanPrunedEvent, type PlanStartedEvent, type PlanStep, type ReactStep, type Role, type RunErrorEvent, type RunFinishedEvent, type RunStartedEvent, type StepCompletedEvent, type StepStartedEvent, type TaskArtifactEvent, type TextMessageContentEvent, type TextMessageEndEvent, type TextMessageStartEvent, type TextPart, type ThoughtStep, type Thread, type ToolCall, type ToolCallArgsEvent, type ToolCallEndEvent, type ToolCallPart, type ToolCallResultEvent, type ToolCallStartEvent, type ToolHandler, type ToolRejectedEvent, type ToolResult, type ToolResultPart, type ToolResults, convertA2AArtifactToDistri, convertA2AMessageToDistri, convertA2APartToDistri, convertA2AStatusUpdateToDistri, convertDistriMessageToA2A, convertDistriPartToA2A, decodeA2AStreamEvent, extractTextFromDistriMessage, extractToolCallsFromDistriMessage, extractToolResultsFromDistriMessage, isDistriArtifact, isDistriEvent, isDistriMessage, isDistriPlan, processA2AMessagesData, processA2AStreamData, uuidv4 };
1072
+ export { A2AProtocolError, type A2AStreamEventData, type ActionPlanStep, Agent, type AgentDefinition, type AgentHandoverEvent, ApiError, type AssistantWithToolCalls, type BasePlanStep, type BatchToolCallsStep, type BrowserAgentConfig, type BrowserScreenshotEvent, type ChatCompletionChoice, type ChatCompletionMessage, type ChatCompletionRequest, type ChatCompletionResponse, type ChatCompletionResponseFormat, type ChatCompletionRole, type ChatProps, type CodePlanStep, type ConfigurationMeta, type ConfigurationResponse, ConnectionError, type ConnectionStatus, DEFAULT_BASE_URL, type DataPart, type DistriBaseTool, type DistriBrowserRuntimeConfig, type DistriChatMessage, DistriClient, type DistriClientConfig, type DistriConfiguration, DistriError, type DistriEvent, type DistriFnTool, type DistriMessage, type DistriPart, type DistriPlan, type DistriStreamEvent, type DistriThread, type ExternalMcpServer, ExternalToolValidationError, type ExternalToolValidationResult, type FeedbackReceivedEvent, type FileBytes, type FileType, type FileUrl, type FinalResultPlanStep, type HookContext, type HookHandler, type HookMutation, type ImagePart, type InlineHookEventData, type InlineHookRequest, type InlineHookRequestedEvent, type InvokeConfig, type InvokeContext, type InvokeResult, type LLMResponse, type LlmExecuteOptions, type LlmPlanStep, type McpDefinition, type McpServerType, type MessageRole, type ModelProviderConfig, type ModelProviderName, type ModelSettings, type PlanAction, type PlanFinishedEvent, type PlanPrunedEvent, type PlanStartedEvent, type PlanStep, type ReactStep, type Role, type RunErrorEvent, type RunFinishedEvent, type RunStartedEvent, type ServerConfig, type SpeechToTextConfig, type StepCompletedEvent, type StepStartedEvent, type StreamingTranscriptionOptions, type TextMessageContentEvent, type TextMessageEndEvent, type TextMessageStartEvent, type TextPart, type ThoughtPlanStep, type ThoughtStep, type Thread, type ToolCall, type ToolCallPart, type ToolCallsEvent, type ToolExecutionEndEvent, type ToolExecutionOptions, type ToolExecutionStartEvent, type ToolHandler, type ToolRejectedEvent, type ToolResult, type ToolResultData, type ToolResultRefPart, type ToolResults, type ToolResultsEvent, type UseToolsOptions, convertA2AMessageToDistri, convertA2APartToDistri, convertA2AStatusUpdateToDistri, convertDistriMessageToA2A, convertDistriPartToA2A, createFailedToolResult, createSuccessfulToolResult, decodeA2AStreamEvent, extractTextFromDistriMessage, extractToolCallsFromDistriMessage, extractToolResultData, extractToolResultsFromDistriMessage, isArrayParts, isDistriEvent, isDistriMessage, processA2AMessagesData, processA2AStreamData, uuidv4 };