@belticlabs/agent-risk-sdk 0.3.0 → 0.5.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/{adapter-BEpzr2R3.d.ts → adapter-DEdhsNt-.d.ts} +3 -10
- package/dist/ai/index.d.ts +2 -2
- package/dist/ai/index.js +6 -8
- package/dist/{chunk-46QN2KEZ.js → chunk-4BUUPU3O.js} +0 -9
- package/dist/chunk-GM4KEEZB.js +163 -0
- package/dist/chunk-JSE6JQJC.js +530 -0
- package/dist/index.d.ts +11 -33
- package/dist/index.js +40 -335
- package/dist/protocol/index.d.ts +2 -2
- package/dist/protocol/index.js +1 -5
- package/dist/{session-DsBWEP8d.d.ts → session-D9E-efc0.d.ts} +74 -97
- package/dist/{verdict-6vCyoAHE.d.ts → verdict-DMnbFuS5.d.ts} +1 -17
- package/dist/x402/hono.d.ts +16 -5
- package/dist/x402/hono.js +14 -8
- package/dist/x402/index.d.ts +15 -27
- package/dist/x402/index.js +15 -59
- package/package.json +2 -30
- package/dist/chunk-4MG6VNAU.js +0 -276
- package/dist/chunk-7G5EHNVW.js +0 -17
- package/dist/chunk-FAQ442YH.js +0 -24
- package/dist/chunk-LM4NIYE5.js +0 -92
- package/dist/chunk-NJVO2WIV.js +0 -17
- package/dist/chunk-OKC6VMFH.js +0 -84
- package/dist/mcp/index.d.ts +0 -58
- package/dist/mcp/index.js +0 -135
- package/dist/middleware-9gI0ou2i.d.ts +0 -15
- package/dist/seller/anti-fraud-gateway.d.ts +0 -40
- package/dist/seller/anti-fraud-gateway.js +0 -38
- package/dist/x402/express.d.ts +0 -13
- package/dist/x402/express.js +0 -27
package/dist/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Verdict
|
|
3
|
+
} from "./chunk-4BUUPU3O.js";
|
|
4
|
+
import {
|
|
5
|
+
ApiClient,
|
|
6
|
+
BelticApiError,
|
|
7
|
+
BelticConfigError,
|
|
8
|
+
ChainRejectedError,
|
|
4
9
|
Session,
|
|
5
10
|
Sessions,
|
|
6
|
-
|
|
7
|
-
} from "./chunk-
|
|
11
|
+
Transport
|
|
12
|
+
} from "./chunk-JSE6JQJC.js";
|
|
8
13
|
import {
|
|
9
14
|
canonicalBytes,
|
|
10
15
|
canonicalize,
|
|
@@ -14,134 +19,22 @@ import {
|
|
|
14
19
|
sha256,
|
|
15
20
|
toHex
|
|
16
21
|
} from "./chunk-X3W2Z5GC.js";
|
|
17
|
-
import {
|
|
18
|
-
Verdict
|
|
19
|
-
} from "./chunk-46QN2KEZ.js";
|
|
20
|
-
import {
|
|
21
|
-
presentedFrom,
|
|
22
|
-
summaryOf
|
|
23
|
-
} from "./chunk-7G5EHNVW.js";
|
|
24
|
-
|
|
25
|
-
// src/core/api-client.ts
|
|
26
|
-
var BelticApiError = class extends Error {
|
|
27
|
-
constructor(status, code, message, details, requestId) {
|
|
28
|
-
super(message);
|
|
29
|
-
this.status = status;
|
|
30
|
-
this.code = code;
|
|
31
|
-
this.details = details;
|
|
32
|
-
this.requestId = requestId;
|
|
33
|
-
this.name = "BelticApiError";
|
|
34
|
-
}
|
|
35
|
-
/** 5xx and network failures are retried by the transport; 4xx are not. */
|
|
36
|
-
get retryable() {
|
|
37
|
-
return this.status === 0 || this.status >= 500 || this.status === 429;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var ApiClient = class {
|
|
41
|
-
baseUrl;
|
|
42
|
-
fetchImpl;
|
|
43
|
-
timeoutMs;
|
|
44
|
-
headers;
|
|
45
|
-
constructor(opts) {
|
|
46
|
-
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
47
|
-
this.fetchImpl = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
48
|
-
this.timeoutMs = opts.timeoutMs ?? 1e4;
|
|
49
|
-
this.headers = {
|
|
50
|
-
authorization: `Bearer ${opts.apiKey}`,
|
|
51
|
-
"content-type": "application/json",
|
|
52
|
-
"user-agent": opts.userAgent ?? "@belticlabs/agent-risk-sdk"
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
post(path, body, headers = {}) {
|
|
56
|
-
return this.request("POST", path, JSON.stringify(body), headers);
|
|
57
|
-
}
|
|
58
|
-
get(path, query = {}) {
|
|
59
|
-
const qs = Object.entries(query).filter((e) => e[1] !== void 0).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
|
|
60
|
-
return this.request("GET", qs ? `${path}?${qs}` : path, void 0, {});
|
|
61
|
-
}
|
|
62
|
-
async request(method, path, body, extra) {
|
|
63
|
-
const controller = new AbortController();
|
|
64
|
-
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
65
|
-
let res;
|
|
66
|
-
try {
|
|
67
|
-
res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
68
|
-
method,
|
|
69
|
-
headers: { ...this.headers, ...extra },
|
|
70
|
-
...body !== void 0 ? { body } : {},
|
|
71
|
-
signal: controller.signal
|
|
72
|
-
});
|
|
73
|
-
} catch (err) {
|
|
74
|
-
throw new BelticApiError(
|
|
75
|
-
0,
|
|
76
|
-
"NETWORK",
|
|
77
|
-
`request to ${path} failed: ${err.message}`
|
|
78
|
-
);
|
|
79
|
-
} finally {
|
|
80
|
-
clearTimeout(timer);
|
|
81
|
-
}
|
|
82
|
-
const text = await res.text();
|
|
83
|
-
let json = null;
|
|
84
|
-
try {
|
|
85
|
-
json = text ? JSON.parse(text) : null;
|
|
86
|
-
} catch {
|
|
87
|
-
json = null;
|
|
88
|
-
}
|
|
89
|
-
if (!res.ok) {
|
|
90
|
-
const e = json?.error;
|
|
91
|
-
throw new BelticApiError(
|
|
92
|
-
res.status,
|
|
93
|
-
e?.code ?? `HTTP_${res.status}`,
|
|
94
|
-
e?.message ?? res.statusText,
|
|
95
|
-
e?.details,
|
|
96
|
-
e?.request_id
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
return json;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// src/core/correlation.ts
|
|
104
|
-
var MemoryCorrelationStore = class {
|
|
105
|
-
constructor(defaultTtlMs = 60 * 60 * 1e3) {
|
|
106
|
-
this.defaultTtlMs = defaultTtlMs;
|
|
107
|
-
}
|
|
108
|
-
entries = /* @__PURE__ */ new Map();
|
|
109
|
-
async bind(key, sessionId, ttlMs = this.defaultTtlMs) {
|
|
110
|
-
this.entries.set(key, { sessionId, expiresAt: Date.now() + ttlMs });
|
|
111
|
-
}
|
|
112
|
-
async resolve(key) {
|
|
113
|
-
const e = this.entries.get(key);
|
|
114
|
-
if (!e) return null;
|
|
115
|
-
if (e.expiresAt < Date.now()) {
|
|
116
|
-
this.entries.delete(key);
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
return e.sessionId;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
22
|
|
|
123
23
|
// src/core/identity.ts
|
|
124
|
-
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
125
|
-
import { dirname } from "path";
|
|
126
24
|
function identityFromSeed(seed, credential) {
|
|
127
25
|
const signer = memorySigner(seed);
|
|
128
26
|
const did = didKeyFromEd25519(signer.publicKey);
|
|
129
27
|
return { did, signer: { ...signer, keyId: did }, ...credential ? { credential } : {} };
|
|
130
28
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
141
|
-
writeFileSync(path, `${JSON.stringify({ seed: toHex(seed) })}
|
|
142
|
-
`, { mode: 384 });
|
|
143
|
-
}
|
|
144
|
-
return identityFromSeed(seed, credential);
|
|
29
|
+
|
|
30
|
+
// src/core/payment-moment.ts
|
|
31
|
+
function summaryOf(m) {
|
|
32
|
+
return {
|
|
33
|
+
protocol: m.protocol,
|
|
34
|
+
payee: m.payee,
|
|
35
|
+
amount: { value: m.amount.value, currency: m.amount.currency },
|
|
36
|
+
...m.payer ? { payer: m.payer } : {}
|
|
37
|
+
};
|
|
145
38
|
}
|
|
146
39
|
|
|
147
40
|
// src/core/decision.ts
|
|
@@ -373,238 +266,65 @@ var Run = class _Run {
|
|
|
373
266
|
}
|
|
374
267
|
};
|
|
375
268
|
|
|
376
|
-
// src/core/transport.ts
|
|
377
|
-
var DEFAULT_TRANSPORT = {
|
|
378
|
-
maxBatch: 50,
|
|
379
|
-
flushMs: 1e3,
|
|
380
|
-
maxBuffered: 5e3,
|
|
381
|
-
backoff: { baseMs: 200, maxMs: 3e4, maxAttempts: Number.POSITIVE_INFINITY }
|
|
382
|
-
};
|
|
383
|
-
var ChainRejectedError = class extends Error {
|
|
384
|
-
constructor(sessionId, source, result) {
|
|
385
|
-
super(
|
|
386
|
-
`chain ${sessionId}:${source} halted at seq ${result.seq}: ${result.status}${result.code ? ` ${result.code}` : ""}`
|
|
387
|
-
);
|
|
388
|
-
this.sessionId = sessionId;
|
|
389
|
-
this.source = source;
|
|
390
|
-
this.result = result;
|
|
391
|
-
this.name = "ChainRejectedError";
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
var TransportClosedError = class extends Error {
|
|
395
|
-
constructor() {
|
|
396
|
-
super("transport is closed");
|
|
397
|
-
this.name = "TransportClosedError";
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
var Transport = class {
|
|
401
|
-
constructor(api, opts = {}) {
|
|
402
|
-
this.api = api;
|
|
403
|
-
this.opts = {
|
|
404
|
-
...DEFAULT_TRANSPORT,
|
|
405
|
-
...opts,
|
|
406
|
-
backoff: { ...DEFAULT_TRANSPORT.backoff, ...opts.backoff }
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
opts;
|
|
410
|
-
chains = /* @__PURE__ */ new Map();
|
|
411
|
-
buffered = 0;
|
|
412
|
-
timer = null;
|
|
413
|
-
closed = false;
|
|
414
|
-
inFlightCount = 0;
|
|
415
|
-
drainWaiters = [];
|
|
416
|
-
get size() {
|
|
417
|
-
return this.buffered;
|
|
418
|
-
}
|
|
419
|
-
hasRoom() {
|
|
420
|
-
return !this.closed && this.buffered < this.opts.maxBuffered;
|
|
421
|
-
}
|
|
422
|
-
haltedError(sessionId, source) {
|
|
423
|
-
return this.chains.get(`${sessionId}:${source}`)?.halted ?? null;
|
|
424
|
-
}
|
|
425
|
-
/** Callers check `hasRoom()` first and assign `seq` only then (GAP-38). */
|
|
426
|
-
enqueue(ev) {
|
|
427
|
-
if (this.closed) throw new TransportClosedError();
|
|
428
|
-
const key = `${ev.sessionId}:${ev.source}`;
|
|
429
|
-
let chain = this.chains.get(key);
|
|
430
|
-
if (!chain) {
|
|
431
|
-
chain = { key, pending: [], inFlight: null, attempts: 0, halted: null };
|
|
432
|
-
this.chains.set(key, chain);
|
|
433
|
-
}
|
|
434
|
-
if (chain.halted) throw chain.halted;
|
|
435
|
-
if (!this.hasRoom()) throw new Error("transport buffer is full");
|
|
436
|
-
chain.pending.push(ev);
|
|
437
|
-
this.buffered++;
|
|
438
|
-
if (chain.pending.length >= this.opts.maxBatch) void this.flushChain(chain);
|
|
439
|
-
else this.schedule();
|
|
440
|
-
}
|
|
441
|
-
/** Send everything pending and wait for every in-flight batch to settle (ack or halt). */
|
|
442
|
-
async flush() {
|
|
443
|
-
this.unschedule();
|
|
444
|
-
for (const chain of this.chains.values()) void this.flushChain(chain);
|
|
445
|
-
await this.drained();
|
|
446
|
-
}
|
|
447
|
-
async close() {
|
|
448
|
-
await this.flush();
|
|
449
|
-
this.closed = true;
|
|
450
|
-
}
|
|
451
|
-
schedule() {
|
|
452
|
-
if (this.timer) return;
|
|
453
|
-
const st = this.opts.setTimeout ?? globalThis.setTimeout;
|
|
454
|
-
this.timer = st(() => {
|
|
455
|
-
this.timer = null;
|
|
456
|
-
for (const chain of this.chains.values()) void this.flushChain(chain);
|
|
457
|
-
}, this.opts.flushMs);
|
|
458
|
-
this.timer.unref?.();
|
|
459
|
-
}
|
|
460
|
-
unschedule() {
|
|
461
|
-
if (!this.timer) return;
|
|
462
|
-
(this.opts.clearTimeout ?? globalThis.clearTimeout)(this.timer);
|
|
463
|
-
this.timer = null;
|
|
464
|
-
}
|
|
465
|
-
drained() {
|
|
466
|
-
if (this.inFlightCount === 0 && [...this.chains.values()].every((c) => c.pending.length === 0 || c.halted)) {
|
|
467
|
-
return Promise.resolve();
|
|
468
|
-
}
|
|
469
|
-
return new Promise((resolve) => this.drainWaiters.push(resolve));
|
|
470
|
-
}
|
|
471
|
-
settleWaiters() {
|
|
472
|
-
if (this.inFlightCount > 0) return;
|
|
473
|
-
if (![...this.chains.values()].every((c) => c.pending.length === 0 || c.halted)) return;
|
|
474
|
-
const waiters = this.drainWaiters;
|
|
475
|
-
this.drainWaiters = [];
|
|
476
|
-
for (const w of waiters) w();
|
|
477
|
-
}
|
|
478
|
-
async flushChain(chain) {
|
|
479
|
-
if (chain.inFlight || chain.halted || chain.pending.length === 0) {
|
|
480
|
-
this.settleWaiters();
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
const batch = chain.pending.splice(0, this.opts.maxBatch);
|
|
484
|
-
chain.inFlight = batch;
|
|
485
|
-
this.inFlightCount++;
|
|
486
|
-
try {
|
|
487
|
-
const ack = await this.send(chain, batch);
|
|
488
|
-
this.buffered -= batch.length;
|
|
489
|
-
this.opts.onAck?.(ack);
|
|
490
|
-
const bad = ack.results.find((r) => r.status === "fork" || r.status === "rejected");
|
|
491
|
-
if (bad) {
|
|
492
|
-
const first = batch[0];
|
|
493
|
-
chain.halted = new ChainRejectedError(first.sessionId, first.source, bad);
|
|
494
|
-
this.buffered -= chain.pending.length;
|
|
495
|
-
chain.pending = [];
|
|
496
|
-
this.opts.onChainHalted?.(chain.halted);
|
|
497
|
-
}
|
|
498
|
-
} catch (err) {
|
|
499
|
-
this.buffered -= batch.length + chain.pending.length;
|
|
500
|
-
chain.pending = [];
|
|
501
|
-
const first = batch[0];
|
|
502
|
-
chain.halted = new ChainRejectedError(first.sessionId, first.source, {
|
|
503
|
-
index: 0,
|
|
504
|
-
sessionId: first.sessionId,
|
|
505
|
-
source: first.source,
|
|
506
|
-
seq: first.seq,
|
|
507
|
-
status: "rejected",
|
|
508
|
-
code: "DELIVERY_FAILED"
|
|
509
|
-
});
|
|
510
|
-
this.opts.onError?.(err);
|
|
511
|
-
this.opts.onChainHalted?.(chain.halted);
|
|
512
|
-
} finally {
|
|
513
|
-
chain.inFlight = null;
|
|
514
|
-
this.inFlightCount--;
|
|
515
|
-
}
|
|
516
|
-
if (chain.pending.length > 0 && !chain.halted) void this.flushChain(chain);
|
|
517
|
-
else this.settleWaiters();
|
|
518
|
-
}
|
|
519
|
-
async send(chain, batch) {
|
|
520
|
-
const { baseMs, maxMs, maxAttempts } = this.opts.backoff;
|
|
521
|
-
for (let attempt = 0; ; attempt++) {
|
|
522
|
-
try {
|
|
523
|
-
const ack = await this.api.post("/v1/evidence", batch);
|
|
524
|
-
chain.attempts = 0;
|
|
525
|
-
return ack;
|
|
526
|
-
} catch (err) {
|
|
527
|
-
const retryable = err instanceof BelticApiError ? err.retryable : true;
|
|
528
|
-
if (!retryable || attempt + 1 >= maxAttempts) throw err;
|
|
529
|
-
this.opts.onError?.(err);
|
|
530
|
-
const delay = Math.min(maxMs, baseMs * 2 ** attempt) * (0.5 + Math.random() / 2);
|
|
531
|
-
await new Promise((r) => (this.opts.setTimeout ?? globalThis.setTimeout)(r, delay));
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
|
|
537
269
|
// src/client.ts
|
|
538
|
-
var SDK_VERSION = "0.
|
|
270
|
+
var SDK_VERSION = "0.5.0";
|
|
539
271
|
var ENV_REQUIRED = ["BELTIC_API_KEY", "BELTIC_BASE_URL", "BELTIC_AGENT_SEED"];
|
|
540
272
|
var ENV_CREDENTIAL = "BELTIC_AGENT_CREDENTIAL";
|
|
541
273
|
var Beltic = class _Beltic {
|
|
542
|
-
api;
|
|
543
274
|
transport;
|
|
544
275
|
sessions;
|
|
545
276
|
identity;
|
|
546
|
-
correlation;
|
|
547
277
|
onReview;
|
|
548
278
|
failOpen;
|
|
549
|
-
|
|
550
|
-
enabled;
|
|
279
|
+
api;
|
|
551
280
|
onError;
|
|
552
281
|
runs = /* @__PURE__ */ new Map();
|
|
553
282
|
/**
|
|
554
283
|
* The client the environment describes: `BELTIC_API_KEY`,
|
|
555
284
|
* `BELTIC_BASE_URL`, `BELTIC_AGENT_SEED` (64 hex) and optionally
|
|
556
|
-
* `BELTIC_AGENT_CREDENTIAL
|
|
557
|
-
*
|
|
285
|
+
* `BELTIC_AGENT_CREDENTIAL`. Any of the three missing is a configuration
|
|
286
|
+
* error, thrown (GAP-78).
|
|
558
287
|
*/
|
|
559
288
|
static fromEnv(env = _Beltic.processEnv(), opts = {}) {
|
|
560
289
|
const missing = ENV_REQUIRED.filter((name) => !env[name]);
|
|
561
|
-
if (missing.length === ENV_REQUIRED.length) return _Beltic.disabled(opts);
|
|
562
290
|
if (missing.length > 0)
|
|
563
|
-
throw new
|
|
564
|
-
|
|
291
|
+
throw new BelticConfigError(
|
|
292
|
+
`${missing.join(", ")} missing \u2014 fromEnv needs ${ENV_REQUIRED.join(", ")}`
|
|
565
293
|
);
|
|
566
294
|
return new _Beltic({
|
|
567
|
-
failOpen: true,
|
|
568
295
|
...opts,
|
|
569
296
|
apiKey: env.BELTIC_API_KEY,
|
|
570
297
|
baseUrl: env.BELTIC_BASE_URL,
|
|
571
298
|
identity: identityFromSeed(fromHex(env.BELTIC_AGENT_SEED), env[ENV_CREDENTIAL])
|
|
572
299
|
});
|
|
573
300
|
}
|
|
574
|
-
/** A client that records nothing and never throws into the work: the null object for "no evidence stream" (GAP-78). */
|
|
575
|
-
static disabled(opts = {}) {
|
|
576
|
-
return new _Beltic({
|
|
577
|
-
...opts,
|
|
578
|
-
apiKey: "",
|
|
579
|
-
baseUrl: "http://beltic.disabled.invalid",
|
|
580
|
-
failOpen: true,
|
|
581
|
-
enabled: false
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
301
|
constructor(opts) {
|
|
585
|
-
|
|
302
|
+
if (!opts.apiKey) throw new BelticConfigError("apiKey is required");
|
|
303
|
+
if (!URL.canParse(opts.baseUrl))
|
|
304
|
+
throw new BelticConfigError(`baseUrl is not a URL: ${JSON.stringify(opts.baseUrl)}`);
|
|
586
305
|
this.failOpen = opts.failOpen ?? false;
|
|
587
306
|
this.onError = opts.onError ?? ((err) => console.error("[beltic]", err));
|
|
588
|
-
this.api = new ApiClient({
|
|
307
|
+
this.api = new ApiClient({
|
|
308
|
+
baseUrl: opts.baseUrl,
|
|
309
|
+
apiKey: opts.apiKey,
|
|
310
|
+
fetch: opts.fetch,
|
|
311
|
+
userAgent: `@belticlabs/agent-risk-sdk/${SDK_VERSION}`
|
|
312
|
+
});
|
|
589
313
|
this.transport = new Transport(this.api, {
|
|
314
|
+
...opts.transport,
|
|
590
315
|
onError: this.onError,
|
|
591
|
-
onChainHalted: this.onError
|
|
592
|
-
...opts.transport
|
|
316
|
+
onChainHalted: this.onError
|
|
593
317
|
});
|
|
594
318
|
this.sessions = new Sessions({
|
|
595
319
|
api: this.api,
|
|
596
320
|
transport: this.transport,
|
|
597
321
|
sdkVersion: SDK_VERSION,
|
|
598
322
|
identity: opts.identity,
|
|
599
|
-
redact: opts.redact,
|
|
600
|
-
now: opts.now,
|
|
601
323
|
failOpen: this.failOpen,
|
|
602
324
|
onError: this.onError,
|
|
603
|
-
openRetryMs: opts.openRetryMs
|
|
604
|
-
enabled: this.enabled
|
|
325
|
+
openRetryMs: opts.openRetryMs
|
|
605
326
|
});
|
|
606
327
|
this.identity = opts.identity;
|
|
607
|
-
this.correlation = opts.correlation ?? new MemoryCorrelationStore();
|
|
608
328
|
this.onReview = opts.onReview ?? "abort";
|
|
609
329
|
}
|
|
610
330
|
/**
|
|
@@ -613,15 +333,14 @@ var Beltic = class _Beltic {
|
|
|
613
333
|
* is flushed first so the platform judges what the caller already saw
|
|
614
334
|
* (GAP-16). A recorded moment is accepted as is: only its comparable core
|
|
615
335
|
* (payee, amount, payer) is sent. `null` only under `failOpen`, when the
|
|
616
|
-
* platform could not be
|
|
336
|
+
* platform could not be reached.
|
|
617
337
|
*/
|
|
618
338
|
async evaluate(sessionId, payment) {
|
|
619
|
-
if (!this.enabled) return null;
|
|
620
339
|
const input = { sessionId, payment: summaryOf(payment) };
|
|
621
|
-
if (!this.failOpen) return this.decide(input);
|
|
622
340
|
try {
|
|
623
341
|
return await this.decide(input);
|
|
624
342
|
} catch (err) {
|
|
343
|
+
if (!this.failOpen || !Transport.outage(err)) throw err;
|
|
625
344
|
this.onError(err);
|
|
626
345
|
return null;
|
|
627
346
|
}
|
|
@@ -663,30 +382,16 @@ var Beltic = class _Beltic {
|
|
|
663
382
|
return globalThis.process?.env ?? {};
|
|
664
383
|
}
|
|
665
384
|
};
|
|
666
|
-
function createBeltic(opts) {
|
|
667
|
-
return new Beltic(opts);
|
|
668
|
-
}
|
|
669
385
|
export {
|
|
670
386
|
ApiClient,
|
|
671
387
|
Beltic,
|
|
672
388
|
BelticApiError,
|
|
673
|
-
|
|
389
|
+
BelticConfigError,
|
|
674
390
|
ChainRejectedError,
|
|
675
|
-
DEFAULT_OPEN_RETRY_MS,
|
|
676
|
-
DEFAULT_TRANSPORT,
|
|
677
391
|
Decision,
|
|
678
|
-
MemoryCorrelationStore,
|
|
679
392
|
Run,
|
|
680
393
|
SDK_VERSION,
|
|
681
394
|
Session,
|
|
682
|
-
Sessions,
|
|
683
395
|
Transport,
|
|
684
|
-
|
|
685
|
-
createBeltic,
|
|
686
|
-
ephemeralIdentity,
|
|
687
|
-
fileIdentity,
|
|
688
|
-
identityFromSeed,
|
|
689
|
-
presentedFrom,
|
|
690
|
-
recordCall,
|
|
691
|
-
summaryOf
|
|
396
|
+
identityFromSeed
|
|
692
397
|
};
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as ALL_SOURCES,
|
|
1
|
+
import { J as JsonValue, E as EvidenceSourceAll } from '../verdict-DMnbFuS5.js';
|
|
2
|
+
export { A as ALL_SOURCES, a as ANOMALY_TYPES, b as Amount, c as AmountSchema, d as ApiError, e as ApiErrorSchema, C as ChainHead, f as ChainHeadSchema, g as CreatePolicyInput, h as CreatePolicyInputSchema, i as CreatePolicyOutput, j as CreatePolicyOutputSchema, k as CreateSessionInput, l as CreateSessionInputSchema, m as CreateSessionOutput, n as CreateSessionOutputSchema, D as Decision, o as DecisionSchema, p as DeclaredIntent, q as DeclaredIntentSchema, r as DigestedEnvelope, s as EvaluateInput, t as EvaluateInputSchema, u as EvaluateOutput, v as EvaluateOutputSchema, w as EventResult, x as EventResultSchema, y as EventResultStatus, z as EventResultStatusSchema, B as EvidenceAck, F as EvidenceAckSchema, G as EvidenceBatchInput, H as EvidenceBatchInputSchema, I as EvidenceEnvelope, K as EvidenceEvent, L as EvidenceEventSchema, M as EvidenceKind, N as EvidenceKindSchema, O as EvidenceSource, Q as EvidenceSourceAllSchema, R as EvidenceSourceSchema, S as GatewayDecisionPayload, T as GatewayDecisionPayloadSchema, U as Hex64, V as Hex64Schema, W as IntentDeclaredPayload, X as IntentDeclaredPayloadSchema, Y as JsonObject, Z as JsonValueSchema, _ as LlmCallEndPayload, $ as LlmCallEndPayloadSchema, a0 as LlmCallStartPayload, a1 as LlmCallStartPayloadSchema, a2 as MAX_BATCH_EVENTS, a3 as OnReview, a4 as PAYMENT_ARTIFACTS, a5 as PLATFORM_KINDS, a6 as PayloadByKind, P as PaymentMomentPayload, a7 as PaymentMomentPayloadSchema, a8 as PaymentSummary, a9 as PaymentSummarySchema, aa as PlatformAnomalyPayload, ab as PlatformAnomalyPayloadSchema, ac as PlatformEvidenceKind, ad as PlatformEvidenceKindSchema, ae as PlatformObservationPayload, af as PlatformObservationPayloadSchema, ag as SESSION_CLOSE_REASONS, ah as SOURCE_ORDER, ai as SeqSchema, aj as SessionClosePayload, ak as SessionClosePayloadSchema, al as SessionIdSchema, am as SessionOpenPayload, an as SessionOpenPayloadSchema, ao as Sig, ap as SigSchema, aq as TimestampSchema, ar as ToolCallEndPayload, as as ToolCallEndPayloadSchema, at as ToolCallStartPayload, au as ToolCallStartPayloadSchema, av as TransportGapPayload, aw as TransportGapPayloadSchema, ax as Verdict, ay as WIRE_KINDS, az as WIRE_SOURCES, aA as WireEvidenceKind, aB as WireEvidenceKindSchema, aC as compareBySessionSource, aD as compareBySourceSeq, aE as isPlatformKind, aF as isWireKind, aG as payloadSchemaFor } from '../verdict-DMnbFuS5.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
declare const PRIMITIVES: readonly ["THRESHOLD", "MEMBERSHIP", "MATCH", "PRESENCE", "FRESHNESS"];
|
package/dist/protocol/index.js
CHANGED
|
@@ -3,8 +3,6 @@ import {
|
|
|
3
3
|
ANNOTATION_CODES,
|
|
4
4
|
ANOMALY_TYPES,
|
|
5
5
|
AmountSchema,
|
|
6
|
-
AnchorEntrySchema,
|
|
7
|
-
AnchorsOutputSchema,
|
|
8
6
|
ApiErrorSchema,
|
|
9
7
|
COLLECTOR_CODES,
|
|
10
8
|
ChainHeadSchema,
|
|
@@ -73,14 +71,12 @@ import {
|
|
|
73
71
|
parseSelectorRef,
|
|
74
72
|
payloadSchemaFor,
|
|
75
73
|
walkPath
|
|
76
|
-
} from "../chunk-
|
|
74
|
+
} from "../chunk-4BUUPU3O.js";
|
|
77
75
|
export {
|
|
78
76
|
ALL_SOURCES,
|
|
79
77
|
ANNOTATION_CODES,
|
|
80
78
|
ANOMALY_TYPES,
|
|
81
79
|
AmountSchema,
|
|
82
|
-
AnchorEntrySchema,
|
|
83
|
-
AnchorsOutputSchema,
|
|
84
80
|
ApiErrorSchema,
|
|
85
81
|
COLLECTOR_CODES,
|
|
86
82
|
ChainHeadSchema,
|