Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 161 to 162

Compare

+68 −0 in 1 place
new file, 68 lines
1+import { CachedStateStorage } from "../../src/engine/state-source.ts";
2+import type { WriterAdoptionFrame } from "../../worker/project/project.ts";
3+import type { Entry } from "../../worker/project/project-types.ts";
4+import type { SqliteLog, SqliteStorage } from "./engine-project.ts";
5+import { StoredJson, storeJson } from "./stored-json.ts";
6+import { storedJsonView } from "./stored-json-view.ts";
7+import { SqliteWriterState, writerFrameChunksDigest } from "./writer-host.ts";
8+
9+/** Keep decoded views alive through the complete page checkpoint, then remove their rows. */
10+export function withDecodedFrames<T>(
11+ storage: SqliteStorage,
12+ namespace: string,
13+ log: SqliteLog,
14+ input: { from: number; to: number; maxEntries: number; maxBytes: number; digest: string },
15+ consume: (frames: Iterable<WriterAdoptionFrame>) => T,
16+): { result: T; digest: string } {
17+ if (
18+ ![input.from, input.to, input.maxEntries, input.maxBytes].every(Number.isSafeInteger) ||
19+ input.from < 0 ||
20+ input.to < input.from ||
21+ input.maxEntries < 1 ||
22+ input.maxEntries > 256 ||
23+ input.maxBytes < 1
24+ )
25+ throw Error("invalid decoded frame page bounds");
26+ return storage.transactionSync(() => {
27+ SqliteWriterState.initialize(storage);
28+ const state = new SqliteWriterState(storage, namespace);
29+ // Temporary nodes are immutable after parsing; cap retained reads for the whole page.
30+ const reads = new CachedStateStorage(state, 64 * 1024, 256);
31+ if (
32+ storage.sql.exec("SELECT 1 AS present FROM writer_state WHERE namespace = ? LIMIT 1", namespace).toArray().length
33+ )
34+ throw Error("decoded frame namespace is occupied");
35+ let digest = input.digest;
36+ let active = true;
37+ const frames = function* (): IterableIterator<WriterAdoptionFrame> {
38+ let bytes = 0;
39+ for (let seq = input.from; seq < input.to && seq < input.from + input.maxEntries; seq++) {
40+ if (!active) throw Error("decoded frame page has ended");
41+ const size = log.frameBytes(seq);
42+ if (size > input.maxBytes - bytes) {
43+ if (bytes) return;
44+ throw Error("decoded frame exceeds page byte bound");
45+ }
46+ digest = writerFrameChunksDigest(digest, seq, log.frameChunks(seq));
47+ storeJson(state, String(seq), log.frameChunks(seq));
48+ bytes += size;
49+ yield { seq, bytes: size, entry: storedJsonView(new StoredJson(reads, String(seq))) as Entry };
50+ }
51+ };
52+ try {
53+ const result = consume(frames());
54+ if (
55+ result &&
56+ typeof result === "object" &&
57+ (typeof (result as { then?: unknown }).then === "function" ||
58+ typeof (result as { next?: unknown }).next === "function")
59+ )
60+ throw Error("decoded frame consumption must finish synchronously");
61+ return { result: structuredClone(result), digest };
62+ } finally {
63+ active = false;
64+ reads.clear();
65+ storage.sql.exec("DELETE FROM writer_state WHERE namespace = ?", namespace);
66+ }
67+ });
68+}
MCP
compare on this site's /mcp
CLI
abso diff 161 162 server/src/decoded-frames.ts --json
JSON
/christopher/abso-core/compare/161..162?file=server%2Fsrc%2Fdecoded-frames.ts&format=json