@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
package/dist/protocol/index.d.ts
CHANGED
|
@@ -1,8 +1,49 @@
|
|
|
1
|
-
import { J as JsonValue, E as EvidenceSourceAll } from '../
|
|
2
|
-
export { A as ALL_SOURCES, a as
|
|
1
|
+
import { J as JsonValue, E as EvidenceSourceAll, D as Decision } from '../index-DAVKGJs5.js';
|
|
2
|
+
export { A as ALL_SOURCES, a as ApiError, b as ApiErrorSchema, C as ChainHead, c as CreatePolicyInputSchema, d as CreatePolicyOutput, e as CreateSessionInput, f as CreateSessionInputSchema, g as CreateSessionOutput, h as DeclaredIntent, i as DeclaredIntentSchema, j as DigestedEnvelope, k as EvaluateInput, l as EvaluateInputSchema, m as EvaluateOutput, n as EventResult, o as EvidenceAck, p as EvidenceBatchInputSchema, q as EvidenceEnvelope, r as EvidenceEvent, s as EvidenceEventSchema, t as EvidenceKind, u as EvidenceSource, v as EvidenceSourceAllSchema, w as EvidenceSourceSchema, G as GatewayDecisionPayload, H as Hex64, x as Hex64Schema, I as IntentDeclaredPayload, y as JsonObject, z as JsonValueSchema, L as LlmCallEndPayload, B as LlmCallParams, F as LlmCallStartPayload, M as MAX_BATCH_EVENTS, P as PayloadByKind, K as PaymentMomentPayload, N as PaymentSummary, O as PaymentSummarySchema, Q as PlatformAnomalyPayload, R as PlatformEvidenceKind, S as PlatformObservationPayload, T as PromptBase, U as PromptDelta, V as SESSION_ID_CHARS, W as SESSION_ID_PREFIX, X as SOURCE_ORDER, Y as SessionClosePayload, Z as SessionIdSchema, _ as SessionOpenPayload, $ as Sig, a0 as TimestampSchema, a1 as ToolCallEndPayload, a2 as ToolCallStartPayload, a3 as TransportGapPayload, a4 as WireEvidenceKind, a5 as chainKey, a6 as compareByArrival, a7 as compareBySessionSource, a8 as compareBySourceSeq, a9 as compareRootFirst, aa as payloadSchemaFor, ab as withinHeads } from '../index-DAVKGJs5.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Amounts are decimal strings, never floats (Fraud Engine RFC › API:
|
|
7
|
+
* `amount: { value: string; currency: string }`). One grammar for the wire
|
|
8
|
+
* and the engine, and one value object that compares and adds over scaled
|
|
9
|
+
* BigInts, so 0.1 + 0.2 is 0.3 and an atomic x402 amount of 18 digits
|
|
10
|
+
* keeps its precision. A currency mismatch is never coerced away (GAP-49):
|
|
11
|
+
* two amounts are comparable only when they name the same currency or one
|
|
12
|
+
* names none (a bare bound in a rule).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
declare const DecimalStringSchema: z.ZodString;
|
|
16
|
+
type DecimalString = z.infer<typeof DecimalStringSchema>;
|
|
17
|
+
declare const AmountSchema: z.ZodObject<{
|
|
18
|
+
value: z.ZodString;
|
|
19
|
+
currency: z.ZodString;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
type Amount = z.infer<typeof AmountSchema>;
|
|
22
|
+
declare class Money {
|
|
23
|
+
readonly value: DecimalString;
|
|
24
|
+
readonly currency: string | null;
|
|
25
|
+
private constructor();
|
|
26
|
+
static of(amount: Amount): Money;
|
|
27
|
+
/** A decimal with no currency: a bound in a rule, a running total. */
|
|
28
|
+
static bare(value: string): Money;
|
|
29
|
+
/** An x402 amount: atomic units of `asset` on `network`, its currency `<network>/<asset>` (GAP-49). */
|
|
30
|
+
static x402(network: string, asset: string, atomic: string | bigint): Money;
|
|
31
|
+
static x402Currency(network: string, asset: string): string;
|
|
32
|
+
/** Anything a selector or a rule param may resolve to; null when it is not an amount. */
|
|
33
|
+
static parse(v: unknown): Money | null;
|
|
34
|
+
comparable(other: Money): boolean;
|
|
35
|
+
compareTo(other: Money): -1 | 0 | 1;
|
|
36
|
+
exceeds(other: Money): boolean;
|
|
37
|
+
plus(other: Money): Money;
|
|
38
|
+
isZero(): boolean;
|
|
39
|
+
/** Numeric view for ratios; precision loss is acceptable for a ratio. */
|
|
40
|
+
toNumber(): number;
|
|
41
|
+
/** this / other, or null when `other` is zero. */
|
|
42
|
+
ratioTo(other: Money): number | null;
|
|
43
|
+
toAmount(): Amount;
|
|
44
|
+
private static scaled;
|
|
45
|
+
}
|
|
46
|
+
|
|
6
47
|
declare const PrimitiveSchema: z.ZodEnum<{
|
|
7
48
|
THRESHOLD: "THRESHOLD";
|
|
8
49
|
MEMBERSHIP: "MEMBERSHIP";
|
|
@@ -66,18 +107,17 @@ declare const PolicyRulesSchema: z.ZodObject<{
|
|
|
66
107
|
}>>;
|
|
67
108
|
code: z.ZodString;
|
|
68
109
|
}, z.core.$strict>>;
|
|
69
|
-
scoreThresholds: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
70
110
|
}, z.core.$strict>;
|
|
71
111
|
type PolicyRules = z.infer<typeof PolicyRulesSchema>;
|
|
72
112
|
|
|
73
113
|
/**
|
|
74
114
|
* Reason codes are the only thing that crosses the verdict boundary besides
|
|
75
115
|
* the verdict itself (Fraud Engine RFC › API: "the seller receives a verdict
|
|
76
|
-
* and reasons — never the record").
|
|
77
|
-
*
|
|
116
|
+
* and reasons — never the record"). The platform's own codes are named here;
|
|
117
|
+
* an owner's rule codes are content, checked only against the pattern (GAP-44).
|
|
78
118
|
*/
|
|
79
119
|
/** Static platform policy — may DENY alone (Fraud Engine RFC › Fraud indicators). */
|
|
80
|
-
declare const INDICATOR_CODES: readonly ["CHAIN_BROKEN", "EVIDENCE_MISMATCH", "
|
|
120
|
+
declare const INDICATOR_CODES: readonly ["CHAIN_BROKEN", "EVIDENCE_MISMATCH", "SESSION_INVALID"];
|
|
81
121
|
type IndicatorCode = (typeof INDICATOR_CODES)[number];
|
|
82
122
|
/**
|
|
83
123
|
* Annotations describe the floor the decision was made on. They never change
|
|
@@ -85,14 +125,8 @@ type IndicatorCode = (typeof INDICATOR_CODES)[number];
|
|
|
85
125
|
* the owner's rules, not a denial (GAP-43).
|
|
86
126
|
*/
|
|
87
127
|
declare const ANNOTATION_CODES: readonly ["NO_AGENT_TRACE", "NO_POLICY"];
|
|
88
|
-
type AnnotationCode = (typeof ANNOTATION_CODES)[number];
|
|
89
128
|
/** Why the Collector refused or downgraded an event (per-event ack, GAP-17). */
|
|
90
|
-
|
|
91
|
-
type CollectorCode = (typeof COLLECTOR_CODES)[number];
|
|
92
|
-
/** Codes the platform default policy uses; owners may define their own (GAP-44). */
|
|
93
|
-
declare const DEFAULT_RULE_CODES: readonly ["CAP_EXCEEDED", "PAYEE_NOT_ALLOWED", "NO_INTENT", "INTENT_EXPIRED"];
|
|
94
|
-
type DefaultRuleCode = (typeof DEFAULT_RULE_CODES)[number];
|
|
95
|
-
type ReasonCode = IndicatorCode | AnnotationCode | DefaultRuleCode | (string & {});
|
|
129
|
+
type CollectorCode = 'SCHEMA_INVALID' | 'SESSION_UNKNOWN' | 'SESSION_CLOSED' | 'SESSION_EXPIRED' | 'SOURCE_FORBIDDEN' | 'SEQ_GAP' | 'PREV_HASH_MISMATCH' | 'SIG_MISSING' | 'SIG_INVALID' | 'PAYLOAD_INVALID' | 'EVENT_TOO_LARGE';
|
|
96
130
|
declare const REASON_CODE_PATTERN: RegExp;
|
|
97
131
|
|
|
98
132
|
/**
|
|
@@ -140,18 +174,28 @@ type Selector = {
|
|
|
140
174
|
all: boolean;
|
|
141
175
|
path: PathSegment[];
|
|
142
176
|
};
|
|
143
|
-
declare class SelectorSyntaxError extends Error {
|
|
144
|
-
readonly input: string;
|
|
145
|
-
readonly at: number;
|
|
146
|
-
readonly code = "SELECTOR_SYNTAX";
|
|
147
|
-
constructor(input: string, at: number, detail: string);
|
|
148
|
-
}
|
|
149
177
|
declare function parseSelector(input: string): Selector;
|
|
150
|
-
declare function formatSelector(sel: Selector): string;
|
|
151
178
|
declare function isSelectorRef(value: unknown): value is `@${string}`;
|
|
152
179
|
declare function parseSelectorRef(ref: string): Selector;
|
|
153
180
|
/** Walk a `path` over a value; `undefined` when any step is missing. */
|
|
154
181
|
declare function walkPath(value: unknown, path: readonly PathSegment[]): unknown;
|
|
155
182
|
declare const SelectorStringSchema: z.ZodString;
|
|
156
183
|
|
|
157
|
-
|
|
184
|
+
/**
|
|
185
|
+
* The verdict as a value (Fraud Engine RFC › API: ALLOW | DENY | REVIEW).
|
|
186
|
+
* Layers combine by severity (GAP-45): the decision is the most severe
|
|
187
|
+
* verdict any layer produced.
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
declare class Verdict {
|
|
191
|
+
readonly value: Decision;
|
|
192
|
+
private constructor();
|
|
193
|
+
static readonly ALLOW: Verdict;
|
|
194
|
+
static readonly REVIEW: Verdict;
|
|
195
|
+
static readonly DENY: Verdict;
|
|
196
|
+
static of(value: Decision): Verdict;
|
|
197
|
+
/** The more severe of the two. */
|
|
198
|
+
atLeast(other: Verdict | Decision): Verdict;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export { ANNOTATION_CODES, type Amount, AmountSchema, type CollectorCode, type DecimalString, DecimalStringSchema, Decision, EvidenceSourceAll, INDICATOR_CODES, type IndicatorCode, JsonValue, Money, type PathSegment, type PolicyRules, PolicyRulesSchema, type Primitive, REASON_CODE_PATTERN, type Rule, type RuleVerdict, type Selector, SelectorStringSchema, Verdict, isSelectorRef, parseSelector, parseSelectorRef, walkPath };
|
package/dist/protocol/index.js
CHANGED
|
@@ -1,148 +1,82 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ALL_SOURCES,
|
|
3
3
|
ANNOTATION_CODES,
|
|
4
|
-
ANOMALY_TYPES,
|
|
5
4
|
AmountSchema,
|
|
6
5
|
ApiErrorSchema,
|
|
7
|
-
COLLECTOR_CODES,
|
|
8
|
-
ChainHeadSchema,
|
|
9
6
|
CreatePolicyInputSchema,
|
|
10
|
-
CreatePolicyOutputSchema,
|
|
11
7
|
CreateSessionInputSchema,
|
|
12
|
-
|
|
13
|
-
DEFAULT_RULE_CODES,
|
|
14
|
-
DecisionSchema,
|
|
8
|
+
DecimalStringSchema,
|
|
15
9
|
DeclaredIntentSchema,
|
|
16
10
|
EvaluateInputSchema,
|
|
17
|
-
EvaluateOutputSchema,
|
|
18
|
-
EventResultSchema,
|
|
19
|
-
EventResultStatusSchema,
|
|
20
|
-
EvidenceAckSchema,
|
|
21
11
|
EvidenceBatchInputSchema,
|
|
22
12
|
EvidenceEventSchema,
|
|
23
|
-
EvidenceKindSchema,
|
|
24
13
|
EvidenceSourceAllSchema,
|
|
25
14
|
EvidenceSourceSchema,
|
|
26
|
-
GatewayDecisionPayloadSchema,
|
|
27
15
|
Hex64Schema,
|
|
28
16
|
INDICATOR_CODES,
|
|
29
|
-
IntentDeclaredPayloadSchema,
|
|
30
17
|
JsonValueSchema,
|
|
31
|
-
LlmCallEndPayloadSchema,
|
|
32
|
-
LlmCallStartPayloadSchema,
|
|
33
18
|
MAX_BATCH_EVENTS,
|
|
34
|
-
|
|
35
|
-
PLATFORM_KINDS,
|
|
36
|
-
PRIMITIVES,
|
|
37
|
-
PaymentMomentPayloadSchema,
|
|
19
|
+
Money,
|
|
38
20
|
PaymentSummarySchema,
|
|
39
|
-
PlatformAnomalyPayloadSchema,
|
|
40
|
-
PlatformEvidenceKindSchema,
|
|
41
|
-
PlatformObservationPayloadSchema,
|
|
42
21
|
PolicyRulesSchema,
|
|
43
|
-
PrimitiveSchema,
|
|
44
22
|
REASON_CODE_PATTERN,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
SESSION_CLOSE_REASONS,
|
|
23
|
+
SESSION_ID_CHARS,
|
|
24
|
+
SESSION_ID_PREFIX,
|
|
48
25
|
SOURCE_ORDER,
|
|
49
26
|
SelectorStringSchema,
|
|
50
|
-
SelectorSyntaxError,
|
|
51
|
-
SeqSchema,
|
|
52
|
-
SessionClosePayloadSchema,
|
|
53
27
|
SessionIdSchema,
|
|
54
|
-
SessionOpenPayloadSchema,
|
|
55
|
-
SigSchema,
|
|
56
28
|
TimestampSchema,
|
|
57
|
-
ToolCallEndPayloadSchema,
|
|
58
|
-
ToolCallStartPayloadSchema,
|
|
59
|
-
TransportGapPayloadSchema,
|
|
60
29
|
Verdict,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
WireEvidenceKindSchema,
|
|
30
|
+
chainKey,
|
|
31
|
+
compareByArrival,
|
|
64
32
|
compareBySessionSource,
|
|
65
33
|
compareBySourceSeq,
|
|
66
|
-
|
|
67
|
-
isPlatformKind,
|
|
34
|
+
compareRootFirst,
|
|
68
35
|
isSelectorRef,
|
|
69
|
-
isWireKind,
|
|
70
36
|
parseSelector,
|
|
71
37
|
parseSelectorRef,
|
|
72
38
|
payloadSchemaFor,
|
|
73
|
-
walkPath
|
|
74
|
-
|
|
39
|
+
walkPath,
|
|
40
|
+
withinHeads
|
|
41
|
+
} from "../chunk-FNU4CRJJ.js";
|
|
75
42
|
export {
|
|
76
43
|
ALL_SOURCES,
|
|
77
44
|
ANNOTATION_CODES,
|
|
78
|
-
ANOMALY_TYPES,
|
|
79
45
|
AmountSchema,
|
|
80
46
|
ApiErrorSchema,
|
|
81
|
-
COLLECTOR_CODES,
|
|
82
|
-
ChainHeadSchema,
|
|
83
47
|
CreatePolicyInputSchema,
|
|
84
|
-
CreatePolicyOutputSchema,
|
|
85
48
|
CreateSessionInputSchema,
|
|
86
|
-
|
|
87
|
-
DEFAULT_RULE_CODES,
|
|
88
|
-
DecisionSchema,
|
|
49
|
+
DecimalStringSchema,
|
|
89
50
|
DeclaredIntentSchema,
|
|
90
51
|
EvaluateInputSchema,
|
|
91
|
-
EvaluateOutputSchema,
|
|
92
|
-
EventResultSchema,
|
|
93
|
-
EventResultStatusSchema,
|
|
94
|
-
EvidenceAckSchema,
|
|
95
52
|
EvidenceBatchInputSchema,
|
|
96
53
|
EvidenceEventSchema,
|
|
97
|
-
EvidenceKindSchema,
|
|
98
54
|
EvidenceSourceAllSchema,
|
|
99
55
|
EvidenceSourceSchema,
|
|
100
|
-
GatewayDecisionPayloadSchema,
|
|
101
56
|
Hex64Schema,
|
|
102
57
|
INDICATOR_CODES,
|
|
103
|
-
IntentDeclaredPayloadSchema,
|
|
104
58
|
JsonValueSchema,
|
|
105
|
-
LlmCallEndPayloadSchema,
|
|
106
|
-
LlmCallStartPayloadSchema,
|
|
107
59
|
MAX_BATCH_EVENTS,
|
|
108
|
-
|
|
109
|
-
PLATFORM_KINDS,
|
|
110
|
-
PRIMITIVES,
|
|
111
|
-
PaymentMomentPayloadSchema,
|
|
60
|
+
Money,
|
|
112
61
|
PaymentSummarySchema,
|
|
113
|
-
PlatformAnomalyPayloadSchema,
|
|
114
|
-
PlatformEvidenceKindSchema,
|
|
115
|
-
PlatformObservationPayloadSchema,
|
|
116
62
|
PolicyRulesSchema,
|
|
117
|
-
PrimitiveSchema,
|
|
118
63
|
REASON_CODE_PATTERN,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
SESSION_CLOSE_REASONS,
|
|
64
|
+
SESSION_ID_CHARS,
|
|
65
|
+
SESSION_ID_PREFIX,
|
|
122
66
|
SOURCE_ORDER,
|
|
123
67
|
SelectorStringSchema,
|
|
124
|
-
SelectorSyntaxError,
|
|
125
|
-
SeqSchema,
|
|
126
|
-
SessionClosePayloadSchema,
|
|
127
68
|
SessionIdSchema,
|
|
128
|
-
SessionOpenPayloadSchema,
|
|
129
|
-
SigSchema,
|
|
130
69
|
TimestampSchema,
|
|
131
|
-
ToolCallEndPayloadSchema,
|
|
132
|
-
ToolCallStartPayloadSchema,
|
|
133
|
-
TransportGapPayloadSchema,
|
|
134
70
|
Verdict,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
WireEvidenceKindSchema,
|
|
71
|
+
chainKey,
|
|
72
|
+
compareByArrival,
|
|
138
73
|
compareBySessionSource,
|
|
139
74
|
compareBySourceSeq,
|
|
140
|
-
|
|
141
|
-
isPlatformKind,
|
|
75
|
+
compareRootFirst,
|
|
142
76
|
isSelectorRef,
|
|
143
|
-
isWireKind,
|
|
144
77
|
parseSelector,
|
|
145
78
|
parseSelectorRef,
|
|
146
79
|
payloadSchemaFor,
|
|
147
|
-
walkPath
|
|
80
|
+
walkPath,
|
|
81
|
+
withinHeads
|
|
148
82
|
};
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { m as EvaluateOutput, D as Decision$1, y as JsonObject, n as EventResult, r as EvidenceEvent, u as EvidenceSource, T as PromptBase, a4 as WireEvidenceKind, P as PayloadByKind, J as JsonValue, a2 as ToolCallStartPayload, Y as SessionClosePayload, h as DeclaredIntent, N as PaymentSummary, K as PaymentMomentPayload } from './index-DAVKGJs5.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The platform's verdict on one payment as a value the host can ask
|
|
5
|
+
* questions of (Fraud Engine RFC › API: ALLOW | DENY | REVIEW). `absent`
|
|
6
|
+
* is the outage case: the platform could not be asked (GAP-70), and no
|
|
7
|
+
* verdict was invented — the host decides what to do without one. A
|
|
8
|
+
* `Session` memoizes decisions by the host's call id, so a re-run approval
|
|
9
|
+
* reads the verdict already given (GAP-79).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
declare class Decision {
|
|
13
|
+
private readonly output;
|
|
14
|
+
private static readonly ABSENT;
|
|
15
|
+
private constructor();
|
|
16
|
+
static of(output: EvaluateOutput): Decision;
|
|
17
|
+
static absent(): Decision;
|
|
18
|
+
get value(): Decision$1 | null;
|
|
19
|
+
get reasonCodes(): readonly string[];
|
|
20
|
+
get decisionId(): string | null;
|
|
21
|
+
get allowed(): boolean;
|
|
22
|
+
get denied(): boolean;
|
|
23
|
+
get review(): boolean;
|
|
24
|
+
get absent(): boolean;
|
|
25
|
+
/** One sentence for the agent or the person: what Beltic said and why. */
|
|
26
|
+
explain(): string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare class BelticApiError extends Error {
|
|
30
|
+
readonly status: number;
|
|
31
|
+
readonly code: string;
|
|
32
|
+
readonly details?: unknown | undefined;
|
|
33
|
+
readonly requestId?: string | undefined;
|
|
34
|
+
constructor(status: number, code: string, message: string, details?: unknown | undefined, requestId?: string | undefined);
|
|
35
|
+
/** 5xx, 429 and network failures are an outage: retried by the transport, absorbed by the fail-open entries; 4xx are neither (GAP-70). */
|
|
36
|
+
get retryable(): boolean;
|
|
37
|
+
}
|
|
38
|
+
declare class ApiClient {
|
|
39
|
+
private readonly baseUrl;
|
|
40
|
+
private readonly headers;
|
|
41
|
+
constructor(baseUrl: string, apiKey: string, userAgent: string);
|
|
42
|
+
post<T>(path: string, body: unknown): Promise<T>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The edge signs event digests (Fraud SDK RFC › Modules › Identity Module);
|
|
47
|
+
* the platform signs its own PLATFORM chain. Both are the same operation
|
|
48
|
+
* over different keys, so one interface.
|
|
49
|
+
*/
|
|
50
|
+
interface Signer {
|
|
51
|
+
/** Raw 32-byte Ed25519 public key. */
|
|
52
|
+
readonly publicKey: Uint8Array;
|
|
53
|
+
/** Stable identifier for logs and key rotation; `did:key` for agents. */
|
|
54
|
+
readonly keyId: string;
|
|
55
|
+
sign(message: Uint8Array): Promise<Uint8Array>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Identity Module (Fraud SDK RFC › Modules): the agent's DID and the
|
|
60
|
+
* event-signing key. Phase 1 is did:key over Ed25519 (GAP-11): the DID *is*
|
|
61
|
+
* the public key, so the signer and the identity are one, both derived from
|
|
62
|
+
* the 32-byte seed the host configures. The credential presented at session
|
|
63
|
+
* start is the DID itself until a VC is verified anywhere (GAP-78).
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
interface AgentIdentity {
|
|
67
|
+
did: string;
|
|
68
|
+
signer: Signer;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* One instrumented call = a `*.start` event, the work, a `*.end` event
|
|
73
|
+
* carrying the outcome or the error (GAP-07 correlates them by `callId`).
|
|
74
|
+
* `openCall` is the span — `Stream.llmCall` and `Stream.toolCall` open
|
|
75
|
+
* one — and `recordCall` runs the work inside it. The AI middleware, the
|
|
76
|
+
* tool wrapper and a host's own tool loop all record the same way.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
interface CallSpan {
|
|
80
|
+
readonly callId: string;
|
|
81
|
+
/** Resolves once `*.start` is sequenced; `end` and `fail` wait for it. */
|
|
82
|
+
readonly opened: Promise<boolean>;
|
|
83
|
+
end(outcome?: JsonObject): Promise<boolean>;
|
|
84
|
+
fail(error: unknown, outcome?: JsonObject): Promise<boolean>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare class ChainRejectedError extends Error {
|
|
88
|
+
readonly sessionId: string;
|
|
89
|
+
readonly source: string;
|
|
90
|
+
readonly result: EventResult;
|
|
91
|
+
constructor(sessionId: string, source: string, result: EventResult, options?: {
|
|
92
|
+
cause?: unknown;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** Which chains a `flush` sends: one session's, or every chain of the process. */
|
|
96
|
+
interface FlushScope {
|
|
97
|
+
sessionId: string;
|
|
98
|
+
}
|
|
99
|
+
declare class Transport {
|
|
100
|
+
private readonly api;
|
|
101
|
+
private readonly chains;
|
|
102
|
+
private readonly waiting;
|
|
103
|
+
private running;
|
|
104
|
+
private buffered;
|
|
105
|
+
private bufferedBytes;
|
|
106
|
+
private timer;
|
|
107
|
+
private closed;
|
|
108
|
+
constructor(api: ApiClient);
|
|
109
|
+
/**
|
|
110
|
+
* What the fail-open entries absorb (GAP-70): the platform could not be
|
|
111
|
+
* reached or failed on its side — a network error, a 5xx, a 429.
|
|
112
|
+
* Everything the platform *rejected* (a 4xx: bad key, unknown session,
|
|
113
|
+
* invalid payload) is a fault of the client and throws.
|
|
114
|
+
*/
|
|
115
|
+
static outage(err: unknown): boolean;
|
|
116
|
+
/** The bytes the platform will measure for an event with this payload (GAP-59), known before a `seq` is spent. */
|
|
117
|
+
static measure(payload: unknown): number;
|
|
118
|
+
/** Whether the platform would take an event of this size at all. */
|
|
119
|
+
static fits(bytes: number): boolean;
|
|
120
|
+
hasRoom(bytes: number): boolean;
|
|
121
|
+
haltedError(sessionId: string, source: string): ChainRejectedError | null;
|
|
122
|
+
/** Whether the platform ended the session under this chain (GAP-85). */
|
|
123
|
+
ended(sessionId: string, source: string): boolean;
|
|
124
|
+
/** Callers check `hasRoom(bytes)` first and assign `seq` only then (GAP-38). */
|
|
125
|
+
enqueue(ev: EvidenceEvent, bytes: number): void;
|
|
126
|
+
/**
|
|
127
|
+
* One attempt per chain, now — a chain waiting out its backoff included;
|
|
128
|
+
* resolves once every attempt settled. With a scope, only that session's
|
|
129
|
+
* chains (GAP-88).
|
|
130
|
+
*/
|
|
131
|
+
flush(scope?: FlushScope): Promise<void>;
|
|
132
|
+
close(): Promise<void>;
|
|
133
|
+
private schedule;
|
|
134
|
+
private unschedule;
|
|
135
|
+
/**
|
|
136
|
+
* Queues the chain for a delivery slot — at the front when forced. A
|
|
137
|
+
* chain waiting out its backoff is left alone unless forced: only
|
|
138
|
+
* `flush` cuts a backoff short.
|
|
139
|
+
*/
|
|
140
|
+
private deliver;
|
|
141
|
+
private promote;
|
|
142
|
+
private pump;
|
|
143
|
+
/** The head of the queue that fits one batch: by count or by bytes, whichever comes first, and never empty. */
|
|
144
|
+
private static batchOf;
|
|
145
|
+
/** Batches until the chain drains; a retryable failure schedules the next attempt and returns. */
|
|
146
|
+
private attempt;
|
|
147
|
+
private release;
|
|
148
|
+
private drop;
|
|
149
|
+
private halt;
|
|
150
|
+
private end;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* One evidence stream = one chain per (sessionId, source), built at the edge
|
|
155
|
+
* (Fraud SDK RFC › Wire contract). The buyer half's AGENT_TRACE stream is
|
|
156
|
+
* signed by the agent identity; the seller half's INTERNAL_NETWORK stream
|
|
157
|
+
* is not (GAP-61).
|
|
158
|
+
*
|
|
159
|
+
* `seq` is handed out only when the transport has room for the event
|
|
160
|
+
* (GAP-38): a dropped event never leaves a hole — the next accepted event
|
|
161
|
+
* is preceded by a `transport.gap` that counts the drops, and how many of
|
|
162
|
+
* them the platform would have refused as too large (GAP-87); the size is
|
|
163
|
+
* measured here, once, before the seq is spent. Payloads ship whole
|
|
164
|
+
* (GAP-33) — except the prompt of a model call, which ships as a delta
|
|
165
|
+
* against the last one on the chain (GAP-89; `PromptLedger`). An outage
|
|
166
|
+
* never reaches `emit`: the transport waits it out (GAP-70); what throws
|
|
167
|
+
* here is a chain the platform rejected. A session the platform closed or
|
|
168
|
+
* expired is over, not broken: `emit` answers `false` and the conversation
|
|
169
|
+
* continues in a fresh stream (GAP-85).
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
/** Who created the session — the seller half treats a bound session as buyer-born. */
|
|
173
|
+
type StreamBorn = 'buyer' | 'seller';
|
|
174
|
+
interface StreamDeps {
|
|
175
|
+
transport: Transport;
|
|
176
|
+
signer?: Signer | undefined;
|
|
177
|
+
/** The conversation's last prompt, when resuming one: what the first model call ships a delta against (GAP-89). */
|
|
178
|
+
prompt?: PromptBase | undefined;
|
|
179
|
+
/** Called once the stream closed, so the registry can forget it. */
|
|
180
|
+
onClosed?: ((stream: Stream) => void) | undefined;
|
|
181
|
+
}
|
|
182
|
+
/** What the host knows of a model call before it runs: the provider-level options, prompt included (GAP-57). */
|
|
183
|
+
interface LlmCallInput {
|
|
184
|
+
callId: string;
|
|
185
|
+
provider: string;
|
|
186
|
+
modelId: string;
|
|
187
|
+
params: Record<string, JsonValue>;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* One tool call as a span: `tool_call.start` now, `tool_call.end` with the
|
|
191
|
+
* outcome and the elapsed time when the host reports it.
|
|
192
|
+
*/
|
|
193
|
+
interface ToolCallSpan {
|
|
194
|
+
readonly callId: string;
|
|
195
|
+
/** Resolves once `tool_call.start` is sequenced; `end` and `fail` wait for it. */
|
|
196
|
+
readonly opened: Promise<boolean>;
|
|
197
|
+
end(outcome?: {
|
|
198
|
+
output?: JsonValue;
|
|
199
|
+
}): Promise<boolean>;
|
|
200
|
+
fail(error: unknown, outcome?: {
|
|
201
|
+
output?: JsonValue;
|
|
202
|
+
}): Promise<boolean>;
|
|
203
|
+
}
|
|
204
|
+
declare class Stream {
|
|
205
|
+
private readonly deps;
|
|
206
|
+
readonly id: string;
|
|
207
|
+
/** The conversation this session belongs to — the root's id (GAP-84). */
|
|
208
|
+
readonly conversationId: string;
|
|
209
|
+
readonly source: EvidenceSource;
|
|
210
|
+
readonly born: StreamBorn;
|
|
211
|
+
private chain;
|
|
212
|
+
private readonly ledger;
|
|
213
|
+
private building;
|
|
214
|
+
private dropped;
|
|
215
|
+
private oversized;
|
|
216
|
+
private droppedFirstTs;
|
|
217
|
+
private droppedLastTs;
|
|
218
|
+
private closed;
|
|
219
|
+
constructor(deps: StreamDeps, id: string,
|
|
220
|
+
/** The conversation this session belongs to — the root's id (GAP-84). */
|
|
221
|
+
conversationId: string, source: EvidenceSource, born: StreamBorn);
|
|
222
|
+
/** Closed by this side, or ended by the platform (GAP-85). */
|
|
223
|
+
get isClosed(): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Resolves once the event is sequenced and buffered — not once it is
|
|
226
|
+
* acknowledged. `false` when the event was dropped for lack of room.
|
|
227
|
+
*/
|
|
228
|
+
emit<K extends WireEvidenceKind>(kind: K, payload: PayloadByKind[K]): Promise<boolean>;
|
|
229
|
+
/** What the drops since the last accepted event add up to (GAP-38/87). */
|
|
230
|
+
private gap;
|
|
231
|
+
/**
|
|
232
|
+
* A model call as a span: `llm_call.start` now, with the prompt as a
|
|
233
|
+
* delta against the last one on this chain (GAP-89), `llm_call.end` when
|
|
234
|
+
* the host reports the result. A start that never left (dropped) forgets
|
|
235
|
+
* the ledger, so the next call ships its prompt whole.
|
|
236
|
+
*/
|
|
237
|
+
llmCall(call: LlmCallInput): CallSpan;
|
|
238
|
+
/** The tool call whose `execute` the host runs itself; see `ToolCallSpan`. */
|
|
239
|
+
toolCall(call: ToolCallStartPayload): ToolCallSpan;
|
|
240
|
+
close(reason?: SessionClosePayload['reason'], extra?: JsonObject): Promise<void>;
|
|
241
|
+
/** Read-your-writes for this session's chains, and only them (GAP-16/66/88). */
|
|
242
|
+
flush(): Promise<void>;
|
|
243
|
+
/** Serialized: two concurrent emits get consecutive seqs, never the same one. */
|
|
244
|
+
private next;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The registry of evidence streams, one object per (session, source) per
|
|
249
|
+
* process: a chain's head lives in it, so two objects for the same chain
|
|
250
|
+
* would both start at seq 0 and fork it. Closed streams are forgotten; a
|
|
251
|
+
* process never continues a chain it did not start — it resumes the
|
|
252
|
+
* conversation in a fresh one (GAP-67/84).
|
|
253
|
+
*
|
|
254
|
+
* The buyer half opens AGENT_TRACE sessions, new or resuming a
|
|
255
|
+
* conversation, and announces them with `session.open` (seq 0) and
|
|
256
|
+
* `intent.declared` (seq 1; GAP-23/60). A session the platform could not
|
|
257
|
+
* open — an outage — resolves `null` for every caller during
|
|
258
|
+
* `OPEN_RETRY_MS`, so the host runs without evidence instead of paying a
|
|
259
|
+
* failed request on every step (GAP-70); a refused one (4xx) throws, and
|
|
260
|
+
* the next call tries again. A resumed conversation's stream starts from
|
|
261
|
+
* the prompt base the platform answered (GAP-89). The seller half attaches
|
|
262
|
+
* to a bound session or opens its own INTERNAL_NETWORK one (GAP-13).
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
interface StartInput {
|
|
266
|
+
intent?: DeclaredIntent | undefined;
|
|
267
|
+
runtime?: {
|
|
268
|
+
framework?: string;
|
|
269
|
+
model?: string;
|
|
270
|
+
} | undefined;
|
|
271
|
+
attestations?: JsonObject | undefined;
|
|
272
|
+
}
|
|
273
|
+
interface OpenInput extends StartInput {
|
|
274
|
+
/** The conversation to continue: any session id of it (GAP-84). */
|
|
275
|
+
resume?: string | undefined;
|
|
276
|
+
}
|
|
277
|
+
interface StreamsDeps {
|
|
278
|
+
api: ApiClient;
|
|
279
|
+
transport: Transport;
|
|
280
|
+
identity: AgentIdentity | null;
|
|
281
|
+
sdkVersion: string;
|
|
282
|
+
}
|
|
283
|
+
declare class Streams {
|
|
284
|
+
private readonly deps;
|
|
285
|
+
private readonly attached;
|
|
286
|
+
private retryAt;
|
|
287
|
+
constructor(deps: StreamsDeps);
|
|
288
|
+
/**
|
|
289
|
+
* Buyer half: a fresh AGENT_TRACE stream — a new conversation, or a new
|
|
290
|
+
* session of the one `resume` names. `null` while the platform is out.
|
|
291
|
+
*/
|
|
292
|
+
open(input?: OpenInput, onClosed?: () => void): Promise<Stream | null>;
|
|
293
|
+
/** Seller half: emit INTERNAL_NETWORK evidence into a session the buyer bound, or open a seller-born one. */
|
|
294
|
+
ensure(sessionId?: string | null): Promise<Stream>;
|
|
295
|
+
/** Whether the platform refused this stream's chain: its next `emit` throws (GAP-85). */
|
|
296
|
+
halted(stream: Stream): boolean;
|
|
297
|
+
private create;
|
|
298
|
+
private attach;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
interface SessionOptions extends StartInput {
|
|
302
|
+
/** Close the session (`expired`) after this long without evidence; unset = only the host closes. */
|
|
303
|
+
idleMs?: number | undefined;
|
|
304
|
+
}
|
|
305
|
+
interface HumanDecisionInput {
|
|
306
|
+
/** Whether the person let the call proceed. */
|
|
307
|
+
allowed: boolean;
|
|
308
|
+
/** The host's own word for what happened: `approved`, `answered`, `rejected`, `cancelled`… */
|
|
309
|
+
outcome: string;
|
|
310
|
+
responder?: string | undefined;
|
|
311
|
+
/** The host's record of what was asked and chosen — a black box to the platform (GAP-75). */
|
|
312
|
+
record?: JsonObject | undefined;
|
|
313
|
+
}
|
|
314
|
+
interface DecideOptions {
|
|
315
|
+
/** The host's id for the call the verdict applies to: memoizes the decision and links it to the span. */
|
|
316
|
+
callId?: string | undefined;
|
|
317
|
+
/** The mandate as of now; declared first when it differs from the last one. */
|
|
318
|
+
intent?: DeclaredIntent | undefined;
|
|
319
|
+
}
|
|
320
|
+
interface SessionDeps {
|
|
321
|
+
streams: Streams;
|
|
322
|
+
evaluate: (sessionId: string, payment: PaymentSummary, callId?: string) => Promise<Decision>;
|
|
323
|
+
/** Called once the platform answered with the conversation id, so the registry can key the handle by it. */
|
|
324
|
+
onOpened: (session: Session, conversationId: string) => void;
|
|
325
|
+
/** Called once the session closed, so the registry forgets it. */
|
|
326
|
+
onClosed: (session: Session) => void;
|
|
327
|
+
}
|
|
328
|
+
declare class Session {
|
|
329
|
+
private readonly deps;
|
|
330
|
+
private readonly opts;
|
|
331
|
+
private opened;
|
|
332
|
+
private current;
|
|
333
|
+
/** The conversation id: what was resumed, then what the platform answered. */
|
|
334
|
+
private conversationId;
|
|
335
|
+
/** JCS hash of the mandate on the chain, and of the one the options carried. */
|
|
336
|
+
private declared;
|
|
337
|
+
private readonly openedWith;
|
|
338
|
+
private closed;
|
|
339
|
+
private timer;
|
|
340
|
+
private readonly calls;
|
|
341
|
+
private readonly decisions;
|
|
342
|
+
constructor(deps: SessionDeps, opts?: SessionOptions, resume?: string | null);
|
|
343
|
+
/**
|
|
344
|
+
* The conversation id — what the host stores and resumes with (GAP-84).
|
|
345
|
+
* Opened on first use; `null` while the platform has not answered and
|
|
346
|
+
* nothing was resumed.
|
|
347
|
+
*/
|
|
348
|
+
id(): Promise<string | null>;
|
|
349
|
+
private open;
|
|
350
|
+
/**
|
|
351
|
+
* The platform's verdict on a payment about to be presented. Asked once
|
|
352
|
+
* per call id: a host that re-runs its approval step reads the same
|
|
353
|
+
* `Decision`. An absent verdict is not memoized, so the next attempt
|
|
354
|
+
* asks again.
|
|
355
|
+
*/
|
|
356
|
+
decide(payment: PaymentSummary | PaymentMomentPayload, opts?: DecideOptions): Promise<Decision>;
|
|
357
|
+
/** The decision given for a call id, or absent. */
|
|
358
|
+
decision(callId: string): Decision;
|
|
359
|
+
/** A tool call the host runs itself, reported as two events by its own call id. */
|
|
360
|
+
readonly tools: {
|
|
361
|
+
start: (call: ToolCallStartPayload) => Promise<boolean>;
|
|
362
|
+
end: (callId: string, outcome?: {
|
|
363
|
+
output?: JsonValue;
|
|
364
|
+
}) => Promise<boolean>;
|
|
365
|
+
fail: (callId: string, error: unknown, outcome?: {
|
|
366
|
+
output?: JsonValue;
|
|
367
|
+
}) => Promise<boolean>;
|
|
368
|
+
};
|
|
369
|
+
/** A person's answer about a call, as the decision it was (GAP-75). */
|
|
370
|
+
humanDecided(callId: string, input: HumanDecisionInput): Promise<boolean>;
|
|
371
|
+
close(reason?: SessionClosePayload['reason']): Promise<void>;
|
|
372
|
+
/** `intent.declared`, unless the mandate is the one already on the chain (GAP-76). */
|
|
373
|
+
private declare;
|
|
374
|
+
private take;
|
|
375
|
+
private touch;
|
|
376
|
+
private static hash;
|
|
377
|
+
private static callOf;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export { BelticApiError as B, ChainRejectedError as C, type DecideOptions as D, type HumanDecisionInput as H, Session as S, Decision as a, type SessionOptions as b };
|