@distri/core 0.2.4 → 0.2.7
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/README.md +60 -1
- package/dist/index.d.mts +680 -273
- package/dist/index.d.ts +680 -273
- package/dist/index.js +1026 -226
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1020 -223
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import {
|
|
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
|
|
59
|
-
type: '
|
|
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
|
|
67
|
-
type: '
|
|
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,405 @@ interface FeedbackReceivedEvent {
|
|
|
129
117
|
feedback: string;
|
|
130
118
|
};
|
|
131
119
|
}
|
|
132
|
-
|
|
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
|
+
/**
|
|
261
|
+
* Response from the token endpoint
|
|
262
|
+
*/
|
|
263
|
+
static readonly TokenType: {
|
|
264
|
+
readonly Main: "main";
|
|
265
|
+
readonly Short: "short";
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Issue an access token + refresh token for temporary authentication.
|
|
269
|
+
* Requires an existing authenticated session (bearer token).
|
|
270
|
+
*
|
|
271
|
+
* @returns Token response with access/refresh token strings
|
|
272
|
+
* @throws ApiError if not authenticated or token issuance fails
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const { access_token, refresh_token } = await client.issueToken();
|
|
277
|
+
* // Persist the refresh token and use access_token for requests
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
issueToken(): Promise<{
|
|
281
|
+
access_token: string;
|
|
282
|
+
refresh_token: string;
|
|
283
|
+
expires_at: number;
|
|
284
|
+
}>;
|
|
285
|
+
/**
|
|
286
|
+
* Get the current access/refresh tokens.
|
|
287
|
+
*/
|
|
288
|
+
getTokens(): {
|
|
289
|
+
accessToken?: string;
|
|
290
|
+
refreshToken?: string;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Update the access/refresh tokens in memory.
|
|
294
|
+
*/
|
|
295
|
+
setTokens(tokens: {
|
|
296
|
+
accessToken?: string;
|
|
297
|
+
refreshToken?: string;
|
|
298
|
+
}): void;
|
|
299
|
+
/**
|
|
300
|
+
* Start streaming speech-to-text transcription via WebSocket
|
|
301
|
+
*/
|
|
302
|
+
streamingTranscription(options?: StreamingTranscriptionOptions): Promise<{
|
|
303
|
+
sendAudio: (audioData: ArrayBuffer) => void;
|
|
304
|
+
sendText: (text: string) => void;
|
|
305
|
+
stop: () => void;
|
|
306
|
+
close: () => void;
|
|
307
|
+
}>;
|
|
308
|
+
/**
|
|
309
|
+
* Transcribe audio blob to text using speech-to-text API
|
|
310
|
+
*/
|
|
311
|
+
transcribe(audioBlob: Blob, config?: SpeechToTextConfig): Promise<string>;
|
|
312
|
+
getConfiguration(): Promise<ConfigurationResponse>;
|
|
313
|
+
updateConfiguration(configuration: DistriConfiguration): Promise<ConfigurationResponse>;
|
|
314
|
+
/**
|
|
315
|
+
* Minimal LLM helper that proxies to the Distri server using Distri messages.
|
|
316
|
+
*/
|
|
317
|
+
llm(messages: DistriMessage[], tools?: unknown[], options?: LlmExecuteOptions): Promise<LLMResponse>;
|
|
318
|
+
/**
|
|
319
|
+
* Get all available agents from the Distri server
|
|
320
|
+
*/
|
|
321
|
+
getAgents(): Promise<AgentDefinition[]>;
|
|
322
|
+
/**
|
|
323
|
+
* Get specific agent by ID
|
|
324
|
+
*/
|
|
325
|
+
getAgent(agentId: string): Promise<AgentConfigWithTools>;
|
|
326
|
+
/**
|
|
327
|
+
* Get or create A2AClient for an agent
|
|
328
|
+
*/
|
|
329
|
+
private getA2AClient;
|
|
330
|
+
/**
|
|
331
|
+
* Send a message to an agent
|
|
332
|
+
*/
|
|
333
|
+
sendMessage(agentId: string, params: MessageSendParams): Promise<Message | Task>;
|
|
334
|
+
/**
|
|
335
|
+
* Send a streaming message to an agent
|
|
336
|
+
*/
|
|
337
|
+
sendMessageStream(agentId: string, params: MessageSendParams): AsyncGenerator<A2AStreamEventData>;
|
|
338
|
+
/**
|
|
339
|
+
* Get task details
|
|
340
|
+
*/
|
|
341
|
+
getTask(agentId: string, taskId: string): Promise<Task>;
|
|
342
|
+
/**
|
|
343
|
+
* Cancel a task
|
|
344
|
+
*/
|
|
345
|
+
cancelTask(agentId: string, taskId: string): Promise<void>;
|
|
346
|
+
/**
|
|
347
|
+
* Get threads from Distri server
|
|
348
|
+
*/
|
|
349
|
+
getThreads(): Promise<DistriThread[]>;
|
|
350
|
+
getThread(threadId: string): Promise<DistriThread>;
|
|
351
|
+
/**
|
|
352
|
+
* Get thread messages
|
|
353
|
+
*/
|
|
354
|
+
getThreadMessages(threadId: string): Promise<Message[]>;
|
|
355
|
+
/**
|
|
356
|
+
* Get messages from a thread as DistriMessage format
|
|
357
|
+
*/
|
|
358
|
+
getThreadMessagesAsDistri(threadId: string): Promise<DistriMessage[]>;
|
|
359
|
+
/**
|
|
360
|
+
* Send a DistriMessage to a thread
|
|
361
|
+
*/
|
|
362
|
+
sendDistriMessage(threadId: string, message: DistriMessage, context: InvokeContext): Promise<void>;
|
|
363
|
+
/**
|
|
364
|
+
* Complete an external tool call
|
|
365
|
+
*/
|
|
366
|
+
completeTool(agentId: string, result: ToolResult): Promise<void>;
|
|
367
|
+
/**
|
|
368
|
+
* Complete an inline hook with a mutation payload.
|
|
369
|
+
*/
|
|
370
|
+
completeInlineHook(hookId: string, mutation: any): Promise<void>;
|
|
371
|
+
/**
|
|
372
|
+
* Get the base URL for making direct requests
|
|
373
|
+
*/
|
|
374
|
+
get baseUrl(): string;
|
|
375
|
+
private applyTokens;
|
|
376
|
+
private ensureAccessToken;
|
|
377
|
+
private refreshTokens;
|
|
378
|
+
private performTokenRefresh;
|
|
379
|
+
private isTokenExpiring;
|
|
380
|
+
private getTokenExpiry;
|
|
381
|
+
private decodeJwtPayload;
|
|
382
|
+
private decodeBase64Url;
|
|
383
|
+
private applyAuthHeader;
|
|
384
|
+
/**
|
|
385
|
+
* Enhanced fetch with retry logic
|
|
386
|
+
*/
|
|
387
|
+
private fetchAbsolute;
|
|
388
|
+
/**
|
|
389
|
+
* Enhanced fetch with retry logic and auth headers.
|
|
390
|
+
* Exposed publicly for extensions like DistriHomeClient.
|
|
391
|
+
*/
|
|
392
|
+
fetch(input: RequestInfo | URL, initialInit?: RequestInit): Promise<Response>;
|
|
393
|
+
/**
|
|
394
|
+
* Delay utility
|
|
395
|
+
*/
|
|
396
|
+
private delay;
|
|
397
|
+
/**
|
|
398
|
+
* Debug logging
|
|
399
|
+
*/
|
|
400
|
+
private debug;
|
|
401
|
+
/**
|
|
402
|
+
* Helper method to create A2A messages
|
|
403
|
+
*/
|
|
404
|
+
static initMessage(parts: Part[] | string, role: "agent" | "user" | undefined, message: Omit<Partial<Message>, 'parts' | 'role' | 'kind'>): Message;
|
|
405
|
+
/**
|
|
406
|
+
* Create a DistriMessage instance
|
|
407
|
+
*/
|
|
408
|
+
static initDistriMessage(role: DistriMessage['role'], parts: DistriPart[], id?: string, created_at?: number): DistriMessage;
|
|
409
|
+
/**
|
|
410
|
+
* Helper method to create message send parameters
|
|
411
|
+
*/
|
|
412
|
+
static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any): MessageSendParams;
|
|
413
|
+
/**
|
|
414
|
+
* Create MessageSendParams from a DistriMessage using InvokeContext
|
|
415
|
+
*/
|
|
416
|
+
static initDistriMessageParams(message: DistriMessage, context: InvokeContext): MessageSendParams;
|
|
417
|
+
}
|
|
418
|
+
declare function uuidv4(): string;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Configuration for Agent invoke method
|
|
422
|
+
*/
|
|
423
|
+
interface InvokeConfig {
|
|
424
|
+
/** Configuration for the message */
|
|
425
|
+
configuration?: MessageSendParams['configuration'];
|
|
426
|
+
/** Context/thread ID */
|
|
427
|
+
contextId?: string;
|
|
428
|
+
/** Metadata for the requests */
|
|
429
|
+
metadata?: any;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Result from agent invoke
|
|
433
|
+
*/
|
|
434
|
+
interface InvokeResult {
|
|
435
|
+
/** Final response message */
|
|
436
|
+
message?: Message;
|
|
437
|
+
/** Task if created */
|
|
438
|
+
task?: any;
|
|
439
|
+
/** Whether the response was streamed */
|
|
440
|
+
streamed: boolean;
|
|
441
|
+
}
|
|
442
|
+
interface ExternalToolValidationResult {
|
|
443
|
+
isValid: boolean;
|
|
444
|
+
requiredTools: string[];
|
|
445
|
+
providedTools: string[];
|
|
446
|
+
missingTools: string[];
|
|
447
|
+
message?: string;
|
|
448
|
+
}
|
|
449
|
+
declare class ExternalToolValidationError extends DistriError {
|
|
450
|
+
missingTools: string[];
|
|
451
|
+
requiredTools: string[];
|
|
452
|
+
providedTools: string[];
|
|
453
|
+
agentName: string;
|
|
454
|
+
constructor(agentName: string, result: ExternalToolValidationResult);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Enhanced Agent class with simple tool system following AG-UI pattern
|
|
458
|
+
*/
|
|
459
|
+
declare class Agent {
|
|
460
|
+
private client;
|
|
461
|
+
private agentDefinition;
|
|
462
|
+
private hookHandlers;
|
|
463
|
+
private defaultHookHandler;
|
|
464
|
+
constructor(agentDefinition: AgentConfigWithTools, client: DistriClient);
|
|
465
|
+
/**
|
|
466
|
+
* Get agent information
|
|
467
|
+
*/
|
|
468
|
+
get id(): string;
|
|
469
|
+
get name(): string;
|
|
470
|
+
get description(): string | undefined;
|
|
471
|
+
get agentType(): string | undefined;
|
|
472
|
+
get iconUrl(): string | undefined;
|
|
473
|
+
/**
|
|
474
|
+
* Get the full agent definition (including backend tools)
|
|
475
|
+
*/
|
|
476
|
+
getDefinition(): AgentConfigWithTools;
|
|
477
|
+
/**
|
|
478
|
+
* Fetch messages for a thread (public method for useChat)
|
|
479
|
+
*/
|
|
480
|
+
getThreadMessages(threadId: string): Promise<Message[]>;
|
|
481
|
+
/**
|
|
482
|
+
* Direct (non-streaming) invoke
|
|
483
|
+
*/
|
|
484
|
+
invoke(params: MessageSendParams, tools?: DistriBaseTool[], hooks?: Record<string, HookHandler>): Promise<Message>;
|
|
485
|
+
/**
|
|
486
|
+
* Streaming invoke
|
|
487
|
+
*/
|
|
488
|
+
invokeStream(params: MessageSendParams, tools?: DistriBaseTool[], hooks?: Record<string, HookHandler>): Promise<AsyncGenerator<DistriChatMessage>>;
|
|
489
|
+
/**
|
|
490
|
+
* Validate that required external tools are registered before invoking.
|
|
491
|
+
*/
|
|
492
|
+
validateExternalTools(tools?: DistriBaseTool[]): ExternalToolValidationResult;
|
|
493
|
+
/**
|
|
494
|
+
* Enhance message params with tool definitions
|
|
495
|
+
*/
|
|
496
|
+
private enhanceParamsWithTools;
|
|
497
|
+
private assertExternalTools;
|
|
498
|
+
private getRequiredExternalTools;
|
|
499
|
+
private resolveToolConfig;
|
|
500
|
+
private extractToolConfig;
|
|
501
|
+
private formatExternalToolValidationMessage;
|
|
502
|
+
/**
|
|
503
|
+
* Register multiple hooks at once.
|
|
504
|
+
*/
|
|
505
|
+
registerHooks(hooks: Record<string, HookHandler>, defaultHandler?: HookHandler): void;
|
|
506
|
+
/**
|
|
507
|
+
* Create an agent instance from an agent ID
|
|
508
|
+
*/
|
|
509
|
+
static create(agentIdOrDef: string | AgentConfigWithTools, client: DistriClient): Promise<Agent>;
|
|
510
|
+
/**
|
|
511
|
+
* Complete an external tool call by sending the result back to the server
|
|
512
|
+
*/
|
|
513
|
+
completeTool(result: ToolResult): Promise<void>;
|
|
514
|
+
/**
|
|
515
|
+
* List all available agents
|
|
516
|
+
*/
|
|
517
|
+
static list(client: DistriClient): Promise<Agent[]>;
|
|
518
|
+
}
|
|
133
519
|
|
|
134
520
|
/**
|
|
135
521
|
* Message roles supported by Distri
|
|
@@ -142,7 +528,16 @@ interface DistriMessage {
|
|
|
142
528
|
id: string;
|
|
143
529
|
role: MessageRole;
|
|
144
530
|
parts: DistriPart[];
|
|
145
|
-
created_at
|
|
531
|
+
created_at: number;
|
|
532
|
+
step_id?: string;
|
|
533
|
+
is_final?: boolean;
|
|
534
|
+
}
|
|
535
|
+
interface LlmExecuteOptions {
|
|
536
|
+
thread_id?: string;
|
|
537
|
+
parent_task_id?: string;
|
|
538
|
+
run_id?: string;
|
|
539
|
+
model_settings?: any;
|
|
540
|
+
is_sub_task?: boolean;
|
|
146
541
|
}
|
|
147
542
|
interface AssistantWithToolCalls {
|
|
148
543
|
id: string;
|
|
@@ -156,6 +551,36 @@ interface AssistantWithToolCalls {
|
|
|
156
551
|
is_external: boolean;
|
|
157
552
|
reason: string | null;
|
|
158
553
|
}
|
|
554
|
+
interface UseToolsOptions {
|
|
555
|
+
agent?: Agent;
|
|
556
|
+
externalTools?: DistriBaseTool[];
|
|
557
|
+
executionOptions?: ToolExecutionOptions;
|
|
558
|
+
}
|
|
559
|
+
interface ToolExecutionOptions {
|
|
560
|
+
autoExecute?: boolean;
|
|
561
|
+
}
|
|
562
|
+
interface HookMutation {
|
|
563
|
+
dynamic_values: Record<string, any>;
|
|
564
|
+
}
|
|
565
|
+
interface HookContext {
|
|
566
|
+
agent_id: string;
|
|
567
|
+
thread_id: string;
|
|
568
|
+
task_id: string;
|
|
569
|
+
run_id: string;
|
|
570
|
+
}
|
|
571
|
+
interface InlineHookRequest {
|
|
572
|
+
hook_id: string;
|
|
573
|
+
hook: string;
|
|
574
|
+
context: HookContext;
|
|
575
|
+
timeout_ms?: number;
|
|
576
|
+
fire_and_forget?: boolean;
|
|
577
|
+
message?: any;
|
|
578
|
+
plan?: any;
|
|
579
|
+
result?: any;
|
|
580
|
+
}
|
|
581
|
+
interface InlineHookEventData extends InlineHookRequest {
|
|
582
|
+
}
|
|
583
|
+
type HookHandler = (req: InlineHookRequest) => Promise<HookMutation> | HookMutation;
|
|
159
584
|
interface ToolResults {
|
|
160
585
|
id: string;
|
|
161
586
|
type: 'tool_results';
|
|
@@ -166,15 +591,6 @@ interface ToolResults {
|
|
|
166
591
|
rejected: boolean;
|
|
167
592
|
reason: string | null;
|
|
168
593
|
}
|
|
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
594
|
interface DistriPlan {
|
|
179
595
|
id: string;
|
|
180
596
|
type: 'plan';
|
|
@@ -184,8 +600,33 @@ interface DistriPlan {
|
|
|
184
600
|
}
|
|
185
601
|
interface BasePlanStep {
|
|
186
602
|
id: string;
|
|
187
|
-
title: string;
|
|
188
603
|
}
|
|
604
|
+
interface ThoughtPlanStep extends BasePlanStep {
|
|
605
|
+
type: 'thought';
|
|
606
|
+
message: string;
|
|
607
|
+
}
|
|
608
|
+
interface ActionPlanStep extends BasePlanStep {
|
|
609
|
+
type: 'action';
|
|
610
|
+
action: PlanAction;
|
|
611
|
+
}
|
|
612
|
+
interface CodePlanStep extends BasePlanStep {
|
|
613
|
+
type: 'code';
|
|
614
|
+
code: string;
|
|
615
|
+
language: string;
|
|
616
|
+
}
|
|
617
|
+
interface FinalResultPlanStep extends BasePlanStep {
|
|
618
|
+
type: 'final_result';
|
|
619
|
+
content: string;
|
|
620
|
+
tool_calls: any[];
|
|
621
|
+
}
|
|
622
|
+
interface PlanAction {
|
|
623
|
+
tool_name?: string;
|
|
624
|
+
input?: string;
|
|
625
|
+
prompt?: string;
|
|
626
|
+
context?: any[];
|
|
627
|
+
tool_calling_config?: any;
|
|
628
|
+
}
|
|
629
|
+
type PlanStep = ThoughtPlanStep | ActionPlanStep | CodePlanStep | FinalResultPlanStep;
|
|
189
630
|
interface LlmPlanStep extends BasePlanStep {
|
|
190
631
|
type: 'llm_call';
|
|
191
632
|
prompt: string;
|
|
@@ -204,82 +645,71 @@ interface ReactStep extends BasePlanStep {
|
|
|
204
645
|
thought: string;
|
|
205
646
|
action: string;
|
|
206
647
|
}
|
|
207
|
-
|
|
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;
|
|
648
|
+
type DistriStreamEvent = DistriMessage | DistriEvent;
|
|
215
649
|
/**
|
|
216
650
|
* Context required for constructing A2A messages from DistriMessage
|
|
217
651
|
*/
|
|
218
652
|
interface InvokeContext {
|
|
219
653
|
thread_id: string;
|
|
220
654
|
run_id?: string;
|
|
655
|
+
task_id?: string;
|
|
221
656
|
getMetadata?: () => any;
|
|
222
657
|
}
|
|
223
658
|
/**
|
|
224
659
|
* Distri message parts - equivalent to Rust enum Part
|
|
225
660
|
*/
|
|
226
661
|
type TextPart = {
|
|
227
|
-
|
|
228
|
-
|
|
662
|
+
part_type: 'text';
|
|
663
|
+
data: string;
|
|
229
664
|
};
|
|
230
|
-
type
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
code: string;
|
|
665
|
+
type ToolCallPart = {
|
|
666
|
+
part_type: 'tool_call';
|
|
667
|
+
data: ToolCall;
|
|
234
668
|
};
|
|
235
|
-
type
|
|
236
|
-
|
|
237
|
-
|
|
669
|
+
type ToolResultRefPart = {
|
|
670
|
+
part_type: 'tool_result';
|
|
671
|
+
data: ToolResult;
|
|
238
672
|
};
|
|
239
|
-
type
|
|
240
|
-
|
|
241
|
-
|
|
673
|
+
type ImagePart = {
|
|
674
|
+
part_type: 'image';
|
|
675
|
+
data: FileType;
|
|
242
676
|
};
|
|
243
|
-
type ImagePart = ImageUrlPart | ImageBytesPart;
|
|
244
677
|
type DataPart = {
|
|
245
|
-
|
|
246
|
-
data:
|
|
678
|
+
part_type: 'data';
|
|
679
|
+
data: object;
|
|
247
680
|
};
|
|
248
|
-
type
|
|
249
|
-
type: 'tool_call';
|
|
250
|
-
tool_call: ToolCall;
|
|
251
|
-
};
|
|
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;
|
|
681
|
+
type DistriPart = TextPart | ToolCallPart | ToolResultRefPart | ImagePart | DataPart;
|
|
261
682
|
/**
|
|
262
683
|
* File type for images
|
|
263
684
|
*/
|
|
264
685
|
interface FileBytes {
|
|
686
|
+
type: 'bytes';
|
|
265
687
|
mime_type: string;
|
|
266
688
|
data: string;
|
|
267
689
|
name?: string;
|
|
268
690
|
}
|
|
269
691
|
interface FileUrl {
|
|
692
|
+
type: 'url';
|
|
270
693
|
mime_type: string;
|
|
271
694
|
url: string;
|
|
272
695
|
name?: string;
|
|
273
696
|
}
|
|
274
697
|
type FileType = FileBytes | FileUrl;
|
|
698
|
+
interface ToolDefinition {
|
|
699
|
+
name: string;
|
|
700
|
+
description: string;
|
|
701
|
+
parameters: object;
|
|
702
|
+
examples?: string;
|
|
703
|
+
output_schema?: object;
|
|
704
|
+
}
|
|
275
705
|
/**
|
|
276
706
|
* Tool definition interface following AG-UI pattern
|
|
277
707
|
*/
|
|
278
|
-
interface DistriBaseTool {
|
|
279
|
-
name: string;
|
|
708
|
+
interface DistriBaseTool extends ToolDefinition {
|
|
280
709
|
type: 'function' | 'ui';
|
|
281
|
-
|
|
282
|
-
|
|
710
|
+
is_final?: boolean;
|
|
711
|
+
autoExecute?: boolean;
|
|
712
|
+
isExternal?: boolean;
|
|
283
713
|
}
|
|
284
714
|
interface DistriFnTool extends DistriBaseTool {
|
|
285
715
|
type: 'function';
|
|
@@ -290,7 +720,7 @@ interface DistriFnTool extends DistriBaseTool {
|
|
|
290
720
|
* Tool handler function
|
|
291
721
|
*/
|
|
292
722
|
interface ToolHandler {
|
|
293
|
-
(input: any): Promise<string | number | boolean | null | object>;
|
|
723
|
+
(input: any): Promise<string | number | boolean | null | DistriPart[] | object>;
|
|
294
724
|
}
|
|
295
725
|
/**
|
|
296
726
|
* Tool call from agent
|
|
@@ -301,15 +731,41 @@ interface ToolCall {
|
|
|
301
731
|
input: any;
|
|
302
732
|
}
|
|
303
733
|
/**
|
|
304
|
-
* Tool result
|
|
734
|
+
* Tool result structure that can come from backend or frontend
|
|
305
735
|
*/
|
|
306
736
|
interface ToolResult {
|
|
307
|
-
tool_call_id: string;
|
|
308
|
-
tool_name: string;
|
|
309
|
-
|
|
737
|
+
readonly tool_call_id: string;
|
|
738
|
+
readonly tool_name: string;
|
|
739
|
+
readonly parts: readonly DistriPart[];
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Tool result data that goes inside the parts array
|
|
743
|
+
*/
|
|
744
|
+
interface ToolResultData {
|
|
745
|
+
result: string | number | boolean | null | object;
|
|
310
746
|
success: boolean;
|
|
311
747
|
error?: string;
|
|
312
748
|
}
|
|
749
|
+
declare function isArrayParts(result: any): boolean;
|
|
750
|
+
/**
|
|
751
|
+
* Type-safe helper to create a successful ToolResult
|
|
752
|
+
* Uses proper DistriPart structure - conversion to backend format happens in encoder
|
|
753
|
+
*/
|
|
754
|
+
declare function createSuccessfulToolResult(toolCallId: string, toolName: string, result: string | number | boolean | null | object | DistriPart[]): ToolResult;
|
|
755
|
+
/**
|
|
756
|
+
* Type-safe helper to create a failed ToolResult
|
|
757
|
+
* Uses proper DistriPart structure - conversion to backend format happens in encoder
|
|
758
|
+
*/
|
|
759
|
+
declare function createFailedToolResult(toolCallId: string, toolName: string, error: string, result?: string | number | boolean | null | object): ToolResult;
|
|
760
|
+
/**
|
|
761
|
+
* Type-safe helper to extract ToolResultData from a ToolResult
|
|
762
|
+
* Handles both frontend DistriPart format and backend BackendPart format
|
|
763
|
+
*/
|
|
764
|
+
declare function extractToolResultData(toolResult: ToolResult): ToolResultData | null;
|
|
765
|
+
interface AgentConfigWithTools extends AgentDefinition {
|
|
766
|
+
markdown?: string;
|
|
767
|
+
resolved_tools?: ToolDefinition[];
|
|
768
|
+
}
|
|
313
769
|
/**
|
|
314
770
|
* Distri-specific Agent type that wraps A2A AgentCard
|
|
315
771
|
*/
|
|
@@ -317,6 +773,8 @@ interface AgentDefinition {
|
|
|
317
773
|
/** The name of the agent. */
|
|
318
774
|
name: string;
|
|
319
775
|
id: string;
|
|
776
|
+
/** Optional package identifier (workspace/plugin) that registered the agent */
|
|
777
|
+
package_name?: string | null;
|
|
320
778
|
/** A brief description of the agent's purpose. */
|
|
321
779
|
description?: string;
|
|
322
780
|
/** The version of the agent. */
|
|
@@ -327,6 +785,8 @@ interface AgentDefinition {
|
|
|
327
785
|
mcp_servers?: McpDefinition[];
|
|
328
786
|
/** Settings related to the model used by the agent. */
|
|
329
787
|
model_settings?: ModelSettings;
|
|
788
|
+
/** Secondary Model Settings used for analysis */
|
|
789
|
+
analysis_model_settings?: ModelSettings;
|
|
330
790
|
/** The size of the history to maintain for the agent. */
|
|
331
791
|
history_size?: number;
|
|
332
792
|
/** The planning configuration for the agent, if any. */
|
|
@@ -337,6 +797,21 @@ interface AgentDefinition {
|
|
|
337
797
|
skills?: AgentSkill[];
|
|
338
798
|
/** List of sub-agents that this agent can transfer control to */
|
|
339
799
|
sub_agents?: string[];
|
|
800
|
+
agent_type?: string;
|
|
801
|
+
context_size?: number;
|
|
802
|
+
tools?: DistriBaseTool[];
|
|
803
|
+
browser_config?: BrowserAgentConfig;
|
|
804
|
+
}
|
|
805
|
+
interface BrowserAgentConfig {
|
|
806
|
+
enabled?: boolean;
|
|
807
|
+
persist_session?: boolean;
|
|
808
|
+
runtime?: DistriBrowserRuntimeConfig | null;
|
|
809
|
+
}
|
|
810
|
+
interface DistriBrowserRuntimeConfig {
|
|
811
|
+
window_size?: [number, number];
|
|
812
|
+
headless?: boolean;
|
|
813
|
+
enable_stealth_mode?: boolean;
|
|
814
|
+
enable_real_emulation?: boolean;
|
|
340
815
|
}
|
|
341
816
|
interface McpDefinition {
|
|
342
817
|
/** The filter applied to the tools in this MCP definition. */
|
|
@@ -350,18 +825,31 @@ interface ModelSettings {
|
|
|
350
825
|
model: string;
|
|
351
826
|
temperature: number;
|
|
352
827
|
max_tokens: number;
|
|
828
|
+
context_size: number;
|
|
353
829
|
top_p: number;
|
|
354
830
|
frequency_penalty: number;
|
|
355
831
|
presence_penalty: number;
|
|
356
|
-
|
|
357
|
-
provider: ModelProvider;
|
|
832
|
+
provider: ModelProviderConfig;
|
|
358
833
|
/** Additional parameters for the agent, if any. */
|
|
359
834
|
parameters?: any;
|
|
360
835
|
/** The format of the response, if specified. */
|
|
361
836
|
response_format?: any;
|
|
362
837
|
}
|
|
363
838
|
type McpServerType = 'tool' | 'agent';
|
|
364
|
-
type
|
|
839
|
+
type ModelProviderName = 'openai' | 'openai_compat' | 'vllora' | string;
|
|
840
|
+
type ModelProviderConfig = {
|
|
841
|
+
name: 'openai';
|
|
842
|
+
} | {
|
|
843
|
+
name: 'openai_compat';
|
|
844
|
+
base_url: string;
|
|
845
|
+
project_id?: string;
|
|
846
|
+
} | {
|
|
847
|
+
name: 'vllora';
|
|
848
|
+
base_url?: string;
|
|
849
|
+
} | {
|
|
850
|
+
name: string;
|
|
851
|
+
[key: string]: any;
|
|
852
|
+
};
|
|
365
853
|
/**
|
|
366
854
|
* Distri Thread type for conversation management
|
|
367
855
|
*/
|
|
@@ -388,22 +876,121 @@ interface ChatProps {
|
|
|
388
876
|
agent: AgentDefinition;
|
|
389
877
|
onThreadUpdate?: () => void;
|
|
390
878
|
}
|
|
879
|
+
interface SpeechToTextConfig {
|
|
880
|
+
model?: 'whisper-1';
|
|
881
|
+
language?: string;
|
|
882
|
+
temperature?: number;
|
|
883
|
+
}
|
|
884
|
+
interface StreamingTranscriptionOptions {
|
|
885
|
+
onTranscript?: (text: string, isFinal: boolean) => void;
|
|
886
|
+
onError?: (error: Error) => void;
|
|
887
|
+
onStart?: () => void;
|
|
888
|
+
onEnd?: () => void;
|
|
889
|
+
}
|
|
391
890
|
/**
|
|
392
891
|
* Connection Status
|
|
393
892
|
*/
|
|
394
893
|
type ConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
894
|
+
/**
|
|
895
|
+
* Default base URL for the Distri cloud service
|
|
896
|
+
*/
|
|
897
|
+
declare const DEFAULT_BASE_URL = "https://api.distri.dev";
|
|
395
898
|
/**
|
|
396
899
|
* Distri Client Configuration
|
|
397
900
|
*/
|
|
398
901
|
interface DistriClientConfig {
|
|
902
|
+
/**
|
|
903
|
+
* Base URL of the Distri server
|
|
904
|
+
* Default: https://api.distri.dev
|
|
905
|
+
*/
|
|
399
906
|
baseUrl: string;
|
|
907
|
+
/**
|
|
908
|
+
* API version (currently unused)
|
|
909
|
+
*/
|
|
400
910
|
apiVersion?: string;
|
|
911
|
+
/**
|
|
912
|
+
* Request timeout in milliseconds (default: 30000)
|
|
913
|
+
*/
|
|
401
914
|
timeout?: number;
|
|
915
|
+
/**
|
|
916
|
+
* Number of retry attempts for failed requests (default: 3)
|
|
917
|
+
*/
|
|
402
918
|
retryAttempts?: number;
|
|
919
|
+
/**
|
|
920
|
+
* Delay between retry attempts in milliseconds (default: 1000)
|
|
921
|
+
*/
|
|
403
922
|
retryDelay?: number;
|
|
923
|
+
/**
|
|
924
|
+
* Enable debug logging
|
|
925
|
+
*/
|
|
404
926
|
debug?: boolean;
|
|
927
|
+
/**
|
|
928
|
+
* Custom headers to include in all requests
|
|
929
|
+
*/
|
|
405
930
|
headers?: Record<string, string>;
|
|
931
|
+
/**
|
|
932
|
+
* Request interceptor for modifying requests before sending
|
|
933
|
+
*/
|
|
406
934
|
interceptor?: (init?: RequestInit) => Promise<RequestInit | undefined>;
|
|
935
|
+
/**
|
|
936
|
+
* Access token for bearer auth (optional)
|
|
937
|
+
*/
|
|
938
|
+
accessToken?: string;
|
|
939
|
+
/**
|
|
940
|
+
* Refresh token for bearer auth (optional)
|
|
941
|
+
*/
|
|
942
|
+
refreshToken?: string;
|
|
943
|
+
/**
|
|
944
|
+
* Token refresh skew in milliseconds (default: 60000)
|
|
945
|
+
*/
|
|
946
|
+
tokenRefreshSkewMs?: number;
|
|
947
|
+
/**
|
|
948
|
+
* Callback invoked when tokens are refreshed
|
|
949
|
+
*/
|
|
950
|
+
onTokenRefresh?: (tokens: {
|
|
951
|
+
accessToken: string;
|
|
952
|
+
refreshToken: string;
|
|
953
|
+
}) => void;
|
|
954
|
+
}
|
|
955
|
+
interface LLMResponse {
|
|
956
|
+
finish_reason: string;
|
|
957
|
+
content: string;
|
|
958
|
+
tool_calls: ToolCall[];
|
|
959
|
+
token_usage: number;
|
|
960
|
+
tools?: any[];
|
|
961
|
+
}
|
|
962
|
+
interface ExternalMcpServer {
|
|
963
|
+
name: string;
|
|
964
|
+
[key: string]: any;
|
|
965
|
+
}
|
|
966
|
+
interface ServerConfig {
|
|
967
|
+
base_url?: string;
|
|
968
|
+
host?: string;
|
|
969
|
+
port?: number;
|
|
970
|
+
[key: string]: any;
|
|
971
|
+
}
|
|
972
|
+
interface DistriConfiguration {
|
|
973
|
+
name: string;
|
|
974
|
+
version: string;
|
|
975
|
+
description?: string;
|
|
976
|
+
license?: string;
|
|
977
|
+
working_directory?: string;
|
|
978
|
+
agents?: string[];
|
|
979
|
+
mcp_servers?: ExternalMcpServer[];
|
|
980
|
+
server?: ServerConfig;
|
|
981
|
+
model_settings?: ModelSettings;
|
|
982
|
+
analysis_model_settings?: ModelSettings;
|
|
983
|
+
keywords?: string[];
|
|
984
|
+
[key: string]: any;
|
|
985
|
+
}
|
|
986
|
+
interface ConfigurationMeta {
|
|
987
|
+
base_path: string;
|
|
988
|
+
overrides_path: string;
|
|
989
|
+
overrides_active: boolean;
|
|
990
|
+
}
|
|
991
|
+
interface ConfigurationResponse {
|
|
992
|
+
configuration: DistriConfiguration;
|
|
993
|
+
meta: ConfigurationMeta;
|
|
407
994
|
}
|
|
408
995
|
/**
|
|
409
996
|
* Error Types
|
|
@@ -427,183 +1014,7 @@ declare class ConnectionError extends DistriError {
|
|
|
427
1014
|
type A2AStreamEventData = Message | TaskStatusUpdateEvent | TaskArtifactUpdateEvent | Task;
|
|
428
1015
|
declare function isDistriMessage(event: DistriStreamEvent): event is DistriMessage;
|
|
429
1016
|
declare function isDistriEvent(event: DistriStreamEvent): event is DistriEvent;
|
|
430
|
-
|
|
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
|
-
}
|
|
1017
|
+
type DistriChatMessage = DistriEvent | DistriMessage;
|
|
607
1018
|
|
|
608
1019
|
/**
|
|
609
1020
|
* Converts an A2A Message to a DistriMessage
|
|
@@ -613,10 +1024,6 @@ declare function convertA2AMessageToDistri(a2aMessage: Message): DistriMessage;
|
|
|
613
1024
|
* Converts A2A status-update events to DistriEvent based on metadata type
|
|
614
1025
|
*/
|
|
615
1026
|
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
1027
|
/**
|
|
621
1028
|
* Enhanced decoder for A2A stream events that properly handles all event types
|
|
622
1029
|
*/
|
|
@@ -624,7 +1031,7 @@ declare function decodeA2AStreamEvent(event: any): DistriChatMessage | null;
|
|
|
624
1031
|
/**
|
|
625
1032
|
* Process A2A stream data (like from stream.json) and convert to DistriMessage/DistriEvent/DistriArtifact array
|
|
626
1033
|
*/
|
|
627
|
-
declare function processA2AStreamData(streamData: any[]): (DistriMessage | DistriEvent
|
|
1034
|
+
declare function processA2AStreamData(streamData: any[]): (DistriMessage | DistriEvent)[];
|
|
628
1035
|
/**
|
|
629
1036
|
* Process A2A messages.json data and convert to DistriMessage array
|
|
630
1037
|
*/
|
|
@@ -654,4 +1061,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
|
|
|
654
1061
|
*/
|
|
655
1062
|
declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
|
|
656
1063
|
|
|
657
|
-
export { A2AProtocolError, type A2AStreamEventData, Agent, type AgentDefinition, type AgentHandoverEvent, ApiError, type AssistantWithToolCalls, type BasePlanStep, type BatchToolCallsStep, type ChatProps, type
|
|
1064
|
+
export { A2AProtocolError, type A2AStreamEventData, type ActionPlanStep, Agent, type AgentConfigWithTools, 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 ToolDefinition, 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 };
|