@arnilo/prism 0.0.96 → 0.1.1

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 (203) hide show
  1. package/CHANGELOG.md +290 -2
  2. package/README.md +17 -3
  3. package/dist/agent-definitions.js +2 -3
  4. package/dist/agent-event-source.d.ts +11 -0
  5. package/dist/agent-event-source.js +512 -0
  6. package/dist/agent-loops.d.ts +5 -0
  7. package/dist/agent-loops.js +99 -14
  8. package/dist/agent-run-lifecycle.d.ts +5 -2
  9. package/dist/agent-run-lifecycle.js +18 -2
  10. package/dist/agent-run-state.d.ts +27 -1
  11. package/dist/agent-run-state.js +113 -7
  12. package/dist/agents.d.ts +3 -1
  13. package/dist/agents.js +1255 -129
  14. package/dist/artifacts.d.ts +132 -0
  15. package/dist/artifacts.js +44 -0
  16. package/dist/cache-helpers.js +18 -9
  17. package/dist/checkpoints.d.ts +4 -0
  18. package/dist/checkpoints.js +17 -9
  19. package/dist/cli-init.js +3 -7
  20. package/dist/cli-runner.d.ts +2 -6
  21. package/dist/cli-runner.js +71 -33
  22. package/dist/compaction.js +5 -4
  23. package/dist/config.js +7 -4
  24. package/dist/content.js +26 -24
  25. package/dist/context-budget.d.ts +67 -0
  26. package/dist/context-budget.js +288 -0
  27. package/dist/contracts.d.ts +590 -8
  28. package/dist/contracts.js +142 -1
  29. package/dist/contribution-parsing.js +6 -2
  30. package/dist/contributions.d.ts +2 -0
  31. package/dist/contributions.js +3 -0
  32. package/dist/conversations.d.ts +50 -0
  33. package/dist/conversations.js +98 -0
  34. package/dist/credentials.d.ts +22 -2
  35. package/dist/credentials.js +18 -3
  36. package/dist/devices.d.ts +94 -0
  37. package/dist/devices.js +138 -0
  38. package/dist/event-multiplexer.js +18 -4
  39. package/dist/extensions.d.ts +18 -1
  40. package/dist/extensions.js +79 -6
  41. package/dist/feedback.js +12 -10
  42. package/dist/guardrails.d.ts +1 -1
  43. package/dist/guardrails.js +26 -17
  44. package/dist/identity.d.ts +92 -0
  45. package/dist/identity.js +265 -0
  46. package/dist/index.d.ts +94 -72
  47. package/dist/index.js +48 -36
  48. package/dist/input.d.ts +10 -1
  49. package/dist/input.js +152 -52
  50. package/dist/instruction-injection.d.ts +1 -1
  51. package/dist/middleware.js +9 -1
  52. package/dist/models.d.ts +2 -0
  53. package/dist/models.js +3 -0
  54. package/dist/node/agent-definitions.js +16 -8
  55. package/dist/node/contribution-discovery.d.ts +1 -2
  56. package/dist/node/contribution-discovery.js +3 -3
  57. package/dist/node/session-store-jsonl.js +13 -7
  58. package/dist/node/settings.d.ts +1 -1
  59. package/dist/node/settings.js +1 -1
  60. package/dist/node/system-project-prompts.js +2 -4
  61. package/dist/node/trust.js +1 -1
  62. package/dist/persistence-lifecycle.d.ts +103 -0
  63. package/dist/persistence-lifecycle.js +202 -0
  64. package/dist/provider-events.d.ts +1 -0
  65. package/dist/provider-events.js +6 -1
  66. package/dist/provider-request-policy.js +3 -4
  67. package/dist/providers/media.d.ts +1 -1
  68. package/dist/providers/openai-compatible.d.ts +46 -1
  69. package/dist/providers/openai-compatible.js +123 -53
  70. package/dist/providers/openai-primitives.js +10 -7
  71. package/dist/providers/transport.d.ts +6 -0
  72. package/dist/providers/transport.js +21 -0
  73. package/dist/providers.d.ts +2 -0
  74. package/dist/providers.js +3 -0
  75. package/dist/redaction.d.ts +1 -0
  76. package/dist/redaction.js +26 -9
  77. package/dist/resources.d.ts +2 -2
  78. package/dist/resources.js +2 -2
  79. package/dist/retry.d.ts +5 -0
  80. package/dist/retry.js +8 -1
  81. package/dist/rpc.js +55 -11
  82. package/dist/run-ledger.d.ts +6 -0
  83. package/dist/run-ledger.js +16 -13
  84. package/dist/run-limits.js +49 -10
  85. package/dist/secure-agent.js +8 -2
  86. package/dist/security.js +7 -2
  87. package/dist/session-stores.d.ts +7 -2
  88. package/dist/session-stores.js +195 -21
  89. package/dist/skill-disclosure.d.ts +35 -0
  90. package/dist/skill-disclosure.js +101 -0
  91. package/dist/skill-load.d.ts +25 -0
  92. package/dist/skill-load.js +112 -0
  93. package/dist/structured-output.d.ts +5 -1
  94. package/dist/structured-output.js +20 -2
  95. package/dist/system-prompts.js +7 -2
  96. package/dist/testing/agent-event-source-conformance.d.ts +4 -0
  97. package/dist/testing/agent-event-source-conformance.js +54 -0
  98. package/dist/testing/compaction-conformance.js +5 -1
  99. package/dist/testing/extension-conformance.js +15 -3
  100. package/dist/testing/feedback.d.ts +1 -3
  101. package/dist/testing/feedback.js +1 -1
  102. package/dist/testing/persistence-schema.d.ts +2 -2
  103. package/dist/testing/persistence-schema.js +280 -35
  104. package/dist/testing/provider-conformance.js +3 -3
  105. package/dist/testing/run-ledger-conformance.js +1 -1
  106. package/dist/testing/session-store-conformance.d.ts +6 -0
  107. package/dist/testing/session-store-conformance.js +37 -2
  108. package/dist/testing/tool-conformance.js +30 -5
  109. package/dist/testing/tool-effect-store-conformance.d.ts +9 -0
  110. package/dist/testing/tool-effect-store-conformance.js +85 -0
  111. package/dist/thinking.js +4 -1
  112. package/dist/tool-effects.d.ts +15 -0
  113. package/dist/tool-effects.js +352 -0
  114. package/dist/tool-result-fold.d.ts +40 -0
  115. package/dist/tool-result-fold.js +176 -0
  116. package/dist/tools.d.ts +8 -3
  117. package/dist/tools.js +248 -13
  118. package/docs/0.1.0-readiness.md +215 -0
  119. package/docs/a2a.md +33 -2
  120. package/docs/acp.md +152 -0
  121. package/docs/ag-ui-adoption.md +77 -0
  122. package/docs/ag-ui.md +225 -0
  123. package/docs/agent-events.md +34 -3
  124. package/docs/agent-identity.md +144 -0
  125. package/docs/agent-loops.md +17 -2
  126. package/docs/agent-session-runtime.md +21 -4
  127. package/docs/browser-automation.md +5 -0
  128. package/docs/caveman.md +129 -0
  129. package/docs/cli-rpc.md +3 -6
  130. package/docs/coding-agent-tools.md +229 -25
  131. package/docs/coding-security.md +77 -11
  132. package/docs/compaction-and-retry.md +5 -2
  133. package/docs/compaction-llm.md +20 -1
  134. package/docs/compaction-observational-memory.md +52 -8
  135. package/docs/context-and-skills.md +94 -7
  136. package/docs/contribution-registries.md +1 -0
  137. package/docs/conversations.md +135 -0
  138. package/docs/credential-storage.md +34 -1
  139. package/docs/credentials-and-redaction.md +11 -1
  140. package/docs/database-persistence.md +27 -7
  141. package/docs/device-adapters.md +97 -0
  142. package/docs/enterprise-postgres-state.md +178 -0
  143. package/docs/evaluations.md +14 -1
  144. package/docs/extensions.md +4 -1
  145. package/docs/forge-integration.md +113 -0
  146. package/docs/guardrails.md +16 -2
  147. package/docs/host-security.md +35 -4
  148. package/docs/index.md +69 -37
  149. package/docs/input-and-prompt-assembly.md +8 -7
  150. package/docs/language-intelligence.md +162 -0
  151. package/docs/mcp-tools.md +62 -5
  152. package/docs/middleware-hooks.md +2 -2
  153. package/docs/migration.md +427 -2
  154. package/docs/model-routing.md +111 -0
  155. package/docs/multimodal-content.md +8 -5
  156. package/docs/node-jsonl-session-store.md +1 -1
  157. package/docs/observability.md +2 -0
  158. package/docs/openapi-tools.md +56 -0
  159. package/docs/performance.md +282 -0
  160. package/docs/policy-and-audit.md +171 -0
  161. package/docs/ponytail.md +127 -0
  162. package/docs/postgres-persistence.md +8 -4
  163. package/docs/process-sessions.md +147 -0
  164. package/docs/provider-caching.md +13 -1
  165. package/docs/provider-conformance.md +29 -5
  166. package/docs/provider-packages.md +43 -2
  167. package/docs/provider-request-policies.md +2 -0
  168. package/docs/providers/ai-sdk.md +24 -7
  169. package/docs/providers/alibaba.md +179 -0
  170. package/docs/providers/anthropic.md +93 -0
  171. package/docs/providers/azure.md +74 -0
  172. package/docs/providers/bedrock.md +72 -0
  173. package/docs/providers/google.md +89 -0
  174. package/docs/providers/ollama.md +166 -0
  175. package/docs/providers/openai-compatible.md +31 -2
  176. package/docs/providers/openai.md +24 -5
  177. package/docs/providers/openrouter.md +2 -0
  178. package/docs/providers/vertex.md +71 -0
  179. package/docs/public-contracts.md +68 -4
  180. package/docs/rag.md +41 -12
  181. package/docs/release-and-install.md +362 -208
  182. package/docs/resource-loading.md +3 -0
  183. package/docs/runs-and-usage.md +3 -0
  184. package/docs/server.md +44 -6
  185. package/docs/session-store-conformance.md +2 -0
  186. package/docs/session-stores.md +41 -2
  187. package/docs/sqlite-persistence.md +11 -3
  188. package/docs/structured-output.md +7 -1
  189. package/docs/supervisors.md +8 -0
  190. package/docs/tool-effects.md +95 -0
  191. package/docs/tools.md +5 -0
  192. package/docs/work-artifacts-and-review.md +102 -0
  193. package/docs/work-connectors.md +32 -0
  194. package/docs/work-tools.md +137 -0
  195. package/docs/workflows.md +6 -0
  196. package/docs/working-and-semantic-memory.md +40 -7
  197. package/package.json +30 -7
  198. package/templates/init/providers.json +22 -0
  199. package/docs/review-coverage-2026-07-14.md +0 -260
  200. package/docs/review-coverage-2026-07-15.md +0 -193
  201. package/docs/review-coverage-2026-07-17-provider-validation.md +0 -192
  202. package/docs/review-coverage-2026-07-19-phase-3.md +0 -174
  203. package/docs/review-coverage-2026-07-20-phase-4.md +0 -175
@@ -1,11 +1,11 @@
1
- import type { AgentInput } from "./input.js";
1
+ import type { AudioContent, DocumentContent, FileContent } from "./content.js";
2
2
  import type { ContributionRegistries } from "./contributions.js";
3
+ import type { AgentInput } from "./input.js";
4
+ import type { ManifestContributionDeclaration } from "./manifests.js";
3
5
  import type { Middleware, MiddlewareHookName, MiddlewareRegistry } from "./middleware.js";
4
6
  import type { SecretRedactor } from "./redaction.js";
5
7
  import type { PermissionPolicy, TrustPolicy } from "./security.js";
6
- import type { ManifestContributionDeclaration } from "./manifests.js";
7
8
  import type { ToolValidator } from "./tools.js";
8
- import type { AudioContent, DocumentContent, FileContent } from "./content.js";
9
9
  export type JsonPrimitive = string | number | boolean | null;
10
10
  export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
11
11
  export interface JsonObject {
@@ -15,6 +15,9 @@ export interface ErrorInfo {
15
15
  readonly name?: string;
16
16
  readonly message: string;
17
17
  readonly code?: string | number;
18
+ /** Provider backpressure hint (e.g. from a `Retry-After` header); retry policies
19
+ * honor it capped at their own `maxDelayMs`. */
20
+ readonly retryAfterMs?: number;
18
21
  readonly cause?: unknown;
19
22
  }
20
23
  export type { AudioContent, DocumentContent, FileContent } from "./content.js";
@@ -43,7 +46,11 @@ export interface ToolCallDeltaContent {
43
46
  readonly id?: string;
44
47
  readonly name?: string;
45
48
  readonly argumentsText?: string;
49
+ /** Who executes the call. `"provider-hosted"` = the provider runs it server-side;
50
+ * the host must NOT dispatch it or send a `tool_result`. Defaults to `"host"`. */
51
+ readonly authority?: ToolCallAuthority;
46
52
  }
53
+ export type ToolCallAuthority = "host" | "provider-hosted";
47
54
  export interface ToolCallContent {
48
55
  readonly type: "tool_call";
49
56
  readonly id: string;
@@ -51,6 +58,10 @@ export interface ToolCallContent {
51
58
  readonly arguments: JsonObject;
52
59
  /** Set when streamed arguments failed JSON parse; dispatch blocks without execute(). */
53
60
  readonly argumentsError?: ErrorInfo;
61
+ /** Who executes the call. `"provider-hosted"` = the provider already ran it
62
+ * server-side; the host must NOT dispatch it or append a `tool_result`. The
63
+ * assistant response text already incorporates the call's effect. */
64
+ readonly authority?: ToolCallAuthority;
54
65
  }
55
66
  export interface ToolResultContent {
56
67
  readonly type: "tool_result";
@@ -229,6 +240,11 @@ export interface ProviderRequestOptions {
229
240
  readonly extra?: JsonObject;
230
241
  /** Provider-neutral JSON-schema structured output request. Requires model `capabilities.structuredOutput`. */
231
242
  readonly structuredOutput?: StructuredOutputOptions;
243
+ /** Opaque provider continuation cursor (e.g. OpenAI `previous_response_id`). When set,
244
+ * the provider resumes from this cursor instead of re-sending full history. */
245
+ readonly continuation?: {
246
+ readonly cursor: string;
247
+ };
232
248
  }
233
249
  export interface ProviderRequest {
234
250
  readonly model: ModelConfig;
@@ -251,12 +267,17 @@ export type ProviderEvent = {
251
267
  readonly id?: string;
252
268
  readonly name?: string;
253
269
  readonly argumentsText?: string;
270
+ readonly authority?: ToolCallAuthority;
254
271
  } | {
255
272
  readonly type: "tool_call";
256
273
  readonly call: ToolCallContent;
257
274
  } | {
258
275
  readonly type: "usage";
259
276
  readonly usage: Usage;
277
+ } | {
278
+ readonly type: "continuation_required";
279
+ readonly cursor: string;
280
+ readonly reason?: string;
260
281
  } | {
261
282
  readonly type: "done";
262
283
  readonly usage?: Usage;
@@ -269,6 +290,64 @@ export interface AIProvider {
269
290
  generate(request: ProviderRequest): AsyncIterable<ProviderEvent>;
270
291
  }
271
292
  export type ProviderResolver = (model: ModelConfig) => AIProvider | undefined;
293
+ /** Realtime audio/session event. Realtime is a bidirectional session, not a request/response
294
+ * stream, so it is a separate neutral seam from `AIProvider.generate()`. Credentials are
295
+ * bound to the session handshake only and never appear in events. */
296
+ export type RealtimeEvent = {
297
+ readonly type: "session_started";
298
+ readonly sessionId?: string;
299
+ } | {
300
+ readonly type: "audio_delta";
301
+ readonly audio: Uint8Array;
302
+ } | {
303
+ readonly type: "transcript_delta";
304
+ readonly text: string;
305
+ readonly role: "user" | "assistant";
306
+ } | {
307
+ readonly type: "tool_call";
308
+ readonly call: ToolCallContent;
309
+ } | {
310
+ readonly type: "interrupted";
311
+ } | {
312
+ readonly type: "session_closed";
313
+ readonly reason?: string;
314
+ } | {
315
+ readonly type: "error";
316
+ readonly error: ErrorInfo;
317
+ };
318
+ /** Neutral bidirectional realtime session seam. The provider owns the transport
319
+ * (e.g. WebSocket); the host owns audio capture/playback and session lifecycle. */
320
+ export interface RealtimeSession {
321
+ readonly id: string;
322
+ readonly provider: string;
323
+ /** Send an audio chunk (PCM/Opus; provider-specific format set at creation). */
324
+ sendAudio(chunk: Uint8Array, options?: {
325
+ readonly signal?: AbortSignal;
326
+ }): Promise<void>;
327
+ /** Inbound events (audio out, transcripts, hosted tool calls, interruption, close, error). */
328
+ events(): AsyncIterable<RealtimeEvent>;
329
+ /** Request the provider stop the current response mid-stream. */
330
+ interrupt(options?: {
331
+ readonly signal?: AbortSignal;
332
+ }): Promise<void>;
333
+ /** Close the session and release the transport. Idempotent. */
334
+ close(reason?: string, options?: {
335
+ readonly signal?: AbortSignal;
336
+ }): Promise<void>;
337
+ }
338
+ /** Factory a provider exposes for realtime sessions; not part of `AIProvider`. */
339
+ export type RealtimeSessionFactory = (options: RealtimeSessionOptions) => RealtimeSession;
340
+ export interface RealtimeSessionOptions {
341
+ readonly model: ModelConfig;
342
+ readonly signal?: AbortSignal;
343
+ /** Provider-specific caps override; providers enforce finite defaults. */
344
+ readonly caps?: RealtimeCaps;
345
+ }
346
+ export interface RealtimeCaps {
347
+ readonly maxAudioEventsPerSecond?: number;
348
+ readonly maxBytesPerSecond?: number;
349
+ readonly maxWallMs?: number;
350
+ }
272
351
  export type InputAssemblyLayout = "legacy" | "cache_aware";
273
352
  export interface RunOptions {
274
353
  readonly signal?: AbortSignal;
@@ -286,11 +365,21 @@ export interface RunOptions {
286
365
  readonly metadata?: Readonly<Record<string, unknown>>;
287
366
  readonly redactor?: SecretRedactor;
288
367
  readonly runLedger?: RunLedger;
368
+ /** Optional durable recovery store. Per-run value overrides this agent default. */
369
+ readonly effectStore?: ToolEffectStore;
289
370
  readonly ownership?: OwnershipScope;
371
+ /** Host-verified identity; when set, must project onto `ownership` without widening. */
372
+ readonly identity?: import("./identity.js").AgentIdentity;
290
373
  readonly idempotencyKey?: string;
291
374
  readonly validate?: ToolValidator;
292
375
  readonly activeSkills?: readonly string[];
293
376
  readonly skills?: readonly Skill[];
377
+ /** Migration opt-in: activate every skill in a configured `SkillRegistry` when `activeSkills` / `skills` are unset. */
378
+ readonly activateAllSkills?: true;
379
+ /** Progressive: catalog (name+description) unless loaded; eager: full instructions every turn. Default progressive. */
380
+ readonly skillsDisclosure?: import("./skill-disclosure.js").SkillsDisclosure;
381
+ /** Opt-in projection-only fold for aged large tool results in provider view; store untouched. */
382
+ readonly toolResultFold?: import("./tool-result-fold.js").ToolResultFoldOptions;
294
383
  readonly instructionInjectors?: readonly InstructionInjector[];
295
384
  readonly inputLayout?: InputAssemblyLayout;
296
385
  readonly loop?: AgentLoopStrategy | AgentLoopOptions;
@@ -338,6 +427,12 @@ export interface AgentConfig {
338
427
  readonly tools?: ToolRegistry | readonly ToolDefinition[];
339
428
  readonly context?: readonly ContextProvider[];
340
429
  readonly skills?: SkillRegistry | readonly Skill[];
430
+ /** Migration opt-in: activate every registry skill by default when run options do not narrow activation. */
431
+ readonly activateAllSkills?: true;
432
+ /** Progressive: catalog (name+description) unless loaded; eager: full instructions every turn. Default progressive. */
433
+ readonly skillsDisclosure?: import("./skill-disclosure.js").SkillsDisclosure;
434
+ /** Opt-in projection-only fold for aged large tool results in provider view; store untouched. */
435
+ readonly toolResultFold?: import("./tool-result-fold.js").ToolResultFoldOptions;
341
436
  readonly inputBuilder?: InputBuilder;
342
437
  readonly promptBuilder?: PromptBuilder;
343
438
  readonly middleware?: MiddlewareRegistry;
@@ -351,7 +446,11 @@ export interface AgentConfig {
351
446
  readonly systemPrompt?: SystemPromptConfig;
352
447
  readonly redactor?: SecretRedactor;
353
448
  readonly runLedger?: RunLedger;
449
+ /** Optional durable recovery store. */
450
+ readonly effectStore?: ToolEffectStore;
354
451
  readonly ownership?: OwnershipScope;
452
+ /** Host-verified identity default for sessions created from this agent. */
453
+ readonly identity?: import("./identity.js").AgentIdentity;
355
454
  readonly idempotencyKey?: string;
356
455
  readonly compaction?: false | CompactionOptions;
357
456
  readonly retry?: false | RetryOptions;
@@ -369,7 +468,7 @@ export interface AgentConfig {
369
468
  readonly secure?: true;
370
469
  }
371
470
  /** Opt-in fail-closed composition over the normal explicit AgentConfig API. */
372
- export interface SecureAgentOptions extends Omit<AgentConfig, "tools" | "validator" | "redactor" | "permission" | "trust" | "ownership" | "limits" | "runState" | "secure"> {
471
+ export interface SecureAgentOptions extends Omit<AgentConfig, "tools" | "validator" | "redactor" | "permission" | "trust" | "ownership" | "identity" | "limits" | "runState" | "secure"> {
373
472
  readonly id: string;
374
473
  readonly tools: readonly ToolDefinition[];
375
474
  readonly toolArgumentValidator: import("./tools.js").ToolArgumentValidator;
@@ -377,6 +476,8 @@ export interface SecureAgentOptions extends Omit<AgentConfig, "tools" | "validat
377
476
  readonly permission: PermissionPolicy;
378
477
  readonly trust: TrustPolicy;
379
478
  readonly ownership: OwnershipScope;
479
+ /** Optional host-verified identity; when set must match `ownership`. */
480
+ readonly identity?: import("./identity.js").AgentIdentity;
380
481
  readonly limits: RunLimits;
381
482
  readonly definitionRevision: string;
382
483
  readonly runState: Omit<AgentRunStateOptions, "definitionRevision" | "interruptBeforeTool">;
@@ -407,14 +508,144 @@ export interface SubscribeOptions {
407
508
  readonly overflow?: SubscriberOverflowPolicy;
408
509
  }
409
510
  export type AgentRunStatus = "succeeded" | "failed" | "aborted" | "suspended" | "denied";
410
- export type AgentRunInterruptionKind = "input_guardrail" | "tool_approval";
511
+ export type AgentRunInterruptionKind = "input_guardrail" | "tool_approval" | "elicitation";
512
+ export type ApprovalOutcome = "allow_once" | "allow_for_run" | "reject_once" | "reject_for_run";
513
+ export type PendingDecisionKind = "tool_approval" | "elicitation";
514
+ /** Redacted match scope for one pending or sticky decision; never contains raw tool arguments. */
515
+ export interface DecisionScope {
516
+ readonly toolName?: string;
517
+ readonly effectKind?: ToolEffectKind;
518
+ /** Redacted principal reference (tenant/kind/id); never a credential. */
519
+ readonly identity?: string;
520
+ /** Bounded argument-value constraints; deep-equal matched per key. */
521
+ readonly actionConstraints?: Readonly<Record<string, JsonValue>>;
522
+ /** SHA-256 of canonical JSON arguments; present instead of raw arguments. */
523
+ readonly argumentsHash?: string;
524
+ }
525
+ /** One redacted, unresolved approval request inside a suspended durable run. */
526
+ export interface PendingDecision {
527
+ /** Unique within the run; nested runs use supervisor-prefixed ids. */
528
+ readonly approvalId: string;
529
+ readonly kind: PendingDecisionKind;
530
+ readonly toolCallId?: string;
531
+ readonly scope: DecisionScope;
532
+ /** Bounded, redacted. */
533
+ readonly reason: string;
534
+ /** Typed payload contract for elicitation decisions. */
535
+ readonly elicitationSchema?: JsonObject;
536
+ /** Delegation chain, root-first; core-written, never client-supplied. */
537
+ readonly attribution?: {
538
+ readonly path: readonly string[];
539
+ };
540
+ }
411
541
  /** Redacted safe-boundary descriptor; never contains tool arguments. */
412
542
  export interface AgentRunInterruption {
413
543
  readonly kind: AgentRunInterruptionKind;
414
544
  readonly reason: string;
415
545
  readonly toolCallId?: string;
416
546
  readonly toolName?: string;
547
+ /** All unresolved approval requests of this suspension; absent for legacy single approvals. */
548
+ readonly pendingDecisions?: readonly PendingDecision[];
549
+ }
550
+ /** One host decision applied to one pending approval request. */
551
+ export interface RunDecision {
552
+ readonly approvalId: string;
553
+ readonly outcome: ApprovalOutcome;
554
+ /** Bounded to 2 KiB; redacted. */
555
+ readonly reason?: string;
556
+ /** Revalidated (schema, guardrails, policy) before dispatch; produces a new arguments hash. */
557
+ readonly modifiedArguments?: JsonObject;
558
+ /** Elicitation payload; validated against the pending decision's elicitationSchema. */
559
+ readonly elicitation?: JsonObject;
560
+ }
561
+ /** Run-scoped sticky decision; exact scope match, rechecked against policy, dropped at run end. */
562
+ export interface StickyDecision {
563
+ readonly scope: DecisionScope;
564
+ readonly outcome: "allow_for_run" | "reject_for_run";
565
+ readonly reason?: string;
566
+ readonly decidedAt: string;
567
+ /** Delegation path when the sticky was created for a nested-run decision. */
568
+ readonly attribution?: {
569
+ readonly path: readonly string[];
570
+ };
571
+ }
572
+ /** Root-visible link between one nested approval and the child-run approval id. */
573
+ export interface NestedRunApproval {
574
+ /** Root-visible approval id (hashed, non-enumerating across runs). */
575
+ readonly id: string;
576
+ /** Approval id as the nested run recorded it. */
577
+ readonly childApprovalId: string;
578
+ }
579
+ /** Root-visible link between a suspended nested run and the tool call that hosted it. */
580
+ export interface NestedRunRef {
581
+ readonly runId: string;
582
+ readonly sessionId?: string;
583
+ readonly toolCallId: string;
584
+ /** Redacted delegation path (child ids, root first). */
585
+ readonly path: readonly string[];
586
+ readonly approvals: readonly NestedRunApproval[];
587
+ /** Decisions persisted by a partial batch, keyed by root-visible approval id. */
588
+ readonly decisions?: Readonly<Record<string, RunDecision>>;
589
+ }
590
+ /** Outcome of resuming a nested run through the host-supplied hook. */
591
+ export type NestedRunOutcome = {
592
+ readonly status: "suspended";
593
+ readonly pendingDecisions: readonly PendingDecision[];
594
+ } | {
595
+ readonly status: "completed";
596
+ readonly value?: JsonValue;
597
+ } | {
598
+ readonly status: "failed";
599
+ readonly code: string;
600
+ readonly message: string;
601
+ };
602
+ /**
603
+ * Host hook that resumes a nested run (supervisor child) with child-visible decisions.
604
+ * Used both when a nested suspension first surfaces (sticky auto-apply) and when root
605
+ * decisions route back to the child on resume.
606
+ */
607
+ export type ResumeNestedRun = (nested: {
608
+ readonly ref: AgentRunRef;
609
+ readonly toolCallId: string;
610
+ readonly path: readonly string[];
611
+ }, decisions: readonly RunDecision[]) => Promise<NestedRunOutcome>;
612
+ /**
613
+ * Thrown by a delegated-run host (e.g. the supervisor) when a nested run suspends on
614
+ * pending decisions inside a tool execution. Core converts it into a root suspension
615
+ * with attributed, root-visible approval ids; the dispatching wrapper attaches `toolCall`.
616
+ */
617
+ export declare class AgentDelegationSuspendedError extends Error {
618
+ readonly ref: AgentRunRef;
619
+ readonly pendingDecisions: readonly PendingDecision[];
620
+ /** Redacted delegation path (child ids) used when decisions carry no attribution. */
621
+ readonly path?: readonly string[] | undefined;
622
+ readonly code = "ERR_PRISM_DELEGATION_SUSPENDED";
623
+ toolCall?: ToolCallContent;
624
+ constructor(ref: AgentRunRef, pendingDecisions: readonly PendingDecision[],
625
+ /** Redacted delegation path (child ids) used when decisions carry no attribution. */
626
+ path?: readonly string[] | undefined);
627
+ }
628
+ /** Shared decision-contract violations. Unknown and foreign approval ids share one non-enumerating error. */
629
+ export declare class AgentDecisionError extends Error {
630
+ readonly code: "ERR_PRISM_DECISION_STALE" | "ERR_PRISM_DECISION_UNKNOWN" | "ERR_PRISM_DECISION_DUPLICATE" | "ERR_PRISM_DECISION_SCOPE" | "ERR_PRISM_DECISION_INVALID" | "ERR_PRISM_DECISION_LIMIT";
631
+ constructor(code: "ERR_PRISM_DECISION_STALE" | "ERR_PRISM_DECISION_UNKNOWN" | "ERR_PRISM_DECISION_DUPLICATE" | "ERR_PRISM_DECISION_SCOPE" | "ERR_PRISM_DECISION_INVALID" | "ERR_PRISM_DECISION_LIMIT", message: string, options?: {
632
+ readonly cause?: unknown;
633
+ });
417
634
  }
635
+ export declare const DEFAULT_MAX_PENDING_DECISIONS = 32;
636
+ export declare const HARD_MAX_PENDING_DECISIONS = 128;
637
+ export declare const DEFAULT_MAX_STICKY_DECISIONS = 64;
638
+ export declare const HARD_MAX_STICKY_DECISIONS = 256;
639
+ export declare const MAX_DECISION_REASON_BYTES: number;
640
+ export declare const HARD_MAX_DECISION_REASON_BYTES: number;
641
+ export declare const MAX_ELICITATION_BYTES: number;
642
+ export declare const HARD_MAX_ELICITATION_BYTES: number;
643
+ export declare const MAX_ACTION_CONSTRAINTS = 32;
644
+ export declare const HARD_MAX_ACTION_CONSTRAINTS = 64;
645
+ /** Maximum delegation attribution depth for surfaced nested pending decisions. */
646
+ export declare const MAX_ATTRIBUTION_DEPTH = 8;
647
+ export declare const MAX_ACTION_CONSTRAINT_BYTES: number;
648
+ export declare const HARD_MAX_ACTION_CONSTRAINT_BYTES: number;
418
649
  export interface AgentRunStateOptions {
419
650
  readonly checkpoints: CheckpointStore;
420
651
  /** Host-authored immutable revision required for durable runs. */
@@ -423,6 +654,8 @@ export interface AgentRunStateOptions {
423
654
  readonly interruptBeforeTool?: boolean;
424
655
  readonly maxStateBytes?: number;
425
656
  readonly fencingToken?: number;
657
+ /** Enables sticky auto-apply when a nested suspension first surfaces during this run. */
658
+ readonly resumeNestedRun?: ResumeNestedRun;
426
659
  }
427
660
  /** Versioned, redacted checkpoint payload. Treat as opaque except status/version/interruption. */
428
661
  export interface AgentRunState {
@@ -439,8 +672,11 @@ export interface AgentRunState {
439
672
  readonly version?: number;
440
673
  }
441
674
  export interface AgentRunResume {
442
- readonly decision: "approve" | "deny";
443
675
  readonly expectedVersion: number;
676
+ /** Legacy single-approval path; `approve` allows all pending once, `deny` terminates the run denied. */
677
+ readonly decision?: "approve" | "deny";
678
+ /** Batch decision path; exactly one of decision/decisions. Applied as one atomic CAS transition. */
679
+ readonly decisions?: readonly RunDecision[];
444
680
  }
445
681
  export interface AgentRunResumeOptions {
446
682
  readonly checkpoints: CheckpointStore;
@@ -448,6 +684,12 @@ export interface AgentRunResumeOptions {
448
684
  readonly definitionRevision: string;
449
685
  readonly ownership?: OwnershipScope;
450
686
  readonly fencingToken?: number;
687
+ /** Routes root decisions for nested-run approvals back to the child (e.g. supervisor). */
688
+ readonly resumeNestedRun?: ResumeNestedRun;
689
+ }
690
+ /** Bounded, abortable options for `resumeAgentRunStream()`. */
691
+ export interface AgentRunResumeStreamOptions extends AgentRunResumeOptions, SubscribeOptions {
692
+ readonly signal?: AbortSignal;
451
693
  }
452
694
  export interface AgentRunRef {
453
695
  readonly runId: string;
@@ -461,6 +703,13 @@ export declare class AgentRunStateError extends Error {
461
703
  readonly code = "ERR_PRISM_AGENT_RUN_STATE";
462
704
  constructor(message: string);
463
705
  }
706
+ /** Durable-loop contract violations: hook-less custom strategy on a durable run, invalid snapshot, or revision drift. */
707
+ export declare class AgentLoopStateError extends Error {
708
+ readonly code: "ERR_PRISM_LOOP_NOT_DURABLE" | "ERR_PRISM_LOOP_SNAPSHOT" | "ERR_PRISM_LOOP_REVISION";
709
+ constructor(code: "ERR_PRISM_LOOP_NOT_DURABLE" | "ERR_PRISM_LOOP_SNAPSHOT" | "ERR_PRISM_LOOP_REVISION", message: string, options?: {
710
+ readonly cause?: unknown;
711
+ });
712
+ }
464
713
  /** Terminal result of `session.run()` / `session.prompt()`. Failed and aborted runs throw {@link AgentRunError} with this shape attached. */
465
714
  export interface AgentRunResult {
466
715
  readonly sessionId: string;
@@ -493,6 +742,22 @@ export declare class AgentRunError extends Error {
493
742
  readonly cause?: unknown;
494
743
  });
495
744
  }
745
+ /** Mid-run steer queue: default pending message count (fail closed at this cap). */
746
+ export declare const DEFAULT_MAX_PENDING_STEERS = 8;
747
+ /** Absolute pending steer count ceiling if hosts later expose overrides. */
748
+ export declare const HARD_MAX_PENDING_STEERS = 32;
749
+ /** Mid-run steer queue: default total UTF-8 byte budget across pending messages. */
750
+ export declare const DEFAULT_MAX_PENDING_STEER_BYTES: number;
751
+ /** Absolute pending steer byte ceiling if hosts later expose overrides. */
752
+ export declare const HARD_MAX_PENDING_STEER_BYTES: number;
753
+ export interface SteerOptions {
754
+ /**
755
+ * When true, abort the in-flight provider stream and continue the same run after
756
+ * injecting steered user text. Default false: inject before the next provider turn
757
+ * (after the current tool batch completes).
758
+ */
759
+ readonly softInterrupt?: boolean;
760
+ }
496
761
  export interface AgentSession {
497
762
  readonly id: string;
498
763
  /** Current branch leaf entry id; advances on every append/run and is re-pointed by `checkout`.
@@ -500,6 +765,12 @@ export interface AgentSession {
500
765
  readonly leafId: string | undefined;
501
766
  run(input: string | Message | readonly Message[], options?: RunOptions): Promise<AgentRunResult>;
502
767
  prompt(input: string, options?: RunOptions): Promise<AgentRunResult>;
768
+ /**
769
+ * Enqueue user text into an active run. Default injects before the next provider turn.
770
+ * `softInterrupt: true` aborts the current provider stream, then continues the same run.
771
+ * Fails closed when no run is active or the pending queue exceeds caps.
772
+ */
773
+ steer(input: string | Message | readonly Message[], options?: SteerOptions): void;
503
774
  /** Subscribe first, then start exactly one run and yield only that run's events until it terminates. */
504
775
  stream(input: string | Message | readonly Message[], options?: RunOptions & SubscribeOptions): AsyncIterable<AgentEvent>;
505
776
  compact(options?: CompactionOptions): Promise<CompactionResult>;
@@ -641,6 +912,13 @@ export type AgentEvent = {
641
912
  readonly sessionId: string;
642
913
  readonly runId: string;
643
914
  readonly size: number;
915
+ } | {
916
+ /** A steered message was dropped by a terminal input guardrail; the run continues without it. */
917
+ readonly type: "steer_rejected";
918
+ readonly sessionId: string;
919
+ readonly runId: string;
920
+ readonly message: Message;
921
+ readonly record: GuardrailRecord;
644
922
  } | {
645
923
  readonly type: "event_subscriber_overflow";
646
924
  readonly sessionId: string;
@@ -704,12 +982,38 @@ export type AgentEvent = {
704
982
  readonly attempt: number;
705
983
  readonly result: ArtifactValidation;
706
984
  };
985
+ export type ToolEffectKind = "none" | "local_mutation" | "external_mutation";
986
+ export type ToolEffectIdempotency = "none" | "optional" | "required" | "tool_managed" | "unsupported";
987
+ /** Static or validated-argument classification of one tool call's side-effect behavior. */
988
+ export interface ToolEffectDeclaration {
989
+ readonly kind: ToolEffectKind;
990
+ readonly idempotency: ToolEffectIdempotency;
991
+ }
992
+ /** Runs after argument validation. It must be synchronous, deterministic, bounded, and side-effect-free. */
993
+ export type ToolEffectClassifier = (args: JsonObject, context: ToolExecutionContext) => ToolEffectDeclaration;
994
+ /**
995
+ * Elicitation contract declared by a tool. When a durable gated run suspends on this tool,
996
+ * the pending decision has kind `elicitation` and carries this schema as its payload contract;
997
+ * the resume decision's `elicitation` payload resolves the call without executing it.
998
+ */
999
+ export interface ToolElicitationRequest {
1000
+ /** Typed payload contract; bounded to HARD_MAX_ELICITATION_BYTES when serialized. */
1001
+ readonly schema: JsonObject;
1002
+ /** Human-facing reason (e.g. the question); bounded to MAX_DECISION_REASON_BYTES. */
1003
+ readonly reason?: string;
1004
+ /** Answer-shape validation beyond structural schema checks; throw to reject the payload. */
1005
+ readonly validate?: (payload: JsonObject) => void;
1006
+ }
707
1007
  export interface ToolDefinition {
708
1008
  readonly name: string;
709
1009
  readonly description?: string;
710
1010
  readonly parameters?: JsonObject;
711
1011
  /** Force any provider turn containing this tool to dispatch sequentially. */
712
1012
  readonly exclusive?: boolean;
1013
+ /** Optional side-effect declaration. Omitted tools retain legacy unmanaged dispatch. */
1014
+ readonly effect?: ToolEffectDeclaration | ToolEffectClassifier;
1015
+ /** Optional elicitation contract for durable gating; return undefined to fall back to plain tool approval. */
1016
+ readonly elicitation?: (args: JsonObject, context: ToolExecutionContext) => ToolElicitationRequest | undefined;
713
1017
  execute(args: JsonObject, context: ToolExecutionContext): Promise<ToolResult> | ToolResult;
714
1018
  }
715
1019
  export interface ToolRegistry {
@@ -724,6 +1028,10 @@ export interface ToolExecutionContext {
724
1028
  readonly toolCallId: string;
725
1029
  readonly signal?: AbortSignal;
726
1030
  readonly metadata?: Readonly<Record<string, unknown>>;
1031
+ /** Host-verified identity for this tool invocation, when enterprise identity is active. */
1032
+ readonly identity?: import("./identity.js").AgentIdentity;
1033
+ /** Core-derived stable effect key. Never accept a model-supplied key as authority. */
1034
+ readonly idempotencyKey?: string;
727
1035
  progress?(progress?: unknown, metadata?: Readonly<Record<string, unknown>>): void | Promise<void>;
728
1036
  }
729
1037
  export interface ToolResult {
@@ -734,6 +1042,90 @@ export interface ToolResult {
734
1042
  readonly error?: ErrorInfo;
735
1043
  readonly metadata?: Readonly<Record<string, unknown>>;
736
1044
  }
1045
+ export type ToolEffectStatus = "pending" | "dispatched" | "completed" | "failed_retryable" | "failed_terminal" | "unknown";
1046
+ export interface ToolEffectRecord extends OwnershipScope {
1047
+ readonly key: string;
1048
+ readonly sessionId: string;
1049
+ readonly runId: string;
1050
+ readonly toolCallId: string;
1051
+ readonly toolName: string;
1052
+ readonly argumentsHash: string;
1053
+ readonly status: ToolEffectStatus;
1054
+ readonly attempt: number;
1055
+ readonly version: number;
1056
+ readonly claimToken?: string;
1057
+ readonly result?: ToolResult;
1058
+ readonly resultRef?: string;
1059
+ readonly failure?: {
1060
+ readonly code: string;
1061
+ readonly reference?: string;
1062
+ };
1063
+ readonly createdAt: string;
1064
+ readonly updatedAt: string;
1065
+ readonly expiresAt?: string;
1066
+ }
1067
+ export interface ToolEffectKey {
1068
+ readonly identity: import("./identity.js").AgentIdentity;
1069
+ readonly ownership: OwnershipScope;
1070
+ readonly key: string;
1071
+ readonly sessionId: string;
1072
+ readonly runId: string;
1073
+ readonly toolCallId: string;
1074
+ readonly toolName: string;
1075
+ readonly argumentsHash: string;
1076
+ readonly signal?: AbortSignal;
1077
+ }
1078
+ export interface ToolEffectTransition extends ToolEffectKey {
1079
+ readonly claimToken: string;
1080
+ readonly expectedVersion: number;
1081
+ }
1082
+ /** Durable claim/CAS store for recoverable tool effects. */
1083
+ export interface ToolEffectStore {
1084
+ get(input: ToolEffectKey): Promise<ToolEffectRecord | undefined>;
1085
+ begin(input: ToolEffectKey & {
1086
+ readonly claimTtlMs?: number;
1087
+ readonly maxAttempts?: number;
1088
+ }): Promise<{
1089
+ readonly outcome: "acquired" | "existing";
1090
+ readonly record: ToolEffectRecord;
1091
+ }>;
1092
+ markDispatched(input: ToolEffectTransition): Promise<ToolEffectRecord>;
1093
+ complete(input: ToolEffectTransition & {
1094
+ readonly result?: ToolResult;
1095
+ readonly resultRef?: string;
1096
+ }): Promise<ToolEffectRecord>;
1097
+ fail(input: ToolEffectTransition & {
1098
+ readonly status: "failed_retryable" | "failed_terminal";
1099
+ readonly failure: {
1100
+ readonly code: string;
1101
+ readonly reference?: string;
1102
+ };
1103
+ }): Promise<ToolEffectRecord>;
1104
+ markUnknown(input: ToolEffectTransition & {
1105
+ readonly failure?: {
1106
+ readonly code: string;
1107
+ readonly reference?: string;
1108
+ };
1109
+ }): Promise<ToolEffectRecord>;
1110
+ resolveUnknown(input: ToolEffectKey & {
1111
+ readonly expectedVersion: number;
1112
+ readonly status: "completed" | "failed_retryable" | "failed_terminal";
1113
+ readonly result?: ToolResult;
1114
+ readonly resultRef?: string;
1115
+ readonly failure?: {
1116
+ readonly code: string;
1117
+ readonly reference?: string;
1118
+ };
1119
+ }): Promise<ToolEffectRecord>;
1120
+ cleanup(input: {
1121
+ readonly ownership: OwnershipScope;
1122
+ readonly before: string;
1123
+ readonly limit?: number;
1124
+ readonly signal?: AbortSignal;
1125
+ }): Promise<{
1126
+ readonly deleted: number;
1127
+ }>;
1128
+ }
737
1129
  export interface CommandDefinition {
738
1130
  readonly name: string;
739
1131
  readonly description?: string;
@@ -826,7 +1218,14 @@ export interface PromptBuildRequest {
826
1218
  readonly messages: readonly Message[];
827
1219
  readonly context?: readonly ContextBlock[];
828
1220
  readonly skills?: readonly Skill[];
1221
+ readonly skillsDisclosure?: import("./skill-disclosure.js").SkillsDisclosure;
1222
+ readonly loadedSkills?: import("./skill-disclosure.js").LoadedSkillSet;
1223
+ /** Skills demoted to catalog-only by context budget this turn. */
1224
+ readonly demotedSkillBodies?: readonly string[];
829
1225
  readonly tools?: readonly ToolDefinition[];
1226
+ /** Model being prompted; lets builders adapt composition to declared capabilities
1227
+ * (e.g. the default builder omits the `Available tools:` text for tool-capable models). */
1228
+ readonly model?: ModelConfig;
830
1229
  readonly metadata?: Readonly<Record<string, unknown>>;
831
1230
  readonly signal?: AbortSignal;
832
1231
  }
@@ -874,6 +1273,9 @@ export interface ExtensionEvent {
874
1273
  export interface Extension {
875
1274
  readonly name: string;
876
1275
  setup(api: ExtensionAPI): void | Promise<void>;
1276
+ /** Host-attested signature/digest for `ExtensionLoadPolicy.verifySignature`. */
1277
+ readonly signature?: string;
1278
+ readonly metadata?: Readonly<Record<string, unknown>>;
877
1279
  }
878
1280
  export interface ProviderPackage {
879
1281
  readonly name: string;
@@ -931,6 +1333,8 @@ export interface OAuthProvider {
931
1333
  readonly id: string;
932
1334
  login(callbacks?: OAuthLoginCallbacks): Promise<OAuthCredentials> | OAuthCredentials;
933
1335
  refresh?(credentials: OAuthCredentials): Promise<OAuthCredentials> | OAuthCredentials;
1336
+ /** Best-effort upstream revocation; the store delete is what fails closed locally. */
1337
+ revoke?(credentials: OAuthCredentials): Promise<void> | void;
934
1338
  getCredential?(credentials: OAuthCredentials): Promise<Credential | undefined> | Credential | undefined;
935
1339
  readonly metadata?: Readonly<Record<string, unknown>>;
936
1340
  }
@@ -1022,7 +1426,80 @@ export interface SessionStore {
1022
1426
  * avoid `list(sessionId)` (full-session scan) + in-memory rebuild. Optional — the
1023
1427
  * built-in memory/JSONL stores omit it and the runtime falls back to `list()`. */
1024
1428
  readBranchPath?(query: SessionBranchRead): Promise<PersistencePage<SessionEntry>>;
1429
+ /**
1430
+ * Optional bounded session search. Prefer implementing this **or** returning a companion
1431
+ * `SessionIndex` from the adapter factory — hosts must not need both. Call
1432
+ * `resolveSessionSearchQuery` before scan/query. Memory defaults to capped linear
1433
+ * search (`sessionSearchMode: "unsupported"` throws). JSONL throws unsupported.
1434
+ */
1435
+ searchSessions?(query: SessionSearchQuery): Promise<PersistencePage<SessionSearchHit>>;
1436
+ }
1437
+ /** Host-written `SessionRecord.metadata` / session metadata key for workspace filtering. */
1438
+ export declare const SESSION_SEARCH_WORKSPACE_METADATA_KEY: "workspaceRoot";
1439
+ export declare const DEFAULT_SESSION_SEARCH_LIMIT = 20;
1440
+ export declare const HARD_MAX_SESSION_SEARCH_LIMIT = 100;
1441
+ export declare const DEFAULT_MAX_SESSION_SEARCH_QUERY_BYTES: number;
1442
+ export declare const HARD_MAX_SESSION_SEARCH_QUERY_BYTES: number;
1443
+ export declare const DEFAULT_MAX_SESSION_SEARCH_SNIPPET_BYTES = 512;
1444
+ export declare const HARD_MAX_SESSION_SEARCH_SNIPPET_BYTES: number;
1445
+ export declare const DEFAULT_MAX_SESSION_SEARCH_CURSOR_BYTES: number;
1446
+ export declare const HARD_MAX_SESSION_SEARCH_CURSOR_BYTES: number;
1447
+ export declare const DEFAULT_MAX_SESSION_SEARCH_LINEAR_SESSIONS = 1000;
1448
+ export declare const HARD_MAX_SESSION_SEARCH_LINEAR_SESSIONS = 5000;
1449
+ export declare const DEFAULT_MAX_SESSION_SEARCH_LINEAR_ENTRIES = 10000;
1450
+ export declare const HARD_MAX_SESSION_SEARCH_LINEAR_ENTRIES = 50000;
1451
+ export declare const DEFAULT_MAX_SESSION_SEARCH_LINEAR_BYTES: number;
1452
+ export declare const HARD_MAX_SESSION_SEARCH_LINEAR_BYTES: number;
1453
+ export declare const DEFAULT_MAX_SESSION_SEARCH_FTS_CANDIDATES = 1000;
1454
+ export declare const HARD_MAX_SESSION_SEARCH_FTS_CANDIDATES = 5000;
1455
+ /** Bounded session search filters. Workspace matches host-written `metadata.workspaceRoot`. */
1456
+ export interface SessionSearchQuery extends PersistenceQuery, OwnershipScope {
1457
+ readonly workspaceRoot?: string;
1458
+ /** Optional full-text / message+summary query (adapter-defined matching). */
1459
+ readonly query?: string;
1460
+ readonly provider?: string;
1461
+ readonly model?: string;
1462
+ readonly label?: string;
1463
+ readonly summary?: string;
1464
+ readonly fromUpdatedAt?: string;
1465
+ readonly toUpdatedAt?: string;
1466
+ readonly signal?: AbortSignal;
1025
1467
  }
1468
+ /**
1469
+ * Safe search hit for resume/checkout. Never includes credentials or raw full transcripts.
1470
+ * `leafId` is the branch tip for `session.checkout` when known.
1471
+ */
1472
+ export interface SessionSearchHit {
1473
+ readonly sessionId: string;
1474
+ readonly leafId?: string;
1475
+ readonly updatedAt?: string;
1476
+ readonly label?: string;
1477
+ readonly summary?: string;
1478
+ readonly snippet?: string;
1479
+ /** Safe display fields only (e.g. workspaceRoot); never credentials. */
1480
+ readonly metadata?: Readonly<Record<string, unknown>>;
1481
+ }
1482
+ /** Narrow search seam; adapters may implement this instead of `SessionStore.searchSessions`. */
1483
+ export interface SessionIndex {
1484
+ search(query: SessionSearchQuery): Promise<PersistencePage<SessionSearchHit>>;
1485
+ }
1486
+ /** Validated search query with finite `limit` / `order` filled in. */
1487
+ export interface ResolvedSessionSearchQuery extends SessionSearchQuery {
1488
+ readonly limit: number;
1489
+ readonly order: "asc" | "desc";
1490
+ }
1491
+ /**
1492
+ * O(1) validation before any scan/query. Applies default page limit; rejects NaN,
1493
+ * non-positive limits, oversize query/cursor/filter strings, and invalid order.
1494
+ */
1495
+ export declare function resolveSessionSearchQuery(query: SessionSearchQuery): ResolvedSessionSearchQuery;
1496
+ export declare const SESSION_SEARCH_UNSUPPORTED_CODE: "session_search_unsupported";
1497
+ /** Thrown when a store opts out of `searchSessions` (memory `unsupported`, JSONL). */
1498
+ export declare class SessionSearchUnsupportedError extends Error {
1499
+ readonly code: "session_search_unsupported";
1500
+ constructor(message?: string);
1501
+ }
1502
+ export declare function isSessionSearchUnsupported(error: unknown): error is SessionSearchUnsupportedError;
1026
1503
  /** Query for a single branch's ancestor chain (DB-friendly: one recursive/ancestor query
1027
1504
  * instead of a full-session scan). Honored by `SessionStore.readBranchPath` and the pure
1028
1505
  * branch helpers' reader overload. `leafId` is optional (omit for the latest leaf). */
@@ -1229,6 +1706,8 @@ export interface AgentEventRecord extends OwnershipScope {
1229
1706
  readonly id: string;
1230
1707
  readonly sessionId: string;
1231
1708
  readonly runId?: string;
1709
+ /** Durable sources allocate positive, strictly increasing per-run positions. */
1710
+ readonly sequence?: number;
1232
1711
  readonly entryId?: string;
1233
1712
  readonly type: AgentEventType;
1234
1713
  readonly timestamp: string;
@@ -1236,6 +1715,58 @@ export interface AgentEventRecord extends OwnershipScope {
1236
1715
  readonly redacted: boolean;
1237
1716
  readonly metadata?: Readonly<Record<string, unknown>>;
1238
1717
  }
1718
+ /** An event record returned by an {@link AgentEventSource}. */
1719
+ export interface DurableAgentEventRecord extends AgentEventRecord {
1720
+ readonly runId: string;
1721
+ readonly sequence: number;
1722
+ }
1723
+ export interface AgentEventEnvelope {
1724
+ readonly record: DurableAgentEventRecord;
1725
+ /** Opaque cursor immediately after `record`. */
1726
+ readonly cursor: string;
1727
+ }
1728
+ export interface AgentEventSourcePage {
1729
+ readonly items: readonly AgentEventEnvelope[];
1730
+ readonly nextCursor?: string;
1731
+ /** True only after every event preceding a terminal event has been returned. */
1732
+ readonly terminal: boolean;
1733
+ }
1734
+ /** Exact-owned, per-run durable event read. `after` is exclusive. */
1735
+ export interface AgentEventSourceRead {
1736
+ readonly ownership: OwnershipScope;
1737
+ readonly sessionId: string;
1738
+ readonly runId: string;
1739
+ readonly after?: string;
1740
+ readonly limit?: number;
1741
+ readonly signal?: AbortSignal;
1742
+ }
1743
+ export interface AgentEventSourceCleanup {
1744
+ readonly ownership: OwnershipScope;
1745
+ readonly before: string;
1746
+ readonly limit?: number;
1747
+ readonly signal?: AbortSignal;
1748
+ }
1749
+ export interface AgentEventSourceOptions {
1750
+ readonly maxEventBytes?: number;
1751
+ readonly maxPageSize?: number;
1752
+ readonly maxCursorBytes?: number;
1753
+ readonly maxQueuedEvents?: number;
1754
+ readonly maxSubscribers?: number;
1755
+ readonly pollIntervalMs?: number;
1756
+ readonly reconnectInitialMs?: number;
1757
+ readonly reconnectMaxMs?: number;
1758
+ readonly maxRetainedEventsPerRun?: number;
1759
+ readonly maxRetentionAgeMs?: number;
1760
+ }
1761
+ /** Optional durable event capability. `RunLedger` remains a write-only contract. */
1762
+ export interface AgentEventSource {
1763
+ append(record: AgentEventRecord): Promise<DurableAgentEventRecord>;
1764
+ page(input: AgentEventSourceRead): Promise<AgentEventSourcePage>;
1765
+ subscribe(input: AgentEventSourceRead): AsyncIterable<AgentEventEnvelope>;
1766
+ cleanup(input: AgentEventSourceCleanup): Promise<{
1767
+ readonly deleted: number;
1768
+ }>;
1769
+ }
1239
1770
  export type ToolCallStatus = "started" | "finished" | "error" | "blocked";
1240
1771
  /** Stored tool-call row. The `result` payload should be redacted before storage when secrets are present. */
1241
1772
  export interface ToolCallRecord extends OwnershipScope {
@@ -1383,16 +1914,21 @@ export interface MigrationRecord {
1383
1914
  }
1384
1915
  /** Query for sessions. */
1385
1916
  export interface SessionQuery extends PersistenceQuery, OwnershipScope {
1917
+ readonly id?: string;
1386
1918
  readonly parentSessionId?: string;
1387
1919
  readonly agentDefinitionId?: string;
1388
1920
  readonly agentDefinitionVersion?: string;
1389
1921
  readonly retentionPolicyId?: string;
1922
+ /** Match sessions whose `metadata` object contains this top-level key (e.g. conversation marker). */
1923
+ readonly metadataKey?: string;
1390
1924
  readonly fromCreatedAt?: string;
1391
1925
  readonly toCreatedAt?: string;
1392
1926
  readonly fromUpdatedAt?: string;
1393
1927
  readonly toUpdatedAt?: string;
1394
1928
  readonly hasExpired?: boolean;
1395
1929
  }
1930
+ /** Validate a top-level `SessionRecord.metadata` key used by `SessionQuery.metadataKey` filters. */
1931
+ export declare function assertSessionMetadataKey(key: string): string;
1396
1932
  /** Query for session entries. */
1397
1933
  export interface SessionEntryQuery extends PersistenceQuery, OwnershipScope {
1398
1934
  readonly sessionId?: string;
@@ -1493,6 +2029,8 @@ export interface ProductionPersistenceStore {
1493
2029
  readonly leases?: LeaseStore;
1494
2030
  /** Optional immutable run/trace feedback storage capability. */
1495
2031
  readonly feedback?: RunFeedbackStore;
2032
+ /** Optional durable, cross-replica-capable event source. */
2033
+ readonly events?: AgentEventSource;
1496
2034
  querySessions(query: SessionQuery): Promise<PersistencePage<SessionRecord>>;
1497
2035
  queryBranches(query: BranchQuery): Promise<PersistencePage<BranchRecord>>;
1498
2036
  queryEntries(query: SessionEntryQuery): Promise<PersistencePage<SessionEntry>>;
@@ -1503,9 +2041,17 @@ export interface ProductionPersistenceStore {
1503
2041
  queryAgentDefinitions(query: AgentDefinitionQuery): Promise<PersistencePage<AgentDefinitionRecord>>;
1504
2042
  queryRetentionPolicies(query: RetentionPolicyQuery): Promise<PersistencePage<RetentionPolicy>>;
1505
2043
  queryMigrations(query: MigrationQuery): Promise<PersistencePage<MigrationRecord>>;
2044
+ /** Optional session-record write capability (conversation threads, host-managed sessions).
2045
+ * Upserts by id; ownership columns are set on create, `metadata`/`updatedAt` on update. */
2046
+ appendSession?(record: SessionRecord): Promise<void>;
1506
2047
  /** DB-friendly branch read (mirrors `SessionStore.readBranchPath`): one ancestor-chain
1507
2048
  * query instead of `queryEntries({ sessionId })` + in-memory walk. Optional. */
1508
2049
  readBranchPath?(query: SessionBranchRead): Promise<PersistencePage<SessionEntry>>;
2050
+ /**
2051
+ * Optional Phase 8 retention / legal-hold / export / tenant-quota lifecycle.
2052
+ * Prefer attaching `createMemoryPersistenceLifecycle()` or adapter-native methods.
2053
+ */
2054
+ readonly lifecycle?: import("./persistence-lifecycle.js").PersistenceLifecycleStore;
1509
2055
  readonly metadata?: Readonly<Record<string, unknown>>;
1510
2056
  }
1511
2057
  export interface CompactionStrategy {
@@ -1635,17 +2181,39 @@ export interface LoopContext {
1635
2181
  /** Maximum independent tool calls dispatched concurrently per provider turn. Default `1`. */
1636
2182
  readonly toolConcurrency: number;
1637
2183
  assemble(nextInput: AgentInput, toolResults?: readonly ToolResult[], turn?: number): Promise<ProviderRequest>;
1638
- /** Charges a complete tool round before any call in it can start. */
1639
- chargeToolRound?(calls: readonly ToolCallContent[]): void;
2184
+ /**
2185
+ * Charges a complete tool round before any call in it can start. On durable interrupt
2186
+ * runs this is also the round-level approval gate: it collects every gated call of the
2187
+ * round into one suspension. Loops must await it; dispatch without it falls back to
2188
+ * per-call single-decision suspensions.
2189
+ */
2190
+ chargeToolRound?(calls: readonly ToolCallContent[]): void | Promise<void>;
1640
2191
  generate(request: ProviderRequest): Promise<ProviderTurnResult>;
1641
2192
  dispatchToolCall(call: ToolCallContent): Promise<ToolResult>;
1642
2193
  isToolCallExclusive?(call: ToolCallContent): boolean;
1643
2194
  appendMessage(message: Message): Promise<void>;
1644
2195
  emit(event: AgentEvent): void;
2196
+ /** True when mid-run steers are queued for the next provider turn. */
2197
+ hasPendingSteers?(): boolean;
2198
+ /** Drain pending steers into history/session. Returns true when any were applied. */
2199
+ applyPendingSteers?(): Promise<boolean>;
2200
+ /** Snapshot captured at the last suspension when the strategy declared snapshot/restore. Present only on resume. */
2201
+ readonly restoredLoopState?: JsonValue;
1645
2202
  }
1646
2203
  export interface AgentLoopStrategy {
1647
2204
  readonly name: string;
2205
+ /** Host-authored loop revision. Joins the durable-run fingerprint when snapshot hooks are present. */
2206
+ readonly revision?: string;
1648
2207
  run(ctx: LoopContext): Promise<Usage | undefined>;
2208
+ /**
2209
+ * Capture loop-local resumable state at suspension. Must return a JSON-compatible value;
2210
+ * core bounds and redacts it inside the durable run-state envelope. Declare together with
2211
+ * `restore`; a custom strategy without both hooks is rejected before any provider call on
2212
+ * durable runs (`AgentLoopStateError` / `ERR_PRISM_LOOP_NOT_DURABLE`).
2213
+ */
2214
+ snapshot?(): JsonValue;
2215
+ /** Rehydrate from a previously captured snapshot; must throw on drift. Called before `run` on resume. */
2216
+ restore?(snapshot: JsonValue): void;
1649
2217
  }
1650
2218
  export type AgentLoopOptions = {
1651
2219
  readonly strategy: "single-shot";
@@ -1663,6 +2231,12 @@ export type AgentLoopOptions = {
1663
2231
  readonly structuredOutput?: StructuredOutputOptions;
1664
2232
  /** `native` maps schema to capable providers; `artifact-loop` keeps repair turns only. */
1665
2233
  readonly structuredOutputMode?: "native" | "artifact-loop";
2234
+ /**
2235
+ * When to attach native `structuredOutput` under `toolCalls: "bounded"`.
2236
+ * `every-turn` (default): schema on every provider request (legacy).
2237
+ * `final-turn-only`: tool-eligible turns omit schema; artifact/revision turns send schema and withdraw tools.
2238
+ */
2239
+ readonly structuredOutputTiming?: "every-turn" | "final-turn-only";
1666
2240
  };
1667
2241
  export interface ArtifactValidation {
1668
2242
  readonly ok: boolean;
@@ -1687,3 +2261,11 @@ export interface ArtifactParseResult<T> {
1687
2261
  export type ArtifactParser<T> = (text: string, ctx: ArtifactContext) => ArtifactParseResult<T> | Promise<ArtifactParseResult<T>>;
1688
2262
  export type ArtifactValidator<T> = (value: T, ctx: ArtifactContext) => ArtifactValidation | Promise<ArtifactValidation>;
1689
2263
  export type ArtifactRepairer<T> = (value: T | undefined, failure: ArtifactValidation, ctx: ArtifactContext) => AgentInput | Promise<AgentInput>;
2264
+ /** Alias re-exports so `dist/contracts.d.ts` exposes implementer contract names. */
2265
+ export type AgentIdentity = import("./identity.js").AgentIdentity;
2266
+ export type Principal = import("./identity.js").Principal;
2267
+ export type IdentityVerifier = import("./identity.js").IdentityVerifier;
2268
+ export type PersistenceLifecycleStore = import("./persistence-lifecycle.js").PersistenceLifecycleStore;
2269
+ export type LegalHoldRecord = import("./persistence-lifecycle.js").LegalHoldRecord;
2270
+ export type TenantQuota = import("./persistence-lifecycle.js").TenantQuota;
2271
+ export type PersistenceResourceKind = import("./persistence-lifecycle.js").PersistenceResourceKind;