@kuntur/a2a-carbon-chat-adapter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +262 -0
- package/dist/index.cjs +2281 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1380 -0
- package/dist/index.d.ts +1380 -0
- package/dist/index.js +2247 -0
- package/dist/index.js.map +1 -0
- package/package.json +94 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1380 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Agent Configuration Types
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A2A Extension configuration passed to agents
|
|
9
|
+
*/
|
|
10
|
+
interface A2AExtensionConfig$1 {
|
|
11
|
+
settings?: {
|
|
12
|
+
thinking_group?: {
|
|
13
|
+
thinking?: boolean;
|
|
14
|
+
};
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Agent Configuration
|
|
21
|
+
*
|
|
22
|
+
* Defines how to connect to an A2A agent.
|
|
23
|
+
*/
|
|
24
|
+
interface AgentConfig {
|
|
25
|
+
/** Unique identifier for this agent configuration */
|
|
26
|
+
id: string;
|
|
27
|
+
/** Display name shown in UI */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Agent's A2A endpoint URL (without /jsonrpc suffix) */
|
|
30
|
+
url: string;
|
|
31
|
+
/** Optional API key for authentication */
|
|
32
|
+
apiKey?: string;
|
|
33
|
+
/** Optional description for agent switcher UI */
|
|
34
|
+
description?: string;
|
|
35
|
+
/** Optional icon URL for agent avatar */
|
|
36
|
+
iconUrl?: string;
|
|
37
|
+
/** Optional A2A extension configuration */
|
|
38
|
+
extensions?: A2AExtensionConfig$1;
|
|
39
|
+
/** Optional metadata for application-specific use */
|
|
40
|
+
metadata?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Multi-agent registry for applications with multiple agents
|
|
44
|
+
*/
|
|
45
|
+
interface AgentRegistry {
|
|
46
|
+
/** Map of agent ID to configuration */
|
|
47
|
+
agents: Record<string, AgentConfig>;
|
|
48
|
+
/** Default agent ID to use when none specified */
|
|
49
|
+
defaultAgentId?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Agent connection state
|
|
53
|
+
*/
|
|
54
|
+
type AgentConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error' | 'streaming';
|
|
55
|
+
/**
|
|
56
|
+
* Agent state including connection and conversation
|
|
57
|
+
*/
|
|
58
|
+
interface AgentState {
|
|
59
|
+
connectionState: AgentConnectionState;
|
|
60
|
+
error?: Error;
|
|
61
|
+
taskId?: string;
|
|
62
|
+
contextId?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Extension type definitions based on agentstack-sdk
|
|
67
|
+
* Reference: https://github.com/i-am-bee/agentstack/blob/main/apps/agentstack-sdk-ts/src/client/a2a/extensions/services/llm.ts
|
|
68
|
+
*/
|
|
69
|
+
interface LLMDemand {
|
|
70
|
+
description?: string | null;
|
|
71
|
+
suggested?: string[] | null;
|
|
72
|
+
}
|
|
73
|
+
interface LLMDemands {
|
|
74
|
+
llm_demands: Record<string, LLMDemand>;
|
|
75
|
+
}
|
|
76
|
+
interface LLMFulfillment {
|
|
77
|
+
identifier?: string | null;
|
|
78
|
+
api_base: string;
|
|
79
|
+
api_key: string;
|
|
80
|
+
api_model: string;
|
|
81
|
+
}
|
|
82
|
+
interface LLMFulfillments {
|
|
83
|
+
llm_fulfillments: Record<string, LLMFulfillment>;
|
|
84
|
+
}
|
|
85
|
+
interface EmbeddingDemand {
|
|
86
|
+
description?: string | null;
|
|
87
|
+
suggested?: string[] | null;
|
|
88
|
+
}
|
|
89
|
+
interface EmbeddingDemands {
|
|
90
|
+
embedding_demands: Record<string, EmbeddingDemand>;
|
|
91
|
+
}
|
|
92
|
+
interface EmbeddingFulfillment {
|
|
93
|
+
api_base: string;
|
|
94
|
+
api_key: string;
|
|
95
|
+
api_model: string;
|
|
96
|
+
}
|
|
97
|
+
interface EmbeddingFulfillments {
|
|
98
|
+
embedding_fulfillments: Record<string, EmbeddingFulfillment>;
|
|
99
|
+
}
|
|
100
|
+
interface MCPDemand {
|
|
101
|
+
suggested?: string[] | null;
|
|
102
|
+
}
|
|
103
|
+
interface MCPDemands {
|
|
104
|
+
mcp_demands: Record<string, MCPDemand>;
|
|
105
|
+
}
|
|
106
|
+
interface MCPFulfillment {
|
|
107
|
+
url: string;
|
|
108
|
+
}
|
|
109
|
+
interface MCPFulfillments {
|
|
110
|
+
mcp_fulfillments: Record<string, MCPFulfillment>;
|
|
111
|
+
}
|
|
112
|
+
interface SecretDemand {
|
|
113
|
+
name?: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
}
|
|
116
|
+
interface SecretDemands {
|
|
117
|
+
secret_demands: Record<string, SecretDemand>;
|
|
118
|
+
}
|
|
119
|
+
interface SecretFulfillment {
|
|
120
|
+
secret: string;
|
|
121
|
+
}
|
|
122
|
+
interface SecretFulfillments {
|
|
123
|
+
secret_fulfillments: Record<string, SecretFulfillment>;
|
|
124
|
+
}
|
|
125
|
+
interface SettingsDemands {
|
|
126
|
+
fields: unknown[];
|
|
127
|
+
}
|
|
128
|
+
interface SettingsFulfillments {
|
|
129
|
+
values: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
interface FormDemands {
|
|
132
|
+
initial_form?: unknown;
|
|
133
|
+
}
|
|
134
|
+
interface FormFulfillments {
|
|
135
|
+
values: Record<string, unknown>;
|
|
136
|
+
}
|
|
137
|
+
interface OAuthDemand {
|
|
138
|
+
scopes?: string[];
|
|
139
|
+
redirect_uri?: string;
|
|
140
|
+
}
|
|
141
|
+
interface OAuthDemands {
|
|
142
|
+
oauth_demands: Record<string, OAuthDemand>;
|
|
143
|
+
}
|
|
144
|
+
interface OAuthFulfillment {
|
|
145
|
+
access_token: string;
|
|
146
|
+
}
|
|
147
|
+
interface OAuthFulfillments {
|
|
148
|
+
oauth_fulfillments: Record<string, OAuthFulfillment>;
|
|
149
|
+
}
|
|
150
|
+
interface ContextToken {
|
|
151
|
+
token: string;
|
|
152
|
+
expires_at?: string | null;
|
|
153
|
+
}
|
|
154
|
+
interface Fulfillments {
|
|
155
|
+
llm: (demand: LLMDemands) => Promise<LLMFulfillments>;
|
|
156
|
+
embedding: (demand: EmbeddingDemands) => Promise<EmbeddingFulfillments>;
|
|
157
|
+
mcp: (demand: MCPDemands) => Promise<MCPFulfillments>;
|
|
158
|
+
oauth: (demand: OAuthDemands) => Promise<OAuthFulfillments>;
|
|
159
|
+
settings: (demand: SettingsDemands) => Promise<SettingsFulfillments>;
|
|
160
|
+
secrets: (demand: SecretDemands) => Promise<SecretFulfillments>;
|
|
161
|
+
form: (demand: FormDemands) => Promise<FormFulfillments>;
|
|
162
|
+
oauthRedirectUri: () => string | null;
|
|
163
|
+
getContextToken: () => ContextToken;
|
|
164
|
+
}
|
|
165
|
+
interface ExtractedDemands {
|
|
166
|
+
llmDemands: LLMDemands | null;
|
|
167
|
+
embeddingDemands: EmbeddingDemands | null;
|
|
168
|
+
mcpDemands: MCPDemands | null;
|
|
169
|
+
oauthDemands: OAuthDemands | null;
|
|
170
|
+
settingsDemands: SettingsDemands | null;
|
|
171
|
+
secretDemands: SecretDemands | null;
|
|
172
|
+
formDemands: FormDemands | null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Extension Handler for agent-client-zero
|
|
177
|
+
*
|
|
178
|
+
* This module handles:
|
|
179
|
+
* 1. Parsing agent card to extract extension demands
|
|
180
|
+
* 2. Building metadata with fulfillments for A2A requests
|
|
181
|
+
* 3. Parsing UI extension metadata from agent responses
|
|
182
|
+
*
|
|
183
|
+
* Reference: https://raw.githubusercontent.com/i-am-bee/agentstack/main/docs/development/custom-ui/client-sdk/extensions.mdx
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Platform configuration for fulfilling extension demands
|
|
188
|
+
* Users configure these values to provide services to agents
|
|
189
|
+
*/
|
|
190
|
+
interface PlatformConfig {
|
|
191
|
+
llm?: {
|
|
192
|
+
apiBase: string;
|
|
193
|
+
apiKey: string;
|
|
194
|
+
defaultModel: string;
|
|
195
|
+
};
|
|
196
|
+
embedding?: {
|
|
197
|
+
apiBase: string;
|
|
198
|
+
apiKey: string;
|
|
199
|
+
defaultModel: string;
|
|
200
|
+
};
|
|
201
|
+
mcp?: {
|
|
202
|
+
servers: Record<string, {
|
|
203
|
+
url: string;
|
|
204
|
+
}>;
|
|
205
|
+
};
|
|
206
|
+
oauth?: {
|
|
207
|
+
redirectUri: string;
|
|
208
|
+
providers: Record<string, {
|
|
209
|
+
accessToken: string;
|
|
210
|
+
}>;
|
|
211
|
+
};
|
|
212
|
+
secrets?: Record<string, string>;
|
|
213
|
+
settings?: Record<string, unknown>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Extract service extension demands from agent card capabilities
|
|
217
|
+
*
|
|
218
|
+
* Reference: https://github.com/i-am-bee/agentstack/blob/main/apps/agentstack-sdk-ts/src/client/a2a/extensions/handle-agent-card.ts
|
|
219
|
+
*/
|
|
220
|
+
declare function extractDemandsFromAgentCard(agentCard: AgentCard): ExtractedDemands;
|
|
221
|
+
/**
|
|
222
|
+
* Build fulfillment functions based on platform configuration
|
|
223
|
+
*/
|
|
224
|
+
declare function buildFulfillments(config: PlatformConfig): Partial<Fulfillments>;
|
|
225
|
+
/**
|
|
226
|
+
* Resolve metadata to send with A2A requests
|
|
227
|
+
* This builds the metadata object that fulfills agent extension demands
|
|
228
|
+
*
|
|
229
|
+
* Reference: https://github.com/i-am-bee/agentstack/blob/main/apps/agentstack-sdk-ts/src/client/a2a/extensions/handle-agent-card.ts#L60-L100
|
|
230
|
+
*/
|
|
231
|
+
declare function resolveMetadata(demands: ExtractedDemands, fulfillments: Partial<Fulfillments>): Promise<Record<string, unknown>>;
|
|
232
|
+
/**
|
|
233
|
+
* Main handler function - combines extraction and resolution
|
|
234
|
+
*
|
|
235
|
+
* Usage:
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const { demands, resolveMetadata } = handleAgentCard(agentCard);
|
|
238
|
+
* const metadata = await resolveMetadata(fulfillments);
|
|
239
|
+
* await client.sendMessage(message, metadata);
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
declare function handleAgentCard(agentCard: AgentCard): {
|
|
243
|
+
demands: ExtractedDemands;
|
|
244
|
+
resolveMetadata: (fulfillments: Partial<Fulfillments>) => Promise<Record<string, unknown>>;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
interface AgentCard {
|
|
248
|
+
name: string;
|
|
249
|
+
url: string;
|
|
250
|
+
description?: string;
|
|
251
|
+
skills?: Array<{
|
|
252
|
+
id: string;
|
|
253
|
+
name: string;
|
|
254
|
+
description: string;
|
|
255
|
+
}>;
|
|
256
|
+
securitySchemes?: Record<string, any>;
|
|
257
|
+
capabilities?: {
|
|
258
|
+
streaming?: boolean;
|
|
259
|
+
};
|
|
260
|
+
extensions?: string[];
|
|
261
|
+
}
|
|
262
|
+
interface A2AExtensionConfig {
|
|
263
|
+
settings?: {
|
|
264
|
+
thinking_group?: {
|
|
265
|
+
thinking?: boolean;
|
|
266
|
+
};
|
|
267
|
+
[key: string]: unknown;
|
|
268
|
+
};
|
|
269
|
+
[key: string]: unknown;
|
|
270
|
+
}
|
|
271
|
+
interface A2AClientConfig {
|
|
272
|
+
apiKey?: string;
|
|
273
|
+
extensions?: A2AExtensionConfig;
|
|
274
|
+
platformConfig?: PlatformConfig;
|
|
275
|
+
}
|
|
276
|
+
interface A2AError {
|
|
277
|
+
code: number;
|
|
278
|
+
message: string;
|
|
279
|
+
data?: any;
|
|
280
|
+
}
|
|
281
|
+
interface A2AMessagePart {
|
|
282
|
+
kind: 'text' | 'file' | 'data';
|
|
283
|
+
text?: string;
|
|
284
|
+
file?: {
|
|
285
|
+
name: string;
|
|
286
|
+
mimeType: string;
|
|
287
|
+
bytes?: string;
|
|
288
|
+
uri?: string;
|
|
289
|
+
};
|
|
290
|
+
data?: Record<string, unknown>;
|
|
291
|
+
}
|
|
292
|
+
interface A2AMessage {
|
|
293
|
+
role: string;
|
|
294
|
+
messageId: string;
|
|
295
|
+
parts: A2AMessagePart[];
|
|
296
|
+
}
|
|
297
|
+
interface StreamChunk {
|
|
298
|
+
contextId?: string;
|
|
299
|
+
taskId?: string;
|
|
300
|
+
kind: 'status-update' | 'artifact-update';
|
|
301
|
+
status?: {
|
|
302
|
+
state: 'submitted' | 'working' | 'completed' | 'failed' | 'canceled' | 'input-required' | 'auth-required';
|
|
303
|
+
message?: A2AMessage & {
|
|
304
|
+
metadata?: Record<string, unknown>;
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
artifact?: {
|
|
308
|
+
artifactId: string;
|
|
309
|
+
name?: string;
|
|
310
|
+
description?: string;
|
|
311
|
+
parts: A2AMessagePart[];
|
|
312
|
+
metadata?: Record<string, unknown>;
|
|
313
|
+
};
|
|
314
|
+
final?: boolean;
|
|
315
|
+
}
|
|
316
|
+
declare class A2AClient {
|
|
317
|
+
private baseUrl;
|
|
318
|
+
private jsonRpcUrl;
|
|
319
|
+
private apiKey;
|
|
320
|
+
private extensions;
|
|
321
|
+
private agentCard;
|
|
322
|
+
private platformConfig;
|
|
323
|
+
private extractedDemands;
|
|
324
|
+
private fulfillments;
|
|
325
|
+
constructor(agentUrl: string, config?: A2AClientConfig);
|
|
326
|
+
/**
|
|
327
|
+
* Get configured extensions
|
|
328
|
+
*/
|
|
329
|
+
getExtensions(): A2AExtensionConfig;
|
|
330
|
+
/**
|
|
331
|
+
* Update extension configuration
|
|
332
|
+
*/
|
|
333
|
+
setExtensions(extensions: A2AExtensionConfig): void;
|
|
334
|
+
initialize(): Promise<AgentCard>;
|
|
335
|
+
getAgentCard(): AgentCard | null;
|
|
336
|
+
getJsonRpcUrl(): string;
|
|
337
|
+
/**
|
|
338
|
+
* Get resolved metadata for A2A requests
|
|
339
|
+
* Call this after initialize() to get metadata that fulfills agent demands
|
|
340
|
+
*/
|
|
341
|
+
getResolvedMetadata(): Promise<Record<string, unknown>>;
|
|
342
|
+
/**
|
|
343
|
+
* Get extracted demands from agent card
|
|
344
|
+
*/
|
|
345
|
+
getExtractedDemands(): ExtractedDemands | null;
|
|
346
|
+
/**
|
|
347
|
+
* Update platform configuration after initialization
|
|
348
|
+
*/
|
|
349
|
+
setPlatformConfig(config: PlatformConfig): void;
|
|
350
|
+
/**
|
|
351
|
+
* Get current platform configuration
|
|
352
|
+
*/
|
|
353
|
+
getPlatformConfig(): PlatformConfig | null;
|
|
354
|
+
/**
|
|
355
|
+
* Build the base params object for A2A requests
|
|
356
|
+
*/
|
|
357
|
+
private buildRequestParams;
|
|
358
|
+
sendMessage(message: string): Promise<any>;
|
|
359
|
+
streamMessage(message: string, onChunk: (chunk: StreamChunk) => void | Promise<void>, onComplete?: () => void | Promise<void>): Promise<void>;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* A2A Extension URIs
|
|
364
|
+
* Reference: https://github.com/i-am-bee/agentstack/blob/main/apps/agentstack-sdk-ts/src/client/a2a/extensions/
|
|
365
|
+
*/
|
|
366
|
+
declare const EXTENSION_URIS: {
|
|
367
|
+
readonly LLM: "https://a2a-extensions.agentstack.beeai.dev/services/llm/v1";
|
|
368
|
+
readonly EMBEDDING: "https://a2a-extensions.agentstack.beeai.dev/services/embedding/v1";
|
|
369
|
+
readonly MCP: "https://a2a-extensions.agentstack.beeai.dev/services/mcp/v1";
|
|
370
|
+
readonly OAUTH_PROVIDER: "https://a2a-extensions.agentstack.beeai.dev/services/oauth-provider/v1";
|
|
371
|
+
readonly SECRETS: "https://a2a-extensions.agentstack.beeai.dev/services/secrets/v1";
|
|
372
|
+
readonly PLATFORM_API: "https://a2a-extensions.agentstack.beeai.dev/services/platform-api/v1";
|
|
373
|
+
readonly FORM_SERVICE: "https://a2a-extensions.agentstack.beeai.dev/services/form/v1";
|
|
374
|
+
readonly CITATION: "https://a2a-extensions.agentstack.beeai.dev/ui/citation/v1";
|
|
375
|
+
readonly TRAJECTORY: "https://a2a-extensions.agentstack.beeai.dev/ui/trajectory/v1";
|
|
376
|
+
readonly ERROR: "https://a2a-extensions.agentstack.beeai.dev/ui/error/v1";
|
|
377
|
+
readonly FORM_REQUEST: "https://a2a-extensions.agentstack.beeai.dev/ui/form-request/v1";
|
|
378
|
+
readonly CANVAS: "https://a2a-extensions.agentstack.beeai.dev/ui/canvas/v1";
|
|
379
|
+
readonly AGENT_DETAIL: "https://a2a-extensions.agentstack.beeai.dev/ui/agent-detail/v1";
|
|
380
|
+
readonly OAUTH_REQUEST: "https://a2a-extensions.agentstack.beeai.dev/ui/oauth/v1";
|
|
381
|
+
readonly SETTINGS: "https://a2a-extensions.agentstack.beeai.dev/ui/settings/v1";
|
|
382
|
+
};
|
|
383
|
+
type ExtensionUri = typeof EXTENSION_URIS[keyof typeof EXTENSION_URIS];
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* UI Extension Metadata Parser
|
|
387
|
+
*
|
|
388
|
+
* Parses metadata from agent responses to extract UI extension data
|
|
389
|
+
* for rendering citations, trajectories, errors, forms, etc.
|
|
390
|
+
*
|
|
391
|
+
* Reference: https://github.com/i-am-bee/agentstack/blob/main/apps/agentstack-ui/src/api/a2a/utils.ts
|
|
392
|
+
*/
|
|
393
|
+
/**
|
|
394
|
+
* Citation metadata structure
|
|
395
|
+
* Reference: https://github.com/i-am-bee/agentstack/blob/main/apps/agentstack-sdk-ts/src/client/a2a/extensions/ui/citation.ts
|
|
396
|
+
*/
|
|
397
|
+
interface Citation {
|
|
398
|
+
url?: string | null;
|
|
399
|
+
start_index?: number | null;
|
|
400
|
+
end_index?: number | null;
|
|
401
|
+
title?: string | null;
|
|
402
|
+
description?: string | null;
|
|
403
|
+
}
|
|
404
|
+
interface CitationMetadata {
|
|
405
|
+
citations: Citation[];
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Trajectory metadata structure
|
|
409
|
+
* Reference: https://github.com/i-am-bee/agentstack/blob/main/apps/agentstack-sdk-ts/src/client/a2a/extensions/ui/trajectory.ts
|
|
410
|
+
*/
|
|
411
|
+
interface TrajectoryMetadata {
|
|
412
|
+
title?: string | null;
|
|
413
|
+
content?: string | null;
|
|
414
|
+
group_id?: string | null;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Error metadata structure
|
|
418
|
+
*/
|
|
419
|
+
interface ErrorMetadata {
|
|
420
|
+
message: string;
|
|
421
|
+
code?: string | null;
|
|
422
|
+
stacktrace?: string | null;
|
|
423
|
+
context?: Record<string, unknown> | null;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Form request metadata structure
|
|
427
|
+
*/
|
|
428
|
+
interface FormField {
|
|
429
|
+
id: string;
|
|
430
|
+
type: 'text' | 'date' | 'file' | 'single_select' | 'multi_select' | 'checkbox' | 'checkbox_group';
|
|
431
|
+
label: string;
|
|
432
|
+
description?: string;
|
|
433
|
+
required?: boolean;
|
|
434
|
+
default_value?: unknown;
|
|
435
|
+
options?: Array<{
|
|
436
|
+
value: string;
|
|
437
|
+
label: string;
|
|
438
|
+
}>;
|
|
439
|
+
col_span?: number;
|
|
440
|
+
}
|
|
441
|
+
interface FormRequestMetadata {
|
|
442
|
+
title?: string;
|
|
443
|
+
description?: string;
|
|
444
|
+
columns?: number;
|
|
445
|
+
submit_label?: string;
|
|
446
|
+
fields: FormField[];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Canvas edit request metadata
|
|
450
|
+
*/
|
|
451
|
+
interface CanvasEditMetadata {
|
|
452
|
+
artifact_id: string;
|
|
453
|
+
start_index: number;
|
|
454
|
+
end_index: number;
|
|
455
|
+
description: string;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Agent detail metadata
|
|
459
|
+
*/
|
|
460
|
+
interface AgentDetailMetadata {
|
|
461
|
+
interaction_mode?: 'single-turn' | 'multi-turn';
|
|
462
|
+
user_greeting?: string;
|
|
463
|
+
version?: string;
|
|
464
|
+
framework?: string;
|
|
465
|
+
source_code_url?: string;
|
|
466
|
+
tools?: Array<{
|
|
467
|
+
name: string;
|
|
468
|
+
description: string;
|
|
469
|
+
}>;
|
|
470
|
+
skills?: Array<{
|
|
471
|
+
id: string;
|
|
472
|
+
name: string;
|
|
473
|
+
description: string;
|
|
474
|
+
}>;
|
|
475
|
+
contributors?: Array<{
|
|
476
|
+
name: string;
|
|
477
|
+
url?: string;
|
|
478
|
+
}>;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Parsed UI extensions from message metadata
|
|
482
|
+
*/
|
|
483
|
+
interface ParsedUIExtensions {
|
|
484
|
+
citations?: CitationMetadata;
|
|
485
|
+
trajectory?: TrajectoryMetadata;
|
|
486
|
+
error?: ErrorMetadata;
|
|
487
|
+
formRequest?: FormRequestMetadata;
|
|
488
|
+
canvas?: CanvasEditMetadata;
|
|
489
|
+
agentDetail?: AgentDetailMetadata;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Extract UI extension data from message metadata
|
|
493
|
+
*/
|
|
494
|
+
declare function parseUIExtensions(metadata: Record<string, unknown> | undefined): ParsedUIExtensions;
|
|
495
|
+
/**
|
|
496
|
+
* Extract citations from message metadata
|
|
497
|
+
* Convenience function for citation-specific extraction
|
|
498
|
+
*/
|
|
499
|
+
declare function extractCitations(metadata: Record<string, unknown> | undefined): Citation[];
|
|
500
|
+
/**
|
|
501
|
+
* Extract trajectory from message metadata
|
|
502
|
+
* Convenience function for trajectory-specific extraction
|
|
503
|
+
*/
|
|
504
|
+
declare function extractTrajectory(metadata: Record<string, unknown> | undefined): TrajectoryMetadata | null;
|
|
505
|
+
/**
|
|
506
|
+
* Extract error from message metadata
|
|
507
|
+
*/
|
|
508
|
+
declare function extractError(metadata: Record<string, unknown> | undefined): ErrorMetadata | null;
|
|
509
|
+
/**
|
|
510
|
+
* Extract form request from message metadata
|
|
511
|
+
*/
|
|
512
|
+
declare function extractFormRequest(metadata: Record<string, unknown> | undefined): FormRequestMetadata | null;
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Chat Component Types
|
|
516
|
+
*/
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Layout modes for the chat interface
|
|
520
|
+
*/
|
|
521
|
+
type ChatLayout = 'fullscreen' | 'sidebar' | 'float';
|
|
522
|
+
/**
|
|
523
|
+
* Props for the main A2AChat component
|
|
524
|
+
*/
|
|
525
|
+
interface A2AChatProps {
|
|
526
|
+
/**
|
|
527
|
+
* Full agent configuration object
|
|
528
|
+
* Use this for complete control over agent settings
|
|
529
|
+
*/
|
|
530
|
+
agent?: AgentConfig;
|
|
531
|
+
/**
|
|
532
|
+
* Agent ID to look up from AgentProvider context
|
|
533
|
+
* Use this when agents are registered in a parent AgentProvider
|
|
534
|
+
*/
|
|
535
|
+
agentId?: string;
|
|
536
|
+
/**
|
|
537
|
+
* Simple URL-only configuration
|
|
538
|
+
* Use this for quick single-agent setups
|
|
539
|
+
*/
|
|
540
|
+
agentUrl?: string;
|
|
541
|
+
/**
|
|
542
|
+
* API key (used with agentUrl)
|
|
543
|
+
*/
|
|
544
|
+
apiKey?: string;
|
|
545
|
+
/**
|
|
546
|
+
* Layout mode
|
|
547
|
+
* @default 'fullscreen'
|
|
548
|
+
*/
|
|
549
|
+
layout?: ChatLayout;
|
|
550
|
+
/**
|
|
551
|
+
* Allow user to switch layouts
|
|
552
|
+
* @default false
|
|
553
|
+
*/
|
|
554
|
+
allowLayoutSwitch?: boolean;
|
|
555
|
+
/**
|
|
556
|
+
* Initial open state (for sidebar/float layouts)
|
|
557
|
+
* @default true for fullscreen, false for others
|
|
558
|
+
*/
|
|
559
|
+
defaultOpen?: boolean;
|
|
560
|
+
/**
|
|
561
|
+
* Custom CSS class name
|
|
562
|
+
*/
|
|
563
|
+
className?: string;
|
|
564
|
+
/**
|
|
565
|
+
* Override agent display name
|
|
566
|
+
*/
|
|
567
|
+
agentName?: string;
|
|
568
|
+
/**
|
|
569
|
+
* Override agent icon
|
|
570
|
+
*/
|
|
571
|
+
agentIconUrl?: string;
|
|
572
|
+
/**
|
|
573
|
+
* Show thinking/reasoning accordion
|
|
574
|
+
* @default true
|
|
575
|
+
*/
|
|
576
|
+
showThinking?: boolean;
|
|
577
|
+
/**
|
|
578
|
+
* Show chain of thought steps
|
|
579
|
+
* @default true
|
|
580
|
+
*/
|
|
581
|
+
showChainOfThought?: boolean;
|
|
582
|
+
/**
|
|
583
|
+
* Enable streaming cancellation
|
|
584
|
+
* @default true
|
|
585
|
+
*/
|
|
586
|
+
allowCancel?: boolean;
|
|
587
|
+
/**
|
|
588
|
+
* A2A extension configuration to send with messages
|
|
589
|
+
*/
|
|
590
|
+
extensions?: A2AExtensionConfig$1;
|
|
591
|
+
/**
|
|
592
|
+
* Called when chat is opened
|
|
593
|
+
*/
|
|
594
|
+
onOpen?: () => void;
|
|
595
|
+
/**
|
|
596
|
+
* Called when chat is closed (sidebar/float only)
|
|
597
|
+
*/
|
|
598
|
+
onClose?: () => void;
|
|
599
|
+
/**
|
|
600
|
+
* Called when user sends a message
|
|
601
|
+
*/
|
|
602
|
+
onSend?: (message: string) => void;
|
|
603
|
+
/**
|
|
604
|
+
* Called when agent responds
|
|
605
|
+
*/
|
|
606
|
+
onResponse?: (response: unknown) => void;
|
|
607
|
+
/**
|
|
608
|
+
* Called on connection state change
|
|
609
|
+
*/
|
|
610
|
+
onConnectionChange?: (state: AgentConnectionState) => void;
|
|
611
|
+
/**
|
|
612
|
+
* Called on error
|
|
613
|
+
*/
|
|
614
|
+
onError?: (error: Error) => void;
|
|
615
|
+
/**
|
|
616
|
+
* Called when user wants to disconnect/switch agents
|
|
617
|
+
*/
|
|
618
|
+
onDisconnect?: () => void;
|
|
619
|
+
/**
|
|
620
|
+
* Custom renderer for citations
|
|
621
|
+
*/
|
|
622
|
+
renderCitations?: (citations: Citation[], text: string) => ReactNode;
|
|
623
|
+
/**
|
|
624
|
+
* Custom renderer for errors
|
|
625
|
+
*/
|
|
626
|
+
renderError?: (error: ErrorMetadata) => ReactNode;
|
|
627
|
+
/**
|
|
628
|
+
* Custom renderer for forms
|
|
629
|
+
*/
|
|
630
|
+
renderForm?: (form: FormRequestMetadata, onSubmit: (values: Record<string, unknown>) => void) => ReactNode;
|
|
631
|
+
/**
|
|
632
|
+
* Custom renderer for user-defined response types
|
|
633
|
+
*/
|
|
634
|
+
renderUserDefined?: (data: unknown, messageItem: unknown) => ReactNode;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Provider Types
|
|
639
|
+
*/
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Props for AgentProvider component
|
|
643
|
+
*/
|
|
644
|
+
interface AgentProviderProps {
|
|
645
|
+
children: ReactNode;
|
|
646
|
+
/**
|
|
647
|
+
* Single agent configuration
|
|
648
|
+
* Use for simple single-agent apps
|
|
649
|
+
*/
|
|
650
|
+
agent?: AgentConfig;
|
|
651
|
+
/**
|
|
652
|
+
* Multiple agent configurations
|
|
653
|
+
* Use for apps with multiple agents
|
|
654
|
+
*/
|
|
655
|
+
agents?: AgentConfig[];
|
|
656
|
+
/**
|
|
657
|
+
* Full registry with default selection
|
|
658
|
+
* Use for complex multi-agent scenarios
|
|
659
|
+
*/
|
|
660
|
+
registry?: AgentRegistry;
|
|
661
|
+
/**
|
|
662
|
+
* Default agent ID when multiple agents provided
|
|
663
|
+
*/
|
|
664
|
+
defaultAgentId?: string;
|
|
665
|
+
/**
|
|
666
|
+
* Persist selected agent to localStorage
|
|
667
|
+
* @default false
|
|
668
|
+
*/
|
|
669
|
+
persistSelection?: boolean;
|
|
670
|
+
/**
|
|
671
|
+
* Storage key for persisted selection
|
|
672
|
+
* @default 'a2a-chat-selected-agent'
|
|
673
|
+
*/
|
|
674
|
+
storageKey?: string;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Context value provided by AgentProvider
|
|
678
|
+
*/
|
|
679
|
+
interface AgentContextValue {
|
|
680
|
+
/** Currently selected agent config */
|
|
681
|
+
currentAgent: AgentConfig | null;
|
|
682
|
+
/** All available agents */
|
|
683
|
+
agents: AgentConfig[];
|
|
684
|
+
/** Select a different agent by ID */
|
|
685
|
+
selectAgent: (agentId: string) => void;
|
|
686
|
+
/** Get agent config by ID */
|
|
687
|
+
getAgent: (agentId: string) => AgentConfig | undefined;
|
|
688
|
+
/** Check if an agent ID exists */
|
|
689
|
+
hasAgent: (agentId: string) => boolean;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Types for UI extension renderers
|
|
694
|
+
*/
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Processed citation for rendering
|
|
698
|
+
* Includes computed display properties
|
|
699
|
+
*/
|
|
700
|
+
interface ProcessedCitation extends Citation {
|
|
701
|
+
id: string;
|
|
702
|
+
number: number;
|
|
703
|
+
highlightedText: string;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Text segment with optional citation reference
|
|
707
|
+
*/
|
|
708
|
+
interface TextSegment {
|
|
709
|
+
text: string;
|
|
710
|
+
citation?: ProcessedCitation;
|
|
711
|
+
isCited: boolean;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Props for CitationRenderer component
|
|
715
|
+
*/
|
|
716
|
+
interface CitationRendererProps {
|
|
717
|
+
text: string;
|
|
718
|
+
citations: Citation[];
|
|
719
|
+
className?: string;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Props for ErrorRenderer component
|
|
723
|
+
*/
|
|
724
|
+
interface ErrorRendererProps {
|
|
725
|
+
error: ErrorMetadata;
|
|
726
|
+
className?: string;
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Props for FormRenderer component
|
|
730
|
+
*/
|
|
731
|
+
interface FormRendererProps {
|
|
732
|
+
form: FormRequestMetadata;
|
|
733
|
+
onSubmit: (values: Record<string, unknown>) => void;
|
|
734
|
+
onCancel?: () => void;
|
|
735
|
+
className?: string;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Citation Renderer Component
|
|
740
|
+
*
|
|
741
|
+
* Renders text with inline citation highlights and a sources list.
|
|
742
|
+
* Citations appear as highlighted text with superscript numbers.
|
|
743
|
+
* Hovering shows a tooltip with source details.
|
|
744
|
+
* Clicking navigates to the source URL.
|
|
745
|
+
*
|
|
746
|
+
* Reference: https://raw.githubusercontent.com/i-am-bee/agentstack/main/docs/development/agent-integration/citations.mdx
|
|
747
|
+
*/
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Main Citation Renderer Component
|
|
751
|
+
*/
|
|
752
|
+
declare const CitationRenderer: React.FC<CitationRendererProps>;
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Error Renderer Component
|
|
756
|
+
*
|
|
757
|
+
* Renders error messages from agent responses with
|
|
758
|
+
* optional stack trace and context information.
|
|
759
|
+
*/
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Error Renderer Component
|
|
763
|
+
*/
|
|
764
|
+
declare const ErrorRenderer: React.FC<ErrorRendererProps>;
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Form Renderer Component
|
|
768
|
+
*
|
|
769
|
+
* Renders dynamic forms from agent form request metadata.
|
|
770
|
+
* Supports text, date, file, select, checkbox, and multi-select fields.
|
|
771
|
+
*/
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Main Form Renderer Component
|
|
775
|
+
*/
|
|
776
|
+
declare const FormRenderer: React.FC<FormRendererProps>;
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Citation processing utilities
|
|
780
|
+
*
|
|
781
|
+
* Reference: https://raw.githubusercontent.com/i-am-bee/agentstack/main/docs/development/agent-integration/citations.mdx
|
|
782
|
+
*/
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Process raw citations into renderable format
|
|
786
|
+
* Assigns numbers and extracts highlighted text
|
|
787
|
+
*/
|
|
788
|
+
declare function processCitations(text: string, citations: Citation[]): ProcessedCitation[];
|
|
789
|
+
/**
|
|
790
|
+
* Segment text into parts with and without citations
|
|
791
|
+
* Returns array of segments for rendering
|
|
792
|
+
*/
|
|
793
|
+
declare function segmentTextWithCitations(text: string, citations: Citation[]): TextSegment[];
|
|
794
|
+
/**
|
|
795
|
+
* Get unique citations (deduplicated by URL)
|
|
796
|
+
*/
|
|
797
|
+
declare function getUniqueCitations(citations: ProcessedCitation[]): ProcessedCitation[];
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Main A2A Chat component
|
|
801
|
+
*
|
|
802
|
+
* Connects to A2A agents and renders chat UI using Carbon AI Chat components.
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
* // Direct agent config
|
|
806
|
+
* <A2AChat
|
|
807
|
+
* agent={{ id: 'my-agent', name: 'My Agent', url: 'https://...' }}
|
|
808
|
+
* layout="sidebar"
|
|
809
|
+
* />
|
|
810
|
+
*
|
|
811
|
+
* @example
|
|
812
|
+
* // Using AgentProvider context
|
|
813
|
+
* <AgentProvider agents={[...]}>
|
|
814
|
+
* <A2AChat agentId="research" />
|
|
815
|
+
* </AgentProvider>
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* // Simple URL-only
|
|
819
|
+
* <A2AChat agentUrl="https://my-agent.example.com" layout="fullscreen" />
|
|
820
|
+
*/
|
|
821
|
+
declare function A2AChat({ agent: agentProp, agentId, agentUrl, apiKey, layout, allowLayoutSwitch, defaultOpen, className, agentName, agentIconUrl, showThinking, showChainOfThought, allowCancel, extensions, onOpen, onClose, onSend, onResponse, onConnectionChange, onError, onDisconnect, renderCitations, renderError, renderForm, renderUserDefined, }: A2AChatProps): react_jsx_runtime.JSX.Element;
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Hook to access agent context
|
|
825
|
+
* Must be used within an AgentProvider
|
|
826
|
+
*/
|
|
827
|
+
declare function useAgentContext(): AgentContextValue;
|
|
828
|
+
/**
|
|
829
|
+
* Optional hook that returns null if not within provider
|
|
830
|
+
* Useful for components that work both with and without provider
|
|
831
|
+
*/
|
|
832
|
+
declare function useAgentContextOptional(): AgentContextValue | null;
|
|
833
|
+
/**
|
|
834
|
+
* Provider for managing agent configurations
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* // Single agent
|
|
838
|
+
* <AgentProvider agent={{ id: 'main', name: 'Assistant', url: '...' }}>
|
|
839
|
+
* <App />
|
|
840
|
+
* </AgentProvider>
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* // Multiple agents
|
|
844
|
+
* <AgentProvider
|
|
845
|
+
* agents={[
|
|
846
|
+
* { id: 'research', name: 'Research', url: '...' },
|
|
847
|
+
* { id: 'code', name: 'Coder', url: '...' },
|
|
848
|
+
* ]}
|
|
849
|
+
* defaultAgentId="research"
|
|
850
|
+
* persistSelection
|
|
851
|
+
* >
|
|
852
|
+
* <App />
|
|
853
|
+
* </AgentProvider>
|
|
854
|
+
*/
|
|
855
|
+
declare function AgentProvider({ children, agent, agents: agentsProp, registry, defaultAgentId, persistSelection, storageKey, }: AgentProviderProps): ReactNode;
|
|
856
|
+
|
|
857
|
+
interface AgentSwitcherProps {
|
|
858
|
+
/** Available agents */
|
|
859
|
+
agents: AgentConfig[];
|
|
860
|
+
/** Currently selected agent ID */
|
|
861
|
+
currentAgentId?: string;
|
|
862
|
+
/** Called when user selects an agent */
|
|
863
|
+
onSelect: (agentId: string) => void;
|
|
864
|
+
/** Variant style */
|
|
865
|
+
variant?: 'dropdown' | 'tabs' | 'cards';
|
|
866
|
+
/** Show agent descriptions */
|
|
867
|
+
showDescriptions?: boolean;
|
|
868
|
+
/** Show agent icons */
|
|
869
|
+
showIcons?: boolean;
|
|
870
|
+
/** Custom class name */
|
|
871
|
+
className?: string;
|
|
872
|
+
/** Disabled state */
|
|
873
|
+
disabled?: boolean;
|
|
874
|
+
/** Label text */
|
|
875
|
+
label?: string;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Component for switching between multiple agents
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* const { agents, currentAgent, selectAgent } = useAgentContext();
|
|
882
|
+
*
|
|
883
|
+
* <AgentSwitcher
|
|
884
|
+
* agents={agents}
|
|
885
|
+
* currentAgentId={currentAgent?.id}
|
|
886
|
+
* onSelect={selectAgent}
|
|
887
|
+
* />
|
|
888
|
+
*/
|
|
889
|
+
declare function AgentSwitcher({ agents, currentAgentId, onSelect, variant, showDescriptions, showIcons, className, disabled, label, }: AgentSwitcherProps): react_jsx_runtime.JSX.Element | null;
|
|
890
|
+
|
|
891
|
+
interface UseA2AAgentOptions {
|
|
892
|
+
/** Agent configuration (or use agentId with AgentProvider) */
|
|
893
|
+
agent?: AgentConfig;
|
|
894
|
+
/** Agent ID to look up from context */
|
|
895
|
+
agentId?: string;
|
|
896
|
+
/** Auto-connect on mount */
|
|
897
|
+
autoConnect?: boolean;
|
|
898
|
+
/** Callbacks */
|
|
899
|
+
onConnect?: () => void;
|
|
900
|
+
onDisconnect?: () => void;
|
|
901
|
+
onError?: (error: Error) => void;
|
|
902
|
+
onMessage?: (message: any) => void;
|
|
903
|
+
}
|
|
904
|
+
interface UseA2AAgentReturn {
|
|
905
|
+
/** Current agent configuration */
|
|
906
|
+
agent: AgentConfig | null;
|
|
907
|
+
/** Connection state */
|
|
908
|
+
state: AgentState;
|
|
909
|
+
/** Send a message to the agent */
|
|
910
|
+
sendMessage: (message: string) => Promise<any>;
|
|
911
|
+
/** Cancel current streaming response */
|
|
912
|
+
cancelStream: () => void;
|
|
913
|
+
/** Disconnect from agent */
|
|
914
|
+
disconnect: () => void;
|
|
915
|
+
/** Reconnect to agent */
|
|
916
|
+
reconnect: () => void;
|
|
917
|
+
/** Clear conversation history */
|
|
918
|
+
clearHistory: () => void;
|
|
919
|
+
/** Whether currently streaming */
|
|
920
|
+
isStreaming: boolean;
|
|
921
|
+
/** Whether connected */
|
|
922
|
+
isConnected: boolean;
|
|
923
|
+
/** Last error */
|
|
924
|
+
error: Error | null;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Hook for interacting with an A2A agent programmatically
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* // With direct config
|
|
931
|
+
* const { sendMessage, isStreaming } = useA2AAgent({
|
|
932
|
+
* agent: { id: 'my-agent', name: 'My Agent', url: 'https://...' }
|
|
933
|
+
* });
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* // With context provider
|
|
937
|
+
* const { sendMessage } = useA2AAgent({ agentId: 'research-agent' });
|
|
938
|
+
*/
|
|
939
|
+
declare function useA2AAgent(options?: UseA2AAgentOptions): UseA2AAgentReturn;
|
|
940
|
+
|
|
941
|
+
interface UseMultiAgentOptions {
|
|
942
|
+
/** Initial agents to register */
|
|
943
|
+
agents?: AgentConfig[];
|
|
944
|
+
/** Default agent ID */
|
|
945
|
+
defaultAgentId?: string;
|
|
946
|
+
/** Called when agent changes */
|
|
947
|
+
onAgentChange?: (agent: AgentConfig) => void;
|
|
948
|
+
}
|
|
949
|
+
interface UseMultiAgentReturn {
|
|
950
|
+
/** All registered agents */
|
|
951
|
+
agents: AgentConfig[];
|
|
952
|
+
/** Currently active agent */
|
|
953
|
+
currentAgent: AgentConfig | null;
|
|
954
|
+
/** Switch to a different agent */
|
|
955
|
+
switchAgent: (agentId: string) => void;
|
|
956
|
+
/** Register a new agent */
|
|
957
|
+
registerAgent: (agent: AgentConfig) => void;
|
|
958
|
+
/** Unregister an agent */
|
|
959
|
+
unregisterAgent: (agentId: string) => void;
|
|
960
|
+
/** Update an existing agent's config */
|
|
961
|
+
updateAgent: (agentId: string, updates: Partial<AgentConfig>) => void;
|
|
962
|
+
/** Get agent by ID */
|
|
963
|
+
getAgent: (agentId: string) => AgentConfig | undefined;
|
|
964
|
+
/** Check if agent exists */
|
|
965
|
+
hasAgent: (agentId: string) => boolean;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Hook for managing multiple agents without using AgentProvider
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* const { currentAgent, switchAgent, agents } = useMultiAgent({
|
|
972
|
+
* agents: [
|
|
973
|
+
* { id: 'research', name: 'Research Agent', url: '...' },
|
|
974
|
+
* { id: 'code', name: 'Code Agent', url: '...' },
|
|
975
|
+
* ],
|
|
976
|
+
* defaultAgentId: 'research'
|
|
977
|
+
* });
|
|
978
|
+
*/
|
|
979
|
+
declare function useMultiAgent(options?: UseMultiAgentOptions): UseMultiAgentReturn;
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* A2A to Carbon AI Chat Translator
|
|
983
|
+
*
|
|
984
|
+
* Translates A2A protocol streaming events to Carbon AI Chat's expected format.
|
|
985
|
+
*
|
|
986
|
+
* References:
|
|
987
|
+
* - Carbon AI Chat streaming: https://github.com/carbon-design-system/carbon-ai-chat/blob/main/examples/react/reasoning-and-chain-of-thought/src/scenarios.ts
|
|
988
|
+
* - A2A Protocol types: https://github.com/a2aproject/a2a-python/blob/main/src/a2a/types.py
|
|
989
|
+
*/
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Carbon message response types
|
|
993
|
+
*/
|
|
994
|
+
declare const MessageResponseTypes: {
|
|
995
|
+
readonly TEXT: "text";
|
|
996
|
+
readonly USER_DEFINED: "user_defined";
|
|
997
|
+
readonly INLINE_ERROR: "inline_error";
|
|
998
|
+
readonly OPTION: "option";
|
|
999
|
+
};
|
|
1000
|
+
type MessageResponseType = typeof MessageResponseTypes[keyof typeof MessageResponseTypes];
|
|
1001
|
+
/**
|
|
1002
|
+
* Chain of thought step status
|
|
1003
|
+
*/
|
|
1004
|
+
declare enum ChainOfThoughtStepStatus {
|
|
1005
|
+
IN_PROGRESS = "in_progress",
|
|
1006
|
+
SUCCESS = "success",
|
|
1007
|
+
ERROR = "error"
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Reasoning step open state
|
|
1011
|
+
*/
|
|
1012
|
+
declare enum ReasoningStepOpenState {
|
|
1013
|
+
OPEN = "open",
|
|
1014
|
+
CLOSE = "close",
|
|
1015
|
+
DEFAULT = "default"
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* User type for response profile
|
|
1019
|
+
*/
|
|
1020
|
+
declare enum UserType {
|
|
1021
|
+
HUMAN = "human",
|
|
1022
|
+
BOT = "bot",
|
|
1023
|
+
WATSONX = "watsonx"
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Response user profile
|
|
1027
|
+
*/
|
|
1028
|
+
interface ResponseUserProfile {
|
|
1029
|
+
id: string;
|
|
1030
|
+
nickname: string;
|
|
1031
|
+
user_type: UserType;
|
|
1032
|
+
profile_picture_url?: string;
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Reasoning step structure
|
|
1036
|
+
*/
|
|
1037
|
+
interface ReasoningStep {
|
|
1038
|
+
title: string;
|
|
1039
|
+
content?: string;
|
|
1040
|
+
open_state?: ReasoningStepOpenState;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Chain of thought step structure
|
|
1044
|
+
*/
|
|
1045
|
+
interface ChainOfThoughtStep {
|
|
1046
|
+
title: string;
|
|
1047
|
+
description?: string;
|
|
1048
|
+
tool_name?: string;
|
|
1049
|
+
request?: {
|
|
1050
|
+
args: unknown;
|
|
1051
|
+
};
|
|
1052
|
+
response?: {
|
|
1053
|
+
content: unknown;
|
|
1054
|
+
};
|
|
1055
|
+
status: ChainOfThoughtStepStatus;
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Message response options
|
|
1059
|
+
*/
|
|
1060
|
+
interface MessageResponseOptions {
|
|
1061
|
+
response_user_profile?: ResponseUserProfile;
|
|
1062
|
+
reasoning?: {
|
|
1063
|
+
open_state?: ReasoningStepOpenState;
|
|
1064
|
+
steps?: ReasoningStep[];
|
|
1065
|
+
content?: string;
|
|
1066
|
+
};
|
|
1067
|
+
chain_of_thought?: ChainOfThoughtStep[];
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Item streaming metadata
|
|
1071
|
+
*/
|
|
1072
|
+
interface ItemStreamingMetadata {
|
|
1073
|
+
id: string;
|
|
1074
|
+
cancellable?: boolean;
|
|
1075
|
+
stream_stopped?: boolean;
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Generic item (text response)
|
|
1079
|
+
*/
|
|
1080
|
+
interface TextItem {
|
|
1081
|
+
response_type: typeof MessageResponseTypes.TEXT;
|
|
1082
|
+
text: string;
|
|
1083
|
+
streaming_metadata?: ItemStreamingMetadata;
|
|
1084
|
+
message_item_options?: {
|
|
1085
|
+
feedback?: {
|
|
1086
|
+
is_on?: boolean;
|
|
1087
|
+
id?: string;
|
|
1088
|
+
};
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* User defined item (custom content)
|
|
1093
|
+
*/
|
|
1094
|
+
interface UserDefinedItem {
|
|
1095
|
+
response_type: typeof MessageResponseTypes.USER_DEFINED;
|
|
1096
|
+
user_defined: Record<string, unknown>;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Generic item union type
|
|
1100
|
+
*/
|
|
1101
|
+
type GenericItem = TextItem | UserDefinedItem;
|
|
1102
|
+
/**
|
|
1103
|
+
* Partial item chunk for streaming
|
|
1104
|
+
*/
|
|
1105
|
+
interface PartialItemChunk {
|
|
1106
|
+
partial_item: Partial<GenericItem> & {
|
|
1107
|
+
response_type: MessageResponseType;
|
|
1108
|
+
streaming_metadata?: ItemStreamingMetadata;
|
|
1109
|
+
};
|
|
1110
|
+
partial_response?: {
|
|
1111
|
+
message_options?: Partial<MessageResponseOptions>;
|
|
1112
|
+
};
|
|
1113
|
+
streaming_metadata: {
|
|
1114
|
+
response_id: string;
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Complete item chunk
|
|
1119
|
+
*/
|
|
1120
|
+
interface CompleteItemChunk {
|
|
1121
|
+
complete_item: GenericItem;
|
|
1122
|
+
partial_response?: {
|
|
1123
|
+
message_options?: Partial<MessageResponseOptions>;
|
|
1124
|
+
};
|
|
1125
|
+
streaming_metadata: {
|
|
1126
|
+
response_id: string;
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Final response chunk
|
|
1131
|
+
*/
|
|
1132
|
+
interface FinalResponseChunk {
|
|
1133
|
+
final_response: {
|
|
1134
|
+
id: string;
|
|
1135
|
+
output: {
|
|
1136
|
+
generic: GenericItem[];
|
|
1137
|
+
};
|
|
1138
|
+
message_options?: MessageResponseOptions;
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Stream chunk union type
|
|
1143
|
+
*/
|
|
1144
|
+
type CarbonStreamChunk = PartialItemChunk | CompleteItemChunk | FinalResponseChunk;
|
|
1145
|
+
/**
|
|
1146
|
+
* Carbon message for addMessage() API
|
|
1147
|
+
*/
|
|
1148
|
+
interface CarbonMessage {
|
|
1149
|
+
output: {
|
|
1150
|
+
generic: GenericItem[];
|
|
1151
|
+
};
|
|
1152
|
+
message_options?: MessageResponseOptions;
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* Legacy Carbon Message format (used by EnhancedChatWrapper)
|
|
1156
|
+
* This is the older format that works with Carbon's addMessage() API directly
|
|
1157
|
+
*/
|
|
1158
|
+
interface LegacyCarbonMessage {
|
|
1159
|
+
response_type: string;
|
|
1160
|
+
text?: string;
|
|
1161
|
+
reasoning_steps?: {
|
|
1162
|
+
steps: Array<{
|
|
1163
|
+
content: string;
|
|
1164
|
+
}>;
|
|
1165
|
+
openState?: 'open' | 'closed';
|
|
1166
|
+
};
|
|
1167
|
+
chain_of_thought?: {
|
|
1168
|
+
steps: ChainOfThoughtStep[];
|
|
1169
|
+
};
|
|
1170
|
+
user_defined?: Record<string, unknown>;
|
|
1171
|
+
metadata?: Record<string, unknown>;
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Extended A2A part with metadata support
|
|
1175
|
+
*/
|
|
1176
|
+
interface A2APartWithMetadata extends A2AMessagePart {
|
|
1177
|
+
metadata?: {
|
|
1178
|
+
content_type?: 'thinking' | 'reasoning_step' | 'response' | 'status' | string;
|
|
1179
|
+
[key: string]: unknown;
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Tool call data structure
|
|
1184
|
+
*/
|
|
1185
|
+
interface ToolCallData {
|
|
1186
|
+
type: 'tool_call';
|
|
1187
|
+
tool_name?: string;
|
|
1188
|
+
args?: unknown;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Tool result data structure
|
|
1192
|
+
*/
|
|
1193
|
+
interface ToolResultData {
|
|
1194
|
+
type: 'tool_result';
|
|
1195
|
+
tool_name?: string;
|
|
1196
|
+
result_preview?: unknown;
|
|
1197
|
+
success?: boolean;
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Translator state for tracking streaming progress
|
|
1201
|
+
*/
|
|
1202
|
+
interface TranslatorState {
|
|
1203
|
+
responseId: string;
|
|
1204
|
+
itemId: string;
|
|
1205
|
+
accumulatedText: string;
|
|
1206
|
+
reasoningSteps: ReasoningStep[];
|
|
1207
|
+
chainOfThought: ChainOfThoughtStep[];
|
|
1208
|
+
pendingToolCalls: Map<string, number>;
|
|
1209
|
+
hasStartedStreaming: boolean;
|
|
1210
|
+
shellMessageSent: boolean;
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* A2A to Carbon AI Chat Translator
|
|
1214
|
+
*
|
|
1215
|
+
* Manages the translation of A2A streaming events to Carbon AI Chat format.
|
|
1216
|
+
* Maintains state across multiple chunks to properly accumulate text and
|
|
1217
|
+
* track reasoning/tool call progress.
|
|
1218
|
+
*/
|
|
1219
|
+
declare class A2AToCarbonTranslator {
|
|
1220
|
+
private state;
|
|
1221
|
+
private agentProfile;
|
|
1222
|
+
constructor(agentProfile?: Partial<ResponseUserProfile>);
|
|
1223
|
+
/**
|
|
1224
|
+
* Create initial translator state
|
|
1225
|
+
*/
|
|
1226
|
+
private createInitialState;
|
|
1227
|
+
/**
|
|
1228
|
+
* Generate unique response ID
|
|
1229
|
+
*/
|
|
1230
|
+
private generateResponseId;
|
|
1231
|
+
/**
|
|
1232
|
+
* Reset state for new message
|
|
1233
|
+
*/
|
|
1234
|
+
reset(): void;
|
|
1235
|
+
/**
|
|
1236
|
+
* Get current response ID
|
|
1237
|
+
*/
|
|
1238
|
+
getResponseId(): string;
|
|
1239
|
+
/**
|
|
1240
|
+
* Get current item ID
|
|
1241
|
+
*/
|
|
1242
|
+
getItemId(): string;
|
|
1243
|
+
/**
|
|
1244
|
+
* Update agent profile
|
|
1245
|
+
*/
|
|
1246
|
+
setAgentProfile(profile: Partial<ResponseUserProfile>): void;
|
|
1247
|
+
/**
|
|
1248
|
+
* Get current agent profile
|
|
1249
|
+
*/
|
|
1250
|
+
getAgentProfile(): ResponseUserProfile;
|
|
1251
|
+
/**
|
|
1252
|
+
* Check if shell message has been sent
|
|
1253
|
+
*/
|
|
1254
|
+
hasShellBeenSent(): boolean;
|
|
1255
|
+
/**
|
|
1256
|
+
* Mark shell message as sent
|
|
1257
|
+
*/
|
|
1258
|
+
markShellSent(): void;
|
|
1259
|
+
/**
|
|
1260
|
+
* Get accumulated text
|
|
1261
|
+
*/
|
|
1262
|
+
getAccumulatedText(): string;
|
|
1263
|
+
/**
|
|
1264
|
+
* Get current reasoning steps
|
|
1265
|
+
*/
|
|
1266
|
+
getReasoningSteps(): ReasoningStep[];
|
|
1267
|
+
/**
|
|
1268
|
+
* Get current chain of thought
|
|
1269
|
+
*/
|
|
1270
|
+
getChainOfThought(): ChainOfThoughtStep[];
|
|
1271
|
+
/**
|
|
1272
|
+
* Check if streaming has started
|
|
1273
|
+
*/
|
|
1274
|
+
hasStartedStreaming(): boolean;
|
|
1275
|
+
/**
|
|
1276
|
+
* Get current state (for debugging/inspection)
|
|
1277
|
+
*/
|
|
1278
|
+
getState(): Readonly<TranslatorState>;
|
|
1279
|
+
/**
|
|
1280
|
+
* Create shell message to initialize Carbon's reducer
|
|
1281
|
+
*
|
|
1282
|
+
* IMPORTANT: This MUST be called before sending any other chunks.
|
|
1283
|
+
* It seeds the message shell so reducers create the container before
|
|
1284
|
+
* reasoning steps or text stream in.
|
|
1285
|
+
*/
|
|
1286
|
+
createShellMessage(includeReasoning?: boolean): PartialItemChunk;
|
|
1287
|
+
/**
|
|
1288
|
+
* Translate a single streaming A2A part to a legacy Carbon message
|
|
1289
|
+
* Used for real-time streaming updates (backward compatibility with EnhancedChatWrapper)
|
|
1290
|
+
* @param part The A2A part to translate
|
|
1291
|
+
* @param metadata Optional extension metadata from the artifact
|
|
1292
|
+
*/
|
|
1293
|
+
translateStreamingPart(part: A2APartWithMetadata, metadata?: Record<string, unknown>): LegacyCarbonMessage | null;
|
|
1294
|
+
/**
|
|
1295
|
+
* Translate an A2A message part to Carbon format
|
|
1296
|
+
*
|
|
1297
|
+
* @param part - The A2A message part to translate
|
|
1298
|
+
* @param artifactMetadata - Optional metadata from artifact level
|
|
1299
|
+
* @returns Carbon stream chunk or null if no action needed
|
|
1300
|
+
*/
|
|
1301
|
+
translatePart(part: A2APartWithMetadata, artifactMetadata?: Record<string, unknown>): CarbonStreamChunk | null;
|
|
1302
|
+
/**
|
|
1303
|
+
* Translate thinking/reasoning content to Carbon reasoning step
|
|
1304
|
+
*/
|
|
1305
|
+
private translateThinkingPart;
|
|
1306
|
+
/**
|
|
1307
|
+
* Translate trajectory extension to Carbon reasoning step
|
|
1308
|
+
*/
|
|
1309
|
+
private translateTrajectoryPart;
|
|
1310
|
+
/**
|
|
1311
|
+
* Translate tool call to Carbon chain of thought (IN_PROGRESS)
|
|
1312
|
+
*/
|
|
1313
|
+
private translateToolCallPart;
|
|
1314
|
+
/**
|
|
1315
|
+
* Translate tool result to Carbon chain of thought (SUCCESS/ERROR)
|
|
1316
|
+
*/
|
|
1317
|
+
private translateToolResultPart;
|
|
1318
|
+
/**
|
|
1319
|
+
* Translate text part to Carbon partial item
|
|
1320
|
+
*/
|
|
1321
|
+
private translateTextPart;
|
|
1322
|
+
/**
|
|
1323
|
+
* Translate file part to Carbon user defined item
|
|
1324
|
+
*/
|
|
1325
|
+
private translateFilePart;
|
|
1326
|
+
/**
|
|
1327
|
+
* Create complete item chunk
|
|
1328
|
+
*
|
|
1329
|
+
* Call this to finalize a specific item while other items may still be streaming.
|
|
1330
|
+
* Optional but useful for accessibility and corrections.
|
|
1331
|
+
*/
|
|
1332
|
+
createCompleteItem(wasStopped?: boolean): CompleteItemChunk;
|
|
1333
|
+
/**
|
|
1334
|
+
* Create final response chunk
|
|
1335
|
+
*
|
|
1336
|
+
* CRITICAL: This MUST be called to end streaming and clear the typing indicator.
|
|
1337
|
+
* Without this, the UI will remain in a loading state.
|
|
1338
|
+
*/
|
|
1339
|
+
createFinalResponse(): FinalResponseChunk;
|
|
1340
|
+
/**
|
|
1341
|
+
* Create error response
|
|
1342
|
+
*/
|
|
1343
|
+
createErrorResponse(errorMessage: string): FinalResponseChunk;
|
|
1344
|
+
/**
|
|
1345
|
+
* Create citations message
|
|
1346
|
+
*
|
|
1347
|
+
* Call this after the main response to add a sources list.
|
|
1348
|
+
*/
|
|
1349
|
+
createCitationsMessage(citations: Array<{
|
|
1350
|
+
url?: string | null;
|
|
1351
|
+
title?: string | null;
|
|
1352
|
+
description?: string | null;
|
|
1353
|
+
}>): CarbonMessage;
|
|
1354
|
+
/**
|
|
1355
|
+
* Translate a complete A2A stream chunk to Carbon format
|
|
1356
|
+
*
|
|
1357
|
+
* This is the main entry point for processing A2A SSE events.
|
|
1358
|
+
* Returns an array of Carbon chunks since one A2A event may produce
|
|
1359
|
+
* multiple Carbon updates (e.g., multiple parts in a message).
|
|
1360
|
+
*/
|
|
1361
|
+
translateStreamChunk(chunk: StreamChunk): CarbonStreamChunk[];
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Create a translator with default settings
|
|
1365
|
+
*/
|
|
1366
|
+
declare function createTranslator(agentName?: string, agentIconUrl?: string): A2AToCarbonTranslator;
|
|
1367
|
+
/**
|
|
1368
|
+
* Check if a Carbon chunk is a final response
|
|
1369
|
+
*/
|
|
1370
|
+
declare function isFinalResponse(chunk: CarbonStreamChunk): chunk is FinalResponseChunk;
|
|
1371
|
+
/**
|
|
1372
|
+
* Check if a Carbon chunk is a partial item
|
|
1373
|
+
*/
|
|
1374
|
+
declare function isPartialItem(chunk: CarbonStreamChunk): chunk is PartialItemChunk;
|
|
1375
|
+
/**
|
|
1376
|
+
* Check if a Carbon chunk is a complete item
|
|
1377
|
+
*/
|
|
1378
|
+
declare function isCompleteItem(chunk: CarbonStreamChunk): chunk is CompleteItemChunk;
|
|
1379
|
+
|
|
1380
|
+
export { A2AChat, type A2AChatProps, A2AClient, type A2AClientConfig, type A2AError, type A2AExtensionConfig$1 as A2AExtensionConfig, type A2AMessage, type A2AMessagePart, type A2APartWithMetadata, A2AToCarbonTranslator, type AgentCard, type AgentConfig, type AgentConnectionState, type AgentContextValue, type AgentDetailMetadata, AgentProvider, type AgentProviderProps, type AgentRegistry, type AgentState, AgentSwitcher, type AgentSwitcherProps, type CanvasEditMetadata, type CarbonMessage, type CarbonStreamChunk, type ChainOfThoughtStep, ChainOfThoughtStepStatus, type ChatLayout, type Citation, type CitationMetadata, CitationRenderer, type CitationRendererProps, type CompleteItemChunk, EXTENSION_URIS, type ErrorMetadata, ErrorRenderer, type ErrorRendererProps, type ExtensionUri, type FinalResponseChunk, type FormField, FormRenderer, type FormRendererProps, type FormRequestMetadata, type GenericItem, type ItemStreamingMetadata, type LegacyCarbonMessage, type MessageResponseOptions, type MessageResponseType, MessageResponseTypes, type ParsedUIExtensions, type PartialItemChunk, type PlatformConfig, type ProcessedCitation, type ReasoningStep, ReasoningStepOpenState, type ResponseUserProfile, type StreamChunk, type TextItem, type TextSegment, type ToolCallData, type ToolResultData, type TrajectoryMetadata, type UseA2AAgentOptions, type UseA2AAgentReturn, type UseMultiAgentOptions, type UseMultiAgentReturn, type UserDefinedItem, UserType, buildFulfillments, createTranslator, extractCitations, extractDemandsFromAgentCard, extractError, extractFormRequest, extractTrajectory, getUniqueCitations, handleAgentCard, isCompleteItem, isFinalResponse, isPartialItem, parseUIExtensions, processCitations, resolveMetadata, segmentTextWithCitations, useA2AAgent, useAgentContext, useAgentContextOptional, useMultiAgent };
|