@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.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
 
@@ -132,32 +146,30 @@ function snapshot(value, options = {}) {
132
146
  if (depth >= maxDepth) return "[Array]";
133
147
  return v.slice(0, maxKeys).map((item) => walk(item, depth + 1));
134
148
  }
135
- if (t === "object") {
136
- const o = v;
137
- if (seen.has(o)) return "[Circular]";
138
- seen.add(o);
139
- if (depth >= maxDepth) return "[Object]";
140
- const out = {};
141
- const keys = Object.keys(o);
142
- let n = 0;
143
- for (const k of keys) {
144
- if (n >= maxKeys) {
145
- out["\u2026"] = `${keys.length - maxKeys} more keys`;
146
- break;
147
- }
148
- try {
149
- if (shouldRedactKey(k, redact)) {
150
- out[k] = "[REDACTED]";
151
- } else {
152
- out[k] = walk(o[k], depth + 1);
153
- }
154
- } catch {
155
- out[k] = "[Unserializable]";
149
+ const o = v;
150
+ if (seen.has(o)) return "[Circular]";
151
+ seen.add(o);
152
+ if (depth >= maxDepth) return "[Object]";
153
+ const out = {};
154
+ const keys = Object.keys(o);
155
+ let n = 0;
156
+ for (const k of keys) {
157
+ if (n >= maxKeys) {
158
+ out["\u2026"] = `${keys.length - maxKeys} more keys`;
159
+ break;
160
+ }
161
+ try {
162
+ if (shouldRedactKey(k, redact)) {
163
+ out[k] = "[REDACTED]";
164
+ } else {
165
+ out[k] = walk(o[k], depth + 1);
156
166
  }
157
- n += 1;
167
+ } catch {
168
+ out[k] = "[Unserializable]";
158
169
  }
159
- return out;
170
+ n += 1;
160
171
  }
172
+ return out;
161
173
  }
162
174
  try {
163
175
  return walk(value, 0);
@@ -166,8 +178,376 @@ function snapshot(value, options = {}) {
166
178
  }
167
179
  }
168
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
+
169
543
  // src/client.ts
170
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
+ }
171
551
  function assertCorrelationId(id) {
172
552
  if (typeof id !== "string") {
173
553
  throw new TypeError(
@@ -392,9 +772,12 @@ var IntentProofClient = class {
392
772
  correlationId,
393
773
  intent: options.intent,
394
774
  action: options.action,
395
- inputs,
775
+ inputs: normalizeInputsForExecutionEvent(inputs),
396
776
  startedAt: startedAt.toISOString(),
397
- attributes: mergeAttrs(self.defaultAttributes, options.attributes)
777
+ attributes: mergeAttrs(
778
+ self.defaultAttributes,
779
+ options.attributes
780
+ )
398
781
  };
399
782
  try {
400
783
  const out = fn.apply(this, args);
@@ -502,6 +885,7 @@ var IntentProofClient = class {
502
885
  this.dispatch(event);
503
886
  }
504
887
  dispatch(event) {
888
+ assertValidExecutionEventWire(JSON.parse(JSON.stringify(event)));
505
889
  for (const ex of this.exporters) {
506
890
  try {
507
891
  const r = ex.export(event);
@@ -702,7 +1086,7 @@ var BoundedQueueExporter = class {
702
1086
  if (this.queue.length >= cap) {
703
1087
  if (this.strategy === "drop-oldest") {
704
1088
  const dropped = this.queue.shift();
705
- if (dropped) this.onDrop?.(dropped, "queue-overflow-drop-oldest");
1089
+ this.onDrop?.(dropped, "queue-overflow-drop-oldest");
706
1090
  this.queue.push(event);
707
1091
  } else {
708
1092
  this.onDrop?.(event, "queue-overflow-drop-newest");
@@ -759,7 +1143,7 @@ var BoundedQueueExporter = class {
759
1143
  };
760
1144
 
761
1145
  // src/index.ts
762
- var VERSION = "0.1.1";
1146
+ var VERSION = "0.1.3";
763
1147
  var client = getIntentProofClient();
764
1148
  function createIntentProofClient(config) {
765
1149
  return new IntentProofClient(config);
@@ -772,12 +1156,16 @@ function createIntentProofClient(config) {
772
1156
  MemoryExporter,
773
1157
  VERSION,
774
1158
  assertCorrelationId,
1159
+ assertValidExecutionEventWire,
775
1160
  assertWrapOptionsShape,
776
1161
  client,
777
1162
  createIntentProofClient,
778
1163
  getCorrelationId,
779
1164
  getIntentProofClient,
780
1165
  runWithCorrelationId,
781
- snapshot
1166
+ snapshot,
1167
+ validateExecutionEvent,
1168
+ validateIntentProofConfig,
1169
+ validateWrapOptions
782
1170
  });
783
1171
  //# sourceMappingURL=index.cjs.map