@a2anet/a2a-utils 0.1.0 → 0.3.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 +1412 -2
- package/dist/artifacts/data.d.ts +118 -0
- package/dist/artifacts/data.d.ts.map +1 -0
- package/dist/artifacts/data.js +583 -0
- package/dist/artifacts/data.js.map +1 -0
- package/dist/artifacts/index.d.ts +33 -0
- package/dist/artifacts/index.d.ts.map +1 -0
- package/dist/artifacts/index.js +131 -0
- package/dist/artifacts/index.js.map +1 -0
- package/dist/artifacts/text.d.ts +54 -0
- package/dist/artifacts/text.d.ts.map +1 -0
- package/dist/artifacts/text.js +151 -0
- package/dist/artifacts/text.js.map +1 -0
- package/dist/client/a2a-session.d.ts +94 -0
- package/dist/client/a2a-session.d.ts.map +1 -0
- package/dist/client/a2a-session.js +264 -0
- package/dist/client/a2a-session.js.map +1 -0
- package/dist/client/a2a-tools.d.ts +152 -0
- package/dist/client/a2a-tools.d.ts.map +1 -0
- package/dist/client/a2a-tools.js +470 -0
- package/dist/client/a2a-tools.js.map +1 -0
- package/dist/client/agent-manager.d.ts +94 -0
- package/dist/client/agent-manager.d.ts.map +1 -0
- package/dist/client/agent-manager.js +243 -0
- package/dist/client/agent-manager.js.map +1 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +7 -0
- package/dist/client/index.js.map +1 -0
- package/dist/files/file-store.d.ts +24 -0
- package/dist/files/file-store.d.ts.map +1 -0
- package/dist/files/file-store.js +5 -0
- package/dist/files/file-store.js.map +1 -0
- package/dist/files/index.d.ts +3 -0
- package/dist/files/index.d.ts.map +1 -0
- package/dist/files/index.js +5 -0
- package/dist/files/index.js.map +1 -0
- package/dist/files/local-file-store.d.ts +26 -0
- package/dist/files/local-file-store.d.ts.map +1 -0
- package/dist/files/local-file-store.js +99 -0
- package/dist/files/local-file-store.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +5 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/json-task-store.d.ts +32 -0
- package/dist/tasks/json-task-store.d.ts.map +1 -0
- package/dist/tasks/json-task-store.js +66 -0
- package/dist/tasks/json-task-store.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/package.json +17 -4
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2025-present A2A Net <hello@a2anet.com>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { DataArtifacts, TextArtifacts, minimizeArtifacts } from "../artifacts/index.js";
|
|
5
|
+
import { ArtifactSettings } from "../types.js";
|
|
6
|
+
export const TEXT_MINIMIZED_TIP = "Text was minimized. Call view_text_artifact() to view specific line ranges.";
|
|
7
|
+
export const DATA_MINIMIZED_TIP = "Data was minimized. Call view_data_artifact() to navigate to specific data.";
|
|
8
|
+
/**
|
|
9
|
+
* LLM-friendly tools that can be used out-of-the-box with agent frameworks.
|
|
10
|
+
*
|
|
11
|
+
* Each method has LLM-friendly docstrings, returns JSON-serialisable objects, and returns actionable error messages.
|
|
12
|
+
*/
|
|
13
|
+
export class A2ATools {
|
|
14
|
+
session;
|
|
15
|
+
artifactSettings;
|
|
16
|
+
constructor(session, opts) {
|
|
17
|
+
this.session = session;
|
|
18
|
+
this.artifactSettings = opts?.artifactSettings ?? new ArtifactSettings();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* List all available agents with their names and descriptions.
|
|
22
|
+
*
|
|
23
|
+
* Use this first to discover what agents are available before sending messages.
|
|
24
|
+
* Each agent has a unique ID (the key) that you'll need for other tools like
|
|
25
|
+
* send_message and get_agent.
|
|
26
|
+
*
|
|
27
|
+
* Returns an object mapping agent IDs to their name and description.
|
|
28
|
+
* If any agents failed to load, an "errors" field is included with details.
|
|
29
|
+
*/
|
|
30
|
+
async getAgents() {
|
|
31
|
+
try {
|
|
32
|
+
const result = await this.session.agentManager.getAgentsForLlm("basic");
|
|
33
|
+
const initErrors = this.session.agentManager.initializationErrors;
|
|
34
|
+
if (Object.keys(result).length === 0 && Object.keys(initErrors).length > 0) {
|
|
35
|
+
const errors = {};
|
|
36
|
+
for (const [agentId, error] of Object.entries(initErrors)) {
|
|
37
|
+
errors[agentId] = `Failed to load agent: ${error}`;
|
|
38
|
+
}
|
|
39
|
+
return { agents: result, errors };
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return { error: true, error_message: `Failed to list agents: ${e}` };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get detailed information about a specific agent, including its skills.
|
|
49
|
+
*
|
|
50
|
+
* Use this after get_agents to learn more about what a specific agent can do.
|
|
51
|
+
* The response includes the agent's name, description, and a list of skills
|
|
52
|
+
* with their descriptions.
|
|
53
|
+
*
|
|
54
|
+
* @param agentId - The agent's unique identifier (from get_agents).
|
|
55
|
+
*/
|
|
56
|
+
async getAgent(agentId) {
|
|
57
|
+
try {
|
|
58
|
+
const result = await this.session.agentManager.getAgentForLlm(agentId, "full");
|
|
59
|
+
if (result === null) {
|
|
60
|
+
const available = Object.keys(await this.session.agentManager.getAgents()).sort();
|
|
61
|
+
return {
|
|
62
|
+
error: true,
|
|
63
|
+
error_message: `Agent '${agentId}' not found. Use get_agents to see available agents. Available: ${available.length > 0 ? available.join(", ") : "(none)"}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
return { error: true, error_message: `Failed to get agent info: ${e}` };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Send a message to an agent and receive a structured response.
|
|
74
|
+
*
|
|
75
|
+
* This is the primary way to communicate with agents. The response includes
|
|
76
|
+
* the agent's reply and any generated artifacts.
|
|
77
|
+
*
|
|
78
|
+
* Artifact data in responses may be minimized for display. Fields prefixed
|
|
79
|
+
* with "_" indicate metadata about minimized content. Use view_text_artifact
|
|
80
|
+
* or view_data_artifact to access full artifact data.
|
|
81
|
+
*
|
|
82
|
+
* If the task is still in progress after the timeout, the response includes
|
|
83
|
+
* a task_id. Use get_task with that task_id to continue monitoring.
|
|
84
|
+
*
|
|
85
|
+
* @param agentId - ID of the agent to message (from get_agents).
|
|
86
|
+
* @param message - The message content to send.
|
|
87
|
+
* @param contextId - Continue an existing conversation by providing its context ID.
|
|
88
|
+
* Omit to start a new conversation.
|
|
89
|
+
* @param taskId - Attach to an existing task (for input_required flows).
|
|
90
|
+
* @param timeout - Override the default timeout in seconds.
|
|
91
|
+
*/
|
|
92
|
+
async sendMessage(agentId, message, contextId, taskId, timeout) {
|
|
93
|
+
try {
|
|
94
|
+
const result = await this.session.sendMessage(agentId, message, {
|
|
95
|
+
contextId,
|
|
96
|
+
taskId,
|
|
97
|
+
timeout,
|
|
98
|
+
});
|
|
99
|
+
let llmResult;
|
|
100
|
+
if (result.kind === "task") {
|
|
101
|
+
llmResult = await this.buildTaskForLlm(result);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
llmResult = this.buildMessageForLlm(result);
|
|
105
|
+
}
|
|
106
|
+
return llmResult;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
const errorMsg = String(e);
|
|
110
|
+
if (errorMsg.toLowerCase().includes("not found")) {
|
|
111
|
+
return {
|
|
112
|
+
error: true,
|
|
113
|
+
error_message: `${errorMsg} Use get_agents to see available agents.`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (e instanceof DOMException && e.name === "TimeoutError") {
|
|
117
|
+
return {
|
|
118
|
+
error: true,
|
|
119
|
+
error_message: "Request timed out. You can retry with a longer timeout, " +
|
|
120
|
+
"or if a task_id was returned earlier, use get_task to check progress.",
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return { error: true, error_message: `Failed to send message: ${e}` };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Check the progress of a task that is still in progress.
|
|
128
|
+
*
|
|
129
|
+
* Use this after send_message returns a task in a non-terminal state
|
|
130
|
+
* (e.g. "working") to monitor its progress.
|
|
131
|
+
*
|
|
132
|
+
* If the task is still running after the timeout, the current state is
|
|
133
|
+
* returned. Call get_task again to continue monitoring.
|
|
134
|
+
*
|
|
135
|
+
* @param agentId - ID of the agent that owns the task.
|
|
136
|
+
* @param taskId - Task ID from a previous send_message response.
|
|
137
|
+
* @param timeout - Override the monitoring timeout in seconds.
|
|
138
|
+
* @param pollInterval - Override the interval between status checks in seconds.
|
|
139
|
+
*/
|
|
140
|
+
async getTask(agentId, taskId, timeout, pollInterval) {
|
|
141
|
+
try {
|
|
142
|
+
const result = await this.session.getTask(agentId, taskId, {
|
|
143
|
+
timeout,
|
|
144
|
+
pollInterval,
|
|
145
|
+
});
|
|
146
|
+
const llmResult = await this.buildTaskForLlm(result);
|
|
147
|
+
return llmResult;
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
const errorMsg = String(e);
|
|
151
|
+
if (errorMsg.toLowerCase().includes("not found")) {
|
|
152
|
+
return {
|
|
153
|
+
error: true,
|
|
154
|
+
error_message: `${errorMsg} Use get_agents to see available agents.`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (e instanceof DOMException && e.name === "TimeoutError") {
|
|
158
|
+
return {
|
|
159
|
+
error: true,
|
|
160
|
+
error_message: "Request timed out. You can retry with a longer timeout, " +
|
|
161
|
+
"or use get_task again to continue monitoring.",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return { error: true, error_message: `Failed to get task: ${e}` };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* View text content from an artifact, optionally selecting a range.
|
|
169
|
+
*
|
|
170
|
+
* Use this for artifacts containing text (documents, logs, code, etc.).
|
|
171
|
+
* You can select by line range OR character range, but not both.
|
|
172
|
+
*
|
|
173
|
+
* @param agentId - ID of the agent that produced the artifact.
|
|
174
|
+
* @param taskId - Task ID containing the artifact.
|
|
175
|
+
* @param artifactId - The artifact's unique identifier (from the task's artifacts list).
|
|
176
|
+
* @param lineStart - Starting line number (1-based, inclusive).
|
|
177
|
+
* @param lineEnd - Ending line number (1-based, inclusive).
|
|
178
|
+
* @param characterStart - Starting character index (0-based, inclusive).
|
|
179
|
+
* @param characterEnd - Ending character index (0-based, exclusive).
|
|
180
|
+
*/
|
|
181
|
+
async viewTextArtifact(agentId, taskId, artifactId, lineStart, lineEnd, characterStart, characterEnd) {
|
|
182
|
+
try {
|
|
183
|
+
const artifact = await this.getArtifact(agentId, taskId, artifactId);
|
|
184
|
+
const text = A2ATools.extractText(artifact);
|
|
185
|
+
const filtered = TextArtifacts.view(text, {
|
|
186
|
+
lineStart,
|
|
187
|
+
lineEnd,
|
|
188
|
+
characterStart,
|
|
189
|
+
characterEnd,
|
|
190
|
+
characterLimit: this.artifactSettings.viewArtifactCharacterLimit,
|
|
191
|
+
});
|
|
192
|
+
const result = {
|
|
193
|
+
artifactId: artifact.artifactId,
|
|
194
|
+
description: artifact.description ?? null,
|
|
195
|
+
name: artifact.name ?? null,
|
|
196
|
+
parts: [{ kind: "text", text: filtered }],
|
|
197
|
+
};
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
const errorMsg = String(e);
|
|
202
|
+
if (errorMsg.toLowerCase().includes("not found")) {
|
|
203
|
+
if (errorMsg.toLowerCase().includes("artifact")) {
|
|
204
|
+
return {
|
|
205
|
+
error: true,
|
|
206
|
+
error_message: `Artifact '${artifactId}' not found in task '${taskId}'. Check the task's artifacts list for valid artifact IDs.`,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
error: true,
|
|
211
|
+
error_message: `${errorMsg} Use get_agents to see available agents.`,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return { error: true, error_message: `Failed to view text artifact: ${e}` };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* View structured data from an artifact with optional filtering.
|
|
219
|
+
*
|
|
220
|
+
* Use this for artifacts containing JSON data (objects, arrays, tables).
|
|
221
|
+
* You can navigate to specific data with json_path, then filter with
|
|
222
|
+
* rows and columns for tabular data.
|
|
223
|
+
*
|
|
224
|
+
* @param agentId - ID of the agent that produced the artifact.
|
|
225
|
+
* @param taskId - Task ID containing the artifact.
|
|
226
|
+
* @param artifactId - The artifact's unique identifier (from the task's artifacts list).
|
|
227
|
+
* @param jsonPath - Dot-separated path to navigate into the data (e.g. "results.items").
|
|
228
|
+
* @param rows - Row selection for list data. Examples: "0" (single row), "0-10" (range),
|
|
229
|
+
* "0,2,5" (specific rows), "all" (every row).
|
|
230
|
+
* @param columns - Column selection for tabular data (list of objects). Examples:
|
|
231
|
+
* "name" (single column), "name,age" (multiple columns), "all" (every column).
|
|
232
|
+
*/
|
|
233
|
+
async viewDataArtifact(agentId, taskId, artifactId, jsonPath, rows, columns) {
|
|
234
|
+
try {
|
|
235
|
+
const parsedRows = A2ATools.parseRows(rows ?? null);
|
|
236
|
+
const parsedColumns = A2ATools.parseColumns(columns ?? null);
|
|
237
|
+
const artifact = await this.getArtifact(agentId, taskId, artifactId);
|
|
238
|
+
const data = A2ATools.extractData(artifact);
|
|
239
|
+
const filtered = DataArtifacts.view(data, {
|
|
240
|
+
jsonPath,
|
|
241
|
+
rows: parsedRows,
|
|
242
|
+
columns: parsedColumns,
|
|
243
|
+
characterLimit: this.artifactSettings.viewArtifactCharacterLimit,
|
|
244
|
+
});
|
|
245
|
+
const result = {
|
|
246
|
+
artifactId: artifact.artifactId,
|
|
247
|
+
description: artifact.description ?? null,
|
|
248
|
+
name: artifact.name ?? null,
|
|
249
|
+
parts: [{ kind: "data", data: filtered }],
|
|
250
|
+
};
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
const errorMsg = String(e);
|
|
255
|
+
if (errorMsg.toLowerCase().includes("not found")) {
|
|
256
|
+
if (errorMsg.toLowerCase().includes("artifact")) {
|
|
257
|
+
return {
|
|
258
|
+
error: true,
|
|
259
|
+
error_message: `Artifact '${artifactId}' not found in task '${taskId}'. Check the task's artifacts list for valid artifact IDs.`,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
error: true,
|
|
264
|
+
error_message: `${errorMsg} Use get_agents to see available agents.`,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return { error: true, error_message: `Failed to view data artifact: ${e}` };
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// -- LLM conversion methods --
|
|
271
|
+
/**
|
|
272
|
+
* Convert an A2A Message to MessageForLLM.
|
|
273
|
+
*
|
|
274
|
+
* Combines all TextParts into a single TextPartForLLM.
|
|
275
|
+
* FileParts are ignored; file handling is done at the artifact level.
|
|
276
|
+
*/
|
|
277
|
+
buildMessageForLlm(message) {
|
|
278
|
+
const parts = [];
|
|
279
|
+
// Combine all text parts
|
|
280
|
+
const textSegments = [];
|
|
281
|
+
for (const part of message.parts) {
|
|
282
|
+
if (part.kind === "text") {
|
|
283
|
+
textSegments.push(part.text);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (textSegments.length > 0) {
|
|
287
|
+
parts.push({ kind: "text", text: textSegments.join("") });
|
|
288
|
+
}
|
|
289
|
+
// Each data part stays separate
|
|
290
|
+
for (const part of message.parts) {
|
|
291
|
+
if (part.kind === "data") {
|
|
292
|
+
parts.push({ kind: "data", data: part.data });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
contextId: message.contextId ?? null,
|
|
297
|
+
kind: "message",
|
|
298
|
+
parts,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/** Convert a Task to TaskForLLM with artifact minimization and file path queries. */
|
|
302
|
+
async buildTaskForLlm(task) {
|
|
303
|
+
// Query fileStore for saved file paths
|
|
304
|
+
let savedFilePaths = null;
|
|
305
|
+
if (this.session.fileStore !== null && task.artifacts) {
|
|
306
|
+
savedFilePaths = {};
|
|
307
|
+
for (const artifact of task.artifacts) {
|
|
308
|
+
const paths = await this.session.fileStore.get(task.id, artifact.artifactId);
|
|
309
|
+
if (paths.length > 0) {
|
|
310
|
+
savedFilePaths[artifact.artifactId] = paths;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const minimized = task.artifacts
|
|
315
|
+
? minimizeArtifacts(task.artifacts, {
|
|
316
|
+
characterLimit: this.artifactSettings.sendMessageCharacterLimit,
|
|
317
|
+
minimizedObjectStringLength: this.artifactSettings.minimizedObjectStringLength,
|
|
318
|
+
savedFilePaths,
|
|
319
|
+
textTip: TEXT_MINIMIZED_TIP,
|
|
320
|
+
dataTip: DATA_MINIMIZED_TIP,
|
|
321
|
+
})
|
|
322
|
+
: [];
|
|
323
|
+
// Build status message
|
|
324
|
+
let statusMessage = null;
|
|
325
|
+
if (task.status.message) {
|
|
326
|
+
statusMessage = this.buildMessageForLlm(task.status.message);
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
id: task.id,
|
|
330
|
+
contextId: task.contextId,
|
|
331
|
+
kind: "task",
|
|
332
|
+
status: {
|
|
333
|
+
state: task.status.state,
|
|
334
|
+
message: statusMessage,
|
|
335
|
+
},
|
|
336
|
+
artifacts: minimized,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Look up an artifact through the resolution chain.
|
|
341
|
+
*
|
|
342
|
+
* 1. Check the task store (local cache)
|
|
343
|
+
* 2. Fetch fresh via session.getTask (remote retrieval)
|
|
344
|
+
*
|
|
345
|
+
* @returns The Artifact.
|
|
346
|
+
*
|
|
347
|
+
* @throws Error if artifact cannot be found.
|
|
348
|
+
*/
|
|
349
|
+
async getArtifact(agentId, taskId, artifactId) {
|
|
350
|
+
// 1. Check task store (local cache)
|
|
351
|
+
const cachedTask = await this.session.taskStore.load(taskId);
|
|
352
|
+
if (cachedTask?.artifacts) {
|
|
353
|
+
for (const artifact of cachedTask.artifacts) {
|
|
354
|
+
if (artifact.artifactId === artifactId) {
|
|
355
|
+
return artifact;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
// 2. Fetch fresh via session.getTask
|
|
360
|
+
const task = await this.session.getTask(agentId, taskId);
|
|
361
|
+
if (task.artifacts) {
|
|
362
|
+
for (const artifact of task.artifacts) {
|
|
363
|
+
if (artifact.artifactId === artifactId) {
|
|
364
|
+
return artifact;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
throw new Error(`Artifact '${artifactId}' not found in task '${taskId}'. The artifact may have expired or the task_id may be incorrect.`);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Extract text content from artifact parts.
|
|
372
|
+
*
|
|
373
|
+
* @throws Error if artifact does not contain text content.
|
|
374
|
+
*/
|
|
375
|
+
static extractText(artifact) {
|
|
376
|
+
const textParts = [];
|
|
377
|
+
for (const part of artifact.parts) {
|
|
378
|
+
if (part.kind === "text") {
|
|
379
|
+
textParts.push(part.text);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (textParts.length === 0) {
|
|
383
|
+
const partTypes = [...new Set(artifact.parts.map((p) => p.kind))].sort();
|
|
384
|
+
throw new Error(`Artifact '${artifact.artifactId}' does not contain text content. ` +
|
|
385
|
+
`Found part types: ${partTypes.join(", ")}`);
|
|
386
|
+
}
|
|
387
|
+
return textParts.join("\n");
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Extract data content from artifact parts.
|
|
391
|
+
*
|
|
392
|
+
* @throws Error if artifact does not contain data content.
|
|
393
|
+
*/
|
|
394
|
+
static extractData(artifact) {
|
|
395
|
+
const dataParts = [];
|
|
396
|
+
for (const part of artifact.parts) {
|
|
397
|
+
if (part.kind === "data") {
|
|
398
|
+
dataParts.push(part.data);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (dataParts.length === 0) {
|
|
402
|
+
const partTypes = [...new Set(artifact.parts.map((p) => p.kind))].sort();
|
|
403
|
+
throw new Error(`Artifact '${artifact.artifactId}' does not contain data content. ` +
|
|
404
|
+
`Found part types: ${partTypes.join(", ")}`);
|
|
405
|
+
}
|
|
406
|
+
return dataParts.length === 1 ? dataParts[0] : dataParts;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Parse a rows string into the type expected by DataArtifacts.view.
|
|
410
|
+
*
|
|
411
|
+
* Accepts: "0" (single int), "0-10" (range string), "0,2,5" (comma-separated
|
|
412
|
+
* list of ints), "all" (passthrough string), or null.
|
|
413
|
+
*/
|
|
414
|
+
static parseRows(rows) {
|
|
415
|
+
if (rows === null) {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
const trimmedRows = rows.trim();
|
|
419
|
+
if (trimmedRows === "all") {
|
|
420
|
+
return "all";
|
|
421
|
+
}
|
|
422
|
+
// Comma-separated list: "0,2,5"
|
|
423
|
+
if (trimmedRows.includes(",")) {
|
|
424
|
+
try {
|
|
425
|
+
return trimmedRows.split(",").map((x) => {
|
|
426
|
+
const n = Number.parseInt(x.trim(), 10);
|
|
427
|
+
if (Number.isNaN(n)) {
|
|
428
|
+
throw new Error();
|
|
429
|
+
}
|
|
430
|
+
return n;
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
throw new Error(`Invalid rows format: '${trimmedRows}'. Comma-separated values must be integers. Examples: '0', '0-10', '0,2,5', 'all'.`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
// Range string: "0-10"
|
|
438
|
+
if (trimmedRows.includes("-")) {
|
|
439
|
+
return trimmedRows;
|
|
440
|
+
}
|
|
441
|
+
// Single integer: "0"
|
|
442
|
+
const n = Number.parseInt(trimmedRows, 10);
|
|
443
|
+
if (Number.isNaN(n)) {
|
|
444
|
+
throw new Error(`Invalid rows format: '${trimmedRows}'. Examples: '0' (single row), '0-10' (range), '0,2,5' (specific rows), 'all'.`);
|
|
445
|
+
}
|
|
446
|
+
return n;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Parse a columns string into the type expected by DataArtifacts.view.
|
|
450
|
+
*
|
|
451
|
+
* Accepts: "name" (single column), "name,age" (comma-separated list),
|
|
452
|
+
* "all" (passthrough string), or null.
|
|
453
|
+
*/
|
|
454
|
+
static parseColumns(columns) {
|
|
455
|
+
if (columns === null) {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
const trimmedColumns = columns.trim();
|
|
459
|
+
if (trimmedColumns === "all") {
|
|
460
|
+
return "all";
|
|
461
|
+
}
|
|
462
|
+
// Comma-separated list: "name,age"
|
|
463
|
+
if (trimmedColumns.includes(",")) {
|
|
464
|
+
return trimmedColumns.split(",").map((c) => c.trim());
|
|
465
|
+
}
|
|
466
|
+
// Single column name
|
|
467
|
+
return trimmedColumns;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
//# sourceMappingURL=a2a-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a-tools.js","sourceRoot":"","sources":["../../src/client/a2a-tools.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,sCAAsC;AAOtC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AASxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,CAAC,MAAM,kBAAkB,GAC3B,6EAA6E,CAAC;A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ED,uBAAuB;QACvB,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,WAAW,CAAC;QACvB,CAAC;QAED,sBAAsB;QACtB,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC3C,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACX,yBAAyB,WAAW,gFAAgF,CACvH,CAAC;QACN,CAAC;QACD,OAAO,CAAC,CAAC;IACb,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,YAAY,CAAC,OAAsB;QAC9C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAEtC,IAAI,cAAc,KAAK,KAAK,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,mCAAmC;QACnC,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,OAAO,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,qBAAqB;QACrB,OAAO,cAAc,CAAC;IAC1B,CAAC;CACJ"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { AgentURLAndCustomHeaders } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Manages A2A agent cards keyed by user-defined agent IDs.
|
|
4
|
+
*
|
|
5
|
+
* Agents are configured via a dict mapping agent_id to config, or a JSON file path.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AgentManager {
|
|
8
|
+
private config;
|
|
9
|
+
private agents;
|
|
10
|
+
private initErrors;
|
|
11
|
+
private initialized;
|
|
12
|
+
private initPromise;
|
|
13
|
+
private readonly timeout;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the agent manager.
|
|
16
|
+
*
|
|
17
|
+
* @param agents - Agent config as:
|
|
18
|
+
* - object: {"agent-id": {"url": "https://...", "custom_headers": {"X-API-Key": "..."}}}
|
|
19
|
+
* - string: path to agents.json file with the same structure
|
|
20
|
+
* - null: empty, add agents later
|
|
21
|
+
* @param opts.timeout - HTTP timeout in seconds for fetching agent cards (default: 15s).
|
|
22
|
+
*/
|
|
23
|
+
constructor(agents?: Record<string, Record<string, unknown>> | string | null, opts?: {
|
|
24
|
+
timeout?: number;
|
|
25
|
+
});
|
|
26
|
+
/** Load and validate agent config. */
|
|
27
|
+
private loadConfig;
|
|
28
|
+
/** Lazily fetch all agent cards on first use (double-check locking). */
|
|
29
|
+
private ensureInitialized;
|
|
30
|
+
private doInitialize;
|
|
31
|
+
/** Fetch a single agent card and register it. */
|
|
32
|
+
private fetchAgent;
|
|
33
|
+
/** Create a fetch implementation that applies the configured timeout and custom headers. */
|
|
34
|
+
private createFetchImpl;
|
|
35
|
+
/** Parse agent card URL into base_url and card_path. */
|
|
36
|
+
private parseAgentCardUrl;
|
|
37
|
+
/**
|
|
38
|
+
* Register a new agent at runtime.
|
|
39
|
+
*
|
|
40
|
+
* @param agentId - User-defined agent identifier.
|
|
41
|
+
* @param url - Agent card URL.
|
|
42
|
+
* @param customHeaders - Optional custom HTTP headers.
|
|
43
|
+
*
|
|
44
|
+
* @throws Error if agentId is already registered.
|
|
45
|
+
*/
|
|
46
|
+
addAgent(agentId: string, url: string, customHeaders?: Record<string, string>): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve agent by ID.
|
|
49
|
+
*
|
|
50
|
+
* @param agentId - User-defined agent identifier.
|
|
51
|
+
*
|
|
52
|
+
* @returns AgentURLAndCustomHeaders, or null if not found.
|
|
53
|
+
*/
|
|
54
|
+
getAgent(agentId: string): Promise<AgentURLAndCustomHeaders | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Get errors from the most recent initialization attempt.
|
|
57
|
+
*
|
|
58
|
+
* @returns Object mapping agent_id to error message for agents that failed to load.
|
|
59
|
+
*/
|
|
60
|
+
get initializationErrors(): Record<string, string>;
|
|
61
|
+
/**
|
|
62
|
+
* Get all registered agents.
|
|
63
|
+
*
|
|
64
|
+
* @returns Object mapping agent_id to AgentURLAndCustomHeaders.
|
|
65
|
+
*/
|
|
66
|
+
getAgents(): Promise<Record<string, AgentURLAndCustomHeaders>>;
|
|
67
|
+
/**
|
|
68
|
+
* Format a single agent card into a summary object.
|
|
69
|
+
*
|
|
70
|
+
* @param card - The agent card to format.
|
|
71
|
+
* @param detail - Detail level — "name", "basic", "skills", or "full".
|
|
72
|
+
*
|
|
73
|
+
* @returns Summary object for the agent.
|
|
74
|
+
*/
|
|
75
|
+
private formatAgentForLlm;
|
|
76
|
+
/**
|
|
77
|
+
* Generate summary for a single agent.
|
|
78
|
+
*
|
|
79
|
+
* @param agentId - User-defined agent identifier.
|
|
80
|
+
* @param detail - Detail level — "name", "basic", "skills", or "full".
|
|
81
|
+
*
|
|
82
|
+
* @returns Summary object for the agent, or null if not found.
|
|
83
|
+
*/
|
|
84
|
+
getAgentForLlm(agentId: string, detail?: "name" | "basic" | "skills" | "full"): Promise<Record<string, unknown> | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Generate summary of all agents.
|
|
87
|
+
*
|
|
88
|
+
* @param detail - Detail level — "name", "basic", "skills", or "full".
|
|
89
|
+
*
|
|
90
|
+
* @returns Object mapping agent_id to summary object, sorted by agent_id.
|
|
91
|
+
*/
|
|
92
|
+
getAgentsForLlm(detail?: "name" | "basic" | "skills" | "full"): Promise<Record<string, Record<string, unknown>>>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=agent-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-manager.d.ts","sourceRoot":"","sources":["../../src/client/agent-manager.ts"],"names":[],"m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