@dexto/server 1.6.20 → 1.6.22
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/a2a/jsonrpc/methods.cjs +1 -1
- package/dist/a2a/jsonrpc/methods.d.ts +14 -4
- package/dist/a2a/jsonrpc/methods.d.ts.map +1 -1
- package/dist/a2a/jsonrpc/methods.js +1 -1
- package/dist/approval/wire-approval-events.cjs +44 -0
- package/dist/approval/wire-approval-events.d.ts +4 -0
- package/dist/approval/wire-approval-events.d.ts.map +1 -0
- package/dist/approval/wire-approval-events.js +20 -0
- package/dist/events/session-sse-subscriber.cjs +167 -0
- package/dist/events/session-sse-subscriber.d.ts +13 -0
- package/dist/events/session-sse-subscriber.d.ts.map +1 -0
- package/dist/events/session-sse-subscriber.js +143 -0
- package/dist/hono/__tests__/test-fixtures.cjs +8 -0
- package/dist/hono/__tests__/test-fixtures.d.ts +1 -0
- package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -1
- package/dist/hono/__tests__/test-fixtures.js +8 -0
- package/dist/hono/index.cjs +40 -8
- package/dist/hono/index.d.ts +45 -4531
- package/dist/hono/index.d.ts.map +1 -1
- package/dist/hono/index.js +43 -9
- package/dist/hono/node/index.cjs +51 -6
- package/dist/hono/node/index.d.ts.map +1 -1
- package/dist/hono/node/index.js +51 -6
- package/dist/hono/routes/a2a-jsonrpc.d.ts.map +1 -1
- package/dist/hono/routes/a2a-tasks.cjs +158 -32
- package/dist/hono/routes/a2a-tasks.d.ts +1 -502
- package/dist/hono/routes/a2a-tasks.d.ts.map +1 -1
- package/dist/hono/routes/a2a-tasks.js +162 -32
- package/dist/hono/routes/a2a.d.ts.map +1 -1
- package/dist/hono/routes/agents.cjs +410 -329
- package/dist/hono/routes/agents.d.ts +16043 -68
- package/dist/hono/routes/agents.d.ts.map +1 -1
- package/dist/hono/routes/agents.js +418 -330
- package/dist/hono/routes/approvals.cjs +102 -88
- package/dist/hono/routes/approvals.d.ts +2089 -142
- package/dist/hono/routes/approvals.d.ts.map +1 -1
- package/dist/hono/routes/approvals.js +108 -89
- package/dist/hono/routes/dexto-auth.cjs +40 -33
- package/dist/hono/routes/dexto-auth.d.ts +401 -2
- package/dist/hono/routes/dexto-auth.d.ts.map +1 -1
- package/dist/hono/routes/dexto-auth.js +40 -33
- package/dist/hono/routes/discovery.cjs +16 -14
- package/dist/hono/routes/discovery.d.ts +586 -1
- package/dist/hono/routes/discovery.d.ts.map +1 -1
- package/dist/hono/routes/discovery.js +16 -14
- package/dist/hono/routes/greeting.cjs +26 -22
- package/dist/hono/routes/greeting.d.ts +787 -3
- package/dist/hono/routes/greeting.d.ts.map +1 -1
- package/dist/hono/routes/greeting.js +26 -22
- package/dist/hono/routes/health.d.ts +1 -1
- package/dist/hono/routes/key.cjs +60 -52
- package/dist/hono/routes/key.d.ts +1597 -1
- package/dist/hono/routes/key.d.ts.map +1 -1
- package/dist/hono/routes/key.js +60 -52
- package/dist/hono/routes/llm.cjs +382 -349
- package/dist/hono/routes/llm.d.ts +12148 -98
- package/dist/hono/routes/llm.d.ts.map +1 -1
- package/dist/hono/routes/llm.js +386 -349
- package/dist/hono/routes/mcp.cjs +257 -226
- package/dist/hono/routes/mcp.d.ts +6605 -309
- package/dist/hono/routes/mcp.d.ts.map +1 -1
- package/dist/hono/routes/mcp.js +263 -225
- package/dist/hono/routes/memory.cjs +102 -89
- package/dist/hono/routes/memory.d.ts +5368 -4
- package/dist/hono/routes/memory.d.ts.map +1 -1
- package/dist/hono/routes/memory.js +108 -90
- package/dist/hono/routes/messages.cjs +189 -191
- package/dist/hono/routes/messages.d.ts +3900 -12
- package/dist/hono/routes/messages.d.ts.map +1 -1
- package/dist/hono/routes/messages.js +192 -191
- package/dist/hono/routes/models.cjs +106 -64
- package/dist/hono/routes/models.d.ts +2875 -2
- package/dist/hono/routes/models.d.ts.map +1 -1
- package/dist/hono/routes/models.js +108 -64
- package/dist/hono/routes/openrouter.cjs +79 -65
- package/dist/hono/routes/openrouter.d.ts +854 -1
- package/dist/hono/routes/openrouter.d.ts.map +1 -1
- package/dist/hono/routes/openrouter.js +79 -65
- package/dist/hono/routes/prompts.cjs +136 -109
- package/dist/hono/routes/prompts.d.ts +2818 -10
- package/dist/hono/routes/prompts.d.ts.map +1 -1
- package/dist/hono/routes/prompts.js +138 -109
- package/dist/hono/routes/queue.cjs +133 -120
- package/dist/hono/routes/queue.d.ts +5240 -11
- package/dist/hono/routes/queue.d.ts.map +1 -1
- package/dist/hono/routes/queue.js +136 -120
- package/dist/hono/routes/resources.cjs +65 -46
- package/dist/hono/routes/resources.d.ts +1983 -5
- package/dist/hono/routes/resources.d.ts.map +1 -1
- package/dist/hono/routes/resources.js +72 -47
- package/dist/hono/routes/schedules.cjs +233 -226
- package/dist/hono/routes/schedules.d.ts +4198 -22
- package/dist/hono/routes/schedules.d.ts.map +1 -1
- package/dist/hono/routes/schedules.js +233 -226
- package/dist/hono/routes/search.cjs +34 -30
- package/dist/hono/routes/search.d.ts +3094 -17
- package/dist/hono/routes/search.d.ts.map +1 -1
- package/dist/hono/routes/search.js +40 -31
- package/dist/hono/routes/sessions.cjs +491 -393
- package/dist/hono/routes/sessions.d.ts +18263 -65
- package/dist/hono/routes/sessions.d.ts.map +1 -1
- package/dist/hono/routes/sessions.js +497 -395
- package/dist/hono/routes/static.d.ts.map +1 -1
- package/dist/hono/routes/system-prompt.cjs +57 -61
- package/dist/hono/routes/system-prompt.d.ts +1228 -2
- package/dist/hono/routes/system-prompt.d.ts.map +1 -1
- package/dist/hono/routes/system-prompt.js +58 -62
- package/dist/hono/routes/tools.cjs +29 -34
- package/dist/hono/routes/tools.d.ts +1755 -6
- package/dist/hono/routes/tools.d.ts.map +1 -1
- package/dist/hono/routes/tools.js +33 -33
- package/dist/hono/routes/webhooks.cjs +115 -123
- package/dist/hono/routes/webhooks.d.ts +2501 -11
- package/dist/hono/routes/webhooks.d.ts.map +1 -1
- package/dist/hono/routes/webhooks.js +120 -124
- package/dist/hono/routes/workspaces.cjs +84 -79
- package/dist/hono/routes/workspaces.d.ts +2093 -2
- package/dist/hono/routes/workspaces.d.ts.map +1 -1
- package/dist/hono/routes/workspaces.js +89 -80
- package/dist/hono/schemas/responses.cjs +463 -260
- package/dist/hono/schemas/responses.d.ts +1893 -209
- package/dist/hono/schemas/responses.d.ts.map +1 -1
- package/dist/hono/schemas/responses.js +203 -14
- package/dist/hono/start-server.cjs +9 -0
- package/dist/hono/start-server.d.ts.map +1 -1
- package/dist/hono/start-server.js +9 -0
- package/dist/hono/types.d.ts +11 -0
- package/dist/hono/types.d.ts.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/package.json +7 -7
package/dist/hono/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hono/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hono/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAA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ACpB,oBAAoB,GACpB,eAAe,GACf,oBAAoB,GACpB,kBAAkB,CAAC;AAEzB,KAAK,uBAAuB,GACtB,eAAe,GACf,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,kBAAkB,GAClB,sBAAsB,GACtB,qBAAqB,CAAC;AAE5B,KAAK,sBAAsB,GAAG,qBAAqB,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;AAE7F,KAAK,kBAAkB,GACjB,sBAAsB,GACtB,eAAe,GACf,iBAAiB,GACjB,qBAAqB,GACrB,kBAAkB,GAClB,wBAAwB,GACxB,qBAAqB,CAAC;AAE5B,KAAK,sBAAsB,GACrB,wBAAwB,GACxB,uBAAuB,GACvB,sBAAsB,GACtB,kBAAkB,CAAC;AAEzB,KAAK,gBAAgB,GAAG,eAAe,CAAC,sBAAsB,EAAE,OAAO,kBAAkB,CAAC,CAAC;AAM3F,KAAK,eAAe,GAAG,YAAY,GAAG,eAAe,GAAG,aAAa,CAAC;AACtE,KAAK,SAAS,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAEpD,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,QAAQ,CAoOvE;AAED,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;AAGrD,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/hono/index.js
CHANGED
|
@@ -17,7 +17,9 @@ import { createResourcesRouter } from "./routes/resources.js";
|
|
|
17
17
|
import { createMemoryRouter } from "./routes/memory.js";
|
|
18
18
|
import { createWorkspacesRouter } from "./routes/workspaces.js";
|
|
19
19
|
import { createSchedulesRouter } from "./routes/schedules.js";
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
createAgentsRouter
|
|
22
|
+
} from "./routes/agents.js";
|
|
21
23
|
import { createApprovalsRouter } from "./routes/approvals.js";
|
|
22
24
|
import { createQueueRouter } from "./routes/queue.js";
|
|
23
25
|
import { createOpenRouterRouter } from "./routes/openrouter.js";
|
|
@@ -93,6 +95,7 @@ function createDextoApp(options) {
|
|
|
93
95
|
approvalCoordinator,
|
|
94
96
|
webhookSubscriber,
|
|
95
97
|
sseSubscriber,
|
|
98
|
+
sessionSseSubscriber,
|
|
96
99
|
agentsContext,
|
|
97
100
|
webRoot,
|
|
98
101
|
webUIConfig,
|
|
@@ -116,14 +119,45 @@ function createDextoApp(options) {
|
|
|
116
119
|
app.use(middlewarePattern, redactionMiddleware);
|
|
117
120
|
const routePrefix = normalizedPrefix;
|
|
118
121
|
const resolvedGetAgentConfigPath = getAgentConfigPath ?? ((_ctx) => void 0);
|
|
119
|
-
const fullApp = app
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
)
|
|
126
|
-
|
|
122
|
+
const fullApp = app;
|
|
123
|
+
const mountedRouters = [
|
|
124
|
+
["/health", createHealthRouter(getAgent)],
|
|
125
|
+
["/", createA2aRouter(getAgentCard)],
|
|
126
|
+
["/", createA2AJsonRpcRouter(getAgent, sseSubscriber)],
|
|
127
|
+
["/", createA2ATasksRouter(getAgent, sseSubscriber)],
|
|
128
|
+
[routePrefix, createGreetingRouter(getAgent)],
|
|
129
|
+
[routePrefix, createMessagesRouter(getAgent, approvalCoordinator)],
|
|
130
|
+
[routePrefix, createLlmRouter(getAgent)],
|
|
131
|
+
[routePrefix, createSessionsRouter(getAgent, sessionSseSubscriber)],
|
|
132
|
+
[routePrefix, createSearchRouter(getAgent)],
|
|
133
|
+
[routePrefix, createMcpRouter(getAgent, resolvedGetAgentConfigPath)],
|
|
134
|
+
[routePrefix, createWebhooksRouter(getAgent, webhookSubscriber)],
|
|
135
|
+
[routePrefix, createPromptsRouter(getAgent)],
|
|
136
|
+
[routePrefix, createResourcesRouter(getAgent)],
|
|
137
|
+
[routePrefix, createMemoryRouter(getAgent)],
|
|
138
|
+
[routePrefix, createWorkspacesRouter(getAgent)],
|
|
139
|
+
[routePrefix, createSchedulesRouter(getAgent)],
|
|
140
|
+
[routePrefix, createApprovalsRouter(getAgent, approvalCoordinator)],
|
|
141
|
+
[
|
|
142
|
+
routePrefix,
|
|
143
|
+
createAgentsRouter(
|
|
144
|
+
getAgent,
|
|
145
|
+
agentsContext || dummyAgentsContext,
|
|
146
|
+
resolvedGetAgentConfigPath
|
|
147
|
+
)
|
|
148
|
+
],
|
|
149
|
+
[routePrefix, createQueueRouter(getAgent)],
|
|
150
|
+
[routePrefix, createOpenRouterRouter()],
|
|
151
|
+
[routePrefix, createKeyRouter()],
|
|
152
|
+
[routePrefix, createToolsRouter(getAgent)],
|
|
153
|
+
[routePrefix, createDiscoveryRouter(resolvedGetAgentConfigPath)],
|
|
154
|
+
[routePrefix, createModelsRouter()],
|
|
155
|
+
[routePrefix, createSystemPromptRouter(getAgent)],
|
|
156
|
+
[routePrefix, createDextoAuthRouter(getAgent)]
|
|
157
|
+
];
|
|
158
|
+
for (const [path, router] of mountedRouters) {
|
|
159
|
+
fullApp.route(path, router);
|
|
160
|
+
}
|
|
127
161
|
fullApp.doc("/openapi.json", {
|
|
128
162
|
openapi: "3.0.0",
|
|
129
163
|
info: {
|
package/dist/hono/node/index.cjs
CHANGED
|
@@ -28,6 +28,12 @@ function createNodeServer(app, options) {
|
|
|
28
28
|
const { getAgent: _getAgent } = options;
|
|
29
29
|
const webhookSubscriber = app.webhookSubscriber;
|
|
30
30
|
const server = (0, import_node_http.createServer)(async (req, res) => {
|
|
31
|
+
const disconnectController = new AbortController();
|
|
32
|
+
const abortOnDisconnect = () => {
|
|
33
|
+
disconnectController.abort();
|
|
34
|
+
};
|
|
35
|
+
req.on("aborted", abortOnDisconnect);
|
|
36
|
+
res.on("close", abortOnDisconnect);
|
|
31
37
|
try {
|
|
32
38
|
if (options.mcpHandlers && req.url?.startsWith("/mcp")) {
|
|
33
39
|
if (req.method === "GET") {
|
|
@@ -64,14 +70,17 @@ function createNodeServer(app, options) {
|
|
|
64
70
|
return;
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
|
-
const request = await toRequest(req);
|
|
73
|
+
const request = await toRequest(req, disconnectController.signal);
|
|
68
74
|
const response = await app.fetch(request);
|
|
69
|
-
await sendNodeResponse(res, response);
|
|
75
|
+
await sendNodeResponse(res, response, disconnectController.signal);
|
|
70
76
|
} catch (error) {
|
|
71
77
|
const message = error instanceof Error ? error.message : String(error);
|
|
72
78
|
import_core.logger.error(`Unhandled error in Node bridge: ${message}`, { error });
|
|
73
79
|
res.statusCode = 500;
|
|
74
80
|
res.end("Internal Server Error");
|
|
81
|
+
} finally {
|
|
82
|
+
req.off("aborted", abortOnDisconnect);
|
|
83
|
+
res.off("close", abortOnDisconnect);
|
|
75
84
|
}
|
|
76
85
|
});
|
|
77
86
|
server.on("close", () => {
|
|
@@ -91,7 +100,7 @@ function createNodeServer(app, options) {
|
|
|
91
100
|
}
|
|
92
101
|
return result;
|
|
93
102
|
}
|
|
94
|
-
async function toRequest(req) {
|
|
103
|
+
async function toRequest(req, signal) {
|
|
95
104
|
const protocol = req.socket?.encrypted ? "https" : "http";
|
|
96
105
|
const host = req.headers.host ?? "localhost";
|
|
97
106
|
const url = new URL(req.url ?? "/", `${protocol}://${host}`);
|
|
@@ -110,10 +119,11 @@ async function toRequest(req) {
|
|
|
110
119
|
method,
|
|
111
120
|
headers,
|
|
112
121
|
body: body ?? void 0,
|
|
122
|
+
signal,
|
|
113
123
|
duplex: body ? "half" : void 0
|
|
114
124
|
});
|
|
115
125
|
}
|
|
116
|
-
async function sendNodeResponse(res, response) {
|
|
126
|
+
async function sendNodeResponse(res, response, signal) {
|
|
117
127
|
res.statusCode = response.status;
|
|
118
128
|
response.headers.forEach((value, key) => {
|
|
119
129
|
if (key.toLowerCase() === "content-length") {
|
|
@@ -128,8 +138,43 @@ async function sendNodeResponse(res, response) {
|
|
|
128
138
|
const webStream = response.body;
|
|
129
139
|
const readable = import_node_stream.Readable.fromWeb(webStream);
|
|
130
140
|
await new Promise((resolve, reject) => {
|
|
131
|
-
|
|
132
|
-
|
|
141
|
+
let settled = false;
|
|
142
|
+
const settle = (callback) => {
|
|
143
|
+
if (settled) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
settled = true;
|
|
147
|
+
cleanup();
|
|
148
|
+
callback();
|
|
149
|
+
};
|
|
150
|
+
const cleanup = () => {
|
|
151
|
+
readable.off("error", handleError);
|
|
152
|
+
readable.off("close", handleReadableClose);
|
|
153
|
+
res.off("finish", handleFinish);
|
|
154
|
+
res.off("close", handleClose);
|
|
155
|
+
signal.removeEventListener("abort", handleAbort);
|
|
156
|
+
};
|
|
157
|
+
const handleError = (error) => {
|
|
158
|
+
settle(() => reject(error));
|
|
159
|
+
};
|
|
160
|
+
const handleReadableClose = () => {
|
|
161
|
+
settle(resolve);
|
|
162
|
+
};
|
|
163
|
+
const handleFinish = () => {
|
|
164
|
+
settle(resolve);
|
|
165
|
+
};
|
|
166
|
+
const handleAbort = () => {
|
|
167
|
+
readable.destroy();
|
|
168
|
+
};
|
|
169
|
+
const handleClose = () => {
|
|
170
|
+
readable.destroy();
|
|
171
|
+
settle(resolve);
|
|
172
|
+
};
|
|
173
|
+
readable.on("error", handleError);
|
|
174
|
+
readable.on("close", handleReadableClose);
|
|
175
|
+
res.on("finish", handleFinish);
|
|
176
|
+
res.on("close", handleClose);
|
|
177
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
133
178
|
readable.pipe(res);
|
|
134
179
|
});
|
|
135
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hono/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAGpF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC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;IAClB,WAAW,CAAC,EAAE;QACV,UAAU,EAAE,CACR,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,OAAO,KACZ,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAC1B,SAAS,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;KAClF,GAAG,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC3B,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;IACxC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;CAC9C,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAoF5F"}
|
package/dist/hono/node/index.js
CHANGED
|
@@ -5,6 +5,12 @@ function createNodeServer(app, options) {
|
|
|
5
5
|
const { getAgent: _getAgent } = options;
|
|
6
6
|
const webhookSubscriber = app.webhookSubscriber;
|
|
7
7
|
const server = createServer(async (req, res) => {
|
|
8
|
+
const disconnectController = new AbortController();
|
|
9
|
+
const abortOnDisconnect = () => {
|
|
10
|
+
disconnectController.abort();
|
|
11
|
+
};
|
|
12
|
+
req.on("aborted", abortOnDisconnect);
|
|
13
|
+
res.on("close", abortOnDisconnect);
|
|
8
14
|
try {
|
|
9
15
|
if (options.mcpHandlers && req.url?.startsWith("/mcp")) {
|
|
10
16
|
if (req.method === "GET") {
|
|
@@ -41,14 +47,17 @@ function createNodeServer(app, options) {
|
|
|
41
47
|
return;
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
|
-
const request = await toRequest(req);
|
|
50
|
+
const request = await toRequest(req, disconnectController.signal);
|
|
45
51
|
const response = await app.fetch(request);
|
|
46
|
-
await sendNodeResponse(res, response);
|
|
52
|
+
await sendNodeResponse(res, response, disconnectController.signal);
|
|
47
53
|
} catch (error) {
|
|
48
54
|
const message = error instanceof Error ? error.message : String(error);
|
|
49
55
|
logger.error(`Unhandled error in Node bridge: ${message}`, { error });
|
|
50
56
|
res.statusCode = 500;
|
|
51
57
|
res.end("Internal Server Error");
|
|
58
|
+
} finally {
|
|
59
|
+
req.off("aborted", abortOnDisconnect);
|
|
60
|
+
res.off("close", abortOnDisconnect);
|
|
52
61
|
}
|
|
53
62
|
});
|
|
54
63
|
server.on("close", () => {
|
|
@@ -68,7 +77,7 @@ function createNodeServer(app, options) {
|
|
|
68
77
|
}
|
|
69
78
|
return result;
|
|
70
79
|
}
|
|
71
|
-
async function toRequest(req) {
|
|
80
|
+
async function toRequest(req, signal) {
|
|
72
81
|
const protocol = req.socket?.encrypted ? "https" : "http";
|
|
73
82
|
const host = req.headers.host ?? "localhost";
|
|
74
83
|
const url = new URL(req.url ?? "/", `${protocol}://${host}`);
|
|
@@ -87,10 +96,11 @@ async function toRequest(req) {
|
|
|
87
96
|
method,
|
|
88
97
|
headers,
|
|
89
98
|
body: body ?? void 0,
|
|
99
|
+
signal,
|
|
90
100
|
duplex: body ? "half" : void 0
|
|
91
101
|
});
|
|
92
102
|
}
|
|
93
|
-
async function sendNodeResponse(res, response) {
|
|
103
|
+
async function sendNodeResponse(res, response, signal) {
|
|
94
104
|
res.statusCode = response.status;
|
|
95
105
|
response.headers.forEach((value, key) => {
|
|
96
106
|
if (key.toLowerCase() === "content-length") {
|
|
@@ -105,8 +115,43 @@ async function sendNodeResponse(res, response) {
|
|
|
105
115
|
const webStream = response.body;
|
|
106
116
|
const readable = Readable.fromWeb(webStream);
|
|
107
117
|
await new Promise((resolve, reject) => {
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
let settled = false;
|
|
119
|
+
const settle = (callback) => {
|
|
120
|
+
if (settled) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
settled = true;
|
|
124
|
+
cleanup();
|
|
125
|
+
callback();
|
|
126
|
+
};
|
|
127
|
+
const cleanup = () => {
|
|
128
|
+
readable.off("error", handleError);
|
|
129
|
+
readable.off("close", handleReadableClose);
|
|
130
|
+
res.off("finish", handleFinish);
|
|
131
|
+
res.off("close", handleClose);
|
|
132
|
+
signal.removeEventListener("abort", handleAbort);
|
|
133
|
+
};
|
|
134
|
+
const handleError = (error) => {
|
|
135
|
+
settle(() => reject(error));
|
|
136
|
+
};
|
|
137
|
+
const handleReadableClose = () => {
|
|
138
|
+
settle(resolve);
|
|
139
|
+
};
|
|
140
|
+
const handleFinish = () => {
|
|
141
|
+
settle(resolve);
|
|
142
|
+
};
|
|
143
|
+
const handleAbort = () => {
|
|
144
|
+
readable.destroy();
|
|
145
|
+
};
|
|
146
|
+
const handleClose = () => {
|
|
147
|
+
readable.destroy();
|
|
148
|
+
settle(resolve);
|
|
149
|
+
};
|
|
150
|
+
readable.on("error", handleError);
|
|
151
|
+
readable.on("close", handleReadableClose);
|
|
152
|
+
res.on("finish", handleFinish);
|
|
153
|
+
res.on("close", handleClose);
|
|
154
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
110
155
|
readable.pipe(res);
|
|
111
156
|
});
|
|
112
157
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2a-jsonrpc.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/a2a-jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAEhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"a2a-jsonrpc.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/a2a-jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAEhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,qBAAqB,8EA4HhG"}
|
|
@@ -25,11 +25,15 @@ var import_zod_openapi = require("@hono/zod-openapi");
|
|
|
25
25
|
var import_methods = require("../../a2a/jsonrpc/methods.js");
|
|
26
26
|
var import_core = require("@dexto/core");
|
|
27
27
|
var import_message = require("../../a2a/adapters/message.js");
|
|
28
|
+
var import_responses = require("../schemas/responses.js");
|
|
29
|
+
function mountA2ATasksSubrouter(app, router) {
|
|
30
|
+
app.route("/", router);
|
|
31
|
+
}
|
|
28
32
|
const PartSchema = import_zod_openapi.z.discriminatedUnion("kind", [
|
|
29
33
|
import_zod_openapi.z.object({
|
|
30
34
|
kind: import_zod_openapi.z.literal("text").describe("Part type discriminator"),
|
|
31
35
|
text: import_zod_openapi.z.string().describe("Text content"),
|
|
32
|
-
metadata:
|
|
36
|
+
metadata: import_responses.JsonObjectSchema.optional().describe("Extension metadata")
|
|
33
37
|
}),
|
|
34
38
|
import_zod_openapi.z.object({
|
|
35
39
|
kind: import_zod_openapi.z.literal("file").describe("Part type discriminator"),
|
|
@@ -45,12 +49,12 @@ const PartSchema = import_zod_openapi.z.discriminatedUnion("kind", [
|
|
|
45
49
|
mimeType: import_zod_openapi.z.string().optional().describe("MIME type")
|
|
46
50
|
})
|
|
47
51
|
]).describe("File data (bytes or URI)"),
|
|
48
|
-
metadata:
|
|
52
|
+
metadata: import_responses.JsonObjectSchema.optional().describe("Extension metadata")
|
|
49
53
|
}),
|
|
50
54
|
import_zod_openapi.z.object({
|
|
51
55
|
kind: import_zod_openapi.z.literal("data").describe("Part type discriminator"),
|
|
52
|
-
data:
|
|
53
|
-
metadata:
|
|
56
|
+
data: import_responses.JsonObjectSchema.describe("Structured JSON data"),
|
|
57
|
+
metadata: import_responses.JsonObjectSchema.optional().describe("Extension metadata")
|
|
54
58
|
})
|
|
55
59
|
]).describe("Message part (text, file, or data)");
|
|
56
60
|
const MessageSchema = import_zod_openapi.z.object({
|
|
@@ -59,7 +63,7 @@ const MessageSchema = import_zod_openapi.z.object({
|
|
|
59
63
|
messageId: import_zod_openapi.z.string().describe("Unique message identifier"),
|
|
60
64
|
taskId: import_zod_openapi.z.string().optional().describe("Associated task ID"),
|
|
61
65
|
contextId: import_zod_openapi.z.string().optional().describe("Context identifier"),
|
|
62
|
-
metadata:
|
|
66
|
+
metadata: import_responses.JsonObjectSchema.optional().describe("Extension metadata"),
|
|
63
67
|
extensions: import_zod_openapi.z.array(import_zod_openapi.z.string()).optional().describe("Extension identifiers"),
|
|
64
68
|
referenceTaskIds: import_zod_openapi.z.array(import_zod_openapi.z.string()).optional().describe("Referenced task IDs"),
|
|
65
69
|
kind: import_zod_openapi.z.literal("message").describe("Object type discriminator")
|
|
@@ -79,18 +83,114 @@ const TaskStatusSchema = import_zod_openapi.z.object({
|
|
|
79
83
|
message: MessageSchema.optional().describe("Status message"),
|
|
80
84
|
timestamp: import_zod_openapi.z.string().optional().describe("ISO 8601 timestamp")
|
|
81
85
|
}).describe("Task status");
|
|
86
|
+
const ArtifactSchema = import_zod_openapi.z.object({
|
|
87
|
+
artifactId: import_zod_openapi.z.string().describe("Unique artifact ID"),
|
|
88
|
+
name: import_zod_openapi.z.string().optional().describe("Artifact name"),
|
|
89
|
+
description: import_zod_openapi.z.string().optional().describe("Artifact description"),
|
|
90
|
+
parts: import_zod_openapi.z.array(PartSchema).describe("Artifact content parts"),
|
|
91
|
+
metadata: import_responses.JsonObjectSchema.optional().describe("Extension metadata"),
|
|
92
|
+
extensions: import_zod_openapi.z.array(import_zod_openapi.z.string()).optional().describe("Extension identifiers")
|
|
93
|
+
}).describe("A2A protocol artifact");
|
|
82
94
|
const TaskSchema = import_zod_openapi.z.object({
|
|
83
95
|
id: import_zod_openapi.z.string().describe("Unique task identifier"),
|
|
84
96
|
contextId: import_zod_openapi.z.string().describe("Context identifier across related tasks"),
|
|
85
97
|
status: TaskStatusSchema.describe("Current task status"),
|
|
86
98
|
history: import_zod_openapi.z.array(MessageSchema).optional().describe("Conversation history"),
|
|
87
|
-
artifacts: import_zod_openapi.z.array(
|
|
88
|
-
metadata:
|
|
99
|
+
artifacts: import_zod_openapi.z.array(ArtifactSchema).optional().describe("Task artifacts"),
|
|
100
|
+
metadata: import_responses.JsonObjectSchema.optional().describe("Extension metadata"),
|
|
89
101
|
kind: import_zod_openapi.z.literal("task").describe("Object type discriminator")
|
|
90
102
|
}).describe("A2A Protocol task");
|
|
103
|
+
const TasksListResponseSchema = import_zod_openapi.z.object({
|
|
104
|
+
tasks: import_zod_openapi.z.array(TaskSchema).describe("Array of tasks"),
|
|
105
|
+
totalSize: import_zod_openapi.z.number().describe("Total number of tasks"),
|
|
106
|
+
pageSize: import_zod_openapi.z.number().describe("Number of tasks in this page"),
|
|
107
|
+
nextPageToken: import_zod_openapi.z.string().describe("Token for next page")
|
|
108
|
+
}).describe("Response body for tasks/list");
|
|
91
109
|
const TaskErrorResponseSchema = import_zod_openapi.z.object({
|
|
92
110
|
error: import_zod_openapi.z.string().describe("Task error message")
|
|
93
111
|
}).strict().describe("A2A task error response");
|
|
112
|
+
function toA2APart(part) {
|
|
113
|
+
switch (part.kind) {
|
|
114
|
+
case "text":
|
|
115
|
+
return {
|
|
116
|
+
kind: "text",
|
|
117
|
+
text: part.text,
|
|
118
|
+
...part.metadata !== void 0 ? { metadata: part.metadata } : {}
|
|
119
|
+
};
|
|
120
|
+
case "file": {
|
|
121
|
+
const file = "bytes" in part.file ? {
|
|
122
|
+
bytes: part.file.bytes,
|
|
123
|
+
...part.file.name !== void 0 ? { name: part.file.name } : {},
|
|
124
|
+
...part.file.mimeType !== void 0 ? { mimeType: part.file.mimeType } : {}
|
|
125
|
+
} : {
|
|
126
|
+
uri: part.file.uri,
|
|
127
|
+
...part.file.name !== void 0 ? { name: part.file.name } : {},
|
|
128
|
+
...part.file.mimeType !== void 0 ? { mimeType: part.file.mimeType } : {}
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
kind: "file",
|
|
132
|
+
file,
|
|
133
|
+
...part.metadata !== void 0 ? { metadata: part.metadata } : {}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
case "data":
|
|
137
|
+
return {
|
|
138
|
+
kind: "data",
|
|
139
|
+
data: part.data,
|
|
140
|
+
...part.metadata !== void 0 ? { metadata: part.metadata } : {}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function toA2AMessage(message) {
|
|
145
|
+
return {
|
|
146
|
+
role: message.role,
|
|
147
|
+
parts: message.parts.map(toA2APart),
|
|
148
|
+
messageId: message.messageId,
|
|
149
|
+
kind: "message",
|
|
150
|
+
...message.taskId !== void 0 ? { taskId: message.taskId } : {},
|
|
151
|
+
...message.contextId !== void 0 ? { contextId: message.contextId } : {},
|
|
152
|
+
...message.metadata !== void 0 ? { metadata: message.metadata } : {},
|
|
153
|
+
...message.extensions !== void 0 ? { extensions: message.extensions } : {},
|
|
154
|
+
...message.referenceTaskIds !== void 0 ? { referenceTaskIds: message.referenceTaskIds } : {}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function toMessageSendParams(body) {
|
|
158
|
+
const pushNotificationConfig = body.configuration?.pushNotificationConfig ? {
|
|
159
|
+
url: body.configuration.pushNotificationConfig.url,
|
|
160
|
+
...body.configuration.pushNotificationConfig.headers !== void 0 ? { headers: body.configuration.pushNotificationConfig.headers } : {}
|
|
161
|
+
} : void 0;
|
|
162
|
+
const configuration = body.configuration ? {
|
|
163
|
+
...body.configuration.acceptedOutputModes !== void 0 ? { acceptedOutputModes: body.configuration.acceptedOutputModes } : {},
|
|
164
|
+
...body.configuration.historyLength !== void 0 ? { historyLength: body.configuration.historyLength } : {},
|
|
165
|
+
...pushNotificationConfig !== void 0 ? { pushNotificationConfig } : {},
|
|
166
|
+
...body.configuration.blocking !== void 0 ? { blocking: body.configuration.blocking } : {}
|
|
167
|
+
} : void 0;
|
|
168
|
+
return {
|
|
169
|
+
message: toA2AMessage(body.message),
|
|
170
|
+
...configuration !== void 0 ? { configuration } : {},
|
|
171
|
+
...body.metadata !== void 0 ? { metadata: body.metadata } : {}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function toListTasksParams(query) {
|
|
175
|
+
return {
|
|
176
|
+
...query.contextId !== void 0 ? { contextId: query.contextId } : {},
|
|
177
|
+
...query.status !== void 0 ? { status: query.status } : {},
|
|
178
|
+
...query.pageSize !== void 0 ? { pageSize: query.pageSize } : {},
|
|
179
|
+
...query.pageToken !== void 0 ? { pageToken: query.pageToken } : {},
|
|
180
|
+
...query.historyLength !== void 0 ? { historyLength: query.historyLength } : {},
|
|
181
|
+
...query.lastUpdatedAfter !== void 0 ? { lastUpdatedAfter: query.lastUpdatedAfter } : {},
|
|
182
|
+
...query.includeArtifacts !== void 0 ? { includeArtifacts: query.includeArtifacts } : {}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function readCancelTaskParam(value) {
|
|
186
|
+
if (Object.prototype.hasOwnProperty.call(value, "id")) {
|
|
187
|
+
return void 0;
|
|
188
|
+
}
|
|
189
|
+
const raw = Object.entries(value).find(
|
|
190
|
+
([key, candidate]) => key === "id:cancel" && typeof candidate === "string"
|
|
191
|
+
)?.[1];
|
|
192
|
+
return typeof raw === "string" ? raw : void 0;
|
|
193
|
+
}
|
|
94
194
|
const MessageSendRequestSchema = import_zod_openapi.z.object({
|
|
95
195
|
message: MessageSchema.describe("Message to send to the agent"),
|
|
96
196
|
configuration: import_zod_openapi.z.object({
|
|
@@ -102,7 +202,7 @@ const MessageSendRequestSchema = import_zod_openapi.z.object({
|
|
|
102
202
|
}).optional().describe("Push notification configuration"),
|
|
103
203
|
blocking: import_zod_openapi.z.boolean().optional().describe("Wait for task completion")
|
|
104
204
|
}).optional().describe("Optional configuration"),
|
|
105
|
-
metadata:
|
|
205
|
+
metadata: import_responses.JsonObjectSchema.optional().describe("Optional metadata")
|
|
106
206
|
}).describe("Request body for message/send");
|
|
107
207
|
const TaskListQuerySchema = import_zod_openapi.z.object({
|
|
108
208
|
contextId: import_zod_openapi.z.string().optional().describe("Filter by context ID"),
|
|
@@ -163,7 +263,9 @@ function createA2ATasksRouter(getAgent, sseSubscriber) {
|
|
|
163
263
|
schema: TaskSchema
|
|
164
264
|
}
|
|
165
265
|
}
|
|
166
|
-
}
|
|
266
|
+
},
|
|
267
|
+
400: import_responses.BadRequestErrorResponse,
|
|
268
|
+
500: import_responses.InternalErrorResponse
|
|
167
269
|
}
|
|
168
270
|
});
|
|
169
271
|
const listTasksRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -180,15 +282,12 @@ function createA2ATasksRouter(getAgent, sseSubscriber) {
|
|
|
180
282
|
description: "Task list",
|
|
181
283
|
content: {
|
|
182
284
|
"application/json": {
|
|
183
|
-
schema:
|
|
184
|
-
tasks: import_zod_openapi.z.array(TaskSchema).describe("Array of tasks"),
|
|
185
|
-
totalSize: import_zod_openapi.z.number().describe("Total number of tasks"),
|
|
186
|
-
pageSize: import_zod_openapi.z.number().describe("Number of tasks in this page"),
|
|
187
|
-
nextPageToken: import_zod_openapi.z.string().describe("Token for next page")
|
|
188
|
-
}).describe("Response body for tasks/list")
|
|
285
|
+
schema: TasksListResponseSchema
|
|
189
286
|
}
|
|
190
287
|
}
|
|
191
|
-
}
|
|
288
|
+
},
|
|
289
|
+
400: import_responses.BadRequestErrorResponse,
|
|
290
|
+
500: import_responses.InternalErrorResponse
|
|
192
291
|
}
|
|
193
292
|
});
|
|
194
293
|
const getTaskRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -228,9 +327,22 @@ function createA2ATasksRouter(getAgent, sseSubscriber) {
|
|
|
228
327
|
description: "Cancel a running task (A2A tasks/cancel)",
|
|
229
328
|
tags: ["a2a"],
|
|
230
329
|
request: {
|
|
231
|
-
params: import_zod_openapi.z.
|
|
232
|
-
|
|
233
|
-
|
|
330
|
+
params: import_zod_openapi.z.preprocess(
|
|
331
|
+
(value) => {
|
|
332
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
333
|
+
const raw = readCancelTaskParam(value);
|
|
334
|
+
if (raw !== void 0) {
|
|
335
|
+
return {
|
|
336
|
+
id: raw.endsWith(":cancel") ? raw.slice(0, -":cancel".length) : raw
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return value;
|
|
341
|
+
},
|
|
342
|
+
import_zod_openapi.z.object({
|
|
343
|
+
id: import_zod_openapi.z.string().describe("Task ID")
|
|
344
|
+
})
|
|
345
|
+
)
|
|
234
346
|
},
|
|
235
347
|
responses: {
|
|
236
348
|
200: {
|
|
@@ -270,7 +382,7 @@ function createA2ATasksRouter(getAgent, sseSubscriber) {
|
|
|
270
382
|
const agent = await getAgent(ctx);
|
|
271
383
|
const session = await agent.createSession(taskId);
|
|
272
384
|
const stream = sseSubscriber.createStream(session.id);
|
|
273
|
-
const { text, image, file } = (0, import_message.a2aToInternalMessage)(validatedBody.message);
|
|
385
|
+
const { text, image, file } = (0, import_message.a2aToInternalMessage)(toA2AMessage(validatedBody.message));
|
|
274
386
|
agent.run(text, image, file, session.id).catch((error) => {
|
|
275
387
|
import_core.logger.error(`Error in streaming task ${session.id}: ${error}`);
|
|
276
388
|
});
|
|
@@ -288,39 +400,53 @@ function createA2ATasksRouter(getAgent, sseSubscriber) {
|
|
|
288
400
|
return ctx.json({ error: "Failed to initiate streaming" }, 500);
|
|
289
401
|
}
|
|
290
402
|
});
|
|
291
|
-
|
|
403
|
+
const messageSendRouter = new import_zod_openapi.OpenAPIHono().openapi(messageSendRoute, async (ctx) => {
|
|
292
404
|
const handlers = new import_methods.A2AMethodHandlers(await getAgent(ctx));
|
|
293
405
|
const body = ctx.req.valid("json");
|
|
294
406
|
import_core.logger.info("REST: message/send", { hasMessage: !!body.message });
|
|
295
|
-
const result = await handlers.messageSend(body);
|
|
296
|
-
|
|
297
|
-
|
|
407
|
+
const result = await handlers.messageSend(toMessageSendParams(body));
|
|
408
|
+
const response = result;
|
|
409
|
+
return ctx.json(response, 200);
|
|
410
|
+
});
|
|
411
|
+
const listTasksRouter = new import_zod_openapi.OpenAPIHono().openapi(listTasksRoute, async (ctx) => {
|
|
298
412
|
const handlers = new import_methods.A2AMethodHandlers(await getAgent(ctx));
|
|
299
413
|
const query = ctx.req.valid("query");
|
|
300
|
-
const result = await handlers.tasksList(query);
|
|
301
|
-
|
|
302
|
-
|
|
414
|
+
const result = await handlers.tasksList(toListTasksParams(query));
|
|
415
|
+
const response = result;
|
|
416
|
+
return ctx.json(response, 200);
|
|
417
|
+
});
|
|
418
|
+
const getTaskRouter = new import_zod_openapi.OpenAPIHono().openapi(getTaskRoute, async (ctx) => {
|
|
303
419
|
const handlers = new import_methods.A2AMethodHandlers(await getAgent(ctx));
|
|
304
420
|
const { id } = ctx.req.valid("param");
|
|
305
421
|
try {
|
|
306
422
|
const task = await handlers.tasksGet({ id });
|
|
307
|
-
|
|
423
|
+
const response = task;
|
|
424
|
+
return ctx.json(response, 200);
|
|
308
425
|
} catch (error) {
|
|
309
426
|
import_core.logger.warn(`Task ${id} not found: ${error}`);
|
|
310
|
-
|
|
427
|
+
const response = { error: "Task not found" };
|
|
428
|
+
return ctx.json(response, 404);
|
|
311
429
|
}
|
|
312
|
-
})
|
|
430
|
+
});
|
|
431
|
+
const cancelTaskRouter = new import_zod_openapi.OpenAPIHono().openapi(cancelTaskRoute, async (ctx) => {
|
|
313
432
|
const handlers = new import_methods.A2AMethodHandlers(await getAgent(ctx));
|
|
314
433
|
const { id } = ctx.req.valid("param");
|
|
315
434
|
import_core.logger.info(`REST: tasks/cancel ${id}`);
|
|
316
435
|
try {
|
|
317
436
|
const task = await handlers.tasksCancel({ id });
|
|
318
|
-
|
|
437
|
+
const response = task;
|
|
438
|
+
return ctx.json(response, 200);
|
|
319
439
|
} catch (error) {
|
|
320
440
|
import_core.logger.error(`Failed to cancel task ${id}: ${error}`);
|
|
321
|
-
|
|
441
|
+
const response = { error: "Task not found" };
|
|
442
|
+
return ctx.json(response, 404);
|
|
322
443
|
}
|
|
323
444
|
});
|
|
445
|
+
mountA2ATasksSubrouter(app, messageSendRouter);
|
|
446
|
+
mountA2ATasksSubrouter(app, listTasksRouter);
|
|
447
|
+
mountA2ATasksSubrouter(app, getTaskRouter);
|
|
448
|
+
mountA2ATasksSubrouter(app, cancelTaskRouter);
|
|
449
|
+
return app;
|
|
324
450
|
}
|
|
325
451
|
// Annotate the CommonJS export names for ESM import in node:
|
|
326
452
|
0 && (module.exports = {
|