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

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 +183 -3
  4. package/dist/agent.d.ts.map +1 -1
  5. package/dist/agent.js +361 -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 +23 -8
  20. package/dist/client.d.ts.map +1 -1
  21. package/dist/client.js +74 -13
  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 +121 -0
  74. package/dist/standard/delegated.d.ts.map +1 -0
  75. package/dist/standard/delegated.js +170 -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 +133 -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 +109 -0
  94. package/dist/standard/server.d.ts.map +1 -0
  95. package/dist/standard/server.js +459 -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,86 @@
1
+ import { TERMINAL_STATES } from './types.js';
2
+ async function sha256Hex(text) {
3
+ const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text));
4
+ return `0x${[...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, '0')).join('')}`;
5
+ }
6
+ /** The A2A 1.0 JSON-RPC endpoint a card publishes (top-level `protocolVersion` covers a released card's interfaces). */
7
+ export function jsonRpcEndpointOf(card) {
8
+ const top = /^1\./.test(String(card.protocolVersion ?? ''));
9
+ const hit = (card.supportedInterfaces ?? []).find((i) => i.protocolBinding === 'JSONRPC' && (/^1\./.test(String(i.protocolVersion ?? '')) || (i.protocolVersion === undefined && top)) && /^https:\/\//.test(String(i.url ?? '')));
10
+ return hit?.url ?? null;
11
+ }
12
+ /** Fetch a card, digest its bytes, read its endpoint. A card without a 1.x JSON-RPC interface is refused. */
13
+ export async function resolveAgentCard(cardUrl, fetchImpl = fetch, expectDigest) {
14
+ if (!/^https:\/\//.test(cardUrl))
15
+ throw new Error('an agent card is fetched over https only');
16
+ const res = await fetchImpl(cardUrl, { headers: { accept: 'application/json' } });
17
+ if (!res.ok)
18
+ throw new Error(`the card at ${cardUrl} answered ${res.status}`);
19
+ const text = await res.text();
20
+ let card;
21
+ try {
22
+ card = JSON.parse(text);
23
+ }
24
+ catch {
25
+ throw new Error(`the card at ${cardUrl} is not JSON`);
26
+ }
27
+ const cardDigest = await sha256Hex(text);
28
+ if (expectDigest && expectDigest.toLowerCase() !== cardDigest.toLowerCase())
29
+ throw new Error(`the card at ${cardUrl} is not the one pinned (${expectDigest.slice(0, 14)}… expected, ${cardDigest.slice(0, 14)}… served)`);
30
+ const endpoint = jsonRpcEndpointOf(card);
31
+ if (!endpoint)
32
+ throw new Error(`${card.name ?? cardUrl} publishes no A2A 1.x JSON-RPC interface`);
33
+ return { card, cardDigest, endpoint, cardUrl };
34
+ }
35
+ const hex32 = () => `0x${[...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, '0')).join('')}`;
36
+ export function createStandardA2aClient(o) {
37
+ const fetchImpl = o.fetch ?? fetch;
38
+ let seq = 0;
39
+ const rpc = async (method, params) => {
40
+ const res = await fetchImpl(o.endpoint, { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json', 'a2a-version': '1.0', ...(o.headers ?? {}) }, body: JSON.stringify({ jsonrpc: '2.0', id: ++seq, method, params }) });
41
+ const body = (await res.json().catch(() => null));
42
+ if (!body)
43
+ throw new Error(`${o.endpoint} answered ${res.status} with no JSON-RPC body`);
44
+ if ('error' in body)
45
+ throw new Error(`${o.endpoint} ${method}: ${body.error.code} ${body.error.message}`);
46
+ return body.result;
47
+ };
48
+ const textOf = (t, m) => {
49
+ const parts = [];
50
+ const take = (ps) => { for (const p of ps ?? [])
51
+ if (typeof p.text === 'string' && p.text.trim())
52
+ parts.push(p.text.trim()); };
53
+ take(m?.parts);
54
+ take(t?.status?.message?.parts);
55
+ for (const a of t?.artifacts ?? [])
56
+ take(a.parts);
57
+ return parts.join('\n');
58
+ };
59
+ const client = {
60
+ async sendMessage(parts, opts) {
61
+ const message = { messageId: hex32(), role: 'ROLE_USER', parts, ...(opts?.contextId ? { contextId: opts.contextId } : {}), ...(opts?.taskId ? { taskId: opts.taskId } : {}), ...(opts?.extensions ? { extensions: opts.extensions } : {}), ...(opts?.metadata ? { metadata: opts.metadata } : {}) };
62
+ return rpc('SendMessage', { message });
63
+ },
64
+ async getTask(id) { return rpc('GetTask', { id }); },
65
+ async awaitTask(id, opts) {
66
+ const deadline = Date.now() + (opts?.timeoutMs ?? 20_000);
67
+ let last = await client.getTask(id);
68
+ while (!TERMINAL_STATES.has(last.status.state) && last.status.state !== 'TASK_STATE_INPUT_REQUIRED' && last.status.state !== 'TASK_STATE_AUTH_REQUIRED' && Date.now() < deadline) {
69
+ await new Promise((r) => setTimeout(r, opts?.everyMs ?? 500));
70
+ last = await client.getTask(id);
71
+ }
72
+ return last;
73
+ },
74
+ async ask(text, opts) {
75
+ const sent = await client.sendMessage([{ text }], opts?.metadata ? { metadata: opts.metadata } : undefined);
76
+ if (sent.message)
77
+ return { text: textOf(undefined, sent.message), message: sent.message };
78
+ if (!sent.task)
79
+ throw new Error('the agent answered with neither a task nor a message');
80
+ const task = TERMINAL_STATES.has(sent.task.status.state) ? sent.task : await client.awaitTask(sent.task.id, { timeoutMs: opts?.timeoutMs });
81
+ return { text: textOf(task), task };
82
+ },
83
+ };
84
+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QACd,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI;YAClB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAC5G,IAAI,IAAI,CAAC,OAAO;gBAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1F,IAAI,CAAC,IAAI,CAAC,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;YACxF,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5I,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;QACtC,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,121 @@
1
+ import type { Hex } from 'viem';
2
+ import type { TaskState } from '@agenticprimitives/fulfillment';
3
+ import type { DelegationWireV1 } from '../session-wire.js';
4
+ import type { MessageV1, PartV1, TaskV1, TaskStateV1 } from './types.js';
5
+ export declare const AP_DELEGATED_TASK_EXTENSION = "https://agenticprimitives.org/a2a/delegated-task/v1";
6
+ /** What a `SendMessage` carries to create a delegation-authorized task. Rides in
7
+ * `message.metadata[AP_DELEGATED_TASK_EXTENSION]`, with the URI also listed in `message.extensions`. */
8
+ export interface DelegatedTaskV1 {
9
+ extension: typeof AP_DELEGATED_TASK_EXTENSION;
10
+ version: 1;
11
+ /** The grant that authorizes this task. Its delegate is the party the runtime checks against `requester`. */
12
+ delegation: DelegationWireV1;
13
+ /** The party the delegation was issued to — the principal's delegate, on whose behalf the task runs. */
14
+ requester: string;
15
+ /** The skill the receiving agent should run. Unknown ⇒ the task is rejected, as before. */
16
+ skill: string;
17
+ /** The SA that authored this message (signs the envelope). */
18
+ sender: string;
19
+ /** keccak over the input body — signed, and what binds `message.parts` to the signature. */
20
+ bodyHash: Hex;
21
+ /** Where the body will live in the assignee's vault. A placeholder the runtime overwrites with where it
22
+ * actually landed; not signed, because `bodyHash` is what binds the content. */
23
+ bodyRef: {
24
+ owner: string;
25
+ recordType: string;
26
+ };
27
+ /** The sender's signature over `hashA2aMessage(envelope)` — re-derived and re-checked by the runtime. */
28
+ signature: Hex;
29
+ /** Seconds since the epoch, as the sender wrote it into the signed envelope. */
30
+ createdAt: number;
31
+ /** An existing task to resubmit against (the auth-required loop): a fresh grant for a parked task. */
32
+ taskId?: Hex;
33
+ }
34
+ /** The exact envelope the runtime verifies — rebuilt from the 1.0 message plus the extension, so
35
+ * `hashA2aMessage` over it is byte-for-byte what the sender signed. */
36
+ export interface ProfileMessageV1 {
37
+ messageId: string;
38
+ threadId?: string;
39
+ sender: string;
40
+ skill: string;
41
+ bodyRef: {
42
+ owner: string;
43
+ recordType: string;
44
+ };
45
+ bodyHash: Hex;
46
+ signature: Hex;
47
+ createdAt: number;
48
+ }
49
+ /** Rebuild the signed envelope from what arrived on the 1.0 wire. */
50
+ export declare function toProfileMessage(message: MessageV1, ext: DelegatedTaskV1): ProfileMessageV1;
51
+ /** The declaration a card makes so a peer learns this agent takes delegated tasks before calling. */
52
+ export declare const DELEGATED_TASK_CARD_EXTENSION: {
53
+ readonly uri: "https://agenticprimitives.org/a2a/delegated-task/v1";
54
+ readonly required: false;
55
+ readonly description: "A task authorized by an ERC-7710 delegation carried on the message; the caller is authenticated by the Authorization header and must be the delegation's delegate. Adds the method GetTaskArtifact { id, artifactId } — a party reads an artifact BODY, which the task projection carries only as a ref and a hash (A2A-INV-04).";
56
+ };
57
+ /** The extension's one method beyond the core set: the artifact-body read a party is entitled to. */
58
+ export declare const GET_TASK_ARTIFACT_METHOD: "GetTaskArtifact";
59
+ /**
60
+ * Read the extension off a message. `null` when the message does not declare it — that is an ordinary
61
+ * conversational message, not an error. A message that DECLARES it and carries a malformed body is an
62
+ * error, and says which field: silently treating it as conversational would run the wrong executor under
63
+ * an authority the sender believed they had presented.
64
+ */
65
+ export declare function readDelegatedTask(message: MessageV1 | null | undefined): DelegatedTaskV1 | {
66
+ error: string;
67
+ } | null;
68
+ /** Attach the extension to a message a client is about to send. */
69
+ export declare function withDelegatedTask(message: MessageV1, req: Omit<DelegatedTaskV1, 'extension' | 'version'>): MessageV1;
70
+ /** The input body a delegated task carries: one data part, so the raw body hash the caller signed binds it. */
71
+ export declare const delegatedInputPart: (input: unknown) => PartV1;
72
+ /** Read the input back off a delegated message. */
73
+ export declare function delegatedInput(message: MessageV1): unknown;
74
+ /** The profile's task states are the 1.0 states under other names — one for one, no remainder. */
75
+ export declare const TASK_STATE_V1: Readonly<Record<TaskState, TaskStateV1>>;
76
+ /** The runtime's name for a 1.0 state. `TASK_STATE_UNSPECIFIED` has no runtime name and is a `failed`
77
+ * reading — a task in no state is not a task anyone should act on. */
78
+ export declare function taskStateFromV1(state: TaskStateV1 | string): TaskState;
79
+ /** What the projection needs from the runtime's record — structural, so this file imports no runtime. */
80
+ export interface DelegatedTaskSourceV1 {
81
+ task: {
82
+ taskId: string;
83
+ state: TaskState;
84
+ assignee: string;
85
+ permissionGrantRef?: string;
86
+ };
87
+ principal: string;
88
+ sender: string;
89
+ skill: string;
90
+ inbound?: Array<{
91
+ messageId: string;
92
+ sender: string;
93
+ threadId?: string;
94
+ createdAt?: number;
95
+ bodyRef?: unknown;
96
+ bodyHash?: string;
97
+ }>;
98
+ artifacts?: Array<{
99
+ artifactId: string;
100
+ artifactKind?: string;
101
+ bodyRef?: unknown;
102
+ bodyHash?: string;
103
+ }>;
104
+ error?: string;
105
+ rev?: number;
106
+ updatedAt?: number;
107
+ }
108
+ /**
109
+ * Project a delegation-authorized task into the A2A 1.0 shape a client reads.
110
+ *
111
+ * BODIES DO NOT COME ALONG (A2A-INV-04). A message body and an artifact body live in the assignee's vault;
112
+ * what travels is the REF and the hash, in `metadata`, exactly as the profile's `tasks/get` returned refs
113
+ * only. A party reads a body with the artifact op it was already entitled to use — the projection widens
114
+ * nothing, and inlining here would have quietly turned a ref into a disclosure.
115
+ */
116
+ export declare function delegatedTaskAsV1(src: DelegatedTaskSourceV1): TaskV1;
117
+ /** The parties to a delegated task: its sender, the principal they act for, and the assignee. A `GetTask`
118
+ * or `CancelTask` from anyone else is answered as though the task did not exist — telling a stranger that
119
+ * it does is itself a disclosure (the profile's own rule, kept). */
120
+ export declare function isPartyToDelegatedTask(task: TaskV1, agent: string | null | undefined): boolean;
121
+ //# sourceMappingURL=delegated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegated.d.ts","sourceRoot":"","sources":["../../src/standard/delegated.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAErF,eAAO,MAAM,2BAA2B,wDAAwD,CAAC;AAEjG;yGACyG;AACzG,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,OAAO,2BAA2B,CAAC;IAC9C,OAAO,EAAE,CAAC,CAAC;IACX,6GAA6G;IAC7G,UAAU,EAAE,gBAAgB,CAAC;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CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,qBAAqB,GAAG,MAAM,CAqCpE;AAED;;qEAEqE;AACrE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAO9F"}
@@ -0,0 +1,170 @@
1
+ export const AP_DELEGATED_TASK_EXTENSION = 'https://agenticprimitives.org/a2a/delegated-task/v1';
2
+ /** Rebuild the signed envelope from what arrived on the 1.0 wire. */
3
+ export function toProfileMessage(message, ext) {
4
+ return {
5
+ messageId: message.messageId,
6
+ ...(message.contextId ? { threadId: message.contextId } : {}),
7
+ sender: ext.sender,
8
+ skill: ext.skill,
9
+ bodyRef: ext.bodyRef,
10
+ bodyHash: ext.bodyHash,
11
+ signature: ext.signature,
12
+ createdAt: ext.createdAt,
13
+ };
14
+ }
15
+ /** The declaration a card makes so a peer learns this agent takes delegated tasks before calling. */
16
+ export const DELEGATED_TASK_CARD_EXTENSION = {
17
+ uri: AP_DELEGATED_TASK_EXTENSION,
18
+ required: false,
19
+ description: 'A task authorized by an ERC-7710 delegation carried on the message; the caller is authenticated by the Authorization header and must be the delegation\'s delegate. Adds the method GetTaskArtifact { id, artifactId } — a party reads an artifact BODY, which the task projection carries only as a ref and a hash (A2A-INV-04).',
20
+ };
21
+ /** The extension's one method beyond the core set: the artifact-body read a party is entitled to. */
22
+ export const GET_TASK_ARTIFACT_METHOD = 'GetTaskArtifact';
23
+ const isWire = (d) => {
24
+ const w = d;
25
+ return !!w && typeof w === 'object'
26
+ && typeof w.delegator === 'string' && /^0x[0-9a-fA-F]{40}$/.test(w.delegator)
27
+ && typeof w.delegate === 'string' && /^0x[0-9a-fA-F]{40}$/.test(w.delegate)
28
+ && typeof w.authority === 'string' && Array.isArray(w.caveats)
29
+ && (typeof w.salt === 'string' || typeof w.salt === 'number')
30
+ && typeof w.signature === 'string';
31
+ };
32
+ /**
33
+ * Read the extension off a message. `null` when the message does not declare it — that is an ordinary
34
+ * conversational message, not an error. A message that DECLARES it and carries a malformed body is an
35
+ * error, and says which field: silently treating it as conversational would run the wrong executor under
36
+ * an authority the sender believed they had presented.
37
+ */
38
+ export function readDelegatedTask(message) {
39
+ // No message at all is not this extension's business: the server's own validation says what is missing.
40
+ if (!message || typeof message !== 'object')
41
+ return null;
42
+ const declared = (message.extensions ?? []).includes(AP_DELEGATED_TASK_EXTENSION);
43
+ const raw = message.metadata?.[AP_DELEGATED_TASK_EXTENSION];
44
+ if (!declared && raw === undefined)
45
+ return null;
46
+ if (raw === undefined)
47
+ return { error: `message declares ${AP_DELEGATED_TASK_EXTENSION} and carries no metadata under it` };
48
+ const d = raw;
49
+ if (!isWire(d.delegation))
50
+ return { error: 'delegated-task: `delegation` is not a delegation wire' };
51
+ if (typeof d.skill !== 'string' || !d.skill.trim())
52
+ return { error: 'delegated-task: `skill` is required' };
53
+ const addr = (v) => typeof v === 'string' && /^0x[0-9a-fA-F]{40}$/.test(v);
54
+ if (!addr(d.requester))
55
+ return { error: 'delegated-task: `requester` must be an address' };
56
+ if (!addr(d.sender))
57
+ return { error: 'delegated-task: `sender` must be an address' };
58
+ if (typeof d.bodyHash !== 'string' || !/^0x[0-9a-fA-F]{64}$/.test(d.bodyHash))
59
+ return { error: 'delegated-task: `bodyHash` must be a 32-byte hash' };
60
+ if (!d.bodyRef || typeof d.bodyRef !== 'object' || !addr(d.bodyRef.owner))
61
+ return { error: 'delegated-task: `bodyRef.owner` must be an address' };
62
+ if (typeof d.signature !== 'string' || !d.signature.startsWith('0x'))
63
+ return { error: 'delegated-task: `signature` is required — the runtime re-derives the digest and checks it' };
64
+ if (typeof d.createdAt !== 'number' || !Number.isFinite(d.createdAt))
65
+ return { error: 'delegated-task: `createdAt` must be a number of seconds' };
66
+ if (d.taskId !== undefined && !/^0x[0-9a-fA-F]{64}$/.test(String(d.taskId)))
67
+ return { error: 'delegated-task: `taskId` must be a 32-byte hex id' };
68
+ // 1.0 lets a messageId be any string; the signed envelope's is a 32-byte hex, because that is what
69
+ // `hashA2aMessage` encodes. Caught here so the sender is told, rather than the digest failing to build.
70
+ if (!/^0x[0-9a-fA-F]{64}$/.test(message.messageId ?? ''))
71
+ return { error: 'delegated-task: `message.messageId` must be a 32-byte hex id — it is part of the signed envelope' };
72
+ return {
73
+ extension: AP_DELEGATED_TASK_EXTENSION, version: 1,
74
+ delegation: d.delegation, requester: d.requester, skill: d.skill.trim(),
75
+ sender: d.sender, bodyHash: d.bodyHash,
76
+ bodyRef: d.bodyRef, signature: d.signature,
77
+ createdAt: d.createdAt, ...(d.taskId ? { taskId: d.taskId } : {}),
78
+ };
79
+ }
80
+ /** Attach the extension to a message a client is about to send. */
81
+ export function withDelegatedTask(message, req) {
82
+ return {
83
+ ...message,
84
+ extensions: [...new Set([...(message.extensions ?? []), AP_DELEGATED_TASK_EXTENSION])],
85
+ metadata: { ...(message.metadata ?? {}), [AP_DELEGATED_TASK_EXTENSION]: { extension: AP_DELEGATED_TASK_EXTENSION, version: 1, ...req } },
86
+ };
87
+ }
88
+ /** The input body a delegated task carries: one data part, so the raw body hash the caller signed binds it. */
89
+ export const delegatedInputPart = (input) => ({ data: input ?? null });
90
+ /** Read the input back off a delegated message. */
91
+ export function delegatedInput(message) {
92
+ const part = (message.parts ?? []).find((p) => p.data !== undefined);
93
+ return part ? part.data : null;
94
+ }
95
+ /** The profile's task states are the 1.0 states under other names — one for one, no remainder. */
96
+ export const TASK_STATE_V1 = {
97
+ submitted: 'TASK_STATE_SUBMITTED',
98
+ working: 'TASK_STATE_WORKING',
99
+ completed: 'TASK_STATE_COMPLETED',
100
+ failed: 'TASK_STATE_FAILED',
101
+ canceled: 'TASK_STATE_CANCELED',
102
+ 'input-required': 'TASK_STATE_INPUT_REQUIRED',
103
+ rejected: 'TASK_STATE_REJECTED',
104
+ 'auth-required': 'TASK_STATE_AUTH_REQUIRED',
105
+ };
106
+ const V1_TO_STATE = Object.fromEntries(Object.entries(TASK_STATE_V1).map(([k, v]) => [v, k]));
107
+ /** The runtime's name for a 1.0 state. `TASK_STATE_UNSPECIFIED` has no runtime name and is a `failed`
108
+ * reading — a task in no state is not a task anyone should act on. */
109
+ export function taskStateFromV1(state) {
110
+ return V1_TO_STATE[state] ?? 'failed';
111
+ }
112
+ /**
113
+ * Project a delegation-authorized task into the A2A 1.0 shape a client reads.
114
+ *
115
+ * BODIES DO NOT COME ALONG (A2A-INV-04). A message body and an artifact body live in the assignee's vault;
116
+ * what travels is the REF and the hash, in `metadata`, exactly as the profile's `tasks/get` returned refs
117
+ * only. A party reads a body with the artifact op it was already entitled to use — the projection widens
118
+ * nothing, and inlining here would have quietly turned a ref into a disclosure.
119
+ */
120
+ export function delegatedTaskAsV1(src) {
121
+ const at = new Date(src.updatedAt ?? Date.now()).toISOString();
122
+ const history = (src.inbound ?? []).map((m) => ({
123
+ messageId: m.messageId,
124
+ role: 'ROLE_USER',
125
+ parts: [{ data: { bodyRef: m.bodyRef ?? null, bodyHash: m.bodyHash ?? null } }],
126
+ contextId: m.threadId ?? src.task.taskId,
127
+ taskId: src.task.taskId,
128
+ metadata: { sender: m.sender, ...(m.createdAt ? { createdAt: m.createdAt } : {}) },
129
+ }));
130
+ const artifacts = (src.artifacts ?? []).map((a) => ({
131
+ artifactId: a.artifactId,
132
+ ...(a.artifactKind ? { name: a.artifactKind } : {}),
133
+ parts: [{ data: { bodyRef: a.bodyRef ?? null, bodyHash: a.bodyHash ?? null } }],
134
+ metadata: { residency: 'vault', note: 'the body lives in the assignee\'s vault; read it with the artifact op' },
135
+ }));
136
+ return {
137
+ id: src.task.taskId,
138
+ contextId: (src.inbound ?? [])[0]?.threadId ?? src.task.taskId,
139
+ status: {
140
+ state: TASK_STATE_V1[src.task.state],
141
+ timestamp: at,
142
+ ...(src.error ? { message: { messageId: `${src.task.taskId}:error`, role: 'ROLE_AGENT', parts: [{ text: src.error }], contextId: src.task.taskId, taskId: src.task.taskId } } : {}),
143
+ },
144
+ ...(artifacts.length ? { artifacts } : {}),
145
+ ...(history.length ? { history } : {}),
146
+ metadata: {
147
+ [AP_DELEGATED_TASK_EXTENSION]: {
148
+ skill: src.skill,
149
+ principal: src.principal,
150
+ sender: src.sender,
151
+ assignee: src.task.assignee,
152
+ ...(src.task.permissionGrantRef ? { permissionGrantRef: src.task.permissionGrantRef } : {}),
153
+ ...(src.rev !== undefined ? { rev: src.rev } : {}),
154
+ },
155
+ },
156
+ };
157
+ }
158
+ /** The parties to a delegated task: its sender, the principal they act for, and the assignee. A `GetTask`
159
+ * or `CancelTask` from anyone else is answered as though the task did not exist — telling a stranger that
160
+ * it does is itself a disclosure (the profile's own rule, kept). */
161
+ export function isPartyToDelegatedTask(task, agent) {
162
+ if (!agent)
163
+ return false;
164
+ const m = task.metadata?.[AP_DELEGATED_TASK_EXTENSION];
165
+ if (!m)
166
+ return false;
167
+ const who = agent.toLowerCase();
168
+ return [m.principal, m.sender, m.assignee].some((a) => typeof a === 'string' && a.toLowerCase() === who);
169
+ }
170
+ //# sourceMappingURL=delegated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegated.js","sourceRoot":"","sources":["../../src/standard/delegated.ts"],"names":[],"mappings":"AA6BA,MAAM,CAAC,MAAM,2BAA2B,GAAG,qDAAqD,CAAC;AAyCjG,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAAC,OAAkB,EAAE,GAAoB;IACvE,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,QAAQ,EAAE,GAAG,CAAC,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,QAAQ,EAAE;YACR,CAAC,2BAA2B,CAAC,EAAE;gBAC7B,KAAK,EAAE,GAAG,CAAC,KAAK;gBAChB,SAAS,EAAE,GAAG,CAAC,SAAS;gBACxB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ;gBAC3B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3F,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACnD;SACF;KACF,CAAC;AACJ,CAAC;AAED;;qEAEqE;AACrE,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAE,KAAgC;IACnF,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,MAAM,CAAC,GAAI,IAAI,CAAC,QAAgD,EAAE,CAAC,2BAA2B,CACtB,CAAC;IACzE,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrB,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAChC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,CAAC;AAC3G,CAAC"}
@@ -0,0 +1,31 @@
1
+ export declare const A2A_ERROR: {
2
+ readonly TaskNotFound: -32001;
3
+ readonly TaskNotCancelable: -32002;
4
+ readonly PushNotificationNotSupported: -32003;
5
+ readonly UnsupportedOperation: -32004;
6
+ readonly ContentTypeNotSupported: -32005;
7
+ readonly InvalidAgentResponse: -32006;
8
+ readonly ExtendedAgentCardNotConfigured: -32007;
9
+ readonly ExtensionSupportRequired: -32008;
10
+ readonly VersionNotSupported: -32009;
11
+ };
12
+ export declare const JSONRPC_ERROR: {
13
+ readonly ParseError: -32700;
14
+ readonly InvalidRequest: -32600;
15
+ readonly MethodNotFound: -32601;
16
+ readonly InvalidParams: -32602;
17
+ readonly Internal: -32603;
18
+ };
19
+ export declare class A2aError extends Error {
20
+ readonly code: number;
21
+ readonly metadata?: Record<string, string> | undefined;
22
+ constructor(code: number, message?: string, metadata?: Record<string, string> | undefined);
23
+ }
24
+ export interface JsonRpcErrorObject {
25
+ code: number;
26
+ message: string;
27
+ data?: unknown;
28
+ }
29
+ /** The JSON-RPC error object for an error: A2A-specific codes carry ErrorInfo in a `data` array. */
30
+ export declare function toJsonRpcError(e: unknown): JsonRpcErrorObject;
31
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/standard/errors.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,SAAS;;;;;;;;;;CAUZ,CAAC;AAEX,eAAO,MAAM,aAAa;;;;;;CAMhB,CAAC;AA+BX,qBAAa,QAAS,SAAQ,KAAK;aACL,IAAI,EAAE,MAAM;aAAoC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;gBAAjF,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAkB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,YAAA;CAI9G;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,oGAAoG;AACpG,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAY7D"}
@@ -0,0 +1,75 @@
1
+ // A2A 1.0 ERRORS ON THE JSON-RPC BINDING — spec 372 S1 (A2A spec §5.4 + §9.5).
2
+ //
3
+ // Every A2A-specific error carries a `google.rpc.ErrorInfo` in `error.data[]`: the reason in UPPER_SNAKE
4
+ // without the "Error" suffix, the domain `a2a-protocol.org`. A client that only reads the code still gets
5
+ // the standard number; one that reads the data learns which task, which version, which content type.
6
+ export const A2A_ERROR = {
7
+ TaskNotFound: -32001,
8
+ TaskNotCancelable: -32002,
9
+ PushNotificationNotSupported: -32003,
10
+ UnsupportedOperation: -32004,
11
+ ContentTypeNotSupported: -32005,
12
+ InvalidAgentResponse: -32006,
13
+ ExtendedAgentCardNotConfigured: -32007,
14
+ ExtensionSupportRequired: -32008,
15
+ VersionNotSupported: -32009,
16
+ };
17
+ export const JSONRPC_ERROR = {
18
+ ParseError: -32700,
19
+ InvalidRequest: -32600,
20
+ MethodNotFound: -32601,
21
+ InvalidParams: -32602,
22
+ Internal: -32603,
23
+ };
24
+ const REASON = {
25
+ [-32001]: 'TASK_NOT_FOUND',
26
+ [-32002]: 'TASK_NOT_CANCELABLE',
27
+ [-32003]: 'PUSH_NOTIFICATION_NOT_SUPPORTED',
28
+ [-32004]: 'UNSUPPORTED_OPERATION',
29
+ [-32005]: 'CONTENT_TYPE_NOT_SUPPORTED',
30
+ [-32006]: 'INVALID_AGENT_RESPONSE',
31
+ [-32007]: 'EXTENDED_AGENT_CARD_NOT_CONFIGURED',
32
+ [-32008]: 'EXTENSION_SUPPORT_REQUIRED',
33
+ [-32009]: 'VERSION_NOT_SUPPORTED',
34
+ };
35
+ const MESSAGE = {
36
+ [-32001]: 'Task not found',
37
+ [-32002]: 'Task cannot be canceled',
38
+ [-32003]: 'Push notifications are not supported',
39
+ [-32004]: 'This operation is not supported',
40
+ [-32005]: 'Incompatible content types',
41
+ [-32006]: 'Invalid agent response',
42
+ [-32007]: 'Extended agent card is not configured',
43
+ [-32008]: 'A required extension is not supported',
44
+ [-32009]: 'Unsupported A2A protocol version',
45
+ [-32700]: 'Invalid JSON payload',
46
+ [-32600]: 'Request payload validation error',
47
+ [-32601]: 'Method not found',
48
+ [-32602]: 'Invalid parameters',
49
+ [-32603]: 'Internal error',
50
+ };
51
+ export class A2aError extends Error {
52
+ code;
53
+ metadata;
54
+ constructor(code, message, metadata) {
55
+ super(message ?? MESSAGE[code] ?? 'A2A error');
56
+ this.code = code;
57
+ this.metadata = metadata;
58
+ this.name = 'A2aError';
59
+ }
60
+ }
61
+ /** The JSON-RPC error object for an error: A2A-specific codes carry ErrorInfo in a `data` array. */
62
+ export function toJsonRpcError(e) {
63
+ if (e instanceof A2aError) {
64
+ const reason = REASON[e.code];
65
+ if (reason) {
66
+ return {
67
+ code: e.code, message: e.message,
68
+ data: [{ '@type': 'type.googleapis.com/google.rpc.ErrorInfo', reason, domain: 'a2a-protocol.org', metadata: { ...(e.metadata ?? {}), timestamp: new Date().toISOString() } }],
69
+ };
70
+ }
71
+ return { code: e.code, message: e.message, ...(e.metadata ? { data: e.metadata } : {}) };
72
+ }
73
+ return { code: JSONRPC_ERROR.Internal, message: MESSAGE[-32603], data: { detail: e instanceof Error ? e.message : String(e) } };
74
+ }
75
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/standard/errors.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,yGAAyG;AACzG,0GAA0G;AAC1G,qGAAqG;AAErG,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,YAAY,EAAE,CAAC,KAAK;IACpB,iBAAiB,EAAE,CAAC,KAAK;IACzB,4BAA4B,EAAE,CAAC,KAAK;IACpC,oBAAoB,EAAE,CAAC,KAAK;IAC5B,uBAAuB,EAAE,CAAC,KAAK;IAC/B,oBAAoB,EAAE,CAAC,KAAK;IAC5B,8BAA8B,EAAE,CAAC,KAAK;IACtC,wBAAwB,EAAE,CAAC,KAAK;IAChC,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CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACnI,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { A2aAgent } from '../agent.js';
2
+ import type { TaskStore } from '../task-store.js';
3
+ import type { TaskRecord } from '../types.js';
4
+ import { type PushConfigStore, type Principal, type StandardExecutor, type StandardServer, type StandardServerConfig, type StandardTaskStore } from './server.js';
5
+ import type { AgentCardV1, MessageV1, TaskV1 } from './types.js';
6
+ /** Project a runtime record into the 1.0 shape. */
7
+ export declare const recordAsV1: (r: TaskRecord) => TaskV1;
8
+ /** A read-only `StandardTaskStore` over the runtime's own store, plus a writable side for tasks this
9
+ * server creates itself (a plain conversation). One `GetTask` answers from whichever holds the id. */
10
+ export declare function taskStoreOverAgent(runtime: TaskStore, own: StandardTaskStore): StandardTaskStore;
11
+ export interface AgentBackedServerOptions {
12
+ /** The delegation-authorized runtime this wire serves. */
13
+ agent: A2aAgent;
14
+ /** The runtime's task store — read for `GetTask` / `ListTasks`, never written here. */
15
+ runtimeStore: TaskStore;
16
+ card: AgentCardV1;
17
+ /** Where this server's own (non-delegated) tasks live. */
18
+ ownStore: StandardTaskStore;
19
+ push?: PushConfigStore;
20
+ /** What answers a message that carries no delegated-task extension — an ordinary conversation. Omit and
21
+ * such a message is refused, saying what this agent takes. */
22
+ executor?: StandardExecutor;
23
+ principal?: StandardServerConfig['principal'];
24
+ /** Extra visibility on top of the delegated-task party rule (e.g. the owner of a conversational task). */
25
+ canSeeOwnTask?: (task: TaskV1, principal: Principal | null) => Promise<boolean> | boolean;
26
+ versions?: string[];
27
+ fetch?: typeof fetch;
28
+ now?: () => number;
29
+ }
30
+ /**
31
+ * Build the ONE server this agent serves: A2A 1.0 methods, the delegation-authorized runtime behind
32
+ * `SendMessage`-with-extension, and an ordinary conversation behind `SendMessage` without one.
33
+ */
34
+ export declare function createAgentBackedServer(opts: AgentBackedServerOptions): StandardServer;
35
+ /** The message a client sends to reach the runtime: what `A2aWireAdapter.submitTask` builds. Exported so a
36
+ * consumer can construct one without the adapter. */
37
+ export type { MessageV1 };
38
+ //# sourceMappingURL=from-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from-agent.d.ts","sourceRoot":"","sources":["../../src/standard/from-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAO9C,OAAO,EAEL,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,KAAK,iBAAiB,EACpI,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEjE,mDAAmD;AACnD,eAAO,MAAM,UAAU,MAAO,UAAU,KAAG,MAQzC,CAAC;AAEH;uGACuG;AACvG,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,iBAAiB,GAAG,iBAAiB,CAchG;AAED,MAAM,WAAW,wBAAwB;IACvC,0DAA0D;IAC1D,KAAK,EAAE,QAAQ,CAAC;IAChB,uFAAuF;IACvF,YAAY,EAAE,SAAS,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,0DAA0D;IAC1D,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB;mEAC+D;IAC/D,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,SAAS,CAAC,EAAE,oB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