2g 0.2.0 → 0.3.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 +14 -0
- package/README.md +4 -4
- package/dist/2g.js +6 -9
- package/dist/2g.js.map +1 -1
- package/dist/2g.mjs +62 -65
- package/dist/2g.mjs.map +1 -1
- package/dist/chunks/cli-chunk.js +3 -3
- package/dist/chunks/cli-chunk.js.map +1 -1
- package/dist/chunks/cli-chunk.mjs +42 -42
- package/dist/chunks/cli-chunk.mjs.map +1 -1
- package/dist/chunks/types-chunk.d.ts +1 -4
- package/package.json +1 -1
package/dist/2g.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import e from "node:path";
|
|
|
2
2
|
|
|
3
3
|
import { performance as t } from "node:perf_hooks";
|
|
4
4
|
|
|
5
|
-
import { E as i, h as s, p as n, m as r, j as o, c, I as l, k as h, D as a, l as u, o as f, q as d, S as p, b as g, s as
|
|
5
|
+
import { E as i, h as s, p as n, m as r, j as o, c, I as l, k as h, D as a, l as u, o as f, q as d, S as p, b as g, s as m, g as y, t as w, L as k } from "./chunks/sessionSockets-chunk.mjs";
|
|
6
6
|
|
|
7
7
|
import S from "node:fs";
|
|
8
8
|
|
|
@@ -27,15 +27,15 @@ const D = function getEventLogState() {
|
|
|
27
27
|
};
|
|
28
28
|
}();
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const x = t.timeOrigin;
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const N = Array.from({
|
|
33
33
|
length: 1e3
|
|
34
34
|
}, (e, t) => `.${`${t}`.padStart(3, "0")}`);
|
|
35
35
|
|
|
36
|
-
let
|
|
36
|
+
let T = -1;
|
|
37
37
|
|
|
38
|
-
let
|
|
38
|
+
let j = "";
|
|
39
39
|
|
|
40
40
|
let F;
|
|
41
41
|
|
|
@@ -74,22 +74,19 @@ function writeCompleteEvent(e, t, i, s, n, r, o, c) {
|
|
|
74
74
|
if (!t) {
|
|
75
75
|
return appendPayload(e, i);
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
return appendPayload(e, t);
|
|
79
|
-
}
|
|
80
|
-
return appendPayload(e, Object.assign(t, i));
|
|
77
|
+
return appendPayload(e, t);
|
|
81
78
|
}(l, s, n)}}\n`);
|
|
82
79
|
} catch {}
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
function stringifyTimestamp() {
|
|
86
|
-
const e =
|
|
83
|
+
const e = x + t.now();
|
|
87
84
|
const i = Math.floor(e);
|
|
88
|
-
if (i !==
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
if (i !== T) {
|
|
86
|
+
T = i;
|
|
87
|
+
j = `${i}`;
|
|
91
88
|
}
|
|
92
|
-
return
|
|
89
|
+
return j + N[1e3 * (e - i) | 0];
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
function stringifyWorkerId(e) {
|
|
@@ -141,16 +138,16 @@ function createEventLogger(i, s) {
|
|
|
141
138
|
writeEvent(D.primarySink, i, e, t, D.eventMeta, s);
|
|
142
139
|
}
|
|
143
140
|
}
|
|
144
|
-
log.span = function span(
|
|
141
|
+
log.span = function span() {
|
|
145
142
|
if (!D.primarySink || s && !D.debug) {
|
|
146
143
|
return NOOP_DONE;
|
|
147
144
|
}
|
|
148
|
-
const
|
|
149
|
-
return function done(
|
|
145
|
+
const e = t.now();
|
|
146
|
+
return function done(n, r) {
|
|
150
147
|
if (!D.primarySink) {
|
|
151
148
|
return;
|
|
152
149
|
}
|
|
153
|
-
writeCompleteEvent(D.primarySink, i,
|
|
150
|
+
writeCompleteEvent(D.primarySink, i, n, r, void 0, t.now() - e, D.eventMeta, s);
|
|
154
151
|
};
|
|
155
152
|
};
|
|
156
153
|
log.path = function relativePath(t) {
|
|
@@ -246,8 +243,8 @@ class LogStream extends I {
|
|
|
246
243
|
#d=[];
|
|
247
244
|
#p=0;
|
|
248
245
|
#g=0;
|
|
249
|
-
#
|
|
250
|
-
#
|
|
246
|
+
#m=0;
|
|
247
|
+
#y=!1;
|
|
251
248
|
#w=!1;
|
|
252
249
|
#k;
|
|
253
250
|
#S=(e, t) => {
|
|
@@ -325,14 +322,14 @@ class LogStream extends I {
|
|
|
325
322
|
}
|
|
326
323
|
#O(e) {
|
|
327
324
|
if ("EAGAIN" === e.code && null != this.#k) {
|
|
328
|
-
this.#
|
|
325
|
+
this.#y = !0;
|
|
329
326
|
this.#k(this.#u, this.#b);
|
|
330
|
-
} else if (0 === this.#
|
|
331
|
-
this.#
|
|
327
|
+
} else if (0 === this.#m) {
|
|
328
|
+
this.#m = 1;
|
|
332
329
|
setImmediate(() => this.#P());
|
|
333
330
|
} else {
|
|
334
|
-
this.#
|
|
335
|
-
setTimeout(() => this.#P(), this.#
|
|
331
|
+
this.#m = Math.min(2 * this.#m, 100);
|
|
332
|
+
setTimeout(() => this.#P(), this.#m);
|
|
336
333
|
}
|
|
337
334
|
}
|
|
338
335
|
#v(e, t) {
|
|
@@ -344,7 +341,7 @@ class LogStream extends I {
|
|
|
344
341
|
}
|
|
345
342
|
return;
|
|
346
343
|
}
|
|
347
|
-
this.#
|
|
344
|
+
this.#m = 0;
|
|
348
345
|
this.emit("write", t);
|
|
349
346
|
if (t === this.#u.length) {
|
|
350
347
|
this.#f -= this.#u.length;
|
|
@@ -374,7 +371,7 @@ class LogStream extends I {
|
|
|
374
371
|
this.#D();
|
|
375
372
|
} else {
|
|
376
373
|
this.#n = !1;
|
|
377
|
-
this.#
|
|
374
|
+
this.#y = !1;
|
|
378
375
|
if (this.#c) {
|
|
379
376
|
this.emit("drain");
|
|
380
377
|
}
|
|
@@ -466,7 +463,7 @@ class LogStream extends I {
|
|
|
466
463
|
}
|
|
467
464
|
this.#D();
|
|
468
465
|
}
|
|
469
|
-
#
|
|
466
|
+
#x() {
|
|
470
467
|
if (!this.#w) {
|
|
471
468
|
this.#w = !0;
|
|
472
469
|
setImmediate(this.#_);
|
|
@@ -487,7 +484,7 @@ class LogStream extends I {
|
|
|
487
484
|
}
|
|
488
485
|
}
|
|
489
486
|
}
|
|
490
|
-
if (null != this.#k && (this.#
|
|
487
|
+
if (null != this.#k && (this.#y || this.#e < 0)) {
|
|
491
488
|
this.#k(this.#u, this.#b);
|
|
492
489
|
} else {
|
|
493
490
|
S.write(this.#e, this.#u, this.#S);
|
|
@@ -579,7 +576,7 @@ class LogStream extends I {
|
|
|
579
576
|
this.#f += e.length;
|
|
580
577
|
this.#d.push(e);
|
|
581
578
|
if (!this.#n) {
|
|
582
|
-
this.#
|
|
579
|
+
this.#x();
|
|
583
580
|
}
|
|
584
581
|
return this.#f < 16384;
|
|
585
582
|
}
|
|
@@ -613,7 +610,7 @@ class LogStream extends I {
|
|
|
613
610
|
this.#g = 1;
|
|
614
611
|
}
|
|
615
612
|
if (!this.#n && this.#d.length - this.#p > this.#g) {
|
|
616
|
-
this.#
|
|
613
|
+
this.#x();
|
|
617
614
|
}
|
|
618
615
|
return this.#f < 16384;
|
|
619
616
|
}
|
|
@@ -655,36 +652,36 @@ const fsFsync = (e, t) => {
|
|
|
655
652
|
};
|
|
656
653
|
|
|
657
654
|
class SocketSink {
|
|
658
|
-
#
|
|
655
|
+
#N;
|
|
659
656
|
constructor(e) {
|
|
660
|
-
this.#
|
|
657
|
+
this.#N = e;
|
|
661
658
|
e.on("error", () => {});
|
|
662
659
|
}
|
|
663
660
|
get writable() {
|
|
664
|
-
return this.#
|
|
661
|
+
return this.#N.writable;
|
|
665
662
|
}
|
|
666
663
|
get buffered() {
|
|
667
|
-
return this.#
|
|
664
|
+
return this.#N.writableLength;
|
|
668
665
|
}
|
|
669
666
|
_writeln(e) {
|
|
670
|
-
return this.#
|
|
667
|
+
return this.#N.write(e);
|
|
671
668
|
}
|
|
672
669
|
end(e) {
|
|
673
|
-
this.#
|
|
670
|
+
this.#N.end(e);
|
|
674
671
|
return this;
|
|
675
672
|
}
|
|
676
673
|
destroy() {
|
|
677
|
-
this.#
|
|
674
|
+
this.#N.destroy();
|
|
678
675
|
}
|
|
679
676
|
}
|
|
680
677
|
|
|
681
678
|
class BroadcastChannel {
|
|
682
|
-
#
|
|
683
|
-
#
|
|
679
|
+
#T;
|
|
680
|
+
#j=[];
|
|
684
681
|
#l=!1;
|
|
685
682
|
constructor(e) {
|
|
686
|
-
this.#
|
|
687
|
-
this.#
|
|
683
|
+
this.#T = e;
|
|
684
|
+
this.#j.push({
|
|
688
685
|
sink: e,
|
|
689
686
|
dropOnBackpressure: !1,
|
|
690
687
|
destroy: () => e.destroy()
|
|
@@ -694,8 +691,8 @@ class BroadcastChannel {
|
|
|
694
691
|
if (this.#l) {
|
|
695
692
|
return !1;
|
|
696
693
|
}
|
|
697
|
-
for (let e = 0; e < this.#
|
|
698
|
-
if (this.#
|
|
694
|
+
for (let e = 0; e < this.#j.length; e++) {
|
|
695
|
+
if (this.#j[e].sink.writable) {
|
|
699
696
|
return !0;
|
|
700
697
|
}
|
|
701
698
|
}
|
|
@@ -708,7 +705,7 @@ class BroadcastChannel {
|
|
|
708
705
|
if (this.#l) {
|
|
709
706
|
e.destroy();
|
|
710
707
|
} else {
|
|
711
|
-
this.#
|
|
708
|
+
this.#j.push({
|
|
712
709
|
sink: e,
|
|
713
710
|
dropOnBackpressure: !1,
|
|
714
711
|
destroy: () => e.destroy()
|
|
@@ -740,11 +737,11 @@ class BroadcastChannel {
|
|
|
740
737
|
e.destroy();
|
|
741
738
|
}
|
|
742
739
|
};
|
|
743
|
-
this.#
|
|
740
|
+
this.#j.push(i);
|
|
744
741
|
const detach = () => {
|
|
745
|
-
const e = this.#
|
|
742
|
+
const e = this.#j.indexOf(i);
|
|
746
743
|
if (e > -1) {
|
|
747
|
-
this.#
|
|
744
|
+
this.#j.splice(e, 1);
|
|
748
745
|
}
|
|
749
746
|
i.destroy();
|
|
750
747
|
};
|
|
@@ -771,7 +768,7 @@ class BroadcastChannel {
|
|
|
771
768
|
e.on("error", () => {});
|
|
772
769
|
}
|
|
773
770
|
_writeln(e) {
|
|
774
|
-
const t = this.#
|
|
771
|
+
const t = this.#j;
|
|
775
772
|
let i = !1;
|
|
776
773
|
for (let s = t.length - 1; s >= 0; s--) {
|
|
777
774
|
const n = t[s];
|
|
@@ -785,24 +782,24 @@ class BroadcastChannel {
|
|
|
785
782
|
return i;
|
|
786
783
|
}
|
|
787
784
|
flush(e) {
|
|
788
|
-
if (this.#
|
|
789
|
-
this.#
|
|
785
|
+
if (this.#T.flush) {
|
|
786
|
+
this.#T.flush(e);
|
|
790
787
|
} else {
|
|
791
788
|
e();
|
|
792
789
|
}
|
|
793
790
|
}
|
|
794
791
|
end(e) {
|
|
795
|
-
for (const t of this.#
|
|
796
|
-
t.sink.end(t.sink === this.#
|
|
792
|
+
for (const t of this.#j) {
|
|
793
|
+
t.sink.end(t.sink === this.#T ? e : void 0);
|
|
797
794
|
}
|
|
798
795
|
return this;
|
|
799
796
|
}
|
|
800
797
|
destroy() {
|
|
801
798
|
this.#l = !0;
|
|
802
|
-
for (const e of this.#
|
|
799
|
+
for (const e of this.#j) {
|
|
803
800
|
e.destroy();
|
|
804
801
|
}
|
|
805
|
-
this.#
|
|
802
|
+
this.#j.length = 0;
|
|
806
803
|
}
|
|
807
804
|
}
|
|
808
805
|
|
|
@@ -873,7 +870,7 @@ function getProcessOrigin() {
|
|
|
873
870
|
if (t && t !== e) {
|
|
874
871
|
return {
|
|
875
872
|
kind: "event_log_child",
|
|
876
|
-
id:
|
|
873
|
+
id: String(process.pid)
|
|
877
874
|
};
|
|
878
875
|
}
|
|
879
876
|
if (process.env.NODE_UNIQUE_ID) {
|
|
@@ -904,7 +901,7 @@ function runProcessCleanup() {
|
|
|
904
901
|
}
|
|
905
902
|
|
|
906
903
|
function createSession(t) {
|
|
907
|
-
const i =
|
|
904
|
+
const i = y();
|
|
908
905
|
const s = Date.now();
|
|
909
906
|
const n = `${process.pid}-${s.toString(36)}-${Math.random().toString(36).slice(2, 8).padEnd(6, "0")}`;
|
|
910
907
|
const r = e.join(i, n);
|
|
@@ -968,9 +965,9 @@ function createSession(t) {
|
|
|
968
965
|
setLocalProcessOrigin(void 0);
|
|
969
966
|
};
|
|
970
967
|
}();
|
|
971
|
-
const
|
|
968
|
+
const x = {
|
|
972
969
|
pid: process.pid,
|
|
973
|
-
formatVersion:
|
|
970
|
+
formatVersion: m,
|
|
974
971
|
startedAt: s,
|
|
975
972
|
command: t.command ?? process.argv.slice(1).join(" "),
|
|
976
973
|
cwd: process.cwd(),
|
|
@@ -987,14 +984,14 @@ function createSession(t) {
|
|
|
987
984
|
mode: 384
|
|
988
985
|
});
|
|
989
986
|
S.renameSync(i, e);
|
|
990
|
-
}(e.join(r, p.meta),
|
|
987
|
+
}(e.join(r, p.meta), x);
|
|
991
988
|
} catch {}
|
|
992
|
-
let
|
|
989
|
+
let N = !1;
|
|
993
990
|
const destroy = () => {
|
|
994
|
-
if (
|
|
991
|
+
if (N) {
|
|
995
992
|
return;
|
|
996
993
|
}
|
|
997
|
-
|
|
994
|
+
N = !0;
|
|
998
995
|
_.destroy();
|
|
999
996
|
$();
|
|
1000
997
|
E();
|
|
@@ -1028,7 +1025,7 @@ function createSession(t) {
|
|
|
1028
1025
|
});
|
|
1029
1026
|
return {
|
|
1030
1027
|
sessionDir: r,
|
|
1031
|
-
meta:
|
|
1028
|
+
meta: x,
|
|
1032
1029
|
sink: _,
|
|
1033
1030
|
destroy
|
|
1034
1031
|
};
|
|
@@ -1165,7 +1162,7 @@ function createPrimarySink(e, t) {
|
|
|
1165
1162
|
function getInitMetadata(e) {
|
|
1166
1163
|
return {
|
|
1167
1164
|
format: "v0-jsonl",
|
|
1168
|
-
formatVersion:
|
|
1165
|
+
formatVersion: m,
|
|
1169
1166
|
version: e ?? "UNVERSIONED",
|
|
1170
1167
|
processOrigin: getProcessOrigin() ?? void 0
|
|
1171
1168
|
};
|