@belticlabs/agent-risk-sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/index.d.ts +3 -3
- package/dist/ai/index.js +1 -1
- package/dist/{chunk-GCKCAKHA.js → chunk-46QN2KEZ.js} +199 -33
- package/dist/{chunk-YVMJ5CZX.js → chunk-W2OY7QXV.js} +1 -1
- package/dist/{client-CVx9LgJC.d.ts → client-NxpD_384.d.ts} +4 -3
- package/dist/index-Bjs3BPPU.d.ts +547 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +2 -2
- package/dist/mcp/index.d.ts +5 -4
- package/dist/mcp/index.js +1 -1
- package/dist/{middleware-_DSwvNIx.d.ts → middleware-D-ejQIoE.d.ts} +3 -3
- package/dist/protocol/index.d.ts +158 -0
- package/dist/protocol/index.js +152 -0
- package/dist/seller/anti-fraud-gateway.d.ts +5 -4
- package/dist/seller/anti-fraud-gateway.js +1 -1
- package/dist/{session-BMNB1N1g.d.ts → session-B2mfurae.d.ts} +14 -2
- package/dist/verdict-BAahb5po.d.ts +26 -0
- package/dist/x402/express.d.ts +7 -6
- package/dist/x402/express.js +2 -2
- package/dist/x402/hono.d.ts +7 -6
- package/dist/x402/hono.js +2 -2
- package/dist/x402/index.d.ts +6 -5
- package/dist/x402/index.js +2 -2
- package/package.json +5 -1
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PaymentMomentPayload } from '
|
|
1
|
+
import { P as PaymentMomentPayload } from '../index-Bjs3BPPU.js';
|
|
2
2
|
import { LanguageModelMiddleware, Tool, ToolSet } from 'ai';
|
|
3
|
-
import { S as Session } from '../session-
|
|
4
|
-
import '
|
|
3
|
+
import { S as Session } from '../session-B2mfurae.js';
|
|
4
|
+
import 'zod';
|
|
5
5
|
|
|
6
6
|
interface PaymentMoments {
|
|
7
7
|
requested?: PaymentMomentPayload;
|
package/dist/ai/index.js
CHANGED
|
@@ -1,39 +1,20 @@
|
|
|
1
|
-
// ../protocol/src/verdict.ts
|
|
2
|
-
var SEVERITY = { ALLOW: 0, REVIEW: 1, DENY: 2 };
|
|
3
|
-
var Verdict = class _Verdict {
|
|
4
|
-
constructor(value) {
|
|
5
|
-
this.value = value;
|
|
6
|
-
}
|
|
7
|
-
static ALLOW = new _Verdict("ALLOW");
|
|
8
|
-
static REVIEW = new _Verdict("REVIEW");
|
|
9
|
-
static DENY = new _Verdict("DENY");
|
|
10
|
-
static of(value) {
|
|
11
|
-
return value === "DENY" ? _Verdict.DENY : value === "REVIEW" ? _Verdict.REVIEW : _Verdict.ALLOW;
|
|
12
|
-
}
|
|
13
|
-
/** The more severe of the two. */
|
|
14
|
-
atLeast(other) {
|
|
15
|
-
const o = typeof other === "string" ? _Verdict.of(other) : other;
|
|
16
|
-
return SEVERITY[o.value] > SEVERITY[this.value] ? o : this;
|
|
17
|
-
}
|
|
18
|
-
/** Whether a synchronous gate must stop the call (GAP-52). */
|
|
19
|
-
blocks(onReview) {
|
|
20
|
-
return this.value === "DENY" || this.value === "REVIEW" && onReview === "abort";
|
|
21
|
-
}
|
|
22
|
-
/** What the gate effectively did: DENY when it blocked, else the verdict itself. */
|
|
23
|
-
effective(onReview) {
|
|
24
|
-
return this.blocks(onReview) ? "DENY" : this.value;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// ../protocol/src/api.ts
|
|
29
|
-
import { z as z4 } from "zod";
|
|
30
|
-
|
|
31
1
|
// ../protocol/src/evidence.ts
|
|
32
2
|
import { z } from "zod";
|
|
33
3
|
var WIRE_SOURCES = ["AGENT_TRACE", "INTERNAL_NETWORK"];
|
|
34
4
|
var ALL_SOURCES = ["AGENT_TRACE", "INTERNAL_NETWORK", "PLATFORM"];
|
|
35
5
|
var EvidenceSourceSchema = z.enum(WIRE_SOURCES);
|
|
36
6
|
var EvidenceSourceAllSchema = z.enum(ALL_SOURCES);
|
|
7
|
+
var SOURCE_ORDER = {
|
|
8
|
+
AGENT_TRACE: 0,
|
|
9
|
+
INTERNAL_NETWORK: 1,
|
|
10
|
+
PLATFORM: 2
|
|
11
|
+
};
|
|
12
|
+
function compareBySourceSeq(a, b) {
|
|
13
|
+
return SOURCE_ORDER[a.source] - SOURCE_ORDER[b.source] || a.seq - b.seq;
|
|
14
|
+
}
|
|
15
|
+
function compareBySessionSource(a, b) {
|
|
16
|
+
return a.sessionId < b.sessionId ? -1 : a.sessionId > b.sessionId ? 1 : SOURCE_ORDER[a.source] - SOURCE_ORDER[b.source];
|
|
17
|
+
}
|
|
37
18
|
var WIRE_KINDS = [
|
|
38
19
|
"session.open",
|
|
39
20
|
"session.close",
|
|
@@ -76,11 +57,42 @@ var EvidenceEventSchema = z.strictObject({
|
|
|
76
57
|
prevHash: Hex64Schema,
|
|
77
58
|
sig: SigSchema.optional()
|
|
78
59
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
60
|
+
function isWireKind(kind) {
|
|
61
|
+
return WIRE_KINDS.includes(kind);
|
|
62
|
+
}
|
|
63
|
+
function isPlatformKind(kind) {
|
|
64
|
+
return PLATFORM_KINDS.includes(kind);
|
|
65
|
+
}
|
|
82
66
|
|
|
83
67
|
// ../protocol/src/reason-codes.ts
|
|
68
|
+
var INDICATOR_CODES = [
|
|
69
|
+
"CHAIN_BROKEN",
|
|
70
|
+
"EVIDENCE_MISMATCH",
|
|
71
|
+
"CREDENTIAL_REVOKED",
|
|
72
|
+
"SESSION_INVALID",
|
|
73
|
+
"PRINCIPAL_FLAGGED"
|
|
74
|
+
];
|
|
75
|
+
var ANNOTATION_CODES = ["NO_AGENT_TRACE", "NO_POLICY"];
|
|
76
|
+
var COLLECTOR_CODES = [
|
|
77
|
+
"SCHEMA_INVALID",
|
|
78
|
+
"SESSION_UNKNOWN",
|
|
79
|
+
"SESSION_CLOSED",
|
|
80
|
+
"SESSION_EXPIRED",
|
|
81
|
+
"SOURCE_FORBIDDEN",
|
|
82
|
+
"KIND_FORBIDDEN",
|
|
83
|
+
"SEQ_GAP",
|
|
84
|
+
"PREV_HASH_MISMATCH",
|
|
85
|
+
"SIG_MISSING",
|
|
86
|
+
"SIG_INVALID",
|
|
87
|
+
"PAYLOAD_INVALID",
|
|
88
|
+
"EVENT_TOO_LARGE"
|
|
89
|
+
];
|
|
90
|
+
var DEFAULT_RULE_CODES = [
|
|
91
|
+
"CAP_EXCEEDED",
|
|
92
|
+
"PAYEE_NOT_ALLOWED",
|
|
93
|
+
"NO_INTENT",
|
|
94
|
+
"INTENT_EXPIRED"
|
|
95
|
+
];
|
|
84
96
|
var REASON_CODE_PATTERN = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
85
97
|
|
|
86
98
|
// ../protocol/src/selector.ts
|
|
@@ -180,6 +192,40 @@ function parseSelector(input) {
|
|
|
180
192
|
"unknown root (payment | intent | session | signal[name=\u2026] | evidence[\u2026])"
|
|
181
193
|
);
|
|
182
194
|
}
|
|
195
|
+
function formatSelector(sel) {
|
|
196
|
+
const path = sel.path.map((p) => "key" in p ? `.${p.key}` : `[${p.index}]`).join("");
|
|
197
|
+
switch (sel.root) {
|
|
198
|
+
case "payment":
|
|
199
|
+
case "intent":
|
|
200
|
+
case "session":
|
|
201
|
+
return `${sel.root}${path}`;
|
|
202
|
+
case "signal":
|
|
203
|
+
return `signal[name=${sel.name}]${path}`;
|
|
204
|
+
case "evidence":
|
|
205
|
+
if (sel.kind === "*") return `evidence[*]${path}`;
|
|
206
|
+
return `evidence[kind=${sel.kind}${sel.source ? `,source=${sel.source}` : ""}]${sel.all ? "[*]" : ""}${path}`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function isSelectorRef(value) {
|
|
210
|
+
return typeof value === "string" && value.startsWith("@") && value.length > 1;
|
|
211
|
+
}
|
|
212
|
+
function parseSelectorRef(ref) {
|
|
213
|
+
return parseSelector(ref.slice(1));
|
|
214
|
+
}
|
|
215
|
+
function walkPath(value, path) {
|
|
216
|
+
let cur = value;
|
|
217
|
+
for (const seg of path) {
|
|
218
|
+
if (cur === null || cur === void 0) return void 0;
|
|
219
|
+
if ("key" in seg) {
|
|
220
|
+
if (typeof cur !== "object" || Array.isArray(cur)) return void 0;
|
|
221
|
+
cur = cur[seg.key];
|
|
222
|
+
} else {
|
|
223
|
+
if (!Array.isArray(cur)) return void 0;
|
|
224
|
+
cur = cur[seg.index];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return cur;
|
|
228
|
+
}
|
|
183
229
|
var SelectorStringSchema = z2.string().refine(
|
|
184
230
|
(s) => {
|
|
185
231
|
try {
|
|
@@ -193,6 +239,7 @@ var SelectorStringSchema = z2.string().refine(
|
|
|
193
239
|
);
|
|
194
240
|
|
|
195
241
|
// ../protocol/src/policy.ts
|
|
242
|
+
import { z as z3 } from "zod";
|
|
196
243
|
var PRIMITIVES = ["THRESHOLD", "MEMBERSHIP", "MATCH", "PRESENCE", "FRESHNESS"];
|
|
197
244
|
var PrimitiveSchema = z3.enum(PRIMITIVES);
|
|
198
245
|
var RuleVerdictSchema = z3.enum(["DENY", "REVIEW"]);
|
|
@@ -216,6 +263,7 @@ var PolicyRulesSchema = z3.strictObject({
|
|
|
216
263
|
});
|
|
217
264
|
|
|
218
265
|
// ../protocol/src/api.ts
|
|
266
|
+
import { z as z4 } from "zod";
|
|
219
267
|
var AmountSchema = z4.strictObject({
|
|
220
268
|
/** Decimal string — never a float. For x402 this is the atomic amount (GAP-49). */
|
|
221
269
|
value: z4.string().regex(/^\d+(\.\d+)?$/, "expected a decimal string"),
|
|
@@ -395,7 +443,125 @@ var PlatformAnomalyPayloadSchema = z5.looseObject({
|
|
|
395
443
|
seq: z5.number().int().min(0).nullable(),
|
|
396
444
|
detail: JsonRecord
|
|
397
445
|
});
|
|
446
|
+
var REGISTRY = {
|
|
447
|
+
"session.open": SessionOpenPayloadSchema,
|
|
448
|
+
"session.close": SessionClosePayloadSchema,
|
|
449
|
+
"intent.declared": IntentDeclaredPayloadSchema,
|
|
450
|
+
"llm_call.start": LlmCallStartPayloadSchema,
|
|
451
|
+
"llm_call.end": LlmCallEndPayloadSchema,
|
|
452
|
+
"tool_call.start": ToolCallStartPayloadSchema,
|
|
453
|
+
"tool_call.end": ToolCallEndPayloadSchema,
|
|
454
|
+
"payment.requested": PaymentMomentPayloadSchema,
|
|
455
|
+
"payment.presented": PaymentMomentPayloadSchema,
|
|
456
|
+
"gateway.decision": GatewayDecisionPayloadSchema,
|
|
457
|
+
"transport.gap": TransportGapPayloadSchema,
|
|
458
|
+
"platform.observation": PlatformObservationPayloadSchema,
|
|
459
|
+
"platform.anomaly": PlatformAnomalyPayloadSchema
|
|
460
|
+
};
|
|
461
|
+
function payloadSchemaFor(kind) {
|
|
462
|
+
return REGISTRY[kind];
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ../protocol/src/verdict.ts
|
|
466
|
+
var SEVERITY = { ALLOW: 0, REVIEW: 1, DENY: 2 };
|
|
467
|
+
var Verdict = class _Verdict {
|
|
468
|
+
constructor(value) {
|
|
469
|
+
this.value = value;
|
|
470
|
+
}
|
|
471
|
+
static ALLOW = new _Verdict("ALLOW");
|
|
472
|
+
static REVIEW = new _Verdict("REVIEW");
|
|
473
|
+
static DENY = new _Verdict("DENY");
|
|
474
|
+
static of(value) {
|
|
475
|
+
return value === "DENY" ? _Verdict.DENY : value === "REVIEW" ? _Verdict.REVIEW : _Verdict.ALLOW;
|
|
476
|
+
}
|
|
477
|
+
/** The more severe of the two. */
|
|
478
|
+
atLeast(other) {
|
|
479
|
+
const o = typeof other === "string" ? _Verdict.of(other) : other;
|
|
480
|
+
return SEVERITY[o.value] > SEVERITY[this.value] ? o : this;
|
|
481
|
+
}
|
|
482
|
+
/** Whether a synchronous gate must stop the call (GAP-52). */
|
|
483
|
+
blocks(onReview) {
|
|
484
|
+
return this.value === "DENY" || this.value === "REVIEW" && onReview === "abort";
|
|
485
|
+
}
|
|
486
|
+
/** What the gate effectively did: DENY when it blocked, else the verdict itself. */
|
|
487
|
+
effective(onReview) {
|
|
488
|
+
return this.blocks(onReview) ? "DENY" : this.value;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
398
491
|
|
|
399
492
|
export {
|
|
493
|
+
WIRE_SOURCES,
|
|
494
|
+
ALL_SOURCES,
|
|
495
|
+
EvidenceSourceSchema,
|
|
496
|
+
EvidenceSourceAllSchema,
|
|
497
|
+
SOURCE_ORDER,
|
|
498
|
+
compareBySourceSeq,
|
|
499
|
+
compareBySessionSource,
|
|
500
|
+
WIRE_KINDS,
|
|
501
|
+
PLATFORM_KINDS,
|
|
502
|
+
WireEvidenceKindSchema,
|
|
503
|
+
PlatformEvidenceKindSchema,
|
|
504
|
+
EvidenceKindSchema,
|
|
505
|
+
Hex64Schema,
|
|
506
|
+
SigSchema,
|
|
507
|
+
SessionIdSchema,
|
|
508
|
+
SeqSchema,
|
|
509
|
+
TimestampSchema,
|
|
510
|
+
JsonValueSchema,
|
|
511
|
+
EvidenceEventSchema,
|
|
512
|
+
isWireKind,
|
|
513
|
+
isPlatformKind,
|
|
514
|
+
INDICATOR_CODES,
|
|
515
|
+
ANNOTATION_CODES,
|
|
516
|
+
COLLECTOR_CODES,
|
|
517
|
+
DEFAULT_RULE_CODES,
|
|
518
|
+
REASON_CODE_PATTERN,
|
|
519
|
+
SelectorSyntaxError,
|
|
520
|
+
parseSelector,
|
|
521
|
+
formatSelector,
|
|
522
|
+
isSelectorRef,
|
|
523
|
+
parseSelectorRef,
|
|
524
|
+
walkPath,
|
|
525
|
+
SelectorStringSchema,
|
|
526
|
+
PRIMITIVES,
|
|
527
|
+
PrimitiveSchema,
|
|
528
|
+
RuleVerdictSchema,
|
|
529
|
+
RuleSchema,
|
|
530
|
+
PolicyRulesSchema,
|
|
531
|
+
AmountSchema,
|
|
532
|
+
DeclaredIntentSchema,
|
|
533
|
+
CreateSessionInputSchema,
|
|
534
|
+
CreateSessionOutputSchema,
|
|
535
|
+
MAX_BATCH_EVENTS,
|
|
536
|
+
EvidenceBatchInputSchema,
|
|
537
|
+
EventResultStatusSchema,
|
|
538
|
+
EventResultSchema,
|
|
539
|
+
ChainHeadSchema,
|
|
540
|
+
EvidenceAckSchema,
|
|
541
|
+
PaymentSummarySchema,
|
|
542
|
+
EvaluateInputSchema,
|
|
543
|
+
DecisionSchema,
|
|
544
|
+
EvaluateOutputSchema,
|
|
545
|
+
AnchorEntrySchema,
|
|
546
|
+
AnchorsOutputSchema,
|
|
547
|
+
CreatePolicyInputSchema,
|
|
548
|
+
CreatePolicyOutputSchema,
|
|
549
|
+
ApiErrorSchema,
|
|
550
|
+
SessionOpenPayloadSchema,
|
|
551
|
+
SESSION_CLOSE_REASONS,
|
|
552
|
+
SessionClosePayloadSchema,
|
|
553
|
+
IntentDeclaredPayloadSchema,
|
|
554
|
+
LlmCallStartPayloadSchema,
|
|
555
|
+
LlmCallEndPayloadSchema,
|
|
556
|
+
ToolCallStartPayloadSchema,
|
|
557
|
+
ToolCallEndPayloadSchema,
|
|
558
|
+
PAYMENT_ARTIFACTS,
|
|
559
|
+
PaymentMomentPayloadSchema,
|
|
560
|
+
GatewayDecisionPayloadSchema,
|
|
561
|
+
TransportGapPayloadSchema,
|
|
562
|
+
PlatformObservationPayloadSchema,
|
|
563
|
+
ANOMALY_TYPES,
|
|
564
|
+
PlatformAnomalyPayloadSchema,
|
|
565
|
+
payloadSchemaFor,
|
|
400
566
|
Verdict
|
|
401
567
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as PaymentSummary, B as EvaluateOutput } from './index-Bjs3BPPU.js';
|
|
2
|
+
import { O as OnReview } from './verdict-BAahb5po.js';
|
|
3
|
+
import { a as ApiClient, T as Transport, d as Sessions, A as AgentIdentity, b as ApiClientOptions, g as TransportOptions, R as RedactFn } from './session-B2mfurae.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Correlation without binding (Fraud SDK RFC › Protocol Adapter — x402:
|
|
@@ -34,7 +35,7 @@ declare class MemoryCorrelationStore implements CorrelationStore {
|
|
|
34
35
|
* Neither half decides risk locally: verdicts are platform-side.
|
|
35
36
|
*/
|
|
36
37
|
|
|
37
|
-
declare const SDK_VERSION = "0.1.
|
|
38
|
+
declare const SDK_VERSION = "0.1.1";
|
|
38
39
|
interface BelticOptions extends Omit<ApiClientOptions, 'userAgent'> {
|
|
39
40
|
/** Buyer half. Without it, `sessions.start` is unavailable; the seller half works. */
|
|
40
41
|
identity?: AgentIdentity | undefined;
|