@dexto/server 1.2.5
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/LICENSE +44 -0
- package/dist/a2a/adapters/index.cjs +42 -0
- package/dist/a2a/adapters/index.d.ts +10 -0
- package/dist/a2a/adapters/index.d.ts.map +1 -0
- package/dist/a2a/adapters/index.js +12 -0
- package/dist/a2a/adapters/message.cjs +193 -0
- package/dist/a2a/adapters/message.d.ts +50 -0
- package/dist/a2a/adapters/message.d.ts.map +1 -0
- package/dist/a2a/adapters/message.js +167 -0
- package/dist/a2a/adapters/state.cjs +57 -0
- package/dist/a2a/adapters/state.d.ts +36 -0
- package/dist/a2a/adapters/state.d.ts.map +1 -0
- package/dist/a2a/adapters/state.js +32 -0
- package/dist/a2a/adapters/task-view.cjs +85 -0
- package/dist/a2a/adapters/task-view.d.ts +58 -0
- package/dist/a2a/adapters/task-view.d.ts.map +1 -0
- package/dist/a2a/adapters/task-view.js +60 -0
- package/dist/a2a/index.cjs +51 -0
- package/dist/a2a/index.d.ts +15 -0
- package/dist/a2a/index.d.ts.map +1 -0
- package/dist/a2a/index.js +30 -0
- package/dist/a2a/jsonrpc/index.cjs +38 -0
- package/dist/a2a/jsonrpc/index.d.ts +11 -0
- package/dist/a2a/jsonrpc/index.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/index.js +10 -0
- package/dist/a2a/jsonrpc/methods.cjs +183 -0
- package/dist/a2a/jsonrpc/methods.d.ts +110 -0
- package/dist/a2a/jsonrpc/methods.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/methods.js +159 -0
- package/dist/a2a/jsonrpc/server.cjs +199 -0
- package/dist/a2a/jsonrpc/server.d.ts +100 -0
- package/dist/a2a/jsonrpc/server.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/server.js +175 -0
- package/dist/a2a/jsonrpc/types.cjs +47 -0
- package/dist/a2a/jsonrpc/types.d.ts +91 -0
- package/dist/a2a/jsonrpc/types.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/types.js +21 -0
- package/dist/a2a/types.cjs +16 -0
- package/dist/a2a/types.d.ts +250 -0
- package/dist/a2a/types.d.ts.map +1 -0
- package/dist/a2a/types.js +0 -0
- package/dist/approval/approval-coordinator.cjs +87 -0
- package/dist/approval/approval-coordinator.d.ts +52 -0
- package/dist/approval/approval-coordinator.d.ts.map +1 -0
- package/dist/approval/approval-coordinator.js +63 -0
- package/dist/approval/manual-approval-handler.cjs +100 -0
- package/dist/approval/manual-approval-handler.d.ts +32 -0
- package/dist/approval/manual-approval-handler.d.ts.map +1 -0
- package/dist/approval/manual-approval-handler.js +76 -0
- package/dist/events/a2a-sse-subscriber.cjs +271 -0
- package/dist/events/a2a-sse-subscriber.d.ts +94 -0
- package/dist/events/a2a-sse-subscriber.d.ts.map +1 -0
- package/dist/events/a2a-sse-subscriber.js +247 -0
- package/dist/events/types.cjs +16 -0
- package/dist/events/types.d.ts +15 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +0 -0
- package/dist/events/webhook-subscriber.cjs +301 -0
- package/dist/events/webhook-subscriber.d.ts +64 -0
- package/dist/events/webhook-subscriber.d.ts.map +1 -0
- package/dist/events/webhook-subscriber.js +269 -0
- package/dist/events/webhook-types.cjs +16 -0
- package/dist/events/webhook-types.d.ts +91 -0
- package/dist/events/webhook-types.d.ts.map +1 -0
- package/dist/events/webhook-types.js +0 -0
- package/dist/hono/__tests__/test-fixtures.cjs +236 -0
- package/dist/hono/__tests__/test-fixtures.d.ts +65 -0
- package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -0
- package/dist/hono/__tests__/test-fixtures.js +197 -0
- package/dist/hono/index.cjs +166 -0
- package/dist/hono/index.d.ts +2783 -0
- package/dist/hono/index.d.ts.map +1 -0
- package/dist/hono/index.js +141 -0
- package/dist/hono/middleware/auth.cjs +75 -0
- package/dist/hono/middleware/auth.d.ts +3 -0
- package/dist/hono/middleware/auth.d.ts.map +1 -0
- package/dist/hono/middleware/auth.js +51 -0
- package/dist/hono/middleware/cors.cjs +57 -0
- package/dist/hono/middleware/cors.d.ts +9 -0
- package/dist/hono/middleware/cors.d.ts.map +1 -0
- package/dist/hono/middleware/cors.js +33 -0
- package/dist/hono/middleware/error.cjs +131 -0
- package/dist/hono/middleware/error.d.ts +5 -0
- package/dist/hono/middleware/error.d.ts.map +1 -0
- package/dist/hono/middleware/error.js +105 -0
- package/dist/hono/middleware/redaction.cjs +45 -0
- package/dist/hono/middleware/redaction.d.ts +4 -0
- package/dist/hono/middleware/redaction.d.ts.map +1 -0
- package/dist/hono/middleware/redaction.js +20 -0
- package/dist/hono/node/index.cjs +139 -0
- package/dist/hono/node/index.d.ts +19 -0
- package/dist/hono/node/index.d.ts.map +1 -0
- package/dist/hono/node/index.js +115 -0
- package/dist/hono/routes/a2a-jsonrpc.cjs +119 -0
- package/dist/hono/routes/a2a-jsonrpc.d.ts +46 -0
- package/dist/hono/routes/a2a-jsonrpc.d.ts.map +1 -0
- package/dist/hono/routes/a2a-jsonrpc.js +95 -0
- package/dist/hono/routes/a2a-tasks.cjs +315 -0
- package/dist/hono/routes/a2a-tasks.d.ts +530 -0
- package/dist/hono/routes/a2a-tasks.d.ts.map +1 -0
- package/dist/hono/routes/a2a-tasks.js +291 -0
- package/dist/hono/routes/a2a.cjs +36 -0
- package/dist/hono/routes/a2a.d.ts +4 -0
- package/dist/hono/routes/a2a.d.ts.map +1 -0
- package/dist/hono/routes/a2a.js +12 -0
- package/dist/hono/routes/agents.cjs +735 -0
- package/dist/hono/routes/agents.d.ts +650 -0
- package/dist/hono/routes/agents.d.ts.map +1 -0
- package/dist/hono/routes/agents.js +711 -0
- package/dist/hono/routes/approvals.cjs +125 -0
- package/dist/hono/routes/approvals.d.ts +89 -0
- package/dist/hono/routes/approvals.d.ts.map +1 -0
- package/dist/hono/routes/approvals.js +101 -0
- package/dist/hono/routes/greeting.cjs +60 -0
- package/dist/hono/routes/greeting.d.ts +19 -0
- package/dist/hono/routes/greeting.d.ts.map +1 -0
- package/dist/hono/routes/greeting.js +36 -0
- package/dist/hono/routes/health.cjs +45 -0
- package/dist/hono/routes/health.d.ts +17 -0
- package/dist/hono/routes/health.d.ts.map +1 -0
- package/dist/hono/routes/health.js +21 -0
- package/dist/hono/routes/llm.cjs +298 -0
- package/dist/hono/routes/llm.d.ts +294 -0
- package/dist/hono/routes/llm.d.ts.map +1 -0
- package/dist/hono/routes/llm.js +287 -0
- package/dist/hono/routes/mcp.cjs +356 -0
- package/dist/hono/routes/mcp.d.ts +246 -0
- package/dist/hono/routes/mcp.d.ts.map +1 -0
- package/dist/hono/routes/mcp.js +332 -0
- package/dist/hono/routes/memory.cjs +192 -0
- package/dist/hono/routes/memory.d.ts +146 -0
- package/dist/hono/routes/memory.d.ts.map +1 -0
- package/dist/hono/routes/memory.js +168 -0
- package/dist/hono/routes/messages.cjs +320 -0
- package/dist/hono/routes/messages.d.ts +163 -0
- package/dist/hono/routes/messages.d.ts.map +1 -0
- package/dist/hono/routes/messages.js +296 -0
- package/dist/hono/routes/prompts.cjs +228 -0
- package/dist/hono/routes/prompts.d.ts +150 -0
- package/dist/hono/routes/prompts.d.ts.map +1 -0
- package/dist/hono/routes/prompts.js +204 -0
- package/dist/hono/routes/resources.cjs +110 -0
- package/dist/hono/routes/resources.d.ts +76 -0
- package/dist/hono/routes/resources.d.ts.map +1 -0
- package/dist/hono/routes/resources.js +86 -0
- package/dist/hono/routes/search.cjs +109 -0
- package/dist/hono/routes/search.d.ts +137 -0
- package/dist/hono/routes/search.d.ts.map +1 -0
- package/dist/hono/routes/search.js +85 -0
- package/dist/hono/routes/sessions.cjs +366 -0
- package/dist/hono/routes/sessions.d.ts +229 -0
- package/dist/hono/routes/sessions.d.ts.map +1 -0
- package/dist/hono/routes/sessions.js +342 -0
- package/dist/hono/routes/webhooks.cjs +228 -0
- package/dist/hono/routes/webhooks.d.ts +127 -0
- package/dist/hono/routes/webhooks.d.ts.map +1 -0
- package/dist/hono/routes/webhooks.js +204 -0
- package/dist/hono/schemas/responses.cjs +276 -0
- package/dist/hono/schemas/responses.d.ts +1418 -0
- package/dist/hono/schemas/responses.d.ts.map +1 -0
- package/dist/hono/schemas/responses.js +227 -0
- package/dist/hono/types.cjs +16 -0
- package/dist/hono/types.d.ts +6 -0
- package/dist/hono/types.d.ts.map +1 -0
- package/dist/hono/types.js +0 -0
- package/dist/index.cjs +38 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/mcp/mcp-handler.cjs +145 -0
- package/dist/mcp/mcp-handler.d.ts +14 -0
- package/dist/mcp/mcp-handler.d.ts.map +1 -0
- package/dist/mcp/mcp-handler.js +118 -0
- package/package.json +59 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Implements JSON-RPC 2.0 specification for A2A Protocol transport.
|
|
5
|
+
* @see https://www.jsonrpc.org/specification
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* JSON-RPC 2.0 Request
|
|
9
|
+
*/
|
|
10
|
+
export interface JsonRpcRequest {
|
|
11
|
+
/** JSON-RPC version (must be "2.0") */
|
|
12
|
+
jsonrpc: '2.0';
|
|
13
|
+
/** Method name to invoke */
|
|
14
|
+
method: string;
|
|
15
|
+
/** Method parameters (optional) */
|
|
16
|
+
params?: any;
|
|
17
|
+
/** Request ID (can be string, number, or null for notifications) */
|
|
18
|
+
id?: string | number | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* JSON-RPC 2.0 Response (Success)
|
|
22
|
+
*/
|
|
23
|
+
export interface JsonRpcSuccessResponse {
|
|
24
|
+
/** JSON-RPC version (must be "2.0") */
|
|
25
|
+
jsonrpc: '2.0';
|
|
26
|
+
/** Result of the method invocation */
|
|
27
|
+
result: any;
|
|
28
|
+
/** Request ID (matches request) */
|
|
29
|
+
id: string | number | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* JSON-RPC 2.0 Response (Error)
|
|
33
|
+
*/
|
|
34
|
+
export interface JsonRpcErrorResponse {
|
|
35
|
+
/** JSON-RPC version (must be "2.0") */
|
|
36
|
+
jsonrpc: '2.0';
|
|
37
|
+
/** Error object */
|
|
38
|
+
error: JsonRpcError;
|
|
39
|
+
/** Request ID (matches request, or null if ID couldn't be determined) */
|
|
40
|
+
id: string | number | null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* JSON-RPC 2.0 Error Object
|
|
44
|
+
*/
|
|
45
|
+
export interface JsonRpcError {
|
|
46
|
+
/** Error code (integer) */
|
|
47
|
+
code: number;
|
|
48
|
+
/** Error message (short description) */
|
|
49
|
+
message: string;
|
|
50
|
+
/** Optional additional error data */
|
|
51
|
+
data?: any;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Union type for JSON-RPC responses
|
|
55
|
+
*/
|
|
56
|
+
export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
57
|
+
/**
|
|
58
|
+
* JSON-RPC 2.0 Batch Request
|
|
59
|
+
*/
|
|
60
|
+
export type JsonRpcBatchRequest = JsonRpcRequest[];
|
|
61
|
+
/**
|
|
62
|
+
* JSON-RPC 2.0 Batch Response
|
|
63
|
+
*/
|
|
64
|
+
export type JsonRpcBatchResponse = JsonRpcResponse[];
|
|
65
|
+
/**
|
|
66
|
+
* Standard JSON-RPC 2.0 Error Codes
|
|
67
|
+
*/
|
|
68
|
+
export declare enum JsonRpcErrorCode {
|
|
69
|
+
/** Invalid JSON was received by the server */
|
|
70
|
+
PARSE_ERROR = -32700,
|
|
71
|
+
/** The JSON sent is not a valid Request object */
|
|
72
|
+
INVALID_REQUEST = -32600,
|
|
73
|
+
/** The method does not exist / is not available */
|
|
74
|
+
METHOD_NOT_FOUND = -32601,
|
|
75
|
+
/** Invalid method parameter(s) */
|
|
76
|
+
INVALID_PARAMS = -32602,
|
|
77
|
+
/** Internal JSON-RPC error */
|
|
78
|
+
INTERNAL_ERROR = -32603,
|
|
79
|
+
/** Reserved for implementation-defined server-errors (-32000 to -32099) */
|
|
80
|
+
SERVER_ERROR_START = -32099,
|
|
81
|
+
SERVER_ERROR_END = -32000
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Type guard to check if response is an error
|
|
85
|
+
*/
|
|
86
|
+
export declare function isJsonRpcError(response: JsonRpcResponse): response is JsonRpcErrorResponse;
|
|
87
|
+
/**
|
|
88
|
+
* Type guard to check if response is success
|
|
89
|
+
*/
|
|
90
|
+
export declare function isJsonRpcSuccess(response: JsonRpcResponse): response is JsonRpcSuccessResponse;
|
|
91
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/a2a/jsonrpc/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,uCAAuC;IACvC,OAAO,EAAE,KAAK,CAAC;IACf,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,oEAAoE;IACpE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC,uCAAuC;IACvC,OAAO,EAAE,KAAK,CAAC;IACf,sCAAsC;IACtC,MAAM,EAAE,GAAG,CAAC;IACZ,mCAAmC;IACnC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,uCAAuC;IACvC,OAAO,EAAE,KAAK,CAAC;IACf,mBAAmB;IACnB,KAAK,EAAE,YAAY,CAAC;IACpB,yEAAyE;IACzE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,IAAI,CAAC,EAAE,GAAG,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,sBAAsB,GAAG,oBAAoB,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,cAAc,EAAE,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,EAAE,CAAC;AAErD;;GAEG;AACH,oBAAY,gBAAgB;IACxB,8CAA8C;IAC9C,WAAW,SAAS;IACpB,kDAAkD;IAClD,eAAe,SAAS;IACxB,mDAAmD;IACnD,gBAAgB,SAAS;IACzB,kCAAkC;IAClC,cAAc,SAAS;IACvB,8BAA8B;IAC9B,cAAc,SAAS;IACvB,2EAA2E;IAC3E,kBAAkB,SAAS;IAC3B,gBAAgB,SAAS;CAC5B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ,IAAI,oBAAoB,CAE1F;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ,IAAI,sBAAsB,CAE9F"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var JsonRpcErrorCode = /* @__PURE__ */ ((JsonRpcErrorCode2) => {
|
|
2
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
3
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
4
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
5
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
6
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
7
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["SERVER_ERROR_START"] = -32099] = "SERVER_ERROR_START";
|
|
8
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["SERVER_ERROR_END"] = -32e3] = "SERVER_ERROR_END";
|
|
9
|
+
return JsonRpcErrorCode2;
|
|
10
|
+
})(JsonRpcErrorCode || {});
|
|
11
|
+
function isJsonRpcError(response) {
|
|
12
|
+
return "error" in response;
|
|
13
|
+
}
|
|
14
|
+
function isJsonRpcSuccess(response) {
|
|
15
|
+
return "result" in response;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
JsonRpcErrorCode,
|
|
19
|
+
isJsonRpcError,
|
|
20
|
+
isJsonRpcSuccess
|
|
21
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: fetch from a2a sdk to avoid drift over time
|
|
3
|
+
* A2A Protocol Type Definitions
|
|
4
|
+
*
|
|
5
|
+
* Type definitions compliant with A2A Protocol v0.3.0 specification.
|
|
6
|
+
* Based on: https://a2a-protocol.org/latest/specification
|
|
7
|
+
*
|
|
8
|
+
* @module a2a/types
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Task state per A2A Protocol specification.
|
|
12
|
+
*
|
|
13
|
+
* States:
|
|
14
|
+
* - submitted: Task has been submitted
|
|
15
|
+
* - working: Task is being processed
|
|
16
|
+
* - input-required: Task needs user input
|
|
17
|
+
* - completed: Task completed successfully
|
|
18
|
+
* - canceled: Task was canceled
|
|
19
|
+
* - failed: Task failed with error
|
|
20
|
+
* - rejected: Task was rejected
|
|
21
|
+
* - auth-required: Authentication required
|
|
22
|
+
* - unknown: State is unknown
|
|
23
|
+
*/
|
|
24
|
+
export type TaskState = 'submitted' | 'working' | 'input-required' | 'completed' | 'canceled' | 'failed' | 'rejected' | 'auth-required' | 'unknown';
|
|
25
|
+
/**
|
|
26
|
+
* Message role per A2A Protocol specification.
|
|
27
|
+
*/
|
|
28
|
+
export type MessageRole = 'user' | 'agent';
|
|
29
|
+
/**
|
|
30
|
+
* Base interface for all part types.
|
|
31
|
+
*/
|
|
32
|
+
export interface PartBase {
|
|
33
|
+
metadata?: {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Text part - contains text content.
|
|
39
|
+
*/
|
|
40
|
+
export interface TextPart extends PartBase {
|
|
41
|
+
readonly kind: 'text';
|
|
42
|
+
text: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* File base interface.
|
|
46
|
+
*/
|
|
47
|
+
export interface FileBase {
|
|
48
|
+
name?: string;
|
|
49
|
+
mimeType?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* File with base64-encoded bytes.
|
|
53
|
+
*/
|
|
54
|
+
export interface FileWithBytes extends FileBase {
|
|
55
|
+
bytes: string;
|
|
56
|
+
uri?: never;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* File with URI reference.
|
|
60
|
+
*/
|
|
61
|
+
export interface FileWithUri extends FileBase {
|
|
62
|
+
uri: string;
|
|
63
|
+
bytes?: never;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* File part - contains file data.
|
|
67
|
+
*/
|
|
68
|
+
export interface FilePart extends PartBase {
|
|
69
|
+
readonly kind: 'file';
|
|
70
|
+
file: FileWithBytes | FileWithUri;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Data part - contains structured JSON data.
|
|
74
|
+
*/
|
|
75
|
+
export interface DataPart extends PartBase {
|
|
76
|
+
readonly kind: 'data';
|
|
77
|
+
data: {
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Union of all part types per A2A specification.
|
|
83
|
+
*/
|
|
84
|
+
export type Part = TextPart | FilePart | DataPart;
|
|
85
|
+
/**
|
|
86
|
+
* A2A Protocol message structure.
|
|
87
|
+
*/
|
|
88
|
+
export interface Message {
|
|
89
|
+
readonly role: MessageRole;
|
|
90
|
+
parts: Part[];
|
|
91
|
+
metadata?: {
|
|
92
|
+
[key: string]: any;
|
|
93
|
+
};
|
|
94
|
+
extensions?: string[];
|
|
95
|
+
referenceTaskIds?: string[];
|
|
96
|
+
messageId: string;
|
|
97
|
+
taskId?: string;
|
|
98
|
+
contextId?: string;
|
|
99
|
+
readonly kind: 'message';
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Task status structure.
|
|
103
|
+
*/
|
|
104
|
+
export interface TaskStatus {
|
|
105
|
+
state: TaskState;
|
|
106
|
+
message?: Message;
|
|
107
|
+
timestamp?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Artifact - generated output from the agent.
|
|
111
|
+
*/
|
|
112
|
+
export interface Artifact {
|
|
113
|
+
artifactId: string;
|
|
114
|
+
name?: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
parts: Part[];
|
|
117
|
+
metadata?: {
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
};
|
|
120
|
+
extensions?: string[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A2A Protocol task structure.
|
|
124
|
+
*/
|
|
125
|
+
export interface Task {
|
|
126
|
+
id: string;
|
|
127
|
+
contextId: string;
|
|
128
|
+
status: TaskStatus;
|
|
129
|
+
history?: Message[];
|
|
130
|
+
artifacts?: Artifact[];
|
|
131
|
+
metadata?: {
|
|
132
|
+
[key: string]: any;
|
|
133
|
+
};
|
|
134
|
+
readonly kind: 'task';
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Task status update event (streaming).
|
|
138
|
+
*/
|
|
139
|
+
export interface TaskStatusUpdateEvent {
|
|
140
|
+
taskId: string;
|
|
141
|
+
contextId: string;
|
|
142
|
+
readonly kind: 'status-update';
|
|
143
|
+
status: TaskStatus;
|
|
144
|
+
final: boolean;
|
|
145
|
+
metadata?: {
|
|
146
|
+
[key: string]: any;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Task artifact update event (streaming).
|
|
151
|
+
*/
|
|
152
|
+
export interface TaskArtifactUpdateEvent {
|
|
153
|
+
taskId: string;
|
|
154
|
+
contextId: string;
|
|
155
|
+
readonly kind: 'artifact-update';
|
|
156
|
+
artifact: Artifact;
|
|
157
|
+
append?: boolean;
|
|
158
|
+
lastChunk?: boolean;
|
|
159
|
+
metadata?: {
|
|
160
|
+
[key: string]: any;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Push notification configuration.
|
|
165
|
+
*/
|
|
166
|
+
export interface PushNotificationConfig {
|
|
167
|
+
url: string;
|
|
168
|
+
headers?: {
|
|
169
|
+
[key: string]: string;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Message send configuration.
|
|
174
|
+
*/
|
|
175
|
+
export interface MessageSendConfiguration {
|
|
176
|
+
acceptedOutputModes?: string[];
|
|
177
|
+
historyLength?: number;
|
|
178
|
+
pushNotificationConfig?: PushNotificationConfig;
|
|
179
|
+
blocking?: boolean;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Parameters for message/send and message/stream methods.
|
|
183
|
+
*/
|
|
184
|
+
export interface MessageSendParams {
|
|
185
|
+
message: Message;
|
|
186
|
+
configuration?: MessageSendConfiguration;
|
|
187
|
+
metadata?: {
|
|
188
|
+
[key: string]: any;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Parameters for tasks/get method.
|
|
193
|
+
*/
|
|
194
|
+
export interface TaskQueryParams {
|
|
195
|
+
id: string;
|
|
196
|
+
historyLength?: number;
|
|
197
|
+
metadata?: {
|
|
198
|
+
[key: string]: any;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Parameters for tasks/list method.
|
|
203
|
+
*/
|
|
204
|
+
export interface ListTasksParams {
|
|
205
|
+
contextId?: string;
|
|
206
|
+
status?: TaskState;
|
|
207
|
+
pageSize?: number;
|
|
208
|
+
pageToken?: string;
|
|
209
|
+
historyLength?: number;
|
|
210
|
+
lastUpdatedAfter?: number;
|
|
211
|
+
includeArtifacts?: boolean;
|
|
212
|
+
metadata?: {
|
|
213
|
+
[key: string]: any;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Result for tasks/list method.
|
|
218
|
+
*/
|
|
219
|
+
export interface ListTasksResult {
|
|
220
|
+
tasks: Task[];
|
|
221
|
+
totalSize: number;
|
|
222
|
+
pageSize: number;
|
|
223
|
+
nextPageToken: string;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Parameters for tasks/cancel and tasks/resubscribe methods.
|
|
227
|
+
*/
|
|
228
|
+
export interface TaskIdParams {
|
|
229
|
+
id: string;
|
|
230
|
+
metadata?: {
|
|
231
|
+
[key: string]: any;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Converted message parts for internal use (compatibility layer).
|
|
236
|
+
* Used by adapters to convert between A2A and Dexto internal format.
|
|
237
|
+
*/
|
|
238
|
+
export interface ConvertedMessage {
|
|
239
|
+
text: string;
|
|
240
|
+
image: {
|
|
241
|
+
image: string;
|
|
242
|
+
mimeType: string;
|
|
243
|
+
} | undefined;
|
|
244
|
+
file: {
|
|
245
|
+
data: string;
|
|
246
|
+
mimeType: string;
|
|
247
|
+
filename?: string;
|
|
248
|
+
} | undefined;
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/a2a/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,SAAS,GACf,WAAW,GACX,SAAS,GACT,gBAAgB,GAChB,WAAW,GACX,UAAU,GACV,QAAQ,GACR,UAAU,GACV,eAAe,GACf,SAAS,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,QAAQ,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE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e;IAC5B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EACC;QACI,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KACpB,GACD,SAAS,CAAC;IAChB,IAAI,EACE;QACI,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB,GACD,SAAS,CAAC;CACnB"}
|
|
File without changes
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var approval_coordinator_exports = {};
|
|
20
|
+
__export(approval_coordinator_exports, {
|
|
21
|
+
ApprovalCoordinator: () => ApprovalCoordinator
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(approval_coordinator_exports);
|
|
24
|
+
var import_node_events = require("node:events");
|
|
25
|
+
class ApprovalCoordinator extends import_node_events.EventEmitter {
|
|
26
|
+
// Track approvalId -> sessionId mapping for multi-client SSE routing
|
|
27
|
+
approvalSessions = /* @__PURE__ */ new Map();
|
|
28
|
+
/**
|
|
29
|
+
* Emit an approval request.
|
|
30
|
+
* Called by ManualApprovalHandler when tool/command needs approval.
|
|
31
|
+
*/
|
|
32
|
+
emitRequest(request) {
|
|
33
|
+
this.approvalSessions.set(request.approvalId, request.sessionId);
|
|
34
|
+
this.emit("approval:request", request);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Emit an approval response.
|
|
38
|
+
* Called by API routes when user submits decision.
|
|
39
|
+
*/
|
|
40
|
+
emitResponse(response) {
|
|
41
|
+
this.emit("approval:response", response);
|
|
42
|
+
this.approvalSessions.delete(response.approvalId);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the sessionId associated with an approval request.
|
|
46
|
+
* Used by API routes to attach sessionId to responses for SSE routing.
|
|
47
|
+
*/
|
|
48
|
+
getSessionId(approvalId) {
|
|
49
|
+
return this.approvalSessions.get(approvalId);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Subscribe to approval requests.
|
|
53
|
+
* Used by streaming endpoints to forward requests to SSE clients.
|
|
54
|
+
*
|
|
55
|
+
* @param handler Callback to handle approval requests
|
|
56
|
+
* @param options Optional AbortSignal for cleanup
|
|
57
|
+
*/
|
|
58
|
+
onRequest(handler, options) {
|
|
59
|
+
const listener = (request) => handler(request);
|
|
60
|
+
this.on("approval:request", listener);
|
|
61
|
+
if (options?.signal) {
|
|
62
|
+
options.signal.addEventListener("abort", () => {
|
|
63
|
+
this.off("approval:request", listener);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Subscribe to approval responses.
|
|
69
|
+
* Used by ManualApprovalHandler to resolve pending approval promises.
|
|
70
|
+
*
|
|
71
|
+
* @param handler Callback to handle approval responses
|
|
72
|
+
* @param options Optional AbortSignal for cleanup
|
|
73
|
+
*/
|
|
74
|
+
onResponse(handler, options) {
|
|
75
|
+
const listener = (response) => handler(response);
|
|
76
|
+
this.on("approval:response", listener);
|
|
77
|
+
if (options?.signal) {
|
|
78
|
+
options.signal.addEventListener("abort", () => {
|
|
79
|
+
this.off("approval:response", listener);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
ApprovalCoordinator
|
|
87
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { ApprovalRequest, ApprovalResponse } from '@dexto/core';
|
|
3
|
+
/**
|
|
4
|
+
* Event coordinator for approval request/response flow between handler and server.
|
|
5
|
+
*
|
|
6
|
+
* Provides explicit separation between agent lifecycle events (on AgentEventBus)
|
|
7
|
+
* and server-mode coordination events (on ApprovalCoordinator).
|
|
8
|
+
*
|
|
9
|
+
* Used by:
|
|
10
|
+
* - ManualApprovalHandler: Emits requests, listens for responses
|
|
11
|
+
* - Streaming endpoints: Listens for requests, helps emit responses
|
|
12
|
+
* - Approval routes: Emits responses from client submissions
|
|
13
|
+
*/
|
|
14
|
+
export declare class ApprovalCoordinator extends EventEmitter {
|
|
15
|
+
private approvalSessions;
|
|
16
|
+
/**
|
|
17
|
+
* Emit an approval request.
|
|
18
|
+
* Called by ManualApprovalHandler when tool/command needs approval.
|
|
19
|
+
*/
|
|
20
|
+
emitRequest(request: ApprovalRequest): void;
|
|
21
|
+
/**
|
|
22
|
+
* Emit an approval response.
|
|
23
|
+
* Called by API routes when user submits decision.
|
|
24
|
+
*/
|
|
25
|
+
emitResponse(response: ApprovalResponse): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get the sessionId associated with an approval request.
|
|
28
|
+
* Used by API routes to attach sessionId to responses for SSE routing.
|
|
29
|
+
*/
|
|
30
|
+
getSessionId(approvalId: string): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Subscribe to approval requests.
|
|
33
|
+
* Used by streaming endpoints to forward requests to SSE clients.
|
|
34
|
+
*
|
|
35
|
+
* @param handler Callback to handle approval requests
|
|
36
|
+
* @param options Optional AbortSignal for cleanup
|
|
37
|
+
*/
|
|
38
|
+
onRequest(handler: (request: ApprovalRequest) => void, options?: {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}): void;
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe to approval responses.
|
|
43
|
+
* Used by ManualApprovalHandler to resolve pending approval promises.
|
|
44
|
+
*
|
|
45
|
+
* @param handler Callback to handle approval responses
|
|
46
|
+
* @param options Optional AbortSignal for cleanup
|
|
47
|
+
*/
|
|
48
|
+
onResponse(handler: (response: ApprovalResponse) => void, options?: {
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}): void;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=approval-coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-coordinator.d.ts","sourceRoot":"","sources":["../../src/approval/approval-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErE;;;;;;;;;;GAUG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IAEjD,OAAO,CAAC,gBAAgB,CAAyC;IAEjE;;;OAGG;IACI,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAMlD;;;OAGG;IACI,YAAY,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAMrD;;;OAGG;IACI,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI3D;;;;;;OAMG;IACI,SAAS,CACZ,OAAO,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,EAC3C,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACnC,IAAI;IAYP;;;;;;OAMG;IACI,UAAU,CACb,OAAO,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,EAC7C,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACnC,IAAI;CAWV"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
class ApprovalCoordinator extends EventEmitter {
|
|
3
|
+
// Track approvalId -> sessionId mapping for multi-client SSE routing
|
|
4
|
+
approvalSessions = /* @__PURE__ */ new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Emit an approval request.
|
|
7
|
+
* Called by ManualApprovalHandler when tool/command needs approval.
|
|
8
|
+
*/
|
|
9
|
+
emitRequest(request) {
|
|
10
|
+
this.approvalSessions.set(request.approvalId, request.sessionId);
|
|
11
|
+
this.emit("approval:request", request);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Emit an approval response.
|
|
15
|
+
* Called by API routes when user submits decision.
|
|
16
|
+
*/
|
|
17
|
+
emitResponse(response) {
|
|
18
|
+
this.emit("approval:response", response);
|
|
19
|
+
this.approvalSessions.delete(response.approvalId);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the sessionId associated with an approval request.
|
|
23
|
+
* Used by API routes to attach sessionId to responses for SSE routing.
|
|
24
|
+
*/
|
|
25
|
+
getSessionId(approvalId) {
|
|
26
|
+
return this.approvalSessions.get(approvalId);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to approval requests.
|
|
30
|
+
* Used by streaming endpoints to forward requests to SSE clients.
|
|
31
|
+
*
|
|
32
|
+
* @param handler Callback to handle approval requests
|
|
33
|
+
* @param options Optional AbortSignal for cleanup
|
|
34
|
+
*/
|
|
35
|
+
onRequest(handler, options) {
|
|
36
|
+
const listener = (request) => handler(request);
|
|
37
|
+
this.on("approval:request", listener);
|
|
38
|
+
if (options?.signal) {
|
|
39
|
+
options.signal.addEventListener("abort", () => {
|
|
40
|
+
this.off("approval:request", listener);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe to approval responses.
|
|
46
|
+
* Used by ManualApprovalHandler to resolve pending approval promises.
|
|
47
|
+
*
|
|
48
|
+
* @param handler Callback to handle approval responses
|
|
49
|
+
* @param options Optional AbortSignal for cleanup
|
|
50
|
+
*/
|
|
51
|
+
onResponse(handler, options) {
|
|
52
|
+
const listener = (response) => handler(response);
|
|
53
|
+
this.on("approval:response", listener);
|
|
54
|
+
if (options?.signal) {
|
|
55
|
+
options.signal.addEventListener("abort", () => {
|
|
56
|
+
this.off("approval:response", listener);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
ApprovalCoordinator
|
|
63
|
+
};
|