@devlab.group/agent-commerce 2.8.0 → 2.9.1
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/README.md +28 -21
- package/dist/ap2.js +2 -2
- package/dist/{chunk-WDD2ZUR3.js → chunk-46Y5M7BA.js} +3 -2
- package/dist/chunk-46Y5M7BA.js.map +1 -0
- package/dist/{chunk-ENK63GKR.js → chunk-J3K7E4CA.js} +3 -3
- package/dist/{chunk-ENK63GKR.js.map → chunk-J3K7E4CA.js.map} +1 -1
- package/dist/{cli/chunk-APC5BTQM.js → chunk-RF3DFVXH.js} +2 -2
- package/dist/{chunk-IWXVQYG5.js.map → chunk-RF3DFVXH.js.map} +1 -1
- package/dist/{chunk-QZW5YL3G.js → chunk-TEI6GTUG.js} +7 -3
- package/dist/chunk-TEI6GTUG.js.map +1 -0
- package/dist/cli/{ap2-GYKFGE66.js → ap2-MUNB4HHC.js} +5 -5
- package/dist/cli/{ap2-GYKFGE66.js.map → ap2-MUNB4HHC.js.map} +1 -1
- package/dist/cli/{chunk-DKWO6LLX.js → chunk-4WPHZLVO.js} +3 -2
- package/dist/cli/chunk-4WPHZLVO.js.map +1 -0
- package/dist/cli/chunk-JP5NQ5II.js +8 -0
- package/dist/cli/{chunk-SAAT2XFX.js.map → chunk-JP5NQ5II.js.map} +1 -1
- package/dist/cli/chunk-KLKNFJTT.js +540 -0
- package/dist/cli/chunk-KLKNFJTT.js.map +1 -0
- package/dist/cli/{chunk-WFIR374D.js → chunk-L264N3ZV.js} +41 -5
- package/dist/cli/chunk-L264N3ZV.js.map +1 -0
- package/dist/cli/{chunk-VWQMSWDF.js → chunk-RAWPZIG6.js} +7 -3
- package/dist/cli/chunk-RAWPZIG6.js.map +1 -0
- package/dist/cli/{chunk-SYXLQ5BS.js → chunk-SEDRU2KV.js} +5 -5
- package/dist/cli/{chunk-SYXLQ5BS.js.map → chunk-SEDRU2KV.js.map} +1 -1
- package/dist/cli/{chunk-3PGFOEVJ.js → chunk-SHIA2B6G.js} +32 -6
- package/dist/cli/chunk-SHIA2B6G.js.map +1 -0
- package/dist/{chunk-IWXVQYG5.js → cli/chunk-UV23DWUY.js} +2 -2
- package/dist/cli/{chunk-APC5BTQM.js.map → chunk-UV23DWUY.js.map} +1 -1
- package/dist/cli/{chunk-YXXPZFWC.js → chunk-UX7GRVL4.js} +126 -18
- package/dist/cli/chunk-UX7GRVL4.js.map +1 -0
- package/dist/cli/{config-JWMHWVRT.js → config-IBG46HTQ.js} +6 -6
- package/dist/cli/{config-JWMHWVRT.js.map → config-IBG46HTQ.js.map} +1 -1
- package/dist/cli/index.js +34 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-OW5GY7TT.js → mcp-55FLXKCC.js} +3 -3
- package/dist/cli/{mcp-OW5GY7TT.js.map → mcp-55FLXKCC.js.map} +1 -1
- package/dist/cli/payment-providers-4OC2TONC.js +6 -0
- package/dist/cli/{payment-providers-QL2BJYMD.js.map → payment-providers-4OC2TONC.js.map} +1 -1
- package/dist/cli/{provider-3A2LVEQS.js → provider-H57SJDEJ.js} +4 -4
- package/dist/cli/{provider-3A2LVEQS.js.map → provider-H57SJDEJ.js.map} +1 -1
- package/dist/cli/receipts-SMX4MFO5.js +9 -0
- package/dist/cli/{receipts-FQUFGEQD.js.map → receipts-SMX4MFO5.js.map} +1 -1
- package/dist/cli/{run-KF5OQYPL.js → run-BS7323JH.js} +830 -184
- package/dist/cli/run-BS7323JH.js.map +1 -0
- package/dist/cli/{x402-5A7CVCIJ.js → x402-RNV3VHJT.js} +5 -5
- package/dist/cli/{x402-5A7CVCIJ.js.map → x402-RNV3VHJT.js.map} +1 -1
- package/dist/index.d.ts +74 -31
- package/dist/index.js +1410 -270
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mpp.js +2 -2
- package/dist/{store-BzgwHOPu.d.ts → store-04pazhFP.d.ts} +52 -1
- package/dist/testing.js +468 -273
- package/dist/testing.js.map +1 -1
- package/dist/x402.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-QZW5YL3G.js.map +0 -1
- package/dist/chunk-WDD2ZUR3.js.map +0 -1
- package/dist/cli/chunk-3PGFOEVJ.js.map +0 -1
- package/dist/cli/chunk-6BWEHQPJ.js +0 -215
- package/dist/cli/chunk-6BWEHQPJ.js.map +0 -1
- package/dist/cli/chunk-DKWO6LLX.js.map +0 -1
- package/dist/cli/chunk-SAAT2XFX.js +0 -8
- package/dist/cli/chunk-VWQMSWDF.js.map +0 -1
- package/dist/cli/chunk-WFIR374D.js.map +0 -1
- package/dist/cli/chunk-YXXPZFWC.js.map +0 -1
- package/dist/cli/payment-providers-QL2BJYMD.js +0 -6
- package/dist/cli/receipts-FQUFGEQD.js +0 -9
- package/dist/cli/run-KF5OQYPL.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -4,9 +4,9 @@ import { MPP_DEFAULT_NETWORK, isMppNetwork, MPP_NETWORKS, MPP_DEFAULT_PAYMENT_FL
|
|
|
4
4
|
import { contentDigest, CONTENT_DIGEST_METADATA_KEY, mppProblem, mppProblemDetail } from './chunk-D7FPSGUQ.js';
|
|
5
5
|
import { X402_PAYMENT_FLOWS, x402_default, buildBackendRequestParts, buildHeaders, setHeader, checkQueryCollision, stringifyPrimitive, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, resolveX402Deployment, bazaarMetadata, validateBackendRequestShape, resolveDeploymentMode, requireX402Network, resolveX402Option, isEvmAddress, isEvmZeroAddress, ENFORCED_SCHEMA_KEYWORDS, isObjectSchemaNode, extractPathParameterNames, findUnparsedBraceToken, compileJsonSchema, SETTLE_AFTER_BACKEND_METADATA_KEY, x402OfferName, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, canonicalJson } from './chunk-VHS6MGXJ.js';
|
|
6
6
|
import { exampleObject } from './chunk-MNI6APE6.js';
|
|
7
|
-
import { featureStatus, exclusionNames, PACKAGE_VERSION, descriptorStatus } from './chunk-
|
|
8
|
-
import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-
|
|
9
|
-
import { hasMethodGroup } from './chunk-
|
|
7
|
+
import { featureStatus, exclusionNames, PACKAGE_VERSION, descriptorStatus } from './chunk-J3K7E4CA.js';
|
|
8
|
+
import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-RF3DFVXH.js';
|
|
9
|
+
import { hasMethodGroup } from './chunk-46Y5M7BA.js';
|
|
10
10
|
import { RESERVED_INPUT_FIELDS, PROTOCOL_NAMES, PAYMENT_METHOD_NAMES, PAYMENT_HEADER, AUTHORIZATION_HEADER, CommerceError, systemClock, NOOP_LOGGER, transactionState, DEFAULT_BACKEND_TIMEOUT_MS, isCommerceError, describeError, isHttpProtocolAdapter, toLogInfo, toCommerceError, extractReservedInputFields, parseAuthorizationHeader, toPaymentRequiredEnvelope, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, toErrorEnvelope, DELIVERY_SUMMARY_META_KEY, toDeliverySummary, PAYMENT_INPUT_FIELD, AUTHORIZATION_INPUT_FIELD, parseAuthorizationSubmission, RECONCILIATION_METADATA_KEY, TRANSACTION_STATES, redactedErrorText } from './chunk-MDOGXTZD.js';
|
|
11
11
|
export { AUTHORIZATION_HEADER, AUTHORIZATION_INPUT_FIELD, COMMERCE_ERROR_CODES, COMMERCE_ERROR_HTTP_STATUS, COMMERCE_EVENT_TYPES, CommerceError, DEFAULT_BACKEND_TIMEOUT_MS, DELIVERY_SUMMARY_META_KEY, MAX_AUTHORIZATION_HEADER_BYTES, NOOP_LOGGER, PAYMENT_HEADER, PAYMENT_INPUT_FIELD, PAYMENT_METHOD_NAMES, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PROTOCOL_NAMES, RECONCILIATION_METADATA_KEY, RESERVED_INPUT_FIELDS, RETRYABLE_ERROR_CODES, TRANSACTION_STATES, extractReservedInputFields, isCommerceError, isHttpProtocolAdapter, isPaymentRequiredEnvelope, parseAuthorizationHeader, parseAuthorizationSubmission, systemClock, toCommerceError, toDeliverySummary, toErrorEnvelope, toPaymentRequiredEnvelope, transactionState } from './chunk-MDOGXTZD.js';
|
|
12
12
|
import { isRecord } from './chunk-2CJNA7MS.js';
|
|
@@ -90,6 +90,42 @@ function substituteOnce(value, env, path2) {
|
|
|
90
90
|
// src/config/filename.ts
|
|
91
91
|
var DEFAULT_CONFIG_FILENAME = "config.yaml";
|
|
92
92
|
|
|
93
|
+
// src/protocols/a2a/constants.ts
|
|
94
|
+
var A2A_SPEC_VERSION = "1.0.1";
|
|
95
|
+
var A2A_PROTOCOL_VERSION = "1.0";
|
|
96
|
+
var A2A_PROTOCOL_BINDING = "JSONRPC";
|
|
97
|
+
var A2A_AGENT_CARD_PATH = "/.well-known/agent-card.json";
|
|
98
|
+
var A2A_DEFAULT_MOUNT_PATH = "/a2a";
|
|
99
|
+
var A2A_JSON_MEDIA_TYPE = "application/json";
|
|
100
|
+
var A2A_DEFAULT_AGENT_NAME = "agent-commerce";
|
|
101
|
+
var A2A_VERSION_HEADER = "a2a-version";
|
|
102
|
+
var A2A_METHOD_SEND_MESSAGE = "SendMessage";
|
|
103
|
+
var A2A_METHOD_GET_TASK = "GetTask";
|
|
104
|
+
var A2A_METHOD_LIST_TASKS = "ListTasks";
|
|
105
|
+
var A2A_METHOD_CANCEL_TASK = "CancelTask";
|
|
106
|
+
var A2A_PUSH_CONFIG_METHODS = [
|
|
107
|
+
"CreateTaskPushNotificationConfig",
|
|
108
|
+
"GetTaskPushNotificationConfig",
|
|
109
|
+
"ListTaskPushNotificationConfigs",
|
|
110
|
+
"DeleteTaskPushNotificationConfig"
|
|
111
|
+
];
|
|
112
|
+
var A2A_UNSUPPORTED_METHODS = [
|
|
113
|
+
"SendStreamingMessage",
|
|
114
|
+
"SubscribeToTask",
|
|
115
|
+
...A2A_PUSH_CONFIG_METHODS,
|
|
116
|
+
"GetExtendedAgentCard"
|
|
117
|
+
];
|
|
118
|
+
var A2A_TASK_STATE_COMPLETED = "TASK_STATE_COMPLETED";
|
|
119
|
+
var A2A_TASK_STATE_FAILED = "TASK_STATE_FAILED";
|
|
120
|
+
var A2A_TASK_STATE_CANCELED = "TASK_STATE_CANCELED";
|
|
121
|
+
var A2A_TASK_STATE_WORKING = "TASK_STATE_WORKING";
|
|
122
|
+
var A2A_TASK_STATE_INPUT_REQUIRED = "TASK_STATE_INPUT_REQUIRED";
|
|
123
|
+
var A2A_EXTENSIONS_HEADER = "a2a-extensions";
|
|
124
|
+
var A2A_X_EXTENSIONS_HEADER = "x-a2a-extensions";
|
|
125
|
+
var A2A_TASK_RETENTION_HOURS = { min: 1, max: 8760, default: 24 };
|
|
126
|
+
var A2A_MAX_RETAINED_TASKS = { min: 1, max: 1e6, default: 1e3 };
|
|
127
|
+
var A2A_MAX_BACKGROUND_RUNS = 20;
|
|
128
|
+
|
|
93
129
|
// src/protocols/acp/constants.ts
|
|
94
130
|
var ACP_SPEC_VERSION = "2026-04-17";
|
|
95
131
|
var ACP_API_VERSION = "2026-04-17";
|
|
@@ -970,7 +1006,11 @@ var ProtocolsSchema = z.object({
|
|
|
970
1006
|
// Optional; A2A is off unless configured
|
|
971
1007
|
a2a: z.object({
|
|
972
1008
|
enabled: BooleanOrString,
|
|
973
|
-
mountPath: MountPathSchema.optional()
|
|
1009
|
+
mountPath: MountPathSchema.optional(),
|
|
1010
|
+
tasks: z.object({
|
|
1011
|
+
retentionHours: NumberOrString.optional(),
|
|
1012
|
+
maxRetained: NumberOrString.optional()
|
|
1013
|
+
}).strict().optional()
|
|
974
1014
|
}).strict().optional(),
|
|
975
1015
|
// Optional and off by default. The business pass requires the sub-blocks
|
|
976
1016
|
// only when ACP is enabled, so a disabled placeholder stays valid and an
|
|
@@ -1309,7 +1349,7 @@ function createRetryGate(ctx) {
|
|
|
1309
1349
|
);
|
|
1310
1350
|
if (existing?.kind === "in-flight" || existing?.kind === "unresolved") {
|
|
1311
1351
|
if (existing.owner !== ticket.proofDigest) return ticket;
|
|
1312
|
-
throw await
|
|
1352
|
+
throw await refusal2(flow, resource, provider, existing.kind);
|
|
1313
1353
|
}
|
|
1314
1354
|
if (existing?.kind !== "replay") return ticket;
|
|
1315
1355
|
const stored = readStoredDelivery(existing.body);
|
|
@@ -1327,7 +1367,7 @@ function createRetryGate(ctx) {
|
|
|
1327
1367
|
const stored = await storedDelivery(flow, resource, provider, replay);
|
|
1328
1368
|
const samePayer = verification.payer !== void 0 && verification.payer === stored.payer;
|
|
1329
1369
|
if (!samePayer || !authorizes(resource, stored, ticket)) {
|
|
1330
|
-
throw await
|
|
1370
|
+
throw await refusal2(flow, resource, provider, "conflict");
|
|
1331
1371
|
}
|
|
1332
1372
|
return redeliver(flow, resource, provider, replay.status, stored, pipelineStart);
|
|
1333
1373
|
}
|
|
@@ -1360,9 +1400,9 @@ function createRetryGate(ctx) {
|
|
|
1360
1400
|
"response"
|
|
1361
1401
|
);
|
|
1362
1402
|
}
|
|
1363
|
-
async function reading(flow, resource,
|
|
1403
|
+
async function reading(flow, resource, read2) {
|
|
1364
1404
|
try {
|
|
1365
|
-
return await
|
|
1405
|
+
return await read2();
|
|
1366
1406
|
} catch (error) {
|
|
1367
1407
|
throw new CommerceError("STORAGE_ERROR", "Payment retry state could not be read", {
|
|
1368
1408
|
requestId: flow.request.requestId,
|
|
@@ -1374,14 +1414,14 @@ function createRetryGate(ctx) {
|
|
|
1374
1414
|
async function acceptOrRefuse(flow, resource, provider, claimed) {
|
|
1375
1415
|
if (claimed === void 0 || claimed.kind === "reserved") return void 0;
|
|
1376
1416
|
if (claimed.kind === "replay") return claimed;
|
|
1377
|
-
throw await
|
|
1417
|
+
throw await refusal2(flow, resource, provider, claimed.kind);
|
|
1378
1418
|
}
|
|
1379
1419
|
async function storedDelivery(flow, resource, provider, replay) {
|
|
1380
1420
|
const stored = readStoredDelivery(replay.body);
|
|
1381
|
-
if (stored === void 0) throw await
|
|
1421
|
+
if (stored === void 0) throw await refusal2(flow, resource, provider, "unresolved");
|
|
1382
1422
|
return stored;
|
|
1383
1423
|
}
|
|
1384
|
-
function
|
|
1424
|
+
function refusal2(flow, resource, provider, kind) {
|
|
1385
1425
|
const { reason, message } = REFUSALS[kind];
|
|
1386
1426
|
const inFlight = kind === "in-flight";
|
|
1387
1427
|
return rejected(
|
|
@@ -1435,7 +1475,7 @@ function createRetryGate(ctx) {
|
|
|
1435
1475
|
const { request } = flow;
|
|
1436
1476
|
const receipt = await reading(flow, resource, () => options.store.getReceipt(stored.receiptId));
|
|
1437
1477
|
if (receipt?.payment === void 0) {
|
|
1438
|
-
throw await
|
|
1478
|
+
throw await refusal2(flow, resource, provider, "unresolved");
|
|
1439
1479
|
}
|
|
1440
1480
|
const durationMs = Math.round(options.clock.monotonicMs() - pipelineStart);
|
|
1441
1481
|
const original = receipt.transactionId;
|
|
@@ -1945,7 +1985,7 @@ function createPaymentAdmission(ctx, authorizeAndReserve, retryGate) {
|
|
|
1945
1985
|
throw mapped;
|
|
1946
1986
|
}
|
|
1947
1987
|
if (verification.status !== "verified") {
|
|
1948
|
-
const
|
|
1988
|
+
const refusal2 = await refusalFor(verification, requirement, request, resource);
|
|
1949
1989
|
await safeEmit(
|
|
1950
1990
|
buildEvent(flow, {
|
|
1951
1991
|
type: "payment.rejected",
|
|
@@ -1953,10 +1993,10 @@ function createPaymentAdmission(ctx, authorizeAndReserve, retryGate) {
|
|
|
1953
1993
|
adapter: request.protocol,
|
|
1954
1994
|
paymentProvider: provider.name,
|
|
1955
1995
|
status: "error",
|
|
1956
|
-
data:
|
|
1996
|
+
data: refusal2.code !== "PAYMENT_INVALID" ? { reason: refusal2.code } : verification.rejectionReason ? { reason: verification.rejectionReason } : {}
|
|
1957
1997
|
})
|
|
1958
1998
|
);
|
|
1959
|
-
throw
|
|
1999
|
+
throw refusal2;
|
|
1960
2000
|
}
|
|
1961
2001
|
if (!verification.replayKey) {
|
|
1962
2002
|
await safeEmit(
|
|
@@ -3243,6 +3283,27 @@ function pickDefined(value) {
|
|
|
3243
3283
|
|
|
3244
3284
|
// src/config/schema/normalize.ts
|
|
3245
3285
|
var DEFAULT_A2A_MOUNT_PATH = "/a2a";
|
|
3286
|
+
function normalizeA2aTasks(tasks) {
|
|
3287
|
+
if (tasks === void 0) return {};
|
|
3288
|
+
return {
|
|
3289
|
+
tasks: {
|
|
3290
|
+
...tasks.retentionHours !== void 0 ? {
|
|
3291
|
+
retentionHours: toNumber(
|
|
3292
|
+
tasks.retentionHours,
|
|
3293
|
+
"protocols.a2a.tasks.retentionHours",
|
|
3294
|
+
A2A_TASK_RETENTION_HOURS
|
|
3295
|
+
)
|
|
3296
|
+
} : {},
|
|
3297
|
+
...tasks.maxRetained !== void 0 ? {
|
|
3298
|
+
maxRetained: toNumber(
|
|
3299
|
+
tasks.maxRetained,
|
|
3300
|
+
"protocols.a2a.tasks.maxRetained",
|
|
3301
|
+
A2A_MAX_RETAINED_TASKS
|
|
3302
|
+
)
|
|
3303
|
+
} : {}
|
|
3304
|
+
}
|
|
3305
|
+
};
|
|
3306
|
+
}
|
|
3246
3307
|
function normalize(raw) {
|
|
3247
3308
|
const protocols = {
|
|
3248
3309
|
http: { enabled: toBoolean(raw.protocols.http.enabled, "protocols.http.enabled") },
|
|
@@ -3253,7 +3314,8 @@ function normalize(raw) {
|
|
|
3253
3314
|
},
|
|
3254
3315
|
a2a: {
|
|
3255
3316
|
enabled: toBoolean(raw.protocols.a2a?.enabled ?? false, "protocols.a2a.enabled"),
|
|
3256
|
-
mountPath: raw.protocols.a2a?.mountPath ?? DEFAULT_A2A_MOUNT_PATH
|
|
3317
|
+
mountPath: raw.protocols.a2a?.mountPath ?? DEFAULT_A2A_MOUNT_PATH,
|
|
3318
|
+
...normalizeA2aTasks(raw.protocols.a2a?.tasks)
|
|
3257
3319
|
},
|
|
3258
3320
|
acp: normalizeAcp(raw.protocols.acp)
|
|
3259
3321
|
};
|
|
@@ -3536,6 +3598,7 @@ var CORS_HEADERS = [
|
|
|
3536
3598
|
"mcp-name",
|
|
3537
3599
|
"a2a-version",
|
|
3538
3600
|
"a2a-extensions",
|
|
3601
|
+
"x-a2a-extensions",
|
|
3539
3602
|
"api-version",
|
|
3540
3603
|
"idempotency-key",
|
|
3541
3604
|
"request-id",
|
|
@@ -3551,7 +3614,9 @@ var CORS_EXPOSED_HEADERS = [
|
|
|
3551
3614
|
"idempotency-key",
|
|
3552
3615
|
"request-id",
|
|
3553
3616
|
"idempotent-replayed",
|
|
3554
|
-
"retry-after"
|
|
3617
|
+
"retry-after",
|
|
3618
|
+
"a2a-extensions",
|
|
3619
|
+
"x-a2a-extensions"
|
|
3555
3620
|
].join(",");
|
|
3556
3621
|
function buildAccessControlHook(options) {
|
|
3557
3622
|
const allowedOrigins = new Set(options.allowedOrigins.map((origin) => origin.toLowerCase()));
|
|
@@ -3939,10 +4004,10 @@ async function resolveManually(options) {
|
|
|
3939
4004
|
if (attempt === void 0) {
|
|
3940
4005
|
throw new CommerceError("RESOURCE_NOT_FOUND", `Payment attempt "${attemptId}" was not found`);
|
|
3941
4006
|
}
|
|
3942
|
-
const refuse = (
|
|
4007
|
+
const refuse = (refusal2, current2 = attempt) => ({
|
|
3943
4008
|
resolved: false,
|
|
3944
|
-
refusal,
|
|
3945
|
-
message: REFUSAL_MESSAGES[
|
|
4009
|
+
refusal: refusal2,
|
|
4010
|
+
message: REFUSAL_MESSAGES[refusal2],
|
|
3946
4011
|
attempt: current2
|
|
3947
4012
|
});
|
|
3948
4013
|
if (attempt.resolution !== void 0) return refuse("already_resolved");
|
|
@@ -4919,37 +4984,6 @@ async function createGateway(options) {
|
|
|
4919
4984
|
};
|
|
4920
4985
|
}
|
|
4921
4986
|
|
|
4922
|
-
// src/protocols/a2a/constants.ts
|
|
4923
|
-
var A2A_SPEC_VERSION = "1.0.1";
|
|
4924
|
-
var A2A_PROTOCOL_VERSION = "1.0";
|
|
4925
|
-
var A2A_PROTOCOL_BINDING = "JSONRPC";
|
|
4926
|
-
var A2A_AGENT_CARD_PATH = "/.well-known/agent-card.json";
|
|
4927
|
-
var A2A_DEFAULT_MOUNT_PATH = "/a2a";
|
|
4928
|
-
var A2A_JSON_MEDIA_TYPE = "application/json";
|
|
4929
|
-
var A2A_DEFAULT_AGENT_NAME = "agent-commerce";
|
|
4930
|
-
var A2A_VERSION_HEADER = "a2a-version";
|
|
4931
|
-
var A2A_METHOD_SEND_MESSAGE = "SendMessage";
|
|
4932
|
-
var A2A_PUSH_CONFIG_METHODS = [
|
|
4933
|
-
"CreateTaskPushNotificationConfig",
|
|
4934
|
-
"GetTaskPushNotificationConfig",
|
|
4935
|
-
"ListTaskPushNotificationConfigs",
|
|
4936
|
-
"DeleteTaskPushNotificationConfig"
|
|
4937
|
-
];
|
|
4938
|
-
var A2A_UNSUPPORTED_METHODS = [
|
|
4939
|
-
"SendStreamingMessage",
|
|
4940
|
-
"GetTask",
|
|
4941
|
-
"ListTasks",
|
|
4942
|
-
"CancelTask",
|
|
4943
|
-
"SubscribeToTask",
|
|
4944
|
-
...A2A_PUSH_CONFIG_METHODS,
|
|
4945
|
-
"GetExtendedAgentCard"
|
|
4946
|
-
];
|
|
4947
|
-
var A2A_TASK_LOOKUP_METHODS = ["GetTask", "CancelTask"];
|
|
4948
|
-
var A2A_TASK_STATE_COMPLETED = "TASK_STATE_COMPLETED";
|
|
4949
|
-
var A2A_TASK_STATE_FAILED = "TASK_STATE_FAILED";
|
|
4950
|
-
var A2A_TASK_STATE_INPUT_REQUIRED = "TASK_STATE_INPUT_REQUIRED";
|
|
4951
|
-
var A2A_EXTENSIONS_HEADER = "a2a-extensions";
|
|
4952
|
-
|
|
4953
4987
|
// src/protocols/a2a/jsonrpc.ts
|
|
4954
4988
|
var JSONRPC_PARSE_ERROR = -32700;
|
|
4955
4989
|
var JSONRPC_INVALID_REQUEST = -32600;
|
|
@@ -4959,10 +4993,12 @@ var JSONRPC_INTERNAL_ERROR = -32603;
|
|
|
4959
4993
|
var A2A_ERROR_TASK_NOT_FOUND = -32001;
|
|
4960
4994
|
var A2A_ERROR_PUSH_NOTIFICATION_NOT_SUPPORTED = -32003;
|
|
4961
4995
|
var A2A_ERROR_UNSUPPORTED_OPERATION = -32004;
|
|
4996
|
+
var A2A_ERROR_TASK_NOT_CANCELABLE = -32002;
|
|
4962
4997
|
var A2A_ERROR_CONTENT_TYPE_NOT_SUPPORTED = -32005;
|
|
4963
4998
|
var A2A_ERROR_VERSION_NOT_SUPPORTED = -32009;
|
|
4964
4999
|
var A2A_ERROR_REASONS = /* @__PURE__ */ new Map([
|
|
4965
5000
|
[A2A_ERROR_TASK_NOT_FOUND, "TASK_NOT_FOUND"],
|
|
5001
|
+
[A2A_ERROR_TASK_NOT_CANCELABLE, "TASK_NOT_CANCELABLE"],
|
|
4966
5002
|
[A2A_ERROR_PUSH_NOTIFICATION_NOT_SUPPORTED, "PUSH_NOTIFICATION_NOT_SUPPORTED"],
|
|
4967
5003
|
[A2A_ERROR_UNSUPPORTED_OPERATION, "UNSUPPORTED_OPERATION"],
|
|
4968
5004
|
[A2A_ERROR_CONTENT_TYPE_NOT_SUPPORTED, "CONTENT_TYPE_NOT_SUPPORTED"],
|
|
@@ -4975,23 +5011,24 @@ function readId(value) {
|
|
|
4975
5011
|
function jsonRpcResult(id, result) {
|
|
4976
5012
|
return { jsonrpc: "2.0", id, result };
|
|
4977
5013
|
}
|
|
4978
|
-
function jsonRpcError(id, code, message) {
|
|
5014
|
+
function jsonRpcError(id, code, message, details = []) {
|
|
4979
5015
|
const reason = A2A_ERROR_REASONS.get(code);
|
|
4980
|
-
const
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
} : {}
|
|
4992
|
-
};
|
|
5016
|
+
const data = [
|
|
5017
|
+
...reason !== void 0 ? [
|
|
5018
|
+
{
|
|
5019
|
+
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
|
|
5020
|
+
reason,
|
|
5021
|
+
domain: "a2a-protocol.org"
|
|
5022
|
+
}
|
|
5023
|
+
] : [],
|
|
5024
|
+
...details
|
|
5025
|
+
];
|
|
5026
|
+
const error = { code, message, ...data.length > 0 ? { data } : {} };
|
|
4993
5027
|
return { jsonrpc: "2.0", id, error };
|
|
4994
5028
|
}
|
|
5029
|
+
function retryInfo(seconds) {
|
|
5030
|
+
return { "@type": "type.googleapis.com/google.rpc.RetryInfo", retryDelay: `${seconds}s` };
|
|
5031
|
+
}
|
|
4995
5032
|
function parseJsonRpcRequest(rawBody) {
|
|
4996
5033
|
let payload;
|
|
4997
5034
|
try {
|
|
@@ -5056,6 +5093,205 @@ function parseJsonRpcRequest(rawBody) {
|
|
|
5056
5093
|
return { ok: true, request: { id, method, params: params ?? {} } };
|
|
5057
5094
|
}
|
|
5058
5095
|
|
|
5096
|
+
// src/protocols/a2a/params.ts
|
|
5097
|
+
function invalid2(message) {
|
|
5098
|
+
return new CommerceError("INPUT_INVALID", message);
|
|
5099
|
+
}
|
|
5100
|
+
function unsupported(message, a2aErrorCode) {
|
|
5101
|
+
return new CommerceError(
|
|
5102
|
+
"PROTOCOL_UNSUPPORTED",
|
|
5103
|
+
message,
|
|
5104
|
+
a2aErrorCode !== void 0 ? { details: { a2aErrorCode } } : {}
|
|
5105
|
+
);
|
|
5106
|
+
}
|
|
5107
|
+
var PROTO_NAME_WORD = /_([a-z0-9])/g;
|
|
5108
|
+
function jsonNames(value, where) {
|
|
5109
|
+
const sentAs = /* @__PURE__ */ new Map();
|
|
5110
|
+
const entries = [];
|
|
5111
|
+
for (const [key, field] of Object.entries(value)) {
|
|
5112
|
+
const name = key.replace(PROTO_NAME_WORD, (_, next) => next.toUpperCase());
|
|
5113
|
+
const earlier = sentAs.get(name);
|
|
5114
|
+
if (earlier !== void 0) {
|
|
5115
|
+
throw invalid2(`${where} sends "${earlier}" and "${key}", two names for one field: send one.`);
|
|
5116
|
+
}
|
|
5117
|
+
sentAs.set(name, key);
|
|
5118
|
+
entries.push([name, field]);
|
|
5119
|
+
}
|
|
5120
|
+
return Object.fromEntries(entries);
|
|
5121
|
+
}
|
|
5122
|
+
function read(params, key) {
|
|
5123
|
+
const value = params[key];
|
|
5124
|
+
return value === null ? void 0 : value;
|
|
5125
|
+
}
|
|
5126
|
+
function checkTenant(params) {
|
|
5127
|
+
const tenant = read(params, "tenant");
|
|
5128
|
+
if (tenant === void 0 || tenant === "") return;
|
|
5129
|
+
if (typeof tenant !== "string") throw invalid2('"tenant" must be a string.');
|
|
5130
|
+
throw unsupported('Tenants are not supported: omit "tenant" or send an empty string.');
|
|
5131
|
+
}
|
|
5132
|
+
function checkMetadata(params) {
|
|
5133
|
+
const metadata = read(params, "metadata");
|
|
5134
|
+
if (metadata !== void 0 && !isRecord(metadata)) {
|
|
5135
|
+
throw invalid2('"metadata" must be a JSON object.');
|
|
5136
|
+
}
|
|
5137
|
+
}
|
|
5138
|
+
var INT32_MAX = 2147483647;
|
|
5139
|
+
function readInteger(value, name, min, max = INT32_MAX) {
|
|
5140
|
+
if (value === void 0) return void 0;
|
|
5141
|
+
const n = typeof value === "number" ? value : typeof value === "string" && /^-?\d+$/.test(value) ? Number(value) : Number.NaN;
|
|
5142
|
+
if (!Number.isInteger(n) || n < min || n > max) {
|
|
5143
|
+
throw invalid2(`"${name}" must be an integer from ${min} to ${max}.`);
|
|
5144
|
+
}
|
|
5145
|
+
return n;
|
|
5146
|
+
}
|
|
5147
|
+
function readBoolean(value, name) {
|
|
5148
|
+
if (value === void 0) return void 0;
|
|
5149
|
+
if (typeof value !== "boolean") throw invalid2(`"${name}" must be true or false.`);
|
|
5150
|
+
return value;
|
|
5151
|
+
}
|
|
5152
|
+
var UTC_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/;
|
|
5153
|
+
function isUtcTimestamp(value) {
|
|
5154
|
+
if (!UTC_TIMESTAMP.test(value)) return false;
|
|
5155
|
+
const ms = Date.parse(value);
|
|
5156
|
+
return Number.isFinite(ms) && new Date(ms).toISOString().slice(0, 19) === value.slice(0, 19);
|
|
5157
|
+
}
|
|
5158
|
+
function admitsJson(range) {
|
|
5159
|
+
const type = (range.split(";")[0] ?? "").trim().toLowerCase();
|
|
5160
|
+
return type === A2A_JSON_MEDIA_TYPE || type === "application/*" || type === "*/*";
|
|
5161
|
+
}
|
|
5162
|
+
function readSendMessageParams(raw) {
|
|
5163
|
+
const params = jsonNames(raw, "The request");
|
|
5164
|
+
const message = params["message"];
|
|
5165
|
+
if (isRecord(message)) {
|
|
5166
|
+
const named = jsonNames(message, "The message");
|
|
5167
|
+
const parts = named["parts"];
|
|
5168
|
+
params["message"] = Array.isArray(parts) ? {
|
|
5169
|
+
...named,
|
|
5170
|
+
parts: parts.map((part) => isRecord(part) ? jsonNames(part, "A message part") : part)
|
|
5171
|
+
} : named;
|
|
5172
|
+
}
|
|
5173
|
+
checkTenant(params);
|
|
5174
|
+
checkMetadata(params);
|
|
5175
|
+
const configuration = read(params, "configuration");
|
|
5176
|
+
if (configuration === void 0) return { params, returnImmediately: false };
|
|
5177
|
+
if (!isRecord(configuration)) throw invalid2('"configuration" must be a JSON object.');
|
|
5178
|
+
const options = jsonNames(configuration, "The configuration");
|
|
5179
|
+
if (read(options, "taskPushNotificationConfig") !== void 0) {
|
|
5180
|
+
throw unsupported(
|
|
5181
|
+
'Push notifications are not supported: omit "configuration.taskPushNotificationConfig".',
|
|
5182
|
+
A2A_ERROR_PUSH_NOTIFICATION_NOT_SUPPORTED
|
|
5183
|
+
);
|
|
5184
|
+
}
|
|
5185
|
+
const modes = read(options, "acceptedOutputModes");
|
|
5186
|
+
if (modes !== void 0) {
|
|
5187
|
+
if (!Array.isArray(modes) || !modes.every((mode) => typeof mode === "string")) {
|
|
5188
|
+
throw invalid2('"configuration.acceptedOutputModes" must be an array of media types.');
|
|
5189
|
+
}
|
|
5190
|
+
if (modes.length > 0 && !modes.some(admitsJson)) {
|
|
5191
|
+
throw unsupported(
|
|
5192
|
+
`This agent answers in ${A2A_JSON_MEDIA_TYPE} only: list it in "configuration.acceptedOutputModes", or omit the field.`,
|
|
5193
|
+
A2A_ERROR_CONTENT_TYPE_NOT_SUPPORTED
|
|
5194
|
+
);
|
|
5195
|
+
}
|
|
5196
|
+
}
|
|
5197
|
+
const historyLength = readInteger(
|
|
5198
|
+
read(options, "historyLength"),
|
|
5199
|
+
"configuration.historyLength",
|
|
5200
|
+
0
|
|
5201
|
+
);
|
|
5202
|
+
return {
|
|
5203
|
+
params,
|
|
5204
|
+
...historyLength !== void 0 ? { historyLength } : {},
|
|
5205
|
+
returnImmediately: readBoolean(read(options, "returnImmediately"), "configuration.returnImmediately") ?? false
|
|
5206
|
+
};
|
|
5207
|
+
}
|
|
5208
|
+
function taskOperationParams(raw) {
|
|
5209
|
+
const params = jsonNames(raw, "The request");
|
|
5210
|
+
checkTenant(params);
|
|
5211
|
+
return params;
|
|
5212
|
+
}
|
|
5213
|
+
function readTaskId(params) {
|
|
5214
|
+
const id = read(params, "id");
|
|
5215
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
5216
|
+
throw invalid2('The request must carry a non-empty task "id".');
|
|
5217
|
+
}
|
|
5218
|
+
return id;
|
|
5219
|
+
}
|
|
5220
|
+
function readGetTaskParams(raw) {
|
|
5221
|
+
const params = taskOperationParams(raw);
|
|
5222
|
+
const id = readTaskId(params);
|
|
5223
|
+
const historyLength = readInteger(read(params, "historyLength"), "historyLength", 0);
|
|
5224
|
+
return { id, ...historyLength !== void 0 ? { historyLength } : {} };
|
|
5225
|
+
}
|
|
5226
|
+
function readCancelTaskParams(raw) {
|
|
5227
|
+
const params = taskOperationParams(raw);
|
|
5228
|
+
checkMetadata(params);
|
|
5229
|
+
return { id: readTaskId(params) };
|
|
5230
|
+
}
|
|
5231
|
+
var TASK_STATES = [
|
|
5232
|
+
"TASK_STATE_SUBMITTED",
|
|
5233
|
+
"TASK_STATE_WORKING",
|
|
5234
|
+
"TASK_STATE_COMPLETED",
|
|
5235
|
+
"TASK_STATE_FAILED",
|
|
5236
|
+
"TASK_STATE_CANCELED",
|
|
5237
|
+
"TASK_STATE_INPUT_REQUIRED",
|
|
5238
|
+
"TASK_STATE_REJECTED",
|
|
5239
|
+
"TASK_STATE_AUTH_REQUIRED"
|
|
5240
|
+
];
|
|
5241
|
+
var A2A_LIST_PAGE_SIZE = { default: 50, max: 100 };
|
|
5242
|
+
function encodePageToken(cursor) {
|
|
5243
|
+
return Buffer.from(JSON.stringify([cursor.updatedAt, cursor.id]), "utf8").toString("base64url");
|
|
5244
|
+
}
|
|
5245
|
+
function decodePageToken(token) {
|
|
5246
|
+
if (!/^[A-Za-z0-9_-]+$/.test(token)) return void 0;
|
|
5247
|
+
let value;
|
|
5248
|
+
try {
|
|
5249
|
+
value = JSON.parse(Buffer.from(token, "base64url").toString("utf8"));
|
|
5250
|
+
} catch {
|
|
5251
|
+
return void 0;
|
|
5252
|
+
}
|
|
5253
|
+
if (!Array.isArray(value) || value.length !== 2) return void 0;
|
|
5254
|
+
const [updatedAt, id] = value;
|
|
5255
|
+
return typeof updatedAt === "string" && isUtcTimestamp(updatedAt) && typeof id === "string" && id.length > 0 ? { updatedAt, id } : void 0;
|
|
5256
|
+
}
|
|
5257
|
+
function readListTasksParams(raw) {
|
|
5258
|
+
const params = taskOperationParams(raw);
|
|
5259
|
+
const contextId = read(params, "contextId");
|
|
5260
|
+
if (contextId !== void 0 && typeof contextId !== "string") {
|
|
5261
|
+
throw invalid2('"contextId" must be a string.');
|
|
5262
|
+
}
|
|
5263
|
+
const status = read(params, "status");
|
|
5264
|
+
if (status !== void 0 && status !== "TASK_STATE_UNSPECIFIED" && !(typeof status === "string" && TASK_STATES.includes(status))) {
|
|
5265
|
+
throw invalid2('"status" must be a TaskState name, such as "TASK_STATE_COMPLETED".');
|
|
5266
|
+
}
|
|
5267
|
+
const pageSize = readInteger(read(params, "pageSize"), "pageSize", 1, A2A_LIST_PAGE_SIZE.max) ?? A2A_LIST_PAGE_SIZE.default;
|
|
5268
|
+
const pageToken = read(params, "pageToken");
|
|
5269
|
+
let after;
|
|
5270
|
+
if (pageToken !== void 0 && pageToken !== "") {
|
|
5271
|
+
after = typeof pageToken === "string" ? decodePageToken(pageToken) : void 0;
|
|
5272
|
+
if (after === void 0) {
|
|
5273
|
+
throw invalid2('"pageToken" must be a nextPageToken this agent returned.');
|
|
5274
|
+
}
|
|
5275
|
+
}
|
|
5276
|
+
const historyLength = readInteger(read(params, "historyLength"), "historyLength", 0);
|
|
5277
|
+
const statusTimestampAfter = read(params, "statusTimestampAfter");
|
|
5278
|
+
if (statusTimestampAfter !== void 0 && !(typeof statusTimestampAfter === "string" && isUtcTimestamp(statusTimestampAfter))) {
|
|
5279
|
+
throw invalid2(
|
|
5280
|
+
'"statusTimestampAfter" must be a UTC timestamp such as "2026-01-01T00:00:00.000Z".'
|
|
5281
|
+
);
|
|
5282
|
+
}
|
|
5283
|
+
const includeArtifacts = readBoolean(read(params, "includeArtifacts"), "includeArtifacts");
|
|
5284
|
+
return {
|
|
5285
|
+
...typeof contextId === "string" && contextId !== "" ? { contextId } : {},
|
|
5286
|
+
...typeof status === "string" && status !== "TASK_STATE_UNSPECIFIED" ? { status } : {},
|
|
5287
|
+
pageSize,
|
|
5288
|
+
...after !== void 0 ? { after } : {},
|
|
5289
|
+
...historyLength !== void 0 ? { historyLength } : {},
|
|
5290
|
+
...typeof statusTimestampAfter === "string" ? { statusTimestampAfter } : {},
|
|
5291
|
+
includeArtifacts: includeArtifacts ?? false
|
|
5292
|
+
};
|
|
5293
|
+
}
|
|
5294
|
+
|
|
5059
5295
|
// src/protocols/a2a/message-mapping.ts
|
|
5060
5296
|
var A2A_USER_ROLE = "ROLE_USER";
|
|
5061
5297
|
var A2A_CALL_SHAPE = 'one data part {"resource": "<skill id>", "input": {...}}';
|
|
@@ -5075,21 +5311,26 @@ var ParamsSchema = z.object({
|
|
|
5075
5311
|
taskId: z.string().optional(),
|
|
5076
5312
|
contextId: z.string().optional()
|
|
5077
5313
|
});
|
|
5078
|
-
function
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
)
|
|
5314
|
+
function readMessage(rawParams) {
|
|
5315
|
+
const parsed = ParamsSchema.safeParse(rawParams);
|
|
5316
|
+
if (!parsed.success) {
|
|
5317
|
+
throw invalid2(
|
|
5318
|
+
'Request must carry a "message" with a "role" and a "parts" array of structured data parts.'
|
|
5319
|
+
);
|
|
5320
|
+
}
|
|
5321
|
+
const message = parsed.data.message;
|
|
5322
|
+
if (message.messageId === void 0 || message.messageId.length === 0) {
|
|
5323
|
+
throw invalid2('Message must carry a non-empty "messageId".');
|
|
5324
|
+
}
|
|
5325
|
+
const roleProblem = userRoleProblem(message.role);
|
|
5326
|
+
if (roleProblem !== void 0) throw invalid2(roleProblem);
|
|
5327
|
+
return parsed.data;
|
|
5087
5328
|
}
|
|
5088
5329
|
function assertNoContinuation(params) {
|
|
5089
5330
|
const message = params.message;
|
|
5090
5331
|
if (params.taskId !== void 0 || message.taskId !== void 0) {
|
|
5091
5332
|
throw unsupported(
|
|
5092
|
-
"Task not found:
|
|
5333
|
+
"Task not found: send the message without a taskId to start a new task.",
|
|
5093
5334
|
A2A_ERROR_TASK_NOT_FOUND
|
|
5094
5335
|
);
|
|
5095
5336
|
}
|
|
@@ -5127,21 +5368,10 @@ function assertSupportedPart(part) {
|
|
|
5127
5368
|
}
|
|
5128
5369
|
}
|
|
5129
5370
|
function parseInvocation(rawParams) {
|
|
5130
|
-
const
|
|
5131
|
-
if (!parsed.success) {
|
|
5132
|
-
throw invalid2(
|
|
5133
|
-
'Request must carry a "message" with a "role" and a "parts" array of structured data parts.'
|
|
5134
|
-
);
|
|
5135
|
-
}
|
|
5136
|
-
const params = parsed.data;
|
|
5371
|
+
const params = readMessage(rawParams);
|
|
5137
5372
|
const message = params.message;
|
|
5138
|
-
if (message.messageId === void 0 || message.messageId.length === 0) {
|
|
5139
|
-
throw invalid2('Message must carry a non-empty "messageId".');
|
|
5140
|
-
}
|
|
5141
5373
|
const messageId = message.messageId;
|
|
5142
5374
|
assertNoContinuation(params);
|
|
5143
|
-
const roleProblem = userRoleProblem(message.role);
|
|
5144
|
-
if (roleProblem !== void 0) throw invalid2(roleProblem);
|
|
5145
5375
|
if (message.parts.length === 0) {
|
|
5146
5376
|
throw invalid2("Message carries no parts: send exactly one structured data part.");
|
|
5147
5377
|
}
|
|
@@ -5194,6 +5424,9 @@ function expiryMs(nowMs, expiresAt) {
|
|
|
5194
5424
|
const ttl = Number.isFinite(requested) ? requested - nowMs : DEFAULT_PENDING_TTL_MS;
|
|
5195
5425
|
return nowMs + Math.min(Math.max(ttl, 0), MAX_PENDING_TTL_MS);
|
|
5196
5426
|
}
|
|
5427
|
+
function pendingExpiresAt(nowMs, expiresAt) {
|
|
5428
|
+
return new Date(expiryMs(nowMs, expiresAt)).toISOString();
|
|
5429
|
+
}
|
|
5197
5430
|
function createPendingPayments(clock, maxEntries = MAX_PENDING_PAYMENTS) {
|
|
5198
5431
|
const tasks = /* @__PURE__ */ new Map();
|
|
5199
5432
|
const now = () => clock.now().getTime();
|
|
@@ -5431,14 +5664,46 @@ function buildAgentCard(options) {
|
|
|
5431
5664
|
};
|
|
5432
5665
|
}
|
|
5433
5666
|
|
|
5667
|
+
// src/protocols/a2a/background.ts
|
|
5668
|
+
function createBackgroundRuns(limit, logger) {
|
|
5669
|
+
let claimed = 0;
|
|
5670
|
+
const runs = /* @__PURE__ */ new Set();
|
|
5671
|
+
return {
|
|
5672
|
+
reserve() {
|
|
5673
|
+
if (claimed >= limit) return false;
|
|
5674
|
+
claimed += 1;
|
|
5675
|
+
return true;
|
|
5676
|
+
},
|
|
5677
|
+
release() {
|
|
5678
|
+
claimed -= 1;
|
|
5679
|
+
},
|
|
5680
|
+
start(work) {
|
|
5681
|
+
const run = work().then(
|
|
5682
|
+
() => void 0,
|
|
5683
|
+
// Callers record task outcomes; log unexpected rejections at error
|
|
5684
|
+
(err) => {
|
|
5685
|
+
logger.error({ err: toLogInfo(err) }, "a2a adapter: background task failed");
|
|
5686
|
+
}
|
|
5687
|
+
).finally(() => {
|
|
5688
|
+
claimed -= 1;
|
|
5689
|
+
runs.delete(run);
|
|
5690
|
+
});
|
|
5691
|
+
runs.add(run);
|
|
5692
|
+
},
|
|
5693
|
+
async settled() {
|
|
5694
|
+
while (runs.size > 0) await Promise.allSettled([...runs]);
|
|
5695
|
+
}
|
|
5696
|
+
};
|
|
5697
|
+
}
|
|
5698
|
+
|
|
5434
5699
|
// src/support/a2a.json
|
|
5435
5700
|
var a2a_default = {
|
|
5436
5701
|
name: "a2a",
|
|
5437
5702
|
kind: "protocol",
|
|
5438
5703
|
title: "A2A",
|
|
5439
|
-
status: "
|
|
5704
|
+
status: "supported",
|
|
5440
5705
|
role: "Transport that carries x402 and MPP payments in `SendMessage`, including through the x402 extension.",
|
|
5441
|
-
subset: "Agent Card, `SendMessage`,
|
|
5706
|
+
subset: "Agent Card, `SendMessage` with `returnImmediately`, `GetTask`, `ListTasks`, `CancelTask` and the paid flow",
|
|
5442
5707
|
spec: {
|
|
5443
5708
|
revisions: ["1.0.1"],
|
|
5444
5709
|
display: "v1.0.1; negotiation `1.0`; `JSONRPC` binding",
|
|
@@ -5453,16 +5718,47 @@ var a2a_default = {
|
|
|
5453
5718
|
packages: [{ name: "@a2a-js/sdk", use: "test" }],
|
|
5454
5719
|
artifacts: [],
|
|
5455
5720
|
features: [
|
|
5456
|
-
{ name: "agent-card", status: "
|
|
5457
|
-
{ name: "jsonrpc", status: "
|
|
5458
|
-
{ name: "SendMessage", status: "
|
|
5459
|
-
{ name: "
|
|
5721
|
+
{ name: "agent-card", status: "supported" },
|
|
5722
|
+
{ name: "jsonrpc", status: "supported" },
|
|
5723
|
+
{ name: "SendMessage", status: "supported" },
|
|
5724
|
+
{ name: "GetTask", status: "supported" },
|
|
5725
|
+
{ name: "ListTasks", status: "supported" },
|
|
5726
|
+
{ name: "CancelTask", status: "supported" },
|
|
5727
|
+
{ name: "returnImmediately", status: "supported" },
|
|
5728
|
+
{
|
|
5729
|
+
name: "x402-extension",
|
|
5730
|
+
status: "experimental",
|
|
5731
|
+
spec: {
|
|
5732
|
+
revisions: ["v0.1"],
|
|
5733
|
+
display: "v0.1.0, commit `a5590226`",
|
|
5734
|
+
source: {
|
|
5735
|
+
repo: "google-agentic-commerce/a2a-x402",
|
|
5736
|
+
commit: "a5590226fc4190fe7a9d2c13ab70128714db3125"
|
|
5737
|
+
},
|
|
5738
|
+
stable: null,
|
|
5739
|
+
statement: "A2A Protocol: x402 Payments Extension v0.1",
|
|
5740
|
+
checked: "2026-11-26"
|
|
5741
|
+
},
|
|
5742
|
+
title: "A2A x402 extension",
|
|
5743
|
+
alias: "a2a-x402 extension",
|
|
5744
|
+
role: "A2A feature: x402 payment inside a task, through status message metadata and a follow-up payment message.",
|
|
5745
|
+
subset: "`TASK_STATE_INPUT_REQUIRED` with x402 v2 requirements, payment by a follow-up message on the task, receipts in the final status; A2A 1.0 wire forms, x402 only",
|
|
5746
|
+
conformance: {
|
|
5747
|
+
suite: "Our tests against the MUST statements of a2a-x402 v0.1; upstream's tests cover only its Python library.",
|
|
5748
|
+
tests: [
|
|
5749
|
+
"tests/integration/a2a-x402-extension.test.ts",
|
|
5750
|
+
"tests/unit/protocols-a2a/x402-extension.test.ts",
|
|
5751
|
+
"tests/unit/protocols-a2a/payment-resume.test.ts",
|
|
5752
|
+
"tests/unit/protocols-a2a/agent-card.test.ts",
|
|
5753
|
+
"tests/unit/core/execution/pipeline.test.ts",
|
|
5754
|
+
"tests/unit/cli/doctor.test.ts"
|
|
5755
|
+
],
|
|
5756
|
+
skipped: []
|
|
5757
|
+
}
|
|
5758
|
+
}
|
|
5460
5759
|
],
|
|
5461
5760
|
exclusions: [
|
|
5462
5761
|
{ name: "SendStreamingMessage" },
|
|
5463
|
-
{ name: "GetTask" },
|
|
5464
|
-
{ name: "ListTasks" },
|
|
5465
|
-
{ name: "CancelTask" },
|
|
5466
5762
|
{ name: "SubscribeToTask" },
|
|
5467
5763
|
{ name: "CreateTaskPushNotificationConfig" },
|
|
5468
5764
|
{ name: "GetTaskPushNotificationConfig" },
|
|
@@ -5472,10 +5768,26 @@ var a2a_default = {
|
|
|
5472
5768
|
{ name: "HTTP+JSON/REST binding" },
|
|
5473
5769
|
{ name: "gRPC binding" },
|
|
5474
5770
|
{ name: "SSE" },
|
|
5475
|
-
{
|
|
5771
|
+
{
|
|
5772
|
+
name: "resuming a background task after a restart",
|
|
5773
|
+
note: "A task the gateway stopped in reads as failed; any payment is in the gateway records."
|
|
5774
|
+
},
|
|
5476
5775
|
{ name: "task resumption other than an x402 extension payment" },
|
|
5477
5776
|
{ name: "push notifications" },
|
|
5478
5777
|
{ name: "multi-turn conversational continuation" },
|
|
5778
|
+
{
|
|
5779
|
+
name: "client-chosen contextId",
|
|
5780
|
+
note: "A `contextId` without a task gets `UnsupportedOperationError`; each new task opens a context the gateway generates."
|
|
5781
|
+
},
|
|
5782
|
+
{
|
|
5783
|
+
name: "listing tasks across contexts",
|
|
5784
|
+
note: "`ListTasks` reads only the given `contextId`; without one, the page is empty."
|
|
5785
|
+
},
|
|
5786
|
+
{
|
|
5787
|
+
name: "task history",
|
|
5788
|
+
note: "Tasks omit `history`; `historyLength` is validated but has nothing to cap."
|
|
5789
|
+
},
|
|
5790
|
+
{ name: "non-empty tenant" },
|
|
5479
5791
|
{ name: "text parts" },
|
|
5480
5792
|
{ name: "file and URL parts (including inline bytes)" },
|
|
5481
5793
|
{ name: "multi-part messages" },
|
|
@@ -5484,38 +5796,347 @@ var a2a_default = {
|
|
|
5484
5796
|
{ name: "A2A authentication schemes" },
|
|
5485
5797
|
{ name: "artifact types beyond Agent Commerce outcome data" },
|
|
5486
5798
|
{
|
|
5487
|
-
name: "
|
|
5488
|
-
note: "Instances with separate receipt stores cannot
|
|
5489
|
-
}
|
|
5490
|
-
],
|
|
5491
|
-
deviations: [
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
"tests/conformance/a2a/
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
"
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5799
|
+
name: "tasks across gateway instances",
|
|
5800
|
+
note: "Instances with separate receipt stores cannot read, cancel or pay each other's tasks."
|
|
5801
|
+
}
|
|
5802
|
+
],
|
|
5803
|
+
deviations: [
|
|
5804
|
+
{
|
|
5805
|
+
summary: "A `ListTasks` page with no matching task has an empty `tasks` array. The proto marks `tasks` REQUIRED, and \xA75.7 requires a REQUIRED array to hold an element, but an empty result has none to return.",
|
|
5806
|
+
spec: "A2A 1.0.1 \xA75.7; `ListTasksResponse.tasks`",
|
|
5807
|
+
tests: ["tests/conformance/a2a/tasks.test.ts"]
|
|
5808
|
+
},
|
|
5809
|
+
{
|
|
5810
|
+
summary: 'The x402 extension uses A2A 1.0 wire forms, such as `TASK_STATE_INPUT_REQUIRED` and `ROLE_USER`, not the A2A 0.3 forms of the v0.1 examples. A payment message with `role: "user"` gets `-32602`, and the task still waits for payment.',
|
|
5811
|
+
spec: "a2a-x402 v0.1 examples",
|
|
5812
|
+
tests: ["tests/integration/a2a-x402-extension.test.ts"]
|
|
5813
|
+
}
|
|
5814
|
+
],
|
|
5815
|
+
conformance: {
|
|
5816
|
+
suite: "Our tests against the A2A 1.0.1 specification, and the A2A TCK at MUST level in CI.",
|
|
5817
|
+
tests: [
|
|
5818
|
+
"tests/conformance/a2a/agent-card.test.ts",
|
|
5819
|
+
"tests/conformance/a2a/errors.test.ts",
|
|
5820
|
+
"tests/conformance/a2a/free-resource.test.ts",
|
|
5821
|
+
"tests/conformance/a2a/paid-resource.test.ts",
|
|
5822
|
+
"tests/conformance/a2a/params.test.ts",
|
|
5823
|
+
"tests/conformance/a2a/protocol-version.test.ts",
|
|
5824
|
+
"tests/conformance/a2a/tasks.test.ts"
|
|
5825
|
+
],
|
|
5826
|
+
skipped: [],
|
|
5827
|
+
upstream: {
|
|
5828
|
+
repo: "a2aproject/a2a-tck",
|
|
5829
|
+
commit: "5e6f37c2d38eb3d7684686243c34d365c83df49b",
|
|
5830
|
+
command: "run_tck.py --sut-host http://127.0.0.1:8099 --transport jsonrpc --level must",
|
|
5831
|
+
workflow: ".github/workflows/ci.yml",
|
|
5832
|
+
job: "tck",
|
|
5833
|
+
results: [
|
|
5834
|
+
{
|
|
5835
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-SEND-001-jsonrpc]",
|
|
5836
|
+
id: "CORE-SEND-001",
|
|
5837
|
+
outcome: "failed",
|
|
5838
|
+
message: "Text parts are not supported",
|
|
5839
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5840
|
+
upstream: "Report drafted, not filed"
|
|
5841
|
+
},
|
|
5842
|
+
{
|
|
5843
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-EXECUTION-MODE-001-jsonrpc]",
|
|
5844
|
+
id: "CORE-EXECUTION-MODE-001",
|
|
5845
|
+
outcome: "failed",
|
|
5846
|
+
message: "Text parts are not supported",
|
|
5847
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5848
|
+
upstream: "Report drafted, not filed"
|
|
5849
|
+
},
|
|
5850
|
+
{
|
|
5851
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-EXECUTION-MODE-002-jsonrpc]",
|
|
5852
|
+
id: "CORE-EXECUTION-MODE-002",
|
|
5853
|
+
outcome: "failed",
|
|
5854
|
+
message: "Text parts are not supported",
|
|
5855
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5856
|
+
upstream: "Report drafted, not filed"
|
|
5857
|
+
},
|
|
5858
|
+
{
|
|
5859
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-MULTI-001a-jsonrpc]",
|
|
5860
|
+
id: "CORE-MULTI-001a",
|
|
5861
|
+
outcome: "failed",
|
|
5862
|
+
message: "Text parts are not supported",
|
|
5863
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5864
|
+
upstream: "Report drafted, not filed"
|
|
5865
|
+
},
|
|
5866
|
+
{
|
|
5867
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-MULTI-003-jsonrpc]",
|
|
5868
|
+
id: "CORE-MULTI-003",
|
|
5869
|
+
outcome: "failed",
|
|
5870
|
+
message: "Text parts are not supported",
|
|
5871
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5872
|
+
upstream: "Report drafted, not filed"
|
|
5873
|
+
},
|
|
5874
|
+
{
|
|
5875
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-MULTI-002a-jsonrpc]",
|
|
5876
|
+
id: "CORE-MULTI-002a",
|
|
5877
|
+
outcome: "failed",
|
|
5878
|
+
message: "Multi-turn conversational continuation is not supported",
|
|
5879
|
+
reason: "The adapter refuses the client contextId with -32004, as the requirement asks, but the requirement sets no expected error and the runner fails on any error. Its sample input also sends a text part.",
|
|
5880
|
+
spec: "A2A 1.0.1 \xA73.4.1",
|
|
5881
|
+
upstream: "Report drafted, not filed"
|
|
5882
|
+
},
|
|
5883
|
+
{
|
|
5884
|
+
test: "tests.compatibility.core_operations.test_transport_behavior.TestJsonRpcFormat::test_response_validates_jsonrpc_envelope",
|
|
5885
|
+
id: "JSONRPC-FMT-001",
|
|
5886
|
+
outcome: "failed",
|
|
5887
|
+
message: "Text parts are not supported",
|
|
5888
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5889
|
+
upstream: "Report drafted, not filed"
|
|
5890
|
+
},
|
|
5891
|
+
{
|
|
5892
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestTextArtifact::test_task_has_text_artifact[jsonrpc]",
|
|
5893
|
+
id: "DM-ART-001",
|
|
5894
|
+
outcome: "skipped",
|
|
5895
|
+
message: "send_message failed: Text parts are not supported",
|
|
5896
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5897
|
+
upstream: "Report drafted, not filed"
|
|
5898
|
+
},
|
|
5899
|
+
{
|
|
5900
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestFileArtifact::test_task_has_file_artifact[jsonrpc]",
|
|
5901
|
+
id: "DM-ART-001",
|
|
5902
|
+
outcome: "skipped",
|
|
5903
|
+
message: "send_message failed: Text parts are not supported",
|
|
5904
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5905
|
+
upstream: "Report drafted, not filed"
|
|
5906
|
+
},
|
|
5907
|
+
{
|
|
5908
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestFileUrlArtifact::test_task_has_file_url_artifact[jsonrpc]",
|
|
5909
|
+
id: "DM-ART-001",
|
|
5910
|
+
outcome: "skipped",
|
|
5911
|
+
message: "send_message failed: Text parts are not supported",
|
|
5912
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5913
|
+
upstream: "Report drafted, not filed"
|
|
5914
|
+
},
|
|
5915
|
+
{
|
|
5916
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestDataArtifact::test_task_has_data_artifact[jsonrpc]",
|
|
5917
|
+
id: "DM-ART-001",
|
|
5918
|
+
outcome: "skipped",
|
|
5919
|
+
message: "send_message failed: Text parts are not supported",
|
|
5920
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5921
|
+
upstream: "Report drafted, not filed"
|
|
5922
|
+
},
|
|
5923
|
+
{
|
|
5924
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestMessageResponse::test_returns_message_with_text_part[jsonrpc]",
|
|
5925
|
+
id: "DM-MSG-001",
|
|
5926
|
+
outcome: "skipped",
|
|
5927
|
+
message: "send_message failed: Text parts are not supported",
|
|
5928
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5929
|
+
upstream: "Report drafted, not filed"
|
|
5930
|
+
},
|
|
5931
|
+
{
|
|
5932
|
+
test: "tests.compatibility.core_operations.test_task_history.TestHistoryLengthLimit::test_get_task_history_does_not_exceed_limit[jsonrpc]",
|
|
5933
|
+
id: "CORE-HIST-002",
|
|
5934
|
+
outcome: "skipped",
|
|
5935
|
+
message: "send_message failed: Text parts are not supported",
|
|
5936
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5937
|
+
upstream: "Report drafted, not filed"
|
|
5938
|
+
},
|
|
5939
|
+
{
|
|
5940
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestGetTask::test_get_task_returns_current_state[jsonrpc]",
|
|
5941
|
+
id: "CORE-GET-001",
|
|
5942
|
+
outcome: "skipped",
|
|
5943
|
+
message: "send_message failed: Text parts are not supported",
|
|
5944
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5945
|
+
upstream: "Report drafted, not filed"
|
|
5946
|
+
},
|
|
5947
|
+
{
|
|
5948
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestCancelTask::test_cancel_task_returns_updated_state[jsonrpc]",
|
|
5949
|
+
id: "CORE-CANCEL-001",
|
|
5950
|
+
outcome: "skipped",
|
|
5951
|
+
message: "send_message failed: Text parts are not supported",
|
|
5952
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5953
|
+
upstream: "Report drafted, not filed"
|
|
5954
|
+
},
|
|
5955
|
+
{
|
|
5956
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestCancelTask::test_cancel_terminal_task_returns_error[jsonrpc]",
|
|
5957
|
+
id: "CORE-CANCEL-002",
|
|
5958
|
+
outcome: "skipped",
|
|
5959
|
+
message: "send_message failed: Text parts are not supported",
|
|
5960
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5961
|
+
upstream: "Report drafted, not filed"
|
|
5962
|
+
},
|
|
5963
|
+
{
|
|
5964
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestMultiTurn::test_send_message_to_terminal_task[jsonrpc]",
|
|
5965
|
+
id: "CORE-SEND-002",
|
|
5966
|
+
outcome: "skipped",
|
|
5967
|
+
message: "send_message failed: Text parts are not supported",
|
|
5968
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5969
|
+
upstream: "Report drafted, not filed"
|
|
5970
|
+
},
|
|
5971
|
+
{
|
|
5972
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestMultiTurn::test_infer_context_from_task[jsonrpc]",
|
|
5973
|
+
id: "CORE-MULTI-005",
|
|
5974
|
+
outcome: "skipped",
|
|
5975
|
+
message: "send_message failed: Text parts are not supported",
|
|
5976
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5977
|
+
upstream: "Report drafted, not filed"
|
|
5978
|
+
},
|
|
5979
|
+
{
|
|
5980
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestMultiTurn::test_reject_mismatching_context[jsonrpc]",
|
|
5981
|
+
id: "CORE-MULTI-006",
|
|
5982
|
+
outcome: "skipped",
|
|
5983
|
+
message: "send_message failed: Text parts are not supported",
|
|
5984
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5985
|
+
upstream: "Report drafted, not filed"
|
|
5986
|
+
},
|
|
5987
|
+
{
|
|
5988
|
+
test: "tests.compatibility.core_operations.test_data_model.TestSendMessageResponseSchema::test_response_validates_against_schema",
|
|
5989
|
+
outcome: "skipped",
|
|
5990
|
+
message: "No successful send_message responses",
|
|
5991
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
5992
|
+
upstream: "Report drafted, not filed"
|
|
5993
|
+
},
|
|
5994
|
+
{
|
|
5995
|
+
test: "tests.compatibility.core_operations.test_data_model.TestCamelCaseFieldNames::test_no_snake_case_keys",
|
|
5996
|
+
id: "DM-SERIAL-001",
|
|
5997
|
+
outcome: "skipped",
|
|
5998
|
+
message: "No successful send_message responses",
|
|
5999
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
6000
|
+
upstream: "Report drafted, not filed"
|
|
6001
|
+
},
|
|
6002
|
+
{
|
|
6003
|
+
test: "tests.compatibility.core_operations.test_data_model.TestEnumSerialization::test_enum_values_are_strings",
|
|
6004
|
+
id: "DM-SERIAL-002",
|
|
6005
|
+
outcome: "skipped",
|
|
6006
|
+
message: "No successful send_message responses",
|
|
6007
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
6008
|
+
upstream: "Report drafted, not filed"
|
|
6009
|
+
},
|
|
6010
|
+
{
|
|
6011
|
+
test: "tests.compatibility.core_operations.test_data_model.TestTimestampFormat::test_timestamps_are_iso8601_utc",
|
|
6012
|
+
id: "DM-SERIAL-003",
|
|
6013
|
+
outcome: "skipped",
|
|
6014
|
+
message: "No successful send_message responses",
|
|
6015
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
6016
|
+
upstream: "Report drafted, not filed"
|
|
6017
|
+
}
|
|
6018
|
+
],
|
|
6019
|
+
skipClasses: [
|
|
6020
|
+
{
|
|
6021
|
+
reason: "The gateway serves only the JSON-RPC binding",
|
|
6022
|
+
messages: [
|
|
6023
|
+
"Transport 'http_json' not configured",
|
|
6024
|
+
"Transport 'grpc' not configured",
|
|
6025
|
+
"Transport 'grpc' not configured (filtered by --transport)",
|
|
6026
|
+
"Transport 'http_json' not configured (filtered by --transport)",
|
|
6027
|
+
"HTTP+JSON transport not configured",
|
|
6028
|
+
"gRPC transport not configured"
|
|
6029
|
+
]
|
|
6030
|
+
},
|
|
6031
|
+
{
|
|
6032
|
+
reason: "The Agent Card declares streaming false (excluded)",
|
|
6033
|
+
messages: [
|
|
6034
|
+
"Agent does not support streaming",
|
|
6035
|
+
"Agent card does not declare capabilities for: ['streaming']",
|
|
6036
|
+
'Streaming not supported: A2A method "SendStreamingMessage" is not supported by this deployment.'
|
|
6037
|
+
]
|
|
6038
|
+
},
|
|
6039
|
+
{
|
|
6040
|
+
reason: "The Agent Card declares push notifications false (excluded)",
|
|
6041
|
+
messages: ["Agent does not support push notifications"]
|
|
6042
|
+
},
|
|
6043
|
+
{
|
|
6044
|
+
reason: "The Agent Card declares no extended card (excluded)",
|
|
6045
|
+
messages: ["Agent does not declare extendedAgentCard capability"]
|
|
6046
|
+
},
|
|
6047
|
+
{
|
|
6048
|
+
reason: "The TCK's probe for an agent that requires its test extension; this card requires none",
|
|
6049
|
+
messages: ["Agent card does not declare urn:a2a:tck:required-extension as required"]
|
|
6050
|
+
}
|
|
6051
|
+
]
|
|
6052
|
+
}
|
|
6053
|
+
},
|
|
6054
|
+
gaps: [
|
|
6055
|
+
{
|
|
6056
|
+
requirement: "\xA73.1: GetTask, ListTasks and CancelTask, which every agent implements",
|
|
6057
|
+
state: "closed"
|
|
6058
|
+
},
|
|
6059
|
+
{
|
|
6060
|
+
requirement: "\xA73.2.2: returnImmediately as well as the blocking default",
|
|
6061
|
+
state: "closed"
|
|
6062
|
+
},
|
|
6063
|
+
{
|
|
6064
|
+
requirement: "\xA73.3.2: validate all input parameters, including tenant and configuration",
|
|
6065
|
+
state: "closed"
|
|
6066
|
+
},
|
|
6067
|
+
{
|
|
6068
|
+
requirement: "\xA77.1: encrypted communication in production; config accepts an http merchant.publicBaseUrl, and doctor warns when its host is not loopback",
|
|
6069
|
+
state: "closed"
|
|
6070
|
+
},
|
|
6071
|
+
{
|
|
6072
|
+
requirement: "\xA72: use the extension URI to declare and activate the extension",
|
|
6073
|
+
state: "closed",
|
|
6074
|
+
feature: "x402-extension"
|
|
6075
|
+
},
|
|
6076
|
+
{
|
|
6077
|
+
requirement: "\xA73: declare the extension in the Agent Card's capabilities.extensions, which the card does when a skill selects x402",
|
|
6078
|
+
state: "closed",
|
|
6079
|
+
feature: "x402-extension"
|
|
6080
|
+
},
|
|
6081
|
+
{
|
|
6082
|
+
requirement: "\xA73.1: clients understand x402 when the extension is required; the card declares it optional, and clients without it pay with _payment",
|
|
6083
|
+
state: "closed",
|
|
6084
|
+
feature: "x402-extension"
|
|
6085
|
+
},
|
|
6086
|
+
{
|
|
6087
|
+
requirement: "\xA74.5: the payment message carries taskId; the adapter finds the task by taskId alone, and an unknown id gets TaskNotFoundError",
|
|
6088
|
+
state: "closed",
|
|
6089
|
+
feature: "x402-extension"
|
|
6090
|
+
},
|
|
6091
|
+
{
|
|
6092
|
+
requirement: "\xA74.5: the final status message carries every receipt of the task; a task allows one settlement attempt",
|
|
6093
|
+
state: "closed",
|
|
6094
|
+
feature: "x402-extension"
|
|
6095
|
+
},
|
|
5504
6096
|
{
|
|
5505
|
-
requirement: "\
|
|
5506
|
-
state: "
|
|
6097
|
+
requirement: "\xA76: append each settlement attempt to x402.payment.receipts, never replace one",
|
|
6098
|
+
state: "closed",
|
|
6099
|
+
feature: "x402-extension"
|
|
5507
6100
|
},
|
|
5508
6101
|
{
|
|
5509
|
-
requirement: "\
|
|
5510
|
-
state: "
|
|
6102
|
+
requirement: "\xA77: clients activate with X-A2A-Extensions; the adapter also accepts A2A-Extensions",
|
|
6103
|
+
state: "closed",
|
|
6104
|
+
feature: "x402-extension"
|
|
5511
6105
|
},
|
|
5512
6106
|
{
|
|
5513
|
-
requirement: "\
|
|
5514
|
-
state: "
|
|
6107
|
+
requirement: "\xA77: echo the extension URI in the response headers of an activating request; the adapter echoes it on every JSON-RPC result, never on a JSON-RPC error",
|
|
6108
|
+
state: "closed",
|
|
6109
|
+
feature: "x402-extension"
|
|
5515
6110
|
},
|
|
5516
6111
|
{
|
|
5517
|
-
requirement: "\
|
|
5518
|
-
state: "
|
|
6112
|
+
requirement: "\xA78: on failure, payment-failed and a reason in the status message text and metadata",
|
|
6113
|
+
state: "closed",
|
|
6114
|
+
feature: "x402-extension"
|
|
6115
|
+
},
|
|
6116
|
+
{
|
|
6117
|
+
requirement: "\xA79: private keys stay with trusted entities, never an LLM; the gateway holds no buyer or merchant key and runs no model",
|
|
6118
|
+
state: "closed",
|
|
6119
|
+
feature: "x402-extension"
|
|
6120
|
+
},
|
|
6121
|
+
{
|
|
6122
|
+
requirement: "\xA79: verify every signature before settlement",
|
|
6123
|
+
state: "closed",
|
|
6124
|
+
feature: "x402-extension"
|
|
6125
|
+
},
|
|
6126
|
+
{
|
|
6127
|
+
requirement: "\xA79: validate all payment data structures",
|
|
6128
|
+
state: "closed",
|
|
6129
|
+
feature: "x402-extension"
|
|
6130
|
+
},
|
|
6131
|
+
{
|
|
6132
|
+
requirement: "\xA79: track used nonces against replay",
|
|
6133
|
+
state: "closed",
|
|
6134
|
+
feature: "x402-extension"
|
|
6135
|
+
},
|
|
6136
|
+
{
|
|
6137
|
+
requirement: "\xA79: all A2A traffic over HTTPS/TLS; TLS is the deployment's, and doctor warns on a public http base URL",
|
|
6138
|
+
state: "closed",
|
|
6139
|
+
feature: "x402-extension"
|
|
5519
6140
|
}
|
|
5520
6141
|
],
|
|
5521
6142
|
docs: ["docs/protocols/a2a.md"]
|
|
@@ -5526,6 +6147,10 @@ var A2A_CAPABILITIES = [
|
|
|
5526
6147
|
"agent-card",
|
|
5527
6148
|
"jsonrpc",
|
|
5528
6149
|
"SendMessage",
|
|
6150
|
+
"GetTask",
|
|
6151
|
+
"ListTasks",
|
|
6152
|
+
"CancelTask",
|
|
6153
|
+
"returnImmediately",
|
|
5529
6154
|
// The x402 A2A transport, opt-in per request
|
|
5530
6155
|
"x402-extension"
|
|
5531
6156
|
];
|
|
@@ -5608,23 +6233,63 @@ function failedTask(error, identity) {
|
|
|
5608
6233
|
identity.statusMessageId
|
|
5609
6234
|
);
|
|
5610
6235
|
}
|
|
6236
|
+
var UNCHARGED_CODES = /* @__PURE__ */ new Set([
|
|
6237
|
+
"RESOURCE_NOT_FOUND",
|
|
6238
|
+
"INPUT_INVALID",
|
|
6239
|
+
"PAYMENT_INVALID",
|
|
6240
|
+
"PAYMENT_REPLAYED",
|
|
6241
|
+
"AUTHORIZATION_REQUIRED",
|
|
6242
|
+
"AUTHORIZATION_INVALID",
|
|
6243
|
+
"AUTHORIZATION_REPLAYED",
|
|
6244
|
+
"AUTHORIZATION_PROVIDER_UNAVAILABLE"
|
|
6245
|
+
]);
|
|
6246
|
+
function chargedNothing(error, proofSent) {
|
|
6247
|
+
if (!proofSent || UNCHARGED_CODES.has(error.code)) return true;
|
|
6248
|
+
const backend = error.code === "BACKEND_ERROR" || error.code === "BACKEND_TIMEOUT";
|
|
6249
|
+
return backend && error.details?.["payment"] === void 0;
|
|
6250
|
+
}
|
|
6251
|
+
function workingTask(taskId, contextId, timestamp) {
|
|
6252
|
+
return {
|
|
6253
|
+
id: taskId,
|
|
6254
|
+
contextId,
|
|
6255
|
+
status: { state: A2A_TASK_STATE_WORKING, timestamp },
|
|
6256
|
+
artifacts: []
|
|
6257
|
+
};
|
|
6258
|
+
}
|
|
6259
|
+
function canceledTask(taskId, contextId, timestamp, messageId) {
|
|
6260
|
+
return withStatusMessage(
|
|
6261
|
+
{ id: taskId, contextId, status: { state: A2A_TASK_STATE_CANCELED, timestamp }, artifacts: [] },
|
|
6262
|
+
"Task canceled.",
|
|
6263
|
+
messageId
|
|
6264
|
+
);
|
|
6265
|
+
}
|
|
6266
|
+
function interruptedTask(task2) {
|
|
6267
|
+
const error = new CommerceError(
|
|
6268
|
+
"INTERNAL_ERROR",
|
|
6269
|
+
"This task stopped before its result was recorded. Any payment is in the gateway records: check with the merchant before paying again."
|
|
6270
|
+
);
|
|
6271
|
+
return failedTask(error, {
|
|
6272
|
+
taskId: task2.id,
|
|
6273
|
+
contextId: task2.contextId,
|
|
6274
|
+
artifactId: `${task2.id}-interrupted`,
|
|
6275
|
+
statusMessageId: `${task2.id}-interrupted`,
|
|
6276
|
+
timestamp: task2.status.timestamp
|
|
6277
|
+
});
|
|
6278
|
+
}
|
|
5611
6279
|
|
|
5612
6280
|
// src/protocols/a2a/payment-resume.ts
|
|
5613
6281
|
function taskResult(id, task2) {
|
|
5614
6282
|
return jsonRpcResult(id, { task: task2 });
|
|
5615
6283
|
}
|
|
5616
|
-
|
|
6284
|
+
var BACKGROUND_FULL = "Too many tasks are running in the background; retry shortly.";
|
|
6285
|
+
var BACKGROUND_RETRY_SECONDS = 1;
|
|
6286
|
+
async function resumePayment(resume, id, params, returnImmediately) {
|
|
6287
|
+
const { context, pendingPayments } = resume;
|
|
5617
6288
|
const message = isRecord(params) ? params["message"] : void 0;
|
|
5618
6289
|
const taskId = isRecord(message) ? message["taskId"] : void 0;
|
|
5619
|
-
if (
|
|
5620
|
-
const pending = await pendingPayments
|
|
6290
|
+
if (typeof taskId !== "string") return void 0;
|
|
6291
|
+
const pending = await pendingPayments.get(taskId);
|
|
5621
6292
|
if (pending === void 0) return void 0;
|
|
5622
|
-
const messageId = isRecord(message) ? message["messageId"] : void 0;
|
|
5623
|
-
if (typeof messageId !== "string" || messageId.length === 0) {
|
|
5624
|
-
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, 'Message must carry a non-empty "messageId".');
|
|
5625
|
-
}
|
|
5626
|
-
const roleProblem = userRoleProblem(isRecord(message) ? message["role"] : void 0);
|
|
5627
|
-
if (roleProblem !== void 0) return jsonRpcError(id, JSONRPC_INVALID_PARAMS, roleProblem);
|
|
5628
6293
|
const contextId = isRecord(message) ? message["contextId"] : void 0;
|
|
5629
6294
|
if (contextId !== void 0 && contextId !== pending.contextId) {
|
|
5630
6295
|
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, 'Message "contextId" does not match the task.');
|
|
@@ -5645,43 +6310,78 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
5645
6310
|
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, toCommerceError(err).message);
|
|
5646
6311
|
}
|
|
5647
6312
|
}
|
|
5648
|
-
const
|
|
6313
|
+
const immediate = returnImmediately && submission.kind === "submitted";
|
|
6314
|
+
if (immediate && !resume.background.reserve()) {
|
|
6315
|
+
return jsonRpcError(id, JSONRPC_INTERNAL_ERROR, BACKGROUND_FULL, [
|
|
6316
|
+
retryInfo(BACKGROUND_RETRY_SECONDS)
|
|
6317
|
+
]);
|
|
6318
|
+
}
|
|
6319
|
+
let taken;
|
|
6320
|
+
try {
|
|
6321
|
+
taken = await pendingPayments.take(taskId);
|
|
6322
|
+
} finally {
|
|
6323
|
+
if (immediate && taken === void 0) resume.background.release();
|
|
6324
|
+
}
|
|
5649
6325
|
if (taken === void 0) return void 0;
|
|
5650
6326
|
const authorization = taken.authorization ?? followUp;
|
|
5651
|
-
|
|
5652
|
-
|
|
6327
|
+
if (submission.kind === "rejected") {
|
|
6328
|
+
const timestamp = context.clock.nowIso();
|
|
6329
|
+
const declined = withStatusMessage(
|
|
6330
|
+
{
|
|
6331
|
+
id: taskId,
|
|
6332
|
+
contextId: taken.contextId,
|
|
6333
|
+
status: { state: A2A_TASK_STATE_FAILED, timestamp },
|
|
6334
|
+
artifacts: []
|
|
6335
|
+
},
|
|
6336
|
+
"Payment was declined.",
|
|
6337
|
+
context.ids.next("a2a-msg"),
|
|
6338
|
+
paymentRejectedMetadata()
|
|
6339
|
+
);
|
|
6340
|
+
await resume.keep(declined, true);
|
|
6341
|
+
return taskResult(id, declined);
|
|
6342
|
+
}
|
|
6343
|
+
const ids = {
|
|
5653
6344
|
taskId,
|
|
5654
6345
|
contextId: taken.contextId,
|
|
5655
6346
|
artifactId: context.ids.next("a2a-artifact"),
|
|
5656
|
-
statusMessageId
|
|
5657
|
-
timestamp: context.clock.nowIso()
|
|
6347
|
+
statusMessageId: context.ids.next("a2a-msg")
|
|
5658
6348
|
};
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
artifacts: []
|
|
5665
|
-
};
|
|
5666
|
-
return taskResult(
|
|
5667
|
-
id,
|
|
5668
|
-
withStatusMessage(
|
|
5669
|
-
declined,
|
|
5670
|
-
"Payment was declined.",
|
|
5671
|
-
statusMessageId,
|
|
5672
|
-
paymentRejectedMetadata()
|
|
5673
|
-
)
|
|
5674
|
-
);
|
|
5675
|
-
}
|
|
5676
|
-
return taskResult(
|
|
5677
|
-
id,
|
|
5678
|
-
await payPending(
|
|
5679
|
-
context,
|
|
5680
|
-
{ ...taken, ...authorization !== void 0 ? { authorization } : {} },
|
|
5681
|
-
submission.payload,
|
|
5682
|
-
identity
|
|
5683
|
-
)
|
|
6349
|
+
const working = withStatusMessage(
|
|
6350
|
+
workingTask(taskId, taken.contextId, context.clock.nowIso()),
|
|
6351
|
+
"Payment received; processing it.",
|
|
6352
|
+
context.ids.next("a2a-msg"),
|
|
6353
|
+
{ [X402_PAYMENT_STATUS_KEY]: "payment-submitted" }
|
|
5684
6354
|
);
|
|
6355
|
+
resume.running.add(taskId);
|
|
6356
|
+
if (!immediate) {
|
|
6357
|
+
await resume.keep(working, false);
|
|
6358
|
+
} else {
|
|
6359
|
+
const refused = await resume.recordWorking(working);
|
|
6360
|
+
if (refused !== void 0) {
|
|
6361
|
+
resume.running.delete(taskId);
|
|
6362
|
+
resume.background.release();
|
|
6363
|
+
const failed = failedTask(refused, { ...ids, timestamp: context.clock.nowIso() });
|
|
6364
|
+
await resume.keep(failed, true);
|
|
6365
|
+
return taskResult(id, failed);
|
|
6366
|
+
}
|
|
6367
|
+
}
|
|
6368
|
+
const pay = async () => {
|
|
6369
|
+
try {
|
|
6370
|
+
const { task: paid, evictable } = await payPending(
|
|
6371
|
+
context,
|
|
6372
|
+
{ ...taken, ...authorization !== void 0 ? { authorization } : {} },
|
|
6373
|
+
submission.payload,
|
|
6374
|
+
ids
|
|
6375
|
+
);
|
|
6376
|
+
await resume.keep(paid, evictable);
|
|
6377
|
+
return paid;
|
|
6378
|
+
} finally {
|
|
6379
|
+
resume.running.delete(taskId);
|
|
6380
|
+
}
|
|
6381
|
+
};
|
|
6382
|
+
if (!immediate) return taskResult(id, await pay());
|
|
6383
|
+
resume.background.start(pay);
|
|
6384
|
+
return taskResult(id, working);
|
|
5685
6385
|
}
|
|
5686
6386
|
function withoutRetryDelay(error) {
|
|
5687
6387
|
if (error.details?.["reason"] !== "payment_identifier_in_flight") return error;
|
|
@@ -5694,7 +6394,7 @@ function withoutRetryDelay(error) {
|
|
|
5694
6394
|
...error.resourceId !== void 0 ? { resourceId: error.resourceId } : {}
|
|
5695
6395
|
});
|
|
5696
6396
|
}
|
|
5697
|
-
async function payPending(context, pending, payload,
|
|
6397
|
+
async function payPending(context, pending, payload, ids) {
|
|
5698
6398
|
const requestId = context.ids.next("a2a");
|
|
5699
6399
|
const request = {
|
|
5700
6400
|
requestId,
|
|
@@ -5713,12 +6413,14 @@ async function payPending(context, pending, payload, identity) {
|
|
|
5713
6413
|
try {
|
|
5714
6414
|
const outcome = await context.pipeline.execute(request);
|
|
5715
6415
|
if (outcome.kind === "delivered" && outcome.payment !== void 0) {
|
|
5716
|
-
|
|
5717
|
-
|
|
6416
|
+
const identity2 = { ...ids, timestamp: context.clock.nowIso() };
|
|
6417
|
+
const task2 = withStatusMessage(
|
|
6418
|
+
completedTask(outcome, identity2),
|
|
5718
6419
|
"Payment settled.",
|
|
5719
|
-
|
|
6420
|
+
identity2.statusMessageId,
|
|
5720
6421
|
paymentCompletedMetadata(outcome.payment)
|
|
5721
6422
|
);
|
|
6423
|
+
return { task: task2, evictable: false };
|
|
5722
6424
|
}
|
|
5723
6425
|
error = new CommerceError("PAYMENT_INVALID", "The payment was not accepted.", { requestId });
|
|
5724
6426
|
} catch (err) {
|
|
@@ -5728,24 +6430,183 @@ async function payPending(context, pending, payload, identity) {
|
|
|
5728
6430
|
"a2a adapter: x402 extension payment failed"
|
|
5729
6431
|
);
|
|
5730
6432
|
}
|
|
6433
|
+
const identity = { ...ids, timestamp: context.clock.nowIso() };
|
|
5731
6434
|
const metadata = paymentFailureMetadata(error, pending.network);
|
|
5732
6435
|
const reason = error.details?.["reason"];
|
|
5733
|
-
let text
|
|
6436
|
+
let text;
|
|
5734
6437
|
if (metadata[X402_PAYMENT_STATUS_KEY] === "payment-completed") {
|
|
5735
6438
|
text = "Payment settled, but the resource could not be delivered.";
|
|
5736
6439
|
} else if (typeof reason === "string" && reason.startsWith("payment_identifier_")) {
|
|
5737
6440
|
text = error.message;
|
|
5738
|
-
} else
|
|
5739
|
-
|
|
6441
|
+
} else {
|
|
6442
|
+
const outcome = error.code.startsWith("PAYMENT_") ? "Payment failed" : "The resource could not be delivered";
|
|
6443
|
+
text = `${outcome}: ${String(metadata[X402_PAYMENT_ERROR_KEY])}.`;
|
|
6444
|
+
}
|
|
6445
|
+
return {
|
|
6446
|
+
task: withStatusMessage(failedTask(error, identity), text, identity.statusMessageId, metadata),
|
|
6447
|
+
evictable: chargedNothing(error, true)
|
|
6448
|
+
};
|
|
6449
|
+
}
|
|
6450
|
+
|
|
6451
|
+
// src/protocols/a2a/task-operations.ts
|
|
6452
|
+
var NOT_FOUND = "Task not found.";
|
|
6453
|
+
function reported(task2, running) {
|
|
6454
|
+
return task2.status.state === A2A_TASK_STATE_WORKING && !running.has(task2.id) ? interruptedTask(task2) : task2;
|
|
6455
|
+
}
|
|
6456
|
+
async function getTask(ops, id, params) {
|
|
6457
|
+
const task2 = await ops.tasks.get(params.id);
|
|
6458
|
+
if (task2 === void 0) return jsonRpcError(id, A2A_ERROR_TASK_NOT_FOUND, NOT_FOUND);
|
|
6459
|
+
return jsonRpcResult(id, reported(task2, ops.running));
|
|
6460
|
+
}
|
|
6461
|
+
function before(a, b) {
|
|
6462
|
+
return a.at > b.at || a.at === b.at && a.id > b.id;
|
|
6463
|
+
}
|
|
6464
|
+
async function listTasks(ops, id, params) {
|
|
6465
|
+
const recorded = params.contextId === void 0 ? [] : await ops.tasks.list(params.contextId);
|
|
6466
|
+
const after = params.statusTimestampAfter !== void 0 ? Date.parse(params.statusTimestampAfter) : void 0;
|
|
6467
|
+
const matching = recorded.map((task2) => reported(task2, ops.running)).filter((task2) => params.status === void 0 || task2.status.state === params.status).filter((task2) => after === void 0 || Date.parse(task2.status.timestamp) >= after).map((task2) => ({ task: task2, key: { at: Date.parse(task2.status.timestamp), id: task2.id } })).sort((a, b) => before(a.key, b.key) ? -1 : before(b.key, a.key) ? 1 : 0);
|
|
6468
|
+
let start = 0;
|
|
6469
|
+
if (params.after !== void 0) {
|
|
6470
|
+
const key = { at: Date.parse(params.after.updatedAt), id: params.after.id };
|
|
6471
|
+
start = matching.findIndex((entry) => before(key, entry.key));
|
|
6472
|
+
if (start === -1) start = matching.length;
|
|
6473
|
+
}
|
|
6474
|
+
const page = matching.slice(start, start + params.pageSize);
|
|
6475
|
+
const last = page.at(-1);
|
|
6476
|
+
const more = start + page.length < matching.length;
|
|
6477
|
+
return jsonRpcResult(id, {
|
|
6478
|
+
tasks: page.map(({ task: task2 }) => {
|
|
6479
|
+
if (params.includeArtifacts) return task2;
|
|
6480
|
+
const { artifacts: _artifacts, ...rest } = task2;
|
|
6481
|
+
return rest;
|
|
6482
|
+
}),
|
|
6483
|
+
nextPageToken: more && last !== void 0 ? encodePageToken({ updatedAt: last.task.status.timestamp, id: last.task.id }) : "",
|
|
6484
|
+
pageSize: params.pageSize,
|
|
6485
|
+
totalSize: matching.length
|
|
6486
|
+
});
|
|
6487
|
+
}
|
|
6488
|
+
async function cancelTask(ops, id, params) {
|
|
6489
|
+
const taken = await ops.pendingPayments.take(params.id);
|
|
6490
|
+
if (taken !== void 0) {
|
|
6491
|
+
const canceled = canceledTask(
|
|
6492
|
+
params.id,
|
|
6493
|
+
taken.contextId,
|
|
6494
|
+
ops.clock.nowIso(),
|
|
6495
|
+
ops.nextMessageId()
|
|
6496
|
+
);
|
|
6497
|
+
if (!await ops.tasks.put(canceled, ops.retainedUntil(), true)) {
|
|
6498
|
+
throw new CommerceError("STORAGE_ERROR", "The canceled task did not fit in the task store.");
|
|
6499
|
+
}
|
|
6500
|
+
return jsonRpcResult(id, canceled);
|
|
5740
6501
|
}
|
|
5741
|
-
|
|
6502
|
+
const task2 = await ops.tasks.get(params.id);
|
|
6503
|
+
if (task2 === void 0) return jsonRpcError(id, A2A_ERROR_TASK_NOT_FOUND, NOT_FOUND);
|
|
6504
|
+
if (task2.status.state === A2A_TASK_STATE_CANCELED) return jsonRpcResult(id, task2);
|
|
6505
|
+
return jsonRpcError(
|
|
6506
|
+
id,
|
|
6507
|
+
A2A_ERROR_TASK_NOT_CANCELABLE,
|
|
6508
|
+
"Only a task waiting for payment can be canceled; this one is running or finished."
|
|
6509
|
+
);
|
|
6510
|
+
}
|
|
6511
|
+
|
|
6512
|
+
// src/protocols/a2a/task-store.ts
|
|
6513
|
+
function createStoredTasks(store, maxRecords) {
|
|
6514
|
+
return {
|
|
6515
|
+
put: (task2, expiresAt, evictable) => store.putTaskRecord(
|
|
6516
|
+
{
|
|
6517
|
+
id: task2.id,
|
|
6518
|
+
protocol: "a2a",
|
|
6519
|
+
groupId: task2.contextId,
|
|
6520
|
+
state: task2.status.state,
|
|
6521
|
+
updatedAt: task2.status.timestamp,
|
|
6522
|
+
document: task2,
|
|
6523
|
+
expiresAt,
|
|
6524
|
+
...evictable === true ? { evictable } : {}
|
|
6525
|
+
},
|
|
6526
|
+
{ maxRecords }
|
|
6527
|
+
),
|
|
6528
|
+
async get(id) {
|
|
6529
|
+
const record = await store.getTaskRecord(id);
|
|
6530
|
+
return record?.protocol === "a2a" ? record.document : void 0;
|
|
6531
|
+
},
|
|
6532
|
+
async list(contextId) {
|
|
6533
|
+
const records = await store.listTaskRecords({ protocol: "a2a", groupId: contextId });
|
|
6534
|
+
return records.map((record) => record.document);
|
|
6535
|
+
}
|
|
6536
|
+
};
|
|
6537
|
+
}
|
|
6538
|
+
function createMemoryTasks(clock, maxRecords) {
|
|
6539
|
+
const tasks = /* @__PURE__ */ new Map();
|
|
6540
|
+
const live = (expiresAtMs) => expiresAtMs > clock.now().getTime();
|
|
6541
|
+
return {
|
|
6542
|
+
async put(task2, expiresAt, evictable = false) {
|
|
6543
|
+
if (!tasks.has(task2.id) && tasks.size >= maxRecords) {
|
|
6544
|
+
for (const [id, held] of tasks) if (!live(held.expiresAtMs)) tasks.delete(id);
|
|
6545
|
+
if (tasks.size >= maxRecords) {
|
|
6546
|
+
let oldest;
|
|
6547
|
+
for (const [id, held] of tasks) {
|
|
6548
|
+
if (held.evictable) {
|
|
6549
|
+
oldest = id;
|
|
6550
|
+
break;
|
|
6551
|
+
}
|
|
6552
|
+
}
|
|
6553
|
+
if (oldest === void 0) return false;
|
|
6554
|
+
tasks.delete(oldest);
|
|
6555
|
+
}
|
|
6556
|
+
}
|
|
6557
|
+
tasks.delete(task2.id);
|
|
6558
|
+
tasks.set(task2.id, { task: task2, expiresAtMs: Date.parse(expiresAt), evictable });
|
|
6559
|
+
return true;
|
|
6560
|
+
},
|
|
6561
|
+
async get(id) {
|
|
6562
|
+
const held = tasks.get(id);
|
|
6563
|
+
return held !== void 0 && live(held.expiresAtMs) ? held.task : void 0;
|
|
6564
|
+
},
|
|
6565
|
+
// ponytail: listing scans all tasks; add a context index if large stores become slow
|
|
6566
|
+
async list(contextId) {
|
|
6567
|
+
return [...tasks.values()].filter((held) => held.task.contextId === contextId && live(held.expiresAtMs)).map((held) => held.task);
|
|
6568
|
+
}
|
|
6569
|
+
};
|
|
5742
6570
|
}
|
|
5743
6571
|
|
|
5744
6572
|
// src/protocols/a2a/adapter.ts
|
|
5745
6573
|
var MAX_REQUEST_BODY_BYTES = 256 * 1024;
|
|
5746
6574
|
var VERSION_PATTERN = /^(\d+\.\d+)(?:\.\d+)?$/;
|
|
5747
6575
|
var A2A_VERSION_PARAMETER = "A2A-Version";
|
|
6576
|
+
var X402_EXTENSION_ECHO = {
|
|
6577
|
+
[A2A_EXTENSIONS_HEADER]: A2A_X402_EXTENSION_URI,
|
|
6578
|
+
[A2A_X_EXTENSIONS_HEADER]: A2A_X402_EXTENSION_URI
|
|
6579
|
+
};
|
|
5748
6580
|
var AGENT_CARD_CACHE_CONTROL = "public, max-age=300";
|
|
6581
|
+
function taskLimit(value, name, bounds) {
|
|
6582
|
+
if (value === void 0) return bounds.default;
|
|
6583
|
+
if (!Number.isInteger(value) || value < bounds.min || value > bounds.max) {
|
|
6584
|
+
throw new CommerceError(
|
|
6585
|
+
"CONFIG_INVALID",
|
|
6586
|
+
`A2A adapter option "tasks.${name}" must be an integer from ${bounds.min} to ${bounds.max}`,
|
|
6587
|
+
{ details: { path: `tasks.${name}` } }
|
|
6588
|
+
);
|
|
6589
|
+
}
|
|
6590
|
+
return value;
|
|
6591
|
+
}
|
|
6592
|
+
function storeFull() {
|
|
6593
|
+
return new CommerceError("GATEWAY_BUSY", "Too many answered tasks are retained; retry shortly.");
|
|
6594
|
+
}
|
|
6595
|
+
async function withParams(id, read2, run) {
|
|
6596
|
+
let params;
|
|
6597
|
+
try {
|
|
6598
|
+
params = read2();
|
|
6599
|
+
} catch (err) {
|
|
6600
|
+
return refusal(id, err);
|
|
6601
|
+
}
|
|
6602
|
+
return run(params);
|
|
6603
|
+
}
|
|
6604
|
+
function refusal(id, err) {
|
|
6605
|
+
const error = toCommerceError(err);
|
|
6606
|
+
const a2aErrorCode = error.details?.["a2aErrorCode"];
|
|
6607
|
+
const code = typeof a2aErrorCode === "number" ? a2aErrorCode : error.code === "PROTOCOL_UNSUPPORTED" ? A2A_ERROR_UNSUPPORTED_OPERATION : JSONRPC_INVALID_PARAMS;
|
|
6608
|
+
return jsonRpcError(id, code, error.message);
|
|
6609
|
+
}
|
|
5749
6610
|
var DEFAULT_AGENT_DESCRIPTION = "Agent Commerce Gateway: canonical commerce resources exposed as A2A skills.";
|
|
5750
6611
|
var A2aProtocolAdapter = class {
|
|
5751
6612
|
name = "a2a";
|
|
@@ -5756,6 +6617,8 @@ var A2aProtocolAdapter = class {
|
|
|
5756
6617
|
agentDescription;
|
|
5757
6618
|
agentVersion;
|
|
5758
6619
|
store;
|
|
6620
|
+
retentionMs;
|
|
6621
|
+
maxRetained;
|
|
5759
6622
|
context;
|
|
5760
6623
|
started = false;
|
|
5761
6624
|
// The card lists only a2a-exposed resources, but a caller can name any id,
|
|
@@ -5768,12 +6631,19 @@ var A2aProtocolAdapter = class {
|
|
|
5768
6631
|
cardEtag = "";
|
|
5769
6632
|
// Purchases waiting for an x402 extension payment
|
|
5770
6633
|
pendingPayments;
|
|
6634
|
+
// Retained responses for task lookup, listing and cancellation
|
|
6635
|
+
tasks;
|
|
6636
|
+
// Active task ids; see TaskOperations.running
|
|
6637
|
+
running = /* @__PURE__ */ new Set();
|
|
6638
|
+
background;
|
|
5771
6639
|
constructor(options = {}) {
|
|
5772
6640
|
this.mountPath = options.mountPath ?? A2A_DEFAULT_MOUNT_PATH;
|
|
5773
6641
|
this.agentName = options.agentName ?? A2A_DEFAULT_AGENT_NAME;
|
|
5774
6642
|
this.agentDescription = options.agentDescription ?? DEFAULT_AGENT_DESCRIPTION;
|
|
5775
6643
|
this.agentVersion = options.agentVersion ?? PACKAGE_VERSION;
|
|
5776
6644
|
this.store = options.store;
|
|
6645
|
+
this.retentionMs = taskLimit(options.tasks?.retentionHours, "retentionHours", A2A_TASK_RETENTION_HOURS) * 36e5;
|
|
6646
|
+
this.maxRetained = taskLimit(options.tasks?.maxRetained, "maxRetained", A2A_MAX_RETAINED_TASKS);
|
|
5777
6647
|
this.descriptor = buildDescriptor(PACKAGE_VERSION);
|
|
5778
6648
|
this.additionalHttpRoutes = [
|
|
5779
6649
|
{
|
|
@@ -5806,6 +6676,8 @@ var A2aProtocolAdapter = class {
|
|
|
5806
6676
|
resources
|
|
5807
6677
|
});
|
|
5808
6678
|
this.pendingPayments = hasMethodGroup(this.store, "pending_tasks") ? createStoredPendingPayments(this.store, context.clock) : createPendingPayments(context.clock);
|
|
6679
|
+
this.tasks = hasMethodGroup(this.store, "task_records") ? createStoredTasks(this.store, this.maxRetained) : createMemoryTasks(context.clock, this.maxRetained);
|
|
6680
|
+
this.background = createBackgroundRuns(A2A_MAX_BACKGROUND_RUNS, context.logger);
|
|
5809
6681
|
this.cardBody = JSON.stringify(this.card);
|
|
5810
6682
|
this.cardEtag = `"${createHash("sha256").update(this.cardBody).digest("base64url")}"`;
|
|
5811
6683
|
this.started = true;
|
|
@@ -5840,6 +6712,7 @@ var A2aProtocolAdapter = class {
|
|
|
5840
6712
|
}
|
|
5841
6713
|
/** `POST <mountPath>`: the A2A JSON-RPC endpoint */
|
|
5842
6714
|
async handleHttp(req, res) {
|
|
6715
|
+
let requestId = null;
|
|
5843
6716
|
try {
|
|
5844
6717
|
if (!this.started) {
|
|
5845
6718
|
this.writeJson(
|
|
@@ -5861,8 +6734,8 @@ var A2aProtocolAdapter = class {
|
|
|
5861
6734
|
);
|
|
5862
6735
|
return;
|
|
5863
6736
|
}
|
|
5864
|
-
const
|
|
5865
|
-
if (
|
|
6737
|
+
const read2 = await readCappedBody(req, MAX_REQUEST_BODY_BYTES);
|
|
6738
|
+
if (read2.kind === "too-large") {
|
|
5866
6739
|
this.writeJson(
|
|
5867
6740
|
res,
|
|
5868
6741
|
413,
|
|
@@ -5874,7 +6747,7 @@ var A2aProtocolAdapter = class {
|
|
|
5874
6747
|
);
|
|
5875
6748
|
return;
|
|
5876
6749
|
}
|
|
5877
|
-
if (
|
|
6750
|
+
if (read2.kind !== "ok") {
|
|
5878
6751
|
this.writeJson(
|
|
5879
6752
|
res,
|
|
5880
6753
|
200,
|
|
@@ -5882,11 +6755,12 @@ var A2aProtocolAdapter = class {
|
|
|
5882
6755
|
);
|
|
5883
6756
|
return;
|
|
5884
6757
|
}
|
|
5885
|
-
const parsed = parseJsonRpcRequest(
|
|
6758
|
+
const parsed = parseJsonRpcRequest(read2.text);
|
|
5886
6759
|
if (!parsed.ok) {
|
|
5887
6760
|
this.writeJson(res, 200, jsonRpcError(parsed.id, parsed.error.code, parsed.error.message));
|
|
5888
6761
|
return;
|
|
5889
6762
|
}
|
|
6763
|
+
requestId = parsed.request.id;
|
|
5890
6764
|
const version = req.headers[A2A_VERSION_HEADER];
|
|
5891
6765
|
const declared = (Array.isArray(version) ? version[0] : version) ?? new URL(req.url ?? "/", "http://localhost").searchParams.get(A2A_VERSION_PARAMETER);
|
|
5892
6766
|
if (declared?.match(VERSION_PATTERN)?.[1] !== A2A_PROTOCOL_VERSION) {
|
|
@@ -5901,24 +6775,21 @@ var A2aProtocolAdapter = class {
|
|
|
5901
6775
|
);
|
|
5902
6776
|
return;
|
|
5903
6777
|
}
|
|
6778
|
+
const activated = requestsX402Extension(req.headers[A2A_EXTENSIONS_HEADER]) || requestsX402Extension(req.headers[A2A_X_EXTENSIONS_HEADER]);
|
|
5904
6779
|
const response = await this.dispatch(
|
|
5905
6780
|
parsed.request.id,
|
|
5906
6781
|
parsed.request.method,
|
|
5907
6782
|
parsed.request.params,
|
|
5908
|
-
|
|
5909
|
-
);
|
|
5910
|
-
this.writeJson(
|
|
5911
|
-
res,
|
|
5912
|
-
200,
|
|
5913
|
-
response,
|
|
5914
|
-
usesX402Extension(response) ? { [A2A_EXTENSIONS_HEADER]: A2A_X402_EXTENSION_URI } : {}
|
|
6783
|
+
activated
|
|
5915
6784
|
);
|
|
6785
|
+
const echo = usesX402Extension(response) || activated && response["error"] === void 0;
|
|
6786
|
+
this.writeJson(res, 200, response, echo ? X402_EXTENSION_ECHO : {});
|
|
5916
6787
|
} catch (err) {
|
|
5917
6788
|
this.context?.logger.error({ err: toLogInfo(err) }, "a2a adapter: request handling failed");
|
|
5918
6789
|
this.writeJson(
|
|
5919
6790
|
res,
|
|
5920
6791
|
200,
|
|
5921
|
-
jsonRpcError(
|
|
6792
|
+
jsonRpcError(requestId, JSONRPC_INTERNAL_ERROR, "Internal server error.")
|
|
5922
6793
|
);
|
|
5923
6794
|
}
|
|
5924
6795
|
}
|
|
@@ -5930,13 +6801,6 @@ var A2aProtocolAdapter = class {
|
|
|
5930
6801
|
`A2A method "${method}" is not supported: this agent does not support push notifications.`
|
|
5931
6802
|
);
|
|
5932
6803
|
}
|
|
5933
|
-
if (A2A_TASK_LOOKUP_METHODS.includes(method)) {
|
|
5934
|
-
return jsonRpcError(
|
|
5935
|
-
id,
|
|
5936
|
-
A2A_ERROR_TASK_NOT_FOUND,
|
|
5937
|
-
"Task not found. Finished tasks are not retained; continue a pending payment with SendMessage."
|
|
5938
|
-
);
|
|
5939
|
-
}
|
|
5940
6804
|
if (A2A_UNSUPPORTED_METHODS.includes(method)) {
|
|
5941
6805
|
return jsonRpcError(
|
|
5942
6806
|
id,
|
|
@@ -5944,49 +6808,198 @@ var A2aProtocolAdapter = class {
|
|
|
5944
6808
|
`A2A method "${method}" is not supported by this deployment.`
|
|
5945
6809
|
);
|
|
5946
6810
|
}
|
|
5947
|
-
|
|
5948
|
-
|
|
6811
|
+
const raw = isRecord(params) ? params : {};
|
|
6812
|
+
const ops = this.operations();
|
|
6813
|
+
switch (method) {
|
|
6814
|
+
case A2A_METHOD_SEND_MESSAGE:
|
|
6815
|
+
break;
|
|
6816
|
+
case A2A_METHOD_GET_TASK:
|
|
6817
|
+
return withParams(
|
|
6818
|
+
id,
|
|
6819
|
+
() => readGetTaskParams(raw),
|
|
6820
|
+
(read2) => getTask(ops, id, read2)
|
|
6821
|
+
);
|
|
6822
|
+
case A2A_METHOD_LIST_TASKS:
|
|
6823
|
+
return withParams(
|
|
6824
|
+
id,
|
|
6825
|
+
() => readListTasksParams(raw),
|
|
6826
|
+
(read2) => listTasks(ops, id, read2)
|
|
6827
|
+
);
|
|
6828
|
+
case A2A_METHOD_CANCEL_TASK:
|
|
6829
|
+
return withParams(
|
|
6830
|
+
id,
|
|
6831
|
+
() => readCancelTaskParams(raw),
|
|
6832
|
+
(read2) => cancelTask(ops, id, read2)
|
|
6833
|
+
);
|
|
6834
|
+
default:
|
|
6835
|
+
return jsonRpcError(id, JSONRPC_METHOD_NOT_FOUND, `Unknown method "${method}".`);
|
|
6836
|
+
}
|
|
6837
|
+
let request;
|
|
6838
|
+
try {
|
|
6839
|
+
request = readSendMessageParams(raw);
|
|
6840
|
+
readMessage(request.params);
|
|
6841
|
+
} catch (err) {
|
|
6842
|
+
return refusal(id, err);
|
|
5949
6843
|
}
|
|
5950
|
-
const resumed = await resumePayment(
|
|
6844
|
+
const resumed = await resumePayment(
|
|
6845
|
+
this.resume(ops),
|
|
6846
|
+
id,
|
|
6847
|
+
request.params,
|
|
6848
|
+
request.returnImmediately
|
|
6849
|
+
);
|
|
5951
6850
|
if (resumed !== void 0) return resumed;
|
|
6851
|
+
const known = await this.answerKnownTask(ops, id, request.params);
|
|
6852
|
+
if (known !== void 0) return known;
|
|
5952
6853
|
let invocation;
|
|
5953
6854
|
try {
|
|
5954
|
-
invocation = parseInvocation(params);
|
|
6855
|
+
invocation = parseInvocation(request.params);
|
|
5955
6856
|
} catch (err) {
|
|
5956
|
-
|
|
5957
|
-
const a2aErrorCode = error.details?.["a2aErrorCode"];
|
|
5958
|
-
const code = typeof a2aErrorCode === "number" ? a2aErrorCode : error.code === "PROTOCOL_UNSUPPORTED" ? A2A_ERROR_UNSUPPORTED_OPERATION : JSONRPC_INVALID_PARAMS;
|
|
5959
|
-
return jsonRpcError(id, code, error.message);
|
|
6857
|
+
return refusal(id, err);
|
|
5960
6858
|
}
|
|
5961
|
-
return this.execute(id, invocation, x402Extension);
|
|
6859
|
+
return this.execute(ops, id, invocation, x402Extension, request.returnImmediately);
|
|
5962
6860
|
}
|
|
5963
|
-
//
|
|
5964
|
-
|
|
5965
|
-
const context = this
|
|
5966
|
-
if (context === void 0) {
|
|
6861
|
+
// Collect task-operation state after startup; handleHttp returns 503 before startup
|
|
6862
|
+
operations() {
|
|
6863
|
+
const { context, tasks, pendingPayments } = this;
|
|
6864
|
+
if (context === void 0 || tasks === void 0 || pendingPayments === void 0) {
|
|
6865
|
+
throw new CommerceError("INTERNAL_ERROR", "A2A adapter is not running.");
|
|
6866
|
+
}
|
|
6867
|
+
return {
|
|
6868
|
+
tasks,
|
|
6869
|
+
pendingPayments,
|
|
6870
|
+
running: this.running,
|
|
6871
|
+
clock: context.clock,
|
|
6872
|
+
retainedUntil: () => this.retainedUntil(context),
|
|
6873
|
+
nextMessageId: () => context.ids.next("a2a-msg")
|
|
6874
|
+
};
|
|
6875
|
+
}
|
|
6876
|
+
resume(ops) {
|
|
6877
|
+
const { context, background } = this;
|
|
6878
|
+
if (context === void 0 || background === void 0) {
|
|
6879
|
+
throw new CommerceError("INTERNAL_ERROR", "A2A adapter is not running.");
|
|
6880
|
+
}
|
|
6881
|
+
return {
|
|
6882
|
+
context,
|
|
6883
|
+
pendingPayments: ops.pendingPayments,
|
|
6884
|
+
keep: (task2, evictable) => this.keep(ops, task2, evictable),
|
|
6885
|
+
running: this.running,
|
|
6886
|
+
background,
|
|
6887
|
+
recordWorking: (task2) => this.recordWorking(ops, task2)
|
|
6888
|
+
};
|
|
6889
|
+
}
|
|
6890
|
+
retainedUntil(context) {
|
|
6891
|
+
return new Date(context.clock.now().getTime() + this.retentionMs).toISOString();
|
|
6892
|
+
}
|
|
6893
|
+
// Retain a response without failing the call. Log capacity refusals at warn
|
|
6894
|
+
// and write exceptions at error; return false in either case.
|
|
6895
|
+
async keep(ops, task2, evictable) {
|
|
6896
|
+
const logger = this.context?.logger;
|
|
6897
|
+
try {
|
|
6898
|
+
if (await ops.tasks.put(task2, ops.retainedUntil(), evictable)) return true;
|
|
6899
|
+
logger?.warn(
|
|
6900
|
+
{ state: task2.status.state },
|
|
6901
|
+
"a2a adapter: task not retained: the task store is full"
|
|
6902
|
+
);
|
|
6903
|
+
} catch (err) {
|
|
6904
|
+
logger?.error(
|
|
6905
|
+
{ state: task2.status.state, err: toLogInfo(err) },
|
|
6906
|
+
"a2a adapter: task not retained"
|
|
6907
|
+
);
|
|
6908
|
+
}
|
|
6909
|
+
return false;
|
|
6910
|
+
}
|
|
6911
|
+
// Store the working response before starting background work; return any
|
|
6912
|
+
// failure so the caller can stop admission
|
|
6913
|
+
async recordWorking(ops, task2) {
|
|
6914
|
+
try {
|
|
6915
|
+
return await ops.tasks.put(task2, ops.retainedUntil()) ? void 0 : storeFull();
|
|
6916
|
+
} catch (err) {
|
|
6917
|
+
this.context?.logger.error({ err: toLogInfo(err) }, "a2a adapter: working task not recorded");
|
|
6918
|
+
return toCommerceError(err);
|
|
6919
|
+
}
|
|
6920
|
+
}
|
|
6921
|
+
/**
|
|
6922
|
+
* Reject further messages on a retained task after the pending-payment path
|
|
6923
|
+
* declines it, including tasks taken by another call. Terminal tasks accept
|
|
6924
|
+
* no further messages (A2A 1.0.1 section 3.1.1). Missing records fall through
|
|
6925
|
+
* to `parseInvocation`, which returns `TaskNotFoundError`.
|
|
6926
|
+
*/
|
|
6927
|
+
async answerKnownTask(ops, id, params) {
|
|
6928
|
+
const message = params["message"];
|
|
6929
|
+
const taskId = isRecord(message) ? message["taskId"] : void 0;
|
|
6930
|
+
if (typeof taskId !== "string") return void 0;
|
|
6931
|
+
const task2 = await ops.tasks.get(taskId);
|
|
6932
|
+
if (task2 === void 0) return void 0;
|
|
6933
|
+
const contextId = isRecord(message) ? message["contextId"] : void 0;
|
|
6934
|
+
if (contextId !== void 0 && contextId !== task2.contextId) {
|
|
6935
|
+
return jsonRpcError(
|
|
6936
|
+
id,
|
|
6937
|
+
JSONRPC_INVALID_PARAMS,
|
|
6938
|
+
'Message "contextId" does not match the task.'
|
|
6939
|
+
);
|
|
6940
|
+
}
|
|
6941
|
+
return jsonRpcError(
|
|
6942
|
+
id,
|
|
6943
|
+
A2A_ERROR_UNSUPPORTED_OPERATION,
|
|
6944
|
+
"This task accepts no further messages: send a new message without a taskId."
|
|
6945
|
+
);
|
|
6946
|
+
}
|
|
6947
|
+
// Return the purchase result, or a stored working task for returnImmediately
|
|
6948
|
+
async execute(ops, id, invocation, x402Extension, returnImmediately) {
|
|
6949
|
+
const { context, background } = this;
|
|
6950
|
+
if (context === void 0 || background === void 0) {
|
|
5967
6951
|
return jsonRpcError(id, JSONRPC_INTERNAL_ERROR, "A2A adapter is not running.");
|
|
5968
6952
|
}
|
|
6953
|
+
const ids = this.taskIds(context);
|
|
6954
|
+
const now = () => ({ ...ids, timestamp: context.clock.nowIso() });
|
|
5969
6955
|
const resource = this.skillsById.get(invocation.resourceId);
|
|
5970
6956
|
if (resource === void 0) {
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
),
|
|
5978
|
-
this.taskIdentity(context, context.ids.next("a2a"))
|
|
5979
|
-
)
|
|
6957
|
+
const unknown = failedTask(
|
|
6958
|
+
new CommerceError(
|
|
6959
|
+
"RESOURCE_NOT_FOUND",
|
|
6960
|
+
`Unknown canonical resource "${invocation.resourceId}".`
|
|
6961
|
+
),
|
|
6962
|
+
now()
|
|
5980
6963
|
);
|
|
5981
|
-
|
|
6964
|
+
await this.keep(ops, unknown, true);
|
|
6965
|
+
return taskResult(id, unknown);
|
|
6966
|
+
}
|
|
6967
|
+
const run = () => this.purchase(ops, context, ids, invocation, resource, x402Extension);
|
|
6968
|
+
if (!returnImmediately) return taskResult(id, await run());
|
|
6969
|
+
if (!background.reserve()) {
|
|
6970
|
+
return taskResult(id, failedTask(new CommerceError("GATEWAY_BUSY", BACKGROUND_FULL), now()));
|
|
6971
|
+
}
|
|
6972
|
+
const working = workingTask(ids.taskId, ids.contextId, context.clock.nowIso());
|
|
6973
|
+
this.running.add(ids.taskId);
|
|
6974
|
+
const refused = await this.recordWorking(ops, working);
|
|
6975
|
+
if (refused !== void 0) {
|
|
6976
|
+
this.running.delete(ids.taskId);
|
|
6977
|
+
background.release();
|
|
6978
|
+
return taskResult(id, failedTask(refused, now()));
|
|
6979
|
+
}
|
|
6980
|
+
background.start(async () => {
|
|
6981
|
+
try {
|
|
6982
|
+
await run();
|
|
6983
|
+
} finally {
|
|
6984
|
+
this.running.delete(ids.taskId);
|
|
6985
|
+
}
|
|
6986
|
+
});
|
|
6987
|
+
return taskResult(id, working);
|
|
6988
|
+
}
|
|
6989
|
+
// Execute the purchase through the pipeline and retain its response when possible
|
|
6990
|
+
async purchase(ops, context, ids, invocation, resource, x402Extension) {
|
|
6991
|
+
const now = () => ({ ...ids, timestamp: context.clock.nowIso() });
|
|
5982
6992
|
const requestId = context.ids.next("a2a");
|
|
5983
|
-
|
|
6993
|
+
let task2;
|
|
6994
|
+
let evictable = true;
|
|
6995
|
+
let proofSent = false;
|
|
5984
6996
|
try {
|
|
5985
6997
|
const { input, payment, authorization } = extractReservedInputFields(
|
|
5986
6998
|
invocation.input,
|
|
5987
6999
|
resource,
|
|
5988
7000
|
requestId
|
|
5989
7001
|
);
|
|
7002
|
+
proofSent = payment !== void 0;
|
|
5990
7003
|
const request = {
|
|
5991
7004
|
requestId,
|
|
5992
7005
|
resourceId: invocation.resourceId,
|
|
@@ -5997,58 +7010,72 @@ var A2aProtocolAdapter = class {
|
|
|
5997
7010
|
...authorization !== void 0 ? { authorization } : {}
|
|
5998
7011
|
};
|
|
5999
7012
|
const outcome = await context.pipeline.execute(request);
|
|
7013
|
+
const identity = now();
|
|
6000
7014
|
if (outcome.kind !== "payment-required") {
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
id,
|
|
6023
|
-
failedTask(
|
|
6024
|
-
new CommerceError(
|
|
6025
|
-
"GATEWAY_BUSY",
|
|
6026
|
-
"Too many unpaid purchases are waiting for payment; retry shortly."
|
|
6027
|
-
),
|
|
6028
|
-
identity
|
|
6029
|
-
)
|
|
6030
|
-
);
|
|
7015
|
+
task2 = completedTask(outcome, identity);
|
|
7016
|
+
evictable = outcome.payment === void 0;
|
|
7017
|
+
} else {
|
|
7018
|
+
task2 = paymentRequiredTask(outcome, identity);
|
|
7019
|
+
const envelope = outcome.requirement.challenge.envelope;
|
|
7020
|
+
if (x402Extension && outcome.requirement.provider === "x402" && isRecord(envelope)) {
|
|
7021
|
+
const network = outcome.requirement.network;
|
|
7022
|
+
return await this.awaitPayment(
|
|
7023
|
+
ops,
|
|
7024
|
+
identity,
|
|
7025
|
+
inputRequired(task2, paymentRequiredMetadata(envelope), identity.statusMessageId),
|
|
7026
|
+
{
|
|
7027
|
+
contextId: identity.contextId,
|
|
7028
|
+
resourceId: invocation.resourceId,
|
|
7029
|
+
input,
|
|
7030
|
+
...authorization !== void 0 ? { authorization } : {},
|
|
7031
|
+
...network !== void 0 ? { network } : {}
|
|
7032
|
+
},
|
|
7033
|
+
pendingExpiresAt(context.clock.now().getTime(), outcome.requirement.expiresAt)
|
|
7034
|
+
);
|
|
7035
|
+
}
|
|
6031
7036
|
}
|
|
6032
|
-
return taskResult(
|
|
6033
|
-
id,
|
|
6034
|
-
inputRequired(task2, paymentRequiredMetadata(envelope), identity.statusMessageId)
|
|
6035
|
-
);
|
|
6036
7037
|
} catch (err) {
|
|
6037
7038
|
const error = toCommerceError(err);
|
|
6038
7039
|
context.logger.warn(
|
|
6039
7040
|
{ resourceId: invocation.resourceId, requestId, err: toLogInfo(error) },
|
|
6040
7041
|
"a2a adapter: execution failed"
|
|
6041
7042
|
);
|
|
6042
|
-
|
|
7043
|
+
task2 = failedTask(error, now());
|
|
7044
|
+
evictable = chargedNothing(error, proofSent);
|
|
7045
|
+
}
|
|
7046
|
+
await this.keep(ops, task2, evictable);
|
|
7047
|
+
return task2;
|
|
7048
|
+
}
|
|
7049
|
+
/**
|
|
7050
|
+
* Record the input-required response before holding its pending purchase,
|
|
7051
|
+
* using the same expiry. Refuse the purchase if the record does not fit.
|
|
7052
|
+
* If pending storage throws, `execute` returns a failed task and attempts
|
|
7053
|
+
* to replace the waiting response with it.
|
|
7054
|
+
*/
|
|
7055
|
+
async awaitPayment(ops, identity, waiting, purchase, expiresAt) {
|
|
7056
|
+
if (!await ops.tasks.put(waiting, expiresAt)) {
|
|
7057
|
+
return failedTask(storeFull(), identity);
|
|
7058
|
+
}
|
|
7059
|
+
if (!await ops.pendingPayments.put(waiting.id, purchase, expiresAt)) {
|
|
7060
|
+
const busy = failedTask(
|
|
7061
|
+
new CommerceError(
|
|
7062
|
+
"GATEWAY_BUSY",
|
|
7063
|
+
"Too many unpaid purchases are waiting for payment; retry shortly."
|
|
7064
|
+
),
|
|
7065
|
+
identity
|
|
7066
|
+
);
|
|
7067
|
+
await this.keep(ops, busy, true);
|
|
7068
|
+
return busy;
|
|
6043
7069
|
}
|
|
7070
|
+
return waiting;
|
|
6044
7071
|
}
|
|
6045
|
-
|
|
7072
|
+
// Generate access keys independently of IdGenerator; keep them out of log fields
|
|
7073
|
+
taskIds(context) {
|
|
6046
7074
|
return {
|
|
6047
|
-
taskId:
|
|
6048
|
-
contextId:
|
|
7075
|
+
taskId: randomUUID(),
|
|
7076
|
+
contextId: randomUUID(),
|
|
6049
7077
|
artifactId: context.ids.next("a2a-artifact"),
|
|
6050
|
-
statusMessageId: context.ids.next("a2a-msg")
|
|
6051
|
-
timestamp: context.clock.nowIso()
|
|
7078
|
+
statusMessageId: context.ids.next("a2a-msg")
|
|
6052
7079
|
};
|
|
6053
7080
|
}
|
|
6054
7081
|
async health() {
|
|
@@ -6060,11 +7087,15 @@ var A2aProtocolAdapter = class {
|
|
|
6060
7087
|
}
|
|
6061
7088
|
async stop() {
|
|
6062
7089
|
this.started = false;
|
|
7090
|
+
await this.background?.settled();
|
|
7091
|
+
this.background = void 0;
|
|
6063
7092
|
this.card = void 0;
|
|
6064
7093
|
this.cardBody = "";
|
|
6065
7094
|
this.cardEtag = "";
|
|
6066
7095
|
this.pendingPayments?.clear();
|
|
6067
7096
|
this.pendingPayments = void 0;
|
|
7097
|
+
this.tasks = void 0;
|
|
7098
|
+
this.running.clear();
|
|
6068
7099
|
this.skillsById = /* @__PURE__ */ new Map();
|
|
6069
7100
|
this.context = void 0;
|
|
6070
7101
|
}
|
|
@@ -6076,7 +7107,8 @@ var A2aProtocolAdapter = class {
|
|
|
6076
7107
|
};
|
|
6077
7108
|
function usesX402Extension(response) {
|
|
6078
7109
|
const result = response["result"];
|
|
6079
|
-
|
|
7110
|
+
const task2 = isRecord(result) && isRecord(result["task"]) ? result["task"] : result;
|
|
7111
|
+
return task2?.status?.message?.extensions?.includes(A2A_X402_EXTENSION_URI) === true;
|
|
6080
7112
|
}
|
|
6081
7113
|
function matchesEtag(header2, etag) {
|
|
6082
7114
|
if (header2 === void 0) return false;
|
|
@@ -10623,8 +11655,8 @@ async function guardAcpRequest(req, options) {
|
|
|
10623
11655
|
}
|
|
10624
11656
|
idempotencyKey = presentedKey;
|
|
10625
11657
|
}
|
|
10626
|
-
const
|
|
10627
|
-
if (
|
|
11658
|
+
const read2 = await readCappedBody(req, options.maxBodyBytes ?? ACP_MAX_REQUEST_BODY_BYTES);
|
|
11659
|
+
if (read2.kind === "too-large") {
|
|
10628
11660
|
return failed(
|
|
10629
11661
|
acpFailure(
|
|
10630
11662
|
413,
|
|
@@ -10634,7 +11666,7 @@ async function guardAcpRequest(req, options) {
|
|
|
10634
11666
|
)
|
|
10635
11667
|
);
|
|
10636
11668
|
}
|
|
10637
|
-
if (
|
|
11669
|
+
if (read2.kind === "unreadable") {
|
|
10638
11670
|
return failed(
|
|
10639
11671
|
acpFailure(
|
|
10640
11672
|
400,
|
|
@@ -10644,7 +11676,7 @@ async function guardAcpRequest(req, options) {
|
|
|
10644
11676
|
)
|
|
10645
11677
|
);
|
|
10646
11678
|
}
|
|
10647
|
-
const raw =
|
|
11679
|
+
const raw = read2.text;
|
|
10648
11680
|
const contentTypeFailure = checkContentType(header(req, "content-type"), raw, route);
|
|
10649
11681
|
if (contentTypeFailure !== void 0) return failed(contentTypeFailure);
|
|
10650
11682
|
const definition = REQUEST_DEFINITIONS[route.operation];
|
|
@@ -11516,6 +12548,26 @@ var MIGRATIONS = [
|
|
|
11516
12548
|
);
|
|
11517
12549
|
`);
|
|
11518
12550
|
}
|
|
12551
|
+
},
|
|
12552
|
+
{
|
|
12553
|
+
version: 6,
|
|
12554
|
+
up(db) {
|
|
12555
|
+
db.exec(`
|
|
12556
|
+
CREATE TABLE IF NOT EXISTS task_records (
|
|
12557
|
+
id TEXT PRIMARY KEY,
|
|
12558
|
+
protocol TEXT NOT NULL,
|
|
12559
|
+
group_id TEXT NOT NULL,
|
|
12560
|
+
state TEXT NOT NULL,
|
|
12561
|
+
updated_at TEXT NOT NULL,
|
|
12562
|
+
document_json TEXT NOT NULL,
|
|
12563
|
+
expires_at TEXT NOT NULL,
|
|
12564
|
+
evictable INTEGER NOT NULL DEFAULT 0
|
|
12565
|
+
);
|
|
12566
|
+
CREATE INDEX IF NOT EXISTS idx_task_records_group ON task_records(protocol, group_id, updated_at);
|
|
12567
|
+
CREATE INDEX IF NOT EXISTS idx_task_records_expires_at ON task_records(expires_at);
|
|
12568
|
+
CREATE INDEX IF NOT EXISTS idx_task_records_evictable ON task_records(updated_at, id) WHERE evictable = 1;
|
|
12569
|
+
`);
|
|
12570
|
+
}
|
|
11519
12571
|
}
|
|
11520
12572
|
];
|
|
11521
12573
|
var SCHEMA_VERSION2 = MIGRATIONS.at(-1)?.version ?? 0;
|
|
@@ -11633,6 +12685,17 @@ function missingLegacyImports(db) {
|
|
|
11633
12685
|
(source) => !(recorded && selectMarker(db, source.name) !== void 0) && usedBefore(db, source)
|
|
11634
12686
|
).map((source) => source.name);
|
|
11635
12687
|
}
|
|
12688
|
+
function recordedLegacyImports(db) {
|
|
12689
|
+
if (!hasTable(db, "legacy_imports")) return [];
|
|
12690
|
+
return db.prepare(
|
|
12691
|
+
"SELECT source, path, rows, imported_at FROM legacy_imports WHERE path IS NOT NULL ORDER BY source"
|
|
12692
|
+
).all().map((row) => ({
|
|
12693
|
+
source: row.source,
|
|
12694
|
+
path: row.path,
|
|
12695
|
+
rows: row.rows,
|
|
12696
|
+
importedAt: row.imported_at
|
|
12697
|
+
}));
|
|
12698
|
+
}
|
|
11636
12699
|
function importLegacyStores(db, receiptsPath, options, clock, logger) {
|
|
11637
12700
|
const recordMarker = db.prepare(
|
|
11638
12701
|
`INSERT INTO legacy_imports (source, path, rows, imported_at) VALUES (?, ?, ?, ?)
|
|
@@ -11875,8 +12938,8 @@ function createHoldMethods(db, clock) {
|
|
|
11875
12938
|
return selectHold.get(reference)?.state;
|
|
11876
12939
|
},
|
|
11877
12940
|
async listOrphanAuthorizationHolds(options) {
|
|
11878
|
-
const
|
|
11879
|
-
return listOrphans.all(
|
|
12941
|
+
const before2 = storedIso(options.updatedBefore, "updatedBefore");
|
|
12942
|
+
return listOrphans.all(before2, clampListLimit(options.limit)).map(rowToHold);
|
|
11880
12943
|
}
|
|
11881
12944
|
};
|
|
11882
12945
|
}
|
|
@@ -12211,6 +13274,85 @@ function rowToTransaction(row, now) {
|
|
|
12211
13274
|
};
|
|
12212
13275
|
}
|
|
12213
13276
|
|
|
13277
|
+
// src/storage/receipts/task-records.ts
|
|
13278
|
+
function rowToRecord(row) {
|
|
13279
|
+
return {
|
|
13280
|
+
id: row.id,
|
|
13281
|
+
protocol: row.protocol,
|
|
13282
|
+
groupId: row.group_id,
|
|
13283
|
+
state: row.state,
|
|
13284
|
+
updatedAt: row.updated_at,
|
|
13285
|
+
document: JSON.parse(row.document_json),
|
|
13286
|
+
expiresAt: row.expires_at,
|
|
13287
|
+
...row.evictable === 1 ? { evictable: true } : {}
|
|
13288
|
+
};
|
|
13289
|
+
}
|
|
13290
|
+
var SWEEP_EXPIRED2 = "DELETE FROM task_records WHERE expires_at <= ?";
|
|
13291
|
+
function sweepExpiredTaskRecords(db, now) {
|
|
13292
|
+
db.prepare(SWEEP_EXPIRED2).run(now);
|
|
13293
|
+
}
|
|
13294
|
+
function createTaskRecordMethods(db, clock) {
|
|
13295
|
+
const sweepExpired = db.prepare(SWEEP_EXPIRED2);
|
|
13296
|
+
const countAll = db.prepare("SELECT COUNT(*) AS count FROM task_records");
|
|
13297
|
+
const hasId = db.prepare("SELECT id FROM task_records WHERE id = ?");
|
|
13298
|
+
const upsert = db.prepare(
|
|
13299
|
+
`INSERT OR REPLACE INTO task_records
|
|
13300
|
+
(id, protocol, group_id, state, updated_at, document_json, expires_at, evictable)
|
|
13301
|
+
VALUES (@id, @protocol, @group_id, @state, @updated_at, @document_json, @expires_at, @evictable)`
|
|
13302
|
+
);
|
|
13303
|
+
const evictOldest = db.prepare(
|
|
13304
|
+
`DELETE FROM task_records WHERE id IN
|
|
13305
|
+
(SELECT id FROM task_records WHERE evictable = 1 ORDER BY updated_at, id LIMIT ?)`
|
|
13306
|
+
);
|
|
13307
|
+
const selectLive = db.prepare(
|
|
13308
|
+
"SELECT * FROM task_records WHERE id = ? AND expires_at > ?"
|
|
13309
|
+
);
|
|
13310
|
+
const listLive = db.prepare(
|
|
13311
|
+
`SELECT * FROM task_records WHERE protocol = ? AND group_id = ? AND expires_at > ?
|
|
13312
|
+
ORDER BY updated_at DESC, id DESC`
|
|
13313
|
+
);
|
|
13314
|
+
const put = db.transaction((row, maxRecords) => {
|
|
13315
|
+
sweepExpired.run(clock.nowIso());
|
|
13316
|
+
if (hasId.get(row.id) === void 0) {
|
|
13317
|
+
const count = countAll.get()?.count ?? 0;
|
|
13318
|
+
if (count >= maxRecords && count - evictOldest.run(count - maxRecords + 1).changes >= maxRecords) {
|
|
13319
|
+
return false;
|
|
13320
|
+
}
|
|
13321
|
+
}
|
|
13322
|
+
upsert.run(row);
|
|
13323
|
+
return true;
|
|
13324
|
+
});
|
|
13325
|
+
return {
|
|
13326
|
+
async putTaskRecord(record, options) {
|
|
13327
|
+
try {
|
|
13328
|
+
if (!Number.isInteger(options.maxRecords) || options.maxRecords < 0) {
|
|
13329
|
+
throw new CommerceError("STORAGE_ERROR", "maxRecords must be a non-negative integer");
|
|
13330
|
+
}
|
|
13331
|
+
const row = {
|
|
13332
|
+
id: record.id,
|
|
13333
|
+
protocol: record.protocol,
|
|
13334
|
+
group_id: record.groupId,
|
|
13335
|
+
state: record.state,
|
|
13336
|
+
updated_at: storedIso(record.updatedAt, "updatedAt"),
|
|
13337
|
+
document_json: JSON.stringify(record.document),
|
|
13338
|
+
expires_at: storedIso(record.expiresAt, "expiresAt"),
|
|
13339
|
+
evictable: record.evictable === true ? 1 : 0
|
|
13340
|
+
};
|
|
13341
|
+
return put.immediate(row, options.maxRecords);
|
|
13342
|
+
} catch (err) {
|
|
13343
|
+
throw toCommerceError(err, "STORAGE_ERROR", "Failed to store task record");
|
|
13344
|
+
}
|
|
13345
|
+
},
|
|
13346
|
+
async getTaskRecord(id) {
|
|
13347
|
+
const row = selectLive.get(id, clock.nowIso());
|
|
13348
|
+
return row !== void 0 ? rowToRecord(row) : void 0;
|
|
13349
|
+
},
|
|
13350
|
+
async listTaskRecords({ protocol, groupId }) {
|
|
13351
|
+
return listLive.all(protocol, groupId, clock.nowIso()).map(rowToRecord);
|
|
13352
|
+
}
|
|
13353
|
+
};
|
|
13354
|
+
}
|
|
13355
|
+
|
|
12214
13356
|
// src/storage/receipts/store.ts
|
|
12215
13357
|
var UNDELIVERED = "backend_status NOT BETWEEN 200 AND 299";
|
|
12216
13358
|
var UNCERTAIN = "status IN ('settlement-uncertain', 'failed')";
|
|
@@ -12515,9 +13657,6 @@ function storeOn(db, options) {
|
|
|
12515
13657
|
const countLiveTasksStmt = db.prepare(
|
|
12516
13658
|
"SELECT COUNT(*) AS count FROM pending_tasks WHERE expires_at > ?"
|
|
12517
13659
|
);
|
|
12518
|
-
const legacyImportsStmt = db.prepare(
|
|
12519
|
-
"SELECT source, path, rows, imported_at FROM legacy_imports WHERE path IS NOT NULL ORDER BY source"
|
|
12520
|
-
);
|
|
12521
13660
|
let closed = false;
|
|
12522
13661
|
let releaseLegacyLocks;
|
|
12523
13662
|
const descriptor = {
|
|
@@ -12532,7 +13671,8 @@ function storeOn(db, options) {
|
|
|
12532
13671
|
"transactions",
|
|
12533
13672
|
"idempotency-keys",
|
|
12534
13673
|
"authorization-holds",
|
|
12535
|
-
"pending-tasks"
|
|
13674
|
+
"pending-tasks",
|
|
13675
|
+
"task-records"
|
|
12536
13676
|
],
|
|
12537
13677
|
status: "stable"
|
|
12538
13678
|
};
|
|
@@ -12545,7 +13685,11 @@ function storeOn(db, options) {
|
|
|
12545
13685
|
`Receipt store schema version mismatch (found ${version}, expected ${SCHEMA_VERSION2})`
|
|
12546
13686
|
);
|
|
12547
13687
|
}
|
|
12548
|
-
if (!db.readonly)
|
|
13688
|
+
if (!db.readonly) {
|
|
13689
|
+
const now = clock.nowIso();
|
|
13690
|
+
sweepExpiredPendingTasks(db, now);
|
|
13691
|
+
sweepExpiredTaskRecords(db, now);
|
|
13692
|
+
}
|
|
12549
13693
|
if (options.legacyStores !== void 0 && releaseLegacyLocks === void 0) {
|
|
12550
13694
|
releaseLegacyLocks = importLegacyStores(
|
|
12551
13695
|
db,
|
|
@@ -12751,6 +13895,7 @@ function storeOn(db, options) {
|
|
|
12751
13895
|
...createIdempotencyMethods(db, clock),
|
|
12752
13896
|
...createHoldMethods(db, clock),
|
|
12753
13897
|
...createPendingTaskMethods(db, clock),
|
|
13898
|
+
...createTaskRecordMethods(db, clock),
|
|
12754
13899
|
// Reads all unresolved transactions at once. Page this query if large
|
|
12755
13900
|
// journals make operator diagnostics too costly.
|
|
12756
13901
|
async summary({ orphanHoldMinAgeMs }) {
|
|
@@ -12771,12 +13916,7 @@ function storeOn(db, options) {
|
|
|
12771
13916
|
unresolvedIdempotencyKeys: unresolvedKeys?.other ?? 0,
|
|
12772
13917
|
unresolvedPaymentKeys: unresolvedKeys?.payment ?? 0,
|
|
12773
13918
|
unexpiredPendingTasks: countLiveTasksStmt.get(now)?.count ?? 0,
|
|
12774
|
-
legacyImports:
|
|
12775
|
-
source: row.source,
|
|
12776
|
-
path: row.path,
|
|
12777
|
-
rows: row.rows,
|
|
12778
|
-
importedAt: row.imported_at
|
|
12779
|
-
})),
|
|
13919
|
+
legacyImports: recordedLegacyImports(db),
|
|
12780
13920
|
missingLegacyImports: missingLegacyImports(db)
|
|
12781
13921
|
};
|
|
12782
13922
|
},
|