@arnilo/prism 0.0.15 → 0.0.17

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.
Files changed (119) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/agent-definitions.js +2 -3
  3. package/dist/agent-loops.js +12 -7
  4. package/dist/agent-run-lifecycle.d.ts +1 -2
  5. package/dist/agent-run-lifecycle.js +1 -1
  6. package/dist/agent-run-state.js +29 -4
  7. package/dist/agents.d.ts +1 -1
  8. package/dist/agents.js +163 -61
  9. package/dist/cache-helpers.js +18 -9
  10. package/dist/checkpoints.d.ts +4 -0
  11. package/dist/checkpoints.js +17 -9
  12. package/dist/cli-init.js +3 -7
  13. package/dist/cli-runner.d.ts +2 -6
  14. package/dist/cli-runner.js +71 -33
  15. package/dist/compaction.js +5 -4
  16. package/dist/config.js +7 -4
  17. package/dist/content.js +26 -24
  18. package/dist/context-budget.js +18 -11
  19. package/dist/contracts.d.ts +16 -3
  20. package/dist/contracts.js +4 -1
  21. package/dist/contribution-parsing.js +6 -2
  22. package/dist/contributions.d.ts +2 -0
  23. package/dist/contributions.js +3 -0
  24. package/dist/conversations.js +2 -1
  25. package/dist/credentials.d.ts +8 -2
  26. package/dist/credentials.js +9 -3
  27. package/dist/event-multiplexer.js +18 -4
  28. package/dist/extensions.d.ts +7 -1
  29. package/dist/extensions.js +64 -6
  30. package/dist/feedback.js +12 -10
  31. package/dist/guardrails.d.ts +1 -1
  32. package/dist/guardrails.js +26 -17
  33. package/dist/identity.js +10 -2
  34. package/dist/index.d.ts +82 -83
  35. package/dist/index.js +42 -42
  36. package/dist/input.d.ts +2 -2
  37. package/dist/input.js +50 -27
  38. package/dist/instruction-injection.d.ts +1 -1
  39. package/dist/middleware.js +9 -1
  40. package/dist/models.d.ts +2 -0
  41. package/dist/models.js +3 -0
  42. package/dist/node/agent-definitions.js +16 -8
  43. package/dist/node/contribution-discovery.d.ts +1 -2
  44. package/dist/node/contribution-discovery.js +3 -3
  45. package/dist/node/session-store-jsonl.js +10 -7
  46. package/dist/node/settings.d.ts +1 -1
  47. package/dist/node/settings.js +1 -1
  48. package/dist/node/system-project-prompts.js +2 -4
  49. package/dist/node/trust.js +1 -1
  50. package/dist/persistence-lifecycle.js +1 -3
  51. package/dist/provider-events.js +3 -1
  52. package/dist/provider-request-policy.js +3 -4
  53. package/dist/providers/media.d.ts +1 -1
  54. package/dist/providers/openai-compatible.d.ts +42 -1
  55. package/dist/providers/openai-compatible.js +110 -49
  56. package/dist/providers/openai-primitives.js +7 -7
  57. package/dist/providers/transport.d.ts +6 -0
  58. package/dist/providers/transport.js +21 -0
  59. package/dist/providers.d.ts +2 -0
  60. package/dist/providers.js +3 -0
  61. package/dist/redaction.d.ts +1 -0
  62. package/dist/redaction.js +26 -9
  63. package/dist/resources.d.ts +2 -2
  64. package/dist/resources.js +2 -2
  65. package/dist/retry.d.ts +5 -0
  66. package/dist/retry.js +8 -1
  67. package/dist/rpc.js +42 -9
  68. package/dist/run-ledger.d.ts +6 -0
  69. package/dist/run-ledger.js +16 -13
  70. package/dist/run-limits.js +49 -10
  71. package/dist/secure-agent.js +1 -1
  72. package/dist/security.js +7 -2
  73. package/dist/session-stores.d.ts +1 -1
  74. package/dist/session-stores.js +28 -24
  75. package/dist/structured-output.js +2 -2
  76. package/dist/system-prompts.js +7 -2
  77. package/dist/testing/compaction-conformance.js +5 -1
  78. package/dist/testing/extension-conformance.js +15 -3
  79. package/dist/testing/feedback.d.ts +1 -3
  80. package/dist/testing/feedback.js +1 -1
  81. package/dist/testing/persistence-schema.js +206 -37
  82. package/dist/testing/provider-conformance.js +3 -3
  83. package/dist/testing/run-ledger-conformance.js +1 -1
  84. package/dist/testing/session-store-conformance.js +1 -1
  85. package/dist/testing/tool-conformance.js +30 -5
  86. package/dist/thinking.js +4 -1
  87. package/dist/tools.d.ts +2 -2
  88. package/dist/tools.js +24 -5
  89. package/docs/0.1.0-readiness.md +139 -0
  90. package/docs/agent-events.md +2 -1
  91. package/docs/agent-session-runtime.md +2 -2
  92. package/docs/cli-rpc.md +1 -5
  93. package/docs/coding-agent-tools.md +2 -0
  94. package/docs/compaction-and-retry.md +3 -1
  95. package/docs/contribution-registries.md +1 -0
  96. package/docs/credentials-and-redaction.md +1 -1
  97. package/docs/extensions.md +1 -1
  98. package/docs/guardrails.md +13 -2
  99. package/docs/index.md +4 -2
  100. package/docs/input-and-prompt-assembly.md +3 -3
  101. package/docs/middleware-hooks.md +2 -2
  102. package/docs/migration.md +40 -0
  103. package/docs/performance.md +33 -0
  104. package/docs/providers/openai-compatible.md +28 -1
  105. package/docs/public-contracts.md +2 -2
  106. package/docs/release-and-install.md +127 -17
  107. package/docs/session-stores.md +1 -1
  108. package/package.json +14 -6
  109. package/docs/review-coverage-2026-07-14.md +0 -260
  110. package/docs/review-coverage-2026-07-15.md +0 -193
  111. package/docs/review-coverage-2026-07-17-provider-validation.md +0 -192
  112. package/docs/review-coverage-2026-07-19-phase-3.md +0 -174
  113. package/docs/review-coverage-2026-07-20-phase-4.md +0 -175
  114. package/docs/review-coverage-2026-07-21-phase-5.md +0 -172
  115. package/docs/review-coverage-2026-07-22-phase-6.md +0 -209
  116. package/docs/review-coverage-2026-07-22-phase-7.md +0 -173
  117. package/docs/review-coverage-2026-07-23-phase-8.md +0 -245
  118. package/docs/review-coverage-2026-07-25-phase-9.md +0 -256
  119. package/docs/review-coverage-2026-07-26-phase-10.md +0 -132
@@ -23,7 +23,12 @@ export async function assertExtensionConforms(extension, options = {}) {
23
23
  // provider/tool/skill capabilities until host code resolves and calls them).
24
24
  if (options.expectThrow) {
25
25
  // A second extension that throws must rethrow under errorPolicy: "throw".
26
- const failing = { name: "conformance-failing", setup: () => { throw new Error("conformance setup failed"); } };
26
+ const failing = {
27
+ name: "conformance-failing",
28
+ setup: () => {
29
+ throw new Error("conformance setup failed");
30
+ },
31
+ };
27
32
  let threw = false;
28
33
  try {
29
34
  await kernel.load([failing]);
@@ -37,9 +42,16 @@ export async function assertExtensionConforms(extension, options = {}) {
37
42
  }
38
43
  if (options.secrets && options.secrets.length > 0) {
39
44
  const secret = options.secrets[0];
40
- const failing = { name: "conformance-failing", setup: () => { throw new Error(`boom ${secret}`); } };
45
+ const failing = {
46
+ name: "conformance-failing",
47
+ setup: () => {
48
+ throw new Error(`boom ${secret}`);
49
+ },
50
+ };
41
51
  const errors = [];
42
- kernel.events.on("extension_error", (event) => { errors.push(event.error ?? {}); });
52
+ kernel.events.on("extension_error", (event) => {
53
+ errors.push(event.error ?? {});
54
+ });
43
55
  await kernel.load([failing]);
44
56
  if (errors.length === 0)
45
57
  throw new Error("Failing extension setup did not emit an extension_error event");
@@ -1,6 +1,4 @@
1
1
  import type { RunFeedbackStore } from "../contracts.js";
2
- export interface RunFeedbackConformanceFactory {
3
- (): RunFeedbackStore | Promise<RunFeedbackStore>;
4
- }
2
+ export type RunFeedbackConformanceFactory = () => RunFeedbackStore | Promise<RunFeedbackStore>;
5
3
  /** Shared minimum behavior for memory and production feedback stores. */
6
4
  export declare function runFeedbackConformance(factory: RunFeedbackConformanceFactory): Promise<void>;
@@ -31,7 +31,7 @@ export async function runFeedbackConformance(factory) {
31
31
  if (await store.delete({ id: "feedback-1", tenantId: "feedback-tenant", userId: "other" })) {
32
32
  throw new Error("cross-owner feedback deletion succeeded");
33
33
  }
34
- if (!await store.delete({ id: "feedback-1", ...owner }))
34
+ if (!(await store.delete({ id: "feedback-1", ...owner })))
35
35
  throw new Error("owned feedback deletion failed");
36
36
  }
37
37
  //# sourceMappingURL=feedback.js.map
@@ -301,34 +301,160 @@ export function createPersistenceSchemaModel() {
301
301
  },
302
302
  ],
303
303
  indexes: [
304
- { name: "prism_sessions_tenant_created_idx", table: "prism_sessions", columns: ["tenant_id", "account_id", "user_id", "created_at"], purpose: "tenant-scoped session listing" },
304
+ {
305
+ name: "prism_sessions_tenant_created_idx",
306
+ table: "prism_sessions",
307
+ columns: ["tenant_id", "account_id", "user_id", "created_at"],
308
+ purpose: "tenant-scoped session listing",
309
+ },
305
310
  { name: "prism_sessions_expires_idx", table: "prism_sessions", columns: ["expires_at"], purpose: "retention expiry scans" },
306
311
  { name: "prism_branches_session_name_idx", table: "prism_branches", columns: ["session_id", "name"], purpose: "named branch lookup" },
307
312
  { name: "prism_branches_leaf_idx", table: "prism_branches", columns: ["leaf_entry_id"], purpose: "leaf-to-branch resolution" },
308
- { name: "prism_session_entries_session_parent_idx", table: "prism_session_entries", columns: ["session_id", "parent_id"], purpose: "parent existence checks and child lookups" },
309
- { name: "prism_session_entries_session_kind_ts_idx", table: "prism_session_entries", columns: ["session_id", "kind", "timestamp"], purpose: "kind-filtered entry listing" },
310
- { name: "prism_session_entries_session_run_ts_idx", table: "prism_session_entries", columns: ["session_id", "run_id", "timestamp"], purpose: "run-scoped entry listing" },
311
- { name: "prism_session_entries_session_ts_id_idx", table: "prism_session_entries", columns: ["session_id", "timestamp", "id"], purpose: "cursor pagination without full scans" },
312
- { name: "prism_session_entries_session_id_idx", table: "prism_session_entries", columns: ["session_id", "id"], purpose: "append parent validation and recursive branch reads" },
313
- { name: "prism_session_append_idempotency_unique", table: "prism_session_append_idempotency", columns: ["session_id", "expected_parent_id", "idempotency_key"], purpose: "append retry deduplication (primary key enforces uniqueness)" },
314
- { name: "prism_runs_session_started_idx", table: "prism_runs", columns: ["session_id", "started_at", "id"], purpose: "run history pagination" },
315
- { name: "prism_runs_branch_started_idx", table: "prism_runs", columns: ["branch_id", "started_at", "id"], purpose: "branch-scoped runs" },
316
- { name: "prism_runs_tenant_idempotency_unique", table: "prism_runs", columns: ["tenant_id", "idempotency_key"], unique: true, purpose: "run-level idempotency deduplication per tenant" },
317
- { name: "prism_agent_events_run_sequence_idx", table: "prism_agent_events", columns: ["run_id", "sequence"], purpose: "stable per-run event timeline pagination" },
318
- { name: "prism_agent_events_session_ts_id_idx", table: "prism_agent_events", columns: ["session_id", "timestamp", "id"], purpose: "event stream pagination" },
319
- { name: "prism_tool_calls_session_name_started_idx", table: "prism_tool_calls", columns: ["session_id", "name", "started_at"], purpose: "tool usage by name" },
320
- { name: "prism_tool_calls_run_started_idx", table: "prism_tool_calls", columns: ["run_id", "started_at"], purpose: "run tool-call listing" },
321
- { name: "prism_usage_run_recorded_idx", table: "prism_usage", columns: ["run_id", "recorded_at", "id"], purpose: "run usage pagination" },
322
- { name: "prism_usage_session_recorded_idx", table: "prism_usage", columns: ["session_id", "recorded_at"], purpose: "usage aggregation" },
323
- { name: "prism_usage_session_scope_recorded_idx", table: "prism_usage", columns: ["session_id", "scope", "recorded_at"], purpose: "scope-safe usage aggregation" },
324
- { name: "prism_run_feedback_owner_created_idx", table: "prism_run_feedback", columns: ["tenant_id", "account_id", "user_id", "created_at", "id"], purpose: "ownership-scoped feedback pagination" },
325
- { name: "prism_run_feedback_run_created_idx", table: "prism_run_feedback", columns: ["run_id", "created_at", "id"], purpose: "run feedback lookup" },
326
- { name: "prism_run_feedback_trace_created_idx", table: "prism_run_feedback", columns: ["trace_id", "created_at", "id"], purpose: "trace feedback lookup" },
327
- { name: "prism_agent_definitions_name_version_idx", table: "prism_agent_definitions", columns: ["name", "version"], purpose: "definition lookup" },
328
- { name: "prism_legal_holds_owner_resource_idx", table: "prism_legal_holds", columns: ["tenant_id", "account_id", "user_id", "resource_kind", "resource_id"], purpose: "hold lookup by owned resource" },
329
- { name: "prism_legal_holds_created_id_idx", table: "prism_legal_holds", columns: ["created_at", "id"], purpose: "hold export pagination" },
330
- { name: "prism_tenant_quotas_owner_kind_idx", table: "prism_tenant_quotas", columns: ["tenant_id", "account_id", "user_id", "resource_kind"], purpose: "tenant quota lookup" },
331
- { name: "prism_migrations_name_version_idx", table: "prism_migrations", columns: ["name", "version"], purpose: "applied-migration lookup (table constraint enforces uniqueness)" },
313
+ {
314
+ name: "prism_session_entries_session_parent_idx",
315
+ table: "prism_session_entries",
316
+ columns: ["session_id", "parent_id"],
317
+ purpose: "parent existence checks and child lookups",
318
+ },
319
+ {
320
+ name: "prism_session_entries_session_kind_ts_idx",
321
+ table: "prism_session_entries",
322
+ columns: ["session_id", "kind", "timestamp"],
323
+ purpose: "kind-filtered entry listing",
324
+ },
325
+ {
326
+ name: "prism_session_entries_session_run_ts_idx",
327
+ table: "prism_session_entries",
328
+ columns: ["session_id", "run_id", "timestamp"],
329
+ purpose: "run-scoped entry listing",
330
+ },
331
+ {
332
+ name: "prism_session_entries_session_ts_id_idx",
333
+ table: "prism_session_entries",
334
+ columns: ["session_id", "timestamp", "id"],
335
+ purpose: "cursor pagination without full scans",
336
+ },
337
+ {
338
+ name: "prism_session_entries_session_id_idx",
339
+ table: "prism_session_entries",
340
+ columns: ["session_id", "id"],
341
+ purpose: "append parent validation and recursive branch reads",
342
+ },
343
+ {
344
+ name: "prism_session_append_idempotency_unique",
345
+ table: "prism_session_append_idempotency",
346
+ columns: ["session_id", "expected_parent_id", "idempotency_key"],
347
+ purpose: "append retry deduplication (primary key enforces uniqueness)",
348
+ },
349
+ {
350
+ name: "prism_runs_session_started_idx",
351
+ table: "prism_runs",
352
+ columns: ["session_id", "started_at", "id"],
353
+ purpose: "run history pagination",
354
+ },
355
+ {
356
+ name: "prism_runs_branch_started_idx",
357
+ table: "prism_runs",
358
+ columns: ["branch_id", "started_at", "id"],
359
+ purpose: "branch-scoped runs",
360
+ },
361
+ {
362
+ name: "prism_runs_tenant_idempotency_unique",
363
+ table: "prism_runs",
364
+ columns: ["tenant_id", "idempotency_key"],
365
+ unique: true,
366
+ purpose: "run-level idempotency deduplication per tenant",
367
+ },
368
+ {
369
+ name: "prism_agent_events_run_sequence_idx",
370
+ table: "prism_agent_events",
371
+ columns: ["run_id", "sequence"],
372
+ purpose: "stable per-run event timeline pagination",
373
+ },
374
+ {
375
+ name: "prism_agent_events_session_ts_id_idx",
376
+ table: "prism_agent_events",
377
+ columns: ["session_id", "timestamp", "id"],
378
+ purpose: "event stream pagination",
379
+ },
380
+ {
381
+ name: "prism_tool_calls_session_name_started_idx",
382
+ table: "prism_tool_calls",
383
+ columns: ["session_id", "name", "started_at"],
384
+ purpose: "tool usage by name",
385
+ },
386
+ {
387
+ name: "prism_tool_calls_run_started_idx",
388
+ table: "prism_tool_calls",
389
+ columns: ["run_id", "started_at"],
390
+ purpose: "run tool-call listing",
391
+ },
392
+ {
393
+ name: "prism_usage_run_recorded_idx",
394
+ table: "prism_usage",
395
+ columns: ["run_id", "recorded_at", "id"],
396
+ purpose: "run usage pagination",
397
+ },
398
+ {
399
+ name: "prism_usage_session_recorded_idx",
400
+ table: "prism_usage",
401
+ columns: ["session_id", "recorded_at"],
402
+ purpose: "usage aggregation",
403
+ },
404
+ {
405
+ name: "prism_usage_session_scope_recorded_idx",
406
+ table: "prism_usage",
407
+ columns: ["session_id", "scope", "recorded_at"],
408
+ purpose: "scope-safe usage aggregation",
409
+ },
410
+ {
411
+ name: "prism_run_feedback_owner_created_idx",
412
+ table: "prism_run_feedback",
413
+ columns: ["tenant_id", "account_id", "user_id", "created_at", "id"],
414
+ purpose: "ownership-scoped feedback pagination",
415
+ },
416
+ {
417
+ name: "prism_run_feedback_run_created_idx",
418
+ table: "prism_run_feedback",
419
+ columns: ["run_id", "created_at", "id"],
420
+ purpose: "run feedback lookup",
421
+ },
422
+ {
423
+ name: "prism_run_feedback_trace_created_idx",
424
+ table: "prism_run_feedback",
425
+ columns: ["trace_id", "created_at", "id"],
426
+ purpose: "trace feedback lookup",
427
+ },
428
+ {
429
+ name: "prism_agent_definitions_name_version_idx",
430
+ table: "prism_agent_definitions",
431
+ columns: ["name", "version"],
432
+ purpose: "definition lookup",
433
+ },
434
+ {
435
+ name: "prism_legal_holds_owner_resource_idx",
436
+ table: "prism_legal_holds",
437
+ columns: ["tenant_id", "account_id", "user_id", "resource_kind", "resource_id"],
438
+ purpose: "hold lookup by owned resource",
439
+ },
440
+ {
441
+ name: "prism_legal_holds_created_id_idx",
442
+ table: "prism_legal_holds",
443
+ columns: ["created_at", "id"],
444
+ purpose: "hold export pagination",
445
+ },
446
+ {
447
+ name: "prism_tenant_quotas_owner_kind_idx",
448
+ table: "prism_tenant_quotas",
449
+ columns: ["tenant_id", "account_id", "user_id", "resource_kind"],
450
+ purpose: "tenant quota lookup",
451
+ },
452
+ {
453
+ name: "prism_migrations_name_version_idx",
454
+ table: "prism_migrations",
455
+ columns: ["name", "version"],
456
+ purpose: "applied-migration lookup (table constraint enforces uniqueness)",
457
+ },
332
458
  ],
333
459
  };
334
460
  }
@@ -346,13 +472,25 @@ function migrationStep(version, name, description) {
346
472
  : version === 2
347
473
  ? { table: "prism_usage", columns: ["scope", "turn", "attempt"], indexes: ["prism_usage_session_scope_recorded_idx"] }
348
474
  : version === 3
349
- ? { tables: ["prism_run_feedback"], indexes: model.indexes.filter((index) => index.name.startsWith("prism_run_feedback_")).map((index) => index.name) }
475
+ ? {
476
+ tables: ["prism_run_feedback"],
477
+ indexes: model.indexes.filter((index) => index.name.startsWith("prism_run_feedback_")).map((index) => index.name),
478
+ }
350
479
  : version === 4
351
- // Adapter-local FTS objects (SQLite FTS5 / Postgres tsvector) map to this canonical name.
352
- ? { search: ["prism_session_search"], indexes: ["prism_sessions_updated_id_idx"] }
480
+ ? // Adapter-local FTS objects (SQLite FTS5 / Postgres tsvector) map to this canonical name.
481
+ { search: ["prism_session_search"], indexes: ["prism_sessions_updated_id_idx"] }
353
482
  : version === 5
354
- ? { tables: ["prism_legal_holds", "prism_tenant_quotas"], indexes: ["prism_legal_holds_owner_resource_idx", "prism_legal_holds_created_id_idx", "prism_tenant_quotas_owner_kind_idx"] }
355
- : (() => { throw new Error(`Unknown migration version ${version}`); })();
483
+ ? {
484
+ tables: ["prism_legal_holds", "prism_tenant_quotas"],
485
+ indexes: [
486
+ "prism_legal_holds_owner_resource_idx",
487
+ "prism_legal_holds_created_id_idx",
488
+ "prism_tenant_quotas_owner_kind_idx",
489
+ ],
490
+ }
491
+ : (() => {
492
+ throw new Error(`Unknown migration version ${version}`);
493
+ })();
356
494
  return {
357
495
  version,
358
496
  name,
@@ -379,13 +517,33 @@ export function createPersistenceMigrationContract() {
379
517
  /** Indexed cursor columns adapters must support for paginated reads. */
380
518
  export function getPersistencePaginationCursors() {
381
519
  return [
382
- { table: "prism_session_entries", columns: ["session_id", "timestamp", "id"], supportsOrder: ["asc", "desc"], purpose: "entry listing and branch paging" },
520
+ {
521
+ table: "prism_session_entries",
522
+ columns: ["session_id", "timestamp", "id"],
523
+ supportsOrder: ["asc", "desc"],
524
+ purpose: "entry listing and branch paging",
525
+ },
383
526
  { table: "prism_runs", columns: ["session_id", "started_at", "id"], supportsOrder: ["asc", "desc"], purpose: "run history" },
384
- { table: "prism_agent_events", columns: ["run_id", "sequence"], supportsOrder: ["asc", "desc"], purpose: "stable per-run event timeline" },
385
- { table: "prism_agent_events", columns: ["session_id", "timestamp", "id"], supportsOrder: ["asc", "desc"], purpose: "session event stream" },
527
+ {
528
+ table: "prism_agent_events",
529
+ columns: ["run_id", "sequence"],
530
+ supportsOrder: ["asc", "desc"],
531
+ purpose: "stable per-run event timeline",
532
+ },
533
+ {
534
+ table: "prism_agent_events",
535
+ columns: ["session_id", "timestamp", "id"],
536
+ supportsOrder: ["asc", "desc"],
537
+ purpose: "session event stream",
538
+ },
386
539
  { table: "prism_usage", columns: ["run_id", "recorded_at", "id"], supportsOrder: ["asc", "desc"], purpose: "run usage totals" },
387
540
  { table: "prism_tool_calls", columns: ["run_id", "started_at"], supportsOrder: ["asc", "desc"], purpose: "run tool-call listing" },
388
- { table: "prism_run_feedback", columns: ["tenant_id", "account_id", "user_id", "created_at", "id"], supportsOrder: ["asc", "desc"], purpose: "owned feedback listing" },
541
+ {
542
+ table: "prism_run_feedback",
543
+ columns: ["tenant_id", "account_id", "user_id", "created_at", "id"],
544
+ supportsOrder: ["asc", "desc"],
545
+ purpose: "owned feedback listing",
546
+ },
389
547
  ];
390
548
  }
391
549
  /** Build a tenant-scoped unique key column list for adapter DDL. */
@@ -418,7 +576,13 @@ export function assertPersistenceSchemaModel(model) {
418
576
  throw new Error("Runs table must include tenant-scoped tenant_id");
419
577
  }
420
578
  const indexTables = new Set(model.indexes.map((index) => index.table));
421
- for (const requiredIndex of ["prism_session_append_idempotency", "prism_session_entries", "prism_agent_events", "prism_runs", "prism_run_feedback"]) {
579
+ for (const requiredIndex of [
580
+ "prism_session_append_idempotency",
581
+ "prism_session_entries",
582
+ "prism_agent_events",
583
+ "prism_runs",
584
+ "prism_run_feedback",
585
+ ]) {
422
586
  if (!indexTables.has(requiredIndex)) {
423
587
  throw new Error(`Persistence schema missing indexes for ${requiredIndex}`);
424
588
  }
@@ -462,7 +626,10 @@ function schemaKey(columns) {
462
626
  return columns.join("\u0000");
463
627
  }
464
628
  function normalizedDefault(value) {
465
- return value?.trim().toLowerCase().replace(/::[a-z_ ]+$/, "");
629
+ return value
630
+ ?.trim()
631
+ .toLowerCase()
632
+ .replace(/::[a-z_ ]+$/, "");
466
633
  }
467
634
  function compatibleColumnType(dialect, actual, expected) {
468
635
  const type = actual.trim().toUpperCase();
@@ -527,7 +694,9 @@ export function assertPersistenceSchemaShape(shape, dialect, model = createPersi
527
694
  const actual = actualIndexes.get(expected.name);
528
695
  if (!actual)
529
696
  throw new Error(`Persistence schema missing required index ${expected.name}`);
530
- if (actual.table !== expected.table || schemaKey(actual.columns) !== schemaKey(expected.columns) || actual.unique !== (expected.unique === true)) {
697
+ if (actual.table !== expected.table ||
698
+ schemaKey(actual.columns) !== schemaKey(expected.columns) ||
699
+ actual.unique !== (expected.unique === true)) {
531
700
  throw new Error(`Persistence schema index ${expected.name} has incompatible definition`);
532
701
  }
533
702
  }
@@ -73,7 +73,7 @@ export function assertProviderOwnedHeadersWin(captured, options) {
73
73
  throw new Error(`Caller header overrode provider-owned "${name}": expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
74
74
  }
75
75
  for (const [name, callerValue] of Object.entries(options.caller)) {
76
- if (Object.prototype.hasOwnProperty.call(ownedLower, name.toLowerCase()))
76
+ if (Object.hasOwn(ownedLower, name.toLowerCase()))
77
77
  continue;
78
78
  const actual = captured.get(name);
79
79
  if (actual !== callerValue)
@@ -90,7 +90,7 @@ export function assertNoSecretLeak(events, secrets) {
90
90
  }
91
91
  }
92
92
  export function assertUsageAccounting(events, expected) {
93
- const usage = [...events].reverse().find((event) => event.type === "done" && event.usage || event.type === "usage");
93
+ const usage = [...events].reverse().find((event) => (event.type === "done" && event.usage) || event.type === "usage");
94
94
  const actual = usage?.type === "usage" ? usage.usage : usage?.usage;
95
95
  if (!actual)
96
96
  throw new Error("Provider stream did not include usage");
@@ -155,6 +155,6 @@ function jsonPrimitives(value) {
155
155
  return primitives;
156
156
  }
157
157
  function textFrom(events) {
158
- return events.map((event) => event.type === "content_delta" && event.content.type === "text" ? event.content.text : "").join("");
158
+ return events.map((event) => (event.type === "content_delta" && event.content.type === "text" ? event.content.text : "")).join("");
159
159
  }
160
160
  //# sourceMappingURL=provider-conformance.js.map
@@ -138,7 +138,7 @@ export async function assertRunLedgerConforms(fixture, options = {}) {
138
138
  await fixture.ledger.appendRun(otherRun);
139
139
  const runs = await fixture.readRuns();
140
140
  const stored = runs.find((row) => row.id === "run-tenant-b");
141
- if (!stored || stored.tenantId !== "tenant-b") {
141
+ if (stored?.tenantId !== "tenant-b") {
142
142
  throw new Error("RunLedger must persist tenant_id on records for tenant-scoped isolation");
143
143
  }
144
144
  const scoped = runs.filter((row) => row.tenantId === tenantId);
@@ -155,7 +155,7 @@ async function assertSessionStoreBranchIsolation(store, options) {
155
155
  throw new Error("SessionStore leaked entries across session ids");
156
156
  }
157
157
  }
158
- async function assertConcurrentParentAppendAllowed(store, sessionId, now, make) {
158
+ async function assertConcurrentParentAppendAllowed(store, sessionId, _now, make) {
159
159
  const forkRoot = make("fork-root");
160
160
  await store.append(forkRoot);
161
161
  const childA = make("fork-a", forkRoot.id);
@@ -26,15 +26,38 @@ export async function assertToolDispatchConforms(registry, options) {
26
26
  // 1. unknown tool → blocked "unknown_tool".
27
27
  await assertToolBlocked({ call: call("does-not-exist", {}), context: baseContext, ...shared, ...pickPolicy(options) }, "unknown_tool");
28
28
  // 2. denied tool (filter) → blocked "tool_denied".
29
- await assertToolBlocked({ call: call(options.tool.name, options.validArgs), context: baseContext, ...shared, ...pickPolicy(options), filter: { deny: [options.tool.name] } }, "tool_denied");
29
+ await assertToolBlocked({
30
+ call: call(options.tool.name, options.validArgs),
31
+ context: baseContext,
32
+ ...shared,
33
+ ...pickPolicy(options),
34
+ filter: { deny: [options.tool.name] },
35
+ }, "tool_denied");
30
36
  // 3. invalid (non-object) arguments → blocked "invalid_arguments".
31
37
  await assertToolBlocked({ call: call(options.tool.name, "not-an-object"), context: baseContext, ...shared, ...pickPolicy(options) }, "invalid_arguments");
32
38
  // 4. permission denial → blocked "permission_denied".
33
- await assertToolBlocked({ call: call(options.tool.name, options.validArgs), context: baseContext, ...shared, ...pickPolicy(options), permission: denyAllPermission }, "permission_denied");
39
+ await assertToolBlocked({
40
+ call: call(options.tool.name, options.validArgs),
41
+ context: baseContext,
42
+ ...shared,
43
+ ...pickPolicy(options),
44
+ permission: denyAllPermission,
45
+ }, "permission_denied");
34
46
  // 5. validator failure → blocked "validation_failed".
35
- await assertToolBlocked({ call: call(options.tool.name, options.validArgs), context: baseContext, ...shared, ...pickPolicy(options), validate: alwaysInvalidValidator }, "validation_failed");
47
+ await assertToolBlocked({
48
+ call: call(options.tool.name, options.validArgs),
49
+ context: baseContext,
50
+ ...shared,
51
+ ...pickPolicy(options),
52
+ validate: alwaysInvalidValidator,
53
+ }, "validation_failed");
36
54
  // 6. valid call → executes (tool_execution_started), no error, no blocked event.
37
- const probe = await dispatchAndCollect({ call: call(options.tool.name, options.validArgs), context: baseContext, ...shared, ...pickPolicy(options) });
55
+ const probe = await dispatchAndCollect({
56
+ call: call(options.tool.name, options.validArgs),
57
+ context: baseContext,
58
+ ...shared,
59
+ ...pickPolicy(options),
60
+ });
38
61
  if (probe.result.error)
39
62
  throw new Error(`Valid tool call was not executed: ${probe.result.error.message}`);
40
63
  if (!probe.events.some((event) => event.type === "tool_execution_started")) {
@@ -69,7 +92,9 @@ export async function dispatchAndCollect(probe) {
69
92
  permission: probe.permission,
70
93
  validate: probe.validate,
71
94
  secrets: probe.secrets,
72
- emit: (event) => { events.push(event); },
95
+ emit: (event) => {
96
+ events.push(event);
97
+ },
73
98
  });
74
99
  return { result, events };
75
100
  }
package/dist/thinking.js CHANGED
@@ -47,7 +47,10 @@ export function applyThinkingLevel(options, level, family = "reasoning_effort")
47
47
  if (!normalized || family === "noop")
48
48
  return options ?? {};
49
49
  const patch = thinkingCompatFor(family, normalized);
50
- if (family === "openai_reasoning" && options?.compat?.reasoning && typeof options.compat.reasoning === "object" && !Array.isArray(options.compat.reasoning)) {
50
+ if (family === "openai_reasoning" &&
51
+ options?.compat?.reasoning &&
52
+ typeof options.compat.reasoning === "object" &&
53
+ !Array.isArray(options.compat.reasoning)) {
51
54
  return mergeProviderRequestOptions(options, {
52
55
  compat: {
53
56
  reasoning: {
package/dist/tools.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import type { AgentEvent, ErrorInfo, Guardrails, JsonObject, OwnershipScope, RunLedger, ToolCallContent, ToolDefinition, ToolExecutionContext, ToolRegistry, ToolResult } from "./contracts.js";
2
- import type { RunLimitTracker } from "./run-limits.js";
3
2
  import type { MiddlewareRegistry } from "./middleware.js";
4
3
  import { type SecretRedactor } from "./redaction.js";
5
4
  import { type DuplicateRegistrationOptions } from "./registry-options.js";
5
+ import type { RunLimitTracker } from "./run-limits.js";
6
6
  import { type PermissionPolicy, type TrustPolicy } from "./security.js";
7
7
  export interface ToolFilter {
8
8
  readonly allow?: readonly string[];
9
9
  readonly deny?: readonly string[];
10
10
  }
11
11
  export type ToolFilterInput = ToolFilter | readonly ToolFilter[];
12
- export type ToolValidator = (tool: ToolDefinition, args: JsonObject, context: ToolExecutionContext) => void | string | ErrorInfo | Promise<void | string | ErrorInfo>;
12
+ export type ToolValidator = (tool: ToolDefinition, args: JsonObject, context: ToolExecutionContext) => undefined | string | ErrorInfo | Promise<undefined | string | ErrorInfo>;
13
13
  export interface ToolArgumentValidationError {
14
14
  readonly path?: string;
15
15
  readonly message: string;
package/dist/tools.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isJsonObject } from "./config.js";
2
- import { createId } from "./ids.js";
3
2
  import { GuardrailError, runGuardrails } from "./guardrails.js";
4
3
  import { assertIdentityActive, assertIdentityMatchesOwnership } from "./identity.js";
4
+ import { createId } from "./ids.js";
5
5
  import { errorToErrorInfo, redactRunLedgerRecord, redactSecrets } from "./redaction.js";
6
6
  import { assertCanRegister } from "./registry-options.js";
7
7
  import { assertPermission, assertTrusted } from "./security.js";
@@ -52,7 +52,9 @@ export function createToolRegistry(tools = [], options = {}) {
52
52
  export function filterTools(tools, filter) {
53
53
  const filters = Array.isArray(filter) ? filter : filter ? [filter] : [];
54
54
  const denied = new Set(filters.flatMap((item) => item.deny ?? []));
55
- const allows = filters.map((item) => item.allow?.length ? new Set(item.allow) : undefined).filter((item) => Boolean(item));
55
+ const allows = filters
56
+ .map((item) => (item.allow?.length ? new Set(item.allow) : undefined))
57
+ .filter((item) => Boolean(item));
56
58
  return tools.filter((tool) => !denied.has(tool.name) && allows.every((allow) => allow.has(tool.name)));
57
59
  }
58
60
  function toolExecutionMetadata(startedAt, status) {
@@ -114,8 +116,18 @@ export async function dispatchToolCall(options) {
114
116
  assertIdentityActive(context.identity);
115
117
  assertIdentityMatchesOwnership(context.identity, options.ownership);
116
118
  }
117
- await assertTrusted(options.trust, { kind: "tool", target: mediatedCall.name, capability: "execute", metadata: options.context.metadata });
118
- await assertPermission(options.permission, { kind: "tool", action: "execute", target: mediatedCall.name, metadata: options.context.metadata });
119
+ await assertTrusted(options.trust, {
120
+ kind: "tool",
121
+ target: mediatedCall.name,
122
+ capability: "execute",
123
+ metadata: options.context.metadata,
124
+ });
125
+ await assertPermission(options.permission, {
126
+ kind: "tool",
127
+ action: "execute",
128
+ target: mediatedCall.name,
129
+ metadata: options.context.metadata,
130
+ });
119
131
  }
120
132
  catch (error) {
121
133
  return blocked(mediatedCall, context, "permission_denied", errorToErrorInfo(error, secrets), options, startedAt);
@@ -170,7 +182,14 @@ export async function dispatchToolCall(options) {
170
182
  const result = { toolCallId: mediatedCall.id, name: mediatedCall.name, error: info };
171
183
  const finishedAt = new Date().toISOString();
172
184
  const metadata = toolExecutionMetadata(startedAt, "error");
173
- await options.emit?.({ type: "tool_execution_error", sessionId: context.sessionId, runId: context.runId, call: mediatedCall, error: info, metadata });
185
+ await options.emit?.({
186
+ type: "tool_execution_error",
187
+ sessionId: context.sessionId,
188
+ runId: context.runId,
189
+ call: mediatedCall,
190
+ error: info,
191
+ metadata,
192
+ });
174
193
  await appendToolCallRecord(options, "error", mediatedCall, startedAt, { finishedAt, result });
175
194
  return result;
176
195
  }