@earendil-works/pi-durable 0.87.0 → 0.87.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.
- package/README.md +29 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{memory-storage.d.ts → storage/memory.d.ts} +12 -6
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/{memory-storage.js → storage/memory.js} +236 -24
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/sqlite/database.d.ts +26 -0
- package/dist/storage/sqlite/database.d.ts.map +1 -0
- package/dist/storage/sqlite/database.js +2 -0
- package/dist/storage/sqlite/database.js.map +1 -0
- package/dist/storage/sqlite/index.d.ts +4 -0
- package/dist/storage/sqlite/index.d.ts.map +1 -0
- package/dist/storage/sqlite/index.js +3 -0
- package/dist/storage/sqlite/index.js.map +1 -0
- package/dist/storage/sqlite/migrations.d.ts +11 -0
- package/dist/storage/sqlite/migrations.d.ts.map +1 -0
- package/dist/storage/sqlite/migrations.js +104 -0
- package/dist/storage/sqlite/migrations.js.map +1 -0
- package/dist/storage/sqlite/node.d.ts +25 -0
- package/dist/storage/sqlite/node.d.ts.map +1 -0
- package/dist/storage/sqlite/node.js +97 -0
- package/dist/storage/sqlite/node.js.map +1 -0
- package/dist/storage/sqlite/storage.d.ts +45 -0
- package/dist/storage/sqlite/storage.d.ts.map +1 -0
- package/dist/storage/sqlite/storage.js +524 -0
- package/dist/storage/sqlite/storage.js.map +1 -0
- package/dist/types.d.ts +113 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/pico-v5-chord-usage.md +64 -63
- package/docs/pico-v5-handoff.md +92 -57
- package/docs/pico-v5.md +519 -350
- package/package.json +20 -3
- package/dist/memory-storage.d.ts.map +0 -1
- package/dist/memory-storage.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { Context, JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { Op } from "@earendil-works/chord/delta";
|
|
2
3
|
import type { Message } from "@earendil-works/pi-ai";
|
|
4
|
+
/** JSON object used as the root of every durable document. */
|
|
5
|
+
export type JsonObject = {
|
|
6
|
+
[key: string]: JsonValue;
|
|
7
|
+
};
|
|
3
8
|
/** Session-global identifier shared by every durable record table. */
|
|
4
9
|
export type Id = number;
|
|
5
|
-
/**
|
|
10
|
+
/** Strictly increasing sequence assigned to one atomic storage commit; gaps are permitted. */
|
|
6
11
|
export type Seq = number;
|
|
7
12
|
/** The root conversation always uses this reserved ID. */
|
|
8
13
|
export declare const ROOT_CONVERSATION_ID: Id;
|
|
9
|
-
/** JSON-safe error snapshot persisted instead of a runtime `Error` object. */
|
|
10
|
-
export type StoredError = {
|
|
11
|
-
readonly message: string;
|
|
12
|
-
/** Optional structured diagnostic data for inspection or recovery. */
|
|
13
|
-
readonly detail?: JsonValue;
|
|
14
|
-
};
|
|
15
14
|
/** Immutable identity, history ancestry, and task ownership of a transcript scope. */
|
|
16
15
|
export type ConversationRecord = {
|
|
17
16
|
readonly id: Id;
|
|
@@ -46,7 +45,7 @@ export type EntryRecord = {
|
|
|
46
45
|
readonly kind: string;
|
|
47
46
|
/** Messages contributed to model context; absent for display or bookkeeping entries. */
|
|
48
47
|
readonly model?: readonly Message[];
|
|
49
|
-
/** JSON payload consumed by views,
|
|
48
|
+
/** JSON payload consumed by views, extensions, or bookkeeping logic. */
|
|
50
49
|
readonly data?: JsonValue;
|
|
51
50
|
/** First entry in the active context selected by this entry. */
|
|
52
51
|
readonly head?: Id;
|
|
@@ -60,15 +59,17 @@ export type EntryDraft = Omit<EntryRecord, "id" | "conversationId" | "byTaskId"
|
|
|
60
59
|
/** `"self"` starts active context at the newly assigned entry ID. */
|
|
61
60
|
readonly head?: Id | "self";
|
|
62
61
|
};
|
|
63
|
-
/** Identity fields shared by every
|
|
64
|
-
type
|
|
62
|
+
/** Identity fields shared by every durable submission state. */
|
|
63
|
+
type SubmissionRecordBase = {
|
|
65
64
|
readonly id: Id;
|
|
66
65
|
readonly conversationId: Id;
|
|
67
66
|
/** Host-provided deduplication key, scoped to the conversation. */
|
|
68
67
|
readonly requestId?: string;
|
|
69
68
|
};
|
|
70
|
-
/** Durable lifecycle of one admitted
|
|
71
|
-
export type
|
|
69
|
+
/** Durable lifecycle of one admitted user input or passive entry write. */
|
|
70
|
+
export type SubmissionRecord = (SubmissionRecordBase & {
|
|
71
|
+
readonly type: "input";
|
|
72
|
+
} & ({
|
|
72
73
|
/** Admitted but not yet represented in the transcript. */
|
|
73
74
|
readonly status: "queued";
|
|
74
75
|
readonly entry?: never;
|
|
@@ -78,31 +79,56 @@ export type Input = InputBase & ({
|
|
|
78
79
|
} | {
|
|
79
80
|
/** Added to the transcript and owned by an active turn. */
|
|
80
81
|
readonly status: "placed";
|
|
81
|
-
/** User transcript entry created when this input was placed. */
|
|
82
82
|
readonly entry: Id;
|
|
83
83
|
readonly answer?: never;
|
|
84
84
|
readonly reason?: never;
|
|
85
85
|
readonly detail?: never;
|
|
86
86
|
} | {
|
|
87
|
-
/** Successfully
|
|
87
|
+
/** Successfully answered user input. */
|
|
88
88
|
readonly status: "done";
|
|
89
|
-
/** User or passive-write transcript entry created when this input was placed. */
|
|
90
89
|
readonly entry: Id;
|
|
91
|
-
|
|
92
|
-
readonly answer?: Id;
|
|
90
|
+
readonly answer: Id;
|
|
93
91
|
readonly reason?: never;
|
|
94
92
|
readonly detail?: never;
|
|
95
93
|
} | {
|
|
96
94
|
/** Terminal input that can no longer receive an answer. */
|
|
97
95
|
readonly status: "unanswered";
|
|
98
|
-
/** Present when the input was placed before becoming unanswered. */
|
|
99
96
|
readonly entry?: Id;
|
|
100
97
|
readonly answer?: never;
|
|
101
|
-
/** Stable machine-readable explanation such as `"aborted"` or `"stale"`. */
|
|
102
98
|
readonly reason: string;
|
|
103
|
-
/** Optional structured diagnostic data. */
|
|
104
99
|
readonly detail?: JsonValue;
|
|
105
|
-
})
|
|
100
|
+
})) | (SubmissionRecordBase & {
|
|
101
|
+
readonly type: "write";
|
|
102
|
+
} & ({
|
|
103
|
+
/** Admitted but not yet appended to the transcript. */
|
|
104
|
+
readonly status: "queued";
|
|
105
|
+
readonly entry?: never;
|
|
106
|
+
readonly answer?: never;
|
|
107
|
+
readonly reason?: never;
|
|
108
|
+
readonly detail?: never;
|
|
109
|
+
} | {
|
|
110
|
+
/** Successfully appended passive entry. */
|
|
111
|
+
readonly status: "done";
|
|
112
|
+
readonly entry: Id;
|
|
113
|
+
readonly answer?: never;
|
|
114
|
+
readonly reason?: never;
|
|
115
|
+
readonly detail?: never;
|
|
116
|
+
} | {
|
|
117
|
+
/** Terminal passive write that could not be placed. */
|
|
118
|
+
readonly status: "unanswered";
|
|
119
|
+
readonly entry?: never;
|
|
120
|
+
readonly answer?: never;
|
|
121
|
+
readonly reason: string;
|
|
122
|
+
readonly detail?: JsonValue;
|
|
123
|
+
}));
|
|
124
|
+
/** Submission fields supplied before the Session assigns an ID. */
|
|
125
|
+
export type SubmissionCreate = SubmissionRecord extends infer Record ? Record extends SubmissionRecord ? Omit<Record, "id"> : never : never;
|
|
126
|
+
/** JSON-safe error snapshot persisted instead of a runtime `Error` object. */
|
|
127
|
+
export type TaskOutcomeError = {
|
|
128
|
+
readonly message: string;
|
|
129
|
+
/** Optional structured diagnostic data for inspection or recovery. */
|
|
130
|
+
readonly detail?: JsonValue;
|
|
131
|
+
};
|
|
106
132
|
/** Durable reason and optional result recorded when a task becomes terminal. */
|
|
107
133
|
export type TaskOutcome<R> = {
|
|
108
134
|
readonly status: "completed";
|
|
@@ -113,7 +139,7 @@ export type TaskOutcome<R> = {
|
|
|
113
139
|
/** Expected task or domain failure explicitly committed by its implementation. */
|
|
114
140
|
| {
|
|
115
141
|
readonly status: "failed";
|
|
116
|
-
readonly error:
|
|
142
|
+
readonly error: TaskOutcomeError;
|
|
117
143
|
readonly result?: R;
|
|
118
144
|
readonly reason?: never;
|
|
119
145
|
}
|
|
@@ -134,7 +160,7 @@ export type TaskOutcome<R> = {
|
|
|
134
160
|
/** Runtime-detected contract failure, such as an uncaught throw or no durable progress. */
|
|
135
161
|
| {
|
|
136
162
|
readonly status: "faulted";
|
|
137
|
-
readonly error:
|
|
163
|
+
readonly error: TaskOutcomeError;
|
|
138
164
|
readonly result?: never;
|
|
139
165
|
readonly reason?: never;
|
|
140
166
|
};
|
|
@@ -191,7 +217,7 @@ export type TaskRecord<I, S, R> = TaskRecordBase<I> & ({
|
|
|
191
217
|
export type DocumentRecord = {
|
|
192
218
|
/** Unique incarnation ID; never reused when the same logical document is recreated. */
|
|
193
219
|
readonly id: Id;
|
|
194
|
-
/**
|
|
220
|
+
/** Stable document definition kind. */
|
|
195
221
|
readonly kind: string;
|
|
196
222
|
/** Family member key; absent for singleton documents. */
|
|
197
223
|
readonly key?: string;
|
|
@@ -253,7 +279,38 @@ export type TaskQuery = {
|
|
|
253
279
|
readonly abortRequested?: boolean;
|
|
254
280
|
readonly background?: boolean;
|
|
255
281
|
};
|
|
256
|
-
/**
|
|
282
|
+
/** Current state or one historical commit sequence used for document membership and content reads. */
|
|
283
|
+
export type DocumentPoint = Seq | "current";
|
|
284
|
+
/** Exact logical identity of a singleton or one keyed family member. */
|
|
285
|
+
export type DocumentAddress = {
|
|
286
|
+
readonly kind: string;
|
|
287
|
+
readonly scope: DocumentRecord["scope"];
|
|
288
|
+
/** Absent selects the singleton; present selects one family member. */
|
|
289
|
+
readonly key?: string;
|
|
290
|
+
};
|
|
291
|
+
/** Ordered scan of document incarnations alive in one exact scope at one point. */
|
|
292
|
+
export type DocumentQuery = {
|
|
293
|
+
readonly scope: DocumentRecord["scope"];
|
|
294
|
+
readonly at: DocumentPoint;
|
|
295
|
+
readonly kind?: string;
|
|
296
|
+
};
|
|
297
|
+
/** Complete checkpoint or Chord operation batch selected by the owning Session. */
|
|
298
|
+
export type DocumentContent = {
|
|
299
|
+
readonly version: number;
|
|
300
|
+
readonly kind: "base";
|
|
301
|
+
readonly value: JsonObject;
|
|
302
|
+
} | {
|
|
303
|
+
readonly version: number;
|
|
304
|
+
readonly kind: "delta";
|
|
305
|
+
readonly ops: readonly Op[];
|
|
306
|
+
};
|
|
307
|
+
/** Detached materialized value and stored definition version at a selected point. */
|
|
308
|
+
export type StoredDocument = {
|
|
309
|
+
readonly record: DocumentRecord;
|
|
310
|
+
readonly version: number;
|
|
311
|
+
readonly value: JsonObject;
|
|
312
|
+
};
|
|
313
|
+
/** One record or document mutation in an atomic storage commit. */
|
|
257
314
|
export type StorageWrite = {
|
|
258
315
|
readonly type: "conversation";
|
|
259
316
|
readonly value: ConversationRecord;
|
|
@@ -264,21 +321,37 @@ export type StorageWrite = {
|
|
|
264
321
|
readonly type: "task";
|
|
265
322
|
readonly value: TaskRecord<JsonValue, JsonValue, JsonValue>;
|
|
266
323
|
} | {
|
|
267
|
-
readonly type: "
|
|
268
|
-
readonly value:
|
|
324
|
+
readonly type: "submission";
|
|
325
|
+
readonly value: SubmissionRecord;
|
|
326
|
+
} | {
|
|
327
|
+
readonly type: "document.create";
|
|
328
|
+
readonly record: DocumentCreate;
|
|
329
|
+
readonly content: Extract<DocumentContent, {
|
|
330
|
+
readonly kind: "base";
|
|
331
|
+
}>;
|
|
332
|
+
} | {
|
|
333
|
+
readonly type: "document.change";
|
|
334
|
+
readonly id: Id;
|
|
335
|
+
readonly content: DocumentContent;
|
|
336
|
+
} | {
|
|
337
|
+
readonly type: "document.retire";
|
|
338
|
+
readonly id: Id;
|
|
269
339
|
};
|
|
270
340
|
/**
|
|
271
341
|
* Atomic persistence boundary for Session records.
|
|
272
342
|
*
|
|
273
343
|
* Storage trusts the owning Session to supply semantically valid records, references,
|
|
274
344
|
* ancestry, and transitions. Implementations enforce atomicity, global ID ownership,
|
|
275
|
-
* immutable conversation/entry creation, and detached values;
|
|
345
|
+
* immutable conversation/entry creation, document record consistency, and detached values;
|
|
346
|
+
* Session serializes commits.
|
|
276
347
|
*/
|
|
277
348
|
export interface Storage {
|
|
278
|
-
/**
|
|
349
|
+
/**
|
|
350
|
+
* Atomically persist one batch and return its sequence. Once resolved, later reads through this storage observe it.
|
|
351
|
+
*/
|
|
279
352
|
commit(writes: readonly StorageWrite[], context: Context): Promise<Seq>;
|
|
280
353
|
/** Return a fresh candidate from the Session-global record ID namespace. */
|
|
281
|
-
mintId(): Id
|
|
354
|
+
mintId(): Promise<Id>;
|
|
282
355
|
/** Look up one conversation by exact ID. */
|
|
283
356
|
conversation(id: Id, context: Context): Promise<ConversationRecord | undefined>;
|
|
284
357
|
/** Scan conversations in ascending ID order. */
|
|
@@ -301,10 +374,16 @@ export interface Storage {
|
|
|
301
374
|
task(id: Id, context: Context): Promise<TaskRecord<JsonValue, JsonValue, JsonValue> | undefined>;
|
|
302
375
|
/** Scan task records matching every supplied filter. */
|
|
303
376
|
scanTasks(query: TaskQuery, cursor: Cursor | undefined, limit: number, context: Context): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>>;
|
|
304
|
-
/** Look up the latest complete record for one admitted
|
|
305
|
-
|
|
306
|
-
/** Find
|
|
307
|
-
|
|
377
|
+
/** Look up the latest complete record for one admitted submission. */
|
|
378
|
+
submission(id: Id, context: Context): Promise<SubmissionRecord | undefined>;
|
|
379
|
+
/** Find a submission by its conversation-scoped host deduplication key. */
|
|
380
|
+
submissionByRequest(conversationId: Id, requestId: string, context: Context): Promise<SubmissionRecord | undefined>;
|
|
381
|
+
/** Resolve the incarnation occupying one exact logical address at the selected point. */
|
|
382
|
+
findDocument(address: DocumentAddress, at: DocumentPoint, context: Context): Promise<DocumentRecord | undefined>;
|
|
383
|
+
/** Materialize one specific incarnation by ID at the selected point without following a replacement at its address. */
|
|
384
|
+
document(id: Id, at: DocumentPoint, context: Context): Promise<StoredDocument | undefined>;
|
|
385
|
+
/** Scan incarnations alive in one exact scope at the selected point. */
|
|
386
|
+
scanDocuments(query: DocumentQuery, cursor: Cursor | undefined, limit: number, context: Context): Promise<Page<DocumentRecord, Cursor>>;
|
|
308
387
|
/** Release backend resources; all later operations must reject. */
|
|
309
388
|
close(context: Context): Promise<void>;
|
|
310
389
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,sEAAsE;AACtE,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC;AAExB,gEAAgE;AAChE,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB,0DAA0D;AAC1D,eAAO,MAAM,oBAAoB,EAAE,EAAM,CAAC;AAE1C,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;CAC5B,CAAC;AAEF,sFAAsF;AACtF,MAAM,MAAM,kBAAkB,GAAG;IAChC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE;QACjB,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC;QAC5B,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;KAChB,CAAC;IACF,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE;QAChB,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC;QAC5B,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;KACpB,CAAC;CACF,CAAC;AAEF,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;CACpB,GAAG,CACD;IACA,QAAQ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;IAEpG,mEAAmE;IACnE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type { Message } from \"@earendil-works/pi-ai\";\n\n/** Session-global identifier shared by every durable record table. */\nexport type Id = number;\n\n/** Monotonic sequence assigned to one atomic storage commit. */\nexport type Seq = number;\n\n/** The root conversation always uses this reserved ID. */\nexport const ROOT_CONVERSATION_ID: Id = 1;\n\n/** JSON-safe error snapshot persisted instead of a runtime `Error` object. */\nexport type StoredError = {\n\treadonly message: string;\n\t/** Optional structured diagnostic data for inspection or recovery. */\n\treadonly detail?: JsonValue;\n};\n\n/** Immutable identity, history ancestry, and task ownership of a transcript scope. */\nexport type ConversationRecord = {\n\treadonly id: Id;\n\t/** Fork source and inclusive parent entry through which history is inherited. */\n\treadonly parent?: {\n\t\treadonly conversationId: Id;\n\t\treadonly at: Id;\n\t};\n\t/** Creator edge used for authorization, subtree abort, and subtree idle waits. */\n\treadonly owner?: {\n\t\treadonly conversationId: Id;\n\t\treadonly taskId: Id;\n\t};\n};\n\n/** An immutable override of one visible entry's contribution to model context. */\nexport type ContextEdit = {\n\t/** Entry whose model messages are omitted or replaced. */\n\treadonly target: Id;\n} & (\n\t| {\n\t\t\treadonly action: \"omit\";\n\t\t\treadonly messages?: never;\n\t }\n\t| {\n\t\t\treadonly action: \"replace\";\n\t\t\t/** Messages contributed instead of the target entry's model messages. */\n\t\t\treadonly messages: readonly Message[];\n\t }\n);\n\n/** Immutable transcript event with separate model-facing and application-facing payloads. */\nexport type EntryRecord = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Application-defined entry discriminator. */\n\treadonly kind: string;\n\t/** Messages contributed to model context; absent for display or bookkeeping entries. */\n\treadonly model?: readonly Message[];\n\t/** JSON payload consumed by views, plugins, or bookkeeping logic. */\n\treadonly data?: JsonValue;\n\t/** First entry in the active context selected by this entry. */\n\treadonly head?: Id;\n\t/** Context-only overrides of earlier visible entries. */\n\treadonly edits?: readonly ContextEdit[];\n\t/** Task that appended this entry, when it was produced by durable work. */\n\treadonly byTaskId?: Id;\n};\n\n/** Entry content supplied before the Session assigns identity and task attribution. */\nexport type EntryDraft = Omit<EntryRecord, \"id\" | \"conversationId\" | \"byTaskId\" | \"head\"> & {\n\t/** `\"self\"` starts active context at the newly assigned entry ID. */\n\treadonly head?: Id | \"self\";\n};\n\n/** Identity fields shared by every input lifecycle state. */\ntype InputBase = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Host-provided deduplication key, scoped to the conversation. */\n\treadonly requestId?: string;\n};\n\n/** Durable lifecycle of one admitted host input and the handle waiting for it. */\nexport type Input = InputBase &\n\t(\n\t\t| {\n\t\t\t\t/** Admitted but not yet represented in the transcript. */\n\t\t\t\treadonly status: \"queued\";\n\t\t\t\treadonly entry?: never;\n\t\t\t\treadonly answer?: never;\n\t\t\t\treadonly reason?: never;\n\t\t\t\treadonly detail?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Added to the transcript and owned by an active turn. */\n\t\t\t\treadonly status: \"placed\";\n\t\t\t\t/** User transcript entry created when this input was placed. */\n\t\t\t\treadonly entry: Id;\n\t\t\t\treadonly answer?: never;\n\t\t\t\treadonly reason?: never;\n\t\t\t\treadonly detail?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Successfully settled with a durable transcript result. */\n\t\t\t\treadonly status: \"done\";\n\t\t\t\t/** User or passive-write transcript entry created when this input was placed. */\n\t\t\t\treadonly entry: Id;\n\t\t\t\t/** Assistant answer entry; absent for a completed passive write. */\n\t\t\t\treadonly answer?: Id;\n\t\t\t\treadonly reason?: never;\n\t\t\t\treadonly detail?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Terminal input that can no longer receive an answer. */\n\t\t\t\treadonly status: \"unanswered\";\n\t\t\t\t/** Present when the input was placed before becoming unanswered. */\n\t\t\t\treadonly entry?: Id;\n\t\t\t\treadonly answer?: never;\n\t\t\t\t/** Stable machine-readable explanation such as `\"aborted\"` or `\"stale\"`. */\n\t\t\t\treadonly reason: string;\n\t\t\t\t/** Optional structured diagnostic data. */\n\t\t\t\treadonly detail?: JsonValue;\n\t\t }\n\t);\n\n/** Durable reason and optional result recorded when a task becomes terminal. */\nexport type TaskOutcome<R> =\n\t| {\n\t\t\treadonly status: \"completed\";\n\t\t\treadonly result: R;\n\t\t\treadonly error?: never;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Expected task or domain failure explicitly committed by its implementation. */\n\t| {\n\t\t\treadonly status: \"failed\";\n\t\t\treadonly error: StoredError;\n\t\t\treadonly result?: R;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Explicit cancellation handled by the task's abort protocol. */\n\t| {\n\t\t\treadonly status: \"aborted\";\n\t\t\treadonly reason?: string;\n\t\t\treadonly result?: R;\n\t\t\treadonly error?: never;\n\t }\n\t/** Task that cannot resume because its definition or migration is unavailable. */\n\t| {\n\t\t\treadonly status: \"orphaned\";\n\t\t\treadonly reason: string;\n\t\t\treadonly result?: never;\n\t\t\treadonly error?: never;\n\t }\n\t/** Runtime-detected contract failure, such as an uncaught throw or no durable progress. */\n\t| {\n\t\t\treadonly status: \"faulted\";\n\t\t\treadonly error: StoredError;\n\t\t\treadonly result?: never;\n\t\t\treadonly reason?: never;\n\t };\n\n/** Complete durable execution state of a task. */\nexport type TaskState<S, R> =\n\t| {\n\t\t\t/** Eligible for scheduling when its dependencies are terminal. */\n\t\t\treadonly status: \"pending\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Reserved by one in-memory task invocation. */\n\t\t\treadonly status: \"running\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Permanently settled durable result receipt. */\n\t\t\treadonly status: \"terminal\";\n\t\t\treadonly checkpoint?: never;\n\t\t\treadonly outcome: TaskOutcome<R>;\n\t };\n\n/** Identity, definition, and scheduling fields shared by every task state. */\ntype TaskRecordBase<I> = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Registered task definition name. */\n\treadonly kind: string;\n\t/** Definition version used to migrate live input and checkpoints. */\n\treadonly version: number;\n\t/** Original task input retained while the task is live or terminal. */\n\treadonly input: I;\n\t/** Tasks that must be terminal before ordinary execution may begin. */\n\treadonly after: readonly Id[];\n\t/** Whether this task is excluded from ordinary idle waits and conversation aborts. */\n\treadonly background: boolean;\n\t/** Durable abort mark checked before run-mode progress is committed. */\n\treadonly abortRequested: boolean;\n};\n\n/** Complete replacement record for one durable task state machine. */\nexport type TaskRecord<I, S, R> = TaskRecordBase<I> &\n\t(\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"pending\" | \"running\" }>;\n\t\t\t\t/** Small first-writer-wins values retained while the task is live. */\n\t\t\t\treadonly memos?: Readonly<Record<string, JsonValue>>;\n\t\t }\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"terminal\" }>;\n\t\t\t\treadonly memos?: never;\n\t\t }\n\t);\n\n/** Persisted lifecycle record for one create-to-retire document incarnation. */\nexport type DocumentRecord = {\n\t/** Unique incarnation ID; never reused when the same logical document is recreated. */\n\treadonly id: Id;\n\t/** Registered document kind. */\n\treadonly kind: string;\n\t/** Family member key; absent for singleton documents. */\n\treadonly key?: string;\n\t/** Commit that created the incarnation, stamped by storage. */\n\treadonly createdAt: Seq;\n\t/** Commit that retired the incarnation; absent while it is current. */\n\treadonly retiredAt?: Seq;\n} & (\n\t| {\n\t\t\treadonly scope: { readonly kind: \"session\" };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n\t| ({ readonly scope: { readonly kind: \"conversation\"; readonly conversationId: Id } } & (\n\t\t\t| {\n\t\t\t\t\t/** Retain only current state. */\n\t\t\t\t\treadonly history: \"latest\";\n\t\t\t\t\t/** Initialize a fork from current source state or the definition's initial value. */\n\t\t\t\t\treadonly fork: \"current\" | \"initial\";\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\t/** Retain history needed for as-of reads. */\n\t\t\t\t\treadonly history: \"rewindable\";\n\t\t\t\t\t/** Initialize a fork at its cutoff, from current state, or from the initial value. */\n\t\t\t\t\treadonly fork: \"asOf\" | \"current\" | \"initial\";\n\t\t\t }\n\t ))\n\t| {\n\t\t\treadonly scope: { readonly kind: \"task\"; readonly taskId: Id };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n);\n\n/** Fields supplied when storage creates and stamps a new `DocumentRecord`. */\nexport type DocumentCreate = DocumentRecord extends infer Record\n\t? Record extends DocumentRecord\n\t\t? Omit<Record, \"createdAt\" | \"retiredAt\">\n\t\t: never\n\t: never;\n\n/** One ordered scan result and its optional continuation state. */\nexport type Page<T, C> = {\n\treadonly items: readonly T[];\n\treadonly next?: C;\n};\n\n/** Backend-owned JSON continuation state that callers only round-trip to the same scan. */\nexport type Cursor = Readonly<Record<string, JsonValue>>;\n\n/** Inclusive ID bounds for a newest-first scan of one conversation's fork-aware history. */\nexport type EntryQuery = {\n\treadonly conversationId: Id;\n\t/** Oldest entry ID that may be returned. */\n\treadonly minEntryId?: Id;\n\t/** Newest entry ID that may be returned. */\n\treadonly maxEntryId?: Id;\n};\n\n/** Optional filters for an ordered scan of durable task records. */\nexport type TaskQuery = {\n\treadonly conversationId?: Id;\n\treadonly kind?: string;\n\treadonly status?: \"pending\" | \"running\" | \"terminal\";\n\treadonly abortRequested?: boolean;\n\treadonly background?: boolean;\n};\n\n/** One table mutation in an atomic storage commit; task and input writes replace whole records. */\nexport type StorageWrite =\n\t| { readonly type: \"conversation\"; readonly value: ConversationRecord }\n\t| { readonly type: \"entry\"; readonly value: EntryRecord }\n\t| { readonly type: \"task\"; readonly value: TaskRecord<JsonValue, JsonValue, JsonValue> }\n\t| { readonly type: \"input\"; readonly value: Input };\n\n/**\n * Atomic persistence boundary for Session records.\n *\n * Storage trusts the owning Session to supply semantically valid records, references,\n * ancestry, and transitions. Implementations enforce atomicity, global ID ownership,\n * immutable conversation/entry creation, and detached values; Session serializes commits.\n */\nexport interface Storage {\n\t/** Atomically persist one batch and return the sequence assigned to that commit. */\n\tcommit(writes: readonly StorageWrite[], context: Context): Promise<Seq>;\n\n\t/** Return a fresh candidate from the Session-global record ID namespace. */\n\tmintId(): Id;\n\n\t/** Look up one conversation by exact ID. */\n\tconversation(id: Id, context: Context): Promise<ConversationRecord | undefined>;\n\n\t/** Scan conversations in ascending ID order. */\n\tscanConversations(\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>>;\n\n\t/** Look up one global entry and the sequence of the commit that persisted it. */\n\tentry(id: Id, context: Context): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\n\t/**\n\t * Return the newest visible entry with a `head` at or below the optional inclusive cutoff.\n\t * The returned entry is the marker; its `head` value is the range's actual lower bound.\n\t */\n\tfindLatestHeadMarker(\n\t\tconversationId: Id,\n\t\tatOrBeforeEntryId: Id | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: Id }) | undefined>;\n\n\t/** Scan the inclusive visible range newest-first, returning at most `limit` entries. */\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\n\t/** Look up the latest complete record for one task. */\n\ttask(id: Id, context: Context): Promise<TaskRecord<JsonValue, JsonValue, JsonValue> | undefined>;\n\n\t/** Scan task records matching every supplied filter. */\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>>;\n\n\t/** Look up the latest complete record for one admitted input. */\n\tinput(id: Id, context: Context): Promise<Input | undefined>;\n\n\t/** Find an input by its conversation-scoped host deduplication key. */\n\tinputByRequest(conversationId: Id, requestId: string, context: Context): Promise<Input | undefined>;\n\n\t/** Release backend resources; all later operations must reject. */\n\tclose(context: Context): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,8DAA8D;AAC9D,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtD,sEAAsE;AACtE,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC;AAExB,8FAA8F;AAC9F,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB,0DAA0D;AAC1D,eAAO,MAAM,oBAAoB,EAAE,EAAM,CAAC;AAE1C,sFAAsF;AACtF,MAAM,MAAM,kBAAkB,GAAG;IAChC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE;QACjB,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC;QAC5B,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;KAChB,CAAC;IACF,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE;QAChB,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC;QAC5B,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;KACpB,CAAC;CACF,CAAC;AAEF,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,EAAE,CA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,CAAC,CAAC;IAEtE,sEAAsE;IACtE,UAAU,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IAE5E,2EAA2E;IAC3E,mBAAmB,CAAC,cAAc,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IAEpH,yFAAyF;IACzF,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;IAEjH,uHAAuH;IACvH,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;IAE3F,wEAAwE;IACxE,aAAa,CACZ,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IAEzC,mEAAmE;IACnE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type { Op } from \"@earendil-works/chord/delta\";\nimport type { Message } from \"@earendil-works/pi-ai\";\n\n/** JSON object used as the root of every durable document. */\nexport type JsonObject = { [key: string]: JsonValue };\n\n/** Session-global identifier shared by every durable record table. */\nexport type Id = number;\n\n/** Strictly increasing sequence assigned to one atomic storage commit; gaps are permitted. */\nexport type Seq = number;\n\n/** The root conversation always uses this reserved ID. */\nexport const ROOT_CONVERSATION_ID: Id = 1;\n\n/** Immutable identity, history ancestry, and task ownership of a transcript scope. */\nexport type ConversationRecord = {\n\treadonly id: Id;\n\t/** Fork source and inclusive parent entry through which history is inherited. */\n\treadonly parent?: {\n\t\treadonly conversationId: Id;\n\t\treadonly at: Id;\n\t};\n\t/** Creator edge used for authorization, subtree abort, and subtree idle waits. */\n\treadonly owner?: {\n\t\treadonly conversationId: Id;\n\t\treadonly taskId: Id;\n\t};\n};\n\n/** An immutable override of one visible entry's contribution to model context. */\nexport type ContextEdit = {\n\t/** Entry whose model messages are omitted or replaced. */\n\treadonly target: Id;\n} & (\n\t| {\n\t\t\treadonly action: \"omit\";\n\t\t\treadonly messages?: never;\n\t }\n\t| {\n\t\t\treadonly action: \"replace\";\n\t\t\t/** Messages contributed instead of the target entry's model messages. */\n\t\t\treadonly messages: readonly Message[];\n\t }\n);\n\n/** Immutable transcript event with separate model-facing and application-facing payloads. */\nexport type EntryRecord = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Application-defined entry discriminator. */\n\treadonly kind: string;\n\t/** Messages contributed to model context; absent for display or bookkeeping entries. */\n\treadonly model?: readonly Message[];\n\t/** JSON payload consumed by views, extensions, or bookkeeping logic. */\n\treadonly data?: JsonValue;\n\t/** First entry in the active context selected by this entry. */\n\treadonly head?: Id;\n\t/** Context-only overrides of earlier visible entries. */\n\treadonly edits?: readonly ContextEdit[];\n\t/** Task that appended this entry, when it was produced by durable work. */\n\treadonly byTaskId?: Id;\n};\n\n/** Entry content supplied before the Session assigns identity and task attribution. */\nexport type EntryDraft = Omit<EntryRecord, \"id\" | \"conversationId\" | \"byTaskId\" | \"head\"> & {\n\t/** `\"self\"` starts active context at the newly assigned entry ID. */\n\treadonly head?: Id | \"self\";\n};\n\n/** Identity fields shared by every durable submission state. */\ntype SubmissionRecordBase = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Host-provided deduplication key, scoped to the conversation. */\n\treadonly requestId?: string;\n};\n\n/** Durable lifecycle of one admitted user input or passive entry write. */\nexport type SubmissionRecord =\n\t| (SubmissionRecordBase & {\n\t\t\treadonly type: \"input\";\n\t } & (\n\t\t\t\t| {\n\t\t\t\t\t\t/** Admitted but not yet represented in the transcript. */\n\t\t\t\t\t\treadonly status: \"queued\";\n\t\t\t\t\t\treadonly entry?: never;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Added to the transcript and owned by an active turn. */\n\t\t\t\t\t\treadonly status: \"placed\";\n\t\t\t\t\t\treadonly entry: Id;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Successfully answered user input. */\n\t\t\t\t\t\treadonly status: \"done\";\n\t\t\t\t\t\treadonly entry: Id;\n\t\t\t\t\t\treadonly answer: Id;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Terminal input that can no longer receive an answer. */\n\t\t\t\t\t\treadonly status: \"unanswered\";\n\t\t\t\t\t\treadonly entry?: Id;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason: string;\n\t\t\t\t\t\treadonly detail?: JsonValue;\n\t\t\t\t }\n\t\t\t))\n\t| (SubmissionRecordBase & {\n\t\t\treadonly type: \"write\";\n\t } & (\n\t\t\t\t| {\n\t\t\t\t\t\t/** Admitted but not yet appended to the transcript. */\n\t\t\t\t\t\treadonly status: \"queued\";\n\t\t\t\t\t\treadonly entry?: never;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Successfully appended passive entry. */\n\t\t\t\t\t\treadonly status: \"done\";\n\t\t\t\t\t\treadonly entry: Id;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Terminal passive write that could not be placed. */\n\t\t\t\t\t\treadonly status: \"unanswered\";\n\t\t\t\t\t\treadonly entry?: never;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason: string;\n\t\t\t\t\t\treadonly detail?: JsonValue;\n\t\t\t\t }\n\t\t\t));\n\n/** Submission fields supplied before the Session assigns an ID. */\nexport type SubmissionCreate = SubmissionRecord extends infer Record\n\t? Record extends SubmissionRecord\n\t\t? Omit<Record, \"id\">\n\t\t: never\n\t: never;\n\n/** JSON-safe error snapshot persisted instead of a runtime `Error` object. */\nexport type TaskOutcomeError = {\n\treadonly message: string;\n\t/** Optional structured diagnostic data for inspection or recovery. */\n\treadonly detail?: JsonValue;\n};\n\n/** Durable reason and optional result recorded when a task becomes terminal. */\nexport type TaskOutcome<R> =\n\t| {\n\t\t\treadonly status: \"completed\";\n\t\t\treadonly result: R;\n\t\t\treadonly error?: never;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Expected task or domain failure explicitly committed by its implementation. */\n\t| {\n\t\t\treadonly status: \"failed\";\n\t\t\treadonly error: TaskOutcomeError;\n\t\t\treadonly result?: R;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Explicit cancellation handled by the task's abort protocol. */\n\t| {\n\t\t\treadonly status: \"aborted\";\n\t\t\treadonly reason?: string;\n\t\t\treadonly result?: R;\n\t\t\treadonly error?: never;\n\t }\n\t/** Task that cannot resume because its definition or migration is unavailable. */\n\t| {\n\t\t\treadonly status: \"orphaned\";\n\t\t\treadonly reason: string;\n\t\t\treadonly result?: never;\n\t\t\treadonly error?: never;\n\t }\n\t/** Runtime-detected contract failure, such as an uncaught throw or no durable progress. */\n\t| {\n\t\t\treadonly status: \"faulted\";\n\t\t\treadonly error: TaskOutcomeError;\n\t\t\treadonly result?: never;\n\t\t\treadonly reason?: never;\n\t };\n\n/** Complete durable execution state of a task. */\nexport type TaskState<S, R> =\n\t| {\n\t\t\t/** Eligible for scheduling when its dependencies are terminal. */\n\t\t\treadonly status: \"pending\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Reserved by one in-memory task invocation. */\n\t\t\treadonly status: \"running\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Permanently settled durable result receipt. */\n\t\t\treadonly status: \"terminal\";\n\t\t\treadonly checkpoint?: never;\n\t\t\treadonly outcome: TaskOutcome<R>;\n\t };\n\n/** Identity, definition, and scheduling fields shared by every task state. */\ntype TaskRecordBase<I> = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Registered task definition name. */\n\treadonly kind: string;\n\t/** Definition version used to migrate live input and checkpoints. */\n\treadonly version: number;\n\t/** Original task input retained while the task is live or terminal. */\n\treadonly input: I;\n\t/** Tasks that must be terminal before ordinary execution may begin. */\n\treadonly after: readonly Id[];\n\t/** Whether this task is excluded from ordinary idle waits and conversation aborts. */\n\treadonly background: boolean;\n\t/** Durable abort mark checked before run-mode progress is committed. */\n\treadonly abortRequested: boolean;\n};\n\n/** Complete replacement record for one durable task state machine. */\nexport type TaskRecord<I, S, R> = TaskRecordBase<I> &\n\t(\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"pending\" | \"running\" }>;\n\t\t\t\t/** Small first-writer-wins values retained while the task is live. */\n\t\t\t\treadonly memos?: Readonly<Record<string, JsonValue>>;\n\t\t }\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"terminal\" }>;\n\t\t\t\treadonly memos?: never;\n\t\t }\n\t);\n\n/** Persisted lifecycle record for one create-to-retire document incarnation. */\nexport type DocumentRecord = {\n\t/** Unique incarnation ID; never reused when the same logical document is recreated. */\n\treadonly id: Id;\n\t/** Stable document definition kind. */\n\treadonly kind: string;\n\t/** Family member key; absent for singleton documents. */\n\treadonly key?: string;\n\t/** Commit that created the incarnation, stamped by storage. */\n\treadonly createdAt: Seq;\n\t/** Commit that retired the incarnation; absent while it is current. */\n\treadonly retiredAt?: Seq;\n} & (\n\t| {\n\t\t\treadonly scope: { readonly kind: \"session\" };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n\t| ({ readonly scope: { readonly kind: \"conversation\"; readonly conversationId: Id } } & (\n\t\t\t| {\n\t\t\t\t\t/** Retain only current state. */\n\t\t\t\t\treadonly history: \"latest\";\n\t\t\t\t\t/** Initialize a fork from current source state or the definition's initial value. */\n\t\t\t\t\treadonly fork: \"current\" | \"initial\";\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\t/** Retain history needed for as-of reads. */\n\t\t\t\t\treadonly history: \"rewindable\";\n\t\t\t\t\t/** Initialize a fork at its cutoff, from current state, or from the initial value. */\n\t\t\t\t\treadonly fork: \"asOf\" | \"current\" | \"initial\";\n\t\t\t }\n\t ))\n\t| {\n\t\t\treadonly scope: { readonly kind: \"task\"; readonly taskId: Id };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n);\n\n/** Fields supplied when storage creates and stamps a new `DocumentRecord`. */\nexport type DocumentCreate = DocumentRecord extends infer Record\n\t? Record extends DocumentRecord\n\t\t? Omit<Record, \"createdAt\" | \"retiredAt\">\n\t\t: never\n\t: never;\n\n/** One ordered scan result and its optional continuation state. */\nexport type Page<T, C> = {\n\treadonly items: readonly T[];\n\treadonly next?: C;\n};\n\n/** Backend-owned JSON continuation state that callers only round-trip to the same scan. */\nexport type Cursor = Readonly<Record<string, JsonValue>>;\n\n/** Inclusive ID bounds for a newest-first scan of one conversation's fork-aware history. */\nexport type EntryQuery = {\n\treadonly conversationId: Id;\n\t/** Oldest entry ID that may be returned. */\n\treadonly minEntryId?: Id;\n\t/** Newest entry ID that may be returned. */\n\treadonly maxEntryId?: Id;\n};\n\n/** Optional filters for an ordered scan of durable task records. */\nexport type TaskQuery = {\n\treadonly conversationId?: Id;\n\treadonly kind?: string;\n\treadonly status?: \"pending\" | \"running\" | \"terminal\";\n\treadonly abortRequested?: boolean;\n\treadonly background?: boolean;\n};\n\n/** Current state or one historical commit sequence used for document membership and content reads. */\nexport type DocumentPoint = Seq | \"current\";\n\n/** Exact logical identity of a singleton or one keyed family member. */\nexport type DocumentAddress = {\n\treadonly kind: string;\n\treadonly scope: DocumentRecord[\"scope\"];\n\t/** Absent selects the singleton; present selects one family member. */\n\treadonly key?: string;\n};\n\n/** Ordered scan of document incarnations alive in one exact scope at one point. */\nexport type DocumentQuery = {\n\treadonly scope: DocumentRecord[\"scope\"];\n\treadonly at: DocumentPoint;\n\treadonly kind?: string;\n};\n\n/** Complete checkpoint or Chord operation batch selected by the owning Session. */\nexport type DocumentContent =\n\t| {\n\t\t\treadonly version: number;\n\t\t\treadonly kind: \"base\";\n\t\t\treadonly value: JsonObject;\n\t }\n\t| {\n\t\t\treadonly version: number;\n\t\t\treadonly kind: \"delta\";\n\t\t\treadonly ops: readonly Op[];\n\t };\n\n/** Detached materialized value and stored definition version at a selected point. */\nexport type StoredDocument = {\n\treadonly record: DocumentRecord;\n\treadonly version: number;\n\treadonly value: JsonObject;\n};\n\n/** One record or document mutation in an atomic storage commit. */\nexport type StorageWrite =\n\t| { readonly type: \"conversation\"; readonly value: ConversationRecord }\n\t| { readonly type: \"entry\"; readonly value: EntryRecord }\n\t| { readonly type: \"task\"; readonly value: TaskRecord<JsonValue, JsonValue, JsonValue> }\n\t| { readonly type: \"submission\"; readonly value: SubmissionRecord }\n\t| {\n\t\t\treadonly type: \"document.create\";\n\t\t\treadonly record: DocumentCreate;\n\t\t\treadonly content: Extract<DocumentContent, { readonly kind: \"base\" }>;\n\t }\n\t| {\n\t\t\treadonly type: \"document.change\";\n\t\t\treadonly id: Id;\n\t\t\treadonly content: DocumentContent;\n\t }\n\t| { readonly type: \"document.retire\"; readonly id: Id };\n\n/**\n * Atomic persistence boundary for Session records.\n *\n * Storage trusts the owning Session to supply semantically valid records, references,\n * ancestry, and transitions. Implementations enforce atomicity, global ID ownership,\n * immutable conversation/entry creation, document record consistency, and detached values;\n * Session serializes commits.\n */\nexport interface Storage {\n\t/**\n\t * Atomically persist one batch and return its sequence. Once resolved, later reads through this storage observe it.\n\t */\n\tcommit(writes: readonly StorageWrite[], context: Context): Promise<Seq>;\n\n\t/** Return a fresh candidate from the Session-global record ID namespace. */\n\tmintId(): Promise<Id>;\n\n\t/** Look up one conversation by exact ID. */\n\tconversation(id: Id, context: Context): Promise<ConversationRecord | undefined>;\n\n\t/** Scan conversations in ascending ID order. */\n\tscanConversations(\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>>;\n\n\t/** Look up one global entry and the sequence of the commit that persisted it. */\n\tentry(id: Id, context: Context): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\n\t/**\n\t * Return the newest visible entry with a `head` at or below the optional inclusive cutoff.\n\t * The returned entry is the marker; its `head` value is the range's actual lower bound.\n\t */\n\tfindLatestHeadMarker(\n\t\tconversationId: Id,\n\t\tatOrBeforeEntryId: Id | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: Id }) | undefined>;\n\n\t/** Scan the inclusive visible range newest-first, returning at most `limit` entries. */\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\n\t/** Look up the latest complete record for one task. */\n\ttask(id: Id, context: Context): Promise<TaskRecord<JsonValue, JsonValue, JsonValue> | undefined>;\n\n\t/** Scan task records matching every supplied filter. */\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>>;\n\n\t/** Look up the latest complete record for one admitted submission. */\n\tsubmission(id: Id, context: Context): Promise<SubmissionRecord | undefined>;\n\n\t/** Find a submission by its conversation-scoped host deduplication key. */\n\tsubmissionByRequest(conversationId: Id, requestId: string, context: Context): Promise<SubmissionRecord | undefined>;\n\n\t/** Resolve the incarnation occupying one exact logical address at the selected point. */\n\tfindDocument(address: DocumentAddress, at: DocumentPoint, context: Context): Promise<DocumentRecord | undefined>;\n\n\t/** Materialize one specific incarnation by ID at the selected point without following a replacement at its address. */\n\tdocument(id: Id, at: DocumentPoint, context: Context): Promise<StoredDocument | undefined>;\n\n\t/** Scan incarnations alive in one exact scope at the selected point. */\n\tscanDocuments(\n\t\tquery: DocumentQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<DocumentRecord, Cursor>>;\n\n\t/** Release backend resources; all later operations must reject. */\n\tclose(context: Context): Promise<void>;\n}\n"]}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AASA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAO,CAAC,CAAC","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type { Message } from \"@earendil-works/pi-ai\";\n\n/** Session-global identifier shared by every durable record table. */\nexport type Id = number;\n\n/** Monotonic sequence assigned to one atomic storage commit. */\nexport type Seq = number;\n\n/** The root conversation always uses this reserved ID. */\nexport const ROOT_CONVERSATION_ID: Id = 1;\n\n/** JSON-safe error snapshot persisted instead of a runtime `Error` object. */\nexport type StoredError = {\n\treadonly message: string;\n\t/** Optional structured diagnostic data for inspection or recovery. */\n\treadonly detail?: JsonValue;\n};\n\n/** Immutable identity, history ancestry, and task ownership of a transcript scope. */\nexport type ConversationRecord = {\n\treadonly id: Id;\n\t/** Fork source and inclusive parent entry through which history is inherited. */\n\treadonly parent?: {\n\t\treadonly conversationId: Id;\n\t\treadonly at: Id;\n\t};\n\t/** Creator edge used for authorization, subtree abort, and subtree idle waits. */\n\treadonly owner?: {\n\t\treadonly conversationId: Id;\n\t\treadonly taskId: Id;\n\t};\n};\n\n/** An immutable override of one visible entry's contribution to model context. */\nexport type ContextEdit = {\n\t/** Entry whose model messages are omitted or replaced. */\n\treadonly target: Id;\n} & (\n\t| {\n\t\t\treadonly action: \"omit\";\n\t\t\treadonly messages?: never;\n\t }\n\t| {\n\t\t\treadonly action: \"replace\";\n\t\t\t/** Messages contributed instead of the target entry's model messages. */\n\t\t\treadonly messages: readonly Message[];\n\t }\n);\n\n/** Immutable transcript event with separate model-facing and application-facing payloads. */\nexport type EntryRecord = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Application-defined entry discriminator. */\n\treadonly kind: string;\n\t/** Messages contributed to model context; absent for display or bookkeeping entries. */\n\treadonly model?: readonly Message[];\n\t/** JSON payload consumed by views, plugins, or bookkeeping logic. */\n\treadonly data?: JsonValue;\n\t/** First entry in the active context selected by this entry. */\n\treadonly head?: Id;\n\t/** Context-only overrides of earlier visible entries. */\n\treadonly edits?: readonly ContextEdit[];\n\t/** Task that appended this entry, when it was produced by durable work. */\n\treadonly byTaskId?: Id;\n};\n\n/** Entry content supplied before the Session assigns identity and task attribution. */\nexport type EntryDraft = Omit<EntryRecord, \"id\" | \"conversationId\" | \"byTaskId\" | \"head\"> & {\n\t/** `\"self\"` starts active context at the newly assigned entry ID. */\n\treadonly head?: Id | \"self\";\n};\n\n/** Identity fields shared by every input lifecycle state. */\ntype InputBase = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Host-provided deduplication key, scoped to the conversation. */\n\treadonly requestId?: string;\n};\n\n/** Durable lifecycle of one admitted host input and the handle waiting for it. */\nexport type Input = InputBase &\n\t(\n\t\t| {\n\t\t\t\t/** Admitted but not yet represented in the transcript. */\n\t\t\t\treadonly status: \"queued\";\n\t\t\t\treadonly entry?: never;\n\t\t\t\treadonly answer?: never;\n\t\t\t\treadonly reason?: never;\n\t\t\t\treadonly detail?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Added to the transcript and owned by an active turn. */\n\t\t\t\treadonly status: \"placed\";\n\t\t\t\t/** User transcript entry created when this input was placed. */\n\t\t\t\treadonly entry: Id;\n\t\t\t\treadonly answer?: never;\n\t\t\t\treadonly reason?: never;\n\t\t\t\treadonly detail?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Successfully settled with a durable transcript result. */\n\t\t\t\treadonly status: \"done\";\n\t\t\t\t/** User or passive-write transcript entry created when this input was placed. */\n\t\t\t\treadonly entry: Id;\n\t\t\t\t/** Assistant answer entry; absent for a completed passive write. */\n\t\t\t\treadonly answer?: Id;\n\t\t\t\treadonly reason?: never;\n\t\t\t\treadonly detail?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Terminal input that can no longer receive an answer. */\n\t\t\t\treadonly status: \"unanswered\";\n\t\t\t\t/** Present when the input was placed before becoming unanswered. */\n\t\t\t\treadonly entry?: Id;\n\t\t\t\treadonly answer?: never;\n\t\t\t\t/** Stable machine-readable explanation such as `\"aborted\"` or `\"stale\"`. */\n\t\t\t\treadonly reason: string;\n\t\t\t\t/** Optional structured diagnostic data. */\n\t\t\t\treadonly detail?: JsonValue;\n\t\t }\n\t);\n\n/** Durable reason and optional result recorded when a task becomes terminal. */\nexport type TaskOutcome<R> =\n\t| {\n\t\t\treadonly status: \"completed\";\n\t\t\treadonly result: R;\n\t\t\treadonly error?: never;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Expected task or domain failure explicitly committed by its implementation. */\n\t| {\n\t\t\treadonly status: \"failed\";\n\t\t\treadonly error: StoredError;\n\t\t\treadonly result?: R;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Explicit cancellation handled by the task's abort protocol. */\n\t| {\n\t\t\treadonly status: \"aborted\";\n\t\t\treadonly reason?: string;\n\t\t\treadonly result?: R;\n\t\t\treadonly error?: never;\n\t }\n\t/** Task that cannot resume because its definition or migration is unavailable. */\n\t| {\n\t\t\treadonly status: \"orphaned\";\n\t\t\treadonly reason: string;\n\t\t\treadonly result?: never;\n\t\t\treadonly error?: never;\n\t }\n\t/** Runtime-detected contract failure, such as an uncaught throw or no durable progress. */\n\t| {\n\t\t\treadonly status: \"faulted\";\n\t\t\treadonly error: StoredError;\n\t\t\treadonly result?: never;\n\t\t\treadonly reason?: never;\n\t };\n\n/** Complete durable execution state of a task. */\nexport type TaskState<S, R> =\n\t| {\n\t\t\t/** Eligible for scheduling when its dependencies are terminal. */\n\t\t\treadonly status: \"pending\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Reserved by one in-memory task invocation. */\n\t\t\treadonly status: \"running\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Permanently settled durable result receipt. */\n\t\t\treadonly status: \"terminal\";\n\t\t\treadonly checkpoint?: never;\n\t\t\treadonly outcome: TaskOutcome<R>;\n\t };\n\n/** Identity, definition, and scheduling fields shared by every task state. */\ntype TaskRecordBase<I> = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Registered task definition name. */\n\treadonly kind: string;\n\t/** Definition version used to migrate live input and checkpoints. */\n\treadonly version: number;\n\t/** Original task input retained while the task is live or terminal. */\n\treadonly input: I;\n\t/** Tasks that must be terminal before ordinary execution may begin. */\n\treadonly after: readonly Id[];\n\t/** Whether this task is excluded from ordinary idle waits and conversation aborts. */\n\treadonly background: boolean;\n\t/** Durable abort mark checked before run-mode progress is committed. */\n\treadonly abortRequested: boolean;\n};\n\n/** Complete replacement record for one durable task state machine. */\nexport type TaskRecord<I, S, R> = TaskRecordBase<I> &\n\t(\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"pending\" | \"running\" }>;\n\t\t\t\t/** Small first-writer-wins values retained while the task is live. */\n\t\t\t\treadonly memos?: Readonly<Record<string, JsonValue>>;\n\t\t }\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"terminal\" }>;\n\t\t\t\treadonly memos?: never;\n\t\t }\n\t);\n\n/** Persisted lifecycle record for one create-to-retire document incarnation. */\nexport type DocumentRecord = {\n\t/** Unique incarnation ID; never reused when the same logical document is recreated. */\n\treadonly id: Id;\n\t/** Registered document kind. */\n\treadonly kind: string;\n\t/** Family member key; absent for singleton documents. */\n\treadonly key?: string;\n\t/** Commit that created the incarnation, stamped by storage. */\n\treadonly createdAt: Seq;\n\t/** Commit that retired the incarnation; absent while it is current. */\n\treadonly retiredAt?: Seq;\n} & (\n\t| {\n\t\t\treadonly scope: { readonly kind: \"session\" };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n\t| ({ readonly scope: { readonly kind: \"conversation\"; readonly conversationId: Id } } & (\n\t\t\t| {\n\t\t\t\t\t/** Retain only current state. */\n\t\t\t\t\treadonly history: \"latest\";\n\t\t\t\t\t/** Initialize a fork from current source state or the definition's initial value. */\n\t\t\t\t\treadonly fork: \"current\" | \"initial\";\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\t/** Retain history needed for as-of reads. */\n\t\t\t\t\treadonly history: \"rewindable\";\n\t\t\t\t\t/** Initialize a fork at its cutoff, from current state, or from the initial value. */\n\t\t\t\t\treadonly fork: \"asOf\" | \"current\" | \"initial\";\n\t\t\t }\n\t ))\n\t| {\n\t\t\treadonly scope: { readonly kind: \"task\"; readonly taskId: Id };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n);\n\n/** Fields supplied when storage creates and stamps a new `DocumentRecord`. */\nexport type DocumentCreate = DocumentRecord extends infer Record\n\t? Record extends DocumentRecord\n\t\t? Omit<Record, \"createdAt\" | \"retiredAt\">\n\t\t: never\n\t: never;\n\n/** One ordered scan result and its optional continuation state. */\nexport type Page<T, C> = {\n\treadonly items: readonly T[];\n\treadonly next?: C;\n};\n\n/** Backend-owned JSON continuation state that callers only round-trip to the same scan. */\nexport type Cursor = Readonly<Record<string, JsonValue>>;\n\n/** Inclusive ID bounds for a newest-first scan of one conversation's fork-aware history. */\nexport type EntryQuery = {\n\treadonly conversationId: Id;\n\t/** Oldest entry ID that may be returned. */\n\treadonly minEntryId?: Id;\n\t/** Newest entry ID that may be returned. */\n\treadonly maxEntryId?: Id;\n};\n\n/** Optional filters for an ordered scan of durable task records. */\nexport type TaskQuery = {\n\treadonly conversationId?: Id;\n\treadonly kind?: string;\n\treadonly status?: \"pending\" | \"running\" | \"terminal\";\n\treadonly abortRequested?: boolean;\n\treadonly background?: boolean;\n};\n\n/** One table mutation in an atomic storage commit; task and input writes replace whole records. */\nexport type StorageWrite =\n\t| { readonly type: \"conversation\"; readonly value: ConversationRecord }\n\t| { readonly type: \"entry\"; readonly value: EntryRecord }\n\t| { readonly type: \"task\"; readonly value: TaskRecord<JsonValue, JsonValue, JsonValue> }\n\t| { readonly type: \"input\"; readonly value: Input };\n\n/**\n * Atomic persistence boundary for Session records.\n *\n * Storage trusts the owning Session to supply semantically valid records, references,\n * ancestry, and transitions. Implementations enforce atomicity, global ID ownership,\n * immutable conversation/entry creation, and detached values; Session serializes commits.\n */\nexport interface Storage {\n\t/** Atomically persist one batch and return the sequence assigned to that commit. */\n\tcommit(writes: readonly StorageWrite[], context: Context): Promise<Seq>;\n\n\t/** Return a fresh candidate from the Session-global record ID namespace. */\n\tmintId(): Id;\n\n\t/** Look up one conversation by exact ID. */\n\tconversation(id: Id, context: Context): Promise<ConversationRecord | undefined>;\n\n\t/** Scan conversations in ascending ID order. */\n\tscanConversations(\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>>;\n\n\t/** Look up one global entry and the sequence of the commit that persisted it. */\n\tentry(id: Id, context: Context): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\n\t/**\n\t * Return the newest visible entry with a `head` at or below the optional inclusive cutoff.\n\t * The returned entry is the marker; its `head` value is the range's actual lower bound.\n\t */\n\tfindLatestHeadMarker(\n\t\tconversationId: Id,\n\t\tatOrBeforeEntryId: Id | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: Id }) | undefined>;\n\n\t/** Scan the inclusive visible range newest-first, returning at most `limit` entries. */\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\n\t/** Look up the latest complete record for one task. */\n\ttask(id: Id, context: Context): Promise<TaskRecord<JsonValue, JsonValue, JsonValue> | undefined>;\n\n\t/** Scan task records matching every supplied filter. */\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>>;\n\n\t/** Look up the latest complete record for one admitted input. */\n\tinput(id: Id, context: Context): Promise<Input | undefined>;\n\n\t/** Find an input by its conversation-scoped host deduplication key. */\n\tinputByRequest(conversationId: Id, requestId: string, context: Context): Promise<Input | undefined>;\n\n\t/** Release backend resources; all later operations must reject. */\n\tclose(context: Context): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAO,CAAC,CAAC","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type { Op } from \"@earendil-works/chord/delta\";\nimport type { Message } from \"@earendil-works/pi-ai\";\n\n/** JSON object used as the root of every durable document. */\nexport type JsonObject = { [key: string]: JsonValue };\n\n/** Session-global identifier shared by every durable record table. */\nexport type Id = number;\n\n/** Strictly increasing sequence assigned to one atomic storage commit; gaps are permitted. */\nexport type Seq = number;\n\n/** The root conversation always uses this reserved ID. */\nexport const ROOT_CONVERSATION_ID: Id = 1;\n\n/** Immutable identity, history ancestry, and task ownership of a transcript scope. */\nexport type ConversationRecord = {\n\treadonly id: Id;\n\t/** Fork source and inclusive parent entry through which history is inherited. */\n\treadonly parent?: {\n\t\treadonly conversationId: Id;\n\t\treadonly at: Id;\n\t};\n\t/** Creator edge used for authorization, subtree abort, and subtree idle waits. */\n\treadonly owner?: {\n\t\treadonly conversationId: Id;\n\t\treadonly taskId: Id;\n\t};\n};\n\n/** An immutable override of one visible entry's contribution to model context. */\nexport type ContextEdit = {\n\t/** Entry whose model messages are omitted or replaced. */\n\treadonly target: Id;\n} & (\n\t| {\n\t\t\treadonly action: \"omit\";\n\t\t\treadonly messages?: never;\n\t }\n\t| {\n\t\t\treadonly action: \"replace\";\n\t\t\t/** Messages contributed instead of the target entry's model messages. */\n\t\t\treadonly messages: readonly Message[];\n\t }\n);\n\n/** Immutable transcript event with separate model-facing and application-facing payloads. */\nexport type EntryRecord = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Application-defined entry discriminator. */\n\treadonly kind: string;\n\t/** Messages contributed to model context; absent for display or bookkeeping entries. */\n\treadonly model?: readonly Message[];\n\t/** JSON payload consumed by views, extensions, or bookkeeping logic. */\n\treadonly data?: JsonValue;\n\t/** First entry in the active context selected by this entry. */\n\treadonly head?: Id;\n\t/** Context-only overrides of earlier visible entries. */\n\treadonly edits?: readonly ContextEdit[];\n\t/** Task that appended this entry, when it was produced by durable work. */\n\treadonly byTaskId?: Id;\n};\n\n/** Entry content supplied before the Session assigns identity and task attribution. */\nexport type EntryDraft = Omit<EntryRecord, \"id\" | \"conversationId\" | \"byTaskId\" | \"head\"> & {\n\t/** `\"self\"` starts active context at the newly assigned entry ID. */\n\treadonly head?: Id | \"self\";\n};\n\n/** Identity fields shared by every durable submission state. */\ntype SubmissionRecordBase = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Host-provided deduplication key, scoped to the conversation. */\n\treadonly requestId?: string;\n};\n\n/** Durable lifecycle of one admitted user input or passive entry write. */\nexport type SubmissionRecord =\n\t| (SubmissionRecordBase & {\n\t\t\treadonly type: \"input\";\n\t } & (\n\t\t\t\t| {\n\t\t\t\t\t\t/** Admitted but not yet represented in the transcript. */\n\t\t\t\t\t\treadonly status: \"queued\";\n\t\t\t\t\t\treadonly entry?: never;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Added to the transcript and owned by an active turn. */\n\t\t\t\t\t\treadonly status: \"placed\";\n\t\t\t\t\t\treadonly entry: Id;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Successfully answered user input. */\n\t\t\t\t\t\treadonly status: \"done\";\n\t\t\t\t\t\treadonly entry: Id;\n\t\t\t\t\t\treadonly answer: Id;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Terminal input that can no longer receive an answer. */\n\t\t\t\t\t\treadonly status: \"unanswered\";\n\t\t\t\t\t\treadonly entry?: Id;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason: string;\n\t\t\t\t\t\treadonly detail?: JsonValue;\n\t\t\t\t }\n\t\t\t))\n\t| (SubmissionRecordBase & {\n\t\t\treadonly type: \"write\";\n\t } & (\n\t\t\t\t| {\n\t\t\t\t\t\t/** Admitted but not yet appended to the transcript. */\n\t\t\t\t\t\treadonly status: \"queued\";\n\t\t\t\t\t\treadonly entry?: never;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Successfully appended passive entry. */\n\t\t\t\t\t\treadonly status: \"done\";\n\t\t\t\t\t\treadonly entry: Id;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason?: never;\n\t\t\t\t\t\treadonly detail?: never;\n\t\t\t\t }\n\t\t\t\t| {\n\t\t\t\t\t\t/** Terminal passive write that could not be placed. */\n\t\t\t\t\t\treadonly status: \"unanswered\";\n\t\t\t\t\t\treadonly entry?: never;\n\t\t\t\t\t\treadonly answer?: never;\n\t\t\t\t\t\treadonly reason: string;\n\t\t\t\t\t\treadonly detail?: JsonValue;\n\t\t\t\t }\n\t\t\t));\n\n/** Submission fields supplied before the Session assigns an ID. */\nexport type SubmissionCreate = SubmissionRecord extends infer Record\n\t? Record extends SubmissionRecord\n\t\t? Omit<Record, \"id\">\n\t\t: never\n\t: never;\n\n/** JSON-safe error snapshot persisted instead of a runtime `Error` object. */\nexport type TaskOutcomeError = {\n\treadonly message: string;\n\t/** Optional structured diagnostic data for inspection or recovery. */\n\treadonly detail?: JsonValue;\n};\n\n/** Durable reason and optional result recorded when a task becomes terminal. */\nexport type TaskOutcome<R> =\n\t| {\n\t\t\treadonly status: \"completed\";\n\t\t\treadonly result: R;\n\t\t\treadonly error?: never;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Expected task or domain failure explicitly committed by its implementation. */\n\t| {\n\t\t\treadonly status: \"failed\";\n\t\t\treadonly error: TaskOutcomeError;\n\t\t\treadonly result?: R;\n\t\t\treadonly reason?: never;\n\t }\n\t/** Explicit cancellation handled by the task's abort protocol. */\n\t| {\n\t\t\treadonly status: \"aborted\";\n\t\t\treadonly reason?: string;\n\t\t\treadonly result?: R;\n\t\t\treadonly error?: never;\n\t }\n\t/** Task that cannot resume because its definition or migration is unavailable. */\n\t| {\n\t\t\treadonly status: \"orphaned\";\n\t\t\treadonly reason: string;\n\t\t\treadonly result?: never;\n\t\t\treadonly error?: never;\n\t }\n\t/** Runtime-detected contract failure, such as an uncaught throw or no durable progress. */\n\t| {\n\t\t\treadonly status: \"faulted\";\n\t\t\treadonly error: TaskOutcomeError;\n\t\t\treadonly result?: never;\n\t\t\treadonly reason?: never;\n\t };\n\n/** Complete durable execution state of a task. */\nexport type TaskState<S, R> =\n\t| {\n\t\t\t/** Eligible for scheduling when its dependencies are terminal. */\n\t\t\treadonly status: \"pending\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Reserved by one in-memory task invocation. */\n\t\t\treadonly status: \"running\";\n\t\t\t/** Complete durable state from which execution resumes. */\n\t\t\treadonly checkpoint: S;\n\t\t\treadonly outcome?: never;\n\t }\n\t| {\n\t\t\t/** Permanently settled durable result receipt. */\n\t\t\treadonly status: \"terminal\";\n\t\t\treadonly checkpoint?: never;\n\t\t\treadonly outcome: TaskOutcome<R>;\n\t };\n\n/** Identity, definition, and scheduling fields shared by every task state. */\ntype TaskRecordBase<I> = {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\t/** Registered task definition name. */\n\treadonly kind: string;\n\t/** Definition version used to migrate live input and checkpoints. */\n\treadonly version: number;\n\t/** Original task input retained while the task is live or terminal. */\n\treadonly input: I;\n\t/** Tasks that must be terminal before ordinary execution may begin. */\n\treadonly after: readonly Id[];\n\t/** Whether this task is excluded from ordinary idle waits and conversation aborts. */\n\treadonly background: boolean;\n\t/** Durable abort mark checked before run-mode progress is committed. */\n\treadonly abortRequested: boolean;\n};\n\n/** Complete replacement record for one durable task state machine. */\nexport type TaskRecord<I, S, R> = TaskRecordBase<I> &\n\t(\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"pending\" | \"running\" }>;\n\t\t\t\t/** Small first-writer-wins values retained while the task is live. */\n\t\t\t\treadonly memos?: Readonly<Record<string, JsonValue>>;\n\t\t }\n\t\t| {\n\t\t\t\treadonly state: Extract<TaskState<S, R>, { readonly status: \"terminal\" }>;\n\t\t\t\treadonly memos?: never;\n\t\t }\n\t);\n\n/** Persisted lifecycle record for one create-to-retire document incarnation. */\nexport type DocumentRecord = {\n\t/** Unique incarnation ID; never reused when the same logical document is recreated. */\n\treadonly id: Id;\n\t/** Stable document definition kind. */\n\treadonly kind: string;\n\t/** Family member key; absent for singleton documents. */\n\treadonly key?: string;\n\t/** Commit that created the incarnation, stamped by storage. */\n\treadonly createdAt: Seq;\n\t/** Commit that retired the incarnation; absent while it is current. */\n\treadonly retiredAt?: Seq;\n} & (\n\t| {\n\t\t\treadonly scope: { readonly kind: \"session\" };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n\t| ({ readonly scope: { readonly kind: \"conversation\"; readonly conversationId: Id } } & (\n\t\t\t| {\n\t\t\t\t\t/** Retain only current state. */\n\t\t\t\t\treadonly history: \"latest\";\n\t\t\t\t\t/** Initialize a fork from current source state or the definition's initial value. */\n\t\t\t\t\treadonly fork: \"current\" | \"initial\";\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\t/** Retain history needed for as-of reads. */\n\t\t\t\t\treadonly history: \"rewindable\";\n\t\t\t\t\t/** Initialize a fork at its cutoff, from current state, or from the initial value. */\n\t\t\t\t\treadonly fork: \"asOf\" | \"current\" | \"initial\";\n\t\t\t }\n\t ))\n\t| {\n\t\t\treadonly scope: { readonly kind: \"task\"; readonly taskId: Id };\n\t\t\treadonly history?: never;\n\t\t\treadonly fork?: never;\n\t }\n);\n\n/** Fields supplied when storage creates and stamps a new `DocumentRecord`. */\nexport type DocumentCreate = DocumentRecord extends infer Record\n\t? Record extends DocumentRecord\n\t\t? Omit<Record, \"createdAt\" | \"retiredAt\">\n\t\t: never\n\t: never;\n\n/** One ordered scan result and its optional continuation state. */\nexport type Page<T, C> = {\n\treadonly items: readonly T[];\n\treadonly next?: C;\n};\n\n/** Backend-owned JSON continuation state that callers only round-trip to the same scan. */\nexport type Cursor = Readonly<Record<string, JsonValue>>;\n\n/** Inclusive ID bounds for a newest-first scan of one conversation's fork-aware history. */\nexport type EntryQuery = {\n\treadonly conversationId: Id;\n\t/** Oldest entry ID that may be returned. */\n\treadonly minEntryId?: Id;\n\t/** Newest entry ID that may be returned. */\n\treadonly maxEntryId?: Id;\n};\n\n/** Optional filters for an ordered scan of durable task records. */\nexport type TaskQuery = {\n\treadonly conversationId?: Id;\n\treadonly kind?: string;\n\treadonly status?: \"pending\" | \"running\" | \"terminal\";\n\treadonly abortRequested?: boolean;\n\treadonly background?: boolean;\n};\n\n/** Current state or one historical commit sequence used for document membership and content reads. */\nexport type DocumentPoint = Seq | \"current\";\n\n/** Exact logical identity of a singleton or one keyed family member. */\nexport type DocumentAddress = {\n\treadonly kind: string;\n\treadonly scope: DocumentRecord[\"scope\"];\n\t/** Absent selects the singleton; present selects one family member. */\n\treadonly key?: string;\n};\n\n/** Ordered scan of document incarnations alive in one exact scope at one point. */\nexport type DocumentQuery = {\n\treadonly scope: DocumentRecord[\"scope\"];\n\treadonly at: DocumentPoint;\n\treadonly kind?: string;\n};\n\n/** Complete checkpoint or Chord operation batch selected by the owning Session. */\nexport type DocumentContent =\n\t| {\n\t\t\treadonly version: number;\n\t\t\treadonly kind: \"base\";\n\t\t\treadonly value: JsonObject;\n\t }\n\t| {\n\t\t\treadonly version: number;\n\t\t\treadonly kind: \"delta\";\n\t\t\treadonly ops: readonly Op[];\n\t };\n\n/** Detached materialized value and stored definition version at a selected point. */\nexport type StoredDocument = {\n\treadonly record: DocumentRecord;\n\treadonly version: number;\n\treadonly value: JsonObject;\n};\n\n/** One record or document mutation in an atomic storage commit. */\nexport type StorageWrite =\n\t| { readonly type: \"conversation\"; readonly value: ConversationRecord }\n\t| { readonly type: \"entry\"; readonly value: EntryRecord }\n\t| { readonly type: \"task\"; readonly value: TaskRecord<JsonValue, JsonValue, JsonValue> }\n\t| { readonly type: \"submission\"; readonly value: SubmissionRecord }\n\t| {\n\t\t\treadonly type: \"document.create\";\n\t\t\treadonly record: DocumentCreate;\n\t\t\treadonly content: Extract<DocumentContent, { readonly kind: \"base\" }>;\n\t }\n\t| {\n\t\t\treadonly type: \"document.change\";\n\t\t\treadonly id: Id;\n\t\t\treadonly content: DocumentContent;\n\t }\n\t| { readonly type: \"document.retire\"; readonly id: Id };\n\n/**\n * Atomic persistence boundary for Session records.\n *\n * Storage trusts the owning Session to supply semantically valid records, references,\n * ancestry, and transitions. Implementations enforce atomicity, global ID ownership,\n * immutable conversation/entry creation, document record consistency, and detached values;\n * Session serializes commits.\n */\nexport interface Storage {\n\t/**\n\t * Atomically persist one batch and return its sequence. Once resolved, later reads through this storage observe it.\n\t */\n\tcommit(writes: readonly StorageWrite[], context: Context): Promise<Seq>;\n\n\t/** Return a fresh candidate from the Session-global record ID namespace. */\n\tmintId(): Promise<Id>;\n\n\t/** Look up one conversation by exact ID. */\n\tconversation(id: Id, context: Context): Promise<ConversationRecord | undefined>;\n\n\t/** Scan conversations in ascending ID order. */\n\tscanConversations(\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>>;\n\n\t/** Look up one global entry and the sequence of the commit that persisted it. */\n\tentry(id: Id, context: Context): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\n\t/**\n\t * Return the newest visible entry with a `head` at or below the optional inclusive cutoff.\n\t * The returned entry is the marker; its `head` value is the range's actual lower bound.\n\t */\n\tfindLatestHeadMarker(\n\t\tconversationId: Id,\n\t\tatOrBeforeEntryId: Id | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: Id }) | undefined>;\n\n\t/** Scan the inclusive visible range newest-first, returning at most `limit` entries. */\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\n\t/** Look up the latest complete record for one task. */\n\ttask(id: Id, context: Context): Promise<TaskRecord<JsonValue, JsonValue, JsonValue> | undefined>;\n\n\t/** Scan task records matching every supplied filter. */\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>>;\n\n\t/** Look up the latest complete record for one admitted submission. */\n\tsubmission(id: Id, context: Context): Promise<SubmissionRecord | undefined>;\n\n\t/** Find a submission by its conversation-scoped host deduplication key. */\n\tsubmissionByRequest(conversationId: Id, requestId: string, context: Context): Promise<SubmissionRecord | undefined>;\n\n\t/** Resolve the incarnation occupying one exact logical address at the selected point. */\n\tfindDocument(address: DocumentAddress, at: DocumentPoint, context: Context): Promise<DocumentRecord | undefined>;\n\n\t/** Materialize one specific incarnation by ID at the selected point without following a replacement at its address. */\n\tdocument(id: Id, at: DocumentPoint, context: Context): Promise<StoredDocument | undefined>;\n\n\t/** Scan incarnations alive in one exact scope at the selected point. */\n\tscanDocuments(\n\t\tquery: DocumentQuery,\n\t\tcursor: Cursor | undefined,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<Page<DocumentRecord, Cursor>>;\n\n\t/** Release backend resources; all later operations must reject. */\n\tclose(context: Context): Promise<void>;\n}\n"]}
|