@intentproof/sdk 0.1.4 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -201
- package/README.md +37 -391
- package/dist/canon.d.ts +11 -0
- package/dist/canon.js +17 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +114 -0
- package/dist/exporter.d.ts +12 -0
- package/dist/exporter.js +68 -0
- package/dist/index.d.ts +3 -524
- package/dist/index.js +22 -1119
- package/dist/instrumentation.d.ts +6 -0
- package/dist/instrumentation.js +129 -0
- package/dist/outbox.d.ts +11 -0
- package/dist/outbox.js +53 -0
- package/dist/signing.d.ts +6 -0
- package/dist/signing.js +55 -0
- package/package.json +38 -71
- package/dist/index.cjs +0 -1172
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -524
- package/dist/index.js.map +0 -1
package/dist/exporter.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Posts signed ExecutionEvents to a configured ingest URL when set.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpExporter = void 0;
|
|
7
|
+
exports.resolveIngestURL = resolveIngestURL;
|
|
8
|
+
exports.ingestRequestHeaders = ingestRequestHeaders;
|
|
9
|
+
const DEFAULT_LOCAL_INGEST_URL = 'http://127.0.0.1:9787/v1/events';
|
|
10
|
+
function resolveIngestURL(explicit) {
|
|
11
|
+
const raw = (explicit ?? process.env.INTENTPROOF_INGEST_URL ?? '').trim();
|
|
12
|
+
if (raw) {
|
|
13
|
+
return normalizeIngestURL(raw);
|
|
14
|
+
}
|
|
15
|
+
if (process.env.INTENTPROOF_USE_LOCAL_INGEST === '1') {
|
|
16
|
+
return DEFAULT_LOCAL_INGEST_URL;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function ingestRequestHeaders() {
|
|
21
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
22
|
+
const token = (process.env.INTENTPROOF_INGEST_TOKEN ?? '').trim();
|
|
23
|
+
if (token) {
|
|
24
|
+
headers.Authorization = `Bearer ${token}`;
|
|
25
|
+
}
|
|
26
|
+
return headers;
|
|
27
|
+
}
|
|
28
|
+
function normalizeIngestURL(raw) {
|
|
29
|
+
const trimmed = raw.trim().replace(/\/+$/, '');
|
|
30
|
+
if (trimmed.endsWith('/v1/events')) {
|
|
31
|
+
return trimmed;
|
|
32
|
+
}
|
|
33
|
+
return trimmed + '/v1/events';
|
|
34
|
+
}
|
|
35
|
+
class HttpExporter {
|
|
36
|
+
ingestURL;
|
|
37
|
+
pending = new Set();
|
|
38
|
+
constructor(ingestURL) {
|
|
39
|
+
this.ingestURL = ingestURL;
|
|
40
|
+
}
|
|
41
|
+
enqueue(event) {
|
|
42
|
+
const body = JSON.stringify(event);
|
|
43
|
+
const task = fetch(this.ingestURL, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: ingestRequestHeaders(),
|
|
46
|
+
body,
|
|
47
|
+
})
|
|
48
|
+
.then(async (res) => {
|
|
49
|
+
if (res.status === 202 || res.status === 200) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const text = await res.text().catch(() => '');
|
|
53
|
+
throw new Error(`ingest POST ${res.status}${text ? `: ${text.slice(0, 200)}` : ''}`);
|
|
54
|
+
})
|
|
55
|
+
.catch((err) => {
|
|
56
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
57
|
+
console.warn(`[intentproof] ingest export failed: ${msg}`);
|
|
58
|
+
});
|
|
59
|
+
this.pending.add(task);
|
|
60
|
+
void task.finally(() => {
|
|
61
|
+
this.pending.delete(task);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async flush() {
|
|
65
|
+
await Promise.all([...this.pending]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.HttpExporter = HttpExporter;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,524 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* This file was automatically generated by json-schema-to-typescript.
|
|
5
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
6
|
-
* and run json-schema-to-typescript to regenerate this file.
|
|
7
|
-
*/
|
|
8
|
-
interface IntentProofRuntimeConfigV1 {
|
|
9
|
-
/**
|
|
10
|
-
* Config document version; MUST be 1 for this schema.
|
|
11
|
-
*/
|
|
12
|
-
version?: 1;
|
|
13
|
-
defaultWrapOptions?: IntentProofWrapOptionsV1$1;
|
|
14
|
-
/**
|
|
15
|
-
* Ordered list of exporter identifiers or inline hooks (SDK-defined encoding).
|
|
16
|
-
*/
|
|
17
|
-
exporters?: {
|
|
18
|
-
/**
|
|
19
|
-
* Exporter kind; custom MUST include implementation-specific fields.
|
|
20
|
-
*/
|
|
21
|
-
type: "console" | "http" | "otel" | "custom";
|
|
22
|
-
/**
|
|
23
|
-
* Required for http exporters when used.
|
|
24
|
-
*/
|
|
25
|
-
endpoint?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Optional HTTP headers for http exporters.
|
|
28
|
-
*/
|
|
29
|
-
headers?: {
|
|
30
|
-
[k: string]: string;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* When true, exporter failures MUST NOT change user-visible outcomes.
|
|
34
|
-
*/
|
|
35
|
-
failOpen?: boolean;
|
|
36
|
-
[k: string]: unknown;
|
|
37
|
-
}[];
|
|
38
|
-
correlation?: {
|
|
39
|
-
/**
|
|
40
|
-
* HTTP header used for inbound correlation extraction when applicable.
|
|
41
|
-
*/
|
|
42
|
-
headerName?: string;
|
|
43
|
-
/**
|
|
44
|
-
* When true, SDK generates a UUID when no correlation is active.
|
|
45
|
-
*/
|
|
46
|
-
generateOnMissing?: boolean;
|
|
47
|
-
};
|
|
48
|
-
serialization?: {
|
|
49
|
-
/**
|
|
50
|
-
* Maximum object graph depth for input/output capture.
|
|
51
|
-
*/
|
|
52
|
-
maxDepth?: number;
|
|
53
|
-
/**
|
|
54
|
-
* Maximum serialized string length for any single field.
|
|
55
|
-
*/
|
|
56
|
-
maxStringLength?: number;
|
|
57
|
-
/**
|
|
58
|
-
* Case-insensitive key names to replace with [REDACTED] in captured objects.
|
|
59
|
-
*/
|
|
60
|
-
redactKeys?: string[];
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Process-wide defaults merged under per-wrap options.
|
|
65
|
-
*/
|
|
66
|
-
interface IntentProofWrapOptionsV1$1 {
|
|
67
|
-
/**
|
|
68
|
-
* Default natural-language intent for wrapped executions when the call site does not override it.
|
|
69
|
-
*/
|
|
70
|
-
intent?: string;
|
|
71
|
-
/**
|
|
72
|
-
* Default operation identifier (often dotted like vendor.service.method); SDKs MAY derive from the callable when omitted.
|
|
73
|
-
*/
|
|
74
|
-
action?: string;
|
|
75
|
-
/**
|
|
76
|
-
* When false, inputs MUST be serialized as an empty object {}.
|
|
77
|
-
*/
|
|
78
|
-
captureInputs?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* When false and status is ok, output MUST be null.
|
|
81
|
-
*/
|
|
82
|
-
captureOutput?: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* When true, failures MUST populate error; when false with captureOutput semantics, see semantics/wrap_behavior.md.
|
|
85
|
-
*/
|
|
86
|
-
captureError?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* When false, error.stack MUST be null on emitted events.
|
|
89
|
-
*/
|
|
90
|
-
captureStack?: boolean;
|
|
91
|
-
/**
|
|
92
|
-
* When true, nested wraps inherit the active correlationId.
|
|
93
|
-
*/
|
|
94
|
-
propagateCorrelation?: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Static attributes merged into each emitted ExecutionEvent.attributes.
|
|
97
|
-
*/
|
|
98
|
-
attributes?: {
|
|
99
|
-
[k: string]: string | number | boolean | null;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Maximum time an exporter hook may block the wrap boundary; 0 means SDK default.
|
|
103
|
-
*/
|
|
104
|
-
exporterTimeoutMs?: number;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* This file was automatically generated by json-schema-to-typescript.
|
|
109
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
110
|
-
* and run json-schema-to-typescript to regenerate this file.
|
|
111
|
-
*/
|
|
112
|
-
type IntentProofExecutionEventV1 = {
|
|
113
|
-
[k: string]: unknown;
|
|
114
|
-
} & {
|
|
115
|
-
/**
|
|
116
|
-
* Stable unique identifier for this execution record.
|
|
117
|
-
*/
|
|
118
|
-
id: string;
|
|
119
|
-
/**
|
|
120
|
-
* Natural-language description of what the user or caller was trying to achieve (often a full sentence or question). No fixed grammar; SHOULD stay human-readable in logs and UIs.
|
|
121
|
-
*/
|
|
122
|
-
intent: string;
|
|
123
|
-
/**
|
|
124
|
-
* Stable identifier for the concrete operation. Many systems use hierarchical dotted names (e.g. vendor.resource.operation); REST paths, RPC names, or other conventions are allowed. The schema does not constrain the format.
|
|
125
|
-
*/
|
|
126
|
-
action: string;
|
|
127
|
-
/**
|
|
128
|
-
* Terminal execution status.
|
|
129
|
-
*/
|
|
130
|
-
status: "ok" | "error";
|
|
131
|
-
/**
|
|
132
|
-
* Captured call inputs. Values MUST be JSON-serializable (see semantics/serialization_rules.md).
|
|
133
|
-
*/
|
|
134
|
-
inputs: {
|
|
135
|
-
[k: string]: unknown;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Captured return value when status is ok, or optional captured value when captureError allows output on failure.
|
|
139
|
-
*/
|
|
140
|
-
output?: null | boolean | number | string | JsonValue[] | {
|
|
141
|
-
[k: string]: JsonValue;
|
|
142
|
-
};
|
|
143
|
-
error?: ExecutionError;
|
|
144
|
-
/**
|
|
145
|
-
* RFC 3339 / ISO 8601 instant when execution started.
|
|
146
|
-
*/
|
|
147
|
-
startedAt: string;
|
|
148
|
-
/**
|
|
149
|
-
* RFC 3339 / ISO 8601 instant when execution completed.
|
|
150
|
-
*/
|
|
151
|
-
completedAt: string;
|
|
152
|
-
/**
|
|
153
|
-
* Wall-clock duration in milliseconds between startedAt and completedAt.
|
|
154
|
-
*/
|
|
155
|
-
durationMs: number;
|
|
156
|
-
/**
|
|
157
|
-
* Optional cross-cutting identifier for distributed tracing. MUST be trimmed and non-empty when present.
|
|
158
|
-
*/
|
|
159
|
-
correlationId?: string;
|
|
160
|
-
/**
|
|
161
|
-
* Flat primitive key/value metadata attached to the event.
|
|
162
|
-
*/
|
|
163
|
-
attributes?: {
|
|
164
|
-
[k: string]: string | number | boolean | null;
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Any JSON-serializable value per semantics/serialization_rules.md.
|
|
169
|
-
*/
|
|
170
|
-
type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
171
|
-
[k: string]: JsonValue;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Structured error when status is error.
|
|
175
|
-
*/
|
|
176
|
-
interface ExecutionError {
|
|
177
|
-
/**
|
|
178
|
-
* Exception or error type name (e.g. Error, TypeError).
|
|
179
|
-
*/
|
|
180
|
-
name: string;
|
|
181
|
-
/**
|
|
182
|
-
* Human-readable error message (may be empty string if the runtime provides none).
|
|
183
|
-
*/
|
|
184
|
-
message: string;
|
|
185
|
-
/**
|
|
186
|
-
* Optional stable machine-readable code.
|
|
187
|
-
*/
|
|
188
|
-
code?: string;
|
|
189
|
-
/**
|
|
190
|
-
* Optional stringified stack trace; null when stacks are suppressed.
|
|
191
|
-
*/
|
|
192
|
-
stack?: string | null;
|
|
193
|
-
cause?: ExecutionError1;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Optional chained cause; MUST conform to ExecutionError when present.
|
|
197
|
-
*/
|
|
198
|
-
interface ExecutionError1 {
|
|
199
|
-
/**
|
|
200
|
-
* Exception or error type name (e.g. Error, TypeError).
|
|
201
|
-
*/
|
|
202
|
-
name: string;
|
|
203
|
-
/**
|
|
204
|
-
* Human-readable error message (may be empty string if the runtime provides none).
|
|
205
|
-
*/
|
|
206
|
-
message: string;
|
|
207
|
-
/**
|
|
208
|
-
* Optional stable machine-readable code.
|
|
209
|
-
*/
|
|
210
|
-
code?: string;
|
|
211
|
-
/**
|
|
212
|
-
* Optional stringified stack trace; null when stacks are suppressed.
|
|
213
|
-
*/
|
|
214
|
-
stack?: string | null;
|
|
215
|
-
cause?: ExecutionError1;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* This file was automatically generated by json-schema-to-typescript.
|
|
220
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
221
|
-
* and run json-schema-to-typescript to regenerate this file.
|
|
222
|
-
*/
|
|
223
|
-
interface IntentProofWrapOptionsV1 {
|
|
224
|
-
/**
|
|
225
|
-
* Default natural-language intent for wrapped executions when the call site does not override it.
|
|
226
|
-
*/
|
|
227
|
-
intent?: string;
|
|
228
|
-
/**
|
|
229
|
-
* Default operation identifier (often dotted like vendor.service.method); SDKs MAY derive from the callable when omitted.
|
|
230
|
-
*/
|
|
231
|
-
action?: string;
|
|
232
|
-
/**
|
|
233
|
-
* When false, inputs MUST be serialized as an empty object {}.
|
|
234
|
-
*/
|
|
235
|
-
captureInputs?: boolean;
|
|
236
|
-
/**
|
|
237
|
-
* When false and status is ok, output MUST be null.
|
|
238
|
-
*/
|
|
239
|
-
captureOutput?: boolean;
|
|
240
|
-
/**
|
|
241
|
-
* When true, failures MUST populate error; when false with captureOutput semantics, see semantics/wrap_behavior.md.
|
|
242
|
-
*/
|
|
243
|
-
captureError?: boolean;
|
|
244
|
-
/**
|
|
245
|
-
* When false, error.stack MUST be null on emitted events.
|
|
246
|
-
*/
|
|
247
|
-
captureStack?: boolean;
|
|
248
|
-
/**
|
|
249
|
-
* When true, nested wraps inherit the active correlationId.
|
|
250
|
-
*/
|
|
251
|
-
propagateCorrelation?: boolean;
|
|
252
|
-
/**
|
|
253
|
-
* Static attributes merged into each emitted ExecutionEvent.attributes.
|
|
254
|
-
*/
|
|
255
|
-
attributes?: {
|
|
256
|
-
[k: string]: string | number | boolean | null;
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* Maximum time an exporter hook may block the wrap boundary; 0 means SDK default.
|
|
260
|
-
*/
|
|
261
|
-
exporterTimeoutMs?: number;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Public types for the SDK.
|
|
266
|
-
*
|
|
267
|
-
* Wire shapes (`ExecutionEvent`, `ExecutionError`, JSON `IntentProofConfig` subset) are generated from
|
|
268
|
-
* `intentproof-spec` JSON Schemas — see `src/generated/`. Regenerate: `npm run generate:types -w @intentproof/sdk`.
|
|
269
|
-
* `WrapOptions` adds TypeScript-only capture callbacks and snapshot options; it is not identical to the
|
|
270
|
-
* JSON `wrap_options` schema (see `IntentProofWrapOptionsV1` for the schema flags).
|
|
271
|
-
*/
|
|
272
|
-
|
|
273
|
-
type ExecutionStatus = IntentProofExecutionEventV1["status"];
|
|
274
|
-
/** Wire error payload — same fields as the normative `ExecutionError` object in the JSON Schema. */
|
|
275
|
-
type ExecutionErrorSnapshot = Readonly<ExecutionError>;
|
|
276
|
-
/** One record per wrapped invocation; identical to the `execution_event` v1 schema shape. */
|
|
277
|
-
type ExecutionEvent = Readonly<IntentProofExecutionEventV1>;
|
|
278
|
-
/**
|
|
279
|
-
* Event fields built in {@link import("./client.js").IntentProofClient.wrap} before status, completion
|
|
280
|
-
* time, `output`, and `error` are set. Declared with `Pick` so it stays aligned with the generated
|
|
281
|
-
* wire type (avoids `Omit` on the schema’s index-signature intersection).
|
|
282
|
-
*/
|
|
283
|
-
type ExecutionEventBase = Pick<IntentProofExecutionEventV1, "id" | "intent" | "action" | "inputs" | "startedAt"> & Partial<Pick<IntentProofExecutionEventV1, "correlationId" | "attributes">>;
|
|
284
|
-
interface Exporter {
|
|
285
|
-
/** Must not throw synchronously; async exporters may return a Promise. */
|
|
286
|
-
export(event: ExecutionEvent): void | Promise<void>;
|
|
287
|
-
/** Wait until async side-effects are idle (optional). */
|
|
288
|
-
flush?(): void | Promise<void>;
|
|
289
|
-
/** Stop accepting work and drain (optional). */
|
|
290
|
-
shutdown?(): void | Promise<void>;
|
|
291
|
-
}
|
|
292
|
-
interface SerializeOptions {
|
|
293
|
-
/** Max object nesting when snapshotting (default 6). */
|
|
294
|
-
maxDepth?: number;
|
|
295
|
-
/** Max enumerable own keys per object (default 50). */
|
|
296
|
-
maxKeys?: number;
|
|
297
|
-
/**
|
|
298
|
-
* Own-property keys to replace with `[REDACTED]` (case-insensitive exact match).
|
|
299
|
-
* Nested objects are walked recursively.
|
|
300
|
-
*/
|
|
301
|
-
redactKeys?: string[];
|
|
302
|
-
/** Truncate string primitives longer than this (default unlimited). */
|
|
303
|
-
maxStringLength?: number;
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Call-site `wrap` options. Includes snapshot tuning plus TypeScript-only `capture*` callbacks.
|
|
307
|
-
* For the JSON `wrap_options` document shape (booleans, attributes, etc.), see {@link IntentProofWrapOptionsV1}.
|
|
308
|
-
*/
|
|
309
|
-
interface WrapOptions extends SerializeOptions {
|
|
310
|
-
/** Non-empty after trim; enforced at runtime in {@link import("./client.js").assertWrapOptionsShape}. */
|
|
311
|
-
intent: string;
|
|
312
|
-
/** Non-empty after trim; enforced at runtime in {@link import("./client.js").assertWrapOptionsShape}. */
|
|
313
|
-
action: string;
|
|
314
|
-
/** Non-empty after trim when set; enforced at runtime. Otherwise uses active context. */
|
|
315
|
-
correlationId?: string;
|
|
316
|
-
/** Extra dimensions on the emitted event. */
|
|
317
|
-
attributes?: Readonly<Record<string, string | number | boolean>>;
|
|
318
|
-
captureInput?: (args: unknown[]) => unknown;
|
|
319
|
-
captureOutput?: (result: unknown) => unknown;
|
|
320
|
-
captureError?: (error: unknown) => unknown;
|
|
321
|
-
/**
|
|
322
|
-
* When false, omit `error.stack` from recorded failures (reduces path/log leakage).
|
|
323
|
-
* Overrides {@link IntentProofConfig.includeErrorStack} for this wrap only.
|
|
324
|
-
*/
|
|
325
|
-
includeErrorStack?: boolean;
|
|
326
|
-
}
|
|
327
|
-
type SchemaConfigFields = Partial<Pick<IntentProofRuntimeConfigV1, "version" | "defaultWrapOptions" | "correlation" | "serialization">>;
|
|
328
|
-
/**
|
|
329
|
-
* Runtime SDK configuration. `exporters` are live class instances; all other fields that appear in
|
|
330
|
-
* `intentproof_config` JSON are taken from the generated {@link IntentProofRuntimeConfigV1} shape.
|
|
331
|
-
*/
|
|
332
|
-
type IntentProofConfig = {
|
|
333
|
-
exporters?: Exporter[];
|
|
334
|
-
/** Invoked when an exporter throws synchronously or rejects. Defaults to `console.error` when unset. */
|
|
335
|
-
onExporterError?: (error: unknown, event: ExecutionEvent) => void;
|
|
336
|
-
/** Default attributes merged into every event (e.g. service, env). */
|
|
337
|
-
defaultAttributes?: Readonly<Record<string, string | number | boolean>>;
|
|
338
|
-
/**
|
|
339
|
-
* When false, omit error stack traces from export payloads (default true).
|
|
340
|
-
* Prefer false in production unless you operate a locked-down ingest pipeline.
|
|
341
|
-
*/
|
|
342
|
-
includeErrorStack?: boolean;
|
|
343
|
-
} & SchemaConfigFields;
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Validates a correlation id: non-empty string after trim (same as `WrapOptions.correlationId` /
|
|
347
|
-
* {@link assertWrapOptionsShape}). Used by {@link runWithCorrelationId}.
|
|
348
|
-
*/
|
|
349
|
-
declare function assertCorrelationId(id: unknown): asserts id is string;
|
|
350
|
-
/** Active correlation id from async context, if any. */
|
|
351
|
-
declare function getCorrelationId(): string | undefined;
|
|
352
|
-
/**
|
|
353
|
-
* Run `fn` with an explicit `correlationId` in async context. The id must be a non-empty string
|
|
354
|
-
* after trim ({@link assertCorrelationId}) — the parameter name implies a caller-supplied id.
|
|
355
|
-
*/
|
|
356
|
-
declare function runWithCorrelationId<T>(correlationId: string, fn: () => T): T;
|
|
357
|
-
/** Runtime validation for {@link IntentProofClient.wrap} options. */
|
|
358
|
-
declare function assertWrapOptionsShape(options: WrapOptions): void;
|
|
359
|
-
declare class IntentProofClient {
|
|
360
|
-
private exporters;
|
|
361
|
-
private onExporterError;
|
|
362
|
-
private defaultAttributes;
|
|
363
|
-
private includeErrorStack;
|
|
364
|
-
constructor(config?: IntentProofConfig);
|
|
365
|
-
configure(config: IntentProofConfig): void;
|
|
366
|
-
/**
|
|
367
|
-
* Await optional {@link Exporter.flush} on each exporter (parallel).
|
|
368
|
-
* Used for graceful shutdown or tests.
|
|
369
|
-
*/
|
|
370
|
-
flush(): Promise<void>;
|
|
371
|
-
/**
|
|
372
|
-
* {@link Exporter.shutdown} when present, otherwise {@link Exporter.flush}.
|
|
373
|
-
*/
|
|
374
|
-
shutdown(): Promise<void>;
|
|
375
|
-
/** Read active correlation id (AsyncLocalStorage). */
|
|
376
|
-
getCorrelationId(): string | undefined;
|
|
377
|
-
/**
|
|
378
|
-
* Run `fn` with a generated correlation id for nested `wrap` calls (callers do not supply an id).
|
|
379
|
-
*/
|
|
380
|
-
withCorrelation<T>(fn: () => T): T;
|
|
381
|
-
/**
|
|
382
|
-
* Run `fn` under an optional inbound `correlationId`. Non-empty after trim uses that id;
|
|
383
|
-
* empty or whitespace-only values generate a UUID instead (e.g. missing request header).
|
|
384
|
-
* To require a validated, non-blank id, use {@link runWithCorrelationId}.
|
|
385
|
-
*/
|
|
386
|
-
withCorrelation<T>(correlationId: string, fn: () => T): T;
|
|
387
|
-
/**
|
|
388
|
-
* Wrap a function to emit one `ExecutionEvent` per invocation (sync or async).
|
|
389
|
-
*/
|
|
390
|
-
wrap<A extends unknown[], R>(options: WrapOptions, fn: (...args: A) => R): (...args: A) => R;
|
|
391
|
-
private handleAsync;
|
|
392
|
-
private emitComplete;
|
|
393
|
-
private dispatch;
|
|
394
|
-
}
|
|
395
|
-
declare function getIntentProofClient(): IntentProofClient;
|
|
396
|
-
|
|
397
|
-
/** JSON-safe value for `ExecutionEvent` inputs/output (depth/key limits, optional redaction). */
|
|
398
|
-
declare function snapshot(value: unknown, options?: SerializeOptions): unknown;
|
|
399
|
-
|
|
400
|
-
interface MemoryExporterOptions {
|
|
401
|
-
/** Keep at most this many recent events (default 1000). Must be a finite number >= 1. */
|
|
402
|
-
maxEvents?: number;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Default exporter: ring buffer in memory for debugging and tests.
|
|
406
|
-
*/
|
|
407
|
-
declare class MemoryExporter implements Exporter {
|
|
408
|
-
private readonly maxEvents;
|
|
409
|
-
private readonly events;
|
|
410
|
-
constructor(options?: MemoryExporterOptions);
|
|
411
|
-
export(event: ExecutionEvent): void;
|
|
412
|
-
/** Mutable snapshot for inspection — newest last. */
|
|
413
|
-
getEvents(): readonly ExecutionEvent[];
|
|
414
|
-
clear(): void;
|
|
415
|
-
flush(): Promise<void>;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
interface HttpExporterOptions {
|
|
419
|
-
url: string;
|
|
420
|
-
method?: string;
|
|
421
|
-
headers?: Record<string, string>;
|
|
422
|
-
/** Serialize event for wire format (default JSON body). */
|
|
423
|
-
body?: (event: ExecutionEvent) => string;
|
|
424
|
-
/**
|
|
425
|
-
* When true, await each request (blocks until HTTP completes). Default false.
|
|
426
|
-
*/
|
|
427
|
-
awaitEach?: boolean;
|
|
428
|
-
/** Abort the request after this many milliseconds (global `AbortSignal.timeout`). */
|
|
429
|
-
timeoutMs?: number;
|
|
430
|
-
onError?: (error: unknown, event: ExecutionEvent) => void;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* POST execution events as JSON. Uses global `fetch` (Node 18+).
|
|
434
|
-
* Fire-and-forget by default to avoid slowing callers.
|
|
435
|
-
*/
|
|
436
|
-
declare class HttpExporter implements Exporter {
|
|
437
|
-
private readonly url;
|
|
438
|
-
private readonly method;
|
|
439
|
-
private readonly headers;
|
|
440
|
-
private readonly body;
|
|
441
|
-
private readonly awaitEach;
|
|
442
|
-
private readonly timeoutMs?;
|
|
443
|
-
private readonly onError?;
|
|
444
|
-
private readonly inFlight;
|
|
445
|
-
private closed;
|
|
446
|
-
constructor(options: HttpExporterOptions);
|
|
447
|
-
private track;
|
|
448
|
-
export(event: ExecutionEvent): void | Promise<void>;
|
|
449
|
-
/** Waits until every started request has settled (success or failure). */
|
|
450
|
-
flush(): Promise<void>;
|
|
451
|
-
/** Stops accepting new events and waits for in-flight requests to finish. */
|
|
452
|
-
shutdown(): Promise<void>;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
type QueueOverflowStrategy = "drop-newest" | "drop-oldest";
|
|
456
|
-
interface BoundedQueueExporterOptions {
|
|
457
|
-
/** Downstream exporter (often {@link import("./http.js").HttpExporter}). */
|
|
458
|
-
exporter: Exporter;
|
|
459
|
-
/** Maximum concurrent async exports to the inner exporter (default `4`). */
|
|
460
|
-
maxConcurrent?: number;
|
|
461
|
-
/**
|
|
462
|
-
* Maximum **queued** events waiting for a worker slot (default `1000`).
|
|
463
|
-
* Use `0` for unlimited backlog (not recommended under sustained overload).
|
|
464
|
-
*/
|
|
465
|
-
maxQueue?: number;
|
|
466
|
-
/** How to handle overflow when the queue is full (default `drop-newest`). */
|
|
467
|
-
strategy?: QueueOverflowStrategy;
|
|
468
|
-
onDrop?: (event: ExecutionEvent, reason: string) => void;
|
|
469
|
-
onInnerError?: (error: unknown, event: ExecutionEvent) => void;
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Bounded concurrency + backlog for async-heavy exporters.
|
|
473
|
-
* Sync inner exporters run on the microtask queue and still respect {@link maxConcurrent}.
|
|
474
|
-
*/
|
|
475
|
-
declare class BoundedQueueExporter implements Exporter {
|
|
476
|
-
private readonly inner;
|
|
477
|
-
private readonly maxConcurrent;
|
|
478
|
-
private readonly maxQueue;
|
|
479
|
-
private readonly strategy;
|
|
480
|
-
private readonly onDrop?;
|
|
481
|
-
private readonly onInnerError?;
|
|
482
|
-
private readonly queue;
|
|
483
|
-
private active;
|
|
484
|
-
/** When false, {@link export} drops events with reason `shutdown`; queued work still drains. */
|
|
485
|
-
private accepting;
|
|
486
|
-
private idleResolvers;
|
|
487
|
-
constructor(options: BoundedQueueExporterOptions);
|
|
488
|
-
export(event: ExecutionEvent): void;
|
|
489
|
-
private pump;
|
|
490
|
-
private runInner;
|
|
491
|
-
private resolveIdleWaitersIfNeeded;
|
|
492
|
-
/** Resolves when the queue is empty and no inner export is in flight. */
|
|
493
|
-
flush(): Promise<void>;
|
|
494
|
-
/**
|
|
495
|
-
* Stops accepting new events; does **not** drop items already in the queue—
|
|
496
|
-
* {@link flush} waits until queued and in-flight work finishes.
|
|
497
|
-
*/
|
|
498
|
-
shutdown(): Promise<void>;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/** Compiled validator for `execution_event` v1 (wire / export shape, camelCase keys). */
|
|
502
|
-
declare const validateExecutionEvent: ValidateFunction;
|
|
503
|
-
/** Compiled validator for `wrap_options` v1. */
|
|
504
|
-
declare const validateWrapOptions: ValidateFunction;
|
|
505
|
-
/** Compiled validator for `intentproof_config` v1 (runtime JSON document subset). */
|
|
506
|
-
declare const validateIntentProofConfig: ValidateFunction;
|
|
507
|
-
/**
|
|
508
|
-
* Ensures an execution record matches the pinned `execution_event` schema (throws on failure).
|
|
509
|
-
*/
|
|
510
|
-
declare function assertValidExecutionEventWire(data: unknown): void;
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* @packageDocumentation
|
|
514
|
-
* Structured `ExecutionEvent` emission for verification / ingest pipelines.
|
|
515
|
-
*/
|
|
516
|
-
|
|
517
|
-
declare const VERSION: string;
|
|
518
|
-
|
|
519
|
-
/** Default singleton — same instance as `getIntentProofClient()`. */
|
|
520
|
-
declare const client: IntentProofClient;
|
|
521
|
-
/** Isolated client instance (tests, workers, per-tenant configuration). */
|
|
522
|
-
declare function createIntentProofClient(config?: IntentProofConfig): IntentProofClient;
|
|
523
|
-
|
|
524
|
-
export { BoundedQueueExporter, type BoundedQueueExporterOptions, type ExecutionError, type ExecutionErrorSnapshot, type ExecutionEvent, type ExecutionEventBase, type ExecutionStatus, type Exporter, HttpExporter, type HttpExporterOptions, IntentProofClient, type IntentProofConfig, type IntentProofExecutionEventV1, type IntentProofRuntimeConfigV1, type IntentProofWrapOptionsV1, type JsonValue, MemoryExporter, type MemoryExporterOptions, type QueueOverflowStrategy, type SerializeOptions, VERSION, type WrapOptions, assertCorrelationId, assertValidExecutionEventWire, assertWrapOptionsShape, client, createIntentProofClient, getCorrelationId, getIntentProofClient, runWithCorrelationId, snapshot, validateExecutionEvent, validateIntentProofConfig, validateWrapOptions };
|
|
1
|
+
export { configure, flush, getInstanceId, getOutbox, getPublicKey, getTenantId, SDK_VERSION, } from './client';
|
|
2
|
+
export { pushSubjectMapping, runWithCorrelationId, wrap, } from './instrumentation';
|
|
3
|
+
export { canonicalizeEvent, eventContentHash, loadPrivateKey, signEvent, verifyEventSignature, SENTINEL_PREV_HASH, } from './signing';
|