2g 0.3.1 → 0.4.0
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 +12 -0
- package/dist/2g-api.js +5 -120
- package/dist/2g-api.js.map +1 -1
- package/dist/2g-api.mjs +1 -120
- package/dist/2g-api.mjs.map +1 -1
- package/dist/2g.js +42 -42
- package/dist/2g.js.map +1 -1
- package/dist/2g.mjs +115 -115
- package/dist/2g.mjs.map +1 -1
- package/dist/chunks/api-chunk.js +430 -0
- package/dist/chunks/api-chunk.js.map +1 -0
- package/dist/chunks/api-chunk.mjs +430 -0
- package/dist/chunks/api-chunk.mjs.map +1 -0
- package/dist/chunks/cli-chunk.js +160 -46
- package/dist/chunks/cli-chunk.js.map +1 -1
- package/dist/chunks/cli-chunk.mjs +214 -100
- package/dist/chunks/cli-chunk.mjs.map +1 -1
- package/dist/chunks/sessionSockets-chunk.js +4 -0
- package/dist/chunks/sessionSockets-chunk.js.map +1 -1
- package/dist/chunks/sessionSockets-chunk.mjs +9 -5
- package/dist/chunks/sessionSockets-chunk.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/tap-chunk.js +0 -287
- package/dist/chunks/tap-chunk.js.map +0 -1
- package/dist/chunks/tap-chunk.mjs +0 -287
- package/dist/chunks/tap-chunk.mjs.map +0 -1
package/dist/2g.mjs
CHANGED
|
@@ -2,44 +2,44 @@ import e from "node:path";
|
|
|
2
2
|
|
|
3
3
|
import { performance as t } from "node:perf_hooks";
|
|
4
4
|
|
|
5
|
-
import { E as i,
|
|
5
|
+
import { E as i, f as s, e as n, m as r, L as o, b as c, I as l, g as h, D as a, h as u, i as f, j as d, k as g, l as p, S as m, a as y, n as w, o as k, r as v, q as S } from "./chunks/sessionSockets-chunk.mjs";
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import b from "node:fs";
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import L from "node:net";
|
|
10
10
|
|
|
11
|
-
import { s as
|
|
11
|
+
import { s as _, f as P, a as E } from "./chunks/pretty-chunk.mjs";
|
|
12
12
|
|
|
13
|
-
import { Buffer as
|
|
13
|
+
import { Buffer as I } from "node:buffer";
|
|
14
14
|
|
|
15
|
-
import { EventEmitter as
|
|
15
|
+
import { EventEmitter as $ } from "node:events";
|
|
16
16
|
|
|
17
|
-
import { isMainThread as
|
|
17
|
+
import { isMainThread as O, threadId as D } from "node:worker_threads";
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const C = Symbol.for(`2g/state-${i}`);
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const x = function getEventLogState() {
|
|
22
22
|
const e = globalThis;
|
|
23
|
-
return e[
|
|
23
|
+
return e[C] ??= {
|
|
24
24
|
logPath: process.cwd(),
|
|
25
25
|
eventLoggerInfo: null,
|
|
26
26
|
debug: !1
|
|
27
27
|
};
|
|
28
28
|
}();
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const N = t.timeOrigin;
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const T = Array.from({
|
|
33
33
|
length: 1e3
|
|
34
34
|
}, (e, t) => `.${`${t}`.padStart(3, "0")}`);
|
|
35
35
|
|
|
36
|
-
let
|
|
36
|
+
let j = -1;
|
|
37
37
|
|
|
38
|
-
let
|
|
38
|
+
let F = "";
|
|
39
39
|
|
|
40
|
-
let
|
|
40
|
+
let M;
|
|
41
41
|
|
|
42
|
-
let
|
|
42
|
+
let R = "";
|
|
43
43
|
|
|
44
44
|
function writeEvent(e, t, i, s, n, r) {
|
|
45
45
|
try {
|
|
@@ -80,21 +80,21 @@ function writeCompleteEvent(e, t, i, s, n, r, o, c) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
function stringifyTimestamp() {
|
|
83
|
-
const e =
|
|
83
|
+
const e = N + t.now();
|
|
84
84
|
const i = Math.floor(e);
|
|
85
|
-
if (i !==
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
if (i !== j) {
|
|
86
|
+
j = i;
|
|
87
|
+
F = `${i}`;
|
|
88
88
|
}
|
|
89
|
-
return
|
|
89
|
+
return F + T[1e3 * (e - i) | 0];
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
function stringifyWorkerId(e) {
|
|
93
|
-
if (e !==
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
if (e !== M) {
|
|
94
|
+
M = e;
|
|
95
|
+
R = JSON.stringify(e);
|
|
96
96
|
}
|
|
97
|
-
return
|
|
97
|
+
return R;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
function appendPayload(e, t) {
|
|
@@ -134,27 +134,27 @@ function serializeError(e, t = 0) {
|
|
|
134
134
|
|
|
135
135
|
function createEventLogger(i, s) {
|
|
136
136
|
function log(e, t) {
|
|
137
|
-
if (
|
|
138
|
-
writeEvent(
|
|
137
|
+
if (x.primarySink && (!s || x.debug)) {
|
|
138
|
+
writeEvent(x.primarySink, i, e, t, x.eventMeta, s);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
log.span = function span() {
|
|
142
|
-
if (!
|
|
142
|
+
if (!x.primarySink || s && !x.debug) {
|
|
143
143
|
return NOOP_DONE;
|
|
144
144
|
}
|
|
145
145
|
const e = t.now();
|
|
146
146
|
return function done(n, r) {
|
|
147
|
-
if (!
|
|
147
|
+
if (!x.primarySink) {
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
|
-
writeCompleteEvent(
|
|
150
|
+
writeCompleteEvent(x.primarySink, i, n, r, void 0, t.now() - e, x.eventMeta, s);
|
|
151
151
|
};
|
|
152
152
|
};
|
|
153
153
|
log.path = function relativePath(t) {
|
|
154
154
|
return {
|
|
155
155
|
toJSON() {
|
|
156
156
|
try {
|
|
157
|
-
return null != t && e.isAbsolute(t) ? e.relative(
|
|
157
|
+
return null != t && e.isAbsolute(t) ? e.relative(x.logPath, t).replace(/\\/g, "/") || "." : t ?? null;
|
|
158
158
|
} catch {
|
|
159
159
|
return t || null;
|
|
160
160
|
}
|
|
@@ -189,7 +189,7 @@ function createDebugSink(e = process.env[o]) {
|
|
|
189
189
|
if (!t) {
|
|
190
190
|
return null;
|
|
191
191
|
}
|
|
192
|
-
const i =
|
|
192
|
+
const i = _(process.stderr);
|
|
193
193
|
return {
|
|
194
194
|
get writable() {
|
|
195
195
|
return !0;
|
|
@@ -211,7 +211,7 @@ function createDebugSink(e = process.env[o]) {
|
|
|
211
211
|
}, t)) {
|
|
212
212
|
continue;
|
|
213
213
|
}
|
|
214
|
-
process.stderr.write(`${
|
|
214
|
+
process.stderr.write(`${P(l, {
|
|
215
215
|
colorize: i,
|
|
216
216
|
stream: process.stderr
|
|
217
217
|
})}\n`);
|
|
@@ -226,7 +226,7 @@ function createDebugSink(e = process.env[o]) {
|
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
class LogStream extends
|
|
229
|
+
class LogStream extends $ {
|
|
230
230
|
#e=-1;
|
|
231
231
|
#t=null;
|
|
232
232
|
#i=null;
|
|
@@ -254,7 +254,7 @@ class LogStream extends E {
|
|
|
254
254
|
if (null != e) {
|
|
255
255
|
this.#L(e);
|
|
256
256
|
} else {
|
|
257
|
-
this.#S(null,
|
|
257
|
+
this.#S(null, I.byteLength(this.#u));
|
|
258
258
|
}
|
|
259
259
|
};
|
|
260
260
|
#_=() => {
|
|
@@ -268,7 +268,7 @@ class LogStream extends E {
|
|
|
268
268
|
this.#s = !1 !== t.closeFd;
|
|
269
269
|
if ("number" == typeof e) {
|
|
270
270
|
try {
|
|
271
|
-
|
|
271
|
+
b.fsyncSync(e);
|
|
272
272
|
} catch {}
|
|
273
273
|
this.#e = e;
|
|
274
274
|
process.nextTick(() => this.emit("ready"));
|
|
@@ -347,8 +347,8 @@ class LogStream extends E {
|
|
|
347
347
|
this.#f -= this.#u.length;
|
|
348
348
|
this.#u = "";
|
|
349
349
|
} else {
|
|
350
|
-
if (
|
|
351
|
-
const e =
|
|
350
|
+
if (I.byteLength(this.#u) > t) {
|
|
351
|
+
const e = I.from(this.#u).toString("utf8", t);
|
|
352
352
|
this.#f -= this.#u.length - e.length;
|
|
353
353
|
this.#u = e;
|
|
354
354
|
} else {
|
|
@@ -379,15 +379,15 @@ class LogStream extends E {
|
|
|
379
379
|
}
|
|
380
380
|
#E(t) {
|
|
381
381
|
this.#I(i => {
|
|
382
|
-
|
|
382
|
+
b.mkdir(e.dirname(t), {
|
|
383
383
|
recursive: !0
|
|
384
384
|
}, () => {
|
|
385
|
-
|
|
385
|
+
b.open(t, "a", 384, (e, t) => {
|
|
386
386
|
if (e || null == t) {
|
|
387
387
|
i(e);
|
|
388
388
|
return;
|
|
389
389
|
}
|
|
390
|
-
|
|
390
|
+
b.fchmod(t, 384, () => {
|
|
391
391
|
i(null, t);
|
|
392
392
|
});
|
|
393
393
|
});
|
|
@@ -411,7 +411,7 @@ class LogStream extends E {
|
|
|
411
411
|
this.#n = !1;
|
|
412
412
|
this.emit("ready");
|
|
413
413
|
if (null != n && n !== this.#e && !isStdFd(n)) {
|
|
414
|
-
fsFsync(n, () =>
|
|
414
|
+
fsFsync(n, () => b.close(n, () => {}));
|
|
415
415
|
}
|
|
416
416
|
if (this.#l) {
|
|
417
417
|
return;
|
|
@@ -450,7 +450,7 @@ class LogStream extends E {
|
|
|
450
450
|
}
|
|
451
451
|
fsFsync(this.#e, e => {
|
|
452
452
|
if (!e && this.#s && !isStdFd(this.#e)) {
|
|
453
|
-
|
|
453
|
+
b.close(this.#e, onClose);
|
|
454
454
|
} else {
|
|
455
455
|
onClose();
|
|
456
456
|
}
|
|
@@ -487,7 +487,7 @@ class LogStream extends E {
|
|
|
487
487
|
if (null != this.#k && (this.#y || this.#e < 0)) {
|
|
488
488
|
this.#k(this.#u, this.#b);
|
|
489
489
|
} else {
|
|
490
|
-
|
|
490
|
+
b.write(this.#e, this.#u, this.#v);
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
493
|
_end() {
|
|
@@ -617,7 +617,7 @@ class LogStream extends E {
|
|
|
617
617
|
write(e, t, i) {
|
|
618
618
|
const s = i || t;
|
|
619
619
|
const n = "string" == typeof t ? t : "utf8";
|
|
620
|
-
const r = "string" == typeof e ? e :
|
|
620
|
+
const r = "string" == typeof e ? e : I.from(e).toString(n);
|
|
621
621
|
const o = "function" == typeof s ? s : void 0;
|
|
622
622
|
try {
|
|
623
623
|
return this._write(r);
|
|
@@ -645,7 +645,7 @@ const isStdFd = e => {
|
|
|
645
645
|
|
|
646
646
|
const fsFsync = (e, t) => {
|
|
647
647
|
try {
|
|
648
|
-
|
|
648
|
+
b.fsync(e, t);
|
|
649
649
|
} catch (e) {
|
|
650
650
|
t(e);
|
|
651
651
|
}
|
|
@@ -809,7 +809,7 @@ function openIpc(e, t = {}) {
|
|
|
809
809
|
return (t, n) => {
|
|
810
810
|
const r = Date.now();
|
|
811
811
|
const attempt = () => {
|
|
812
|
-
const o =
|
|
812
|
+
const o = L.connect(e);
|
|
813
813
|
let c = !1;
|
|
814
814
|
o.once("connect", () => {
|
|
815
815
|
const e = o._handle?.fd;
|
|
@@ -847,25 +847,25 @@ function openIpc(e, t = {}) {
|
|
|
847
847
|
};
|
|
848
848
|
}
|
|
849
849
|
|
|
850
|
-
const
|
|
850
|
+
const U = Symbol.for("2g/process-origin");
|
|
851
851
|
|
|
852
852
|
function setLocalProcessOrigin(e) {
|
|
853
853
|
const t = globalThis;
|
|
854
854
|
if (e) {
|
|
855
|
-
t[
|
|
855
|
+
t[U] = e;
|
|
856
856
|
} else {
|
|
857
|
-
delete t[
|
|
857
|
+
delete t[U];
|
|
858
858
|
}
|
|
859
859
|
}
|
|
860
860
|
|
|
861
861
|
function getProcessOrigin() {
|
|
862
|
-
if (!
|
|
862
|
+
if (!O) {
|
|
863
863
|
return {
|
|
864
864
|
kind: "worker_thread",
|
|
865
|
-
id: String(
|
|
865
|
+
id: String(D)
|
|
866
866
|
};
|
|
867
867
|
}
|
|
868
|
-
const e = globalThis[
|
|
868
|
+
const e = globalThis[U];
|
|
869
869
|
const t = process.env[h];
|
|
870
870
|
if (t && t !== e) {
|
|
871
871
|
return {
|
|
@@ -882,11 +882,11 @@ function getProcessOrigin() {
|
|
|
882
882
|
return null;
|
|
883
883
|
}
|
|
884
884
|
|
|
885
|
-
const
|
|
885
|
+
const A = Symbol.for("2g/process-cleanup");
|
|
886
886
|
|
|
887
887
|
function getProcessCleanupState() {
|
|
888
888
|
const e = globalThis;
|
|
889
|
-
return e[
|
|
889
|
+
return e[A] ??= {
|
|
890
890
|
registered: !1,
|
|
891
891
|
callbacks: new Set
|
|
892
892
|
};
|
|
@@ -901,24 +901,24 @@ function runProcessCleanup() {
|
|
|
901
901
|
}
|
|
902
902
|
|
|
903
903
|
function createSession(t) {
|
|
904
|
-
const i =
|
|
904
|
+
const i = k();
|
|
905
905
|
const s = Date.now();
|
|
906
906
|
const n = `${process.pid}-${s.toString(36)}-${Math.random().toString(36).slice(2, 8).padEnd(6, "0")}`;
|
|
907
907
|
const r = e.join(i, n);
|
|
908
908
|
try {
|
|
909
|
-
|
|
909
|
+
b.mkdirSync(r, {
|
|
910
910
|
recursive: !0,
|
|
911
911
|
mode: 448
|
|
912
912
|
});
|
|
913
|
-
|
|
913
|
+
b.chmodSync(i, 448);
|
|
914
914
|
} catch {}
|
|
915
|
-
const o = t.maxSegments ?? a;
|
|
916
|
-
const c = t.maxSegmentSize ??
|
|
917
|
-
const
|
|
918
|
-
const
|
|
919
|
-
const
|
|
920
|
-
const
|
|
921
|
-
|
|
915
|
+
const o = t.maxSegments ?? (x.debug ? a : u);
|
|
916
|
+
const c = t.maxSegmentSize ?? (x.debug ? f : d);
|
|
917
|
+
const S = g(r, n, "live");
|
|
918
|
+
const _ = g(r, n, "ipc");
|
|
919
|
+
const P = new LogStream(e.join(r, "0.jsonl"));
|
|
920
|
+
const E = new BroadcastChannel(P);
|
|
921
|
+
E.add(createDebugSink());
|
|
922
922
|
!function trackSegmentRotation(t, i, s, n) {
|
|
923
923
|
let r = 0;
|
|
924
924
|
t.on("write", o => {
|
|
@@ -928,33 +928,33 @@ function createSession(t) {
|
|
|
928
928
|
}
|
|
929
929
|
r = 0;
|
|
930
930
|
!function rotateSegments(t, i) {
|
|
931
|
-
|
|
931
|
+
b.rmSync(e.join(t, i - 1 + ".jsonl"), {
|
|
932
932
|
force: !0
|
|
933
933
|
});
|
|
934
934
|
for (let s = i - 1; s >= 1; s--) {
|
|
935
935
|
const i = e.join(t, s - 1 + ".jsonl");
|
|
936
936
|
const n = e.join(t, `${s}.jsonl`);
|
|
937
937
|
try {
|
|
938
|
-
|
|
938
|
+
b.renameSync(i, n);
|
|
939
939
|
} catch {}
|
|
940
940
|
}
|
|
941
941
|
}(i, s);
|
|
942
942
|
t.reopen();
|
|
943
943
|
});
|
|
944
|
-
}(
|
|
945
|
-
const
|
|
946
|
-
const
|
|
947
|
-
const
|
|
948
|
-
const
|
|
949
|
-
const
|
|
944
|
+
}(P, r, o, c);
|
|
945
|
+
const I = L.createServer(e => E.attach(e));
|
|
946
|
+
const $ = L.createServer(e => E.ingest(e));
|
|
947
|
+
const O = p(I, S.path);
|
|
948
|
+
const D = p($, _.path);
|
|
949
|
+
const C = function publishIpcPath(e) {
|
|
950
950
|
process.env[l] = e;
|
|
951
951
|
return () => {
|
|
952
952
|
if (process.env[l] === e) {
|
|
953
953
|
delete process.env[l];
|
|
954
954
|
}
|
|
955
955
|
};
|
|
956
|
-
}(
|
|
957
|
-
const
|
|
956
|
+
}(_.path);
|
|
957
|
+
const N = function publishProcessOrigin() {
|
|
958
958
|
const e = String(process.pid);
|
|
959
959
|
process.env[h] = e;
|
|
960
960
|
setLocalProcessOrigin(e);
|
|
@@ -965,40 +965,40 @@ function createSession(t) {
|
|
|
965
965
|
setLocalProcessOrigin(void 0);
|
|
966
966
|
};
|
|
967
967
|
}();
|
|
968
|
-
const
|
|
968
|
+
const T = {
|
|
969
969
|
pid: process.pid,
|
|
970
|
-
formatVersion:
|
|
970
|
+
formatVersion: w,
|
|
971
971
|
startedAt: s,
|
|
972
972
|
command: t.command ?? process.argv.slice(1).join(" "),
|
|
973
973
|
cwd: process.cwd(),
|
|
974
974
|
maxSegments: o,
|
|
975
975
|
version: t.version,
|
|
976
|
-
socket:
|
|
977
|
-
ipcSocket:
|
|
976
|
+
socket: S.name,
|
|
977
|
+
ipcSocket: _.name,
|
|
978
978
|
origin: createSessionOrigin()
|
|
979
979
|
};
|
|
980
980
|
try {
|
|
981
981
|
!function writeJsonAtomic(e, t) {
|
|
982
982
|
const i = `${e}.${process.pid}.tmp`;
|
|
983
|
-
|
|
983
|
+
b.writeFileSync(i, JSON.stringify(t, null, 2), {
|
|
984
984
|
mode: 384
|
|
985
985
|
});
|
|
986
|
-
|
|
987
|
-
}(e.join(r,
|
|
986
|
+
b.renameSync(i, e);
|
|
987
|
+
}(e.join(r, m.meta), T);
|
|
988
988
|
} catch {}
|
|
989
|
-
let
|
|
989
|
+
let j = !1;
|
|
990
990
|
const destroy = () => {
|
|
991
|
-
if (
|
|
991
|
+
if (j) {
|
|
992
992
|
return;
|
|
993
993
|
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
I();
|
|
997
|
-
$();
|
|
994
|
+
j = !0;
|
|
995
|
+
E.destroy();
|
|
998
996
|
O();
|
|
999
997
|
D();
|
|
1000
|
-
|
|
1001
|
-
|
|
998
|
+
C();
|
|
999
|
+
N();
|
|
1000
|
+
v(S.path);
|
|
1001
|
+
v(_.path);
|
|
1002
1002
|
};
|
|
1003
1003
|
!function registerProcessCleanup(e) {
|
|
1004
1004
|
const t = getProcessCleanupState();
|
|
@@ -1020,13 +1020,13 @@ function createSession(t) {
|
|
|
1020
1020
|
}(destroy);
|
|
1021
1021
|
setImmediate(() => {
|
|
1022
1022
|
try {
|
|
1023
|
-
|
|
1023
|
+
y();
|
|
1024
1024
|
} catch {}
|
|
1025
1025
|
});
|
|
1026
1026
|
return {
|
|
1027
1027
|
sessionDir: r,
|
|
1028
|
-
meta:
|
|
1029
|
-
sink:
|
|
1028
|
+
meta: T,
|
|
1029
|
+
sink: E,
|
|
1030
1030
|
destroy
|
|
1031
1031
|
};
|
|
1032
1032
|
}
|
|
@@ -1046,10 +1046,10 @@ function createSessionOrigin() {
|
|
|
1046
1046
|
};
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
|
-
const
|
|
1049
|
+
const B = events("root");
|
|
1050
1050
|
|
|
1051
1051
|
function installChildEventLogger(e) {
|
|
1052
|
-
if (
|
|
1052
|
+
if (x.primarySink) {
|
|
1053
1053
|
return !0;
|
|
1054
1054
|
}
|
|
1055
1055
|
const t = function getProcessWorkerId() {
|
|
@@ -1057,7 +1057,7 @@ function installChildEventLogger(e) {
|
|
|
1057
1057
|
return e ? `${e.kind}:${e.id}` : void 0;
|
|
1058
1058
|
}();
|
|
1059
1059
|
if (t) {
|
|
1060
|
-
|
|
1060
|
+
x.eventMeta = {
|
|
1061
1061
|
_w: t
|
|
1062
1062
|
};
|
|
1063
1063
|
}
|
|
@@ -1065,16 +1065,16 @@ function installChildEventLogger(e) {
|
|
|
1065
1065
|
return process.env[l];
|
|
1066
1066
|
}();
|
|
1067
1067
|
if (i) {
|
|
1068
|
-
|
|
1068
|
+
x.debug = e?.debug ?? !!process.env[o];
|
|
1069
1069
|
!function connectToParent(e) {
|
|
1070
|
-
|
|
1070
|
+
x.primarySink = createPrimarySink(openIpc(e), {
|
|
1071
1071
|
closeFd: !1
|
|
1072
1072
|
});
|
|
1073
|
-
|
|
1073
|
+
x.eventLoggerInfo = {
|
|
1074
1074
|
destination: "ipc",
|
|
1075
1075
|
isUserVisibleOutput: !1
|
|
1076
1076
|
};
|
|
1077
|
-
|
|
1077
|
+
B("init", getInitMetadata());
|
|
1078
1078
|
}(i);
|
|
1079
1079
|
return !0;
|
|
1080
1080
|
} else {
|
|
@@ -1087,13 +1087,13 @@ function installEventLogger(e) {
|
|
|
1087
1087
|
if (installChildEventLogger(t)) {
|
|
1088
1088
|
return;
|
|
1089
1089
|
}
|
|
1090
|
-
const i = parseLogTarget(process.env[
|
|
1090
|
+
const i = parseLogTarget(process.env[S]) ?? parseLogTarget("string" == typeof e || "number" == typeof e ? e : void 0);
|
|
1091
1091
|
if (null != i) {
|
|
1092
1092
|
if ("number" == typeof i) {
|
|
1093
|
-
|
|
1093
|
+
E(i);
|
|
1094
1094
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1095
|
+
x.debug = t?.debug ?? !0;
|
|
1096
|
+
x.eventLoggerInfo = function getExplicitTargetInfo(e) {
|
|
1097
1097
|
if ("number" == typeof e) {
|
|
1098
1098
|
return {
|
|
1099
1099
|
destination: 1 === e ? "stdout" : 2 === e ? "stderr" : "fd",
|
|
@@ -1111,10 +1111,10 @@ function installEventLogger(e) {
|
|
|
1111
1111
|
return;
|
|
1112
1112
|
}
|
|
1113
1113
|
if (t && !1 !== t.session) {
|
|
1114
|
-
|
|
1114
|
+
x.debug = t.debug ?? !!process.env[o];
|
|
1115
1115
|
const e = createSession(t);
|
|
1116
|
-
|
|
1117
|
-
|
|
1116
|
+
x.logPath = e.sessionDir;
|
|
1117
|
+
x.eventLoggerInfo = {
|
|
1118
1118
|
destination: "session",
|
|
1119
1119
|
isUserVisibleOutput: !1,
|
|
1120
1120
|
sessionDir: e.sessionDir
|
|
@@ -1124,11 +1124,11 @@ function installEventLogger(e) {
|
|
|
1124
1124
|
}
|
|
1125
1125
|
}
|
|
1126
1126
|
|
|
1127
|
-
const getEventLoggerInfo = () =>
|
|
1127
|
+
const getEventLoggerInfo = () => x.primarySink?.writable ? x.eventLoggerInfo : null;
|
|
1128
1128
|
|
|
1129
1129
|
function flushEventLogger() {
|
|
1130
1130
|
return new Promise(e => {
|
|
1131
|
-
const t =
|
|
1131
|
+
const t = x.primarySink;
|
|
1132
1132
|
if (t?.flush) {
|
|
1133
1133
|
t.flush(() => e());
|
|
1134
1134
|
} else {
|
|
@@ -1151,7 +1151,7 @@ function parseLogTarget(t) {
|
|
|
1151
1151
|
try {
|
|
1152
1152
|
const i = e.parse(t);
|
|
1153
1153
|
const s = e.format(i);
|
|
1154
|
-
|
|
1154
|
+
x.logPath = i.dir || process.cwd();
|
|
1155
1155
|
return s;
|
|
1156
1156
|
} catch {
|
|
1157
1157
|
return;
|
|
@@ -1161,8 +1161,8 @@ function parseLogTarget(t) {
|
|
|
1161
1161
|
function createPrimarySink(e, t) {
|
|
1162
1162
|
const i = new LogStream(e, t);
|
|
1163
1163
|
i.once("error", () => {
|
|
1164
|
-
|
|
1165
|
-
|
|
1164
|
+
x.primarySink = void 0;
|
|
1165
|
+
x.eventLoggerInfo = null;
|
|
1166
1166
|
});
|
|
1167
1167
|
return i;
|
|
1168
1168
|
}
|
|
@@ -1170,15 +1170,15 @@ function createPrimarySink(e, t) {
|
|
|
1170
1170
|
function getInitMetadata(e) {
|
|
1171
1171
|
return {
|
|
1172
1172
|
format: "v0-jsonl",
|
|
1173
|
-
formatVersion:
|
|
1173
|
+
formatVersion: w,
|
|
1174
1174
|
version: e ?? "UNVERSIONED",
|
|
1175
1175
|
processOrigin: getProcessOrigin() ?? void 0
|
|
1176
1176
|
};
|
|
1177
1177
|
}
|
|
1178
1178
|
|
|
1179
1179
|
function activateSink(e, t) {
|
|
1180
|
-
|
|
1181
|
-
|
|
1180
|
+
x.primarySink = e;
|
|
1181
|
+
B("init", getInitMetadata(t));
|
|
1182
1182
|
}
|
|
1183
1183
|
|
|
1184
1184
|
installChildEventLogger();
|