@mailmodo/a2a 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +171 -93
- package/dist/{a2a_request_handler-DQfg1Q-R.d.ts → a2a_request_handler-1Isk3l-0.d.mts} +16 -4
- package/dist/{a2a_request_handler-DPkhsCMt.d.mts → a2a_request_handler-BuP9LgXH.d.ts} +16 -4
- package/dist/chunk-7JFJW6P6.mjs +38 -0
- package/dist/{chunk-LVD4GF26.mjs → chunk-AZGEDUZX.mjs} +6 -7
- package/dist/chunk-BNBEZNW7.mjs +122 -0
- package/dist/client/index.d.mts +401 -47
- package/dist/client/index.d.ts +401 -47
- package/dist/client/index.js +525 -78
- package/dist/client/index.mjs +1110 -29
- package/dist/{types-Due_Cv6t.d.mts → extensions-DvruCIzw.d.mts} +40 -1
- package/dist/{types-Due_Cv6t.d.ts → extensions-DvruCIzw.d.ts} +40 -1
- package/dist/index.d.mts +5 -33
- package/dist/index.d.ts +5 -33
- package/dist/index.js +27 -2083
- package/dist/index.mjs +6 -42
- package/dist/server/express/index.d.mts +76 -4
- package/dist/server/express/index.d.ts +76 -4
- package/dist/server/express/index.js +563 -37
- package/dist/server/express/index.mjs +642 -6
- package/dist/server/index.d.mts +296 -6
- package/dist/server/index.d.ts +296 -6
- package/dist/server/index.js +265 -52
- package/dist/server/index.mjs +1050 -12
- package/package.json +39 -17
- package/dist/auth-handler-DVLcl8yj.d.mts +0 -209
- package/dist/auth-handler-Gzpf3xHC.d.ts +0 -209
- package/dist/chunk-HZFUOBJQ.mjs +0 -198
- package/dist/chunk-LIEYEFQG.mjs +0 -879
- package/dist/chunk-UBRSFN2J.mjs +0 -776
- package/dist/error-DExKs0Q3.d.mts +0 -233
- package/dist/error-j1vYKII2.d.ts +0 -233
package/dist/chunk-HZFUOBJQ.mjs
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AGENT_CARD_PATH,
|
|
3
|
-
HTTP_EXTENSION_HEADER
|
|
4
|
-
} from "./chunk-PHP7LM4Y.mjs";
|
|
5
|
-
import {
|
|
6
|
-
A2AError,
|
|
7
|
-
JsonRpcTransportHandler,
|
|
8
|
-
ServerCallContext,
|
|
9
|
-
UnauthenticatedUser
|
|
10
|
-
} from "./chunk-LVD4GF26.mjs";
|
|
11
|
-
|
|
12
|
-
// src/server/utils.ts
|
|
13
|
-
function getCurrentTimestamp() {
|
|
14
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
15
|
-
}
|
|
16
|
-
function isObject(value) {
|
|
17
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18
|
-
}
|
|
19
|
-
function isTaskStatusUpdate(update) {
|
|
20
|
-
return isObject(update) && "state" in update && !("parts" in update);
|
|
21
|
-
}
|
|
22
|
-
function isArtifactUpdate(update) {
|
|
23
|
-
return isObject(update) && "parts" in update;
|
|
24
|
-
}
|
|
25
|
-
function getRequestedExtensions(values) {
|
|
26
|
-
if (!values) {
|
|
27
|
-
return /* @__PURE__ */ new Set();
|
|
28
|
-
}
|
|
29
|
-
return new Set(
|
|
30
|
-
values.split(",").map((ext) => ext.trim()).filter((ext) => ext.length > 0)
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/server/express/common.ts
|
|
35
|
-
var UserBuilder = {
|
|
36
|
-
NoAuthentication: () => Promise.resolve(new UnauthenticatedUser())
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/server/express/a2a_express_app.ts
|
|
40
|
-
import express3 from "express";
|
|
41
|
-
|
|
42
|
-
// src/server/express/json_rpc_handler.ts
|
|
43
|
-
import express from "express";
|
|
44
|
-
function jsonRpcHandler(options) {
|
|
45
|
-
const jsonRpcTransportHandler = new JsonRpcTransportHandler(options.requestHandler);
|
|
46
|
-
const router = express.Router();
|
|
47
|
-
router.use(express.json(), jsonErrorHandler);
|
|
48
|
-
router.post("/", async (req, res) => {
|
|
49
|
-
try {
|
|
50
|
-
const user = await options.userBuilder(req);
|
|
51
|
-
const context = new ServerCallContext(
|
|
52
|
-
getRequestedExtensions(req.header(HTTP_EXTENSION_HEADER)),
|
|
53
|
-
user ?? new UnauthenticatedUser()
|
|
54
|
-
);
|
|
55
|
-
const rpcResponseOrStream = await jsonRpcTransportHandler.handle(req.body, context);
|
|
56
|
-
if (context.activatedExtensions) {
|
|
57
|
-
res.setHeader(HTTP_EXTENSION_HEADER, Array.from(context.activatedExtensions));
|
|
58
|
-
}
|
|
59
|
-
if (typeof rpcResponseOrStream?.[Symbol.asyncIterator] === "function") {
|
|
60
|
-
const stream = rpcResponseOrStream;
|
|
61
|
-
res.setHeader("Content-Type", "text/event-stream");
|
|
62
|
-
res.setHeader("Cache-Control", "no-cache");
|
|
63
|
-
res.setHeader("Connection", "keep-alive");
|
|
64
|
-
res.flushHeaders();
|
|
65
|
-
try {
|
|
66
|
-
for await (const event of stream) {
|
|
67
|
-
res.write(`id: ${(/* @__PURE__ */ new Date()).getTime()}
|
|
68
|
-
`);
|
|
69
|
-
res.write(`data: ${JSON.stringify(event)}
|
|
70
|
-
|
|
71
|
-
`);
|
|
72
|
-
}
|
|
73
|
-
} catch (streamError) {
|
|
74
|
-
console.error(`Error during SSE streaming (request ${req.body?.id}):`, streamError);
|
|
75
|
-
let a2aError;
|
|
76
|
-
if (streamError instanceof A2AError) {
|
|
77
|
-
a2aError = streamError;
|
|
78
|
-
} else {
|
|
79
|
-
a2aError = A2AError.internalError(
|
|
80
|
-
streamError instanceof Error && streamError.message || "Streaming error."
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
const errorResponse = {
|
|
84
|
-
jsonrpc: "2.0",
|
|
85
|
-
id: req.body?.id || null,
|
|
86
|
-
// Use original request ID if available
|
|
87
|
-
error: a2aError.toJSONRPCError()
|
|
88
|
-
};
|
|
89
|
-
if (!res.headersSent) {
|
|
90
|
-
res.status(500).json(errorResponse);
|
|
91
|
-
} else {
|
|
92
|
-
res.write(`id: ${(/* @__PURE__ */ new Date()).getTime()}
|
|
93
|
-
`);
|
|
94
|
-
res.write(`event: error
|
|
95
|
-
`);
|
|
96
|
-
res.write(`data: ${JSON.stringify(errorResponse)}
|
|
97
|
-
|
|
98
|
-
`);
|
|
99
|
-
}
|
|
100
|
-
} finally {
|
|
101
|
-
if (!res.writableEnded) {
|
|
102
|
-
res.end();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
const rpcResponse = rpcResponseOrStream;
|
|
107
|
-
res.status(200).json(rpcResponse);
|
|
108
|
-
}
|
|
109
|
-
} catch (error) {
|
|
110
|
-
console.error("Unhandled error in JSON-RPC POST handler:", error);
|
|
111
|
-
const a2aError = error instanceof A2AError ? error : A2AError.internalError("General processing error.");
|
|
112
|
-
const errorResponse = {
|
|
113
|
-
jsonrpc: "2.0",
|
|
114
|
-
id: req.body?.id || null,
|
|
115
|
-
error: a2aError.toJSONRPCError()
|
|
116
|
-
};
|
|
117
|
-
if (!res.headersSent) {
|
|
118
|
-
res.status(500).json(errorResponse);
|
|
119
|
-
} else if (!res.writableEnded) {
|
|
120
|
-
res.end();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
return router;
|
|
125
|
-
}
|
|
126
|
-
var jsonErrorHandler = (err, _req, res, next) => {
|
|
127
|
-
if (err instanceof SyntaxError && "body" in err) {
|
|
128
|
-
const a2aError = A2AError.parseError("Invalid JSON payload.");
|
|
129
|
-
const errorResponse = {
|
|
130
|
-
jsonrpc: "2.0",
|
|
131
|
-
id: null,
|
|
132
|
-
error: a2aError.toJSONRPCError()
|
|
133
|
-
};
|
|
134
|
-
return res.status(400).json(errorResponse);
|
|
135
|
-
}
|
|
136
|
-
next(err);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// src/server/express/agent_card_handler.ts
|
|
140
|
-
import express2 from "express";
|
|
141
|
-
function agentCardHandler(options) {
|
|
142
|
-
const router = express2.Router();
|
|
143
|
-
const provider = typeof options.agentCardProvider === "function" ? options.agentCardProvider : options.agentCardProvider.getAgentCard.bind(options.agentCardProvider);
|
|
144
|
-
router.get("/", async (_req, res) => {
|
|
145
|
-
try {
|
|
146
|
-
const agentCard = await provider();
|
|
147
|
-
res.json(agentCard);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
console.error("Error fetching agent card:", error);
|
|
150
|
-
res.status(500).json({ error: "Failed to retrieve agent card" });
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
return router;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// src/server/express/a2a_express_app.ts
|
|
157
|
-
var A2AExpressApp = class {
|
|
158
|
-
requestHandler;
|
|
159
|
-
userBuilder;
|
|
160
|
-
constructor(requestHandler, userBuilder = UserBuilder.NoAuthentication) {
|
|
161
|
-
this.requestHandler = requestHandler;
|
|
162
|
-
this.userBuilder = userBuilder;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Adds A2A routes to an existing Express app.
|
|
166
|
-
* @param app Optional existing Express app.
|
|
167
|
-
* @param baseUrl The base URL for A2A endpoints (e.g., "/a2a/api").
|
|
168
|
-
* @param middlewares Optional array of Express middlewares to apply to the A2A routes.
|
|
169
|
-
* @param agentCardPath Optional custom path for the agent card endpoint (defaults to .well-known/agent-card.json).
|
|
170
|
-
* @returns The Express app with A2A routes.
|
|
171
|
-
*/
|
|
172
|
-
setupRoutes(app, baseUrl = "", middlewares, agentCardPath = AGENT_CARD_PATH) {
|
|
173
|
-
const router = express3.Router();
|
|
174
|
-
router.use(express3.json(), jsonErrorHandler);
|
|
175
|
-
if (middlewares && middlewares.length > 0) {
|
|
176
|
-
router.use(middlewares);
|
|
177
|
-
}
|
|
178
|
-
router.use(
|
|
179
|
-
jsonRpcHandler({
|
|
180
|
-
requestHandler: this.requestHandler,
|
|
181
|
-
userBuilder: this.userBuilder
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
router.use(`/${agentCardPath}`, agentCardHandler({ agentCardProvider: this.requestHandler }));
|
|
185
|
-
app.use(baseUrl, router);
|
|
186
|
-
return app;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
export {
|
|
191
|
-
getCurrentTimestamp,
|
|
192
|
-
isObject,
|
|
193
|
-
isTaskStatusUpdate,
|
|
194
|
-
isArtifactUpdate,
|
|
195
|
-
getRequestedExtensions,
|
|
196
|
-
UserBuilder,
|
|
197
|
-
A2AExpressApp
|
|
198
|
-
};
|