@intentproof/sdk 0.1.2 → 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/README.md CHANGED
@@ -377,9 +377,13 @@ Custom **`body`** serializers: if **`body(event)`** throws, **`HttpExporter`** n
377
377
 
378
378
  ## Canonical specification (`intentproof-spec`)
379
379
 
380
- Schemas, golden oracles, and the **Vitest conformance oracle** live in the **[IntentProof specification repository (`intentproof-spec`)](https://github.com/intentproof/intentproof-spec)**.
380
+ **Shared pins and terminology** (`INTENTPROOF_SPEC_ROOT`, **`intentproofSpecCommit`**, script names): **[`intentproof-spec` CONTRIBUTING — Terminology](https://github.com/IntentProof/intentproof-spec/blob/main/CONTRIBUTING.md#terminology-shared-with-sdk-repos)**.
381
381
 
382
- - **CI:** every push/PR runs `scripts/run-conformance.sh` from that repo (see `.github/workflows/ci.yml`).
382
+ Schemas, golden oracles, and the **Vitest conformance oracle** live in the **[IntentProof specification repository (`intentproof-spec`)](https://github.com/IntentProof/intentproof-spec)**.
383
+
384
+ - **Version pin:** **`intentproofSpecVersion`** and **`intentproofSpecCommit`** in the root **`package.json`** and **`packages/sdk/package.json`** match **`spec.json`** and the spec **`HEAD`** checkout; **`scripts/check-sdk-spec-pin.sh`** enforces this before conformance.
385
+
386
+ - **CI:** every push/PR checks out this SDK plus **`intentproof-spec`** and runs **`scripts/spec-conformance.sh`** (pin check + full oracle; see `.github/workflows/ci.yml`). The **`sdk`** job sets **`INTENTPROOF_SPEC_ROOT`** so **`packages/sdk`** Vitest also imports the spec **`sdk_test_harness`**—golden **`execution_event_cases.jsonl`** oracle plus a **`MemoryExporter`** **`validateExecutionEvent`** smoke (`spec_conformance.integration.test.ts`).
383
387
  - **Local:** clone `intentproof-spec` **next to** this repository (`../intentproof-spec`), then:
384
388
 
385
389
  ```bash
@@ -388,10 +392,20 @@ Schemas, golden oracles, and the **Vitest conformance oracle** live in the **[In
388
392
 
389
393
  Or set `INTENTPROOF_SPEC_ROOT` to your spec checkout and run `bash scripts/spec-conformance.sh`.
390
394
 
395
+ - **Generated fingerprint metadata:** schema codegen writes **`packages/sdk/src/generated/spec_fingerprint.json`** (spec version, generator version, per-schema SHA-256, aggregate hash). Validate/update generated artifacts with:
396
+
397
+ ```bash
398
+ bash scripts/verify-generated-types.sh
399
+ ```
400
+
401
+ - **No handwritten model types:** **`scripts/check-no-handwritten-model-types.sh`** delegates to the shared **`intentproof-spec`** checker. It is wired into **`npm run ci`**, CI, and release, and fails if schema model/type declarations appear outside **`packages/sdk/src/generated`** or if the bridge aliases in **`packages/sdk/src/types.ts`** stop mapping to generated types.
402
+
391
403
  ---
392
404
 
393
405
  ## Project development
394
406
 
407
+ Contributing and shared **`intentproof-spec`** terminology: **[`CONTRIBUTING.md`](CONTRIBUTING.md)**.
408
+
395
409
  Layout: **npm workspace** (`package.json` **`workspaces`**, publishable package [`packages/sdk`](packages/sdk)). Requires **Node.js** 22 or newer (see `.nvmrc` and workspace **`engines`**). Release history: [`CHANGELOG.md`](CHANGELOG.md).
396
410
 
397
411
  ```bash
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -26,13 +36,17 @@ __export(index_exports, {
26
36
  MemoryExporter: () => MemoryExporter,
27
37
  VERSION: () => VERSION,
28
38
  assertCorrelationId: () => assertCorrelationId,
39
+ assertValidExecutionEventWire: () => assertValidExecutionEventWire,
29
40
  assertWrapOptionsShape: () => assertWrapOptionsShape,
30
41
  client: () => client,
31
42
  createIntentProofClient: () => createIntentProofClient,
32
43
  getCorrelationId: () => getCorrelationId,
33
44
  getIntentProofClient: () => getIntentProofClient,
34
45
  runWithCorrelationId: () => runWithCorrelationId,
35
- snapshot: () => snapshot
46
+ snapshot: () => snapshot,
47
+ validateExecutionEvent: () => validateExecutionEvent,
48
+ validateIntentProofConfig: () => validateIntentProofConfig,
49
+ validateWrapOptions: () => validateWrapOptions
36
50
  });
37
51
  module.exports = __toCommonJS(index_exports);
38
52
 
@@ -164,8 +178,376 @@ function snapshot(value, options = {}) {
164
178
  }
165
179
  }
166
180
 
181
+ // src/validators.ts
182
+ var import__ = require("ajv/dist/2020.js");
183
+ var AjvFormats = __toESM(require("ajv-formats"), 1);
184
+
185
+ // src/generated/embed/execution-event.v1.ts
186
+ var execution_event_v1_default = {
187
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
188
+ $defs: {
189
+ ExecutionError: {
190
+ additionalProperties: false,
191
+ properties: {
192
+ cause: {
193
+ $ref: "#/$defs/ExecutionError",
194
+ description: "Optional chained cause; MUST conform to ExecutionError when present."
195
+ },
196
+ code: { description: "Optional stable machine-readable code.", type: "string" },
197
+ message: {
198
+ description: "Human-readable error message (may be empty string if the runtime provides none).",
199
+ type: "string"
200
+ },
201
+ name: {
202
+ description: "Exception or error type name (e.g. Error, TypeError).",
203
+ minLength: 1,
204
+ type: "string"
205
+ },
206
+ stack: {
207
+ description: "Optional stringified stack trace; null when stacks are suppressed.",
208
+ type: ["string", "null"]
209
+ }
210
+ },
211
+ required: ["name", "message"],
212
+ type: "object"
213
+ },
214
+ JsonValue: {
215
+ anyOf: [
216
+ { type: "null" },
217
+ { type: "boolean" },
218
+ { type: "number" },
219
+ { type: "string" },
220
+ { items: { $ref: "#/$defs/JsonValue" }, type: "array" },
221
+ { additionalProperties: { $ref: "#/$defs/JsonValue" }, type: "object" }
222
+ ],
223
+ description: "Any JSON-serializable value per semantics/serialization_rules.md."
224
+ }
225
+ },
226
+ $id: "https://intentproof.dev/schema/execution_event.v1.schema.json",
227
+ $schema: "https://json-schema.org/draft/2020-12/schema",
228
+ additionalProperties: false,
229
+ allOf: [
230
+ {
231
+ if: { properties: { status: { const: "ok" } }, required: ["status"] },
232
+ then: { not: { required: ["error"] }, required: ["output"] }
233
+ },
234
+ {
235
+ if: { properties: { status: { const: "error" } }, required: ["status"] },
236
+ then: { required: ["error"] }
237
+ }
238
+ ],
239
+ properties: {
240
+ action: {
241
+ description: "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.",
242
+ minLength: 1,
243
+ type: "string"
244
+ },
245
+ attributes: {
246
+ additionalProperties: { type: ["string", "number", "boolean", "null"] },
247
+ description: "Flat primitive key/value metadata attached to the event.",
248
+ propertyNames: { pattern: "^[A-Za-z0-9_.:-]{1,256}$" },
249
+ type: "object"
250
+ },
251
+ completedAt: {
252
+ description: "RFC 3339 / ISO 8601 instant when execution completed.",
253
+ format: "date-time",
254
+ type: "string"
255
+ },
256
+ correlationId: {
257
+ description: "Optional cross-cutting identifier for distributed tracing. MUST be trimmed and non-empty when present.",
258
+ minLength: 1,
259
+ type: "string"
260
+ },
261
+ durationMs: {
262
+ description: "Wall-clock duration in milliseconds between startedAt and completedAt.",
263
+ minimum: 0,
264
+ type: "number"
265
+ },
266
+ error: {
267
+ $ref: "#/$defs/ExecutionError",
268
+ description: "Structured error when status is error."
269
+ },
270
+ id: {
271
+ description: "Stable unique identifier for this execution record.",
272
+ minLength: 1,
273
+ type: "string"
274
+ },
275
+ inputs: {
276
+ additionalProperties: true,
277
+ description: "Captured call inputs. Values MUST be JSON-serializable (see semantics/serialization_rules.md).",
278
+ type: "object"
279
+ },
280
+ intent: {
281
+ description: "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.",
282
+ minLength: 1,
283
+ type: "string"
284
+ },
285
+ output: {
286
+ $ref: "#/$defs/JsonValue",
287
+ description: "Captured return value when status is ok, or optional captured value when captureError allows output on failure."
288
+ },
289
+ startedAt: {
290
+ description: "RFC 3339 / ISO 8601 instant when execution started.",
291
+ format: "date-time",
292
+ type: "string"
293
+ },
294
+ status: {
295
+ description: "Terminal execution status.",
296
+ enum: ["ok", "error"],
297
+ type: "string"
298
+ }
299
+ },
300
+ required: [
301
+ "id",
302
+ "intent",
303
+ "action",
304
+ "status",
305
+ "inputs",
306
+ "startedAt",
307
+ "completedAt",
308
+ "durationMs"
309
+ ],
310
+ title: "IntentProof ExecutionEvent v1",
311
+ type: "object"
312
+ };
313
+
314
+ // src/generated/embed/intentproof-config.v1.ts
315
+ var intentproof_config_v1_default = {
316
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
317
+ $defs: {
318
+ WrapOptionsV1: {
319
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
320
+ $id: "https://intentproof.dev/schema/wrap_options.v1.schema.json",
321
+ $schema: "https://json-schema.org/draft/2020-12/schema",
322
+ additionalProperties: false,
323
+ properties: {
324
+ action: {
325
+ description: "Default operation identifier (often dotted like vendor.service.method); SDKs MAY derive from the callable when omitted.",
326
+ minLength: 1,
327
+ type: "string"
328
+ },
329
+ attributes: {
330
+ additionalProperties: { type: ["string", "number", "boolean", "null"] },
331
+ description: "Static attributes merged into each emitted ExecutionEvent.attributes.",
332
+ type: "object"
333
+ },
334
+ captureError: {
335
+ default: true,
336
+ description: "When true, failures MUST populate error; when false with captureOutput semantics, see semantics/wrap_behavior.md.",
337
+ type: "boolean"
338
+ },
339
+ captureInputs: {
340
+ default: true,
341
+ description: "When false, inputs MUST be serialized as an empty object {}.",
342
+ type: "boolean"
343
+ },
344
+ captureOutput: {
345
+ default: true,
346
+ description: "When false and status is ok, output MUST be null.",
347
+ type: "boolean"
348
+ },
349
+ captureStack: {
350
+ default: true,
351
+ description: "When false, error.stack MUST be null on emitted events.",
352
+ type: "boolean"
353
+ },
354
+ exporterTimeoutMs: {
355
+ description: "Maximum time an exporter hook may block the wrap boundary; 0 means SDK default.",
356
+ minimum: 0,
357
+ type: "number"
358
+ },
359
+ intent: {
360
+ description: "Default natural-language intent for wrapped executions when the call site does not override it.",
361
+ minLength: 1,
362
+ type: "string"
363
+ },
364
+ propagateCorrelation: {
365
+ default: true,
366
+ description: "When true, nested wraps inherit the active correlationId.",
367
+ type: "boolean"
368
+ }
369
+ },
370
+ title: "IntentProof WrapOptions v1",
371
+ type: "object"
372
+ }
373
+ },
374
+ $id: "https://intentproof.dev/schema/intentproof_config.v1.schema.json",
375
+ $schema: "https://json-schema.org/draft/2020-12/schema",
376
+ additionalProperties: false,
377
+ properties: {
378
+ correlation: {
379
+ additionalProperties: false,
380
+ properties: {
381
+ generateOnMissing: {
382
+ default: true,
383
+ description: "When true, SDK generates a UUID when no correlation is active.",
384
+ type: "boolean"
385
+ },
386
+ headerName: {
387
+ default: "x-intentproof-correlation-id",
388
+ description: "HTTP header used for inbound correlation extraction when applicable.",
389
+ type: "string"
390
+ }
391
+ },
392
+ type: "object"
393
+ },
394
+ defaultWrapOptions: { $ref: "#/$defs/WrapOptionsV1" },
395
+ exporters: {
396
+ description: "Ordered list of exporter identifiers or inline hooks (SDK-defined encoding).",
397
+ items: {
398
+ additionalProperties: true,
399
+ properties: {
400
+ endpoint: {
401
+ description: "Required for http exporters when used.",
402
+ format: "uri",
403
+ type: "string"
404
+ },
405
+ failOpen: {
406
+ default: true,
407
+ description: "When true, exporter failures MUST NOT change user-visible outcomes.",
408
+ type: "boolean"
409
+ },
410
+ headers: {
411
+ additionalProperties: { type: "string" },
412
+ description: "Optional HTTP headers for http exporters.",
413
+ type: "object"
414
+ },
415
+ type: {
416
+ description: "Exporter kind; custom MUST include implementation-specific fields.",
417
+ enum: ["console", "http", "otel", "custom"],
418
+ type: "string"
419
+ }
420
+ },
421
+ required: ["type"],
422
+ type: "object"
423
+ },
424
+ type: "array"
425
+ },
426
+ serialization: {
427
+ additionalProperties: false,
428
+ properties: {
429
+ maxDepth: {
430
+ default: 32,
431
+ description: "Maximum object graph depth for input/output capture.",
432
+ minimum: 1,
433
+ type: "integer"
434
+ },
435
+ maxStringLength: {
436
+ default: 65536,
437
+ description: "Maximum serialized string length for any single field.",
438
+ minimum: 1,
439
+ type: "integer"
440
+ },
441
+ redactKeys: {
442
+ description: "Case-insensitive key names to replace with [REDACTED] in captured objects.",
443
+ items: { type: "string" },
444
+ type: "array"
445
+ }
446
+ },
447
+ type: "object"
448
+ },
449
+ version: {
450
+ const: 1,
451
+ description: "Config document version; MUST be 1 for this schema.",
452
+ type: "integer"
453
+ }
454
+ },
455
+ title: "IntentProof Runtime Config v1",
456
+ type: "object"
457
+ };
458
+
459
+ // src/generated/embed/wrap-options.v1.ts
460
+ var wrap_options_v1_default = {
461
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
462
+ $id: "https://intentproof.dev/schema/wrap_options.v1.schema.json",
463
+ $schema: "https://json-schema.org/draft/2020-12/schema",
464
+ additionalProperties: false,
465
+ properties: {
466
+ action: {
467
+ description: "Default operation identifier (often dotted like vendor.service.method); SDKs MAY derive from the callable when omitted.",
468
+ minLength: 1,
469
+ type: "string"
470
+ },
471
+ attributes: {
472
+ additionalProperties: { type: ["string", "number", "boolean", "null"] },
473
+ description: "Static attributes merged into each emitted ExecutionEvent.attributes.",
474
+ type: "object"
475
+ },
476
+ captureError: {
477
+ default: true,
478
+ description: "When true, failures MUST populate error; when false with captureOutput semantics, see semantics/wrap_behavior.md.",
479
+ type: "boolean"
480
+ },
481
+ captureInputs: {
482
+ default: true,
483
+ description: "When false, inputs MUST be serialized as an empty object {}.",
484
+ type: "boolean"
485
+ },
486
+ captureOutput: {
487
+ default: true,
488
+ description: "When false and status is ok, output MUST be null.",
489
+ type: "boolean"
490
+ },
491
+ captureStack: {
492
+ default: true,
493
+ description: "When false, error.stack MUST be null on emitted events.",
494
+ type: "boolean"
495
+ },
496
+ exporterTimeoutMs: {
497
+ description: "Maximum time an exporter hook may block the wrap boundary; 0 means SDK default.",
498
+ minimum: 0,
499
+ type: "number"
500
+ },
501
+ intent: {
502
+ description: "Default natural-language intent for wrapped executions when the call site does not override it.",
503
+ minLength: 1,
504
+ type: "string"
505
+ },
506
+ propagateCorrelation: {
507
+ default: true,
508
+ description: "When true, nested wraps inherit the active correlationId.",
509
+ type: "boolean"
510
+ }
511
+ },
512
+ title: "IntentProof WrapOptions v1",
513
+ type: "object"
514
+ };
515
+
516
+ // src/validators.ts
517
+ var ajv = new import__.Ajv2020({
518
+ allErrors: true,
519
+ strict: false
520
+ });
521
+ var addFormats = AjvFormats.default;
522
+ addFormats(ajv);
523
+ var validateExecutionEvent = ajv.compile(
524
+ execution_event_v1_default
525
+ );
526
+ var validateWrapOptions = ajv.compile(
527
+ wrap_options_v1_default
528
+ );
529
+ var validateIntentProofConfig = ajv.compile(
530
+ intentproof_config_v1_default
531
+ );
532
+ function errorsText(v) {
533
+ return ajv.errorsText(v.errors, { separator: "; " });
534
+ }
535
+ function assertValidExecutionEventWire(data) {
536
+ if (!validateExecutionEvent(data)) {
537
+ throw new TypeError(
538
+ `ExecutionEvent wire JSON failed schema validation: ${errorsText(validateExecutionEvent)}`
539
+ );
540
+ }
541
+ }
542
+
167
543
  // src/client.ts
168
544
  var correlationStore = new import_async_hooks.AsyncLocalStorage();
545
+ function normalizeInputsForExecutionEvent(inputs) {
546
+ if (inputs !== null && typeof inputs === "object" && !Array.isArray(inputs)) {
547
+ return inputs;
548
+ }
549
+ return { args: inputs };
550
+ }
169
551
  function assertCorrelationId(id) {
170
552
  if (typeof id !== "string") {
171
553
  throw new TypeError(
@@ -390,9 +772,12 @@ var IntentProofClient = class {
390
772
  correlationId,
391
773
  intent: options.intent,
392
774
  action: options.action,
393
- inputs,
775
+ inputs: normalizeInputsForExecutionEvent(inputs),
394
776
  startedAt: startedAt.toISOString(),
395
- attributes: mergeAttrs(self.defaultAttributes, options.attributes)
777
+ attributes: mergeAttrs(
778
+ self.defaultAttributes,
779
+ options.attributes
780
+ )
396
781
  };
397
782
  try {
398
783
  const out = fn.apply(this, args);
@@ -500,6 +885,7 @@ var IntentProofClient = class {
500
885
  this.dispatch(event);
501
886
  }
502
887
  dispatch(event) {
888
+ assertValidExecutionEventWire(JSON.parse(JSON.stringify(event)));
503
889
  for (const ex of this.exporters) {
504
890
  try {
505
891
  const r = ex.export(event);
@@ -757,7 +1143,7 @@ var BoundedQueueExporter = class {
757
1143
  };
758
1144
 
759
1145
  // src/index.ts
760
- var VERSION = "0.1.2";
1146
+ var VERSION = "0.1.3";
761
1147
  var client = getIntentProofClient();
762
1148
  function createIntentProofClient(config) {
763
1149
  return new IntentProofClient(config);
@@ -770,12 +1156,16 @@ function createIntentProofClient(config) {
770
1156
  MemoryExporter,
771
1157
  VERSION,
772
1158
  assertCorrelationId,
1159
+ assertValidExecutionEventWire,
773
1160
  assertWrapOptionsShape,
774
1161
  client,
775
1162
  createIntentProofClient,
776
1163
  getCorrelationId,
777
1164
  getIntentProofClient,
778
1165
  runWithCorrelationId,
779
- snapshot
1166
+ snapshot,
1167
+ validateExecutionEvent,
1168
+ validateIntentProofConfig,
1169
+ validateWrapOptions
780
1170
  });
781
1171
  //# sourceMappingURL=index.cjs.map