@intentproof/sdk 0.1.1 → 0.1.3

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/index.d.cts CHANGED
@@ -1,25 +1,286 @@
1
- /** Wire shape for emitted execution records (verification / ingest). */
2
- type ExecutionStatus = "ok" | "error";
3
- interface ExecutionErrorSnapshot {
4
- readonly name: string;
5
- readonly message: string;
6
- readonly stack?: string;
1
+ import { ValidateFunction } from 'ajv';
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
+ };
7
62
  }
8
- /** One record per wrapped invocation — stable fields for a verifier to consume. */
9
- interface ExecutionEvent {
10
- readonly id: string;
11
- readonly correlationId?: string;
12
- readonly intent: string;
13
- readonly action: string;
14
- readonly inputs: unknown;
15
- readonly output?: unknown;
16
- readonly error?: ExecutionErrorSnapshot;
17
- readonly status: ExecutionStatus;
18
- readonly startedAt: string;
19
- readonly completedAt: string;
20
- readonly durationMs: number;
21
- readonly attributes?: Readonly<Record<string, string | number | boolean>>;
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;
22
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">>;
23
284
  interface Exporter {
24
285
  /** Must not throw synchronously; async exporters may return a Promise. */
25
286
  export(event: ExecutionEvent): void | Promise<void>;
@@ -41,6 +302,10 @@ interface SerializeOptions {
41
302
  /** Truncate string primitives longer than this (default unlimited). */
42
303
  maxStringLength?: number;
43
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
+ */
44
309
  interface WrapOptions extends SerializeOptions {
45
310
  /** Non-empty after trim; enforced at runtime in {@link import("./client.js").assertWrapOptionsShape}. */
46
311
  intent: string;
@@ -59,9 +324,14 @@ interface WrapOptions extends SerializeOptions {
59
324
  */
60
325
  includeErrorStack?: boolean;
61
326
  }
62
- interface IntentProofConfig {
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 = {
63
333
  exporters?: Exporter[];
64
- /** Invoked if an exporter throws synchronously or rejects. Defaults to `console.error` when unset. */
334
+ /** Invoked when an exporter throws synchronously or rejects. Defaults to `console.error` when unset. */
65
335
  onExporterError?: (error: unknown, event: ExecutionEvent) => void;
66
336
  /** Default attributes merged into every event (e.g. service, env). */
67
337
  defaultAttributes?: Readonly<Record<string, string | number | boolean>>;
@@ -70,7 +340,7 @@ interface IntentProofConfig {
70
340
  * Prefer false in production unless you operate a locked-down ingest pipeline.
71
341
  */
72
342
  includeErrorStack?: boolean;
73
- }
343
+ } & SchemaConfigFields;
74
344
 
75
345
  /**
76
346
  * Validates a correlation id: non-empty string after trim (same as `WrapOptions.correlationId` /
@@ -228,6 +498,17 @@ declare class BoundedQueueExporter implements Exporter {
228
498
  shutdown(): Promise<void>;
229
499
  }
230
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
+
231
512
  /**
232
513
  * @packageDocumentation
233
514
  * Structured `ExecutionEvent` emission for verification / ingest pipelines.
@@ -240,4 +521,4 @@ declare const client: IntentProofClient;
240
521
  /** Isolated client instance (tests, workers, per-tenant configuration). */
241
522
  declare function createIntentProofClient(config?: IntentProofConfig): IntentProofClient;
242
523
 
243
- export { BoundedQueueExporter, type BoundedQueueExporterOptions, type ExecutionErrorSnapshot, type ExecutionEvent, type ExecutionStatus, type Exporter, HttpExporter, type HttpExporterOptions, IntentProofClient, type IntentProofConfig, MemoryExporter, type MemoryExporterOptions, type QueueOverflowStrategy, type SerializeOptions, VERSION, type WrapOptions, assertCorrelationId, assertWrapOptionsShape, client, createIntentProofClient, getCorrelationId, getIntentProofClient, runWithCorrelationId, snapshot };
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 };