@arnilo/prism 0.2.4 → 0.2.6

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 (51) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/agent-session/create-agent.d.ts +6 -0
  3. package/dist/agent-session/create-agent.js +13 -0
  4. package/dist/agent-session/event-subscriber.d.ts +17 -0
  5. package/dist/agent-session/event-subscriber.js +68 -0
  6. package/dist/agent-session/helpers.d.ts +44 -0
  7. package/dist/agent-session/helpers.js +194 -0
  8. package/dist/agent-session/session.d.ts +101 -0
  9. package/dist/agent-session/session.js +1568 -0
  10. package/dist/agent-session.d.ts +6 -105
  11. package/dist/agent-session.js +6 -1833
  12. package/dist/contracts-core/agent.d.ts +257 -0
  13. package/dist/contracts-core/agent.js +5 -0
  14. package/dist/contracts-core/compaction.d.ts +72 -0
  15. package/dist/contracts-core/compaction.js +2 -0
  16. package/dist/contracts-core/content.d.ts +116 -0
  17. package/dist/contracts-core/content.js +2 -0
  18. package/dist/contracts-core/extensions.d.ts +163 -0
  19. package/dist/contracts-core/extensions.js +2 -0
  20. package/dist/contracts-core/loop.d.ts +98 -0
  21. package/dist/contracts-core/loop.js +2 -0
  22. package/dist/contracts-core/persistence.d.ts +366 -0
  23. package/dist/contracts-core/persistence.js +9 -0
  24. package/dist/contracts-core/provider.d.ts +97 -0
  25. package/dist/contracts-core/provider.js +2 -0
  26. package/dist/contracts-core/resources.d.ts +44 -0
  27. package/dist/contracts-core/resources.js +7 -0
  28. package/dist/contracts-core/run-limits.d.ts +81 -0
  29. package/dist/contracts-core/run-limits.js +2 -0
  30. package/dist/contracts-core/session.d.ts +187 -0
  31. package/dist/contracts-core/session.js +131 -0
  32. package/dist/contracts-core.d.ts +13 -1425
  33. package/dist/contracts-core.js +10 -138
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +1 -1
  36. package/docs/0.1.0-readiness.md +10 -10
  37. package/docs/acp.md +2 -0
  38. package/docs/browser-automation.md +1 -1
  39. package/docs/coding-agent-tools.md +5 -4
  40. package/docs/coding-review-and-diagnostics.md +76 -0
  41. package/docs/coding-security.md +2 -0
  42. package/docs/coding-workspaces.md +69 -0
  43. package/docs/forge-integration.md +6 -0
  44. package/docs/index.md +5 -5
  45. package/docs/indexed-code-search.md +82 -0
  46. package/docs/language-intelligence.md +15 -0
  47. package/docs/migration.md +20 -0
  48. package/docs/process-sessions.md +58 -3
  49. package/docs/release-and-install.md +71 -3
  50. package/docs/work-artifacts-and-review.md +4 -0
  51. package/package.json +2 -2
@@ -0,0 +1,98 @@
1
+ /** Contracts-core loop family (0.2.5 plan 025 Task 1 split).
2
+ * Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
3
+ import type { AgentEvent, ProviderTurnResult, ToolResult } from "../contracts-protocol.js";
4
+ import type { AgentInput } from "../input.js";
5
+ import type { JsonValue, Message, ToolCallContent, Usage } from "./content.js";
6
+ import type { ProviderRequest, StructuredOutputOptions } from "./provider.js";
7
+ export interface LoopContext {
8
+ readonly sessionId: string;
9
+ readonly runId: string;
10
+ readonly metadata: Readonly<Record<string, unknown>>;
11
+ readonly signal: AbortSignal;
12
+ readonly history: Message[];
13
+ readonly input: AgentInput;
14
+ readonly inputMessages: readonly Message[];
15
+ readonly maxToolRounds: number;
16
+ /** Maximum independent tool calls dispatched concurrently per provider turn. Default `1`. */
17
+ readonly toolConcurrency: number;
18
+ assemble(nextInput: AgentInput, toolResults?: readonly ToolResult[], turn?: number): Promise<ProviderRequest>;
19
+ /**
20
+ * Charges a complete tool round before any call in it can start. On durable interrupt
21
+ * runs this is also the round-level approval gate: it collects every gated call of the
22
+ * round into one suspension. Loops must await it; dispatch without it falls back to
23
+ * per-call single-decision suspensions.
24
+ */
25
+ chargeToolRound?(calls: readonly ToolCallContent[]): void | Promise<void>;
26
+ generate(request: ProviderRequest): Promise<ProviderTurnResult>;
27
+ dispatchToolCall(call: ToolCallContent): Promise<ToolResult>;
28
+ isToolCallExclusive?(call: ToolCallContent): boolean;
29
+ appendMessage(message: Message): Promise<void>;
30
+ emit(event: AgentEvent): void;
31
+ /** True when mid-run steers are queued for the next provider turn. */
32
+ hasPendingSteers?(): boolean;
33
+ /** Drain pending steers into history/session. Returns true when any were applied. */
34
+ applyPendingSteers?(): Promise<boolean>;
35
+ /** Snapshot captured at the last suspension when the strategy declared snapshot/restore. Present only on resume. */
36
+ readonly restoredLoopState?: JsonValue;
37
+ }
38
+ export interface AgentLoopStrategy {
39
+ readonly name: string;
40
+ /** Host-authored loop revision. Joins the durable-run fingerprint when snapshot hooks are present. */
41
+ readonly revision?: string;
42
+ run(ctx: LoopContext): Promise<Usage | undefined>;
43
+ /**
44
+ * Capture loop-local resumable state at suspension. Must return a JSON-compatible value;
45
+ * core bounds and redacts it inside the durable run-state envelope. Declare together with
46
+ * `restore`; a custom strategy without both hooks is rejected before any provider call on
47
+ * durable runs (`AgentLoopStateError` / `ERR_PRISM_LOOP_NOT_DURABLE`).
48
+ */
49
+ snapshot?(): JsonValue;
50
+ /** Rehydrate from a previously captured snapshot; must throw on drift. Called before `run` on resume. */
51
+ restore?(snapshot: JsonValue): void;
52
+ }
53
+ export type AgentLoopOptions = {
54
+ readonly strategy: "single-shot";
55
+ /** Independent tool calls per turn run concurrently up to this limit. Default `1` (sequential). */
56
+ readonly toolConcurrency?: number;
57
+ } | {
58
+ readonly strategy: "generate-validate-revise";
59
+ readonly validator: ArtifactValidator<unknown>;
60
+ readonly parser?: ArtifactParser<unknown>;
61
+ readonly repairer?: ArtifactRepairer<unknown>;
62
+ readonly maxRevisions?: number;
63
+ /** Dispatch provider tool calls in artifact turns. Default `"disabled"`; `"bounded"` uses RunOptions.maxToolRounds sequentially. */
64
+ readonly toolCalls?: "disabled" | "bounded";
65
+ /** Native provider JSON-schema output. Ignored when `structuredOutputMode` is `artifact-loop`. */
66
+ readonly structuredOutput?: StructuredOutputOptions;
67
+ /** `native` maps schema to capable providers; `artifact-loop` keeps repair turns only. */
68
+ readonly structuredOutputMode?: "native" | "artifact-loop";
69
+ /**
70
+ * When to attach native `structuredOutput` under `toolCalls: "bounded"`.
71
+ * `every-turn` (default): schema on every provider request (legacy).
72
+ * `final-turn-only`: tool-eligible turns omit schema; artifact/revision turns send schema and withdraw tools.
73
+ */
74
+ readonly structuredOutputTiming?: "every-turn" | "final-turn-only";
75
+ };
76
+ export interface ArtifactValidation {
77
+ readonly ok: boolean;
78
+ readonly errors?: readonly {
79
+ readonly path?: string;
80
+ readonly message: string;
81
+ }[];
82
+ readonly metadata?: Readonly<Record<string, unknown>>;
83
+ }
84
+ export interface ArtifactContext {
85
+ readonly sessionId: string;
86
+ readonly runId: string;
87
+ readonly turn: number;
88
+ readonly signal: AbortSignal;
89
+ readonly metadata: Readonly<Record<string, unknown>>;
90
+ }
91
+ export interface ArtifactParseResult<T> {
92
+ readonly ok: boolean;
93
+ readonly value?: T;
94
+ readonly error?: string;
95
+ }
96
+ export type ArtifactParser<T> = (text: string, ctx: ArtifactContext) => ArtifactParseResult<T> | Promise<ArtifactParseResult<T>>;
97
+ export type ArtifactValidator<T> = (value: T, ctx: ArtifactContext) => ArtifactValidation | Promise<ArtifactValidation>;
98
+ export type ArtifactRepairer<T> = (value: T | undefined, failure: ArtifactValidation, ctx: ArtifactContext) => AgentInput | Promise<AgentInput>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=loop.js.map
@@ -0,0 +1,366 @@
1
+ /** Contracts-core persistence family (0.2.5 plan 025 Task 1 split).
2
+ * Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
3
+ import type { AgentEventRecord, AgentEventSource, AgentEventType, RunRecord, RunStatus, ToolCallRecord, ToolCallStatus, UsageRecord, UsageScope } from "../contracts-protocol.js";
4
+ import type { AgentDefinition } from "./agent.js";
5
+ import type { JsonObject } from "./content.js";
6
+ import type { SessionBranchRead, SessionEntry, SessionEntryKind, SessionStore } from "./session.js";
7
+ export interface StoreFactory {
8
+ readonly name: string;
9
+ create(config?: JsonObject): Promise<SessionStore> | SessionStore;
10
+ readonly metadata?: Readonly<Record<string, unknown>>;
11
+ }
12
+ /** Ownership scope identifiers. Hosts may use these for multi-tenant isolation. */
13
+ export interface OwnershipScope {
14
+ readonly tenantId?: string;
15
+ readonly accountId?: string;
16
+ readonly userId?: string;
17
+ }
18
+ /** Cursor-paginated result page. */
19
+ export interface PersistencePage<T> {
20
+ readonly items: readonly T[];
21
+ readonly nextCursor?: string;
22
+ readonly total?: number;
23
+ }
24
+ /** Common query controls for cursor-based pagination. */
25
+ export interface PersistenceQuery {
26
+ readonly cursor?: string;
27
+ readonly limit?: number;
28
+ readonly order?: "asc" | "desc";
29
+ }
30
+ /** Generic versioned checkpoint key. Namespaces prevent consumer collisions. */
31
+ export interface CheckpointKey extends OwnershipScope {
32
+ readonly namespace: string;
33
+ readonly key: string;
34
+ readonly signal?: AbortSignal;
35
+ }
36
+ /** Input for an optimistic checkpoint write. Versions must strictly increase. */
37
+ export interface CheckpointSaveInput extends CheckpointKey {
38
+ readonly version: number;
39
+ /** Exact current version required before update; use 0 for create-only. */
40
+ readonly expectedVersion?: number;
41
+ /** Monotonic lease fence. Lower or absent worker fences cannot replace a fenced record. */
42
+ readonly fencingToken?: number;
43
+ readonly value: unknown;
44
+ readonly category?: string;
45
+ readonly metadata?: Readonly<Record<string, unknown>>;
46
+ }
47
+ /** Durable generic checkpoint record. */
48
+ export interface CheckpointRecord extends OwnershipScope {
49
+ readonly namespace: string;
50
+ readonly key: string;
51
+ readonly version: number;
52
+ readonly fencingToken?: number;
53
+ readonly value: unknown;
54
+ readonly category?: string;
55
+ readonly createdAt: string;
56
+ readonly updatedAt: string;
57
+ readonly metadata?: Readonly<Record<string, unknown>>;
58
+ }
59
+ /** Bounded checkpoint query. */
60
+ export interface CheckpointQuery extends PersistenceQuery, OwnershipScope {
61
+ readonly namespace?: string;
62
+ readonly keyPrefix?: string;
63
+ readonly category?: string | readonly string[];
64
+ readonly signal?: AbortSignal;
65
+ }
66
+ /** Generic versioned checkpoint capability for persistence adapters. */
67
+ export interface CheckpointStore {
68
+ saveCheckpoint(input: CheckpointSaveInput): Promise<CheckpointRecord>;
69
+ loadCheckpoint(input: CheckpointKey): Promise<CheckpointRecord | null>;
70
+ listCheckpoints(query?: CheckpointQuery): Promise<PersistencePage<CheckpointRecord>>;
71
+ deleteCheckpoint(input: CheckpointKey): Promise<boolean>;
72
+ }
73
+ /** Generic lease key. Ownership fields are part of the trust boundary. */
74
+ export interface LeaseKey extends OwnershipScope {
75
+ readonly namespace: string;
76
+ readonly key: string;
77
+ readonly signal?: AbortSignal;
78
+ }
79
+ export interface LeaseAcquireInput extends LeaseKey {
80
+ readonly ownerId: string;
81
+ readonly ttlMs: number;
82
+ }
83
+ export interface LeaseClaimInput extends LeaseKey {
84
+ readonly ownerId: string;
85
+ readonly token: string;
86
+ readonly ttlMs?: number;
87
+ }
88
+ export interface LeaseRecord extends OwnershipScope {
89
+ readonly namespace: string;
90
+ readonly key: string;
91
+ readonly ownerId: string;
92
+ readonly token: string;
93
+ readonly fencingToken: number;
94
+ readonly acquiredAt: string;
95
+ readonly expiresAt: string;
96
+ readonly updatedAt: string;
97
+ }
98
+ /** Atomic distributed lease capability. Expired rows retain fencing counters. */
99
+ export interface LeaseStore {
100
+ tryAcquireLease(input: LeaseAcquireInput): Promise<LeaseRecord | null>;
101
+ renewLease(input: LeaseClaimInput & {
102
+ readonly ttlMs: number;
103
+ }): Promise<LeaseRecord | null>;
104
+ releaseLease(input: LeaseClaimInput): Promise<boolean>;
105
+ getLease(input: LeaseKey): Promise<LeaseRecord | null>;
106
+ }
107
+ /** Stored session record. Does not include provider objects or credentials. */
108
+ export interface SessionRecord extends OwnershipScope {
109
+ readonly id: string;
110
+ readonly parentSessionId?: string;
111
+ readonly agentDefinitionId?: string;
112
+ readonly agentDefinitionVersion?: string;
113
+ readonly createdAt: string;
114
+ readonly updatedAt: string;
115
+ readonly expiresAt?: string;
116
+ readonly retentionPolicyId?: string;
117
+ readonly metadata?: Readonly<Record<string, unknown>>;
118
+ /** Write version for optimistic metadata CAS; undefined on legacy/never-written rows. */
119
+ readonly version?: number;
120
+ }
121
+ /** Stored branch handle / leaf pointer. The leaf is the current entry id for the branch. */
122
+ export interface BranchRecord {
123
+ readonly id: string;
124
+ readonly sessionId: string;
125
+ readonly name?: string;
126
+ readonly rootEntryId?: string;
127
+ readonly parentBranchId?: string;
128
+ /** Durable leaf entry id for this branch (the persistence-side branch tip). */
129
+ readonly leafEntryId?: string;
130
+ readonly createdAt: string;
131
+ readonly metadata?: Readonly<Record<string, unknown>>;
132
+ }
133
+ export interface RunFeedbackRecord extends OwnershipScope {
134
+ readonly id: string;
135
+ readonly runId: string;
136
+ readonly sessionId: string;
137
+ readonly traceId?: string;
138
+ readonly rating?: number;
139
+ readonly comment?: string;
140
+ readonly tags: readonly string[];
141
+ readonly scorerIds: readonly string[];
142
+ readonly evaluationIds: readonly string[];
143
+ readonly createdAt: string;
144
+ readonly createdBy?: string;
145
+ readonly metadata?: Readonly<Record<string, unknown>>;
146
+ }
147
+ export interface AppendRunFeedbackInput extends OwnershipScope {
148
+ readonly id: string;
149
+ readonly runId: string;
150
+ readonly sessionId?: string;
151
+ readonly traceId?: string;
152
+ readonly rating?: number;
153
+ readonly comment?: string;
154
+ readonly tags?: readonly string[];
155
+ readonly scorerIds?: readonly string[];
156
+ readonly evaluationIds?: readonly string[];
157
+ readonly createdAt?: string;
158
+ readonly createdBy?: string;
159
+ readonly metadata?: Readonly<Record<string, unknown>>;
160
+ readonly signal?: AbortSignal;
161
+ }
162
+ /** Cursor-paginated, ownership-scoped feedback query. */
163
+ export interface RunFeedbackQuery extends PersistenceQuery, OwnershipScope {
164
+ readonly runId?: string;
165
+ readonly sessionId?: string;
166
+ readonly traceId?: string;
167
+ readonly rating?: number;
168
+ readonly scorerId?: string;
169
+ readonly evaluationId?: string;
170
+ readonly tag?: string;
171
+ readonly fromCreatedAt?: string;
172
+ readonly toCreatedAt?: string;
173
+ readonly signal?: AbortSignal;
174
+ }
175
+ export interface DeleteRunFeedbackInput extends OwnershipScope {
176
+ readonly id: string;
177
+ readonly signal?: AbortSignal;
178
+ }
179
+ /** Feedback storage seam. Records are append-only; correction uses a new record and deletion is explicit. */
180
+ export interface RunFeedbackStore {
181
+ append(input: AppendRunFeedbackInput): Promise<RunFeedbackRecord>;
182
+ query(query: RunFeedbackQuery): Promise<PersistencePage<RunFeedbackRecord>>;
183
+ delete(input: DeleteRunFeedbackInput): Promise<boolean>;
184
+ }
185
+ /** Stored agent definition version. Does not include provider credentials/resolvers/provider instances. */
186
+ export interface AgentDefinitionRecord extends OwnershipScope {
187
+ readonly id: string;
188
+ readonly name: string;
189
+ readonly version: string;
190
+ readonly source?: string;
191
+ readonly agentDefinition: AgentDefinition;
192
+ readonly createdAt: string;
193
+ readonly createdBy?: string;
194
+ readonly metadata?: Readonly<Record<string, unknown>>;
195
+ }
196
+ /** Stored retention policy. */
197
+ export interface RetentionPolicy extends OwnershipScope {
198
+ readonly id: string;
199
+ readonly name?: string;
200
+ readonly maxAgeDays?: number;
201
+ readonly maxEntriesPerSession?: number;
202
+ readonly maxTotalBytes?: number;
203
+ readonly archiveStore?: string;
204
+ readonly appliedKinds?: readonly SessionEntryKind[];
205
+ readonly createdAt: string;
206
+ readonly metadata?: Readonly<Record<string, unknown>>;
207
+ }
208
+ /** Stored migration record. */
209
+ export interface MigrationRecord {
210
+ readonly id: string;
211
+ readonly name: string;
212
+ readonly version: string;
213
+ readonly appliedAt: string;
214
+ readonly appliedBy?: string;
215
+ readonly checksum?: string;
216
+ readonly metadata?: Readonly<Record<string, unknown>>;
217
+ }
218
+ /** Query for sessions. */
219
+ export interface SessionQuery extends PersistenceQuery, OwnershipScope {
220
+ readonly id?: string;
221
+ readonly parentSessionId?: string;
222
+ readonly agentDefinitionId?: string;
223
+ readonly agentDefinitionVersion?: string;
224
+ readonly retentionPolicyId?: string;
225
+ /** Match sessions whose `metadata` object contains this top-level key (e.g. conversation marker). */
226
+ readonly metadataKey?: string;
227
+ readonly fromCreatedAt?: string;
228
+ readonly toCreatedAt?: string;
229
+ readonly fromUpdatedAt?: string;
230
+ readonly toUpdatedAt?: string;
231
+ readonly hasExpired?: boolean;
232
+ }
233
+ /** Validate a top-level `SessionRecord.metadata` key used by `SessionQuery.metadataKey` filters. */
234
+ export declare function assertSessionMetadataKey(key: string): string;
235
+ /** Query for session entries. */
236
+ export interface SessionEntryQuery extends PersistenceQuery, OwnershipScope {
237
+ readonly sessionId?: string;
238
+ readonly runId?: string;
239
+ readonly parentId?: string;
240
+ /** Filter to entries on the branch ending at this leaf id. */
241
+ readonly leafId?: string;
242
+ readonly kind?: SessionEntryKind | readonly SessionEntryKind[];
243
+ readonly fromTimestamp?: string;
244
+ readonly toTimestamp?: string;
245
+ }
246
+ /** Query for branch handles/leaves. */
247
+ export interface BranchQuery extends PersistenceQuery {
248
+ readonly sessionId?: string;
249
+ readonly name?: string;
250
+ readonly parentBranchId?: string;
251
+ readonly hasLeaf?: boolean;
252
+ }
253
+ /** Query for runs. */
254
+ export interface RunQuery extends PersistenceQuery, OwnershipScope {
255
+ readonly sessionId?: string;
256
+ readonly branchId?: string;
257
+ readonly agentDefinitionId?: string;
258
+ readonly agentDefinitionVersion?: string;
259
+ readonly status?: RunStatus | readonly RunStatus[];
260
+ readonly fromStartedAt?: string;
261
+ readonly toStartedAt?: string;
262
+ readonly fromFinishedAt?: string;
263
+ readonly toFinishedAt?: string;
264
+ readonly isFinished?: boolean;
265
+ }
266
+ /** Query for agent event ledger rows. */
267
+ export interface AgentEventQuery extends PersistenceQuery, OwnershipScope {
268
+ readonly sessionId?: string;
269
+ readonly runId?: string;
270
+ readonly entryId?: string;
271
+ readonly type?: AgentEventType | readonly AgentEventType[];
272
+ readonly fromTimestamp?: string;
273
+ readonly toTimestamp?: string;
274
+ readonly redacted?: boolean;
275
+ }
276
+ /** Query for tool-call rows. */
277
+ export interface ToolCallQuery extends PersistenceQuery, OwnershipScope {
278
+ readonly sessionId?: string;
279
+ readonly runId?: string;
280
+ readonly entryId?: string;
281
+ readonly name?: string;
282
+ readonly status?: ToolCallStatus | readonly ToolCallStatus[];
283
+ readonly fromStartedAt?: string;
284
+ readonly toStartedAt?: string;
285
+ readonly fromFinishedAt?: string;
286
+ readonly toFinishedAt?: string;
287
+ readonly redacted?: boolean;
288
+ }
289
+ /** Query for usage rows. */
290
+ export interface UsageQuery extends PersistenceQuery, OwnershipScope {
291
+ readonly sessionId?: string;
292
+ readonly runId?: string;
293
+ readonly entryId?: string;
294
+ readonly scope?: UsageScope;
295
+ readonly turn?: number;
296
+ readonly attempt?: number;
297
+ readonly fromRecordedAt?: string;
298
+ readonly toRecordedAt?: string;
299
+ }
300
+ /** Query for agent definition versions. */
301
+ export interface AgentDefinitionQuery extends PersistenceQuery, OwnershipScope {
302
+ readonly name?: string;
303
+ readonly version?: string;
304
+ readonly source?: string;
305
+ readonly fromCreatedAt?: string;
306
+ readonly toCreatedAt?: string;
307
+ }
308
+ /** Query for retention policies. */
309
+ export interface RetentionPolicyQuery extends PersistenceQuery, OwnershipScope {
310
+ readonly name?: string;
311
+ readonly archiveStore?: string;
312
+ }
313
+ /** Query for migration records. */
314
+ export interface MigrationQuery extends PersistenceQuery {
315
+ readonly name?: string;
316
+ readonly version?: string;
317
+ readonly fromAppliedAt?: string;
318
+ readonly toAppliedAt?: string;
319
+ }
320
+ /**
321
+ * Production database-neutral persistence store contract.
322
+ * Hosts implement this interface to provide durable, paginated storage
323
+ * for sessions, entries, runs, events, tool calls, usage, agent definitions,
324
+ * and migrations, with optional generic checkpoint and atomic lease capabilities. No SQL client, ORM, host file storage, or network dependency is
325
+ * required by the contract.
326
+ */
327
+ export interface ProductionPersistenceStore {
328
+ readonly name?: string;
329
+ /** Optional generic write capability for resumable consumers such as workflows. */
330
+ readonly checkpoints?: CheckpointStore;
331
+ /** Optional atomic distributed lease capability for coordinators and workers. */
332
+ readonly leases?: LeaseStore;
333
+ /** Optional immutable run/trace feedback storage capability. */
334
+ readonly feedback?: RunFeedbackStore;
335
+ /** Optional durable, cross-replica-capable event source. */
336
+ readonly events?: AgentEventSource;
337
+ querySessions(query: SessionQuery): Promise<PersistencePage<SessionRecord>>;
338
+ queryBranches(query: BranchQuery): Promise<PersistencePage<BranchRecord>>;
339
+ queryEntries(query: SessionEntryQuery): Promise<PersistencePage<SessionEntry>>;
340
+ queryRuns(query: RunQuery): Promise<PersistencePage<RunRecord>>;
341
+ queryEvents(query: AgentEventQuery): Promise<PersistencePage<AgentEventRecord>>;
342
+ queryToolCalls(query: ToolCallQuery): Promise<PersistencePage<ToolCallRecord>>;
343
+ queryUsage(query: UsageQuery): Promise<PersistencePage<UsageRecord>>;
344
+ queryAgentDefinitions(query: AgentDefinitionQuery): Promise<PersistencePage<AgentDefinitionRecord>>;
345
+ queryRetentionPolicies(query: RetentionPolicyQuery): Promise<PersistencePage<RetentionPolicy>>;
346
+ queryMigrations(query: MigrationQuery): Promise<PersistencePage<MigrationRecord>>;
347
+ /** Optional session-record write capability (conversation threads, host-managed sessions).
348
+ * Upserts by id; ownership columns are set on create, `metadata`/`updatedAt` on update.
349
+ * Additive CAS: pass `expectedVersion` to require the stored version to match before the
350
+ * write (0 = create-only, a positive number = exact current version); omit it for legacy
351
+ * last-write-wins. Returns the new `version` when the underlying store supports it. */
352
+ appendSession?(record: SessionRecord & {
353
+ readonly expectedVersion?: number;
354
+ }): Promise<{
355
+ readonly version: number;
356
+ } | undefined>;
357
+ /** DB-friendly branch read (mirrors `SessionStore.readBranchPath`): one ancestor-chain
358
+ * query instead of `queryEntries({ sessionId })` + in-memory walk. Optional. */
359
+ readBranchPath?(query: SessionBranchRead): Promise<PersistencePage<SessionEntry>>;
360
+ /**
361
+ * Optional Phase 8 retention / legal-hold / export / tenant-quota lifecycle.
362
+ * Prefer attaching `createMemoryPersistenceLifecycle()` or adapter-native methods.
363
+ */
364
+ readonly lifecycle?: import("../persistence-lifecycle.js").PersistenceLifecycleStore;
365
+ readonly metadata?: Readonly<Record<string, unknown>>;
366
+ }
@@ -0,0 +1,9 @@
1
+ const SESSION_METADATA_KEY_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
2
+ /** Validate a top-level `SessionRecord.metadata` key used by `SessionQuery.metadataKey` filters. */
3
+ export function assertSessionMetadataKey(key) {
4
+ if (typeof key !== "string" || !SESSION_METADATA_KEY_PATTERN.test(key)) {
5
+ throw new RangeError("metadataKey must match /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/");
6
+ }
7
+ return key;
8
+ }
9
+ //# sourceMappingURL=persistence.js.map
@@ -0,0 +1,97 @@
1
+ /** Contracts-core provider family (0.2.5 plan 025 Task 1 split).
2
+ * Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
3
+ import type { ProviderEvent, RealtimeEvent, ToolDefinition } from "../contracts-protocol.js";
4
+ import type { ContextBlock } from "./agent.js";
5
+ import type { JsonObject, Message, ModelConfig } from "./content.js";
6
+ export type CacheRetention = "none" | "short" | "long";
7
+ export type PromptCacheKind = "implicit" | "openai_key" | "cache_control" | "provider_specific" | "none";
8
+ export interface ModelCacheCapabilities {
9
+ readonly kind?: PromptCacheKind;
10
+ readonly maxKeyLength?: number;
11
+ readonly maxBreakpoints?: number;
12
+ readonly minCacheableTokens?: number;
13
+ readonly longRetention?: boolean;
14
+ }
15
+ export type PromptCacheMode = "auto" | "on" | "off";
16
+ export type PromptCacheBreakpointLocation = "system_prompt" | "tools" | "stable_context" | "last_stable_message" | "last_user_message" | "message_id";
17
+ export type PromptCacheBreakpointTtl = "short" | "long";
18
+ export interface PromptCacheBreakpoint {
19
+ readonly location: PromptCacheBreakpointLocation;
20
+ readonly messageId?: string;
21
+ readonly ttl?: PromptCacheBreakpointTtl;
22
+ }
23
+ export interface PromptCacheHints {
24
+ readonly mode?: PromptCacheMode;
25
+ readonly key?: string;
26
+ readonly retention?: CacheRetention;
27
+ readonly breakpoints?: readonly PromptCacheBreakpoint[];
28
+ }
29
+ export interface StructuredOutputOptions {
30
+ readonly name: string;
31
+ readonly schema: JsonObject;
32
+ readonly strict?: boolean;
33
+ }
34
+ export interface ProviderRequestOptions {
35
+ readonly sessionId?: string;
36
+ readonly cacheRetention?: CacheRetention;
37
+ readonly cacheKey?: string;
38
+ readonly cache?: PromptCacheHints;
39
+ readonly headers?: Readonly<Record<string, string>>;
40
+ readonly compat?: JsonObject;
41
+ readonly extra?: JsonObject;
42
+ /** Provider-neutral JSON-schema structured output request. Requires model `capabilities.structuredOutput`. */
43
+ readonly structuredOutput?: StructuredOutputOptions;
44
+ /** Opaque provider continuation cursor (e.g. OpenAI `previous_response_id`). When set,
45
+ * the provider resumes from this cursor instead of re-sending full history. */
46
+ readonly continuation?: {
47
+ readonly cursor: string;
48
+ };
49
+ }
50
+ export interface ProviderRequest {
51
+ readonly model: ModelConfig;
52
+ readonly messages: readonly Message[];
53
+ readonly tools?: readonly ToolDefinition[];
54
+ readonly context?: readonly ContextBlock[];
55
+ readonly options?: ProviderRequestOptions;
56
+ readonly metadata?: Readonly<Record<string, unknown>>;
57
+ readonly signal?: AbortSignal;
58
+ }
59
+ export interface AIProvider {
60
+ readonly id: string;
61
+ generate(request: ProviderRequest): AsyncIterable<ProviderEvent>;
62
+ }
63
+ export type ProviderResolver = (model: ModelConfig) => AIProvider | undefined;
64
+ /** Realtime audio/session event. Realtime is a bidirectional session, not a request/response
65
+ * stream, so it is a separate neutral seam from `AIProvider.generate()`. Credentials are
66
+ * bound to the session handshake only and never appear in events. */
67
+ export interface RealtimeSession {
68
+ readonly id: string;
69
+ readonly provider: string;
70
+ /** Send an audio chunk (PCM/Opus; provider-specific format set at creation). */
71
+ sendAudio(chunk: Uint8Array, options?: {
72
+ readonly signal?: AbortSignal;
73
+ }): Promise<void>;
74
+ /** Inbound events (audio out, transcripts, hosted tool calls, interruption, close, error). */
75
+ events(): AsyncIterable<RealtimeEvent>;
76
+ /** Request the provider stop the current response mid-stream. */
77
+ interrupt(options?: {
78
+ readonly signal?: AbortSignal;
79
+ }): Promise<void>;
80
+ /** Close the session and release the transport. Idempotent. */
81
+ close(reason?: string, options?: {
82
+ readonly signal?: AbortSignal;
83
+ }): Promise<void>;
84
+ }
85
+ /** Factory a provider exposes for realtime sessions; not part of `AIProvider`. */
86
+ export type RealtimeSessionFactory = (options: RealtimeSessionOptions) => RealtimeSession;
87
+ export interface RealtimeSessionOptions {
88
+ readonly model: ModelConfig;
89
+ readonly signal?: AbortSignal;
90
+ /** Provider-specific caps override; providers enforce finite defaults. */
91
+ readonly caps?: RealtimeCaps;
92
+ }
93
+ export interface RealtimeCaps {
94
+ readonly maxAudioEventsPerSecond?: number;
95
+ readonly maxBytesPerSecond?: number;
96
+ readonly maxWallMs?: number;
97
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1,44 @@
1
+ /** Contracts-core resources family (0.2.5 plan 025 Task 1 split).
2
+ * Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
3
+ import type { PermissionPolicy, TrustPolicy } from "../security.js";
4
+ import type { OAuthCredentials } from "./extensions.js";
5
+ export interface Resource {
6
+ readonly uri: string;
7
+ readonly mediaType?: string;
8
+ readonly text?: string;
9
+ readonly data?: Uint8Array;
10
+ readonly metadata?: Readonly<Record<string, unknown>>;
11
+ }
12
+ export interface ResourceLoader {
13
+ load(uri: string, context?: ResourceLoadContext): Promise<Resource>;
14
+ list?(context?: ResourceLoadContext): Promise<readonly Resource[]>;
15
+ }
16
+ export interface ResourceLoadContext {
17
+ readonly signal?: AbortSignal;
18
+ readonly metadata?: Readonly<Record<string, unknown>>;
19
+ readonly permission?: PermissionPolicy;
20
+ readonly trust?: TrustPolicy;
21
+ }
22
+ export interface SettingsProvider {
23
+ get<T = unknown>(key: string): Promise<T | undefined> | T | undefined;
24
+ }
25
+ export interface CredentialRequest {
26
+ readonly name: string;
27
+ readonly provider?: string;
28
+ readonly metadata?: Readonly<Record<string, unknown>>;
29
+ }
30
+ export interface Credential {
31
+ readonly type: "bearer" | "api_key" | "basic" | "custom";
32
+ readonly value: string;
33
+ readonly metadata?: Readonly<Record<string, unknown>>;
34
+ }
35
+ export interface CredentialResolver {
36
+ resolve(request: CredentialRequest): Promise<Credential | undefined> | Credential | undefined;
37
+ }
38
+ export interface CredentialResolverSource {
39
+ readonly name: string;
40
+ readonly resolver: CredentialResolver;
41
+ }
42
+ export interface OAuthCredentialStore {
43
+ set(provider: string, credentials: OAuthCredentials): void | Promise<void>;
44
+ }
@@ -0,0 +1,7 @@
1
+ export {};
2
+ // ponytail: AgentLoopStrategy orchestrates shared runtime primitives via
3
+ // LoopContext; it never re-implements provider calls, retry, abort, store, or
4
+ // events. Single-shot is the default; loops are opt-in. T is host-defined,
5
+ // Prism never instantiates it. No domain control-flow vocabulary (boundary
6
+ // guard); artifact types are generic over host T.
7
+ //# sourceMappingURL=resources.js.map