@posthog/agent 2.0.2 → 2.1.2
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/{agent-DBQY1BfC.d.ts → agent-kRbaLUfe.d.ts} +3 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +63 -5
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +75 -5
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +63 -5
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/{bin.js → bin.cjs} +286 -244
- package/dist/server/bin.cjs.map +1 -0
- package/package.json +4 -4
- package/src/adapters/claude/claude-agent.ts +12 -2
- package/src/adapters/claude/types.ts +1 -0
- package/src/sagas/resume-saga.test.ts +144 -0
- package/src/sagas/resume-saga.ts +23 -0
- package/src/sagas/test-fixtures.ts +9 -0
- package/src/session-log-writer.ts +81 -1
- package/dist/server/bin.d.ts +0 -1
- package/dist/server/bin.js.map +0 -1
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
-
});
|
|
14
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
15
10
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
11
|
};
|
|
17
12
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -33,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
28
|
|
|
34
29
|
// ../../node_modules/ms/index.js
|
|
35
30
|
var require_ms = __commonJS({
|
|
36
|
-
"../../node_modules/ms/index.js"(
|
|
31
|
+
"../../node_modules/ms/index.js"(exports2, module2) {
|
|
37
32
|
"use strict";
|
|
38
33
|
var s = 1e3;
|
|
39
34
|
var m = s * 60;
|
|
@@ -41,7 +36,7 @@ var require_ms = __commonJS({
|
|
|
41
36
|
var d = h * 24;
|
|
42
37
|
var w = d * 7;
|
|
43
38
|
var y = d * 365.25;
|
|
44
|
-
|
|
39
|
+
module2.exports = function(val, options) {
|
|
45
40
|
options = options || {};
|
|
46
41
|
var type = typeof val;
|
|
47
42
|
if (type === "string" && val.length > 0) {
|
|
@@ -150,7 +145,7 @@ var require_ms = __commonJS({
|
|
|
150
145
|
|
|
151
146
|
// ../../node_modules/debug/src/common.js
|
|
152
147
|
var require_common = __commonJS({
|
|
153
|
-
"../../node_modules/debug/src/common.js"(
|
|
148
|
+
"../../node_modules/debug/src/common.js"(exports2, module2) {
|
|
154
149
|
"use strict";
|
|
155
150
|
function setup(env) {
|
|
156
151
|
createDebug.debug = createDebug;
|
|
@@ -322,20 +317,20 @@ var require_common = __commonJS({
|
|
|
322
317
|
createDebug.enable(createDebug.load());
|
|
323
318
|
return createDebug;
|
|
324
319
|
}
|
|
325
|
-
|
|
320
|
+
module2.exports = setup;
|
|
326
321
|
}
|
|
327
322
|
});
|
|
328
323
|
|
|
329
324
|
// ../../node_modules/debug/src/browser.js
|
|
330
325
|
var require_browser = __commonJS({
|
|
331
|
-
"../../node_modules/debug/src/browser.js"(
|
|
326
|
+
"../../node_modules/debug/src/browser.js"(exports2, module2) {
|
|
332
327
|
"use strict";
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
328
|
+
exports2.formatArgs = formatArgs;
|
|
329
|
+
exports2.save = save;
|
|
330
|
+
exports2.load = load;
|
|
331
|
+
exports2.useColors = useColors;
|
|
332
|
+
exports2.storage = localstorage();
|
|
333
|
+
exports2.destroy = /* @__PURE__ */ (() => {
|
|
339
334
|
let warned = false;
|
|
340
335
|
return () => {
|
|
341
336
|
if (!warned) {
|
|
@@ -344,7 +339,7 @@ var require_browser = __commonJS({
|
|
|
344
339
|
}
|
|
345
340
|
};
|
|
346
341
|
})();
|
|
347
|
-
|
|
342
|
+
exports2.colors = [
|
|
348
343
|
"#0000CC",
|
|
349
344
|
"#0000FF",
|
|
350
345
|
"#0033CC",
|
|
@@ -437,7 +432,7 @@ var require_browser = __commonJS({
|
|
|
437
432
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
438
433
|
}
|
|
439
434
|
function formatArgs(args) {
|
|
440
|
-
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" +
|
|
435
|
+
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
|
|
441
436
|
if (!this.useColors) {
|
|
442
437
|
return;
|
|
443
438
|
}
|
|
@@ -456,14 +451,14 @@ var require_browser = __commonJS({
|
|
|
456
451
|
});
|
|
457
452
|
args.splice(lastC, 0, c);
|
|
458
453
|
}
|
|
459
|
-
|
|
454
|
+
exports2.log = console.debug || console.log || (() => {
|
|
460
455
|
});
|
|
461
456
|
function save(namespaces) {
|
|
462
457
|
try {
|
|
463
458
|
if (namespaces) {
|
|
464
|
-
|
|
459
|
+
exports2.storage.setItem("debug", namespaces);
|
|
465
460
|
} else {
|
|
466
|
-
|
|
461
|
+
exports2.storage.removeItem("debug");
|
|
467
462
|
}
|
|
468
463
|
} catch (error) {
|
|
469
464
|
}
|
|
@@ -471,7 +466,7 @@ var require_browser = __commonJS({
|
|
|
471
466
|
function load() {
|
|
472
467
|
let r;
|
|
473
468
|
try {
|
|
474
|
-
r =
|
|
469
|
+
r = exports2.storage.getItem("debug") || exports2.storage.getItem("DEBUG");
|
|
475
470
|
} catch (error) {
|
|
476
471
|
}
|
|
477
472
|
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
@@ -485,8 +480,8 @@ var require_browser = __commonJS({
|
|
|
485
480
|
} catch (error) {
|
|
486
481
|
}
|
|
487
482
|
}
|
|
488
|
-
|
|
489
|
-
var { formatters } =
|
|
483
|
+
module2.exports = require_common()(exports2);
|
|
484
|
+
var { formatters } = module2.exports;
|
|
490
485
|
formatters.j = function(v) {
|
|
491
486
|
try {
|
|
492
487
|
return JSON.stringify(v);
|
|
@@ -499,9 +494,9 @@ var require_browser = __commonJS({
|
|
|
499
494
|
|
|
500
495
|
// ../../node_modules/has-flag/index.js
|
|
501
496
|
var require_has_flag = __commonJS({
|
|
502
|
-
"../../node_modules/has-flag/index.js"(
|
|
497
|
+
"../../node_modules/has-flag/index.js"(exports2, module2) {
|
|
503
498
|
"use strict";
|
|
504
|
-
|
|
499
|
+
module2.exports = (flag, argv = process.argv) => {
|
|
505
500
|
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
506
501
|
const position = argv.indexOf(prefix + flag);
|
|
507
502
|
const terminatorPosition = argv.indexOf("--");
|
|
@@ -512,10 +507,10 @@ var require_has_flag = __commonJS({
|
|
|
512
507
|
|
|
513
508
|
// ../../node_modules/supports-color/index.js
|
|
514
509
|
var require_supports_color = __commonJS({
|
|
515
|
-
"../../node_modules/supports-color/index.js"(
|
|
510
|
+
"../../node_modules/supports-color/index.js"(exports2, module2) {
|
|
516
511
|
"use strict";
|
|
517
|
-
var os4 =
|
|
518
|
-
var tty =
|
|
512
|
+
var os4 = require("os");
|
|
513
|
+
var tty = require("tty");
|
|
519
514
|
var hasFlag = require_has_flag();
|
|
520
515
|
var { env } = process;
|
|
521
516
|
var forceColor;
|
|
@@ -604,7 +599,7 @@ var require_supports_color = __commonJS({
|
|
|
604
599
|
const level = supportsColor(stream, stream && stream.isTTY);
|
|
605
600
|
return translateLevel(level);
|
|
606
601
|
}
|
|
607
|
-
|
|
602
|
+
module2.exports = {
|
|
608
603
|
supportsColor: getSupportLevel,
|
|
609
604
|
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
610
605
|
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
@@ -614,26 +609,26 @@ var require_supports_color = __commonJS({
|
|
|
614
609
|
|
|
615
610
|
// ../../node_modules/debug/src/node.js
|
|
616
611
|
var require_node = __commonJS({
|
|
617
|
-
"../../node_modules/debug/src/node.js"(
|
|
612
|
+
"../../node_modules/debug/src/node.js"(exports2, module2) {
|
|
618
613
|
"use strict";
|
|
619
|
-
var tty =
|
|
620
|
-
var util =
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
614
|
+
var tty = require("tty");
|
|
615
|
+
var util = require("util");
|
|
616
|
+
exports2.init = init;
|
|
617
|
+
exports2.log = log;
|
|
618
|
+
exports2.formatArgs = formatArgs;
|
|
619
|
+
exports2.save = save;
|
|
620
|
+
exports2.load = load;
|
|
621
|
+
exports2.useColors = useColors;
|
|
622
|
+
exports2.destroy = util.deprecate(
|
|
628
623
|
() => {
|
|
629
624
|
},
|
|
630
625
|
"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
|
|
631
626
|
);
|
|
632
|
-
|
|
627
|
+
exports2.colors = [6, 2, 3, 4, 5, 1];
|
|
633
628
|
try {
|
|
634
629
|
const supportsColor = require_supports_color();
|
|
635
630
|
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
636
|
-
|
|
631
|
+
exports2.colors = [
|
|
637
632
|
20,
|
|
638
633
|
21,
|
|
639
634
|
26,
|
|
@@ -714,7 +709,7 @@ var require_node = __commonJS({
|
|
|
714
709
|
}
|
|
715
710
|
} catch (error) {
|
|
716
711
|
}
|
|
717
|
-
|
|
712
|
+
exports2.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
718
713
|
return /^debug_/i.test(key);
|
|
719
714
|
}).reduce((obj, key) => {
|
|
720
715
|
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
@@ -734,7 +729,7 @@ var require_node = __commonJS({
|
|
|
734
729
|
return obj;
|
|
735
730
|
}, {});
|
|
736
731
|
function useColors() {
|
|
737
|
-
return "colors" in
|
|
732
|
+
return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
738
733
|
}
|
|
739
734
|
function formatArgs(args) {
|
|
740
735
|
const { namespace: name, useColors: useColors2 } = this;
|
|
@@ -743,19 +738,19 @@ var require_node = __commonJS({
|
|
|
743
738
|
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
744
739
|
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
745
740
|
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
746
|
-
args.push(colorCode + "m+" +
|
|
741
|
+
args.push(colorCode + "m+" + module2.exports.humanize(this.diff) + "\x1B[0m");
|
|
747
742
|
} else {
|
|
748
743
|
args[0] = getDate() + name + " " + args[0];
|
|
749
744
|
}
|
|
750
745
|
}
|
|
751
746
|
function getDate() {
|
|
752
|
-
if (
|
|
747
|
+
if (exports2.inspectOpts.hideDate) {
|
|
753
748
|
return "";
|
|
754
749
|
}
|
|
755
750
|
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
756
751
|
}
|
|
757
752
|
function log(...args) {
|
|
758
|
-
return process.stderr.write(util.formatWithOptions(
|
|
753
|
+
return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args) + "\n");
|
|
759
754
|
}
|
|
760
755
|
function save(namespaces) {
|
|
761
756
|
if (namespaces) {
|
|
@@ -769,13 +764,13 @@ var require_node = __commonJS({
|
|
|
769
764
|
}
|
|
770
765
|
function init(debug2) {
|
|
771
766
|
debug2.inspectOpts = {};
|
|
772
|
-
const keys = Object.keys(
|
|
767
|
+
const keys = Object.keys(exports2.inspectOpts);
|
|
773
768
|
for (let i = 0; i < keys.length; i++) {
|
|
774
|
-
debug2.inspectOpts[keys[i]] =
|
|
769
|
+
debug2.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
|
|
775
770
|
}
|
|
776
771
|
}
|
|
777
|
-
|
|
778
|
-
var { formatters } =
|
|
772
|
+
module2.exports = require_common()(exports2);
|
|
773
|
+
var { formatters } = module2.exports;
|
|
779
774
|
formatters.o = function(v) {
|
|
780
775
|
this.inspectOpts.colors = this.useColors;
|
|
781
776
|
return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
@@ -789,25 +784,25 @@ var require_node = __commonJS({
|
|
|
789
784
|
|
|
790
785
|
// ../../node_modules/debug/src/index.js
|
|
791
786
|
var require_src = __commonJS({
|
|
792
|
-
"../../node_modules/debug/src/index.js"(
|
|
787
|
+
"../../node_modules/debug/src/index.js"(exports2, module2) {
|
|
793
788
|
"use strict";
|
|
794
789
|
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
795
|
-
|
|
790
|
+
module2.exports = require_browser();
|
|
796
791
|
} else {
|
|
797
|
-
|
|
792
|
+
module2.exports = require_node();
|
|
798
793
|
}
|
|
799
794
|
}
|
|
800
795
|
});
|
|
801
796
|
|
|
802
797
|
// ../../node_modules/@kwsites/file-exists/dist/src/index.js
|
|
803
798
|
var require_src2 = __commonJS({
|
|
804
|
-
"../../node_modules/@kwsites/file-exists/dist/src/index.js"(
|
|
799
|
+
"../../node_modules/@kwsites/file-exists/dist/src/index.js"(exports2) {
|
|
805
800
|
"use strict";
|
|
806
|
-
var __importDefault =
|
|
801
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
807
802
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
808
803
|
};
|
|
809
|
-
Object.defineProperty(
|
|
810
|
-
var fs_1 =
|
|
804
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
805
|
+
var fs_1 = require("fs");
|
|
811
806
|
var debug_1 = __importDefault(require_src());
|
|
812
807
|
var log = debug_1.default("@kwsites/file-exists");
|
|
813
808
|
function check(path7, isFile, isDirectory) {
|
|
@@ -833,34 +828,34 @@ var require_src2 = __commonJS({
|
|
|
833
828
|
throw e;
|
|
834
829
|
}
|
|
835
830
|
}
|
|
836
|
-
function exists2(path7, type =
|
|
837
|
-
return check(path7, (type &
|
|
831
|
+
function exists2(path7, type = exports2.READABLE) {
|
|
832
|
+
return check(path7, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
|
|
838
833
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
834
|
+
exports2.exists = exists2;
|
|
835
|
+
exports2.FILE = 1;
|
|
836
|
+
exports2.FOLDER = 2;
|
|
837
|
+
exports2.READABLE = exports2.FILE + exports2.FOLDER;
|
|
843
838
|
}
|
|
844
839
|
});
|
|
845
840
|
|
|
846
841
|
// ../../node_modules/@kwsites/file-exists/dist/index.js
|
|
847
842
|
var require_dist = __commonJS({
|
|
848
|
-
"../../node_modules/@kwsites/file-exists/dist/index.js"(
|
|
843
|
+
"../../node_modules/@kwsites/file-exists/dist/index.js"(exports2) {
|
|
849
844
|
"use strict";
|
|
850
845
|
function __export2(m) {
|
|
851
|
-
for (var p in m) if (!
|
|
846
|
+
for (var p in m) if (!exports2.hasOwnProperty(p)) exports2[p] = m[p];
|
|
852
847
|
}
|
|
853
|
-
Object.defineProperty(
|
|
848
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
854
849
|
__export2(require_src2());
|
|
855
850
|
}
|
|
856
851
|
});
|
|
857
852
|
|
|
858
853
|
// ../../node_modules/@kwsites/promise-deferred/dist/index.js
|
|
859
854
|
var require_dist2 = __commonJS({
|
|
860
|
-
"../../node_modules/@kwsites/promise-deferred/dist/index.js"(
|
|
855
|
+
"../../node_modules/@kwsites/promise-deferred/dist/index.js"(exports2) {
|
|
861
856
|
"use strict";
|
|
862
|
-
Object.defineProperty(
|
|
863
|
-
|
|
857
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
858
|
+
exports2.createDeferred = exports2.deferred = void 0;
|
|
864
859
|
function deferred2() {
|
|
865
860
|
let done;
|
|
866
861
|
let fail;
|
|
@@ -891,24 +886,20 @@ var require_dist2 = __commonJS({
|
|
|
891
886
|
}
|
|
892
887
|
};
|
|
893
888
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
889
|
+
exports2.deferred = deferred2;
|
|
890
|
+
exports2.createDeferred = deferred2;
|
|
891
|
+
exports2.default = deferred2;
|
|
897
892
|
}
|
|
898
893
|
});
|
|
899
894
|
|
|
900
895
|
// src/server/bin.ts
|
|
901
|
-
|
|
902
|
-
|
|
896
|
+
var import_commander = require("commander");
|
|
897
|
+
var import_zod4 = require("zod");
|
|
903
898
|
|
|
904
899
|
// src/server/agent-server.ts
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
PROTOCOL_VERSION
|
|
909
|
-
} from "@agentclientprotocol/sdk";
|
|
910
|
-
import { serve } from "@hono/node-server";
|
|
911
|
-
import { Hono } from "hono";
|
|
900
|
+
var import_sdk4 = require("@agentclientprotocol/sdk");
|
|
901
|
+
var import_node_server = require("@hono/node-server");
|
|
902
|
+
var import_hono = require("hono");
|
|
912
903
|
|
|
913
904
|
// src/acp-extensions.ts
|
|
914
905
|
var POSTHOG_NOTIFICATIONS = {
|
|
@@ -945,7 +936,7 @@ var POSTHOG_NOTIFICATIONS = {
|
|
|
945
936
|
};
|
|
946
937
|
|
|
947
938
|
// src/adapters/acp-connection.ts
|
|
948
|
-
|
|
939
|
+
var import_sdk3 = require("@agentclientprotocol/sdk");
|
|
949
940
|
|
|
950
941
|
// src/utils/logger.ts
|
|
951
942
|
var Logger = class _Logger {
|
|
@@ -1001,7 +992,7 @@ var Logger = class _Logger {
|
|
|
1001
992
|
};
|
|
1002
993
|
|
|
1003
994
|
// src/utils/streams.ts
|
|
1004
|
-
|
|
995
|
+
var import_web = require("stream/web");
|
|
1005
996
|
var Pushable = class {
|
|
1006
997
|
queue = [];
|
|
1007
998
|
resolvers = [];
|
|
@@ -1043,7 +1034,7 @@ var Pushable = class {
|
|
|
1043
1034
|
};
|
|
1044
1035
|
function pushableToReadableStream(pushable) {
|
|
1045
1036
|
const iterator = pushable[Symbol.asyncIterator]();
|
|
1046
|
-
return new
|
|
1037
|
+
return new import_web.ReadableStream({
|
|
1047
1038
|
async pull(controller) {
|
|
1048
1039
|
const { value, done } = await iterator.next();
|
|
1049
1040
|
if (done) {
|
|
@@ -1059,7 +1050,7 @@ function createBidirectionalStreams() {
|
|
|
1059
1050
|
const agentToClientPushable = new Pushable();
|
|
1060
1051
|
const clientToAgentReadable = pushableToReadableStream(clientToAgentPushable);
|
|
1061
1052
|
const agentToClientReadable = pushableToReadableStream(agentToClientPushable);
|
|
1062
|
-
const clientToAgentWritable = new
|
|
1053
|
+
const clientToAgentWritable = new import_web.WritableStream({
|
|
1063
1054
|
write(chunk) {
|
|
1064
1055
|
clientToAgentPushable.push(chunk);
|
|
1065
1056
|
},
|
|
@@ -1067,7 +1058,7 @@ function createBidirectionalStreams() {
|
|
|
1067
1058
|
clientToAgentPushable.end();
|
|
1068
1059
|
}
|
|
1069
1060
|
});
|
|
1070
|
-
const agentToClientWritable = new
|
|
1061
|
+
const agentToClientWritable = new import_web.WritableStream({
|
|
1071
1062
|
write(chunk) {
|
|
1072
1063
|
agentToClientPushable.push(chunk);
|
|
1073
1064
|
},
|
|
@@ -1091,7 +1082,7 @@ function createTappedWritableStream(underlying, options) {
|
|
|
1091
1082
|
const decoder = new TextDecoder();
|
|
1092
1083
|
let buffer = "";
|
|
1093
1084
|
let _messageCount = 0;
|
|
1094
|
-
return new
|
|
1085
|
+
return new import_web.WritableStream({
|
|
1095
1086
|
async write(chunk) {
|
|
1096
1087
|
buffer += decoder.decode(chunk, { stream: true });
|
|
1097
1088
|
const lines = buffer.split("\n");
|
|
@@ -1129,7 +1120,7 @@ function createTappedWritableStream(underlying, options) {
|
|
|
1129
1120
|
});
|
|
1130
1121
|
}
|
|
1131
1122
|
function nodeReadableToWebReadable(nodeStream) {
|
|
1132
|
-
return new
|
|
1123
|
+
return new import_web.ReadableStream({
|
|
1133
1124
|
start(controller) {
|
|
1134
1125
|
nodeStream.on("data", (chunk) => {
|
|
1135
1126
|
controller.enqueue(new Uint8Array(chunk));
|
|
@@ -1147,7 +1138,7 @@ function nodeReadableToWebReadable(nodeStream) {
|
|
|
1147
1138
|
});
|
|
1148
1139
|
}
|
|
1149
1140
|
function nodeWritableToWebWritable(nodeStream) {
|
|
1150
|
-
return new
|
|
1141
|
+
return new import_web.WritableStream({
|
|
1151
1142
|
write(chunk) {
|
|
1152
1143
|
return new Promise((resolve4, reject) => {
|
|
1153
1144
|
const ok = nodeStream.write(Buffer.from(chunk), (err) => {
|
|
@@ -1174,21 +1165,17 @@ function nodeWritableToWebWritable(nodeStream) {
|
|
|
1174
1165
|
}
|
|
1175
1166
|
|
|
1176
1167
|
// src/adapters/claude/claude-agent.ts
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
import {
|
|
1184
|
-
query
|
|
1185
|
-
} from "@anthropic-ai/claude-agent-sdk";
|
|
1186
|
-
import { v7 as uuidv7 } from "uuid";
|
|
1168
|
+
var fs2 = __toESM(require("fs"), 1);
|
|
1169
|
+
var os3 = __toESM(require("os"), 1);
|
|
1170
|
+
var path3 = __toESM(require("path"), 1);
|
|
1171
|
+
var import_sdk2 = require("@agentclientprotocol/sdk");
|
|
1172
|
+
var import_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
1173
|
+
var import_uuid = require("uuid");
|
|
1187
1174
|
|
|
1188
1175
|
// package.json
|
|
1189
1176
|
var package_default = {
|
|
1190
1177
|
name: "@posthog/agent",
|
|
1191
|
-
version: "2.
|
|
1178
|
+
version: "2.1.2",
|
|
1192
1179
|
repository: "https://github.com/PostHog/twig",
|
|
1193
1180
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
1194
1181
|
exports: {
|
|
@@ -1234,7 +1221,7 @@ var package_default = {
|
|
|
1234
1221
|
}
|
|
1235
1222
|
},
|
|
1236
1223
|
bin: {
|
|
1237
|
-
"agent-server": "./dist/server/bin.
|
|
1224
|
+
"agent-server": "./dist/server/bin.cjs"
|
|
1238
1225
|
},
|
|
1239
1226
|
type: "module",
|
|
1240
1227
|
keywords: [
|
|
@@ -1529,7 +1516,7 @@ function promptToClaude(prompt) {
|
|
|
1529
1516
|
}
|
|
1530
1517
|
|
|
1531
1518
|
// src/adapters/claude/conversion/sdk-to-acp.ts
|
|
1532
|
-
|
|
1519
|
+
var import_sdk = require("@agentclientprotocol/sdk");
|
|
1533
1520
|
|
|
1534
1521
|
// src/utils/acp-content.ts
|
|
1535
1522
|
function text(value) {
|
|
@@ -2316,13 +2303,13 @@ function handleResultMessage(message, context) {
|
|
|
2316
2303
|
if (message.result.includes("Please run /login")) {
|
|
2317
2304
|
return {
|
|
2318
2305
|
shouldStop: true,
|
|
2319
|
-
error: RequestError.authRequired()
|
|
2306
|
+
error: import_sdk.RequestError.authRequired()
|
|
2320
2307
|
};
|
|
2321
2308
|
}
|
|
2322
2309
|
if (message.is_error) {
|
|
2323
2310
|
return {
|
|
2324
2311
|
shouldStop: true,
|
|
2325
|
-
error: RequestError.internalError(void 0, message.result)
|
|
2312
|
+
error: import_sdk.RequestError.internalError(void 0, message.result)
|
|
2326
2313
|
};
|
|
2327
2314
|
}
|
|
2328
2315
|
return { shouldStop: true, stopReason: "end_turn" };
|
|
@@ -2331,7 +2318,7 @@ function handleResultMessage(message, context) {
|
|
|
2331
2318
|
if (message.is_error) {
|
|
2332
2319
|
return {
|
|
2333
2320
|
shouldStop: true,
|
|
2334
|
-
error: RequestError.internalError(
|
|
2321
|
+
error: import_sdk.RequestError.internalError(
|
|
2335
2322
|
void 0,
|
|
2336
2323
|
message.errors.join(", ") || message.subtype
|
|
2337
2324
|
)
|
|
@@ -2344,7 +2331,7 @@ function handleResultMessage(message, context) {
|
|
|
2344
2331
|
if (message.is_error) {
|
|
2345
2332
|
return {
|
|
2346
2333
|
shouldStop: true,
|
|
2347
|
-
error: RequestError.internalError(
|
|
2334
|
+
error: import_sdk.RequestError.internalError(
|
|
2348
2335
|
void 0,
|
|
2349
2336
|
message.errors.join(", ") || message.subtype
|
|
2350
2337
|
)
|
|
@@ -2409,7 +2396,7 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2409
2396
|
if (shouldSkipUserAssistantMessage(message)) {
|
|
2410
2397
|
logSpecialMessages(message, logger);
|
|
2411
2398
|
if (isLoginRequiredMessage(message)) {
|
|
2412
|
-
return { shouldStop: true, error: RequestError.authRequired() };
|
|
2399
|
+
return { shouldStop: true, error: import_sdk.RequestError.authRequired() };
|
|
2413
2400
|
}
|
|
2414
2401
|
return {};
|
|
2415
2402
|
}
|
|
@@ -2431,8 +2418,8 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2431
2418
|
}
|
|
2432
2419
|
|
|
2433
2420
|
// src/adapters/claude/mcp/tool-metadata.ts
|
|
2434
|
-
|
|
2435
|
-
|
|
2421
|
+
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
2422
|
+
var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
2436
2423
|
var mcpToolMetadataCache = /* @__PURE__ */ new Map();
|
|
2437
2424
|
function buildToolKey(serverName, toolName) {
|
|
2438
2425
|
return `mcp__${serverName}__${toolName}`;
|
|
@@ -2441,12 +2428,12 @@ function isHttpMcpServer(config) {
|
|
|
2441
2428
|
return config.type === "http" && typeof config.url === "string";
|
|
2442
2429
|
}
|
|
2443
2430
|
async function fetchToolsFromHttpServer(_serverName, config) {
|
|
2444
|
-
const transport = new StreamableHTTPClientTransport(new URL(config.url), {
|
|
2431
|
+
const transport = new import_streamableHttp.StreamableHTTPClientTransport(new URL(config.url), {
|
|
2445
2432
|
requestInit: {
|
|
2446
2433
|
headers: config.headers || {}
|
|
2447
2434
|
}
|
|
2448
2435
|
});
|
|
2449
|
-
const client = new Client({
|
|
2436
|
+
const client = new import_client.Client({
|
|
2450
2437
|
name: "twig-metadata-fetcher",
|
|
2451
2438
|
version: "1.0.0"
|
|
2452
2439
|
});
|
|
@@ -2500,8 +2487,8 @@ function isMcpToolReadOnly(toolName) {
|
|
|
2500
2487
|
}
|
|
2501
2488
|
|
|
2502
2489
|
// src/adapters/claude/plan/utils.ts
|
|
2503
|
-
|
|
2504
|
-
|
|
2490
|
+
var os = __toESM(require("os"), 1);
|
|
2491
|
+
var path = __toESM(require("path"), 1);
|
|
2505
2492
|
function getClaudeConfigDir() {
|
|
2506
2493
|
return process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
2507
2494
|
}
|
|
@@ -2543,21 +2530,21 @@ function getLatestAssistantText(notifications) {
|
|
|
2543
2530
|
}
|
|
2544
2531
|
|
|
2545
2532
|
// src/adapters/claude/questions/utils.ts
|
|
2546
|
-
|
|
2533
|
+
var import_zod = require("zod");
|
|
2547
2534
|
var OPTION_PREFIX = "option_";
|
|
2548
|
-
var QuestionOptionSchema = z.object({
|
|
2549
|
-
label: z.string(),
|
|
2550
|
-
description: z.string().optional()
|
|
2535
|
+
var QuestionOptionSchema = import_zod.z.object({
|
|
2536
|
+
label: import_zod.z.string(),
|
|
2537
|
+
description: import_zod.z.string().optional()
|
|
2551
2538
|
});
|
|
2552
|
-
var QuestionItemSchema = z.object({
|
|
2553
|
-
question: z.string(),
|
|
2554
|
-
header: z.string().optional(),
|
|
2555
|
-
options: z.array(QuestionOptionSchema),
|
|
2556
|
-
multiSelect: z.boolean().optional(),
|
|
2557
|
-
completed: z.boolean().optional()
|
|
2539
|
+
var QuestionItemSchema = import_zod.z.object({
|
|
2540
|
+
question: import_zod.z.string(),
|
|
2541
|
+
header: import_zod.z.string().optional(),
|
|
2542
|
+
options: import_zod.z.array(QuestionOptionSchema),
|
|
2543
|
+
multiSelect: import_zod.z.boolean().optional(),
|
|
2544
|
+
completed: import_zod.z.boolean().optional()
|
|
2558
2545
|
});
|
|
2559
|
-
var QuestionMetaSchema = z.object({
|
|
2560
|
-
questions: z.array(QuestionItemSchema)
|
|
2546
|
+
var QuestionMetaSchema = import_zod.z.object({
|
|
2547
|
+
questions: import_zod.z.array(QuestionItemSchema)
|
|
2561
2548
|
});
|
|
2562
2549
|
function normalizeAskUserQuestionInput(input) {
|
|
2563
2550
|
if (input.questions && input.questions.length > 0) {
|
|
@@ -3079,10 +3066,10 @@ function toSdkModelId(modelId) {
|
|
|
3079
3066
|
}
|
|
3080
3067
|
|
|
3081
3068
|
// src/adapters/claude/session/options.ts
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3069
|
+
var import_node_child_process = require("child_process");
|
|
3070
|
+
var fs = __toESM(require("fs"), 1);
|
|
3071
|
+
var os2 = __toESM(require("os"), 1);
|
|
3072
|
+
var path2 = __toESM(require("path"), 1);
|
|
3086
3073
|
var BRANCH_NAMING_INSTRUCTIONS = `
|
|
3087
3074
|
# Branch Naming
|
|
3088
3075
|
|
|
@@ -3141,7 +3128,7 @@ function getAbortController(userProvidedController) {
|
|
|
3141
3128
|
}
|
|
3142
3129
|
function buildSpawnWrapper(sessionId, onProcessSpawned, onProcessExited) {
|
|
3143
3130
|
return (spawnOpts) => {
|
|
3144
|
-
const child = spawn(spawnOpts.command, spawnOpts.args, {
|
|
3131
|
+
const child = (0, import_node_child_process.spawn)(spawnOpts.command, spawnOpts.args, {
|
|
3145
3132
|
cwd: spawnOpts.cwd,
|
|
3146
3133
|
env: spawnOpts.env,
|
|
3147
3134
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -3299,8 +3286,8 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3299
3286
|
async newSession(params) {
|
|
3300
3287
|
this.checkAuthStatus();
|
|
3301
3288
|
const meta = params._meta;
|
|
3302
|
-
const internalSessionId =
|
|
3303
|
-
const permissionMode = "default";
|
|
3289
|
+
const internalSessionId = (0, import_uuid.v7)();
|
|
3290
|
+
const permissionMode = meta?.permissionMode && TWIG_EXECUTION_MODES.includes(meta.permissionMode) ? meta.permissionMode : "default";
|
|
3304
3291
|
const mcpServers = parseMcpServers(params);
|
|
3305
3292
|
await fetchMcpToolMetadata(mcpServers, this.logger);
|
|
3306
3293
|
const options = buildSessionOptions({
|
|
@@ -3316,7 +3303,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3316
3303
|
onProcessExited: this.processCallbacks?.onProcessExited
|
|
3317
3304
|
});
|
|
3318
3305
|
const input = new Pushable();
|
|
3319
|
-
const q = query({ prompt: input, options });
|
|
3306
|
+
const q = (0, import_claude_agent_sdk.query)({ prompt: input, options });
|
|
3320
3307
|
const session = this.createSession(
|
|
3321
3308
|
internalSessionId,
|
|
3322
3309
|
q,
|
|
@@ -3353,10 +3340,11 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3353
3340
|
const meta = params._meta;
|
|
3354
3341
|
const mcpServers = parseMcpServers(params);
|
|
3355
3342
|
await fetchMcpToolMetadata(mcpServers, this.logger);
|
|
3343
|
+
const permissionMode = meta?.permissionMode && TWIG_EXECUTION_MODES.includes(meta.permissionMode) ? meta.permissionMode : "default";
|
|
3356
3344
|
const { query: q, session } = await this.initializeQuery({
|
|
3357
3345
|
internalSessionId,
|
|
3358
3346
|
cwd: params.cwd,
|
|
3359
|
-
permissionMode
|
|
3347
|
+
permissionMode,
|
|
3360
3348
|
mcpServers,
|
|
3361
3349
|
systemPrompt: buildSystemPrompt(meta?.systemPrompt),
|
|
3362
3350
|
userProvidedOptions: meta?.claudeCode?.options,
|
|
@@ -3419,7 +3407,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3419
3407
|
}
|
|
3420
3408
|
};
|
|
3421
3409
|
}
|
|
3422
|
-
throw
|
|
3410
|
+
throw import_sdk2.RequestError.methodNotFound(method);
|
|
3423
3411
|
}
|
|
3424
3412
|
createSession(sessionId, q, input, permissionMode, cwd, abortController) {
|
|
3425
3413
|
const session = {
|
|
@@ -3451,7 +3439,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3451
3439
|
onProcessSpawned: this.processCallbacks?.onProcessSpawned,
|
|
3452
3440
|
onProcessExited: this.processCallbacks?.onProcessExited
|
|
3453
3441
|
});
|
|
3454
|
-
const q = query({ prompt: input, options });
|
|
3442
|
+
const q = (0, import_claude_agent_sdk.query)({ prompt: input, options });
|
|
3455
3443
|
const abortController = options.abortController;
|
|
3456
3444
|
const session = this.createSession(
|
|
3457
3445
|
config.internalSessionId,
|
|
@@ -3537,7 +3525,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3537
3525
|
path3.resolve(os3.homedir(), ".claude.json")
|
|
3538
3526
|
);
|
|
3539
3527
|
if (backupExists && !configExists) {
|
|
3540
|
-
throw
|
|
3528
|
+
throw import_sdk2.RequestError.authRequired();
|
|
3541
3529
|
}
|
|
3542
3530
|
}
|
|
3543
3531
|
async trySetModel(q, modelId) {
|
|
@@ -3656,8 +3644,8 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3656
3644
|
};
|
|
3657
3645
|
|
|
3658
3646
|
// src/adapters/codex/spawn.ts
|
|
3659
|
-
|
|
3660
|
-
|
|
3647
|
+
var import_node_child_process2 = require("child_process");
|
|
3648
|
+
var import_node_fs = require("fs");
|
|
3661
3649
|
function buildConfigArgs(options) {
|
|
3662
3650
|
const args = [];
|
|
3663
3651
|
args.push("-c", `features.remote_models=false`);
|
|
@@ -3678,7 +3666,7 @@ function buildConfigArgs(options) {
|
|
|
3678
3666
|
}
|
|
3679
3667
|
function findCodexBinary(options) {
|
|
3680
3668
|
const configArgs = buildConfigArgs(options);
|
|
3681
|
-
if (options.binaryPath &&
|
|
3669
|
+
if (options.binaryPath && (0, import_node_fs.existsSync)(options.binaryPath)) {
|
|
3682
3670
|
return { command: options.binaryPath, args: configArgs };
|
|
3683
3671
|
}
|
|
3684
3672
|
return { command: "npx", args: ["@zed-industries/codex-acp", ...configArgs] };
|
|
@@ -3700,7 +3688,7 @@ function spawnCodexProcess(options) {
|
|
|
3700
3688
|
hasApiKey: !!options.apiKey,
|
|
3701
3689
|
binaryPath: options.binaryPath
|
|
3702
3690
|
});
|
|
3703
|
-
const child =
|
|
3691
|
+
const child = (0, import_node_child_process2.spawn)(command, args, {
|
|
3704
3692
|
cwd: options.cwd,
|
|
3705
3693
|
env,
|
|
3706
3694
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -3838,9 +3826,9 @@ function createClaudeConnection(config) {
|
|
|
3838
3826
|
hasLogWriter: !!logWriter
|
|
3839
3827
|
});
|
|
3840
3828
|
}
|
|
3841
|
-
const agentStream = ndJsonStream(agentWritable, streams.agent.readable);
|
|
3829
|
+
const agentStream = (0, import_sdk3.ndJsonStream)(agentWritable, streams.agent.readable);
|
|
3842
3830
|
let agent = null;
|
|
3843
|
-
const agentConnection = new AgentSideConnection((client) => {
|
|
3831
|
+
const agentConnection = new import_sdk3.AgentSideConnection((client) => {
|
|
3844
3832
|
agent = new ClaudeAcpAgent(client, logWriter, config.processCallbacks);
|
|
3845
3833
|
logger.info(`Created ${agent.adapterName} agent`);
|
|
3846
3834
|
return agent;
|
|
@@ -4256,29 +4244,26 @@ var PostHogAPIClient = class {
|
|
|
4256
4244
|
};
|
|
4257
4245
|
|
|
4258
4246
|
// src/otel-log-writer.ts
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
LoggerProvider
|
|
4265
|
-
} from "@opentelemetry/sdk-logs";
|
|
4266
|
-
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
4247
|
+
var import_api_logs = require("@opentelemetry/api-logs");
|
|
4248
|
+
var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
|
|
4249
|
+
var import_resources = require("@opentelemetry/resources");
|
|
4250
|
+
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
4251
|
+
var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
4267
4252
|
var OtelLogWriter = class {
|
|
4268
4253
|
loggerProvider;
|
|
4269
4254
|
logger;
|
|
4270
4255
|
constructor(config, sessionContext, _debugLogger) {
|
|
4271
4256
|
const logsPath = config.logsPath ?? "/i/v1/agent-logs";
|
|
4272
|
-
const exporter = new OTLPLogExporter({
|
|
4257
|
+
const exporter = new import_exporter_logs_otlp_http.OTLPLogExporter({
|
|
4273
4258
|
url: `${config.posthogHost}${logsPath}`,
|
|
4274
4259
|
headers: { Authorization: `Bearer ${config.apiKey}` }
|
|
4275
4260
|
});
|
|
4276
|
-
const processor = new BatchLogRecordProcessor(exporter, {
|
|
4261
|
+
const processor = new import_sdk_logs.BatchLogRecordProcessor(exporter, {
|
|
4277
4262
|
scheduledDelayMillis: config.flushIntervalMs ?? 500
|
|
4278
4263
|
});
|
|
4279
|
-
this.loggerProvider = new LoggerProvider({
|
|
4280
|
-
resource: resourceFromAttributes({
|
|
4281
|
-
[ATTR_SERVICE_NAME]: "twig-agent",
|
|
4264
|
+
this.loggerProvider = new import_sdk_logs.LoggerProvider({
|
|
4265
|
+
resource: (0, import_resources.resourceFromAttributes)({
|
|
4266
|
+
[import_semantic_conventions.ATTR_SERVICE_NAME]: "twig-agent",
|
|
4282
4267
|
run_id: sessionContext.runId,
|
|
4283
4268
|
task_id: sessionContext.taskId,
|
|
4284
4269
|
device_type: sessionContext.deviceType ?? "local"
|
|
@@ -4294,7 +4279,7 @@ var OtelLogWriter = class {
|
|
|
4294
4279
|
const { notification } = entry;
|
|
4295
4280
|
const eventType = notification.notification.method;
|
|
4296
4281
|
this.logger.emit({
|
|
4297
|
-
severityNumber: SeverityNumber.INFO,
|
|
4282
|
+
severityNumber: import_api_logs.SeverityNumber.INFO,
|
|
4298
4283
|
severityText: "INFO",
|
|
4299
4284
|
body: JSON.stringify(notification),
|
|
4300
4285
|
attributes: {
|
|
@@ -4354,9 +4339,22 @@ var SessionLogWriter = class {
|
|
|
4354
4339
|
}
|
|
4355
4340
|
try {
|
|
4356
4341
|
const message = JSON.parse(line);
|
|
4342
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
4343
|
+
if (this.isAgentMessageChunk(message)) {
|
|
4344
|
+
const text2 = this.extractChunkText(message);
|
|
4345
|
+
if (text2) {
|
|
4346
|
+
if (!session.chunkBuffer) {
|
|
4347
|
+
session.chunkBuffer = { text: text2, firstTimestamp: timestamp };
|
|
4348
|
+
} else {
|
|
4349
|
+
session.chunkBuffer.text += text2;
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
return;
|
|
4353
|
+
}
|
|
4354
|
+
this.emitCoalescedMessage(sessionId, session);
|
|
4357
4355
|
const entry = {
|
|
4358
4356
|
type: "notification",
|
|
4359
|
-
timestamp
|
|
4357
|
+
timestamp,
|
|
4360
4358
|
notification: message
|
|
4361
4359
|
};
|
|
4362
4360
|
if (session.otelWriter) {
|
|
@@ -4378,6 +4376,7 @@ var SessionLogWriter = class {
|
|
|
4378
4376
|
async flush(sessionId) {
|
|
4379
4377
|
const session = this.sessions.get(sessionId);
|
|
4380
4378
|
if (!session) return;
|
|
4379
|
+
this.emitCoalescedMessage(sessionId, session);
|
|
4381
4380
|
if (session.otelWriter) {
|
|
4382
4381
|
await session.otelWriter.flush();
|
|
4383
4382
|
}
|
|
@@ -4399,6 +4398,49 @@ var SessionLogWriter = class {
|
|
|
4399
4398
|
this.logger.error("Failed to persist session logs:", error);
|
|
4400
4399
|
}
|
|
4401
4400
|
}
|
|
4401
|
+
isAgentMessageChunk(message) {
|
|
4402
|
+
if (message.method !== "session/update") return false;
|
|
4403
|
+
const params = message.params;
|
|
4404
|
+
const update = params?.update;
|
|
4405
|
+
return update?.sessionUpdate === "agent_message_chunk";
|
|
4406
|
+
}
|
|
4407
|
+
extractChunkText(message) {
|
|
4408
|
+
const params = message.params;
|
|
4409
|
+
const update = params?.update;
|
|
4410
|
+
const content = update?.content;
|
|
4411
|
+
if (content?.type === "text" && content.text) {
|
|
4412
|
+
return content.text;
|
|
4413
|
+
}
|
|
4414
|
+
return "";
|
|
4415
|
+
}
|
|
4416
|
+
emitCoalescedMessage(sessionId, session) {
|
|
4417
|
+
if (!session.chunkBuffer) return;
|
|
4418
|
+
const { text: text2, firstTimestamp } = session.chunkBuffer;
|
|
4419
|
+
session.chunkBuffer = void 0;
|
|
4420
|
+
const entry = {
|
|
4421
|
+
type: "notification",
|
|
4422
|
+
timestamp: firstTimestamp,
|
|
4423
|
+
notification: {
|
|
4424
|
+
jsonrpc: "2.0",
|
|
4425
|
+
method: "session/update",
|
|
4426
|
+
params: {
|
|
4427
|
+
update: {
|
|
4428
|
+
sessionUpdate: "agent_message",
|
|
4429
|
+
content: { type: "text", text: text2 }
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
}
|
|
4433
|
+
};
|
|
4434
|
+
if (session.otelWriter) {
|
|
4435
|
+
session.otelWriter.emit({ notification: entry });
|
|
4436
|
+
}
|
|
4437
|
+
if (this.posthogAPI) {
|
|
4438
|
+
const pending = this.pendingEntries.get(sessionId) ?? [];
|
|
4439
|
+
pending.push(entry);
|
|
4440
|
+
this.pendingEntries.set(sessionId, pending);
|
|
4441
|
+
this.scheduleFlush(sessionId);
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4402
4444
|
scheduleFlush(sessionId) {
|
|
4403
4445
|
const existing = this.flushTimeouts.get(sessionId);
|
|
4404
4446
|
if (existing) clearTimeout(existing);
|
|
@@ -4408,18 +4450,18 @@ var SessionLogWriter = class {
|
|
|
4408
4450
|
};
|
|
4409
4451
|
|
|
4410
4452
|
// ../git/dist/queries.js
|
|
4411
|
-
|
|
4412
|
-
|
|
4453
|
+
var fs4 = __toESM(require("fs/promises"), 1);
|
|
4454
|
+
var path5 = __toESM(require("path"), 1);
|
|
4413
4455
|
|
|
4414
4456
|
// ../../node_modules/simple-git/dist/esm/index.js
|
|
4457
|
+
var import_node_buffer = require("buffer");
|
|
4415
4458
|
var import_file_exists = __toESM(require_dist(), 1);
|
|
4416
4459
|
var import_debug = __toESM(require_src(), 1);
|
|
4460
|
+
var import_child_process = require("child_process");
|
|
4417
4461
|
var import_promise_deferred = __toESM(require_dist2(), 1);
|
|
4462
|
+
var import_node_path = require("path");
|
|
4418
4463
|
var import_promise_deferred2 = __toESM(require_dist2(), 1);
|
|
4419
|
-
|
|
4420
|
-
import { spawn as spawn3 } from "child_process";
|
|
4421
|
-
import { normalize } from "path";
|
|
4422
|
-
import { EventEmitter } from "events";
|
|
4464
|
+
var import_node_events = require("events");
|
|
4423
4465
|
var __defProp2 = Object.defineProperty;
|
|
4424
4466
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
4425
4467
|
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
@@ -4427,7 +4469,7 @@ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
|
4427
4469
|
var __esm = (fn, res) => function __init() {
|
|
4428
4470
|
return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
|
|
4429
4471
|
};
|
|
4430
|
-
var __commonJS2 = (cb, mod) => function
|
|
4472
|
+
var __commonJS2 = (cb, mod) => function __require() {
|
|
4431
4473
|
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4432
4474
|
};
|
|
4433
4475
|
var __export = (target, all) => {
|
|
@@ -4596,7 +4638,7 @@ function prefixedArray(input, prefix) {
|
|
|
4596
4638
|
return output;
|
|
4597
4639
|
}
|
|
4598
4640
|
function bufferToString(input) {
|
|
4599
|
-
return (Array.isArray(input) ?
|
|
4641
|
+
return (Array.isArray(input) ? import_node_buffer.Buffer.concat(input) : input).toString("utf-8");
|
|
4600
4642
|
}
|
|
4601
4643
|
function pick(source, properties) {
|
|
4602
4644
|
const out = {};
|
|
@@ -5805,7 +5847,7 @@ var init_git_executor_chain = __esm({
|
|
|
5805
5847
|
rejection = reason || rejection;
|
|
5806
5848
|
}
|
|
5807
5849
|
});
|
|
5808
|
-
const spawned =
|
|
5850
|
+
const spawned = (0, import_child_process.spawn)(command, args, spawnOptions);
|
|
5809
5851
|
spawned.stdout.on(
|
|
5810
5852
|
"data",
|
|
5811
5853
|
onDataReceived(stdOut, "stdOut", logger, outputLogger.step("stdOut"))
|
|
@@ -7725,7 +7767,7 @@ var init_branch = __esm({
|
|
|
7725
7767
|
});
|
|
7726
7768
|
function toPath(input) {
|
|
7727
7769
|
const path7 = input.trim().replace(/^["']|["']$/g, "");
|
|
7728
|
-
return path7 && normalize(path7);
|
|
7770
|
+
return path7 && (0, import_node_path.normalize)(path7);
|
|
7729
7771
|
}
|
|
7730
7772
|
var parseCheckIgnore;
|
|
7731
7773
|
var init_CheckIgnore = __esm({
|
|
@@ -8156,7 +8198,7 @@ var init_tag = __esm({
|
|
|
8156
8198
|
}
|
|
8157
8199
|
});
|
|
8158
8200
|
var require_git = __commonJS2({
|
|
8159
|
-
"src/git.js"(
|
|
8201
|
+
"src/git.js"(exports2, module2) {
|
|
8160
8202
|
"use strict";
|
|
8161
8203
|
var { GitExecutor: GitExecutor2 } = (init_git_executor(), __toCommonJS(git_executor_exports));
|
|
8162
8204
|
var { SimpleGitApi: SimpleGitApi2 } = (init_simple_git_api(), __toCommonJS(simple_git_api_exports));
|
|
@@ -8530,7 +8572,7 @@ var require_git = __commonJS2({
|
|
|
8530
8572
|
trailingFunctionArgument2(arguments)
|
|
8531
8573
|
);
|
|
8532
8574
|
};
|
|
8533
|
-
|
|
8575
|
+
module2.exports = Git2;
|
|
8534
8576
|
}
|
|
8535
8577
|
});
|
|
8536
8578
|
init_pathspec();
|
|
@@ -8785,7 +8827,7 @@ init_utils();
|
|
|
8785
8827
|
var PluginStore = class {
|
|
8786
8828
|
constructor() {
|
|
8787
8829
|
this.plugins = /* @__PURE__ */ new Set();
|
|
8788
|
-
this.events = new EventEmitter();
|
|
8830
|
+
this.events = new import_node_events.EventEmitter();
|
|
8789
8831
|
}
|
|
8790
8832
|
on(type, listener) {
|
|
8791
8833
|
this.events.on(type, listener);
|
|
@@ -8971,23 +9013,23 @@ function createGitClient(baseDir, options) {
|
|
|
8971
9013
|
}
|
|
8972
9014
|
|
|
8973
9015
|
// ../git/dist/lock-detector.js
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
var execFileAsync = promisify(execFile);
|
|
9016
|
+
var import_node_child_process3 = require("child_process");
|
|
9017
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
9018
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
9019
|
+
var import_node_util = require("util");
|
|
9020
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process3.execFile);
|
|
8979
9021
|
async function getIndexLockPath(repoPath) {
|
|
8980
9022
|
try {
|
|
8981
9023
|
const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "index.lock"], { cwd: repoPath });
|
|
8982
|
-
return
|
|
9024
|
+
return import_node_path2.default.resolve(repoPath, stdout.trim());
|
|
8983
9025
|
} catch {
|
|
8984
|
-
return
|
|
9026
|
+
return import_node_path2.default.join(repoPath, ".git", "index.lock");
|
|
8985
9027
|
}
|
|
8986
9028
|
}
|
|
8987
9029
|
async function getLockInfo(repoPath) {
|
|
8988
9030
|
const lockPath = await getIndexLockPath(repoPath);
|
|
8989
9031
|
try {
|
|
8990
|
-
const stat = await
|
|
9032
|
+
const stat = await import_promises.default.stat(lockPath);
|
|
8991
9033
|
return {
|
|
8992
9034
|
path: lockPath,
|
|
8993
9035
|
ageMs: Date.now() - stat.mtimeMs
|
|
@@ -8998,7 +9040,7 @@ async function getLockInfo(repoPath) {
|
|
|
8998
9040
|
}
|
|
8999
9041
|
async function removeLock(repoPath) {
|
|
9000
9042
|
const lockPath = await getIndexLockPath(repoPath);
|
|
9001
|
-
await
|
|
9043
|
+
await import_promises.default.rm(lockPath, { force: true });
|
|
9002
9044
|
}
|
|
9003
9045
|
async function isLocked(repoPath) {
|
|
9004
9046
|
return await getLockInfo(repoPath) !== null;
|
|
@@ -9162,8 +9204,8 @@ async function getHeadSha(baseDir, options) {
|
|
|
9162
9204
|
}
|
|
9163
9205
|
|
|
9164
9206
|
// src/sagas/apply-snapshot-saga.ts
|
|
9165
|
-
|
|
9166
|
-
|
|
9207
|
+
var import_promises2 = require("fs/promises");
|
|
9208
|
+
var import_node_path3 = require("path");
|
|
9167
9209
|
|
|
9168
9210
|
// ../shared/dist/index.js
|
|
9169
9211
|
var consoleLogger = {
|
|
@@ -9293,10 +9335,10 @@ var Saga = class {
|
|
|
9293
9335
|
};
|
|
9294
9336
|
|
|
9295
9337
|
// ../git/dist/sagas/tree.js
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9338
|
+
var import_node_fs2 = require("fs");
|
|
9339
|
+
var fs5 = __toESM(require("fs/promises"), 1);
|
|
9340
|
+
var path6 = __toESM(require("path"), 1);
|
|
9341
|
+
var tar = __toESM(require("tar"), 1);
|
|
9300
9342
|
|
|
9301
9343
|
// ../git/dist/git-saga.js
|
|
9302
9344
|
var GitSaga = class extends Saga {
|
|
@@ -9383,7 +9425,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
9383
9425
|
if (filesToArchive.length === 0) {
|
|
9384
9426
|
return void 0;
|
|
9385
9427
|
}
|
|
9386
|
-
const existingFiles = filesToArchive.filter((f) =>
|
|
9428
|
+
const existingFiles = filesToArchive.filter((f) => (0, import_node_fs2.existsSync)(path6.join(baseDir, f)));
|
|
9387
9429
|
if (existingFiles.length === 0) {
|
|
9388
9430
|
return void 0;
|
|
9389
9431
|
}
|
|
@@ -9575,17 +9617,17 @@ var ApplySnapshotSaga = class extends Saga {
|
|
|
9575
9617
|
archivePath = null;
|
|
9576
9618
|
async execute(input) {
|
|
9577
9619
|
const { snapshot, repositoryPath, apiClient, taskId, runId } = input;
|
|
9578
|
-
const tmpDir =
|
|
9620
|
+
const tmpDir = (0, import_node_path3.join)(repositoryPath, ".posthog", "tmp");
|
|
9579
9621
|
if (!snapshot.archiveUrl) {
|
|
9580
9622
|
throw new Error("Cannot apply snapshot: no archive URL");
|
|
9581
9623
|
}
|
|
9582
9624
|
await this.step({
|
|
9583
9625
|
name: "create_tmp_dir",
|
|
9584
|
-
execute: () =>
|
|
9626
|
+
execute: () => (0, import_promises2.mkdir)(tmpDir, { recursive: true }),
|
|
9585
9627
|
rollback: async () => {
|
|
9586
9628
|
}
|
|
9587
9629
|
});
|
|
9588
|
-
this.archivePath =
|
|
9630
|
+
this.archivePath = (0, import_node_path3.join)(tmpDir, `${snapshot.treeHash}.tar.gz`);
|
|
9589
9631
|
await this.step({
|
|
9590
9632
|
name: "download_archive",
|
|
9591
9633
|
execute: async () => {
|
|
@@ -9599,11 +9641,11 @@ var ApplySnapshotSaga = class extends Saga {
|
|
|
9599
9641
|
}
|
|
9600
9642
|
const base64Content = Buffer.from(arrayBuffer).toString("utf-8");
|
|
9601
9643
|
const binaryContent = Buffer.from(base64Content, "base64");
|
|
9602
|
-
await
|
|
9644
|
+
await (0, import_promises2.writeFile)(this.archivePath, binaryContent);
|
|
9603
9645
|
},
|
|
9604
9646
|
rollback: async () => {
|
|
9605
9647
|
if (this.archivePath) {
|
|
9606
|
-
await
|
|
9648
|
+
await (0, import_promises2.rm)(this.archivePath, { force: true }).catch(() => {
|
|
9607
9649
|
});
|
|
9608
9650
|
}
|
|
9609
9651
|
}
|
|
@@ -9619,7 +9661,7 @@ var ApplySnapshotSaga = class extends Saga {
|
|
|
9619
9661
|
if (!applyResult.success) {
|
|
9620
9662
|
throw new Error(`Failed to apply tree: ${applyResult.error}`);
|
|
9621
9663
|
}
|
|
9622
|
-
await
|
|
9664
|
+
await (0, import_promises2.rm)(this.archivePath, { force: true }).catch(() => {
|
|
9623
9665
|
});
|
|
9624
9666
|
this.log.info("Tree snapshot applied", {
|
|
9625
9667
|
treeHash: snapshot.treeHash,
|
|
@@ -9631,9 +9673,9 @@ var ApplySnapshotSaga = class extends Saga {
|
|
|
9631
9673
|
};
|
|
9632
9674
|
|
|
9633
9675
|
// src/sagas/capture-tree-saga.ts
|
|
9634
|
-
|
|
9635
|
-
|
|
9636
|
-
|
|
9676
|
+
var import_node_fs3 = require("fs");
|
|
9677
|
+
var import_promises3 = require("fs/promises");
|
|
9678
|
+
var import_node_path4 = require("path");
|
|
9637
9679
|
var CaptureTreeSaga2 = class extends Saga {
|
|
9638
9680
|
async execute(input) {
|
|
9639
9681
|
const {
|
|
@@ -9644,14 +9686,14 @@ var CaptureTreeSaga2 = class extends Saga {
|
|
|
9644
9686
|
taskId,
|
|
9645
9687
|
runId
|
|
9646
9688
|
} = input;
|
|
9647
|
-
const tmpDir =
|
|
9648
|
-
if (
|
|
9689
|
+
const tmpDir = (0, import_node_path4.join)(repositoryPath, ".posthog", "tmp");
|
|
9690
|
+
if ((0, import_node_fs3.existsSync)((0, import_node_path4.join)(repositoryPath, ".gitmodules"))) {
|
|
9649
9691
|
this.log.warn(
|
|
9650
9692
|
"Repository has submodules - snapshot may not capture submodule state"
|
|
9651
9693
|
);
|
|
9652
9694
|
}
|
|
9653
9695
|
const shouldArchive = !!apiClient;
|
|
9654
|
-
const archivePath = shouldArchive ?
|
|
9696
|
+
const archivePath = shouldArchive ? (0, import_node_path4.join)(tmpDir, `tree-${Date.now()}.tar.gz`) : void 0;
|
|
9655
9697
|
const gitCaptureSaga = new CaptureTreeSaga(this.log);
|
|
9656
9698
|
const captureResult = await gitCaptureSaga.run({
|
|
9657
9699
|
baseDir: repositoryPath,
|
|
@@ -9681,7 +9723,7 @@ var CaptureTreeSaga2 = class extends Saga {
|
|
|
9681
9723
|
runId
|
|
9682
9724
|
);
|
|
9683
9725
|
} finally {
|
|
9684
|
-
await
|
|
9726
|
+
await (0, import_promises3.rm)(createdArchivePath, { force: true }).catch(() => {
|
|
9685
9727
|
});
|
|
9686
9728
|
}
|
|
9687
9729
|
}
|
|
@@ -9705,7 +9747,7 @@ var CaptureTreeSaga2 = class extends Saga {
|
|
|
9705
9747
|
const archiveUrl = await this.step({
|
|
9706
9748
|
name: "upload_archive",
|
|
9707
9749
|
execute: async () => {
|
|
9708
|
-
const archiveContent = await
|
|
9750
|
+
const archiveContent = await (0, import_promises3.readFile)(archivePath);
|
|
9709
9751
|
const base64Content = archiveContent.toString("base64");
|
|
9710
9752
|
const artifacts = await apiClient.uploadTaskArtifacts(taskId, runId, [
|
|
9711
9753
|
{
|
|
@@ -9725,7 +9767,7 @@ var CaptureTreeSaga2 = class extends Saga {
|
|
|
9725
9767
|
return void 0;
|
|
9726
9768
|
},
|
|
9727
9769
|
rollback: async () => {
|
|
9728
|
-
await
|
|
9770
|
+
await (0, import_promises3.rm)(archivePath, { force: true }).catch(() => {
|
|
9729
9771
|
});
|
|
9730
9772
|
}
|
|
9731
9773
|
});
|
|
@@ -9856,21 +9898,21 @@ var AsyncMutex = class {
|
|
|
9856
9898
|
};
|
|
9857
9899
|
|
|
9858
9900
|
// src/server/jwt.ts
|
|
9859
|
-
|
|
9860
|
-
|
|
9901
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
9902
|
+
var import_zod2 = require("zod");
|
|
9861
9903
|
var SANDBOX_CONNECTION_AUDIENCE = "posthog:sandbox_connection";
|
|
9862
|
-
var userDataSchema =
|
|
9863
|
-
run_id:
|
|
9864
|
-
task_id:
|
|
9865
|
-
team_id:
|
|
9866
|
-
user_id:
|
|
9867
|
-
distinct_id:
|
|
9868
|
-
mode:
|
|
9904
|
+
var userDataSchema = import_zod2.z.object({
|
|
9905
|
+
run_id: import_zod2.z.string(),
|
|
9906
|
+
task_id: import_zod2.z.string(),
|
|
9907
|
+
team_id: import_zod2.z.number(),
|
|
9908
|
+
user_id: import_zod2.z.number(),
|
|
9909
|
+
distinct_id: import_zod2.z.string(),
|
|
9910
|
+
mode: import_zod2.z.enum(["interactive", "background"]).optional().default("interactive")
|
|
9869
9911
|
});
|
|
9870
9912
|
var jwtPayloadSchema = userDataSchema.extend({
|
|
9871
|
-
exp:
|
|
9872
|
-
iat:
|
|
9873
|
-
aud:
|
|
9913
|
+
exp: import_zod2.z.number(),
|
|
9914
|
+
iat: import_zod2.z.number().optional(),
|
|
9915
|
+
aud: import_zod2.z.string().optional()
|
|
9874
9916
|
});
|
|
9875
9917
|
var JwtValidationError = class extends Error {
|
|
9876
9918
|
constructor(message, code) {
|
|
@@ -9881,7 +9923,7 @@ var JwtValidationError = class extends Error {
|
|
|
9881
9923
|
};
|
|
9882
9924
|
function validateJwt(token, publicKey) {
|
|
9883
9925
|
try {
|
|
9884
|
-
const decoded =
|
|
9926
|
+
const decoded = import_jsonwebtoken.default.verify(token, publicKey, {
|
|
9885
9927
|
algorithms: ["RS256"],
|
|
9886
9928
|
audience: SANDBOX_CONNECTION_AUDIENCE
|
|
9887
9929
|
});
|
|
@@ -9897,10 +9939,10 @@ function validateJwt(token, publicKey) {
|
|
|
9897
9939
|
if (error instanceof JwtValidationError) {
|
|
9898
9940
|
throw error;
|
|
9899
9941
|
}
|
|
9900
|
-
if (error instanceof
|
|
9942
|
+
if (error instanceof import_jsonwebtoken.default.TokenExpiredError) {
|
|
9901
9943
|
throw new JwtValidationError("Token expired", "expired");
|
|
9902
9944
|
}
|
|
9903
|
-
if (error instanceof
|
|
9945
|
+
if (error instanceof import_jsonwebtoken.default.JsonWebTokenError) {
|
|
9904
9946
|
throw new JwtValidationError("Invalid signature", "invalid_signature");
|
|
9905
9947
|
}
|
|
9906
9948
|
throw new JwtValidationError("Invalid token", "invalid_token");
|
|
@@ -9908,23 +9950,23 @@ function validateJwt(token, publicKey) {
|
|
|
9908
9950
|
}
|
|
9909
9951
|
|
|
9910
9952
|
// src/server/schemas.ts
|
|
9911
|
-
|
|
9912
|
-
var jsonRpcRequestSchema =
|
|
9913
|
-
jsonrpc:
|
|
9914
|
-
method:
|
|
9915
|
-
params:
|
|
9916
|
-
id:
|
|
9953
|
+
var import_zod3 = require("zod");
|
|
9954
|
+
var jsonRpcRequestSchema = import_zod3.z.object({
|
|
9955
|
+
jsonrpc: import_zod3.z.literal("2.0"),
|
|
9956
|
+
method: import_zod3.z.string(),
|
|
9957
|
+
params: import_zod3.z.record(import_zod3.z.unknown()).optional(),
|
|
9958
|
+
id: import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number()]).optional()
|
|
9917
9959
|
});
|
|
9918
|
-
var userMessageParamsSchema =
|
|
9919
|
-
content:
|
|
9960
|
+
var userMessageParamsSchema = import_zod3.z.object({
|
|
9961
|
+
content: import_zod3.z.string().min(1, "Content is required")
|
|
9920
9962
|
});
|
|
9921
9963
|
var commandParamsSchemas = {
|
|
9922
9964
|
user_message: userMessageParamsSchema,
|
|
9923
9965
|
"posthog/user_message": userMessageParamsSchema,
|
|
9924
|
-
cancel:
|
|
9925
|
-
"posthog/cancel":
|
|
9926
|
-
close:
|
|
9927
|
-
"posthog/close":
|
|
9966
|
+
cancel: import_zod3.z.object({}).optional(),
|
|
9967
|
+
"posthog/cancel": import_zod3.z.object({}).optional(),
|
|
9968
|
+
close: import_zod3.z.object({}).optional(),
|
|
9969
|
+
"posthog/close": import_zod3.z.object({}).optional()
|
|
9928
9970
|
};
|
|
9929
9971
|
function validateCommandParams(method, params) {
|
|
9930
9972
|
const schema = commandParamsSchemas[method] ?? commandParamsSchemas[method.replace("posthog/", "")];
|
|
@@ -10045,7 +10087,7 @@ var AgentServer = class {
|
|
|
10045
10087
|
return payload.mode ?? this.config.mode;
|
|
10046
10088
|
}
|
|
10047
10089
|
createApp() {
|
|
10048
|
-
const app = new Hono();
|
|
10090
|
+
const app = new import_hono.Hono();
|
|
10049
10091
|
app.get("/health", (c) => {
|
|
10050
10092
|
return c.json({ status: "ok", hasSession: !!this.session });
|
|
10051
10093
|
});
|
|
@@ -10178,7 +10220,7 @@ var AgentServer = class {
|
|
|
10178
10220
|
}
|
|
10179
10221
|
async start() {
|
|
10180
10222
|
await new Promise((resolve4) => {
|
|
10181
|
-
this.server = serve(
|
|
10223
|
+
this.server = (0, import_node_server.serve)(
|
|
10182
10224
|
{
|
|
10183
10225
|
fetch: this.app.fetch,
|
|
10184
10226
|
port: this.config.port
|
|
@@ -10323,13 +10365,13 @@ var AgentServer = class {
|
|
|
10323
10365
|
onAcpMessage,
|
|
10324
10366
|
this.logger
|
|
10325
10367
|
);
|
|
10326
|
-
const clientStream =
|
|
10327
|
-
const clientConnection = new ClientSideConnection(
|
|
10368
|
+
const clientStream = (0, import_sdk4.ndJsonStream)(tappedWritable, tappedReadable);
|
|
10369
|
+
const clientConnection = new import_sdk4.ClientSideConnection(
|
|
10328
10370
|
() => this.createCloudClient(payload),
|
|
10329
10371
|
clientStream
|
|
10330
10372
|
);
|
|
10331
10373
|
await clientConnection.initialize({
|
|
10332
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
10374
|
+
protocolVersion: import_sdk4.PROTOCOL_VERSION,
|
|
10333
10375
|
clientCapabilities: {}
|
|
10334
10376
|
});
|
|
10335
10377
|
await clientConnection.newSession({
|
|
@@ -10504,21 +10546,21 @@ var AgentServer = class {
|
|
|
10504
10546
|
};
|
|
10505
10547
|
|
|
10506
10548
|
// src/server/bin.ts
|
|
10507
|
-
var envSchema =
|
|
10508
|
-
JWT_PUBLIC_KEY:
|
|
10549
|
+
var envSchema = import_zod4.z.object({
|
|
10550
|
+
JWT_PUBLIC_KEY: import_zod4.z.string({
|
|
10509
10551
|
required_error: "JWT_PUBLIC_KEY is required for authenticating client connections"
|
|
10510
10552
|
}).min(1, "JWT_PUBLIC_KEY cannot be empty"),
|
|
10511
|
-
POSTHOG_API_URL:
|
|
10553
|
+
POSTHOG_API_URL: import_zod4.z.string({
|
|
10512
10554
|
required_error: "POSTHOG_API_URL is required for LLM gateway communication"
|
|
10513
10555
|
}).url("POSTHOG_API_URL must be a valid URL"),
|
|
10514
|
-
POSTHOG_PERSONAL_API_KEY:
|
|
10556
|
+
POSTHOG_PERSONAL_API_KEY: import_zod4.z.string({
|
|
10515
10557
|
required_error: "POSTHOG_PERSONAL_API_KEY is required for authenticating with PostHog services"
|
|
10516
10558
|
}).min(1, "POSTHOG_PERSONAL_API_KEY cannot be empty"),
|
|
10517
|
-
POSTHOG_PROJECT_ID:
|
|
10559
|
+
POSTHOG_PROJECT_ID: import_zod4.z.string({
|
|
10518
10560
|
required_error: "POSTHOG_PROJECT_ID is required for routing requests to the correct project"
|
|
10519
10561
|
}).regex(/^\d+$/, "POSTHOG_PROJECT_ID must be a numeric string").transform((val) => parseInt(val, 10))
|
|
10520
10562
|
});
|
|
10521
|
-
var program = new Command();
|
|
10563
|
+
var program = new import_commander.Command();
|
|
10522
10564
|
program.name("agent-server").description("PostHog cloud agent server - runs in sandbox environments").option("--port <port>", "HTTP server port", "3001").option(
|
|
10523
10565
|
"--mode <mode>",
|
|
10524
10566
|
"Execution mode: interactive or background",
|
|
@@ -10555,4 +10597,4 @@ ${errors}`);
|
|
|
10555
10597
|
await server.start();
|
|
10556
10598
|
});
|
|
10557
10599
|
program.parse();
|
|
10558
|
-
//# sourceMappingURL=bin.
|
|
10600
|
+
//# sourceMappingURL=bin.cjs.map
|