@alvin0/ai-agent-sdk-a2a 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 alvin0 (chaulamdinhai) <chaulamdinhai@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @alvin0/ai-agent-sdk-a2a
2
+
3
+ Runtime: **Node 22.12+**.
4
+
5
+ ```sh
6
+ pnpm add @alvin0/ai-agent-sdk-core @alvin0/ai-agent-sdk-a2a
7
+ ```
8
+
9
+ Node-elevated bridge between ai-agent-sdk agents/teams and the official A2A
10
+ client/server APIs.
11
+
12
+ ```ts
13
+ import { linkA2AAgent } from '@alvin0/ai-agent-sdk-a2a/client'
14
+ import { createDefinedAgentA2AServer } from '@alvin0/ai-agent-sdk-a2a/server'
15
+ ```
16
+
17
+ This package is intentionally classified as Node. The official A2A 1.1.0 codec
18
+ uses `Buffer.from` for raw binary `Part` serialization. Text, structured data,
19
+ URLs, and binary values are supported in Node, but the package must not be
20
+ advertised for Edge/Worker runtimes until the committed negative promotion gate
21
+ passes without Node globals.
22
+
23
+ Authentication, endpoint policy, persistence, and HTTP framework adaptation
24
+ remain host-owned. Configure explicit origins, HTTPS/private-network policy,
25
+ resource bounds, session ownership, and deadlines for the deployment boundary.
26
+
27
+ Composition: `runtime-team.linkAgent`. Lifecycle: `borrowed-caller-owned`; close
28
+ the runtime/team first, then retain the idempotent unlink and server-dispose
29
+ reports separately.
@@ -0,0 +1,146 @@
1
+ //#region src/common/integration-operation.ts
2
+ const A2A_INTEGRATION_OPERATIONS = Object.freeze({
3
+ "a2a-client-link": Object.freeze([
4
+ "agent-card-resolve",
5
+ "link",
6
+ "send",
7
+ "stream",
8
+ "unlink"
9
+ ]),
10
+ "a2a-server": Object.freeze([
11
+ "request",
12
+ "execute",
13
+ "cancel",
14
+ "dispose"
15
+ ])
16
+ });
17
+ function beginA2AIntegrationOperation(logger, family, operation) {
18
+ assertIdentity(operation, 64, "integration operation");
19
+ const operationId = crypto.randomUUID(), startedAt = now();
20
+ log(logger, "info", "SDK integration operation started", {
21
+ integrationSchemaVersion: 1,
22
+ integrationFamily: family,
23
+ integrationOperation: operation,
24
+ operationId,
25
+ kind: "logical-start"
26
+ });
27
+ let terminal = false;
28
+ const finish = (status, errorCode) => {
29
+ if (terminal) return;
30
+ terminal = true;
31
+ log(logger, status === "error" ? "error" : "info", message(status), {
32
+ integrationSchemaVersion: 1,
33
+ integrationFamily: family,
34
+ integrationOperation: operation,
35
+ operationId,
36
+ kind: "logical-terminal",
37
+ status,
38
+ durationMs: elapsed(startedAt),
39
+ ...errorCode === void 0 ? {} : { errorCode: boundedCode(errorCode) }
40
+ });
41
+ };
42
+ return {
43
+ attempt(attemptNumber) {
44
+ if (!Number.isSafeInteger(attemptNumber) || attemptNumber < 1) throw new TypeError("integration attemptNumber must be a positive safe integer");
45
+ const attemptId = crypto.randomUUID(), attemptStartedAt = now();
46
+ log(logger, "info", "SDK integration attempt started", {
47
+ integrationSchemaVersion: 1,
48
+ integrationFamily: family,
49
+ integrationOperation: operation,
50
+ operationId,
51
+ kind: "attempt-start",
52
+ attemptId,
53
+ attemptNumber
54
+ });
55
+ let ended = false;
56
+ const end = (status, errorCode) => {
57
+ if (ended) return;
58
+ ended = true;
59
+ log(logger, status === "error" ? "error" : "info", message(status), {
60
+ integrationSchemaVersion: 1,
61
+ integrationFamily: family,
62
+ integrationOperation: operation,
63
+ operationId,
64
+ kind: "attempt-terminal",
65
+ attemptId,
66
+ attemptNumber,
67
+ status,
68
+ durationMs: elapsed(attemptStartedAt),
69
+ ...errorCode === void 0 ? {} : { errorCode: boundedCode(errorCode) }
70
+ });
71
+ };
72
+ return {
73
+ success: () => end("success"),
74
+ fail: (code) => end("error", code),
75
+ abort: () => end("aborted")
76
+ };
77
+ },
78
+ success: () => finish("success"),
79
+ fail: (code) => finish("error", code),
80
+ abort: () => finish("aborted")
81
+ };
82
+ }
83
+ function a2aErrorCode(error) {
84
+ if (typeof error === "object" && error !== null) for (const key of ["code", "name"]) {
85
+ const descriptor = Object.getOwnPropertyDescriptor(error, key);
86
+ if (descriptor !== void 0 && "value" in descriptor && typeof descriptor.value === "string") return boundedCode(descriptor.value);
87
+ }
88
+ return "A2A_OPERATION_FAILED";
89
+ }
90
+ function a2aIntegrationChildLogger(logger, scope) {
91
+ assertIdentity(scope, 64, "integration scope");
92
+ try {
93
+ return logger?.child({ integrationScope: scope });
94
+ } catch {
95
+ return;
96
+ }
97
+ }
98
+ function log(logger, level, message, fields) {
99
+ try {
100
+ logger?.[level](message, fields);
101
+ } catch {}
102
+ }
103
+ function now() {
104
+ return globalThis.performance?.now() ?? Date.now();
105
+ }
106
+ function elapsed(startedAt) {
107
+ const value = now() - startedAt;
108
+ return Number.isFinite(value) ? Math.max(0, value) : 0;
109
+ }
110
+ function message(status) {
111
+ return status === "success" ? "SDK integration operation completed" : status === "error" ? "SDK integration operation failed" : "SDK integration operation aborted";
112
+ }
113
+ function boundedCode(value) {
114
+ const normalized = value.replace(/[^A-Za-z0-9_.:-]/g, "_");
115
+ return (normalized.length === 0 ? "A2A_OPERATION_FAILED" : normalized).slice(0, 128);
116
+ }
117
+ function assertIdentity(value, limit, label) {
118
+ if (value.length === 0 || value.length > limit) throw new TypeError(`${label} must contain 1-${limit} characters`);
119
+ }
120
+
121
+ //#endregion
122
+ //#region src/common/cleanup-report.ts
123
+ const NO_USAGE = Object.freeze({
124
+ logicalCalls: 0,
125
+ attempts: 0,
126
+ complete: 0,
127
+ partial: 0,
128
+ estimated: 0,
129
+ missing: 0,
130
+ notApplicable: 0,
131
+ possiblyBilledAttemptsWithoutUsage: 0
132
+ });
133
+ /** Build static metadata-only teardown evidence without retaining the thrown value. */
134
+ function cleanupFailure(code, stage, message) {
135
+ return Object.freeze({
136
+ code,
137
+ stage,
138
+ message,
139
+ usageCoverage: NO_USAGE,
140
+ possiblyBilledAttemptsWithoutUsage: 0
141
+ });
142
+ }
143
+
144
+ //#endregion
145
+ export { beginA2AIntegrationOperation as i, a2aErrorCode as n, a2aIntegrationChildLogger as r, cleanupFailure as t };
146
+ //# sourceMappingURL=cleanup-report-CTjMJ9EU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup-report-CTjMJ9EU.mjs","names":[],"sources":["../src/common/integration-operation.ts","../src/common/cleanup-report.ts"],"sourcesContent":["import type { IntegrationOperationEvidenceFields, SdkLogger } from '@alvin0/ai-agent-sdk-core/observability'\n\nexport const A2A_INTEGRATION_OPERATIONS = Object.freeze({\n 'a2a-client-link': Object.freeze(['agent-card-resolve', 'link', 'send', 'stream', 'unlink']),\n 'a2a-server': Object.freeze(['request', 'execute', 'cancel', 'dispose']),\n} as const)\n\nexport type A2AIntegrationFamily = keyof typeof A2A_INTEGRATION_OPERATIONS\nexport type A2AIntegrationOperationName = (typeof A2A_INTEGRATION_OPERATIONS)[A2AIntegrationFamily][number]\ntype TerminalStatus = 'success' | 'error' | 'aborted'\n\nexport interface A2AIntegrationAttempt {\n success(): void\n fail(errorCode?: string): void\n abort(): void\n}\n\nexport interface A2AIntegrationOperation extends A2AIntegrationAttempt {\n attempt(attemptNumber: number): A2AIntegrationAttempt\n}\n\nexport function beginA2AIntegrationOperation(\n logger: SdkLogger | undefined,\n family: A2AIntegrationFamily,\n operation: A2AIntegrationOperationName,\n): A2AIntegrationOperation {\n assertIdentity(operation, 64, 'integration operation')\n const operationId = crypto.randomUUID(), startedAt = now()\n log(logger, 'info', 'SDK integration operation started', {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'logical-start',\n })\n let terminal = false\n const finish = (status: TerminalStatus, errorCode?: string): void => {\n if (terminal) return\n terminal = true\n log(logger, status === 'error' ? 'error' : 'info', message(status), {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'logical-terminal',\n status, durationMs: elapsed(startedAt),\n ...(errorCode === undefined ? {} : { errorCode: boundedCode(errorCode) }),\n })\n }\n return {\n attempt(attemptNumber) {\n if (!Number.isSafeInteger(attemptNumber) || attemptNumber < 1) {\n throw new TypeError('integration attemptNumber must be a positive safe integer')\n }\n const attemptId = crypto.randomUUID(), attemptStartedAt = now()\n log(logger, 'info', 'SDK integration attempt started', {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'attempt-start',\n attemptId, attemptNumber,\n })\n let ended = false\n const end = (status: TerminalStatus, errorCode?: string): void => {\n if (ended) return\n ended = true\n log(logger, status === 'error' ? 'error' : 'info', message(status), {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'attempt-terminal',\n attemptId, attemptNumber, status, durationMs: elapsed(attemptStartedAt),\n ...(errorCode === undefined ? {} : { errorCode: boundedCode(errorCode) }),\n })\n }\n return { success: () => end('success'), fail: code => end('error', code), abort: () => end('aborted') }\n },\n success: () => finish('success'),\n fail: code => finish('error', code),\n abort: () => finish('aborted'),\n }\n}\n\nexport function a2aErrorCode(error: unknown): string {\n if (typeof error === 'object' && error !== null) {\n for (const key of ['code', 'name']) {\n const descriptor = Object.getOwnPropertyDescriptor(error, key)\n if (descriptor !== undefined && 'value' in descriptor && typeof descriptor.value === 'string') {\n return boundedCode(descriptor.value)\n }\n }\n }\n return 'A2A_OPERATION_FAILED'\n}\n\nexport function a2aIntegrationChildLogger(logger: SdkLogger | undefined, scope: string): SdkLogger | undefined {\n assertIdentity(scope, 64, 'integration scope')\n try { return logger?.child({ integrationScope: scope }) } catch { return undefined }\n}\n\nfunction log(logger: SdkLogger | undefined, level: 'info' | 'error', message: string,\n fields: IntegrationOperationEvidenceFields): void {\n try { logger?.[level](message, fields) } catch { /* diagnostic observers never own operation correctness */ }\n}\nfunction now(): number { return globalThis.performance?.now() ?? Date.now() }\nfunction elapsed(startedAt: number): number {\n const value = now() - startedAt\n return Number.isFinite(value) ? Math.max(0, value) : 0\n}\nfunction message(status: TerminalStatus): string {\n return status === 'success' ? 'SDK integration operation completed'\n : status === 'error' ? 'SDK integration operation failed' : 'SDK integration operation aborted'\n}\nfunction boundedCode(value: string): string {\n const normalized = value.replace(/[^A-Za-z0-9_.:-]/g, '_')\n return (normalized.length === 0 ? 'A2A_OPERATION_FAILED' : normalized).slice(0, 128)\n}\nfunction assertIdentity(value: string, limit: number, label: string): void {\n if (value.length === 0 || value.length > limit) throw new TypeError(`${label} must contain 1-${limit} characters`)\n}\n","import type { SupportSafeError } from '@alvin0/ai-agent-sdk-core'\n\nconst NO_USAGE = Object.freeze({ logicalCalls: 0, attempts: 0, complete: 0, partial: 0,\n estimated: 0, missing: 0, notApplicable: 0, possiblyBilledAttemptsWithoutUsage: 0 })\n\n/** Build static metadata-only teardown evidence without retaining the thrown value. */\nexport function cleanupFailure(code: string, stage: string, message: string): SupportSafeError {\n return Object.freeze({ code, stage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