@belticlabs/agent-risk-sdk 0.5.0 → 0.7.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/dist/ai/index.d.ts +6 -16
- package/dist/ai/index.js +30 -41
- package/dist/{chunk-4BUUPU3O.js → chunk-FNU4CRJJ.js} +218 -229
- package/dist/{chunk-GM4KEEZB.js → chunk-HI656UWG.js} +34 -55
- package/dist/chunk-JGVVQUXQ.js +38 -0
- package/dist/chunk-M4I3FGZG.js +13 -0
- package/dist/{chunk-X3W2Z5GC.js → chunk-UXXSE643.js} +25 -23
- package/dist/client-Xn9M58OJ.d.ts +71 -0
- package/dist/{verdict-DMnbFuS5.d.ts → index-DAVKGJs5.d.ts} +129 -162
- package/dist/index.d.ts +3 -2
- package/dist/index.js +714 -190
- package/dist/protocol/index.d.ts +66 -22
- package/dist/protocol/index.js +19 -85
- package/dist/session-DAN29XoB.d.ts +380 -0
- package/dist/x402/hono.d.ts +5 -17
- package/dist/x402/hono.js +8 -14
- package/dist/x402/index.d.ts +11 -43
- package/dist/x402/index.js +42 -53
- package/package.json +1 -1
- package/dist/adapter-DEdhsNt-.d.ts +0 -22
- package/dist/chunk-JSE6JQJC.js +0 -530
- package/dist/session-D9E-efc0.d.ts +0 -462
|
@@ -12,6 +12,21 @@ var SOURCE_ORDER = {
|
|
|
12
12
|
function compareBySourceSeq(a, b) {
|
|
13
13
|
return SOURCE_ORDER[a.source] - SOURCE_ORDER[b.source] || a.seq - b.seq;
|
|
14
14
|
}
|
|
15
|
+
function chainKey(sessionId, source) {
|
|
16
|
+
return `${sessionId}:${source}`;
|
|
17
|
+
}
|
|
18
|
+
function compareByArrival(a, b) {
|
|
19
|
+
return a.ts.localeCompare(b.ts) || a.receivedAt.localeCompare(b.receivedAt) || a.sessionId.localeCompare(b.sessionId) || compareBySourceSeq(a, b);
|
|
20
|
+
}
|
|
21
|
+
function compareRootFirst(conversationId) {
|
|
22
|
+
return (a, b) => Number(b.id === conversationId) - Number(a.id === conversationId);
|
|
23
|
+
}
|
|
24
|
+
function withinHeads(heads) {
|
|
25
|
+
return (e) => {
|
|
26
|
+
const cap = heads[chainKey(e.sessionId, e.source)];
|
|
27
|
+
return cap !== void 0 && e.seq <= cap;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
15
30
|
function compareBySessionSource(a, b) {
|
|
16
31
|
return a.sessionId < b.sessionId ? -1 : a.sessionId > b.sessionId ? 1 : SOURCE_ORDER[a.source] - SOURCE_ORDER[b.source];
|
|
17
32
|
}
|
|
@@ -34,7 +49,12 @@ var PlatformEvidenceKindSchema = z.enum(PLATFORM_KINDS);
|
|
|
34
49
|
var EvidenceKindSchema = z.enum([...WIRE_KINDS, ...PLATFORM_KINDS]);
|
|
35
50
|
var Hex64Schema = z.string().regex(/^[0-9a-f]{64}$/, "expected 64 lowercase hex chars");
|
|
36
51
|
var SigSchema = z.string().regex(/^ed25519:[A-Za-z0-9_-]{86}$/, "expected ed25519:<base64url>");
|
|
37
|
-
var
|
|
52
|
+
var SESSION_ID_PREFIX = "sess_";
|
|
53
|
+
var SESSION_ID_CHARS = 22;
|
|
54
|
+
var SessionIdSchema = z.string().regex(
|
|
55
|
+
new RegExp(`^${SESSION_ID_PREFIX}[0-9A-Za-z]{${SESSION_ID_CHARS}}$`),
|
|
56
|
+
`expected ${SESSION_ID_PREFIX} followed by ${SESSION_ID_CHARS} base62 chars`
|
|
57
|
+
);
|
|
38
58
|
var SeqSchema = z.number().int().min(0);
|
|
39
59
|
var TimestampSchema = z.iso.datetime({ offset: false });
|
|
40
60
|
var JsonValueSchema = z.lazy(
|
|
@@ -57,46 +77,99 @@ var EvidenceEventSchema = z.strictObject({
|
|
|
57
77
|
prevHash: Hex64Schema,
|
|
58
78
|
sig: SigSchema.optional()
|
|
59
79
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
|
|
81
|
+
// ../protocol/src/money.ts
|
|
82
|
+
import { z as z2 } from "zod";
|
|
83
|
+
var DecimalStringSchema = z2.string().regex(/^\d+(\.\d+)?$/, "expected a decimal string");
|
|
84
|
+
var AmountSchema = z2.strictObject({
|
|
85
|
+
/** Decimal string — never a float. For x402 this is the atomic amount (GAP-49). */
|
|
86
|
+
value: DecimalStringSchema,
|
|
87
|
+
/** ISO code, or `<network>/<asset>` for on-chain rails (GAP-49). */
|
|
88
|
+
currency: z2.string().min(1).max(128)
|
|
89
|
+
});
|
|
90
|
+
var ComparableSchema = z2.union([
|
|
91
|
+
DecimalStringSchema.transform((value) => ({ value, currency: null })),
|
|
92
|
+
z2.number().finite().transform(String).pipe(DecimalStringSchema).transform((value) => ({ value, currency: null })),
|
|
93
|
+
z2.object({ value: DecimalStringSchema, currency: z2.string().optional() }).transform((a) => ({ value: a.value, currency: a.currency ?? null }))
|
|
94
|
+
]);
|
|
95
|
+
var Money = class _Money {
|
|
96
|
+
constructor(value, currency) {
|
|
97
|
+
this.value = value;
|
|
98
|
+
this.currency = currency;
|
|
99
|
+
}
|
|
100
|
+
static of(amount) {
|
|
101
|
+
return new _Money(DecimalStringSchema.parse(amount.value), amount.currency);
|
|
102
|
+
}
|
|
103
|
+
/** A decimal with no currency: a bound in a rule, a running total. */
|
|
104
|
+
static bare(value) {
|
|
105
|
+
return new _Money(DecimalStringSchema.parse(value), null);
|
|
106
|
+
}
|
|
107
|
+
/** An x402 amount: atomic units of `asset` on `network`, its currency `<network>/<asset>` (GAP-49). */
|
|
108
|
+
static x402(network, asset, atomic) {
|
|
109
|
+
return new _Money(
|
|
110
|
+
DecimalStringSchema.parse(atomic.toString()),
|
|
111
|
+
_Money.x402Currency(network, asset)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
static x402Currency(network, asset) {
|
|
115
|
+
return `${network}/${asset}`;
|
|
116
|
+
}
|
|
117
|
+
/** Anything a selector or a rule param may resolve to; null when it is not an amount. */
|
|
118
|
+
static parse(v) {
|
|
119
|
+
const r = ComparableSchema.safeParse(v);
|
|
120
|
+
return r.success ? new _Money(r.data.value, r.data.currency) : null;
|
|
121
|
+
}
|
|
122
|
+
comparable(other) {
|
|
123
|
+
return this.currency === null || other.currency === null || this.currency === other.currency;
|
|
124
|
+
}
|
|
125
|
+
compareTo(other) {
|
|
126
|
+
const [a, b] = _Money.scaled(this.value, other.value);
|
|
127
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
128
|
+
}
|
|
129
|
+
exceeds(other) {
|
|
130
|
+
return this.compareTo(other) > 0;
|
|
131
|
+
}
|
|
132
|
+
plus(other) {
|
|
133
|
+
const [a, b, scale] = _Money.scaled(this.value, other.value);
|
|
134
|
+
const digits = (a + b).toString().padStart(scale + 1, "0");
|
|
135
|
+
const int = digits.slice(0, digits.length - scale);
|
|
136
|
+
const frac = digits.slice(digits.length - scale);
|
|
137
|
+
return new _Money(scale ? `${int}.${frac}` : int, this.currency);
|
|
138
|
+
}
|
|
139
|
+
isZero() {
|
|
140
|
+
return this.toNumber() === 0;
|
|
141
|
+
}
|
|
142
|
+
/** Numeric view for ratios; precision loss is acceptable for a ratio. */
|
|
143
|
+
toNumber() {
|
|
144
|
+
return Number(this.value);
|
|
145
|
+
}
|
|
146
|
+
/** this / other, or null when `other` is zero. */
|
|
147
|
+
ratioTo(other) {
|
|
148
|
+
return other.isZero() ? null : this.toNumber() / other.toNumber();
|
|
149
|
+
}
|
|
150
|
+
toAmount() {
|
|
151
|
+
if (this.currency === null) throw new TypeError("an amount needs a currency");
|
|
152
|
+
return { value: this.value, currency: this.currency };
|
|
153
|
+
}
|
|
154
|
+
static scaled(a, b) {
|
|
155
|
+
const [ai, af = ""] = a.split(".");
|
|
156
|
+
const [bi, bf = ""] = b.split(".");
|
|
157
|
+
const scale = Math.max(af.length, bf.length);
|
|
158
|
+
return [
|
|
159
|
+
BigInt(`${ai}${af.padEnd(scale, "0")}`),
|
|
160
|
+
BigInt(`${bi}${bf.padEnd(scale, "0")}`),
|
|
161
|
+
scale
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
};
|
|
66
165
|
|
|
67
166
|
// ../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
|
-
];
|
|
167
|
+
var INDICATOR_CODES = ["CHAIN_BROKEN", "EVIDENCE_MISMATCH", "SESSION_INVALID"];
|
|
75
168
|
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
|
-
];
|
|
96
169
|
var REASON_CODE_PATTERN = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
97
170
|
|
|
98
171
|
// ../protocol/src/selector.ts
|
|
99
|
-
import { z as
|
|
172
|
+
import { z as z3 } from "zod";
|
|
100
173
|
var SelectorSyntaxError = class extends Error {
|
|
101
174
|
constructor(input, at, detail) {
|
|
102
175
|
super(`invalid selector "${input}" at ${at}: ${detail}`);
|
|
@@ -192,20 +265,6 @@ function parseSelector(input) {
|
|
|
192
265
|
"unknown root (payment | intent | session | signal[name=\u2026] | evidence[\u2026])"
|
|
193
266
|
);
|
|
194
267
|
}
|
|
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
268
|
function isSelectorRef(value) {
|
|
210
269
|
return typeof value === "string" && value.startsWith("@") && value.length > 1;
|
|
211
270
|
}
|
|
@@ -226,7 +285,7 @@ function walkPath(value, path) {
|
|
|
226
285
|
}
|
|
227
286
|
return cur;
|
|
228
287
|
}
|
|
229
|
-
var SelectorStringSchema =
|
|
288
|
+
var SelectorStringSchema = z3.string().refine(
|
|
230
289
|
(s) => {
|
|
231
290
|
try {
|
|
232
291
|
parseSelector(s);
|
|
@@ -239,156 +298,126 @@ var SelectorStringSchema = z2.string().refine(
|
|
|
239
298
|
);
|
|
240
299
|
|
|
241
300
|
// ../protocol/src/policy.ts
|
|
242
|
-
import { z as
|
|
243
|
-
var
|
|
244
|
-
var
|
|
245
|
-
var
|
|
246
|
-
|
|
247
|
-
id: z3.string().min(1).max(64),
|
|
301
|
+
import { z as z4 } from "zod";
|
|
302
|
+
var PrimitiveSchema = z4.enum(["THRESHOLD", "MEMBERSHIP", "MATCH", "PRESENCE", "FRESHNESS"]);
|
|
303
|
+
var RuleVerdictSchema = z4.enum(["DENY", "REVIEW"]);
|
|
304
|
+
var RuleSchema = z4.strictObject({
|
|
305
|
+
id: z4.string().min(1).max(64),
|
|
248
306
|
primitive: PrimitiveSchema,
|
|
249
307
|
selector: SelectorStringSchema,
|
|
250
|
-
params:
|
|
308
|
+
params: z4.record(z4.string(), JsonValueSchema),
|
|
251
309
|
onFail: RuleVerdictSchema,
|
|
252
310
|
/** What to do when the selector (or a `@ref`) resolves to nothing. Default: skip (GAP-44). */
|
|
253
|
-
onMissing:
|
|
311
|
+
onMissing: z4.enum(["skip", "DENY", "REVIEW"]).optional(),
|
|
254
312
|
/** Reason code surfaced to the caller when the rule fails (GAP-44). */
|
|
255
|
-
code:
|
|
313
|
+
code: z4.string().regex(REASON_CODE_PATTERN)
|
|
256
314
|
});
|
|
257
|
-
var PolicyRulesSchema =
|
|
258
|
-
rules:
|
|
315
|
+
var PolicyRulesSchema = z4.strictObject({
|
|
316
|
+
rules: z4.array(RuleSchema).max(200).refine((rules) => new Set(rules.map((r) => r.id)).size === rules.length, {
|
|
259
317
|
message: "rule ids must be unique"
|
|
260
|
-
})
|
|
261
|
-
/** Domain-score thresholds — the only configurable part of the scores layer. */
|
|
262
|
-
scoreThresholds: z3.record(z3.string(), z3.number().min(0).max(1)).optional()
|
|
318
|
+
})
|
|
263
319
|
});
|
|
264
320
|
|
|
265
321
|
// ../protocol/src/api.ts
|
|
266
|
-
import { z as
|
|
267
|
-
var
|
|
268
|
-
|
|
269
|
-
value: z4.string().regex(/^\d+(\.\d+)?$/, "expected a decimal string"),
|
|
270
|
-
/** ISO code, or `<network>/<asset>` for on-chain rails (GAP-49). */
|
|
271
|
-
currency: z4.string().min(1).max(128)
|
|
272
|
-
});
|
|
273
|
-
var DeclaredIntentSchema = z4.strictObject({
|
|
274
|
-
mandate: z4.string().min(1).max(4e3),
|
|
322
|
+
import { z as z5 } from "zod";
|
|
323
|
+
var DeclaredIntentSchema = z5.strictObject({
|
|
324
|
+
mandate: z5.string().min(1).max(4e3),
|
|
275
325
|
maxAmount: AmountSchema.optional(),
|
|
276
|
-
merchantAllowlist:
|
|
326
|
+
merchantAllowlist: z5.array(z5.string().min(1)).optional(),
|
|
277
327
|
validUntil: TimestampSchema
|
|
278
328
|
});
|
|
279
|
-
var CreateSessionInputSchema =
|
|
329
|
+
var CreateSessionInputSchema = z5.strictObject({
|
|
280
330
|
source: EvidenceSourceSchema,
|
|
281
|
-
/** Buyer-born sessions. `credential` is
|
|
282
|
-
agent:
|
|
283
|
-
intent: DeclaredIntentSchema.optional()
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
expiresAt: TimestampSchema
|
|
288
|
-
});
|
|
331
|
+
/** Buyer-born sessions. `credential` is accepted and not kept: the DID is the credential (GAP-11). */
|
|
332
|
+
agent: z5.strictObject({ did: z5.string().min(1), credential: z5.string().min(1) }).optional(),
|
|
333
|
+
intent: DeclaredIntentSchema.optional(),
|
|
334
|
+
/** Any session of a conversation to continue: the new session joins it as a fresh chain (GAP-84). AGENT_TRACE only. */
|
|
335
|
+
resume: SessionIdSchema.optional()
|
|
336
|
+
}).describe("session input");
|
|
289
337
|
var MAX_BATCH_EVENTS = 500;
|
|
290
|
-
var EvidenceBatchInputSchema =
|
|
291
|
-
var
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
sessionId: SessionIdSchema.nullable(),
|
|
295
|
-
source: EvidenceSourceSchema.nullable(),
|
|
296
|
-
seq: z4.number().int().min(0).nullable(),
|
|
297
|
-
status: EventResultStatusSchema,
|
|
298
|
-
code: z4.string().optional(),
|
|
299
|
-
eventDigest: Hex64Schema.optional()
|
|
300
|
-
});
|
|
301
|
-
var ChainHeadSchema = z4.strictObject({
|
|
302
|
-
seq: z4.number().int().min(0),
|
|
303
|
-
digest: Hex64Schema
|
|
304
|
-
});
|
|
305
|
-
var EvidenceAckSchema = z4.strictObject({
|
|
306
|
-
results: z4.array(EventResultSchema),
|
|
307
|
-
/** Head of every chain touched by the batch, after the batch. Keyed `sessionId:source`. */
|
|
308
|
-
heads: z4.record(z4.string(), ChainHeadSchema)
|
|
309
|
-
});
|
|
310
|
-
var PaymentSummarySchema = z4.strictObject({
|
|
311
|
-
protocol: z4.string().min(1),
|
|
312
|
-
payee: z4.string().min(1),
|
|
338
|
+
var EvidenceBatchInputSchema = z5.array(z5.unknown()).min(1).max(MAX_BATCH_EVENTS).describe("evidence batch");
|
|
339
|
+
var PaymentSummarySchema = z5.strictObject({
|
|
340
|
+
protocol: z5.string().min(1),
|
|
341
|
+
payee: z5.string().min(1),
|
|
313
342
|
amount: AmountSchema,
|
|
314
343
|
/** Not in the RFC; needed by `principal-links` and `EVIDENCE_MISMATCH` (GAP-06). */
|
|
315
|
-
payer:
|
|
316
|
-
});
|
|
317
|
-
var EvaluateInputSchema = z4.strictObject({
|
|
318
|
-
sessionId: SessionIdSchema,
|
|
319
|
-
payment: PaymentSummarySchema
|
|
344
|
+
payer: z5.string().min(1).optional()
|
|
320
345
|
});
|
|
321
|
-
var
|
|
322
|
-
var EvaluateOutputSchema = z4.strictObject({
|
|
323
|
-
decision: DecisionSchema,
|
|
324
|
-
reasonCodes: z4.array(z4.string().regex(REASON_CODE_PATTERN)),
|
|
346
|
+
var EvaluateInputSchema = z5.strictObject({
|
|
325
347
|
sessionId: SessionIdSchema,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
var ApiErrorSchema = z4.strictObject({
|
|
336
|
-
error: z4.strictObject({
|
|
337
|
-
code: z4.string().min(1),
|
|
338
|
-
message: z4.string().min(1),
|
|
348
|
+
payment: PaymentSummarySchema,
|
|
349
|
+
/** The caller's own id for the call under decision: the same id within one conversation reads the decision already taken (GAP-84). */
|
|
350
|
+
callId: z5.string().min(1).max(256).optional()
|
|
351
|
+
}).describe("evaluate input");
|
|
352
|
+
var CreatePolicyInputSchema = z5.strictObject({ rules: PolicyRulesSchema }).describe("policy input");
|
|
353
|
+
var ApiErrorSchema = z5.strictObject({
|
|
354
|
+
error: z5.strictObject({
|
|
355
|
+
code: z5.string().min(1),
|
|
356
|
+
message: z5.string().min(1),
|
|
339
357
|
details: JsonValueSchema.optional(),
|
|
340
|
-
request_id:
|
|
358
|
+
request_id: z5.string().optional()
|
|
341
359
|
})
|
|
342
360
|
});
|
|
343
361
|
|
|
344
362
|
// ../protocol/src/payloads/index.ts
|
|
345
|
-
import { z as
|
|
363
|
+
import { z as z6 } from "zod";
|
|
346
364
|
var Json = JsonValueSchema;
|
|
347
|
-
var JsonRecord =
|
|
348
|
-
var SessionOpenPayloadSchema =
|
|
349
|
-
runtime:
|
|
350
|
-
sdk:
|
|
351
|
-
version:
|
|
352
|
-
framework:
|
|
353
|
-
model:
|
|
365
|
+
var JsonRecord = z6.record(z6.string(), Json);
|
|
366
|
+
var SessionOpenPayloadSchema = z6.looseObject({
|
|
367
|
+
runtime: z6.looseObject({
|
|
368
|
+
sdk: z6.string().min(1),
|
|
369
|
+
version: z6.string().min(1),
|
|
370
|
+
framework: z6.string().optional(),
|
|
371
|
+
model: z6.string().optional()
|
|
354
372
|
}),
|
|
355
373
|
/** Runtime / repo attestations read by the (staged) Attestation Assurance score. */
|
|
356
374
|
attestations: JsonRecord.optional()
|
|
357
375
|
});
|
|
358
376
|
var SESSION_CLOSE_REASONS = ["completed", "settled", "aborted", "expired"];
|
|
359
|
-
var SessionClosePayloadSchema =
|
|
360
|
-
reason:
|
|
361
|
-
transaction:
|
|
377
|
+
var SessionClosePayloadSchema = z6.looseObject({
|
|
378
|
+
reason: z6.enum(SESSION_CLOSE_REASONS),
|
|
379
|
+
transaction: z6.string().optional()
|
|
362
380
|
});
|
|
363
381
|
var IntentDeclaredPayloadSchema = DeclaredIntentSchema.loose();
|
|
364
|
-
var
|
|
365
|
-
|
|
382
|
+
var PromptDeltaSchema = z6.strictObject({
|
|
383
|
+
prior: z6.string().min(1),
|
|
384
|
+
shared: z6.number().int().min(0),
|
|
385
|
+
messages: z6.array(Json)
|
|
386
|
+
});
|
|
387
|
+
var LlmCallParamsSchema = z6.looseObject({
|
|
388
|
+
prompt: Json.optional(),
|
|
389
|
+
promptDelta: PromptDeltaSchema.optional()
|
|
390
|
+
}).refine((p) => p.prompt === void 0 || p.promptDelta === void 0, {
|
|
391
|
+
message: "params carries prompt or promptDelta, not both"
|
|
392
|
+
});
|
|
393
|
+
var LlmCallStartPayloadSchema = z6.looseObject({
|
|
394
|
+
callId: z6.string().min(1),
|
|
366
395
|
// GAP-07
|
|
367
|
-
provider:
|
|
368
|
-
modelId:
|
|
369
|
-
params:
|
|
396
|
+
provider: z6.string().min(1),
|
|
397
|
+
modelId: z6.string().min(1),
|
|
398
|
+
params: LlmCallParamsSchema
|
|
370
399
|
});
|
|
371
|
-
var LlmCallEndPayloadSchema =
|
|
372
|
-
callId:
|
|
400
|
+
var LlmCallEndPayloadSchema = z6.looseObject({
|
|
401
|
+
callId: z6.string().min(1),
|
|
373
402
|
content: Json.optional(),
|
|
374
|
-
finishReason:
|
|
403
|
+
finishReason: z6.string().optional(),
|
|
375
404
|
usage: JsonRecord.optional(),
|
|
376
|
-
durationMs:
|
|
377
|
-
error:
|
|
405
|
+
durationMs: z6.number().int().min(0),
|
|
406
|
+
error: z6.looseObject({ name: z6.string(), message: z6.string() }).optional()
|
|
378
407
|
});
|
|
379
|
-
var ToolCallStartPayloadSchema =
|
|
380
|
-
callId:
|
|
408
|
+
var ToolCallStartPayloadSchema = z6.looseObject({
|
|
409
|
+
callId: z6.string().min(1),
|
|
381
410
|
// GAP-07
|
|
382
|
-
toolName:
|
|
411
|
+
toolName: z6.string().min(1),
|
|
383
412
|
input: Json,
|
|
384
|
-
transport:
|
|
385
|
-
server:
|
|
413
|
+
transport: z6.enum(["local", "mcp"]).optional(),
|
|
414
|
+
server: z6.string().optional()
|
|
386
415
|
});
|
|
387
|
-
var ToolCallEndPayloadSchema =
|
|
388
|
-
callId:
|
|
416
|
+
var ToolCallEndPayloadSchema = z6.looseObject({
|
|
417
|
+
callId: z6.string().min(1),
|
|
389
418
|
output: Json.optional(),
|
|
390
|
-
error:
|
|
391
|
-
durationMs:
|
|
419
|
+
error: z6.looseObject({ name: z6.string(), message: z6.string() }).optional(),
|
|
420
|
+
durationMs: z6.number().int().min(0)
|
|
392
421
|
});
|
|
393
422
|
var PAYMENT_ARTIFACTS = [
|
|
394
423
|
"http-402",
|
|
@@ -396,29 +425,30 @@ var PAYMENT_ARTIFACTS = [
|
|
|
396
425
|
"payment-signature",
|
|
397
426
|
"checkout-url"
|
|
398
427
|
];
|
|
399
|
-
var PaymentMomentPayloadSchema =
|
|
400
|
-
protocol:
|
|
401
|
-
payee:
|
|
402
|
-
amount:
|
|
403
|
-
payer:
|
|
404
|
-
artifact:
|
|
428
|
+
var PaymentMomentPayloadSchema = z6.looseObject({
|
|
429
|
+
protocol: z6.string().min(1),
|
|
430
|
+
payee: z6.string().min(1),
|
|
431
|
+
amount: z6.looseObject({ value: z6.string().min(1), currency: z6.string().min(1) }),
|
|
432
|
+
payer: z6.string().optional(),
|
|
433
|
+
artifact: z6.enum(PAYMENT_ARTIFACTS),
|
|
405
434
|
raw: JsonRecord
|
|
406
435
|
});
|
|
407
|
-
var GatewayDecisionPayloadSchema =
|
|
408
|
-
gateway:
|
|
409
|
-
call:
|
|
410
|
-
decision:
|
|
411
|
-
reasonCodes:
|
|
436
|
+
var GatewayDecisionPayloadSchema = z6.looseObject({
|
|
437
|
+
gateway: z6.string().min(1),
|
|
438
|
+
call: z6.looseObject({ tool: z6.string().min(1), args: Json.optional() }),
|
|
439
|
+
decision: z6.enum(["ALLOW", "DENY", "REVIEW", "CHALLENGE"]),
|
|
440
|
+
reasonCodes: z6.array(z6.string()),
|
|
412
441
|
/** The gateway's own record of what it decided on — a black box to the platform. */
|
|
413
442
|
record: JsonRecord
|
|
414
443
|
});
|
|
415
|
-
var TransportGapPayloadSchema =
|
|
416
|
-
dropped:
|
|
417
|
-
|
|
418
|
-
|
|
444
|
+
var TransportGapPayloadSchema = z6.looseObject({
|
|
445
|
+
dropped: z6.number().int().min(1),
|
|
446
|
+
oversized: z6.number().int().min(0).optional(),
|
|
447
|
+
firstTs: z6.string(),
|
|
448
|
+
lastTs: z6.string()
|
|
419
449
|
});
|
|
420
|
-
var PlatformObservationPayloadSchema =
|
|
421
|
-
origin:
|
|
450
|
+
var PlatformObservationPayloadSchema = z6.strictObject({
|
|
451
|
+
origin: z6.string().min(1),
|
|
422
452
|
params: Json,
|
|
423
453
|
response: Json
|
|
424
454
|
});
|
|
@@ -430,10 +460,10 @@ var ANOMALY_TYPES = [
|
|
|
430
460
|
"clock_skew",
|
|
431
461
|
"source_conflict"
|
|
432
462
|
];
|
|
433
|
-
var PlatformAnomalyPayloadSchema =
|
|
434
|
-
type:
|
|
463
|
+
var PlatformAnomalyPayloadSchema = z6.looseObject({
|
|
464
|
+
type: z6.enum(ANOMALY_TYPES),
|
|
435
465
|
source: EvidenceSourceAllSchema,
|
|
436
|
-
seq:
|
|
466
|
+
seq: z6.number().int().min(0).nullable(),
|
|
437
467
|
detail: JsonRecord
|
|
438
468
|
});
|
|
439
469
|
var REGISTRY = {
|
|
@@ -472,87 +502,46 @@ var Verdict = class _Verdict {
|
|
|
472
502
|
const o = typeof other === "string" ? _Verdict.of(other) : other;
|
|
473
503
|
return SEVERITY[o.value] > SEVERITY[this.value] ? o : this;
|
|
474
504
|
}
|
|
475
|
-
/** Whether a synchronous gate must stop the call (GAP-52). */
|
|
476
|
-
blocks(onReview) {
|
|
477
|
-
return this.value === "DENY" || this.value === "REVIEW" && onReview === "abort";
|
|
478
|
-
}
|
|
479
|
-
/** What the gate effectively did: DENY when it blocked, else the verdict itself. */
|
|
480
|
-
effective(onReview) {
|
|
481
|
-
return this.blocks(onReview) ? "DENY" : this.value;
|
|
482
|
-
}
|
|
483
505
|
};
|
|
484
506
|
|
|
485
507
|
export {
|
|
486
|
-
WIRE_SOURCES,
|
|
487
508
|
ALL_SOURCES,
|
|
488
509
|
EvidenceSourceSchema,
|
|
489
510
|
EvidenceSourceAllSchema,
|
|
490
511
|
SOURCE_ORDER,
|
|
491
512
|
compareBySourceSeq,
|
|
513
|
+
chainKey,
|
|
514
|
+
compareByArrival,
|
|
515
|
+
compareRootFirst,
|
|
516
|
+
withinHeads,
|
|
492
517
|
compareBySessionSource,
|
|
493
|
-
WIRE_KINDS,
|
|
494
|
-
PLATFORM_KINDS,
|
|
495
|
-
WireEvidenceKindSchema,
|
|
496
|
-
PlatformEvidenceKindSchema,
|
|
497
|
-
EvidenceKindSchema,
|
|
498
518
|
Hex64Schema,
|
|
499
|
-
|
|
519
|
+
SESSION_ID_PREFIX,
|
|
520
|
+
SESSION_ID_CHARS,
|
|
500
521
|
SessionIdSchema,
|
|
501
|
-
SeqSchema,
|
|
502
522
|
TimestampSchema,
|
|
503
523
|
JsonValueSchema,
|
|
504
524
|
EvidenceEventSchema,
|
|
505
|
-
|
|
506
|
-
|
|
525
|
+
DecimalStringSchema,
|
|
526
|
+
AmountSchema,
|
|
527
|
+
Money,
|
|
507
528
|
INDICATOR_CODES,
|
|
508
529
|
ANNOTATION_CODES,
|
|
509
|
-
COLLECTOR_CODES,
|
|
510
|
-
DEFAULT_RULE_CODES,
|
|
511
530
|
REASON_CODE_PATTERN,
|
|
512
|
-
SelectorSyntaxError,
|
|
513
531
|
parseSelector,
|
|
514
|
-
formatSelector,
|
|
515
532
|
isSelectorRef,
|
|
516
533
|
parseSelectorRef,
|
|
517
534
|
walkPath,
|
|
518
535
|
SelectorStringSchema,
|
|
519
|
-
PRIMITIVES,
|
|
520
|
-
PrimitiveSchema,
|
|
521
|
-
RuleVerdictSchema,
|
|
522
|
-
RuleSchema,
|
|
523
536
|
PolicyRulesSchema,
|
|
524
|
-
AmountSchema,
|
|
525
537
|
DeclaredIntentSchema,
|
|
526
538
|
CreateSessionInputSchema,
|
|
527
|
-
CreateSessionOutputSchema,
|
|
528
539
|
MAX_BATCH_EVENTS,
|
|
529
540
|
EvidenceBatchInputSchema,
|
|
530
|
-
EventResultStatusSchema,
|
|
531
|
-
EventResultSchema,
|
|
532
|
-
ChainHeadSchema,
|
|
533
|
-
EvidenceAckSchema,
|
|
534
541
|
PaymentSummarySchema,
|
|
535
542
|
EvaluateInputSchema,
|
|
536
|
-
DecisionSchema,
|
|
537
|
-
EvaluateOutputSchema,
|
|
538
543
|
CreatePolicyInputSchema,
|
|
539
|
-
CreatePolicyOutputSchema,
|
|
540
544
|
ApiErrorSchema,
|
|
541
|
-
SessionOpenPayloadSchema,
|
|
542
|
-
SESSION_CLOSE_REASONS,
|
|
543
|
-
SessionClosePayloadSchema,
|
|
544
|
-
IntentDeclaredPayloadSchema,
|
|
545
|
-
LlmCallStartPayloadSchema,
|
|
546
|
-
LlmCallEndPayloadSchema,
|
|
547
|
-
ToolCallStartPayloadSchema,
|
|
548
|
-
ToolCallEndPayloadSchema,
|
|
549
|
-
PAYMENT_ARTIFACTS,
|
|
550
|
-
PaymentMomentPayloadSchema,
|
|
551
|
-
GatewayDecisionPayloadSchema,
|
|
552
|
-
TransportGapPayloadSchema,
|
|
553
|
-
PlatformObservationPayloadSchema,
|
|
554
|
-
ANOMALY_TYPES,
|
|
555
|
-
PlatformAnomalyPayloadSchema,
|
|
556
545
|
payloadSchemaFor,
|
|
557
546
|
Verdict
|
|
558
547
|
};
|