@agent-score/commerce 1.0.0 → 1.0.2
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/dist/{_response-DmziuJz6.d.mts → _response-DS-LR590.d.mts} +13 -8
- package/dist/{_response-rbK0zM7y.d.ts → _response-RpEB7-vl.d.ts} +13 -8
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/core.js +86 -67
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +86 -67
- package/dist/core.mjs.map +1 -1
- package/dist/discovery/index.js +3 -3
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +3 -3
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.d.mts +1 -1
- package/dist/identity/express.d.ts +1 -1
- package/dist/identity/express.js +120 -71
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +120 -71
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +1 -1
- package/dist/identity/fastify.d.ts +1 -1
- package/dist/identity/fastify.js +120 -71
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +120 -71
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +1 -1
- package/dist/identity/hono.d.ts +1 -1
- package/dist/identity/hono.js +120 -71
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +120 -71
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +1 -1
- package/dist/identity/nextjs.d.ts +1 -1
- package/dist/identity/nextjs.js +120 -71
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +120 -71
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.d.mts +1 -2
- package/dist/identity/policy.d.ts +1 -2
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +1 -1
- package/dist/identity/web.d.ts +1 -1
- package/dist/identity/web.js +120 -71
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +120 -71
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +122 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -81
- package/dist/index.mjs.map +1 -1
- package/dist/stripe-multichain/index.d.mts +3 -3
- package/dist/stripe-multichain/index.d.ts +3 -3
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/identity/web.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-
|
|
1
|
+
export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-DS-LR590.mjs';
|
|
2
2
|
export { e as extractPaymentSignerAddress, r as readX402PaymentHeader } from '../signer-Cvdwn6Cs.mjs';
|
|
3
3
|
import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AgentScoreData, VerifyWalletSignerResult } from '../core.mjs';
|
|
4
4
|
|
package/dist/identity/web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-
|
|
1
|
+
export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-RpEB7-vl.js';
|
|
2
2
|
export { e as extractPaymentSignerAddress, r as readX402PaymentHeader } from '../signer-Cvdwn6Cs.js';
|
|
3
3
|
import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AgentScoreData, VerifyWalletSignerResult } from '../core.js';
|
|
4
4
|
|
package/dist/identity/web.js
CHANGED
|
@@ -38,11 +38,10 @@ module.exports = __toCommonJS(web_exports);
|
|
|
38
38
|
var FIXABLE_DENIAL_REASONS = /* @__PURE__ */ new Set([
|
|
39
39
|
"kyc_required",
|
|
40
40
|
"kyc_pending",
|
|
41
|
-
"kyc_failed"
|
|
42
|
-
"jurisdiction_restricted"
|
|
41
|
+
"kyc_failed"
|
|
43
42
|
]);
|
|
44
43
|
function isFixableDenial(reasons) {
|
|
45
|
-
if (!reasons || reasons.length === 0) return
|
|
44
|
+
if (!reasons || reasons.length === 0) return false;
|
|
46
45
|
return reasons.every((r) => FIXABLE_DENIAL_REASONS.has(r));
|
|
47
46
|
}
|
|
48
47
|
function denialReasonStatus(reason) {
|
|
@@ -115,6 +114,47 @@ function verificationAgentInstructions(input = {}) {
|
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
// src/_response.ts
|
|
117
|
+
var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
|
|
118
|
+
action: "contact_support",
|
|
119
|
+
steps: [
|
|
120
|
+
"The wallet's operator failed an UNFIXABLE compliance check (sanctions, age, or jurisdiction). `reasons` lists which: `sanctions_flagged` / `age_insufficient` / `jurisdiction_restricted`. KYC re-verification won't change the outcome \u2014 the policy denial is structural.",
|
|
121
|
+
"Surface the denial to the user with the merchant's support contact. Do not retry the same merchant request; do not hand the user a verify_url (verification won't fix this code path).",
|
|
122
|
+
"Fixable compliance reasons (`kyc_required`, `kyc_pending`, `kyc_failed`) do NOT land on this code \u2014 the gate auto-mints a verification session for those and returns `identity_verification_required` with poll endpoints, same shape as `missing_identity`. `jurisdiction_restricted` IS in the unfixable bucket because the API only emits it after KYC is verified (the user's KYC'd country is in the blocked list \u2014 re-doing KYC won't change the country)."
|
|
123
|
+
],
|
|
124
|
+
user_message: "This purchase is denied by the merchant's compliance policy and cannot be resolved by re-verifying. Contact the merchant's support if you believe this is in error."
|
|
125
|
+
});
|
|
126
|
+
var PAYMENT_REQUIRED_INSTRUCTIONS = JSON.stringify({
|
|
127
|
+
action: "contact_merchant",
|
|
128
|
+
steps: [
|
|
129
|
+
"The merchant's AgentScore tier does not include the assess feature, so agent identity cannot be evaluated. This is a merchant-side configuration gap \u2014 there is no agent-side recovery.",
|
|
130
|
+
"Contact the merchant (their support channel \u2014 typically listed in /llms.txt or the OpenAPI servers metadata) and request they upgrade their AgentScore plan."
|
|
131
|
+
],
|
|
132
|
+
user_message: "This merchant's identity gate is misconfigured (AgentScore tier doesn't support assess). Contact the merchant \u2014 there's nothing to fix on the agent side."
|
|
133
|
+
});
|
|
134
|
+
var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
|
|
135
|
+
action: "deliver_verify_url_and_poll",
|
|
136
|
+
steps: [
|
|
137
|
+
"Share verify_url with the user \u2014 they complete identity verification on AgentScore.",
|
|
138
|
+
"If session_id + poll_secret are present in the body, poll poll_url every 5 seconds with header `X-Poll-Secret: <poll_secret>` until status=verified. The poll returns a one-time operator_token.",
|
|
139
|
+
"Retry the original request with header `X-Operator-Token: <opc_...>`."
|
|
140
|
+
],
|
|
141
|
+
user_message: "Identity verification is required. Visit verify_url, then poll poll_url for the operator token and retry."
|
|
142
|
+
});
|
|
143
|
+
var TOKEN_EXPIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
|
|
144
|
+
action: "deliver_verify_url_and_poll",
|
|
145
|
+
steps: [
|
|
146
|
+
"The operator token is expired or revoked. AgentScore auto-mints a fresh verification session \u2014 complete it to receive a new opc_...",
|
|
147
|
+
"Share verify_url with the user, then poll poll_url every 5 seconds with header `X-Poll-Secret: <poll_secret>` until status=verified. The poll returns a fresh one-time operator_token.",
|
|
148
|
+
"Retry the original request with header `X-Operator-Token: <new_opc_...>`."
|
|
149
|
+
],
|
|
150
|
+
user_message: "Operator token is expired or revoked. A new verification session has been minted \u2014 visit verify_url to refresh."
|
|
151
|
+
});
|
|
152
|
+
var DEFAULT_AGENT_INSTRUCTIONS = {
|
|
153
|
+
wallet_not_trusted: WALLET_NOT_TRUSTED_INSTRUCTIONS,
|
|
154
|
+
payment_required: PAYMENT_REQUIRED_INSTRUCTIONS,
|
|
155
|
+
identity_verification_required: IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS,
|
|
156
|
+
token_expired: TOKEN_EXPIRED_FALLBACK_INSTRUCTIONS
|
|
157
|
+
};
|
|
118
158
|
var DEFAULT_MESSAGES = {
|
|
119
159
|
missing_identity: "No identity provided. Send X-Wallet-Address (wallet) or X-Operator-Token (credential).",
|
|
120
160
|
identity_verification_required: "Identity verification is required to access this resource. Visit verify_url to complete KYC.",
|
|
@@ -151,7 +191,8 @@ function denialReasonToBody(reason) {
|
|
|
151
191
|
if (reason.session_id) body.session_id = reason.session_id;
|
|
152
192
|
if (reason.poll_secret) body.poll_secret = reason.poll_secret;
|
|
153
193
|
if (reason.poll_url) body.poll_url = reason.poll_url;
|
|
154
|
-
|
|
194
|
+
const instructions = reason.agent_instructions ?? DEFAULT_AGENT_INSTRUCTIONS[reason.code];
|
|
195
|
+
if (instructions) body.agent_instructions = instructions;
|
|
155
196
|
if (reason.agent_memory) body.agent_memory = reason.agent_memory;
|
|
156
197
|
if (reason.claimed_operator) body.claimed_operator = reason.claimed_operator;
|
|
157
198
|
if (reason.code === "wallet_signer_mismatch") body.actual_signer_operator = reason.actual_signer_operator ?? null;
|
|
@@ -301,80 +342,80 @@ function createAgentScoreCore(options) {
|
|
|
301
342
|
} = options;
|
|
302
343
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
303
344
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
304
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
345
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
305
346
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
306
347
|
const API_TIMEOUT_MS = 1e4;
|
|
307
348
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
|
308
|
-
async function
|
|
309
|
-
if (!
|
|
310
|
-
|
|
311
|
-
|
|
349
|
+
async function tryMintSessionDenial(ctx) {
|
|
350
|
+
if (!createSessionOnMissing) return void 0;
|
|
351
|
+
try {
|
|
352
|
+
const sessionBody = {};
|
|
353
|
+
if (createSessionOnMissing.context != null) sessionBody.context = createSessionOnMissing.context;
|
|
354
|
+
if (createSessionOnMissing.productName != null) sessionBody.product_name = createSessionOnMissing.productName;
|
|
355
|
+
if (createSessionOnMissing.getSessionOptions && ctx !== void 0) {
|
|
312
356
|
try {
|
|
313
|
-
const
|
|
314
|
-
if (
|
|
315
|
-
if (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
expires_at: data.expires_at
|
|
351
|
-
};
|
|
352
|
-
const result = await createSessionOnMissing.onBeforeSession(ctx, sessionMeta);
|
|
353
|
-
if (result && typeof result === "object") extra = result;
|
|
354
|
-
} catch (err) {
|
|
355
|
-
console.warn("[gate] createSessionOnMissing.onBeforeSession hook failed:", err instanceof Error ? err.message : err);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
const apiNextSteps = data.next_steps;
|
|
359
|
-
return {
|
|
360
|
-
kind: "deny",
|
|
361
|
-
reason: {
|
|
362
|
-
code: "identity_verification_required",
|
|
363
|
-
verify_url: data.verify_url,
|
|
364
|
-
session_id: data.session_id,
|
|
365
|
-
poll_secret: data.poll_secret,
|
|
366
|
-
poll_url: data.poll_url,
|
|
367
|
-
agent_instructions: apiNextSteps ? JSON.stringify(apiNextSteps) : void 0,
|
|
368
|
-
agent_memory: agentMemoryHint,
|
|
369
|
-
...extra && { extra }
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
}
|
|
357
|
+
const dynamic = await createSessionOnMissing.getSessionOptions(ctx);
|
|
358
|
+
if (dynamic?.context != null) sessionBody.context = dynamic.context;
|
|
359
|
+
if (dynamic?.productName != null) sessionBody.product_name = dynamic.productName;
|
|
360
|
+
} catch (err) {
|
|
361
|
+
console.warn("[gate] createSessionOnMissing.getSessionOptions hook failed:", err instanceof Error ? err.message : err);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const sessionBaseUrl = stripTrailingSlashes(createSessionOnMissing.baseUrl ?? "https://api.agentscore.sh");
|
|
365
|
+
const sessionRes = await fetch(`${sessionBaseUrl}/v1/sessions`, {
|
|
366
|
+
method: "POST",
|
|
367
|
+
headers: {
|
|
368
|
+
"X-API-Key": createSessionOnMissing.apiKey,
|
|
369
|
+
"Content-Type": "application/json",
|
|
370
|
+
Accept: "application/json",
|
|
371
|
+
"User-Agent": userAgentHeader
|
|
372
|
+
},
|
|
373
|
+
body: JSON.stringify(sessionBody),
|
|
374
|
+
signal: AbortSignal.timeout(API_TIMEOUT_MS)
|
|
375
|
+
});
|
|
376
|
+
if (!sessionRes.ok) return void 0;
|
|
377
|
+
const data = await sessionRes.json();
|
|
378
|
+
if (typeof data.session_id !== "string" || typeof data.poll_secret !== "string" || typeof data.verify_url !== "string") {
|
|
379
|
+
console.warn("[gate] /v1/sessions returned 200 without required fields \u2014 falling back to bare denial");
|
|
380
|
+
return void 0;
|
|
381
|
+
}
|
|
382
|
+
let extra;
|
|
383
|
+
if (createSessionOnMissing.onBeforeSession && ctx !== void 0) {
|
|
384
|
+
try {
|
|
385
|
+
const sessionMeta = {
|
|
386
|
+
session_id: data.session_id,
|
|
387
|
+
verify_url: data.verify_url,
|
|
388
|
+
poll_secret: data.poll_secret,
|
|
389
|
+
poll_url: data.poll_url,
|
|
390
|
+
expires_at: data.expires_at
|
|
391
|
+
};
|
|
392
|
+
const result = await createSessionOnMissing.onBeforeSession(ctx, sessionMeta);
|
|
393
|
+
if (result && typeof result === "object") extra = result;
|
|
374
394
|
} catch (err) {
|
|
375
|
-
console.warn("[gate] createSessionOnMissing
|
|
395
|
+
console.warn("[gate] createSessionOnMissing.onBeforeSession hook failed:", err instanceof Error ? err.message : err);
|
|
376
396
|
}
|
|
377
397
|
}
|
|
398
|
+
const apiNextSteps = data.next_steps;
|
|
399
|
+
return {
|
|
400
|
+
code: "identity_verification_required",
|
|
401
|
+
verify_url: data.verify_url,
|
|
402
|
+
session_id: data.session_id,
|
|
403
|
+
poll_secret: data.poll_secret,
|
|
404
|
+
poll_url: data.poll_url,
|
|
405
|
+
agent_instructions: apiNextSteps ? JSON.stringify(apiNextSteps) : void 0,
|
|
406
|
+
agent_memory: agentMemoryHint,
|
|
407
|
+
...extra && { extra }
|
|
408
|
+
};
|
|
409
|
+
} catch (err) {
|
|
410
|
+
console.warn("[gate] createSessionOnMissing path failed \u2014 falling back to bare denial:", err instanceof Error ? err.message : err);
|
|
411
|
+
return void 0;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async function evaluate(identity, ctx) {
|
|
415
|
+
if (!identity || !identity.address && !identity.operatorToken) {
|
|
416
|
+
if (failOpen) return { kind: "allow" };
|
|
417
|
+
const sessionReason = await tryMintSessionDenial(ctx);
|
|
418
|
+
if (sessionReason) return { kind: "deny", reason: sessionReason };
|
|
378
419
|
const missingIdentityInstructions = JSON.stringify({
|
|
379
420
|
action: "probe_identity_then_session",
|
|
380
421
|
steps: [
|
|
@@ -399,6 +440,10 @@ function createAgentScoreCore(options) {
|
|
|
399
440
|
if (cached.allow) {
|
|
400
441
|
return { kind: "allow", data: cached.raw };
|
|
401
442
|
}
|
|
443
|
+
if (isFixableDenial(cached.reasons)) {
|
|
444
|
+
const sessionReason = await tryMintSessionDenial(ctx);
|
|
445
|
+
if (sessionReason) return { kind: "deny", reason: sessionReason };
|
|
446
|
+
}
|
|
402
447
|
return {
|
|
403
448
|
kind: "deny",
|
|
404
449
|
reason: {
|
|
@@ -496,6 +541,10 @@ function createAgentScoreCore(options) {
|
|
|
496
541
|
if (allow) {
|
|
497
542
|
return { kind: "allow", data };
|
|
498
543
|
}
|
|
544
|
+
if (isFixableDenial(decisionReasons)) {
|
|
545
|
+
const sessionReason = await tryMintSessionDenial(ctx);
|
|
546
|
+
if (sessionReason) return { kind: "deny", reason: sessionReason };
|
|
547
|
+
}
|
|
499
548
|
return {
|
|
500
549
|
kind: "deny",
|
|
501
550
|
reason: {
|