@tangle-network/agent-runtime 10.0.19 → 10.0.20
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 +4 -0
- package/dist/{activation-DLnZJab0.js → activation-5TrUzeFd.js} +2 -2
- package/dist/{activation-DLnZJab0.js.map → activation-5TrUzeFd.js.map} +1 -1
- package/dist/{activation-BudDVuT6.d.ts → activation-B0arteLE.d.ts} +2 -2
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +4 -4
- package/dist/{delegate-9b8qGlXp.js → delegate-DnW85VY0.js} +2 -2
- package/dist/{delegate-9b8qGlXp.js.map → delegate-DnW85VY0.js.map} +1 -1
- package/dist/{driver-control-acknowledgers-b5MsXxR5.js → driver-control-acknowledgers-vgmZqgZ-.js} +8 -8
- package/dist/{driver-control-acknowledgers-b5MsXxR5.js.map → driver-control-acknowledgers-vgmZqgZ-.js.map} +1 -1
- package/dist/durable-writer-thread.js +4 -4
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +13 -14
- package/dist/durable.js.map +1 -1
- package/dist/{graph--n31XKWJ.js → graph-DHNPE7kw.js} +8 -8
- package/dist/{graph--n31XKWJ.js.map → graph-DHNPE7kw.js.map} +1 -1
- package/dist/{graph-registry-aMRd94PD.js → graph-registry-DI8o9iCB.js} +1 -1
- package/dist/{graph-registry-SgsCxCTZ.js → graph-registry-qyaNDATw.js} +2 -3
- package/dist/{graph-registry-SgsCxCTZ.js.map → graph-registry-qyaNDATw.js.map} +1 -1
- package/dist/{improve-sIZhpXqE.js → improve-BLFqeD3X.js} +6 -6
- package/dist/{improve-sIZhpXqE.js.map → improve-BLFqeD3X.js.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -10
- package/dist/intelligence.d.ts +2 -2
- package/dist/intelligence.js +4 -4
- package/dist/{continuation-CDdjAkpk.js → jsonl-file-B2ESMrTh.js} +396 -4
- package/dist/jsonl-file-B2ESMrTh.js.map +1 -0
- package/dist/kernel.d.ts +1 -1
- package/dist/kernel.js +17 -18
- package/dist/{loop-runner-Bn7lFuQZ.d.ts → loop-runner-BFC781pC.d.ts} +2 -2
- package/dist/{loop-runner-Dt7I2oMa.js → loop-runner-CITvo-q1.js} +2 -2
- package/dist/{loop-runner-Dt7I2oMa.js.map → loop-runner-CITvo-q1.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +6 -6
- package/dist/mcp/memory-bin.js +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{provision-supervisor-DfDAdtqb.js → provision-supervisor-CyUbiMz8.js} +6 -6
- package/dist/{provision-supervisor-DfDAdtqb.js.map → provision-supervisor-CyUbiMz8.js.map} +1 -1
- package/dist/{result-blob-store-Dke805sV.js → result-blob-store-CJjp44Mz.js} +3 -3
- package/dist/{result-blob-store-Dke805sV.js.map → result-blob-store-CJjp44Mz.js.map} +1 -1
- package/dist/{run-cancellation-B0SgcidY.js → run-cancellation-BNBmsY3a.js} +2 -2
- package/dist/{run-cancellation-B0SgcidY.js.map → run-cancellation-BNBmsY3a.js.map} +1 -1
- package/dist/{run-lock-BOg7BaXF.js → run-lock-Dcr79Wql.js} +2 -2
- package/dist/{run-lock-BOg7BaXF.js.map → run-lock-Dcr79Wql.js.map} +1 -1
- package/dist/{run-reopen-B7TN2aQQ.js → run-reopen-Cr2SHmYa.js} +6 -6
- package/dist/{run-reopen-B7TN2aQQ.js.map → run-reopen-Cr2SHmYa.js.map} +1 -1
- package/dist/{run-state-BNBUy2uK.js → run-state-AYXAe_lX.js} +7 -7
- package/dist/{run-state-BNBUy2uK.js.map → run-state-AYXAe_lX.js.map} +1 -1
- package/dist/{runtime-DXeWY00j.js → runtime-D-FpUoQg.js} +19 -20
- package/dist/{runtime-DXeWY00j.js.map → runtime-D-FpUoQg.js.map} +1 -1
- package/dist/{search-executor-BoQHI2Tz.js → search-executor-BHfb4p6C.js} +4 -4
- package/dist/{search-executor-BoQHI2Tz.js.map → search-executor-BHfb4p6C.js.map} +1 -1
- package/dist/{server-Xkgobp5y.js → server-CAXzZHVz.js} +4 -4
- package/dist/{server-Xkgobp5y.js.map → server-CAXzZHVz.js.map} +1 -1
- package/dist/{settle-record-B5OpVDnC.js → settle-record-BlIw2MU1.js} +3 -3
- package/dist/{settle-record-B5OpVDnC.js.map → settle-record-BlIw2MU1.js.map} +1 -1
- package/dist/{structural-rollout-BSF5tzUm.js → structural-rollout-BVuf5hFl.js} +4 -4
- package/dist/{structural-rollout-BSF5tzUm.js.map → structural-rollout-BVuf5hFl.js.map} +1 -1
- package/dist/{supervise-Drc1Pj1d.js → supervise-Ci8wiyla.js} +13 -13
- package/dist/supervise-Ci8wiyla.js.map +1 -0
- package/dist/{supervise-identity-Cz-Hzg9s.js → supervise-identity-CtxWEk1I.js} +3 -3
- package/dist/{supervise-identity-Cz-Hzg9s.js.map → supervise-identity-CtxWEk1I.js.map} +1 -1
- package/dist/{supervision-discovery-DdRd1lsz.js → supervision-discovery-DKxqbnHf.js} +4 -4
- package/dist/{supervision-discovery-DdRd1lsz.js.map → supervision-discovery-DKxqbnHf.js.map} +1 -1
- package/dist/{supervisor-CwUD7dsm.js → supervisor-KcnH2hC4.js} +10 -592
- package/dist/supervisor-KcnH2hC4.js.map +1 -0
- package/dist/{supervisor-accounting-CPDPG8mH.js → supervisor-accounting-DlDUl58C.js} +600 -8
- package/dist/supervisor-accounting-DlDUl58C.js.map +1 -0
- package/dist/{supervisor-root-contract-Uw2q3nvG.js → supervisor-root-contract-BCbu1A4n.js} +3 -3
- package/dist/{supervisor-root-contract-Uw2q3nvG.js.map → supervisor-root-contract-BCbu1A4n.js.map} +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +11 -11
- package/dist/{failure-cause-C96rzF-d.js → tool-server-n4XYpCok.js} +181 -2
- package/dist/tool-server-n4XYpCok.js.map +1 -0
- package/dist/{top-web-5ThvdyD0.js → top-web-B-sHmI3g.js} +8 -8
- package/dist/{top-web-5ThvdyD0.js.map → top-web-B-sHmI3g.js.map} +1 -1
- package/dist/tui/bin.js +3 -3
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/{types-BLhsL4qy.d.ts → types-YXZL7Wxi.d.ts} +5 -3
- package/package.json +1 -1
- package/dist/continuation-CDdjAkpk.js.map +0 -1
- package/dist/failure-cause-C96rzF-d.js.map +0 -1
- package/dist/jsonl-file-B8xfYz9M.js +0 -397
- package/dist/jsonl-file-B8xfYz9M.js.map +0 -1
- package/dist/supervise-Drc1Pj1d.js.map +0 -1
- package/dist/supervisor-CwUD7dsm.js.map +0 -1
- package/dist/supervisor-accounting-CPDPG8mH.js.map +0 -1
- package/dist/tool-server-BhsyVDj2.js +0 -174
- package/dist/tool-server-BhsyVDj2.js.map +0 -1
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
import { g as routesToDurableWriter, m as durableCallAsync, x as fenceRunWrite, y as runFencedAsync } from "./durable-file-pao7FijS.js";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { closeSync, fstatSync, fsync, fsyncSync, ftruncateSync, openSync, readSync, statSync, writeSync } from "node:fs";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
// src/runtime/supervise/abortable.ts
|
|
6
|
-
/** Provenance of an explicit cancellation, preserved through every abort link. */
|
|
7
|
-
var RunCancellationReason = class extends Error {
|
|
8
|
-
source;
|
|
9
|
-
operationId;
|
|
10
|
-
operator;
|
|
11
|
-
constructor(source, reason, operationId, operator) {
|
|
12
|
-
super(reason);
|
|
13
|
-
this.source = source;
|
|
14
|
-
this.operationId = operationId;
|
|
15
|
-
this.operator = operator;
|
|
16
|
-
this.name = "RunCancellationReason";
|
|
17
|
-
}
|
|
18
|
-
toString() {
|
|
19
|
-
return this.message;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
/** The signal's explicit reason, or the caller's fallback when none was supplied. */
|
|
23
|
-
function abortReason(signal, fallback) {
|
|
24
|
-
const reason = signal.reason;
|
|
25
|
-
if (reason instanceof RunCancellationReason) return reason;
|
|
26
|
-
if (typeof reason === "string" && reason.length > 0) return reason;
|
|
27
|
-
if (reason instanceof Error && reason.name !== "AbortError" && reason.message.length > 0) return reason.message;
|
|
28
|
-
return fallback;
|
|
29
|
-
}
|
|
30
|
-
/** An `AbortError` carrying the signal's own string reason, or `fallback` when it states none. */
|
|
31
|
-
function signalAbortError(signal, fallback) {
|
|
32
|
-
const reason = abortReason(signal, fallback);
|
|
33
|
-
const error = new Error(reason instanceof Error ? reason.message : typeof reason === "string" && reason.length > 0 ? reason : fallback);
|
|
34
|
-
error.name = "AbortError";
|
|
35
|
-
return error;
|
|
36
|
-
}
|
|
37
|
-
/** A parent abort stops the call at once. The timeout still bounds a parent that stays open. */
|
|
38
|
-
function deadlineSignal(parent, ms) {
|
|
39
|
-
const timeout = AbortSignal.timeout(ms);
|
|
40
|
-
return parent === void 0 ? timeout : AbortSignal.any([parent, timeout]);
|
|
41
|
-
}
|
|
42
|
-
/** Cascade source aborts and preserve their reason; release removes the source listeners. */
|
|
43
|
-
function linkAbort(...sources) {
|
|
44
|
-
const controller = new AbortController();
|
|
45
|
-
const listeners = [];
|
|
46
|
-
const release = () => {
|
|
47
|
-
for (const { source, onAbort } of listeners) source.removeEventListener("abort", onAbort);
|
|
48
|
-
listeners.length = 0;
|
|
49
|
-
};
|
|
50
|
-
const abort = (reason) => {
|
|
51
|
-
release();
|
|
52
|
-
controller.abort(reason);
|
|
53
|
-
};
|
|
54
|
-
const alreadyAborted = sources.find((source) => source.aborted);
|
|
55
|
-
if (alreadyAborted !== void 0) {
|
|
56
|
-
controller.abort(abortReason(alreadyAborted, "aborted by parent scope"));
|
|
57
|
-
return {
|
|
58
|
-
signal: controller.signal,
|
|
59
|
-
abort,
|
|
60
|
-
release
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
for (const source of sources) {
|
|
64
|
-
const onAbort = () => abort(abortReason(source, "aborted by parent scope"));
|
|
65
|
-
listeners.push({
|
|
66
|
-
source,
|
|
67
|
-
onAbort
|
|
68
|
-
});
|
|
69
|
-
source.addEventListener("abort", onAbort, { once: true });
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
signal: controller.signal,
|
|
73
|
-
abort,
|
|
74
|
-
release
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/** Settle work against cancellation once, observing the losing promise.
|
|
78
|
-
* Defer abort one microtask so already-completed work wins. An action's own abort listener
|
|
79
|
-
* cannot win this race: this function subscribes before invoking it.
|
|
80
|
-
*/
|
|
81
|
-
async function runAbortable(act, signal, fallback) {
|
|
82
|
-
const aborted = () => typeof fallback === "string" ? signalAbortError(signal, fallback) : fallback();
|
|
83
|
-
if (signal.aborted) throw aborted();
|
|
84
|
-
return await new Promise((resolve, reject) => {
|
|
85
|
-
let settled = false;
|
|
86
|
-
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
87
|
-
const onAbort = () => {
|
|
88
|
-
queueMicrotask(() => {
|
|
89
|
-
if (settled) return;
|
|
90
|
-
settled = true;
|
|
91
|
-
cleanup();
|
|
92
|
-
reject(aborted());
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
96
|
-
let work;
|
|
97
|
-
try {
|
|
98
|
-
work = Promise.resolve(act());
|
|
99
|
-
} catch (error) {
|
|
100
|
-
cleanup();
|
|
101
|
-
reject(error);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
work.then((value) => {
|
|
105
|
-
if (settled) return;
|
|
106
|
-
settled = true;
|
|
107
|
-
cleanup();
|
|
108
|
-
resolve(value);
|
|
109
|
-
}, (error) => {
|
|
110
|
-
if (settled) return;
|
|
111
|
-
settled = true;
|
|
112
|
-
cleanup();
|
|
113
|
-
reject(error);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
// src/content-digest.ts
|
|
118
|
-
function sha256(value) {
|
|
119
|
-
return createHash("sha256").update(value).digest("hex");
|
|
120
|
-
}
|
|
121
|
-
// src/durable/jsonl-append.ts
|
|
122
|
-
async function appendCommittedJsonLine(path, record, options = {}) {
|
|
123
|
-
const encoded = JSON.stringify(record);
|
|
124
|
-
if (encoded === void 0) throw new TypeError("JSONL records must be JSON serializable");
|
|
125
|
-
const stamp = options.journalStamp === true;
|
|
126
|
-
if (routesToDurableWriter()) return durableCallAsync({
|
|
127
|
-
name: "appendCommittedLine",
|
|
128
|
-
args: [
|
|
129
|
-
path,
|
|
130
|
-
encoded,
|
|
131
|
-
stamp
|
|
132
|
-
]
|
|
133
|
-
});
|
|
134
|
-
const written = writeCommittedLine(path, encoded, stamp);
|
|
135
|
-
try {
|
|
136
|
-
await promisify(fsync)(written.fd);
|
|
137
|
-
return written.stamp;
|
|
138
|
-
} finally {
|
|
139
|
-
closeSync(written.fd);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/** The committed append the durable writer runs: the fenced write, then its fsync on that thread. @internal */
|
|
143
|
-
function appendCommittedLine(path, encoded, journalStamp) {
|
|
144
|
-
const written = writeCommittedLine(path, encoded, journalStamp);
|
|
145
|
-
try {
|
|
146
|
-
fsyncSync(written.fd);
|
|
147
|
-
return written.stamp;
|
|
148
|
-
} finally {
|
|
149
|
-
closeSync(written.fd);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/** Under one fence: recover the tail, write the whole line, and stamp the file when asked. */
|
|
153
|
-
function writeCommittedLine(path, encoded, journalStamp) {
|
|
154
|
-
let fd;
|
|
155
|
-
try {
|
|
156
|
-
return fenceRunWrite(() => {
|
|
157
|
-
const bytes = Buffer.from(`${prepareJsonlTail(path) ? "\n" : ""}${encoded}\n`);
|
|
158
|
-
fd = openSync(path, "a");
|
|
159
|
-
let offset = 0;
|
|
160
|
-
while (offset < bytes.length) {
|
|
161
|
-
const written = writeSync(fd, bytes, offset, bytes.length - offset);
|
|
162
|
-
if (written <= 0) throw new Error(`append-only file write made no progress at byte ${offset}`);
|
|
163
|
-
offset += written;
|
|
164
|
-
}
|
|
165
|
-
if (!journalStamp) return { fd };
|
|
166
|
-
const stamp = journalFileStamp(fstatSync(fd, { bigint: true }));
|
|
167
|
-
if (journalFileStamp(statSync(path, { bigint: true })) !== stamp) throw new Error("spawn journal changed while acknowledging its append");
|
|
168
|
-
return {
|
|
169
|
-
fd,
|
|
170
|
-
stamp
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
} catch (error) {
|
|
174
|
-
if (fd !== void 0) closeSync(fd);
|
|
175
|
-
throw error;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/** Detect replacement, truncation, and same-size edits; this is not a cross-process write lock. @internal */
|
|
179
|
-
function journalFileStamp(stat) {
|
|
180
|
-
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
181
|
-
}
|
|
182
|
-
/** Recover only an uncommitted tail. Caller holds the generation fence. @internal */
|
|
183
|
-
function prepareJsonlTail(path) {
|
|
184
|
-
let fd;
|
|
185
|
-
try {
|
|
186
|
-
fd = openSync(path, "r+");
|
|
187
|
-
} catch (error) {
|
|
188
|
-
if (error.code === "ENOENT") return false;
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const size = fstatSync(fd).size;
|
|
193
|
-
if (size === 0) return false;
|
|
194
|
-
const last = Buffer.allocUnsafe(1);
|
|
195
|
-
readAt(fd, last, size - 1);
|
|
196
|
-
if (last[0] === 10) return false;
|
|
197
|
-
const chunks = [];
|
|
198
|
-
let end = size;
|
|
199
|
-
let tailStart = 0;
|
|
200
|
-
while (end > 0) {
|
|
201
|
-
const start = Math.max(0, end - 65536);
|
|
202
|
-
const chunk = Buffer.allocUnsafe(end - start);
|
|
203
|
-
readAt(fd, chunk, start);
|
|
204
|
-
const newline = chunk.lastIndexOf(10);
|
|
205
|
-
chunks.push(chunk.subarray(newline + 1));
|
|
206
|
-
if (newline >= 0) {
|
|
207
|
-
tailStart = start + newline + 1;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
end = start;
|
|
211
|
-
}
|
|
212
|
-
try {
|
|
213
|
-
JSON.parse(Buffer.concat(chunks.reverse()).toString("utf8"));
|
|
214
|
-
return true;
|
|
215
|
-
} catch (error) {
|
|
216
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
217
|
-
ftruncateSync(fd, tailStart);
|
|
218
|
-
fsyncSync(fd);
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
} finally {
|
|
222
|
-
closeSync(fd);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function readAt(fd, buffer, position) {
|
|
226
|
-
let offset = 0;
|
|
227
|
-
while (offset < buffer.length) {
|
|
228
|
-
const read = readSync(fd, buffer, offset, buffer.length - offset, position + offset);
|
|
229
|
-
if (read === 0) throw new Error("journal changed while preparing its append tail");
|
|
230
|
-
offset += read;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
// src/durable/jsonl-file.ts
|
|
234
|
-
/** Parse in-memory evidence with the same commit boundary as streamed journal reads. */
|
|
235
|
-
function parseCommittedJsonLines(text, source) {
|
|
236
|
-
const lines = text.split("\n");
|
|
237
|
-
const records = [];
|
|
238
|
-
for (const [index, line] of lines.entries()) {
|
|
239
|
-
const record = parseRecord(line, source, index + 1, index < lines.length - 1);
|
|
240
|
-
if (record !== void 0) records.push(record.value);
|
|
241
|
-
}
|
|
242
|
-
return records;
|
|
243
|
-
}
|
|
244
|
-
/** Read a fixed file prefix one record at a time, never allocating the whole journal as a string.
|
|
245
|
-
* A reader cannot chase concurrent appends forever. Missing files are empty only when requested;
|
|
246
|
-
* corruption, short reads, and other I/O errors remain failures. Closing the iterator closes the fd. */
|
|
247
|
-
async function* readCommittedJsonLines(path, options = {}) {
|
|
248
|
-
const fs = await import("node:fs/promises");
|
|
249
|
-
let handle;
|
|
250
|
-
try {
|
|
251
|
-
handle = options.handle ?? await fs.open(path, "r");
|
|
252
|
-
} catch (error) {
|
|
253
|
-
if (options.allowMissing && isNoEntError(error)) return;
|
|
254
|
-
throw error;
|
|
255
|
-
}
|
|
256
|
-
try {
|
|
257
|
-
const start = options.start ?? 0;
|
|
258
|
-
const end = options.end ?? (await handle.stat()).size;
|
|
259
|
-
if (end <= start) return;
|
|
260
|
-
const fragments = [];
|
|
261
|
-
let offset = start;
|
|
262
|
-
let lineNumber = 1;
|
|
263
|
-
const parse = (terminated) => {
|
|
264
|
-
const bytes = Buffer.concat(fragments);
|
|
265
|
-
let line;
|
|
266
|
-
try {
|
|
267
|
-
line = options.strictUtf8 ? new TextDecoder("utf-8", { fatal: true }).decode(bytes) : bytes.toString("utf8");
|
|
268
|
-
} catch (cause) {
|
|
269
|
-
if (!terminated || options.invalid === "skip" && cause instanceof TypeError) return void 0;
|
|
270
|
-
throw new Error(`${path}: malformed UTF-8 at line ${lineNumber}`, { cause });
|
|
271
|
-
}
|
|
272
|
-
return parseRecord(line, path, lineNumber++, terminated, options.allowWhitespaceLines, options.invalid);
|
|
273
|
-
};
|
|
274
|
-
let position = start;
|
|
275
|
-
while (position < end) {
|
|
276
|
-
const buffer = Buffer.alloc(Math.min(65536, end - position));
|
|
277
|
-
const { bytesRead } = await handle.read(buffer, 0, buffer.length, position);
|
|
278
|
-
if (bytesRead === 0) throw new Error(`${path}: journal changed while reading its committed prefix`);
|
|
279
|
-
position += bytesRead;
|
|
280
|
-
const bytes = buffer.subarray(0, bytesRead);
|
|
281
|
-
options.onBytes?.(bytes);
|
|
282
|
-
let start = 0;
|
|
283
|
-
for (let end = bytes.indexOf(10); end !== -1; end = bytes.indexOf(10, start)) {
|
|
284
|
-
fragments.push(bytes.subarray(start, end));
|
|
285
|
-
const record = parse(true);
|
|
286
|
-
offset += fragments.reduce((size, part) => size + part.length, 0) + 1;
|
|
287
|
-
fragments.length = 0;
|
|
288
|
-
options.onCommit?.(offset);
|
|
289
|
-
if (record !== void 0) yield record.value;
|
|
290
|
-
start = end + 1;
|
|
291
|
-
}
|
|
292
|
-
if (start < bytes.length) fragments.push(bytes.subarray(start));
|
|
293
|
-
}
|
|
294
|
-
const record = parse(false);
|
|
295
|
-
if (record !== void 0) {
|
|
296
|
-
options.onCommit?.(end);
|
|
297
|
-
yield record.value;
|
|
298
|
-
}
|
|
299
|
-
} finally {
|
|
300
|
-
if (options.handle === void 0) await handle.close();
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
/** An invalid unterminated tail may be a torn write; other parse failures are not evidence of one. */
|
|
304
|
-
function parseRecord(line, source, lineNumber, terminated, allowWhitespaceLines = false, invalid = "throw") {
|
|
305
|
-
if (line.length === 0 || allowWhitespaceLines && line.trim().length === 0) return void 0;
|
|
306
|
-
try {
|
|
307
|
-
return { value: JSON.parse(line) };
|
|
308
|
-
} catch (cause) {
|
|
309
|
-
if (!(cause instanceof SyntaxError)) throw cause;
|
|
310
|
-
if (!terminated || invalid === "skip") return void 0;
|
|
311
|
-
throw new Error(`${source}: malformed JSONL record at line ${lineNumber}`, { cause });
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
/** Serialize JSONL file updates across processes and aliases using Eval's existing file lock.
|
|
315
|
-
* The caller owns validation and the record format. The lock path names the canonical file,
|
|
316
|
-
* including its first write, so two directory aliases cannot acquire different write heads.
|
|
317
|
-
*
|
|
318
|
-
* The wait bounds one live holder, not the queue. A holder that keeps the lock for the whole
|
|
319
|
-
* bound is stuck and the caller is told; the lock primitive itself takes over a dead holder.
|
|
320
|
-
* Writers that each release are progress, so a caller behind them keeps waiting. A bound on the
|
|
321
|
-
* queue would refuse a caller whenever the writers ahead of it together took that long, which a
|
|
322
|
-
* host with slow disk syncs does to a handful of concurrent writers.
|
|
323
|
-
* @internal
|
|
324
|
-
*/
|
|
325
|
-
async function withJsonlFileLock(path, operation) {
|
|
326
|
-
const fs = await import("node:fs/promises");
|
|
327
|
-
const { dirname } = await import("node:path");
|
|
328
|
-
const { tryAcquireAtomicFileLock } = await import("@tangle-network/agent-eval/ledger-core");
|
|
329
|
-
await fs.mkdir(dirname(path), { recursive: true });
|
|
330
|
-
await (await fs.open(path, "a")).close();
|
|
331
|
-
const canonicalPath = await fs.realpath(path);
|
|
332
|
-
let holder;
|
|
333
|
-
let heldSince = Date.now();
|
|
334
|
-
for (;;) {
|
|
335
|
-
const acquisition = tryAcquireAtomicFileLock({ lockPath: `${canonicalPath}.lock` });
|
|
336
|
-
if (!acquisition.acquired) {
|
|
337
|
-
if (acquisition.reason === "held" && acquisition.holder.nonce !== holder) {
|
|
338
|
-
holder = acquisition.holder.nonce;
|
|
339
|
-
heldSince = Date.now();
|
|
340
|
-
}
|
|
341
|
-
if (Date.now() - heldSince >= 5e3) throw new Error(`journal file lock unavailable after 5000ms: ${canonicalPath}`);
|
|
342
|
-
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
try {
|
|
346
|
-
return await operation(canonicalPath);
|
|
347
|
-
} finally {
|
|
348
|
-
acquisition.lock.release();
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/** Read one keyed registry snapshot without an extra whole-file text allocation.
|
|
353
|
-
* Historical registry files allow whitespace-only separators; append journals remain strict.
|
|
354
|
-
* @internal
|
|
355
|
-
*/
|
|
356
|
-
async function readCommittedJsonFile(path) {
|
|
357
|
-
const records = [];
|
|
358
|
-
for await (const record of readCommittedJsonLines(path, {
|
|
359
|
-
allowMissing: true,
|
|
360
|
-
allowWhitespaceLines: true
|
|
361
|
-
})) records.push(record);
|
|
362
|
-
return records;
|
|
363
|
-
}
|
|
364
|
-
/** Replace one keyed row and publish one durable snapshot. The caller holds the file lock.
|
|
365
|
-
* Keep unrelated rows in order and put the replacement last. No revision archive is retained.
|
|
366
|
-
* @internal
|
|
367
|
-
*/
|
|
368
|
-
async function upsertCommittedJsonLine(path, record, key) {
|
|
369
|
-
const encoded = JSON.stringify(record);
|
|
370
|
-
if (encoded === void 0) throw new Error("JSONL records must be JSON serializable");
|
|
371
|
-
const snapshot = JSON.parse(encoded);
|
|
372
|
-
const id = key(snapshot);
|
|
373
|
-
const updated = [];
|
|
374
|
-
for await (const prior of readCommittedJsonLines(path, {
|
|
375
|
-
allowMissing: true,
|
|
376
|
-
allowWhitespaceLines: true
|
|
377
|
-
})) if (key(prior) !== id) updated.push(prior);
|
|
378
|
-
updated.push(snapshot);
|
|
379
|
-
const { writeAtomicDurableFile } = await import("./durable-file-iPCEs_-s.js");
|
|
380
|
-
writeAtomicDurableFile(path, `${updated.map((row) => JSON.stringify(row)).join("\n")}\n`, { preserveMode: true });
|
|
381
|
-
}
|
|
382
|
-
/** Recover a torn tail under the same generation fence as durable publications. @internal */
|
|
383
|
-
async function prepareJsonlAppend(path) {
|
|
384
|
-
return runFencedAsync("prepareJsonlAppend", prepareJsonlTailFenced, path);
|
|
385
|
-
}
|
|
386
|
-
/** The fenced tail recovery the durable writer runs. @internal */
|
|
387
|
-
function prepareJsonlTailFenced(path) {
|
|
388
|
-
return fenceRunWrite(() => prepareJsonlTail(path));
|
|
389
|
-
}
|
|
390
|
-
/** True for a filesystem error meaning "the file is not there yet" — the one condition an
|
|
391
|
-
* append-only reader treats as an empty log rather than a fault. */
|
|
392
|
-
function isNoEntError(error) {
|
|
393
|
-
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
394
|
-
}
|
|
395
|
-
export { runAbortable as _, readCommittedJsonFile as a, withJsonlFileLock as c, journalFileStamp as d, sha256 as f, linkAbort as g, deadlineSignal as h, prepareJsonlTailFenced as i, appendCommittedJsonLine as l, abortReason as m, parseCommittedJsonLines as n, readCommittedJsonLines as o, RunCancellationReason as p, prepareJsonlAppend as r, upsertCommittedJsonLine as s, isNoEntError as t, appendCommittedLine as u, signalAbortError as v };
|
|
396
|
-
|
|
397
|
-
//# sourceMappingURL=jsonl-file-B8xfYz9M.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl-file-B8xfYz9M.js","names":[],"sources":["../src/runtime/supervise/abortable.ts","../src/content-digest.ts","../src/durable/jsonl-append.ts","../src/durable/jsonl-file.ts"],"sourcesContent":["/** Provenance of an explicit cancellation, preserved through every abort link. */\nexport class RunCancellationReason extends Error {\n constructor(\n readonly source: string,\n reason: string,\n readonly operationId?: string,\n /** Who stopped the run, from the durable cancel request; absent for an in-process abort. */\n readonly operator?: string,\n ) {\n super(reason)\n this.name = 'RunCancellationReason'\n }\n\n override toString(): string {\n return this.message\n }\n}\n\n/** The signal's explicit reason, or the caller's fallback when none was supplied. */\nexport function abortReason(signal: AbortSignal, fallback: string): unknown {\n const reason = signal.reason\n if (reason instanceof RunCancellationReason) return reason\n if (typeof reason === 'string' && reason.length > 0) return reason\n // A default AbortError carries no caller reason.\n if (reason instanceof Error && reason.name !== 'AbortError' && reason.message.length > 0) {\n return reason.message\n }\n return fallback\n}\n\n/** An `AbortError` carrying the signal's own string reason, or `fallback` when it states none. */\nexport function signalAbortError(signal: AbortSignal, fallback: string): Error {\n const reason = abortReason(signal, fallback)\n const error = new Error(\n reason instanceof Error\n ? reason.message\n : typeof reason === 'string' && reason.length > 0\n ? reason\n : fallback,\n )\n error.name = 'AbortError'\n return error\n}\n\n/** A parent abort stops the call at once. The timeout still bounds a parent that stays open. */\nexport function deadlineSignal(parent: AbortSignal | undefined, ms: number): AbortSignal {\n const timeout = AbortSignal.timeout(ms)\n return parent === undefined ? timeout : AbortSignal.any([parent, timeout])\n}\n\ninterface LinkedAbort {\n readonly signal: AbortSignal\n abort(reason?: unknown): void\n /** Stop listening to the sources. Idempotent; required where a source outlives the link. */\n release(): void\n}\n\n/** Cascade source aborts and preserve their reason; release removes the source listeners. */\nexport function linkAbort(...sources: ReadonlyArray<AbortSignal>): LinkedAbort {\n const controller = new AbortController()\n const listeners: Array<{ source: AbortSignal; onAbort: () => void }> = []\n const release = (): void => {\n for (const { source, onAbort } of listeners) source.removeEventListener('abort', onAbort)\n listeners.length = 0\n }\n const abort = (reason?: unknown): void => {\n release()\n controller.abort(reason)\n }\n const alreadyAborted = sources.find((source) => source.aborted)\n if (alreadyAborted !== undefined) {\n controller.abort(abortReason(alreadyAborted, 'aborted by parent scope'))\n return { signal: controller.signal, abort, release }\n }\n for (const source of sources) {\n const onAbort = (): void => abort(abortReason(source, 'aborted by parent scope'))\n listeners.push({ source, onAbort })\n source.addEventListener('abort', onAbort, { once: true })\n }\n return { signal: controller.signal, abort, release }\n}\n\n/** Settle work against cancellation once, observing the losing promise.\n * Defer abort one microtask so already-completed work wins. An action's own abort listener\n * cannot win this race: this function subscribes before invoking it.\n */\nexport async function runAbortable<T>(\n act: () => Promise<T>,\n signal: AbortSignal,\n /** The abort's message when the signal states none, or the abort error itself. */\n fallback: string | (() => unknown),\n): Promise<T> {\n const aborted = () =>\n typeof fallback === 'string' ? signalAbortError(signal, fallback) : fallback()\n if (signal.aborted) throw aborted()\n return await new Promise<T>((resolve, reject) => {\n let settled = false\n const cleanup = () => signal.removeEventListener('abort', onAbort)\n const onAbort = () => {\n queueMicrotask(() => {\n if (settled) return\n settled = true\n cleanup()\n reject(aborted())\n })\n }\n signal.addEventListener('abort', onAbort, { once: true })\n let work: Promise<T>\n try {\n work = Promise.resolve(act())\n } catch (error) {\n cleanup()\n reject(error)\n return\n }\n work.then(\n (value) => {\n if (settled) return\n settled = true\n cleanup()\n resolve(value)\n },\n (error) => {\n if (settled) return\n settled = true\n cleanup()\n reject(error)\n },\n )\n })\n}\n","import { createHash } from 'node:crypto'\n\nexport function sha256(value: string): string {\n return createHash('sha256').update(value).digest('hex')\n}\n","import {\n type BigIntStats,\n closeSync,\n fstatSync,\n fsync,\n fsyncSync,\n ftruncateSync,\n openSync,\n readSync,\n statSync,\n writeSync,\n} from 'node:fs'\nimport { promisify } from 'node:util'\nimport { durableCallAsync, routesToDurableWriter } from './durable-writer'\nimport { fenceRunWrite } from './run-fence'\n\n/** Append one JSONL record under the caller's existing single-writer discipline.\n * The caller creates the parent directory. Recover only an uncommitted tail and handle short\n * writes under one generation fence; fsync after the fence, off the event loop (#2362), and\n * resolve only once the bytes are durable. A claimed append made on the main thread runs on the\n * durable writer (durable-writer.ts). With `journalStamp`, the append also proves, inside the\n * fence, that the file it wrote is still the one at `path`, and resolves with that file's stamp.\n * @internal\n */\nexport function appendCommittedJsonLine(path: string, record: unknown): Promise<undefined>\nexport function appendCommittedJsonLine(\n path: string,\n record: unknown,\n options: { readonly journalStamp: true },\n): Promise<string>\nexport async function appendCommittedJsonLine(\n path: string,\n record: unknown,\n options: { readonly journalStamp?: boolean } = {},\n): Promise<string | undefined> {\n const encoded = JSON.stringify(record)\n if (encoded === undefined) throw new TypeError('JSONL records must be JSON serializable')\n const stamp = options.journalStamp === true\n if (routesToDurableWriter())\n return durableCallAsync({ name: 'appendCommittedLine', args: [path, encoded, stamp] })\n const written = writeCommittedLine(path, encoded, stamp)\n try {\n await promisify(fsync)(written.fd)\n return written.stamp\n } finally {\n closeSync(written.fd)\n }\n}\n\n/** The committed append the durable writer runs: the fenced write, then its fsync on that thread. @internal */\nexport function appendCommittedLine(\n path: string,\n encoded: string,\n journalStamp: boolean,\n): string | undefined {\n const written = writeCommittedLine(path, encoded, journalStamp)\n try {\n fsyncSync(written.fd)\n return written.stamp\n } finally {\n closeSync(written.fd)\n }\n}\n\n/** Under one fence: recover the tail, write the whole line, and stamp the file when asked. */\nfunction writeCommittedLine(\n path: string,\n encoded: string,\n journalStamp: boolean,\n): { fd: number; stamp?: string } {\n let fd: number | undefined\n try {\n return fenceRunWrite(() => {\n const bytes = Buffer.from(`${prepareJsonlTail(path) ? '\\n' : ''}${encoded}\\n`)\n fd = openSync(path, 'a')\n let offset = 0\n while (offset < bytes.length) {\n const written = writeSync(fd, bytes, offset, bytes.length - offset)\n if (written <= 0)\n throw new Error(`append-only file write made no progress at byte ${offset}`)\n offset += written\n }\n if (!journalStamp) return { fd }\n const stamp = journalFileStamp(fstatSync(fd, { bigint: true }))\n if (journalFileStamp(statSync(path, { bigint: true })) !== stamp) {\n throw new Error('spawn journal changed while acknowledging its append')\n }\n return { fd, stamp }\n })\n } catch (error) {\n if (fd !== undefined) closeSync(fd)\n throw error\n }\n}\n\n/** Detect replacement, truncation, and same-size edits; this is not a cross-process write lock. @internal */\nexport function journalFileStamp(stat: BigIntStats): string {\n return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`\n}\n\n/** Recover only an uncommitted tail. Caller holds the generation fence. @internal */\nexport function prepareJsonlTail(path: string): boolean {\n let fd: number\n try {\n fd = openSync(path, 'r+')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false\n throw error\n }\n try {\n const size = fstatSync(fd).size\n if (size === 0) return false\n const last = Buffer.allocUnsafe(1)\n readAt(fd, last, size - 1)\n if (last[0] === 0x0a) return false\n const chunks: Buffer[] = []\n let end = size\n let tailStart = 0\n while (end > 0) {\n const start = Math.max(0, end - 65_536)\n const chunk = Buffer.allocUnsafe(end - start)\n readAt(fd, chunk, start)\n const newline = chunk.lastIndexOf(0x0a)\n chunks.push(chunk.subarray(newline + 1))\n if (newline >= 0) {\n tailStart = start + newline + 1\n break\n }\n end = start\n }\n try {\n JSON.parse(Buffer.concat(chunks.reverse()).toString('utf8'))\n return true\n } catch (error) {\n if (!(error instanceof SyntaxError)) throw error\n ftruncateSync(fd, tailStart)\n fsyncSync(fd)\n return false\n }\n } finally {\n closeSync(fd)\n }\n}\n\nfunction readAt(fd: number, buffer: Buffer, position: number): void {\n let offset = 0\n while (offset < buffer.length) {\n const read = readSync(fd, buffer, offset, buffer.length - offset, position + offset)\n if (read === 0) throw new Error('journal changed while preparing its append tail')\n offset += read\n }\n}\n","import type { FileHandle } from 'node:fs/promises'\nimport { runFencedAsync } from './durable-writer'\nimport { prepareJsonlTail } from './jsonl-append'\nimport { fenceRunWrite } from './run-fence'\n\n/** Parse in-memory evidence with the same commit boundary as streamed journal reads. */\nexport function parseCommittedJsonLines<T>(text: string, source: string): T[] {\n const lines = text.split('\\n')\n const records: T[] = []\n for (const [index, line] of lines.entries()) {\n const record = parseRecord<T>(line, source, index + 1, index < lines.length - 1)\n if (record !== undefined) records.push(record.value)\n }\n return records\n}\n\n/** Read a fixed file prefix one record at a time, never allocating the whole journal as a string.\n * A reader cannot chase concurrent appends forever. Missing files are empty only when requested;\n * corruption, short reads, and other I/O errors remain failures. Closing the iterator closes the fd. */\nexport async function* readCommittedJsonLines<T>(\n path: string,\n options: {\n allowMissing?: boolean\n allowWhitespaceLines?: boolean\n invalid?: 'throw' | 'skip'\n onBytes?: (bytes: Uint8Array) => void\n /** Internal fixed-prefix range. The caller supplies a record boundary and owns the handle. */\n handle?: FileHandle\n start?: number\n end?: number\n strictUtf8?: boolean\n onCommit?: (offset: number) => void\n } = {},\n): AsyncGenerator<T> {\n const fs = await import('node:fs/promises')\n let handle: FileHandle\n try {\n handle = options.handle ?? (await fs.open(path, 'r'))\n } catch (error) {\n if (options.allowMissing && isNoEntError(error)) return\n throw error\n }\n try {\n const start = options.start ?? 0\n const end = options.end ?? (await handle.stat()).size\n if (end <= start) return\n const fragments: Buffer[] = []\n let offset = start\n let lineNumber = 1\n const parse = (terminated: boolean): { value: T } | undefined => {\n const bytes = Buffer.concat(fragments)\n let line: string\n try {\n line = options.strictUtf8\n ? new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n : bytes.toString('utf8')\n } catch (cause) {\n if (!terminated || (options.invalid === 'skip' && cause instanceof TypeError))\n return undefined\n throw new Error(`${path}: malformed UTF-8 at line ${lineNumber}`, { cause })\n }\n return parseRecord<T>(\n line,\n path,\n lineNumber++,\n terminated,\n options.allowWhitespaceLines,\n options.invalid,\n )\n }\n let position = start\n while (position < end) {\n const buffer = Buffer.alloc(Math.min(65_536, end - position))\n const { bytesRead } = await handle.read(buffer, 0, buffer.length, position)\n if (bytesRead === 0) {\n throw new Error(`${path}: journal changed while reading its committed prefix`)\n }\n position += bytesRead\n const bytes = buffer.subarray(0, bytesRead)\n options.onBytes?.(bytes)\n let start = 0\n for (let end = bytes.indexOf(10); end !== -1; end = bytes.indexOf(10, start)) {\n fragments.push(bytes.subarray(start, end))\n const record = parse(true)\n offset += fragments.reduce((size, part) => size + part.length, 0) + 1\n fragments.length = 0\n options.onCommit?.(offset)\n if (record !== undefined) yield record.value\n start = end + 1\n }\n if (start < bytes.length) fragments.push(bytes.subarray(start))\n }\n const record = parse(false)\n if (record !== undefined) {\n options.onCommit?.(end)\n yield record.value\n }\n } finally {\n if (options.handle === undefined) await handle.close()\n }\n}\n\n/** An invalid unterminated tail may be a torn write; other parse failures are not evidence of one. */\nfunction parseRecord<T>(\n line: string,\n source: string,\n lineNumber: number,\n terminated: boolean,\n allowWhitespaceLines = false,\n invalid: 'throw' | 'skip' = 'throw',\n): { value: T } | undefined {\n if (line.length === 0 || (allowWhitespaceLines && line.trim().length === 0)) return undefined\n try {\n return { value: JSON.parse(line) as T }\n } catch (cause) {\n if (!(cause instanceof SyntaxError)) throw cause\n if (!terminated || invalid === 'skip') return undefined\n throw new Error(`${source}: malformed JSONL record at line ${lineNumber}`, { cause })\n }\n}\n\nexport { appendCommittedJsonLine } from './jsonl-append'\n\n/** Serialize JSONL file updates across processes and aliases using Eval's existing file lock.\n * The caller owns validation and the record format. The lock path names the canonical file,\n * including its first write, so two directory aliases cannot acquire different write heads.\n *\n * The wait bounds one live holder, not the queue. A holder that keeps the lock for the whole\n * bound is stuck and the caller is told; the lock primitive itself takes over a dead holder.\n * Writers that each release are progress, so a caller behind them keeps waiting. A bound on the\n * queue would refuse a caller whenever the writers ahead of it together took that long, which a\n * host with slow disk syncs does to a handful of concurrent writers.\n * @internal\n */\nexport async function withJsonlFileLock<T>(\n path: string,\n operation: (canonicalPath: string) => Promise<T>,\n): Promise<T> {\n const fs = await import('node:fs/promises')\n const { dirname } = await import('node:path')\n const { tryAcquireAtomicFileLock } = await import('@tangle-network/agent-eval/ledger-core')\n await fs.mkdir(dirname(path), { recursive: true })\n const file = await fs.open(path, 'a')\n await file.close()\n const canonicalPath = await fs.realpath(path)\n let holder: string | undefined\n let heldSince = Date.now()\n for (;;) {\n const acquisition = tryAcquireAtomicFileLock({ lockPath: `${canonicalPath}.lock` })\n if (!acquisition.acquired) {\n // Each acquisition writes a new nonce, so a changed nonce is a later holder, also when the\n // same process took the lock again. A recovery in progress names no holder, so the clock\n // keeps running.\n if (acquisition.reason === 'held' && acquisition.holder.nonce !== holder) {\n holder = acquisition.holder.nonce\n heldSince = Date.now()\n }\n if (Date.now() - heldSince >= 5000) {\n throw new Error(`journal file lock unavailable after 5000ms: ${canonicalPath}`)\n }\n await new Promise((resolve) => setTimeout(resolve, 25))\n continue\n }\n try {\n return await operation(canonicalPath)\n } finally {\n acquisition.lock.release()\n }\n }\n}\n\n/** Read one keyed registry snapshot without an extra whole-file text allocation.\n * Historical registry files allow whitespace-only separators; append journals remain strict.\n * @internal\n */\nexport async function readCommittedJsonFile<T>(path: string): Promise<T[]> {\n const records: T[] = []\n for await (const record of readCommittedJsonLines<T>(path, {\n allowMissing: true,\n allowWhitespaceLines: true,\n })) {\n records.push(record)\n }\n return records\n}\n\n/** Replace one keyed row and publish one durable snapshot. The caller holds the file lock.\n * Keep unrelated rows in order and put the replacement last. No revision archive is retained.\n * @internal\n */\nexport async function upsertCommittedJsonLine<T>(\n path: string,\n record: T,\n key: (record: T) => string,\n): Promise<void> {\n const encoded = JSON.stringify(record)\n if (encoded === undefined) throw new Error('JSONL records must be JSON serializable')\n const snapshot: T = JSON.parse(encoded)\n const id = key(snapshot)\n const updated: T[] = []\n for await (const prior of readCommittedJsonLines<T>(path, {\n allowMissing: true,\n allowWhitespaceLines: true,\n })) {\n if (key(prior) !== id) updated.push(prior)\n }\n updated.push(snapshot)\n // Reuse Runtime's file publication owner; this module owns JSONL framing, not another\n // durability implementation. Preserve the existing snapshot's permissions across rename.\n const { writeAtomicDurableFile } = await import('../runtime/supervise/durable-file')\n writeAtomicDurableFile(path, `${updated.map((row) => JSON.stringify(row)).join('\\n')}\\n`, {\n preserveMode: true,\n })\n}\n\n/** Recover a torn tail under the same generation fence as durable publications. @internal */\nexport async function prepareJsonlAppend(path: string): Promise<boolean> {\n return runFencedAsync('prepareJsonlAppend', prepareJsonlTailFenced, path)\n}\n\n/** The fenced tail recovery the durable writer runs. @internal */\nexport function prepareJsonlTailFenced(path: string): boolean {\n return fenceRunWrite(() => prepareJsonlTail(path))\n}\n\n/** True for a filesystem error meaning \"the file is not there yet\" — the one condition an\n * append-only reader treats as an empty log rather than a fault. */\nexport function isNoEntError(error: unknown): boolean {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'code' in error &&\n (error as { code: unknown }).code === 'ENOENT'\n )\n}\n"],"mappings":";;;;;;AACA,IAAa,wBAAb,cAA2C,MAAM;CAEpC;CAEA;CAEA;CALX,YACE,QACA,QACA,aAEA,UACA;EACA,MAAM,MAAM;EANH,KAAA,SAAA;EAEA,KAAA,cAAA;EAEA,KAAA,WAAA;EAGT,KAAK,OAAO;CACd;CAEA,WAA4B;EAC1B,OAAO,KAAK;CACd;AACF;;AAGA,SAAgB,YAAY,QAAqB,UAA2B;CAC1E,MAAM,SAAS,OAAO;CACtB,IAAI,kBAAkB,uBAAuB,OAAO;CACpD,IAAI,OAAO,WAAW,YAAY,OAAO,SAAS,GAAG,OAAO;CAE5D,IAAI,kBAAkB,SAAS,OAAO,SAAS,gBAAgB,OAAO,QAAQ,SAAS,GACrF,OAAO,OAAO;CAEhB,OAAO;AACT;;AAGA,SAAgB,iBAAiB,QAAqB,UAAyB;CAC7E,MAAM,SAAS,YAAY,QAAQ,QAAQ;CAC3C,MAAM,QAAQ,IAAI,MAChB,kBAAkB,QACd,OAAO,UACP,OAAO,WAAW,YAAY,OAAO,SAAS,IAC5C,SACA,QACR;CACA,MAAM,OAAO;CACb,OAAO;AACT;;AAGA,SAAgB,eAAe,QAAi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