@agenticprimitives/a2a 0.0.0-alpha.2 → 0.0.0-alpha.20

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.
Files changed (121) hide show
  1. package/CLAUDE.md +58 -21
  2. package/bin/a2a-conform.mjs +17 -0
  3. package/dist/agent.d.ts +171 -3
  4. package/dist/agent.d.ts.map +1 -1
  5. package/dist/agent.js +346 -62
  6. package/dist/agent.js.map +1 -1
  7. package/dist/auth.d.ts +72 -9
  8. package/dist/auth.d.ts.map +1 -1
  9. package/dist/auth.js +62 -19
  10. package/dist/auth.js.map +1 -1
  11. package/dist/authority-extension.d.ts +58 -0
  12. package/dist/authority-extension.d.ts.map +1 -0
  13. package/dist/authority-extension.js +70 -0
  14. package/dist/authority-extension.js.map +1 -0
  15. package/dist/card-audience.d.ts +87 -0
  16. package/dist/card-audience.d.ts.map +1 -0
  17. package/dist/card-audience.js +135 -0
  18. package/dist/card-audience.js.map +1 -0
  19. package/dist/client.d.ts +20 -8
  20. package/dist/client.d.ts.map +1 -1
  21. package/dist/client.js +69 -14
  22. package/dist/client.js.map +1 -1
  23. package/dist/cloudflare/index.d.ts.map +1 -1
  24. package/dist/cloudflare/index.js +10 -2
  25. package/dist/cloudflare/index.js.map +1 -1
  26. package/dist/conform/index.d.ts +36 -0
  27. package/dist/conform/index.d.ts.map +1 -0
  28. package/dist/conform/index.js +232 -0
  29. package/dist/conform/index.js.map +1 -0
  30. package/dist/discovery.d.ts +4 -0
  31. package/dist/discovery.d.ts.map +1 -1
  32. package/dist/discovery.js +6 -2
  33. package/dist/discovery.js.map +1 -1
  34. package/dist/engagement.d.ts +37 -0
  35. package/dist/engagement.d.ts.map +1 -0
  36. package/dist/engagement.js +83 -0
  37. package/dist/engagement.js.map +1 -0
  38. package/dist/grant.d.ts +4 -2
  39. package/dist/grant.d.ts.map +1 -1
  40. package/dist/grant.js +21 -13
  41. package/dist/grant.js.map +1 -1
  42. package/dist/handoff.d.ts +42 -0
  43. package/dist/handoff.d.ts.map +1 -0
  44. package/dist/handoff.js +28 -0
  45. package/dist/handoff.js.map +1 -0
  46. package/dist/index.d.ts +24 -7
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +22 -3
  49. package/dist/index.js.map +1 -1
  50. package/dist/payment-gate.d.ts +88 -0
  51. package/dist/payment-gate.d.ts.map +1 -0
  52. package/dist/payment-gate.js +47 -0
  53. package/dist/payment-gate.js.map +1 -0
  54. package/dist/runtime.d.ts +13 -1
  55. package/dist/runtime.d.ts.map +1 -1
  56. package/dist/runtime.js +35 -10
  57. package/dist/runtime.js.map +1 -1
  58. package/dist/session-wire.d.ts +69 -0
  59. package/dist/session-wire.d.ts.map +1 -0
  60. package/dist/session-wire.js +170 -0
  61. package/dist/session-wire.js.map +1 -0
  62. package/dist/skill-handler.d.ts +26 -1
  63. package/dist/skill-handler.d.ts.map +1 -1
  64. package/dist/skill-handler.js.map +1 -1
  65. package/dist/standard/caller.d.ts +86 -0
  66. package/dist/standard/caller.d.ts.map +1 -0
  67. package/dist/standard/caller.js +159 -0
  68. package/dist/standard/caller.js.map +1 -0
  69. package/dist/standard/client.d.ts +50 -0
  70. package/dist/standard/client.d.ts.map +1 -0
  71. package/dist/standard/client.js +86 -0
  72. package/dist/standard/client.js.map +1 -0
  73. package/dist/standard/delegated.d.ts +119 -0
  74. package/dist/standard/delegated.d.ts.map +1 -0
  75. package/dist/standard/delegated.js +168 -0
  76. package/dist/standard/delegated.js.map +1 -0
  77. package/dist/standard/errors.d.ts +31 -0
  78. package/dist/standard/errors.d.ts.map +1 -0
  79. package/dist/standard/errors.js +75 -0
  80. package/dist/standard/errors.js.map +1 -0
  81. package/dist/standard/from-agent.d.ts +38 -0
  82. package/dist/standard/from-agent.d.ts.map +1 -0
  83. package/dist/standard/from-agent.js +109 -0
  84. package/dist/standard/from-agent.js.map +1 -0
  85. package/dist/standard/index.d.ts +9 -0
  86. package/dist/standard/index.d.ts.map +1 -0
  87. package/dist/standard/index.js +13 -0
  88. package/dist/standard/index.js.map +1 -0
  89. package/dist/standard/mount.d.ts +91 -0
  90. package/dist/standard/mount.d.ts.map +1 -0
  91. package/dist/standard/mount.js +181 -0
  92. package/dist/standard/mount.js.map +1 -0
  93. package/dist/standard/server.d.ts +105 -0
  94. package/dist/standard/server.d.ts.map +1 -0
  95. package/dist/standard/server.js +454 -0
  96. package/dist/standard/server.js.map +1 -0
  97. package/dist/standard/types.d.ts +186 -0
  98. package/dist/standard/types.d.ts.map +1 -0
  99. package/dist/standard/types.js +14 -0
  100. package/dist/standard/types.js.map +1 -0
  101. package/dist/subject-ask.d.ts +96 -0
  102. package/dist/subject-ask.d.ts.map +1 -0
  103. package/dist/subject-ask.js +45 -0
  104. package/dist/subject-ask.js.map +1 -0
  105. package/dist/subject-hop.d.ts +75 -0
  106. package/dist/subject-hop.d.ts.map +1 -0
  107. package/dist/subject-hop.js +170 -0
  108. package/dist/subject-hop.js.map +1 -0
  109. package/dist/task-store.d.ts +9 -3
  110. package/dist/task-store.d.ts.map +1 -1
  111. package/dist/task-store.js +12 -6
  112. package/dist/task-store.js.map +1 -1
  113. package/dist/wire-verify.d.ts +35 -0
  114. package/dist/wire-verify.d.ts.map +1 -0
  115. package/dist/wire-verify.js +51 -0
  116. package/dist/wire-verify.js.map +1 -0
  117. package/package.json +20 -6
  118. package/dist/jsonrpc.d.ts +0 -25
  119. package/dist/jsonrpc.d.ts.map +0 -1
  120. package/dist/jsonrpc.js +0 -52
  121. package/dist/jsonrpc.js.map +0 -1
@@ -0,0 +1,109 @@
1
+ import { AP_DELEGATED_TASK_EXTENSION, DELEGATED_TASK_CARD_EXTENSION, delegatedInput, delegatedTaskAsV1, isPartyToDelegatedTask, readDelegatedTask, toProfileMessage, } from './delegated.js';
2
+ import { wireToDelegation } from '../session-wire.js';
3
+ import { A2A_ERROR, A2aError, JSONRPC_ERROR } from './errors.js';
4
+ import { createMemoryPushStore, createStandardA2aServer, } from './server.js';
5
+ /** Project a runtime record into the 1.0 shape. */
6
+ export const recordAsV1 = (r) => delegatedTaskAsV1({
7
+ task: { taskId: r.task.taskId, state: r.task.state, assignee: r.task.assignee, permissionGrantRef: r.task.permissionGrantRef },
8
+ principal: r.principal, sender: r.sender, skill: r.skill,
9
+ inbound: (r.inbound ?? []).map((m) => ({ messageId: m.messageId, sender: m.sender, threadId: m.threadId, createdAt: m.createdAt, bodyRef: m.bodyRef, bodyHash: m.bodyHash })),
10
+ artifacts: (r.artifacts ?? []).map((a) => ({ artifactId: a.artifactId, artifactKind: a.artifactKind, bodyRef: a.bodyRef, bodyHash: a.contentHash })),
11
+ ...(r.error ? { error: r.error } : {}),
12
+ ...(r.rev !== undefined ? { rev: r.rev } : {}),
13
+ ...(r.updatedAt !== undefined ? { updatedAt: r.updatedAt } : {}),
14
+ });
15
+ /** A read-only `StandardTaskStore` over the runtime's own store, plus a writable side for tasks this
16
+ * server creates itself (a plain conversation). One `GetTask` answers from whichever holds the id. */
17
+ export function taskStoreOverAgent(runtime, own) {
18
+ return {
19
+ async get(id) {
20
+ const rec = /^0x[0-9a-fA-F]{64}$/.test(id) ? await runtime.get(id).catch(() => null) : null;
21
+ return rec ? recordAsV1(rec) : own.get(id);
22
+ },
23
+ put: (t) => own.put(t),
24
+ async all() {
25
+ const mine = await own.all();
26
+ if (!runtime.list)
27
+ return mine;
28
+ const theirs = (await runtime.list(200).catch(() => [])).map(recordAsV1);
29
+ return [...theirs, ...mine];
30
+ },
31
+ };
32
+ }
33
+ const REFUSES_PLAIN = 'this agent takes delegation-authorized tasks; carry the delegated-task extension on the message';
34
+ /**
35
+ * Build the ONE server this agent serves: A2A 1.0 methods, the delegation-authorized runtime behind
36
+ * `SendMessage`-with-extension, and an ordinary conversation behind `SendMessage` without one.
37
+ */
38
+ export function createAgentBackedServer(opts) {
39
+ const tasks = taskStoreOverAgent(opts.runtimeStore, opts.ownStore);
40
+ const card = {
41
+ ...opts.card,
42
+ capabilities: {
43
+ ...opts.card.capabilities,
44
+ extensions: [
45
+ ...(opts.card.capabilities.extensions ?? []).filter((e) => e.uri !== AP_DELEGATED_TASK_EXTENSION),
46
+ { ...DELEGATED_TASK_CARD_EXTENSION },
47
+ ],
48
+ },
49
+ };
50
+ return createStandardA2aServer({
51
+ card,
52
+ tasks,
53
+ push: opts.push ?? createMemoryPushStore(),
54
+ ...(opts.principal ? { principal: opts.principal } : {}),
55
+ ...(opts.versions ? { versions: opts.versions } : {}),
56
+ ...(opts.fetch ? { fetch: opts.fetch } : {}),
57
+ ...(opts.now ? { now: opts.now } : {}),
58
+ executor: opts.executor ?? { execute: async (ctx) => ctx.reject([{ text: REFUSES_PLAIN }]) },
59
+ // A delegated task is the RUNTIME's: it keeps its id, its states and its gates.
60
+ beforeSend: async ({ message, configuration }, principal) => {
61
+ const ext = readDelegatedTask(message);
62
+ if (ext === null)
63
+ return null; // an ordinary conversation
64
+ if ('error' in ext)
65
+ throw new A2aError(JSONRPC_ERROR.InvalidParams, ext.error);
66
+ // The caller at the door and the party the grant names must be the same agent. The runtime checks
67
+ // this too (delegate === requester); doing it here as well means an impostor never reaches it.
68
+ if (principal && ext.requester.toLowerCase() !== principal.agent.toLowerCase()) {
69
+ throw new A2aError(JSONRPC_ERROR.InvalidParams, `the delegated task names ${ext.requester} as its requester; you are calling as ${principal.agent}`);
70
+ }
71
+ const profileMessage = toProfileMessage(message, ext);
72
+ const params = {
73
+ // The wire carries `salt` as a decimal string; the runtime hashes a bigint.
74
+ delegation: wireToDelegation(ext.delegation),
75
+ requester: ext.requester,
76
+ message: profileMessage,
77
+ input: delegatedInput(message),
78
+ ...(configuration?.taskPushNotificationConfig?.url ? { pushConfig: { url: configuration.taskPushNotificationConfig.url, ...(configuration.taskPushNotificationConfig.token ? { token: configuration.taskPushNotificationConfig.token } : {}) } } : {}),
79
+ };
80
+ const r = ext.taskId
81
+ ? await opts.agent.resubmit({ ...params, taskId: ext.taskId })
82
+ : await opts.agent.messageSend(params);
83
+ if (!r.ok)
84
+ throw new A2aError(r.code === -32001 ? JSONRPC_ERROR.InvalidParams : r.code, r.message);
85
+ const rec = await opts.runtimeStore.get(r.result.taskId);
86
+ // The projection is the answer; falling back to a synthetic task would report a state nothing holds.
87
+ if (!rec)
88
+ throw new A2aError(A2A_ERROR.InvalidAgentResponse, `the runtime accepted task ${r.result.taskId} and the store does not hold it`);
89
+ return { task: recordAsV1(rec) };
90
+ },
91
+ onCancel: async (task, principal) => {
92
+ if (!isPartyToDelegatedTask(task, principal?.agent))
93
+ return null; // not the runtime's — the ordinary path
94
+ // The door authenticated this caller; the runtime re-runs the party test and nothing else.
95
+ const r = await opts.agent.tasksCancelAs({ taskId: task.id, caller: principal.agent });
96
+ if (!r.ok)
97
+ throw new A2aError(r.code, r.message);
98
+ const rec = await opts.runtimeStore.get(task.id);
99
+ return rec ? recordAsV1(rec) : null;
100
+ },
101
+ canSeeTask: async (task, principal, op) => {
102
+ const delegated = task.metadata?.[AP_DELEGATED_TASK_EXTENSION] !== undefined;
103
+ if (delegated)
104
+ return isPartyToDelegatedTask(task, principal?.agent);
105
+ return opts.canSeeOwnTask ? (await opts.canSeeOwnTask(task, principal)) === true : true;
106
+ },
107
+ });
108
+ }
109
+ //# sourceMappingURL=from-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from-agent.js","sourceRoot":"","sources":["../../src/standard/from-agent.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,2BAA2B,EAAE,6BAA6B,EAAE,cAAc,EAAE,iBAAiB,EAC7F,sBAAsB,EAAE,iBAAiB,EAAE,gBAAgB,GAC5D,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EACL,qBAAqB,EAAE,uBAAuB,GAE/C,MAAM,aAAa,CAAC;AAGrB,mDAAmD;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,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AM,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;YACjD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAS,CAAC,CAAC;YACxD,OAAO,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACtC,CAAC;QAED,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE;YACxC,MAAM,SAAS,GAAI,IAAI,CAAC,QAAgD,EAAE,CAAC,2BAA2B,CAAC,KAAK,SAAS,CAAC;YACtH,IAAI,SAAS;gBAAE,OAAO,sBAAsB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;YACrE,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1F,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export * from './server.js';
4
+ export * from './caller.js';
5
+ export * from './delegated.js';
6
+ export * from './from-agent.js';
7
+ export * from './client.js';
8
+ export * from './mount.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/standard/index.ts"],"names":[],"mappings":"AAEA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAG5B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,13 @@
1
+ // @agenticprimitives/a2a/standard — the A2A 1.0 standard surface (spec 372 S1), beside the delegation
2
+ // profile at the package root. A door for every A2A 1.0 client and the official TCK; never a grant.
3
+ export * from './types.js';
4
+ export * from './errors.js';
5
+ export * from './server.js';
6
+ export * from './caller.js';
7
+ export * from './delegated.js';
8
+ export * from './from-agent.js';
9
+ export * from './client.js';
10
+ // Spec 372 S2/S4, spec 399 §4 — mounting this surface in front of a harness: card fields, task-id shape, the
11
+ // one task view, the two admission schemes, delegated/engagement dispatch, the reply-kind → state table.
12
+ export * from './mount.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/standard/index.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,oGAAoG;AACpG,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,6GAA6G;AAC7G,yGAAyG;AACzG,cAAc,YAAY,CAAC"}
@@ -0,0 +1,91 @@
1
+ import type { Address } from 'viem';
2
+ import type { ExecutionContext, Principal, StandardServerConfig, StandardTaskStore } from './server.js';
3
+ import type { PartV1, TaskV1 } from './types.js';
4
+ /** The delegation runtime mints 32-byte hex task ids; a standard server's own conversational tasks are
5
+ * uuids. That is how a read knows which side holds a task — the shape is minted, not guessed. */
6
+ export declare const isRuntimeTaskId: (id: unknown) => boolean;
7
+ /** The text of a message's parts, joined; `data` parts that are strings count as text. */
8
+ export declare const partsText: (parts: PartV1[]) => string;
9
+ /** The first structured `data` part, or null. */
10
+ export declare const partsData: (parts: PartV1[]) => Record<string, unknown> | null;
11
+ /** Spec 390 W2 — the W3C Trace Context a request arrived with, as headers to forward on the next hop so the
12
+ * run's record keeps it. Ids only: nothing admits on these. */
13
+ export declare function traceHeadersOf(h: Headers): Record<string, string>;
14
+ export interface StandardCardFieldsOpts {
15
+ /** Where this surface takes A2A 1.0 JSON-RPC. */
16
+ messageUrl: string;
17
+ /** The card extensions this surface admits (default: the delegated-task and engagement extensions). */
18
+ extensions?: Array<{
19
+ uri: string;
20
+ [k: string]: unknown;
21
+ }>;
22
+ /** The bearer scheme a person presents (default: a Home session — it names the asking person and grants nothing). */
23
+ bearer?: {
24
+ name: string;
25
+ bearerFormat: string;
26
+ description: string;
27
+ };
28
+ }
29
+ /**
30
+ * The 1.0 fields a live card needs on top of what a runtime already builds: an interface with a protocol
31
+ * version, input/output modes, skills with names, the extensions this surface admits and the bearer scheme.
32
+ * Additive — every field the card carried stays; a released card (spec 347 §8) is served byte-for-byte and
33
+ * never passes through here.
34
+ */
35
+ export declare function withStandardCardFields(live: Record<string, unknown>, opts: StandardCardFieldsOpts): Record<string, unknown>;
36
+ /** A JSON-RPC call forwarded to the agent's own delegation runtime; the response comes back verbatim. */
37
+ export type DelegatedRpc = (agent: Address, rpc: unknown, principal: Principal | null) => Promise<{
38
+ result?: unknown;
39
+ error?: {
40
+ code: number;
41
+ message: string;
42
+ };
43
+ }>;
44
+ /**
45
+ * ONE TASK VIEW over two stores (spec 372 S4): a 32-byte hex id can only be the runtime's, so a read asks
46
+ * the object that owns it; anything else is a conversation this server made. A caller cannot tell, and
47
+ * must not have to. Writes go to the local store only — a delegated task is the runtime's to write.
48
+ */
49
+ export declare function runtimeBackedTaskStore(input: {
50
+ local: StandardTaskStore;
51
+ agent: Address;
52
+ rpc: DelegatedRpc;
53
+ }): StandardTaskStore;
54
+ /**
55
+ * What runs in front of `SendMessage` and `CancelTask` when the agent has a delegation runtime and/or answers
56
+ * engagement probes. A message carrying the DELEGATED-TASK extension is forwarded to the runtime, which keeps
57
+ * its own task id (two ids for one task would make `GetTask` a coin toss). An engagement PROBE is answered
58
+ * with a MESSAGE and no task (spec 336 §5) — the provider's own document — and only for a known caller who is
59
+ * the requester it names, addressed to this agent. A malformed engagement document is refused, never ignored.
60
+ */
61
+ export declare function delegatedDispatch(input: {
62
+ agent: Address;
63
+ rpc?: DelegatedRpc;
64
+ answerProbe?: (input: {
65
+ agent: Address;
66
+ probe: Record<string, unknown>;
67
+ caller: Principal | null;
68
+ }) => Promise<Record<string, unknown>>;
69
+ }): Pick<StandardServerConfig, 'beforeSend' | 'onCancel'>;
70
+ /** A delegated task is visible to its parties; a conversation, to whoever had it (its `asker`). A task
71
+ * nobody claimed is visible — the single-tenant shape. */
72
+ export declare function canSeeDelegatedOrOwnTask(task: TaskV1, principal: Principal | null): boolean;
73
+ /**
74
+ * TWO SCHEMES, ONE MECHANISM EACH (ADR-0013). `Bearer` is a PERSON's session; `A2A-Session` is an AGENT's
75
+ * session wire, verified on chain per request (spec 372 S3c). The scheme token selects which runs — neither
76
+ * is ever tried because the other failed, and each fails closed on its own terms. `first` is the product's
77
+ * own door (an in-process marker, say): it answers a principal, `null` to refuse, or `undefined` to say the
78
+ * request is not its to judge.
79
+ */
80
+ export declare function principalBySchemes(input: {
81
+ bearer: (token: string) => Promise<Principal | null>;
82
+ wire?: ((request: Request) => Promise<Principal | null>) | null;
83
+ first?: (request: Request) => Principal | null | undefined;
84
+ }): (request: Request) => Promise<Principal | null>;
85
+ /** The task state a harness reply's KIND maps to (spec 372 S4): a question parks as INPUT_REQUIRED, an act
86
+ * that needs a mandate as AUTH_REQUIRED, an answer or a done act completes, a refusal rejects, an error fails. */
87
+ export type ReplySettlement = 'completed' | 'input-required' | 'auth-required' | 'rejected' | 'failed';
88
+ export declare function settlementForReplyKind(kind: string | undefined): ReplySettlement;
89
+ /** Move the task to a settlement with the given parts. */
90
+ export declare function settleTask(ctx: ExecutionContext, settlement: ReplySettlement, parts: PartV1[]): Promise<void>;
91
+ //# sourceMappingURL=mount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/standard/mount.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,M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,CAAC;CAC5D,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAUlD;AAED;mHACmH;AACnH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,GAAG,UAAU,GAAG,QAAQ,CAAC;AACvG,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,CAShF;AAED,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,GAAG,EAAE,gBAAgB,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ7G"}
@@ -0,0 +1,181 @@
1
+ import { AP_ENGAGEMENT_EXTENSION_URI, ENGAGEMENT_CARD_EXTENSION, engagementOf, engagementResponseMessage } from '../engagement.js';
2
+ import { AP_DELEGATED_TASK_EXTENSION, DELEGATED_TASK_CARD_EXTENSION, isPartyToDelegatedTask, readDelegatedTask } from './delegated.js';
3
+ /** The delegation runtime mints 32-byte hex task ids; a standard server's own conversational tasks are
4
+ * uuids. That is how a read knows which side holds a task — the shape is minted, not guessed. */
5
+ export const isRuntimeTaskId = (id) => typeof id === 'string' && /^0x[0-9a-fA-F]{64}$/.test(id);
6
+ /** The text of a message's parts, joined; `data` parts that are strings count as text. */
7
+ export const partsText = (parts) => parts.map((p) => (typeof p.text === 'string' ? p.text : typeof p.data === 'string' ? p.data : '')).filter(Boolean).join('\n').trim();
8
+ /** The first structured `data` part, or null. */
9
+ export const partsData = (parts) => { const d = parts.find((p) => p.data && typeof p.data === 'object' && !Array.isArray(p.data)); return d ? d.data : null; };
10
+ /** Spec 390 W2 — the W3C Trace Context a request arrived with, as headers to forward on the next hop so the
11
+ * run's record keeps it. Ids only: nothing admits on these. */
12
+ export function traceHeadersOf(h) {
13
+ const out = {};
14
+ const tp = h.get('traceparent');
15
+ const ts = h.get('tracestate');
16
+ if (tp)
17
+ out.traceparent = tp;
18
+ if (ts)
19
+ out.tracestate = ts;
20
+ return out;
21
+ }
22
+ /**
23
+ * The 1.0 fields a live card needs on top of what a runtime already builds: an interface with a protocol
24
+ * version, input/output modes, skills with names, the extensions this surface admits and the bearer scheme.
25
+ * Additive — every field the card carried stays; a released card (spec 347 §8) is served byte-for-byte and
26
+ * never passes through here.
27
+ */
28
+ export function withStandardCardFields(live, opts) {
29
+ const skills = (Array.isArray(live.skills) ? live.skills : []);
30
+ const caps = (live.capabilities && typeof live.capabilities === 'object' ? live.capabilities : {});
31
+ const extensions = opts.extensions ?? [{ ...DELEGATED_TASK_CARD_EXTENSION }, { ...ENGAGEMENT_CARD_EXTENSION }];
32
+ const ours = new Set(extensions.map((e) => e.uri));
33
+ const bearer = opts.bearer ?? { name: 'homeSession', bearerFormat: 'home-session', description: 'A Home session presented as a bearer names the asking person; it grants nothing (spec 372 §0).' };
34
+ return {
35
+ ...live,
36
+ protocolVersion: '1.0',
37
+ supportedInterfaces: [{ url: opts.messageUrl, protocolBinding: 'JSONRPC', protocolVersion: '1.0' }],
38
+ // Honest flags: the standard server streams (SSE) and delivers push — the flags describe the surface a
39
+ // 1.0 client reaches by these methods.
40
+ capabilities: {
41
+ ...caps, streaming: true, pushNotifications: true, extendedAgentCard: false,
42
+ // The card SAYS how to authorize a task, so a peer learns it before calling rather than by failing.
43
+ extensions: [
44
+ ...(caps.extensions ?? []).filter((e) => !ours.has(e.uri) && e.uri !== AP_DELEGATED_TASK_EXTENSION && e.uri !== AP_ENGAGEMENT_EXTENSION_URI),
45
+ ...extensions,
46
+ ],
47
+ },
48
+ defaultInputModes: ['text/plain', 'application/json'],
49
+ defaultOutputModes: ['text/plain', 'application/json'],
50
+ skills: skills.map((s) => ({ id: s.id, name: s.name ?? s.id, description: s.description ?? s.name ?? s.id, tags: s.tags ?? [] })),
51
+ securitySchemes: { ...(live.securitySchemes ?? {}), [bearer.name]: { httpAuthSecurityScheme: { scheme: 'bearer', bearerFormat: bearer.bearerFormat, description: bearer.description } } },
52
+ securityRequirements: [{ schemes: { [bearer.name]: { list: [] } } }],
53
+ };
54
+ }
55
+ /**
56
+ * ONE TASK VIEW over two stores (spec 372 S4): a 32-byte hex id can only be the runtime's, so a read asks
57
+ * the object that owns it; anything else is a conversation this server made. A caller cannot tell, and
58
+ * must not have to. Writes go to the local store only — a delegated task is the runtime's to write.
59
+ */
60
+ export function runtimeBackedTaskStore(input) {
61
+ const { local, agent, rpc } = input;
62
+ return {
63
+ async get(id) {
64
+ if (!isRuntimeTaskId(id))
65
+ return local.get(id);
66
+ const r = await rpc(agent, { jsonrpc: '2.0', id: 1, method: 'GetTask', params: { id } }, null).catch(() => null);
67
+ return r?.result ?? null;
68
+ },
69
+ put: (t) => local.put(t),
70
+ async all() {
71
+ const own = await local.all();
72
+ const r = await rpc(agent, { jsonrpc: '2.0', id: 1, method: 'ListTasks', params: {} }, null).catch(() => null);
73
+ const theirs = (r?.result?.tasks ?? []);
74
+ return [...theirs, ...own];
75
+ },
76
+ };
77
+ }
78
+ const a2aError = (message, code) => Object.assign(new Error(message), { code, name: 'A2aError' });
79
+ /**
80
+ * What runs in front of `SendMessage` and `CancelTask` when the agent has a delegation runtime and/or answers
81
+ * engagement probes. A message carrying the DELEGATED-TASK extension is forwarded to the runtime, which keeps
82
+ * its own task id (two ids for one task would make `GetTask` a coin toss). An engagement PROBE is answered
83
+ * with a MESSAGE and no task (spec 336 §5) — the provider's own document — and only for a known caller who is
84
+ * the requester it names, addressed to this agent. A malformed engagement document is refused, never ignored.
85
+ */
86
+ export function delegatedDispatch(input) {
87
+ const { agent, rpc, answerProbe } = input;
88
+ if (!rpc && !answerProbe)
89
+ return {};
90
+ return {
91
+ beforeSend: async ({ message, configuration }, principal) => {
92
+ const eng = engagementOf(message);
93
+ if (eng && 'errors' in eng)
94
+ throw a2aError(`the engagement document is malformed: ${eng.errors.join('; ')}`, -32602);
95
+ if (eng && 'probe' in eng) {
96
+ if (!answerProbe)
97
+ throw a2aError('this agent does not answer engagement probes here', -32601);
98
+ if (!principal)
99
+ throw a2aError('a probe names its requester, and the caller must be known', -32001);
100
+ if (String(eng.probe.requester).toLowerCase() !== principal.agent.toLowerCase())
101
+ throw a2aError('the probe names a requester other than its caller', -32602);
102
+ if (String(eng.probe.candidate).toLowerCase() !== agent.toLowerCase())
103
+ throw a2aError('the probe is addressed to another agent', -32602);
104
+ const response = await answerProbe({ agent, probe: eng.probe, caller: principal });
105
+ return { message: engagementResponseMessage(response) };
106
+ }
107
+ if (eng && 'response' in eng)
108
+ throw a2aError('an engagement response is read by the requester that probed, not sent to it as a new message', -32602);
109
+ if (!rpc)
110
+ return null;
111
+ const ext = readDelegatedTask(message);
112
+ if (ext === null)
113
+ return null;
114
+ const r = await rpc(agent, { jsonrpc: '2.0', id: 1, method: 'SendMessage', params: { message, ...(configuration ? { configuration } : {}) } }, principal);
115
+ if (r.error)
116
+ throw a2aError(r.error.message, r.error.code);
117
+ return r.result ?? null;
118
+ },
119
+ onCancel: async (task, principal) => {
120
+ if (!isRuntimeTaskId(task.id) || !rpc)
121
+ return null;
122
+ const r = await rpc(agent, { jsonrpc: '2.0', id: 1, method: 'CancelTask', params: { id: task.id } }, principal);
123
+ if (r.error)
124
+ throw a2aError(r.error.message, r.error.code);
125
+ return r.result ?? null;
126
+ },
127
+ };
128
+ }
129
+ /** A delegated task is visible to its parties; a conversation, to whoever had it (its `asker`). A task
130
+ * nobody claimed is visible — the single-tenant shape. */
131
+ export function canSeeDelegatedOrOwnTask(task, principal) {
132
+ const delegated = task.metadata?.[AP_DELEGATED_TASK_EXTENSION] !== undefined;
133
+ if (delegated)
134
+ return isPartyToDelegatedTask(task, principal?.agent);
135
+ const asker = task.metadata?.asker;
136
+ return !asker || asker === principal?.agent;
137
+ }
138
+ /**
139
+ * TWO SCHEMES, ONE MECHANISM EACH (ADR-0013). `Bearer` is a PERSON's session; `A2A-Session` is an AGENT's
140
+ * session wire, verified on chain per request (spec 372 S3c). The scheme token selects which runs — neither
141
+ * is ever tried because the other failed, and each fails closed on its own terms. `first` is the product's
142
+ * own door (an in-process marker, say): it answers a principal, `null` to refuse, or `undefined` to say the
143
+ * request is not its to judge.
144
+ */
145
+ export function principalBySchemes(input) {
146
+ return async (request) => {
147
+ const own = input.first?.(request);
148
+ if (own !== undefined)
149
+ return own;
150
+ const auth = request.headers.get('authorization') ?? '';
151
+ if (/^A2A-Session\s/i.test(auth))
152
+ return input.wire ? input.wire(request) : null;
153
+ const token = /^Bearer\s+(.+)$/i.exec(auth)?.[1]?.trim();
154
+ if (!token)
155
+ return null;
156
+ return input.bearer(token).catch(() => null);
157
+ };
158
+ }
159
+ export function settlementForReplyKind(kind) {
160
+ switch (kind) {
161
+ case 'answer':
162
+ case 'done': return 'completed';
163
+ case 'prompt': return 'input-required';
164
+ case 'authority_required': return 'auth-required';
165
+ case 'refused':
166
+ case 'denied': return 'rejected';
167
+ case 'error': return 'failed';
168
+ default: return 'completed';
169
+ }
170
+ }
171
+ /** Move the task to a settlement with the given parts. */
172
+ export function settleTask(ctx, settlement, parts) {
173
+ switch (settlement) {
174
+ case 'completed': return ctx.complete(parts);
175
+ case 'input-required': return ctx.inputRequired(parts);
176
+ case 'auth-required': return ctx.authRequired(parts);
177
+ case 'rejected': return ctx.reject(parts);
178
+ case 'failed': return ctx.fail(parts);
179
+ }
180
+ }
181
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../../src/standard/mount.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnI,OAAO,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIvI;kGACkG;AAClG,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAW,EAAW,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,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/C,CAAC,CAAC;AACJ,CAAC;AAKD,MAAM,UAAU,sBAAsB,CAAC,IAAwB;IAC7D,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ,CAAC;QAAC,KAAK,MAAM,CAAC,CAAC,OAAO,WAAW,CAAC;QAC/C,KAAK,QAAQ,CAAC,CAAC,OAAO,gBAAgB,CAAC;QACvC,KAAK,oBAAoB,CAAC,CAAC,OAAO,eAAe,CAAC;QAClD,KAAK,SAAS,CAAC;QAAC,KAAK,QAAQ,CAAC,CAAC,OAAO,UAAU,CAAC;QACjD,KAAK,OAAO,CAAC,CAAC,OAAO,QAAQ,CAAC;QAC9B,OAAO,CAAC,CAAC,OAAO,WAAW,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CAAC,GAAqB,EAAE,UAA2B,EAAE,KAAe;IAC5F,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,WAAW,CAAC,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7C,KAAK,gBAAgB,CAAC,CAAC,OAAO,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACvD,KAAK,eAAe,CAAC,CAAC,OAAO,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACrD,KAAK,UAAU,CAAC,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,KAAK,QAAQ,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
@@ -0,0 +1,105 @@
1
+ import { type AgentCardV1, type ArtifactV1, type MessageV1, type PartV1, type SendMessageConfigurationV1, type TaskPushNotificationConfigV1, type TaskV1 } from './types.js';
2
+ export interface StandardTaskStore {
3
+ get(id: string): Promise<TaskV1 | null>;
4
+ put(task: TaskV1): Promise<void>;
5
+ /** Every task, newest status first. Filtering is the server's. */
6
+ all(): Promise<TaskV1[]>;
7
+ }
8
+ export interface PushConfigStore {
9
+ put(cfg: TaskPushNotificationConfigV1 & {
10
+ id: string;
11
+ taskId: string;
12
+ }): Promise<void>;
13
+ get(taskId: string, id: string): Promise<(TaskPushNotificationConfigV1 & {
14
+ id: string;
15
+ taskId: string;
16
+ }) | null>;
17
+ list(taskId: string): Promise<Array<TaskPushNotificationConfigV1 & {
18
+ id: string;
19
+ taskId: string;
20
+ }>>;
21
+ delete(taskId: string, id: string): Promise<boolean>;
22
+ }
23
+ export interface Principal {
24
+ agent: string;
25
+ [k: string]: unknown;
26
+ }
27
+ /** What an executor is handed: the message, the task as created, the admitted principal, and the ways it
28
+ * may move the task. Every call records on the task, fans out to subscribers and delivers to push configs. */
29
+ export interface ExecutionContext {
30
+ message: MessageV1;
31
+ task: TaskV1;
32
+ principal: Principal | null;
33
+ /** Spec 390 W2 — the request's headers, read-only, so an executor can carry W3C Trace Context
34
+ * (`traceparent` / `tracestate`) into the run it starts. Correlation only: nothing here admits. */
35
+ headers: Headers;
36
+ /** True while a client is streaming this run (`SendStreamingMessage`). */
37
+ streaming: boolean;
38
+ working(message?: PartV1[] | MessageV1): Promise<void>;
39
+ artifact(artifact: Omit<ArtifactV1, 'artifactId'> & {
40
+ artifactId?: string;
41
+ }, opts?: {
42
+ append?: boolean;
43
+ lastChunk?: boolean;
44
+ }): Promise<ArtifactV1>;
45
+ inputRequired(message?: PartV1[] | MessageV1): Promise<void>;
46
+ authRequired(message?: PartV1[] | MessageV1): Promise<void>;
47
+ complete(message?: PartV1[] | MessageV1): Promise<void>;
48
+ fail(message?: PartV1[] | MessageV1): Promise<void>;
49
+ reject(message?: PartV1[] | MessageV1): Promise<void>;
50
+ /** Reply with a MESSAGE and no task at all — only before any other event. */
51
+ reply(parts: PartV1[] | MessageV1): Promise<void>;
52
+ }
53
+ export interface StandardExecutor {
54
+ execute(ctx: ExecutionContext): Promise<void>;
55
+ /** Asked to stop a non-terminal task; the server marks it canceled either way. */
56
+ cancel?(task: TaskV1): Promise<void>;
57
+ }
58
+ export interface StandardServerConfig {
59
+ card: AgentCardV1;
60
+ executor: StandardExecutor;
61
+ tasks?: StandardTaskStore;
62
+ push?: PushConfigStore;
63
+ /** Admission: who is asking. Configured ⇒ a request resolving to nobody is 401 before any method runs. */
64
+ principal?: (request: Request) => Promise<Principal | null>;
65
+ /** `Major.Minor` versions served; default ['1.0']. A request naming another is -32009. */
66
+ versions?: string[];
67
+ /**
68
+ * Answer a `SendMessage` WITHOUT creating a task of this server's own (spec 372 S4). Returns the result
69
+ * to reply with, or `null` to let the ordinary path run. This is how a message that carries an extension
70
+ * routing it to another runtime keeps THAT runtime's task id: two ids for one task would make `GetTask`
71
+ * a coin toss.
72
+ */
73
+ beforeSend?: (params: {
74
+ message: MessageV1;
75
+ configuration?: SendMessageConfigurationV1;
76
+ }, principal: Principal | null) => Promise<{
77
+ task?: TaskV1;
78
+ message?: MessageV1;
79
+ } | null>;
80
+ /** Cancel a task this server did not create. Returns the updated task, or `null` to let the ordinary
81
+ * path run. */
82
+ onCancel?: (task: TaskV1, principal: Principal | null) => Promise<TaskV1 | null>;
83
+ /**
84
+ * May this principal see or act on this task (spec 372 S4)? Default: yes — the in-memory single-tenant
85
+ * shape the TCK's SUT runs. A deployment that carries other people's tasks MUST bind this: a delegated
86
+ * task has parties, and a `GetTask` from anyone else is answered TaskNotFound, never "forbidden" —
87
+ * telling a stranger that a task exists is itself a disclosure.
88
+ */
89
+ canSeeTask?: (task: TaskV1, principal: Principal | null, op: 'get' | 'cancel' | 'continue' | 'list' | 'push') => Promise<boolean> | boolean;
90
+ /** Served by `GetExtendedAgentCard` when `card.capabilities.extendedAgentCard` is true. */
91
+ extendedCard?: AgentCardV1;
92
+ /** Push delivery transport (default: global fetch). */
93
+ fetch?: typeof fetch;
94
+ now?: () => number;
95
+ /** How long a subscription to an IDLE non-terminal task stays open (default 60 s). */
96
+ idleSubscriptionMs?: number;
97
+ }
98
+ export interface StandardServer {
99
+ handle(request: Request): Promise<Response>;
100
+ card(): AgentCardV1;
101
+ }
102
+ export declare function createMemoryTaskStore(): StandardTaskStore;
103
+ export declare function createMemoryPushStore(): PushConfigStore;
104
+ export declare function createStandardA2aServer(config: StandardServerConfig): StandardServer;
105
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/standard/server.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,0BAA0B,EACxE,KAAK,4BAA4B,EAAoB,KAAK,MAAM,EACxF,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACxC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,kEAAkE;IAClE,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,GAAG,EAAE,4BAA4B,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvF,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,4BAA4B,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACjH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,4BAA4B,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;I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