billion-context 0.1.59-pr.307.159 → 0.1.59
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 +34 -99
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47033,15 +47033,12 @@ function caDir() {
|
|
|
47033
47033
|
}
|
|
47034
47034
|
|
|
47035
47035
|
// src/logger.ts
|
|
47036
|
-
import { createWriteStream,
|
|
47036
|
+
import { createWriteStream, mkdirSync, statSync, renameSync } from "fs";
|
|
47037
47037
|
import path2 from "path";
|
|
47038
47038
|
var MAX_BYTES = 10 * 1024 * 1024;
|
|
47039
47039
|
var stream;
|
|
47040
|
-
var streamFd;
|
|
47041
47040
|
var logPath;
|
|
47042
47041
|
var bytesWritten = 0;
|
|
47043
|
-
var reopenWarned = false;
|
|
47044
|
-
var capture = null;
|
|
47045
47042
|
function openStream(file) {
|
|
47046
47043
|
mkdirSync(path2.dirname(file), { recursive: true });
|
|
47047
47044
|
let existingSize = 0;
|
|
@@ -47057,69 +47054,23 @@ function openStream(file) {
|
|
|
47057
47054
|
} catch {
|
|
47058
47055
|
}
|
|
47059
47056
|
const s3 = createWriteStream(file, { flags: "a" });
|
|
47060
|
-
s3.on("open", (fd) => {
|
|
47061
|
-
if (stream === s3) streamFd = fd;
|
|
47062
|
-
});
|
|
47063
47057
|
s3.on("error", () => {
|
|
47064
47058
|
try {
|
|
47065
47059
|
s3.destroy();
|
|
47066
47060
|
} catch {
|
|
47067
47061
|
}
|
|
47068
|
-
if (stream === s3)
|
|
47069
|
-
stream = void 0;
|
|
47070
|
-
streamFd = void 0;
|
|
47071
|
-
}
|
|
47062
|
+
if (stream === s3) stream = void 0;
|
|
47072
47063
|
});
|
|
47073
47064
|
bytesWritten = existingSize;
|
|
47074
47065
|
return s3;
|
|
47075
47066
|
}
|
|
47076
|
-
function isOrphaned(s3) {
|
|
47077
|
-
if (stream === s3 && streamFd === void 0) return false;
|
|
47078
|
-
try {
|
|
47079
|
-
const fdStat = fstatSync(streamFd);
|
|
47080
|
-
const pathStat = statSync(logPath);
|
|
47081
|
-
return fdStat.ino !== pathStat.ino || fdStat.dev !== pathStat.dev;
|
|
47082
|
-
} catch {
|
|
47083
|
-
return true;
|
|
47084
|
-
}
|
|
47085
|
-
}
|
|
47086
|
-
function closeQuietly(s3) {
|
|
47087
|
-
try {
|
|
47088
|
-
s3.end();
|
|
47089
|
-
} catch {
|
|
47090
|
-
}
|
|
47091
|
-
}
|
|
47092
|
-
function warnReopenFailed(err2) {
|
|
47093
|
-
if (reopenWarned) return;
|
|
47094
|
-
reopenWarned = true;
|
|
47095
|
-
const reason = err2 instanceof Error ? err2.message : String(err2);
|
|
47096
|
-
const msg = `log file ${logPath ?? "?"} unavailable (${reason}); continuing with stderr-only logging`;
|
|
47097
|
-
if (capture) {
|
|
47098
|
-
try {
|
|
47099
|
-
capture("warn", msg);
|
|
47100
|
-
} catch {
|
|
47101
|
-
}
|
|
47102
|
-
}
|
|
47103
|
-
try {
|
|
47104
|
-
process.stderr.write(`${(/* @__PURE__ */ new Date()).toISOString()} [warn] ${msg}
|
|
47105
|
-
`);
|
|
47106
|
-
} catch {
|
|
47107
|
-
}
|
|
47108
|
-
}
|
|
47109
47067
|
function getStream() {
|
|
47110
47068
|
if (!logPath) return void 0;
|
|
47111
|
-
if (stream && stream.writable
|
|
47112
|
-
if (stream) closeQuietly(stream);
|
|
47113
|
-
stream = void 0;
|
|
47114
|
-
streamFd = void 0;
|
|
47069
|
+
if (stream && stream.writable) return stream;
|
|
47115
47070
|
try {
|
|
47116
47071
|
stream = openStream(logPath);
|
|
47117
|
-
reopenWarned = false;
|
|
47118
47072
|
return stream;
|
|
47119
|
-
} catch
|
|
47120
|
-
stream = void 0;
|
|
47121
|
-
streamFd = void 0;
|
|
47122
|
-
warnReopenFailed(err2);
|
|
47073
|
+
} catch {
|
|
47123
47074
|
return void 0;
|
|
47124
47075
|
}
|
|
47125
47076
|
}
|
|
@@ -47130,9 +47081,10 @@ function configureLogger(file) {
|
|
|
47130
47081
|
return void 0;
|
|
47131
47082
|
}
|
|
47132
47083
|
logPath = file;
|
|
47133
|
-
stream =
|
|
47084
|
+
stream = openStream(file);
|
|
47134
47085
|
return file;
|
|
47135
47086
|
}
|
|
47087
|
+
var capture = null;
|
|
47136
47088
|
var log = (level, msg) => {
|
|
47137
47089
|
if (capture) {
|
|
47138
47090
|
try {
|
|
@@ -47150,21 +47102,22 @@ var log = (level, msg) => {
|
|
|
47150
47102
|
let s3 = getStream();
|
|
47151
47103
|
if (s3) {
|
|
47152
47104
|
if (bytesWritten >= MAX_BYTES) {
|
|
47153
|
-
|
|
47154
|
-
|
|
47155
|
-
|
|
47105
|
+
try {
|
|
47106
|
+
s3.end();
|
|
47107
|
+
} catch {
|
|
47108
|
+
}
|
|
47109
|
+
stream = openStream(logPath);
|
|
47110
|
+
s3 = stream;
|
|
47156
47111
|
}
|
|
47157
|
-
|
|
47112
|
+
try {
|
|
47113
|
+
s3.write(line);
|
|
47114
|
+
bytesWritten += Buffer.byteLength(line);
|
|
47115
|
+
} catch {
|
|
47158
47116
|
try {
|
|
47159
|
-
s3.
|
|
47160
|
-
bytesWritten += Buffer.byteLength(line);
|
|
47117
|
+
s3.destroy();
|
|
47161
47118
|
} catch {
|
|
47162
|
-
try {
|
|
47163
|
-
s3.destroy();
|
|
47164
|
-
} catch {
|
|
47165
|
-
}
|
|
47166
|
-
stream = void 0;
|
|
47167
47119
|
}
|
|
47120
|
+
stream = void 0;
|
|
47168
47121
|
}
|
|
47169
47122
|
}
|
|
47170
47123
|
};
|
|
@@ -47176,7 +47129,6 @@ function closeLogger() {
|
|
|
47176
47129
|
}
|
|
47177
47130
|
}
|
|
47178
47131
|
stream = void 0;
|
|
47179
|
-
streamFd = void 0;
|
|
47180
47132
|
bytesWritten = 0;
|
|
47181
47133
|
}
|
|
47182
47134
|
|
|
@@ -49878,17 +49830,15 @@ function normalizeSseLineEndings(buf) {
|
|
|
49878
49830
|
}
|
|
49879
49831
|
|
|
49880
49832
|
// src/loop/tag-echo-filter.ts
|
|
49881
|
-
var PAIRED = /\x3cacp\s[^<>]
|
|
49882
|
-
var
|
|
49883
|
-
var LONE_CLOSE = /<\/acp(?=[\s>])[^<>]{0,32}>/;
|
|
49833
|
+
var PAIRED = /\x3cacp\s[^<>]*>([^<>]{0,64})<\/acp>/;
|
|
49834
|
+
var LONE = /<\/?acp(?=[\s>])[^<>]*>/;
|
|
49884
49835
|
var PARTIAL_TAIL = /(\x3cacp\s[^<>]*|<\/?a?c?p?)$/;
|
|
49885
|
-
var
|
|
49836
|
+
var TRUNCATED_TAG = /\x3cacp\s[^<>]*tokens\s*=\s*"[^<>"]*"[^<>]*$/;
|
|
49886
49837
|
var CLOSE_TAG = "</acp";
|
|
49887
49838
|
var HOLD_LIMIT = 128;
|
|
49888
|
-
var TAG_OPEN_CAP = 4096;
|
|
49889
49839
|
var SWALLOW_CAP = 80;
|
|
49890
49840
|
function stripAcpTags(text) {
|
|
49891
|
-
return text.replace(new RegExp(PAIRED.source, "g"), "").replace(new RegExp(
|
|
49841
|
+
return text.replace(new RegExp(PAIRED.source, "g"), "").replace(new RegExp(LONE.source, "g"), "").replace(new RegExp(TRUNCATED_TAG.source), "");
|
|
49892
49842
|
}
|
|
49893
49843
|
function containsRenderTagText(s3) {
|
|
49894
49844
|
return /\x3c\/?acp(?=[\s>])/.test(s3) || /\\u003c\/?acp(?=[\s>\\])/.test(s3);
|
|
@@ -49931,26 +49881,15 @@ function createTagEchoFilter(onDrop) {
|
|
|
49931
49881
|
return out;
|
|
49932
49882
|
}
|
|
49933
49883
|
const p2 = PAIRED.exec(buf);
|
|
49934
|
-
const
|
|
49935
|
-
|
|
49936
|
-
|
|
49937
|
-
|
|
49938
|
-
if (cand && (m2 === null || cand.index < m2.index)) m2 = cand;
|
|
49939
|
-
}
|
|
49884
|
+
const l = LONE.exec(buf);
|
|
49885
|
+
let m2;
|
|
49886
|
+
if (p2 && l) m2 = p2.index <= l.index ? p2 : l;
|
|
49887
|
+
else m2 = p2 ?? l;
|
|
49940
49888
|
if (!m2) {
|
|
49941
49889
|
const t = PARTIAL_TAIL.exec(buf);
|
|
49942
|
-
if (t) {
|
|
49943
|
-
|
|
49944
|
-
|
|
49945
|
-
if (t[0].length <= cap) {
|
|
49946
|
-
held = t[0];
|
|
49947
|
-
out += buf.slice(0, buf.length - t[0].length);
|
|
49948
|
-
} else if (definite) {
|
|
49949
|
-
drop(t[0]);
|
|
49950
|
-
out += buf.slice(0, buf.length - t[0].length);
|
|
49951
|
-
} else {
|
|
49952
|
-
out += buf;
|
|
49953
|
-
}
|
|
49890
|
+
if (t && t[0].length <= HOLD_LIMIT) {
|
|
49891
|
+
held = t[0];
|
|
49892
|
+
out += buf.slice(0, buf.length - t[0].length);
|
|
49954
49893
|
} else {
|
|
49955
49894
|
out += buf;
|
|
49956
49895
|
}
|
|
@@ -49959,7 +49898,8 @@ function createTagEchoFilter(onDrop) {
|
|
|
49959
49898
|
drop(m2[0]);
|
|
49960
49899
|
out += buf.slice(0, m2.index);
|
|
49961
49900
|
buf = buf.slice(m2.index + m2[0].length);
|
|
49962
|
-
|
|
49901
|
+
const wasPaired = m2 === p2;
|
|
49902
|
+
if (!wasPaired && /^\x3cacp\s/.test(m2[0])) {
|
|
49963
49903
|
swallowUntilClose = true;
|
|
49964
49904
|
swallowed = "";
|
|
49965
49905
|
}
|
|
@@ -49973,19 +49913,14 @@ function createTagEchoFilter(onDrop) {
|
|
|
49973
49913
|
return process2(chunk);
|
|
49974
49914
|
},
|
|
49975
49915
|
flush() {
|
|
49976
|
-
|
|
49977
|
-
const wasSwallowing = swallowUntilClose;
|
|
49916
|
+
let rest = swallowed + held;
|
|
49978
49917
|
swallowed = "";
|
|
49979
49918
|
held = "";
|
|
49980
49919
|
swallowUntilClose = false;
|
|
49981
|
-
|
|
49982
|
-
if (rest.length > 0) drop(rest);
|
|
49983
|
-
return "";
|
|
49984
|
-
}
|
|
49985
|
-
const t = new RegExp(TRUNC_OPEN.source).exec(rest);
|
|
49920
|
+
const t = new RegExp(TRUNCATED_TAG.source).exec(rest);
|
|
49986
49921
|
if (t) {
|
|
49987
49922
|
drop(t[0]);
|
|
49988
|
-
|
|
49923
|
+
rest = rest.slice(0, t.index);
|
|
49989
49924
|
}
|
|
49990
49925
|
return rest;
|
|
49991
49926
|
},
|