@galdor/a2a 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/dist/client.d.ts +107 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +241 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +89 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +321 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +236 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +148 -0
- package/dist/types.js.map +1 -0
- package/package.json +36 -0
- package/src/a2a.test.ts +267 -0
- package/src/client.ts +298 -0
- package/src/index.ts +54 -0
- package/src/server.ts +408 -0
- package/src/types.ts +297 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The A2A HTTP surface as a Bun.serve-compatible fetch handler.
|
|
3
|
+
*
|
|
4
|
+
* Two routes are served:
|
|
5
|
+
* - GET /.well-known/agent.json → the Agent Card
|
|
6
|
+
* - POST <any other path> → JSON-RPC (tasks/send, tasks/get)
|
|
7
|
+
*
|
|
8
|
+
* Tasks live in an in-memory store keyed by id. Sends targeting the same id are
|
|
9
|
+
* serialized through a per-entry promise chain, while the task handler itself
|
|
10
|
+
* runs without holding any data lock — so a concurrent `tasks/get` observes the
|
|
11
|
+
* "working" state mid-flight. The single-threaded event loop keeps each
|
|
12
|
+
* synchronous section atomic.
|
|
13
|
+
*/
|
|
14
|
+
import { AGENT_CARD_PATH, agentText, appendMessage, ERR_INTERNAL_ERROR, ERR_INVALID_PARAMS, ERR_INVALID_REQUEST, ERR_INVALID_TASK_STATE, ERR_METHOD_NOT_FOUND, ERR_PARSE_ERROR, ERR_TASK_NOT_FOUND, isTerminalState, METHOD_TASKS_GET, METHOD_TASKS_SEND, } from "./types.js";
|
|
15
|
+
/**
|
|
16
|
+
* Adapts a plain function into a {@link Handler}.
|
|
17
|
+
*
|
|
18
|
+
* @param fn - The task-handling function.
|
|
19
|
+
* @returns A {@link Handler} that delegates to `fn`.
|
|
20
|
+
*/
|
|
21
|
+
export function handlerFunc(fn) {
|
|
22
|
+
return { handle: fn };
|
|
23
|
+
}
|
|
24
|
+
// Inbound-request and store limits. The server accepts unauthenticated input,
|
|
25
|
+
// so every growth vector is bounded.
|
|
26
|
+
const MAX_REQUEST_BYTES = 4 << 20; // 4 MiB
|
|
27
|
+
const MAX_TASK_ID_LEN = 512;
|
|
28
|
+
const DEFAULT_MAX_TASKS = 4096;
|
|
29
|
+
/**
|
|
30
|
+
* Exposes an agent over the A2A HTTP surface.
|
|
31
|
+
*
|
|
32
|
+
* Prefer {@link newServer} for construction. Wire {@link Server.fetch} into
|
|
33
|
+
* Bun.serve to start listening.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const server = newServer(card, async (task) => {
|
|
37
|
+
* appendMessage(task, agentText("hi"));
|
|
38
|
+
* task.status.state = "completed";
|
|
39
|
+
* });
|
|
40
|
+
* Bun.serve({ port: 8080, fetch: server.fetch });
|
|
41
|
+
*/
|
|
42
|
+
export class Server {
|
|
43
|
+
/** The Agent Card served verbatim at the well-known path. */
|
|
44
|
+
card;
|
|
45
|
+
handler;
|
|
46
|
+
/** Maximum number of tasks retained in the in-memory store. */
|
|
47
|
+
maxTasks = DEFAULT_MAX_TASKS;
|
|
48
|
+
tasks = new Map();
|
|
49
|
+
/**
|
|
50
|
+
* @param card - The Agent Card to advertise.
|
|
51
|
+
* @param handler - The handler that processes each task.
|
|
52
|
+
*/
|
|
53
|
+
constructor(card, handler) {
|
|
54
|
+
this.card = card;
|
|
55
|
+
this.handler = handler;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Bun.serve-compatible request handler, pre-bound so it can be passed by
|
|
59
|
+
* reference. Routes GETs of the well-known path to the Agent Card, POSTs to
|
|
60
|
+
* the JSON-RPC dispatcher, and rejects other methods with HTTP 405.
|
|
61
|
+
*
|
|
62
|
+
* @param req - The incoming HTTP request.
|
|
63
|
+
* @returns The HTTP response.
|
|
64
|
+
*/
|
|
65
|
+
fetch = async (req) => {
|
|
66
|
+
const url = new URL(req.url);
|
|
67
|
+
if (req.method === "GET" && url.pathname === AGENT_CARD_PATH) {
|
|
68
|
+
return this.serveAgentCard();
|
|
69
|
+
}
|
|
70
|
+
if (req.method !== "POST") {
|
|
71
|
+
return new Response("method not allowed", { status: 405 });
|
|
72
|
+
}
|
|
73
|
+
return this.serveJSONRPC(req);
|
|
74
|
+
};
|
|
75
|
+
serveAgentCard() {
|
|
76
|
+
return new Response(JSON.stringify(this.card), {
|
|
77
|
+
status: 200,
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
80
|
+
"Cache-Control": "no-store",
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async serveJSONRPC(req) {
|
|
85
|
+
// Bound the body: an unauthenticated peer must not drive unbounded
|
|
86
|
+
// allocation with a giant POST. Reject early on a declared Content-Length
|
|
87
|
+
// over the cap, and otherwise count bytes as the body streams in so an
|
|
88
|
+
// unsized body is also rejected once it crosses the cap.
|
|
89
|
+
const declared = req.headers.get("content-length");
|
|
90
|
+
if (declared !== null) {
|
|
91
|
+
const n = Number(declared);
|
|
92
|
+
if (Number.isFinite(n) && n > MAX_REQUEST_BYTES) {
|
|
93
|
+
return jsonResponse(errorReply(null, ERR_PARSE_ERROR, "parse error", "request body too large"));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const body = await readRequestCapped(req, MAX_REQUEST_BYTES);
|
|
97
|
+
if (body === null) {
|
|
98
|
+
return jsonResponse(errorReply(null, ERR_PARSE_ERROR, "parse error", "request body too large"));
|
|
99
|
+
}
|
|
100
|
+
let msg;
|
|
101
|
+
try {
|
|
102
|
+
msg = JSON.parse(body);
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
return jsonResponse(errorReply(null, ERR_PARSE_ERROR, "parse error", String(e)));
|
|
106
|
+
}
|
|
107
|
+
const id = msg.id ?? null;
|
|
108
|
+
if (msg.jsonrpc !== "2.0") {
|
|
109
|
+
return jsonResponse(errorReply(id, ERR_INVALID_REQUEST, 'jsonrpc must be "2.0"', String(msg.jsonrpc)));
|
|
110
|
+
}
|
|
111
|
+
let reply;
|
|
112
|
+
switch (msg.method) {
|
|
113
|
+
case METHOD_TASKS_SEND:
|
|
114
|
+
reply = await this.handleTasksSend(id, msg.params, req.signal);
|
|
115
|
+
break;
|
|
116
|
+
case METHOD_TASKS_GET:
|
|
117
|
+
reply = this.handleTasksGet(id, msg.params);
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
reply = errorReply(id, ERR_METHOD_NOT_FOUND, "method not found", String(msg.method));
|
|
121
|
+
}
|
|
122
|
+
return jsonResponse(reply);
|
|
123
|
+
}
|
|
124
|
+
async handleTasksSend(id, rawParams, signal) {
|
|
125
|
+
const p = rawParams;
|
|
126
|
+
if (!p || typeof p !== "object") {
|
|
127
|
+
return errorReply(id, ERR_INVALID_PARAMS, "decode params", "");
|
|
128
|
+
}
|
|
129
|
+
const message = p.message;
|
|
130
|
+
if (!message || !Array.isArray(message.parts) || message.parts.length === 0) {
|
|
131
|
+
return errorReply(id, ERR_INVALID_PARAMS, "message.parts is empty", "");
|
|
132
|
+
}
|
|
133
|
+
const reqID = p.id ?? "";
|
|
134
|
+
if (reqID.length > MAX_TASK_ID_LEN) {
|
|
135
|
+
return errorReply(id, ERR_INVALID_PARAMS, "id too long", "");
|
|
136
|
+
}
|
|
137
|
+
// Look up or create the entry. The synchronous section is atomic on the
|
|
138
|
+
// event loop. An empty id always allocates a fresh uuid-keyed task.
|
|
139
|
+
let entry = reqID !== "" ? this.tasks.get(reqID) : undefined;
|
|
140
|
+
if (entry === undefined) {
|
|
141
|
+
if (this.tasks.size >= this.maxTasks && !this.evictOne()) {
|
|
142
|
+
return errorReply(id, ERR_INTERNAL_ERROR, "task store is full", "");
|
|
143
|
+
}
|
|
144
|
+
const newID = reqID !== "" ? reqID : crypto.randomUUID();
|
|
145
|
+
const task = {
|
|
146
|
+
id: newID,
|
|
147
|
+
status: { state: "submitted", timestamp: new Date().toISOString() },
|
|
148
|
+
history: [],
|
|
149
|
+
...(p.sessionId !== undefined && p.sessionId !== "" ? { sessionId: p.sessionId } : {}),
|
|
150
|
+
...(p.metadata !== undefined ? { metadata: { ...p.metadata } } : {}),
|
|
151
|
+
};
|
|
152
|
+
entry = { task, updated: Date.now(), lock: Promise.resolve() };
|
|
153
|
+
this.tasks.set(newID, entry);
|
|
154
|
+
}
|
|
155
|
+
// Serialize same-id sends: chain onto the entry's lock.
|
|
156
|
+
const e = entry;
|
|
157
|
+
const prev = e.lock;
|
|
158
|
+
let release;
|
|
159
|
+
e.lock = new Promise((res) => {
|
|
160
|
+
release = res;
|
|
161
|
+
});
|
|
162
|
+
await prev;
|
|
163
|
+
try {
|
|
164
|
+
return await this.processSend(id, e, message, p, signal);
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
release();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async processSend(id, e, message, p, signal) {
|
|
171
|
+
// Phase 1: reject a terminal task, append the user message, flip to
|
|
172
|
+
// "running" and commit — so a concurrent tasks/get observes progress.
|
|
173
|
+
if (isTerminalState(e.task.status.state)) {
|
|
174
|
+
return errorReply(id, ERR_INVALID_TASK_STATE, "task is in a terminal state and cannot be continued", e.task.status.state);
|
|
175
|
+
}
|
|
176
|
+
appendMessage(e.task, message);
|
|
177
|
+
if (p.sessionId !== undefined && p.sessionId !== "") {
|
|
178
|
+
e.task.sessionId = p.sessionId;
|
|
179
|
+
}
|
|
180
|
+
if (p.metadata !== undefined && Object.keys(p.metadata).length > 0) {
|
|
181
|
+
e.task.metadata = { ...(e.task.metadata ?? {}), ...p.metadata };
|
|
182
|
+
}
|
|
183
|
+
// Flip only state + timestamp; a prior status message (e.g. an
|
|
184
|
+
// input-required prompt) stays visible on the mid-handler snapshot.
|
|
185
|
+
e.task.status = {
|
|
186
|
+
...e.task.status,
|
|
187
|
+
state: "working",
|
|
188
|
+
timestamp: new Date().toISOString(),
|
|
189
|
+
};
|
|
190
|
+
e.updated = Date.now();
|
|
191
|
+
// Detach an independent copy for the handler so its mutations can't bleed
|
|
192
|
+
// into the stored task until committed.
|
|
193
|
+
const wc = structuredClone(e.task);
|
|
194
|
+
// Phase 2: run the handler. No data lock is held across the await, so a
|
|
195
|
+
// concurrent tasks/get returns the "working" snapshot promptly.
|
|
196
|
+
try {
|
|
197
|
+
await this.handler.handle(wc, signal);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
wc.status = {
|
|
201
|
+
state: "failed",
|
|
202
|
+
message: agentText(err instanceof Error ? err.message : String(err)),
|
|
203
|
+
timestamp: new Date().toISOString(),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (!isTerminalState(wc.status.state) && wc.status.state !== "input-required") {
|
|
207
|
+
// Handler returned cleanly but forgot to set a terminal state. A handler
|
|
208
|
+
// that asked for more input (input-required) is left as-is so the task
|
|
209
|
+
// can be continued with a later tasks/send.
|
|
210
|
+
wc.status = { ...wc.status, state: "completed", timestamp: new Date().toISOString() };
|
|
211
|
+
}
|
|
212
|
+
// Phase 3: commit the result and snapshot for the reply.
|
|
213
|
+
e.task = wc;
|
|
214
|
+
e.updated = Date.now();
|
|
215
|
+
return successReply(id, structuredClone(wc));
|
|
216
|
+
}
|
|
217
|
+
evictOne() {
|
|
218
|
+
let oldestID = "";
|
|
219
|
+
let oldest = Number.POSITIVE_INFINITY;
|
|
220
|
+
for (const [tid, e] of this.tasks) {
|
|
221
|
+
if (!isTerminalState(e.task.status.state))
|
|
222
|
+
continue;
|
|
223
|
+
if (oldestID === "" || e.updated < oldest) {
|
|
224
|
+
oldestID = tid;
|
|
225
|
+
oldest = e.updated;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (oldestID === "")
|
|
229
|
+
return false;
|
|
230
|
+
this.tasks.delete(oldestID);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
handleTasksGet(id, rawParams) {
|
|
234
|
+
const p = rawParams;
|
|
235
|
+
if (!p || typeof p !== "object") {
|
|
236
|
+
return errorReply(id, ERR_INVALID_PARAMS, "decode params", "");
|
|
237
|
+
}
|
|
238
|
+
if (!p.id) {
|
|
239
|
+
return errorReply(id, ERR_INVALID_PARAMS, "id is required", "");
|
|
240
|
+
}
|
|
241
|
+
const e = this.tasks.get(p.id);
|
|
242
|
+
if (e === undefined) {
|
|
243
|
+
return errorReply(id, ERR_TASK_NOT_FOUND, "task not found", p.id);
|
|
244
|
+
}
|
|
245
|
+
const snap = structuredClone(e.task);
|
|
246
|
+
if (p.historyLength !== undefined &&
|
|
247
|
+
p.historyLength > 0 &&
|
|
248
|
+
snap.history !== undefined &&
|
|
249
|
+
snap.history.length > p.historyLength) {
|
|
250
|
+
snap.history = snap.history.slice(snap.history.length - p.historyLength);
|
|
251
|
+
}
|
|
252
|
+
return successReply(id, snap);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Constructs a {@link Server}, accepting either a {@link Handler} object or a
|
|
257
|
+
* plain {@link HandlerFn}. The card is served verbatim at the well-known path.
|
|
258
|
+
*
|
|
259
|
+
* @param card - The Agent Card to advertise.
|
|
260
|
+
* @param handler - The task handler, as an object or a function.
|
|
261
|
+
* @returns A ready-to-serve {@link Server}.
|
|
262
|
+
*/
|
|
263
|
+
export function newServer(card, handler) {
|
|
264
|
+
const h = typeof handler === "function" ? { handle: handler } : handler;
|
|
265
|
+
return new Server(card, h);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Reads a request body, counting bytes as they arrive and aborting once the
|
|
269
|
+
* cap is exceeded — so an oversized body is rejected without first being fully
|
|
270
|
+
* buffered.
|
|
271
|
+
*
|
|
272
|
+
* @param req - The incoming request.
|
|
273
|
+
* @param cap - Maximum number of body bytes to accept.
|
|
274
|
+
* @returns The decoded body text, or `null` if the body exceeds `cap`.
|
|
275
|
+
*/
|
|
276
|
+
async function readRequestCapped(req, cap) {
|
|
277
|
+
const stream = req.body;
|
|
278
|
+
if (stream === null) {
|
|
279
|
+
return "";
|
|
280
|
+
}
|
|
281
|
+
const reader = stream.getReader();
|
|
282
|
+
const chunks = [];
|
|
283
|
+
let total = 0;
|
|
284
|
+
for (;;) {
|
|
285
|
+
const { done, value } = await reader.read();
|
|
286
|
+
if (done) {
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
if (value) {
|
|
290
|
+
total += value.byteLength;
|
|
291
|
+
if (total > cap) {
|
|
292
|
+
await reader.cancel();
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
chunks.push(value);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const buf = new Uint8Array(total);
|
|
299
|
+
let offset = 0;
|
|
300
|
+
for (const chunk of chunks) {
|
|
301
|
+
buf.set(chunk, offset);
|
|
302
|
+
offset += chunk.byteLength;
|
|
303
|
+
}
|
|
304
|
+
return new TextDecoder().decode(buf);
|
|
305
|
+
}
|
|
306
|
+
function successReply(id, result) {
|
|
307
|
+
return { jsonrpc: "2.0", id, result };
|
|
308
|
+
}
|
|
309
|
+
function errorReply(id, code, message, detail) {
|
|
310
|
+
const error = detail !== "" ? { code, message, data: { detail } } : { code, message };
|
|
311
|
+
return { jsonrpc: "2.0", id: id ?? null, error };
|
|
312
|
+
}
|
|
313
|
+
function jsonResponse(msg) {
|
|
314
|
+
// JSON-RPC over HTTP always returns 200 even for protocol-level errors —
|
|
315
|
+
// the error lives in the response envelope.
|
|
316
|
+
return new Response(JSON.stringify(msg), {
|
|
317
|
+
status: 200,
|
|
318
|
+
headers: { "Content-Type": "application/json; charset=utf-8" },
|
|
319
|
+
});
|
|
320
|
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CAAC,UAAU,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,YAAY,CAAC,EAAS,EAAE,MAAe;IAC9C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,UAAU,CAAC,EAAS,EAAE,IAAY,EAAE,OAAe,EAAE,MAAc;IAC1E,MAAM,KAAK,GACT,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC1E,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC;AACnD,CAAC;AAED,SAAS,YAAY,CAAC,GAAgB;IACpC,yEAAyE;IACzE,4CAA4C;IAC5C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;QACvC,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,cAAc,EAAE,iCAAiC,EAAE;KAC/D,CAAC,CAAC;AACL,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types, constants, message helpers and errors for the Agent-to-Agent
|
|
3
|
+
* (A2A) protocol carried as JSON-RPC 2.0 over HTTP.
|
|
4
|
+
*
|
|
5
|
+
* Field names are camelCase and serialize directly to the on-wire JSON. Data
|
|
6
|
+
* shapes are plain interfaces; failures are represented as {@link Error}
|
|
7
|
+
* subclasses ({@link A2AError}, {@link RPCError}).
|
|
8
|
+
*
|
|
9
|
+
* Scope notes for this implementation:
|
|
10
|
+
* - {@link TaskState} is the A2A-spec six-value lifecycle:
|
|
11
|
+
* submitted | working | input-required | completed | failed | canceled.
|
|
12
|
+
* - {@link TaskStatus} carries the state plus an optional status `message`
|
|
13
|
+
* (e.g. an input-required prompt or a failure message) and a `timestamp`.
|
|
14
|
+
* - A task's full message log lives in {@link Task.history}; non-message
|
|
15
|
+
* outputs live in {@link Task.artifacts}.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Well-known location of an agent's card. The A2A spec mandates this exact
|
|
19
|
+
* suffix; clients discover an agent at `<baseURL>/.well-known/agent.json`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const AGENT_CARD_PATH = "/.well-known/agent.json";
|
|
22
|
+
/** A2A protocol revision this implementation targets. */
|
|
23
|
+
export declare const PROTOCOL_VERSION = "0.1";
|
|
24
|
+
/** JSON-RPC method name for creating or continuing a task. */
|
|
25
|
+
export declare const METHOD_TASKS_SEND = "tasks/send";
|
|
26
|
+
/** JSON-RPC method name for fetching a task's current state. */
|
|
27
|
+
export declare const METHOD_TASKS_GET = "tasks/get";
|
|
28
|
+
/** Malformed JSON in the request body. */
|
|
29
|
+
export declare const ERR_PARSE_ERROR = -32700;
|
|
30
|
+
/** Request envelope is not a valid JSON-RPC request. */
|
|
31
|
+
export declare const ERR_INVALID_REQUEST = -32600;
|
|
32
|
+
/** Requested method is not implemented. */
|
|
33
|
+
export declare const ERR_METHOD_NOT_FOUND = -32601;
|
|
34
|
+
/** Method params are missing or invalid. */
|
|
35
|
+
export declare const ERR_INVALID_PARAMS = -32602;
|
|
36
|
+
/** Unexpected server-side failure. */
|
|
37
|
+
export declare const ERR_INTERNAL_ERROR = -32603;
|
|
38
|
+
/** No task exists for the supplied id. */
|
|
39
|
+
export declare const ERR_TASK_NOT_FOUND = -32001;
|
|
40
|
+
/** Task cannot accept the request in its current state (e.g. terminal). */
|
|
41
|
+
export declare const ERR_INVALID_TASK_STATE = -32002;
|
|
42
|
+
/** AgentProvider identifies the organization running the agent. */
|
|
43
|
+
export interface AgentProvider {
|
|
44
|
+
organization: string;
|
|
45
|
+
url: string;
|
|
46
|
+
}
|
|
47
|
+
/** AgentCapabilities advertises optional protocol features. */
|
|
48
|
+
export interface AgentCapabilities {
|
|
49
|
+
streaming?: boolean;
|
|
50
|
+
pushNotifications?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** AgentSkill is one discrete capability the agent advertises. */
|
|
53
|
+
export interface AgentSkill {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
tags?: string[];
|
|
58
|
+
examples?: string[];
|
|
59
|
+
}
|
|
60
|
+
/** AgentCard is the metadata document served at /.well-known/agent.json. */
|
|
61
|
+
export interface AgentCard {
|
|
62
|
+
name: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
url: string;
|
|
65
|
+
version?: string;
|
|
66
|
+
provider?: AgentProvider;
|
|
67
|
+
capabilities: AgentCapabilities;
|
|
68
|
+
skills: AgentSkill[];
|
|
69
|
+
defaultInputModes?: string[];
|
|
70
|
+
defaultOutputModes?: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Part is one element of a message's content. The A2A spec defines "text",
|
|
74
|
+
* "file" and "data" parts; only "text" is implemented. `type` is the
|
|
75
|
+
* discriminator so future parts deserialize without breaking older readers.
|
|
76
|
+
*/
|
|
77
|
+
export interface Part {
|
|
78
|
+
type: string;
|
|
79
|
+
/** Text is set when type === "text". */
|
|
80
|
+
text?: string;
|
|
81
|
+
metadata?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
/** Role identifies who sent a message. */
|
|
84
|
+
export type Role = "user" | "agent";
|
|
85
|
+
/** TaskMessage is one turn in a task's message log. */
|
|
86
|
+
export interface TaskMessage {
|
|
87
|
+
role: Role;
|
|
88
|
+
parts: Part[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* TaskState is the discrete lifecycle state of a task, per the A2A spec.
|
|
92
|
+
*
|
|
93
|
+
* `submitted` → `working` are non-terminal; `input-required` is non-terminal
|
|
94
|
+
* and signals the agent needs more input (the task can be continued with
|
|
95
|
+
* another tasks/send); `completed` / `failed` / `canceled` are terminal.
|
|
96
|
+
*/
|
|
97
|
+
export type TaskState = "submitted" | "working" | "input-required" | "completed" | "failed" | "canceled";
|
|
98
|
+
/** TaskStatus is the status block of a Task. */
|
|
99
|
+
export interface TaskStatus {
|
|
100
|
+
state: TaskState;
|
|
101
|
+
/** Optional status message (e.g. an input-required prompt or a failure message). */
|
|
102
|
+
message?: TaskMessage;
|
|
103
|
+
/** RFC 3339 timestamp of the last status transition. Omitted when unset. */
|
|
104
|
+
timestamp?: string;
|
|
105
|
+
}
|
|
106
|
+
/** Artifact is a non-message output of a task (a file, a JSON blob, …). */
|
|
107
|
+
export interface Artifact {
|
|
108
|
+
name?: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
parts: Part[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Task is the unit of work the protocol revolves around. Clients create one
|
|
114
|
+
* with tasks/send; servers append messages and transition Status as they
|
|
115
|
+
* process it; clients poll via tasks/get until the state is terminal.
|
|
116
|
+
*/
|
|
117
|
+
export interface Task {
|
|
118
|
+
id: string;
|
|
119
|
+
sessionId?: string;
|
|
120
|
+
status: TaskStatus;
|
|
121
|
+
/** The message log: the initial user message followed by assistant/user turns. */
|
|
122
|
+
history?: TaskMessage[];
|
|
123
|
+
/** Intermediate outputs that don't belong in the message log. */
|
|
124
|
+
artifacts?: Artifact[];
|
|
125
|
+
metadata?: Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Builds a text {@link Part} from a string.
|
|
129
|
+
*
|
|
130
|
+
* @param s - The text content.
|
|
131
|
+
* @returns A part with `type` `"text"`.
|
|
132
|
+
*/
|
|
133
|
+
export declare function textPart(s: string): Part;
|
|
134
|
+
/**
|
|
135
|
+
* Builds a user-role {@link TaskMessage} carrying a single text part.
|
|
136
|
+
*
|
|
137
|
+
* @param s - The user's text.
|
|
138
|
+
* @returns A message with role `"user"`.
|
|
139
|
+
* @example
|
|
140
|
+
* client.sendTask(userText("What is the weather?"));
|
|
141
|
+
*/
|
|
142
|
+
export declare function userText(s: string): TaskMessage;
|
|
143
|
+
/**
|
|
144
|
+
* Builds an agent-role {@link TaskMessage} carrying a single text part; the
|
|
145
|
+
* agent-side counterpart of {@link userText}.
|
|
146
|
+
*
|
|
147
|
+
* @param s - The agent's text.
|
|
148
|
+
* @returns A message with role `"agent"`.
|
|
149
|
+
*/
|
|
150
|
+
export declare function agentText(s: string): TaskMessage;
|
|
151
|
+
/**
|
|
152
|
+
* Concatenates the text of every text part in a message, joined by newlines.
|
|
153
|
+
* Non-text parts are skipped.
|
|
154
|
+
*
|
|
155
|
+
* @param m - The message to flatten.
|
|
156
|
+
* @returns The combined text, or an empty string if the message has no text
|
|
157
|
+
* parts.
|
|
158
|
+
*/
|
|
159
|
+
export declare function messageText(m: TaskMessage): string;
|
|
160
|
+
/**
|
|
161
|
+
* Appends a message to a task's history, mutating the task in place. Stamps the
|
|
162
|
+
* status timestamp when it isn't set yet.
|
|
163
|
+
*
|
|
164
|
+
* @param task - The task whose history to extend.
|
|
165
|
+
* @param m - The message to append.
|
|
166
|
+
*/
|
|
167
|
+
export declare function appendMessage(task: Task, m: TaskMessage): void;
|
|
168
|
+
/**
|
|
169
|
+
* Reports whether a task state is terminal (no further work will occur).
|
|
170
|
+
*
|
|
171
|
+
* @param state - The state to test.
|
|
172
|
+
* @returns `true` for `"completed"`, `"failed"`, or `"canceled"`.
|
|
173
|
+
*/
|
|
174
|
+
export declare function isTerminalState(state: TaskState): boolean;
|
|
175
|
+
/** Base error for transport and protocol failures raised by this library. */
|
|
176
|
+
export declare class A2AError extends Error {
|
|
177
|
+
name: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Error carrying a JSON-RPC error envelope returned by a remote agent.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* try {
|
|
184
|
+
* await client.getTask("missing");
|
|
185
|
+
* } catch (e) {
|
|
186
|
+
* if (e instanceof RPCError) console.error(e.code, e.message);
|
|
187
|
+
* }
|
|
188
|
+
*/
|
|
189
|
+
export declare class RPCError extends A2AError {
|
|
190
|
+
name: string;
|
|
191
|
+
/** The JSON-RPC numeric error code. */
|
|
192
|
+
readonly code: number;
|
|
193
|
+
/** Optional implementation-defined error detail. */
|
|
194
|
+
readonly data?: unknown;
|
|
195
|
+
/**
|
|
196
|
+
* @param code - JSON-RPC error code.
|
|
197
|
+
* @param message - Human-readable error message.
|
|
198
|
+
* @param data - Optional structured error detail.
|
|
199
|
+
*/
|
|
200
|
+
constructor(code: number, message: string, data?: unknown);
|
|
201
|
+
}
|
|
202
|
+
/** JSON-RPC id: a number, string, or null. */
|
|
203
|
+
export type RPCId = number | string | null;
|
|
204
|
+
/** RPCRequest is an inbound JSON-RPC request envelope. */
|
|
205
|
+
export interface RPCRequest {
|
|
206
|
+
jsonrpc: "2.0";
|
|
207
|
+
id?: RPCId;
|
|
208
|
+
method?: string;
|
|
209
|
+
params?: unknown;
|
|
210
|
+
}
|
|
211
|
+
/** RPCErrorObject is the `error` member of a JSON-RPC response. */
|
|
212
|
+
export interface RPCErrorObject {
|
|
213
|
+
code: number;
|
|
214
|
+
message: string;
|
|
215
|
+
data?: unknown;
|
|
216
|
+
}
|
|
217
|
+
/** RPCResponse is an outbound JSON-RPC response envelope. */
|
|
218
|
+
export interface RPCResponse {
|
|
219
|
+
jsonrpc: "2.0";
|
|
220
|
+
id: RPCId;
|
|
221
|
+
result?: unknown;
|
|
222
|
+
error?: RPCErrorObject;
|
|
223
|
+
}
|
|
224
|
+
/** tasksSendParams is the params payload for `tasks/send`. */
|
|
225
|
+
export interface TasksSendParams {
|
|
226
|
+
id?: string;
|
|
227
|
+
sessionId?: string;
|
|
228
|
+
message: TaskMessage;
|
|
229
|
+
metadata?: Record<string, unknown>;
|
|
230
|
+
}
|
|
231
|
+
/** tasksGetParams is the params payload for `tasks/get`. */
|
|
232
|
+
export interface TasksGetParams {
|
|
233
|
+
id: string;
|
|
234
|
+
historyLength?: number;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe,4BAA4B,CAAC;AAEzD,yDAAyD;AACzD,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AAEtC,8DAA8D;AAC9D,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAC9C,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAG5C,0CAA0C;AAC1C,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,2CAA2C;AAC3C,eAAO,MAAM,oBAAoB,SAAS,CAAC;AAC3C,4CAA4C;AAC5C,eAAO,MAAM,kBAAkB,SAAS,CAAC;AACzC,sCAAsC;AACtC,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAEzC,0CAA0C;AAC1C,eAAO,MAAM,kBAAkB,SAAS,CAAC;AACzC,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAE7C,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IA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