poe-code 3.0.308 → 3.0.309
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/dist/index.js +35 -2
- package/dist/index.js.map +2 -2
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/process-launcher/dist/launcher.js +32 -1
package/package.json
CHANGED
|
@@ -180,7 +180,18 @@ export async function* followManagedLogs(options) {
|
|
|
180
180
|
throw new Error(`Invalid managed log poll interval: ${pollIntervalMs}`);
|
|
181
181
|
}
|
|
182
182
|
const cursor = createFollowLogCursor();
|
|
183
|
-
|
|
183
|
+
const initialLines = options.lines === undefined
|
|
184
|
+
? []
|
|
185
|
+
: await readInitialFollowLogWindow(fs, options.baseDir, options.id, stream, options.lines, cursor);
|
|
186
|
+
if (options.lines === undefined) {
|
|
187
|
+
await primeFollowCursor(fs, options.baseDir, options.id, stream, cursor);
|
|
188
|
+
}
|
|
189
|
+
for (const line of initialLines) {
|
|
190
|
+
if (options.signal?.aborted) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
yield line;
|
|
194
|
+
}
|
|
184
195
|
while (!options.signal?.aborted) {
|
|
185
196
|
await sleep(pollIntervalMs);
|
|
186
197
|
if (options.signal?.aborted) {
|
|
@@ -200,6 +211,26 @@ function createFollowLogCursor() {
|
|
|
200
211
|
remainder: ""
|
|
201
212
|
};
|
|
202
213
|
}
|
|
214
|
+
async function readInitialFollowLogWindow(fs, baseDir, id, stream, lines, cursor) {
|
|
215
|
+
assertValidLogLineCount(lines);
|
|
216
|
+
const stat = await statFollowedLog(fs, baseDir, id, stream);
|
|
217
|
+
resetFollowCursor(cursor, stat?.fileId ?? null);
|
|
218
|
+
if (stat === null) {
|
|
219
|
+
return [];
|
|
220
|
+
}
|
|
221
|
+
const bytes = await readFollowedLogBytes(fs, resolveCurrentLogPath(baseDir, id, stream), 0);
|
|
222
|
+
cursor.offset = bytes.byteLength;
|
|
223
|
+
const allLines = consumeFollowedLogBytes(cursor, bytes);
|
|
224
|
+
if (lines === 0) {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
return allLines.slice(-lines);
|
|
228
|
+
}
|
|
229
|
+
function assertValidLogLineCount(lines) {
|
|
230
|
+
if (!Number.isFinite(lines) || !Number.isInteger(lines) || lines < 0) {
|
|
231
|
+
throw new Error("lines must be a finite non-negative integer");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
203
234
|
async function primeFollowCursor(fs, baseDir, id, stream, cursor) {
|
|
204
235
|
const stat = await statFollowedLog(fs, baseDir, id, stream);
|
|
205
236
|
resetFollowCursor(cursor, stat?.fileId ?? null);
|