@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.js CHANGED
@@ -94,32 +94,30 @@ function snapshot(value, options = {}) {
94
94
  if (depth >= maxDepth) return "[Array]";
95
95
  return v.slice(0, maxKeys).map((item) => walk(item, depth + 1));
96
96
  }
97
- if (t === "object") {
98
- const o = v;
99
- if (seen.has(o)) return "[Circular]";
100
- seen.add(o);
101
- if (depth >= maxDepth) return "[Object]";
102
- const out = {};
103
- const keys = Object.keys(o);
104
- let n = 0;
105
- for (const k of keys) {
106
- if (n >= maxKeys) {
107
- out["\u2026"] = `${keys.length - maxKeys} more keys`;
108
- break;
109
- }
110
- try {
111
- if (shouldRedactKey(k, redact)) {
112
- out[k] = "[REDACTED]";
113
- } else {
114
- out[k] = walk(o[k], depth + 1);
115
- }
116
- } catch {
117
- out[k] = "[Unserializable]";
97
+ const o = v;
98
+ if (seen.has(o)) return "[Circular]";
99
+ seen.add(o);
100
+ if (depth >= maxDepth) return "[Object]";
101
+ const out = {};
102
+ const keys = Object.keys(o);
103
+ let n = 0;
104
+ for (const k of keys) {
105
+ if (n >= maxKeys) {
106
+ out["\u2026"] = `${keys.length - maxKeys} more keys`;
107
+ break;
108
+ }
109
+ try {
110
+ if (shouldRedactKey(k, redact)) {
111
+ out[k] = "[REDACTED]";
112
+ } else {
113
+ out[k] = walk(o[k], depth + 1);
118
114
  }
119
- n += 1;
115
+ } catch {
116
+ out[k] = "[Unserializable]";
120
117
  }
121
- return out;
118
+ n += 1;
122
119
  }
120
+ return out;
123
121
  }
124
122
  try {
125
123
  return walk(value, 0);
@@ -128,8 +126,376 @@ function snapshot(value, options = {}) {
128
126
  }
129
127
  }
130
128
 
129
+ // src/validators.ts
130
+ import { Ajv2020 } from "ajv/dist/2020.js";
131
+ import * as AjvFormats from "ajv-formats";
132
+
133
+ // src/generated/embed/execution-event.v1.ts
134
+ var execution_event_v1_default = {
135
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
136
+ $defs: {
137
+ ExecutionError: {
138
+ additionalProperties: false,
139
+ properties: {
140
+ cause: {
141
+ $ref: "#/$defs/ExecutionError",
142
+ description: "Optional chained cause; MUST conform to ExecutionError when present."
143
+ },
144
+ code: { description: "Optional stable machine-readable code.", type: "string" },
145
+ message: {
146
+ description: "Human-readable error message (may be empty string if the runtime provides none).",
147
+ type: "string"
148
+ },
149
+ name: {
150
+ description: "Exception or error type name (e.g. Error, TypeError).",
151
+ minLength: 1,
152
+ type: "string"
153
+ },
154
+ stack: {
155
+ description: "Optional stringified stack trace; null when stacks are suppressed.",
156
+ type: ["string", "null"]
157
+ }
158
+ },
159
+ required: ["name", "message"],
160
+ type: "object"
161
+ },
162
+ JsonValue: {
163
+ anyOf: [
164
+ { type: "null" },
165
+ { type: "boolean" },
166
+ { type: "number" },
167
+ { type: "string" },
168
+ { items: { $ref: "#/$defs/JsonValue" }, type: "array" },
169
+ { additionalProperties: { $ref: "#/$defs/JsonValue" }, type: "object" }
170
+ ],
171
+ description: "Any JSON-serializable value per semantics/serialization_rules.md."
172
+ }
173
+ },
174
+ $id: "https://intentproof.dev/schema/execution_event.v1.schema.json",
175
+ $schema: "https://json-schema.org/draft/2020-12/schema",
176
+ additionalProperties: false,
177
+ allOf: [
178
+ {
179
+ if: { properties: { status: { const: "ok" } }, required: ["status"] },
180
+ then: { not: { required: ["error"] }, required: ["output"] }
181
+ },
182
+ {
183
+ if: { properties: { status: { const: "error" } }, required: ["status"] },
184
+ then: { required: ["error"] }
185
+ }
186
+ ],
187
+ properties: {
188
+ action: {
189
+ 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.",
190
+ minLength: 1,
191
+ type: "string"
192
+ },
193
+ attributes: {
194
+ additionalProperties: { type: ["string", "number", "boolean", "null"] },
195
+ description: "Flat primitive key/value metadata attached to the event.",
196
+ propertyNames: { pattern: "^[A-Za-z0-9_.:-]{1,256}$" },
197
+ type: "object"
198
+ },
199
+ completedAt: {
200
+ description: "RFC 3339 / ISO 8601 instant when execution completed.",
201
+ format: "date-time",
202
+ type: "string"
203
+ },
204
+ correlationId: {
205
+ description: "Optional cross-cutting identifier for distributed tracing. MUST be trimmed and non-empty when present.",
206
+ minLength: 1,
207
+ type: "string"
208
+ },
209
+ durationMs: {
210
+ description: "Wall-clock duration in milliseconds between startedAt and completedAt.",
211
+ minimum: 0,
212
+ type: "number"
213
+ },
214
+ error: {
215
+ $ref: "#/$defs/ExecutionError",
216
+ description: "Structured error when status is error."
217
+ },
218
+ id: {
219
+ description: "Stable unique identifier for this execution record.",
220
+ minLength: 1,
221
+ type: "string"
222
+ },
223
+ inputs: {
224
+ additionalProperties: true,
225
+ description: "Captured call inputs. Values MUST be JSON-serializable (see semantics/serialization_rules.md).",
226
+ type: "object"
227
+ },
228
+ intent: {
229
+ 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.",
230
+ minLength: 1,
231
+ type: "string"
232
+ },
233
+ output: {
234
+ $ref: "#/$defs/JsonValue",
235
+ description: "Captured return value when status is ok, or optional captured value when captureError allows output on failure."
236
+ },
237
+ startedAt: {
238
+ description: "RFC 3339 / ISO 8601 instant when execution started.",
239
+ format: "date-time",
240
+ type: "string"
241
+ },
242
+ status: {
243
+ description: "Terminal execution status.",
244
+ enum: ["ok", "error"],
245
+ type: "string"
246
+ }
247
+ },
248
+ required: [
249
+ "id",
250
+ "intent",
251
+ "action",
252
+ "status",
253
+ "inputs",
254
+ "startedAt",
255
+ "completedAt",
256
+ "durationMs"
257
+ ],
258
+ title: "IntentProof ExecutionEvent v1",
259
+ type: "object"
260
+ };
261
+
262
+ // src/generated/embed/intentproof-config.v1.ts
263
+ var intentproof_config_v1_default = {
264
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
265
+ $defs: {
266
+ WrapOptionsV1: {
267
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
268
+ $id: "https://intentproof.dev/schema/wrap_options.v1.schema.json",
269
+ $schema: "https://json-schema.org/draft/2020-12/schema",
270
+ additionalProperties: false,
271
+ properties: {
272
+ action: {
273
+ description: "Default operation identifier (often dotted like vendor.service.method); SDKs MAY derive from the callable when omitted.",
274
+ minLength: 1,
275
+ type: "string"
276
+ },
277
+ attributes: {
278
+ additionalProperties: { type: ["string", "number", "boolean", "null"] },
279
+ description: "Static attributes merged into each emitted ExecutionEvent.attributes.",
280
+ type: "object"
281
+ },
282
+ captureError: {
283
+ default: true,
284
+ description: "When true, failures MUST populate error; when false with captureOutput semantics, see semantics/wrap_behavior.md.",
285
+ type: "boolean"
286
+ },
287
+ captureInputs: {
288
+ default: true,
289
+ description: "When false, inputs MUST be serialized as an empty object {}.",
290
+ type: "boolean"
291
+ },
292
+ captureOutput: {
293
+ default: true,
294
+ description: "When false and status is ok, output MUST be null.",
295
+ type: "boolean"
296
+ },
297
+ captureStack: {
298
+ default: true,
299
+ description: "When false, error.stack MUST be null on emitted events.",
300
+ type: "boolean"
301
+ },
302
+ exporterTimeoutMs: {
303
+ description: "Maximum time an exporter hook may block the wrap boundary; 0 means SDK default.",
304
+ minimum: 0,
305
+ type: "number"
306
+ },
307
+ intent: {
308
+ description: "Default natural-language intent for wrapped executions when the call site does not override it.",
309
+ minLength: 1,
310
+ type: "string"
311
+ },
312
+ propagateCorrelation: {
313
+ default: true,
314
+ description: "When true, nested wraps inherit the active correlationId.",
315
+ type: "boolean"
316
+ }
317
+ },
318
+ title: "IntentProof WrapOptions v1",
319
+ type: "object"
320
+ }
321
+ },
322
+ $id: "https://intentproof.dev/schema/intentproof_config.v1.schema.json",
323
+ $schema: "https://json-schema.org/draft/2020-12/schema",
324
+ additionalProperties: false,
325
+ properties: {
326
+ correlation: {
327
+ additionalProperties: false,
328
+ properties: {
329
+ generateOnMissing: {
330
+ default: true,
331
+ description: "When true, SDK generates a UUID when no correlation is active.",
332
+ type: "boolean"
333
+ },
334
+ headerName: {
335
+ default: "x-intentproof-correlation-id",
336
+ description: "HTTP header used for inbound correlation extraction when applicable.",
337
+ type: "string"
338
+ }
339
+ },
340
+ type: "object"
341
+ },
342
+ defaultWrapOptions: { $ref: "#/$defs/WrapOptionsV1" },
343
+ exporters: {
344
+ description: "Ordered list of exporter identifiers or inline hooks (SDK-defined encoding).",
345
+ items: {
346
+ additionalProperties: true,
347
+ properties: {
348
+ endpoint: {
349
+ description: "Required for http exporters when used.",
350
+ format: "uri",
351
+ type: "string"
352
+ },
353
+ failOpen: {
354
+ default: true,
355
+ description: "When true, exporter failures MUST NOT change user-visible outcomes.",
356
+ type: "boolean"
357
+ },
358
+ headers: {
359
+ additionalProperties: { type: "string" },
360
+ description: "Optional HTTP headers for http exporters.",
361
+ type: "object"
362
+ },
363
+ type: {
364
+ description: "Exporter kind; custom MUST include implementation-specific fields.",
365
+ enum: ["console", "http", "otel", "custom"],
366
+ type: "string"
367
+ }
368
+ },
369
+ required: ["type"],
370
+ type: "object"
371
+ },
372
+ type: "array"
373
+ },
374
+ serialization: {
375
+ additionalProperties: false,
376
+ properties: {
377
+ maxDepth: {
378
+ default: 32,
379
+ description: "Maximum object graph depth for input/output capture.",
380
+ minimum: 1,
381
+ type: "integer"
382
+ },
383
+ maxStringLength: {
384
+ default: 65536,
385
+ description: "Maximum serialized string length for any single field.",
386
+ minimum: 1,
387
+ type: "integer"
388
+ },
389
+ redactKeys: {
390
+ description: "Case-insensitive key names to replace with [REDACTED] in captured objects.",
391
+ items: { type: "string" },
392
+ type: "array"
393
+ }
394
+ },
395
+ type: "object"
396
+ },
397
+ version: {
398
+ const: 1,
399
+ description: "Config document version; MUST be 1 for this schema.",
400
+ type: "integer"
401
+ }
402
+ },
403
+ title: "IntentProof Runtime Config v1",
404
+ type: "object"
405
+ };
406
+
407
+ // src/generated/embed/wrap-options.v1.ts
408
+ var wrap_options_v1_default = {
409
+ $comment: "Normative IntentProof source tree: https://github.com/IntentProof/intentproof-spec/tree/main/schema \u2014 $id is a logical URI; see README.",
410
+ $id: "https://intentproof.dev/schema/wrap_options.v1.schema.json",
411
+ $schema: "https://json-schema.org/draft/2020-12/schema",
412
+ additionalProperties: false,
413
+ properties: {
414
+ action: {
415
+ description: "Default operation identifier (often dotted like vendor.service.method); SDKs MAY derive from the callable when omitted.",
416
+ minLength: 1,
417
+ type: "string"
418
+ },
419
+ attributes: {
420
+ additionalProperties: { type: ["string", "number", "boolean", "null"] },
421
+ description: "Static attributes merged into each emitted ExecutionEvent.attributes.",
422
+ type: "object"
423
+ },
424
+ captureError: {
425
+ default: true,
426
+ description: "When true, failures MUST populate error; when false with captureOutput semantics, see semantics/wrap_behavior.md.",
427
+ type: "boolean"
428
+ },
429
+ captureInputs: {
430
+ default: true,
431
+ description: "When false, inputs MUST be serialized as an empty object {}.",
432
+ type: "boolean"
433
+ },
434
+ captureOutput: {
435
+ default: true,
436
+ description: "When false and status is ok, output MUST be null.",
437
+ type: "boolean"
438
+ },
439
+ captureStack: {
440
+ default: true,
441
+ description: "When false, error.stack MUST be null on emitted events.",
442
+ type: "boolean"
443
+ },
444
+ exporterTimeoutMs: {
445
+ description: "Maximum time an exporter hook may block the wrap boundary; 0 means SDK default.",
446
+ minimum: 0,
447
+ type: "number"
448
+ },
449
+ intent: {
450
+ description: "Default natural-language intent for wrapped executions when the call site does not override it.",
451
+ minLength: 1,
452
+ type: "string"
453
+ },
454
+ propagateCorrelation: {
455
+ default: true,
456
+ description: "When true, nested wraps inherit the active correlationId.",
457
+ type: "boolean"
458
+ }
459
+ },
460
+ title: "IntentProof WrapOptions v1",
461
+ type: "object"
462
+ };
463
+
464
+ // src/validators.ts
465
+ var ajv = new Ajv2020({
466
+ allErrors: true,
467
+ strict: false
468
+ });
469
+ var addFormats = AjvFormats.default;
470
+ addFormats(ajv);
471
+ var validateExecutionEvent = ajv.compile(
472
+ execution_event_v1_default
473
+ );
474
+ var validateWrapOptions = ajv.compile(
475
+ wrap_options_v1_default
476
+ );
477
+ var validateIntentProofConfig = ajv.compile(
478
+ intentproof_config_v1_default
479
+ );
480
+ function errorsText(v) {
481
+ return ajv.errorsText(v.errors, { separator: "; " });
482
+ }
483
+ function assertValidExecutionEventWire(data) {
484
+ if (!validateExecutionEvent(data)) {
485
+ throw new TypeError(
486
+ `ExecutionEvent wire JSON failed schema validation: ${errorsText(validateExecutionEvent)}`
487
+ );
488
+ }
489
+ }
490
+
131
491
  // src/client.ts
132
492
  var correlationStore = new AsyncLocalStorage();
493
+ function normalizeInputsForExecutionEvent(inputs) {
494
+ if (inputs !== null && typeof inputs === "object" && !Array.isArray(inputs)) {
495
+ return inputs;
496
+ }
497
+ return { args: inputs };
498
+ }
133
499
  function assertCorrelationId(id) {
134
500
  if (typeof id !== "string") {
135
501
  throw new TypeError(
@@ -354,9 +720,12 @@ var IntentProofClient = class {
354
720
  correlationId,
355
721
  intent: options.intent,
356
722
  action: options.action,
357
- inputs,
723
+ inputs: normalizeInputsForExecutionEvent(inputs),
358
724
  startedAt: startedAt.toISOString(),
359
- attributes: mergeAttrs(self.defaultAttributes, options.attributes)
725
+ attributes: mergeAttrs(
726
+ self.defaultAttributes,
727
+ options.attributes
728
+ )
360
729
  };
361
730
  try {
362
731
  const out = fn.apply(this, args);
@@ -464,6 +833,7 @@ var IntentProofClient = class {
464
833
  this.dispatch(event);
465
834
  }
466
835
  dispatch(event) {
836
+ assertValidExecutionEventWire(JSON.parse(JSON.stringify(event)));
467
837
  for (const ex of this.exporters) {
468
838
  try {
469
839
  const r = ex.export(event);
@@ -664,7 +1034,7 @@ var BoundedQueueExporter = class {
664
1034
  if (this.queue.length >= cap) {
665
1035
  if (this.strategy === "drop-oldest") {
666
1036
  const dropped = this.queue.shift();
667
- if (dropped) this.onDrop?.(dropped, "queue-overflow-drop-oldest");
1037
+ this.onDrop?.(dropped, "queue-overflow-drop-oldest");
668
1038
  this.queue.push(event);
669
1039
  } else {
670
1040
  this.onDrop?.(event, "queue-overflow-drop-newest");
@@ -721,7 +1091,7 @@ var BoundedQueueExporter = class {
721
1091
  };
722
1092
 
723
1093
  // src/index.ts
724
- var VERSION = "0.1.1";
1094
+ var VERSION = "0.1.3";
725
1095
  var client = getIntentProofClient();
726
1096
  function createIntentProofClient(config) {
727
1097
  return new IntentProofClient(config);
@@ -733,12 +1103,16 @@ export {
733
1103
  MemoryExporter,
734
1104
  VERSION,
735
1105
  assertCorrelationId,
1106
+ assertValidExecutionEventWire,
736
1107
  assertWrapOptionsShape,
737
1108
  client,
738
1109
  createIntentProofClient,
739
1110
  getCorrelationId,
740
1111
  getIntentProofClient,
741
1112
  runWithCorrelationId,
742
- snapshot
1113
+ snapshot,
1114
+ validateExecutionEvent,
1115
+ validateIntentProofConfig,
1116
+ validateWrapOptions
743
1117
  };
744
1118
  //# sourceMappingURL=index.js.map