@distri/core 0.2.3 → 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,13 +1,20 @@
1
- import { AgentSkill, Message, TaskStatusUpdateEvent, TaskArtifactUpdateEvent, Task, MessageSendParams, Part } from '@a2a-js/sdk/client';
1
+ import { MessageSendParams, Message, Task, Part, AgentSkill, TaskStatusUpdateEvent, TaskArtifactUpdateEvent } from '@a2a-js/sdk/client';
2
+ export { AgentCard, Message, MessageSendParams, Task, TaskArtifactUpdateEvent, TaskStatus, TaskStatusUpdateEvent } from '@a2a-js/sdk/client';
2
3
 
3
4
  type Role = 'user' | 'system' | 'assistant';
4
5
  interface RunStartedEvent {
5
6
  type: 'run_started';
6
- data: {};
7
+ data: {
8
+ runId?: string;
9
+ taskId?: string;
10
+ };
7
11
  }
8
12
  interface RunFinishedEvent {
9
13
  type: 'run_finished';
10
- data: {};
14
+ data: {
15
+ runId?: string;
16
+ taskId?: string;
17
+ };
11
18
  }
12
19
  interface RunErrorEvent {
13
20
  type: 'run_error';
@@ -16,17 +23,38 @@ interface RunErrorEvent {
16
23
  code?: string;
17
24
  };
18
25
  }
26
+ interface PlanStartedEvent {
27
+ type: 'plan_started';
28
+ data: {
29
+ initial_plan?: boolean;
30
+ };
31
+ }
32
+ interface PlanFinishedEvent {
33
+ type: 'plan_finished';
34
+ data: {
35
+ total_steps?: number;
36
+ };
37
+ }
38
+ interface PlanPrunedEvent {
39
+ type: 'plan_pruned';
40
+ data: {
41
+ removed_steps?: any;
42
+ };
43
+ }
19
44
  interface TextMessageStartEvent {
20
45
  type: 'text_message_start';
21
46
  data: {
22
47
  message_id: string;
48
+ step_id: string;
23
49
  role: Role;
50
+ is_final?: boolean;
24
51
  };
25
52
  }
26
53
  interface TextMessageContentEvent {
27
54
  type: 'text_message_content';
28
55
  data: {
29
56
  message_id: string;
57
+ step_id: string;
30
58
  delta: string;
31
59
  };
32
60
  }
@@ -34,35 +62,29 @@ interface TextMessageEndEvent {
34
62
  type: 'text_message_end';
35
63
  data: {
36
64
  message_id: string;
65
+ step_id: string;
37
66
  };
38
67
  }
39
- interface ToolCallStartEvent {
40
- type: 'tool_call_start';
68
+ interface ToolExecutionStartEvent {
69
+ type: 'tool_execution_start';
41
70
  data: {
42
71
  tool_call_id: string;
43
72
  tool_call_name: string;
44
73
  parent_message_id?: string;
45
- is_external?: boolean;
46
- };
47
- }
48
- interface ToolCallArgsEvent {
49
- type: 'tool_call_args';
50
- data: {
51
- tool_call_id: string;
52
- delta: string;
74
+ input?: any;
53
75
  };
54
76
  }
55
- interface ToolCallEndEvent {
56
- type: 'tool_call_end';
77
+ interface ToolExecutionEndEvent {
78
+ type: 'tool_execution_end';
57
79
  data: {
58
80
  tool_call_id: string;
59
81
  };
60
82
  }
61
- interface ToolCallResultEvent {
62
- type: 'tool_call_result';
83
+ interface ToolRejectedEvent {
84
+ type: 'tool_rejected';
63
85
  data: {
64
- tool_call_id: string;
65
- result: string;
86
+ reason?: string;
87
+ tool_call_id?: string;
66
88
  };
67
89
  }
68
90
  interface AgentHandoverEvent {
@@ -73,7 +95,445 @@ interface AgentHandoverEvent {
73
95
  reason?: string;
74
96
  };
75
97
  }
76
- type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | ToolCallResultEvent | AgentHandoverEvent;
98
+ interface StepStartedEvent {
99
+ type: 'step_started';
100
+ data: {
101
+ step_id: string;
102
+ step_title: string;
103
+ step_index: number;
104
+ };
105
+ }
106
+ interface StepCompletedEvent {
107
+ type: 'step_completed';
108
+ data: {
109
+ step_id: string;
110
+ step_title: string;
111
+ step_index: number;
112
+ };
113
+ }
114
+ interface FeedbackReceivedEvent {
115
+ type: 'feedback_received';
116
+ data: {
117
+ feedback: string;
118
+ };
119
+ }
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
+ }
77
537
 
78
538
  /**
79
539
  * Message roles supported by Distri
@@ -86,7 +546,122 @@ interface DistriMessage {
86
546
  id: string;
87
547
  role: MessageRole;
88
548
  parts: DistriPart[];
89
- 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;
559
+ }
560
+ interface AssistantWithToolCalls {
561
+ id: string;
562
+ type: 'llm_response';
563
+ timestamp: number;
564
+ content: string;
565
+ tool_calls: any[];
566
+ step_id?: string;
567
+ success: boolean;
568
+ rejected: boolean;
569
+ is_external: boolean;
570
+ reason: string | null;
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;
602
+ interface ToolResults {
603
+ id: string;
604
+ type: 'tool_results';
605
+ timestamp: number;
606
+ results: any[];
607
+ step_id?: string;
608
+ success: boolean;
609
+ rejected: boolean;
610
+ reason: string | null;
611
+ }
612
+ interface DistriPlan {
613
+ id: string;
614
+ type: 'plan';
615
+ timestamp: number;
616
+ reasoning: string;
617
+ steps: PlanStep[];
618
+ }
619
+ interface BasePlanStep {
620
+ id: string;
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;
648
+ interface LlmPlanStep extends BasePlanStep {
649
+ type: 'llm_call';
650
+ prompt: string;
651
+ context: any[];
652
+ }
653
+ interface BatchToolCallsStep extends BasePlanStep {
654
+ type: 'batch_tool_calls';
655
+ tool_calls: any[];
656
+ }
657
+ interface ThoughtStep extends BasePlanStep {
658
+ type: 'thought';
659
+ message: string;
660
+ }
661
+ interface ReactStep extends BasePlanStep {
662
+ type: 'react_step';
663
+ thought: string;
664
+ action: string;
90
665
  }
91
666
  type DistriStreamEvent = DistriMessage | DistriEvent;
92
667
  /**
@@ -95,55 +670,44 @@ type DistriStreamEvent = DistriMessage | DistriEvent;
95
670
  interface InvokeContext {
96
671
  thread_id: string;
97
672
  run_id?: string;
673
+ task_id?: string;
98
674
  getMetadata?: () => any;
99
675
  }
100
676
  /**
101
677
  * Distri message parts - equivalent to Rust enum Part
102
678
  */
103
679
  type TextPart = {
104
- type: 'text';
105
- text: string;
680
+ part_type: 'text';
681
+ data: string;
106
682
  };
107
- type CodeObservationPart = {
108
- type: 'code_observation';
109
- thought: string;
110
- code: string;
683
+ type ToolCallPart = {
684
+ part_type: 'tool_call';
685
+ data: ToolCall;
111
686
  };
112
- type ImageUrlPart = {
113
- type: 'image_url';
114
- image: FileUrl;
687
+ type ToolResultRefPart = {
688
+ part_type: 'tool_result';
689
+ data: ToolResult;
115
690
  };
116
- type ImageBytesPart = {
117
- type: 'image_bytes';
118
- image: FileBytes;
691
+ type ImagePart = {
692
+ part_type: 'image';
693
+ data: FileType;
119
694
  };
120
- type ImagePart = ImageUrlPart | ImageBytesPart;
121
695
  type DataPart = {
122
- type: 'data';
123
- data: any;
124
- };
125
- type ToolCallPart = {
126
- type: 'tool_call';
127
- tool_call: ToolCall;
696
+ part_type: 'data';
697
+ data: object;
128
698
  };
129
- type ToolResultPart = {
130
- type: 'tool_result';
131
- tool_result: ToolResult;
132
- };
133
- type PlanPart = {
134
- type: 'plan';
135
- plan: string;
136
- };
137
- type DistriPart = TextPart | CodeObservationPart | ImagePart | DataPart | ToolCallPart | ToolResultPart | PlanPart;
699
+ type DistriPart = TextPart | ToolCallPart | ToolResultRefPart | ImagePart | DataPart;
138
700
  /**
139
701
  * File type for images
140
702
  */
141
703
  interface FileBytes {
704
+ type: 'bytes';
142
705
  mime_type: string;
143
706
  data: string;
144
707
  name?: string;
145
708
  }
146
709
  interface FileUrl {
710
+ type: 'url';
147
711
  mime_type: string;
148
712
  url: string;
149
713
  name?: string;
@@ -156,7 +720,10 @@ interface DistriBaseTool {
156
720
  name: string;
157
721
  type: 'function' | 'ui';
158
722
  description: string;
159
- input_schema: object;
723
+ parameters: object;
724
+ is_final?: boolean;
725
+ autoExecute?: boolean;
726
+ isExternal?: boolean;
160
727
  }
161
728
  interface DistriFnTool extends DistriBaseTool {
162
729
  type: 'function';
@@ -167,7 +734,7 @@ interface DistriFnTool extends DistriBaseTool {
167
734
  * Tool handler function
168
735
  */
169
736
  interface ToolHandler {
170
- (input: any): Promise<string | number | boolean | null | object>;
737
+ (input: any): Promise<string | number | boolean | null | DistriPart[] | object>;
171
738
  }
172
739
  /**
173
740
  * Tool call from agent
@@ -178,21 +745,46 @@ interface ToolCall {
178
745
  input: any;
179
746
  }
180
747
  /**
181
- * Tool result for responding to tool calls
748
+ * Tool result structure that can come from backend or frontend
182
749
  */
183
750
  interface ToolResult {
184
- tool_call_id: string;
185
- 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;
186
760
  success: boolean;
187
761
  error?: string;
188
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;
189
779
  /**
190
780
  * Distri-specific Agent type that wraps A2A AgentCard
191
781
  */
192
- interface DistriAgent {
782
+ interface AgentDefinition {
193
783
  /** The name of the agent. */
194
784
  name: string;
195
785
  id: string;
786
+ /** Optional package identifier (workspace/plugin) that registered the agent */
787
+ package_name?: string | null;
196
788
  /** A brief description of the agent's purpose. */
197
789
  description?: string;
198
790
  /** The version of the agent. */
@@ -213,6 +805,21 @@ interface DistriAgent {
213
805
  skills?: AgentSkill[];
214
806
  /** List of sub-agents that this agent can transfer control to */
215
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;
216
823
  }
217
824
  interface McpDefinition {
218
825
  /** The filter applied to the tools in this MCP definition. */
@@ -226,18 +833,31 @@ interface ModelSettings {
226
833
  model: string;
227
834
  temperature: number;
228
835
  max_tokens: number;
836
+ context_size: number;
229
837
  top_p: number;
230
838
  frequency_penalty: number;
231
839
  presence_penalty: number;
232
- max_iterations: number;
233
- provider: ModelProvider;
840
+ provider: ModelProviderConfig;
234
841
  /** Additional parameters for the agent, if any. */
235
842
  parameters?: any;
236
843
  /** The format of the response, if specified. */
237
844
  response_format?: any;
238
845
  }
239
846
  type McpServerType = 'tool' | 'agent';
240
- 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
+ };
241
861
  /**
242
862
  * Distri Thread type for conversation management
243
863
  */
@@ -261,208 +881,169 @@ interface Thread {
261
881
  }
262
882
  interface ChatProps {
263
883
  thread: Thread;
264
- agent: DistriAgent;
884
+ agent: AgentDefinition;
265
885
  onThreadUpdate?: () => void;
266
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
+ }
267
898
  /**
268
899
  * Connection Status
269
900
  */
270
901
  type ConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error';
271
902
  /**
272
- * Distri Client Configuration
903
+ * Default base URL for the Distri cloud service
273
904
  */
274
- interface DistriClientConfig {
275
- baseUrl: string;
276
- apiVersion?: string;
277
- timeout?: number;
278
- retryAttempts?: number;
279
- retryDelay?: number;
280
- debug?: boolean;
281
- headers?: Record<string, string>;
282
- interceptor?: (init?: RequestInit) => Promise<RequestInit | undefined>;
283
- }
284
- type A2AStreamEventData = Message | TaskStatusUpdateEvent | TaskArtifactUpdateEvent | Task;
285
- declare function isDistriMessage(event: DistriStreamEvent): event is DistriMessage;
286
- declare function isDistriEvent(event: DistriStreamEvent): event is DistriEvent;
287
-
905
+ declare const DEFAULT_BASE_URL = "https://api.distri.dev";
288
906
  /**
289
- * Enhanced Distri Client that wraps A2AClient and adds Distri-specific features
907
+ * Distri Client Configuration
290
908
  */
291
- declare class DistriClient {
292
- private config;
293
- private agentClients;
294
- constructor(config: DistriClientConfig);
295
- /**
296
- * Get all available agents from the Distri server
297
- */
298
- getAgents(): Promise<DistriAgent[]>;
299
- /**
300
- * Get specific agent by ID
301
- */
302
- getAgent(agentId: string): Promise<DistriAgent>;
303
- /**
304
- * Get or create A2AClient for an agent
305
- */
306
- private getA2AClient;
307
- /**
308
- * Send a message to an agent
309
- */
310
- sendMessage(agentId: string, params: MessageSendParams): Promise<Message | Task>;
311
- /**
312
- * Send a streaming message to an agent
313
- */
314
- sendMessageStream(agentId: string, params: MessageSendParams): AsyncGenerator<A2AStreamEventData>;
315
- /**
316
- * Get task details
317
- */
318
- getTask(agentId: string, taskId: string): Promise<Task>;
319
- /**
320
- * Cancel a task
321
- */
322
- cancelTask(agentId: string, taskId: string): Promise<void>;
323
- /**
324
- * Get threads from Distri server
325
- */
326
- getThreads(): Promise<DistriThread[]>;
327
- getThread(threadId: string): Promise<DistriThread>;
909
+ interface DistriClientConfig {
328
910
  /**
329
- * Get thread messages
911
+ * Base URL of the Distri server
912
+ * Default: https://api.distri.dev
330
913
  */
331
- getThreadMessages(threadId: string): Promise<Message[]>;
914
+ baseUrl: string;
332
915
  /**
333
- * Get messages from a thread as DistriMessage format
916
+ * API version (currently unused)
334
917
  */
335
- getThreadMessagesAsDistri(threadId: string): Promise<DistriMessage[]>;
918
+ apiVersion?: string;
336
919
  /**
337
- * Send a DistriMessage to a thread
920
+ * Request timeout in milliseconds (default: 30000)
338
921
  */
339
- sendDistriMessage(threadId: string, message: DistriMessage, context: InvokeContext): Promise<void>;
922
+ timeout?: number;
340
923
  /**
341
- * Get the base URL for making direct requests
924
+ * Number of retry attempts for failed requests (default: 3)
342
925
  */
343
- get baseUrl(): string;
926
+ retryAttempts?: number;
344
927
  /**
345
- * Enhanced fetch with retry logic
928
+ * Delay between retry attempts in milliseconds (default: 1000)
346
929
  */
347
- private fetchAbsolute;
930
+ retryDelay?: number;
348
931
  /**
349
- * Enhanced fetch with retry logic
932
+ * Enable debug logging
350
933
  */
351
- private fetch;
934
+ debug?: boolean;
352
935
  /**
353
- * Delay utility
936
+ * Custom headers to include in all requests
354
937
  */
355
- private delay;
938
+ headers?: Record<string, string>;
356
939
  /**
357
- * Debug logging
940
+ * Request interceptor for modifying requests before sending
358
941
  */
359
- private debug;
942
+ interceptor?: (init?: RequestInit) => Promise<RequestInit | undefined>;
360
943
  /**
361
- * Helper method to create A2A messages
944
+ * Access token for bearer auth (optional)
362
945
  */
363
- static initMessage(parts: Part[] | string, role: "agent" | "user" | undefined, message: Omit<Partial<Message>, 'parts' | 'role' | 'kind'>): Message;
946
+ accessToken?: string;
364
947
  /**
365
- * Create a DistriMessage instance
948
+ * Refresh token for bearer auth (optional)
366
949
  */
367
- static initDistriMessage(role: DistriMessage['role'], parts: DistriPart[], id?: string, created_at?: string): DistriMessage;
950
+ refreshToken?: string;
368
951
  /**
369
- * Helper method to create message send parameters
952
+ * Token refresh skew in milliseconds (default: 60000)
370
953
  */
371
- static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any): MessageSendParams;
954
+ tokenRefreshSkewMs?: number;
372
955
  /**
373
- * Create MessageSendParams from a DistriMessage using InvokeContext
956
+ * Callback invoked when tokens are refreshed
374
957
  */
375
- static initDistriMessageParams(message: DistriMessage, context: InvokeContext): MessageSendParams;
958
+ onTokenRefresh?: (tokens: {
959
+ accessToken: string;
960
+ refreshToken: string;
961
+ }) => void;
376
962
  }
377
- declare function uuidv4(): string;
378
-
379
- /**
380
- * Configuration for Agent invoke method
381
- */
382
- interface InvokeConfig {
383
- /** Configuration for the message */
384
- configuration?: MessageSendParams['configuration'];
385
- /** Context/thread ID */
386
- contextId?: string;
387
- /** Metadata for the requests */
388
- metadata?: any;
963
+ interface LLMResponse {
964
+ finish_reason: string;
965
+ content: string;
966
+ tool_calls: ToolCall[];
967
+ token_usage: number;
968
+ tools?: any[];
389
969
  }
390
- /**
391
- * Result from agent invoke
392
- */
393
- interface InvokeResult {
394
- /** Final response message */
395
- message?: Message;
396
- /** Task if created */
397
- task?: any;
398
- /** Whether the response was streamed */
399
- streamed: boolean;
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;
400
1002
  }
401
1003
  /**
402
- * Enhanced Agent class with simple tool system following AG-UI pattern
1004
+ * Error Types
403
1005
  */
404
- declare class Agent {
405
- private client;
406
- private agentDefinition;
407
- private tools;
408
- constructor(agentDefinition: DistriAgent, client: DistriClient);
409
- /**
410
- * Add a tool to the agent (AG-UI style)
411
- */
412
- registerTool(tool: DistriBaseTool): void;
413
- /**
414
- * Add multiple tools at once
415
- */
416
- registerTools(tools: DistriBaseTool[]): void;
417
- /**
418
- * Remove a tool
419
- */
420
- unregisterTool(toolName: string): void;
421
- /**
422
- * Get all registered tools
423
- */
424
- getTools(): DistriBaseTool[];
425
- /**
426
- * Check if a tool is registered
427
- */
428
- hasTool(toolName: string): boolean;
429
- /**
430
- * Get agent information
431
- */
432
- get id(): string;
433
- get name(): string;
434
- get description(): string | undefined;
435
- get iconUrl(): string | undefined;
436
- /**
437
- * Fetch messages for a thread (public method for useChat)
438
- */
439
- getThreadMessages(threadId: string): Promise<Message[]>;
440
- /**
441
- * Direct (non-streaming) invoke
442
- */
443
- invoke(params: MessageSendParams): Promise<Message>;
444
- /**
445
- * Streaming invoke
446
- */
447
- invokeStream(params: MessageSendParams): Promise<AsyncGenerator<DistriEvent | DistriMessage>>;
448
- /**
449
- * Enhance message params with tool definitions
450
- */
451
- private enhanceParamsWithTools;
452
- /**
453
- * Create an agent instance from an agent ID
454
- */
455
- static create(agentId: string, client: DistriClient): Promise<Agent>;
456
- /**
457
- * List all available agents
458
- */
459
- static list(client: DistriClient): Promise<Agent[]>;
1006
+ declare class DistriError extends Error {
1007
+ code: string;
1008
+ details?: any | undefined;
1009
+ constructor(message: string, code: string, details?: any | undefined);
460
1010
  }
1011
+ declare class A2AProtocolError extends DistriError {
1012
+ constructor(message: string, details?: any);
1013
+ }
1014
+ declare class ApiError extends DistriError {
1015
+ statusCode: number;
1016
+ constructor(message: string, statusCode: number, details?: any);
1017
+ }
1018
+ declare class ConnectionError extends DistriError {
1019
+ constructor(message: string, details?: any);
1020
+ }
1021
+
1022
+ type A2AStreamEventData = Message | TaskStatusUpdateEvent | TaskArtifactUpdateEvent | Task;
1023
+ declare function isDistriMessage(event: DistriStreamEvent): event is DistriMessage;
1024
+ declare function isDistriEvent(event: DistriStreamEvent): event is DistriEvent;
1025
+ type DistriChatMessage = DistriEvent | DistriMessage;
461
1026
 
462
1027
  /**
463
1028
  * Converts an A2A Message to a DistriMessage
464
1029
  */
465
1030
  declare function convertA2AMessageToDistri(a2aMessage: Message): DistriMessage;
1031
+ /**
1032
+ * Converts A2A status-update events to DistriEvent based on metadata type
1033
+ */
1034
+ declare function convertA2AStatusUpdateToDistri(statusUpdate: any): DistriEvent | null;
1035
+ /**
1036
+ * Enhanced decoder for A2A stream events that properly handles all event types
1037
+ */
1038
+ declare function decodeA2AStreamEvent(event: any): DistriChatMessage | null;
1039
+ /**
1040
+ * Process A2A stream data (like from stream.json) and convert to DistriMessage/DistriEvent/DistriArtifact array
1041
+ */
1042
+ declare function processA2AStreamData(streamData: any[]): (DistriMessage | DistriEvent)[];
1043
+ /**
1044
+ * Process A2A messages.json data and convert to DistriMessage array
1045
+ */
1046
+ declare function processA2AMessagesData(data: any[]): DistriMessage[];
466
1047
  /**
467
1048
  * Converts an A2A Part to a DistriPart
468
1049
  */
@@ -488,4 +1069,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
488
1069
  */
489
1070
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
490
1071
 
491
- export { Agent, type AgentHandoverEvent, type ChatProps, type CodeObservationPart, type ConnectionStatus, type DataPart, type DistriAgent, type DistriBaseTool, DistriClient, type DistriClientConfig, type DistriEvent, type DistriFnTool, type DistriMessage, type DistriPart, type DistriStreamEvent, type DistriThread, type FileType, type ImagePart, type InvokeConfig, type InvokeContext, type InvokeResult, type McpDefinition, type McpServerType, type MessageRole, type ModelProvider, type ModelSettings, type PlanPart, type RunErrorEvent, type RunFinishedEvent, type RunStartedEvent, type TextMessageContentEvent, type TextMessageEndEvent, type TextMessageStartEvent, type TextPart, type Thread, type ToolCall, type ToolCallArgsEvent, type ToolCallEndEvent, type ToolCallPart, type ToolCallResultEvent, type ToolCallStartEvent, type ToolResult, type ToolResultPart, convertA2AMessageToDistri, convertA2APartToDistri, convertDistriMessageToA2A, convertDistriPartToA2A, extractTextFromDistriMessage, extractToolCallsFromDistriMessage, extractToolResultsFromDistriMessage, isDistriEvent, isDistriMessage, 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 };