repoburg 1.3.285 → 1.3.286
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/agent-pane/backend/dist/index.js +739 -380
- package/agent-pane/backend/dist/server.js +723 -371
- package/agent-pane/frontend/dist/assets/TerminalView-6GBZ9nXN.css +32 -0
- package/agent-pane/frontend/dist/assets/TerminalView-BFw1zt_D.js +56 -0
- package/agent-pane/frontend/dist/assets/index-8ltC2W3q.js +660 -0
- package/agent-pane/frontend/dist/assets/index-sz14_w3J.css +1 -0
- package/agent-pane/frontend/dist/index.html +2 -2
- package/daemon/dist/agentPane.js +19 -1
- package/daemon/dist/agentPane.spec.js +62 -0
- package/daemon/dist/index.js +4 -3
- package/daemon/dist/middleware/checkRemoteAuth.js +14 -0
- package/daemon/dist/middleware/checkRemoteAuth.spec.js +29 -0
- package/package.json +4 -1
- package/tabtape/extension/dist/build-info.json +4 -4
- package/tabtape/extension/dist/manifest.json +1 -1
- package/tabtape/extension/dist/recorder.js +13 -13
- package/tabtape/extension/dist/recorder.js.map +1 -1
- package/tabtape/ui/dist/build-info.json +4 -4
- package/agent-pane/frontend/dist/assets/index-BlbOKgb_.css +0 -1
- package/agent-pane/frontend/dist/assets/index-Db6gAdkM.js +0 -649
|
@@ -2676,7 +2676,7 @@ var require_server = __commonJS({
|
|
|
2676
2676
|
var https = __require("node:https");
|
|
2677
2677
|
var http22 = __require("node:http2");
|
|
2678
2678
|
var dns = __require("node:dns");
|
|
2679
|
-
var
|
|
2679
|
+
var os5 = __require("node:os");
|
|
2680
2680
|
var { kState, kOptions, kServerBindings, kHttp2ServerSessions } = require_symbols2();
|
|
2681
2681
|
var { FSTWRN003 } = require_warnings();
|
|
2682
2682
|
var { onListenHookRunner } = require_hooks();
|
|
@@ -2938,7 +2938,7 @@ var require_server = __commonJS({
|
|
|
2938
2938
|
}
|
|
2939
2939
|
function getAddresses(address) {
|
|
2940
2940
|
if (address.address === "0.0.0.0") {
|
|
2941
|
-
return Object.values(
|
|
2941
|
+
return Object.values(os5.networkInterfaces()).flatMap((iface) => {
|
|
2942
2942
|
return iface.filter((iface2) => iface2.family === "IPv4");
|
|
2943
2943
|
}).sort((iface) => {
|
|
2944
2944
|
return iface.internal ? -1 : 1;
|
|
@@ -6124,8 +6124,8 @@ var require_req = __commonJS({
|
|
|
6124
6124
|
if (req.originalUrl) {
|
|
6125
6125
|
_req.url = req.originalUrl;
|
|
6126
6126
|
} else {
|
|
6127
|
-
const
|
|
6128
|
-
_req.url = typeof
|
|
6127
|
+
const path12 = req.path;
|
|
6128
|
+
_req.url = typeof path12 === "string" ? path12 : req.url ? req.url.path || req.url : void 0;
|
|
6129
6129
|
}
|
|
6130
6130
|
if (req.query) {
|
|
6131
6131
|
_req.query = req.query;
|
|
@@ -6290,14 +6290,14 @@ var require_redact = __commonJS({
|
|
|
6290
6290
|
}
|
|
6291
6291
|
return obj;
|
|
6292
6292
|
}
|
|
6293
|
-
function parsePath(
|
|
6293
|
+
function parsePath(path12) {
|
|
6294
6294
|
const parts = [];
|
|
6295
6295
|
let current = "";
|
|
6296
6296
|
let inBrackets = false;
|
|
6297
6297
|
let inQuotes = false;
|
|
6298
6298
|
let quoteChar = "";
|
|
6299
|
-
for (let i = 0; i <
|
|
6300
|
-
const char =
|
|
6299
|
+
for (let i = 0; i < path12.length; i++) {
|
|
6300
|
+
const char = path12[i];
|
|
6301
6301
|
if (!inBrackets && char === ".") {
|
|
6302
6302
|
if (current) {
|
|
6303
6303
|
parts.push(current);
|
|
@@ -6428,10 +6428,10 @@ var require_redact = __commonJS({
|
|
|
6428
6428
|
return current;
|
|
6429
6429
|
}
|
|
6430
6430
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
6431
|
-
for (const
|
|
6432
|
-
const parts = parsePath(
|
|
6431
|
+
for (const path12 of paths) {
|
|
6432
|
+
const parts = parsePath(path12);
|
|
6433
6433
|
if (parts.includes("*")) {
|
|
6434
|
-
redactWildcardPath(obj, parts, censor,
|
|
6434
|
+
redactWildcardPath(obj, parts, censor, path12, remove);
|
|
6435
6435
|
} else {
|
|
6436
6436
|
if (remove) {
|
|
6437
6437
|
removeKey(obj, parts);
|
|
@@ -6516,8 +6516,8 @@ var require_redact = __commonJS({
|
|
|
6516
6516
|
}
|
|
6517
6517
|
} else {
|
|
6518
6518
|
if (afterWildcard.includes("*")) {
|
|
6519
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
6520
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
6519
|
+
const wrappedCensor = typeof censor === "function" ? (value, path12) => {
|
|
6520
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path12];
|
|
6521
6521
|
return censor(value, fullPath);
|
|
6522
6522
|
} : censor;
|
|
6523
6523
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -6552,8 +6552,8 @@ var require_redact = __commonJS({
|
|
|
6552
6552
|
return null;
|
|
6553
6553
|
}
|
|
6554
6554
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
6555
|
-
for (const
|
|
6556
|
-
const parts = parsePath(
|
|
6555
|
+
for (const path12 of pathsToClone) {
|
|
6556
|
+
const parts = parsePath(path12);
|
|
6557
6557
|
let current = pathStructure;
|
|
6558
6558
|
for (let i = 0; i < parts.length; i++) {
|
|
6559
6559
|
const part = parts[i];
|
|
@@ -6605,24 +6605,24 @@ var require_redact = __commonJS({
|
|
|
6605
6605
|
}
|
|
6606
6606
|
return cloneSelectively(obj, pathStructure);
|
|
6607
6607
|
}
|
|
6608
|
-
function validatePath(
|
|
6609
|
-
if (typeof
|
|
6608
|
+
function validatePath(path12) {
|
|
6609
|
+
if (typeof path12 !== "string") {
|
|
6610
6610
|
throw new Error("Paths must be (non-empty) strings");
|
|
6611
6611
|
}
|
|
6612
|
-
if (
|
|
6612
|
+
if (path12 === "") {
|
|
6613
6613
|
throw new Error("Invalid redaction path ()");
|
|
6614
6614
|
}
|
|
6615
|
-
if (
|
|
6616
|
-
throw new Error(`Invalid redaction path (${
|
|
6615
|
+
if (path12.includes("..")) {
|
|
6616
|
+
throw new Error(`Invalid redaction path (${path12})`);
|
|
6617
6617
|
}
|
|
6618
|
-
if (
|
|
6619
|
-
throw new Error(`Invalid redaction path (${
|
|
6618
|
+
if (path12.includes(",")) {
|
|
6619
|
+
throw new Error(`Invalid redaction path (${path12})`);
|
|
6620
6620
|
}
|
|
6621
6621
|
let bracketCount = 0;
|
|
6622
6622
|
let inQuotes = false;
|
|
6623
6623
|
let quoteChar = "";
|
|
6624
|
-
for (let i = 0; i <
|
|
6625
|
-
const char =
|
|
6624
|
+
for (let i = 0; i < path12.length; i++) {
|
|
6625
|
+
const char = path12[i];
|
|
6626
6626
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
6627
6627
|
if (!inQuotes) {
|
|
6628
6628
|
inQuotes = true;
|
|
@@ -6636,20 +6636,20 @@ var require_redact = __commonJS({
|
|
|
6636
6636
|
} else if (char === "]" && !inQuotes) {
|
|
6637
6637
|
bracketCount--;
|
|
6638
6638
|
if (bracketCount < 0) {
|
|
6639
|
-
throw new Error(`Invalid redaction path (${
|
|
6639
|
+
throw new Error(`Invalid redaction path (${path12})`);
|
|
6640
6640
|
}
|
|
6641
6641
|
}
|
|
6642
6642
|
}
|
|
6643
6643
|
if (bracketCount !== 0) {
|
|
6644
|
-
throw new Error(`Invalid redaction path (${
|
|
6644
|
+
throw new Error(`Invalid redaction path (${path12})`);
|
|
6645
6645
|
}
|
|
6646
6646
|
}
|
|
6647
6647
|
function validatePaths(paths) {
|
|
6648
6648
|
if (!Array.isArray(paths)) {
|
|
6649
6649
|
throw new TypeError("paths must be an array");
|
|
6650
6650
|
}
|
|
6651
|
-
for (const
|
|
6652
|
-
validatePath(
|
|
6651
|
+
for (const path12 of paths) {
|
|
6652
|
+
validatePath(path12);
|
|
6653
6653
|
}
|
|
6654
6654
|
}
|
|
6655
6655
|
function slowRedact(options = {}) {
|
|
@@ -6817,8 +6817,8 @@ var require_redaction = __commonJS({
|
|
|
6817
6817
|
if (shape[k] === null) {
|
|
6818
6818
|
o[k] = (value) => topCensor(value, [k]);
|
|
6819
6819
|
} else {
|
|
6820
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
6821
|
-
return censor(value, [k, ...
|
|
6820
|
+
const wrappedCensor = typeof censor === "function" ? (value, path12) => {
|
|
6821
|
+
return censor(value, [k, ...path12]);
|
|
6822
6822
|
} : censor;
|
|
6823
6823
|
o[k] = Redact({
|
|
6824
6824
|
paths: shape[k],
|
|
@@ -7036,10 +7036,10 @@ var require_atomic_sleep = __commonJS({
|
|
|
7036
7036
|
var require_sonic_boom = __commonJS({
|
|
7037
7037
|
"node_modules/sonic-boom/index.js"(exports, module) {
|
|
7038
7038
|
"use strict";
|
|
7039
|
-
var
|
|
7039
|
+
var fs8 = __require("fs");
|
|
7040
7040
|
var EventEmitter2 = __require("events");
|
|
7041
7041
|
var inherits = __require("util").inherits;
|
|
7042
|
-
var
|
|
7042
|
+
var path12 = __require("path");
|
|
7043
7043
|
var sleep = require_atomic_sleep();
|
|
7044
7044
|
var assert = __require("assert");
|
|
7045
7045
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -7093,20 +7093,20 @@ var require_sonic_boom = __commonJS({
|
|
|
7093
7093
|
const mode = sonic.mode;
|
|
7094
7094
|
if (sonic.sync) {
|
|
7095
7095
|
try {
|
|
7096
|
-
if (sonic.mkdir)
|
|
7097
|
-
const fd =
|
|
7096
|
+
if (sonic.mkdir) fs8.mkdirSync(path12.dirname(file), { recursive: true });
|
|
7097
|
+
const fd = fs8.openSync(file, flags, mode);
|
|
7098
7098
|
fileOpened(null, fd);
|
|
7099
7099
|
} catch (err) {
|
|
7100
7100
|
fileOpened(err);
|
|
7101
7101
|
throw err;
|
|
7102
7102
|
}
|
|
7103
7103
|
} else if (sonic.mkdir) {
|
|
7104
|
-
|
|
7104
|
+
fs8.mkdir(path12.dirname(file), { recursive: true }, (err) => {
|
|
7105
7105
|
if (err) return fileOpened(err);
|
|
7106
|
-
|
|
7106
|
+
fs8.open(file, flags, mode, fileOpened);
|
|
7107
7107
|
});
|
|
7108
7108
|
} else {
|
|
7109
|
-
|
|
7109
|
+
fs8.open(file, flags, mode, fileOpened);
|
|
7110
7110
|
}
|
|
7111
7111
|
}
|
|
7112
7112
|
function SonicBoom(opts) {
|
|
@@ -7147,8 +7147,8 @@ var require_sonic_boom = __commonJS({
|
|
|
7147
7147
|
this.flush = flushBuffer;
|
|
7148
7148
|
this.flushSync = flushBufferSync;
|
|
7149
7149
|
this._actualWrite = actualWriteBuffer;
|
|
7150
|
-
fsWriteSync = () =>
|
|
7151
|
-
fsWrite = () =>
|
|
7150
|
+
fsWriteSync = () => fs8.writeSync(this.fd, this._writingBuf);
|
|
7151
|
+
fsWrite = () => fs8.write(this.fd, this._writingBuf, this.release);
|
|
7152
7152
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
7153
7153
|
this._writingBuf = "";
|
|
7154
7154
|
this.write = write;
|
|
@@ -7157,15 +7157,15 @@ var require_sonic_boom = __commonJS({
|
|
|
7157
7157
|
this._actualWrite = actualWrite;
|
|
7158
7158
|
fsWriteSync = () => {
|
|
7159
7159
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
7160
|
-
return
|
|
7160
|
+
return fs8.writeSync(this.fd, this._writingBuf);
|
|
7161
7161
|
}
|
|
7162
|
-
return
|
|
7162
|
+
return fs8.writeSync(this.fd, this._writingBuf, "utf8");
|
|
7163
7163
|
};
|
|
7164
7164
|
fsWrite = () => {
|
|
7165
7165
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
7166
|
-
return
|
|
7166
|
+
return fs8.write(this.fd, this._writingBuf, this.release);
|
|
7167
7167
|
}
|
|
7168
|
-
return
|
|
7168
|
+
return fs8.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
7169
7169
|
};
|
|
7170
7170
|
} else {
|
|
7171
7171
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -7222,7 +7222,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7222
7222
|
}
|
|
7223
7223
|
}
|
|
7224
7224
|
if (this._fsync) {
|
|
7225
|
-
|
|
7225
|
+
fs8.fsyncSync(this.fd);
|
|
7226
7226
|
}
|
|
7227
7227
|
const len = this._len;
|
|
7228
7228
|
if (this._reopening) {
|
|
@@ -7336,7 +7336,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7336
7336
|
const onDrain = () => {
|
|
7337
7337
|
if (!this._fsync) {
|
|
7338
7338
|
try {
|
|
7339
|
-
|
|
7339
|
+
fs8.fsync(this.fd, (err) => {
|
|
7340
7340
|
this._flushPending = false;
|
|
7341
7341
|
cb(err);
|
|
7342
7342
|
});
|
|
@@ -7438,7 +7438,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7438
7438
|
const fd = this.fd;
|
|
7439
7439
|
this.once("ready", () => {
|
|
7440
7440
|
if (fd !== this.fd) {
|
|
7441
|
-
|
|
7441
|
+
fs8.close(fd, (err) => {
|
|
7442
7442
|
if (err) {
|
|
7443
7443
|
return this.emit("error", err);
|
|
7444
7444
|
}
|
|
@@ -7487,7 +7487,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7487
7487
|
buf = this._bufs[0];
|
|
7488
7488
|
}
|
|
7489
7489
|
try {
|
|
7490
|
-
const n = Buffer.isBuffer(buf) ?
|
|
7490
|
+
const n = Buffer.isBuffer(buf) ? fs8.writeSync(this.fd, buf) : fs8.writeSync(this.fd, buf, "utf8");
|
|
7491
7491
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
7492
7492
|
buf = releasedBufObj.writingBuf;
|
|
7493
7493
|
this._len = releasedBufObj.len;
|
|
@@ -7503,7 +7503,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7503
7503
|
}
|
|
7504
7504
|
}
|
|
7505
7505
|
try {
|
|
7506
|
-
|
|
7506
|
+
fs8.fsyncSync(this.fd);
|
|
7507
7507
|
} catch {
|
|
7508
7508
|
}
|
|
7509
7509
|
}
|
|
@@ -7524,7 +7524,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7524
7524
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
7525
7525
|
}
|
|
7526
7526
|
try {
|
|
7527
|
-
const n =
|
|
7527
|
+
const n = fs8.writeSync(this.fd, buf);
|
|
7528
7528
|
buf = buf.subarray(n);
|
|
7529
7529
|
this._len = Math.max(this._len - n, 0);
|
|
7530
7530
|
if (buf.length <= 0) {
|
|
@@ -7552,13 +7552,13 @@ var require_sonic_boom = __commonJS({
|
|
|
7552
7552
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
7553
7553
|
if (this.sync) {
|
|
7554
7554
|
try {
|
|
7555
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
7555
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs8.writeSync(this.fd, this._writingBuf) : fs8.writeSync(this.fd, this._writingBuf, "utf8");
|
|
7556
7556
|
release(null, written);
|
|
7557
7557
|
} catch (err) {
|
|
7558
7558
|
release(err);
|
|
7559
7559
|
}
|
|
7560
7560
|
} else {
|
|
7561
|
-
|
|
7561
|
+
fs8.write(this.fd, this._writingBuf, release);
|
|
7562
7562
|
}
|
|
7563
7563
|
}
|
|
7564
7564
|
function actualWriteBuffer() {
|
|
@@ -7567,7 +7567,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7567
7567
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
7568
7568
|
if (this.sync) {
|
|
7569
7569
|
try {
|
|
7570
|
-
const written =
|
|
7570
|
+
const written = fs8.writeSync(this.fd, this._writingBuf);
|
|
7571
7571
|
release(null, written);
|
|
7572
7572
|
} catch (err) {
|
|
7573
7573
|
release(err);
|
|
@@ -7576,7 +7576,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7576
7576
|
if (kCopyBuffer) {
|
|
7577
7577
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
7578
7578
|
}
|
|
7579
|
-
|
|
7579
|
+
fs8.write(this.fd, this._writingBuf, release);
|
|
7580
7580
|
}
|
|
7581
7581
|
}
|
|
7582
7582
|
function actualClose(sonic) {
|
|
@@ -7592,12 +7592,12 @@ var require_sonic_boom = __commonJS({
|
|
|
7592
7592
|
sonic._lens = [];
|
|
7593
7593
|
assert(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
7594
7594
|
try {
|
|
7595
|
-
|
|
7595
|
+
fs8.fsync(sonic.fd, closeWrapped);
|
|
7596
7596
|
} catch {
|
|
7597
7597
|
}
|
|
7598
7598
|
function closeWrapped() {
|
|
7599
7599
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
7600
|
-
|
|
7600
|
+
fs8.close(sonic.fd, done);
|
|
7601
7601
|
} else {
|
|
7602
7602
|
done();
|
|
7603
7603
|
}
|
|
@@ -8433,15 +8433,15 @@ var require_transport = __commonJS({
|
|
|
8433
8433
|
if (!unquoted) {
|
|
8434
8434
|
return false;
|
|
8435
8435
|
}
|
|
8436
|
-
let
|
|
8437
|
-
if (
|
|
8436
|
+
let path12 = unquoted;
|
|
8437
|
+
if (path12.startsWith("file://")) {
|
|
8438
8438
|
try {
|
|
8439
|
-
|
|
8439
|
+
path12 = fileURLToPath3(path12);
|
|
8440
8440
|
} catch {
|
|
8441
8441
|
return false;
|
|
8442
8442
|
}
|
|
8443
8443
|
}
|
|
8444
|
-
return isAbsolute(
|
|
8444
|
+
return isAbsolute(path12) && !existsSync3(path12);
|
|
8445
8445
|
}
|
|
8446
8446
|
function stripQuotes(value) {
|
|
8447
8447
|
const first = value[0];
|
|
@@ -10135,7 +10135,7 @@ var require_multistream = __commonJS({
|
|
|
10135
10135
|
var require_pino = __commonJS({
|
|
10136
10136
|
"node_modules/pino/pino.js"(exports, module) {
|
|
10137
10137
|
"use strict";
|
|
10138
|
-
var
|
|
10138
|
+
var os5 = __require("node:os");
|
|
10139
10139
|
var stdSerializers = require_pino_std_serializers();
|
|
10140
10140
|
var caller = require_caller();
|
|
10141
10141
|
var redaction = require_redaction();
|
|
@@ -10182,7 +10182,7 @@ var require_pino = __commonJS({
|
|
|
10182
10182
|
} = symbols;
|
|
10183
10183
|
var { epochTime, nullTime } = time;
|
|
10184
10184
|
var { pid } = process;
|
|
10185
|
-
var hostname2 =
|
|
10185
|
+
var hostname2 = os5.hostname();
|
|
10186
10186
|
var defaultErrorSerializer = stdSerializers.err;
|
|
10187
10187
|
var defaultOptions = {
|
|
10188
10188
|
level: "info",
|
|
@@ -11882,7 +11882,7 @@ var require_reply = __commonJS({
|
|
|
11882
11882
|
let handled = 0;
|
|
11883
11883
|
let skipped = true;
|
|
11884
11884
|
let sent = false;
|
|
11885
|
-
function
|
|
11885
|
+
function send2() {
|
|
11886
11886
|
if (handled === 0 && !sent) {
|
|
11887
11887
|
sent = true;
|
|
11888
11888
|
res.addTrailers(trailers);
|
|
@@ -11896,7 +11896,7 @@ var require_reply = __commonJS({
|
|
|
11896
11896
|
handled++;
|
|
11897
11897
|
if (err) reply.log.debug(err);
|
|
11898
11898
|
else trailers[trailerName] = value;
|
|
11899
|
-
process.nextTick(
|
|
11899
|
+
process.nextTick(send2);
|
|
11900
11900
|
};
|
|
11901
11901
|
if (typeof reply[kReplyTrailers][trailerName] !== "function") continue;
|
|
11902
11902
|
skipped = false;
|
|
@@ -17117,8 +17117,8 @@ var require_utils = __commonJS({
|
|
|
17117
17117
|
}
|
|
17118
17118
|
return ind;
|
|
17119
17119
|
}
|
|
17120
|
-
function removeDotSegments(
|
|
17121
|
-
let input =
|
|
17120
|
+
function removeDotSegments(path12) {
|
|
17121
|
+
let input = path12;
|
|
17122
17122
|
const output = [];
|
|
17123
17123
|
let nextSlash = -1;
|
|
17124
17124
|
let len = 0;
|
|
@@ -17370,8 +17370,8 @@ var require_schemes = __commonJS({
|
|
|
17370
17370
|
wsComponent.secure = void 0;
|
|
17371
17371
|
}
|
|
17372
17372
|
if (wsComponent.resourceName) {
|
|
17373
|
-
const [
|
|
17374
|
-
wsComponent.path =
|
|
17373
|
+
const [path12, query2] = wsComponent.resourceName.split("?");
|
|
17374
|
+
wsComponent.path = path12 && path12 !== "/" ? path12 : void 0;
|
|
17375
17375
|
wsComponent.query = query2;
|
|
17376
17376
|
wsComponent.resourceName = void 0;
|
|
17377
17377
|
}
|
|
@@ -17457,7 +17457,7 @@ var require_schemes = __commonJS({
|
|
|
17457
17457
|
serialize: wsSerialize
|
|
17458
17458
|
}
|
|
17459
17459
|
);
|
|
17460
|
-
var
|
|
17460
|
+
var wss3 = (
|
|
17461
17461
|
/** @type {SchemeHandler} */
|
|
17462
17462
|
{
|
|
17463
17463
|
scheme: "wss",
|
|
@@ -17490,7 +17490,7 @@ var require_schemes = __commonJS({
|
|
|
17490
17490
|
http: http3,
|
|
17491
17491
|
https,
|
|
17492
17492
|
ws,
|
|
17493
|
-
wss:
|
|
17493
|
+
wss: wss3,
|
|
17494
17494
|
urn,
|
|
17495
17495
|
"urn:uuid": urnuuid
|
|
17496
17496
|
}
|
|
@@ -22308,8 +22308,8 @@ var require_utils2 = __commonJS({
|
|
|
22308
22308
|
}
|
|
22309
22309
|
return ind;
|
|
22310
22310
|
}
|
|
22311
|
-
function removeDotSegments(
|
|
22312
|
-
let input =
|
|
22311
|
+
function removeDotSegments(path12) {
|
|
22312
|
+
let input = path12;
|
|
22313
22313
|
const output = [];
|
|
22314
22314
|
let nextSlash = -1;
|
|
22315
22315
|
let len = 0;
|
|
@@ -22654,8 +22654,8 @@ var require_schemes2 = __commonJS({
|
|
|
22654
22654
|
wsComponent.secure = void 0;
|
|
22655
22655
|
}
|
|
22656
22656
|
if (wsComponent.resourceName) {
|
|
22657
|
-
const [
|
|
22658
|
-
wsComponent.path =
|
|
22657
|
+
const [path12, query2] = wsComponent.resourceName.split("?");
|
|
22658
|
+
wsComponent.path = path12 && path12 !== "/" ? path12 : void 0;
|
|
22659
22659
|
wsComponent.query = query2;
|
|
22660
22660
|
wsComponent.resourceName = void 0;
|
|
22661
22661
|
}
|
|
@@ -22741,7 +22741,7 @@ var require_schemes2 = __commonJS({
|
|
|
22741
22741
|
serialize: wsSerialize
|
|
22742
22742
|
}
|
|
22743
22743
|
);
|
|
22744
|
-
var
|
|
22744
|
+
var wss3 = (
|
|
22745
22745
|
/** @type {SchemeHandler} */
|
|
22746
22746
|
{
|
|
22747
22747
|
scheme: "wss",
|
|
@@ -22774,7 +22774,7 @@ var require_schemes2 = __commonJS({
|
|
|
22774
22774
|
http: http3,
|
|
22775
22775
|
https,
|
|
22776
22776
|
ws,
|
|
22777
|
-
wss:
|
|
22777
|
+
wss: wss3,
|
|
22778
22778
|
urn,
|
|
22779
22779
|
"urn:uuid": urnuuid
|
|
22780
22780
|
}
|
|
@@ -23431,12 +23431,12 @@ var require_dist = __commonJS({
|
|
|
23431
23431
|
throw new Error(`Unknown format "${name}"`);
|
|
23432
23432
|
return f;
|
|
23433
23433
|
};
|
|
23434
|
-
function addFormats(ajv, list,
|
|
23434
|
+
function addFormats(ajv, list, fs8, exportName) {
|
|
23435
23435
|
var _a;
|
|
23436
23436
|
var _b;
|
|
23437
23437
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
23438
23438
|
for (const f of list)
|
|
23439
|
-
ajv.addFormat(f,
|
|
23439
|
+
ajv.addFormat(f, fs8[f]);
|
|
23440
23440
|
}
|
|
23441
23441
|
module.exports = exports = formatsPlugin;
|
|
23442
23442
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -24139,8 +24139,8 @@ var require_utils3 = __commonJS({
|
|
|
24139
24139
|
}
|
|
24140
24140
|
return ind;
|
|
24141
24141
|
}
|
|
24142
|
-
function removeDotSegments(
|
|
24143
|
-
let input =
|
|
24142
|
+
function removeDotSegments(path12) {
|
|
24143
|
+
let input = path12;
|
|
24144
24144
|
const output = [];
|
|
24145
24145
|
let nextSlash = -1;
|
|
24146
24146
|
let len = 0;
|
|
@@ -24485,8 +24485,8 @@ var require_schemes3 = __commonJS({
|
|
|
24485
24485
|
wsComponent.secure = void 0;
|
|
24486
24486
|
}
|
|
24487
24487
|
if (wsComponent.resourceName) {
|
|
24488
|
-
const [
|
|
24489
|
-
wsComponent.path =
|
|
24488
|
+
const [path12, query2] = wsComponent.resourceName.split("?");
|
|
24489
|
+
wsComponent.path = path12 && path12 !== "/" ? path12 : void 0;
|
|
24490
24490
|
wsComponent.query = query2;
|
|
24491
24491
|
wsComponent.resourceName = void 0;
|
|
24492
24492
|
}
|
|
@@ -24572,7 +24572,7 @@ var require_schemes3 = __commonJS({
|
|
|
24572
24572
|
serialize: wsSerialize
|
|
24573
24573
|
}
|
|
24574
24574
|
);
|
|
24575
|
-
var
|
|
24575
|
+
var wss3 = (
|
|
24576
24576
|
/** @type {SchemeHandler} */
|
|
24577
24577
|
{
|
|
24578
24578
|
scheme: "wss",
|
|
@@ -24605,7 +24605,7 @@ var require_schemes3 = __commonJS({
|
|
|
24605
24605
|
http: http3,
|
|
24606
24606
|
https,
|
|
24607
24607
|
ws,
|
|
24608
|
-
wss:
|
|
24608
|
+
wss: wss3,
|
|
24609
24609
|
urn,
|
|
24610
24610
|
"urn:uuid": urnuuid
|
|
24611
24611
|
}
|
|
@@ -32003,13 +32003,13 @@ var require_node = __commonJS({
|
|
|
32003
32003
|
this.staticChildrenNodes[index] = node;
|
|
32004
32004
|
}
|
|
32005
32005
|
}
|
|
32006
|
-
findStaticMatchingChild(
|
|
32007
|
-
const charCode =
|
|
32006
|
+
findStaticMatchingChild(path12, pathIndex) {
|
|
32007
|
+
const charCode = path12.charCodeAt(pathIndex);
|
|
32008
32008
|
const charCodes = this.staticChildrenCharCodes;
|
|
32009
32009
|
for (let i = 0; i < charCodes.length; i++) {
|
|
32010
32010
|
if (charCodes[i] === charCode) {
|
|
32011
32011
|
const staticChild = this.staticChildrenNodes[i];
|
|
32012
|
-
if (staticChild.matchPrefix(
|
|
32012
|
+
if (staticChild.matchPrefix(path12, pathIndex)) {
|
|
32013
32013
|
return staticChild;
|
|
32014
32014
|
}
|
|
32015
32015
|
return null;
|
|
@@ -32017,34 +32017,34 @@ var require_node = __commonJS({
|
|
|
32017
32017
|
}
|
|
32018
32018
|
return null;
|
|
32019
32019
|
}
|
|
32020
|
-
getStaticChild(
|
|
32021
|
-
if (
|
|
32020
|
+
getStaticChild(path12, pathIndex = 0) {
|
|
32021
|
+
if (path12.length === pathIndex) {
|
|
32022
32022
|
return this;
|
|
32023
32023
|
}
|
|
32024
|
-
const staticChild = this.findStaticMatchingChild(
|
|
32024
|
+
const staticChild = this.findStaticMatchingChild(path12, pathIndex);
|
|
32025
32025
|
if (staticChild) {
|
|
32026
|
-
return staticChild.getStaticChild(
|
|
32026
|
+
return staticChild.getStaticChild(path12, pathIndex + staticChild.prefix.length);
|
|
32027
32027
|
}
|
|
32028
32028
|
return null;
|
|
32029
32029
|
}
|
|
32030
|
-
createStaticChild(
|
|
32031
|
-
if (
|
|
32030
|
+
createStaticChild(path12) {
|
|
32031
|
+
if (path12.length === 0) {
|
|
32032
32032
|
return this;
|
|
32033
32033
|
}
|
|
32034
|
-
const childIndex = this.staticChildrenCharCodes.indexOf(
|
|
32034
|
+
const childIndex = this.staticChildrenCharCodes.indexOf(path12.charCodeAt(0));
|
|
32035
32035
|
let staticChild = childIndex === -1 ? void 0 : this.staticChildrenNodes[childIndex];
|
|
32036
32036
|
if (staticChild) {
|
|
32037
32037
|
let i = 1;
|
|
32038
32038
|
for (; i < staticChild.prefix.length; i++) {
|
|
32039
|
-
if (
|
|
32039
|
+
if (path12.charCodeAt(i) !== staticChild.prefix.charCodeAt(i)) {
|
|
32040
32040
|
staticChild = staticChild.split(this, i);
|
|
32041
32041
|
break;
|
|
32042
32042
|
}
|
|
32043
32043
|
}
|
|
32044
|
-
return staticChild.createStaticChild(
|
|
32044
|
+
return staticChild.createStaticChild(path12.slice(i));
|
|
32045
32045
|
}
|
|
32046
|
-
const node = new StaticNode(
|
|
32047
|
-
this.setStaticChild(
|
|
32046
|
+
const node = new StaticNode(path12);
|
|
32047
|
+
this.setStaticChild(path12.charAt(0), node);
|
|
32048
32048
|
return node;
|
|
32049
32049
|
}
|
|
32050
32050
|
};
|
|
@@ -32104,8 +32104,8 @@ var require_node = __commonJS({
|
|
|
32104
32104
|
parentNode.setStaticChild(parentPrefix.charAt(0), staticNode);
|
|
32105
32105
|
return staticNode;
|
|
32106
32106
|
}
|
|
32107
|
-
getNextNode(
|
|
32108
|
-
let node = this.findStaticMatchingChild(
|
|
32107
|
+
getNextNode(path12, pathIndex, nodeStack, paramsCount) {
|
|
32108
|
+
let node = this.findStaticMatchingChild(path12, pathIndex);
|
|
32109
32109
|
let parametricBrotherNodeIndex = 0;
|
|
32110
32110
|
if (node === null) {
|
|
32111
32111
|
if (this.parametricChildren.length === 0) {
|
|
@@ -32152,8 +32152,8 @@ var require_node = __commonJS({
|
|
|
32152
32152
|
this.kind = NODE_TYPES.PARAMETRIC;
|
|
32153
32153
|
this.nodePaths = /* @__PURE__ */ new Set([nodePath2]);
|
|
32154
32154
|
}
|
|
32155
|
-
getNextNode(
|
|
32156
|
-
return this.findStaticMatchingChild(
|
|
32155
|
+
getNextNode(path12, pathIndex) {
|
|
32156
|
+
return this.findStaticMatchingChild(path12, pathIndex);
|
|
32157
32157
|
}
|
|
32158
32158
|
};
|
|
32159
32159
|
var WildcardNode = class extends Node {
|
|
@@ -32509,81 +32509,81 @@ var require_url_sanitizer = __commonJS({
|
|
|
32509
32509
|
return String.fromCharCode(charCode);
|
|
32510
32510
|
}
|
|
32511
32511
|
var MIN_NATIVE_SCAN_LENGTH = 12;
|
|
32512
|
-
function safeDecodeURI(
|
|
32513
|
-
if (
|
|
32514
|
-
return safeDecodeURINativeScan(
|
|
32512
|
+
function safeDecodeURI(path12, useSemicolonDelimiter) {
|
|
32513
|
+
if (path12.length >= MIN_NATIVE_SCAN_LENGTH) {
|
|
32514
|
+
return safeDecodeURINativeScan(path12, useSemicolonDelimiter);
|
|
32515
32515
|
}
|
|
32516
|
-
return safeDecodeURICharScan(
|
|
32516
|
+
return safeDecodeURICharScan(path12, useSemicolonDelimiter, 1);
|
|
32517
32517
|
}
|
|
32518
|
-
function safeDecodeURINativeScan(
|
|
32519
|
-
const percentIndex =
|
|
32520
|
-
let delimIndex =
|
|
32521
|
-
const hashIndex =
|
|
32518
|
+
function safeDecodeURINativeScan(path12, useSemicolonDelimiter) {
|
|
32519
|
+
const percentIndex = path12.indexOf("%", 1);
|
|
32520
|
+
let delimIndex = path12.indexOf("?", 1);
|
|
32521
|
+
const hashIndex = path12.indexOf("#", 1);
|
|
32522
32522
|
if (hashIndex !== -1 && (delimIndex === -1 || hashIndex < delimIndex)) {
|
|
32523
32523
|
delimIndex = hashIndex;
|
|
32524
32524
|
}
|
|
32525
32525
|
if (useSemicolonDelimiter) {
|
|
32526
|
-
const semicolonIndex =
|
|
32526
|
+
const semicolonIndex = path12.indexOf(";", 1);
|
|
32527
32527
|
if (semicolonIndex !== -1 && (delimIndex === -1 || semicolonIndex < delimIndex)) {
|
|
32528
32528
|
delimIndex = semicolonIndex;
|
|
32529
32529
|
}
|
|
32530
32530
|
}
|
|
32531
32531
|
if (percentIndex === -1 || delimIndex !== -1 && percentIndex > delimIndex) {
|
|
32532
32532
|
if (delimIndex === -1) {
|
|
32533
|
-
return { path:
|
|
32533
|
+
return { path: path12, querystring: "", shouldDecodeParam: false };
|
|
32534
32534
|
}
|
|
32535
32535
|
return {
|
|
32536
|
-
path:
|
|
32537
|
-
querystring:
|
|
32536
|
+
path: path12.slice(0, delimIndex),
|
|
32537
|
+
querystring: path12.slice(delimIndex + 1),
|
|
32538
32538
|
shouldDecodeParam: false
|
|
32539
32539
|
};
|
|
32540
32540
|
}
|
|
32541
|
-
return safeDecodeURIPercentScan(
|
|
32541
|
+
return safeDecodeURIPercentScan(path12, useSemicolonDelimiter, percentIndex);
|
|
32542
32542
|
}
|
|
32543
|
-
function safeDecodeURICharScan(
|
|
32544
|
-
for (let i = startIndex; i <
|
|
32545
|
-
const charCode =
|
|
32543
|
+
function safeDecodeURICharScan(path12, useSemicolonDelimiter, startIndex) {
|
|
32544
|
+
for (let i = startIndex; i < path12.length; i++) {
|
|
32545
|
+
const charCode = path12.charCodeAt(i);
|
|
32546
32546
|
if (charCode === 37) {
|
|
32547
|
-
return safeDecodeURIPercentScan(
|
|
32547
|
+
return safeDecodeURIPercentScan(path12, useSemicolonDelimiter, i);
|
|
32548
32548
|
} else if (charCode === 63 || charCode === 35 || charCode === 59 && useSemicolonDelimiter) {
|
|
32549
32549
|
return {
|
|
32550
|
-
path:
|
|
32551
|
-
querystring:
|
|
32550
|
+
path: path12.slice(0, i),
|
|
32551
|
+
querystring: path12.slice(i + 1),
|
|
32552
32552
|
shouldDecodeParam: false
|
|
32553
32553
|
};
|
|
32554
32554
|
}
|
|
32555
32555
|
}
|
|
32556
|
-
return { path:
|
|
32556
|
+
return { path: path12, querystring: "", shouldDecodeParam: false };
|
|
32557
32557
|
}
|
|
32558
|
-
function reencodePercentChar(
|
|
32559
|
-
return
|
|
32558
|
+
function reencodePercentChar(path12, index) {
|
|
32559
|
+
return path12.slice(0, index + 1) + "25" + path12.slice(index + 1);
|
|
32560
32560
|
}
|
|
32561
|
-
function safeDecodeURIPercentScan(
|
|
32561
|
+
function safeDecodeURIPercentScan(path12, useSemicolonDelimiter, startIndex) {
|
|
32562
32562
|
let shouldDecode = false;
|
|
32563
32563
|
let shouldDecodeParam = false;
|
|
32564
32564
|
let querystring = "";
|
|
32565
|
-
for (let i = startIndex; i <
|
|
32566
|
-
const charCode =
|
|
32565
|
+
for (let i = startIndex; i < path12.length; i++) {
|
|
32566
|
+
const charCode = path12.charCodeAt(i);
|
|
32567
32567
|
if (charCode === 37) {
|
|
32568
|
-
const componentCharCode = decodeComponentCharCode(
|
|
32568
|
+
const componentCharCode = decodeComponentCharCode(path12.charCodeAt(i + 1), path12.charCodeAt(i + 2));
|
|
32569
32569
|
if (componentCharCode === 0) {
|
|
32570
32570
|
shouldDecode = true;
|
|
32571
32571
|
} else {
|
|
32572
32572
|
shouldDecodeParam = true;
|
|
32573
32573
|
if (componentCharCode === 37) {
|
|
32574
32574
|
shouldDecode = true;
|
|
32575
|
-
|
|
32575
|
+
path12 = reencodePercentChar(path12, i);
|
|
32576
32576
|
i += 2;
|
|
32577
32577
|
}
|
|
32578
32578
|
i += 2;
|
|
32579
32579
|
}
|
|
32580
32580
|
} else if (charCode === 63 || charCode === 35 || charCode === 59 && useSemicolonDelimiter) {
|
|
32581
|
-
querystring =
|
|
32582
|
-
|
|
32581
|
+
querystring = path12.slice(i + 1);
|
|
32582
|
+
path12 = path12.slice(0, i);
|
|
32583
32583
|
break;
|
|
32584
32584
|
}
|
|
32585
32585
|
}
|
|
32586
|
-
const decodedPath = shouldDecode ? decodeURI(
|
|
32586
|
+
const decodedPath = shouldDecode ? decodeURI(path12) : path12;
|
|
32587
32587
|
return { path: decodedPath, querystring, shouldDecodeParam };
|
|
32588
32588
|
}
|
|
32589
32589
|
function safeDecodeURIComponent(uriComponent) {
|
|
@@ -32678,7 +32678,7 @@ var require_find_my_way = __commonJS({
|
|
|
32678
32678
|
this.trees = /* @__PURE__ */ Object.create(null);
|
|
32679
32679
|
this._treeGET = null;
|
|
32680
32680
|
}
|
|
32681
|
-
Router.prototype.on = function on(method,
|
|
32681
|
+
Router.prototype.on = function on(method, path12, opts, handler, store) {
|
|
32682
32682
|
if (typeof opts === "function") {
|
|
32683
32683
|
if (handler !== void 0) {
|
|
32684
32684
|
store = handler;
|
|
@@ -32686,34 +32686,34 @@ var require_find_my_way = __commonJS({
|
|
|
32686
32686
|
handler = opts;
|
|
32687
32687
|
opts = {};
|
|
32688
32688
|
}
|
|
32689
|
-
assert(typeof
|
|
32690
|
-
assert(
|
|
32691
|
-
assert(
|
|
32689
|
+
assert(typeof path12 === "string", "Path should be a string");
|
|
32690
|
+
assert(path12.length > 0, "The path could not be empty");
|
|
32691
|
+
assert(path12[0] === "/" || path12[0] === "*", "The first character of a path should be `/` or `*`");
|
|
32692
32692
|
assert(typeof handler === "function", "Handler should be a function");
|
|
32693
|
-
const optionalParamMatch =
|
|
32693
|
+
const optionalParamMatch = path12.match(OPTIONAL_PARAM_REGEXP);
|
|
32694
32694
|
if (optionalParamMatch) {
|
|
32695
|
-
assert(
|
|
32696
|
-
const pathFull =
|
|
32697
|
-
const pathOptional =
|
|
32695
|
+
assert(path12.length === optionalParamMatch.index + optionalParamMatch[0].length, "Optional Parameter needs to be the last parameter of the path");
|
|
32696
|
+
const pathFull = path12.replace(OPTIONAL_PARAM_REGEXP, "$1$2");
|
|
32697
|
+
const pathOptional = path12.replace(OPTIONAL_PARAM_REGEXP, "$2") || "/";
|
|
32698
32698
|
this.on(method, pathFull, opts, handler, store);
|
|
32699
32699
|
this.on(method, pathOptional, opts, handler, store);
|
|
32700
32700
|
return;
|
|
32701
32701
|
}
|
|
32702
|
-
const route =
|
|
32702
|
+
const route = path12;
|
|
32703
32703
|
if (this.ignoreDuplicateSlashes) {
|
|
32704
|
-
|
|
32704
|
+
path12 = removeDuplicateSlashes(path12);
|
|
32705
32705
|
}
|
|
32706
32706
|
if (this.ignoreTrailingSlash) {
|
|
32707
|
-
|
|
32707
|
+
path12 = trimLastSlash(path12);
|
|
32708
32708
|
}
|
|
32709
32709
|
const methods = Array.isArray(method) ? method : [method];
|
|
32710
32710
|
for (const method2 of methods) {
|
|
32711
32711
|
assert(typeof method2 === "string", "Method should be a string");
|
|
32712
32712
|
assert(httpMethods.includes(method2), `Method '${method2}' is not an http method.`);
|
|
32713
|
-
this._on(method2,
|
|
32713
|
+
this._on(method2, path12, opts, handler, store, route);
|
|
32714
32714
|
}
|
|
32715
32715
|
};
|
|
32716
|
-
Router.prototype._on = function _on(method,
|
|
32716
|
+
Router.prototype._on = function _on(method, path12, opts, handler, store) {
|
|
32717
32717
|
let constraints = {};
|
|
32718
32718
|
if (opts.constraints !== void 0) {
|
|
32719
32719
|
assert(typeof opts.constraints === "object" && opts.constraints !== null, "Constraints should be an object");
|
|
@@ -32726,7 +32726,7 @@ var require_find_my_way = __commonJS({
|
|
|
32726
32726
|
if (this.trees[method] === void 0) {
|
|
32727
32727
|
this.trees[method] = new StaticNode("/");
|
|
32728
32728
|
}
|
|
32729
|
-
let pattern =
|
|
32729
|
+
let pattern = path12;
|
|
32730
32730
|
if (pattern === "*" && this.trees[method].prefix.length !== 0) {
|
|
32731
32731
|
const currentRoot = this.trees[method];
|
|
32732
32732
|
this.trees[method] = new StaticNode("");
|
|
@@ -32834,19 +32834,19 @@ var require_find_my_way = __commonJS({
|
|
|
32834
32834
|
throw new Error(`Method '${method}' already declared for route '${pattern}' with constraints '${JSON.stringify(constraints)}'`);
|
|
32835
32835
|
}
|
|
32836
32836
|
}
|
|
32837
|
-
const route = { method, path:
|
|
32837
|
+
const route = { method, path: path12, pattern, params, opts, handler, store };
|
|
32838
32838
|
this.routes.push(route);
|
|
32839
32839
|
currentNode.addRoute(route, this.constrainer);
|
|
32840
32840
|
};
|
|
32841
|
-
Router.prototype.hasRoute = function hasRoute(method,
|
|
32842
|
-
const route = this.findRoute(method,
|
|
32841
|
+
Router.prototype.hasRoute = function hasRoute(method, path12, constraints) {
|
|
32842
|
+
const route = this.findRoute(method, path12, constraints);
|
|
32843
32843
|
return route !== null;
|
|
32844
32844
|
};
|
|
32845
|
-
Router.prototype.findRoute = function findNode(method,
|
|
32845
|
+
Router.prototype.findRoute = function findNode(method, path12, constraints = {}) {
|
|
32846
32846
|
if (this.trees[method] === void 0) {
|
|
32847
32847
|
return null;
|
|
32848
32848
|
}
|
|
32849
|
-
let pattern =
|
|
32849
|
+
let pattern = path12;
|
|
32850
32850
|
let currentNode = this.trees[method];
|
|
32851
32851
|
let parentNodePathIndex = currentNode.prefix.length;
|
|
32852
32852
|
const params = [];
|
|
@@ -32967,39 +32967,39 @@ var require_find_my_way = __commonJS({
|
|
|
32967
32967
|
this._treeGET = null;
|
|
32968
32968
|
this.routes = [];
|
|
32969
32969
|
};
|
|
32970
|
-
Router.prototype.off = function off(method,
|
|
32971
|
-
assert(typeof
|
|
32972
|
-
assert(
|
|
32973
|
-
assert(
|
|
32970
|
+
Router.prototype.off = function off(method, path12, constraints) {
|
|
32971
|
+
assert(typeof path12 === "string", "Path should be a string");
|
|
32972
|
+
assert(path12.length > 0, "The path could not be empty");
|
|
32973
|
+
assert(path12[0] === "/" || path12[0] === "*", "The first character of a path should be `/` or `*`");
|
|
32974
32974
|
assert(
|
|
32975
32975
|
typeof constraints === "undefined" || typeof constraints === "object" && !Array.isArray(constraints) && constraints !== null,
|
|
32976
32976
|
"Constraints should be an object or undefined."
|
|
32977
32977
|
);
|
|
32978
|
-
const optionalParamMatch =
|
|
32978
|
+
const optionalParamMatch = path12.match(OPTIONAL_PARAM_REGEXP);
|
|
32979
32979
|
if (optionalParamMatch) {
|
|
32980
|
-
assert(
|
|
32981
|
-
const pathFull =
|
|
32982
|
-
const pathOptional =
|
|
32980
|
+
assert(path12.length === optionalParamMatch.index + optionalParamMatch[0].length, "Optional Parameter needs to be the last parameter of the path");
|
|
32981
|
+
const pathFull = path12.replace(OPTIONAL_PARAM_REGEXP, "$1$2");
|
|
32982
|
+
const pathOptional = path12.replace(OPTIONAL_PARAM_REGEXP, "$2") || "/";
|
|
32983
32983
|
this.off(method, pathFull, constraints);
|
|
32984
32984
|
this.off(method, pathOptional, constraints);
|
|
32985
32985
|
return;
|
|
32986
32986
|
}
|
|
32987
32987
|
if (this.ignoreDuplicateSlashes) {
|
|
32988
|
-
|
|
32988
|
+
path12 = removeDuplicateSlashes(path12);
|
|
32989
32989
|
}
|
|
32990
32990
|
if (this.ignoreTrailingSlash) {
|
|
32991
|
-
|
|
32991
|
+
path12 = trimLastSlash(path12);
|
|
32992
32992
|
}
|
|
32993
32993
|
const methods = Array.isArray(method) ? method : [method];
|
|
32994
32994
|
for (const method2 of methods) {
|
|
32995
|
-
this._off(method2,
|
|
32995
|
+
this._off(method2, path12, constraints);
|
|
32996
32996
|
}
|
|
32997
32997
|
};
|
|
32998
|
-
Router.prototype._off = function _off(method,
|
|
32998
|
+
Router.prototype._off = function _off(method, path12, constraints) {
|
|
32999
32999
|
assert(typeof method === "string", "Method should be a string");
|
|
33000
33000
|
assert(httpMethods.includes(method), `Method '${method}' is not an http method.`);
|
|
33001
33001
|
function matcherWithoutConstraints(route) {
|
|
33002
|
-
return method !== route.method ||
|
|
33002
|
+
return method !== route.method || path12 !== route.path;
|
|
33003
33003
|
}
|
|
33004
33004
|
function matcherWithConstraints(route) {
|
|
33005
33005
|
return matcherWithoutConstraints(route) || !deepEqual(constraints, route.opts.constraints || {});
|
|
@@ -33036,37 +33036,37 @@ var require_find_my_way = __commonJS({
|
|
|
33036
33036
|
if (handle === null) return this._defaultRoute(req, res, ctx);
|
|
33037
33037
|
return ctx === void 0 ? handle.handler(req, res, handle.params, handle.store, handle.searchParams) : handle.handler.call(ctx, req, res, handle.params, handle.store, handle.searchParams);
|
|
33038
33038
|
};
|
|
33039
|
-
Router.prototype.find = function find(method,
|
|
33039
|
+
Router.prototype.find = function find(method, path12, derivedConstraints) {
|
|
33040
33040
|
let currentNode = method === "GET" ? this._treeGET : this.trees[method];
|
|
33041
33041
|
if (currentNode == null) return null;
|
|
33042
|
-
if (
|
|
33043
|
-
|
|
33042
|
+
if (path12.charCodeAt(0) !== 47) {
|
|
33043
|
+
path12 = path12.replace(FULL_PATH_REGEXP, "/");
|
|
33044
33044
|
}
|
|
33045
33045
|
if (this.ignoreDuplicateSlashes) {
|
|
33046
|
-
|
|
33046
|
+
path12 = removeDuplicateSlashes(path12);
|
|
33047
33047
|
}
|
|
33048
33048
|
let sanitizedUrl;
|
|
33049
33049
|
let querystring2;
|
|
33050
33050
|
let shouldDecodeParam;
|
|
33051
33051
|
try {
|
|
33052
|
-
sanitizedUrl =
|
|
33053
|
-
|
|
33052
|
+
sanitizedUrl = path12.length >= MIN_NATIVE_SCAN_LENGTH ? safeDecodeURINativeScan(path12, this.useSemicolonDelimiter) : safeDecodeURICharScan(path12, this.useSemicolonDelimiter, 1);
|
|
33053
|
+
path12 = sanitizedUrl.path;
|
|
33054
33054
|
querystring2 = sanitizedUrl.querystring;
|
|
33055
33055
|
shouldDecodeParam = sanitizedUrl.shouldDecodeParam;
|
|
33056
33056
|
} catch (error) {
|
|
33057
|
-
return this._onBadUrl(
|
|
33057
|
+
return this._onBadUrl(path12);
|
|
33058
33058
|
}
|
|
33059
33059
|
if (this.ignoreTrailingSlash) {
|
|
33060
|
-
|
|
33060
|
+
path12 = trimLastSlash(path12);
|
|
33061
33061
|
}
|
|
33062
|
-
const originPath =
|
|
33062
|
+
const originPath = path12;
|
|
33063
33063
|
if (this.caseSensitive === false) {
|
|
33064
|
-
|
|
33064
|
+
path12 = path12.toLowerCase();
|
|
33065
33065
|
}
|
|
33066
33066
|
const maxParamLength = this.maxParamLength;
|
|
33067
33067
|
let pathIndex = currentNode.prefix.length;
|
|
33068
33068
|
const params = [];
|
|
33069
|
-
const pathLen =
|
|
33069
|
+
const pathLen = path12.length;
|
|
33070
33070
|
const brothersNodesStack = [];
|
|
33071
33071
|
let maxParamLengthExceeded = false;
|
|
33072
33072
|
while (true) {
|
|
@@ -33081,7 +33081,7 @@ var require_find_my_way = __commonJS({
|
|
|
33081
33081
|
};
|
|
33082
33082
|
}
|
|
33083
33083
|
}
|
|
33084
|
-
let node = currentNode.getNextNode(
|
|
33084
|
+
let node = currentNode.getNextNode(path12, pathIndex, brothersNodesStack, params.length);
|
|
33085
33085
|
if (node === null) {
|
|
33086
33086
|
if (brothersNodesStack.length === 0) {
|
|
33087
33087
|
if (maxParamLengthExceeded && this.onMaxParamLength) {
|
|
@@ -33182,8 +33182,8 @@ var require_find_my_way = __commonJS({
|
|
|
33182
33182
|
Router.prototype._rebuild = function(routes) {
|
|
33183
33183
|
this.reset();
|
|
33184
33184
|
for (const route of routes) {
|
|
33185
|
-
const { method, path:
|
|
33186
|
-
this._on(method,
|
|
33185
|
+
const { method, path: path12, opts, handler, store } = route;
|
|
33186
|
+
this._on(method, path12, opts, handler, store);
|
|
33187
33187
|
}
|
|
33188
33188
|
};
|
|
33189
33189
|
Router.prototype._defaultRoute = function(req, res, ctx) {
|
|
@@ -33194,24 +33194,24 @@ var require_find_my_way = __commonJS({
|
|
|
33194
33194
|
res.end();
|
|
33195
33195
|
}
|
|
33196
33196
|
};
|
|
33197
|
-
Router.prototype._onBadUrl = function(
|
|
33197
|
+
Router.prototype._onBadUrl = function(path12) {
|
|
33198
33198
|
if (this.onBadUrl === null) {
|
|
33199
33199
|
return null;
|
|
33200
33200
|
}
|
|
33201
33201
|
const onBadUrl = this.onBadUrl;
|
|
33202
33202
|
return {
|
|
33203
|
-
handler: (req, res, ctx) => onBadUrl(
|
|
33203
|
+
handler: (req, res, ctx) => onBadUrl(path12, req, res),
|
|
33204
33204
|
params: {},
|
|
33205
33205
|
store: null
|
|
33206
33206
|
};
|
|
33207
33207
|
};
|
|
33208
|
-
Router.prototype._onMaxParamLength = function(
|
|
33208
|
+
Router.prototype._onMaxParamLength = function(path12) {
|
|
33209
33209
|
if (this.onMaxParamLength === null) {
|
|
33210
33210
|
return null;
|
|
33211
33211
|
}
|
|
33212
33212
|
const onMaxParamLength = this.onMaxParamLength;
|
|
33213
33213
|
return {
|
|
33214
|
-
handler: (req, res, ctx) => onMaxParamLength(
|
|
33214
|
+
handler: (req, res, ctx) => onMaxParamLength(path12, req, res),
|
|
33215
33215
|
params: {},
|
|
33216
33216
|
store: null
|
|
33217
33217
|
};
|
|
@@ -33243,12 +33243,12 @@ var require_find_my_way = __commonJS({
|
|
|
33243
33243
|
if (!httpMethods.hasOwnProperty(i)) continue;
|
|
33244
33244
|
const m = httpMethods[i];
|
|
33245
33245
|
const methodName = m.toLowerCase();
|
|
33246
|
-
Router.prototype[methodName] = function(
|
|
33247
|
-
return this.on(m,
|
|
33246
|
+
Router.prototype[methodName] = function(path12, handler, store) {
|
|
33247
|
+
return this.on(m, path12, handler, store);
|
|
33248
33248
|
};
|
|
33249
33249
|
}
|
|
33250
|
-
Router.prototype.all = function(
|
|
33251
|
-
this.on(httpMethods,
|
|
33250
|
+
Router.prototype.all = function(path12, handler, store) {
|
|
33251
|
+
this.on(httpMethods, path12, handler, store);
|
|
33252
33252
|
};
|
|
33253
33253
|
Router.sanitizeUrlPath = function sanitizeUrlPath(url, useSemicolonDelimiter) {
|
|
33254
33254
|
const decoded = safeDecodeURI(url, useSemicolonDelimiter);
|
|
@@ -33263,14 +33263,14 @@ var require_find_my_way = __commonJS({
|
|
|
33263
33263
|
function escapeRegExp(string) {
|
|
33264
33264
|
return string.replace(ESCAPE_REGEXP, "\\$&");
|
|
33265
33265
|
}
|
|
33266
|
-
function removeDuplicateSlashes(
|
|
33267
|
-
return
|
|
33266
|
+
function removeDuplicateSlashes(path12) {
|
|
33267
|
+
return path12.indexOf("//") !== -1 ? path12.replace(REMOVE_DUPLICATE_SLASHES_REGEXP, "/") : path12;
|
|
33268
33268
|
}
|
|
33269
|
-
function trimLastSlash(
|
|
33270
|
-
if (
|
|
33271
|
-
return
|
|
33269
|
+
function trimLastSlash(path12) {
|
|
33270
|
+
if (path12.length > 1 && path12.charCodeAt(path12.length - 1) === 47) {
|
|
33271
|
+
return path12.slice(0, -1);
|
|
33272
33272
|
}
|
|
33273
|
-
return
|
|
33273
|
+
return path12;
|
|
33274
33274
|
}
|
|
33275
33275
|
function trimRegExpStartAndEnd(regexString) {
|
|
33276
33276
|
if (regexString.charCodeAt(1) === 94) {
|
|
@@ -33281,22 +33281,22 @@ var require_find_my_way = __commonJS({
|
|
|
33281
33281
|
}
|
|
33282
33282
|
return regexString;
|
|
33283
33283
|
}
|
|
33284
|
-
function getClosingParenthensePosition(
|
|
33284
|
+
function getClosingParenthensePosition(path12, idx) {
|
|
33285
33285
|
let parentheses = 1;
|
|
33286
|
-
while (idx <
|
|
33286
|
+
while (idx < path12.length) {
|
|
33287
33287
|
idx++;
|
|
33288
|
-
if (
|
|
33288
|
+
if (path12.charCodeAt(idx) === 92) {
|
|
33289
33289
|
idx++;
|
|
33290
33290
|
continue;
|
|
33291
33291
|
}
|
|
33292
|
-
if (
|
|
33292
|
+
if (path12.charCodeAt(idx) === 41) {
|
|
33293
33293
|
parentheses--;
|
|
33294
|
-
} else if (
|
|
33294
|
+
} else if (path12.charCodeAt(idx) === 40) {
|
|
33295
33295
|
parentheses++;
|
|
33296
33296
|
}
|
|
33297
33297
|
if (!parentheses) return idx;
|
|
33298
33298
|
}
|
|
33299
|
-
throw new TypeError('Invalid regexp expression in "' +
|
|
33299
|
+
throw new TypeError('Invalid regexp expression in "' + path12 + '"');
|
|
33300
33300
|
}
|
|
33301
33301
|
function defaultBuildPrettyMeta(route) {
|
|
33302
33302
|
if (!route) return {};
|
|
@@ -33331,8 +33331,8 @@ var require_head_route = __commonJS({
|
|
|
33331
33331
|
done(null, null);
|
|
33332
33332
|
return;
|
|
33333
33333
|
}
|
|
33334
|
-
const
|
|
33335
|
-
reply.header("content-length",
|
|
33334
|
+
const size2 = "" + Buffer.byteLength(payload);
|
|
33335
|
+
reply.header("content-length", size2);
|
|
33336
33336
|
done(null, null);
|
|
33337
33337
|
}
|
|
33338
33338
|
function parseHeadOnSendHandlers(onSendHandlers) {
|
|
@@ -33529,12 +33529,12 @@ var require_route = __commonJS({
|
|
|
33529
33529
|
function route({ options: options2, isFastify }) {
|
|
33530
33530
|
throwIfAlreadyStarted("Cannot add route!");
|
|
33531
33531
|
const opts = { ...options2 };
|
|
33532
|
-
const
|
|
33532
|
+
const path12 = opts.url || opts.path || "";
|
|
33533
33533
|
if (!opts.handler) {
|
|
33534
|
-
throw new FST_ERR_ROUTE_MISSING_HANDLER(opts.method,
|
|
33534
|
+
throw new FST_ERR_ROUTE_MISSING_HANDLER(opts.method, path12);
|
|
33535
33535
|
}
|
|
33536
33536
|
if (opts.errorHandler !== void 0 && typeof opts.errorHandler !== "function") {
|
|
33537
|
-
throw new FST_ERR_ROUTE_HANDLER_NOT_FN(opts.method,
|
|
33537
|
+
throw new FST_ERR_ROUTE_HANDLER_NOT_FN(opts.method, path12);
|
|
33538
33538
|
}
|
|
33539
33539
|
validateBodyLimitOption(opts.bodyLimit);
|
|
33540
33540
|
validateHandlerTimeoutOption(opts.handlerTimeout);
|
|
@@ -33544,22 +33544,22 @@ var require_route = __commonJS({
|
|
|
33544
33544
|
if (Array.isArray(opts.method)) {
|
|
33545
33545
|
for (let i = 0; i < opts.method.length; ++i) {
|
|
33546
33546
|
opts.method[i] = normalizeAndValidateMethod.call(this, opts.method[i]);
|
|
33547
|
-
validateSchemaBodyOption.call(this, opts.method[i],
|
|
33547
|
+
validateSchemaBodyOption.call(this, opts.method[i], path12, opts.schema);
|
|
33548
33548
|
isGetRoute = opts.method.includes("GET");
|
|
33549
33549
|
isHeadRoute = opts.method.includes("HEAD");
|
|
33550
33550
|
}
|
|
33551
33551
|
} else {
|
|
33552
33552
|
opts.method = normalizeAndValidateMethod.call(this, opts.method);
|
|
33553
|
-
validateSchemaBodyOption.call(this, opts.method,
|
|
33553
|
+
validateSchemaBodyOption.call(this, opts.method, path12, opts.schema);
|
|
33554
33554
|
isGetRoute = opts.method === "GET";
|
|
33555
33555
|
isHeadRoute = opts.method === "HEAD";
|
|
33556
33556
|
}
|
|
33557
33557
|
const headOpts = shouldExposeHead && isGetRoute ? { ...options2 } : null;
|
|
33558
33558
|
const prefix = this[kRoutePrefix];
|
|
33559
|
-
if (
|
|
33559
|
+
if (path12 === "/" && prefix.length > 0 && opts.method !== "HEAD") {
|
|
33560
33560
|
switch (opts.prefixTrailingSlash) {
|
|
33561
33561
|
case "slash":
|
|
33562
|
-
addNewRoute.call(this, { path:
|
|
33562
|
+
addNewRoute.call(this, { path: path12, isFastify });
|
|
33563
33563
|
break;
|
|
33564
33564
|
case "no-slash":
|
|
33565
33565
|
addNewRoute.call(this, { path: "", isFastify });
|
|
@@ -33568,20 +33568,20 @@ var require_route = __commonJS({
|
|
|
33568
33568
|
default:
|
|
33569
33569
|
addNewRoute.call(this, { path: "", isFastify });
|
|
33570
33570
|
if (ignoreTrailingSlash !== true && (ignoreDuplicateSlashes !== true || !prefix.endsWith("/"))) {
|
|
33571
|
-
addNewRoute.call(this, { path:
|
|
33571
|
+
addNewRoute.call(this, { path: path12, prefixing: true, isFastify });
|
|
33572
33572
|
}
|
|
33573
33573
|
}
|
|
33574
|
-
} else if (
|
|
33575
|
-
addNewRoute.call(this, { path:
|
|
33574
|
+
} else if (path12[0] === "/" && prefix.endsWith("/")) {
|
|
33575
|
+
addNewRoute.call(this, { path: path12.slice(1), isFastify });
|
|
33576
33576
|
} else {
|
|
33577
|
-
addNewRoute.call(this, { path:
|
|
33577
|
+
addNewRoute.call(this, { path: path12, isFastify });
|
|
33578
33578
|
}
|
|
33579
33579
|
return this;
|
|
33580
|
-
function addNewRoute({ path:
|
|
33581
|
-
const url = prefix +
|
|
33580
|
+
function addNewRoute({ path: path13, prefixing = false, isFastify: isFastify2 = false }) {
|
|
33581
|
+
const url = prefix + path13;
|
|
33582
33582
|
opts.url = url;
|
|
33583
33583
|
opts.path = url;
|
|
33584
|
-
opts.routePath =
|
|
33584
|
+
opts.routePath = path13;
|
|
33585
33585
|
opts.prefix = prefix;
|
|
33586
33586
|
opts.logLevel = opts.logLevel || this[kLogLevel];
|
|
33587
33587
|
validateLogLevelOption(opts.logLevel, opts.method, opts.url, logger);
|
|
@@ -33713,7 +33713,7 @@ var require_route = __commonJS({
|
|
|
33713
33713
|
});
|
|
33714
33714
|
if (shouldExposeHead && isGetRoute && !isHeadRoute && !hasHEADHandler) {
|
|
33715
33715
|
const onSendHandlers = parseHeadOnSendHandlers(headOpts.onSend);
|
|
33716
|
-
prepareRoute.call(this, { method: "HEAD", url:
|
|
33716
|
+
prepareRoute.call(this, { method: "HEAD", url: path13, options: { ...headOpts, onSend: onSendHandlers }, isFastify: true });
|
|
33717
33717
|
}
|
|
33718
33718
|
}
|
|
33719
33719
|
}
|
|
@@ -33837,9 +33837,9 @@ var require_route = __commonJS({
|
|
|
33837
33837
|
}
|
|
33838
33838
|
return method;
|
|
33839
33839
|
}
|
|
33840
|
-
function validateSchemaBodyOption(method,
|
|
33840
|
+
function validateSchemaBodyOption(method, path12, schema) {
|
|
33841
33841
|
if (this[kSupportedHTTPMethods].bodyless.has(method) && schema?.body) {
|
|
33842
|
-
throw new FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED(method,
|
|
33842
|
+
throw new FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED(method, path12);
|
|
33843
33843
|
}
|
|
33844
33844
|
}
|
|
33845
33845
|
function validateBodyLimitOption(bodyLimit) {
|
|
@@ -33854,11 +33854,11 @@ var require_route = __commonJS({
|
|
|
33854
33854
|
throw new FST_ERR_ROUTE_HANDLER_TIMEOUT_OPTION_NOT_INT(handlerTimeout);
|
|
33855
33855
|
}
|
|
33856
33856
|
}
|
|
33857
|
-
function validateLogLevelOption(logLevel, method,
|
|
33857
|
+
function validateLogLevelOption(logLevel, method, path12, logger) {
|
|
33858
33858
|
if (logLevel == null || logLevel === "") return;
|
|
33859
33859
|
if (logger?.levels?.values == null) return;
|
|
33860
33860
|
if (typeof logLevel !== "string" || logger.levels.values[logLevel] === void 0) {
|
|
33861
|
-
throw new FST_ERR_ROUTE_LOG_LEVEL_INVALID(method,
|
|
33861
|
+
throw new FST_ERR_ROUTE_LOG_LEVEL_INVALID(method, path12, logLevel);
|
|
33862
33862
|
}
|
|
33863
33863
|
}
|
|
33864
33864
|
function runPreParsing(err, request, reply) {
|
|
@@ -33947,7 +33947,7 @@ var require_four_oh_four = __commonJS({
|
|
|
33947
33947
|
});
|
|
33948
33948
|
}
|
|
33949
33949
|
function createRouteEventHandler() {
|
|
33950
|
-
return function onRouteEvent(
|
|
33950
|
+
return function onRouteEvent(path12, req, res) {
|
|
33951
33951
|
const fourOhFourContext = this[kFourOhFourLevelInstance][kFourOhFourContext];
|
|
33952
33952
|
const id = getGenReqId(fourOhFourContext.server, req);
|
|
33953
33953
|
const childLogger = createChildLogger(fourOhFourContext, logger, req, id);
|
|
@@ -36618,19 +36618,19 @@ var require_fastify = __commonJS({
|
|
|
36618
36618
|
}
|
|
36619
36619
|
fourOhFour.router.lookup(req, res);
|
|
36620
36620
|
}
|
|
36621
|
-
function onBadUrl(
|
|
36621
|
+
function onBadUrl(path12, req, res) {
|
|
36622
36622
|
if (options.frameworkErrors) {
|
|
36623
36623
|
const id = getGenReqId(routeEventContext.server, req);
|
|
36624
36624
|
const childLogger = createChildLogger(routeEventContext, options.logger, req, id);
|
|
36625
36625
|
const request = new Request(id, null, req, null, childLogger, routeEventContext);
|
|
36626
36626
|
const reply = new Reply(res, request, childLogger);
|
|
36627
36627
|
routeEventContext.server[kLogController].incomingRequest(request, reply);
|
|
36628
|
-
return options.frameworkErrors(new FST_ERR_BAD_URL(
|
|
36628
|
+
return options.frameworkErrors(new FST_ERR_BAD_URL(path12), request, reply);
|
|
36629
36629
|
}
|
|
36630
36630
|
const body = JSON.stringify({
|
|
36631
36631
|
error: "Bad Request",
|
|
36632
36632
|
code: "FST_ERR_BAD_URL",
|
|
36633
|
-
message: `'${
|
|
36633
|
+
message: `'${path12}' is not a valid url component`,
|
|
36634
36634
|
statusCode: 400
|
|
36635
36635
|
});
|
|
36636
36636
|
res.writeHead(400, {
|
|
@@ -36639,19 +36639,19 @@ var require_fastify = __commonJS({
|
|
|
36639
36639
|
});
|
|
36640
36640
|
res.end(body);
|
|
36641
36641
|
}
|
|
36642
|
-
function onMaxParamLength(
|
|
36642
|
+
function onMaxParamLength(path12, req, res) {
|
|
36643
36643
|
if (options.frameworkErrors) {
|
|
36644
36644
|
const id = getGenReqId(routeEventContext.server, req);
|
|
36645
36645
|
const childLogger = createChildLogger(routeEventContext, options.logger, req, id);
|
|
36646
36646
|
const request = new Request(id, null, req, null, childLogger, routeEventContext);
|
|
36647
36647
|
const reply = new Reply(res, request, childLogger);
|
|
36648
36648
|
routeEventContext.server[kLogController].incomingRequest(request, reply);
|
|
36649
|
-
return options.frameworkErrors(new FST_ERR_MAX_PARAM_LENGTH(
|
|
36649
|
+
return options.frameworkErrors(new FST_ERR_MAX_PARAM_LENGTH(path12), request, reply);
|
|
36650
36650
|
}
|
|
36651
36651
|
const body = JSON.stringify({
|
|
36652
36652
|
error: "Bad Request",
|
|
36653
36653
|
code: "FST_ERR_MAX_PARAM_LENGTH",
|
|
36654
|
-
message: `'${
|
|
36654
|
+
message: `'${path12}' is exceeding the max param length`,
|
|
36655
36655
|
statusCode: 414
|
|
36656
36656
|
});
|
|
36657
36657
|
res.writeHead(414, {
|
|
@@ -41001,8 +41001,8 @@ var import_cors = __toESM(require_cors(), 1);
|
|
|
41001
41001
|
// src/db/index.ts
|
|
41002
41002
|
import Database from "better-sqlite3";
|
|
41003
41003
|
var db;
|
|
41004
|
-
function initDb(
|
|
41005
|
-
db = new Database(
|
|
41004
|
+
function initDb(path12 = "data.db") {
|
|
41005
|
+
db = new Database(path12);
|
|
41006
41006
|
db.pragma("journal_mode = WAL");
|
|
41007
41007
|
db.pragma("foreign_keys = ON");
|
|
41008
41008
|
createTables(db);
|
|
@@ -41187,6 +41187,9 @@ CREATE INDEX IF NOT EXISTS idx_workspaces_path ON workspaces(path);
|
|
|
41187
41187
|
if (!turnColumns.some((c) => c.name === "resume_attempts")) {
|
|
41188
41188
|
database.exec("ALTER TABLE turns ADD COLUMN resume_attempts INTEGER NOT NULL DEFAULT 0");
|
|
41189
41189
|
}
|
|
41190
|
+
if (!turnColumns.some((c) => c.name === "resume_at")) {
|
|
41191
|
+
database.exec("ALTER TABLE turns ADD COLUMN resume_at TEXT");
|
|
41192
|
+
}
|
|
41190
41193
|
const threadColumns = database.prepare("PRAGMA table_info(discussion_threads)").all();
|
|
41191
41194
|
if (!threadColumns.some((c) => c.name === "external_thread_id")) {
|
|
41192
41195
|
database.exec("ALTER TABLE discussion_threads ADD COLUMN external_thread_id TEXT");
|
|
@@ -41288,11 +41291,11 @@ function initWs(allowRequest = isLocalRequest) {
|
|
|
41288
41291
|
});
|
|
41289
41292
|
return wss;
|
|
41290
41293
|
}
|
|
41291
|
-
function handleUpgrade(
|
|
41294
|
+
function handleUpgrade(wss3, request, socket, head) {
|
|
41292
41295
|
const url = request.url || "";
|
|
41293
41296
|
if (url.startsWith("/ws")) {
|
|
41294
|
-
|
|
41295
|
-
|
|
41297
|
+
wss3.handleUpgrade(request, socket, head, (ws) => {
|
|
41298
|
+
wss3.emit("connection", ws, request);
|
|
41296
41299
|
});
|
|
41297
41300
|
} else {
|
|
41298
41301
|
socket.destroy();
|
|
@@ -41311,8 +41314,274 @@ function getWss() {
|
|
|
41311
41314
|
return wss;
|
|
41312
41315
|
}
|
|
41313
41316
|
|
|
41314
|
-
//
|
|
41317
|
+
// ../shared/terminal-protocol.ts
|
|
41318
|
+
var TERMINAL_WS_PATH = "/ws/terminal";
|
|
41319
|
+
var TERMINAL_CLOSE = {
|
|
41320
|
+
/** The same terminal was opened elsewhere, e.g. in a duplicated tab. */
|
|
41321
|
+
takenOver: 4001,
|
|
41322
|
+
/** Too many terminals are open on this machine. */
|
|
41323
|
+
limit: 4002,
|
|
41324
|
+
/** The shell could not start; the close reason says why. */
|
|
41325
|
+
unavailable: 4003,
|
|
41326
|
+
/** The request has no usable terminal id. */
|
|
41327
|
+
badRequest: 4004
|
|
41328
|
+
};
|
|
41329
|
+
|
|
41330
|
+
// src/terminal/manager.ts
|
|
41331
|
+
import fs from "node:fs";
|
|
41332
|
+
import { createRequire as createNodeRequire } from "node:module";
|
|
41333
|
+
import os from "node:os";
|
|
41315
41334
|
import path from "node:path";
|
|
41335
|
+
var MAX_TERMINALS = 8;
|
|
41336
|
+
var DETACHED_TTL_MS = 15 * 6e4;
|
|
41337
|
+
var UNACKED_HIGH = 1024 * 1024;
|
|
41338
|
+
var UNACKED_LOW = 128 * 1024;
|
|
41339
|
+
var PING_MS = 3e4;
|
|
41340
|
+
var CLOSE_REASON_LENGTH = 120;
|
|
41341
|
+
var terminals = /* @__PURE__ */ new Map();
|
|
41342
|
+
var nodeRequire = createNodeRequire(import.meta.url);
|
|
41343
|
+
var ptyModule = null;
|
|
41344
|
+
function loadPty() {
|
|
41345
|
+
ptyModule ??= import("node-pty").then((mod) => {
|
|
41346
|
+
ensureSpawnHelperRuns();
|
|
41347
|
+
return mod;
|
|
41348
|
+
}).catch((err) => {
|
|
41349
|
+
ptyModule = null;
|
|
41350
|
+
throw err;
|
|
41351
|
+
});
|
|
41352
|
+
return ptyModule;
|
|
41353
|
+
}
|
|
41354
|
+
function ensureSpawnHelperRuns() {
|
|
41355
|
+
if (process.platform === "win32") return;
|
|
41356
|
+
try {
|
|
41357
|
+
const root = path.dirname(nodeRequire.resolve("node-pty/package.json"));
|
|
41358
|
+
fs.chmodSync(path.join(root, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper"), 493);
|
|
41359
|
+
} catch {
|
|
41360
|
+
}
|
|
41361
|
+
}
|
|
41362
|
+
function loginShell() {
|
|
41363
|
+
if (process.platform === "win32") return { file: process.env.COMSPEC ?? "cmd.exe", args: [] };
|
|
41364
|
+
return { file: process.env.SHELL || os.userInfo().shell || "/bin/sh", args: ["-l"] };
|
|
41365
|
+
}
|
|
41366
|
+
function usableDir(dir) {
|
|
41367
|
+
try {
|
|
41368
|
+
if (dir && fs.statSync(dir).isDirectory()) return dir;
|
|
41369
|
+
} catch {
|
|
41370
|
+
}
|
|
41371
|
+
return os.homedir();
|
|
41372
|
+
}
|
|
41373
|
+
function bundledCliDir() {
|
|
41374
|
+
try {
|
|
41375
|
+
const sdkPlatform = `@anthropic-ai/claude-agent-sdk-${process.platform}-${process.arch}`;
|
|
41376
|
+
return path.dirname(nodeRequire.resolve(`${sdkPlatform}/package.json`));
|
|
41377
|
+
} catch {
|
|
41378
|
+
return null;
|
|
41379
|
+
}
|
|
41380
|
+
}
|
|
41381
|
+
function shellEnv() {
|
|
41382
|
+
const env = {};
|
|
41383
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
41384
|
+
if (value !== void 0 && key !== "CLAUDECODE" && !key.startsWith("CLAUDE_CODE_RESUME_")) env[key] = value;
|
|
41385
|
+
}
|
|
41386
|
+
env.TERM = "xterm-256color";
|
|
41387
|
+
env.COLORTERM = "truecolor";
|
|
41388
|
+
env.LANG ||= "en_US.UTF-8";
|
|
41389
|
+
const cliDir = bundledCliDir();
|
|
41390
|
+
if (cliDir) env.PATH = env.PATH ? `${env.PATH}${path.delimiter}${cliDir}` : cliDir;
|
|
41391
|
+
return env;
|
|
41392
|
+
}
|
|
41393
|
+
function send(ws, message) {
|
|
41394
|
+
if (ws.readyState === ws.OPEN) ws.send(JSON.stringify(message));
|
|
41395
|
+
}
|
|
41396
|
+
function setPaused(term, paused) {
|
|
41397
|
+
if (term.paused === paused) return;
|
|
41398
|
+
term.paused = paused;
|
|
41399
|
+
if (paused) term.pty.pause();
|
|
41400
|
+
else term.pty.resume();
|
|
41401
|
+
}
|
|
41402
|
+
function resize(term, cols, rows) {
|
|
41403
|
+
try {
|
|
41404
|
+
term.pty.resize(cols, rows);
|
|
41405
|
+
} catch {
|
|
41406
|
+
}
|
|
41407
|
+
}
|
|
41408
|
+
function clearExpiry(term) {
|
|
41409
|
+
if (term.expiry) clearTimeout(term.expiry);
|
|
41410
|
+
term.expiry = null;
|
|
41411
|
+
}
|
|
41412
|
+
function startShell(pty, id, request) {
|
|
41413
|
+
const { file, args } = loginShell();
|
|
41414
|
+
const term = {
|
|
41415
|
+
pty: pty.spawn(file, args, {
|
|
41416
|
+
name: "xterm-256color",
|
|
41417
|
+
cols: request.cols,
|
|
41418
|
+
rows: request.rows,
|
|
41419
|
+
cwd: usableDir(request.cwd),
|
|
41420
|
+
env: shellEnv(),
|
|
41421
|
+
encoding: null
|
|
41422
|
+
// bytes: a multi-byte character may span two chunks
|
|
41423
|
+
}),
|
|
41424
|
+
socket: null,
|
|
41425
|
+
unacked: 0,
|
|
41426
|
+
paused: false,
|
|
41427
|
+
expiry: null
|
|
41428
|
+
};
|
|
41429
|
+
term.pty.onData((chunk) => {
|
|
41430
|
+
const ws = term.socket;
|
|
41431
|
+
if (!ws || ws.readyState !== ws.OPEN) return;
|
|
41432
|
+
const bytes = chunk;
|
|
41433
|
+
ws.send(bytes, { binary: true });
|
|
41434
|
+
term.unacked += bytes.length;
|
|
41435
|
+
if (term.unacked > UNACKED_HIGH) setPaused(term, true);
|
|
41436
|
+
});
|
|
41437
|
+
term.pty.onExit(({ exitCode }) => {
|
|
41438
|
+
clearExpiry(term);
|
|
41439
|
+
terminals.delete(id);
|
|
41440
|
+
const ws = term.socket;
|
|
41441
|
+
term.socket = null;
|
|
41442
|
+
if (!ws) return;
|
|
41443
|
+
send(ws, { type: "exit", code: exitCode });
|
|
41444
|
+
ws.close(1e3);
|
|
41445
|
+
});
|
|
41446
|
+
terminals.set(id, term);
|
|
41447
|
+
return term;
|
|
41448
|
+
}
|
|
41449
|
+
function onClientMessage(term, data, isBinary) {
|
|
41450
|
+
if (isBinary) {
|
|
41451
|
+
term.pty.write(data);
|
|
41452
|
+
return;
|
|
41453
|
+
}
|
|
41454
|
+
let message;
|
|
41455
|
+
try {
|
|
41456
|
+
message = JSON.parse(data.toString());
|
|
41457
|
+
} catch {
|
|
41458
|
+
return;
|
|
41459
|
+
}
|
|
41460
|
+
if (message.type === "resize") {
|
|
41461
|
+
const { cols, rows } = message;
|
|
41462
|
+
if (Number.isInteger(cols) && Number.isInteger(rows) && cols > 0 && rows > 0) resize(term, cols, rows);
|
|
41463
|
+
} else if (message.type === "ack" && Number.isFinite(message.bytes)) {
|
|
41464
|
+
term.unacked = Math.max(0, term.unacked - message.bytes);
|
|
41465
|
+
if (term.unacked < UNACKED_LOW) setPaused(term, false);
|
|
41466
|
+
}
|
|
41467
|
+
}
|
|
41468
|
+
function attach(term, ws, attached) {
|
|
41469
|
+
clearExpiry(term);
|
|
41470
|
+
const previous = term.socket;
|
|
41471
|
+
term.socket = ws;
|
|
41472
|
+
term.unacked = 0;
|
|
41473
|
+
previous?.close(TERMINAL_CLOSE.takenOver, "Opened somewhere else");
|
|
41474
|
+
setPaused(term, false);
|
|
41475
|
+
let alive = true;
|
|
41476
|
+
const ping = setInterval(() => {
|
|
41477
|
+
if (!alive) {
|
|
41478
|
+
ws.terminate();
|
|
41479
|
+
return;
|
|
41480
|
+
}
|
|
41481
|
+
alive = false;
|
|
41482
|
+
ws.ping();
|
|
41483
|
+
}, PING_MS);
|
|
41484
|
+
ping.unref?.();
|
|
41485
|
+
ws.on("pong", () => {
|
|
41486
|
+
alive = true;
|
|
41487
|
+
});
|
|
41488
|
+
ws.on("message", (data, isBinary) => {
|
|
41489
|
+
if (term.socket === ws) onClientMessage(term, data, isBinary);
|
|
41490
|
+
});
|
|
41491
|
+
ws.on("close", () => {
|
|
41492
|
+
clearInterval(ping);
|
|
41493
|
+
if (term.socket !== ws) return;
|
|
41494
|
+
term.socket = null;
|
|
41495
|
+
setPaused(term, true);
|
|
41496
|
+
term.expiry = setTimeout(() => term.pty.kill(), DETACHED_TTL_MS);
|
|
41497
|
+
term.expiry.unref?.();
|
|
41498
|
+
});
|
|
41499
|
+
ws.on("error", () => ws.terminate());
|
|
41500
|
+
send(ws, { type: "ready", attached });
|
|
41501
|
+
}
|
|
41502
|
+
async function openTerminal(ws, request) {
|
|
41503
|
+
let pty;
|
|
41504
|
+
try {
|
|
41505
|
+
pty = await loadPty();
|
|
41506
|
+
} catch (err) {
|
|
41507
|
+
console.error("[terminal] node-pty is not available:", err.message);
|
|
41508
|
+
ws.close(TERMINAL_CLOSE.unavailable, "This machine cannot run a terminal here");
|
|
41509
|
+
return;
|
|
41510
|
+
}
|
|
41511
|
+
if (ws.readyState !== ws.OPEN) return;
|
|
41512
|
+
const running = terminals.get(request.id);
|
|
41513
|
+
if (running) {
|
|
41514
|
+
resize(running, request.cols, request.rows);
|
|
41515
|
+
attach(running, ws, true);
|
|
41516
|
+
return;
|
|
41517
|
+
}
|
|
41518
|
+
if (terminals.size >= MAX_TERMINALS) {
|
|
41519
|
+
ws.close(TERMINAL_CLOSE.limit, `At most ${MAX_TERMINALS} terminals can be open`);
|
|
41520
|
+
return;
|
|
41521
|
+
}
|
|
41522
|
+
try {
|
|
41523
|
+
attach(startShell(pty, request.id, request), ws, false);
|
|
41524
|
+
} catch (err) {
|
|
41525
|
+
const reason = err.message;
|
|
41526
|
+
console.error("[terminal] could not start a shell:", reason);
|
|
41527
|
+
ws.close(TERMINAL_CLOSE.unavailable, reason.slice(0, CLOSE_REASON_LENGTH));
|
|
41528
|
+
}
|
|
41529
|
+
}
|
|
41530
|
+
function stopAllTerminals() {
|
|
41531
|
+
for (const term of terminals.values()) {
|
|
41532
|
+
clearExpiry(term);
|
|
41533
|
+
term.pty.kill();
|
|
41534
|
+
}
|
|
41535
|
+
}
|
|
41536
|
+
|
|
41537
|
+
// src/terminal/ws.ts
|
|
41538
|
+
var TERMINAL_ID = /^[\w-]{8,64}$/;
|
|
41539
|
+
var DEFAULT_COLS = 80;
|
|
41540
|
+
var DEFAULT_ROWS = 24;
|
|
41541
|
+
var MAX_SIZE = 1e3;
|
|
41542
|
+
var wss2 = null;
|
|
41543
|
+
function size(value, fallback) {
|
|
41544
|
+
const n = Number(value);
|
|
41545
|
+
return Number.isInteger(n) && n > 0 && n <= MAX_SIZE ? n : fallback;
|
|
41546
|
+
}
|
|
41547
|
+
function onConnection(ws, request) {
|
|
41548
|
+
const { searchParams } = new URL(request.url ?? "", "http://localhost");
|
|
41549
|
+
const id = searchParams.get("id") ?? "";
|
|
41550
|
+
if (!TERMINAL_ID.test(id)) {
|
|
41551
|
+
ws.close(TERMINAL_CLOSE.badRequest, "Bad terminal id");
|
|
41552
|
+
return;
|
|
41553
|
+
}
|
|
41554
|
+
void openTerminal(ws, {
|
|
41555
|
+
id,
|
|
41556
|
+
cols: size(searchParams.get("cols"), DEFAULT_COLS),
|
|
41557
|
+
rows: size(searchParams.get("rows"), DEFAULT_ROWS),
|
|
41558
|
+
cwd: searchParams.get("cwd")
|
|
41559
|
+
});
|
|
41560
|
+
}
|
|
41561
|
+
function initTerminalWs(allowRequest = isLocalRequest) {
|
|
41562
|
+
wss2 = new import_websocket_server.default({
|
|
41563
|
+
noServer: true,
|
|
41564
|
+
verifyClient: ({ req }) => allowRequest(req.headers.origin, req.headers.host)
|
|
41565
|
+
});
|
|
41566
|
+
wss2.on("connection", onConnection);
|
|
41567
|
+
return wss2;
|
|
41568
|
+
}
|
|
41569
|
+
function isTerminalUpgrade(url) {
|
|
41570
|
+
return url === TERMINAL_WS_PATH || !!url?.startsWith(`${TERMINAL_WS_PATH}?`);
|
|
41571
|
+
}
|
|
41572
|
+
function handleTerminalUpgrade(request, socket, head) {
|
|
41573
|
+
const server = wss2;
|
|
41574
|
+
if (!server) {
|
|
41575
|
+
socket.destroy();
|
|
41576
|
+
return;
|
|
41577
|
+
}
|
|
41578
|
+
server.handleUpgrade(request, socket, head, (ws) => {
|
|
41579
|
+
server.emit("connection", ws, request);
|
|
41580
|
+
});
|
|
41581
|
+
}
|
|
41582
|
+
|
|
41583
|
+
// src/routes/sessions.ts
|
|
41584
|
+
import path2 from "node:path";
|
|
41316
41585
|
|
|
41317
41586
|
// node_modules/uuid/dist/esm/stringify.js
|
|
41318
41587
|
var byteToHex = [];
|
|
@@ -41602,8 +41871,8 @@ async function registerSessionRoutes(fastify) {
|
|
|
41602
41871
|
}
|
|
41603
41872
|
let workspaceChanged = false;
|
|
41604
41873
|
if (cwd !== void 0) {
|
|
41605
|
-
const oldAbs = existing.cwd ?
|
|
41606
|
-
const newAbs = cwd ?
|
|
41874
|
+
const oldAbs = existing.cwd ? path2.resolve(existing.cwd) : null;
|
|
41875
|
+
const newAbs = cwd ? path2.resolve(cwd) : null;
|
|
41607
41876
|
workspaceChanged = oldAbs !== newAbs;
|
|
41608
41877
|
if (workspaceChanged && existing.is_running) {
|
|
41609
41878
|
return reply.code(409).send({ error: "Cannot change workspace while a turn is running" });
|
|
@@ -41963,12 +42232,13 @@ function markTurnInterrupted(db2, turnId, reason, opts = {}) {
|
|
|
41963
42232
|
if (turn.status === "pending" && turn.resume_state === "waiting") return false;
|
|
41964
42233
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
41965
42234
|
const detail = opts.detail ?? null;
|
|
42235
|
+
const resumeAt = opts.resumeAt ?? null;
|
|
41966
42236
|
const retry = turn.resume_state === "resuming";
|
|
41967
42237
|
const at = retry ? turn.interrupted_at ?? now : opts.at ?? now;
|
|
41968
42238
|
db2.prepare(
|
|
41969
|
-
`UPDATE turns SET status = 'pending', resume_state = 'waiting', interrupt_reason = ?, interrupted_at = ?, error = NULL, updated_at = ?
|
|
42239
|
+
`UPDATE turns SET status = 'pending', resume_state = 'waiting', interrupt_reason = ?, interrupted_at = ?, resume_at = ?, error = NULL, updated_at = ?
|
|
41970
42240
|
WHERE id = ?`
|
|
41971
|
-
).run(reason, at, now, turnId);
|
|
42241
|
+
).run(reason, at, resumeAt, now, turnId);
|
|
41972
42242
|
if (retry) {
|
|
41973
42243
|
updateLatestInterruptionItem(db2, turn.session_id, turnId, { reason, outcome: "waiting", detail });
|
|
41974
42244
|
} else {
|
|
@@ -41987,7 +42257,8 @@ function markTurnInterrupted(db2, turnId, reason, opts = {}) {
|
|
|
41987
42257
|
reason,
|
|
41988
42258
|
interruptedAt: at,
|
|
41989
42259
|
attempts: turn.resume_attempts,
|
|
41990
|
-
detail
|
|
42260
|
+
detail,
|
|
42261
|
+
resumeAt
|
|
41991
42262
|
});
|
|
41992
42263
|
if (opts.notify !== false) {
|
|
41993
42264
|
for (const listener of listeners) {
|
|
@@ -42008,7 +42279,7 @@ function markTurnResuming(db2, turnId, opts = {}) {
|
|
|
42008
42279
|
const reason = turn.interrupt_reason ?? "host_restart";
|
|
42009
42280
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
42010
42281
|
db2.prepare(
|
|
42011
|
-
`UPDATE turns SET status = 'running', resume_state = 'resuming', resume_attempts = ?, error = NULL, updated_at = ?
|
|
42282
|
+
`UPDATE turns SET status = 'running', resume_state = 'resuming', resume_attempts = ?, resume_at = NULL, error = NULL, updated_at = ?
|
|
42012
42283
|
WHERE id = ?`
|
|
42013
42284
|
).run(attempt, now, turnId);
|
|
42014
42285
|
updateLatestInterruptionItem(db2, turn.session_id, turnId, { outcome: "resuming" });
|
|
@@ -42016,6 +42287,14 @@ function markTurnResuming(db2, turnId, opts = {}) {
|
|
|
42016
42287
|
broadcast("turn:resuming", { sessionId: turn.session_id, turnId, attempt, reason, manual: !!opts.manual });
|
|
42017
42288
|
return { sessionId: turn.session_id, attempt, reason };
|
|
42018
42289
|
}
|
|
42290
|
+
function listSignedOutTurns(db2) {
|
|
42291
|
+
const rows = db2.prepare(
|
|
42292
|
+
`SELECT id, session_id FROM turns
|
|
42293
|
+
WHERE status = 'pending' AND resume_state = 'waiting' AND interrupt_reason = 'auth'
|
|
42294
|
+
ORDER BY interrupted_at ASC, created_at ASC`
|
|
42295
|
+
).all();
|
|
42296
|
+
return rows.map((row) => ({ sessionId: row.session_id, turnId: row.id }));
|
|
42297
|
+
}
|
|
42019
42298
|
function isResumable(turn, manual) {
|
|
42020
42299
|
if (turn.status === "pending" && turn.resume_state === "waiting") return true;
|
|
42021
42300
|
return manual && turn.status === "failed" && (turn.resume_state === "gave_up" || turn.resume_state === "skipped");
|
|
@@ -42025,7 +42304,7 @@ function markTurnResumed(db2, turnId, opts = {}) {
|
|
|
42025
42304
|
if (!turn) return;
|
|
42026
42305
|
if (turn.resume_state !== "resuming" && !(opts.settle && turn.resume_state === "waiting")) return;
|
|
42027
42306
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
42028
|
-
db2.prepare("UPDATE turns SET resume_state = 'resumed', updated_at = ? WHERE id = ?").run(now, turnId);
|
|
42307
|
+
db2.prepare("UPDATE turns SET resume_state = 'resumed', resume_at = NULL, updated_at = ? WHERE id = ?").run(now, turnId);
|
|
42029
42308
|
updateLatestInterruptionItem(db2, turn.session_id, turnId, { outcome: "resumed", resumed_at: now });
|
|
42030
42309
|
broadcast("turn:resumed", { sessionId: turn.session_id, turnId, resumedAt: now });
|
|
42031
42310
|
}
|
|
@@ -42033,12 +42312,9 @@ function finalizeInterruptedTurn(db2, turnId, state, error) {
|
|
|
42033
42312
|
const turn = getTurn(db2, turnId);
|
|
42034
42313
|
if (!turn || !isLive(turn.status)) return false;
|
|
42035
42314
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
42036
|
-
db2.prepare(
|
|
42037
|
-
|
|
42038
|
-
|
|
42039
|
-
now,
|
|
42040
|
-
turnId
|
|
42041
|
-
);
|
|
42315
|
+
db2.prepare(
|
|
42316
|
+
"UPDATE turns SET status = 'failed', resume_state = ?, resume_at = NULL, error = ?, updated_at = ? WHERE id = ?"
|
|
42317
|
+
).run(state, error, now, turnId);
|
|
42042
42318
|
updateLatestInterruptionItem(db2, turn.session_id, turnId, { outcome: state });
|
|
42043
42319
|
recomputeSessionRunning(db2, turn.session_id, "failed");
|
|
42044
42320
|
broadcast("turn:failed", { sessionId: turn.session_id, turnId, error, resumeState: state });
|
|
@@ -42047,7 +42323,7 @@ function finalizeInterruptedTurn(db2, turnId, state, error) {
|
|
|
42047
42323
|
function markResumeCancelled(db2, turnId) {
|
|
42048
42324
|
const turn = getTurn(db2, turnId);
|
|
42049
42325
|
if (!turn || turn.resume_state !== "waiting" && turn.resume_state !== "resuming") return;
|
|
42050
|
-
db2.prepare("UPDATE turns SET resume_state = 'cancelled' WHERE id = ?").run(turnId);
|
|
42326
|
+
db2.prepare("UPDATE turns SET resume_state = 'cancelled', resume_at = NULL WHERE id = ?").run(turnId);
|
|
42051
42327
|
updateLatestInterruptionItem(db2, turn.session_id, turnId, { outcome: "cancelled" });
|
|
42052
42328
|
}
|
|
42053
42329
|
function recoverInterruptedTurns(db2, opts) {
|
|
@@ -42122,6 +42398,8 @@ async function probeApi(opts = {}) {
|
|
|
42122
42398
|
|
|
42123
42399
|
// src/resume/resume-manager.ts
|
|
42124
42400
|
var HOUR = 60 * 60 * 1e3;
|
|
42401
|
+
var RESET_MARGIN_MS = 3e4;
|
|
42402
|
+
var CLOCK_CHECK_MS = 6e4;
|
|
42125
42403
|
function envNumber(env, name, fallback) {
|
|
42126
42404
|
const raw = env[name];
|
|
42127
42405
|
if (raw === void 0 || raw === "") return fallback;
|
|
@@ -42177,6 +42455,12 @@ function stopAutoResume() {
|
|
|
42177
42455
|
config = null;
|
|
42178
42456
|
rescanDelay = null;
|
|
42179
42457
|
}
|
|
42458
|
+
function usageLimitResumeAt(resetsAt, now = Date.now()) {
|
|
42459
|
+
const cfg = config ?? readAutoResumeConfig();
|
|
42460
|
+
if (!cfg.enabled || !resetsAt) return null;
|
|
42461
|
+
const due = resetsAt * 1e3 + RESET_MARGIN_MS;
|
|
42462
|
+
return due > now && due - now <= cfg.maxAgeMs ? new Date(due).toISOString() : null;
|
|
42463
|
+
}
|
|
42180
42464
|
function scheduleScan(delayMs) {
|
|
42181
42465
|
if (!config) return;
|
|
42182
42466
|
if (scanning) {
|
|
@@ -42209,21 +42493,32 @@ async function runScan() {
|
|
|
42209
42493
|
})();
|
|
42210
42494
|
return scanning;
|
|
42211
42495
|
}
|
|
42496
|
+
function limitWaitMs(turn) {
|
|
42497
|
+
const resumeAt = turn.resume_at ? Date.parse(turn.resume_at) : NaN;
|
|
42498
|
+
return Number.isNaN(resumeAt) ? CLOCK_CHECK_MS : Math.min(resumeAt - Date.now(), CLOCK_CHECK_MS);
|
|
42499
|
+
}
|
|
42212
42500
|
async function scan() {
|
|
42213
42501
|
const cfg = config;
|
|
42214
42502
|
if (!cfg || !cfg.enabled) return;
|
|
42215
42503
|
await orphansReaped;
|
|
42216
42504
|
const db2 = getDb();
|
|
42217
42505
|
const waiting = db2.prepare(
|
|
42218
|
-
|
|
42219
|
-
|
|
42506
|
+
// A signed-out turn would fail again and use up its attempts; it waits
|
|
42507
|
+
// for the user, without an age limit (resumeSignedOutTurns).
|
|
42508
|
+
`SELECT id, session_id, interrupted_at, interrupt_reason, resume_at, resume_attempts FROM turns
|
|
42509
|
+
WHERE status = 'pending' AND resume_state = 'waiting' AND COALESCE(interrupt_reason, '') != 'auth'
|
|
42220
42510
|
ORDER BY interrupted_at ASC, created_at ASC`
|
|
42221
42511
|
).all();
|
|
42222
42512
|
const due = [];
|
|
42513
|
+
let nextLook = null;
|
|
42223
42514
|
for (const turn of waiting) {
|
|
42224
42515
|
const at = turn.interrupted_at ? Date.parse(turn.interrupted_at) : NaN;
|
|
42225
42516
|
if (Number.isFinite(at) && Date.now() - at > cfg.maxAgeMs) {
|
|
42226
42517
|
finalizeInterruptedTurn(db2, turn.id, "skipped", "Interrupted too long ago to resume automatically");
|
|
42518
|
+
} else if (turn.interrupt_reason === "usage_limit") {
|
|
42519
|
+
const wait = limitWaitMs(turn);
|
|
42520
|
+
if (wait <= 0) due.push(turn);
|
|
42521
|
+
else nextLook = Math.min(nextLook ?? wait, wait);
|
|
42227
42522
|
} else if (turn.resume_attempts >= cfg.maxAttempts) {
|
|
42228
42523
|
finalizeInterruptedTurn(
|
|
42229
42524
|
db2,
|
|
@@ -42235,6 +42530,7 @@ async function scan() {
|
|
|
42235
42530
|
due.push(turn);
|
|
42236
42531
|
}
|
|
42237
42532
|
}
|
|
42533
|
+
if (nextLook !== null) scheduleScan(nextLook);
|
|
42238
42534
|
if (due.length === 0) {
|
|
42239
42535
|
probeFailures = 0;
|
|
42240
42536
|
return;
|
|
@@ -42255,7 +42551,8 @@ async function scan() {
|
|
|
42255
42551
|
for (let i = 0; i < due.length; i++) {
|
|
42256
42552
|
if (config !== cfg) return;
|
|
42257
42553
|
if (i > 0) await new Promise((resolve) => setTimeout(resolve, cfg.staggerMs));
|
|
42258
|
-
const
|
|
42554
|
+
const counted = countAttempt && due[i].interrupt_reason !== "usage_limit";
|
|
42555
|
+
const result = await resumeTurn(due[i].id, { manual: false, countAttempt: counted });
|
|
42259
42556
|
if (!result.ok && result.status === 409) {
|
|
42260
42557
|
finalizeInterruptedTurn(db2, due[i].id, "skipped", result.error);
|
|
42261
42558
|
}
|
|
@@ -42304,6 +42601,27 @@ async function resumeNow(sessionId, turnId) {
|
|
|
42304
42601
|
if (!row || row.session_id !== sessionId) return { ok: false, status: 404, error: "Turn not found" };
|
|
42305
42602
|
return resumeTurn(turnId, { manual: true });
|
|
42306
42603
|
}
|
|
42604
|
+
var resumingSignedOut = null;
|
|
42605
|
+
function resumeSignedOutTurns() {
|
|
42606
|
+
const db2 = getDb();
|
|
42607
|
+
const turns = listSignedOutTurns(db2);
|
|
42608
|
+
if (!resumingSignedOut && turns.length > 0) {
|
|
42609
|
+
const { staggerMs } = config ?? readAutoResumeConfig();
|
|
42610
|
+
resumingSignedOut = (async () => {
|
|
42611
|
+
await orphansReaped;
|
|
42612
|
+
for (let i = 0; i < turns.length; i++) {
|
|
42613
|
+
if (i > 0) await new Promise((resolve) => setTimeout(resolve, staggerMs));
|
|
42614
|
+
const result = await resumeTurn(turns[i].turnId, { manual: true });
|
|
42615
|
+
if (!result.ok && result.status === 409) {
|
|
42616
|
+
finalizeInterruptedTurn(db2, turns[i].turnId, "skipped", result.error);
|
|
42617
|
+
}
|
|
42618
|
+
}
|
|
42619
|
+
})().catch((err) => console.error("[resume] could not resume the signed-out turns:", err)).finally(() => {
|
|
42620
|
+
resumingSignedOut = null;
|
|
42621
|
+
});
|
|
42622
|
+
}
|
|
42623
|
+
return { turns: turns.length };
|
|
42624
|
+
}
|
|
42307
42625
|
|
|
42308
42626
|
// src/routes/turns.ts
|
|
42309
42627
|
async function registerTurnRoutes(fastify) {
|
|
@@ -42421,6 +42739,9 @@ async function registerTurnRoutes(fastify) {
|
|
|
42421
42739
|
return reply.code(202).send({ success: true });
|
|
42422
42740
|
}
|
|
42423
42741
|
);
|
|
42742
|
+
fastify.post("/api/turns/resume-signed-out", async (_request, reply) => {
|
|
42743
|
+
return reply.code(202).send(resumeSignedOutTurns());
|
|
42744
|
+
});
|
|
42424
42745
|
}
|
|
42425
42746
|
|
|
42426
42747
|
// src/routes/thread-turns.ts
|
|
@@ -42819,9 +43140,9 @@ async function browseFolder(input, opts = {}) {
|
|
|
42819
43140
|
const atHome = dir === nodePath.resolve(home);
|
|
42820
43141
|
const folders = await Promise.all(
|
|
42821
43142
|
names.slice(0, limit).map(async (name) => {
|
|
42822
|
-
const
|
|
43143
|
+
const path12 = nodePath.join(dir, name);
|
|
42823
43144
|
const skipProbe = atHome && HOME_STANDARD_FOLDERS.has(name) || dir === "/Volumes";
|
|
42824
|
-
return { name, path:
|
|
43145
|
+
return { name, path: path12, git: !skipProbe && await exists(nodePath.join(path12, ".git")) };
|
|
42825
43146
|
})
|
|
42826
43147
|
);
|
|
42827
43148
|
const parent = nodePath.dirname(dir);
|
|
@@ -42859,11 +43180,11 @@ async function registerWorkspaceRoutes(fastify) {
|
|
|
42859
43180
|
}
|
|
42860
43181
|
}
|
|
42861
43182
|
}, async (request, reply) => {
|
|
42862
|
-
const { path:
|
|
42863
|
-
if (!
|
|
43183
|
+
const { path: path12, label = null } = request.body || {};
|
|
43184
|
+
if (!path12 || !path12.trim()) {
|
|
42864
43185
|
return reply.code(400).send({ error: "Path is required" });
|
|
42865
43186
|
}
|
|
42866
|
-
const resolved = await resolveWorkspacePath(
|
|
43187
|
+
const resolved = await resolveWorkspacePath(path12);
|
|
42867
43188
|
if ("error" in resolved) {
|
|
42868
43189
|
return reply.code(400).send({ error: resolved.error });
|
|
42869
43190
|
}
|
|
@@ -42905,8 +43226,8 @@ async function registerWorkspaceRoutes(fastify) {
|
|
|
42905
43226
|
"-e",
|
|
42906
43227
|
'POSIX path of (choose folder with prompt "Select a workspace directory")'
|
|
42907
43228
|
]);
|
|
42908
|
-
const
|
|
42909
|
-
return { path:
|
|
43229
|
+
const path12 = stdout.trim().replace(/\/$/, "");
|
|
43230
|
+
return { path: path12 };
|
|
42910
43231
|
} catch {
|
|
42911
43232
|
return reply.code(204).send({ cancelled: true });
|
|
42912
43233
|
}
|
|
@@ -42922,11 +43243,11 @@ async function registerWorkspaceRoutes(fastify) {
|
|
|
42922
43243
|
}
|
|
42923
43244
|
}
|
|
42924
43245
|
}, async (request, reply) => {
|
|
42925
|
-
const { path:
|
|
42926
|
-
if (!
|
|
43246
|
+
const { path: path12 } = request.body || {};
|
|
43247
|
+
if (!path12 || !path12.trim()) {
|
|
42927
43248
|
return reply.code(400).send({ error: "Path is required" });
|
|
42928
43249
|
}
|
|
42929
|
-
const trimmedPath =
|
|
43250
|
+
const trimmedPath = path12.trim();
|
|
42930
43251
|
const db2 = getDb();
|
|
42931
43252
|
const existing = db2.prepare("SELECT * FROM workspaces WHERE path = ?").get(trimmedPath);
|
|
42932
43253
|
if (existing) {
|
|
@@ -43573,17 +43894,17 @@ async function registerPerfLogRoutes(fastify) {
|
|
|
43573
43894
|
if (entries.length === 0) {
|
|
43574
43895
|
return reply.send({ written: 0 });
|
|
43575
43896
|
}
|
|
43576
|
-
const
|
|
43897
|
+
const path12 = perfLogPath();
|
|
43577
43898
|
try {
|
|
43578
|
-
mkdirSync(dirname(
|
|
43899
|
+
mkdirSync(dirname(path12), { recursive: true });
|
|
43579
43900
|
try {
|
|
43580
|
-
if (statSync(
|
|
43581
|
-
renameSync(
|
|
43901
|
+
if (statSync(path12).size > MAX_BYTES) {
|
|
43902
|
+
renameSync(path12, `${path12}.1`);
|
|
43582
43903
|
}
|
|
43583
43904
|
} catch {
|
|
43584
43905
|
}
|
|
43585
43906
|
const lines = entries.map((e) => `${new Date(e.t).toISOString()} [${oneLine(e.cat)}] ${oneLine(e.msg)}`).join("\n");
|
|
43586
|
-
appendFileSync(
|
|
43907
|
+
appendFileSync(path12, `${lines}
|
|
43587
43908
|
`, "utf-8");
|
|
43588
43909
|
return reply.send({ written: entries.length });
|
|
43589
43910
|
} catch (err) {
|
|
@@ -43659,24 +43980,24 @@ import { existsSync } from "node:fs";
|
|
|
43659
43980
|
import http from "node:http";
|
|
43660
43981
|
import net from "node:net";
|
|
43661
43982
|
import crypto from "node:crypto";
|
|
43662
|
-
import
|
|
43663
|
-
import
|
|
43983
|
+
import os2 from "node:os";
|
|
43984
|
+
import path3 from "node:path";
|
|
43664
43985
|
import { mkdir, readdir as readdir2, symlink, lstat, access, readFile, writeFile, unlink } from "node:fs/promises";
|
|
43665
|
-
var VSCODE_WEB_DATA_DIR =
|
|
43986
|
+
var VSCODE_WEB_DATA_DIR = path3.join(os2.homedir(), ".repoburg", "vscode-web");
|
|
43666
43987
|
function resolveDesktopUserDir() {
|
|
43667
43988
|
if (process.platform === "darwin") {
|
|
43668
|
-
return
|
|
43989
|
+
return path3.join(os2.homedir(), "Library", "Application Support", "Code", "User");
|
|
43669
43990
|
}
|
|
43670
43991
|
if (process.platform === "win32" && process.env.APPDATA) {
|
|
43671
|
-
return
|
|
43992
|
+
return path3.join(process.env.APPDATA, "Code", "User");
|
|
43672
43993
|
}
|
|
43673
43994
|
if (process.platform === "linux") {
|
|
43674
|
-
return
|
|
43995
|
+
return path3.join(os2.homedir(), ".config", "Code", "User");
|
|
43675
43996
|
}
|
|
43676
43997
|
return null;
|
|
43677
43998
|
}
|
|
43678
43999
|
async function linkUnlessExists(src, dst) {
|
|
43679
|
-
await mkdir(
|
|
44000
|
+
await mkdir(path3.dirname(dst), { recursive: true });
|
|
43680
44001
|
try {
|
|
43681
44002
|
await lstat(dst);
|
|
43682
44003
|
return false;
|
|
@@ -43691,19 +44012,19 @@ function fileRegistryUri(dir) {
|
|
|
43691
44012
|
}
|
|
43692
44013
|
async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
|
|
43693
44014
|
try {
|
|
43694
|
-
const desktopExt =
|
|
44015
|
+
const desktopExt = path3.join(os2.homedir(), ".vscode", "extensions");
|
|
43695
44016
|
let entries;
|
|
43696
44017
|
try {
|
|
43697
44018
|
entries = await readdir2(desktopExt, { withFileTypes: true });
|
|
43698
44019
|
} catch {
|
|
43699
44020
|
return;
|
|
43700
44021
|
}
|
|
43701
|
-
const serverExt =
|
|
44022
|
+
const serverExt = path3.join(dataDir, "extensions");
|
|
43702
44023
|
const linkedFolders = [];
|
|
43703
44024
|
for (const entry of entries) {
|
|
43704
44025
|
if (!entry.isDirectory()) continue;
|
|
43705
|
-
const target =
|
|
43706
|
-
await linkUnlessExists(
|
|
44026
|
+
const target = path3.join(serverExt, entry.name);
|
|
44027
|
+
await linkUnlessExists(path3.join(desktopExt, entry.name), target);
|
|
43707
44028
|
const st = await lstat(target).catch(() => null);
|
|
43708
44029
|
if (st?.isSymbolicLink()) linkedFolders.push(entry.name);
|
|
43709
44030
|
}
|
|
@@ -43711,15 +44032,15 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
|
|
|
43711
44032
|
await pruneObsolete(serverExt, linkedFolders);
|
|
43712
44033
|
const desktopUser = resolveDesktopUserDir();
|
|
43713
44034
|
if (!desktopUser) return;
|
|
43714
|
-
const serverUser =
|
|
44035
|
+
const serverUser = path3.join(dataDir, "data", "User");
|
|
43715
44036
|
for (const item of ["settings.json", "keybindings.json", "snippets"]) {
|
|
43716
|
-
const src =
|
|
44037
|
+
const src = path3.join(desktopUser, item);
|
|
43717
44038
|
try {
|
|
43718
44039
|
await access(src);
|
|
43719
44040
|
} catch {
|
|
43720
44041
|
continue;
|
|
43721
44042
|
}
|
|
43722
|
-
await linkUnlessExists(src,
|
|
44043
|
+
await linkUnlessExists(src, path3.join(serverUser, item));
|
|
43723
44044
|
}
|
|
43724
44045
|
} catch {
|
|
43725
44046
|
}
|
|
@@ -43727,13 +44048,13 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
|
|
|
43727
44048
|
async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
|
|
43728
44049
|
let desktopEntries = [];
|
|
43729
44050
|
try {
|
|
43730
|
-
desktopEntries = JSON.parse(await readFile(
|
|
44051
|
+
desktopEntries = JSON.parse(await readFile(path3.join(desktopExt, "extensions.json"), "utf8"));
|
|
43731
44052
|
} catch {
|
|
43732
44053
|
return;
|
|
43733
44054
|
}
|
|
43734
44055
|
const linked = new Set(linkedFolders);
|
|
43735
44056
|
const toAdd = desktopEntries.filter((e) => e.identifier?.id && linked.has(e.relativeLocation));
|
|
43736
|
-
const serverRegistryPath =
|
|
44057
|
+
const serverRegistryPath = path3.join(serverExt, "extensions.json");
|
|
43737
44058
|
let serverEntries = [];
|
|
43738
44059
|
try {
|
|
43739
44060
|
serverEntries = JSON.parse(await readFile(serverRegistryPath, "utf8"));
|
|
@@ -43743,13 +44064,13 @@ async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
|
|
|
43743
44064
|
const additions = toAdd.filter((e) => !known.has(`${e.identifier.id.toLowerCase()}@${e.version}`));
|
|
43744
44065
|
if (additions.length === 0) return;
|
|
43745
44066
|
for (const entry of additions) {
|
|
43746
|
-
const dir =
|
|
44067
|
+
const dir = path3.join(serverExt, entry.relativeLocation);
|
|
43747
44068
|
serverEntries.push({ ...entry, location: fileRegistryUri(dir) });
|
|
43748
44069
|
}
|
|
43749
44070
|
await writeFile(serverRegistryPath, JSON.stringify(serverEntries));
|
|
43750
44071
|
}
|
|
43751
44072
|
async function pruneObsolete(serverExt, linkedFolders) {
|
|
43752
|
-
const obsoletePath =
|
|
44073
|
+
const obsoletePath = path3.join(serverExt, ".obsolete");
|
|
43753
44074
|
let obsolete;
|
|
43754
44075
|
try {
|
|
43755
44076
|
obsolete = JSON.parse(await readFile(obsoletePath, "utf8"));
|
|
@@ -44207,17 +44528,17 @@ function proxyHandler(request, reply) {
|
|
|
44207
44528
|
}
|
|
44208
44529
|
|
|
44209
44530
|
// src/routes/apps.ts
|
|
44210
|
-
import
|
|
44211
|
-
import
|
|
44531
|
+
import fs6 from "node:fs";
|
|
44532
|
+
import path8 from "node:path";
|
|
44212
44533
|
|
|
44213
44534
|
// src/apps/instances.ts
|
|
44214
|
-
import
|
|
44215
|
-
import
|
|
44535
|
+
import fs3 from "node:fs";
|
|
44536
|
+
import path5 from "node:path";
|
|
44216
44537
|
|
|
44217
44538
|
// src/apps/apps-registry.ts
|
|
44218
|
-
import
|
|
44219
|
-
import
|
|
44220
|
-
import
|
|
44539
|
+
import fs2 from "node:fs";
|
|
44540
|
+
import path4 from "node:path";
|
|
44541
|
+
import os3 from "node:os";
|
|
44221
44542
|
import { fileURLToPath } from "node:url";
|
|
44222
44543
|
|
|
44223
44544
|
// node_modules/lucide-static/icon-nodes.json
|
|
@@ -98441,10 +98762,10 @@ function setAppsRootOverride(root) {
|
|
|
98441
98762
|
rootOverride = root;
|
|
98442
98763
|
}
|
|
98443
98764
|
function appsRoot() {
|
|
98444
|
-
return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ??
|
|
98765
|
+
return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ?? path4.join(os3.homedir(), ".repoburg", "agent-pane", "apps");
|
|
98445
98766
|
}
|
|
98446
98767
|
function appDir(id) {
|
|
98447
|
-
return
|
|
98768
|
+
return path4.join(appsRoot(), id);
|
|
98448
98769
|
}
|
|
98449
98770
|
var examplesRootOverride = null;
|
|
98450
98771
|
function setExamplesRootOverride(root) {
|
|
@@ -98453,28 +98774,28 @@ function setExamplesRootOverride(root) {
|
|
|
98453
98774
|
function examplesRoot() {
|
|
98454
98775
|
if (examplesRootOverride) return examplesRootOverride;
|
|
98455
98776
|
if (process.env.AGENT_PANE_EXAMPLES_DIR) return process.env.AGENT_PANE_EXAMPLES_DIR;
|
|
98456
|
-
const here =
|
|
98457
|
-
for (const candidate of [
|
|
98458
|
-
if (
|
|
98777
|
+
const here = path4.dirname(fileURLToPath(import.meta.url));
|
|
98778
|
+
for (const candidate of [path4.resolve(here, "../../examples"), path4.resolve(here, "../../../examples")]) {
|
|
98779
|
+
if (fs2.existsSync(candidate)) return candidate;
|
|
98459
98780
|
}
|
|
98460
98781
|
return null;
|
|
98461
98782
|
}
|
|
98462
98783
|
function isInAppFolder(cwd) {
|
|
98463
98784
|
if (!cwd) return false;
|
|
98464
|
-
const rel =
|
|
98465
|
-
return rel !== "" && !
|
|
98785
|
+
const rel = path4.relative(path4.resolve(appsRoot()), path4.resolve(cwd));
|
|
98786
|
+
return rel !== "" && !path4.isAbsolute(rel) && rel.split(path4.sep)[0] !== "..";
|
|
98466
98787
|
}
|
|
98467
98788
|
function appsConventions() {
|
|
98468
98789
|
return APPS_MD_SKELETON;
|
|
98469
98790
|
}
|
|
98470
98791
|
function ensureAppsRoot() {
|
|
98471
98792
|
const root = appsRoot();
|
|
98472
|
-
|
|
98793
|
+
fs2.mkdirSync(root, { recursive: true });
|
|
98473
98794
|
for (const name of ["CLAUDE.md", "AGENTS.md"]) {
|
|
98474
|
-
const file =
|
|
98795
|
+
const file = path4.join(root, name);
|
|
98475
98796
|
try {
|
|
98476
|
-
if (
|
|
98477
|
-
|
|
98797
|
+
if (fs2.existsSync(file) && fs2.readFileSync(file, "utf-8") === APPS_MD_FILE) continue;
|
|
98798
|
+
fs2.writeFileSync(file, APPS_MD_FILE);
|
|
98478
98799
|
} catch (err) {
|
|
98479
98800
|
console.warn(`[apps] could not update ${file}: ${err.message}`);
|
|
98480
98801
|
}
|
|
@@ -98639,7 +98960,7 @@ folder's own CLAUDE.md / AGENTS.md. -->
|
|
|
98639
98960
|
${APPS_MD_SKELETON}`;
|
|
98640
98961
|
function readManifestIn(dir) {
|
|
98641
98962
|
try {
|
|
98642
|
-
const raw =
|
|
98963
|
+
const raw = fs2.readFileSync(path4.join(dir, "manifest.json"), "utf-8");
|
|
98643
98964
|
const parsed = JSON.parse(raw);
|
|
98644
98965
|
if (!parsed || typeof parsed.title !== "string") return null;
|
|
98645
98966
|
return {
|
|
@@ -98657,7 +98978,7 @@ function readManifest(id) {
|
|
|
98657
98978
|
}
|
|
98658
98979
|
function readAppFile(id, name) {
|
|
98659
98980
|
try {
|
|
98660
|
-
return
|
|
98981
|
+
return fs2.readFileSync(path4.join(appDir(id), name), "utf-8");
|
|
98661
98982
|
} catch {
|
|
98662
98983
|
return "";
|
|
98663
98984
|
}
|
|
@@ -98675,7 +98996,7 @@ function readState(id) {
|
|
|
98675
98996
|
}
|
|
98676
98997
|
function isRegularFile(p) {
|
|
98677
98998
|
try {
|
|
98678
|
-
return
|
|
98999
|
+
return fs2.statSync(p).isFile();
|
|
98679
99000
|
} catch {
|
|
98680
99001
|
return false;
|
|
98681
99002
|
}
|
|
@@ -98686,15 +99007,15 @@ var HOT_RELOAD_DEBOUNCE_MS = 250;
|
|
|
98686
99007
|
function startAppsWatch(onAppChange) {
|
|
98687
99008
|
stopAppsWatch();
|
|
98688
99009
|
const root = appsRoot();
|
|
98689
|
-
|
|
99010
|
+
fs2.mkdirSync(root, { recursive: true });
|
|
98690
99011
|
try {
|
|
98691
|
-
watcher =
|
|
99012
|
+
watcher = fs2.watch(root, { recursive: true }, (_event, filename) => {
|
|
98692
99013
|
const rel = String(filename ?? "");
|
|
98693
|
-
const segs = rel.split(
|
|
99014
|
+
const segs = rel.split(path4.sep);
|
|
98694
99015
|
const appId = segs[0];
|
|
98695
99016
|
const file = segs[segs.length - 1];
|
|
98696
|
-
if (!appId || appId ===
|
|
98697
|
-
if (segs.length === 1 && isRegularFile(
|
|
99017
|
+
if (!appId || appId === path4.basename(root) || !APP_ID_RE.test(appId) || file === "state.json") return;
|
|
99018
|
+
if (segs.length === 1 && isRegularFile(path4.join(root, appId))) return;
|
|
98698
99019
|
const timer2 = pendingChanges.get(appId);
|
|
98699
99020
|
if (timer2) clearTimeout(timer2);
|
|
98700
99021
|
pendingChanges.set(
|
|
@@ -98765,12 +99086,12 @@ function getInstanceState(appId, workspace = "") {
|
|
|
98765
99086
|
const stored = readRow(appId, workspace);
|
|
98766
99087
|
if (stored) return stored;
|
|
98767
99088
|
if (workspace === "") {
|
|
98768
|
-
const legacyFile =
|
|
98769
|
-
if (
|
|
99089
|
+
const legacyFile = path5.join(appDir(appId), "state.json");
|
|
99090
|
+
if (fs3.existsSync(legacyFile)) {
|
|
98770
99091
|
const legacy = readState(appId);
|
|
98771
99092
|
const imported = { pinned: legacy.pinned, data: legacy.data, version: 1 };
|
|
98772
99093
|
writeRow(appId, "", imported);
|
|
98773
|
-
|
|
99094
|
+
fs3.rmSync(legacyFile, { force: true });
|
|
98774
99095
|
return imported;
|
|
98775
99096
|
}
|
|
98776
99097
|
}
|
|
@@ -98798,14 +99119,14 @@ function deleteAppInstances(appId) {
|
|
|
98798
99119
|
}
|
|
98799
99120
|
|
|
98800
99121
|
// src/apps/mcp-tools.ts
|
|
98801
|
-
import
|
|
99122
|
+
import fs5 from "node:fs";
|
|
98802
99123
|
|
|
98803
99124
|
// src/apps/headless-runtime.ts
|
|
98804
99125
|
import vm2 from "node:vm";
|
|
98805
99126
|
|
|
98806
99127
|
// src/apps/app-compile.ts
|
|
98807
99128
|
import vm from "node:vm";
|
|
98808
|
-
import
|
|
99129
|
+
import path6 from "node:path";
|
|
98809
99130
|
import ts from "typescript";
|
|
98810
99131
|
|
|
98811
99132
|
// src/apps/app-lint.ts
|
|
@@ -99097,15 +99418,15 @@ function typeCheckModules(appId, modules) {
|
|
|
99097
99418
|
};
|
|
99098
99419
|
const host = ts.createCompilerHost(options);
|
|
99099
99420
|
const origReadFile = host.readFile.bind(host);
|
|
99100
|
-
host.readFile = (fname) =>
|
|
99421
|
+
host.readFile = (fname) => path6.basename(fname) === BRIDGE_DTS_FILE ? BRIDGE_DTS : origReadFile(fname);
|
|
99101
99422
|
host.writeFile = () => {
|
|
99102
99423
|
};
|
|
99103
|
-
const bridgePath =
|
|
99104
|
-
const rootNames = [...modules.map((m) =>
|
|
99424
|
+
const bridgePath = path6.join(dir, BRIDGE_DTS_FILE);
|
|
99425
|
+
const rootNames = [...modules.map((m) => path6.join(dir, m.file)), bridgePath];
|
|
99105
99426
|
const program = ts.createProgram(rootNames, options, host);
|
|
99106
99427
|
const out = [];
|
|
99107
99428
|
for (const mod of modules) {
|
|
99108
|
-
const sf = program.getSourceFile(
|
|
99429
|
+
const sf = program.getSourceFile(path6.join(dir, mod.file));
|
|
99109
99430
|
if (!sf) continue;
|
|
99110
99431
|
out.push(
|
|
99111
99432
|
...[...program.getSyntacticDiagnostics(sf), ...program.getSemanticDiagnostics(sf)].map((d) => tsDiagnosticToFile(mod.file, d)).filter((d) => d !== null)
|
|
@@ -99186,9 +99507,9 @@ function compileAppJs(appId) {
|
|
|
99186
99507
|
|
|
99187
99508
|
// src/apps/app-files.ts
|
|
99188
99509
|
import crypto2 from "node:crypto";
|
|
99189
|
-
import
|
|
99190
|
-
import
|
|
99191
|
-
import
|
|
99510
|
+
import fs4 from "node:fs";
|
|
99511
|
+
import os4 from "node:os";
|
|
99512
|
+
import path7 from "node:path";
|
|
99192
99513
|
var APP_FILE_MAX_BYTES = 5 * 1024 * 1024;
|
|
99193
99514
|
var APP_FILE_TYPES = {
|
|
99194
99515
|
"image/png": "png",
|
|
@@ -99213,11 +99534,11 @@ function setAppFilesRootOverride(root) {
|
|
|
99213
99534
|
rootOverride2 = root;
|
|
99214
99535
|
}
|
|
99215
99536
|
function appFilesRoot() {
|
|
99216
|
-
return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ??
|
|
99537
|
+
return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ?? path7.join(os4.homedir(), ".repoburg", "agent-pane", "app-files");
|
|
99217
99538
|
}
|
|
99218
99539
|
function appFilesDir(appId) {
|
|
99219
99540
|
if (!APP_ID_RE.test(appId)) throw new AppFileError("Invalid app id", 400);
|
|
99220
|
-
return
|
|
99541
|
+
return path7.join(appFilesRoot(), appId);
|
|
99221
99542
|
}
|
|
99222
99543
|
function appFileUrl(appId, fileId) {
|
|
99223
99544
|
return `/api/apps/${appId}/files/${fileId}`;
|
|
@@ -99278,12 +99599,12 @@ function saveAppFile(appId, upload) {
|
|
|
99278
99599
|
const type = sniffImageType(bytes);
|
|
99279
99600
|
if (!type) throw new AppFileError(`The file is not a ${ACCEPTED} image`, 400);
|
|
99280
99601
|
const fileId = `${crypto2.createHash("sha256").update(bytes).digest("hex")}.${APP_FILE_TYPES[type]}`;
|
|
99281
|
-
const file =
|
|
99282
|
-
if (!
|
|
99283
|
-
|
|
99602
|
+
const file = path7.join(dir, fileId);
|
|
99603
|
+
if (!fs4.existsSync(file)) {
|
|
99604
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
99284
99605
|
const tmp = `${file}.${process.pid}.${crypto2.randomBytes(4).toString("hex")}.tmp`;
|
|
99285
|
-
|
|
99286
|
-
|
|
99606
|
+
fs4.writeFileSync(tmp, bytes);
|
|
99607
|
+
fs4.renameSync(tmp, file);
|
|
99287
99608
|
}
|
|
99288
99609
|
return { id: fileId, url: appFileUrl(appId, fileId), path: file, type, size: bytes.length };
|
|
99289
99610
|
}
|
|
@@ -99310,9 +99631,9 @@ function getAppFile(appId, ref) {
|
|
|
99310
99631
|
if (!APP_ID_RE.test(appId)) return null;
|
|
99311
99632
|
const fileId = appFileRefId(appId, ref);
|
|
99312
99633
|
if (!fileId) return null;
|
|
99313
|
-
const file =
|
|
99634
|
+
const file = path7.join(appFilesDir(appId), fileId);
|
|
99314
99635
|
try {
|
|
99315
|
-
const stat2 =
|
|
99636
|
+
const stat2 = fs4.statSync(file);
|
|
99316
99637
|
if (!stat2.isFile()) return null;
|
|
99317
99638
|
return { id: fileId, url: appFileUrl(appId, fileId), path: file, type: fileType(fileId), size: stat2.size };
|
|
99318
99639
|
} catch {
|
|
@@ -99322,14 +99643,14 @@ function getAppFile(appId, ref) {
|
|
|
99322
99643
|
function readAppFileData(appId, fileId) {
|
|
99323
99644
|
if (!APP_ID_RE.test(appId) || !APP_FILE_ID_RE.test(fileId)) return null;
|
|
99324
99645
|
try {
|
|
99325
|
-
return { bytes:
|
|
99646
|
+
return { bytes: fs4.readFileSync(path7.join(appFilesDir(appId), fileId)), type: fileType(fileId) };
|
|
99326
99647
|
} catch {
|
|
99327
99648
|
return null;
|
|
99328
99649
|
}
|
|
99329
99650
|
}
|
|
99330
99651
|
function deleteAppFiles(appId) {
|
|
99331
99652
|
if (!APP_ID_RE.test(appId)) return;
|
|
99332
|
-
|
|
99653
|
+
fs4.rmSync(appFilesDir(appId), { recursive: true, force: true });
|
|
99333
99654
|
}
|
|
99334
99655
|
|
|
99335
99656
|
// src/apps/headless-runtime.ts
|
|
@@ -99510,7 +99831,7 @@ var TOOL_NS = "__";
|
|
|
99510
99831
|
function listAppTools() {
|
|
99511
99832
|
const tools = [];
|
|
99512
99833
|
try {
|
|
99513
|
-
for (const entry of
|
|
99834
|
+
for (const entry of fs5.readdirSync(appsRoot(), { withFileTypes: true })) {
|
|
99514
99835
|
if (!entry.isDirectory()) continue;
|
|
99515
99836
|
const manifest = readManifest(entry.name);
|
|
99516
99837
|
for (const tool of manifest?.tools ?? []) {
|
|
@@ -99586,9 +99907,9 @@ function resolveToolWorkspace(workspace) {
|
|
|
99586
99907
|
const rows = getDb().prepare("SELECT path, deleted FROM workspaces").all();
|
|
99587
99908
|
const active = rows.filter((w) => !w.deleted).map((w) => w.path);
|
|
99588
99909
|
if (active.includes(workspace)) return workspace;
|
|
99589
|
-
const cwd =
|
|
99910
|
+
const cwd = path8.isAbsolute(workspace) ? path8.resolve(workspace) : "";
|
|
99590
99911
|
if (isInAppFolder(cwd)) return "";
|
|
99591
|
-
const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path +
|
|
99912
|
+
const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path + path8.sep)).sort((a, b) => b.path.length - a.path.length)[0];
|
|
99592
99913
|
if (covering && !covering.deleted) return covering.path;
|
|
99593
99914
|
throw new Error(`Unknown workspace: ${workspace}. Known workspaces: ${active.join(", ") || "none"}`);
|
|
99594
99915
|
}
|
|
@@ -99643,7 +99964,7 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
99643
99964
|
fastify.get("/api/apps", async () => {
|
|
99644
99965
|
try {
|
|
99645
99966
|
ensureAppsRoot();
|
|
99646
|
-
const entries =
|
|
99967
|
+
const entries = fs6.readdirSync(appsRoot(), { withFileTypes: true });
|
|
99647
99968
|
const apps = [];
|
|
99648
99969
|
for (const entry of entries) {
|
|
99649
99970
|
if (!entry.isDirectory() || !APP_ID_RE.test(entry.name)) continue;
|
|
@@ -99670,9 +99991,9 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
99670
99991
|
if (!exRoot) return [];
|
|
99671
99992
|
const out = [];
|
|
99672
99993
|
try {
|
|
99673
|
-
for (const entry of
|
|
99994
|
+
for (const entry of fs6.readdirSync(exRoot, { withFileTypes: true })) {
|
|
99674
99995
|
if (!entry.isDirectory() || !APP_ID_RE.test(entry.name)) continue;
|
|
99675
|
-
const manifest = readManifestIn(
|
|
99996
|
+
const manifest = readManifestIn(path8.join(exRoot, entry.name));
|
|
99676
99997
|
if (!manifest) continue;
|
|
99677
99998
|
out.push({
|
|
99678
99999
|
id: entry.name,
|
|
@@ -99693,11 +100014,11 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
99693
100014
|
if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
|
|
99694
100015
|
const exRoot = examplesRoot();
|
|
99695
100016
|
if (!exRoot) return reply.code(404).send({ error: "Examples catalog not available" });
|
|
99696
|
-
const src =
|
|
100017
|
+
const src = path8.join(exRoot, id);
|
|
99697
100018
|
if (!readManifestIn(src)) return reply.code(404).send({ error: "Example not found" });
|
|
99698
100019
|
if (readManifest(id)) return reply.code(409).send({ error: "App already installed" });
|
|
99699
100020
|
ensureAppsRoot();
|
|
99700
|
-
|
|
100021
|
+
fs6.cpSync(src, appDir(id), { recursive: true });
|
|
99701
100022
|
return { ok: true, id };
|
|
99702
100023
|
});
|
|
99703
100024
|
fastify.post(
|
|
@@ -99729,10 +100050,10 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
99729
100050
|
if (readManifest(id)) return reply.code(409).send({ error: "App already exists" });
|
|
99730
100051
|
ensureAppsRoot();
|
|
99731
100052
|
const dir = appDir(id);
|
|
99732
|
-
|
|
100053
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
99733
100054
|
const cleanTitle2 = title.trim();
|
|
99734
|
-
|
|
99735
|
-
|
|
100055
|
+
fs6.writeFileSync(
|
|
100056
|
+
path8.join(dir, "manifest.json"),
|
|
99736
100057
|
JSON.stringify(
|
|
99737
100058
|
{
|
|
99738
100059
|
title: cleanTitle2,
|
|
@@ -99743,8 +100064,8 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
99743
100064
|
2
|
|
99744
100065
|
)
|
|
99745
100066
|
);
|
|
99746
|
-
|
|
99747
|
-
|
|
100067
|
+
fs6.writeFileSync(path8.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
|
|
100068
|
+
fs6.writeFileSync(path8.join(dir, "app.ts"), SKELETON_TS);
|
|
99748
100069
|
return { ok: true, id };
|
|
99749
100070
|
}
|
|
99750
100071
|
);
|
|
@@ -99779,11 +100100,11 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
99779
100100
|
if (readManifest(id)) return reply.code(409).send({ error: "App already exists" });
|
|
99780
100101
|
ensureAppsRoot();
|
|
99781
100102
|
const dir = appDir(id);
|
|
99782
|
-
|
|
100103
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
99783
100104
|
if (!Object.hasOwn(files ?? {}, "manifest.json")) {
|
|
99784
|
-
|
|
100105
|
+
fs6.writeFileSync(path8.join(dir, "manifest.json"), JSON.stringify({ title: id }, null, 2));
|
|
99785
100106
|
}
|
|
99786
|
-
for (const [name, content] of entries)
|
|
100107
|
+
for (const [name, content] of entries) fs6.writeFileSync(path8.join(dir, name), content);
|
|
99787
100108
|
return { ok: true, id };
|
|
99788
100109
|
}
|
|
99789
100110
|
);
|
|
@@ -99945,7 +100266,7 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
99945
100266
|
const { id } = request.params;
|
|
99946
100267
|
if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
|
|
99947
100268
|
if (!readManifest(id)) return reply.code(404).send({ error: "App not found" });
|
|
99948
|
-
|
|
100269
|
+
fs6.rmSync(appDir(id), { recursive: true, force: true });
|
|
99949
100270
|
deleteAppFiles(id);
|
|
99950
100271
|
deleteAppInstances(id);
|
|
99951
100272
|
invalidateHeadlessRuntime(id);
|
|
@@ -100458,7 +100779,7 @@ async function registerUsageRoutes(fastify) {
|
|
|
100458
100779
|
|
|
100459
100780
|
// src/claude/session-import.ts
|
|
100460
100781
|
import { readFile as readFile2, realpath } from "node:fs/promises";
|
|
100461
|
-
import
|
|
100782
|
+
import path9 from "node:path";
|
|
100462
100783
|
import { getSessionInfo, listSessions } from "@anthropic-ai/claude-agent-sdk";
|
|
100463
100784
|
|
|
100464
100785
|
// src/claude/claude-message-mapper.ts
|
|
@@ -100538,9 +100859,9 @@ function mapToolUse(block) {
|
|
|
100538
100859
|
};
|
|
100539
100860
|
}
|
|
100540
100861
|
function deriveFileChangeData(input, toolName) {
|
|
100541
|
-
const
|
|
100862
|
+
const path12 = input.file_path ?? input.notebook_path ?? "";
|
|
100542
100863
|
const kind = toolName === "Write" ? "add" : "modify";
|
|
100543
|
-
return { changes: [{ path:
|
|
100864
|
+
return { changes: [{ path: path12, kind }], status: "in_progress" };
|
|
100544
100865
|
}
|
|
100545
100866
|
function extractToolResultText(content) {
|
|
100546
100867
|
if (!content) return "";
|
|
@@ -100903,7 +101224,7 @@ async function realDir(dir) {
|
|
|
100903
101224
|
}
|
|
100904
101225
|
}
|
|
100905
101226
|
async function sameDir(a, realB) {
|
|
100906
|
-
const realA = await realDir(a) ??
|
|
101227
|
+
const realA = await realDir(a) ?? path9.resolve(a);
|
|
100907
101228
|
return realA === realB;
|
|
100908
101229
|
}
|
|
100909
101230
|
function knownClaudeSessionIds(db2) {
|
|
@@ -101138,23 +101459,23 @@ function mapTokenUsage(data) {
|
|
|
101138
101459
|
}
|
|
101139
101460
|
|
|
101140
101461
|
// src/apps/register-mcp.ts
|
|
101141
|
-
import
|
|
101142
|
-
import
|
|
101462
|
+
import fs7 from "node:fs";
|
|
101463
|
+
import path10 from "node:path";
|
|
101143
101464
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
101144
101465
|
var MCP_SERVER_NAME = "agentpane-miniapps";
|
|
101145
101466
|
function panePublicUrl() {
|
|
101146
101467
|
return (process.env.AGENT_PANE_PUBLIC_URL || process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
|
|
101147
101468
|
}
|
|
101148
101469
|
function stdioScriptPath() {
|
|
101149
|
-
const here =
|
|
101470
|
+
const here = path10.dirname(fileURLToPath2(import.meta.url));
|
|
101150
101471
|
const candidates = [
|
|
101151
|
-
|
|
101472
|
+
path10.resolve(here, "../../scripts/miniapp-mcp-stdio.mjs"),
|
|
101152
101473
|
// src/apps/ → backend/scripts
|
|
101153
|
-
|
|
101474
|
+
path10.resolve(here, "../scripts/miniapp-mcp-stdio.mjs")
|
|
101154
101475
|
// dist bundle → backend/scripts
|
|
101155
101476
|
];
|
|
101156
101477
|
for (const candidate of candidates) {
|
|
101157
|
-
if (
|
|
101478
|
+
if (fs7.existsSync(candidate)) return candidate;
|
|
101158
101479
|
}
|
|
101159
101480
|
return null;
|
|
101160
101481
|
}
|
|
@@ -101943,7 +102264,6 @@ async function refreshContext(entry, sessionId, db2) {
|
|
|
101943
102264
|
|
|
101944
102265
|
// src/claude/api-errors.ts
|
|
101945
102266
|
var FATAL_ERRORS = /* @__PURE__ */ new Set([
|
|
101946
|
-
"authentication_failed",
|
|
101947
102267
|
"oauth_org_not_allowed",
|
|
101948
102268
|
"account_on_hold",
|
|
101949
102269
|
"verification_required",
|
|
@@ -101965,7 +102285,15 @@ var NETWORK_TEXTS = [
|
|
|
101965
102285
|
/socket hang up|fetch failed|network error/i,
|
|
101966
102286
|
/overloaded/i
|
|
101967
102287
|
];
|
|
101968
|
-
|
|
102288
|
+
var SIGN_IN_ADVICE = /\/login|(sign|log) in again/i;
|
|
102289
|
+
var OUTSIDE_LOGIN_TEXTS = /api[ -]key|gateway|bedrock|vertex|foundry|mantle/i;
|
|
102290
|
+
function isSignedOut(text) {
|
|
102291
|
+
if (!text) return true;
|
|
102292
|
+
return SIGN_IN_ADVICE.test(text) || !OUTSIDE_LOGIN_TEXTS.test(text);
|
|
102293
|
+
}
|
|
102294
|
+
function classifyApiError({ error, status, text, limitRejected }) {
|
|
102295
|
+
if (error === "authentication_failed" || !error && status === 401) return isSignedOut(text) ? "auth" : "fatal";
|
|
102296
|
+
if (limitRejected && (error === "rate_limit" || !error && status === 429)) return "usage_limit";
|
|
101969
102297
|
if (error && FATAL_ERRORS.has(error)) return "fatal";
|
|
101970
102298
|
if (error && TRANSIENT_ERRORS.has(error)) return "network";
|
|
101971
102299
|
if (typeof status === "number") {
|
|
@@ -102330,6 +102658,10 @@ async function ensureSessionStarted(session, mapKey, resumeSessionId, resume) {
|
|
|
102330
102658
|
handleBackgroundTasksChanged(message, session.id, entry);
|
|
102331
102659
|
continue;
|
|
102332
102660
|
}
|
|
102661
|
+
if (message.type === "rate_limit_event") {
|
|
102662
|
+
entry.rateLimit = message.rate_limit_info;
|
|
102663
|
+
continue;
|
|
102664
|
+
}
|
|
102333
102665
|
const currentTurnId = entry.turnId;
|
|
102334
102666
|
if (!currentTurnId) {
|
|
102335
102667
|
handleTaskFrame(message, session.id, entry, db2);
|
|
@@ -102882,11 +103214,18 @@ async function handleResultMessage(message, sessionId, turnId, entry, db2) {
|
|
|
102882
103214
|
const apiError = entry.lastApiError;
|
|
102883
103215
|
entry.lastApiError = null;
|
|
102884
103216
|
if (message.is_error) {
|
|
102885
|
-
const row = db2.prepare("SELECT status FROM turns WHERE id = ?").get(turnId);
|
|
103217
|
+
const row = db2.prepare("SELECT status, resume_state FROM turns WHERE id = ?").get(turnId);
|
|
102886
103218
|
if (row?.status !== "pending" && row?.status !== "running") return;
|
|
103219
|
+
if (row.status === "pending" && row.resume_state === "waiting") return;
|
|
102887
103220
|
const text = (message.result || apiError?.text || "Claude API error").trim();
|
|
102888
|
-
const kind = classifyApiError({
|
|
102889
|
-
|
|
103221
|
+
const kind = classifyApiError({
|
|
103222
|
+
error: apiError?.error,
|
|
103223
|
+
status: message.api_error_status,
|
|
103224
|
+
text,
|
|
103225
|
+
limitRejected: entry.rateLimit?.status === "rejected"
|
|
103226
|
+
});
|
|
103227
|
+
const resumeAt = kind === "usage_limit" ? usageLimitResumeAt(entry.rateLimit?.resetsAt) : null;
|
|
103228
|
+
if (kind !== "fatal" && !entry.threadId && markTurnInterrupted(db2, turnId, kind, { detail: text, resumeAt })) {
|
|
102890
103229
|
return;
|
|
102891
103230
|
}
|
|
102892
103231
|
failTurn(db2, sessionId, turnId, text);
|
|
@@ -103187,9 +103526,22 @@ async function reapOrphans() {
|
|
|
103187
103526
|
const ended = await reapOrphanCliProcesses(getDb());
|
|
103188
103527
|
if (ended > 0) console.log(`[claude] ended ${ended} CLI process(es) left by the previous host`);
|
|
103189
103528
|
}
|
|
103529
|
+
function retireCli(sessionId, entry) {
|
|
103530
|
+
if (entry.turnId) streamingMessageIds.delete(entry.turnId);
|
|
103531
|
+
entry.turnId = null;
|
|
103532
|
+
entry.closeReason ??= "clear";
|
|
103533
|
+
clearResume(entry);
|
|
103534
|
+
entry.promptQueue.close();
|
|
103535
|
+
entry.query.close();
|
|
103536
|
+
sessionMap2.delete(sessionId);
|
|
103537
|
+
}
|
|
103190
103538
|
async function resumeInterruptedTurn(session, turn, opts) {
|
|
103191
103539
|
if (turn.thread_id) throw new Error("Discussion-thread turns cannot be resumed");
|
|
103192
|
-
|
|
103540
|
+
let live = sessionMap2.get(session.id);
|
|
103541
|
+
if (live && opts.reason === "auth" && !live.backgroundTasks?.length) {
|
|
103542
|
+
retireCli(session.id, live);
|
|
103543
|
+
live = void 0;
|
|
103544
|
+
}
|
|
103193
103545
|
if (live && !live.closeReason) {
|
|
103194
103546
|
if (live.turnId && live.turnId !== turn.id) streamingMessageIds.delete(live.turnId);
|
|
103195
103547
|
clearResume(live);
|
|
@@ -103365,8 +103717,8 @@ var RepoburgHttpClient = class {
|
|
|
103365
103717
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
103366
103718
|
}
|
|
103367
103719
|
/** Perform a JSON request. Throws a concise error on non-OK/non-JSON responses. */
|
|
103368
|
-
async request(method,
|
|
103369
|
-
const response = await fetch(`${this.baseUrl}${
|
|
103720
|
+
async request(method, path12, body) {
|
|
103721
|
+
const response = await fetch(`${this.baseUrl}${path12}`, {
|
|
103370
103722
|
method,
|
|
103371
103723
|
headers: { "Content-Type": "application/json" },
|
|
103372
103724
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
@@ -103375,17 +103727,17 @@ var RepoburgHttpClient = class {
|
|
|
103375
103727
|
if (!response.ok) {
|
|
103376
103728
|
if (isHtml(text)) {
|
|
103377
103729
|
throw new Error(
|
|
103378
|
-
`${method} ${
|
|
103730
|
+
`${method} ${path12} failed: ${response.status} HTML response from ${this.baseUrl} \u2014 the URL points to the wrong server`
|
|
103379
103731
|
);
|
|
103380
103732
|
}
|
|
103381
|
-
throw new Error(`${method} ${
|
|
103733
|
+
throw new Error(`${method} ${path12} failed: ${response.status} ${text}`);
|
|
103382
103734
|
}
|
|
103383
103735
|
if (text.length === 0) return void 0;
|
|
103384
103736
|
try {
|
|
103385
103737
|
return JSON.parse(text);
|
|
103386
103738
|
} catch {
|
|
103387
103739
|
throw new Error(
|
|
103388
|
-
`${method} ${
|
|
103740
|
+
`${method} ${path12} failed: non-JSON response from ${this.baseUrl} \u2014 the URL points to the wrong server`
|
|
103389
103741
|
);
|
|
103390
103742
|
}
|
|
103391
103743
|
}
|
|
@@ -103440,7 +103792,7 @@ var RepoburgHttpClient = class {
|
|
|
103440
103792
|
};
|
|
103441
103793
|
|
|
103442
103794
|
// src/repoburg/backend-resolver.ts
|
|
103443
|
-
import
|
|
103795
|
+
import path11 from "node:path";
|
|
103444
103796
|
var HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
103445
103797
|
var HEALTH_TIMEOUT_MS = 3e4;
|
|
103446
103798
|
function daemonBaseUrl() {
|
|
@@ -103495,7 +103847,7 @@ async function backendHealthy(baseUrl, expectedPath) {
|
|
|
103495
103847
|
const health = await fetchJson(`${baseUrl}/health`, void 0, 2e3);
|
|
103496
103848
|
if (health.status !== "ok") return false;
|
|
103497
103849
|
if (expectedPath && health.projectPath) {
|
|
103498
|
-
return
|
|
103850
|
+
return path11.resolve(health.projectPath) === path11.resolve(expectedPath);
|
|
103499
103851
|
}
|
|
103500
103852
|
return true;
|
|
103501
103853
|
} catch {
|
|
@@ -103516,7 +103868,7 @@ function serviceBaseUrl(service) {
|
|
|
103516
103868
|
return `http://localhost:${service.port}`;
|
|
103517
103869
|
}
|
|
103518
103870
|
function coveringService(services, absPath) {
|
|
103519
|
-
return services.filter((s) => absPath === s.path || absPath.startsWith(s.path +
|
|
103871
|
+
return services.filter((s) => absPath === s.path || absPath.startsWith(s.path + path11.sep)).sort((a, b) => b.path.length - a.path.length)[0];
|
|
103520
103872
|
}
|
|
103521
103873
|
async function restartService(daemon, name) {
|
|
103522
103874
|
try {
|
|
@@ -103552,7 +103904,7 @@ async function resolveBackendUrl(projectPath, opts = {}) {
|
|
|
103552
103904
|
if (envUrl) {
|
|
103553
103905
|
return { baseUrl: envUrl.replace(/\/+$/, ""), port: 0, name: "REPOBURG_BACKEND_URL" };
|
|
103554
103906
|
}
|
|
103555
|
-
const absPath =
|
|
103907
|
+
const absPath = path11.resolve(projectPath);
|
|
103556
103908
|
const daemon = daemonBaseUrl();
|
|
103557
103909
|
const cached = resolvedCache.get(absPath);
|
|
103558
103910
|
if (cached && await backendHealthy(cached.baseUrl, cached.servesPath ?? absPath)) {
|
|
@@ -104988,11 +105340,13 @@ async function createAgentPaneApp(dbPath, opts = {}) {
|
|
|
104988
105340
|
await registerSidecarRoutes(fastify);
|
|
104989
105341
|
await registerUsageRoutes(fastify);
|
|
104990
105342
|
await registerClaudeSessionRoutes(fastify);
|
|
104991
|
-
const
|
|
104992
|
-
|
|
105343
|
+
const wss3 = initWs(allowRequest);
|
|
105344
|
+
initTerminalWs(allowRequest);
|
|
105345
|
+
wss3.on("connection", (ws) => {
|
|
104993
105346
|
ws.send(JSON.stringify({ event: "background_tasks:snapshot", data: { sessions: listAllBackgroundTasks() } }));
|
|
105347
|
+
ws.send(JSON.stringify({ event: "signed_out_turns:snapshot", data: { turns: listSignedOutTurns(getDb()) } }));
|
|
104994
105348
|
});
|
|
104995
|
-
return { fastify, wss:
|
|
105349
|
+
return { fastify, wss: wss3 };
|
|
104996
105350
|
}
|
|
104997
105351
|
|
|
104998
105352
|
// src/host-lifecycle.ts
|
|
@@ -105003,11 +105357,12 @@ function startHostServices() {
|
|
|
105003
105357
|
}
|
|
105004
105358
|
async function shutdownHost() {
|
|
105005
105359
|
stopAutoResume();
|
|
105360
|
+
stopAllTerminals();
|
|
105006
105361
|
await shutdownAllProviders();
|
|
105007
105362
|
await getVscodeWebManager().stopAll();
|
|
105008
105363
|
}
|
|
105009
|
-
async function closeServer(fastify,
|
|
105010
|
-
for (const client of
|
|
105364
|
+
async function closeServer(fastify, wss3, timeoutMs = CLOSE_TIMEOUT_MS) {
|
|
105365
|
+
for (const client of wss3.clients) client.terminate();
|
|
105011
105366
|
await Promise.race([
|
|
105012
105367
|
fastify.close(),
|
|
105013
105368
|
// Covers what `wss` does not own, like proxied /vscode sockets.
|
|
@@ -105018,12 +105373,16 @@ async function closeServer(fastify, wss2, timeoutMs = CLOSE_TIMEOUT_MS) {
|
|
|
105018
105373
|
// src/index.ts
|
|
105019
105374
|
var PORT = Number(process.env.AGENT_PANE_PORT ?? 3003);
|
|
105020
105375
|
async function main() {
|
|
105021
|
-
const { fastify, wss:
|
|
105376
|
+
const { fastify, wss: wss3 } = await createAgentPaneApp("data.db");
|
|
105022
105377
|
fastify.server.on("upgrade", (req, socket, head) => {
|
|
105023
105378
|
if ((req.url || "").startsWith("/vscode")) {
|
|
105024
105379
|
handleVscodeWebUpgrade(req, socket, head);
|
|
105025
105380
|
return;
|
|
105026
105381
|
}
|
|
105382
|
+
if (isTerminalUpgrade(req.url)) {
|
|
105383
|
+
handleTerminalUpgrade(req, socket, head);
|
|
105384
|
+
return;
|
|
105385
|
+
}
|
|
105027
105386
|
const wsServer = getWss();
|
|
105028
105387
|
if (wsServer) {
|
|
105029
105388
|
handleUpgrade(wsServer, req, socket, head);
|
|
@@ -105031,10 +105390,10 @@ async function main() {
|
|
|
105031
105390
|
socket.destroy();
|
|
105032
105391
|
}
|
|
105033
105392
|
});
|
|
105034
|
-
|
|
105393
|
+
wss3.on("connection", () => {
|
|
105035
105394
|
fastify.log.info("WebSocket client connected");
|
|
105036
105395
|
});
|
|
105037
|
-
|
|
105396
|
+
wss3.on("close", () => {
|
|
105038
105397
|
fastify.log.info("WebSocket client disconnected");
|
|
105039
105398
|
});
|
|
105040
105399
|
try {
|
|
@@ -105049,7 +105408,7 @@ async function main() {
|
|
|
105049
105408
|
async function gracefulShutdown(signal) {
|
|
105050
105409
|
fastify.log.info(`Received ${signal}, shutting down...`);
|
|
105051
105410
|
await shutdownHost();
|
|
105052
|
-
await closeServer(fastify,
|
|
105411
|
+
await closeServer(fastify, wss3);
|
|
105053
105412
|
process.exit(0);
|
|
105054
105413
|
}
|
|
105055
105414
|
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
|