@arnilo/prism 0.1.3 → 0.1.5

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 (43) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/agent-approval.d.ts +49 -0
  3. package/dist/agent-approval.js +178 -0
  4. package/dist/agent-run-lifecycle.d.ts +5 -1
  5. package/dist/agent-run-lifecycle.js +211 -3
  6. package/dist/agent-session.d.ts +98 -0
  7. package/dist/agent-session.js +1811 -0
  8. package/dist/agent-tool-dispatch.d.ts +13 -0
  9. package/dist/agent-tool-dispatch.js +92 -0
  10. package/dist/agents.d.ts +16 -9
  11. package/dist/agents.js +14 -2267
  12. package/dist/cli-init.d.ts +0 -2
  13. package/dist/cli-init.js +0 -2
  14. package/dist/cli-runner.js +1 -1
  15. package/dist/contracts-core.d.ts +1396 -0
  16. package/dist/contracts-core.js +119 -0
  17. package/dist/contracts-protocol.d.ts +594 -0
  18. package/dist/contracts-protocol.js +2 -0
  19. package/dist/contracts-run-state.d.ts +285 -0
  20. package/dist/contracts-run-state.js +77 -0
  21. package/dist/contracts.d.ts +7 -2269
  22. package/dist/contracts.js +7 -192
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +1 -1
  25. package/dist/rpc.js +2 -1
  26. package/docs/agent-loops.md +1 -1
  27. package/docs/agent-session-runtime.md +4 -2
  28. package/docs/browser-automation.md +13 -9
  29. package/docs/coding-agent-tools.md +1 -2
  30. package/docs/compaction-observational-memory.md +5 -6
  31. package/docs/index.md +4 -4
  32. package/docs/migration.md +114 -1
  33. package/docs/performance.md +10 -0
  34. package/docs/provider-conformance.md +2 -2
  35. package/docs/provider-layer.md +1 -1
  36. package/docs/provider-packages.md +1 -1
  37. package/docs/provider-primitives.md +1 -1
  38. package/docs/public-contracts.md +4 -2
  39. package/docs/release-and-install.md +64 -0
  40. package/docs/tool-execution-primitives.md +3 -3
  41. package/docs/tools.md +2 -2
  42. package/docs/use-case-model-selection.md +12 -11
  43. package/package.json +2 -2
@@ -0,0 +1,594 @@
1
+ import type { AgentLoopOptions, AgentLoopStrategy, ArtifactValidation, CompactionOptions, ContentBlock, ErrorInfo, GuardrailRecord, Guardrails, InstructionInjector, JsonObject, Message, ModelConfig, OwnershipScope, ProviderRequestPolicy, ProviderResolver, RetryOptions, RunLimitBreach, RunLimits, Skill, SubscriberOverflowPolicy, SystemPromptConfig, ToolCallAuthority, ToolCallContent, Usage } from "./contracts-core.js";
2
+ import type { AgentRunInterruption, AgentRunStateOptions } from "./contracts-run-state.js";
3
+ import type { ProviderRequestOptions } from "./contracts-core.js";
4
+ import type { SecretRedactor } from "./redaction.js";
5
+ import type { ToolValidator } from "./tools.js";
6
+ export type ProviderEvent = {
7
+ readonly type: "message_start";
8
+ readonly messageId?: string;
9
+ } | {
10
+ readonly type: "content_delta";
11
+ readonly content: ContentBlock;
12
+ } | {
13
+ readonly type: "tool_call_delta";
14
+ readonly index: number;
15
+ readonly id?: string;
16
+ readonly name?: string;
17
+ readonly argumentsText?: string;
18
+ readonly authority?: ToolCallAuthority;
19
+ } | {
20
+ readonly type: "tool_call";
21
+ readonly call: ToolCallContent;
22
+ } | {
23
+ readonly type: "usage";
24
+ readonly usage: Usage;
25
+ } | {
26
+ readonly type: "continuation_required";
27
+ readonly cursor: string;
28
+ readonly reason?: string;
29
+ } | {
30
+ readonly type: "done";
31
+ readonly usage?: Usage;
32
+ } | {
33
+ readonly type: "error";
34
+ readonly error: ErrorInfo;
35
+ };
36
+ export type RealtimeEvent = {
37
+ readonly type: "session_started";
38
+ readonly sessionId?: string;
39
+ } | {
40
+ readonly type: "audio_delta";
41
+ readonly audio: Uint8Array;
42
+ } | {
43
+ readonly type: "transcript_delta";
44
+ readonly text: string;
45
+ readonly role: "user" | "assistant";
46
+ } | {
47
+ readonly type: "tool_call";
48
+ readonly call: ToolCallContent;
49
+ } | {
50
+ readonly type: "interrupted";
51
+ } | {
52
+ readonly type: "session_closed";
53
+ readonly reason?: string;
54
+ } | {
55
+ readonly type: "error";
56
+ readonly error: ErrorInfo;
57
+ };
58
+ /** Neutral bidirectional realtime session seam. The provider owns the transport
59
+ * (e.g. WebSocket); the host owns audio capture/playback and session lifecycle. */
60
+ export type InputAssemblyLayout = "legacy" | "cache_aware";
61
+ export interface RunOptions {
62
+ readonly signal?: AbortSignal;
63
+ readonly model?: ModelConfig;
64
+ readonly providerSource?: ProviderResolver;
65
+ /** Run-scoped ceilings. When an agent config also sets limits, these can only narrow it. */
66
+ readonly limits?: RunLimits;
67
+ readonly providerOptions?: ProviderRequestOptions;
68
+ readonly providerRequestPolicies?: ProviderRequestPolicy | readonly ProviderRequestPolicy[];
69
+ readonly systemPrompt?: SystemPromptConfig;
70
+ readonly compaction?: false | CompactionOptions;
71
+ readonly retry?: false | RetryOptions;
72
+ readonly metadata?: Readonly<Record<string, unknown>>;
73
+ readonly redactor?: SecretRedactor;
74
+ readonly runLedger?: RunLedger;
75
+ /** Optional durable recovery store. Per-run value overrides this agent default. */
76
+ readonly effectStore?: ToolEffectStore;
77
+ readonly ownership?: OwnershipScope;
78
+ /** Host-verified identity; when set, must project onto `ownership` without widening. */
79
+ readonly identity?: import("./identity.js").AgentIdentity;
80
+ readonly idempotencyKey?: string;
81
+ readonly validate?: ToolValidator;
82
+ readonly activeSkills?: readonly string[];
83
+ readonly skills?: readonly Skill[];
84
+ /** Migration opt-in: activate every skill in a configured `SkillRegistry` when `activeSkills` / `skills` are unset. */
85
+ readonly activateAllSkills?: true;
86
+ /** Progressive: catalog (name+description) unless loaded; eager: full instructions every turn. Default progressive. */
87
+ readonly skillsDisclosure?: import("./skill-disclosure.js").SkillsDisclosure;
88
+ /** Opt-in projection-only fold for aged large tool results in provider view; store untouched. */
89
+ readonly toolResultFold?: import("./tool-result-fold.js").ToolResultFoldOptions;
90
+ readonly instructionInjectors?: readonly InstructionInjector[];
91
+ readonly inputLayout?: InputAssemblyLayout;
92
+ readonly loop?: AgentLoopStrategy | AgentLoopOptions;
93
+ /** Appended to agent-level guardrails for this run. */
94
+ readonly guardrails?: Guardrails;
95
+ /** Opt-in durable interruption/checkpointing. */
96
+ readonly runState?: AgentRunStateOptions;
97
+ }
98
+ export interface ProviderTurnMetadata {
99
+ readonly providerId: string;
100
+ readonly model: ModelConfig;
101
+ readonly requestId?: string;
102
+ readonly latencyMs?: number;
103
+ readonly attempt?: number;
104
+ readonly httpStatus?: number;
105
+ readonly rateLimitRemaining?: number;
106
+ readonly rateLimitResetMs?: number;
107
+ }
108
+ export interface ToolExecutionMetadata {
109
+ readonly durationMs: number;
110
+ readonly status: ToolCallStatus;
111
+ }
112
+ export type AgentEvent = {
113
+ readonly type: "agent_started";
114
+ readonly sessionId: string;
115
+ readonly runId: string;
116
+ } | {
117
+ readonly type: "agent_finished";
118
+ readonly sessionId: string;
119
+ readonly runId: string;
120
+ readonly usage?: Usage;
121
+ } | {
122
+ readonly type: "agent_suspended";
123
+ readonly sessionId: string;
124
+ readonly runId: string;
125
+ readonly interruption: AgentRunInterruption;
126
+ readonly version: number;
127
+ } | {
128
+ readonly type: "agent_resumed";
129
+ readonly sessionId: string;
130
+ readonly runId: string;
131
+ readonly version: number;
132
+ } | {
133
+ readonly type: "agent_denied";
134
+ readonly sessionId: string;
135
+ readonly runId: string;
136
+ readonly interruption: AgentRunInterruption;
137
+ readonly version: number;
138
+ } | {
139
+ readonly type: "turn_started";
140
+ readonly sessionId: string;
141
+ readonly runId: string;
142
+ readonly turn: number;
143
+ } | {
144
+ readonly type: "turn_finished";
145
+ readonly sessionId: string;
146
+ readonly runId: string;
147
+ readonly turn: number;
148
+ } | {
149
+ readonly type: "provider_turn_started";
150
+ readonly sessionId: string;
151
+ readonly runId: string;
152
+ readonly turn: number;
153
+ readonly metadata: ProviderTurnMetadata;
154
+ } | {
155
+ readonly type: "provider_turn_finished";
156
+ readonly sessionId: string;
157
+ readonly runId: string;
158
+ readonly turn: number;
159
+ readonly metadata: ProviderTurnMetadata;
160
+ readonly usage?: Usage;
161
+ readonly error?: ErrorInfo;
162
+ } | {
163
+ readonly type: "message_started";
164
+ readonly sessionId: string;
165
+ readonly runId: string;
166
+ readonly message: Message;
167
+ } | {
168
+ readonly type: "message_delta";
169
+ readonly sessionId: string;
170
+ readonly runId: string;
171
+ readonly content: ContentBlock;
172
+ } | {
173
+ readonly type: "message_finished";
174
+ readonly sessionId: string;
175
+ readonly runId: string;
176
+ readonly message: Message;
177
+ } | {
178
+ readonly type: "tool_execution_started";
179
+ readonly sessionId: string;
180
+ readonly runId: string;
181
+ readonly call: ToolCallContent;
182
+ } | {
183
+ readonly type: "tool_execution_progress";
184
+ readonly sessionId: string;
185
+ readonly runId: string;
186
+ readonly toolCallId: string;
187
+ readonly name: string;
188
+ readonly progress?: unknown;
189
+ readonly metadata?: Readonly<Record<string, unknown>>;
190
+ } | {
191
+ readonly type: "tool_execution_finished";
192
+ readonly sessionId: string;
193
+ readonly runId: string;
194
+ readonly result: ToolResult;
195
+ readonly metadata: ToolExecutionMetadata;
196
+ } | {
197
+ readonly type: "tool_execution_error";
198
+ readonly sessionId: string;
199
+ readonly runId: string;
200
+ readonly call: ToolCallContent;
201
+ readonly error: ErrorInfo;
202
+ readonly metadata: ToolExecutionMetadata;
203
+ } | {
204
+ readonly type: "tool_execution_blocked";
205
+ readonly sessionId: string;
206
+ readonly runId: string;
207
+ readonly toolCallId: string;
208
+ readonly name: string;
209
+ readonly reason: string;
210
+ readonly error: ErrorInfo;
211
+ readonly metadata: ToolExecutionMetadata;
212
+ } | {
213
+ readonly type: "guardrail_decision";
214
+ readonly sessionId: string;
215
+ readonly runId: string;
216
+ readonly toolCallId?: string;
217
+ readonly toolName?: string;
218
+ readonly record: GuardrailRecord;
219
+ } | {
220
+ readonly type: "run_limit_exceeded";
221
+ readonly sessionId: string;
222
+ readonly runId: string;
223
+ readonly breach: RunLimitBreach;
224
+ } | {
225
+ readonly type: "queue_updated";
226
+ readonly sessionId: string;
227
+ readonly runId: string;
228
+ readonly size: number;
229
+ } | {
230
+ /** A steered message was dropped by a terminal input guardrail; the run continues without it. */
231
+ readonly type: "steer_rejected";
232
+ readonly sessionId: string;
233
+ readonly runId: string;
234
+ readonly message: Message;
235
+ readonly record: GuardrailRecord;
236
+ } | {
237
+ readonly type: "event_subscriber_overflow";
238
+ readonly sessionId: string;
239
+ readonly runId?: string;
240
+ readonly droppedEvents: number;
241
+ readonly maxQueuedEvents: number;
242
+ readonly overflow: SubscriberOverflowPolicy;
243
+ } | {
244
+ readonly type: "compaction_started";
245
+ readonly sessionId: string;
246
+ readonly runId?: string;
247
+ } | {
248
+ readonly type: "compaction_finished";
249
+ readonly sessionId: string;
250
+ readonly runId?: string;
251
+ readonly summary: string;
252
+ } | {
253
+ readonly type: "retry_scheduled";
254
+ readonly sessionId: string;
255
+ readonly runId: string;
256
+ readonly attempt: number;
257
+ readonly delayMs: number;
258
+ readonly error: ErrorInfo;
259
+ } | {
260
+ readonly type: "error";
261
+ readonly sessionId?: string;
262
+ readonly runId?: string;
263
+ readonly error: ErrorInfo;
264
+ } | {
265
+ readonly type: "artifact_validation_started";
266
+ readonly sessionId: string;
267
+ readonly runId: string;
268
+ readonly turn: number;
269
+ readonly attempt: number;
270
+ } | {
271
+ readonly type: "artifact_validation_finished";
272
+ readonly sessionId: string;
273
+ readonly runId: string;
274
+ readonly turn: number;
275
+ readonly attempt: number;
276
+ readonly result: ArtifactValidation;
277
+ } | {
278
+ readonly type: "artifact_revision_started";
279
+ readonly sessionId: string;
280
+ readonly runId: string;
281
+ readonly turn: number;
282
+ readonly attempt: number;
283
+ readonly failure: ArtifactValidation;
284
+ } | {
285
+ readonly type: "artifact_finished";
286
+ readonly sessionId: string;
287
+ readonly runId: string;
288
+ readonly turn: number;
289
+ readonly attempt: number;
290
+ readonly result: ArtifactValidation;
291
+ } | {
292
+ readonly type: "artifact_failed";
293
+ readonly sessionId: string;
294
+ readonly runId: string;
295
+ readonly turn: number;
296
+ readonly attempt: number;
297
+ readonly result: ArtifactValidation;
298
+ };
299
+ export type ToolEffectKind = "none" | "local_mutation" | "external_mutation";
300
+ export type ToolEffectIdempotency = "none" | "optional" | "required" | "tool_managed" | "unsupported";
301
+ /** Static or validated-argument classification of one tool call's side-effect behavior. */
302
+ export interface ToolEffectDeclaration {
303
+ readonly kind: ToolEffectKind;
304
+ readonly idempotency: ToolEffectIdempotency;
305
+ }
306
+ /** Runs after argument validation. It must be synchronous, deterministic, bounded, and side-effect-free. */
307
+ export type ToolEffectClassifier = (args: JsonObject, context: ToolExecutionContext) => ToolEffectDeclaration;
308
+ /**
309
+ * Elicitation contract declared by a tool. When a durable gated run suspends on this tool,
310
+ * the pending decision has kind `elicitation` and carries this schema as its payload contract;
311
+ * the resume decision's `elicitation` payload resolves the call without executing it.
312
+ */
313
+ export interface ToolElicitationRequest {
314
+ /** Typed payload contract; bounded to HARD_MAX_ELICITATION_BYTES when serialized. */
315
+ readonly schema: JsonObject;
316
+ /** Human-facing reason (e.g. the question); bounded to MAX_DECISION_REASON_BYTES. */
317
+ readonly reason?: string;
318
+ /** Answer-shape validation beyond structural schema checks; throw to reject the payload. */
319
+ readonly validate?: (payload: JsonObject) => void;
320
+ }
321
+ export interface ToolDefinition {
322
+ readonly name: string;
323
+ readonly description?: string;
324
+ readonly parameters?: JsonObject;
325
+ /** Force any provider turn containing this tool to dispatch sequentially. */
326
+ readonly exclusive?: boolean;
327
+ /** Optional side-effect declaration. Omitted tools retain legacy unmanaged dispatch. */
328
+ readonly effect?: ToolEffectDeclaration | ToolEffectClassifier;
329
+ /** Optional elicitation contract for durable gating; return undefined to fall back to plain tool approval. */
330
+ readonly elicitation?: (args: JsonObject, context: ToolExecutionContext) => ToolElicitationRequest | undefined;
331
+ execute(args: JsonObject, context: ToolExecutionContext): Promise<ToolResult> | ToolResult;
332
+ }
333
+ export interface ToolRegistry {
334
+ register(tool: ToolDefinition): void;
335
+ get(name: string): ToolDefinition | undefined;
336
+ resolve(name: string): ToolDefinition;
337
+ list(): readonly ToolDefinition[];
338
+ }
339
+ export interface ToolExecutionContext {
340
+ readonly sessionId: string;
341
+ readonly runId: string;
342
+ readonly toolCallId: string;
343
+ readonly signal?: AbortSignal;
344
+ readonly metadata?: Readonly<Record<string, unknown>>;
345
+ /** Host-verified identity for this tool invocation, when enterprise identity is active. */
346
+ readonly identity?: import("./identity.js").AgentIdentity;
347
+ /** Core-derived stable effect key. Never accept a model-supplied key as authority. */
348
+ readonly idempotencyKey?: string;
349
+ progress?(progress?: unknown, metadata?: Readonly<Record<string, unknown>>): void | Promise<void>;
350
+ }
351
+ export interface ToolResult {
352
+ readonly toolCallId: string;
353
+ readonly name: string;
354
+ readonly content?: readonly ContentBlock[];
355
+ readonly value?: unknown;
356
+ readonly error?: ErrorInfo;
357
+ readonly metadata?: Readonly<Record<string, unknown>>;
358
+ }
359
+ export type ToolEffectStatus = "pending" | "dispatched" | "completed" | "failed_retryable" | "failed_terminal" | "unknown";
360
+ export interface ToolEffectRecord extends OwnershipScope {
361
+ readonly key: string;
362
+ readonly sessionId: string;
363
+ readonly runId: string;
364
+ readonly toolCallId: string;
365
+ readonly toolName: string;
366
+ readonly argumentsHash: string;
367
+ readonly status: ToolEffectStatus;
368
+ readonly attempt: number;
369
+ readonly version: number;
370
+ readonly claimToken?: string;
371
+ readonly result?: ToolResult;
372
+ readonly resultRef?: string;
373
+ readonly failure?: {
374
+ readonly code: string;
375
+ readonly reference?: string;
376
+ };
377
+ readonly createdAt: string;
378
+ readonly updatedAt: string;
379
+ readonly expiresAt?: string;
380
+ }
381
+ export interface ToolEffectKey {
382
+ readonly identity: import("./identity.js").AgentIdentity;
383
+ readonly ownership: OwnershipScope;
384
+ readonly key: string;
385
+ readonly sessionId: string;
386
+ readonly runId: string;
387
+ readonly toolCallId: string;
388
+ readonly toolName: string;
389
+ readonly argumentsHash: string;
390
+ readonly signal?: AbortSignal;
391
+ }
392
+ export interface ToolEffectTransition extends ToolEffectKey {
393
+ readonly claimToken: string;
394
+ readonly expectedVersion: number;
395
+ }
396
+ /** Durable claim/CAS store for recoverable tool effects. */
397
+ export interface ToolEffectStore {
398
+ get(input: ToolEffectKey): Promise<ToolEffectRecord | undefined>;
399
+ begin(input: ToolEffectKey & {
400
+ readonly claimTtlMs?: number;
401
+ readonly maxAttempts?: number;
402
+ }): Promise<{
403
+ readonly outcome: "acquired" | "existing";
404
+ readonly record: ToolEffectRecord;
405
+ }>;
406
+ markDispatched(input: ToolEffectTransition): Promise<ToolEffectRecord>;
407
+ complete(input: ToolEffectTransition & {
408
+ readonly result?: ToolResult;
409
+ readonly resultRef?: string;
410
+ }): Promise<ToolEffectRecord>;
411
+ fail(input: ToolEffectTransition & {
412
+ readonly status: "failed_retryable" | "failed_terminal";
413
+ readonly failure: {
414
+ readonly code: string;
415
+ readonly reference?: string;
416
+ };
417
+ }): Promise<ToolEffectRecord>;
418
+ markUnknown(input: ToolEffectTransition & {
419
+ readonly failure?: {
420
+ readonly code: string;
421
+ readonly reference?: string;
422
+ };
423
+ }): Promise<ToolEffectRecord>;
424
+ resolveUnknown(input: ToolEffectKey & {
425
+ readonly expectedVersion: number;
426
+ readonly status: "completed" | "failed_retryable" | "failed_terminal";
427
+ readonly result?: ToolResult;
428
+ readonly resultRef?: string;
429
+ readonly failure?: {
430
+ readonly code: string;
431
+ readonly reference?: string;
432
+ };
433
+ }): Promise<ToolEffectRecord>;
434
+ cleanup(input: {
435
+ readonly ownership: OwnershipScope;
436
+ readonly before: string;
437
+ readonly limit?: number;
438
+ readonly signal?: AbortSignal;
439
+ }): Promise<{
440
+ readonly deleted: number;
441
+ }>;
442
+ }
443
+ export type RunStatus = "queued" | "running" | "suspended" | "denied" | "succeeded" | "failed" | "aborted";
444
+ /** Stored run record. */
445
+ export interface RunRecord extends OwnershipScope {
446
+ readonly id: string;
447
+ readonly sessionId: string;
448
+ readonly branchId?: string;
449
+ readonly agentDefinitionId?: string;
450
+ readonly agentDefinitionVersion?: string;
451
+ readonly model?: ModelConfig;
452
+ readonly provider?: string;
453
+ readonly idempotencyKey?: string;
454
+ readonly status?: RunStatus;
455
+ readonly startedAt: string;
456
+ readonly finishedAt?: string;
457
+ readonly abortReason?: string;
458
+ readonly error?: ErrorInfo;
459
+ readonly metadata?: Readonly<Record<string, unknown>>;
460
+ }
461
+ export type AgentEventType = AgentEvent["type"];
462
+ /** Stored agent event ledger row. The `event` payload should be redacted before storage when secrets are present. */
463
+ export interface AgentEventRecord extends OwnershipScope {
464
+ readonly id: string;
465
+ readonly sessionId: string;
466
+ readonly runId?: string;
467
+ /** Durable sources allocate positive, strictly increasing per-run positions. */
468
+ readonly sequence?: number;
469
+ readonly entryId?: string;
470
+ readonly type: AgentEventType;
471
+ readonly timestamp: string;
472
+ readonly event: AgentEvent;
473
+ readonly redacted: boolean;
474
+ readonly metadata?: Readonly<Record<string, unknown>>;
475
+ }
476
+ /** An event record returned by an {@link AgentEventSource}. */
477
+ export interface DurableAgentEventRecord extends AgentEventRecord {
478
+ readonly runId: string;
479
+ readonly sequence: number;
480
+ }
481
+ export interface AgentEventEnvelope {
482
+ readonly record: DurableAgentEventRecord;
483
+ /** Opaque cursor immediately after `record`. */
484
+ readonly cursor: string;
485
+ }
486
+ export interface AgentEventSourcePage {
487
+ readonly items: readonly AgentEventEnvelope[];
488
+ readonly nextCursor?: string;
489
+ /** True only after every event preceding a terminal event has been returned. */
490
+ readonly terminal: boolean;
491
+ }
492
+ /** Exact-owned, per-run durable event read. `after` is exclusive. */
493
+ export interface AgentEventSourceRead {
494
+ readonly ownership: OwnershipScope;
495
+ readonly sessionId: string;
496
+ readonly runId: string;
497
+ readonly after?: string;
498
+ readonly limit?: number;
499
+ readonly signal?: AbortSignal;
500
+ }
501
+ export interface AgentEventSourceCleanup {
502
+ readonly ownership: OwnershipScope;
503
+ readonly before: string;
504
+ readonly limit?: number;
505
+ readonly signal?: AbortSignal;
506
+ }
507
+ export interface AgentEventSourceOptions {
508
+ readonly maxEventBytes?: number;
509
+ readonly maxPageSize?: number;
510
+ readonly maxCursorBytes?: number;
511
+ readonly maxQueuedEvents?: number;
512
+ readonly maxSubscribers?: number;
513
+ readonly pollIntervalMs?: number;
514
+ readonly reconnectInitialMs?: number;
515
+ readonly reconnectMaxMs?: number;
516
+ readonly maxRetainedEventsPerRun?: number;
517
+ readonly maxRetentionAgeMs?: number;
518
+ }
519
+ /** Optional durable event capability. `RunLedger` remains a write-only contract. */
520
+ export interface AgentEventSource {
521
+ append(record: AgentEventRecord): Promise<DurableAgentEventRecord>;
522
+ page(input: AgentEventSourceRead): Promise<AgentEventSourcePage>;
523
+ subscribe(input: AgentEventSourceRead): AsyncIterable<AgentEventEnvelope>;
524
+ cleanup(input: AgentEventSourceCleanup): Promise<{
525
+ readonly deleted: number;
526
+ }>;
527
+ }
528
+ export type ToolCallStatus = "started" | "finished" | "error" | "blocked";
529
+ /** Stored tool-call row. The `result` payload should be redacted before storage when secrets are present. */
530
+ export interface ToolCallRecord extends OwnershipScope {
531
+ readonly id: string;
532
+ readonly sessionId: string;
533
+ readonly runId?: string;
534
+ readonly entryId?: string;
535
+ readonly toolCallId: string;
536
+ readonly name: string;
537
+ readonly arguments: JsonObject;
538
+ readonly result?: ToolResult;
539
+ readonly status?: ToolCallStatus;
540
+ readonly reason?: string;
541
+ readonly progress?: unknown;
542
+ readonly progressMetadata?: Readonly<Record<string, unknown>>;
543
+ readonly progressAt?: string;
544
+ readonly startedAt: string;
545
+ readonly finishedAt?: string;
546
+ readonly redacted: boolean;
547
+ readonly metadata?: Readonly<Record<string, unknown>>;
548
+ }
549
+ export type UsageScope = "provider_turn" | "run_total";
550
+ /** Stored usage row. `scope` prevents provider-turn and aggregate totals from being summed together. */
551
+ export interface UsageRecord extends OwnershipScope {
552
+ readonly id: string;
553
+ readonly sessionId: string;
554
+ readonly runId?: string;
555
+ readonly entryId?: string;
556
+ readonly scope: UsageScope;
557
+ readonly turn?: number;
558
+ readonly attempt?: number;
559
+ readonly usage: Usage;
560
+ readonly recordedAt: string;
561
+ readonly metadata?: Readonly<Record<string, unknown>>;
562
+ }
563
+ /** Host-implemented write-side ledger for runs, events, tool calls, and usage. */
564
+ export interface RunLedger {
565
+ appendRun(record: RunRecord): Promise<void> | void;
566
+ appendEvent(record: AgentEventRecord): Promise<void> | void;
567
+ appendToolCall(record: ToolCallRecord): Promise<void> | void;
568
+ appendUsage(record: UsageRecord): Promise<void> | void;
569
+ }
570
+ /** Union of records that may be handed to a {@link RunLedger}. */
571
+ export type RunLedgerRecord = RunRecord | AgentEventRecord | ToolCallRecord | UsageRecord;
572
+ export type RunLedgerDurability = "write_through" | "flush_on_terminal" | "buffered";
573
+ export interface RunLedgerFlushResult {
574
+ readonly accepted: number;
575
+ readonly flushed: number;
576
+ readonly buffered: number;
577
+ }
578
+ /** Optional durability seam implemented by bounded ledger adapters. */
579
+ export interface FlushableRunLedger extends RunLedger {
580
+ readonly durability: RunLedgerDurability;
581
+ flush(): Promise<RunLedgerFlushResult>;
582
+ status(): RunLedgerFlushResult;
583
+ dispose(options?: {
584
+ readonly flush?: boolean;
585
+ }): Promise<void>;
586
+ }
587
+ /** Immutable human feedback linked to an existing owned run/trace and optional evaluations. */
588
+ export interface ProviderTurnResult {
589
+ readonly content: readonly ContentBlock[];
590
+ readonly calls: readonly ToolCallContent[];
591
+ readonly messageId?: string;
592
+ readonly started: boolean;
593
+ readonly usage?: Usage;
594
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=contracts-protocol.js.map