dsh-a2a-server 0.1.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/LICENSE +21 -0
- package/README.md +335 -0
- package/README.zh-CN.md +316 -0
- package/cordis.patch.yml +30 -0
- package/lib/config.d.ts +116 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +110 -0
- package/lib/config.js.map +1 -0
- package/lib/contexts.d.ts +84 -0
- package/lib/contexts.d.ts.map +1 -0
- package/lib/contexts.js +103 -0
- package/lib/contexts.js.map +1 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +505 -0
- package/lib/index.js.map +1 -0
- package/lib/projection.d.ts +131 -0
- package/lib/projection.d.ts.map +1 -0
- package/lib/projection.js +98 -0
- package/lib/projection.js.map +1 -0
- package/lib/protocol/brand.d.ts +32 -0
- package/lib/protocol/brand.d.ts.map +1 -0
- package/lib/protocol/brand.js +25 -0
- package/lib/protocol/brand.js.map +1 -0
- package/lib/protocol/card.d.ts +43 -0
- package/lib/protocol/card.d.ts.map +1 -0
- package/lib/protocol/card.js +58 -0
- package/lib/protocol/card.js.map +1 -0
- package/lib/protocol/index.d.ts +23 -0
- package/lib/protocol/index.d.ts.map +1 -0
- package/lib/protocol/index.js +20 -0
- package/lib/protocol/index.js.map +1 -0
- package/lib/protocol/jsonrpc.d.ts +93 -0
- package/lib/protocol/jsonrpc.d.ts.map +1 -0
- package/lib/protocol/jsonrpc.js +81 -0
- package/lib/protocol/jsonrpc.js.map +1 -0
- package/lib/protocol/normalize.d.ts +72 -0
- package/lib/protocol/normalize.d.ts.map +1 -0
- package/lib/protocol/normalize.js +278 -0
- package/lib/protocol/normalize.js.map +1 -0
- package/lib/protocol/sse.d.ts +20 -0
- package/lib/protocol/sse.d.ts.map +1 -0
- package/lib/protocol/sse.js +23 -0
- package/lib/protocol/sse.js.map +1 -0
- package/lib/protocol/wire.d.ts +164 -0
- package/lib/protocol/wire.d.ts.map +1 -0
- package/lib/protocol/wire.js +26 -0
- package/lib/protocol/wire.js.map +1 -0
- package/lib/router.d.ts +56 -0
- package/lib/router.d.ts.map +1 -0
- package/lib/router.js +432 -0
- package/lib/router.js.map +1 -0
- package/lib/security.d.ts +89 -0
- package/lib/security.d.ts.map +1 -0
- package/lib/security.js +171 -0
- package/lib/security.js.map +1 -0
- package/lib/tasks.d.ts +75 -0
- package/lib/tasks.d.ts.map +1 -0
- package/lib/tasks.js +84 -0
- package/lib/tasks.js.map +1 -0
- package/lib/types.d.ts +71 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +17 -0
- package/lib/types.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `a2aTask` projection unit: task state read back from the session log.
|
|
3
|
+
*
|
|
4
|
+
* Without this, task state lives only in the process-local slot table, and
|
|
5
|
+
* `settleSlot` removes a slot the moment it settles — so a peer that polls
|
|
6
|
+
* `tasks/get` is told the task never existed, moments after it completed. That
|
|
7
|
+
* breaks the polling path A2A treats as the baseline update mechanism
|
|
8
|
+
* (`message/stream` and push notifications are both optional capabilities;
|
|
9
|
+
* `tasks/get` is not).
|
|
10
|
+
*
|
|
11
|
+
* The unit is a pure left fold over the `a2a/task` edges the server already
|
|
12
|
+
* appends. It holds no subscriptions: the registry drives every committed event
|
|
13
|
+
* through `apply` once, and the persisted projection cache turns a cold read
|
|
14
|
+
* into a cache row plus a tail replay rather than a full log load.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-a2a/projection
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
const STATES = [
|
|
20
|
+
'submitted', 'working', 'input-required', 'auth-required',
|
|
21
|
+
'completed', 'canceled', 'failed', 'rejected',
|
|
22
|
+
];
|
|
23
|
+
/** Validates the wire payload before it leaves the host. */
|
|
24
|
+
export const A2A_TASK_VIEW_SCHEMA = z.object({
|
|
25
|
+
tasks: z.record(z.string(), z.object({
|
|
26
|
+
taskId: z.string(),
|
|
27
|
+
peer: z.string(),
|
|
28
|
+
state: z.enum(STATES),
|
|
29
|
+
output: z.string().optional(),
|
|
30
|
+
stopReason: z.string().optional(),
|
|
31
|
+
updatedAt: z.string(),
|
|
32
|
+
})),
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* The projection definition, in the shape `ctx.sessionProjections.register()` wants.
|
|
36
|
+
*
|
|
37
|
+
* Declared as a plain object rather than built inside `apply()` so the fold can
|
|
38
|
+
* be unit-tested without a Cordis context or a session.
|
|
39
|
+
*/
|
|
40
|
+
export const a2aTaskProjection = {
|
|
41
|
+
key: 'a2aTask',
|
|
42
|
+
schema: A2A_TASK_VIEW_SCHEMA,
|
|
43
|
+
stateVersion: 1,
|
|
44
|
+
/**
|
|
45
|
+
* State for the empty log.
|
|
46
|
+
* @returns the initial state.
|
|
47
|
+
*/
|
|
48
|
+
init() {
|
|
49
|
+
return { tasks: {} };
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Fold one committed event.
|
|
53
|
+
*
|
|
54
|
+
* Returns the SAME reference for every event that is not an `a2a/task` edge:
|
|
55
|
+
* the drive gates its change feed on `Object.is`, so a fresh object here would
|
|
56
|
+
* wake every downstream consumer on every unrelated event in the session.
|
|
57
|
+
* @param state - the state covering all prior events.
|
|
58
|
+
* @param event - the next committed session event.
|
|
59
|
+
* @returns the next state, or `state` unchanged.
|
|
60
|
+
*/
|
|
61
|
+
apply(state, event) {
|
|
62
|
+
if (event.type !== 'a2a/task')
|
|
63
|
+
return state;
|
|
64
|
+
const data = event.data;
|
|
65
|
+
if (typeof data?.taskId !== 'string' || typeof data.state !== 'string')
|
|
66
|
+
return state;
|
|
67
|
+
const previous = state.tasks[data.taskId];
|
|
68
|
+
// Terminal states are final: a late edge must not reopen a settled task.
|
|
69
|
+
if (previous !== undefined && TERMINAL.has(previous.state))
|
|
70
|
+
return state;
|
|
71
|
+
return {
|
|
72
|
+
tasks: {
|
|
73
|
+
...state.tasks,
|
|
74
|
+
[data.taskId]: {
|
|
75
|
+
taskId: data.taskId,
|
|
76
|
+
peer: data.peer,
|
|
77
|
+
state: data.state,
|
|
78
|
+
...data.output === undefined ? {} : { output: data.output },
|
|
79
|
+
...data.stopReason === undefined ? {} : { stopReason: data.stopReason },
|
|
80
|
+
// The log has no wall-clock of its own, so the fold stamps when it
|
|
81
|
+
// observed the edge. A replay therefore restamps; consumers use this
|
|
82
|
+
// for `Task.status.timestamp`, which A2A treats as advisory.
|
|
83
|
+
updatedAt: new Date().toISOString(),
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* State → wire payload.
|
|
90
|
+
* @param state - the current state.
|
|
91
|
+
* @returns the whole current value.
|
|
92
|
+
*/
|
|
93
|
+
view(state) {
|
|
94
|
+
return { tasks: state.tasks };
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
const TERMINAL = new Set(['completed', 'canceled', 'failed', 'rejected']);
|
|
98
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AA0CvB,MAAM,MAAM,GAAG;IACb,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe;IACzD,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU;CACrC,CAAA;AAEV,4DAA4D;AAC5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC;QACnC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QACrB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACjC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC,CAAC;CACJ,CAAC,CAAA;AAiBF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,GAAG,EAAE,SAAkB;IACvB,MAAM,EAAE,oBAAoB;IAC5B,YAAY,EAAE,CAAC;IAEf;;;OAGG;IACH,IAAI;QACF,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;IACtB,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,KAAoB,EAAE,KAAmB;QAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;YAAE,OAAO,KAAK,CAAA;QAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,IAA2B,CAAA;QAC9C,IAAI,OAAO,IAAI,EAAE,MAAM,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QAEpF,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACzC,yEAAyE;QACzE,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QAExE,OAAO;YACL,KAAK,EAAE;gBACL,GAAG,KAAK,CAAC,KAAK;gBACd,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;oBACb,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,GAAG,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;oBAC3D,GAAG,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE;oBACvE,mEAAmE;oBACnE,qEAAqE;oBACrE,6DAA6D;oBAC7D,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBACpC;aACF;SACF,CAAA;IACH,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,KAAoB;QACvB,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAA;IAC/B,CAAC;CACF,CAAA;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAe,CAAC,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branded identifiers for the A2A wire vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* Branding keeps a raw string from being used where a checked id is required —
|
|
5
|
+
* the same discipline `dsh-session` applies to `SessionId`.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-a2a/protocol/brand
|
|
8
|
+
*/
|
|
9
|
+
declare const contextIdBrand: unique symbol;
|
|
10
|
+
declare const taskIdBrand: unique symbol;
|
|
11
|
+
/** An A2A `contextId`. This server mints it verbatim from a `SessionId`. */
|
|
12
|
+
export type A2AContextId = string & {
|
|
13
|
+
readonly [contextIdBrand]: true;
|
|
14
|
+
};
|
|
15
|
+
/** An A2A `Task.id`, minted per accepted message. */
|
|
16
|
+
export type A2ATaskId = string & {
|
|
17
|
+
readonly [taskIdBrand]: true;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Brand a raw string as a context id.
|
|
21
|
+
* @param value - the raw identifier.
|
|
22
|
+
* @returns the same string, branded.
|
|
23
|
+
*/
|
|
24
|
+
export declare function A2AContextId(value: string): A2AContextId;
|
|
25
|
+
/**
|
|
26
|
+
* Brand a raw string as a task id.
|
|
27
|
+
* @param value - the raw identifier.
|
|
28
|
+
* @returns the same string, branded.
|
|
29
|
+
*/
|
|
30
|
+
export declare function A2ATaskId(value: string): A2ATaskId;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=brand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/protocol/brand.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAA;AAC3C,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAA;AAExC,4EAA4E;AAC5E,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE,IAAI,CAAA;CAAE,CAAA;AAEvE,qDAAqD;AACrD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,IAAI,CAAA;CAAE,CAAA;AAEjE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAExD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAElD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branded identifiers for the A2A wire vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* Branding keeps a raw string from being used where a checked id is required —
|
|
5
|
+
* the same discipline `dsh-session` applies to `SessionId`.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-a2a/protocol/brand
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Brand a raw string as a context id.
|
|
11
|
+
* @param value - the raw identifier.
|
|
12
|
+
* @returns the same string, branded.
|
|
13
|
+
*/
|
|
14
|
+
export function A2AContextId(value) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Brand a raw string as a task id.
|
|
19
|
+
* @param value - the raw identifier.
|
|
20
|
+
* @returns the same string, branded.
|
|
21
|
+
*/
|
|
22
|
+
export function A2ATaskId(value) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=brand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/protocol/brand.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,KAAqB,CAAA;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,KAAkB,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Card construction.
|
|
3
|
+
*
|
|
4
|
+
* The card is the whole public product surface of an inbound-only A2A server:
|
|
5
|
+
* it is fetched anonymously, before any credential is presented. Skills are
|
|
6
|
+
* therefore whatever the deployment DECLARES, never a projection of the live
|
|
7
|
+
* tool registry — broadcasting the installed tool inventory to anyone who scans
|
|
8
|
+
* the port is information disclosure, not discovery.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-a2a/protocol/card
|
|
11
|
+
*/
|
|
12
|
+
import type { A2AAgentCard, A2AAgentSkill } from './wire.ts';
|
|
13
|
+
/** Everything the card renderer needs from the deployment. */
|
|
14
|
+
export interface CardInput {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
version: string;
|
|
18
|
+
/** The routable URL peers should post to; already resolved past any proxy. */
|
|
19
|
+
url: string;
|
|
20
|
+
protocolVersion: string;
|
|
21
|
+
provider?: {
|
|
22
|
+
organization: string;
|
|
23
|
+
url: string;
|
|
24
|
+
};
|
|
25
|
+
skills: A2AAgentSkill[];
|
|
26
|
+
streaming: boolean;
|
|
27
|
+
pushNotifications: boolean;
|
|
28
|
+
/** Whether the RPC endpoint requires a bearer credential (it always does). */
|
|
29
|
+
authRequired: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** The single skill advertised when a deployment declares none. */
|
|
32
|
+
export declare const FALLBACK_SKILL: A2AAgentSkill;
|
|
33
|
+
/**
|
|
34
|
+
* Build the Agent Card.
|
|
35
|
+
*
|
|
36
|
+
* Both interface spellings are emitted: `url` + `preferredTransport` for v0.3
|
|
37
|
+
* readers and `supportedInterfaces[]` for v1.0 readers. That costs a few bytes
|
|
38
|
+
* and removes an entire class of "peer could not find our endpoint" failure.
|
|
39
|
+
* @param input - the deployment-resolved card facts.
|
|
40
|
+
* @returns the card document to serve.
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildAgentCard(input: CardInput): A2AAgentCard;
|
|
43
|
+
//# sourceMappingURL=card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/protocol/card.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE5D,8DAA8D;AAC9D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,8EAA8E;IAC9E,GAAG,EAAE,MAAM,CAAA;IACX,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAChD,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,SAAS,EAAE,OAAO,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,8EAA8E;IAC9E,YAAY,EAAE,OAAO,CAAA;CACtB;AAED,mEAAmE;AACnE,eAAO,MAAM,cAAc,EAAE,aAK5B,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY,CA6B7D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Card construction.
|
|
3
|
+
*
|
|
4
|
+
* The card is the whole public product surface of an inbound-only A2A server:
|
|
5
|
+
* it is fetched anonymously, before any credential is presented. Skills are
|
|
6
|
+
* therefore whatever the deployment DECLARES, never a projection of the live
|
|
7
|
+
* tool registry — broadcasting the installed tool inventory to anyone who scans
|
|
8
|
+
* the port is information disclosure, not discovery.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-a2a/protocol/card
|
|
11
|
+
*/
|
|
12
|
+
/** The single skill advertised when a deployment declares none. */
|
|
13
|
+
export const FALLBACK_SKILL = {
|
|
14
|
+
id: 'general',
|
|
15
|
+
name: 'general',
|
|
16
|
+
description: 'General-purpose agent task execution.',
|
|
17
|
+
tags: ['general'],
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Build the Agent Card.
|
|
21
|
+
*
|
|
22
|
+
* Both interface spellings are emitted: `url` + `preferredTransport` for v0.3
|
|
23
|
+
* readers and `supportedInterfaces[]` for v1.0 readers. That costs a few bytes
|
|
24
|
+
* and removes an entire class of "peer could not find our endpoint" failure.
|
|
25
|
+
* @param input - the deployment-resolved card facts.
|
|
26
|
+
* @returns the card document to serve.
|
|
27
|
+
*/
|
|
28
|
+
export function buildAgentCard(input) {
|
|
29
|
+
const skills = input.skills.length > 0 ? input.skills : [FALLBACK_SKILL];
|
|
30
|
+
const card = {
|
|
31
|
+
protocolVersion: input.protocolVersion,
|
|
32
|
+
name: input.name,
|
|
33
|
+
description: input.description,
|
|
34
|
+
version: input.version,
|
|
35
|
+
url: input.url,
|
|
36
|
+
preferredTransport: 'JSONRPC',
|
|
37
|
+
supportedInterfaces: [{
|
|
38
|
+
url: input.url,
|
|
39
|
+
protocolBinding: 'JSONRPC',
|
|
40
|
+
protocolVersion: input.protocolVersion,
|
|
41
|
+
}],
|
|
42
|
+
capabilities: {
|
|
43
|
+
streaming: input.streaming,
|
|
44
|
+
pushNotifications: input.pushNotifications,
|
|
45
|
+
stateTransitionHistory: false,
|
|
46
|
+
},
|
|
47
|
+
defaultInputModes: ['text/plain'],
|
|
48
|
+
defaultOutputModes: ['text/plain'],
|
|
49
|
+
skills,
|
|
50
|
+
...input.provider === undefined ? {} : { provider: input.provider },
|
|
51
|
+
};
|
|
52
|
+
if (input.authRequired) {
|
|
53
|
+
card.securitySchemes = { bearer: { type: 'http', scheme: 'bearer' } };
|
|
54
|
+
card.security = [{ bearer: [] }];
|
|
55
|
+
}
|
|
56
|
+
return card;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.js","sourceRoot":"","sources":["../../src/protocol/card.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoBH,mEAAmE;AACnE,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,uCAAuC;IACpD,IAAI,EAAE,CAAC,SAAS,CAAC;CAClB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,KAAgB;IAC7C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAA;IACxE,MAAM,IAAI,GAAiB;QACzB,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,kBAAkB,EAAE,SAAS;QAC7B,mBAAmB,EAAE,CAAC;gBACpB,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,eAAe,EAAE,SAAS;gBAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;aACvC,CAAC;QACF,YAAY,EAAE;YACZ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;YAC1C,sBAAsB,EAAE,KAAK;SAC9B;QACD,iBAAiB,EAAE,CAAC,YAAY,CAAC;QACjC,kBAAkB,EAAE,CAAC,YAAY,CAAC;QAClC,MAAM;QACN,GAAG,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE;KACpE,CAAA;IACD,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAA;QACrE,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The A2A wire protocol as a dependency-free library.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here touches Cordis, HTTP, or the harness: it is types, framing,
|
|
5
|
+
* dialect normalization, and document construction, so the spec's own JSON
|
|
6
|
+
* examples can be used as golden tests without booting anything.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-a2a/protocol
|
|
9
|
+
*/
|
|
10
|
+
export { A2AContextId, A2ATaskId } from './brand.ts';
|
|
11
|
+
export type { A2AContextId as A2AContextIdType, A2ATaskId as A2ATaskIdType } from './brand.ts';
|
|
12
|
+
export { TERMINAL_STATES, isTerminal, } from './wire.ts';
|
|
13
|
+
export type { A2AAgentCard, A2AAgentSkill, A2AArtifact, A2ADataPart, A2ADialect, A2AFilePart, A2AMessage, A2AMessageSendConfiguration, A2AMessageSendParams, A2APart, A2APushNotificationConfig, A2ARole, A2AStreamEvent, A2ATask, A2ATaskArtifactUpdateEvent, A2ATaskState, A2ATaskStatus, A2ATaskStatusUpdateEvent, A2ATextPart, } from './wire.ts';
|
|
14
|
+
export { A2ARpcError, ERR_CONTENT_TYPE_NOT_SUPPORTED, ERR_INTERNAL, ERR_INVALID_PARAMS, ERR_INVALID_REQUEST, ERR_METHOD_NOT_FOUND, ERR_PARSE, ERR_PUSH_NOT_SUPPORTED, ERR_TASK_NOT_CANCELABLE, ERR_TASK_NOT_FOUND, ERR_UNSUPPORTED_OPERATION, invalidParams, jsonRpcError, jsonRpcResult, taskNotFound, } from './jsonrpc.ts';
|
|
15
|
+
export type { JsonRpcFailure, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccess } from './jsonrpc.ts';
|
|
16
|
+
export { parsePart, parseSendParams, partsToText, renderArtifactUpdate, renderStatusUpdate, renderTask, resolveMethod, } from './normalize.ts';
|
|
17
|
+
export type { A2AOperation } from './normalize.ts';
|
|
18
|
+
export { buildAgentCard, FALLBACK_SKILL } from './card.ts';
|
|
19
|
+
export type { CardInput } from './card.ts';
|
|
20
|
+
export { sseFrame } from './sse.ts';
|
|
21
|
+
/** ISO 8601 UTC with millisecond precision, the timestamp shape A2A uses. */
|
|
22
|
+
export declare function nowIso(): string;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACpD,YAAY,EAAE,YAAY,IAAI,gBAAgB,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAE9F,OAAO,EACL,eAAe,EACf,UAAU,GACX,MAAM,WAAW,CAAA;AAClB,YAAY,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,2BAA2B,EAC3B,oBAAoB,EACpB,OAAO,EACP,yBAAyB,EACzB,OAAO,EACP,cAAc,EACd,OAAO,EACP,0BAA0B,EAC1B,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,WAAW,GACZ,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,WAAW,EACX,8BAA8B,EAC9B,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAEnG,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,aAAa,GACd,MAAM,gBAAgB,CAAA;AACvB,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1D,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,6EAA6E;AAC7E,wBAAgB,MAAM,IAAI,MAAM,CAE/B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The A2A wire protocol as a dependency-free library.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here touches Cordis, HTTP, or the harness: it is types, framing,
|
|
5
|
+
* dialect normalization, and document construction, so the spec's own JSON
|
|
6
|
+
* examples can be used as golden tests without booting anything.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-a2a/protocol
|
|
9
|
+
*/
|
|
10
|
+
export { A2AContextId, A2ATaskId } from "./brand.js";
|
|
11
|
+
export { TERMINAL_STATES, isTerminal, } from "./wire.js";
|
|
12
|
+
export { A2ARpcError, ERR_CONTENT_TYPE_NOT_SUPPORTED, ERR_INTERNAL, ERR_INVALID_PARAMS, ERR_INVALID_REQUEST, ERR_METHOD_NOT_FOUND, ERR_PARSE, ERR_PUSH_NOT_SUPPORTED, ERR_TASK_NOT_CANCELABLE, ERR_TASK_NOT_FOUND, ERR_UNSUPPORTED_OPERATION, invalidParams, jsonRpcError, jsonRpcResult, taskNotFound, } from "./jsonrpc.js";
|
|
13
|
+
export { parsePart, parseSendParams, partsToText, renderArtifactUpdate, renderStatusUpdate, renderTask, resolveMethod, } from "./normalize.js";
|
|
14
|
+
export { buildAgentCard, FALLBACK_SKILL } from "./card.js";
|
|
15
|
+
export { sseFrame } from "./sse.js";
|
|
16
|
+
/** ISO 8601 UTC with millisecond precision, the timestamp shape A2A uses. */
|
|
17
|
+
export function nowIso() {
|
|
18
|
+
return new Date().toISOString();
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAGpD,OAAO,EACL,eAAe,EACf,UAAU,GACX,MAAM,WAAW,CAAA;AAuBlB,OAAO,EACL,WAAW,EACX,8BAA8B,EAC9B,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,cAAc,CAAA;AAGrB,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,aAAa,GACd,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAG1D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,6EAA6E;AAC7E,MAAM,UAAU,MAAM;IACpB,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 framing and the A2A error-code vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* Authentication, rate limiting, and the trust gate deliberately do NOT get
|
|
5
|
+
* JSON-RPC codes: A2A puts transport security at the HTTP layer, and the
|
|
6
|
+
* `-32050…` range some implementations invent is not reserved, so no peer SDK
|
|
7
|
+
* recognizes it. Those failures answer with an HTTP status whose body is still
|
|
8
|
+
* a valid JSON-RPC error envelope, so a client that blindly parses the body
|
|
9
|
+
* and one that reads the status are both served.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-a2a/protocol/jsonrpc
|
|
12
|
+
*/
|
|
13
|
+
/** Standard JSON-RPC 2.0 codes. */
|
|
14
|
+
export declare const ERR_PARSE = -32700;
|
|
15
|
+
export declare const ERR_INVALID_REQUEST = -32600;
|
|
16
|
+
export declare const ERR_METHOD_NOT_FOUND = -32601;
|
|
17
|
+
export declare const ERR_INVALID_PARAMS = -32602;
|
|
18
|
+
export declare const ERR_INTERNAL = -32603;
|
|
19
|
+
/** A2A-reserved codes, used only with their spec semantics. */
|
|
20
|
+
export declare const ERR_TASK_NOT_FOUND = -32001;
|
|
21
|
+
export declare const ERR_TASK_NOT_CANCELABLE = -32002;
|
|
22
|
+
export declare const ERR_PUSH_NOT_SUPPORTED = -32003;
|
|
23
|
+
export declare const ERR_UNSUPPORTED_OPERATION = -32004;
|
|
24
|
+
export declare const ERR_CONTENT_TYPE_NOT_SUPPORTED = -32005;
|
|
25
|
+
/** A JSON-RPC request as received from a peer. */
|
|
26
|
+
export interface JsonRpcRequest {
|
|
27
|
+
jsonrpc?: string;
|
|
28
|
+
id?: string | number | null;
|
|
29
|
+
method?: string;
|
|
30
|
+
params?: unknown;
|
|
31
|
+
}
|
|
32
|
+
/** A successful JSON-RPC response. */
|
|
33
|
+
export interface JsonRpcSuccess {
|
|
34
|
+
jsonrpc: '2.0';
|
|
35
|
+
id: string | number | null;
|
|
36
|
+
result: unknown;
|
|
37
|
+
}
|
|
38
|
+
/** A failed JSON-RPC response. */
|
|
39
|
+
export interface JsonRpcFailure {
|
|
40
|
+
jsonrpc: '2.0';
|
|
41
|
+
id: string | number | null;
|
|
42
|
+
error: {
|
|
43
|
+
code: number;
|
|
44
|
+
message: string;
|
|
45
|
+
data?: unknown;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Either shape of JSON-RPC response. */
|
|
49
|
+
export type JsonRpcResponse = JsonRpcSuccess | JsonRpcFailure;
|
|
50
|
+
/**
|
|
51
|
+
* Build a success envelope.
|
|
52
|
+
* @param id - the request id being answered.
|
|
53
|
+
* @param result - the method's result value.
|
|
54
|
+
* @returns the response envelope.
|
|
55
|
+
*/
|
|
56
|
+
export declare function jsonRpcResult(id: string | number | null, result: unknown): JsonRpcSuccess;
|
|
57
|
+
/**
|
|
58
|
+
* Build an error envelope.
|
|
59
|
+
* @param id - the request id being answered, or null when unknown.
|
|
60
|
+
* @param code - the JSON-RPC or A2A error code.
|
|
61
|
+
* @param message - a human-readable explanation carrying no internal paths.
|
|
62
|
+
* @param data - optional structured detail.
|
|
63
|
+
* @returns the response envelope.
|
|
64
|
+
*/
|
|
65
|
+
export declare function jsonRpcError(id: string | number | null, code: number, message: string, data?: unknown): JsonRpcFailure;
|
|
66
|
+
/** An error carrying the JSON-RPC code a handler wants reported. */
|
|
67
|
+
export declare class A2ARpcError extends Error {
|
|
68
|
+
readonly code: number;
|
|
69
|
+
readonly httpStatus: number;
|
|
70
|
+
/**
|
|
71
|
+
* @param code - the JSON-RPC or A2A error code.
|
|
72
|
+
* @param message - the human-readable explanation.
|
|
73
|
+
* @param httpStatus - the HTTP status to answer with; defaults to 200 because
|
|
74
|
+
* an ordinary JSON-RPC error is a successful HTTP exchange.
|
|
75
|
+
*/
|
|
76
|
+
constructor(code: number, message: string, httpStatus?: number);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reject a malformed or unsupported parameter.
|
|
80
|
+
* @param detail - what was wrong.
|
|
81
|
+
* @returns the error to throw.
|
|
82
|
+
*/
|
|
83
|
+
export declare function invalidParams(detail: string): A2ARpcError;
|
|
84
|
+
/**
|
|
85
|
+
* Report a task that does not exist, or that this identity may not see.
|
|
86
|
+
*
|
|
87
|
+
* A task owned by another peer answers with this same error rather than a 403,
|
|
88
|
+
* so a peer cannot probe which task ids exist by comparing responses.
|
|
89
|
+
* @param taskId - the id the peer asked about.
|
|
90
|
+
* @returns the error to throw.
|
|
91
|
+
*/
|
|
92
|
+
export declare function taskNotFound(taskId: string): A2ARpcError;
|
|
93
|
+
//# sourceMappingURL=jsonrpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc.d.ts","sourceRoot":"","sources":["../../src/protocol/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mCAAmC;AACnC,eAAO,MAAM,SAAS,SAAS,CAAA;AAC/B,eAAO,MAAM,mBAAmB,SAAS,CAAA;AACzC,eAAO,MAAM,oBAAoB,SAAS,CAAA;AAC1C,eAAO,MAAM,kBAAkB,SAAS,CAAA;AACxC,eAAO,MAAM,YAAY,SAAS,CAAA;AAElC,+DAA+D;AAC/D,eAAO,MAAM,kBAAkB,SAAS,CAAA;AACxC,eAAO,MAAM,uBAAuB,SAAS,CAAA;AAC7C,eAAO,MAAM,sBAAsB,SAAS,CAAA;AAC5C,eAAO,MAAM,yBAAyB,SAAS,CAAA;AAC/C,eAAO,MAAM,8BAA8B,SAAS,CAAA;AAEpD,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAA;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC1B,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAA;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC1B,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CACzD;AAED,yCAAyC;AACzC,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,cAAc,CAAA;AAE7D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,cAAc,CAEzF;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,OAAO,GACb,cAAc,CAEhB;AAED,oEAAoE;AACpE,qBAAa,WAAY,SAAQ,KAAK;IAQlC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAT7B;;;;;OAKG;gBAEQ,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,UAAU,GAAE,MAAY;CAKpC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAEzD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAExD"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 framing and the A2A error-code vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* Authentication, rate limiting, and the trust gate deliberately do NOT get
|
|
5
|
+
* JSON-RPC codes: A2A puts transport security at the HTTP layer, and the
|
|
6
|
+
* `-32050…` range some implementations invent is not reserved, so no peer SDK
|
|
7
|
+
* recognizes it. Those failures answer with an HTTP status whose body is still
|
|
8
|
+
* a valid JSON-RPC error envelope, so a client that blindly parses the body
|
|
9
|
+
* and one that reads the status are both served.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-a2a/protocol/jsonrpc
|
|
12
|
+
*/
|
|
13
|
+
/** Standard JSON-RPC 2.0 codes. */
|
|
14
|
+
export const ERR_PARSE = -32700;
|
|
15
|
+
export const ERR_INVALID_REQUEST = -32600;
|
|
16
|
+
export const ERR_METHOD_NOT_FOUND = -32601;
|
|
17
|
+
export const ERR_INVALID_PARAMS = -32602;
|
|
18
|
+
export const ERR_INTERNAL = -32603;
|
|
19
|
+
/** A2A-reserved codes, used only with their spec semantics. */
|
|
20
|
+
export const ERR_TASK_NOT_FOUND = -32001;
|
|
21
|
+
export const ERR_TASK_NOT_CANCELABLE = -32002;
|
|
22
|
+
export const ERR_PUSH_NOT_SUPPORTED = -32003;
|
|
23
|
+
export const ERR_UNSUPPORTED_OPERATION = -32004;
|
|
24
|
+
export const ERR_CONTENT_TYPE_NOT_SUPPORTED = -32005;
|
|
25
|
+
/**
|
|
26
|
+
* Build a success envelope.
|
|
27
|
+
* @param id - the request id being answered.
|
|
28
|
+
* @param result - the method's result value.
|
|
29
|
+
* @returns the response envelope.
|
|
30
|
+
*/
|
|
31
|
+
export function jsonRpcResult(id, result) {
|
|
32
|
+
return { jsonrpc: '2.0', id, result };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build an error envelope.
|
|
36
|
+
* @param id - the request id being answered, or null when unknown.
|
|
37
|
+
* @param code - the JSON-RPC or A2A error code.
|
|
38
|
+
* @param message - a human-readable explanation carrying no internal paths.
|
|
39
|
+
* @param data - optional structured detail.
|
|
40
|
+
* @returns the response envelope.
|
|
41
|
+
*/
|
|
42
|
+
export function jsonRpcError(id, code, message, data) {
|
|
43
|
+
return { jsonrpc: '2.0', id, error: { code, message, ...data === undefined ? {} : { data } } };
|
|
44
|
+
}
|
|
45
|
+
/** An error carrying the JSON-RPC code a handler wants reported. */
|
|
46
|
+
export class A2ARpcError extends Error {
|
|
47
|
+
code;
|
|
48
|
+
httpStatus;
|
|
49
|
+
/**
|
|
50
|
+
* @param code - the JSON-RPC or A2A error code.
|
|
51
|
+
* @param message - the human-readable explanation.
|
|
52
|
+
* @param httpStatus - the HTTP status to answer with; defaults to 200 because
|
|
53
|
+
* an ordinary JSON-RPC error is a successful HTTP exchange.
|
|
54
|
+
*/
|
|
55
|
+
constructor(code, message, httpStatus = 200) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.code = code;
|
|
58
|
+
this.httpStatus = httpStatus;
|
|
59
|
+
this.name = 'A2ARpcError';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reject a malformed or unsupported parameter.
|
|
64
|
+
* @param detail - what was wrong.
|
|
65
|
+
* @returns the error to throw.
|
|
66
|
+
*/
|
|
67
|
+
export function invalidParams(detail) {
|
|
68
|
+
return new A2ARpcError(ERR_INVALID_PARAMS, detail);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Report a task that does not exist, or that this identity may not see.
|
|
72
|
+
*
|
|
73
|
+
* A task owned by another peer answers with this same error rather than a 403,
|
|
74
|
+
* so a peer cannot probe which task ids exist by comparing responses.
|
|
75
|
+
* @param taskId - the id the peer asked about.
|
|
76
|
+
* @returns the error to throw.
|
|
77
|
+
*/
|
|
78
|
+
export function taskNotFound(taskId) {
|
|
79
|
+
return new A2ARpcError(ERR_TASK_NOT_FOUND, `task not found: ${taskId}`);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=jsonrpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc.js","sourceRoot":"","sources":["../../src/protocol/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mCAAmC;AACnC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAK,CAAA;AAC/B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,CAAA;AACzC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAA;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAA;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,CAAA;AAElC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAA;AACxC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAK,CAAA;AAC7C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAK,CAAA;AAC5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,KAAK,CAAA;AAC/C,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,KAAK,CAAA;AA2BpD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,EAA0B,EAAE,MAAe;IACvE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAA;AACvC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,EAA0B,EAC1B,IAAY,EACZ,OAAe,EACf,IAAc;IAEd,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;AAChG,CAAC;AAED,oEAAoE;AACpE,MAAM,OAAO,WAAY,SAAQ,KAAK;IAQzB;IAEA;IATX;;;;;OAKG;IACH,YACW,IAAY,EACrB,OAAe,EACN,aAAqB,GAAG;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAA;QAJL,SAAI,GAAJ,IAAI,CAAQ;QAEZ,eAAU,GAAV,UAAU,CAAc;QAGjC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,OAAO,IAAI,WAAW,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;AACpD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,WAAW,CAAC,kBAAkB,EAAE,mBAAmB,MAAM,EAAE,CAAC,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dialect normalization between A2A v0.3.0 and v1.0.
|
|
3
|
+
*
|
|
4
|
+
* Inbound is permissive, outbound is strict: a request in either spelling is
|
|
5
|
+
* parsed into the internal v0.3 shape, and the response is rendered back in the
|
|
6
|
+
* dialect that request declared. Nothing mixes the two spellings in one reply.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-a2a/protocol/normalize
|
|
9
|
+
*/
|
|
10
|
+
import type { A2ADialect, A2AMessageSendParams, A2APart, A2ATask, A2ATaskStatusUpdateEvent, A2ATaskArtifactUpdateEvent } from './wire.ts';
|
|
11
|
+
/** The internal operation a peer's method name resolves to. */
|
|
12
|
+
export type A2AOperation = 'send' | 'stream' | 'get' | 'cancel' | 'resubscribe' | 'push_set' | 'push_get' | 'push_list' | 'push_delete';
|
|
13
|
+
/** One row of the method table: which operation, and which dialect it implies. */
|
|
14
|
+
interface MethodEntry {
|
|
15
|
+
operation: A2AOperation;
|
|
16
|
+
dialect: A2ADialect;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a method name to its operation and implied dialect.
|
|
20
|
+
* @param method - the raw `method` string from the request.
|
|
21
|
+
* @returns the entry, or undefined for an unknown method.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveMethod(method: string): MethodEntry | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Read a `Part` written in any of the three known spellings.
|
|
26
|
+
*
|
|
27
|
+
* v0.3 discriminates on `kind`, v1.0 on member presence, and pre-0.3 peers used
|
|
28
|
+
* `type`. Unknown shapes yield undefined rather than throwing, so one odd part
|
|
29
|
+
* cannot fail a request whose other parts are usable.
|
|
30
|
+
* @param raw - one element of a `parts` array.
|
|
31
|
+
* @returns the normalized part, or undefined when unrecognizable.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parsePart(raw: unknown): A2APart | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Render every part as text the model can read.
|
|
36
|
+
*
|
|
37
|
+
* File and data parts become bracketed references rather than being dropped, so
|
|
38
|
+
* the agent knows something was attached and can ask about it. This is the same
|
|
39
|
+
* flattening `dsh-acp` applies to baseline resource links.
|
|
40
|
+
* @param parts - normalized parts, in order.
|
|
41
|
+
* @returns the joined text, empty when nothing rendered.
|
|
42
|
+
*/
|
|
43
|
+
export declare function partsToText(parts: readonly A2APart[]): string;
|
|
44
|
+
/**
|
|
45
|
+
* Parse `message/send` and `message/stream` parameters from either dialect.
|
|
46
|
+
* @param raw - the request's `params` value.
|
|
47
|
+
* @returns the normalized parameters, or undefined when the shape is unusable.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseSendParams(raw: unknown): A2AMessageSendParams | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Render a task in the requested dialect.
|
|
52
|
+
* @param task - the internal v0.3-shaped task.
|
|
53
|
+
* @param dialect - the dialect the peer spoke.
|
|
54
|
+
* @returns the wire object to serialize.
|
|
55
|
+
*/
|
|
56
|
+
export declare function renderTask(task: A2ATask, dialect: A2ADialect): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Render a status-update stream event in the requested dialect.
|
|
59
|
+
* @param event - the internal event.
|
|
60
|
+
* @param dialect - the dialect the peer spoke.
|
|
61
|
+
* @returns the wire object to serialize.
|
|
62
|
+
*/
|
|
63
|
+
export declare function renderStatusUpdate(event: A2ATaskStatusUpdateEvent, dialect: A2ADialect): unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Render an artifact-update stream event in the requested dialect.
|
|
66
|
+
* @param event - the internal event.
|
|
67
|
+
* @param dialect - the dialect the peer spoke.
|
|
68
|
+
* @returns the wire object to serialize.
|
|
69
|
+
*/
|
|
70
|
+
export declare function renderArtifactUpdate(event: A2ATaskArtifactUpdateEvent, dialect: A2ADialect): unknown;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/protocol/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,UAAU,EAGV,oBAAoB,EACpB,OAAO,EAEP,OAAO,EAEP,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,WAAW,CAAA;AAElB,+DAA+D;AAC/D,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,QAAQ,GACR,KAAK,GACL,QAAQ,GACR,aAAa,GACb,UAAU,GACV,UAAU,GACV,WAAW,GACX,aAAa,CAAA;AAEjB,kFAAkF;AAClF,UAAU,WAAW;IACnB,SAAS,EAAE,YAAY,CAAA;IACvB,OAAO,EAAE,UAAU,CAAA;CACpB;AAiCD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAErE;AAmBD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAsB3D;AAmCD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAc7D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAqC9E;AAcD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAOtE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,wBAAwB,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAGhG;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,0BAA0B,EACjC,OAAO,EAAE,UAAU,GAClB,OAAO,CAET"}
|