@orkestrel/train 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +38 -2
- package/dist/src/browser/index.d.ts +378 -0
- package/dist/src/browser/index.js +473 -0
- package/dist/src/browser/index.js.map +1 -0
- package/dist/src/core/index.cjs +8425 -0
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/index.d.cts +5480 -0
- package/dist/src/core/index.d.ts +5480 -0
- package/dist/src/core/index.js +8266 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/server/index.cjs +353 -0
- package/dist/src/server/index.cjs.map +1 -0
- package/dist/src/server/index.d.cts +223 -0
- package/dist/src/server/index.d.ts +223 -0
- package/dist/src/server/index.js +345 -0
- package/dist/src/server/index.js.map +1 -0
- package/package.json +124 -5
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { InferError, MemorySource, buildSourceError, checkSignal, digestBytes, isInferError, quoteFaultText } from "@orkestrel/infer";
|
|
2
|
+
import { CHECKPOINT_FILE_EXTENSION, checkCheckpointId, computeHeadName, isCheckpointId, mergeGGUF, mergeSafetensors, readCheckpointGGUF, readTrainerRows } from "../core/index.js";
|
|
3
|
+
import { isRecord, isString, isUint8Array } from "@orkestrel/contract";
|
|
4
|
+
import { createIndexedDBDatabase, supportsIndexedDB } from "@orkestrel/indexeddb";
|
|
5
|
+
// src/browser/constants.ts
|
|
6
|
+
/**
|
|
7
|
+
* Holds the media type of a head file a page receives.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* GGUF has no registered media type, so a head file is opaque bytes to the page.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* HEAD_FILE_TYPE // 'application/octet-stream'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
var HEAD_FILE_TYPE = "application/octet-stream";
|
|
18
|
+
/**
|
|
19
|
+
* Holds the media type of a checkpoint file a page receives.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* GGUF has no registered media type, so a checkpoint file is opaque bytes to the page.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* CHECKPOINT_FILE_TYPE // 'application/octet-stream'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
var CHECKPOINT_FILE_TYPE = "application/octet-stream";
|
|
30
|
+
/**
|
|
31
|
+
* Holds the default IndexedDB database name used by `IndexedDBCheckpointStore`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* CHECKPOINT_DATABASE_NAME // 'orkestrel-train-checkpoints'
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
var CHECKPOINT_DATABASE_NAME = "orkestrel-train-checkpoints";
|
|
39
|
+
/**
|
|
40
|
+
* Holds the IndexedDB object store name holding checkpoint records.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* CHECKPOINT_STORE_NAME // 'checkpoints'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
var CHECKPOINT_STORE_NAME = "checkpoints";
|
|
48
|
+
/**
|
|
49
|
+
* Holds the `@orkestrel/indexeddb` store schema for browser checkpoint persistence.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* CHECKPOINT_STORES.checkpoints.path // 'id'
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
var CHECKPOINT_STORES = Object.freeze({ checkpoints: Object.freeze({ path: "id" }) });
|
|
57
|
+
/**
|
|
58
|
+
* Holds the media type of a merged safetensors file a page receives.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* Safetensors has no registered media type, so the file is opaque bytes to the page.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* SAFETENSORS_FILE_TYPE // 'application/octet-stream'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
var SAFETENSORS_FILE_TYPE = "application/octet-stream";
|
|
69
|
+
/**
|
|
70
|
+
* Holds the default file name assigned by `buildMergedSafetensorsFile` when no name is supplied.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* SAFETENSORS_FILE_NAME // 'model.safetensors'
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
var SAFETENSORS_FILE_NAME = "model.safetensors";
|
|
78
|
+
// src/browser/helpers.ts
|
|
79
|
+
/**
|
|
80
|
+
* Reads a byte stream to the end as UTF-8 text.
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* Decodes through a `Response`, which strips a byte order mark. With a signal, the stream is piped
|
|
84
|
+
* through a pass-through transform under it, so an abort cancels the read mid-stream and rejects
|
|
85
|
+
* with the `ABORT` code; a stream that fails otherwise rejects with its own error.
|
|
86
|
+
*
|
|
87
|
+
* @param stream - The bytes
|
|
88
|
+
* @param signal - Cancels the read
|
|
89
|
+
* @returns The text
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* await readStreamText(new Blob(['{"state":"user: hi","label":"chatter"}\n']).stream())
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
async function readStreamText(stream, signal) {
|
|
97
|
+
checkSignal(signal, "The row read");
|
|
98
|
+
const piped = signal === void 0 ? stream : stream.pipeThrough(new TransformStream(), { signal });
|
|
99
|
+
try {
|
|
100
|
+
return await new Response(piped).text();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
checkSignal(signal, "The row read");
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Reads training rows from NDJSON bytes a page holds: a `Blob`, such as a `File` from an input, or a
|
|
108
|
+
* byte stream, such as a fetch body.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Decodes the bytes with `readStreamText` and reads the text with `readTrainerRows`, rejecting as each
|
|
112
|
+
* states.
|
|
113
|
+
*
|
|
114
|
+
* @param source - The NDJSON bytes
|
|
115
|
+
* @param signal - Cancels the read; it then rejects with the `ABORT` code
|
|
116
|
+
* @returns The rows, in line order
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const rows = await readRowStream(input.files[0])
|
|
121
|
+
* const result = await trainer.execute(rows)
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
async function readRowStream(source, signal) {
|
|
125
|
+
const stream = "getReader" in source ? source : source.stream();
|
|
126
|
+
return readTrainerRows([await readStreamText(stream, signal)], signal);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Builds the `File` a page hands back for a head file, named by its content.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* The name is `computeHeadName` of the bytes, the digest `@orkestrel/infer`'s head reports, and the type is
|
|
133
|
+
* `HEAD_FILE_TYPE`. A page can store it or offer it for download through an object URL.
|
|
134
|
+
*
|
|
135
|
+
* @param bytes - The head file's bytes
|
|
136
|
+
* @returns The file
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const file = await buildHeadFile(result.bytes)
|
|
141
|
+
* file.name // '3f2a…9c.gguf'
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
async function buildHeadFile(bytes) {
|
|
145
|
+
return new File([bytes], await computeHeadName(bytes), { type: HEAD_FILE_TYPE });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Reads a byte stream to the end as raw bytes.
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* With a signal, pipes the stream through a pass-through transform under it so an abort cancels the
|
|
152
|
+
* read mid-stream and rejects with the `ABORT` code.
|
|
153
|
+
*
|
|
154
|
+
* @param stream - The byte stream
|
|
155
|
+
* @param signal - Cancels the read
|
|
156
|
+
* @returns The collected bytes
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* await readStreamBytes(new Blob([Uint8Array.of(1, 2)]).stream()) // Uint8Array [1, 2]
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async function readStreamBytes(stream, signal) {
|
|
164
|
+
checkSignal(signal, "The checkpoint read");
|
|
165
|
+
const piped = signal === void 0 ? stream : stream.pipeThrough(new TransformStream(), { signal });
|
|
166
|
+
try {
|
|
167
|
+
return new Uint8Array(await new Response(piped).arrayBuffer());
|
|
168
|
+
} catch (error) {
|
|
169
|
+
checkSignal(signal, "The checkpoint read");
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Reads and validates a GGUF v3 training checkpoint from a browser `Blob`, `File`, or
|
|
175
|
+
* `ReadableStream`.
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* Reads the stream bytes through `readStreamBytes` and parses them through `readCheckpointGGUF`,
|
|
179
|
+
* enforcing format, tensor triple, finite value, and optional binding checks.
|
|
180
|
+
*
|
|
181
|
+
* @param source - The checkpoint `Blob`, `File`, or byte stream
|
|
182
|
+
* @param options - Optional expected bindings and abort signal
|
|
183
|
+
* @returns The decoded and validated checkpoint
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* const checkpoint = await readCheckpointStream(file, { base: backbone.digest })
|
|
188
|
+
* checkpoint.mode // 'adapter'
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
async function readCheckpointStream(source, options = {}) {
|
|
192
|
+
checkSignal(options.signal, "The checkpoint read");
|
|
193
|
+
const bytes = await readStreamBytes("getReader" in source ? source : source.stream(), options.signal);
|
|
194
|
+
return readCheckpointGGUF(new MemorySource(bytes), options);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Builds the `File` a page hands back for a checkpoint GGUF file, named by an explicit identifier
|
|
198
|
+
* or its SHA-256 content digest.
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* When `id` is supplied, validates it against `CHECKPOINT_ID_PATTERN` and names the file
|
|
202
|
+
* `<id>.gguf`; otherwise computes `<sha256>.gguf`. Uses `CHECKPOINT_FILE_TYPE`.
|
|
203
|
+
*
|
|
204
|
+
* @param bytes - The serialized GGUF v3 checkpoint bytes
|
|
205
|
+
* @param id - Optional validated checkpoint identifier for the filename stem
|
|
206
|
+
* @returns The browser `File`
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* const file = await buildCheckpointFile(bytes, 'step-10')
|
|
211
|
+
* file.name // 'step-10.gguf'
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
async function buildCheckpointFile(bytes, id) {
|
|
215
|
+
if (id !== void 0) checkCheckpointId(id);
|
|
216
|
+
const stem = id ?? await digestBytes(bytes);
|
|
217
|
+
return new File([bytes], `${stem}${CHECKPOINT_FILE_EXTENSION}`, { type: CHECKPOINT_FILE_TYPE });
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Wraps an async iterable of byte chunks as a pull-driven browser `ReadableStream`.
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* Pulls one chunk at a time from the underlying async iterator so streaming merges remain bounded
|
|
224
|
+
* in memory, and calls `iterator.return()` when the stream is cancelled.
|
|
225
|
+
*
|
|
226
|
+
* @param chunks - The async iterable of byte chunks
|
|
227
|
+
* @returns A pull-driven `ReadableStream`
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const stream = buildByteStream(mergeGGUF({ source, adapter }))
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
function buildByteStream(chunks) {
|
|
235
|
+
const iterator = chunks[Symbol.asyncIterator]();
|
|
236
|
+
return new ReadableStream({
|
|
237
|
+
async pull(controller) {
|
|
238
|
+
const step = await iterator.next();
|
|
239
|
+
if (step.done === true) {
|
|
240
|
+
controller.close();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
controller.enqueue(step.value);
|
|
244
|
+
},
|
|
245
|
+
async cancel() {
|
|
246
|
+
await iterator.return?.();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Streams an adapter- or section-merged safetensors file in the browser as a pull-driven
|
|
252
|
+
* `ReadableStream`.
|
|
253
|
+
*
|
|
254
|
+
* @remarks
|
|
255
|
+
* Delegates to `mergeSafetensors` and `buildByteStream`, pulling bounded slices without holding the
|
|
256
|
+
* full base checkpoint in memory.
|
|
257
|
+
*
|
|
258
|
+
* @param options - The streaming safetensors merge options
|
|
259
|
+
* @returns A `ReadableStream` yielding merged safetensors bytes
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* const stream = streamMergedSafetensors({ source, adapter, architecture })
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
function streamMergedSafetensors(options) {
|
|
267
|
+
return buildByteStream(mergeSafetensors(options));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Streams an adapter- or section-merged GGUF v3 file in the browser as a pull-driven
|
|
271
|
+
* `ReadableStream`.
|
|
272
|
+
*
|
|
273
|
+
* @remarks
|
|
274
|
+
* Delegates to `mergeGGUF` and `buildByteStream`, pulling bounded slices without holding the full
|
|
275
|
+
* base checkpoint in memory, supporting `F32`, `BF16`, `Q8_0`, and `Q4_K` targeted tensor formats.
|
|
276
|
+
*
|
|
277
|
+
* @param options - The streaming GGUF merge options
|
|
278
|
+
* @returns A `ReadableStream` yielding merged GGUF v3 bytes
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* const stream = streamMergedGGUF({ source, adapter, format: 'F32' })
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
function streamMergedGGUF(options) {
|
|
286
|
+
return buildByteStream(mergeGGUF(options));
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Builds a browser `File` containing adapter- or section-merged safetensors bytes assembled from
|
|
290
|
+
* `mergeSafetensors`.
|
|
291
|
+
*
|
|
292
|
+
* @remarks
|
|
293
|
+
* Collects streamed chunks into a `File` with media type `SAFETENSORS_FILE_TYPE` and filename
|
|
294
|
+
* `name` (defaulting to `SAFETENSORS_FILE_NAME`).
|
|
295
|
+
*
|
|
296
|
+
* @param options - The streaming safetensors merge options
|
|
297
|
+
* @param name - Optional filename for the returned `File`. Default: `SAFETENSORS_FILE_NAME`
|
|
298
|
+
* @returns The assembled browser `File`
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* const file = await buildMergedSafetensorsFile({ source, adapter, architecture })
|
|
303
|
+
* file.name // 'model.safetensors'
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
async function buildMergedSafetensorsFile(options, name = SAFETENSORS_FILE_NAME) {
|
|
307
|
+
const chunks = [];
|
|
308
|
+
for await (const chunk of mergeSafetensors(options)) chunks.push(chunk);
|
|
309
|
+
return new File(chunks, name, { type: SAFETENSORS_FILE_TYPE });
|
|
310
|
+
}
|
|
311
|
+
// src/browser/stores/IndexedDBCheckpointStore.ts
|
|
312
|
+
/**
|
|
313
|
+
* Persists training checkpoints in browser IndexedDB through `@orkestrel/indexeddb`.
|
|
314
|
+
*
|
|
315
|
+
* @remarks
|
|
316
|
+
* Refuses construction with the `HOST` code when the page provides no `indexedDB` capability.
|
|
317
|
+
* Validates every checkpoint identifier against `CHECKPOINT_ID_PATTERN` before issuing database
|
|
318
|
+
* requests, and surfaces IndexedDB faults as `InferError` (`SOURCE` code) or `ABORT` when
|
|
319
|
+
* cancelled.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* import { createIndexedDBCheckpointStore } from '@orkestrel/train/browser'
|
|
324
|
+
*
|
|
325
|
+
* const store = createIndexedDBCheckpointStore({ name: 'checkpoints' })
|
|
326
|
+
* await store.save({ id: 'step-10', bytes })
|
|
327
|
+
* await store.has('step-10') // true
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
var IndexedDBCheckpointStore = class {
|
|
331
|
+
#database;
|
|
332
|
+
/**
|
|
333
|
+
* Creates an IndexedDB-backed checkpoint store over the named database.
|
|
334
|
+
*
|
|
335
|
+
* @param options - Optional IndexedDB database name
|
|
336
|
+
*/
|
|
337
|
+
constructor(options = {}) {
|
|
338
|
+
if (!isRecord(options)) throw new InferError("The IndexedDB checkpoint store options must be a plain object.", { code: "ARGUMENT" });
|
|
339
|
+
const { name = CHECKPOINT_DATABASE_NAME } = options;
|
|
340
|
+
if (!isString(name) || name.trim().length === 0) throw new InferError("An IndexedDB checkpoint store requires a non-empty database name.", { code: "ARGUMENT" });
|
|
341
|
+
if (!supportsIndexedDB()) throw new InferError("The page offers no IndexedDB, which a checkpoint store persists in.", {
|
|
342
|
+
code: "HOST",
|
|
343
|
+
context: { capability: "indexedDB" }
|
|
344
|
+
});
|
|
345
|
+
this.#database = createIndexedDBDatabase({
|
|
346
|
+
name,
|
|
347
|
+
stores: CHECKPOINT_STORES
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Writes a checkpoint entry into IndexedDB under its validated identifier.
|
|
352
|
+
*
|
|
353
|
+
* @param entry - The identifier and serialized GGUF v3 checkpoint bytes
|
|
354
|
+
* @param signal - Cancels the write before committing to IndexedDB
|
|
355
|
+
*/
|
|
356
|
+
async save(entry, signal) {
|
|
357
|
+
checkSignal(signal, "The checkpoint save");
|
|
358
|
+
if (!isRecord(entry) || !isUint8Array(entry["bytes"])) throw new InferError("A checkpoint entry requires a valid id and Uint8Array bytes.", { code: "ARGUMENT" });
|
|
359
|
+
checkCheckpointId(entry.id);
|
|
360
|
+
await this.#database.store(CHECKPOINT_STORE_NAME).set({
|
|
361
|
+
id: entry.id,
|
|
362
|
+
bytes: new Uint8Array(entry.bytes)
|
|
363
|
+
}).catch((cause) => {
|
|
364
|
+
throw this.#fail(cause, "save", signal);
|
|
365
|
+
});
|
|
366
|
+
checkSignal(signal, "The checkpoint save");
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Loads a stored checkpoint entry by identifier, or `undefined` when absent.
|
|
370
|
+
*
|
|
371
|
+
* @param id - The validated checkpoint identifier
|
|
372
|
+
* @param signal - Cancels the read
|
|
373
|
+
* @returns The stored entry, or `undefined` when missing
|
|
374
|
+
*/
|
|
375
|
+
async load(id, signal) {
|
|
376
|
+
checkSignal(signal, "The checkpoint load");
|
|
377
|
+
checkCheckpointId(id);
|
|
378
|
+
const record = await this.#database.store(CHECKPOINT_STORE_NAME).get(id).catch((cause) => {
|
|
379
|
+
throw this.#fail(cause, "load", signal);
|
|
380
|
+
});
|
|
381
|
+
checkSignal(signal, "The checkpoint load");
|
|
382
|
+
if (record === void 0) return void 0;
|
|
383
|
+
const bytes = record["bytes"];
|
|
384
|
+
if (!isUint8Array(bytes)) throw new InferError(`The stored checkpoint ${quoteFaultText(id)} holds malformed bytes.`, {
|
|
385
|
+
code: "FORMAT",
|
|
386
|
+
context: { id }
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
id,
|
|
390
|
+
bytes: new Uint8Array(bytes)
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Checks whether a checkpoint identifier is present in the store.
|
|
395
|
+
*
|
|
396
|
+
* @param id - The validated checkpoint identifier
|
|
397
|
+
* @param signal - Cancels the presence check
|
|
398
|
+
* @returns True if the checkpoint exists; false otherwise
|
|
399
|
+
*/
|
|
400
|
+
async has(id, signal) {
|
|
401
|
+
checkSignal(signal, "The checkpoint check");
|
|
402
|
+
checkCheckpointId(id);
|
|
403
|
+
const present = await this.#database.store(CHECKPOINT_STORE_NAME).has(id).catch((cause) => {
|
|
404
|
+
throw this.#fail(cause, "check", signal);
|
|
405
|
+
});
|
|
406
|
+
checkSignal(signal, "The checkpoint check");
|
|
407
|
+
return present;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Lists the stored checkpoint identifiers in ascending order.
|
|
411
|
+
*
|
|
412
|
+
* @param signal - Cancels the key listing
|
|
413
|
+
* @returns The sorted checkpoint identifiers
|
|
414
|
+
*/
|
|
415
|
+
async list(signal) {
|
|
416
|
+
checkSignal(signal, "The checkpoint list");
|
|
417
|
+
const keys = await this.#database.store(CHECKPOINT_STORE_NAME).keys().catch((cause) => {
|
|
418
|
+
throw this.#fail(cause, "list", signal);
|
|
419
|
+
});
|
|
420
|
+
checkSignal(signal, "The checkpoint list");
|
|
421
|
+
return keys.filter(isCheckpointId).toSorted();
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Deletes a stored checkpoint by identifier; a missing identifier is a no-op.
|
|
425
|
+
*
|
|
426
|
+
* @param id - The validated checkpoint identifier
|
|
427
|
+
* @param signal - Cancels the removal
|
|
428
|
+
*/
|
|
429
|
+
async remove(id, signal) {
|
|
430
|
+
checkSignal(signal, "The checkpoint removal");
|
|
431
|
+
checkCheckpointId(id);
|
|
432
|
+
await this.#database.store(CHECKPOINT_STORE_NAME).remove(id).catch((cause) => {
|
|
433
|
+
throw this.#fail(cause, "remove", signal);
|
|
434
|
+
});
|
|
435
|
+
checkSignal(signal, "The checkpoint removal");
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Deletes every stored checkpoint from IndexedDB.
|
|
439
|
+
*
|
|
440
|
+
* @param signal - Cancels the clear operation
|
|
441
|
+
*/
|
|
442
|
+
async clear(signal) {
|
|
443
|
+
checkSignal(signal, "The checkpoint clear");
|
|
444
|
+
await this.#database.store(CHECKPOINT_STORE_NAME).clear().catch((cause) => {
|
|
445
|
+
throw this.#fail(cause, "clear", signal);
|
|
446
|
+
});
|
|
447
|
+
checkSignal(signal, "The checkpoint clear");
|
|
448
|
+
}
|
|
449
|
+
#fail(cause, step, signal) {
|
|
450
|
+
checkSignal(signal, `The checkpoint ${step}`);
|
|
451
|
+
if (isInferError(cause)) return cause;
|
|
452
|
+
return buildSourceError(cause, `The IndexedDB checkpoint store failed to ${step}: ${cause instanceof Error ? cause.message : String(cause)}`, signal);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
// src/browser/factories.ts
|
|
456
|
+
/**
|
|
457
|
+
* Creates an IndexedDB-backed checkpoint store for browser persistence.
|
|
458
|
+
*
|
|
459
|
+
* @param options - Optional IndexedDB database name
|
|
460
|
+
* @returns A {@link CheckpointStoreInterface} backed by `@orkestrel/indexeddb`
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* const store = createIndexedDBCheckpointStore({ name: 'checkpoints' })
|
|
465
|
+
* await store.list() // []
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
function createIndexedDBCheckpointStore(options) {
|
|
469
|
+
return new IndexedDBCheckpointStore(options);
|
|
470
|
+
}
|
|
471
|
+
export { CHECKPOINT_DATABASE_NAME, CHECKPOINT_FILE_TYPE, CHECKPOINT_STORES, CHECKPOINT_STORE_NAME, HEAD_FILE_TYPE, IndexedDBCheckpointStore, SAFETENSORS_FILE_NAME, SAFETENSORS_FILE_TYPE, buildByteStream, buildCheckpointFile, buildHeadFile, buildMergedSafetensorsFile, createIndexedDBCheckpointStore, readCheckpointStream, readRowStream, readStreamBytes, readStreamText, streamMergedGGUF, streamMergedSafetensors };
|
|
472
|
+
|
|
473
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/browser/constants.ts","../../../src/browser/helpers.ts","../../../src/browser/stores/IndexedDBCheckpointStore.ts","../../../src/browser/factories.ts"],"sourcesContent":["/**\n * Holds the media type of a head file a page receives.\n *\n * @remarks\n * GGUF has no registered media type, so a head file is opaque bytes to the page.\n *\n * @example\n * ```ts\n * HEAD_FILE_TYPE // 'application/octet-stream'\n * ```\n */\nexport const HEAD_FILE_TYPE = 'application/octet-stream'\n\n/**\n * Holds the media type of a checkpoint file a page receives.\n *\n * @remarks\n * GGUF has no registered media type, so a checkpoint file is opaque bytes to the page.\n *\n * @example\n * ```ts\n * CHECKPOINT_FILE_TYPE // 'application/octet-stream'\n * ```\n */\nexport const CHECKPOINT_FILE_TYPE = 'application/octet-stream'\n\n/**\n * Holds the default IndexedDB database name used by `IndexedDBCheckpointStore`.\n *\n * @example\n * ```ts\n * CHECKPOINT_DATABASE_NAME // 'orkestrel-train-checkpoints'\n * ```\n */\nexport const CHECKPOINT_DATABASE_NAME = 'orkestrel-train-checkpoints'\n\n/**\n * Holds the IndexedDB object store name holding checkpoint records.\n *\n * @example\n * ```ts\n * CHECKPOINT_STORE_NAME // 'checkpoints'\n * ```\n */\nexport const CHECKPOINT_STORE_NAME = 'checkpoints'\n\n/**\n * Holds the `@orkestrel/indexeddb` store schema for browser checkpoint persistence.\n *\n * @example\n * ```ts\n * CHECKPOINT_STORES.checkpoints.path // 'id'\n * ```\n */\nexport const CHECKPOINT_STORES = Object.freeze({\n\tcheckpoints: Object.freeze({ path: 'id' }),\n})\n\n/**\n * Holds the media type of a merged safetensors file a page receives.\n *\n * @remarks\n * Safetensors has no registered media type, so the file is opaque bytes to the page.\n *\n * @example\n * ```ts\n * SAFETENSORS_FILE_TYPE // 'application/octet-stream'\n * ```\n */\nexport const SAFETENSORS_FILE_TYPE = 'application/octet-stream'\n\n/**\n * Holds the default file name assigned by `buildMergedSafetensorsFile` when no name is supplied.\n *\n * @example\n * ```ts\n * SAFETENSORS_FILE_NAME // 'model.safetensors'\n * ```\n */\nexport const SAFETENSORS_FILE_NAME = 'model.safetensors'\n","import type {\n\tCheckpoint,\n\tCheckpointReadOptions,\n\tMergeGGUFOptions,\n\tMergeSafetensorsOptions,\n\tTrainerRow,\n} from '@src/core'\nimport { checkSignal, digestBytes, MemorySource } from '@orkestrel/infer'\nimport {\n\tcheckCheckpointId,\n\tCHECKPOINT_FILE_EXTENSION,\n\tcomputeHeadName,\n\tmergeGGUF,\n\tmergeSafetensors,\n\treadCheckpointGGUF,\n\treadTrainerRows,\n} from '@src/core'\nimport {\n\tCHECKPOINT_FILE_TYPE,\n\tHEAD_FILE_TYPE,\n\tSAFETENSORS_FILE_NAME,\n\tSAFETENSORS_FILE_TYPE,\n} from './constants.js'\n\n/**\n * Reads a byte stream to the end as UTF-8 text.\n *\n * @remarks\n * Decodes through a `Response`, which strips a byte order mark. With a signal, the stream is piped\n * through a pass-through transform under it, so an abort cancels the read mid-stream and rejects\n * with the `ABORT` code; a stream that fails otherwise rejects with its own error.\n *\n * @param stream - The bytes\n * @param signal - Cancels the read\n * @returns The text\n *\n * @example\n * ```ts\n * await readStreamText(new Blob(['{\"state\":\"user: hi\",\"label\":\"chatter\"}\\n']).stream())\n * ```\n */\nexport async function readStreamText(\n\tstream: ReadableStream<Uint8Array>,\n\tsignal?: AbortSignal,\n): Promise<string> {\n\tcheckSignal(signal, 'The row read')\n\tconst piped =\n\t\tsignal === undefined\n\t\t\t? stream\n\t\t\t: stream.pipeThrough(new TransformStream<Uint8Array, Uint8Array>(), { signal })\n\ttry {\n\t\treturn await new Response(piped).text()\n\t} catch (error) {\n\t\tcheckSignal(signal, 'The row read')\n\t\tthrow error\n\t}\n}\n\n/**\n * Reads training rows from NDJSON bytes a page holds: a `Blob`, such as a `File` from an input, or a\n * byte stream, such as a fetch body.\n *\n * @remarks\n * Decodes the bytes with `readStreamText` and reads the text with `readTrainerRows`, rejecting as each\n * states.\n *\n * @param source - The NDJSON bytes\n * @param signal - Cancels the read; it then rejects with the `ABORT` code\n * @returns The rows, in line order\n *\n * @example\n * ```ts\n * const rows = await readRowStream(input.files[0])\n * const result = await trainer.execute(rows)\n * ```\n */\nexport async function readRowStream(\n\tsource: Blob | ReadableStream<Uint8Array>,\n\tsignal?: AbortSignal,\n): Promise<readonly TrainerRow[]> {\n\tconst stream = 'getReader' in source ? source : source.stream()\n\treturn readTrainerRows([await readStreamText(stream, signal)], signal)\n}\n\n/**\n * Builds the `File` a page hands back for a head file, named by its content.\n *\n * @remarks\n * The name is `computeHeadName` of the bytes, the digest `@orkestrel/infer`'s head reports, and the type is\n * `HEAD_FILE_TYPE`. A page can store it or offer it for download through an object URL.\n *\n * @param bytes - The head file's bytes\n * @returns The file\n *\n * @example\n * ```ts\n * const file = await buildHeadFile(result.bytes)\n * file.name // '3f2a…9c.gguf'\n * ```\n */\nexport async function buildHeadFile(bytes: Uint8Array<ArrayBuffer>): Promise<File> {\n\treturn new File([bytes], await computeHeadName(bytes), { type: HEAD_FILE_TYPE })\n}\n\n/**\n * Reads a byte stream to the end as raw bytes.\n *\n * @remarks\n * With a signal, pipes the stream through a pass-through transform under it so an abort cancels the\n * read mid-stream and rejects with the `ABORT` code.\n *\n * @param stream - The byte stream\n * @param signal - Cancels the read\n * @returns The collected bytes\n *\n * @example\n * ```ts\n * await readStreamBytes(new Blob([Uint8Array.of(1, 2)]).stream()) // Uint8Array [1, 2]\n * ```\n */\nexport async function readStreamBytes(\n\tstream: ReadableStream<Uint8Array>,\n\tsignal?: AbortSignal,\n): Promise<Uint8Array<ArrayBuffer>> {\n\tcheckSignal(signal, 'The checkpoint read')\n\tconst piped =\n\t\tsignal === undefined\n\t\t\t? stream\n\t\t\t: stream.pipeThrough(new TransformStream<Uint8Array, Uint8Array>(), { signal })\n\ttry {\n\t\treturn new Uint8Array(await new Response(piped).arrayBuffer())\n\t} catch (error) {\n\t\tcheckSignal(signal, 'The checkpoint read')\n\t\tthrow error\n\t}\n}\n\n/**\n * Reads and validates a GGUF v3 training checkpoint from a browser `Blob`, `File`, or\n * `ReadableStream`.\n *\n * @remarks\n * Reads the stream bytes through `readStreamBytes` and parses them through `readCheckpointGGUF`,\n * enforcing format, tensor triple, finite value, and optional binding checks.\n *\n * @param source - The checkpoint `Blob`, `File`, or byte stream\n * @param options - Optional expected bindings and abort signal\n * @returns The decoded and validated checkpoint\n *\n * @example\n * ```ts\n * const checkpoint = await readCheckpointStream(file, { base: backbone.digest })\n * checkpoint.mode // 'adapter'\n * ```\n */\nexport async function readCheckpointStream(\n\tsource: Blob | ReadableStream<Uint8Array>,\n\toptions: CheckpointReadOptions = {},\n): Promise<Checkpoint> {\n\tcheckSignal(options.signal, 'The checkpoint read')\n\tconst stream = 'getReader' in source ? source : source.stream()\n\tconst bytes = await readStreamBytes(stream, options.signal)\n\treturn readCheckpointGGUF(new MemorySource(bytes), options)\n}\n\n/**\n * Builds the `File` a page hands back for a checkpoint GGUF file, named by an explicit identifier\n * or its SHA-256 content digest.\n *\n * @remarks\n * When `id` is supplied, validates it against `CHECKPOINT_ID_PATTERN` and names the file\n * `<id>.gguf`; otherwise computes `<sha256>.gguf`. Uses `CHECKPOINT_FILE_TYPE`.\n *\n * @param bytes - The serialized GGUF v3 checkpoint bytes\n * @param id - Optional validated checkpoint identifier for the filename stem\n * @returns The browser `File`\n *\n * @example\n * ```ts\n * const file = await buildCheckpointFile(bytes, 'step-10')\n * file.name // 'step-10.gguf'\n * ```\n */\nexport async function buildCheckpointFile(\n\tbytes: Uint8Array<ArrayBuffer>,\n\tid?: string,\n): Promise<File> {\n\tif (id !== undefined) checkCheckpointId(id)\n\tconst stem = id ?? (await digestBytes(bytes))\n\treturn new File([bytes], `${stem}${CHECKPOINT_FILE_EXTENSION}`, {\n\t\ttype: CHECKPOINT_FILE_TYPE,\n\t})\n}\n\n/**\n * Wraps an async iterable of byte chunks as a pull-driven browser `ReadableStream`.\n *\n * @remarks\n * Pulls one chunk at a time from the underlying async iterator so streaming merges remain bounded\n * in memory, and calls `iterator.return()` when the stream is cancelled.\n *\n * @param chunks - The async iterable of byte chunks\n * @returns A pull-driven `ReadableStream`\n *\n * @example\n * ```ts\n * const stream = buildByteStream(mergeGGUF({ source, adapter }))\n * ```\n */\nexport function buildByteStream(\n\tchunks: AsyncIterable<Uint8Array<ArrayBuffer>>,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\tconst iterator = chunks[Symbol.asyncIterator]()\n\treturn new ReadableStream<Uint8Array<ArrayBuffer>>({\n\t\tasync pull(controller) {\n\t\t\tconst step = await iterator.next()\n\t\t\tif (step.done === true) {\n\t\t\t\tcontroller.close()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcontroller.enqueue(step.value)\n\t\t},\n\t\tasync cancel() {\n\t\t\tawait iterator.return?.()\n\t\t},\n\t})\n}\n\n/**\n * Streams an adapter- or section-merged safetensors file in the browser as a pull-driven\n * `ReadableStream`.\n *\n * @remarks\n * Delegates to `mergeSafetensors` and `buildByteStream`, pulling bounded slices without holding the\n * full base checkpoint in memory.\n *\n * @param options - The streaming safetensors merge options\n * @returns A `ReadableStream` yielding merged safetensors bytes\n *\n * @example\n * ```ts\n * const stream = streamMergedSafetensors({ source, adapter, architecture })\n * ```\n */\nexport function streamMergedSafetensors(\n\toptions: MergeSafetensorsOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\treturn buildByteStream(mergeSafetensors(options))\n}\n\n/**\n * Streams an adapter- or section-merged GGUF v3 file in the browser as a pull-driven\n * `ReadableStream`.\n *\n * @remarks\n * Delegates to `mergeGGUF` and `buildByteStream`, pulling bounded slices without holding the full\n * base checkpoint in memory, supporting `F32`, `BF16`, `Q8_0`, and `Q4_K` targeted tensor formats.\n *\n * @param options - The streaming GGUF merge options\n * @returns A `ReadableStream` yielding merged GGUF v3 bytes\n *\n * @example\n * ```ts\n * const stream = streamMergedGGUF({ source, adapter, format: 'F32' })\n * ```\n */\nexport function streamMergedGGUF(\n\toptions: MergeGGUFOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\treturn buildByteStream(mergeGGUF(options))\n}\n\n/**\n * Builds a browser `File` containing adapter- or section-merged safetensors bytes assembled from\n * `mergeSafetensors`.\n *\n * @remarks\n * Collects streamed chunks into a `File` with media type `SAFETENSORS_FILE_TYPE` and filename\n * `name` (defaulting to `SAFETENSORS_FILE_NAME`).\n *\n * @param options - The streaming safetensors merge options\n * @param name - Optional filename for the returned `File`. Default: `SAFETENSORS_FILE_NAME`\n * @returns The assembled browser `File`\n *\n * @example\n * ```ts\n * const file = await buildMergedSafetensorsFile({ source, adapter, architecture })\n * file.name // 'model.safetensors'\n * ```\n */\nexport async function buildMergedSafetensorsFile(\n\toptions: MergeSafetensorsOptions,\n\tname: string = SAFETENSORS_FILE_NAME,\n): Promise<File> {\n\tconst chunks: Array<Uint8Array<ArrayBuffer>> = []\n\tfor await (const chunk of mergeSafetensors(options)) {\n\t\tchunks.push(chunk)\n\t}\n\treturn new File(chunks, name, { type: SAFETENSORS_FILE_TYPE })\n}\n","import type { IndexedDBDatabaseInterface } from '@orkestrel/indexeddb'\nimport type { CheckpointEntry, CheckpointStoreInterface } from '@src/core'\nimport type { IndexedDBCheckpointStoreOptions } from '../types.js'\nimport { isRecord, isString, isUint8Array } from '@orkestrel/contract'\nimport { createIndexedDBDatabase, supportsIndexedDB } from '@orkestrel/indexeddb'\nimport {\n\tbuildSourceError,\n\tcheckSignal,\n\tisInferError,\n\tInferError,\n\tquoteFaultText,\n} from '@orkestrel/infer'\nimport { checkCheckpointId, isCheckpointId } from '@src/core'\nimport { CHECKPOINT_DATABASE_NAME, CHECKPOINT_STORE_NAME, CHECKPOINT_STORES } from '../constants.js'\n\n/**\n * Persists training checkpoints in browser IndexedDB through `@orkestrel/indexeddb`.\n *\n * @remarks\n * Refuses construction with the `HOST` code when the page provides no `indexedDB` capability.\n * Validates every checkpoint identifier against `CHECKPOINT_ID_PATTERN` before issuing database\n * requests, and surfaces IndexedDB faults as `InferError` (`SOURCE` code) or `ABORT` when\n * cancelled.\n *\n * @example\n * ```ts\n * import { createIndexedDBCheckpointStore } from '@orkestrel/train/browser'\n *\n * const store = createIndexedDBCheckpointStore({ name: 'checkpoints' })\n * await store.save({ id: 'step-10', bytes })\n * await store.has('step-10') // true\n * ```\n */\nexport class IndexedDBCheckpointStore implements CheckpointStoreInterface {\n\treadonly #database: IndexedDBDatabaseInterface<typeof CHECKPOINT_STORES>\n\n\t/**\n\t * Creates an IndexedDB-backed checkpoint store over the named database.\n\t *\n\t * @param options - Optional IndexedDB database name\n\t */\n\tconstructor(options: IndexedDBCheckpointStoreOptions = {}) {\n\t\tif (!isRecord(options)) {\n\t\t\tthrow new InferError('The IndexedDB checkpoint store options must be a plain object.', {\n\t\t\t\tcode: 'ARGUMENT',\n\t\t\t})\n\t\t}\n\t\tconst { name = CHECKPOINT_DATABASE_NAME } = options\n\t\tif (!isString(name) || name.trim().length === 0) {\n\t\t\tthrow new InferError('An IndexedDB checkpoint store requires a non-empty database name.', {\n\t\t\t\tcode: 'ARGUMENT',\n\t\t\t})\n\t\t}\n\t\tif (!supportsIndexedDB()) {\n\t\t\tthrow new InferError('The page offers no IndexedDB, which a checkpoint store persists in.', {\n\t\t\t\tcode: 'HOST',\n\t\t\t\tcontext: { capability: 'indexedDB' },\n\t\t\t})\n\t\t}\n\t\tthis.#database = createIndexedDBDatabase({ name, stores: CHECKPOINT_STORES })\n\t}\n\n\t/**\n\t * Writes a checkpoint entry into IndexedDB under its validated identifier.\n\t *\n\t * @param entry - The identifier and serialized GGUF v3 checkpoint bytes\n\t * @param signal - Cancels the write before committing to IndexedDB\n\t */\n\tasync save(entry: CheckpointEntry, signal?: AbortSignal): Promise<void> {\n\t\tcheckSignal(signal, 'The checkpoint save')\n\t\tif (!isRecord(entry) || !isUint8Array(entry['bytes'])) {\n\t\t\tthrow new InferError('A checkpoint entry requires a valid id and Uint8Array bytes.', {\n\t\t\t\tcode: 'ARGUMENT',\n\t\t\t})\n\t\t}\n\t\tcheckCheckpointId(entry.id)\n\t\tawait this.#database\n\t\t\t.store(CHECKPOINT_STORE_NAME)\n\t\t\t.set({ id: entry.id, bytes: new Uint8Array(entry.bytes) })\n\t\t\t.catch((cause: unknown) => {\n\t\t\t\tthrow this.#fail(cause, 'save', signal)\n\t\t\t})\n\t\tcheckSignal(signal, 'The checkpoint save')\n\t}\n\n\t/**\n\t * Loads a stored checkpoint entry by identifier, or `undefined` when absent.\n\t *\n\t * @param id - The validated checkpoint identifier\n\t * @param signal - Cancels the read\n\t * @returns The stored entry, or `undefined` when missing\n\t */\n\tasync load(id: string, signal?: AbortSignal): Promise<CheckpointEntry | undefined> {\n\t\tcheckSignal(signal, 'The checkpoint load')\n\t\tcheckCheckpointId(id)\n\t\tconst record = await this.#database\n\t\t\t.store(CHECKPOINT_STORE_NAME)\n\t\t\t.get(id)\n\t\t\t.catch((cause: unknown) => {\n\t\t\t\tthrow this.#fail(cause, 'load', signal)\n\t\t\t})\n\t\tcheckSignal(signal, 'The checkpoint load')\n\t\tif (record === undefined) return undefined\n\t\tconst bytes = record['bytes']\n\t\tif (!isUint8Array(bytes)) {\n\t\t\tthrow new InferError(`The stored checkpoint ${quoteFaultText(id)} holds malformed bytes.`, {\n\t\t\t\tcode: 'FORMAT',\n\t\t\t\tcontext: { id },\n\t\t\t})\n\t\t}\n\t\treturn { id, bytes: new Uint8Array(bytes) }\n\t}\n\n\t/**\n\t * Checks whether a checkpoint identifier is present in the store.\n\t *\n\t * @param id - The validated checkpoint identifier\n\t * @param signal - Cancels the presence check\n\t * @returns True if the checkpoint exists; false otherwise\n\t */\n\tasync has(id: string, signal?: AbortSignal): Promise<boolean> {\n\t\tcheckSignal(signal, 'The checkpoint check')\n\t\tcheckCheckpointId(id)\n\t\tconst present = await this.#database\n\t\t\t.store(CHECKPOINT_STORE_NAME)\n\t\t\t.has(id)\n\t\t\t.catch((cause: unknown) => {\n\t\t\t\tthrow this.#fail(cause, 'check', signal)\n\t\t\t})\n\t\tcheckSignal(signal, 'The checkpoint check')\n\t\treturn present\n\t}\n\n\t/**\n\t * Lists the stored checkpoint identifiers in ascending order.\n\t *\n\t * @param signal - Cancels the key listing\n\t * @returns The sorted checkpoint identifiers\n\t */\n\tasync list(signal?: AbortSignal): Promise<readonly string[]> {\n\t\tcheckSignal(signal, 'The checkpoint list')\n\t\tconst keys = await this.#database\n\t\t\t.store(CHECKPOINT_STORE_NAME)\n\t\t\t.keys()\n\t\t\t.catch((cause: unknown) => {\n\t\t\t\tthrow this.#fail(cause, 'list', signal)\n\t\t\t})\n\t\tcheckSignal(signal, 'The checkpoint list')\n\t\treturn keys.filter(isCheckpointId).toSorted()\n\t}\n\n\t/**\n\t * Deletes a stored checkpoint by identifier; a missing identifier is a no-op.\n\t *\n\t * @param id - The validated checkpoint identifier\n\t * @param signal - Cancels the removal\n\t */\n\tasync remove(id: string, signal?: AbortSignal): Promise<void> {\n\t\tcheckSignal(signal, 'The checkpoint removal')\n\t\tcheckCheckpointId(id)\n\t\tawait this.#database\n\t\t\t.store(CHECKPOINT_STORE_NAME)\n\t\t\t.remove(id)\n\t\t\t.catch((cause: unknown) => {\n\t\t\t\tthrow this.#fail(cause, 'remove', signal)\n\t\t\t})\n\t\tcheckSignal(signal, 'The checkpoint removal')\n\t}\n\n\t/**\n\t * Deletes every stored checkpoint from IndexedDB.\n\t *\n\t * @param signal - Cancels the clear operation\n\t */\n\tasync clear(signal?: AbortSignal): Promise<void> {\n\t\tcheckSignal(signal, 'The checkpoint clear')\n\t\tawait this.#database\n\t\t\t.store(CHECKPOINT_STORE_NAME)\n\t\t\t.clear()\n\t\t\t.catch((cause: unknown) => {\n\t\t\t\tthrow this.#fail(cause, 'clear', signal)\n\t\t\t})\n\t\tcheckSignal(signal, 'The checkpoint clear')\n\t}\n\n\t// Translates an IndexedDB failure into a typed InferError, preserving abort priority.\n\t#fail(cause: unknown, step: string, signal: AbortSignal | undefined): InferError {\n\t\tcheckSignal(signal, `The checkpoint ${step}`)\n\t\tif (isInferError(cause)) return cause\n\t\treturn buildSourceError(\n\t\t\tcause,\n\t\t\t`The IndexedDB checkpoint store failed to ${step}: ${cause instanceof Error ? cause.message : String(cause)}`,\n\t\t\tsignal,\n\t\t)\n\t}\n}\n","import type { CheckpointStoreInterface } from '@src/core'\nimport type { IndexedDBCheckpointStoreOptions } from './types.js'\nimport { IndexedDBCheckpointStore } from './stores/IndexedDBCheckpointStore.js'\n\n/**\n * Creates an IndexedDB-backed checkpoint store for browser persistence.\n *\n * @param options - Optional IndexedDB database name\n * @returns A {@link CheckpointStoreInterface} backed by `@orkestrel/indexeddb`\n *\n * @example\n * ```ts\n * const store = createIndexedDBCheckpointStore({ name: 'checkpoints' })\n * await store.list() // []\n * ```\n */\nexport function createIndexedDBCheckpointStore(\n\toptions?: IndexedDBCheckpointStoreOptions,\n): CheckpointStoreInterface {\n\treturn new IndexedDBCheckpointStore(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,IAAa,iBAAiB;;;;;;;;;;;;AAa9B,IAAa,uBAAuB;;;;;;;;;AAUpC,IAAa,2BAA2B;;;;;;;;;AAUxC,IAAa,wBAAwB;;;;;;;;;AAUrC,IAAa,oBAAoB,OAAO,OAAO,EAC9C,aAAa,OAAO,OAAO,EAAE,MAAM,KAAK,CAAC,EAC1C,CAAC;;;;;;;;;;;;AAaD,IAAa,wBAAwB;;;;;;;;;AAUrC,IAAa,wBAAwB;;;;;;;;;;;;;;;;;;;ACtCrC,eAAsB,eACrB,QACA,QACkB;CAClB,YAAY,QAAQ,cAAc;CAClC,MAAM,QACL,WAAW,KAAA,IACR,SACA,OAAO,YAAY,IAAI,gBAAwC,GAAG,EAAE,OAAO,CAAC;CAChF,IAAI;EACH,OAAO,MAAM,IAAI,SAAS,KAAK,CAAC,CAAC,KAAK;CACvC,SAAS,OAAO;EACf,YAAY,QAAQ,cAAc;EAClC,MAAM;CACP;AACD;;;;;;;;;;;;;;;;;;;AAoBA,eAAsB,cACrB,QACA,QACiC;CACjC,MAAM,SAAS,eAAe,SAAS,SAAS,OAAO,OAAO;CAC9D,OAAO,gBAAgB,CAAC,MAAM,eAAe,QAAQ,MAAM,CAAC,GAAG,MAAM;AACtE;;;;;;;;;;;;;;;;;AAkBA,eAAsB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