@earendil-works/pi-durable 1.4.0 → 1.5.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/CHANGELOG.md +204 -0
- package/README.md +195 -85
- package/dist/codemode/codemode.d.ts +6 -5
- package/dist/codemode/codemode.d.ts.map +1 -1
- package/dist/codemode/codemode.js +10 -49
- package/dist/codemode/codemode.js.map +1 -1
- package/dist/codemode/models.d.ts +2 -1
- package/dist/codemode/models.d.ts.map +1 -1
- package/dist/codemode/models.js +4 -4
- package/dist/codemode/models.js.map +1 -1
- package/dist/documents.d.ts +1 -1
- package/dist/documents.d.ts.map +1 -1
- package/dist/documents.js +1 -1
- package/dist/documents.js.map +1 -1
- package/dist/entries.d.ts +1 -1
- package/dist/entries.d.ts.map +1 -1
- package/dist/entries.js.map +1 -1
- package/dist/env/index.d.ts +13 -11
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +1 -1
- package/dist/env/node-watch.d.ts +4 -4
- package/dist/env/node-watch.d.ts.map +1 -1
- package/dist/env/node-watch.js +18 -16
- package/dist/env/node-watch.js.map +1 -1
- package/dist/env/node.d.ts +3 -3
- package/dist/env/node.d.ts.map +1 -1
- package/dist/env/node.js +1 -1
- package/dist/env/node.js.map +1 -1
- package/dist/errors.d.ts +18 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +26 -3
- package/dist/errors.js.map +1 -1
- package/dist/harness/agent.d.ts.map +1 -1
- package/dist/harness/agent.js +37 -3
- package/dist/harness/agent.js.map +1 -1
- package/dist/harness/compaction.d.ts +8 -3
- package/dist/harness/compaction.d.ts.map +1 -1
- package/dist/harness/compaction.js +40 -11
- package/dist/harness/compaction.js.map +1 -1
- package/dist/harness/context.d.ts +24 -8
- package/dist/harness/context.d.ts.map +1 -1
- package/dist/harness/context.js +71 -25
- package/dist/harness/context.js.map +1 -1
- package/dist/harness/define.d.ts +8 -4
- package/dist/harness/define.d.ts.map +1 -1
- package/dist/harness/define.js +4 -0
- package/dist/harness/define.js.map +1 -1
- package/dist/harness/generation.d.ts +39 -6
- package/dist/harness/generation.d.ts.map +1 -1
- package/dist/harness/generation.js +451 -100
- package/dist/harness/generation.js.map +1 -1
- package/dist/harness/harness.d.ts +3 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/harness.js +87 -62
- package/dist/harness/harness.js.map +1 -1
- package/dist/harness/inbox.d.ts +7 -2
- package/dist/harness/inbox.d.ts.map +1 -1
- package/dist/harness/inbox.js +5 -2
- package/dist/harness/inbox.js.map +1 -1
- package/dist/harness/json.d.ts +21 -5
- package/dist/harness/json.d.ts.map +1 -1
- package/dist/harness/json.js +23 -5
- package/dist/harness/json.js.map +1 -1
- package/dist/harness/live.d.ts +124 -17
- package/dist/harness/live.d.ts.map +1 -1
- package/dist/harness/live.js +93 -12
- package/dist/harness/live.js.map +1 -1
- package/dist/harness/partial-changes.d.ts +54 -0
- package/dist/harness/partial-changes.d.ts.map +1 -0
- package/dist/harness/partial-changes.js +163 -0
- package/dist/harness/partial-changes.js.map +1 -0
- package/dist/harness/prompt.d.ts +1 -1
- package/dist/harness/prompt.d.ts.map +1 -1
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/provider.d.ts +1 -1
- package/dist/harness/provider.d.ts.map +1 -1
- package/dist/harness/provider.js.map +1 -1
- package/dist/harness/registry-reader.d.ts +11 -0
- package/dist/harness/registry-reader.d.ts.map +1 -0
- package/dist/harness/registry-reader.js +25 -0
- package/dist/harness/registry-reader.js.map +1 -0
- package/dist/harness/scheduler.d.ts +48 -20
- package/dist/harness/scheduler.d.ts.map +1 -1
- package/dist/harness/scheduler.js +1006 -380
- package/dist/harness/scheduler.js.map +1 -1
- package/dist/harness/submissions.d.ts +18 -11
- package/dist/harness/submissions.d.ts.map +1 -1
- package/dist/harness/submissions.js +63 -26
- package/dist/harness/submissions.js.map +1 -1
- package/dist/harness/task-graph.d.ts +14 -9
- package/dist/harness/task-graph.d.ts.map +1 -1
- package/dist/harness/task-graph.js +38 -28
- package/dist/harness/task-graph.js.map +1 -1
- package/dist/harness/telemetry.d.ts +11 -11
- package/dist/harness/telemetry.d.ts.map +1 -1
- package/dist/harness/telemetry.js +7 -7
- package/dist/harness/telemetry.js.map +1 -1
- package/dist/harness/tool.d.ts +3 -1
- package/dist/harness/tool.d.ts.map +1 -1
- package/dist/harness/tool.js +172 -56
- package/dist/harness/tool.js.map +1 -1
- package/dist/harness/transcript.d.ts +72 -0
- package/dist/harness/transcript.d.ts.map +1 -0
- package/dist/harness/transcript.js +264 -0
- package/dist/harness/transcript.js.map +1 -0
- package/dist/harness/types.d.ts +237 -61
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/usage.d.ts +2 -1
- package/dist/harness/usage.d.ts.map +1 -1
- package/dist/harness/usage.js +1 -1
- package/dist/harness/usage.js.map +1 -1
- package/dist/harness/util.d.ts +4 -2
- package/dist/harness/util.d.ts.map +1 -1
- package/dist/harness/util.js +9 -0
- package/dist/harness/util.js.map +1 -1
- package/dist/harness/view.d.ts +44 -22
- package/dist/harness/view.d.ts.map +1 -1
- package/dist/harness/view.js +130 -71
- package/dist/harness/view.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/search.d.ts +19 -3
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +107 -44
- package/dist/search.js.map +1 -1
- package/dist/session/cached-storage.d.ts +72 -0
- package/dist/session/cached-storage.d.ts.map +1 -0
- package/dist/session/cached-storage.js +269 -0
- package/dist/session/cached-storage.js.map +1 -0
- package/dist/session/conversation-tails.d.ts +33 -0
- package/dist/session/conversation-tails.d.ts.map +1 -0
- package/dist/session/conversation-tails.js +101 -0
- package/dist/session/conversation-tails.js.map +1 -0
- package/dist/session/forks.d.ts +1 -1
- package/dist/session/forks.d.ts.map +1 -1
- package/dist/session/forks.js.map +1 -1
- package/dist/session/keys.d.ts +69 -0
- package/dist/session/keys.d.ts.map +1 -0
- package/dist/session/keys.js +161 -0
- package/dist/session/keys.js.map +1 -0
- package/dist/session/session.d.ts +169 -26
- package/dist/session/session.d.ts.map +1 -1
- package/dist/session/session.js +1029 -171
- package/dist/session/session.js.map +1 -1
- package/dist/session/transaction.d.ts +84 -5
- package/dist/session/transaction.d.ts.map +1 -1
- package/dist/session/transaction.js +227 -40
- package/dist/session/transaction.js.map +1 -1
- package/dist/session/writer.d.ts +74 -0
- package/dist/session/writer.d.ts.map +1 -0
- package/dist/session/writer.js +294 -0
- package/dist/session/writer.js.map +1 -0
- package/dist/storage/indexeddb.d.ts +12 -3
- package/dist/storage/indexeddb.d.ts.map +1 -1
- package/dist/storage/indexeddb.js +91 -41
- package/dist/storage/indexeddb.js.map +1 -1
- package/dist/storage/jsonl/index.d.ts +1 -1
- package/dist/storage/jsonl/index.d.ts.map +1 -1
- package/dist/storage/jsonl/index.js +1 -1
- package/dist/storage/jsonl/index.js.map +1 -1
- package/dist/storage/jsonl/node.d.ts +3 -3
- package/dist/storage/jsonl/node.d.ts.map +1 -1
- package/dist/storage/jsonl/node.js +2 -2
- package/dist/storage/jsonl/node.js.map +1 -1
- package/dist/storage/jsonl/storage.d.ts +46 -5
- package/dist/storage/jsonl/storage.d.ts.map +1 -1
- package/dist/storage/jsonl/storage.js +158 -43
- package/dist/storage/jsonl/storage.js.map +1 -1
- package/dist/storage/memory.d.ts +9 -3
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +28 -2
- package/dist/storage/memory.js.map +1 -1
- package/dist/storage/sqlite/commit.d.ts +52 -0
- package/dist/storage/sqlite/commit.d.ts.map +1 -0
- package/dist/storage/sqlite/commit.js +371 -0
- package/dist/storage/sqlite/commit.js.map +1 -0
- package/dist/storage/sqlite/rows.d.ts +33 -0
- package/dist/storage/sqlite/rows.d.ts.map +1 -0
- package/dist/storage/sqlite/rows.js +53 -0
- package/dist/storage/sqlite/rows.js.map +1 -0
- package/dist/storage/sqlite/statements.d.ts +13 -0
- package/dist/storage/sqlite/statements.d.ts.map +1 -0
- package/dist/storage/sqlite/statements.js +88 -0
- package/dist/storage/sqlite/statements.js.map +1 -0
- package/dist/storage/sqlite/storage.d.ts +23 -10
- package/dist/storage/sqlite/storage.d.ts.map +1 -1
- package/dist/storage/sqlite/storage.js +120 -261
- package/dist/storage/sqlite/storage.js.map +1 -1
- package/dist/storage/store/commit.d.ts +33 -0
- package/dist/storage/store/commit.d.ts.map +1 -0
- package/dist/storage/store/commit.js +286 -0
- package/dist/storage/store/commit.js.map +1 -0
- package/dist/storage/store/documents.d.ts +43 -0
- package/dist/storage/store/documents.d.ts.map +1 -0
- package/dist/storage/store/documents.js +102 -0
- package/dist/storage/store/documents.js.map +1 -0
- package/dist/storage/store/index.d.ts +2 -0
- package/dist/storage/store/index.d.ts.map +1 -0
- package/dist/storage/store/index.js +2 -0
- package/dist/storage/store/index.js.map +1 -0
- package/dist/storage/store/queries.d.ts +49 -0
- package/dist/storage/store/queries.d.ts.map +1 -0
- package/dist/storage/store/queries.js +93 -0
- package/dist/storage/store/queries.js.map +1 -0
- package/dist/storage/store/storage.d.ts +60 -0
- package/dist/storage/store/storage.d.ts.map +1 -0
- package/dist/storage/store/storage.js +438 -0
- package/dist/storage/store/storage.js.map +1 -0
- package/dist/storage/store/tables.d.ts +54 -0
- package/dist/storage/store/tables.d.ts.map +1 -0
- package/dist/storage/store/tables.js +108 -0
- package/dist/storage/store/tables.js.map +1 -0
- package/dist/testing/commit-writes.d.ts +5 -0
- package/dist/testing/commit-writes.d.ts.map +1 -0
- package/dist/testing/commit-writes.js +12 -0
- package/dist/testing/commit-writes.js.map +1 -0
- package/dist/testing/env-conformance.js +7 -7
- package/dist/testing/env-conformance.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/storage-benchmark.d.ts.map +1 -1
- package/dist/testing/storage-benchmark.js +18 -17
- package/dist/testing/storage-benchmark.js.map +1 -1
- package/dist/testing/storage-conformance.d.ts.map +1 -1
- package/dist/testing/storage-conformance.js +354 -69
- package/dist/testing/storage-conformance.js.map +1 -1
- package/dist/tool-search/tool-search.d.ts +8 -14
- package/dist/tool-search/tool-search.d.ts.map +1 -1
- package/dist/tool-search/tool-search.js +25 -13
- package/dist/tool-search/tool-search.js.map +1 -1
- package/dist/tools/bash.d.ts +13 -13
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +16 -15
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/edit.d.ts +7 -7
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +9 -9
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/file-mutation-queue.d.ts +1 -1
- package/dist/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/tools/file-mutation-queue.js.map +1 -1
- package/dist/tools/index.d.ts +32 -32
- package/dist/tools/path-utils.d.ts +1 -1
- package/dist/tools/path-utils.d.ts.map +1 -1
- package/dist/tools/path-utils.js.map +1 -1
- package/dist/tools/read.d.ts +6 -6
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +19 -8
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/write.d.ts +4 -4
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +5 -5
- package/dist/tools/write.js.map +1 -1
- package/dist/types.d.ts +228 -78
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +19 -12
- package/dist/harness/events.d.ts +0 -186
- package/dist/harness/events.d.ts.map +0 -1
- package/dist/harness/events.js +0 -373
- package/dist/harness/events.js.map +0 -1
- package/dist/session/observation.d.ts +0 -42
- package/dist/session/observation.d.ts.map +0 -1
- package/dist/session/observation.js +0 -281
- package/dist/session/observation.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Op } from "@earendil-works/chord/delta";
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
|
+
import type { Draft, Op } from "@earendil-works/chord/delta";
|
|
3
|
+
import type { JsonValue } from "@earendil-works/chord/json";
|
|
4
|
+
import type { WatchCall, WatchEnd, WatchHandle } from "@earendil-works/chord/watch";
|
|
3
5
|
import type { Message, Models } from "@earendil-works/pi-ai";
|
|
4
6
|
import type { TelemetryCarrier } from "@earendil-works/pi-telemetry";
|
|
5
7
|
import type { ExecutionEnv } from "./env/index.ts";
|
|
@@ -107,18 +109,25 @@ export type ReportTask = {
|
|
|
107
109
|
readonly kind: string;
|
|
108
110
|
readonly conversationId: ConversationId;
|
|
109
111
|
};
|
|
110
|
-
/** A host callback, by its `HarnessOptions` name; `env` is the environment builder, `models` a provider call. */
|
|
111
|
-
export type HostCallback = "now" | "settings" | "registry" | "env" | "models" | "setTimer" | "onWake";
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
|
|
113
|
+
* A host callback, by its `HarnessOptions` name; `env` is the environment builder, `models` a provider call, and
|
|
114
|
+
* `telemetry` a telemetry adapter call made while a commit is published, which must not fail it.
|
|
115
|
+
*/
|
|
116
|
+
export type HostCallback = "now" | "settings" | "registry" | "env" | "models" | "setTimer" | "onWake" | "telemetry";
|
|
117
|
+
/**
|
|
118
|
+
* What a report to `HarnessOptions.onReport` is about, by `kind` (`Report` adds the error). `extension`, where present,
|
|
119
|
+
* names the extension whose code failed, when known; for a task's own code, the one that installed the definition the
|
|
120
|
+
* task ran.
|
|
121
|
+
* - `storage_failed`: the error failed the Session, which closes: a Storage error, often a platform reset.
|
|
116
122
|
* - `task_faulted`: the task ended `faulted`: its phase threw (`reason: "threw"`), or its abort handler was cut off
|
|
117
|
-
* `settings.restartLimit` times (`reason: "restart_limit"`).
|
|
118
|
-
* - `
|
|
123
|
+
* `settings.restartLimit` times (`reason: "restart_limit"`), as was a phase of a task of an extension's kind.
|
|
124
|
+
* - `task_interrupted`: crashes ended the task: it ended itself after being cut off `settings.restartLimit` times in a
|
|
125
|
+
* row (`reason: "restart_limit"`; a tool call, a compaction, a generation), or a generation's run ended because the
|
|
126
|
+
* host kept stopping while the model answered (`reason: "interrupted"`). `restarts` is the task's count when it ended.
|
|
119
127
|
* - `migration_failed`: the task's stored state could not be migrated; it is blocked until the registry changes.
|
|
120
128
|
* - `task_outdated`: a running task keeps running under its old definition, which was uninstalled (`missing_task`)
|
|
121
|
-
* or replaced by one that cannot take over its state (`
|
|
129
|
+
* or replaced by one that cannot take over its state: older than the task (`task_too_old`), or newer without a
|
|
130
|
+
* `migrate` (`migration_failed`).
|
|
122
131
|
* - `task_error`: the task's own `runtime.report()`, or a failure in running it.
|
|
123
132
|
* - `extension_error`: a hook, a section, a wrapper, or a tool's invalid structured output; with the task that ran it,
|
|
124
133
|
* or, outside a task, the conversation whose agent was resolved.
|
|
@@ -126,47 +135,53 @@ export type HostCallback = "now" | "settings" | "registry" | "env" | "models" |
|
|
|
126
135
|
* - `listener_error`: a commit, close, watch, view, or document listener threw.
|
|
127
136
|
*/
|
|
128
137
|
export type ReportInfo = {
|
|
129
|
-
readonly
|
|
138
|
+
readonly kind: "storage_failed";
|
|
130
139
|
} | {
|
|
131
|
-
readonly
|
|
140
|
+
readonly kind: "task_faulted";
|
|
132
141
|
readonly task: ReportTask;
|
|
133
142
|
readonly extension?: string;
|
|
134
143
|
readonly reason: "threw" | "restart_limit";
|
|
135
144
|
} | {
|
|
136
|
-
readonly
|
|
145
|
+
readonly kind: "task_interrupted";
|
|
137
146
|
readonly task: ReportTask;
|
|
138
147
|
readonly extension?: string;
|
|
148
|
+
readonly reason: "restart_limit" | "interrupted";
|
|
149
|
+
readonly restarts: number;
|
|
139
150
|
} | {
|
|
140
|
-
readonly
|
|
151
|
+
readonly kind: "migration_failed";
|
|
141
152
|
readonly task: ReportTask;
|
|
142
153
|
readonly extension?: string;
|
|
143
154
|
} | {
|
|
144
|
-
readonly
|
|
155
|
+
readonly kind: "task_outdated";
|
|
145
156
|
readonly task: ReportTask;
|
|
146
157
|
readonly extension?: string;
|
|
147
|
-
readonly reason: "missing_task" | "
|
|
158
|
+
readonly reason: "missing_task" | "task_too_old" | "migration_failed";
|
|
148
159
|
} | {
|
|
149
|
-
readonly
|
|
160
|
+
readonly kind: "task_error";
|
|
150
161
|
readonly task: ReportTask;
|
|
151
162
|
readonly extension?: string;
|
|
152
163
|
} | {
|
|
153
|
-
readonly
|
|
164
|
+
readonly kind: "extension_error";
|
|
154
165
|
readonly extension?: string;
|
|
155
166
|
readonly task?: ReportTask;
|
|
156
167
|
readonly conversationId?: ConversationId;
|
|
157
168
|
} | {
|
|
158
|
-
readonly
|
|
169
|
+
readonly kind: "host_error";
|
|
159
170
|
readonly callback: HostCallback;
|
|
160
171
|
readonly task?: ReportTask;
|
|
161
172
|
} | {
|
|
162
|
-
readonly
|
|
173
|
+
readonly kind: "listener_error";
|
|
174
|
+
};
|
|
175
|
+
/** One report to `HarnessOptions.onReport`: what it is about (`ReportInfo`, by `kind`) and the `error` reported. */
|
|
176
|
+
export type Report = ReportInfo & {
|
|
177
|
+
readonly error: unknown;
|
|
163
178
|
};
|
|
164
179
|
/** Whose code a task's `runtime.report()` is about when not the task's own: an extension's, or a host callback. */
|
|
165
180
|
export type ReportFrom = {
|
|
166
|
-
readonly
|
|
181
|
+
readonly kind: "extension";
|
|
167
182
|
readonly extension?: string;
|
|
168
183
|
} | {
|
|
169
|
-
readonly
|
|
184
|
+
readonly kind: "host";
|
|
170
185
|
readonly callback: HostCallback;
|
|
171
186
|
};
|
|
172
187
|
/**
|
|
@@ -233,9 +248,11 @@ export interface TaskRuntime<I, S, R, H extends object> extends DocumentObserver
|
|
|
233
248
|
* Commit on the Session line after rereading the task. Rejects when the task is terminal, the invocation ended, the
|
|
234
249
|
* Harness is closing, or, in a run invocation, the task carries an abort mark. A returned state replaces the task's
|
|
235
250
|
* state in the same commit; returning nothing leaves it unchanged. `tx.createTask()` defaults to the task's
|
|
236
|
-
* conversation. Inside the callback read only through `tx`: `snapshot()`, `
|
|
251
|
+
* conversation. Inside the callback read only through `tx`: `snapshot()`, `watchDoc()`, `getTask()`, and the other Session and runtime reads may queue on the line the callback holds, and then never resolve.
|
|
252
|
+
* `options.persistence` may defer storing a commit that changes only documents (`CommitPersistence`); one that returns
|
|
253
|
+
* a state is immediate.
|
|
237
254
|
*/
|
|
238
|
-
commit(change: (tx: Tx, current: RunningTask<I, S, R>) => NextTaskState<S, R> | undefined | Promise<NextTaskState<S, R> | undefined>, context: Context): Promise<void>;
|
|
255
|
+
commit(change: (tx: Tx, current: RunningTask<I, S, R>) => NextTaskState<S, R> | undefined | Promise<NextTaskState<S, R> | undefined>, context: Context, options?: CommitOptions): Promise<void>;
|
|
239
256
|
/** Read a durable memo of this task. */
|
|
240
257
|
memo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;
|
|
241
258
|
/** Store `candidate` unless a memo already exists; return the durable winner. */
|
|
@@ -265,6 +282,12 @@ export interface TaskRuntime<I, S, R, H extends object> extends DocumentObserver
|
|
|
265
282
|
entry(id: EntryId, context: Context): Promise<EntryRecord | undefined>;
|
|
266
283
|
/** Undefined when the entry is absent, not visible, or has another kind. */
|
|
267
284
|
entry<D extends JsonValue>(token: Entry<D>, id: EntryId, context: Context): Promise<TypedEntry<D> | undefined>;
|
|
285
|
+
/**
|
|
286
|
+
* Committed raw history of the task's conversation, fork-aware, as `Conversation.entries()`: every entry, also those a
|
|
287
|
+
* compaction summary or reset left behind. Entries never change, so a range bounded by entry IDs reads the same
|
|
288
|
+
* before and after a compaction, and in a rerun after a crash.
|
|
289
|
+
*/
|
|
290
|
+
entries(query: Omit<EntryQuery, "conversationId">, limit: number, cursor: Cursor | undefined, context: Context): Promise<Page<EntryRecord, Cursor>>;
|
|
268
291
|
/** Committed raw active transcript and model context, optionally cut off at the visible entry `at`. */
|
|
269
292
|
context(conversationId: ConversationId, context: Context, options?: {
|
|
270
293
|
readonly at?: EntryId;
|
|
@@ -434,7 +457,7 @@ type SubmissionRecordBase = {
|
|
|
434
457
|
/** Host-provided deduplication key, scoped to the conversation. */
|
|
435
458
|
readonly requestId?: string;
|
|
436
459
|
};
|
|
437
|
-
/** Durable lifecycle of one admitted user input
|
|
460
|
+
/** Durable lifecycle of one admitted user input, passive entry write, or continue. */
|
|
438
461
|
export type SubmissionRecord = (SubmissionRecordBase & {
|
|
439
462
|
readonly type: "input";
|
|
440
463
|
} & ({
|
|
@@ -488,6 +511,30 @@ export type SubmissionRecord = (SubmissionRecordBase & {
|
|
|
488
511
|
readonly answer?: never;
|
|
489
512
|
readonly reason: string;
|
|
490
513
|
readonly detail?: JsonValue;
|
|
514
|
+
})) | (SubmissionRecordBase & {
|
|
515
|
+
/** A run started without a user message; it places no entry and is never queued. */
|
|
516
|
+
readonly type: "continue";
|
|
517
|
+
} & ({
|
|
518
|
+
/** Owned by an active run. */
|
|
519
|
+
readonly status: "placed";
|
|
520
|
+
readonly entry?: never;
|
|
521
|
+
readonly answer?: never;
|
|
522
|
+
readonly reason?: never;
|
|
523
|
+
readonly detail?: never;
|
|
524
|
+
} | {
|
|
525
|
+
/** The run answered. */
|
|
526
|
+
readonly status: "done";
|
|
527
|
+
readonly entry?: never;
|
|
528
|
+
readonly answer: EntryId;
|
|
529
|
+
readonly reason?: never;
|
|
530
|
+
readonly detail?: never;
|
|
531
|
+
} | {
|
|
532
|
+
/** The run ended without an answer. */
|
|
533
|
+
readonly status: "unanswered";
|
|
534
|
+
readonly entry?: never;
|
|
535
|
+
readonly answer?: never;
|
|
536
|
+
readonly reason: string;
|
|
537
|
+
readonly detail?: JsonValue;
|
|
491
538
|
}));
|
|
492
539
|
/** Terminal status staged for a submission; identity, type, and entry come from its current record. */
|
|
493
540
|
export type SubmissionSettlement = {
|
|
@@ -619,8 +666,9 @@ type TaskRecordBase<I, R> = {
|
|
|
619
666
|
readonly endedAt?: number;
|
|
620
667
|
/**
|
|
621
668
|
* How many times in a row a crash, eviction, or reset cut the task off while it ran, without the task changing its
|
|
622
|
-
* state since; open counts them, and a close does not. At `HarnessSettings.restartLimit` the task
|
|
623
|
-
*
|
|
669
|
+
* state since; open counts them, and a close does not. At `HarnessSettings.restartLimit` the task ends (the built-in
|
|
670
|
+
* tasks end themselves, visibly; the scheduler faults any other kind), and a generation reads it to charge an
|
|
671
|
+
* interrupted model request as a failed attempt.
|
|
624
672
|
*/
|
|
625
673
|
readonly restarts?: number;
|
|
626
674
|
};
|
|
@@ -795,20 +843,30 @@ export type StorageWrite = {
|
|
|
795
843
|
readonly type: "document.retire";
|
|
796
844
|
readonly id: DocumentId;
|
|
797
845
|
};
|
|
798
|
-
/**
|
|
846
|
+
/**
|
|
847
|
+
* Committed change of one document incarnation: `type: "document"` with `kind: "change"` (a creation or an update) or
|
|
848
|
+
* `kind: "retire"` (this commit retired the incarnation), or a `document.copy`.
|
|
849
|
+
*/
|
|
799
850
|
export type DocumentCommitChange = {
|
|
800
851
|
readonly type: "document";
|
|
852
|
+
readonly kind: "change";
|
|
801
853
|
readonly record: DocumentRecord;
|
|
802
854
|
/** Conversation owning the document; task documents derive it from their task record. Undefined only for Session documents. */
|
|
803
855
|
readonly conversationId: ConversationId | undefined;
|
|
804
|
-
/** Definition version of `value
|
|
805
|
-
readonly version: number
|
|
806
|
-
/** Exact adopted immutable revision
|
|
807
|
-
readonly value: JsonObject
|
|
808
|
-
/** Exact adopted operations for an ordinary update; empty for creation
|
|
856
|
+
/** Definition version of `value`. */
|
|
857
|
+
readonly version: number;
|
|
858
|
+
/** Exact adopted immutable revision. */
|
|
859
|
+
readonly value: JsonObject;
|
|
860
|
+
/** Exact adopted operations for an ordinary update; empty for creation. */
|
|
809
861
|
readonly ops: readonly Op[];
|
|
810
862
|
} | {
|
|
811
|
-
|
|
863
|
+
readonly type: "document";
|
|
864
|
+
readonly kind: "retire";
|
|
865
|
+
readonly record: DocumentRecord;
|
|
866
|
+
/** Conversation owning the document; task documents derive it from their task record. Undefined only for Session documents. */
|
|
867
|
+
readonly conversationId: ConversationId | undefined;
|
|
868
|
+
} | {
|
|
869
|
+
/** Definition-free child initialization; consumers hydrate through watch acquisition. */
|
|
812
870
|
readonly type: "document.copy";
|
|
813
871
|
readonly record: DocumentRecord;
|
|
814
872
|
readonly conversationId: ConversationId;
|
|
@@ -819,14 +877,20 @@ export type TableCommitChange = Extract<StorageWrite, {
|
|
|
819
877
|
readonly type: "conversation" | "entry" | "task" | "submission";
|
|
820
878
|
}>;
|
|
821
879
|
export type CommitChange = TableCommitChange | DocumentCommitChange;
|
|
822
|
-
/**
|
|
880
|
+
/**
|
|
881
|
+
* Every immutable change one Session storage transaction stored, with its `seq`. Change order is unspecified. A commit
|
|
882
|
+
* held in memory (`CommitPersistence`) is published once it is stored: by the next commit that reads or writes its
|
|
883
|
+
* document, alone (`seq` of its own), or with that commit, whose document change then carries the held operations
|
|
884
|
+
* followed by its own.
|
|
885
|
+
*/
|
|
823
886
|
export type CommitPublication = {
|
|
824
887
|
readonly seq: Seq;
|
|
825
888
|
readonly changes: readonly CommitChange[];
|
|
826
889
|
};
|
|
827
890
|
/**
|
|
828
891
|
* Transaction surface of one Session commit callback.
|
|
829
|
-
* Table reads and creation results are trusted immutable values and may be shared with internal commit state
|
|
892
|
+
* Table reads and creation results are trusted immutable values and may be shared with internal commit state; the
|
|
893
|
+
* Session may freeze them (its caches and context ranges keep them), so mutating one can throw.
|
|
830
894
|
*/
|
|
831
895
|
export interface Tx {
|
|
832
896
|
conversation(id: ConversationId): Promise<ConversationRecord | undefined>;
|
|
@@ -840,7 +904,11 @@ export interface Tx {
|
|
|
840
904
|
latestHeadMarker(conversationId: ConversationId): Promise<(EntryRecord & {
|
|
841
905
|
readonly head: EntryId;
|
|
842
906
|
}) | undefined>;
|
|
907
|
+
/** ID of the newest entry visible from the conversation; `undefined` when it has none. */
|
|
908
|
+
latestEntryId(conversationId: ConversationId): Promise<EntryId | undefined>;
|
|
843
909
|
scanTasks(query: TaskQuery, limit: number, cursor?: Cursor): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>>;
|
|
910
|
+
/** Committed submission record, such as one of `pi.live.run.inputs`; a placed input's `entry` is its transcript entry. */
|
|
911
|
+
submission(id: SubmissionId): Promise<SubmissionRecord | undefined>;
|
|
844
912
|
/** Committed submission with a conversation-scoped request ID. */
|
|
845
913
|
submissionByRequest(conversationId: ConversationId, requestId: string): Promise<SubmissionRecord | undefined>;
|
|
846
914
|
/** Create a conversation with explicitly selected ownership. */
|
|
@@ -864,7 +932,7 @@ export interface Tx {
|
|
|
864
932
|
*/
|
|
865
933
|
createSubmission(create: SubmissionCreate): Promise<SubmissionRecord>;
|
|
866
934
|
/**
|
|
867
|
-
* Settle a queued or placed submission; only a placed input can be answered, and a settled submission stays
|
|
935
|
+
* Settle a queued or placed submission; only a placed input or continue can be answered, and a settled submission stays
|
|
868
936
|
* unchanged. Resolved against this transaction's latest record of the submission, so it works after table writes.
|
|
869
937
|
* Run tasks settle the inputs they answer.
|
|
870
938
|
*/
|
|
@@ -887,32 +955,53 @@ export interface Tx {
|
|
|
887
955
|
retireDoc<T extends JsonObject, I extends JsonValue>(token: ConversationDocFamilyToken<T, I>, conversationId: ConversationId, key: string): Promise<void>;
|
|
888
956
|
retireDoc<T extends JsonObject, I extends JsonValue>(token: TaskDocFamilyToken<T, I>, taskId: TaskId, key: string): Promise<void>;
|
|
889
957
|
}
|
|
890
|
-
/**
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
958
|
+
/**
|
|
959
|
+
* Watch of one document address (kind, scope, and key), from the incarnation found at acquisition on. A retirement is a
|
|
960
|
+
* call with `retired` set, the last value the watch was given and no ops (a change made in the retiring commit itself
|
|
961
|
+
* is not shown: that commit publishes the retirement only); the watch goes on, and a document created at the address
|
|
962
|
+
* later arrives as `[["r", value]]`, folded with what is pending. It ends `ended` when its scope's owner ends: a task
|
|
963
|
+
* document's watch once the retirement call of the commit that makes its task terminal returned, every watch at Session
|
|
964
|
+
* close (a pending retirement dropped); `failed` with the error that failed the Session.
|
|
965
|
+
*/
|
|
966
|
+
export type DocumentWatch<T extends JsonObject> = WatchHandle<Readonly<T>>;
|
|
967
|
+
/**
|
|
968
|
+
* A synchronous observer of committed Durable state, for adapters such as a Chord source (`observeDoc()`,
|
|
969
|
+
* `Harness.observeConversation()`, `Harness.observeTaskGraph()`), with the shapes of Chord's watch: `advance` gets a
|
|
970
|
+
* `WatchCall`, `end` a `WatchEnd`. `advance` gets every change, unfolded, as memory adopts it: for a stored commit at its
|
|
971
|
+
* publication once Storage stored it, for a deferred one before it is stored. A view or the graph gets at most one call
|
|
972
|
+
* per commit, a document observer one per change at its address (two for a commit that retires and recreates it); the
|
|
973
|
+
* task graph also advances outside any commit's publication, on the Session line, when a registry change or a failed
|
|
974
|
+
* migration changes a
|
|
975
|
+
* `blocked` reason. Durable's failures are final, so every call is a `value` call; a failure ends the observer. Calls
|
|
976
|
+
* may come before the attaching promise resolves; their ops apply from `Observation.value`. `advance` must only record
|
|
977
|
+
* the call, synchronously and quickly, never await, call the Session, or throw. A throw is reported as
|
|
978
|
+
* `listener_error`, detaches the observer, and ends it `listener_error` with the error. `end` is called once: `ended`
|
|
979
|
+
* when the observed scope's owner ends (a task document's task, after its retirement change, inside that commit's
|
|
980
|
+
* `adopt`), `failed` with "session closed" when the Session closes (an adapter follows the next Session) or with the
|
|
981
|
+
* error that failed the Session; never after `detach()`.
|
|
982
|
+
*/
|
|
983
|
+
export type Observer<T> = {
|
|
984
|
+
advance(call: WatchCall<T>, context: Context): void;
|
|
985
|
+
end(end: WatchEnd): void;
|
|
986
|
+
};
|
|
987
|
+
/**
|
|
988
|
+
* A synchronous observer of stored commits (`Session.observeCommits()`): `advance` gets each `CommitPublication`, `end`
|
|
989
|
+
* the Session's close (`failed` with "session closed", or with the error that failed the Session).
|
|
990
|
+
*/
|
|
991
|
+
export type CommitObserver = {
|
|
992
|
+
advance(publication: CommitPublication, context: Context): void;
|
|
993
|
+
end(end: WatchEnd): void;
|
|
903
994
|
};
|
|
904
|
-
/**
|
|
905
|
-
export
|
|
906
|
-
|
|
995
|
+
/** An attached `CommitObserver`: how to detach it. Idempotent: no `advance` or `end` follows it. */
|
|
996
|
+
export type CommitObservation = {
|
|
997
|
+
detach(): void;
|
|
998
|
+
};
|
|
999
|
+
/** An attached `Observer`: the value at attachment, which every later `advance` starts from, and how to detach it. */
|
|
1000
|
+
export type Observation<T> = {
|
|
907
1001
|
readonly value: T;
|
|
908
|
-
/**
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
stop(): Promise<WatchEnd>;
|
|
912
|
-
/** Settle when the watch terminates; an already-running callback remains caller-owned. */
|
|
913
|
-
readonly closed: Promise<WatchEnd>;
|
|
914
|
-
}
|
|
915
|
-
export type DocumentWatch<T extends JsonObject> = WatchHandle<Readonly<T> | null>;
|
|
1002
|
+
/** Idempotent: no `advance` or `end` follows it, not even for the rest of a commit underway. */
|
|
1003
|
+
detach(): void;
|
|
1004
|
+
};
|
|
916
1005
|
/** Committed document reads. */
|
|
917
1006
|
export type DocumentReader = Pick<Session, "snapshot" | "snapshotAsOf">;
|
|
918
1007
|
/** Non-creating document watch acquisition shared by Session and later invocation APIs. */
|
|
@@ -924,19 +1013,43 @@ export interface DocumentObserver {
|
|
|
924
1013
|
watchDoc<T extends JsonObject, I extends JsonValue>(token: ConversationDocFamilyToken<T, I>, conversationId: ConversationId, key: string, context: Context): Promise<DocumentWatch<T> | undefined>;
|
|
925
1014
|
watchDoc<T extends JsonObject, I extends JsonValue>(token: TaskDocFamilyToken<T, I>, taskId: TaskId, key: string, context: Context): Promise<DocumentWatch<T> | undefined>;
|
|
926
1015
|
}
|
|
927
|
-
/** Why a Session ended
|
|
1016
|
+
/** Why a Session ended, by `kind`: `close()`, or a failed Storage call, whose error it carries. */
|
|
928
1017
|
export type SessionEnd = {
|
|
929
|
-
readonly
|
|
1018
|
+
readonly kind: "closed";
|
|
930
1019
|
} | {
|
|
931
|
-
readonly
|
|
1020
|
+
readonly kind: "failed";
|
|
932
1021
|
readonly error: unknown;
|
|
933
1022
|
};
|
|
1023
|
+
/**
|
|
1024
|
+
* When a commit reaches Storage. `immediate`, the default: before `commit()` resolves. `deferred`: when every write of
|
|
1025
|
+
* the commit changes an existing conversation document with `history: "latest"` and `fork: "initial"` (no creation,
|
|
1026
|
+
* migration, or retirement), the Session adopts it in memory, shows it to watches and views, and resolves, but stores it
|
|
1027
|
+
* later: with the next commit that reads (`tx.doc()`) or writes that document, before the document leaves memory or
|
|
1028
|
+
* retires, at `close()`, and at the latest about `withinMs` after the commit (default `settings.progress.persistWithinMs`,
|
|
1029
|
+
* 1,000 ms; `Infinity` waits for one of the others). A commit that writes anything else is immediate. A crash loses what
|
|
1030
|
+
* is held, so only state whose loss is acceptable, such as streamed progress, should be deferred, and nothing durable may
|
|
1031
|
+
* depend on it without reading it in a commit.
|
|
1032
|
+
*/
|
|
1033
|
+
export type CommitPersistence = {
|
|
1034
|
+
readonly kind: "immediate";
|
|
1035
|
+
} | {
|
|
1036
|
+
readonly kind: "deferred";
|
|
1037
|
+
readonly withinMs?: number;
|
|
1038
|
+
};
|
|
1039
|
+
/** Options of one Session commit. */
|
|
1040
|
+
export type CommitOptions = {
|
|
1041
|
+
readonly persistence?: CommitPersistence;
|
|
1042
|
+
};
|
|
934
1043
|
/** Owner of one mutation line, its records, and its tracked documents. */
|
|
935
1044
|
export interface Session extends DocumentObserver {
|
|
936
1045
|
/**
|
|
937
|
-
* Run one atomic transaction on the Session mutation line. Inside the callback read only through `tx`: `snapshot()`, `
|
|
1046
|
+
* Run one atomic transaction on the Session mutation line. Inside the callback read only through `tx`: `snapshot()`, `watchDoc()`, `getTask()`, and the other Session and runtime reads may queue on the line the callback holds, and then never resolve.
|
|
1047
|
+
* `options.persistence` may defer storing it (`CommitPersistence`). The callback may run while an earlier commit is
|
|
1048
|
+
* being stored: at its first read or write of what an unpublished commit wrote, it waits until that commit is stored
|
|
1049
|
+
* and published; code before that runs early, so act on what it computes only once the commit resolves. Resolves
|
|
1050
|
+
* once the commit is stored and published, after every earlier commit's outcome.
|
|
938
1051
|
*/
|
|
939
|
-
commit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;
|
|
1052
|
+
commit<T>(change: (tx: Tx) => T | Promise<T>, context: Context, options?: CommitOptions): Promise<T>;
|
|
940
1053
|
/** Seal admission, settle admitted commits, then close storage. */
|
|
941
1054
|
close(context: Context): Promise<void>;
|
|
942
1055
|
/**
|
|
@@ -944,8 +1057,30 @@ export interface Session extends DocumentObserver {
|
|
|
944
1057
|
* which closes the Session itself. A failed Session is reopened from Storage; nothing else is left to clean up.
|
|
945
1058
|
*/
|
|
946
1059
|
readonly closed: Promise<SessionEnd>;
|
|
947
|
-
/**
|
|
948
|
-
|
|
1060
|
+
/**
|
|
1061
|
+
* Attach a synchronous `Observer` to one document address, atomically on the Session line, as `watchDoc()` acquires
|
|
1062
|
+
* a watch: the observation's value includes every commit before it, and `advance` gets every later one, retirements
|
|
1063
|
+
* and later incarnations included. `undefined` when the address is absent. `context` governs only the attachment:
|
|
1064
|
+
* cancelled while attaching, the promise rejects and nothing stays attached.
|
|
1065
|
+
*/
|
|
1066
|
+
observeDoc<T extends JsonObject>(token: SessionDocToken<T>, observer: Observer<Readonly<T>>, context: Context): Promise<Observation<Readonly<T>> | undefined>;
|
|
1067
|
+
observeDoc<T extends JsonObject>(token: ConversationDocToken<T>, conversationId: ConversationId, observer: Observer<Readonly<T>>, context: Context): Promise<Observation<Readonly<T>> | undefined>;
|
|
1068
|
+
observeDoc<T extends JsonObject>(token: TaskDocToken<T>, taskId: TaskId, observer: Observer<Readonly<T>>, context: Context): Promise<Observation<Readonly<T>> | undefined>;
|
|
1069
|
+
observeDoc<T extends JsonObject, I extends JsonValue>(token: SessionDocFamilyToken<T, I>, key: string, observer: Observer<Readonly<T>>, context: Context): Promise<Observation<Readonly<T>> | undefined>;
|
|
1070
|
+
observeDoc<T extends JsonObject, I extends JsonValue>(token: ConversationDocFamilyToken<T, I>, conversationId: ConversationId, key: string, observer: Observer<Readonly<T>>, context: Context): Promise<Observation<Readonly<T>> | undefined>;
|
|
1071
|
+
observeDoc<T extends JsonObject, I extends JsonValue>(token: TaskDocFamilyToken<T, I>, taskId: TaskId, key: string, observer: Observer<Readonly<T>>, context: Context): Promise<Observation<Readonly<T>> | undefined>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Observe stored commits, each with exactly what it stored, except that a document the commit retires is published
|
|
1074
|
+
* as its retirement only; a commit held in memory is published when it is stored (`CommitPublication`). Commits are
|
|
1075
|
+
* published in line order once Storage stored them, a macrotask apart; a publication queues one dispatch, which runs
|
|
1076
|
+
* a microtask later, before every wait the commit resolves and every abort it queues, and calls the observers
|
|
1077
|
+
* attached by then; a commit published while none was attached has no dispatch. There is no order relative to watch listeners. `advance` runs synchronously and must not block or
|
|
1078
|
+
* call Session APIs; a throw is reported as `listener_error`, detaches the observer, and ends it `listener_error`.
|
|
1079
|
+
* `end` is called once, when the Session closes (`ended`, after its last publication) or fails (`failed`), never
|
|
1080
|
+
* after `detach()`. Attaches synchronously; the observation has no `value`: commits are events, not a state, and the
|
|
1081
|
+
* Session does not know Storage's newest `seq` before its own first commit.
|
|
1082
|
+
*/
|
|
1083
|
+
observeCommits(observer: CommitObserver): CommitObservation;
|
|
949
1084
|
/**
|
|
950
1085
|
* Observe close synchronously when it begins, also when a failed Storage call closes the Session. The listener must
|
|
951
1086
|
* not block or call Session APIs.
|
|
@@ -957,15 +1092,14 @@ export interface Session extends DocumentObserver {
|
|
|
957
1092
|
snapshot<T extends JsonObject, I extends JsonValue>(token: SessionDocFamilyToken<T, I>, key: string, context: Context): Promise<Readonly<T> | undefined>;
|
|
958
1093
|
snapshot<T extends JsonObject, I extends JsonValue>(token: ConversationDocFamilyToken<T, I>, conversationId: ConversationId, key: string, context: Context): Promise<Readonly<T> | undefined>;
|
|
959
1094
|
snapshot<T extends JsonObject, I extends JsonValue>(token: TaskDocFamilyToken<T, I>, taskId: TaskId, key: string, context: Context): Promise<Readonly<T> | undefined>;
|
|
960
|
-
documentState<T extends JsonObject>(token: SessionDocToken<T>, context: Context): Promise<DocumentState<T> | undefined>;
|
|
961
|
-
documentState<T extends JsonObject>(token: ConversationDocToken<T>, conversationId: ConversationId, context: Context): Promise<DocumentState<T> | undefined>;
|
|
962
|
-
documentState<T extends JsonObject>(token: TaskDocToken<T>, taskId: TaskId, context: Context): Promise<DocumentState<T> | undefined>;
|
|
963
|
-
documentState<T extends JsonObject, I extends JsonValue>(token: SessionDocFamilyToken<T, I>, key: string, context: Context): Promise<DocumentState<T> | undefined>;
|
|
964
|
-
documentState<T extends JsonObject, I extends JsonValue>(token: ConversationDocFamilyToken<T, I>, conversationId: ConversationId, key: string, context: Context): Promise<DocumentState<T> | undefined>;
|
|
965
|
-
documentState<T extends JsonObject, I extends JsonValue>(token: TaskDocFamilyToken<T, I>, taskId: TaskId, key: string, context: Context): Promise<DocumentState<T> | undefined>;
|
|
966
1095
|
snapshotAsOf<T extends JsonObject>(token: RewindableConversationDocToken<T>, conversationId: ConversationId, at: EntryId, context: Context): Promise<Readonly<T> | undefined>;
|
|
967
1096
|
snapshotAsOf<T extends JsonObject, I extends JsonValue>(token: RewindableConversationDocFamilyToken<T, I>, conversationId: ConversationId, key: string, at: EntryId, context: Context): Promise<Readonly<T> | undefined>;
|
|
968
1097
|
}
|
|
1098
|
+
/** What `Storage.commit()` stored: the number of durable batches, and why the next one was refused, if one was. */
|
|
1099
|
+
export type CommitResult = {
|
|
1100
|
+
readonly stored: number;
|
|
1101
|
+
readonly refused?: unknown;
|
|
1102
|
+
};
|
|
969
1103
|
/**
|
|
970
1104
|
* Atomic persistence boundary for Session records.
|
|
971
1105
|
*
|
|
@@ -981,12 +1115,28 @@ export interface Session extends DocumentObserver {
|
|
|
981
1115
|
*/
|
|
982
1116
|
export interface Storage {
|
|
983
1117
|
/**
|
|
984
|
-
*
|
|
1118
|
+
* Persist `batches` in order, each as one ordinary atomic commit with its own seq, checked against the state the
|
|
1119
|
+
* earlier ones left, in as few round trips as the backend can. Every batch has at least one write: a commit without
|
|
1120
|
+
* writes never reaches Storage, so the Session never sends an empty batch. Stops at the first batch Durable's own checks refuse
|
|
1121
|
+
* (global IDs, document actions, copy resolution): the batches before it are durable, it and the ones after are not.
|
|
1122
|
+
* Calls `receive(index, seq)` once per durable batch, in order, synchronously, after all of them are durable and
|
|
1123
|
+
* before the next commit starts. Resolves with the number of durable batches and the refusal, if any. Rejects for an
|
|
1124
|
+
* unknown outcome (connection lost, statement or commit failed); `receive` calls made before the rejection still
|
|
1125
|
+
* stand. `receive` is a durability receipt, not publication: the Session publishes later. Once it resolved, later
|
|
1126
|
+
* reads through this storage observe the stored batches.
|
|
1127
|
+
*/
|
|
1128
|
+
commit(batches: readonly (readonly StorageWrite[])[], receive: (index: number, seq: Seq) => void, context: Context): Promise<CommitResult>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Optional. Run `publish`, the Session's publication of one stored or held commit (its cache write-through,
|
|
1131
|
+
* adoption, and observers), inside this storage's own scope, such as a store's attached host batch, so what the
|
|
1132
|
+
* publication marks lands together. Call `publish` exactly once, now or soon after; the Session publishes the next
|
|
1133
|
+
* commit only once it ran. Without it, the Session publishes directly.
|
|
985
1134
|
*/
|
|
986
|
-
|
|
1135
|
+
publishing?(publish: () => void, context: Context): void;
|
|
987
1136
|
/**
|
|
988
|
-
* Return a fresh branded candidate from the Session-global numeric ID namespace, greater than every ID minted
|
|
989
|
-
*
|
|
1137
|
+
* Return a fresh branded candidate from the Session-global numeric ID namespace, greater than every ID minted since
|
|
1138
|
+
* this storage was opened and every ID stored, also across reopen: scans order by ID as creation order, and the
|
|
1139
|
+
* Harness relies on it.
|
|
990
1140
|
*/
|
|
991
1141
|
mintId<I extends Id<string>>(): Promise<I>;
|
|
992
1142
|
/** Look up one conversation by exact ID. */
|