@intentproof/sdk 0.1.2 → 0.1.4
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 +26 -10
- package/dist/index.cjs +397 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +305 -24
- package/dist/index.d.ts +305 -24
- package/dist/index.js +382 -5
- package/dist/index.js.map +1 -1
- package/package.json +13 -3
package/dist/index.js
CHANGED
|
@@ -126,8 +126,376 @@ function snapshot(value, options = {}) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
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
|
+
|
|
129
491
|
// src/client.ts
|
|
130
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
|
+
}
|
|
131
499
|
function assertCorrelationId(id) {
|
|
132
500
|
if (typeof id !== "string") {
|
|
133
501
|
throw new TypeError(
|
|
@@ -153,7 +521,8 @@ function runWithCorrelationId(correlationId, fn) {
|
|
|
153
521
|
return correlationStore.run(correlationId, fn);
|
|
154
522
|
}
|
|
155
523
|
function defaultOnExporterError(error, _event) {
|
|
156
|
-
|
|
524
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
525
|
+
console.error("[intentproof] exporter error", message);
|
|
157
526
|
}
|
|
158
527
|
function toErrorSnapshot(e, includeStack) {
|
|
159
528
|
if (e instanceof Error) {
|
|
@@ -352,9 +721,12 @@ var IntentProofClient = class {
|
|
|
352
721
|
correlationId,
|
|
353
722
|
intent: options.intent,
|
|
354
723
|
action: options.action,
|
|
355
|
-
inputs,
|
|
724
|
+
inputs: normalizeInputsForExecutionEvent(inputs),
|
|
356
725
|
startedAt: startedAt.toISOString(),
|
|
357
|
-
attributes: mergeAttrs(
|
|
726
|
+
attributes: mergeAttrs(
|
|
727
|
+
self.defaultAttributes,
|
|
728
|
+
options.attributes
|
|
729
|
+
)
|
|
358
730
|
};
|
|
359
731
|
try {
|
|
360
732
|
const out = fn.apply(this, args);
|
|
@@ -462,6 +834,7 @@ var IntentProofClient = class {
|
|
|
462
834
|
this.dispatch(event);
|
|
463
835
|
}
|
|
464
836
|
dispatch(event) {
|
|
837
|
+
assertValidExecutionEventWire(JSON.parse(JSON.stringify(event)));
|
|
465
838
|
for (const ex of this.exporters) {
|
|
466
839
|
try {
|
|
467
840
|
const r = ex.export(event);
|
|
@@ -719,7 +1092,7 @@ var BoundedQueueExporter = class {
|
|
|
719
1092
|
};
|
|
720
1093
|
|
|
721
1094
|
// src/index.ts
|
|
722
|
-
var VERSION = "0.1.
|
|
1095
|
+
var VERSION = "0.1.4";
|
|
723
1096
|
var client = getIntentProofClient();
|
|
724
1097
|
function createIntentProofClient(config) {
|
|
725
1098
|
return new IntentProofClient(config);
|
|
@@ -731,12 +1104,16 @@ export {
|
|
|
731
1104
|
MemoryExporter,
|
|
732
1105
|
VERSION,
|
|
733
1106
|
assertCorrelationId,
|
|
1107
|
+
assertValidExecutionEventWire,
|
|
734
1108
|
assertWrapOptionsShape,
|
|
735
1109
|
client,
|
|
736
1110
|
createIntentProofClient,
|
|
737
1111
|
getCorrelationId,
|
|
738
1112
|
getIntentProofClient,
|
|
739
1113
|
runWithCorrelationId,
|
|
740
|
-
snapshot
|
|
1114
|
+
snapshot,
|
|
1115
|
+
validateExecutionEvent,
|
|
1116
|
+
validateIntentProofConfig,
|
|
1117
|
+
validateWrapOptions
|
|
741
1118
|
};
|
|
742
1119
|
//# sourceMappingURL=index.js.map
|