@belticlabs/agent-risk-sdk 0.5.0 → 0.6.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-AjCgj-KM.d.ts +6 -0
- package/dist/ai/index.d.ts +6 -16
- package/dist/ai/index.js +21 -29
- package/dist/{chunk-X3W2Z5GC.js → chunk-77D74TWX.js} +0 -1
- package/dist/{chunk-GM4KEEZB.js → chunk-IUWC6HT5.js} +23 -42
- package/dist/chunk-M4I3FGZG.js +13 -0
- package/dist/chunk-ZMPKY7AX.js +39 -0
- package/dist/client-CgCjOrRP.d.ts +65 -0
- package/dist/{verdict-DMnbFuS5.d.ts → index-IfY4XCvJ.d.ts} +1 -24
- package/dist/index.d.ts +3 -2
- package/dist/index.js +524 -186
- package/dist/protocol/index.d.ts +26 -3
- package/dist/protocol/index.js +487 -74
- package/dist/session-Dcof4UIn.d.ts +308 -0
- package/dist/x402/hono.d.ts +6 -17
- package/dist/x402/hono.js +7 -13
- package/dist/x402/index.d.ts +25 -42
- package/dist/x402/index.js +11 -31
- package/package.json +1 -1
- package/dist/adapter-DEdhsNt-.d.ts +0 -22
- package/dist/chunk-4BUUPU3O.js +0 -558
- package/dist/chunk-JSE6JQJC.js +0 -530
- package/dist/session-D9E-efc0.d.ts +0 -462
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
import { w as EventResult, K as EvidenceEvent, u as EvaluateOutput, ax as Verdict, a3 as OnReview, a8 as PaymentSummary, P as PaymentMomentPayload, D as Decision$1, p as DeclaredIntent, at as ToolCallStartPayload, J as JsonValue, Y as JsonObject, aj as SessionClosePayload, O as EvidenceSource, C as ChainHead, aA as WireEvidenceKind, a6 as PayloadByKind } from './verdict-DMnbFuS5.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The edge signs event digests (Fraud SDK RFC › Modules › Identity Module);
|
|
5
|
-
* the platform signs its own PLATFORM chain. Both are the same operation
|
|
6
|
-
* over different keys, so one interface.
|
|
7
|
-
*/
|
|
8
|
-
interface Signer {
|
|
9
|
-
/** Raw 32-byte Ed25519 public key. */
|
|
10
|
-
readonly publicKey: Uint8Array;
|
|
11
|
-
/** Stable identifier for logs and key rotation; `did:key` for agents. */
|
|
12
|
-
readonly keyId: string;
|
|
13
|
-
sign(message: Uint8Array): Promise<Uint8Array>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface ApiClientOptions {
|
|
17
|
-
baseUrl: string;
|
|
18
|
-
apiKey: string;
|
|
19
|
-
fetch?: typeof globalThis.fetch | undefined;
|
|
20
|
-
userAgent?: string | undefined;
|
|
21
|
-
}
|
|
22
|
-
declare class BelticApiError extends Error {
|
|
23
|
-
readonly status: number;
|
|
24
|
-
readonly code: string;
|
|
25
|
-
readonly details?: unknown | undefined;
|
|
26
|
-
readonly requestId?: string | undefined;
|
|
27
|
-
constructor(status: number, code: string, message: string, details?: unknown | undefined, requestId?: string | undefined);
|
|
28
|
-
/** 5xx, 429 and network failures are retried by the transport and absorbed by `failOpen`; 4xx are neither (GAP-70). */
|
|
29
|
-
get retryable(): boolean;
|
|
30
|
-
}
|
|
31
|
-
declare class ApiClient {
|
|
32
|
-
private readonly baseUrl;
|
|
33
|
-
private readonly fetchImpl;
|
|
34
|
-
private readonly headers;
|
|
35
|
-
constructor(opts: ApiClientOptions);
|
|
36
|
-
post<T>(path: string, body: unknown, headers?: Record<string, string>): Promise<T>;
|
|
37
|
-
get<T>(path: string, query?: Record<string, string | undefined>): Promise<T>;
|
|
38
|
-
private request;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Identity Module (Fraud SDK RFC › Modules): the agent's credential (DID +
|
|
43
|
-
* VC) and the event-signing key. Phase 1 is did:key over Ed25519 (GAP-11):
|
|
44
|
-
* the DID *is* the public key, so the signer and the identity are one.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
interface AgentIdentity {
|
|
48
|
-
did: string;
|
|
49
|
-
signer: Signer;
|
|
50
|
-
/** Opaque credential presented at session start (stored, not verified this phase). */
|
|
51
|
-
credential?: string;
|
|
52
|
-
}
|
|
53
|
-
declare function identityFromSeed(seed: Uint8Array, credential?: string): AgentIdentity;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Transport (Fraud SDK RFC › Modules: "buffering, batching, chained delivery
|
|
57
|
-
* to the Collector"). Contract as assumed in GAP-18/38: one FIFO per
|
|
58
|
-
* chain; at most one batch in flight per chain, so order is preserved;
|
|
59
|
-
* exponential backoff on network / 5xx; a `fork` or `rejected` ack halts
|
|
60
|
-
* the chain and surfaces `ChainRejectedError` — an SDK must not silently
|
|
61
|
-
* keep chaining onto a head the platform never accepted.
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/** What a host may tune; the defaults are `DEFAULT_TUNING`. */
|
|
65
|
-
interface TransportTuning {
|
|
66
|
-
flushMs: number;
|
|
67
|
-
/** Total buffered events across chains; beyond this new events are dropped (GAP-38). */
|
|
68
|
-
maxBuffered: number;
|
|
69
|
-
backoff: {
|
|
70
|
-
baseMs: number;
|
|
71
|
-
maxMs: number;
|
|
72
|
-
maxAttempts: number;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
interface TransportOptions extends TransportTuning {
|
|
76
|
-
onError?: ((err: Error) => void) | undefined;
|
|
77
|
-
onChainHalted?: ((err: ChainRejectedError) => void) | undefined;
|
|
78
|
-
}
|
|
79
|
-
declare class ChainRejectedError extends Error {
|
|
80
|
-
readonly sessionId: string;
|
|
81
|
-
readonly source: string;
|
|
82
|
-
readonly result: EventResult;
|
|
83
|
-
constructor(sessionId: string, source: string, result: EventResult, options?: {
|
|
84
|
-
cause?: unknown;
|
|
85
|
-
});
|
|
86
|
-
/** Halted by retries exhausted on an outage — not by anything the platform rejected (GAP-70). */
|
|
87
|
-
get transient(): boolean;
|
|
88
|
-
}
|
|
89
|
-
declare class Transport {
|
|
90
|
-
private readonly api;
|
|
91
|
-
private readonly opts;
|
|
92
|
-
private readonly chains;
|
|
93
|
-
private buffered;
|
|
94
|
-
private timer;
|
|
95
|
-
private closed;
|
|
96
|
-
private inFlightCount;
|
|
97
|
-
private drainWaiters;
|
|
98
|
-
constructor(api: ApiClient, opts?: Partial<TransportOptions>);
|
|
99
|
-
/**
|
|
100
|
-
* What `failOpen` may absorb (GAP-70): the platform could not be reached
|
|
101
|
-
* or failed on its side — a network error, a 5xx, a 429, or a chain
|
|
102
|
-
* halted after exhausting its retries on those. Everything the platform
|
|
103
|
-
* *rejected* (a 4xx: bad key, unknown session, invalid payload; a `fork`
|
|
104
|
-
* or `rejected` ack) is a fault of the client and throws in both modes.
|
|
105
|
-
*/
|
|
106
|
-
static outage(err: unknown): boolean;
|
|
107
|
-
get size(): number;
|
|
108
|
-
hasRoom(): boolean;
|
|
109
|
-
haltedError(sessionId: string, source: string): ChainRejectedError | null;
|
|
110
|
-
/** Callers check `hasRoom()` first and assign `seq` only then (GAP-38). */
|
|
111
|
-
enqueue(ev: EvidenceEvent): void;
|
|
112
|
-
/** Send everything pending and wait for every in-flight batch to settle (ack or halt). */
|
|
113
|
-
flush(): Promise<void>;
|
|
114
|
-
close(): Promise<void>;
|
|
115
|
-
private schedule;
|
|
116
|
-
private unschedule;
|
|
117
|
-
private drained;
|
|
118
|
-
private settleWaiters;
|
|
119
|
-
private flushChain;
|
|
120
|
-
private send;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* One SDK, two halves (Fraud SDK RFC › Summary). `Beltic` is the single
|
|
125
|
-
* client: sessions and evidence for both halves, `evaluate` for whichever
|
|
126
|
-
* half is about to let a payment through. Protocol integrations are plain
|
|
127
|
-
* functions behind subpath exports, each pulling exactly one optional peer:
|
|
128
|
-
*
|
|
129
|
-
* @belticlabs/agent-risk-sdk/ai → middleware(session), wrapTools(session, …)
|
|
130
|
-
* @belticlabs/agent-risk-sdk/x402 → belticFetch(session), x402Summary(…), attachX402(beltic, …)
|
|
131
|
-
* @belticlabs/agent-risk-sdk/hono → belticPaymentMiddleware(beltic, …)
|
|
132
|
-
*
|
|
133
|
-
* Neither half decides risk locally: verdicts are platform-side.
|
|
134
|
-
*
|
|
135
|
-
* A host that runs its own agent loop takes `beltic.run(key)` — a `Run`
|
|
136
|
-
* keyed by its own session id that owns spans, verdicts and the mandate
|
|
137
|
-
* (GAP-79); every integration above accepts a `Run` where it accepts a
|
|
138
|
-
* `Session`. `Beltic.fromEnv()` reads `BELTIC_*`; a client is configured
|
|
139
|
-
* or it is not constructed — there is no disabled client (GAP-78).
|
|
140
|
-
*
|
|
141
|
-
* Evidence is a side channel of the work it observes. With `failOpen` a
|
|
142
|
-
* platform outage never throws into that work: `Session.emit` reports and
|
|
143
|
-
* answers `false`, `sessions.open` answers `null`, `evaluate` answers
|
|
144
|
-
* `null` — never an invented verdict; the host decides what to do without
|
|
145
|
-
* one. What the platform *rejects* (a 4xx, a forked chain) is the client's
|
|
146
|
-
* fault and throws in both modes (GAP-70). `sessions.start` and
|
|
147
|
-
* `sessions.ensure` throw either way: they are the primitives the fail-open
|
|
148
|
-
* entries are built on.
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
declare const SDK_VERSION = "0.5.0";
|
|
152
|
-
type Env = Record<string, string | undefined>;
|
|
153
|
-
interface BelticOptions {
|
|
154
|
-
apiKey: string;
|
|
155
|
-
baseUrl: string;
|
|
156
|
-
fetch?: typeof globalThis.fetch | undefined;
|
|
157
|
-
/** Buyer half. Without it, `sessions.start` and `open` are unavailable; the seller half works. */
|
|
158
|
-
identity?: AgentIdentity | undefined;
|
|
159
|
-
transport?: Partial<TransportTuning> | undefined;
|
|
160
|
-
/** What a synchronous seller hook does with REVIEW (GAP-52). */
|
|
161
|
-
onReview?: OnReview | undefined;
|
|
162
|
-
/** A platform outage never fails the work evidence observes; see the module note (GAP-70). */
|
|
163
|
-
failOpen?: boolean | undefined;
|
|
164
|
-
/** Where fail-open failures and transport delivery failures go. Default: `console.error`. */
|
|
165
|
-
onError?: ((err: Error) => void) | undefined;
|
|
166
|
-
/** Fail-open only: how long `sessions.open` answers null after the platform could not open a session (GAP-71). */
|
|
167
|
-
openRetryMs?: number | undefined;
|
|
168
|
-
}
|
|
169
|
-
/** What `fromEnv` takes besides the environment: everything the variables do not say. */
|
|
170
|
-
type FromEnvOptions = Omit<BelticOptions, 'apiKey' | 'baseUrl' | 'identity'>;
|
|
171
|
-
/** The platform's answer, with the verdict as a value the caller can ask `blocks(onReview)`. */
|
|
172
|
-
type Evaluation = EvaluateOutput & {
|
|
173
|
-
verdict: Verdict;
|
|
174
|
-
};
|
|
175
|
-
declare class Beltic {
|
|
176
|
-
readonly transport: Transport;
|
|
177
|
-
readonly sessions: Sessions;
|
|
178
|
-
readonly identity: AgentIdentity | undefined;
|
|
179
|
-
readonly onReview: OnReview;
|
|
180
|
-
readonly failOpen: boolean;
|
|
181
|
-
private readonly api;
|
|
182
|
-
private readonly onError;
|
|
183
|
-
private readonly runs;
|
|
184
|
-
/**
|
|
185
|
-
* The client the environment describes: `BELTIC_API_KEY`,
|
|
186
|
-
* `BELTIC_BASE_URL`, `BELTIC_AGENT_SEED` (64 hex) and optionally
|
|
187
|
-
* `BELTIC_AGENT_CREDENTIAL`. Any of the three missing is a configuration
|
|
188
|
-
* error, thrown (GAP-78).
|
|
189
|
-
*/
|
|
190
|
-
static fromEnv(env?: Env, opts?: FromEnvOptions): Beltic;
|
|
191
|
-
constructor(opts: BelticOptions);
|
|
192
|
-
/**
|
|
193
|
-
* The platform's verdict on a payment — the seller's before it verifies,
|
|
194
|
-
* the buyer's before it presents. Read-your-writes: the buffered evidence
|
|
195
|
-
* is flushed first so the platform judges what the caller already saw
|
|
196
|
-
* (GAP-16). A recorded moment is accepted as is: only its comparable core
|
|
197
|
-
* (payee, amount, payer) is sent. `null` only under `failOpen`, when the
|
|
198
|
-
* platform could not be reached.
|
|
199
|
-
*/
|
|
200
|
-
evaluate(sessionId: string, payment: PaymentSummary | PaymentMomentPayload): Promise<Evaluation | null>;
|
|
201
|
-
private decide;
|
|
202
|
-
/**
|
|
203
|
-
* The run for a key of the host's own — one object per key until it
|
|
204
|
-
* closes (the options count on the first call only). See `Run`.
|
|
205
|
-
*/
|
|
206
|
-
run(key: string, opts?: RunOptions): Run;
|
|
207
|
-
flush(): Promise<void>;
|
|
208
|
-
shutdown(): Promise<void>;
|
|
209
|
-
/** `process.env` where there is a `process` (Node); `{}` on workerd, where the shell passes its `env`. */
|
|
210
|
-
private static processEnv;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* The platform's verdict on one payment as a value the host can ask
|
|
215
|
-
* questions of (Fraud Engine RFC › API: ALLOW | DENY | REVIEW). `absent`
|
|
216
|
-
* is the fail-open case: the platform could not be asked (GAP-70), and no
|
|
217
|
-
* verdict was invented — the host decides what to do without one. A
|
|
218
|
-
* `Run` memoizes decisions by the host's call id, so a re-run approval
|
|
219
|
-
* reads the verdict already given (GAP-79).
|
|
220
|
-
*/
|
|
221
|
-
|
|
222
|
-
declare class Decision {
|
|
223
|
-
readonly evaluation: Evaluation | null;
|
|
224
|
-
private static readonly ABSENT;
|
|
225
|
-
private constructor();
|
|
226
|
-
static of(evaluation: Evaluation): Decision;
|
|
227
|
-
static absent(): Decision;
|
|
228
|
-
get value(): Decision$1 | null;
|
|
229
|
-
get reasonCodes(): readonly string[];
|
|
230
|
-
get decisionId(): string | null;
|
|
231
|
-
get allowed(): boolean;
|
|
232
|
-
get denied(): boolean;
|
|
233
|
-
get review(): boolean;
|
|
234
|
-
get absent(): boolean;
|
|
235
|
-
/** Whether a gate must stop the payment (GAP-52); an absent verdict never blocks. */
|
|
236
|
-
blocks(onReview: OnReview): boolean;
|
|
237
|
-
/** One sentence for the agent or the person: what Beltic said and why. */
|
|
238
|
-
explain(): string;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
interface RunOptions {
|
|
242
|
-
/** What `sessions.open` sends when this run actually opens a session. */
|
|
243
|
-
open?: OpenSessionInput | undefined;
|
|
244
|
-
/** Close the session (`expired`) after this long without evidence; unset = only the host closes. */
|
|
245
|
-
idleMs?: number | undefined;
|
|
246
|
-
}
|
|
247
|
-
interface HumanDecisionInput {
|
|
248
|
-
/** Whether the person let the call proceed. */
|
|
249
|
-
allowed: boolean;
|
|
250
|
-
/** The host's own word for what happened: `approved`, `answered`, `rejected`, `cancelled`… */
|
|
251
|
-
outcome: string;
|
|
252
|
-
responder?: string | undefined;
|
|
253
|
-
/** The host's record of what was asked and chosen — a black box to the platform (GAP-75). */
|
|
254
|
-
record?: JsonObject | undefined;
|
|
255
|
-
}
|
|
256
|
-
interface DecideOptions {
|
|
257
|
-
/** The host's id for the call the verdict applies to: memoizes the decision and links it to the span. */
|
|
258
|
-
callId?: string | undefined;
|
|
259
|
-
/** The mandate as of now; declared first when it differs from the last one. */
|
|
260
|
-
intent?: DeclaredIntent | undefined;
|
|
261
|
-
}
|
|
262
|
-
interface RunDeps {
|
|
263
|
-
sessions: Sessions;
|
|
264
|
-
evaluate: (sessionId: string, payment: PaymentSummary | PaymentMomentPayload) => Promise<Evaluation | null>;
|
|
265
|
-
/** Called once the run closed, so the registry forgets it. */
|
|
266
|
-
onClosed: (run: Run) => void;
|
|
267
|
-
}
|
|
268
|
-
declare class Run {
|
|
269
|
-
private readonly deps;
|
|
270
|
-
readonly key: string;
|
|
271
|
-
private readonly opts;
|
|
272
|
-
private opened;
|
|
273
|
-
private current;
|
|
274
|
-
/** JCS hash of the mandate on the chain, and of the one the open input carried. */
|
|
275
|
-
private declared;
|
|
276
|
-
private openedWith;
|
|
277
|
-
private closed;
|
|
278
|
-
private timer;
|
|
279
|
-
private readonly calls;
|
|
280
|
-
private readonly decisions;
|
|
281
|
-
private readonly byPayment;
|
|
282
|
-
constructor(deps: RunDeps, key: string, opts?: RunOptions);
|
|
283
|
-
/** The session this run records into — opened on first use, `null` when there is none. */
|
|
284
|
-
session(): Promise<Session | null>;
|
|
285
|
-
private readonly opener;
|
|
286
|
-
/** `intent.declared`, unless the mandate is the one already on the chain. */
|
|
287
|
-
declare(intent: DeclaredIntent): Promise<boolean>;
|
|
288
|
-
/**
|
|
289
|
-
* The platform's verdict on a payment about to be presented. Asked once
|
|
290
|
-
* per call id: a host that re-runs its approval step reads the same
|
|
291
|
-
* `Decision`. An absent verdict is not memoized, so the next attempt
|
|
292
|
-
* asks again.
|
|
293
|
-
*/
|
|
294
|
-
decide(payment: PaymentSummary | PaymentMomentPayload, opts?: DecideOptions): Promise<Decision>;
|
|
295
|
-
/** The decision given for a call id, or absent. */
|
|
296
|
-
decision(callId: string): Decision;
|
|
297
|
-
/**
|
|
298
|
-
* The decision given for a payment with the same comparable core (payee,
|
|
299
|
-
* amount, payer — or payee and amount when one side names no payer), or
|
|
300
|
-
* absent.
|
|
301
|
-
*/
|
|
302
|
-
decisionFor(payment: PaymentSummary | PaymentMomentPayload): Decision;
|
|
303
|
-
/** A tool call the host runs itself, reported as two events by its own call id. */
|
|
304
|
-
readonly tools: {
|
|
305
|
-
start: (call: ToolCallStartPayload) => Promise<boolean>;
|
|
306
|
-
end: (callId: string, outcome?: {
|
|
307
|
-
output?: JsonValue;
|
|
308
|
-
}) => Promise<boolean>;
|
|
309
|
-
fail: (callId: string, error: unknown, outcome?: {
|
|
310
|
-
output?: JsonValue;
|
|
311
|
-
}) => Promise<boolean>;
|
|
312
|
-
};
|
|
313
|
-
/** A person's answer about a call, as the decision it was (GAP-75). */
|
|
314
|
-
humanDecided(callId: string, input: HumanDecisionInput): Promise<boolean>;
|
|
315
|
-
close(reason?: SessionClosePayload['reason']): Promise<void>;
|
|
316
|
-
private take;
|
|
317
|
-
private touch;
|
|
318
|
-
private static hash;
|
|
319
|
-
/** With the payer first, then without it. */
|
|
320
|
-
private static paymentKeys;
|
|
321
|
-
private static callOf;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* A risk session as the SDK sees it: one chain per (sessionId, source),
|
|
326
|
-
* built at the edge (Fraud SDK RFC › Wire contract). The buyer half opens
|
|
327
|
-
* AGENT_TRACE sessions and announces them with `session.open` (seq 0) and
|
|
328
|
-
* `intent.declared` (seq 1; GAP-23/60); the seller half attaches to a bound
|
|
329
|
-
* session or opens its own INTERNAL_NETWORK session (GAP-13).
|
|
330
|
-
*
|
|
331
|
-
* `seq` is handed out only when the transport has room for the event
|
|
332
|
-
* (GAP-38): a dropped event never leaves a hole — the next accepted event
|
|
333
|
-
* is preceded by a `transport.gap` that counts the drops. Payloads ship
|
|
334
|
-
* whole (GAP-33).
|
|
335
|
-
*
|
|
336
|
-
* Evidence is a side channel of the agent's work: with `failOpen` an emit
|
|
337
|
-
* refused because the platform is unreachable is reported and returns
|
|
338
|
-
* `false` instead of throwing into the model or tool call it observes;
|
|
339
|
-
* anything the platform rejected still throws (GAP-70).
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
|
-
/** Who created the session — the seller half treats a bound session as buyer-born. */
|
|
343
|
-
type SessionBorn = 'buyer' | 'seller';
|
|
344
|
-
interface SessionDeps {
|
|
345
|
-
transport: Transport;
|
|
346
|
-
signer?: Signer | undefined;
|
|
347
|
-
now?: (() => Date) | undefined;
|
|
348
|
-
/** Called once the session closed, so the registry can forget it. */
|
|
349
|
-
onClosed?: ((session: Session) => void) | undefined;
|
|
350
|
-
/** Report instead of throw when the platform is unreachable (GAP-70). */
|
|
351
|
-
failOpen?: boolean | undefined;
|
|
352
|
-
onError?: ((err: Error) => void) | undefined;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* One tool call as a span: `tool_call.start` now, `tool_call.end` with the
|
|
356
|
-
* outcome and the elapsed time when the host reports it. For hosts that run
|
|
357
|
-
* their own tool loop and cannot hand the SDK an `execute` to wrap.
|
|
358
|
-
*/
|
|
359
|
-
interface ToolCallSpan {
|
|
360
|
-
readonly callId: string;
|
|
361
|
-
/** Resolves once `tool_call.start` is sequenced; `end` and `fail` wait for it. */
|
|
362
|
-
readonly opened: Promise<boolean>;
|
|
363
|
-
end(outcome?: {
|
|
364
|
-
output?: JsonValue;
|
|
365
|
-
}): Promise<boolean>;
|
|
366
|
-
fail(error: unknown, outcome?: {
|
|
367
|
-
output?: JsonValue;
|
|
368
|
-
}): Promise<boolean>;
|
|
369
|
-
}
|
|
370
|
-
declare class Session {
|
|
371
|
-
private readonly deps;
|
|
372
|
-
readonly id: string;
|
|
373
|
-
readonly source: EvidenceSource;
|
|
374
|
-
readonly expiresAt: string | null;
|
|
375
|
-
readonly born: SessionBorn;
|
|
376
|
-
private chain;
|
|
377
|
-
private building;
|
|
378
|
-
private dropped;
|
|
379
|
-
private droppedFirstTs;
|
|
380
|
-
private droppedLastTs;
|
|
381
|
-
private closed;
|
|
382
|
-
private readonly now;
|
|
383
|
-
constructor(deps: SessionDeps, id: string, source: EvidenceSource, expiresAt: string | null, born: SessionBorn);
|
|
384
|
-
get head(): ChainHead | null;
|
|
385
|
-
get droppedCount(): number;
|
|
386
|
-
get isClosed(): boolean;
|
|
387
|
-
/**
|
|
388
|
-
* Resolves once the event is sequenced and buffered — not once it is
|
|
389
|
-
* acknowledged. `false` when the event was dropped, or (fail-open) when
|
|
390
|
-
* the chain halted on an outage.
|
|
391
|
-
*/
|
|
392
|
-
emit<K extends WireEvidenceKind>(kind: K, payload: PayloadByKind[K]): Promise<boolean>;
|
|
393
|
-
/** The tool call whose `execute` the host runs itself; see `ToolCallSpan`. */
|
|
394
|
-
toolCall(call: ToolCallStartPayload): ToolCallSpan;
|
|
395
|
-
private chainEvent;
|
|
396
|
-
close(reason?: SessionClosePayload['reason'], extra?: JsonObject): Promise<void>;
|
|
397
|
-
/** Read-your-writes: the platform must hold the evidence before anyone judges it (GAP-16/66). */
|
|
398
|
-
flush(): Promise<void>;
|
|
399
|
-
/** Serialized: two concurrent emits get consecutive seqs, never the same one. */
|
|
400
|
-
private next;
|
|
401
|
-
}
|
|
402
|
-
interface StartSessionInput {
|
|
403
|
-
intent?: DeclaredIntent;
|
|
404
|
-
runtime?: {
|
|
405
|
-
framework?: string;
|
|
406
|
-
model?: string;
|
|
407
|
-
};
|
|
408
|
-
attestations?: JsonObject;
|
|
409
|
-
}
|
|
410
|
-
/** What `open` sends when it actually opens: a value, or a resolver run only then. */
|
|
411
|
-
type OpenSessionInput = StartSessionInput | (() => StartSessionInput | Promise<StartSessionInput>);
|
|
412
|
-
/** What an integration takes: a session, or the run that owns one — resolved by `Sessions.resolve`. */
|
|
413
|
-
type SessionSource = Session | Run;
|
|
414
|
-
interface SessionsDeps {
|
|
415
|
-
api: ApiClient;
|
|
416
|
-
transport: Transport;
|
|
417
|
-
identity?: AgentIdentity | undefined;
|
|
418
|
-
sdkVersion: string;
|
|
419
|
-
failOpen?: boolean | undefined;
|
|
420
|
-
onError?: ((err: Error) => void) | undefined;
|
|
421
|
-
/** Fail-open only: after the platform could not open a session, `open` resolves null for this long (GAP-71). */
|
|
422
|
-
openRetryMs?: number | undefined;
|
|
423
|
-
}
|
|
424
|
-
declare class Sessions {
|
|
425
|
-
private readonly deps;
|
|
426
|
-
/**
|
|
427
|
-
* One session object per (session, source) per process: a chain's head
|
|
428
|
-
* lives in it, so two objects for the same chain would both start at
|
|
429
|
-
* seq 0 and fork it. Closed sessions are forgotten; a process restart
|
|
430
|
-
* mid-session still loses the head (GAP-67).
|
|
431
|
-
*/
|
|
432
|
-
private readonly attached;
|
|
433
|
-
/** Buyer sessions by the host's own key (GAP-71). */
|
|
434
|
-
private readonly opened;
|
|
435
|
-
private retryAt;
|
|
436
|
-
constructor(deps: SessionsDeps);
|
|
437
|
-
/** The session behind a source: itself, or the one the run opens (null when the run has none). */
|
|
438
|
-
static resolve(source: SessionSource): Promise<Session | null>;
|
|
439
|
-
/**
|
|
440
|
-
* Buyer half: the evidence session for a key of the host's own (its
|
|
441
|
-
* session, run or conversation id), opened on first use and reused
|
|
442
|
-
* after. A halted chain is reopened as a fresh session that continues
|
|
443
|
-
* the same key; a closed key is forgotten. When the platform cannot be
|
|
444
|
-
* reached, a fail-open client resolves null — the host runs without
|
|
445
|
-
* evidence — until `openRetryMs` has passed (GAP-71); otherwise, and
|
|
446
|
-
* whenever the platform refused, the error is thrown and the next call
|
|
447
|
-
* tries again. The identity is configuration: missing, it throws either
|
|
448
|
-
* way.
|
|
449
|
-
*/
|
|
450
|
-
open(key: string, input?: OpenSessionInput): Promise<Session | null>;
|
|
451
|
-
private forget;
|
|
452
|
-
private openFresh;
|
|
453
|
-
/** Buyer half: create an AGENT_TRACE session bound to the agent identity, then announce it on the chain. */
|
|
454
|
-
start(input?: StartSessionInput): Promise<Session>;
|
|
455
|
-
private identityFor;
|
|
456
|
-
private create;
|
|
457
|
-
/** Seller half: emit INTERNAL_NETWORK evidence into a session the buyer bound, or open a seller-born one. */
|
|
458
|
-
ensure(sessionId?: string | null): Promise<Session>;
|
|
459
|
-
private attach;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export { type AgentIdentity as A, Beltic as B, ChainRejectedError as C, type DecideOptions as D, type Env as E, type FromEnvOptions as F, type HumanDecisionInput as H, type OpenSessionInput as O, Run as R, type SessionSource as S, type ToolCallSpan as T, ApiClient as a, type ApiClientOptions as b, BelticApiError as c, type BelticOptions as d, Decision as e, type Evaluation as f, type RunOptions as g, SDK_VERSION as h, Session as i, type SessionBorn as j, Sessions as k, type StartSessionInput as l, Transport as m, type TransportOptions as n, type TransportTuning as o, identityFromSeed as p };
|