@devlab.group/agent-commerce 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -17
- 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-QZW5YL3G.js → chunk-5Q6W7YTK.js} +3 -3
- package/dist/{chunk-QZW5YL3G.js.map → chunk-5Q6W7YTK.js.map} +1 -1
- package/dist/{chunk-ENK63GKR.js → chunk-JF45GSNA.js} +3 -3
- package/dist/{chunk-ENK63GKR.js.map → chunk-JF45GSNA.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/cli/{ap2-GYKFGE66.js → ap2-SJZAZQIR.js} +5 -5
- package/dist/cli/{ap2-GYKFGE66.js.map → ap2-SJZAZQIR.js.map} +1 -1
- package/dist/cli/chunk-25WJIUJU.js +8 -0
- package/dist/cli/{chunk-SAAT2XFX.js.map → chunk-25WJIUJU.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-IJFPWT4I.js +435 -0
- package/dist/cli/chunk-IJFPWT4I.js.map +1 -0
- package/dist/cli/{chunk-VWQMSWDF.js → chunk-K34CRXKX.js} +3 -3
- package/dist/cli/{chunk-VWQMSWDF.js.map → chunk-K34CRXKX.js.map} +1 -1
- package/dist/cli/{chunk-WFIR374D.js → chunk-L264N3ZV.js} +41 -5
- package/dist/cli/chunk-L264N3ZV.js.map +1 -0
- package/dist/cli/{chunk-SYXLQ5BS.js → chunk-NM7V2Y4I.js} +5 -5
- package/dist/cli/{chunk-SYXLQ5BS.js.map → chunk-NM7V2Y4I.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/cli/{chunk-YXXPZFWC.js → chunk-U3SEGD4H.js} +126 -18
- package/dist/cli/chunk-U3SEGD4H.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/{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 +33 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-OW5GY7TT.js → mcp-F3EQQWDZ.js} +3 -3
- package/dist/cli/{mcp-OW5GY7TT.js.map → mcp-F3EQQWDZ.js.map} +1 -1
- package/dist/cli/payment-providers-FPTGQBU7.js +6 -0
- package/dist/cli/{payment-providers-QL2BJYMD.js.map → payment-providers-FPTGQBU7.js.map} +1 -1
- package/dist/cli/{provider-3A2LVEQS.js → provider-XACFJ7MG.js} +4 -4
- package/dist/cli/{provider-3A2LVEQS.js.map → provider-XACFJ7MG.js.map} +1 -1
- package/dist/cli/receipts-AXCPPGOK.js +9 -0
- package/dist/cli/{receipts-FQUFGEQD.js.map → receipts-AXCPPGOK.js.map} +1 -1
- package/dist/cli/{run-KF5OQYPL.js → run-C3VWMM57.js} +830 -184
- package/dist/cli/run-C3VWMM57.js.map +1 -0
- package/dist/cli/{x402-5A7CVCIJ.js → x402-SUXWULOP.js} +5 -5
- package/dist/cli/{x402-5A7CVCIJ.js.map → x402-SUXWULOP.js.map} +1 -1
- package/dist/index.d.ts +74 -31
- package/dist/index.js +1290 -255
- 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-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-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-JF45GSNA.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; the x402 extension is experimental",
|
|
5442
5707
|
spec: {
|
|
5443
5708
|
revisions: ["1.0.1"],
|
|
5444
5709
|
display: "v1.0.1; negotiation `1.0`; `JSONRPC` binding",
|
|
@@ -5453,16 +5718,17 @@ 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: "
|
|
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" },
|
|
5459
5728
|
{ name: "x402-extension", status: "experimental" }
|
|
5460
5729
|
],
|
|
5461
5730
|
exclusions: [
|
|
5462
5731
|
{ name: "SendStreamingMessage" },
|
|
5463
|
-
{ name: "GetTask" },
|
|
5464
|
-
{ name: "ListTasks" },
|
|
5465
|
-
{ name: "CancelTask" },
|
|
5466
5732
|
{ name: "SubscribeToTask" },
|
|
5467
5733
|
{ name: "CreateTaskPushNotificationConfig" },
|
|
5468
5734
|
{ name: "GetTaskPushNotificationConfig" },
|
|
@@ -5472,10 +5738,26 @@ var a2a_default = {
|
|
|
5472
5738
|
{ name: "HTTP+JSON/REST binding" },
|
|
5473
5739
|
{ name: "gRPC binding" },
|
|
5474
5740
|
{ name: "SSE" },
|
|
5475
|
-
{
|
|
5741
|
+
{
|
|
5742
|
+
name: "resuming a background task after a restart",
|
|
5743
|
+
note: "A task the gateway stopped in reads as failed; any payment is in the gateway records."
|
|
5744
|
+
},
|
|
5476
5745
|
{ name: "task resumption other than an x402 extension payment" },
|
|
5477
5746
|
{ name: "push notifications" },
|
|
5478
5747
|
{ name: "multi-turn conversational continuation" },
|
|
5748
|
+
{
|
|
5749
|
+
name: "client-chosen contextId",
|
|
5750
|
+
note: "A `contextId` without a task gets `UnsupportedOperationError`; each new task opens a context the gateway generates."
|
|
5751
|
+
},
|
|
5752
|
+
{
|
|
5753
|
+
name: "listing tasks across contexts",
|
|
5754
|
+
note: "`ListTasks` reads only the given `contextId`; without one, the page is empty."
|
|
5755
|
+
},
|
|
5756
|
+
{
|
|
5757
|
+
name: "task history",
|
|
5758
|
+
note: "Tasks omit `history`; `historyLength` is validated but has nothing to cap."
|
|
5759
|
+
},
|
|
5760
|
+
{ name: "non-empty tenant" },
|
|
5479
5761
|
{ name: "text parts" },
|
|
5480
5762
|
{ name: "file and URL parts (including inline bytes)" },
|
|
5481
5763
|
{ name: "multi-part messages" },
|
|
@@ -5484,38 +5766,272 @@ var a2a_default = {
|
|
|
5484
5766
|
{ name: "A2A authentication schemes" },
|
|
5485
5767
|
{ name: "artifact types beyond Agent Commerce outcome data" },
|
|
5486
5768
|
{
|
|
5487
|
-
name: "
|
|
5488
|
-
note: "Instances with separate receipt stores cannot
|
|
5769
|
+
name: "tasks across gateway instances",
|
|
5770
|
+
note: "Instances with separate receipt stores cannot read, cancel or pay each other's tasks."
|
|
5771
|
+
}
|
|
5772
|
+
],
|
|
5773
|
+
deviations: [
|
|
5774
|
+
{
|
|
5775
|
+
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.",
|
|
5776
|
+
spec: "A2A 1.0.1 \xA75.7; `ListTasksResponse.tasks`",
|
|
5777
|
+
tests: ["tests/conformance/a2a/tasks.test.ts"]
|
|
5489
5778
|
}
|
|
5490
5779
|
],
|
|
5491
|
-
deviations: [],
|
|
5492
5780
|
conformance: {
|
|
5493
|
-
suite: "Our tests against the A2A 1.0.1 specification
|
|
5781
|
+
suite: "Our tests against the A2A 1.0.1 specification, and the A2A TCK at MUST level in CI.",
|
|
5494
5782
|
tests: [
|
|
5495
5783
|
"tests/conformance/a2a/agent-card.test.ts",
|
|
5496
5784
|
"tests/conformance/a2a/errors.test.ts",
|
|
5497
5785
|
"tests/conformance/a2a/free-resource.test.ts",
|
|
5498
5786
|
"tests/conformance/a2a/paid-resource.test.ts",
|
|
5499
|
-
"tests/conformance/a2a/
|
|
5787
|
+
"tests/conformance/a2a/params.test.ts",
|
|
5788
|
+
"tests/conformance/a2a/protocol-version.test.ts",
|
|
5789
|
+
"tests/conformance/a2a/tasks.test.ts"
|
|
5500
5790
|
],
|
|
5501
|
-
skipped: []
|
|
5791
|
+
skipped: [],
|
|
5792
|
+
upstream: {
|
|
5793
|
+
repo: "a2aproject/a2a-tck",
|
|
5794
|
+
commit: "5e6f37c2d38eb3d7684686243c34d365c83df49b",
|
|
5795
|
+
command: "run_tck.py --sut-host http://127.0.0.1:8099 --transport jsonrpc --level must",
|
|
5796
|
+
workflow: ".github/workflows/ci.yml",
|
|
5797
|
+
job: "tck",
|
|
5798
|
+
results: [
|
|
5799
|
+
{
|
|
5800
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-SEND-001-jsonrpc]",
|
|
5801
|
+
id: "CORE-SEND-001",
|
|
5802
|
+
outcome: "failed",
|
|
5803
|
+
message: "Text parts are not supported",
|
|
5804
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5805
|
+
upstream: "Report drafted, not filed"
|
|
5806
|
+
},
|
|
5807
|
+
{
|
|
5808
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-EXECUTION-MODE-001-jsonrpc]",
|
|
5809
|
+
id: "CORE-EXECUTION-MODE-001",
|
|
5810
|
+
outcome: "failed",
|
|
5811
|
+
message: "Text parts are not supported",
|
|
5812
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5813
|
+
upstream: "Report drafted, not filed"
|
|
5814
|
+
},
|
|
5815
|
+
{
|
|
5816
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-EXECUTION-MODE-002-jsonrpc]",
|
|
5817
|
+
id: "CORE-EXECUTION-MODE-002",
|
|
5818
|
+
outcome: "failed",
|
|
5819
|
+
message: "Text parts are not supported",
|
|
5820
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5821
|
+
upstream: "Report drafted, not filed"
|
|
5822
|
+
},
|
|
5823
|
+
{
|
|
5824
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-MULTI-001a-jsonrpc]",
|
|
5825
|
+
id: "CORE-MULTI-001a",
|
|
5826
|
+
outcome: "failed",
|
|
5827
|
+
message: "Text parts are not supported",
|
|
5828
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5829
|
+
upstream: "Report drafted, not filed"
|
|
5830
|
+
},
|
|
5831
|
+
{
|
|
5832
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-MULTI-003-jsonrpc]",
|
|
5833
|
+
id: "CORE-MULTI-003",
|
|
5834
|
+
outcome: "failed",
|
|
5835
|
+
message: "Text parts are not supported",
|
|
5836
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5837
|
+
upstream: "Report drafted, not filed"
|
|
5838
|
+
},
|
|
5839
|
+
{
|
|
5840
|
+
test: "tests.compatibility.core_operations.test_requirements::test_must_requirement[CORE-MULTI-002a-jsonrpc]",
|
|
5841
|
+
id: "CORE-MULTI-002a",
|
|
5842
|
+
outcome: "failed",
|
|
5843
|
+
message: "Multi-turn conversational continuation is not supported",
|
|
5844
|
+
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.",
|
|
5845
|
+
spec: "A2A 1.0.1 \xA73.4.1",
|
|
5846
|
+
upstream: "Report drafted, not filed"
|
|
5847
|
+
},
|
|
5848
|
+
{
|
|
5849
|
+
test: "tests.compatibility.core_operations.test_transport_behavior.TestJsonRpcFormat::test_response_validates_jsonrpc_envelope",
|
|
5850
|
+
id: "JSONRPC-FMT-001",
|
|
5851
|
+
outcome: "failed",
|
|
5852
|
+
message: "Text parts are not supported",
|
|
5853
|
+
reason: "The test sends a text part, and the Agent Card declares only application/json input",
|
|
5854
|
+
upstream: "Report drafted, not filed"
|
|
5855
|
+
},
|
|
5856
|
+
{
|
|
5857
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestTextArtifact::test_task_has_text_artifact[jsonrpc]",
|
|
5858
|
+
id: "DM-ART-001",
|
|
5859
|
+
outcome: "skipped",
|
|
5860
|
+
message: "send_message failed: Text parts are not supported",
|
|
5861
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5862
|
+
upstream: "Report drafted, not filed"
|
|
5863
|
+
},
|
|
5864
|
+
{
|
|
5865
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestFileArtifact::test_task_has_file_artifact[jsonrpc]",
|
|
5866
|
+
id: "DM-ART-001",
|
|
5867
|
+
outcome: "skipped",
|
|
5868
|
+
message: "send_message failed: Text parts are not supported",
|
|
5869
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5870
|
+
upstream: "Report drafted, not filed"
|
|
5871
|
+
},
|
|
5872
|
+
{
|
|
5873
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestFileUrlArtifact::test_task_has_file_url_artifact[jsonrpc]",
|
|
5874
|
+
id: "DM-ART-001",
|
|
5875
|
+
outcome: "skipped",
|
|
5876
|
+
message: "send_message failed: Text parts are not supported",
|
|
5877
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5878
|
+
upstream: "Report drafted, not filed"
|
|
5879
|
+
},
|
|
5880
|
+
{
|
|
5881
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestDataArtifact::test_task_has_data_artifact[jsonrpc]",
|
|
5882
|
+
id: "DM-ART-001",
|
|
5883
|
+
outcome: "skipped",
|
|
5884
|
+
message: "send_message failed: Text parts are not supported",
|
|
5885
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5886
|
+
upstream: "Report drafted, not filed"
|
|
5887
|
+
},
|
|
5888
|
+
{
|
|
5889
|
+
test: "tests.compatibility.core_operations.test_artifacts.TestMessageResponse::test_returns_message_with_text_part[jsonrpc]",
|
|
5890
|
+
id: "DM-MSG-001",
|
|
5891
|
+
outcome: "skipped",
|
|
5892
|
+
message: "send_message failed: Text parts are not supported",
|
|
5893
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5894
|
+
upstream: "Report drafted, not filed"
|
|
5895
|
+
},
|
|
5896
|
+
{
|
|
5897
|
+
test: "tests.compatibility.core_operations.test_task_history.TestHistoryLengthLimit::test_get_task_history_does_not_exceed_limit[jsonrpc]",
|
|
5898
|
+
id: "CORE-HIST-002",
|
|
5899
|
+
outcome: "skipped",
|
|
5900
|
+
message: "send_message failed: Text parts are not supported",
|
|
5901
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5902
|
+
upstream: "Report drafted, not filed"
|
|
5903
|
+
},
|
|
5904
|
+
{
|
|
5905
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestGetTask::test_get_task_returns_current_state[jsonrpc]",
|
|
5906
|
+
id: "CORE-GET-001",
|
|
5907
|
+
outcome: "skipped",
|
|
5908
|
+
message: "send_message failed: Text parts are not supported",
|
|
5909
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5910
|
+
upstream: "Report drafted, not filed"
|
|
5911
|
+
},
|
|
5912
|
+
{
|
|
5913
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestCancelTask::test_cancel_task_returns_updated_state[jsonrpc]",
|
|
5914
|
+
id: "CORE-CANCEL-001",
|
|
5915
|
+
outcome: "skipped",
|
|
5916
|
+
message: "send_message failed: Text parts are not supported",
|
|
5917
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5918
|
+
upstream: "Report drafted, not filed"
|
|
5919
|
+
},
|
|
5920
|
+
{
|
|
5921
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestCancelTask::test_cancel_terminal_task_returns_error[jsonrpc]",
|
|
5922
|
+
id: "CORE-CANCEL-002",
|
|
5923
|
+
outcome: "skipped",
|
|
5924
|
+
message: "send_message failed: Text parts are not supported",
|
|
5925
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5926
|
+
upstream: "Report drafted, not filed"
|
|
5927
|
+
},
|
|
5928
|
+
{
|
|
5929
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestMultiTurn::test_send_message_to_terminal_task[jsonrpc]",
|
|
5930
|
+
id: "CORE-SEND-002",
|
|
5931
|
+
outcome: "skipped",
|
|
5932
|
+
message: "send_message failed: Text parts are not supported",
|
|
5933
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5934
|
+
upstream: "Report drafted, not filed"
|
|
5935
|
+
},
|
|
5936
|
+
{
|
|
5937
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestMultiTurn::test_infer_context_from_task[jsonrpc]",
|
|
5938
|
+
id: "CORE-MULTI-005",
|
|
5939
|
+
outcome: "skipped",
|
|
5940
|
+
message: "send_message failed: Text parts are not supported",
|
|
5941
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5942
|
+
upstream: "Report drafted, not filed"
|
|
5943
|
+
},
|
|
5944
|
+
{
|
|
5945
|
+
test: "tests.compatibility.core_operations.test_task_lifecycle.TestMultiTurn::test_reject_mismatching_context[jsonrpc]",
|
|
5946
|
+
id: "CORE-MULTI-006",
|
|
5947
|
+
outcome: "skipped",
|
|
5948
|
+
message: "send_message failed: Text parts are not supported",
|
|
5949
|
+
reason: "The test creates its task with a text part, which the adapter refuses",
|
|
5950
|
+
upstream: "Report drafted, not filed"
|
|
5951
|
+
},
|
|
5952
|
+
{
|
|
5953
|
+
test: "tests.compatibility.core_operations.test_data_model.TestSendMessageResponseSchema::test_response_validates_against_schema",
|
|
5954
|
+
outcome: "skipped",
|
|
5955
|
+
message: "No successful send_message responses",
|
|
5956
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
5957
|
+
upstream: "Report drafted, not filed"
|
|
5958
|
+
},
|
|
5959
|
+
{
|
|
5960
|
+
test: "tests.compatibility.core_operations.test_data_model.TestCamelCaseFieldNames::test_no_snake_case_keys",
|
|
5961
|
+
id: "DM-SERIAL-001",
|
|
5962
|
+
outcome: "skipped",
|
|
5963
|
+
message: "No successful send_message responses",
|
|
5964
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
5965
|
+
upstream: "Report drafted, not filed"
|
|
5966
|
+
},
|
|
5967
|
+
{
|
|
5968
|
+
test: "tests.compatibility.core_operations.test_data_model.TestEnumSerialization::test_enum_values_are_strings",
|
|
5969
|
+
id: "DM-SERIAL-002",
|
|
5970
|
+
outcome: "skipped",
|
|
5971
|
+
message: "No successful send_message responses",
|
|
5972
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
5973
|
+
upstream: "Report drafted, not filed"
|
|
5974
|
+
},
|
|
5975
|
+
{
|
|
5976
|
+
test: "tests.compatibility.core_operations.test_data_model.TestTimestampFormat::test_timestamps_are_iso8601_utc",
|
|
5977
|
+
id: "DM-SERIAL-003",
|
|
5978
|
+
outcome: "skipped",
|
|
5979
|
+
message: "No successful send_message responses",
|
|
5980
|
+
reason: "Every message in the run sends a text part, which leaves no successful response to check",
|
|
5981
|
+
upstream: "Report drafted, not filed"
|
|
5982
|
+
}
|
|
5983
|
+
],
|
|
5984
|
+
skipClasses: [
|
|
5985
|
+
{
|
|
5986
|
+
reason: "The gateway serves only the JSON-RPC binding",
|
|
5987
|
+
messages: [
|
|
5988
|
+
"Transport 'http_json' not configured",
|
|
5989
|
+
"Transport 'grpc' not configured",
|
|
5990
|
+
"Transport 'grpc' not configured (filtered by --transport)",
|
|
5991
|
+
"Transport 'http_json' not configured (filtered by --transport)",
|
|
5992
|
+
"HTTP+JSON transport not configured",
|
|
5993
|
+
"gRPC transport not configured"
|
|
5994
|
+
]
|
|
5995
|
+
},
|
|
5996
|
+
{
|
|
5997
|
+
reason: "The Agent Card declares streaming false (excluded)",
|
|
5998
|
+
messages: [
|
|
5999
|
+
"Agent does not support streaming",
|
|
6000
|
+
"Agent card does not declare capabilities for: ['streaming']",
|
|
6001
|
+
'Streaming not supported: A2A method "SendStreamingMessage" is not supported by this deployment.'
|
|
6002
|
+
]
|
|
6003
|
+
},
|
|
6004
|
+
{
|
|
6005
|
+
reason: "The Agent Card declares push notifications false (excluded)",
|
|
6006
|
+
messages: ["Agent does not support push notifications"]
|
|
6007
|
+
},
|
|
6008
|
+
{
|
|
6009
|
+
reason: "The Agent Card declares no extended card (excluded)",
|
|
6010
|
+
messages: ["Agent does not declare extendedAgentCard capability"]
|
|
6011
|
+
},
|
|
6012
|
+
{
|
|
6013
|
+
reason: "The TCK's probe for an agent that requires its test extension; this card requires none",
|
|
6014
|
+
messages: ["Agent card does not declare urn:a2a:tck:required-extension as required"]
|
|
6015
|
+
}
|
|
6016
|
+
]
|
|
6017
|
+
}
|
|
5502
6018
|
},
|
|
5503
6019
|
gaps: [
|
|
5504
6020
|
{
|
|
5505
6021
|
requirement: "\xA73.1: GetTask, ListTasks and CancelTask, which every agent implements",
|
|
5506
|
-
state: "
|
|
6022
|
+
state: "closed"
|
|
5507
6023
|
},
|
|
5508
6024
|
{
|
|
5509
6025
|
requirement: "\xA73.2.2: returnImmediately as well as the blocking default",
|
|
5510
|
-
state: "
|
|
6026
|
+
state: "closed"
|
|
5511
6027
|
},
|
|
5512
6028
|
{
|
|
5513
6029
|
requirement: "\xA73.3.2: validate all input parameters, including tenant and configuration",
|
|
5514
|
-
state: "
|
|
6030
|
+
state: "closed"
|
|
5515
6031
|
},
|
|
5516
6032
|
{
|
|
5517
|
-
requirement: "\xA77.1: encrypted communication in production; merchant.publicBaseUrl
|
|
5518
|
-
state: "
|
|
6033
|
+
requirement: "\xA77.1: encrypted communication in production; config accepts an http merchant.publicBaseUrl, and doctor warns when its host is not loopback",
|
|
6034
|
+
state: "closed"
|
|
5519
6035
|
}
|
|
5520
6036
|
],
|
|
5521
6037
|
docs: ["docs/protocols/a2a.md"]
|
|
@@ -5526,6 +6042,10 @@ var A2A_CAPABILITIES = [
|
|
|
5526
6042
|
"agent-card",
|
|
5527
6043
|
"jsonrpc",
|
|
5528
6044
|
"SendMessage",
|
|
6045
|
+
"GetTask",
|
|
6046
|
+
"ListTasks",
|
|
6047
|
+
"CancelTask",
|
|
6048
|
+
"returnImmediately",
|
|
5529
6049
|
// The x402 A2A transport, opt-in per request
|
|
5530
6050
|
"x402-extension"
|
|
5531
6051
|
];
|
|
@@ -5608,23 +6128,63 @@ function failedTask(error, identity) {
|
|
|
5608
6128
|
identity.statusMessageId
|
|
5609
6129
|
);
|
|
5610
6130
|
}
|
|
6131
|
+
var UNCHARGED_CODES = /* @__PURE__ */ new Set([
|
|
6132
|
+
"RESOURCE_NOT_FOUND",
|
|
6133
|
+
"INPUT_INVALID",
|
|
6134
|
+
"PAYMENT_INVALID",
|
|
6135
|
+
"PAYMENT_REPLAYED",
|
|
6136
|
+
"AUTHORIZATION_REQUIRED",
|
|
6137
|
+
"AUTHORIZATION_INVALID",
|
|
6138
|
+
"AUTHORIZATION_REPLAYED",
|
|
6139
|
+
"AUTHORIZATION_PROVIDER_UNAVAILABLE"
|
|
6140
|
+
]);
|
|
6141
|
+
function chargedNothing(error, proofSent) {
|
|
6142
|
+
if (!proofSent || UNCHARGED_CODES.has(error.code)) return true;
|
|
6143
|
+
const backend = error.code === "BACKEND_ERROR" || error.code === "BACKEND_TIMEOUT";
|
|
6144
|
+
return backend && error.details?.["payment"] === void 0;
|
|
6145
|
+
}
|
|
6146
|
+
function workingTask(taskId, contextId, timestamp) {
|
|
6147
|
+
return {
|
|
6148
|
+
id: taskId,
|
|
6149
|
+
contextId,
|
|
6150
|
+
status: { state: A2A_TASK_STATE_WORKING, timestamp },
|
|
6151
|
+
artifacts: []
|
|
6152
|
+
};
|
|
6153
|
+
}
|
|
6154
|
+
function canceledTask(taskId, contextId, timestamp, messageId) {
|
|
6155
|
+
return withStatusMessage(
|
|
6156
|
+
{ id: taskId, contextId, status: { state: A2A_TASK_STATE_CANCELED, timestamp }, artifacts: [] },
|
|
6157
|
+
"Task canceled.",
|
|
6158
|
+
messageId
|
|
6159
|
+
);
|
|
6160
|
+
}
|
|
6161
|
+
function interruptedTask(task2) {
|
|
6162
|
+
const error = new CommerceError(
|
|
6163
|
+
"INTERNAL_ERROR",
|
|
6164
|
+
"This task stopped before its result was recorded. Any payment is in the gateway records: check with the merchant before paying again."
|
|
6165
|
+
);
|
|
6166
|
+
return failedTask(error, {
|
|
6167
|
+
taskId: task2.id,
|
|
6168
|
+
contextId: task2.contextId,
|
|
6169
|
+
artifactId: `${task2.id}-interrupted`,
|
|
6170
|
+
statusMessageId: `${task2.id}-interrupted`,
|
|
6171
|
+
timestamp: task2.status.timestamp
|
|
6172
|
+
});
|
|
6173
|
+
}
|
|
5611
6174
|
|
|
5612
6175
|
// src/protocols/a2a/payment-resume.ts
|
|
5613
6176
|
function taskResult(id, task2) {
|
|
5614
6177
|
return jsonRpcResult(id, { task: task2 });
|
|
5615
6178
|
}
|
|
5616
|
-
|
|
6179
|
+
var BACKGROUND_FULL = "Too many tasks are running in the background; retry shortly.";
|
|
6180
|
+
var BACKGROUND_RETRY_SECONDS = 1;
|
|
6181
|
+
async function resumePayment(resume, id, params, returnImmediately) {
|
|
6182
|
+
const { context, pendingPayments } = resume;
|
|
5617
6183
|
const message = isRecord(params) ? params["message"] : void 0;
|
|
5618
6184
|
const taskId = isRecord(message) ? message["taskId"] : void 0;
|
|
5619
|
-
if (
|
|
5620
|
-
const pending = await pendingPayments
|
|
6185
|
+
if (typeof taskId !== "string") return void 0;
|
|
6186
|
+
const pending = await pendingPayments.get(taskId);
|
|
5621
6187
|
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
6188
|
const contextId = isRecord(message) ? message["contextId"] : void 0;
|
|
5629
6189
|
if (contextId !== void 0 && contextId !== pending.contextId) {
|
|
5630
6190
|
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, 'Message "contextId" does not match the task.');
|
|
@@ -5645,43 +6205,78 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
5645
6205
|
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, toCommerceError(err).message);
|
|
5646
6206
|
}
|
|
5647
6207
|
}
|
|
5648
|
-
const
|
|
6208
|
+
const immediate = returnImmediately && submission.kind === "submitted";
|
|
6209
|
+
if (immediate && !resume.background.reserve()) {
|
|
6210
|
+
return jsonRpcError(id, JSONRPC_INTERNAL_ERROR, BACKGROUND_FULL, [
|
|
6211
|
+
retryInfo(BACKGROUND_RETRY_SECONDS)
|
|
6212
|
+
]);
|
|
6213
|
+
}
|
|
6214
|
+
let taken;
|
|
6215
|
+
try {
|
|
6216
|
+
taken = await pendingPayments.take(taskId);
|
|
6217
|
+
} finally {
|
|
6218
|
+
if (immediate && taken === void 0) resume.background.release();
|
|
6219
|
+
}
|
|
5649
6220
|
if (taken === void 0) return void 0;
|
|
5650
6221
|
const authorization = taken.authorization ?? followUp;
|
|
5651
|
-
|
|
5652
|
-
|
|
6222
|
+
if (submission.kind === "rejected") {
|
|
6223
|
+
const timestamp = context.clock.nowIso();
|
|
6224
|
+
const declined = withStatusMessage(
|
|
6225
|
+
{
|
|
6226
|
+
id: taskId,
|
|
6227
|
+
contextId: taken.contextId,
|
|
6228
|
+
status: { state: A2A_TASK_STATE_FAILED, timestamp },
|
|
6229
|
+
artifacts: []
|
|
6230
|
+
},
|
|
6231
|
+
"Payment was declined.",
|
|
6232
|
+
context.ids.next("a2a-msg"),
|
|
6233
|
+
paymentRejectedMetadata()
|
|
6234
|
+
);
|
|
6235
|
+
await resume.keep(declined, true);
|
|
6236
|
+
return taskResult(id, declined);
|
|
6237
|
+
}
|
|
6238
|
+
const ids = {
|
|
5653
6239
|
taskId,
|
|
5654
6240
|
contextId: taken.contextId,
|
|
5655
6241
|
artifactId: context.ids.next("a2a-artifact"),
|
|
5656
|
-
statusMessageId
|
|
5657
|
-
timestamp: context.clock.nowIso()
|
|
6242
|
+
statusMessageId: context.ids.next("a2a-msg")
|
|
5658
6243
|
};
|
|
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
|
-
)
|
|
6244
|
+
const working = withStatusMessage(
|
|
6245
|
+
workingTask(taskId, taken.contextId, context.clock.nowIso()),
|
|
6246
|
+
"Payment received; processing it.",
|
|
6247
|
+
context.ids.next("a2a-msg"),
|
|
6248
|
+
{ [X402_PAYMENT_STATUS_KEY]: "payment-submitted" }
|
|
5684
6249
|
);
|
|
6250
|
+
resume.running.add(taskId);
|
|
6251
|
+
if (!immediate) {
|
|
6252
|
+
await resume.keep(working, false);
|
|
6253
|
+
} else {
|
|
6254
|
+
const refused = await resume.recordWorking(working);
|
|
6255
|
+
if (refused !== void 0) {
|
|
6256
|
+
resume.running.delete(taskId);
|
|
6257
|
+
resume.background.release();
|
|
6258
|
+
const failed = failedTask(refused, { ...ids, timestamp: context.clock.nowIso() });
|
|
6259
|
+
await resume.keep(failed, true);
|
|
6260
|
+
return taskResult(id, failed);
|
|
6261
|
+
}
|
|
6262
|
+
}
|
|
6263
|
+
const pay = async () => {
|
|
6264
|
+
try {
|
|
6265
|
+
const { task: paid, evictable } = await payPending(
|
|
6266
|
+
context,
|
|
6267
|
+
{ ...taken, ...authorization !== void 0 ? { authorization } : {} },
|
|
6268
|
+
submission.payload,
|
|
6269
|
+
ids
|
|
6270
|
+
);
|
|
6271
|
+
await resume.keep(paid, evictable);
|
|
6272
|
+
return paid;
|
|
6273
|
+
} finally {
|
|
6274
|
+
resume.running.delete(taskId);
|
|
6275
|
+
}
|
|
6276
|
+
};
|
|
6277
|
+
if (!immediate) return taskResult(id, await pay());
|
|
6278
|
+
resume.background.start(pay);
|
|
6279
|
+
return taskResult(id, working);
|
|
5685
6280
|
}
|
|
5686
6281
|
function withoutRetryDelay(error) {
|
|
5687
6282
|
if (error.details?.["reason"] !== "payment_identifier_in_flight") return error;
|
|
@@ -5694,7 +6289,7 @@ function withoutRetryDelay(error) {
|
|
|
5694
6289
|
...error.resourceId !== void 0 ? { resourceId: error.resourceId } : {}
|
|
5695
6290
|
});
|
|
5696
6291
|
}
|
|
5697
|
-
async function payPending(context, pending, payload,
|
|
6292
|
+
async function payPending(context, pending, payload, ids) {
|
|
5698
6293
|
const requestId = context.ids.next("a2a");
|
|
5699
6294
|
const request = {
|
|
5700
6295
|
requestId,
|
|
@@ -5713,12 +6308,14 @@ async function payPending(context, pending, payload, identity) {
|
|
|
5713
6308
|
try {
|
|
5714
6309
|
const outcome = await context.pipeline.execute(request);
|
|
5715
6310
|
if (outcome.kind === "delivered" && outcome.payment !== void 0) {
|
|
5716
|
-
|
|
5717
|
-
|
|
6311
|
+
const identity2 = { ...ids, timestamp: context.clock.nowIso() };
|
|
6312
|
+
const task2 = withStatusMessage(
|
|
6313
|
+
completedTask(outcome, identity2),
|
|
5718
6314
|
"Payment settled.",
|
|
5719
|
-
|
|
6315
|
+
identity2.statusMessageId,
|
|
5720
6316
|
paymentCompletedMetadata(outcome.payment)
|
|
5721
6317
|
);
|
|
6318
|
+
return { task: task2, evictable: false };
|
|
5722
6319
|
}
|
|
5723
6320
|
error = new CommerceError("PAYMENT_INVALID", "The payment was not accepted.", { requestId });
|
|
5724
6321
|
} catch (err) {
|
|
@@ -5728,24 +6325,183 @@ async function payPending(context, pending, payload, identity) {
|
|
|
5728
6325
|
"a2a adapter: x402 extension payment failed"
|
|
5729
6326
|
);
|
|
5730
6327
|
}
|
|
6328
|
+
const identity = { ...ids, timestamp: context.clock.nowIso() };
|
|
5731
6329
|
const metadata = paymentFailureMetadata(error, pending.network);
|
|
5732
6330
|
const reason = error.details?.["reason"];
|
|
5733
|
-
let text
|
|
6331
|
+
let text;
|
|
5734
6332
|
if (metadata[X402_PAYMENT_STATUS_KEY] === "payment-completed") {
|
|
5735
6333
|
text = "Payment settled, but the resource could not be delivered.";
|
|
5736
6334
|
} else if (typeof reason === "string" && reason.startsWith("payment_identifier_")) {
|
|
5737
6335
|
text = error.message;
|
|
5738
|
-
} else
|
|
5739
|
-
|
|
6336
|
+
} else {
|
|
6337
|
+
const outcome = error.code.startsWith("PAYMENT_") ? "Payment failed" : "The resource could not be delivered";
|
|
6338
|
+
text = `${outcome}: ${String(metadata[X402_PAYMENT_ERROR_KEY])}.`;
|
|
5740
6339
|
}
|
|
5741
|
-
return
|
|
6340
|
+
return {
|
|
6341
|
+
task: withStatusMessage(failedTask(error, identity), text, identity.statusMessageId, metadata),
|
|
6342
|
+
evictable: chargedNothing(error, true)
|
|
6343
|
+
};
|
|
6344
|
+
}
|
|
6345
|
+
|
|
6346
|
+
// src/protocols/a2a/task-operations.ts
|
|
6347
|
+
var NOT_FOUND = "Task not found.";
|
|
6348
|
+
function reported(task2, running) {
|
|
6349
|
+
return task2.status.state === A2A_TASK_STATE_WORKING && !running.has(task2.id) ? interruptedTask(task2) : task2;
|
|
6350
|
+
}
|
|
6351
|
+
async function getTask(ops, id, params) {
|
|
6352
|
+
const task2 = await ops.tasks.get(params.id);
|
|
6353
|
+
if (task2 === void 0) return jsonRpcError(id, A2A_ERROR_TASK_NOT_FOUND, NOT_FOUND);
|
|
6354
|
+
return jsonRpcResult(id, reported(task2, ops.running));
|
|
6355
|
+
}
|
|
6356
|
+
function before(a, b) {
|
|
6357
|
+
return a.at > b.at || a.at === b.at && a.id > b.id;
|
|
6358
|
+
}
|
|
6359
|
+
async function listTasks(ops, id, params) {
|
|
6360
|
+
const recorded = params.contextId === void 0 ? [] : await ops.tasks.list(params.contextId);
|
|
6361
|
+
const after = params.statusTimestampAfter !== void 0 ? Date.parse(params.statusTimestampAfter) : void 0;
|
|
6362
|
+
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);
|
|
6363
|
+
let start = 0;
|
|
6364
|
+
if (params.after !== void 0) {
|
|
6365
|
+
const key = { at: Date.parse(params.after.updatedAt), id: params.after.id };
|
|
6366
|
+
start = matching.findIndex((entry) => before(key, entry.key));
|
|
6367
|
+
if (start === -1) start = matching.length;
|
|
6368
|
+
}
|
|
6369
|
+
const page = matching.slice(start, start + params.pageSize);
|
|
6370
|
+
const last = page.at(-1);
|
|
6371
|
+
const more = start + page.length < matching.length;
|
|
6372
|
+
return jsonRpcResult(id, {
|
|
6373
|
+
tasks: page.map(({ task: task2 }) => {
|
|
6374
|
+
if (params.includeArtifacts) return task2;
|
|
6375
|
+
const { artifacts: _artifacts, ...rest } = task2;
|
|
6376
|
+
return rest;
|
|
6377
|
+
}),
|
|
6378
|
+
nextPageToken: more && last !== void 0 ? encodePageToken({ updatedAt: last.task.status.timestamp, id: last.task.id }) : "",
|
|
6379
|
+
pageSize: params.pageSize,
|
|
6380
|
+
totalSize: matching.length
|
|
6381
|
+
});
|
|
6382
|
+
}
|
|
6383
|
+
async function cancelTask(ops, id, params) {
|
|
6384
|
+
const taken = await ops.pendingPayments.take(params.id);
|
|
6385
|
+
if (taken !== void 0) {
|
|
6386
|
+
const canceled = canceledTask(
|
|
6387
|
+
params.id,
|
|
6388
|
+
taken.contextId,
|
|
6389
|
+
ops.clock.nowIso(),
|
|
6390
|
+
ops.nextMessageId()
|
|
6391
|
+
);
|
|
6392
|
+
if (!await ops.tasks.put(canceled, ops.retainedUntil(), true)) {
|
|
6393
|
+
throw new CommerceError("STORAGE_ERROR", "The canceled task did not fit in the task store.");
|
|
6394
|
+
}
|
|
6395
|
+
return jsonRpcResult(id, canceled);
|
|
6396
|
+
}
|
|
6397
|
+
const task2 = await ops.tasks.get(params.id);
|
|
6398
|
+
if (task2 === void 0) return jsonRpcError(id, A2A_ERROR_TASK_NOT_FOUND, NOT_FOUND);
|
|
6399
|
+
if (task2.status.state === A2A_TASK_STATE_CANCELED) return jsonRpcResult(id, task2);
|
|
6400
|
+
return jsonRpcError(
|
|
6401
|
+
id,
|
|
6402
|
+
A2A_ERROR_TASK_NOT_CANCELABLE,
|
|
6403
|
+
"Only a task waiting for payment can be canceled; this one is running or finished."
|
|
6404
|
+
);
|
|
6405
|
+
}
|
|
6406
|
+
|
|
6407
|
+
// src/protocols/a2a/task-store.ts
|
|
6408
|
+
function createStoredTasks(store, maxRecords) {
|
|
6409
|
+
return {
|
|
6410
|
+
put: (task2, expiresAt, evictable) => store.putTaskRecord(
|
|
6411
|
+
{
|
|
6412
|
+
id: task2.id,
|
|
6413
|
+
protocol: "a2a",
|
|
6414
|
+
groupId: task2.contextId,
|
|
6415
|
+
state: task2.status.state,
|
|
6416
|
+
updatedAt: task2.status.timestamp,
|
|
6417
|
+
document: task2,
|
|
6418
|
+
expiresAt,
|
|
6419
|
+
...evictable === true ? { evictable } : {}
|
|
6420
|
+
},
|
|
6421
|
+
{ maxRecords }
|
|
6422
|
+
),
|
|
6423
|
+
async get(id) {
|
|
6424
|
+
const record = await store.getTaskRecord(id);
|
|
6425
|
+
return record?.protocol === "a2a" ? record.document : void 0;
|
|
6426
|
+
},
|
|
6427
|
+
async list(contextId) {
|
|
6428
|
+
const records = await store.listTaskRecords({ protocol: "a2a", groupId: contextId });
|
|
6429
|
+
return records.map((record) => record.document);
|
|
6430
|
+
}
|
|
6431
|
+
};
|
|
6432
|
+
}
|
|
6433
|
+
function createMemoryTasks(clock, maxRecords) {
|
|
6434
|
+
const tasks = /* @__PURE__ */ new Map();
|
|
6435
|
+
const live = (expiresAtMs) => expiresAtMs > clock.now().getTime();
|
|
6436
|
+
return {
|
|
6437
|
+
async put(task2, expiresAt, evictable = false) {
|
|
6438
|
+
if (!tasks.has(task2.id) && tasks.size >= maxRecords) {
|
|
6439
|
+
for (const [id, held] of tasks) if (!live(held.expiresAtMs)) tasks.delete(id);
|
|
6440
|
+
if (tasks.size >= maxRecords) {
|
|
6441
|
+
let oldest;
|
|
6442
|
+
for (const [id, held] of tasks) {
|
|
6443
|
+
if (held.evictable) {
|
|
6444
|
+
oldest = id;
|
|
6445
|
+
break;
|
|
6446
|
+
}
|
|
6447
|
+
}
|
|
6448
|
+
if (oldest === void 0) return false;
|
|
6449
|
+
tasks.delete(oldest);
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6452
|
+
tasks.delete(task2.id);
|
|
6453
|
+
tasks.set(task2.id, { task: task2, expiresAtMs: Date.parse(expiresAt), evictable });
|
|
6454
|
+
return true;
|
|
6455
|
+
},
|
|
6456
|
+
async get(id) {
|
|
6457
|
+
const held = tasks.get(id);
|
|
6458
|
+
return held !== void 0 && live(held.expiresAtMs) ? held.task : void 0;
|
|
6459
|
+
},
|
|
6460
|
+
// ponytail: listing scans all tasks; add a context index if large stores become slow
|
|
6461
|
+
async list(contextId) {
|
|
6462
|
+
return [...tasks.values()].filter((held) => held.task.contextId === contextId && live(held.expiresAtMs)).map((held) => held.task);
|
|
6463
|
+
}
|
|
6464
|
+
};
|
|
5742
6465
|
}
|
|
5743
6466
|
|
|
5744
6467
|
// src/protocols/a2a/adapter.ts
|
|
5745
6468
|
var MAX_REQUEST_BODY_BYTES = 256 * 1024;
|
|
5746
6469
|
var VERSION_PATTERN = /^(\d+\.\d+)(?:\.\d+)?$/;
|
|
5747
6470
|
var A2A_VERSION_PARAMETER = "A2A-Version";
|
|
6471
|
+
var X402_EXTENSION_ECHO = {
|
|
6472
|
+
[A2A_EXTENSIONS_HEADER]: A2A_X402_EXTENSION_URI,
|
|
6473
|
+
[A2A_X_EXTENSIONS_HEADER]: A2A_X402_EXTENSION_URI
|
|
6474
|
+
};
|
|
5748
6475
|
var AGENT_CARD_CACHE_CONTROL = "public, max-age=300";
|
|
6476
|
+
function taskLimit(value, name, bounds) {
|
|
6477
|
+
if (value === void 0) return bounds.default;
|
|
6478
|
+
if (!Number.isInteger(value) || value < bounds.min || value > bounds.max) {
|
|
6479
|
+
throw new CommerceError(
|
|
6480
|
+
"CONFIG_INVALID",
|
|
6481
|
+
`A2A adapter option "tasks.${name}" must be an integer from ${bounds.min} to ${bounds.max}`,
|
|
6482
|
+
{ details: { path: `tasks.${name}` } }
|
|
6483
|
+
);
|
|
6484
|
+
}
|
|
6485
|
+
return value;
|
|
6486
|
+
}
|
|
6487
|
+
function storeFull() {
|
|
6488
|
+
return new CommerceError("GATEWAY_BUSY", "Too many answered tasks are retained; retry shortly.");
|
|
6489
|
+
}
|
|
6490
|
+
async function withParams(id, read2, run) {
|
|
6491
|
+
let params;
|
|
6492
|
+
try {
|
|
6493
|
+
params = read2();
|
|
6494
|
+
} catch (err) {
|
|
6495
|
+
return refusal(id, err);
|
|
6496
|
+
}
|
|
6497
|
+
return run(params);
|
|
6498
|
+
}
|
|
6499
|
+
function refusal(id, err) {
|
|
6500
|
+
const error = toCommerceError(err);
|
|
6501
|
+
const a2aErrorCode = error.details?.["a2aErrorCode"];
|
|
6502
|
+
const code = typeof a2aErrorCode === "number" ? a2aErrorCode : error.code === "PROTOCOL_UNSUPPORTED" ? A2A_ERROR_UNSUPPORTED_OPERATION : JSONRPC_INVALID_PARAMS;
|
|
6503
|
+
return jsonRpcError(id, code, error.message);
|
|
6504
|
+
}
|
|
5749
6505
|
var DEFAULT_AGENT_DESCRIPTION = "Agent Commerce Gateway: canonical commerce resources exposed as A2A skills.";
|
|
5750
6506
|
var A2aProtocolAdapter = class {
|
|
5751
6507
|
name = "a2a";
|
|
@@ -5756,6 +6512,8 @@ var A2aProtocolAdapter = class {
|
|
|
5756
6512
|
agentDescription;
|
|
5757
6513
|
agentVersion;
|
|
5758
6514
|
store;
|
|
6515
|
+
retentionMs;
|
|
6516
|
+
maxRetained;
|
|
5759
6517
|
context;
|
|
5760
6518
|
started = false;
|
|
5761
6519
|
// The card lists only a2a-exposed resources, but a caller can name any id,
|
|
@@ -5768,12 +6526,19 @@ var A2aProtocolAdapter = class {
|
|
|
5768
6526
|
cardEtag = "";
|
|
5769
6527
|
// Purchases waiting for an x402 extension payment
|
|
5770
6528
|
pendingPayments;
|
|
6529
|
+
// Retained responses for task lookup, listing and cancellation
|
|
6530
|
+
tasks;
|
|
6531
|
+
// Active task ids; see TaskOperations.running
|
|
6532
|
+
running = /* @__PURE__ */ new Set();
|
|
6533
|
+
background;
|
|
5771
6534
|
constructor(options = {}) {
|
|
5772
6535
|
this.mountPath = options.mountPath ?? A2A_DEFAULT_MOUNT_PATH;
|
|
5773
6536
|
this.agentName = options.agentName ?? A2A_DEFAULT_AGENT_NAME;
|
|
5774
6537
|
this.agentDescription = options.agentDescription ?? DEFAULT_AGENT_DESCRIPTION;
|
|
5775
6538
|
this.agentVersion = options.agentVersion ?? PACKAGE_VERSION;
|
|
5776
6539
|
this.store = options.store;
|
|
6540
|
+
this.retentionMs = taskLimit(options.tasks?.retentionHours, "retentionHours", A2A_TASK_RETENTION_HOURS) * 36e5;
|
|
6541
|
+
this.maxRetained = taskLimit(options.tasks?.maxRetained, "maxRetained", A2A_MAX_RETAINED_TASKS);
|
|
5777
6542
|
this.descriptor = buildDescriptor(PACKAGE_VERSION);
|
|
5778
6543
|
this.additionalHttpRoutes = [
|
|
5779
6544
|
{
|
|
@@ -5806,6 +6571,8 @@ var A2aProtocolAdapter = class {
|
|
|
5806
6571
|
resources
|
|
5807
6572
|
});
|
|
5808
6573
|
this.pendingPayments = hasMethodGroup(this.store, "pending_tasks") ? createStoredPendingPayments(this.store, context.clock) : createPendingPayments(context.clock);
|
|
6574
|
+
this.tasks = hasMethodGroup(this.store, "task_records") ? createStoredTasks(this.store, this.maxRetained) : createMemoryTasks(context.clock, this.maxRetained);
|
|
6575
|
+
this.background = createBackgroundRuns(A2A_MAX_BACKGROUND_RUNS, context.logger);
|
|
5809
6576
|
this.cardBody = JSON.stringify(this.card);
|
|
5810
6577
|
this.cardEtag = `"${createHash("sha256").update(this.cardBody).digest("base64url")}"`;
|
|
5811
6578
|
this.started = true;
|
|
@@ -5840,6 +6607,7 @@ var A2aProtocolAdapter = class {
|
|
|
5840
6607
|
}
|
|
5841
6608
|
/** `POST <mountPath>`: the A2A JSON-RPC endpoint */
|
|
5842
6609
|
async handleHttp(req, res) {
|
|
6610
|
+
let requestId = null;
|
|
5843
6611
|
try {
|
|
5844
6612
|
if (!this.started) {
|
|
5845
6613
|
this.writeJson(
|
|
@@ -5861,8 +6629,8 @@ var A2aProtocolAdapter = class {
|
|
|
5861
6629
|
);
|
|
5862
6630
|
return;
|
|
5863
6631
|
}
|
|
5864
|
-
const
|
|
5865
|
-
if (
|
|
6632
|
+
const read2 = await readCappedBody(req, MAX_REQUEST_BODY_BYTES);
|
|
6633
|
+
if (read2.kind === "too-large") {
|
|
5866
6634
|
this.writeJson(
|
|
5867
6635
|
res,
|
|
5868
6636
|
413,
|
|
@@ -5874,7 +6642,7 @@ var A2aProtocolAdapter = class {
|
|
|
5874
6642
|
);
|
|
5875
6643
|
return;
|
|
5876
6644
|
}
|
|
5877
|
-
if (
|
|
6645
|
+
if (read2.kind !== "ok") {
|
|
5878
6646
|
this.writeJson(
|
|
5879
6647
|
res,
|
|
5880
6648
|
200,
|
|
@@ -5882,11 +6650,12 @@ var A2aProtocolAdapter = class {
|
|
|
5882
6650
|
);
|
|
5883
6651
|
return;
|
|
5884
6652
|
}
|
|
5885
|
-
const parsed = parseJsonRpcRequest(
|
|
6653
|
+
const parsed = parseJsonRpcRequest(read2.text);
|
|
5886
6654
|
if (!parsed.ok) {
|
|
5887
6655
|
this.writeJson(res, 200, jsonRpcError(parsed.id, parsed.error.code, parsed.error.message));
|
|
5888
6656
|
return;
|
|
5889
6657
|
}
|
|
6658
|
+
requestId = parsed.request.id;
|
|
5890
6659
|
const version = req.headers[A2A_VERSION_HEADER];
|
|
5891
6660
|
const declared = (Array.isArray(version) ? version[0] : version) ?? new URL(req.url ?? "/", "http://localhost").searchParams.get(A2A_VERSION_PARAMETER);
|
|
5892
6661
|
if (declared?.match(VERSION_PATTERN)?.[1] !== A2A_PROTOCOL_VERSION) {
|
|
@@ -5901,24 +6670,21 @@ var A2aProtocolAdapter = class {
|
|
|
5901
6670
|
);
|
|
5902
6671
|
return;
|
|
5903
6672
|
}
|
|
6673
|
+
const activated = requestsX402Extension(req.headers[A2A_EXTENSIONS_HEADER]) || requestsX402Extension(req.headers[A2A_X_EXTENSIONS_HEADER]);
|
|
5904
6674
|
const response = await this.dispatch(
|
|
5905
6675
|
parsed.request.id,
|
|
5906
6676
|
parsed.request.method,
|
|
5907
6677
|
parsed.request.params,
|
|
5908
|
-
|
|
5909
|
-
);
|
|
5910
|
-
this.writeJson(
|
|
5911
|
-
res,
|
|
5912
|
-
200,
|
|
5913
|
-
response,
|
|
5914
|
-
usesX402Extension(response) ? { [A2A_EXTENSIONS_HEADER]: A2A_X402_EXTENSION_URI } : {}
|
|
6678
|
+
activated
|
|
5915
6679
|
);
|
|
6680
|
+
const echo = usesX402Extension(response) || activated && response["error"] === void 0;
|
|
6681
|
+
this.writeJson(res, 200, response, echo ? X402_EXTENSION_ECHO : {});
|
|
5916
6682
|
} catch (err) {
|
|
5917
6683
|
this.context?.logger.error({ err: toLogInfo(err) }, "a2a adapter: request handling failed");
|
|
5918
6684
|
this.writeJson(
|
|
5919
6685
|
res,
|
|
5920
6686
|
200,
|
|
5921
|
-
jsonRpcError(
|
|
6687
|
+
jsonRpcError(requestId, JSONRPC_INTERNAL_ERROR, "Internal server error.")
|
|
5922
6688
|
);
|
|
5923
6689
|
}
|
|
5924
6690
|
}
|
|
@@ -5930,13 +6696,6 @@ var A2aProtocolAdapter = class {
|
|
|
5930
6696
|
`A2A method "${method}" is not supported: this agent does not support push notifications.`
|
|
5931
6697
|
);
|
|
5932
6698
|
}
|
|
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
6699
|
if (A2A_UNSUPPORTED_METHODS.includes(method)) {
|
|
5941
6700
|
return jsonRpcError(
|
|
5942
6701
|
id,
|
|
@@ -5944,49 +6703,198 @@ var A2aProtocolAdapter = class {
|
|
|
5944
6703
|
`A2A method "${method}" is not supported by this deployment.`
|
|
5945
6704
|
);
|
|
5946
6705
|
}
|
|
5947
|
-
|
|
5948
|
-
|
|
6706
|
+
const raw = isRecord(params) ? params : {};
|
|
6707
|
+
const ops = this.operations();
|
|
6708
|
+
switch (method) {
|
|
6709
|
+
case A2A_METHOD_SEND_MESSAGE:
|
|
6710
|
+
break;
|
|
6711
|
+
case A2A_METHOD_GET_TASK:
|
|
6712
|
+
return withParams(
|
|
6713
|
+
id,
|
|
6714
|
+
() => readGetTaskParams(raw),
|
|
6715
|
+
(read2) => getTask(ops, id, read2)
|
|
6716
|
+
);
|
|
6717
|
+
case A2A_METHOD_LIST_TASKS:
|
|
6718
|
+
return withParams(
|
|
6719
|
+
id,
|
|
6720
|
+
() => readListTasksParams(raw),
|
|
6721
|
+
(read2) => listTasks(ops, id, read2)
|
|
6722
|
+
);
|
|
6723
|
+
case A2A_METHOD_CANCEL_TASK:
|
|
6724
|
+
return withParams(
|
|
6725
|
+
id,
|
|
6726
|
+
() => readCancelTaskParams(raw),
|
|
6727
|
+
(read2) => cancelTask(ops, id, read2)
|
|
6728
|
+
);
|
|
6729
|
+
default:
|
|
6730
|
+
return jsonRpcError(id, JSONRPC_METHOD_NOT_FOUND, `Unknown method "${method}".`);
|
|
6731
|
+
}
|
|
6732
|
+
let request;
|
|
6733
|
+
try {
|
|
6734
|
+
request = readSendMessageParams(raw);
|
|
6735
|
+
readMessage(request.params);
|
|
6736
|
+
} catch (err) {
|
|
6737
|
+
return refusal(id, err);
|
|
5949
6738
|
}
|
|
5950
|
-
const resumed = await resumePayment(
|
|
6739
|
+
const resumed = await resumePayment(
|
|
6740
|
+
this.resume(ops),
|
|
6741
|
+
id,
|
|
6742
|
+
request.params,
|
|
6743
|
+
request.returnImmediately
|
|
6744
|
+
);
|
|
5951
6745
|
if (resumed !== void 0) return resumed;
|
|
6746
|
+
const known = await this.answerKnownTask(ops, id, request.params);
|
|
6747
|
+
if (known !== void 0) return known;
|
|
5952
6748
|
let invocation;
|
|
5953
6749
|
try {
|
|
5954
|
-
invocation = parseInvocation(params);
|
|
6750
|
+
invocation = parseInvocation(request.params);
|
|
5955
6751
|
} 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);
|
|
6752
|
+
return refusal(id, err);
|
|
5960
6753
|
}
|
|
5961
|
-
return this.execute(id, invocation, x402Extension);
|
|
6754
|
+
return this.execute(ops, id, invocation, x402Extension, request.returnImmediately);
|
|
5962
6755
|
}
|
|
5963
|
-
//
|
|
5964
|
-
|
|
5965
|
-
const context = this
|
|
5966
|
-
if (context === void 0) {
|
|
6756
|
+
// Collect task-operation state after startup; handleHttp returns 503 before startup
|
|
6757
|
+
operations() {
|
|
6758
|
+
const { context, tasks, pendingPayments } = this;
|
|
6759
|
+
if (context === void 0 || tasks === void 0 || pendingPayments === void 0) {
|
|
6760
|
+
throw new CommerceError("INTERNAL_ERROR", "A2A adapter is not running.");
|
|
6761
|
+
}
|
|
6762
|
+
return {
|
|
6763
|
+
tasks,
|
|
6764
|
+
pendingPayments,
|
|
6765
|
+
running: this.running,
|
|
6766
|
+
clock: context.clock,
|
|
6767
|
+
retainedUntil: () => this.retainedUntil(context),
|
|
6768
|
+
nextMessageId: () => context.ids.next("a2a-msg")
|
|
6769
|
+
};
|
|
6770
|
+
}
|
|
6771
|
+
resume(ops) {
|
|
6772
|
+
const { context, background } = this;
|
|
6773
|
+
if (context === void 0 || background === void 0) {
|
|
6774
|
+
throw new CommerceError("INTERNAL_ERROR", "A2A adapter is not running.");
|
|
6775
|
+
}
|
|
6776
|
+
return {
|
|
6777
|
+
context,
|
|
6778
|
+
pendingPayments: ops.pendingPayments,
|
|
6779
|
+
keep: (task2, evictable) => this.keep(ops, task2, evictable),
|
|
6780
|
+
running: this.running,
|
|
6781
|
+
background,
|
|
6782
|
+
recordWorking: (task2) => this.recordWorking(ops, task2)
|
|
6783
|
+
};
|
|
6784
|
+
}
|
|
6785
|
+
retainedUntil(context) {
|
|
6786
|
+
return new Date(context.clock.now().getTime() + this.retentionMs).toISOString();
|
|
6787
|
+
}
|
|
6788
|
+
// Retain a response without failing the call. Log capacity refusals at warn
|
|
6789
|
+
// and write exceptions at error; return false in either case.
|
|
6790
|
+
async keep(ops, task2, evictable) {
|
|
6791
|
+
const logger = this.context?.logger;
|
|
6792
|
+
try {
|
|
6793
|
+
if (await ops.tasks.put(task2, ops.retainedUntil(), evictable)) return true;
|
|
6794
|
+
logger?.warn(
|
|
6795
|
+
{ state: task2.status.state },
|
|
6796
|
+
"a2a adapter: task not retained: the task store is full"
|
|
6797
|
+
);
|
|
6798
|
+
} catch (err) {
|
|
6799
|
+
logger?.error(
|
|
6800
|
+
{ state: task2.status.state, err: toLogInfo(err) },
|
|
6801
|
+
"a2a adapter: task not retained"
|
|
6802
|
+
);
|
|
6803
|
+
}
|
|
6804
|
+
return false;
|
|
6805
|
+
}
|
|
6806
|
+
// Store the working response before starting background work; return any
|
|
6807
|
+
// failure so the caller can stop admission
|
|
6808
|
+
async recordWorking(ops, task2) {
|
|
6809
|
+
try {
|
|
6810
|
+
return await ops.tasks.put(task2, ops.retainedUntil()) ? void 0 : storeFull();
|
|
6811
|
+
} catch (err) {
|
|
6812
|
+
this.context?.logger.error({ err: toLogInfo(err) }, "a2a adapter: working task not recorded");
|
|
6813
|
+
return toCommerceError(err);
|
|
6814
|
+
}
|
|
6815
|
+
}
|
|
6816
|
+
/**
|
|
6817
|
+
* Reject further messages on a retained task after the pending-payment path
|
|
6818
|
+
* declines it, including tasks taken by another call. Terminal tasks accept
|
|
6819
|
+
* no further messages (A2A 1.0.1 section 3.1.1). Missing records fall through
|
|
6820
|
+
* to `parseInvocation`, which returns `TaskNotFoundError`.
|
|
6821
|
+
*/
|
|
6822
|
+
async answerKnownTask(ops, id, params) {
|
|
6823
|
+
const message = params["message"];
|
|
6824
|
+
const taskId = isRecord(message) ? message["taskId"] : void 0;
|
|
6825
|
+
if (typeof taskId !== "string") return void 0;
|
|
6826
|
+
const task2 = await ops.tasks.get(taskId);
|
|
6827
|
+
if (task2 === void 0) return void 0;
|
|
6828
|
+
const contextId = isRecord(message) ? message["contextId"] : void 0;
|
|
6829
|
+
if (contextId !== void 0 && contextId !== task2.contextId) {
|
|
6830
|
+
return jsonRpcError(
|
|
6831
|
+
id,
|
|
6832
|
+
JSONRPC_INVALID_PARAMS,
|
|
6833
|
+
'Message "contextId" does not match the task.'
|
|
6834
|
+
);
|
|
6835
|
+
}
|
|
6836
|
+
return jsonRpcError(
|
|
6837
|
+
id,
|
|
6838
|
+
A2A_ERROR_UNSUPPORTED_OPERATION,
|
|
6839
|
+
"This task accepts no further messages: send a new message without a taskId."
|
|
6840
|
+
);
|
|
6841
|
+
}
|
|
6842
|
+
// Return the purchase result, or a stored working task for returnImmediately
|
|
6843
|
+
async execute(ops, id, invocation, x402Extension, returnImmediately) {
|
|
6844
|
+
const { context, background } = this;
|
|
6845
|
+
if (context === void 0 || background === void 0) {
|
|
5967
6846
|
return jsonRpcError(id, JSONRPC_INTERNAL_ERROR, "A2A adapter is not running.");
|
|
5968
6847
|
}
|
|
6848
|
+
const ids = this.taskIds(context);
|
|
6849
|
+
const now = () => ({ ...ids, timestamp: context.clock.nowIso() });
|
|
5969
6850
|
const resource = this.skillsById.get(invocation.resourceId);
|
|
5970
6851
|
if (resource === void 0) {
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
),
|
|
5978
|
-
this.taskIdentity(context, context.ids.next("a2a"))
|
|
5979
|
-
)
|
|
6852
|
+
const unknown = failedTask(
|
|
6853
|
+
new CommerceError(
|
|
6854
|
+
"RESOURCE_NOT_FOUND",
|
|
6855
|
+
`Unknown canonical resource "${invocation.resourceId}".`
|
|
6856
|
+
),
|
|
6857
|
+
now()
|
|
5980
6858
|
);
|
|
5981
|
-
|
|
6859
|
+
await this.keep(ops, unknown, true);
|
|
6860
|
+
return taskResult(id, unknown);
|
|
6861
|
+
}
|
|
6862
|
+
const run = () => this.purchase(ops, context, ids, invocation, resource, x402Extension);
|
|
6863
|
+
if (!returnImmediately) return taskResult(id, await run());
|
|
6864
|
+
if (!background.reserve()) {
|
|
6865
|
+
return taskResult(id, failedTask(new CommerceError("GATEWAY_BUSY", BACKGROUND_FULL), now()));
|
|
6866
|
+
}
|
|
6867
|
+
const working = workingTask(ids.taskId, ids.contextId, context.clock.nowIso());
|
|
6868
|
+
this.running.add(ids.taskId);
|
|
6869
|
+
const refused = await this.recordWorking(ops, working);
|
|
6870
|
+
if (refused !== void 0) {
|
|
6871
|
+
this.running.delete(ids.taskId);
|
|
6872
|
+
background.release();
|
|
6873
|
+
return taskResult(id, failedTask(refused, now()));
|
|
6874
|
+
}
|
|
6875
|
+
background.start(async () => {
|
|
6876
|
+
try {
|
|
6877
|
+
await run();
|
|
6878
|
+
} finally {
|
|
6879
|
+
this.running.delete(ids.taskId);
|
|
6880
|
+
}
|
|
6881
|
+
});
|
|
6882
|
+
return taskResult(id, working);
|
|
6883
|
+
}
|
|
6884
|
+
// Execute the purchase through the pipeline and retain its response when possible
|
|
6885
|
+
async purchase(ops, context, ids, invocation, resource, x402Extension) {
|
|
6886
|
+
const now = () => ({ ...ids, timestamp: context.clock.nowIso() });
|
|
5982
6887
|
const requestId = context.ids.next("a2a");
|
|
5983
|
-
|
|
6888
|
+
let task2;
|
|
6889
|
+
let evictable = true;
|
|
6890
|
+
let proofSent = false;
|
|
5984
6891
|
try {
|
|
5985
6892
|
const { input, payment, authorization } = extractReservedInputFields(
|
|
5986
6893
|
invocation.input,
|
|
5987
6894
|
resource,
|
|
5988
6895
|
requestId
|
|
5989
6896
|
);
|
|
6897
|
+
proofSent = payment !== void 0;
|
|
5990
6898
|
const request = {
|
|
5991
6899
|
requestId,
|
|
5992
6900
|
resourceId: invocation.resourceId,
|
|
@@ -5997,58 +6905,72 @@ var A2aProtocolAdapter = class {
|
|
|
5997
6905
|
...authorization !== void 0 ? { authorization } : {}
|
|
5998
6906
|
};
|
|
5999
6907
|
const outcome = await context.pipeline.execute(request);
|
|
6908
|
+
const identity = now();
|
|
6000
6909
|
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
|
-
);
|
|
6910
|
+
task2 = completedTask(outcome, identity);
|
|
6911
|
+
evictable = outcome.payment === void 0;
|
|
6912
|
+
} else {
|
|
6913
|
+
task2 = paymentRequiredTask(outcome, identity);
|
|
6914
|
+
const envelope = outcome.requirement.challenge.envelope;
|
|
6915
|
+
if (x402Extension && outcome.requirement.provider === "x402" && isRecord(envelope)) {
|
|
6916
|
+
const network = outcome.requirement.network;
|
|
6917
|
+
return await this.awaitPayment(
|
|
6918
|
+
ops,
|
|
6919
|
+
identity,
|
|
6920
|
+
inputRequired(task2, paymentRequiredMetadata(envelope), identity.statusMessageId),
|
|
6921
|
+
{
|
|
6922
|
+
contextId: identity.contextId,
|
|
6923
|
+
resourceId: invocation.resourceId,
|
|
6924
|
+
input,
|
|
6925
|
+
...authorization !== void 0 ? { authorization } : {},
|
|
6926
|
+
...network !== void 0 ? { network } : {}
|
|
6927
|
+
},
|
|
6928
|
+
pendingExpiresAt(context.clock.now().getTime(), outcome.requirement.expiresAt)
|
|
6929
|
+
);
|
|
6930
|
+
}
|
|
6031
6931
|
}
|
|
6032
|
-
return taskResult(
|
|
6033
|
-
id,
|
|
6034
|
-
inputRequired(task2, paymentRequiredMetadata(envelope), identity.statusMessageId)
|
|
6035
|
-
);
|
|
6036
6932
|
} catch (err) {
|
|
6037
6933
|
const error = toCommerceError(err);
|
|
6038
6934
|
context.logger.warn(
|
|
6039
6935
|
{ resourceId: invocation.resourceId, requestId, err: toLogInfo(error) },
|
|
6040
6936
|
"a2a adapter: execution failed"
|
|
6041
6937
|
);
|
|
6042
|
-
|
|
6938
|
+
task2 = failedTask(error, now());
|
|
6939
|
+
evictable = chargedNothing(error, proofSent);
|
|
6940
|
+
}
|
|
6941
|
+
await this.keep(ops, task2, evictable);
|
|
6942
|
+
return task2;
|
|
6943
|
+
}
|
|
6944
|
+
/**
|
|
6945
|
+
* Record the input-required response before holding its pending purchase,
|
|
6946
|
+
* using the same expiry. Refuse the purchase if the record does not fit.
|
|
6947
|
+
* If pending storage throws, `execute` returns a failed task and attempts
|
|
6948
|
+
* to replace the waiting response with it.
|
|
6949
|
+
*/
|
|
6950
|
+
async awaitPayment(ops, identity, waiting, purchase, expiresAt) {
|
|
6951
|
+
if (!await ops.tasks.put(waiting, expiresAt)) {
|
|
6952
|
+
return failedTask(storeFull(), identity);
|
|
6953
|
+
}
|
|
6954
|
+
if (!await ops.pendingPayments.put(waiting.id, purchase, expiresAt)) {
|
|
6955
|
+
const busy = failedTask(
|
|
6956
|
+
new CommerceError(
|
|
6957
|
+
"GATEWAY_BUSY",
|
|
6958
|
+
"Too many unpaid purchases are waiting for payment; retry shortly."
|
|
6959
|
+
),
|
|
6960
|
+
identity
|
|
6961
|
+
);
|
|
6962
|
+
await this.keep(ops, busy, true);
|
|
6963
|
+
return busy;
|
|
6043
6964
|
}
|
|
6965
|
+
return waiting;
|
|
6044
6966
|
}
|
|
6045
|
-
|
|
6967
|
+
// Generate access keys independently of IdGenerator; keep them out of log fields
|
|
6968
|
+
taskIds(context) {
|
|
6046
6969
|
return {
|
|
6047
|
-
taskId:
|
|
6048
|
-
contextId:
|
|
6970
|
+
taskId: randomUUID(),
|
|
6971
|
+
contextId: randomUUID(),
|
|
6049
6972
|
artifactId: context.ids.next("a2a-artifact"),
|
|
6050
|
-
statusMessageId: context.ids.next("a2a-msg")
|
|
6051
|
-
timestamp: context.clock.nowIso()
|
|
6973
|
+
statusMessageId: context.ids.next("a2a-msg")
|
|
6052
6974
|
};
|
|
6053
6975
|
}
|
|
6054
6976
|
async health() {
|
|
@@ -6060,11 +6982,15 @@ var A2aProtocolAdapter = class {
|
|
|
6060
6982
|
}
|
|
6061
6983
|
async stop() {
|
|
6062
6984
|
this.started = false;
|
|
6985
|
+
await this.background?.settled();
|
|
6986
|
+
this.background = void 0;
|
|
6063
6987
|
this.card = void 0;
|
|
6064
6988
|
this.cardBody = "";
|
|
6065
6989
|
this.cardEtag = "";
|
|
6066
6990
|
this.pendingPayments?.clear();
|
|
6067
6991
|
this.pendingPayments = void 0;
|
|
6992
|
+
this.tasks = void 0;
|
|
6993
|
+
this.running.clear();
|
|
6068
6994
|
this.skillsById = /* @__PURE__ */ new Map();
|
|
6069
6995
|
this.context = void 0;
|
|
6070
6996
|
}
|
|
@@ -6076,7 +7002,8 @@ var A2aProtocolAdapter = class {
|
|
|
6076
7002
|
};
|
|
6077
7003
|
function usesX402Extension(response) {
|
|
6078
7004
|
const result = response["result"];
|
|
6079
|
-
|
|
7005
|
+
const task2 = isRecord(result) && isRecord(result["task"]) ? result["task"] : result;
|
|
7006
|
+
return task2?.status?.message?.extensions?.includes(A2A_X402_EXTENSION_URI) === true;
|
|
6080
7007
|
}
|
|
6081
7008
|
function matchesEtag(header2, etag) {
|
|
6082
7009
|
if (header2 === void 0) return false;
|
|
@@ -10623,8 +11550,8 @@ async function guardAcpRequest(req, options) {
|
|
|
10623
11550
|
}
|
|
10624
11551
|
idempotencyKey = presentedKey;
|
|
10625
11552
|
}
|
|
10626
|
-
const
|
|
10627
|
-
if (
|
|
11553
|
+
const read2 = await readCappedBody(req, options.maxBodyBytes ?? ACP_MAX_REQUEST_BODY_BYTES);
|
|
11554
|
+
if (read2.kind === "too-large") {
|
|
10628
11555
|
return failed(
|
|
10629
11556
|
acpFailure(
|
|
10630
11557
|
413,
|
|
@@ -10634,7 +11561,7 @@ async function guardAcpRequest(req, options) {
|
|
|
10634
11561
|
)
|
|
10635
11562
|
);
|
|
10636
11563
|
}
|
|
10637
|
-
if (
|
|
11564
|
+
if (read2.kind === "unreadable") {
|
|
10638
11565
|
return failed(
|
|
10639
11566
|
acpFailure(
|
|
10640
11567
|
400,
|
|
@@ -10644,7 +11571,7 @@ async function guardAcpRequest(req, options) {
|
|
|
10644
11571
|
)
|
|
10645
11572
|
);
|
|
10646
11573
|
}
|
|
10647
|
-
const raw =
|
|
11574
|
+
const raw = read2.text;
|
|
10648
11575
|
const contentTypeFailure = checkContentType(header(req, "content-type"), raw, route);
|
|
10649
11576
|
if (contentTypeFailure !== void 0) return failed(contentTypeFailure);
|
|
10650
11577
|
const definition = REQUEST_DEFINITIONS[route.operation];
|
|
@@ -11516,6 +12443,26 @@ var MIGRATIONS = [
|
|
|
11516
12443
|
);
|
|
11517
12444
|
`);
|
|
11518
12445
|
}
|
|
12446
|
+
},
|
|
12447
|
+
{
|
|
12448
|
+
version: 6,
|
|
12449
|
+
up(db) {
|
|
12450
|
+
db.exec(`
|
|
12451
|
+
CREATE TABLE IF NOT EXISTS task_records (
|
|
12452
|
+
id TEXT PRIMARY KEY,
|
|
12453
|
+
protocol TEXT NOT NULL,
|
|
12454
|
+
group_id TEXT NOT NULL,
|
|
12455
|
+
state TEXT NOT NULL,
|
|
12456
|
+
updated_at TEXT NOT NULL,
|
|
12457
|
+
document_json TEXT NOT NULL,
|
|
12458
|
+
expires_at TEXT NOT NULL,
|
|
12459
|
+
evictable INTEGER NOT NULL DEFAULT 0
|
|
12460
|
+
);
|
|
12461
|
+
CREATE INDEX IF NOT EXISTS idx_task_records_group ON task_records(protocol, group_id, updated_at);
|
|
12462
|
+
CREATE INDEX IF NOT EXISTS idx_task_records_expires_at ON task_records(expires_at);
|
|
12463
|
+
CREATE INDEX IF NOT EXISTS idx_task_records_evictable ON task_records(updated_at, id) WHERE evictable = 1;
|
|
12464
|
+
`);
|
|
12465
|
+
}
|
|
11519
12466
|
}
|
|
11520
12467
|
];
|
|
11521
12468
|
var SCHEMA_VERSION2 = MIGRATIONS.at(-1)?.version ?? 0;
|
|
@@ -11633,6 +12580,17 @@ function missingLegacyImports(db) {
|
|
|
11633
12580
|
(source) => !(recorded && selectMarker(db, source.name) !== void 0) && usedBefore(db, source)
|
|
11634
12581
|
).map((source) => source.name);
|
|
11635
12582
|
}
|
|
12583
|
+
function recordedLegacyImports(db) {
|
|
12584
|
+
if (!hasTable(db, "legacy_imports")) return [];
|
|
12585
|
+
return db.prepare(
|
|
12586
|
+
"SELECT source, path, rows, imported_at FROM legacy_imports WHERE path IS NOT NULL ORDER BY source"
|
|
12587
|
+
).all().map((row) => ({
|
|
12588
|
+
source: row.source,
|
|
12589
|
+
path: row.path,
|
|
12590
|
+
rows: row.rows,
|
|
12591
|
+
importedAt: row.imported_at
|
|
12592
|
+
}));
|
|
12593
|
+
}
|
|
11636
12594
|
function importLegacyStores(db, receiptsPath, options, clock, logger) {
|
|
11637
12595
|
const recordMarker = db.prepare(
|
|
11638
12596
|
`INSERT INTO legacy_imports (source, path, rows, imported_at) VALUES (?, ?, ?, ?)
|
|
@@ -11875,8 +12833,8 @@ function createHoldMethods(db, clock) {
|
|
|
11875
12833
|
return selectHold.get(reference)?.state;
|
|
11876
12834
|
},
|
|
11877
12835
|
async listOrphanAuthorizationHolds(options) {
|
|
11878
|
-
const
|
|
11879
|
-
return listOrphans.all(
|
|
12836
|
+
const before2 = storedIso(options.updatedBefore, "updatedBefore");
|
|
12837
|
+
return listOrphans.all(before2, clampListLimit(options.limit)).map(rowToHold);
|
|
11880
12838
|
}
|
|
11881
12839
|
};
|
|
11882
12840
|
}
|
|
@@ -12211,6 +13169,85 @@ function rowToTransaction(row, now) {
|
|
|
12211
13169
|
};
|
|
12212
13170
|
}
|
|
12213
13171
|
|
|
13172
|
+
// src/storage/receipts/task-records.ts
|
|
13173
|
+
function rowToRecord(row) {
|
|
13174
|
+
return {
|
|
13175
|
+
id: row.id,
|
|
13176
|
+
protocol: row.protocol,
|
|
13177
|
+
groupId: row.group_id,
|
|
13178
|
+
state: row.state,
|
|
13179
|
+
updatedAt: row.updated_at,
|
|
13180
|
+
document: JSON.parse(row.document_json),
|
|
13181
|
+
expiresAt: row.expires_at,
|
|
13182
|
+
...row.evictable === 1 ? { evictable: true } : {}
|
|
13183
|
+
};
|
|
13184
|
+
}
|
|
13185
|
+
var SWEEP_EXPIRED2 = "DELETE FROM task_records WHERE expires_at <= ?";
|
|
13186
|
+
function sweepExpiredTaskRecords(db, now) {
|
|
13187
|
+
db.prepare(SWEEP_EXPIRED2).run(now);
|
|
13188
|
+
}
|
|
13189
|
+
function createTaskRecordMethods(db, clock) {
|
|
13190
|
+
const sweepExpired = db.prepare(SWEEP_EXPIRED2);
|
|
13191
|
+
const countAll = db.prepare("SELECT COUNT(*) AS count FROM task_records");
|
|
13192
|
+
const hasId = db.prepare("SELECT id FROM task_records WHERE id = ?");
|
|
13193
|
+
const upsert = db.prepare(
|
|
13194
|
+
`INSERT OR REPLACE INTO task_records
|
|
13195
|
+
(id, protocol, group_id, state, updated_at, document_json, expires_at, evictable)
|
|
13196
|
+
VALUES (@id, @protocol, @group_id, @state, @updated_at, @document_json, @expires_at, @evictable)`
|
|
13197
|
+
);
|
|
13198
|
+
const evictOldest = db.prepare(
|
|
13199
|
+
`DELETE FROM task_records WHERE id IN
|
|
13200
|
+
(SELECT id FROM task_records WHERE evictable = 1 ORDER BY updated_at, id LIMIT ?)`
|
|
13201
|
+
);
|
|
13202
|
+
const selectLive = db.prepare(
|
|
13203
|
+
"SELECT * FROM task_records WHERE id = ? AND expires_at > ?"
|
|
13204
|
+
);
|
|
13205
|
+
const listLive = db.prepare(
|
|
13206
|
+
`SELECT * FROM task_records WHERE protocol = ? AND group_id = ? AND expires_at > ?
|
|
13207
|
+
ORDER BY updated_at DESC, id DESC`
|
|
13208
|
+
);
|
|
13209
|
+
const put = db.transaction((row, maxRecords) => {
|
|
13210
|
+
sweepExpired.run(clock.nowIso());
|
|
13211
|
+
if (hasId.get(row.id) === void 0) {
|
|
13212
|
+
const count = countAll.get()?.count ?? 0;
|
|
13213
|
+
if (count >= maxRecords && count - evictOldest.run(count - maxRecords + 1).changes >= maxRecords) {
|
|
13214
|
+
return false;
|
|
13215
|
+
}
|
|
13216
|
+
}
|
|
13217
|
+
upsert.run(row);
|
|
13218
|
+
return true;
|
|
13219
|
+
});
|
|
13220
|
+
return {
|
|
13221
|
+
async putTaskRecord(record, options) {
|
|
13222
|
+
try {
|
|
13223
|
+
if (!Number.isInteger(options.maxRecords) || options.maxRecords < 0) {
|
|
13224
|
+
throw new CommerceError("STORAGE_ERROR", "maxRecords must be a non-negative integer");
|
|
13225
|
+
}
|
|
13226
|
+
const row = {
|
|
13227
|
+
id: record.id,
|
|
13228
|
+
protocol: record.protocol,
|
|
13229
|
+
group_id: record.groupId,
|
|
13230
|
+
state: record.state,
|
|
13231
|
+
updated_at: storedIso(record.updatedAt, "updatedAt"),
|
|
13232
|
+
document_json: JSON.stringify(record.document),
|
|
13233
|
+
expires_at: storedIso(record.expiresAt, "expiresAt"),
|
|
13234
|
+
evictable: record.evictable === true ? 1 : 0
|
|
13235
|
+
};
|
|
13236
|
+
return put.immediate(row, options.maxRecords);
|
|
13237
|
+
} catch (err) {
|
|
13238
|
+
throw toCommerceError(err, "STORAGE_ERROR", "Failed to store task record");
|
|
13239
|
+
}
|
|
13240
|
+
},
|
|
13241
|
+
async getTaskRecord(id) {
|
|
13242
|
+
const row = selectLive.get(id, clock.nowIso());
|
|
13243
|
+
return row !== void 0 ? rowToRecord(row) : void 0;
|
|
13244
|
+
},
|
|
13245
|
+
async listTaskRecords({ protocol, groupId }) {
|
|
13246
|
+
return listLive.all(protocol, groupId, clock.nowIso()).map(rowToRecord);
|
|
13247
|
+
}
|
|
13248
|
+
};
|
|
13249
|
+
}
|
|
13250
|
+
|
|
12214
13251
|
// src/storage/receipts/store.ts
|
|
12215
13252
|
var UNDELIVERED = "backend_status NOT BETWEEN 200 AND 299";
|
|
12216
13253
|
var UNCERTAIN = "status IN ('settlement-uncertain', 'failed')";
|
|
@@ -12515,9 +13552,6 @@ function storeOn(db, options) {
|
|
|
12515
13552
|
const countLiveTasksStmt = db.prepare(
|
|
12516
13553
|
"SELECT COUNT(*) AS count FROM pending_tasks WHERE expires_at > ?"
|
|
12517
13554
|
);
|
|
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
13555
|
let closed = false;
|
|
12522
13556
|
let releaseLegacyLocks;
|
|
12523
13557
|
const descriptor = {
|
|
@@ -12532,7 +13566,8 @@ function storeOn(db, options) {
|
|
|
12532
13566
|
"transactions",
|
|
12533
13567
|
"idempotency-keys",
|
|
12534
13568
|
"authorization-holds",
|
|
12535
|
-
"pending-tasks"
|
|
13569
|
+
"pending-tasks",
|
|
13570
|
+
"task-records"
|
|
12536
13571
|
],
|
|
12537
13572
|
status: "stable"
|
|
12538
13573
|
};
|
|
@@ -12545,7 +13580,11 @@ function storeOn(db, options) {
|
|
|
12545
13580
|
`Receipt store schema version mismatch (found ${version}, expected ${SCHEMA_VERSION2})`
|
|
12546
13581
|
);
|
|
12547
13582
|
}
|
|
12548
|
-
if (!db.readonly)
|
|
13583
|
+
if (!db.readonly) {
|
|
13584
|
+
const now = clock.nowIso();
|
|
13585
|
+
sweepExpiredPendingTasks(db, now);
|
|
13586
|
+
sweepExpiredTaskRecords(db, now);
|
|
13587
|
+
}
|
|
12549
13588
|
if (options.legacyStores !== void 0 && releaseLegacyLocks === void 0) {
|
|
12550
13589
|
releaseLegacyLocks = importLegacyStores(
|
|
12551
13590
|
db,
|
|
@@ -12751,6 +13790,7 @@ function storeOn(db, options) {
|
|
|
12751
13790
|
...createIdempotencyMethods(db, clock),
|
|
12752
13791
|
...createHoldMethods(db, clock),
|
|
12753
13792
|
...createPendingTaskMethods(db, clock),
|
|
13793
|
+
...createTaskRecordMethods(db, clock),
|
|
12754
13794
|
// Reads all unresolved transactions at once. Page this query if large
|
|
12755
13795
|
// journals make operator diagnostics too costly.
|
|
12756
13796
|
async summary({ orphanHoldMinAgeMs }) {
|
|
@@ -12771,12 +13811,7 @@ function storeOn(db, options) {
|
|
|
12771
13811
|
unresolvedIdempotencyKeys: unresolvedKeys?.other ?? 0,
|
|
12772
13812
|
unresolvedPaymentKeys: unresolvedKeys?.payment ?? 0,
|
|
12773
13813
|
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
|
-
})),
|
|
13814
|
+
legacyImports: recordedLegacyImports(db),
|
|
12780
13815
|
missingLegacyImports: missingLegacyImports(db)
|
|
12781
13816
|
};
|
|
12782
13817
|
},
|