@agent-score/commerce 1.5.1 → 1.6.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 +22 -8
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/core.d.mts +36 -27
- package/dist/core.d.ts +36 -27
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/identity/express.d.mts +2 -2
- package/dist/identity/express.d.ts +2 -2
- package/dist/identity/express.js +1 -1
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +1 -1
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +2 -2
- package/dist/identity/fastify.d.ts +2 -2
- package/dist/identity/fastify.js +1 -1
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +1 -1
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +2 -2
- package/dist/identity/hono.d.ts +2 -2
- package/dist/identity/hono.js +1 -1
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +1 -1
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +2 -2
- package/dist/identity/nextjs.d.ts +2 -2
- package/dist/identity/nextjs.js +1 -1
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +1 -1
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.d.mts +3 -3
- package/dist/identity/policy.d.ts +3 -3
- package/dist/identity/policy.js +3 -3
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +2 -2
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +3 -3
- package/dist/identity/web.d.ts +3 -3
- package/dist/identity/web.js +1 -1
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +1 -1
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +217 -123
- package/dist/index.d.ts +217 -123
- package/dist/index.js +86 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -330,73 +330,86 @@ function readX402PaymentHeader(request) {
|
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
// src/identity/a2a.ts
|
|
333
|
+
var PROTOCOL_VERSION = "1.0";
|
|
334
|
+
var DEFAULT_PROTOCOL_BINDING = "HTTP+JSON";
|
|
335
|
+
var DEFAULT_INPUT_MODE = "application/json";
|
|
336
|
+
var DEFAULT_OUTPUT_MODE = "application/json";
|
|
333
337
|
var UCP_A2A_EXTENSION_URI = "https://ucp.dev/2026-04-08/specification/reference";
|
|
334
|
-
function ucpA2AExtension(capabilities = {}) {
|
|
338
|
+
function ucpA2AExtension(capabilities = {}, options = {}) {
|
|
335
339
|
return {
|
|
336
340
|
uri: UCP_A2A_EXTENSION_URI,
|
|
341
|
+
description: "UCP support: this agent serves Universal Commerce Protocol bindings via the A2A transport.",
|
|
342
|
+
required: options.required ?? false,
|
|
337
343
|
params: { capabilities }
|
|
338
344
|
};
|
|
339
345
|
}
|
|
340
|
-
var PROTOCOL_VERSION = "1.0";
|
|
341
|
-
var CARD_VERSION = 1;
|
|
342
346
|
function buildA2AAgentCard(input) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (operatorId) {
|
|
348
|
-
const operatorVerification = input.data.operator_verification;
|
|
349
|
-
const accountVerification = input.data.account_verification;
|
|
350
|
-
identity = {
|
|
351
|
-
issuer,
|
|
352
|
-
operator_id: operatorId,
|
|
353
|
-
kyc_level: accountVerification?.kyc_level ?? operatorVerification?.level ?? "none",
|
|
354
|
-
sanctions_clear: accountVerification?.sanctions_clear === true,
|
|
355
|
-
age_bracket: accountVerification?.age_bracket ?? "unknown",
|
|
356
|
-
jurisdiction: accountVerification?.jurisdiction ?? "",
|
|
357
|
-
verified_at: accountVerification?.verified_at ?? operatorVerification?.verified_at ?? null,
|
|
358
|
-
verify_url: input.verifyUrl ?? input.data.verify_url ?? `${issuer}/verify`
|
|
359
|
-
};
|
|
360
|
-
}
|
|
347
|
+
if (!input.skills || input.skills.length === 0) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
"buildA2AAgentCard: `skills` MUST be a non-empty list. Per spec \xA74.4.1 (proto field 12 [field_behavior=REQUIRED]), every Agent Card must declare at least one AgentSkill. Construct A2AAgentCard directly to bypass."
|
|
350
|
+
);
|
|
361
351
|
}
|
|
352
|
+
const capabilities = {};
|
|
353
|
+
if (input.streaming !== void 0) capabilities.streaming = input.streaming;
|
|
354
|
+
if (input.push_notifications !== void 0) capabilities.push_notifications = input.push_notifications;
|
|
355
|
+
if (input.extensions && input.extensions.length > 0) capabilities.extensions = input.extensions;
|
|
356
|
+
if (input.extended_agent_card !== void 0) capabilities.extended_agent_card = input.extended_agent_card;
|
|
357
|
+
const primaryInterface = {
|
|
358
|
+
url: input.url,
|
|
359
|
+
protocol_binding: input.protocol_binding ?? DEFAULT_PROTOCOL_BINDING,
|
|
360
|
+
protocol_version: input.a2a_protocol_version ?? PROTOCOL_VERSION
|
|
361
|
+
};
|
|
362
362
|
const card = {
|
|
363
|
-
protocol_version: PROTOCOL_VERSION,
|
|
364
|
-
card_version: CARD_VERSION,
|
|
365
363
|
name: input.name,
|
|
366
|
-
|
|
364
|
+
description: input.description,
|
|
365
|
+
supported_interfaces: [primaryInterface],
|
|
366
|
+
version: input.version ?? "1.0.0",
|
|
367
|
+
capabilities,
|
|
368
|
+
default_input_modes: input.default_input_modes ?? [DEFAULT_INPUT_MODE],
|
|
369
|
+
default_output_modes: input.default_output_modes ?? [DEFAULT_OUTPUT_MODE],
|
|
370
|
+
skills: input.skills
|
|
367
371
|
};
|
|
368
|
-
if (input.
|
|
369
|
-
if (input.
|
|
370
|
-
if (input.
|
|
371
|
-
if (input.
|
|
372
|
-
if (input.
|
|
372
|
+
if (input.provider !== void 0) card.provider = input.provider;
|
|
373
|
+
if (input.documentation_url !== void 0) card.documentation_url = input.documentation_url;
|
|
374
|
+
if (input.icon_url !== void 0) card.icon_url = input.icon_url;
|
|
375
|
+
if (input.signatures !== void 0 && input.signatures.length > 0) card.signatures = input.signatures;
|
|
376
|
+
if (input.security_schemes !== void 0) card.security_schemes = input.security_schemes;
|
|
377
|
+
if (input.security_requirements !== void 0) card.security_requirements = input.security_requirements;
|
|
378
|
+
if (input.extras) {
|
|
379
|
+
for (const [k, v] of Object.entries(input.extras)) {
|
|
380
|
+
card[k] = v;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
373
383
|
return card;
|
|
374
384
|
}
|
|
375
385
|
|
|
376
386
|
// src/identity/ucp.ts
|
|
377
|
-
function
|
|
387
|
+
function ucpSigningKeyFromJWKImpl(jwk) {
|
|
378
388
|
if (!jwk || typeof jwk !== "object") {
|
|
379
|
-
throw new Error(`
|
|
389
|
+
throw new Error(`UCPSigningKey.fromJWK expected a non-null object; got ${typeof jwk}.`);
|
|
380
390
|
}
|
|
381
391
|
if (typeof jwk.kid !== "string" || !jwk.kid) {
|
|
382
|
-
throw new Error("
|
|
392
|
+
throw new Error("UCPSigningKey.fromJWK: JWK missing required field `kid` (or non-string).");
|
|
383
393
|
}
|
|
384
394
|
if (typeof jwk.kty !== "string" || !jwk.kty) {
|
|
385
|
-
throw new Error("
|
|
395
|
+
throw new Error("UCPSigningKey.fromJWK: JWK missing required field `kty` (or non-string).");
|
|
386
396
|
}
|
|
387
397
|
if (jwk.kty !== "OKP" && jwk.kty !== "EC" && jwk.kty !== "RSA") {
|
|
388
398
|
throw new Error(
|
|
389
|
-
`
|
|
399
|
+
`UCPSigningKey.fromJWK: kty=${JSON.stringify(jwk.kty)} is not a supported asymmetric key type (expected OKP, EC, or RSA). Symmetric \`oct\` keys are rejected because they cannot publicly verify a JWS in the trust-mode UCP flow.`
|
|
390
400
|
);
|
|
391
401
|
}
|
|
392
402
|
if ((jwk.kty === "EC" || jwk.kty === "OKP") && (typeof jwk.crv !== "string" || !jwk.crv)) {
|
|
393
|
-
throw new Error(`
|
|
403
|
+
throw new Error(`UCPSigningKey.fromJWK: kty=${jwk.kty} requires a non-empty \`crv\` field (e.g., "P-256" for EC, "Ed25519" for OKP).`);
|
|
394
404
|
}
|
|
395
405
|
return jwk;
|
|
396
406
|
}
|
|
407
|
+
var UCPSigningKey = {
|
|
408
|
+
fromJWK: ucpSigningKeyFromJWKImpl
|
|
409
|
+
};
|
|
397
410
|
var DEFAULT_VERSION = "2026-04-08";
|
|
398
411
|
var AGENTSCORE_CAPABILITY_NAME = "sh.agentscore.identity";
|
|
399
|
-
var AGENTSCORE_CAPABILITY_VERSION = "
|
|
412
|
+
var AGENTSCORE_CAPABILITY_VERSION = "2026-04-08";
|
|
400
413
|
var AGENTSCORE_DEFAULT_SPEC_URL = "https://agentscore.sh/specification/identity";
|
|
401
414
|
var AGENTSCORE_DEFAULT_SCHEMA_URL = "https://agentscore.sh/schemas/ucp/sh-agentscore-identity-v1.json";
|
|
402
415
|
var AGENTSCORE_EXTENDS = ["dev.ucp.shopping.checkout", "dev.ucp.shopping.cart"];
|
|
@@ -420,44 +433,47 @@ var RESERVED_UCP_FIELDS = /* @__PURE__ */ new Set([
|
|
|
420
433
|
"prototype"
|
|
421
434
|
]);
|
|
422
435
|
function buildUCPProfile(input) {
|
|
436
|
+
for (const [name, bindings] of Object.entries(input.services ?? {})) {
|
|
437
|
+
for (const binding of bindings) {
|
|
438
|
+
if ((binding.transport === "rest" || binding.transport === "mcp" || binding.transport === "a2a") && (binding.endpoint === void 0 || binding.endpoint === null || binding.endpoint === "")) {
|
|
439
|
+
throw new Error(
|
|
440
|
+
`buildUCPProfile: service "${name}" transport=${binding.transport} requires \`endpoint\`. Per UCP spec service.json business_schema, rest/mcp/a2a bindings MUST carry an endpoint URL.`
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const paymentHandlers = {};
|
|
446
|
+
for (const [name, bindings] of Object.entries(input.payment_handlers ?? {})) {
|
|
447
|
+
paymentHandlers[name] = bindings.map((binding) => {
|
|
448
|
+
if (Array.isArray(binding.available_instruments) && binding.available_instruments.length === 0) {
|
|
449
|
+
const { available_instruments: _drop, ...rest } = binding;
|
|
450
|
+
return rest;
|
|
451
|
+
}
|
|
452
|
+
return binding;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
423
455
|
const capabilities = {};
|
|
424
456
|
for (const [name, bindings] of Object.entries(input.capabilities ?? {})) {
|
|
425
457
|
capabilities[name] = [...bindings];
|
|
426
458
|
}
|
|
427
|
-
if (input.
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
verify_url: input.data.verify_url ?? null,
|
|
440
|
-
issuer: "https://agentscore.sh"
|
|
441
|
-
};
|
|
442
|
-
const agentscoreBinding = {
|
|
443
|
-
version: AGENTSCORE_CAPABILITY_VERSION,
|
|
444
|
-
spec: input.agentscore_spec_url ?? AGENTSCORE_DEFAULT_SPEC_URL,
|
|
445
|
-
schema: input.agentscore_schema_url ?? AGENTSCORE_DEFAULT_SCHEMA_URL,
|
|
446
|
-
extends: AGENTSCORE_EXTENDS,
|
|
447
|
-
// `claims` is our vendor extra on the binding; allowed per spec via the
|
|
448
|
-
// `[k: string]: unknown` index signature on UCPCapabilityBinding.
|
|
449
|
-
claims
|
|
450
|
-
};
|
|
451
|
-
const existing = capabilities[AGENTSCORE_CAPABILITY_NAME];
|
|
452
|
-
if (existing) existing.push(agentscoreBinding);
|
|
453
|
-
else capabilities[AGENTSCORE_CAPABILITY_NAME] = [agentscoreBinding];
|
|
454
|
-
}
|
|
459
|
+
if (input.agentscore_gate) {
|
|
460
|
+
const gateConfig = { ...input.agentscore_gate };
|
|
461
|
+
const agentscoreBinding = {
|
|
462
|
+
version: AGENTSCORE_CAPABILITY_VERSION,
|
|
463
|
+
spec: input.agentscore_spec_url ?? AGENTSCORE_DEFAULT_SPEC_URL,
|
|
464
|
+
schema: input.agentscore_schema_url ?? AGENTSCORE_DEFAULT_SCHEMA_URL,
|
|
465
|
+
extends: AGENTSCORE_EXTENDS
|
|
466
|
+
};
|
|
467
|
+
if (Object.keys(gateConfig).length > 0) agentscoreBinding.config = gateConfig;
|
|
468
|
+
const existing = capabilities[AGENTSCORE_CAPABILITY_NAME];
|
|
469
|
+
if (existing) existing.push(agentscoreBinding);
|
|
470
|
+
else capabilities[AGENTSCORE_CAPABILITY_NAME] = [agentscoreBinding];
|
|
455
471
|
}
|
|
456
472
|
const ucp = {
|
|
457
473
|
version: input.version ?? DEFAULT_VERSION,
|
|
458
474
|
services: input.services ?? {},
|
|
459
475
|
capabilities,
|
|
460
|
-
payment_handlers:
|
|
476
|
+
payment_handlers: paymentHandlers
|
|
461
477
|
};
|
|
462
478
|
if (input.name !== void 0) ucp.name = input.name;
|
|
463
479
|
if (input.supported_versions !== void 0) ucp.supported_versions = input.supported_versions;
|
|
@@ -758,7 +774,7 @@ function buildJWKSResponse(keys) {
|
|
|
758
774
|
}
|
|
759
775
|
|
|
760
776
|
// src/identity/policy.ts
|
|
761
|
-
function
|
|
777
|
+
function buildGateOptionsFromPolicy(policy, base) {
|
|
762
778
|
if (!policy || !policy.enforcement) return null;
|
|
763
779
|
return {
|
|
764
780
|
apiKey: base.apiKey,
|
|
@@ -806,11 +822,13 @@ function shippingStateAllowed(state, country, policy) {
|
|
|
806
822
|
export {
|
|
807
823
|
AGENTSCORE_UCP_CAPABILITY,
|
|
808
824
|
FIXABLE_DENIAL_REASONS,
|
|
825
|
+
UCPSigningKey,
|
|
809
826
|
UCPVerificationError,
|
|
810
827
|
UCP_A2A_EXTENSION_URI,
|
|
811
828
|
buildA2AAgentCard,
|
|
812
829
|
buildAgentMemoryHint,
|
|
813
830
|
buildContactSupportNextSteps,
|
|
831
|
+
buildGateOptionsFromPolicy,
|
|
814
832
|
buildJWKSResponse,
|
|
815
833
|
buildSignerMismatchBody,
|
|
816
834
|
buildUCPProfile,
|
|
@@ -820,14 +838,12 @@ export {
|
|
|
820
838
|
extractPaymentSignerAddress,
|
|
821
839
|
generateUCPSigningKey,
|
|
822
840
|
isFixableDenial,
|
|
823
|
-
policyToGateOptions,
|
|
824
841
|
readX402PaymentHeader,
|
|
825
842
|
runGateWithEnforcement,
|
|
826
843
|
shippingCountryAllowed,
|
|
827
844
|
shippingStateAllowed,
|
|
828
845
|
signUCPProfile,
|
|
829
846
|
ucpA2AExtension,
|
|
830
|
-
ucpSigningKeyFromJWK,
|
|
831
847
|
verificationAgentInstructions,
|
|
832
848
|
verifyUCPProfile
|
|
833
849
|
};
|