@a2anet/a2a-utils 0.1.0 → 0.4.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-agents.d.ts +94 -0
- package/dist/client/a2a-agents.d.ts.map +1 -0
- package/dist/client/a2a-agents.js +243 -0
- package/dist/client/a2a-agents.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/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,131 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2025-present A2A Net <hello@a2anet.com>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { DataArtifacts } from "./data.js";
|
|
5
|
+
import { TextArtifacts } from "./text.js";
|
|
6
|
+
/**
|
|
7
|
+
* Minimize artifact list for LLM display.
|
|
8
|
+
*
|
|
9
|
+
* Combines all TextParts within each artifact into a single TextPartForLLM.
|
|
10
|
+
* Handles FileParts by including file metadata and saved paths.
|
|
11
|
+
*
|
|
12
|
+
* @param artifacts - List of artifacts to minimize.
|
|
13
|
+
* @param opts.characterLimit - Character limit above which to minimize.
|
|
14
|
+
* @param opts.minimizedObjectStringLength - Max length for string values in objects.
|
|
15
|
+
* @param opts.savedFilePaths - Mapping of artifactId to saved file paths.
|
|
16
|
+
* When provided, file parts show saved locations.
|
|
17
|
+
* When null, FileWithBytes parts show an error and FileWithUri parts
|
|
18
|
+
* show the raw URI.
|
|
19
|
+
* @param opts.textTip - Tip string for minimized text artifacts. null = no tip.
|
|
20
|
+
* @param opts.dataTip - Tip string for minimized data artifacts. null = no tip.
|
|
21
|
+
*
|
|
22
|
+
* @returns List of ArtifactForLLM objects.
|
|
23
|
+
*/
|
|
24
|
+
export function minimizeArtifacts(artifacts, opts) {
|
|
25
|
+
const characterLimit = opts?.characterLimit ?? 50_000;
|
|
26
|
+
const minimizedObjectStringLength = opts?.minimizedObjectStringLength ?? 5_000;
|
|
27
|
+
const savedFilePaths = opts?.savedFilePaths ?? null;
|
|
28
|
+
const textTip = opts?.textTip ?? null;
|
|
29
|
+
const dataTip = opts?.dataTip ?? null;
|
|
30
|
+
const result = [];
|
|
31
|
+
for (const artifact of artifacts) {
|
|
32
|
+
const parts = [];
|
|
33
|
+
// Combine all text parts into one
|
|
34
|
+
const textSegments = [];
|
|
35
|
+
for (const part of artifact.parts) {
|
|
36
|
+
if (part.kind === "text") {
|
|
37
|
+
textSegments.push(part.text);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (textSegments.length > 0) {
|
|
41
|
+
const combinedText = textSegments.join("");
|
|
42
|
+
const textMinimized = TextArtifacts.minimize(combinedText, {
|
|
43
|
+
characterLimit,
|
|
44
|
+
tip: textTip,
|
|
45
|
+
});
|
|
46
|
+
parts.push({
|
|
47
|
+
kind: "text",
|
|
48
|
+
...textMinimized,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Each data part stays separate
|
|
52
|
+
for (const part of artifact.parts) {
|
|
53
|
+
if (part.kind === "data") {
|
|
54
|
+
const dataMinimized = DataArtifacts.minimize(part.data, {
|
|
55
|
+
characterLimit,
|
|
56
|
+
minimizedObjectStringLength,
|
|
57
|
+
tip: dataTip,
|
|
58
|
+
});
|
|
59
|
+
parts.push({ kind: "data", data: dataMinimized });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Handle file parts
|
|
63
|
+
const artifactSaved = savedFilePaths !== null ? (savedFilePaths[artifact.artifactId] ?? null) : null;
|
|
64
|
+
for (const part of artifact.parts) {
|
|
65
|
+
if (part.kind === "file") {
|
|
66
|
+
const fileObj = part.file;
|
|
67
|
+
const name = fileObj.name ?? null;
|
|
68
|
+
const mimeType = fileObj.mimeType ?? null;
|
|
69
|
+
let filePart;
|
|
70
|
+
if ("bytes" in fileObj) {
|
|
71
|
+
// FileWithBytes
|
|
72
|
+
if (artifactSaved !== null) {
|
|
73
|
+
filePart = {
|
|
74
|
+
kind: "file",
|
|
75
|
+
name,
|
|
76
|
+
mimeType,
|
|
77
|
+
uri: null,
|
|
78
|
+
bytes: { _saved_to: artifactSaved },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
filePart = {
|
|
83
|
+
kind: "file",
|
|
84
|
+
name,
|
|
85
|
+
mimeType,
|
|
86
|
+
uri: null,
|
|
87
|
+
bytes: {
|
|
88
|
+
_error: "No FileStore configured. Cannot access file bytes.",
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if ("uri" in fileObj) {
|
|
94
|
+
// FileWithUri
|
|
95
|
+
if (artifactSaved !== null) {
|
|
96
|
+
filePart = {
|
|
97
|
+
kind: "file",
|
|
98
|
+
name,
|
|
99
|
+
mimeType,
|
|
100
|
+
uri: { _saved_to: artifactSaved },
|
|
101
|
+
bytes: null,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
filePart = {
|
|
106
|
+
kind: "file",
|
|
107
|
+
name,
|
|
108
|
+
mimeType,
|
|
109
|
+
uri: fileObj.uri,
|
|
110
|
+
bytes: null,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
parts.push(filePart);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
result.push({
|
|
121
|
+
artifactId: artifact.artifactId,
|
|
122
|
+
description: artifact.description ?? null,
|
|
123
|
+
name: artifact.name ?? null,
|
|
124
|
+
parts,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
export { DataArtifacts } from "./data.js";
|
|
130
|
+
export { TextArtifacts } from "./text.js";
|
|
131
|
+
//# sourceMappingURL=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ts {
|
|
3
|
+
/**
|
|
4
|
+
* View text content with optional line or character range selection.
|
|
5
|
+
*
|
|
6
|
+
* @param text - The text to view.
|
|
7
|
+
* @param opts.lineStart - Starting line number (1-based, inclusive). null = start.
|
|
8
|
+
* @param opts.lineEnd - Ending line number (1-based, inclusive). null = end.
|
|
9
|
+
* @param opts.characterStart - Starting character index (0-based, inclusive). null = start.
|
|
10
|
+
* @param opts.characterEnd - Ending character index (0-based, exclusive). null = end.
|
|
11
|
+
* @param opts.characterLimit - Maximum output size in characters.
|
|
12
|
+
*
|
|
13
|
+
* @returns Filtered text string.
|
|
14
|
+
*
|
|
15
|
+
* @throws Error if both line and character selection are provided,
|
|
16
|
+
* or if parameters are invalid.
|
|
17
|
+
*/
|
|
18
|
+
static view(text: string, opts?: {
|
|
19
|
+
lineStart?: number | null;
|
|
20
|
+
lineEnd?: number | null;
|
|
21
|
+
characterStart?: number | null;
|
|
22
|
+
characterEnd?: number | null;
|
|
23
|
+
characterLimit?: number;
|
|
24
|
+
}): string;
|
|
25
|
+
/**
|
|
26
|
+
* Minimize text content for display.
|
|
27
|
+
*
|
|
28
|
+
* If text is <= characterLimit chars, return it in full inside "text" key.
|
|
29
|
+
* If text is > characterLimit chars, show first half and last half with metadata.
|
|
30
|
+
*
|
|
31
|
+
* @param text - The text content to minimize.
|
|
32
|
+
* @param opts.characterLimit - Character limit above which to minimize.
|
|
33
|
+
* @param opts.tip - Tip to include. Defaults to null (no tip); pass a string to include one.
|
|
34
|
+
*
|
|
35
|
+
* @returns Object with "text" key containing readable content and metadata fields.
|
|
36
|
+
*/
|
|
37
|
+
static minimize(text: string, opts?: {
|
|
38
|
+
characterLimit?: number;
|
|
39
|
+
tip?: string | null;
|
|
40
|
+
}): Record<string, unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Parse line range parameters.
|
|
43
|
+
*
|
|
44
|
+
* @param lineStart - Starting line number (1-based, inclusive). null means 1.
|
|
45
|
+
* @param lineEnd - Ending line number (1-based, inclusive). null means totalLines.
|
|
46
|
+
* @param totalLines - Total number of lines.
|
|
47
|
+
*
|
|
48
|
+
* @returns Tuple of [startIndex, endIndex] as 0-based indices.
|
|
49
|
+
*
|
|
50
|
+
* @throws Error if line numbers are invalid.
|
|
51
|
+
*/
|
|
52
|
+
private static parseLineRange;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/artifacts/text.ts"],"names":[],"mappings":"AAaA,0DAA0D;AAC1D,qBAAa,aAAa;IACtB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,IAAI,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;KAC3B,GACF,MAAM;IAuCT;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,QAAQ,CACX,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,GACF,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAqD1B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;CA8BhC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2025-present A2A Net <hello@a2anet.com>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
/**
|
|
5
|
+
* Text artifact viewing and minimization.
|
|
6
|
+
*/
|
|
7
|
+
/** Format a number with comma separators (locale-independent, matching Python's `f"{n:,}"`). */
|
|
8
|
+
function formatNumber(n) {
|
|
9
|
+
return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
10
|
+
}
|
|
11
|
+
/** Text artifact operations: viewing and minimization. */
|
|
12
|
+
export class TextArtifacts {
|
|
13
|
+
/**
|
|
14
|
+
* View text content with optional line or character range selection.
|
|
15
|
+
*
|
|
16
|
+
* @param text - The text to view.
|
|
17
|
+
* @param opts.lineStart - Starting line number (1-based, inclusive). null = start.
|
|
18
|
+
* @param opts.lineEnd - Ending line number (1-based, inclusive). null = end.
|
|
19
|
+
* @param opts.characterStart - Starting character index (0-based, inclusive). null = start.
|
|
20
|
+
* @param opts.characterEnd - Ending character index (0-based, exclusive). null = end.
|
|
21
|
+
* @param opts.characterLimit - Maximum output size in characters.
|
|
22
|
+
*
|
|
23
|
+
* @returns Filtered text string.
|
|
24
|
+
*
|
|
25
|
+
* @throws Error if both line and character selection are provided,
|
|
26
|
+
* or if parameters are invalid.
|
|
27
|
+
*/
|
|
28
|
+
static view(text, opts) {
|
|
29
|
+
const lineStart = opts?.lineStart ?? null;
|
|
30
|
+
const lineEnd = opts?.lineEnd ?? null;
|
|
31
|
+
const characterStart = opts?.characterStart ?? null;
|
|
32
|
+
const characterEnd = opts?.characterEnd ?? null;
|
|
33
|
+
const characterLimit = opts?.characterLimit ?? 50_000;
|
|
34
|
+
const hasLine = lineStart !== null || lineEnd !== null;
|
|
35
|
+
const hasChar = characterStart !== null || characterEnd !== null;
|
|
36
|
+
if (hasLine && hasChar) {
|
|
37
|
+
throw new Error("Cannot use both line and character selection");
|
|
38
|
+
}
|
|
39
|
+
let resultText;
|
|
40
|
+
if (hasChar) {
|
|
41
|
+
const start = characterStart ?? 0;
|
|
42
|
+
const end = characterEnd ?? text.length;
|
|
43
|
+
resultText = text.slice(start, end);
|
|
44
|
+
}
|
|
45
|
+
else if (hasLine) {
|
|
46
|
+
const lines = text.split("\n");
|
|
47
|
+
const totalLines = lines.length;
|
|
48
|
+
const [startIdx, endIdx] = TextArtifacts.parseLineRange(lineStart, lineEnd, totalLines);
|
|
49
|
+
const selectedLines = lines.slice(startIdx, endIdx);
|
|
50
|
+
resultText = selectedLines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
resultText = text;
|
|
54
|
+
}
|
|
55
|
+
if (resultText.length > characterLimit) {
|
|
56
|
+
throw new Error(`Selected text (${formatNumber(resultText.length)} characters) exceeds the maximum output size of ${formatNumber(characterLimit)} characters. Try selecting a smaller range.`);
|
|
57
|
+
}
|
|
58
|
+
return resultText;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Minimize text content for display.
|
|
62
|
+
*
|
|
63
|
+
* If text is <= characterLimit chars, return it in full inside "text" key.
|
|
64
|
+
* If text is > characterLimit chars, show first half and last half with metadata.
|
|
65
|
+
*
|
|
66
|
+
* @param text - The text content to minimize.
|
|
67
|
+
* @param opts.characterLimit - Character limit above which to minimize.
|
|
68
|
+
* @param opts.tip - Tip to include. Defaults to null (no tip); pass a string to include one.
|
|
69
|
+
*
|
|
70
|
+
* @returns Object with "text" key containing readable content and metadata fields.
|
|
71
|
+
*/
|
|
72
|
+
static minimize(text, opts) {
|
|
73
|
+
const characterLimit = opts?.characterLimit ?? 50_000;
|
|
74
|
+
const tip = opts?.tip ?? null;
|
|
75
|
+
if (text.length <= characterLimit) {
|
|
76
|
+
return { text };
|
|
77
|
+
}
|
|
78
|
+
const half = Math.floor(characterLimit / 2);
|
|
79
|
+
const lines = text.split("\n");
|
|
80
|
+
const lineCount = lines.length;
|
|
81
|
+
// Find which line the half char falls on for the start
|
|
82
|
+
let charCount = 0;
|
|
83
|
+
let startEndLine = 1;
|
|
84
|
+
for (let i = 0; i < lines.length; i++) {
|
|
85
|
+
charCount += lines[i].length + 1; // +1 for newline
|
|
86
|
+
if (charCount >= half) {
|
|
87
|
+
startEndLine = i + 1;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Find which line the end section starts on
|
|
92
|
+
charCount = 0;
|
|
93
|
+
let endStartLine = lineCount;
|
|
94
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
95
|
+
charCount += lines[i].length + 1;
|
|
96
|
+
if (charCount >= half) {
|
|
97
|
+
endStartLine = i + 1;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const omittedChars = text.length - 2 * half;
|
|
102
|
+
const result = {
|
|
103
|
+
text: `${text.slice(0, half)}\n\n[... ${formatNumber(omittedChars)} characters omitted ...]\n\n${text.slice(-half)}`,
|
|
104
|
+
_total_lines: lineCount,
|
|
105
|
+
_total_characters: text.length,
|
|
106
|
+
_start_line_range: `1-${startEndLine}`,
|
|
107
|
+
_end_line_range: `${endStartLine}-${lineCount}`,
|
|
108
|
+
_start_character_range: `0-${half}`,
|
|
109
|
+
_end_character_range: `${text.length - half}-${text.length}`,
|
|
110
|
+
};
|
|
111
|
+
if (tip !== null) {
|
|
112
|
+
result._tip = tip;
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Parse line range parameters.
|
|
118
|
+
*
|
|
119
|
+
* @param lineStart - Starting line number (1-based, inclusive). null means 1.
|
|
120
|
+
* @param lineEnd - Ending line number (1-based, inclusive). null means totalLines.
|
|
121
|
+
* @param totalLines - Total number of lines.
|
|
122
|
+
*
|
|
123
|
+
* @returns Tuple of [startIndex, endIndex] as 0-based indices.
|
|
124
|
+
*
|
|
125
|
+
* @throws Error if line numbers are invalid.
|
|
126
|
+
*/
|
|
127
|
+
static parseLineRange(lineStart, lineEnd, totalLines) {
|
|
128
|
+
let start = lineStart ?? 1;
|
|
129
|
+
let end = lineEnd ?? totalLines;
|
|
130
|
+
// Handle negative line numbers (count from end)
|
|
131
|
+
if (start < 0) {
|
|
132
|
+
start = totalLines + start + 1;
|
|
133
|
+
}
|
|
134
|
+
if (end < 0) {
|
|
135
|
+
end = totalLines + end + 1;
|
|
136
|
+
}
|
|
137
|
+
// Validate range
|
|
138
|
+
if (start < 1) {
|
|
139
|
+
throw new Error(`line_start must be >= 1 (got ${start})`);
|
|
140
|
+
}
|
|
141
|
+
if (end > totalLines) {
|
|
142
|
+
throw new Error(`line_end (${end}) exceeds total lines (${totalLines})`);
|
|
143
|
+
}
|
|
144
|
+
if (start > end) {
|
|
145
|
+
throw new Error(`line_start (${start}) must be <= line_end (${end})`);
|
|
146
|
+
}
|
|
147
|
+
// Convert to 0-based indices
|
|
148
|
+
return [start - 1, end];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/artifacts/text.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,sCAAsC;AAEtC;;GAEG;AAEH,gGAAgG;AAChG,SAAS,YAAY,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED,0DAA0D;AAC1D,MAAM,OAAO,aAAa;IACtB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,IAAI,CACP,IAAY,EACZ,IAMC;QAED,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,IAAI,CAAC;QAC1C,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC;QACtC,MAAM,cAAc,GAAG,IAAI,EAAE,cAAc,IAAI,IAAI,CAAC;QACpD,MAAM,YAAY,GAAG,IAAI,EAAE,YAAY,IAAI,IAAI,CAAC;QAChD,MAAM,cAAc,GAAG,IAAI,EAAE,cAAc,IAAI,MAAM,CAAC;QAEtD,MAAM,OAAO,GAAG,SAAS,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,CAAC;QACvD,MAAM,OA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,CAAC,CAAC;QAC7E,CAAC;QACD,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,eAAe,KAAK,0BAA0B,GAAG,GAAG,CAAC,CAAC;QAC1E,CAAC;QAED,6BAA6B;QAC7B,OAAO,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5B,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 A2AAgents {
|
|
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=a2a-agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a-agents.d.ts","sourceRoot":"","sources":["../../src/client/a2a-agents.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;GAIG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,MAAM,CAAgD;IAC9D,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;;;;;;OAQG;gBAEC,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,GAAG,IAAW,EACtE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAM/B,sCAAsC;IACtC,OAAO,CAAC,UAAU;IAelB,wEAAwE;YAC1D,iBAAiB;YAUjB,YAAY;IAoC1B,iDAAiD;YACnC,UAAU;IAgBxB,4FAA4F;IAC5F,OAAO,CAAC,eAAe;IAqBvB,wDAA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