@devlab.group/agent-commerce 2.7.2 → 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 +79 -30
- package/dist/ap2.d.ts +3 -11
- package/dist/ap2.js +97 -28
- package/dist/ap2.js.map +1 -1
- package/dist/{chunk-77HLISG4.js → chunk-2PVRHMVT.js} +14 -10
- package/dist/chunk-2PVRHMVT.js.map +1 -0
- package/dist/{chunk-WDD2ZUR3.js → chunk-46Y5M7BA.js} +3 -2
- package/dist/chunk-46Y5M7BA.js.map +1 -0
- package/dist/{chunk-XXHC6AA3.js → chunk-5Q6W7YTK.js} +160 -41
- package/dist/chunk-5Q6W7YTK.js.map +1 -0
- package/dist/chunk-JF45GSNA.js +22 -0
- package/dist/chunk-JF45GSNA.js.map +1 -0
- package/dist/{chunk-YHNTTMED.js → chunk-MDOGXTZD.js} +2 -2
- package/dist/chunk-MDOGXTZD.js.map +1 -0
- package/dist/chunk-MNI6APE6.js +64 -0
- package/dist/chunk-MNI6APE6.js.map +1 -0
- package/dist/{chunk-IWXVQYG5.js → chunk-RF3DFVXH.js} +2 -2
- package/dist/{chunk-IWXVQYG5.js.map → chunk-RF3DFVXH.js.map} +1 -1
- package/dist/{chunk-DJRWYDKJ.js → chunk-RXYGC7A3.js} +3 -3
- package/dist/{chunk-DJRWYDKJ.js.map → chunk-RXYGC7A3.js.map} +1 -1
- package/dist/{chunk-5AO5N2XY.js → chunk-VHS6MGXJ.js} +621 -4
- package/dist/chunk-VHS6MGXJ.js.map +1 -0
- package/dist/cli/{ap2-O3HJSS2E.js → ap2-SJZAZQIR.js} +36 -9
- package/dist/cli/ap2-SJZAZQIR.js.map +1 -0
- package/dist/cli/chunk-25WJIUJU.js +8 -0
- package/dist/cli/{chunk-B4QJV7OC.js.map → chunk-25WJIUJU.js.map} +1 -1
- package/dist/cli/chunk-2PO65227.js +619 -0
- package/dist/cli/chunk-2PO65227.js.map +1 -0
- package/dist/cli/{chunk-DKWO6LLX.js → chunk-4WPHZLVO.js} +3 -2
- package/dist/cli/chunk-4WPHZLVO.js.map +1 -0
- package/dist/cli/chunk-4YZULHX2.js +64 -0
- package/dist/cli/chunk-4YZULHX2.js.map +1 -0
- package/dist/cli/chunk-526C4KZA.js +93 -0
- package/dist/cli/chunk-526C4KZA.js.map +1 -0
- package/dist/cli/{chunk-FETTSOMT.js → chunk-5CH5VFC6.js} +139 -4
- package/dist/cli/chunk-5CH5VFC6.js.map +1 -0
- package/dist/cli/chunk-GISJ73ML.js +20 -0
- package/dist/cli/chunk-GISJ73ML.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-QUFFT5K3.js → chunk-K34CRXKX.js} +141 -42
- package/dist/cli/chunk-K34CRXKX.js.map +1 -0
- package/dist/cli/{chunk-OETKXDGA.js → chunk-L264N3ZV.js} +127 -274
- package/dist/cli/chunk-L264N3ZV.js.map +1 -0
- package/dist/cli/chunk-MASLG557.js +26 -0
- package/dist/cli/chunk-MASLG557.js.map +1 -0
- package/dist/cli/{chunk-S5TQXKQ7.js → chunk-NM7V2Y4I.js} +7 -5
- package/dist/cli/chunk-NM7V2Y4I.js.map +1 -0
- package/dist/cli/chunk-RQ7W3NA5.js +143 -0
- package/dist/cli/chunk-RQ7W3NA5.js.map +1 -0
- package/dist/cli/chunk-RWBUHDU7.js +48 -0
- package/dist/cli/chunk-RWBUHDU7.js.map +1 -0
- package/dist/cli/{chunk-GBBG66O6.js → chunk-SHIA2B6G.js} +161 -106
- package/dist/cli/chunk-SHIA2B6G.js.map +1 -0
- package/dist/cli/{chunk-FL4HPCD4.js → chunk-THH7Y3OO.js} +3 -35
- package/dist/cli/chunk-THH7Y3OO.js.map +1 -0
- package/dist/cli/{chunk-XRG5UTIC.js → chunk-U3SEGD4H.js} +127 -19
- package/dist/cli/chunk-U3SEGD4H.js.map +1 -0
- package/dist/cli/{chunk-55AI6CLW.js → chunk-USIXWAXZ.js} +2 -2
- package/dist/cli/chunk-USIXWAXZ.js.map +1 -0
- package/dist/cli/{chunk-APC5BTQM.js → chunk-UV23DWUY.js} +2 -2
- package/dist/cli/{chunk-APC5BTQM.js.map → chunk-UV23DWUY.js.map} +1 -1
- package/dist/cli/config-IBG46HTQ.js +14 -0
- package/dist/cli/{config-ODN4IEMZ.js.map → config-IBG46HTQ.js.map} +1 -1
- package/dist/cli/index.js +373 -82
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-G2D2Z77G.js → mcp-F3EQQWDZ.js} +84 -45
- package/dist/cli/mcp-F3EQQWDZ.js.map +1 -0
- package/dist/cli/payment-providers-FPTGQBU7.js +6 -0
- package/dist/cli/{payment-providers-7RIIZ5OF.js.map → payment-providers-FPTGQBU7.js.map} +1 -1
- package/dist/cli/{provider-ARV3VAQ7.js → provider-XACFJ7MG.js} +145 -23
- package/dist/cli/provider-XACFJ7MG.js.map +1 -0
- package/dist/cli/receipts-AXCPPGOK.js +9 -0
- package/dist/cli/{receipts-HLQ7D722.js.map → receipts-AXCPPGOK.js.map} +1 -1
- package/dist/cli/{run-BHODKC6H.js → run-C3VWMM57.js} +912 -237
- package/dist/cli/run-C3VWMM57.js.map +1 -0
- package/dist/cli/{x402-LHW2YQ6W.js → x402-SUXWULOP.js} +12 -8
- package/dist/cli/x402-SUXWULOP.js.map +1 -0
- package/dist/index.d.ts +108 -41
- package/dist/index.js +1614 -633
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +80 -42
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +3 -2
- package/dist/mpp.js +139 -20
- package/dist/mpp.js.map +1 -1
- package/dist/{protocol-adapter-DdFL5LBU.d.ts → protocol-adapter-D6JH_kk-.d.ts} +2 -2
- package/dist/{runtime-BmaSp2Ce.d.ts → runtime-D8u6lYfx.d.ts} +10 -0
- package/dist/{store-DQwbKhnc.d.ts → store-04pazhFP.d.ts} +54 -3
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +469 -274
- package/dist/testing.js.map +1 -1
- package/dist/{transaction-BXXJltZ-.d.ts → transaction-F9ZvhokH.d.ts} +1 -1
- package/dist/types-Dl27vhEc.d.ts +167 -0
- package/dist/x402.d.ts +7 -110
- package/dist/x402.js +6 -5
- package/dist/x402.js.map +1 -1
- package/package.json +3 -1
- package/dist/chunk-2573DASO.js +0 -8
- package/dist/chunk-2573DASO.js.map +0 -1
- package/dist/chunk-5AO5N2XY.js.map +0 -1
- package/dist/chunk-77HLISG4.js.map +0 -1
- package/dist/chunk-WDD2ZUR3.js.map +0 -1
- package/dist/chunk-XXHC6AA3.js.map +0 -1
- package/dist/chunk-YHNTTMED.js.map +0 -1
- package/dist/cli/ap2-O3HJSS2E.js.map +0 -1
- package/dist/cli/chunk-3NVJAQRO.js +0 -119
- package/dist/cli/chunk-3NVJAQRO.js.map +0 -1
- package/dist/cli/chunk-55AI6CLW.js.map +0 -1
- package/dist/cli/chunk-66NTYSXI.js +0 -277
- package/dist/cli/chunk-66NTYSXI.js.map +0 -1
- package/dist/cli/chunk-B4QJV7OC.js +0 -8
- package/dist/cli/chunk-DKWO6LLX.js.map +0 -1
- package/dist/cli/chunk-FETTSOMT.js.map +0 -1
- package/dist/cli/chunk-FL4HPCD4.js.map +0 -1
- package/dist/cli/chunk-GBBG66O6.js.map +0 -1
- package/dist/cli/chunk-H7EBJ4I3.js +0 -53
- package/dist/cli/chunk-H7EBJ4I3.js.map +0 -1
- package/dist/cli/chunk-OETKXDGA.js.map +0 -1
- package/dist/cli/chunk-QUFFT5K3.js.map +0 -1
- package/dist/cli/chunk-S5TQXKQ7.js.map +0 -1
- package/dist/cli/chunk-TPC4EJLT.js +0 -11
- package/dist/cli/chunk-TPC4EJLT.js.map +0 -1
- package/dist/cli/chunk-XRG5UTIC.js.map +0 -1
- package/dist/cli/config-ODN4IEMZ.js +0 -13
- package/dist/cli/mcp-G2D2Z77G.js.map +0 -1
- package/dist/cli/payment-providers-7RIIZ5OF.js +0 -6
- package/dist/cli/provider-ARV3VAQ7.js.map +0 -1
- package/dist/cli/receipts-HLQ7D722.js +0 -9
- package/dist/cli/run-BHODKC6H.js.map +0 -1
- package/dist/cli/x402-LHW2YQ6W.js.map +0 -1
- package/dist/networks-DDHYJLcg.d.ts +0 -39
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { openSqliteDatabase, AP2_SPEC_VERSION, AP2_MODES, AP2_DEFAULT_CLOCK_SKEW_SECONDS, AP2_JWK_MEMBERS, AP2_KEY_TYPE, AP2_SIGNING_ALGORITHM, AP2_JWK_CURVE, AP2_JWK_COORDINATE_BYTES, AP2_MAX_CLOCK_SKEW_SECONDS } from './chunk-
|
|
2
|
-
import { readCappedBody, createBearerCheck, MCP_TOOL_NAME_PATTERN, settlementResponse, joinUrl, settlementResponseFromDetails, settlementFailure, x402ErrorCode, x402RefusalStatus } from './chunk-
|
|
1
|
+
import { openSqliteDatabase, AP2_SPEC_VERSION, AP2_MODES, AP2_DEFAULT_CLOCK_SKEW_SECONDS, AP2_JWK_MEMBERS, AP2_KEY_TYPE, AP2_SIGNING_ALGORITHM, AP2_JWK_CURVE, AP2_JWK_COORDINATE_BYTES, AP2_MAX_CLOCK_SKEW_SECONDS } from './chunk-RXYGC7A3.js';
|
|
2
|
+
import { readCappedBody, createBearerCheck, MCP_TOOL_NAME_PATTERN, publicEndpointUrl, settlementResponse, joinUrl, settlementResponseFromDetails, settlementFailure, x402ErrorCode, x402RefusalStatus } from './chunk-2PVRHMVT.js';
|
|
3
3
|
import { MPP_DEFAULT_NETWORK, isMppNetwork, MPP_NETWORKS, MPP_DEFAULT_PAYMENT_FLOW, MPP_MIN_CHALLENGE_SECRET_LENGTH, MPP_PROFILE } from './chunk-6Z2H53CG.js';
|
|
4
4
|
import { contentDigest, CONTENT_DIGEST_METADATA_KEY, mppProblem, mppProblemDetail } from './chunk-D7FPSGUQ.js';
|
|
5
|
-
import { X402_PAYMENT_FLOWS, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, resolveX402Deployment, resolveDeploymentMode, requireX402Network, resolveX402Option, isEvmAddress, isEvmZeroAddress, SETTLE_AFTER_BACKEND_METADATA_KEY, x402OfferName, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, canonicalJson } from './chunk-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
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
|
+
import { exampleObject } from './chunk-MNI6APE6.js';
|
|
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
|
+
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
|
+
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';
|
|
11
12
|
import { isRecord } from './chunk-2CJNA7MS.js';
|
|
12
13
|
import { promises, accessSync, constants, existsSync } from 'fs';
|
|
13
14
|
import * as path from 'path';
|
|
@@ -15,7 +16,6 @@ import { resolve } from 'path';
|
|
|
15
16
|
import { parse, YAMLError } from 'yaml';
|
|
16
17
|
import { z } from 'zod';
|
|
17
18
|
import { randomUUID, createHash } from 'crypto';
|
|
18
|
-
import { isDeepStrictEqual } from 'util';
|
|
19
19
|
import Fastify from 'fastify';
|
|
20
20
|
import { createRequire } from 'module';
|
|
21
21
|
import pino from 'pino';
|
|
@@ -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";
|
|
@@ -831,6 +867,43 @@ function normalizeMpp(raw) {
|
|
|
831
867
|
});
|
|
832
868
|
return mpp;
|
|
833
869
|
}
|
|
870
|
+
var SERVER_NAME = /^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]\/[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]$/;
|
|
871
|
+
var re2 = (source) => new RegExp(source.replaceAll(String.raw`\s`, String.raw`[\t\n\f\r ]`));
|
|
872
|
+
var RANGES = [
|
|
873
|
+
// `comparatorRangeRe`, `hyphenRangeRe`, `orRangeRe`
|
|
874
|
+
String.raw`^\s*(?:\^|~|>=|<=|>|<|=)\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*$`,
|
|
875
|
+
String.raw`^\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s-\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*$`,
|
|
876
|
+
String.raw`^\s*(?:v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*)(?:\|\|\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*)+$`
|
|
877
|
+
].map(re2);
|
|
878
|
+
var DOTTED_VERSION_LIKE = re2(
|
|
879
|
+
String.raw`^\s*(?:v?\d+|x|X|\*)(?:\.(?:\d+|x|X|\*)){1,2}(?:-[0-9A-Za-z.-]+)?\s*$`
|
|
880
|
+
);
|
|
881
|
+
function looksLikeVersionRange(version) {
|
|
882
|
+
const trimmed = version.replace(new RegExp("^\\p{White_Space}+|\\p{White_Space}+$", "gu"), "");
|
|
883
|
+
if (trimmed === "") return false;
|
|
884
|
+
if (RANGES.some((range) => range.test(trimmed))) return true;
|
|
885
|
+
return DOTTED_VERSION_LIKE.test(trimmed) && /[xX*]/.test(trimmed);
|
|
886
|
+
}
|
|
887
|
+
var codePoints = (min, max) => z.string().refine(
|
|
888
|
+
(value) => {
|
|
889
|
+
const length = [...value].length;
|
|
890
|
+
return length >= min && length <= max;
|
|
891
|
+
},
|
|
892
|
+
{ message: `must be ${min} to ${max} characters` }
|
|
893
|
+
);
|
|
894
|
+
var McpRegistrySchema = z.object({
|
|
895
|
+
name: z.string().max(200).regex(SERVER_NAME, {
|
|
896
|
+
message: 'must be a namespace and a name joined by one "/", such as io.github.acme/weather. Each side has at least 2 characters and starts and ends with a letter or digit; the namespace may also hold "." and "-", the name ".", "_" and "-".'
|
|
897
|
+
}),
|
|
898
|
+
version: codePoints(1, 255).refine((value) => value !== "latest", {
|
|
899
|
+
message: 'must not be "latest", which the MCP Registry reserves'
|
|
900
|
+
}).refine((value) => !looksLikeVersionRange(value), {
|
|
901
|
+
message: "must name one version, not a range such as ^1.2.3, 1.x or 1.0 - 2.0. The MCP Registry also reads a dotted version holding x, X or * anywhere, such as 1.0.0-next.1, as a range."
|
|
902
|
+
}),
|
|
903
|
+
description: codePoints(1, 100)
|
|
904
|
+
}).strict();
|
|
905
|
+
|
|
906
|
+
// src/config/schema/raw.ts
|
|
834
907
|
var SUPPORTED_CONFIG_VERSION = 1;
|
|
835
908
|
var NumberOrString = z.union([z.number(), z.string()]);
|
|
836
909
|
var BooleanOrString = z.union([z.boolean(), z.string()]);
|
|
@@ -925,12 +998,19 @@ var ProtocolsSchema = z.object({
|
|
|
925
998
|
http: z.object({ enabled: BooleanOrString }).strict(),
|
|
926
999
|
mcp: z.object({
|
|
927
1000
|
enabled: BooleanOrString,
|
|
928
|
-
mountPath: MountPathSchema
|
|
1001
|
+
mountPath: MountPathSchema,
|
|
1002
|
+
// Experimental metadata for `export mcp-registry` and `doctor --registry`.
|
|
1003
|
+
// Validated at config load; unused by the MCP adapter.
|
|
1004
|
+
registry: McpRegistrySchema.optional()
|
|
929
1005
|
}).strict(),
|
|
930
1006
|
// Optional; A2A is off unless configured
|
|
931
1007
|
a2a: z.object({
|
|
932
1008
|
enabled: BooleanOrString,
|
|
933
|
-
mountPath: MountPathSchema.optional()
|
|
1009
|
+
mountPath: MountPathSchema.optional(),
|
|
1010
|
+
tasks: z.object({
|
|
1011
|
+
retentionHours: NumberOrString.optional(),
|
|
1012
|
+
maxRetained: NumberOrString.optional()
|
|
1013
|
+
}).strict().optional()
|
|
934
1014
|
}).strict().optional(),
|
|
935
1015
|
// Optional and off by default. The business pass requires the sub-blocks
|
|
936
1016
|
// only when ACP is enabled, so a disabled placeholder stays valid and an
|
|
@@ -1055,6 +1135,10 @@ var X402Schema = z.object({
|
|
|
1055
1135
|
allowMainnet: BooleanOrString.optional(),
|
|
1056
1136
|
// Accepts credential-free facilitator access on mainnet. Never defaulted
|
|
1057
1137
|
allowUnauthenticatedFacilitator: BooleanOrString.optional(),
|
|
1138
|
+
// Experimental: use the configured public endpoint in x402 challenges
|
|
1139
|
+
publicResourceUrl: BooleanOrString.optional(),
|
|
1140
|
+
// Experimental Bazaar discovery metadata; enabling it requires publicResourceUrl
|
|
1141
|
+
bazaar: z.object({ enabled: BooleanOrString }).strict().optional(),
|
|
1058
1142
|
// Experimental ERC-8409 quotes; signing a quote transfers no funds
|
|
1059
1143
|
quote: z.object({
|
|
1060
1144
|
enabled: BooleanOrString,
|
|
@@ -1265,7 +1349,7 @@ function createRetryGate(ctx) {
|
|
|
1265
1349
|
);
|
|
1266
1350
|
if (existing?.kind === "in-flight" || existing?.kind === "unresolved") {
|
|
1267
1351
|
if (existing.owner !== ticket.proofDigest) return ticket;
|
|
1268
|
-
throw await
|
|
1352
|
+
throw await refusal2(flow, resource, provider, existing.kind);
|
|
1269
1353
|
}
|
|
1270
1354
|
if (existing?.kind !== "replay") return ticket;
|
|
1271
1355
|
const stored = readStoredDelivery(existing.body);
|
|
@@ -1283,7 +1367,7 @@ function createRetryGate(ctx) {
|
|
|
1283
1367
|
const stored = await storedDelivery(flow, resource, provider, replay);
|
|
1284
1368
|
const samePayer = verification.payer !== void 0 && verification.payer === stored.payer;
|
|
1285
1369
|
if (!samePayer || !authorizes(resource, stored, ticket)) {
|
|
1286
|
-
throw await
|
|
1370
|
+
throw await refusal2(flow, resource, provider, "conflict");
|
|
1287
1371
|
}
|
|
1288
1372
|
return redeliver(flow, resource, provider, replay.status, stored, pipelineStart);
|
|
1289
1373
|
}
|
|
@@ -1316,9 +1400,9 @@ function createRetryGate(ctx) {
|
|
|
1316
1400
|
"response"
|
|
1317
1401
|
);
|
|
1318
1402
|
}
|
|
1319
|
-
async function reading(flow, resource,
|
|
1403
|
+
async function reading(flow, resource, read2) {
|
|
1320
1404
|
try {
|
|
1321
|
-
return await
|
|
1405
|
+
return await read2();
|
|
1322
1406
|
} catch (error) {
|
|
1323
1407
|
throw new CommerceError("STORAGE_ERROR", "Payment retry state could not be read", {
|
|
1324
1408
|
requestId: flow.request.requestId,
|
|
@@ -1330,14 +1414,14 @@ function createRetryGate(ctx) {
|
|
|
1330
1414
|
async function acceptOrRefuse(flow, resource, provider, claimed) {
|
|
1331
1415
|
if (claimed === void 0 || claimed.kind === "reserved") return void 0;
|
|
1332
1416
|
if (claimed.kind === "replay") return claimed;
|
|
1333
|
-
throw await
|
|
1417
|
+
throw await refusal2(flow, resource, provider, claimed.kind);
|
|
1334
1418
|
}
|
|
1335
1419
|
async function storedDelivery(flow, resource, provider, replay) {
|
|
1336
1420
|
const stored = readStoredDelivery(replay.body);
|
|
1337
|
-
if (stored === void 0) throw await
|
|
1421
|
+
if (stored === void 0) throw await refusal2(flow, resource, provider, "unresolved");
|
|
1338
1422
|
return stored;
|
|
1339
1423
|
}
|
|
1340
|
-
function
|
|
1424
|
+
function refusal2(flow, resource, provider, kind) {
|
|
1341
1425
|
const { reason, message } = REFUSALS[kind];
|
|
1342
1426
|
const inFlight = kind === "in-flight";
|
|
1343
1427
|
return rejected(
|
|
@@ -1391,7 +1475,7 @@ function createRetryGate(ctx) {
|
|
|
1391
1475
|
const { request } = flow;
|
|
1392
1476
|
const receipt = await reading(flow, resource, () => options.store.getReceipt(stored.receiptId));
|
|
1393
1477
|
if (receipt?.payment === void 0) {
|
|
1394
|
-
throw await
|
|
1478
|
+
throw await refusal2(flow, resource, provider, "unresolved");
|
|
1395
1479
|
}
|
|
1396
1480
|
const durationMs = Math.round(options.clock.monotonicMs() - pipelineStart);
|
|
1397
1481
|
const original = receipt.transactionId;
|
|
@@ -1447,148 +1531,6 @@ function readStoredDelivery(value) {
|
|
|
1447
1531
|
};
|
|
1448
1532
|
}
|
|
1449
1533
|
|
|
1450
|
-
// src/core/execution/backend-request.ts
|
|
1451
|
-
var NEVER_FORWARDED_HEADER = /^(authorization|cookie|set-cookie|host|content-length|content-type|connection|keep-alive|te|trailer|transfer-encoding|upgrade|idempotency-key|proxy-.*)$/;
|
|
1452
|
-
var PATH_PARAM_PATTERN = /\{([a-zA-Z0-9_.-]+)\}/g;
|
|
1453
|
-
function extractPathParameterNames(url) {
|
|
1454
|
-
return [...url.matchAll(PATH_PARAM_PATTERN)].map((match) => match[1]);
|
|
1455
|
-
}
|
|
1456
|
-
function findUnparsedBraceToken(url) {
|
|
1457
|
-
const residue = url.replace(PATH_PARAM_PATTERN, "");
|
|
1458
|
-
const index = residue.search(/[{}]/);
|
|
1459
|
-
if (index === -1) return void 0;
|
|
1460
|
-
const token = /\{[^{}]*\}?|\}/.exec(residue.slice(index));
|
|
1461
|
-
return token?.[0] ?? residue[index];
|
|
1462
|
-
}
|
|
1463
|
-
function validateBackendRequestShape(handler, input, context, backendHeaders) {
|
|
1464
|
-
const inputRecord = isRecord(input) ? input : {};
|
|
1465
|
-
const parts = buildBackendRequestParts(handler, inputRecord, context);
|
|
1466
|
-
buildHeaders(handler, context, backendHeaders);
|
|
1467
|
-
let target;
|
|
1468
|
-
try {
|
|
1469
|
-
target = new URL(parts.url);
|
|
1470
|
-
} catch {
|
|
1471
|
-
return;
|
|
1472
|
-
}
|
|
1473
|
-
checkQueryCollision(target, parts.query, context);
|
|
1474
|
-
}
|
|
1475
|
-
function acceptsBody(method) {
|
|
1476
|
-
return method !== "GET" && method !== "DELETE";
|
|
1477
|
-
}
|
|
1478
|
-
function buildBackendRequestParts(handler, input, context) {
|
|
1479
|
-
const bindings = handler.inputBindings;
|
|
1480
|
-
if (bindings === void 0) {
|
|
1481
|
-
const { url: url2, remaining } = applyPathTemplate(handler.url, input, context);
|
|
1482
|
-
return acceptsBody(handler.method) ? { url: url2, query: {}, body: { value: remaining } } : { url: url2, query: remaining };
|
|
1483
|
-
}
|
|
1484
|
-
const pathValues = bindings.path === void 0 ? {} : resolveBoundGroup(input, bindings.path, "path", context);
|
|
1485
|
-
const { url } = applyPathTemplate(handler.url, pathValues, context);
|
|
1486
|
-
const query = bindings.query === void 0 ? {} : resolveBoundGroup(input, bindings.query, "query", context);
|
|
1487
|
-
const bodyValue = bindings.body === void 0 ? void 0 : input[bindings.body];
|
|
1488
|
-
if (bodyValue === void 0 || !acceptsBody(handler.method)) return { url, query };
|
|
1489
|
-
return { url, query, body: { value: bodyValue } };
|
|
1490
|
-
}
|
|
1491
|
-
function resolveBoundGroup(input, key, kind, context) {
|
|
1492
|
-
const value = input[key];
|
|
1493
|
-
if (value === void 0) return {};
|
|
1494
|
-
if (!isRecord(value)) {
|
|
1495
|
-
throw new CommerceError(
|
|
1496
|
-
"INPUT_INVALID",
|
|
1497
|
-
`Input "${key}" must be an object of ${kind} parameters`,
|
|
1498
|
-
{ ...context, details: { field: key } }
|
|
1499
|
-
);
|
|
1500
|
-
}
|
|
1501
|
-
return value;
|
|
1502
|
-
}
|
|
1503
|
-
function checkQueryCollision(target, remaining, context) {
|
|
1504
|
-
const templateKeys = new Set(target.searchParams.keys());
|
|
1505
|
-
for (const key of Object.keys(remaining)) {
|
|
1506
|
-
if (templateKeys.has(key)) {
|
|
1507
|
-
throw new CommerceError(
|
|
1508
|
-
"INPUT_INVALID",
|
|
1509
|
-
`Input key "${key}" collides with a query parameter already set on backend.url`,
|
|
1510
|
-
{ requestId: context.requestId, resourceId: context.resourceId, details: { field: key } }
|
|
1511
|
-
);
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
var TRAVERSAL_PATH_VALUES = /* @__PURE__ */ new Set(["", ".", ".."]);
|
|
1516
|
-
function applyPathTemplate(template, input, context) {
|
|
1517
|
-
const remaining = { ...input };
|
|
1518
|
-
let missing;
|
|
1519
|
-
let invalid3;
|
|
1520
|
-
const url = template.replace(PATH_PARAM_PATTERN, (_match, key) => {
|
|
1521
|
-
if (!Object.hasOwn(remaining, key)) {
|
|
1522
|
-
missing = key;
|
|
1523
|
-
return "";
|
|
1524
|
-
}
|
|
1525
|
-
const value = remaining[key];
|
|
1526
|
-
delete remaining[key];
|
|
1527
|
-
const raw = stringifyPrimitive(value);
|
|
1528
|
-
if (TRAVERSAL_PATH_VALUES.has(raw)) {
|
|
1529
|
-
invalid3 = key;
|
|
1530
|
-
return "";
|
|
1531
|
-
}
|
|
1532
|
-
return encodeURIComponent(raw);
|
|
1533
|
-
});
|
|
1534
|
-
if (missing !== void 0) {
|
|
1535
|
-
throw new CommerceError("INPUT_INVALID", `Path parameter "${missing}" was not supplied`, {
|
|
1536
|
-
...context,
|
|
1537
|
-
details: { field: missing }
|
|
1538
|
-
});
|
|
1539
|
-
}
|
|
1540
|
-
if (invalid3 !== void 0) {
|
|
1541
|
-
throw new CommerceError("INPUT_INVALID", `Path parameter "${invalid3}" is not a valid value`, {
|
|
1542
|
-
...context,
|
|
1543
|
-
details: { field: invalid3 }
|
|
1544
|
-
});
|
|
1545
|
-
}
|
|
1546
|
-
return { url, remaining };
|
|
1547
|
-
}
|
|
1548
|
-
function stringifyPrimitive(value) {
|
|
1549
|
-
if (value === void 0 || value === null) return "";
|
|
1550
|
-
if (typeof value === "string") return value;
|
|
1551
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
1552
|
-
try {
|
|
1553
|
-
return JSON.stringify(value);
|
|
1554
|
-
} catch {
|
|
1555
|
-
return String(value);
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
function buildHeaders(handler, context, forwarded = {}) {
|
|
1559
|
-
let headers;
|
|
1560
|
-
try {
|
|
1561
|
-
headers = new Headers(handler.headers);
|
|
1562
|
-
} catch {
|
|
1563
|
-
throw invalidHeaderError(context);
|
|
1564
|
-
}
|
|
1565
|
-
for (const [name, value] of Object.entries(forwarded)) {
|
|
1566
|
-
if (NEVER_FORWARDED_HEADER.test(name.toLowerCase())) continue;
|
|
1567
|
-
try {
|
|
1568
|
-
if (!headers.has(name)) headers.set(name, value);
|
|
1569
|
-
} catch {
|
|
1570
|
-
throw new CommerceError("INPUT_INVALID", "A forwarded request header is invalid", {
|
|
1571
|
-
...context,
|
|
1572
|
-
details: { reason: "invalid-forwarded-header" }
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
return headers;
|
|
1577
|
-
}
|
|
1578
|
-
function setHeader(headers, name, value, context) {
|
|
1579
|
-
try {
|
|
1580
|
-
headers.set(name, value);
|
|
1581
|
-
} catch {
|
|
1582
|
-
throw invalidHeaderError(context);
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
function invalidHeaderError(context) {
|
|
1586
|
-
return new CommerceError("BACKEND_ERROR", "Backend request headers are invalid", {
|
|
1587
|
-
...context,
|
|
1588
|
-
details: { reason: "invalid-header" }
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
1534
|
// src/core/execution/backend-http.ts
|
|
1593
1535
|
var MAX_BODY_SNIPPET_LENGTH = 512;
|
|
1594
1536
|
var IDEMPOTENCY_KEY_HEADER = "idempotency-key";
|
|
@@ -1793,130 +1735,6 @@ function safeStringify(value) {
|
|
|
1793
1735
|
function isAbortError(error) {
|
|
1794
1736
|
return error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError");
|
|
1795
1737
|
}
|
|
1796
|
-
var SUPPORTED_TYPES = /* @__PURE__ */ new Set([
|
|
1797
|
-
"object",
|
|
1798
|
-
"string",
|
|
1799
|
-
"number",
|
|
1800
|
-
"integer",
|
|
1801
|
-
"boolean",
|
|
1802
|
-
"array",
|
|
1803
|
-
"null"
|
|
1804
|
-
]);
|
|
1805
|
-
function compileJsonSchema(schema) {
|
|
1806
|
-
return (input) => {
|
|
1807
|
-
if (schema === void 0) return { valid: true, value: input };
|
|
1808
|
-
const errors = validateNode(schema, input, "$");
|
|
1809
|
-
return errors.length === 0 ? { valid: true, value: input } : { valid: false, errors };
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1812
|
-
function matchesType(type, value) {
|
|
1813
|
-
switch (type) {
|
|
1814
|
-
case "object":
|
|
1815
|
-
return isRecord(value);
|
|
1816
|
-
case "array":
|
|
1817
|
-
return Array.isArray(value);
|
|
1818
|
-
case "string":
|
|
1819
|
-
return typeof value === "string";
|
|
1820
|
-
case "boolean":
|
|
1821
|
-
return typeof value === "boolean";
|
|
1822
|
-
case "number":
|
|
1823
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
1824
|
-
case "integer":
|
|
1825
|
-
return typeof value === "number" && Number.isInteger(value);
|
|
1826
|
-
case "null":
|
|
1827
|
-
return value === null;
|
|
1828
|
-
default:
|
|
1829
|
-
return true;
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
function describeType(value) {
|
|
1833
|
-
if (value === null) return "null";
|
|
1834
|
-
if (Array.isArray(value)) return "array";
|
|
1835
|
-
return typeof value;
|
|
1836
|
-
}
|
|
1837
|
-
function deepEqual(a, b) {
|
|
1838
|
-
return a === b || isDeepStrictEqual(a, b);
|
|
1839
|
-
}
|
|
1840
|
-
function own(obj, key) {
|
|
1841
|
-
return Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
1842
|
-
}
|
|
1843
|
-
function typeList(raw) {
|
|
1844
|
-
if (typeof raw === "string") return [raw];
|
|
1845
|
-
if (Array.isArray(raw) && raw.every((entry) => typeof entry === "string")) {
|
|
1846
|
-
return raw;
|
|
1847
|
-
}
|
|
1848
|
-
return void 0;
|
|
1849
|
-
}
|
|
1850
|
-
function isObjectSchemaNode(schema) {
|
|
1851
|
-
const types = typeList(schema["type"]);
|
|
1852
|
-
if (types !== void 0) return types.includes("object");
|
|
1853
|
-
return Object.hasOwn(schema, "properties") || Object.hasOwn(schema, "required");
|
|
1854
|
-
}
|
|
1855
|
-
function validateNode(schema, value, path2) {
|
|
1856
|
-
const errors = [];
|
|
1857
|
-
const types = typeList(own(schema, "type"));
|
|
1858
|
-
const recognizedTypes = types?.filter((entry) => SUPPORTED_TYPES.has(entry));
|
|
1859
|
-
if (types !== void 0 && recognizedTypes !== void 0 && recognizedTypes.length === types.length && types.length > 0) {
|
|
1860
|
-
if (!types.some((entry) => matchesType(entry, value))) {
|
|
1861
|
-
errors.push({
|
|
1862
|
-
path: path2,
|
|
1863
|
-
message: `expected type "${types.join(" | ")}" but got ${describeType(value)}`
|
|
1864
|
-
});
|
|
1865
|
-
return errors;
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
const enumRaw = own(schema, "enum");
|
|
1869
|
-
if (Array.isArray(enumRaw)) {
|
|
1870
|
-
const allowed = enumRaw;
|
|
1871
|
-
if (!allowed.some((candidate) => deepEqual(candidate, value))) {
|
|
1872
|
-
errors.push({ path: path2, message: `must be one of ${JSON.stringify(allowed)}` });
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
if (isObjectSchemaNode(schema) && isRecord(value)) {
|
|
1876
|
-
errors.push(...validateObject(schema, value, path2));
|
|
1877
|
-
} else if ((types?.includes("array") ?? false) && Array.isArray(value)) {
|
|
1878
|
-
errors.push(...validateArray(schema, value, path2));
|
|
1879
|
-
}
|
|
1880
|
-
return errors;
|
|
1881
|
-
}
|
|
1882
|
-
function validateObject(schema, value, path2) {
|
|
1883
|
-
const errors = [];
|
|
1884
|
-
const propsRaw = own(schema, "properties");
|
|
1885
|
-
const properties = isRecord(propsRaw) ? propsRaw : {};
|
|
1886
|
-
const requiredRaw = own(schema, "required");
|
|
1887
|
-
const required = Array.isArray(requiredRaw) ? requiredRaw.filter((entry) => typeof entry === "string") : [];
|
|
1888
|
-
for (const key of required) {
|
|
1889
|
-
if (!Object.hasOwn(value, key)) {
|
|
1890
|
-
errors.push({ path: `${path2}.${key}`, message: "is required" });
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
const additional = own(schema, "additionalProperties");
|
|
1894
|
-
for (const key of Object.keys(value)) {
|
|
1895
|
-
const propSchemaRaw = own(properties, key);
|
|
1896
|
-
if (propSchemaRaw !== void 0) {
|
|
1897
|
-
if (isRecord(propSchemaRaw)) {
|
|
1898
|
-
errors.push(...validateNode(propSchemaRaw, value[key], `${path2}.${key}`));
|
|
1899
|
-
}
|
|
1900
|
-
continue;
|
|
1901
|
-
}
|
|
1902
|
-
if (additional === false) {
|
|
1903
|
-
errors.push({ path: `${path2}.${key}`, message: "additional property not allowed" });
|
|
1904
|
-
} else if (isRecord(additional)) {
|
|
1905
|
-
errors.push(...validateNode(additional, value[key], `${path2}.${key}`));
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
return errors;
|
|
1909
|
-
}
|
|
1910
|
-
function validateArray(schema, value, path2) {
|
|
1911
|
-
const errors = [];
|
|
1912
|
-
const itemsRaw = own(schema, "items");
|
|
1913
|
-
if (isRecord(itemsRaw)) {
|
|
1914
|
-
value.forEach((item, index) => {
|
|
1915
|
-
errors.push(...validateNode(itemsRaw, item, `${path2}[${index}]`));
|
|
1916
|
-
});
|
|
1917
|
-
}
|
|
1918
|
-
return errors;
|
|
1919
|
-
}
|
|
1920
1738
|
|
|
1921
1739
|
// src/core/execution/pipeline/authorization.ts
|
|
1922
1740
|
function resolveAuthorizationProviders(providers, resource, requestId) {
|
|
@@ -2101,6 +1919,7 @@ function createPaymentAdmission(ctx, authorizeAndReserve, retryGate) {
|
|
|
2101
1919
|
currency: pricing.currency,
|
|
2102
1920
|
requestedAt: options.clock.nowIso(),
|
|
2103
1921
|
input: validInput,
|
|
1922
|
+
protocol: request.protocol,
|
|
2104
1923
|
// Transport facts a rail may bind into its challenge, such as a body digest
|
|
2105
1924
|
...request.metadata !== void 0 ? { metadata: request.metadata } : {}
|
|
2106
1925
|
});
|
|
@@ -2166,7 +1985,7 @@ function createPaymentAdmission(ctx, authorizeAndReserve, retryGate) {
|
|
|
2166
1985
|
throw mapped;
|
|
2167
1986
|
}
|
|
2168
1987
|
if (verification.status !== "verified") {
|
|
2169
|
-
const
|
|
1988
|
+
const refusal2 = await refusalFor(verification, requirement, request, resource);
|
|
2170
1989
|
await safeEmit(
|
|
2171
1990
|
buildEvent(flow, {
|
|
2172
1991
|
type: "payment.rejected",
|
|
@@ -2174,10 +1993,10 @@ function createPaymentAdmission(ctx, authorizeAndReserve, retryGate) {
|
|
|
2174
1993
|
adapter: request.protocol,
|
|
2175
1994
|
paymentProvider: provider.name,
|
|
2176
1995
|
status: "error",
|
|
2177
|
-
data:
|
|
1996
|
+
data: refusal2.code !== "PAYMENT_INVALID" ? { reason: refusal2.code } : verification.rejectionReason ? { reason: verification.rejectionReason } : {}
|
|
2178
1997
|
})
|
|
2179
1998
|
);
|
|
2180
|
-
throw
|
|
1999
|
+
throw refusal2;
|
|
2181
2000
|
}
|
|
2182
2001
|
if (!verification.replayKey) {
|
|
2183
2002
|
await safeEmit(
|
|
@@ -3129,27 +2948,6 @@ var EMPTY_CLOSED_OBJECT_SCHEMA = {
|
|
|
3129
2948
|
properties: {},
|
|
3130
2949
|
additionalProperties: false
|
|
3131
2950
|
};
|
|
3132
|
-
var UNSUPPORTED_SCHEMA_KEYWORDS = [
|
|
3133
|
-
"pattern",
|
|
3134
|
-
"minLength",
|
|
3135
|
-
"maxLength",
|
|
3136
|
-
"format",
|
|
3137
|
-
"minimum",
|
|
3138
|
-
"maximum",
|
|
3139
|
-
"exclusiveMinimum",
|
|
3140
|
-
"exclusiveMaximum",
|
|
3141
|
-
"multipleOf",
|
|
3142
|
-
"oneOf",
|
|
3143
|
-
"anyOf",
|
|
3144
|
-
"allOf",
|
|
3145
|
-
"not",
|
|
3146
|
-
"$ref",
|
|
3147
|
-
"const",
|
|
3148
|
-
"patternProperties",
|
|
3149
|
-
"minItems",
|
|
3150
|
-
"maxItems",
|
|
3151
|
-
"uniqueItems"
|
|
3152
|
-
];
|
|
3153
2951
|
function excludesObjectType(schema) {
|
|
3154
2952
|
const type = schema["type"];
|
|
3155
2953
|
if (type === void 0 || type === "object") return false;
|
|
@@ -3157,8 +2955,8 @@ function excludesObjectType(schema) {
|
|
|
3157
2955
|
return true;
|
|
3158
2956
|
}
|
|
3159
2957
|
function validateResourceSchemaKeywords(id, path2, schema) {
|
|
3160
|
-
for (const keyword of
|
|
3161
|
-
if (
|
|
2958
|
+
for (const keyword of Object.keys(schema)) {
|
|
2959
|
+
if (!ENFORCED_SCHEMA_KEYWORDS.has(keyword)) {
|
|
3162
2960
|
console.warn(
|
|
3163
2961
|
`[agent-commerce] resource "${id}" ${path2} uses JSON Schema keyword "${keyword}", which this gateway does not enforce (see src/core/execution/validation.ts for the supported subset). Remove it or treat it as documentation only.`
|
|
3164
2962
|
);
|
|
@@ -3372,9 +3170,10 @@ function normalizeResource(id, entry, protocols, x402, mpp, ap2) {
|
|
|
3372
3170
|
{ details: { path: `resources.${id}.mimeType`, resourceId: id } }
|
|
3373
3171
|
);
|
|
3374
3172
|
}
|
|
3375
|
-
const servingRail = paymentMethods
|
|
3376
|
-
|
|
3377
|
-
|
|
3173
|
+
const servingRail = servingRailOf(paymentMethods, {
|
|
3174
|
+
x402: x402?.config.enabled === true,
|
|
3175
|
+
mpp: mpp?.enabled === true
|
|
3176
|
+
});
|
|
3378
3177
|
const idempotency = normalizeResourceIdempotency(id, entry, paymentMethods, servingRail);
|
|
3379
3178
|
const pricing = entry.pricing.type === "free" ? { type: "free" } : { type: "fixed", amount: entry.pricing.amount, currency: entry.pricing.currency };
|
|
3380
3179
|
const authorization = normalizeResourceAuthorization(id, entry, pricing, ap2);
|
|
@@ -3403,6 +3202,11 @@ function normalizeResource(id, entry, protocols, x402, mpp, ap2) {
|
|
|
3403
3202
|
...idempotency !== void 0 ? { idempotency } : {}
|
|
3404
3203
|
};
|
|
3405
3204
|
}
|
|
3205
|
+
function servingRailOf(paymentMethods, enabled) {
|
|
3206
|
+
return paymentMethods.find(
|
|
3207
|
+
(method) => method === "x402" && enabled.x402 || method === "mpp" && enabled.mpp
|
|
3208
|
+
);
|
|
3209
|
+
}
|
|
3406
3210
|
function normalizeResourceIdempotency(id, entry, paymentMethods, servingRail) {
|
|
3407
3211
|
const raw = entry.idempotency;
|
|
3408
3212
|
if (raw === void 0) return void 0;
|
|
@@ -3479,16 +3283,39 @@ function pickDefined(value) {
|
|
|
3479
3283
|
|
|
3480
3284
|
// src/config/schema/normalize.ts
|
|
3481
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
|
+
}
|
|
3482
3307
|
function normalize(raw) {
|
|
3483
3308
|
const protocols = {
|
|
3484
3309
|
http: { enabled: toBoolean(raw.protocols.http.enabled, "protocols.http.enabled") },
|
|
3485
3310
|
mcp: {
|
|
3486
3311
|
enabled: toBoolean(raw.protocols.mcp.enabled, "protocols.mcp.enabled"),
|
|
3487
|
-
mountPath: raw.protocols.mcp.mountPath
|
|
3312
|
+
mountPath: raw.protocols.mcp.mountPath,
|
|
3313
|
+
...raw.protocols.mcp.registry !== void 0 ? { registry: raw.protocols.mcp.registry } : {}
|
|
3488
3314
|
},
|
|
3489
3315
|
a2a: {
|
|
3490
3316
|
enabled: toBoolean(raw.protocols.a2a?.enabled ?? false, "protocols.a2a.enabled"),
|
|
3491
|
-
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)
|
|
3492
3319
|
},
|
|
3493
3320
|
acp: normalizeAcp(raw.protocols.acp)
|
|
3494
3321
|
};
|
|
@@ -3516,10 +3343,19 @@ function normalize(raw) {
|
|
|
3516
3343
|
return mimeType !== void 0 ? [[resource.id, mimeType]] : [];
|
|
3517
3344
|
})
|
|
3518
3345
|
);
|
|
3346
|
+
const rails = { x402: x402?.enabled === true, mpp: mpp?.enabled === true };
|
|
3347
|
+
const railOf = (resource) => servingRailOf(resource.paymentMethods, rails);
|
|
3348
|
+
const onX402 = resources.filter((resource) => railOf(resource) === "x402");
|
|
3349
|
+
const publicUrl = raw.payments.x402?.publicResourceUrl;
|
|
3350
|
+
const resourceUrls = publicUrl !== void 0 && toBoolean(publicUrl, "payments.x402.publicResourceUrl") ? publicResourceUrls(raw.merchant.publicBaseUrl, protocols, onX402) : void 0;
|
|
3351
|
+
const bazaarRaw = raw.payments.x402?.bazaar;
|
|
3352
|
+
const resourceBazaar = bazaarRaw !== void 0 && toBoolean(bazaarRaw.enabled, "payments.x402.bazaar.enabled") ? bazaarExtensions(resourceUrls, resources, mimeTypes, railOf) : void 0;
|
|
3519
3353
|
const x402WithFlows = x402 !== void 0 ? {
|
|
3520
3354
|
...x402,
|
|
3521
3355
|
...flowOverrides2("x402"),
|
|
3522
|
-
...Object.keys(mimeTypes).length > 0 ? { resourceMimeTypes: mimeTypes } : {}
|
|
3356
|
+
...Object.keys(mimeTypes).length > 0 ? { resourceMimeTypes: mimeTypes } : {},
|
|
3357
|
+
...resourceUrls !== void 0 ? { resourceUrls } : {},
|
|
3358
|
+
...resourceBazaar !== void 0 ? { resourceBazaar } : {}
|
|
3523
3359
|
} : x402;
|
|
3524
3360
|
const mppWithFlows = mpp !== void 0 ? { ...mpp, ...flowOverrides2("mpp") } : mpp;
|
|
3525
3361
|
if (protocols.acp.enabled) validateAcpCheckoutMapping(protocols.acp, resources);
|
|
@@ -3559,6 +3395,58 @@ function normalize(raw) {
|
|
|
3559
3395
|
...ap2 !== void 0 ? { authorization: { ap2 } } : {}
|
|
3560
3396
|
};
|
|
3561
3397
|
}
|
|
3398
|
+
function bazaarExtensions(resourceUrls, resources, mimeTypes, railOf) {
|
|
3399
|
+
if (resourceUrls === void 0) {
|
|
3400
|
+
throw new CommerceError(
|
|
3401
|
+
"CONFIG_INVALID",
|
|
3402
|
+
"payments.x402.bazaar.enabled requires payments.x402.publicResourceUrl: true",
|
|
3403
|
+
{ details: { path: "payments.x402.bazaar.enabled" } }
|
|
3404
|
+
);
|
|
3405
|
+
}
|
|
3406
|
+
return Object.fromEntries(
|
|
3407
|
+
resources.flatMap((resource) => {
|
|
3408
|
+
const urls = resourceUrls[resource.id];
|
|
3409
|
+
if (urls === void 0) {
|
|
3410
|
+
const rail = railOf(resource);
|
|
3411
|
+
if (resource.paymentMethods.includes("x402") && rail !== void 0) {
|
|
3412
|
+
console.warn(
|
|
3413
|
+
`[agent-commerce] resource "${resource.id}" gets no Bazaar metadata: the gateway serves it on ${rail}, the first enabled rail in its payments, which issues no x402 challenge. Payment is unaffected.`
|
|
3414
|
+
);
|
|
3415
|
+
}
|
|
3416
|
+
return [];
|
|
3417
|
+
}
|
|
3418
|
+
const surfaces = ["http", "mcp"].filter((surface) => urls[surface] !== void 0);
|
|
3419
|
+
const { extensions, omitted } = bazaarMetadata(resource, surfaces, mimeTypes[resource.id]);
|
|
3420
|
+
for (const { surfaces: left, reason } of omitted) {
|
|
3421
|
+
console.warn(
|
|
3422
|
+
`[agent-commerce] resource "${resource.id}" gets no Bazaar metadata on ${left.join(" and ")}: ${reason}. Payment is unaffected.`
|
|
3423
|
+
);
|
|
3424
|
+
}
|
|
3425
|
+
return Object.keys(extensions).length > 0 ? [[resource.id, extensions]] : [];
|
|
3426
|
+
})
|
|
3427
|
+
);
|
|
3428
|
+
}
|
|
3429
|
+
function publicResourceUrls(publicBaseUrl, protocols, resources) {
|
|
3430
|
+
if (!isHttpUrl(publicBaseUrl)) {
|
|
3431
|
+
throw new CommerceError(
|
|
3432
|
+
"CONFIG_INVALID",
|
|
3433
|
+
`payments.x402.publicResourceUrl needs merchant.publicBaseUrl to be an http:// or https:// URL, not ${JSON.stringify(publicBaseUrl)}`,
|
|
3434
|
+
{ details: { path: "merchant.publicBaseUrl" } }
|
|
3435
|
+
);
|
|
3436
|
+
}
|
|
3437
|
+
const path2 = (surface, id) => surface === "http" ? `/api/resources/${encodeURIComponent(id)}/invoke` : protocols[surface].mountPath;
|
|
3438
|
+
return Object.fromEntries(
|
|
3439
|
+
resources.map((resource) => [
|
|
3440
|
+
resource.id,
|
|
3441
|
+
Object.fromEntries(
|
|
3442
|
+
["http", "mcp", "a2a"].filter((surface) => resource.exposedVia.includes(surface)).map((surface) => [
|
|
3443
|
+
surface,
|
|
3444
|
+
publicEndpointUrl(publicBaseUrl, path2(surface, resource.id))
|
|
3445
|
+
])
|
|
3446
|
+
)
|
|
3447
|
+
])
|
|
3448
|
+
);
|
|
3449
|
+
}
|
|
3562
3450
|
function validateMountPaths(protocols) {
|
|
3563
3451
|
const mounts = [
|
|
3564
3452
|
["mcp", protocols.mcp],
|
|
@@ -3633,6 +3521,9 @@ function describeIssue(issue) {
|
|
|
3633
3521
|
// src/config/load.ts
|
|
3634
3522
|
var CONFIG_PATH_ENV_VAR = "AGENT_COMMERCE_CONFIG";
|
|
3635
3523
|
async function loadConfig(options = {}) {
|
|
3524
|
+
return parseConfig(await readConfigFile(options), options.env ?? process.env);
|
|
3525
|
+
}
|
|
3526
|
+
async function readConfigFile(options = {}) {
|
|
3636
3527
|
const env = options.env ?? process.env;
|
|
3637
3528
|
const cwd = options.cwd ?? process.cwd();
|
|
3638
3529
|
const configPath = resolveConfigPath(options.path, env, cwd);
|
|
@@ -3645,9 +3536,8 @@ async function loadConfig(options = {}) {
|
|
|
3645
3536
|
cause: error
|
|
3646
3537
|
});
|
|
3647
3538
|
}
|
|
3648
|
-
let raw;
|
|
3649
3539
|
try {
|
|
3650
|
-
|
|
3540
|
+
return parse(text);
|
|
3651
3541
|
} catch (error) {
|
|
3652
3542
|
const { reason, details } = describeYamlError(error);
|
|
3653
3543
|
throw new CommerceError(
|
|
@@ -3661,7 +3551,6 @@ async function loadConfig(options = {}) {
|
|
|
3661
3551
|
}
|
|
3662
3552
|
);
|
|
3663
3553
|
}
|
|
3664
|
-
return parseConfig(raw, env);
|
|
3665
3554
|
}
|
|
3666
3555
|
var YAML_ERROR_EXPLANATIONS = {
|
|
3667
3556
|
DUPLICATE_KEY: "map keys must be unique",
|
|
@@ -3709,6 +3598,7 @@ var CORS_HEADERS = [
|
|
|
3709
3598
|
"mcp-name",
|
|
3710
3599
|
"a2a-version",
|
|
3711
3600
|
"a2a-extensions",
|
|
3601
|
+
"x-a2a-extensions",
|
|
3712
3602
|
"api-version",
|
|
3713
3603
|
"idempotency-key",
|
|
3714
3604
|
"request-id",
|
|
@@ -3724,7 +3614,9 @@ var CORS_EXPOSED_HEADERS = [
|
|
|
3724
3614
|
"idempotency-key",
|
|
3725
3615
|
"request-id",
|
|
3726
3616
|
"idempotent-replayed",
|
|
3727
|
-
"retry-after"
|
|
3617
|
+
"retry-after",
|
|
3618
|
+
"a2a-extensions",
|
|
3619
|
+
"x-a2a-extensions"
|
|
3728
3620
|
].join(",");
|
|
3729
3621
|
function buildAccessControlHook(options) {
|
|
3730
3622
|
const allowedOrigins = new Set(options.allowedOrigins.map((origin) => origin.toLowerCase()));
|
|
@@ -4112,10 +4004,10 @@ async function resolveManually(options) {
|
|
|
4112
4004
|
if (attempt === void 0) {
|
|
4113
4005
|
throw new CommerceError("RESOURCE_NOT_FOUND", `Payment attempt "${attemptId}" was not found`);
|
|
4114
4006
|
}
|
|
4115
|
-
const refuse = (
|
|
4007
|
+
const refuse = (refusal2, current2 = attempt) => ({
|
|
4116
4008
|
resolved: false,
|
|
4117
|
-
refusal,
|
|
4118
|
-
message: REFUSAL_MESSAGES[
|
|
4009
|
+
refusal: refusal2,
|
|
4010
|
+
message: REFUSAL_MESSAGES[refusal2],
|
|
4119
4011
|
attempt: current2
|
|
4120
4012
|
});
|
|
4121
4013
|
if (attempt.resolution !== void 0) return refuse("already_resolved");
|
|
@@ -4390,6 +4282,7 @@ function createReadinessProbe(options, ttlMs = READINESS_TTL_MS) {
|
|
|
4390
4282
|
|
|
4391
4283
|
// src/gateway/well-known.ts
|
|
4392
4284
|
var GATEWAY_SUPPORTED_SPEC = "agent-commerce/v1.0.0";
|
|
4285
|
+
var QUOTE_STATUS = featureStatus(x402_default, "erc-8409-quotes");
|
|
4393
4286
|
function publicHealth(health) {
|
|
4394
4287
|
const { detail: _detail, ...rest } = health;
|
|
4395
4288
|
return rest;
|
|
@@ -4402,9 +4295,15 @@ function publicProtocols(protocols) {
|
|
|
4402
4295
|
acp: { enabled: protocols.acp.enabled, mountPath: protocols.acp.mountPath }
|
|
4403
4296
|
};
|
|
4404
4297
|
}
|
|
4405
|
-
function
|
|
4298
|
+
function offerHealth(health, offer) {
|
|
4299
|
+
const name = x402OfferName(offer);
|
|
4300
|
+
const component = health?.components?.find((candidate) => candidate.name === name);
|
|
4301
|
+
if (component === void 0) return {};
|
|
4302
|
+
const { status, undetermined } = component;
|
|
4303
|
+
return { status, ...undetermined !== void 0 ? { undetermined } : {} };
|
|
4304
|
+
}
|
|
4305
|
+
function publicOffer(option, health) {
|
|
4406
4306
|
const { network, asset, assetName, assetVersion, assetDecimals, payTo, assetTransferMethod } = option;
|
|
4407
|
-
const status = statuses.get(x402OfferName(option));
|
|
4408
4307
|
return {
|
|
4409
4308
|
network,
|
|
4410
4309
|
asset,
|
|
@@ -4413,7 +4312,7 @@ function publicOffer(option, statuses) {
|
|
|
4413
4312
|
assetDecimals,
|
|
4414
4313
|
payTo,
|
|
4415
4314
|
...assetTransferMethod !== void 0 ? { assetTransferMethod } : {},
|
|
4416
|
-
...
|
|
4315
|
+
...offerHealth(health, option)
|
|
4417
4316
|
};
|
|
4418
4317
|
}
|
|
4419
4318
|
function flowOverrides(flows) {
|
|
@@ -4423,7 +4322,7 @@ function publicQuote(providers) {
|
|
|
4423
4322
|
const x402 = providers.find((provider) => provider.name === "x402");
|
|
4424
4323
|
if (x402?.quote === void 0) return void 0;
|
|
4425
4324
|
const { issuer, requestScheme, extension } = x402.quote;
|
|
4426
|
-
return { issuer, requestScheme, extension, status:
|
|
4325
|
+
return { issuer, requestScheme, extension, status: QUOTE_STATUS };
|
|
4427
4326
|
}
|
|
4428
4327
|
function buildWellKnownDocument(options) {
|
|
4429
4328
|
const adapters = options.adapters.map(({ descriptor, health }) => ({
|
|
@@ -4431,10 +4330,9 @@ function buildWellKnownDocument(options) {
|
|
|
4431
4330
|
health: publicHealth(health)
|
|
4432
4331
|
}));
|
|
4433
4332
|
const { x402, mpp } = options.config.payments;
|
|
4434
|
-
const
|
|
4435
|
-
const
|
|
4436
|
-
|
|
4437
|
-
);
|
|
4333
|
+
const probed = (name) => options.paymentHealth?.find((provider) => provider.name === name)?.health;
|
|
4334
|
+
const x402Health = probed("x402");
|
|
4335
|
+
const x402Options = x402?.options !== void 0 && x402.options.length > 1 ? x402.options : [];
|
|
4438
4336
|
const quote = publicQuote(options.paymentProviders);
|
|
4439
4337
|
return {
|
|
4440
4338
|
gateway: {
|
|
@@ -4467,12 +4365,12 @@ function buildWellKnownDocument(options) {
|
|
|
4467
4365
|
),
|
|
4468
4366
|
paymentFlow: x402.paymentFlow ?? X402_DEFAULT_PAYMENT_FLOW,
|
|
4469
4367
|
...flowOverrides(x402.resourcePaymentFlows),
|
|
4470
|
-
...
|
|
4368
|
+
...x402Options.length > 0 ? { options: x402Options.map((option) => publicOffer(option, x402Health)) } : offerHealth(x402Health, x402),
|
|
4471
4369
|
...x402.resourceOptions !== void 0 ? {
|
|
4472
4370
|
resourceOptions: Object.fromEntries(
|
|
4473
4371
|
Object.entries(x402.resourceOptions).map(([id, list]) => [
|
|
4474
4372
|
id,
|
|
4475
|
-
list.map((option) => publicOffer(option,
|
|
4373
|
+
list.map((option) => publicOffer(option, x402Health))
|
|
4476
4374
|
])
|
|
4477
4375
|
)
|
|
4478
4376
|
} : {},
|
|
@@ -4491,7 +4389,13 @@ function buildWellKnownDocument(options) {
|
|
|
4491
4389
|
facilitator: { mode: mpp.facilitator.mode },
|
|
4492
4390
|
mode: resolveDeploymentMode(requireX402Network(mpp.network, "payments.mpp.network")),
|
|
4493
4391
|
paymentFlow: mpp.paymentFlow ?? MPP_DEFAULT_PAYMENT_FLOW,
|
|
4494
|
-
...flowOverrides(mpp.resourcePaymentFlows)
|
|
4392
|
+
...flowOverrides(mpp.resourcePaymentFlows),
|
|
4393
|
+
// MPP settles through an x402 provider, which names the offer
|
|
4394
|
+
...offerHealth(probed("mpp"), {
|
|
4395
|
+
network: mpp.network,
|
|
4396
|
+
asset: mpp.asset,
|
|
4397
|
+
payTo: mpp.recipient
|
|
4398
|
+
})
|
|
4495
4399
|
}
|
|
4496
4400
|
} : {}
|
|
4497
4401
|
}
|
|
@@ -5080,37 +4984,6 @@ async function createGateway(options) {
|
|
|
5080
4984
|
};
|
|
5081
4985
|
}
|
|
5082
4986
|
|
|
5083
|
-
// src/protocols/a2a/constants.ts
|
|
5084
|
-
var A2A_SPEC_VERSION = "1.0.1";
|
|
5085
|
-
var A2A_PROTOCOL_VERSION = "1.0";
|
|
5086
|
-
var A2A_PROTOCOL_BINDING = "JSONRPC";
|
|
5087
|
-
var A2A_AGENT_CARD_PATH = "/.well-known/agent-card.json";
|
|
5088
|
-
var A2A_DEFAULT_MOUNT_PATH = "/a2a";
|
|
5089
|
-
var A2A_JSON_MEDIA_TYPE = "application/json";
|
|
5090
|
-
var A2A_DEFAULT_AGENT_NAME = "agent-commerce";
|
|
5091
|
-
var A2A_VERSION_HEADER = "a2a-version";
|
|
5092
|
-
var A2A_METHOD_SEND_MESSAGE = "SendMessage";
|
|
5093
|
-
var A2A_PUSH_CONFIG_METHODS = [
|
|
5094
|
-
"CreateTaskPushNotificationConfig",
|
|
5095
|
-
"GetTaskPushNotificationConfig",
|
|
5096
|
-
"ListTaskPushNotificationConfigs",
|
|
5097
|
-
"DeleteTaskPushNotificationConfig"
|
|
5098
|
-
];
|
|
5099
|
-
var A2A_UNSUPPORTED_METHODS = [
|
|
5100
|
-
"SendStreamingMessage",
|
|
5101
|
-
"GetTask",
|
|
5102
|
-
"ListTasks",
|
|
5103
|
-
"CancelTask",
|
|
5104
|
-
"SubscribeToTask",
|
|
5105
|
-
...A2A_PUSH_CONFIG_METHODS,
|
|
5106
|
-
"GetExtendedAgentCard"
|
|
5107
|
-
];
|
|
5108
|
-
var A2A_TASK_LOOKUP_METHODS = ["GetTask", "CancelTask"];
|
|
5109
|
-
var A2A_TASK_STATE_COMPLETED = "TASK_STATE_COMPLETED";
|
|
5110
|
-
var A2A_TASK_STATE_FAILED = "TASK_STATE_FAILED";
|
|
5111
|
-
var A2A_TASK_STATE_INPUT_REQUIRED = "TASK_STATE_INPUT_REQUIRED";
|
|
5112
|
-
var A2A_EXTENSIONS_HEADER = "a2a-extensions";
|
|
5113
|
-
|
|
5114
4987
|
// src/protocols/a2a/jsonrpc.ts
|
|
5115
4988
|
var JSONRPC_PARSE_ERROR = -32700;
|
|
5116
4989
|
var JSONRPC_INVALID_REQUEST = -32600;
|
|
@@ -5120,10 +4993,12 @@ var JSONRPC_INTERNAL_ERROR = -32603;
|
|
|
5120
4993
|
var A2A_ERROR_TASK_NOT_FOUND = -32001;
|
|
5121
4994
|
var A2A_ERROR_PUSH_NOTIFICATION_NOT_SUPPORTED = -32003;
|
|
5122
4995
|
var A2A_ERROR_UNSUPPORTED_OPERATION = -32004;
|
|
4996
|
+
var A2A_ERROR_TASK_NOT_CANCELABLE = -32002;
|
|
5123
4997
|
var A2A_ERROR_CONTENT_TYPE_NOT_SUPPORTED = -32005;
|
|
5124
4998
|
var A2A_ERROR_VERSION_NOT_SUPPORTED = -32009;
|
|
5125
4999
|
var A2A_ERROR_REASONS = /* @__PURE__ */ new Map([
|
|
5126
5000
|
[A2A_ERROR_TASK_NOT_FOUND, "TASK_NOT_FOUND"],
|
|
5001
|
+
[A2A_ERROR_TASK_NOT_CANCELABLE, "TASK_NOT_CANCELABLE"],
|
|
5127
5002
|
[A2A_ERROR_PUSH_NOTIFICATION_NOT_SUPPORTED, "PUSH_NOTIFICATION_NOT_SUPPORTED"],
|
|
5128
5003
|
[A2A_ERROR_UNSUPPORTED_OPERATION, "UNSUPPORTED_OPERATION"],
|
|
5129
5004
|
[A2A_ERROR_CONTENT_TYPE_NOT_SUPPORTED, "CONTENT_TYPE_NOT_SUPPORTED"],
|
|
@@ -5136,23 +5011,24 @@ function readId(value) {
|
|
|
5136
5011
|
function jsonRpcResult(id, result) {
|
|
5137
5012
|
return { jsonrpc: "2.0", id, result };
|
|
5138
5013
|
}
|
|
5139
|
-
function jsonRpcError(id, code, message) {
|
|
5014
|
+
function jsonRpcError(id, code, message, details = []) {
|
|
5140
5015
|
const reason = A2A_ERROR_REASONS.get(code);
|
|
5141
|
-
const
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
} : {}
|
|
5153
|
-
};
|
|
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 } : {} };
|
|
5154
5027
|
return { jsonrpc: "2.0", id, error };
|
|
5155
5028
|
}
|
|
5029
|
+
function retryInfo(seconds) {
|
|
5030
|
+
return { "@type": "type.googleapis.com/google.rpc.RetryInfo", retryDelay: `${seconds}s` };
|
|
5031
|
+
}
|
|
5156
5032
|
function parseJsonRpcRequest(rawBody) {
|
|
5157
5033
|
let payload;
|
|
5158
5034
|
try {
|
|
@@ -5217,6 +5093,205 @@ function parseJsonRpcRequest(rawBody) {
|
|
|
5217
5093
|
return { ok: true, request: { id, method, params: params ?? {} } };
|
|
5218
5094
|
}
|
|
5219
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
|
+
|
|
5220
5295
|
// src/protocols/a2a/message-mapping.ts
|
|
5221
5296
|
var A2A_USER_ROLE = "ROLE_USER";
|
|
5222
5297
|
var A2A_CALL_SHAPE = 'one data part {"resource": "<skill id>", "input": {...}}';
|
|
@@ -5236,21 +5311,26 @@ var ParamsSchema = z.object({
|
|
|
5236
5311
|
taskId: z.string().optional(),
|
|
5237
5312
|
contextId: z.string().optional()
|
|
5238
5313
|
});
|
|
5239
|
-
function
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
)
|
|
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;
|
|
5248
5328
|
}
|
|
5249
5329
|
function assertNoContinuation(params) {
|
|
5250
5330
|
const message = params.message;
|
|
5251
5331
|
if (params.taskId !== void 0 || message.taskId !== void 0) {
|
|
5252
5332
|
throw unsupported(
|
|
5253
|
-
"Task not found:
|
|
5333
|
+
"Task not found: send the message without a taskId to start a new task.",
|
|
5254
5334
|
A2A_ERROR_TASK_NOT_FOUND
|
|
5255
5335
|
);
|
|
5256
5336
|
}
|
|
@@ -5288,21 +5368,10 @@ function assertSupportedPart(part) {
|
|
|
5288
5368
|
}
|
|
5289
5369
|
}
|
|
5290
5370
|
function parseInvocation(rawParams) {
|
|
5291
|
-
const
|
|
5292
|
-
if (!parsed.success) {
|
|
5293
|
-
throw invalid2(
|
|
5294
|
-
'Request must carry a "message" with a "role" and a "parts" array of structured data parts.'
|
|
5295
|
-
);
|
|
5296
|
-
}
|
|
5297
|
-
const params = parsed.data;
|
|
5371
|
+
const params = readMessage(rawParams);
|
|
5298
5372
|
const message = params.message;
|
|
5299
|
-
if (message.messageId === void 0 || message.messageId.length === 0) {
|
|
5300
|
-
throw invalid2('Message must carry a non-empty "messageId".');
|
|
5301
|
-
}
|
|
5302
5373
|
const messageId = message.messageId;
|
|
5303
5374
|
assertNoContinuation(params);
|
|
5304
|
-
const roleProblem = userRoleProblem(message.role);
|
|
5305
|
-
if (roleProblem !== void 0) throw invalid2(roleProblem);
|
|
5306
5375
|
if (message.parts.length === 0) {
|
|
5307
5376
|
throw invalid2("Message carries no parts: send exactly one structured data part.");
|
|
5308
5377
|
}
|
|
@@ -5355,6 +5424,9 @@ function expiryMs(nowMs, expiresAt) {
|
|
|
5355
5424
|
const ttl = Number.isFinite(requested) ? requested - nowMs : DEFAULT_PENDING_TTL_MS;
|
|
5356
5425
|
return nowMs + Math.min(Math.max(ttl, 0), MAX_PENDING_TTL_MS);
|
|
5357
5426
|
}
|
|
5427
|
+
function pendingExpiresAt(nowMs, expiresAt) {
|
|
5428
|
+
return new Date(expiryMs(nowMs, expiresAt)).toISOString();
|
|
5429
|
+
}
|
|
5358
5430
|
function createPendingPayments(clock, maxEntries = MAX_PENDING_PAYMENTS) {
|
|
5359
5431
|
const tasks = /* @__PURE__ */ new Map();
|
|
5360
5432
|
const now = () => clock.now().getTime();
|
|
@@ -5534,42 +5606,6 @@ function skillDescription(resource) {
|
|
|
5534
5606
|
}
|
|
5535
5607
|
return base;
|
|
5536
5608
|
}
|
|
5537
|
-
function exampleValue(schema, name) {
|
|
5538
|
-
if (!isRecord(schema)) return `<${name}>`;
|
|
5539
|
-
const examples = schema["examples"];
|
|
5540
|
-
if (Array.isArray(examples) && examples.length > 0) return examples[0];
|
|
5541
|
-
if (schema["default"] !== void 0) return schema["default"];
|
|
5542
|
-
const allowed = schema["enum"];
|
|
5543
|
-
if (Array.isArray(allowed) && allowed.length > 0) return allowed[0];
|
|
5544
|
-
const declared = schema["type"];
|
|
5545
|
-
const type = Array.isArray(declared) ? declared[0] : declared;
|
|
5546
|
-
switch (type) {
|
|
5547
|
-
case "object":
|
|
5548
|
-
return exampleObject(schema);
|
|
5549
|
-
case "array":
|
|
5550
|
-
return schema["items"] !== void 0 ? [exampleValue(schema["items"], name)] : [];
|
|
5551
|
-
case "number":
|
|
5552
|
-
case "integer":
|
|
5553
|
-
return 0;
|
|
5554
|
-
case "boolean":
|
|
5555
|
-
return false;
|
|
5556
|
-
case "null":
|
|
5557
|
-
return null;
|
|
5558
|
-
default:
|
|
5559
|
-
return `<${name}>`;
|
|
5560
|
-
}
|
|
5561
|
-
}
|
|
5562
|
-
function exampleObject(schema) {
|
|
5563
|
-
const properties = isRecord(schema["properties"]) ? schema["properties"] : {};
|
|
5564
|
-
const required = Array.isArray(schema["required"]) ? schema["required"] : [];
|
|
5565
|
-
const example = {};
|
|
5566
|
-
for (const key of required) {
|
|
5567
|
-
if (typeof key !== "string" || key === PAYMENT_INPUT_FIELD || key === AUTHORIZATION_INPUT_FIELD)
|
|
5568
|
-
continue;
|
|
5569
|
-
example[key] = exampleValue(properties[key], key);
|
|
5570
|
-
}
|
|
5571
|
-
return example;
|
|
5572
|
-
}
|
|
5573
5609
|
function skillExample(resource) {
|
|
5574
5610
|
return JSON.stringify({
|
|
5575
5611
|
resource: resource.id,
|
|
@@ -5622,38 +5658,398 @@ function buildAgentCard(options) {
|
|
|
5622
5658
|
]
|
|
5623
5659
|
} : {}
|
|
5624
5660
|
},
|
|
5625
|
-
defaultInputModes: [A2A_JSON_MEDIA_TYPE],
|
|
5626
|
-
defaultOutputModes: [A2A_JSON_MEDIA_TYPE],
|
|
5627
|
-
skills: options.resources.map(buildAgentSkill)
|
|
5628
|
-
};
|
|
5629
|
-
}
|
|
5661
|
+
defaultInputModes: [A2A_JSON_MEDIA_TYPE],
|
|
5662
|
+
defaultOutputModes: [A2A_JSON_MEDIA_TYPE],
|
|
5663
|
+
skills: options.resources.map(buildAgentSkill)
|
|
5664
|
+
};
|
|
5665
|
+
}
|
|
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
|
+
|
|
5699
|
+
// src/support/a2a.json
|
|
5700
|
+
var a2a_default = {
|
|
5701
|
+
name: "a2a",
|
|
5702
|
+
kind: "protocol",
|
|
5703
|
+
title: "A2A",
|
|
5704
|
+
status: "supported",
|
|
5705
|
+
role: "Transport that carries x402 and MPP payments in `SendMessage`, including through the x402 extension.",
|
|
5706
|
+
subset: "Agent Card, `SendMessage` with `returnImmediately`, `GetTask`, `ListTasks`, `CancelTask` and the paid flow; the x402 extension is experimental",
|
|
5707
|
+
spec: {
|
|
5708
|
+
revisions: ["1.0.1"],
|
|
5709
|
+
display: "v1.0.1; negotiation `1.0`; `JSONRPC` binding",
|
|
5710
|
+
source: {
|
|
5711
|
+
repo: "a2aproject/A2A",
|
|
5712
|
+
commit: "3303592588e388e62e0f69f701af531d2f4e3991"
|
|
5713
|
+
},
|
|
5714
|
+
stable: true,
|
|
5715
|
+
statement: "the first stable, production-ready version",
|
|
5716
|
+
checked: "2026-11-17"
|
|
5717
|
+
},
|
|
5718
|
+
packages: [{ name: "@a2a-js/sdk", use: "test" }],
|
|
5719
|
+
artifacts: [],
|
|
5720
|
+
features: [
|
|
5721
|
+
{ name: "agent-card", status: "supported" },
|
|
5722
|
+
{ name: "jsonrpc", status: "supported" },
|
|
5723
|
+
{ name: "SendMessage", status: "supported" },
|
|
5724
|
+
{ name: "GetTask", status: "supported" },
|
|
5725
|
+
{ name: "ListTasks", status: "supported" },
|
|
5726
|
+
{ name: "CancelTask", status: "supported" },
|
|
5727
|
+
{ name: "returnImmediately", status: "supported" },
|
|
5728
|
+
{ name: "x402-extension", status: "experimental" }
|
|
5729
|
+
],
|
|
5730
|
+
exclusions: [
|
|
5731
|
+
{ name: "SendStreamingMessage" },
|
|
5732
|
+
{ name: "SubscribeToTask" },
|
|
5733
|
+
{ name: "CreateTaskPushNotificationConfig" },
|
|
5734
|
+
{ name: "GetTaskPushNotificationConfig" },
|
|
5735
|
+
{ name: "ListTaskPushNotificationConfigs" },
|
|
5736
|
+
{ name: "DeleteTaskPushNotificationConfig" },
|
|
5737
|
+
{ name: "GetExtendedAgentCard" },
|
|
5738
|
+
{ name: "HTTP+JSON/REST binding" },
|
|
5739
|
+
{ name: "gRPC binding" },
|
|
5740
|
+
{ name: "SSE" },
|
|
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
|
+
},
|
|
5745
|
+
{ name: "task resumption other than an x402 extension payment" },
|
|
5746
|
+
{ name: "push notifications" },
|
|
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" },
|
|
5761
|
+
{ name: "text parts" },
|
|
5762
|
+
{ name: "file and URL parts (including inline bytes)" },
|
|
5763
|
+
{ name: "multi-part messages" },
|
|
5764
|
+
{ name: "message roles other than ROLE_USER" },
|
|
5765
|
+
{ name: "authenticated extended agent cards" },
|
|
5766
|
+
{ name: "A2A authentication schemes" },
|
|
5767
|
+
{ name: "artifact types beyond Agent Commerce outcome data" },
|
|
5768
|
+
{
|
|
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"]
|
|
5778
|
+
}
|
|
5779
|
+
],
|
|
5780
|
+
conformance: {
|
|
5781
|
+
suite: "Our tests against the A2A 1.0.1 specification, and the A2A TCK at MUST level in CI.",
|
|
5782
|
+
tests: [
|
|
5783
|
+
"tests/conformance/a2a/agent-card.test.ts",
|
|
5784
|
+
"tests/conformance/a2a/errors.test.ts",
|
|
5785
|
+
"tests/conformance/a2a/free-resource.test.ts",
|
|
5786
|
+
"tests/conformance/a2a/paid-resource.test.ts",
|
|
5787
|
+
"tests/conformance/a2a/params.test.ts",
|
|
5788
|
+
"tests/conformance/a2a/protocol-version.test.ts",
|
|
5789
|
+
"tests/conformance/a2a/tasks.test.ts"
|
|
5790
|
+
],
|
|
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
|
+
}
|
|
6018
|
+
},
|
|
6019
|
+
gaps: [
|
|
6020
|
+
{
|
|
6021
|
+
requirement: "\xA73.1: GetTask, ListTasks and CancelTask, which every agent implements",
|
|
6022
|
+
state: "closed"
|
|
6023
|
+
},
|
|
6024
|
+
{
|
|
6025
|
+
requirement: "\xA73.2.2: returnImmediately as well as the blocking default",
|
|
6026
|
+
state: "closed"
|
|
6027
|
+
},
|
|
6028
|
+
{
|
|
6029
|
+
requirement: "\xA73.3.2: validate all input parameters, including tenant and configuration",
|
|
6030
|
+
state: "closed"
|
|
6031
|
+
},
|
|
6032
|
+
{
|
|
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"
|
|
6035
|
+
}
|
|
6036
|
+
],
|
|
6037
|
+
docs: ["docs/protocols/a2a.md"]
|
|
6038
|
+
};
|
|
5630
6039
|
|
|
5631
6040
|
// src/protocols/a2a/descriptor.ts
|
|
5632
6041
|
var A2A_CAPABILITIES = [
|
|
5633
6042
|
"agent-card",
|
|
5634
6043
|
"jsonrpc",
|
|
5635
6044
|
"SendMessage",
|
|
6045
|
+
"GetTask",
|
|
6046
|
+
"ListTasks",
|
|
6047
|
+
"CancelTask",
|
|
6048
|
+
"returnImmediately",
|
|
5636
6049
|
// The x402 A2A transport, opt-in per request
|
|
5637
6050
|
"x402-extension"
|
|
5638
6051
|
];
|
|
5639
|
-
var A2A_UNSUPPORTED =
|
|
5640
|
-
// Methods, as the protocol names them; the transport refuses the same list
|
|
5641
|
-
...A2A_UNSUPPORTED_METHODS,
|
|
5642
|
-
// Transports other than the one binding served
|
|
5643
|
-
"HTTP+JSON/REST binding",
|
|
5644
|
-
"gRPC binding",
|
|
5645
|
-
// Behaviors
|
|
5646
|
-
"SSE",
|
|
5647
|
-
"long-running task persistence",
|
|
5648
|
-
"task resumption other than an x402 extension payment",
|
|
5649
|
-
"push notifications",
|
|
5650
|
-
"multi-turn conversational continuation",
|
|
5651
|
-
"authenticated extended agent cards",
|
|
5652
|
-
"A2A authentication schemes",
|
|
5653
|
-
"artifact types beyond Agent Commerce outcome data",
|
|
5654
|
-
// Instances with separate receipt stores cannot resume each other's tasks
|
|
5655
|
-
"x402 extension payments across gateway instances"
|
|
5656
|
-
];
|
|
6052
|
+
var A2A_UNSUPPORTED = exclusionNames(a2a_default);
|
|
5657
6053
|
function buildDescriptor(implementationVersion) {
|
|
5658
6054
|
return {
|
|
5659
6055
|
name: "a2a",
|
|
@@ -5661,7 +6057,7 @@ function buildDescriptor(implementationVersion) {
|
|
|
5661
6057
|
implementationVersion,
|
|
5662
6058
|
supportedSpec: A2A_SPEC_VERSION,
|
|
5663
6059
|
capabilities: A2A_CAPABILITIES,
|
|
5664
|
-
status:
|
|
6060
|
+
status: descriptorStatus(a2a_default),
|
|
5665
6061
|
unsupported: A2A_UNSUPPORTED
|
|
5666
6062
|
};
|
|
5667
6063
|
}
|
|
@@ -5732,23 +6128,63 @@ function failedTask(error, identity) {
|
|
|
5732
6128
|
identity.statusMessageId
|
|
5733
6129
|
);
|
|
5734
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
|
+
}
|
|
5735
6174
|
|
|
5736
6175
|
// src/protocols/a2a/payment-resume.ts
|
|
5737
6176
|
function taskResult(id, task2) {
|
|
5738
6177
|
return jsonRpcResult(id, { task: task2 });
|
|
5739
6178
|
}
|
|
5740
|
-
|
|
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;
|
|
5741
6183
|
const message = isRecord(params) ? params["message"] : void 0;
|
|
5742
6184
|
const taskId = isRecord(message) ? message["taskId"] : void 0;
|
|
5743
|
-
if (
|
|
5744
|
-
const pending = await pendingPayments
|
|
6185
|
+
if (typeof taskId !== "string") return void 0;
|
|
6186
|
+
const pending = await pendingPayments.get(taskId);
|
|
5745
6187
|
if (pending === void 0) return void 0;
|
|
5746
|
-
const messageId = isRecord(message) ? message["messageId"] : void 0;
|
|
5747
|
-
if (typeof messageId !== "string" || messageId.length === 0) {
|
|
5748
|
-
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, 'Message must carry a non-empty "messageId".');
|
|
5749
|
-
}
|
|
5750
|
-
const roleProblem = userRoleProblem(isRecord(message) ? message["role"] : void 0);
|
|
5751
|
-
if (roleProblem !== void 0) return jsonRpcError(id, JSONRPC_INVALID_PARAMS, roleProblem);
|
|
5752
6188
|
const contextId = isRecord(message) ? message["contextId"] : void 0;
|
|
5753
6189
|
if (contextId !== void 0 && contextId !== pending.contextId) {
|
|
5754
6190
|
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, 'Message "contextId" does not match the task.');
|
|
@@ -5769,43 +6205,78 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
5769
6205
|
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, toCommerceError(err).message);
|
|
5770
6206
|
}
|
|
5771
6207
|
}
|
|
5772
|
-
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
|
+
}
|
|
5773
6220
|
if (taken === void 0) return void 0;
|
|
5774
6221
|
const authorization = taken.authorization ?? followUp;
|
|
5775
|
-
|
|
5776
|
-
|
|
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 = {
|
|
5777
6239
|
taskId,
|
|
5778
6240
|
contextId: taken.contextId,
|
|
5779
6241
|
artifactId: context.ids.next("a2a-artifact"),
|
|
5780
|
-
statusMessageId
|
|
5781
|
-
timestamp: context.clock.nowIso()
|
|
6242
|
+
statusMessageId: context.ids.next("a2a-msg")
|
|
5782
6243
|
};
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
artifacts: []
|
|
5789
|
-
};
|
|
5790
|
-
return taskResult(
|
|
5791
|
-
id,
|
|
5792
|
-
withStatusMessage(
|
|
5793
|
-
declined,
|
|
5794
|
-
"Payment was declined.",
|
|
5795
|
-
statusMessageId,
|
|
5796
|
-
paymentRejectedMetadata()
|
|
5797
|
-
)
|
|
5798
|
-
);
|
|
5799
|
-
}
|
|
5800
|
-
return taskResult(
|
|
5801
|
-
id,
|
|
5802
|
-
await payPending(
|
|
5803
|
-
context,
|
|
5804
|
-
{ ...taken, ...authorization !== void 0 ? { authorization } : {} },
|
|
5805
|
-
submission.payload,
|
|
5806
|
-
identity
|
|
5807
|
-
)
|
|
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" }
|
|
5808
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);
|
|
5809
6280
|
}
|
|
5810
6281
|
function withoutRetryDelay(error) {
|
|
5811
6282
|
if (error.details?.["reason"] !== "payment_identifier_in_flight") return error;
|
|
@@ -5818,7 +6289,7 @@ function withoutRetryDelay(error) {
|
|
|
5818
6289
|
...error.resourceId !== void 0 ? { resourceId: error.resourceId } : {}
|
|
5819
6290
|
});
|
|
5820
6291
|
}
|
|
5821
|
-
async function payPending(context, pending, payload,
|
|
6292
|
+
async function payPending(context, pending, payload, ids) {
|
|
5822
6293
|
const requestId = context.ids.next("a2a");
|
|
5823
6294
|
const request = {
|
|
5824
6295
|
requestId,
|
|
@@ -5837,12 +6308,14 @@ async function payPending(context, pending, payload, identity) {
|
|
|
5837
6308
|
try {
|
|
5838
6309
|
const outcome = await context.pipeline.execute(request);
|
|
5839
6310
|
if (outcome.kind === "delivered" && outcome.payment !== void 0) {
|
|
5840
|
-
|
|
5841
|
-
|
|
6311
|
+
const identity2 = { ...ids, timestamp: context.clock.nowIso() };
|
|
6312
|
+
const task2 = withStatusMessage(
|
|
6313
|
+
completedTask(outcome, identity2),
|
|
5842
6314
|
"Payment settled.",
|
|
5843
|
-
|
|
6315
|
+
identity2.statusMessageId,
|
|
5844
6316
|
paymentCompletedMetadata(outcome.payment)
|
|
5845
6317
|
);
|
|
6318
|
+
return { task: task2, evictable: false };
|
|
5846
6319
|
}
|
|
5847
6320
|
error = new CommerceError("PAYMENT_INVALID", "The payment was not accepted.", { requestId });
|
|
5848
6321
|
} catch (err) {
|
|
@@ -5852,24 +6325,183 @@ async function payPending(context, pending, payload, identity) {
|
|
|
5852
6325
|
"a2a adapter: x402 extension payment failed"
|
|
5853
6326
|
);
|
|
5854
6327
|
}
|
|
6328
|
+
const identity = { ...ids, timestamp: context.clock.nowIso() };
|
|
5855
6329
|
const metadata = paymentFailureMetadata(error, pending.network);
|
|
5856
6330
|
const reason = error.details?.["reason"];
|
|
5857
|
-
let text
|
|
6331
|
+
let text;
|
|
5858
6332
|
if (metadata[X402_PAYMENT_STATUS_KEY] === "payment-completed") {
|
|
5859
6333
|
text = "Payment settled, but the resource could not be delivered.";
|
|
5860
6334
|
} else if (typeof reason === "string" && reason.startsWith("payment_identifier_")) {
|
|
5861
6335
|
text = error.message;
|
|
5862
|
-
} else
|
|
5863
|
-
|
|
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])}.`;
|
|
6339
|
+
}
|
|
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);
|
|
5864
6396
|
}
|
|
5865
|
-
|
|
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
|
+
};
|
|
5866
6465
|
}
|
|
5867
6466
|
|
|
5868
6467
|
// src/protocols/a2a/adapter.ts
|
|
5869
6468
|
var MAX_REQUEST_BODY_BYTES = 256 * 1024;
|
|
5870
6469
|
var VERSION_PATTERN = /^(\d+\.\d+)(?:\.\d+)?$/;
|
|
5871
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
|
+
};
|
|
5872
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
|
+
}
|
|
5873
6505
|
var DEFAULT_AGENT_DESCRIPTION = "Agent Commerce Gateway: canonical commerce resources exposed as A2A skills.";
|
|
5874
6506
|
var A2aProtocolAdapter = class {
|
|
5875
6507
|
name = "a2a";
|
|
@@ -5880,6 +6512,8 @@ var A2aProtocolAdapter = class {
|
|
|
5880
6512
|
agentDescription;
|
|
5881
6513
|
agentVersion;
|
|
5882
6514
|
store;
|
|
6515
|
+
retentionMs;
|
|
6516
|
+
maxRetained;
|
|
5883
6517
|
context;
|
|
5884
6518
|
started = false;
|
|
5885
6519
|
// The card lists only a2a-exposed resources, but a caller can name any id,
|
|
@@ -5892,12 +6526,19 @@ var A2aProtocolAdapter = class {
|
|
|
5892
6526
|
cardEtag = "";
|
|
5893
6527
|
// Purchases waiting for an x402 extension payment
|
|
5894
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;
|
|
5895
6534
|
constructor(options = {}) {
|
|
5896
6535
|
this.mountPath = options.mountPath ?? A2A_DEFAULT_MOUNT_PATH;
|
|
5897
6536
|
this.agentName = options.agentName ?? A2A_DEFAULT_AGENT_NAME;
|
|
5898
6537
|
this.agentDescription = options.agentDescription ?? DEFAULT_AGENT_DESCRIPTION;
|
|
5899
6538
|
this.agentVersion = options.agentVersion ?? PACKAGE_VERSION;
|
|
5900
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);
|
|
5901
6542
|
this.descriptor = buildDescriptor(PACKAGE_VERSION);
|
|
5902
6543
|
this.additionalHttpRoutes = [
|
|
5903
6544
|
{
|
|
@@ -5930,6 +6571,8 @@ var A2aProtocolAdapter = class {
|
|
|
5930
6571
|
resources
|
|
5931
6572
|
});
|
|
5932
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);
|
|
5933
6576
|
this.cardBody = JSON.stringify(this.card);
|
|
5934
6577
|
this.cardEtag = `"${createHash("sha256").update(this.cardBody).digest("base64url")}"`;
|
|
5935
6578
|
this.started = true;
|
|
@@ -5964,6 +6607,7 @@ var A2aProtocolAdapter = class {
|
|
|
5964
6607
|
}
|
|
5965
6608
|
/** `POST <mountPath>`: the A2A JSON-RPC endpoint */
|
|
5966
6609
|
async handleHttp(req, res) {
|
|
6610
|
+
let requestId = null;
|
|
5967
6611
|
try {
|
|
5968
6612
|
if (!this.started) {
|
|
5969
6613
|
this.writeJson(
|
|
@@ -5985,8 +6629,8 @@ var A2aProtocolAdapter = class {
|
|
|
5985
6629
|
);
|
|
5986
6630
|
return;
|
|
5987
6631
|
}
|
|
5988
|
-
const
|
|
5989
|
-
if (
|
|
6632
|
+
const read2 = await readCappedBody(req, MAX_REQUEST_BODY_BYTES);
|
|
6633
|
+
if (read2.kind === "too-large") {
|
|
5990
6634
|
this.writeJson(
|
|
5991
6635
|
res,
|
|
5992
6636
|
413,
|
|
@@ -5998,7 +6642,7 @@ var A2aProtocolAdapter = class {
|
|
|
5998
6642
|
);
|
|
5999
6643
|
return;
|
|
6000
6644
|
}
|
|
6001
|
-
if (
|
|
6645
|
+
if (read2.kind !== "ok") {
|
|
6002
6646
|
this.writeJson(
|
|
6003
6647
|
res,
|
|
6004
6648
|
200,
|
|
@@ -6006,11 +6650,12 @@ var A2aProtocolAdapter = class {
|
|
|
6006
6650
|
);
|
|
6007
6651
|
return;
|
|
6008
6652
|
}
|
|
6009
|
-
const parsed = parseJsonRpcRequest(
|
|
6653
|
+
const parsed = parseJsonRpcRequest(read2.text);
|
|
6010
6654
|
if (!parsed.ok) {
|
|
6011
6655
|
this.writeJson(res, 200, jsonRpcError(parsed.id, parsed.error.code, parsed.error.message));
|
|
6012
6656
|
return;
|
|
6013
6657
|
}
|
|
6658
|
+
requestId = parsed.request.id;
|
|
6014
6659
|
const version = req.headers[A2A_VERSION_HEADER];
|
|
6015
6660
|
const declared = (Array.isArray(version) ? version[0] : version) ?? new URL(req.url ?? "/", "http://localhost").searchParams.get(A2A_VERSION_PARAMETER);
|
|
6016
6661
|
if (declared?.match(VERSION_PATTERN)?.[1] !== A2A_PROTOCOL_VERSION) {
|
|
@@ -6025,24 +6670,21 @@ var A2aProtocolAdapter = class {
|
|
|
6025
6670
|
);
|
|
6026
6671
|
return;
|
|
6027
6672
|
}
|
|
6673
|
+
const activated = requestsX402Extension(req.headers[A2A_EXTENSIONS_HEADER]) || requestsX402Extension(req.headers[A2A_X_EXTENSIONS_HEADER]);
|
|
6028
6674
|
const response = await this.dispatch(
|
|
6029
6675
|
parsed.request.id,
|
|
6030
6676
|
parsed.request.method,
|
|
6031
6677
|
parsed.request.params,
|
|
6032
|
-
|
|
6033
|
-
);
|
|
6034
|
-
this.writeJson(
|
|
6035
|
-
res,
|
|
6036
|
-
200,
|
|
6037
|
-
response,
|
|
6038
|
-
usesX402Extension(response) ? { [A2A_EXTENSIONS_HEADER]: A2A_X402_EXTENSION_URI } : {}
|
|
6678
|
+
activated
|
|
6039
6679
|
);
|
|
6680
|
+
const echo = usesX402Extension(response) || activated && response["error"] === void 0;
|
|
6681
|
+
this.writeJson(res, 200, response, echo ? X402_EXTENSION_ECHO : {});
|
|
6040
6682
|
} catch (err) {
|
|
6041
6683
|
this.context?.logger.error({ err: toLogInfo(err) }, "a2a adapter: request handling failed");
|
|
6042
6684
|
this.writeJson(
|
|
6043
6685
|
res,
|
|
6044
6686
|
200,
|
|
6045
|
-
jsonRpcError(
|
|
6687
|
+
jsonRpcError(requestId, JSONRPC_INTERNAL_ERROR, "Internal server error.")
|
|
6046
6688
|
);
|
|
6047
6689
|
}
|
|
6048
6690
|
}
|
|
@@ -6054,13 +6696,6 @@ var A2aProtocolAdapter = class {
|
|
|
6054
6696
|
`A2A method "${method}" is not supported: this agent does not support push notifications.`
|
|
6055
6697
|
);
|
|
6056
6698
|
}
|
|
6057
|
-
if (A2A_TASK_LOOKUP_METHODS.includes(method)) {
|
|
6058
|
-
return jsonRpcError(
|
|
6059
|
-
id,
|
|
6060
|
-
A2A_ERROR_TASK_NOT_FOUND,
|
|
6061
|
-
"Task not found. Finished tasks are not retained; continue a pending payment with SendMessage."
|
|
6062
|
-
);
|
|
6063
|
-
}
|
|
6064
6699
|
if (A2A_UNSUPPORTED_METHODS.includes(method)) {
|
|
6065
6700
|
return jsonRpcError(
|
|
6066
6701
|
id,
|
|
@@ -6068,49 +6703,198 @@ var A2aProtocolAdapter = class {
|
|
|
6068
6703
|
`A2A method "${method}" is not supported by this deployment.`
|
|
6069
6704
|
);
|
|
6070
6705
|
}
|
|
6071
|
-
|
|
6072
|
-
|
|
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);
|
|
6073
6738
|
}
|
|
6074
|
-
const resumed = await resumePayment(
|
|
6739
|
+
const resumed = await resumePayment(
|
|
6740
|
+
this.resume(ops),
|
|
6741
|
+
id,
|
|
6742
|
+
request.params,
|
|
6743
|
+
request.returnImmediately
|
|
6744
|
+
);
|
|
6075
6745
|
if (resumed !== void 0) return resumed;
|
|
6746
|
+
const known = await this.answerKnownTask(ops, id, request.params);
|
|
6747
|
+
if (known !== void 0) return known;
|
|
6076
6748
|
let invocation;
|
|
6077
6749
|
try {
|
|
6078
|
-
invocation = parseInvocation(params);
|
|
6750
|
+
invocation = parseInvocation(request.params);
|
|
6079
6751
|
} catch (err) {
|
|
6080
|
-
|
|
6081
|
-
const a2aErrorCode = error.details?.["a2aErrorCode"];
|
|
6082
|
-
const code = typeof a2aErrorCode === "number" ? a2aErrorCode : error.code === "PROTOCOL_UNSUPPORTED" ? A2A_ERROR_UNSUPPORTED_OPERATION : JSONRPC_INVALID_PARAMS;
|
|
6083
|
-
return jsonRpcError(id, code, error.message);
|
|
6752
|
+
return refusal(id, err);
|
|
6084
6753
|
}
|
|
6085
|
-
return this.execute(id, invocation, x402Extension);
|
|
6754
|
+
return this.execute(ops, id, invocation, x402Extension, request.returnImmediately);
|
|
6086
6755
|
}
|
|
6087
|
-
//
|
|
6088
|
-
|
|
6089
|
-
const context = this
|
|
6090
|
-
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) {
|
|
6091
6846
|
return jsonRpcError(id, JSONRPC_INTERNAL_ERROR, "A2A adapter is not running.");
|
|
6092
6847
|
}
|
|
6848
|
+
const ids = this.taskIds(context);
|
|
6849
|
+
const now = () => ({ ...ids, timestamp: context.clock.nowIso() });
|
|
6093
6850
|
const resource = this.skillsById.get(invocation.resourceId);
|
|
6094
6851
|
if (resource === void 0) {
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
),
|
|
6102
|
-
this.taskIdentity(context, context.ids.next("a2a"))
|
|
6103
|
-
)
|
|
6852
|
+
const unknown = failedTask(
|
|
6853
|
+
new CommerceError(
|
|
6854
|
+
"RESOURCE_NOT_FOUND",
|
|
6855
|
+
`Unknown canonical resource "${invocation.resourceId}".`
|
|
6856
|
+
),
|
|
6857
|
+
now()
|
|
6104
6858
|
);
|
|
6105
|
-
|
|
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() });
|
|
6106
6887
|
const requestId = context.ids.next("a2a");
|
|
6107
|
-
|
|
6888
|
+
let task2;
|
|
6889
|
+
let evictable = true;
|
|
6890
|
+
let proofSent = false;
|
|
6108
6891
|
try {
|
|
6109
6892
|
const { input, payment, authorization } = extractReservedInputFields(
|
|
6110
6893
|
invocation.input,
|
|
6111
6894
|
resource,
|
|
6112
6895
|
requestId
|
|
6113
6896
|
);
|
|
6897
|
+
proofSent = payment !== void 0;
|
|
6114
6898
|
const request = {
|
|
6115
6899
|
requestId,
|
|
6116
6900
|
resourceId: invocation.resourceId,
|
|
@@ -6121,58 +6905,72 @@ var A2aProtocolAdapter = class {
|
|
|
6121
6905
|
...authorization !== void 0 ? { authorization } : {}
|
|
6122
6906
|
};
|
|
6123
6907
|
const outcome = await context.pipeline.execute(request);
|
|
6908
|
+
const identity = now();
|
|
6124
6909
|
if (outcome.kind !== "payment-required") {
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
id,
|
|
6147
|
-
failedTask(
|
|
6148
|
-
new CommerceError(
|
|
6149
|
-
"GATEWAY_BUSY",
|
|
6150
|
-
"Too many unpaid purchases are waiting for payment; retry shortly."
|
|
6151
|
-
),
|
|
6152
|
-
identity
|
|
6153
|
-
)
|
|
6154
|
-
);
|
|
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
|
+
}
|
|
6155
6931
|
}
|
|
6156
|
-
return taskResult(
|
|
6157
|
-
id,
|
|
6158
|
-
inputRequired(task2, paymentRequiredMetadata(envelope), identity.statusMessageId)
|
|
6159
|
-
);
|
|
6160
6932
|
} catch (err) {
|
|
6161
6933
|
const error = toCommerceError(err);
|
|
6162
6934
|
context.logger.warn(
|
|
6163
6935
|
{ resourceId: invocation.resourceId, requestId, err: toLogInfo(error) },
|
|
6164
6936
|
"a2a adapter: execution failed"
|
|
6165
6937
|
);
|
|
6166
|
-
|
|
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;
|
|
6167
6964
|
}
|
|
6965
|
+
return waiting;
|
|
6168
6966
|
}
|
|
6169
|
-
|
|
6967
|
+
// Generate access keys independently of IdGenerator; keep them out of log fields
|
|
6968
|
+
taskIds(context) {
|
|
6170
6969
|
return {
|
|
6171
|
-
taskId:
|
|
6172
|
-
contextId:
|
|
6970
|
+
taskId: randomUUID(),
|
|
6971
|
+
contextId: randomUUID(),
|
|
6173
6972
|
artifactId: context.ids.next("a2a-artifact"),
|
|
6174
|
-
statusMessageId: context.ids.next("a2a-msg")
|
|
6175
|
-
timestamp: context.clock.nowIso()
|
|
6973
|
+
statusMessageId: context.ids.next("a2a-msg")
|
|
6176
6974
|
};
|
|
6177
6975
|
}
|
|
6178
6976
|
async health() {
|
|
@@ -6184,11 +6982,15 @@ var A2aProtocolAdapter = class {
|
|
|
6184
6982
|
}
|
|
6185
6983
|
async stop() {
|
|
6186
6984
|
this.started = false;
|
|
6985
|
+
await this.background?.settled();
|
|
6986
|
+
this.background = void 0;
|
|
6187
6987
|
this.card = void 0;
|
|
6188
6988
|
this.cardBody = "";
|
|
6189
6989
|
this.cardEtag = "";
|
|
6190
6990
|
this.pendingPayments?.clear();
|
|
6191
6991
|
this.pendingPayments = void 0;
|
|
6992
|
+
this.tasks = void 0;
|
|
6993
|
+
this.running.clear();
|
|
6192
6994
|
this.skillsById = /* @__PURE__ */ new Map();
|
|
6193
6995
|
this.context = void 0;
|
|
6194
6996
|
}
|
|
@@ -6200,7 +7002,8 @@ var A2aProtocolAdapter = class {
|
|
|
6200
7002
|
};
|
|
6201
7003
|
function usesX402Extension(response) {
|
|
6202
7004
|
const result = response["result"];
|
|
6203
|
-
|
|
7005
|
+
const task2 = isRecord(result) && isRecord(result["task"]) ? result["task"] : result;
|
|
7006
|
+
return task2?.status?.message?.extensions?.includes(A2A_X402_EXTENSION_URI) === true;
|
|
6204
7007
|
}
|
|
6205
7008
|
function matchesEtag(header2, etag) {
|
|
6206
7009
|
if (header2 === void 0) return false;
|
|
@@ -6238,6 +7041,97 @@ function canonicalInput(request) {
|
|
|
6238
7041
|
return input;
|
|
6239
7042
|
}
|
|
6240
7043
|
|
|
7044
|
+
// src/support/acp.json
|
|
7045
|
+
var acp_default = {
|
|
7046
|
+
name: "acp",
|
|
7047
|
+
kind: "protocol",
|
|
7048
|
+
title: "ACP",
|
|
7049
|
+
status: "experimental",
|
|
7050
|
+
role: "Checkout API that forwards checkout operations to the merchant, whose payment handler receives `payment_data`. Gateway checkout routes are free and carry no x402 or MPP payment.",
|
|
7051
|
+
subset: "discovery and the five checkout operations",
|
|
7052
|
+
spec: {
|
|
7053
|
+
revisions: ["2026-04-17"],
|
|
7054
|
+
display: "stable snapshot `2026-04-17`; REST binding",
|
|
7055
|
+
source: {
|
|
7056
|
+
repo: "agentic-commerce-protocol/agentic-commerce-protocol",
|
|
7057
|
+
commit: "6b828681206f1f98a3faba978610ced66770d2ae"
|
|
7058
|
+
},
|
|
7059
|
+
stable: false,
|
|
7060
|
+
statement: "currently in `beta`",
|
|
7061
|
+
checked: "2026-11-17"
|
|
7062
|
+
},
|
|
7063
|
+
packages: [],
|
|
7064
|
+
artifacts: [
|
|
7065
|
+
{
|
|
7066
|
+
path: "src/protocols/acp/spec/2026-04-17/schema.agentic_checkout.json",
|
|
7067
|
+
revision: "6b828681206f1f98a3faba978610ced66770d2ae"
|
|
7068
|
+
},
|
|
7069
|
+
{
|
|
7070
|
+
path: "tests/fixtures/acp/2026-04-17",
|
|
7071
|
+
revision: "6b828681206f1f98a3faba978610ced66770d2ae"
|
|
7072
|
+
}
|
|
7073
|
+
],
|
|
7074
|
+
features: [
|
|
7075
|
+
{ name: "rest transport", status: "experimental" },
|
|
7076
|
+
{ name: "well-known discovery", status: "experimental" },
|
|
7077
|
+
{ name: "bearer authentication", status: "experimental" },
|
|
7078
|
+
{ name: "API-Version enforcement", status: "experimental" },
|
|
7079
|
+
{ name: "request header forwarding to the merchant", status: "experimental" },
|
|
7080
|
+
{ name: "checkout service", status: "experimental" },
|
|
7081
|
+
{ name: "createCheckoutSession", status: "experimental" },
|
|
7082
|
+
{ name: "updateCheckoutSession", status: "experimental" },
|
|
7083
|
+
{ name: "getCheckoutSession", status: "experimental" },
|
|
7084
|
+
{ name: "completeCheckoutSession", status: "experimental" },
|
|
7085
|
+
{ name: "cancelCheckoutSession", status: "experimental" }
|
|
7086
|
+
],
|
|
7087
|
+
exclusions: [
|
|
7088
|
+
{
|
|
7089
|
+
name: "carts service",
|
|
7090
|
+
note: "The discovery document advertises only the checkout service."
|
|
7091
|
+
},
|
|
7092
|
+
{ name: "feed service" },
|
|
7093
|
+
{ name: "standalone orders service" },
|
|
7094
|
+
{ name: "delegate_payment" },
|
|
7095
|
+
{ name: "delegate_authentication" },
|
|
7096
|
+
{ name: "ACP MCP transport binding" },
|
|
7097
|
+
{ name: "webhooks", note: "The merchant backend sends ACP order webhooks itself." },
|
|
7098
|
+
{ name: "outbound merchant-to-agent delivery" },
|
|
7099
|
+
{ name: "ACP client role" },
|
|
7100
|
+
{
|
|
7101
|
+
name: "Signature header verification",
|
|
7102
|
+
note: "The adapter forwards the header to the merchant unverified."
|
|
7103
|
+
},
|
|
7104
|
+
{
|
|
7105
|
+
name: "Timestamp replay-window verification",
|
|
7106
|
+
note: "The adapter forwards the header to the merchant unverified."
|
|
7107
|
+
},
|
|
7108
|
+
{ name: "discount extension" },
|
|
7109
|
+
{ name: "general ACP extension framework" },
|
|
7110
|
+
{ name: "multiple ACP API versions" },
|
|
7111
|
+
{ name: "seller-backed payment handler integration" }
|
|
7112
|
+
],
|
|
7113
|
+
deviations: [
|
|
7114
|
+
{
|
|
7115
|
+
summary: "After a merchant 5xx, retrying the same `Idempotency-Key` returns 409 `idempotency_unresolved` unless `protocols.acp.idempotency.merchantIdempotent` is true. The merchant may have acted, and another execution could duplicate the order.",
|
|
7116
|
+
spec: "ACP RFC \xA76.5",
|
|
7117
|
+
tests: ["tests/conformance/acp/idempotency.test.ts", "tests/conformance/acp/errors.test.ts"]
|
|
7118
|
+
}
|
|
7119
|
+
],
|
|
7120
|
+
conformance: {
|
|
7121
|
+
suite: "Our tests against the vendored schema and official examples; ACP publishes no conformance suite.",
|
|
7122
|
+
tests: [
|
|
7123
|
+
"tests/conformance/acp/checkout.test.ts",
|
|
7124
|
+
"tests/conformance/acp/errors.test.ts",
|
|
7125
|
+
"tests/conformance/acp/idempotency.test.ts",
|
|
7126
|
+
"tests/conformance/acp/protocol.test.ts",
|
|
7127
|
+
"tests/conformance/acp/snapshot.test.ts"
|
|
7128
|
+
],
|
|
7129
|
+
skipped: []
|
|
7130
|
+
},
|
|
7131
|
+
gaps: [],
|
|
7132
|
+
docs: ["docs/protocols/acp.md"]
|
|
7133
|
+
};
|
|
7134
|
+
|
|
6241
7135
|
// src/protocols/acp/descriptor.ts
|
|
6242
7136
|
var ACP_CAPABILITIES = [
|
|
6243
7137
|
"rest transport",
|
|
@@ -6249,28 +7143,7 @@ var ACP_CAPABILITIES = [
|
|
|
6249
7143
|
"checkout service",
|
|
6250
7144
|
...ACP_CHECKOUT_OPERATIONS
|
|
6251
7145
|
];
|
|
6252
|
-
var ACP_UNSUPPORTED =
|
|
6253
|
-
// Services this seller does not implement, named as ACP names them. The
|
|
6254
|
-
// discovery document advertises `checkout` alone, and these are the reason.
|
|
6255
|
-
"carts service",
|
|
6256
|
-
"feed service",
|
|
6257
|
-
"standalone orders service",
|
|
6258
|
-
"delegate_payment",
|
|
6259
|
-
"delegate_authentication",
|
|
6260
|
-
// Bindings and delivery directions
|
|
6261
|
-
"ACP MCP transport binding",
|
|
6262
|
-
"webhooks",
|
|
6263
|
-
"outbound merchant-to-agent delivery",
|
|
6264
|
-
"ACP client role",
|
|
6265
|
-
// Request authentication beyond the bearer token
|
|
6266
|
-
"Signature header verification",
|
|
6267
|
-
"Timestamp replay-window verification",
|
|
6268
|
-
// Extensions, versioning and payment handlers
|
|
6269
|
-
"discount extension",
|
|
6270
|
-
"general ACP extension framework",
|
|
6271
|
-
"multiple ACP API versions",
|
|
6272
|
-
"seller-backed payment handler integration"
|
|
6273
|
-
];
|
|
7146
|
+
var ACP_UNSUPPORTED = exclusionNames(acp_default);
|
|
6274
7147
|
function buildDescriptor2(implementationVersion) {
|
|
6275
7148
|
return {
|
|
6276
7149
|
name: "acp",
|
|
@@ -6278,7 +7151,7 @@ function buildDescriptor2(implementationVersion) {
|
|
|
6278
7151
|
implementationVersion,
|
|
6279
7152
|
supportedSpec: ACP_SPEC_VERSION,
|
|
6280
7153
|
capabilities: ACP_CAPABILITIES,
|
|
6281
|
-
status:
|
|
7154
|
+
status: descriptorStatus(acp_default),
|
|
6282
7155
|
unsupported: ACP_UNSUPPORTED
|
|
6283
7156
|
};
|
|
6284
7157
|
}
|
|
@@ -10677,8 +11550,8 @@ async function guardAcpRequest(req, options) {
|
|
|
10677
11550
|
}
|
|
10678
11551
|
idempotencyKey = presentedKey;
|
|
10679
11552
|
}
|
|
10680
|
-
const
|
|
10681
|
-
if (
|
|
11553
|
+
const read2 = await readCappedBody(req, options.maxBodyBytes ?? ACP_MAX_REQUEST_BODY_BYTES);
|
|
11554
|
+
if (read2.kind === "too-large") {
|
|
10682
11555
|
return failed(
|
|
10683
11556
|
acpFailure(
|
|
10684
11557
|
413,
|
|
@@ -10688,7 +11561,7 @@ async function guardAcpRequest(req, options) {
|
|
|
10688
11561
|
)
|
|
10689
11562
|
);
|
|
10690
11563
|
}
|
|
10691
|
-
if (
|
|
11564
|
+
if (read2.kind === "unreadable") {
|
|
10692
11565
|
return failed(
|
|
10693
11566
|
acpFailure(
|
|
10694
11567
|
400,
|
|
@@ -10698,7 +11571,7 @@ async function guardAcpRequest(req, options) {
|
|
|
10698
11571
|
)
|
|
10699
11572
|
);
|
|
10700
11573
|
}
|
|
10701
|
-
const raw =
|
|
11574
|
+
const raw = read2.text;
|
|
10702
11575
|
const contentTypeFailure = checkContentType(header(req, "content-type"), raw, route);
|
|
10703
11576
|
if (contentTypeFailure !== void 0) return failed(contentTypeFailure);
|
|
10704
11577
|
const definition = REQUEST_DEFINITIONS[route.operation];
|
|
@@ -11570,6 +12443,26 @@ var MIGRATIONS = [
|
|
|
11570
12443
|
);
|
|
11571
12444
|
`);
|
|
11572
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
|
+
}
|
|
11573
12466
|
}
|
|
11574
12467
|
];
|
|
11575
12468
|
var SCHEMA_VERSION2 = MIGRATIONS.at(-1)?.version ?? 0;
|
|
@@ -11687,6 +12580,17 @@ function missingLegacyImports(db) {
|
|
|
11687
12580
|
(source) => !(recorded && selectMarker(db, source.name) !== void 0) && usedBefore(db, source)
|
|
11688
12581
|
).map((source) => source.name);
|
|
11689
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
|
+
}
|
|
11690
12594
|
function importLegacyStores(db, receiptsPath, options, clock, logger) {
|
|
11691
12595
|
const recordMarker = db.prepare(
|
|
11692
12596
|
`INSERT INTO legacy_imports (source, path, rows, imported_at) VALUES (?, ?, ?, ?)
|
|
@@ -11929,8 +12833,8 @@ function createHoldMethods(db, clock) {
|
|
|
11929
12833
|
return selectHold.get(reference)?.state;
|
|
11930
12834
|
},
|
|
11931
12835
|
async listOrphanAuthorizationHolds(options) {
|
|
11932
|
-
const
|
|
11933
|
-
return listOrphans.all(
|
|
12836
|
+
const before2 = storedIso(options.updatedBefore, "updatedBefore");
|
|
12837
|
+
return listOrphans.all(before2, clampListLimit(options.limit)).map(rowToHold);
|
|
11934
12838
|
}
|
|
11935
12839
|
};
|
|
11936
12840
|
}
|
|
@@ -12265,6 +13169,85 @@ function rowToTransaction(row, now) {
|
|
|
12265
13169
|
};
|
|
12266
13170
|
}
|
|
12267
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
|
+
|
|
12268
13251
|
// src/storage/receipts/store.ts
|
|
12269
13252
|
var UNDELIVERED = "backend_status NOT BETWEEN 200 AND 299";
|
|
12270
13253
|
var UNCERTAIN = "status IN ('settlement-uncertain', 'failed')";
|
|
@@ -12569,9 +13552,6 @@ function storeOn(db, options) {
|
|
|
12569
13552
|
const countLiveTasksStmt = db.prepare(
|
|
12570
13553
|
"SELECT COUNT(*) AS count FROM pending_tasks WHERE expires_at > ?"
|
|
12571
13554
|
);
|
|
12572
|
-
const legacyImportsStmt = db.prepare(
|
|
12573
|
-
"SELECT source, path, rows, imported_at FROM legacy_imports WHERE path IS NOT NULL ORDER BY source"
|
|
12574
|
-
);
|
|
12575
13555
|
let closed = false;
|
|
12576
13556
|
let releaseLegacyLocks;
|
|
12577
13557
|
const descriptor = {
|
|
@@ -12586,7 +13566,8 @@ function storeOn(db, options) {
|
|
|
12586
13566
|
"transactions",
|
|
12587
13567
|
"idempotency-keys",
|
|
12588
13568
|
"authorization-holds",
|
|
12589
|
-
"pending-tasks"
|
|
13569
|
+
"pending-tasks",
|
|
13570
|
+
"task-records"
|
|
12590
13571
|
],
|
|
12591
13572
|
status: "stable"
|
|
12592
13573
|
};
|
|
@@ -12599,7 +13580,11 @@ function storeOn(db, options) {
|
|
|
12599
13580
|
`Receipt store schema version mismatch (found ${version}, expected ${SCHEMA_VERSION2})`
|
|
12600
13581
|
);
|
|
12601
13582
|
}
|
|
12602
|
-
if (!db.readonly)
|
|
13583
|
+
if (!db.readonly) {
|
|
13584
|
+
const now = clock.nowIso();
|
|
13585
|
+
sweepExpiredPendingTasks(db, now);
|
|
13586
|
+
sweepExpiredTaskRecords(db, now);
|
|
13587
|
+
}
|
|
12603
13588
|
if (options.legacyStores !== void 0 && releaseLegacyLocks === void 0) {
|
|
12604
13589
|
releaseLegacyLocks = importLegacyStores(
|
|
12605
13590
|
db,
|
|
@@ -12805,6 +13790,7 @@ function storeOn(db, options) {
|
|
|
12805
13790
|
...createIdempotencyMethods(db, clock),
|
|
12806
13791
|
...createHoldMethods(db, clock),
|
|
12807
13792
|
...createPendingTaskMethods(db, clock),
|
|
13793
|
+
...createTaskRecordMethods(db, clock),
|
|
12808
13794
|
// Reads all unresolved transactions at once. Page this query if large
|
|
12809
13795
|
// journals make operator diagnostics too costly.
|
|
12810
13796
|
async summary({ orphanHoldMinAgeMs }) {
|
|
@@ -12825,12 +13811,7 @@ function storeOn(db, options) {
|
|
|
12825
13811
|
unresolvedIdempotencyKeys: unresolvedKeys?.other ?? 0,
|
|
12826
13812
|
unresolvedPaymentKeys: unresolvedKeys?.payment ?? 0,
|
|
12827
13813
|
unexpiredPendingTasks: countLiveTasksStmt.get(now)?.count ?? 0,
|
|
12828
|
-
legacyImports:
|
|
12829
|
-
source: row.source,
|
|
12830
|
-
path: row.path,
|
|
12831
|
-
rows: row.rows,
|
|
12832
|
-
importedAt: row.imported_at
|
|
12833
|
-
})),
|
|
13814
|
+
legacyImports: recordedLegacyImports(db),
|
|
12834
13815
|
missingLegacyImports: missingLegacyImports(db)
|
|
12835
13816
|
};
|
|
12836
13817
|
},
|