@fungi.computer/shiitake 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +454 -2
- package/dist/agar-extension.d.ts +9 -0
- package/dist/agar-extension.js +38 -0
- package/dist/agent-control.d.ts +77 -0
- package/dist/agent-control.js +434 -0
- package/dist/client-entry.d.ts +211 -0
- package/dist/client-entry.js +101 -0
- package/dist/client-wire.d.ts +199 -0
- package/dist/client-wire.js +271 -0
- package/dist/client.d.ts +439 -0
- package/dist/client.js +4 -0
- package/dist/cloudflare.d.ts +220 -0
- package/dist/cloudflare.js +531 -0
- package/dist/effect.d.ts +42 -0
- package/dist/effect.js +20 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.js +81 -0
- package/dist/extension-client.d.ts +38 -0
- package/dist/extension-client.js +56 -0
- package/dist/extension-contract.d.ts +73 -0
- package/dist/extension-contract.js +11 -0
- package/dist/extensions.d.ts +589 -0
- package/dist/extensions.js +263 -0
- package/dist/fleet.d.ts +313 -0
- package/dist/fleet.js +540 -0
- package/dist/hosted.d.ts +133 -0
- package/dist/hosted.js +265 -0
- package/dist/http-routes.d.ts +772 -0
- package/dist/http-routes.js +242 -0
- package/dist/http.d.ts +1 -0
- package/dist/http.js +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +13 -0
- package/dist/internal/accepted-run-executor.d.ts +23 -0
- package/dist/internal/accepted-run-executor.js +129 -0
- package/dist/internal/admission-door.d.ts +75 -0
- package/dist/internal/admission-door.js +105 -0
- package/dist/internal/agent-close.d.ts +4 -0
- package/dist/internal/agent-close.js +42 -0
- package/dist/internal/browser-sessions.d.ts +31 -0
- package/dist/internal/browser-sessions.js +173 -0
- package/dist/internal/client-boundary.d.ts +262 -0
- package/dist/internal/client-boundary.js +202 -0
- package/dist/internal/compaction/compaction.d.ts +54 -0
- package/dist/internal/compaction/compaction.js +291 -0
- package/dist/internal/compaction/session-compaction.d.ts +69 -0
- package/dist/internal/compaction/session-compaction.js +330 -0
- package/dist/internal/compaction/settings.d.ts +11 -0
- package/dist/internal/compaction/settings.js +40 -0
- package/dist/internal/compaction/utils.d.ts +45 -0
- package/dist/internal/compaction/utils.js +319 -0
- package/dist/internal/contracts.d.ts +235 -0
- package/dist/internal/contracts.js +1 -0
- package/dist/internal/coordinator.d.ts +18 -0
- package/dist/internal/coordinator.js +362 -0
- package/dist/internal/document-codec.d.ts +11 -0
- package/dist/internal/document-codec.js +39 -0
- package/dist/internal/effect-client.d.ts +13 -0
- package/dist/internal/effect-client.js +102 -0
- package/dist/internal/effect-contracts.d.ts +236 -0
- package/dist/internal/effect-contracts.js +2 -0
- package/dist/internal/extension-command-registry.d.ts +11 -0
- package/dist/internal/extension-command-registry.js +29 -0
- package/dist/internal/extension-command-tools.d.ts +17 -0
- package/dist/internal/extension-command-tools.js +50 -0
- package/dist/internal/extension-context.d.ts +25 -0
- package/dist/internal/extension-context.js +35 -0
- package/dist/internal/extension-definitions.d.ts +5 -0
- package/dist/internal/extension-definitions.js +6 -0
- package/dist/internal/extension-hook.d.ts +25 -0
- package/dist/internal/extension-hook.js +46 -0
- package/dist/internal/extension-roster.d.ts +23 -0
- package/dist/internal/extension-roster.js +228 -0
- package/dist/internal/extension-runtime.d.ts +63 -0
- package/dist/internal/extension-runtime.js +1004 -0
- package/dist/internal/failure.d.ts +2 -0
- package/dist/internal/failure.js +9 -0
- package/dist/internal/host-meta.d.ts +41 -0
- package/dist/internal/host-meta.js +39 -0
- package/dist/internal/json-value.d.ts +4 -0
- package/dist/internal/json-value.js +3 -0
- package/dist/internal/model-acquisition.d.ts +21 -0
- package/dist/internal/model-acquisition.js +98 -0
- package/dist/internal/model-preference.d.ts +21 -0
- package/dist/internal/model-preference.js +20 -0
- package/dist/internal/observation-kernel.d.ts +28 -0
- package/dist/internal/observation-kernel.js +169 -0
- package/dist/internal/promise-facade.d.ts +18 -0
- package/dist/internal/promise-facade.js +172 -0
- package/dist/internal/run-scope.d.ts +27 -0
- package/dist/internal/run-scope.js +214 -0
- package/dist/internal/runtime-coordinator.d.ts +34 -0
- package/dist/internal/runtime-coordinator.js +233 -0
- package/dist/internal/runtime-core.d.ts +19 -0
- package/dist/internal/runtime-core.js +39 -0
- package/dist/internal/runtime-reconciliation.d.ts +18 -0
- package/dist/internal/runtime-reconciliation.js +162 -0
- package/dist/internal/session-context.d.ts +11 -0
- package/dist/internal/session-context.js +67 -0
- package/dist/internal/session-status.d.ts +10 -0
- package/dist/internal/session-status.js +52 -0
- package/dist/internal/woodstock/agent-reply.d.ts +25 -0
- package/dist/internal/woodstock/agent-reply.js +67 -0
- package/dist/internal/woodstock/client-projection.d.ts +29 -0
- package/dist/internal/woodstock/client-projection.js +512 -0
- package/dist/internal/woodstock/compaction-activity.d.ts +17 -0
- package/dist/internal/woodstock/compaction-activity.js +32 -0
- package/dist/internal/woodstock/cursor.d.ts +9 -0
- package/dist/internal/woodstock/cursor.js +44 -0
- package/dist/internal/woodstock/extension-store.d.ts +72 -0
- package/dist/internal/woodstock/extension-store.js +262 -0
- package/dist/internal/woodstock/fleet-store.d.ts +36 -0
- package/dist/internal/woodstock/fleet-store.js +100 -0
- package/dist/internal/woodstock/identities.d.ts +6 -0
- package/dist/internal/woodstock/identities.js +11 -0
- package/dist/internal/woodstock/index.d.ts +170 -0
- package/dist/internal/woodstock/index.js +546 -0
- package/dist/internal/woodstock/progress.d.ts +32 -0
- package/dist/internal/woodstock/progress.js +89 -0
- package/dist/internal/woodstock/run-recovery.d.ts +8 -0
- package/dist/internal/woodstock/run-recovery.js +95 -0
- package/dist/internal/woodstock/session-attention.d.ts +16 -0
- package/dist/internal/woodstock/session-attention.js +88 -0
- package/dist/internal/woodstock/session-documents.d.ts +18 -0
- package/dist/internal/woodstock/session-documents.js +51 -0
- package/dist/internal/woodstock/session-entry.d.ts +478 -0
- package/dist/internal/woodstock/session-entry.js +484 -0
- package/dist/internal/woodstock/session-grants.d.ts +24 -0
- package/dist/internal/woodstock/session-grants.js +84 -0
- package/dist/internal/woodstock/session-inbox.d.ts +56 -0
- package/dist/internal/woodstock/session-inbox.js +307 -0
- package/dist/internal/woodstock/session-store.d.ts +432 -0
- package/dist/internal/woodstock/session-store.js +2006 -0
- package/dist/internal/woodstock/storage-admission.d.ts +14 -0
- package/dist/internal/woodstock/storage-admission.js +44 -0
- package/dist/model-preference.d.ts +20 -0
- package/dist/model-preference.js +30 -0
- package/dist/node.d.ts +64 -0
- package/dist/node.js +256 -0
- package/dist/remote-client.d.ts +11 -0
- package/dist/remote-client.js +298 -0
- package/dist/session-attention.d.ts +35 -0
- package/dist/session-attention.js +22 -0
- package/dist/session-documents.d.ts +28 -0
- package/dist/session-documents.js +1 -0
- package/dist/testing.d.ts +54 -0
- package/dist/testing.js +215 -0
- package/docs/api/README.md +26 -0
- package/docs/api/agar-extension.md +40 -0
- package/docs/api/agent-control.md +151 -0
- package/docs/api/client-entry.md +344 -0
- package/docs/api/client.md +1112 -0
- package/docs/api/cloudflare.md +500 -0
- package/docs/api/effect.md +884 -0
- package/docs/api/extensions.md +2003 -0
- package/docs/api/fleet.md +734 -0
- package/docs/api/hosted.md +382 -0
- package/docs/api/http.md +111 -0
- package/docs/api/index.md +1116 -0
- package/docs/api/model-preference.md +151 -0
- package/docs/api/node.md +142 -0
- package/docs/api/testing.md +250 -0
- package/package.json +130 -3
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import type { Message, Usage, MuleResume } from "@fungi.computer/mule/effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import type { ModelPreference } from "../model-preference.js";
|
|
4
|
+
import type { AcceptedWork } from "../client-boundary.js";
|
|
5
|
+
import type { Json } from "../../extensions.js";
|
|
6
|
+
import type { SqliteOwner } from "../contracts.js";
|
|
7
|
+
import { type CompactionTrigger, type StoredSessionEntry } from "./session-entry.js";
|
|
8
|
+
import type { VerifiedAgentReply } from "./agent-reply.js";
|
|
9
|
+
/**
|
|
10
|
+
* Who admitted one accepted command: a human, host or addressed caller
|
|
11
|
+
* (`user`), or one rostered extension with its correlation.
|
|
12
|
+
*/
|
|
13
|
+
export declare const ExtensionAdmissionOriginSchema: Schema.Struct<{
|
|
14
|
+
readonly kind: Schema.Literal<"extension">;
|
|
15
|
+
readonly extensionId: Schema.String;
|
|
16
|
+
readonly correlation: Schema.NullOr<Schema.String>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const AdmissionOriginSchema: Schema.Union<readonly [Schema.Struct<{
|
|
19
|
+
readonly kind: Schema.Literal<"user">;
|
|
20
|
+
}>, Schema.Struct<{
|
|
21
|
+
readonly kind: Schema.Literal<"extension">;
|
|
22
|
+
readonly extensionId: Schema.String;
|
|
23
|
+
readonly correlation: Schema.NullOr<Schema.String>;
|
|
24
|
+
}>]>;
|
|
25
|
+
/** Durable producer tag stored with every accepted command. */
|
|
26
|
+
export type AdmissionOrigin = Schema.Schema.Type<typeof AdmissionOriginSchema>;
|
|
27
|
+
/** One decoded row in the retained Session entry tree. */
|
|
28
|
+
export type StoredSessionRow = Readonly<{
|
|
29
|
+
id: string;
|
|
30
|
+
sessionId: string;
|
|
31
|
+
parentId: string | null;
|
|
32
|
+
sequence: number;
|
|
33
|
+
state: "complete" | "streaming";
|
|
34
|
+
timestamp: number;
|
|
35
|
+
completedAt: number | null;
|
|
36
|
+
entry: StoredSessionEntry;
|
|
37
|
+
}>;
|
|
38
|
+
/** Persisted conversation facts; run status belongs to the Session's owner. */
|
|
39
|
+
export type StoredSessionSummary = Readonly<{
|
|
40
|
+
createdAt: number;
|
|
41
|
+
updatedAt: number;
|
|
42
|
+
title: string;
|
|
43
|
+
}>;
|
|
44
|
+
/** One persisted conversation's stored facts, or a row that could not be read. */
|
|
45
|
+
export type StoredSessionSummaryRow = (StoredSessionSummary & Readonly<{
|
|
46
|
+
kind: "session";
|
|
47
|
+
sessionId: string;
|
|
48
|
+
}>) | Readonly<{
|
|
49
|
+
kind: "unavailable";
|
|
50
|
+
sessionId: string;
|
|
51
|
+
}>;
|
|
52
|
+
/** One page of stored conversation facts, in stable Session identity order. */
|
|
53
|
+
export type StoredSessionSummaryPage = Readonly<{
|
|
54
|
+
sessions: readonly StoredSessionSummaryRow[];
|
|
55
|
+
next: string | undefined;
|
|
56
|
+
}>;
|
|
57
|
+
export declare function readStoredSessionFactPage(owner: SqliteOwner, after?: string): StoredSessionSummaryPage;
|
|
58
|
+
/**
|
|
59
|
+
* Read one persisted Session's stored title facts without opening its host.
|
|
60
|
+
* This is the one title read: the user's title when set, otherwise the
|
|
61
|
+
* title derived from the first entered prompt.
|
|
62
|
+
*/
|
|
63
|
+
export declare function readStoredSessionSummary(owner: SqliteOwner, sessionId: string): StoredSessionSummary | undefined;
|
|
64
|
+
export type AppendSessionEntryInput = Readonly<{
|
|
65
|
+
sessionId: string;
|
|
66
|
+
id: string;
|
|
67
|
+
entry: StoredSessionEntry;
|
|
68
|
+
state?: "complete" | "streaming";
|
|
69
|
+
}>;
|
|
70
|
+
export type CompleteSessionLeafInput = Readonly<{
|
|
71
|
+
sessionId: string;
|
|
72
|
+
id: string;
|
|
73
|
+
entry: Extract<StoredSessionEntry, {
|
|
74
|
+
kind: "message";
|
|
75
|
+
}>;
|
|
76
|
+
}>;
|
|
77
|
+
export type ReadSelectedPathInput = Readonly<{
|
|
78
|
+
sessionId: string;
|
|
79
|
+
leafId?: string;
|
|
80
|
+
}>;
|
|
81
|
+
export type SessionQueueHead = Readonly<{
|
|
82
|
+
state: "idle";
|
|
83
|
+
}> | Readonly<{
|
|
84
|
+
state: "queued" | "running";
|
|
85
|
+
jobId: string;
|
|
86
|
+
cancellationRequested: boolean;
|
|
87
|
+
}>;
|
|
88
|
+
export type PrepareSessionRunInput = Readonly<{
|
|
89
|
+
sessionId: string;
|
|
90
|
+
commandFactId: string;
|
|
91
|
+
}>;
|
|
92
|
+
export type PreparedSessionRun = Readonly<{
|
|
93
|
+
command: StoredSessionRow & Readonly<{
|
|
94
|
+
entry: Extract<StoredSessionEntry, {
|
|
95
|
+
kind: "command";
|
|
96
|
+
}>;
|
|
97
|
+
}>;
|
|
98
|
+
modelPreference: ModelPreference | null;
|
|
99
|
+
messages: readonly Message[];
|
|
100
|
+
/**
|
|
101
|
+
* Context rows, not the whole lineage: the latest compaction's kept window
|
|
102
|
+
* through this work, after the few older facts that still decide it.
|
|
103
|
+
*/
|
|
104
|
+
path: readonly StoredSessionRow[];
|
|
105
|
+
entryDelivery: "new" | "replay";
|
|
106
|
+
resume: MuleResume | undefined;
|
|
107
|
+
abnormalTerminal: "failed" | "cancelled" | undefined;
|
|
108
|
+
}>;
|
|
109
|
+
export type StoredSessionCommandEntry = Extract<StoredSessionEntry, {
|
|
110
|
+
kind: "command";
|
|
111
|
+
}>;
|
|
112
|
+
/** One stable private command admission before conversation entry. */
|
|
113
|
+
export type StoredCommandAdmission = Readonly<{
|
|
114
|
+
id: string;
|
|
115
|
+
sessionId: string;
|
|
116
|
+
/** Durable acceptance-fact order; never a conversation-entry sequence. */
|
|
117
|
+
sequence: number;
|
|
118
|
+
timestamp: number;
|
|
119
|
+
entry: StoredSessionCommandEntry;
|
|
120
|
+
/** Producer that admitted this command through the accepted-command door. */
|
|
121
|
+
origin: AdmissionOrigin;
|
|
122
|
+
}>;
|
|
123
|
+
export type RunContract = StoredSessionCommandEntry["contract"];
|
|
124
|
+
export type AppendCompactionInput = Readonly<{
|
|
125
|
+
resumesRun?: boolean;
|
|
126
|
+
trigger: CompactionTrigger;
|
|
127
|
+
/** Estimated context tokens once this compaction is the boundary. */
|
|
128
|
+
tokensAfter: number;
|
|
129
|
+
sessionId: string;
|
|
130
|
+
expectedLeafId: string;
|
|
131
|
+
workId: string;
|
|
132
|
+
firstKeptEntryId: string;
|
|
133
|
+
summary: string;
|
|
134
|
+
tokensBefore: number;
|
|
135
|
+
usage: Usage;
|
|
136
|
+
contextRevision: string;
|
|
137
|
+
details?: Readonly<{
|
|
138
|
+
readFiles: readonly string[];
|
|
139
|
+
modifiedFiles: readonly string[];
|
|
140
|
+
}>;
|
|
141
|
+
}>;
|
|
142
|
+
/** Private owner identities retained after one durable acceptance commit. */
|
|
143
|
+
export type AcceptedCommand = Readonly<{
|
|
144
|
+
sessionId: string;
|
|
145
|
+
requestId: string;
|
|
146
|
+
commandId: string;
|
|
147
|
+
}>;
|
|
148
|
+
export type AcceptedSessionCommand = Readonly<{
|
|
149
|
+
accepted: AcceptedCommand;
|
|
150
|
+
command: StoredCommandAdmission;
|
|
151
|
+
delivery: "new" | "replay";
|
|
152
|
+
}>;
|
|
153
|
+
export type AcceptedSessionCancellation = Readonly<{
|
|
154
|
+
accepted: Readonly<{
|
|
155
|
+
commandId: string;
|
|
156
|
+
entryId: string;
|
|
157
|
+
}>;
|
|
158
|
+
delivery: "new" | "replay";
|
|
159
|
+
/** True when the target is the live Watchdog execution. */
|
|
160
|
+
active: boolean;
|
|
161
|
+
}>;
|
|
162
|
+
export type EnqueueAcceptedWork = (work: Readonly<{
|
|
163
|
+
jobId: string;
|
|
164
|
+
sessionId: string;
|
|
165
|
+
commandFactId: string;
|
|
166
|
+
}>) => void;
|
|
167
|
+
export type RecordAcceptedCancellation = (input: Readonly<{
|
|
168
|
+
jobId: string;
|
|
169
|
+
cancellationId: string;
|
|
170
|
+
onlyIfPending?: boolean;
|
|
171
|
+
}>) => Readonly<{
|
|
172
|
+
status: "recorded" | "replayed" | "conflict" | "missing";
|
|
173
|
+
}>;
|
|
174
|
+
export type SessionTreeNode = Readonly<{
|
|
175
|
+
row: StoredSessionRow;
|
|
176
|
+
children: readonly SessionTreeNode[];
|
|
177
|
+
}>;
|
|
178
|
+
export type SessionTreeInput = Readonly<{
|
|
179
|
+
sessionId: string;
|
|
180
|
+
}>;
|
|
181
|
+
export type SelectSessionBranchInput = Readonly<{
|
|
182
|
+
sessionId: string;
|
|
183
|
+
entryId: string;
|
|
184
|
+
assertIdleSession?: (queue: string) => void;
|
|
185
|
+
}>;
|
|
186
|
+
export type ForkSessionAtInput = SelectSessionBranchInput;
|
|
187
|
+
/** Bounded existence check; admission conditions never need transcript history. */
|
|
188
|
+
export declare function hasStoredSession(owner: SqliteOwner, sessionId: string): boolean;
|
|
189
|
+
/** Read one retained Session entry by its globally unique row identity. */
|
|
190
|
+
export declare function readSessionEntryById(owner: SqliteOwner, id: string): StoredSessionRow | undefined;
|
|
191
|
+
/** Read waiting admission facts without consulting or recreating scheduler order. */
|
|
192
|
+
export declare function readPendingSessionCommands(owner: SqliteOwner, sessionId: string, limit: number, only?: "all" | "prompts"): {
|
|
193
|
+
commands: Readonly<{
|
|
194
|
+
id: string;
|
|
195
|
+
sessionId: string;
|
|
196
|
+
/** Durable acceptance-fact order; never a conversation-entry sequence. */
|
|
197
|
+
sequence: number;
|
|
198
|
+
timestamp: number;
|
|
199
|
+
entry: StoredSessionCommandEntry;
|
|
200
|
+
/** Producer that admitted this command through the accepted-command door. */
|
|
201
|
+
origin: AdmissionOrigin;
|
|
202
|
+
}>[];
|
|
203
|
+
total: number;
|
|
204
|
+
};
|
|
205
|
+
/** Observe one pending steer without materializing or consuming its admission. */
|
|
206
|
+
export declare function hasPendingSessionSteer(owner: SqliteOwner, sessionId: string, workId: string): boolean;
|
|
207
|
+
/** Materialize controls at one Mule safe point exactly once. */
|
|
208
|
+
export declare function takePendingSessionControls(owner: SqliteOwner, sessionId: string, delivery: "steer" | "followUp", targetWorkId: string): readonly Readonly<{
|
|
209
|
+
workId: string;
|
|
210
|
+
requestId: string;
|
|
211
|
+
message: Message;
|
|
212
|
+
}>[];
|
|
213
|
+
/** Settle controls delivered by one parent run, exactly once per request. */
|
|
214
|
+
export declare function settleSessionControls(owner: SqliteOwner, input: Readonly<{
|
|
215
|
+
sessionId: string;
|
|
216
|
+
parentWorkId: string;
|
|
217
|
+
outcome: "completed" | "cancelled" | "failed" | "interrupted";
|
|
218
|
+
enqueue: EnqueueAcceptedWork;
|
|
219
|
+
}>): void;
|
|
220
|
+
/** Read one stable private command admission by accepted work identity. */
|
|
221
|
+
export declare function readSessionCommandAdmission(owner: SqliteOwner, sessionId: string, id: string): StoredCommandAdmission | undefined;
|
|
222
|
+
/** Read one stable private command admission by accepted request identity. */
|
|
223
|
+
export declare function readSessionCommandAdmissionByRequest(owner: SqliteOwner, sessionId: string, requestId: string): StoredCommandAdmission | undefined;
|
|
224
|
+
/** Read entries correlated to one accepted work identity in Session order. */
|
|
225
|
+
export declare function readSessionEntriesForWork(owner: SqliteOwner, sessionId: string, workId: string): readonly StoredSessionRow[];
|
|
226
|
+
/** Read the latest retained live-retry event for one accepted work item. */
|
|
227
|
+
export declare function readLatestLiveRetryForWork(owner: SqliteOwner, sessionId: string, workId: string): Readonly<{
|
|
228
|
+
event: Extract<StoredSessionEntry, {
|
|
229
|
+
kind: "live_retry";
|
|
230
|
+
}>["event"];
|
|
231
|
+
timestamp: number;
|
|
232
|
+
}> | undefined;
|
|
233
|
+
/** An indexed existence read: recovery errors never acknowledge successful delivery. */
|
|
234
|
+
export declare function hasSuccessfulToolResult(owner: SqliteOwner, sessionId: string, workId: string, toolCallId: string): boolean;
|
|
235
|
+
/** Most recent tool intent without a matching outcome for the running work. */
|
|
236
|
+
export declare function readActiveToolForWork(owner: SqliteOwner, sessionId: string, workId: string): string | undefined;
|
|
237
|
+
/** Reserve or replay a durable Session identity before its first prompt. */
|
|
238
|
+
export declare function createStoredSession(owner: SqliteOwner, requestId: string,
|
|
239
|
+
/** Refuses a new Session under storage pressure; replays skip it. */
|
|
240
|
+
admitNew: () => void): string;
|
|
241
|
+
/**
|
|
242
|
+
* Permanently remove one idle Session: its entries, command admissions,
|
|
243
|
+
* creation receipt and inbox row, so a retried creation request reserves a
|
|
244
|
+
* fresh Session.
|
|
245
|
+
* Returns false when the Session does not exist.
|
|
246
|
+
*/
|
|
247
|
+
export declare function deleteStoredSession(owner: SqliteOwner, input: Readonly<{
|
|
248
|
+
sessionId: string;
|
|
249
|
+
assertIdleSession: (queue: string) => void;
|
|
250
|
+
recordInboxDeletion: (sessionId: string) => void;
|
|
251
|
+
}>): boolean;
|
|
252
|
+
/** Create the retained Session schema and private creation/admission receipts. */
|
|
253
|
+
export declare function prepareSessionStore(owner: SqliteOwner): void;
|
|
254
|
+
/** Read the nullable preference at exactly this selected lineage. */
|
|
255
|
+
export declare function readSessionModelPreference(owner: SqliteOwner, sessionId: string): ModelPreference | null;
|
|
256
|
+
/**
|
|
257
|
+
* Woodstock order of the newest model choice on the selected lineage, or null.
|
|
258
|
+
* Clients compare it with terminal orders; Woodstock assigns it no meaning.
|
|
259
|
+
*/
|
|
260
|
+
export declare function readLastModelChoiceSequence(owner: SqliteOwner, sessionId: string): number | null;
|
|
261
|
+
/** Append a decoded preference request; no command or scheduler work is minted. */
|
|
262
|
+
export declare function setSessionModelPreference(owner: SqliteOwner, sessionId: string, preference: ModelPreference | null): StoredSessionRow;
|
|
263
|
+
/**
|
|
264
|
+
* Set or clear the user's Session title. Display metadata only: no entry is
|
|
265
|
+
* appended, so history, the selected leaf and recency are unchanged. Setting
|
|
266
|
+
* the same value again is a no-op write.
|
|
267
|
+
*/
|
|
268
|
+
export declare function setSessionTitle(owner: SqliteOwner, sessionId: string, title: string | null): void;
|
|
269
|
+
/**
|
|
270
|
+
* The retained append word.
|
|
271
|
+
*
|
|
272
|
+
* Complete entries advance the selected leaf. A streaming message placeholder
|
|
273
|
+
* is durable but deliberately leaves the selected branch unchanged.
|
|
274
|
+
*/
|
|
275
|
+
export declare function appendSessionEntry(owner: SqliteOwner, input: AppendSessionEntryInput): StoredSessionRow;
|
|
276
|
+
/**
|
|
277
|
+
* The retained leaf-finalize word.
|
|
278
|
+
*
|
|
279
|
+
* The private placeholder keeps its message identity. When the complete leaf
|
|
280
|
+
* advanced during streaming, finish after that leaf with a fresh sequence.
|
|
281
|
+
* Otherwise retain its original position. Completed history is never moved.
|
|
282
|
+
*/
|
|
283
|
+
export declare function completeSessionLeaf(owner: SqliteOwner, input: CompleteSessionLeafInput): StoredSessionRow;
|
|
284
|
+
/** Rows one bounded lineage read decodes at once. */
|
|
285
|
+
export declare const lineageRowLimit = 200;
|
|
286
|
+
/**
|
|
287
|
+
* Stored bytes one model context read may decode: the retained storage
|
|
288
|
+
* plane's `LLM_CONTEXT_BYTES`, now a typed refusal rather than a silent
|
|
289
|
+
* truncation, because a truncated context would change the model's input.
|
|
290
|
+
*/
|
|
291
|
+
export declare const contextByteLimit: number;
|
|
292
|
+
/**
|
|
293
|
+
* Root-to-tip walks carry identities only (the 2026-08-15 connection-plane
|
|
294
|
+
* law); entry data is read afterwards for exactly the rows a reader needs.
|
|
295
|
+
* The selected walk drops streaming placeholders after walking; the fork walk
|
|
296
|
+
* stops at them, as a fork copies only complete history.
|
|
297
|
+
*/
|
|
298
|
+
declare const lineageWalks: {
|
|
299
|
+
readonly selected: "WITH RECURSIVE branch (id, parent_id, sequence, state) AS (\n SELECT id, parent_id, sequence, state\n FROM session_entries\n WHERE session_id = ? AND id = ?\n UNION\n SELECT parent.id, parent.parent_id, parent.sequence, parent.state\n FROM session_entries AS parent\n JOIN branch AS child ON parent.id = child.parent_id\n WHERE parent.session_id = ?\n )";
|
|
300
|
+
readonly fork: "WITH RECURSIVE branch (id, parent_id, sequence, state) AS (\n SELECT id, parent_id, sequence, state\n FROM session_entries\n WHERE session_id = ? AND id = ? AND state != 'streaming'\n UNION\n SELECT parent.id, parent.parent_id, parent.sequence, parent.state\n FROM session_entries AS parent\n JOIN branch AS child ON parent.id = child.parent_id\n WHERE parent.session_id = ? AND parent.state != 'streaming'\n )";
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* One validated root-to-tip lineage, located in SQL without decoding its
|
|
304
|
+
* rows. Readers take bounded windows of it by sequence.
|
|
305
|
+
*/
|
|
306
|
+
export type SessionLineage = Readonly<{
|
|
307
|
+
sessionId: string;
|
|
308
|
+
walk: keyof typeof lineageWalks;
|
|
309
|
+
/** The entry the walk starts from: the selected leaf or a fork point. */
|
|
310
|
+
tipId: string;
|
|
311
|
+
/** The oldest row; client cursors carry it as their generation. */
|
|
312
|
+
rootId: string;
|
|
313
|
+
newestId: string;
|
|
314
|
+
newestSequence: number;
|
|
315
|
+
}>;
|
|
316
|
+
/** Locate the selected lineage; undefined when the Session has no leaf. */
|
|
317
|
+
export declare function readSessionLineage(owner: SqliteOwner, input: ReadSelectedPathInput): SessionLineage | undefined;
|
|
318
|
+
export type LineageWindowInput = Readonly<{
|
|
319
|
+
/** Exclusive lower sequence bound; omitted starts at the root. */
|
|
320
|
+
after?: number;
|
|
321
|
+
/** Exclusive upper sequence bound; omitted ends at the newest row. */
|
|
322
|
+
before?: number;
|
|
323
|
+
/** `newest` takes rows backward from `before`, `oldest` forward from `after`. */
|
|
324
|
+
from: "oldest" | "newest";
|
|
325
|
+
/** Most rows to take; the stored-byte bound may stop the window earlier. */
|
|
326
|
+
rows: number;
|
|
327
|
+
}>;
|
|
328
|
+
/** A contiguous run of lineage rows, oldest first, and whether more remain. */
|
|
329
|
+
export type LineageWindow = Readonly<{
|
|
330
|
+
rows: readonly StoredSessionRow[];
|
|
331
|
+
more: boolean;
|
|
332
|
+
}>;
|
|
333
|
+
/**
|
|
334
|
+
* Read one contiguous window of a lineage, bounded by row count and by stored
|
|
335
|
+
* bytes. Row sizes are measured in SQL before any entry is decoded.
|
|
336
|
+
*/
|
|
337
|
+
export declare function readLineageWindow(owner: SqliteOwner, lineage: SessionLineage, input: LineageWindowInput): LineageWindow;
|
|
338
|
+
/** Whether a complete row with this sequence lies on the lineage. */
|
|
339
|
+
export declare function lineageHasSequence(owner: SqliteOwner, lineage: SessionLineage, rowSequence: number): boolean;
|
|
340
|
+
/** The sequence of one complete row on the lineage, if it is there. */
|
|
341
|
+
export declare function lineageEntrySequence(owner: SqliteOwner, lineage: SessionLineage, id: string): number | undefined;
|
|
342
|
+
/** What a bounded client page needs to know about the works it shows. */
|
|
343
|
+
export type LineageWorkFacts = Readonly<{
|
|
344
|
+
/** Works whose command entry lies on the lineage. */
|
|
345
|
+
commands: ReadonlySet<string>;
|
|
346
|
+
/** Newest failure text each work recorded on the lineage. */
|
|
347
|
+
diagnostics: ReadonlyMap<string, string>;
|
|
348
|
+
/** Host metadata of the cancellation that ended each work. */
|
|
349
|
+
cancellations: ReadonlyMap<string, Json>;
|
|
350
|
+
}>;
|
|
351
|
+
/**
|
|
352
|
+
* Look up, across the whole lineage, only the facts of the given works. A
|
|
353
|
+
* diagnostic is the newest of an assistant error, a final retry error or a
|
|
354
|
+
* work terminal's diagnostic; only that text is extracted, never the message.
|
|
355
|
+
*/
|
|
356
|
+
export declare function readLineageWorkFacts(owner: SqliteOwner, lineage: SessionLineage, workIds: ReadonlySet<string>): LineageWorkFacts;
|
|
357
|
+
/**
|
|
358
|
+
* Read one complete selected root-to-leaf branch, decoding every row.
|
|
359
|
+
*
|
|
360
|
+
* Heap grows with the whole lineage, so no production reader uses this:
|
|
361
|
+
* clients page with `readLineageWindow`, runs read `readSessionContextPath`.
|
|
362
|
+
*/
|
|
363
|
+
export declare function readSelectedPath(owner: SqliteOwner, input: ReadSelectedPathInput): readonly StoredSessionRow[];
|
|
364
|
+
/**
|
|
365
|
+
* Context rows of the current selected lineage for one accepted work, or,
|
|
366
|
+
* without a work, the settled context the next run starts from.
|
|
367
|
+
*/
|
|
368
|
+
export declare function readSessionContextPath(owner: SqliteOwner, input: Readonly<{
|
|
369
|
+
sessionId: string;
|
|
370
|
+
workId?: string;
|
|
371
|
+
}>): readonly StoredSessionRow[];
|
|
372
|
+
/** Work cancelled before delivery stays in history but never enters model context. */
|
|
373
|
+
export declare function withdrawnWorkIds(path: readonly StoredSessionRow[]): ReadonlySet<string>;
|
|
374
|
+
export declare function buildSessionContext(path: readonly StoredSessionRow[], activeWorkId?: string): readonly Message[];
|
|
375
|
+
/** Prepare one accepted command against its frozen selected lineage. */
|
|
376
|
+
export declare function prepareSessionRun(owner: SqliteOwner, input: PrepareSessionRunInput): PreparedSessionRun;
|
|
377
|
+
/** One compaction that committed nothing, recorded so clients show the result. */
|
|
378
|
+
export type CompactionNoticeInput = Readonly<{
|
|
379
|
+
sessionId: string;
|
|
380
|
+
workId: string;
|
|
381
|
+
trigger: CompactionTrigger;
|
|
382
|
+
result: "nothing_to_compact" | "failed";
|
|
383
|
+
/** Bounded, display-safe reason; only a failure carries one. */
|
|
384
|
+
diagnostic?: string | undefined;
|
|
385
|
+
}>;
|
|
386
|
+
/** Append one compaction notice on the selected lineage. */
|
|
387
|
+
export declare function appendCompactionNoticeOwned(owner: SqliteOwner, input: CompactionNoticeInput): StoredSessionRow;
|
|
388
|
+
/** Atomically append one compaction transition using the selected leaf CAS. */
|
|
389
|
+
export declare function appendCompactionTransitionOwned(owner: SqliteOwner, input: AppendCompactionInput): StoredSessionRow;
|
|
390
|
+
/**
|
|
391
|
+
* Write one decoded admission (a prompt or a compaction request) and its one
|
|
392
|
+
* durable work pointer.
|
|
393
|
+
*
|
|
394
|
+
* Only the accepted-command door (`internal/admission-door.ts`) calls this,
|
|
395
|
+
* inside its owner transaction. A retried request id replays only when the
|
|
396
|
+
* whole canonical command (kind, delivery, text, images, host metadata,
|
|
397
|
+
* verified reply and origin) is unchanged.
|
|
398
|
+
*/
|
|
399
|
+
export declare function acceptSessionCommandOwned(owner: SqliteOwner, sessionId: string, input: AcceptedWork, meta: Json | undefined, origin: AdmissionOrigin, contract: RunContract, enqueue: EnqueueAcceptedWork | undefined, targetWorkId?: string, reply?: VerifiedAgentReply): AcceptedSessionCommand;
|
|
400
|
+
/** Cancel the running turn and every waiting admission in one owner transaction. */
|
|
401
|
+
export declare function acceptSessionAbort(owner: SqliteOwner, sessionId: string, readQueueHead: () => SessionQueueHead, record: RecordAcceptedCancellation, meta?: Json): AcceptedSessionCancellation | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* Atomically resolve one accepted request and delegate queued work to
|
|
404
|
+
* Watchdog. `undefined` means it is too late (or the id names nothing): the
|
|
405
|
+
* command is unknown, has already settled, or, for an `onlyIfPending` cancel,
|
|
406
|
+
* has already started. Nothing is written in that case.
|
|
407
|
+
*/
|
|
408
|
+
export declare function acceptSessionCancellation(owner: SqliteOwner, sessionId: string, commandId: string, readQueueHead: () => SessionQueueHead, record: RecordAcceptedCancellation, onlyIfPending?: boolean, meta?: Json): AcceptedSessionCancellation | undefined;
|
|
409
|
+
/** Move the durable leaf to an existing entry in the same Session. */
|
|
410
|
+
export declare function selectSessionBranch(owner: SqliteOwner, input: SelectSessionBranchInput): void;
|
|
411
|
+
/**
|
|
412
|
+
* Record one operator or party line on an idle Session. The request id is
|
|
413
|
+
* the idempotency key: a replay of the same line is `false`, another line
|
|
414
|
+
* under the same id is a conflict.
|
|
415
|
+
*/
|
|
416
|
+
export declare function appendOperatorEntry(owner: SqliteOwner, input: Readonly<{
|
|
417
|
+
sessionId: string;
|
|
418
|
+
requestId: string;
|
|
419
|
+
author: "operator" | "party";
|
|
420
|
+
meta: Json | undefined;
|
|
421
|
+
text: string;
|
|
422
|
+
assertIdleSession: (queue: string) => void;
|
|
423
|
+
}>): boolean;
|
|
424
|
+
/** Read the complete retained Session tree, including orphan roots. */
|
|
425
|
+
export declare function readSessionTree(owner: SqliteOwner, input: SessionTreeInput): readonly SessionTreeNode[];
|
|
426
|
+
/** Fork exactly one Session root-to-entry lineage with fresh row identities. */
|
|
427
|
+
export declare function forkSessionAt(owner: SqliteOwner, input: ForkSessionAtInput): string;
|
|
428
|
+
/** Read document state from the selected transcript branch. */
|
|
429
|
+
export declare function readSessionDocument(owner: SqliteOwner, sessionId: string, extensionId: string, name: string): string | undefined;
|
|
430
|
+
/** Append a document snapshot under the same transaction as its producing hook. */
|
|
431
|
+
export declare function writeSessionDocument(owner: SqliteOwner, sessionId: string, extensionId: string, name: string, valueJson: string): void;
|
|
432
|
+
export {};
|