@essentialai/cogent-bridge-bundled 3.23.6 → 3.23.8
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/cogent-bridge.mjs +505 -390
- package/package.json +1 -1
package/cogent-bridge.mjs
CHANGED
|
@@ -1259,8 +1259,8 @@ var init_parseUtil = __esm({
|
|
|
1259
1259
|
init_errors();
|
|
1260
1260
|
init_en();
|
|
1261
1261
|
makeIssue = (params) => {
|
|
1262
|
-
const { data, path:
|
|
1263
|
-
const fullPath = [...
|
|
1262
|
+
const { data, path: path26, errorMaps, issueData } = params;
|
|
1263
|
+
const fullPath = [...path26, ...issueData.path || []];
|
|
1264
1264
|
const fullIssue = {
|
|
1265
1265
|
...issueData,
|
|
1266
1266
|
path: fullPath
|
|
@@ -1540,11 +1540,11 @@ var init_types = __esm({
|
|
|
1540
1540
|
init_parseUtil();
|
|
1541
1541
|
init_util();
|
|
1542
1542
|
ParseInputLazyPath = class {
|
|
1543
|
-
constructor(parent, value,
|
|
1543
|
+
constructor(parent, value, path26, key) {
|
|
1544
1544
|
this._cachedPath = [];
|
|
1545
1545
|
this.parent = parent;
|
|
1546
1546
|
this.data = value;
|
|
1547
|
-
this._path =
|
|
1547
|
+
this._path = path26;
|
|
1548
1548
|
this._key = key;
|
|
1549
1549
|
}
|
|
1550
1550
|
get path() {
|
|
@@ -4996,10 +4996,10 @@ function assignProp(target, prop, value) {
|
|
|
4996
4996
|
configurable: true
|
|
4997
4997
|
});
|
|
4998
4998
|
}
|
|
4999
|
-
function getElementAtPath(obj,
|
|
5000
|
-
if (!
|
|
4999
|
+
function getElementAtPath(obj, path26) {
|
|
5000
|
+
if (!path26)
|
|
5001
5001
|
return obj;
|
|
5002
|
-
return
|
|
5002
|
+
return path26.reduce((acc, key) => acc?.[key], obj);
|
|
5003
5003
|
}
|
|
5004
5004
|
function promiseAllObject(promisesObj) {
|
|
5005
5005
|
const keys = Object.keys(promisesObj);
|
|
@@ -5248,11 +5248,11 @@ function aborted(x, startIndex = 0) {
|
|
|
5248
5248
|
}
|
|
5249
5249
|
return false;
|
|
5250
5250
|
}
|
|
5251
|
-
function prefixIssues(
|
|
5251
|
+
function prefixIssues(path26, issues) {
|
|
5252
5252
|
return issues.map((iss) => {
|
|
5253
5253
|
var _a;
|
|
5254
5254
|
(_a = iss).path ?? (_a.path = []);
|
|
5255
|
-
iss.path.unshift(
|
|
5255
|
+
iss.path.unshift(path26);
|
|
5256
5256
|
return iss;
|
|
5257
5257
|
});
|
|
5258
5258
|
}
|
|
@@ -17058,8 +17058,8 @@ var require_utils = __commonJS({
|
|
|
17058
17058
|
}
|
|
17059
17059
|
return ind;
|
|
17060
17060
|
}
|
|
17061
|
-
function removeDotSegments(
|
|
17062
|
-
let input =
|
|
17061
|
+
function removeDotSegments(path26) {
|
|
17062
|
+
let input = path26;
|
|
17063
17063
|
const output = [];
|
|
17064
17064
|
let nextSlash = -1;
|
|
17065
17065
|
let len = 0;
|
|
@@ -17258,8 +17258,8 @@ var require_schemes = __commonJS({
|
|
|
17258
17258
|
wsComponent.secure = void 0;
|
|
17259
17259
|
}
|
|
17260
17260
|
if (wsComponent.resourceName) {
|
|
17261
|
-
const [
|
|
17262
|
-
wsComponent.path =
|
|
17261
|
+
const [path26, query] = wsComponent.resourceName.split("?");
|
|
17262
|
+
wsComponent.path = path26 && path26 !== "/" ? path26 : void 0;
|
|
17263
17263
|
wsComponent.query = query;
|
|
17264
17264
|
wsComponent.resourceName = void 0;
|
|
17265
17265
|
}
|
|
@@ -20612,12 +20612,12 @@ var require_dist = __commonJS({
|
|
|
20612
20612
|
throw new Error(`Unknown format "${name}"`);
|
|
20613
20613
|
return f;
|
|
20614
20614
|
};
|
|
20615
|
-
function addFormats(ajv, list,
|
|
20615
|
+
function addFormats(ajv, list, fs24, exportName) {
|
|
20616
20616
|
var _a;
|
|
20617
20617
|
var _b;
|
|
20618
20618
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
20619
20619
|
for (const f of list)
|
|
20620
|
-
ajv.addFormat(f,
|
|
20620
|
+
ajv.addFormat(f, fs24[f]);
|
|
20621
20621
|
}
|
|
20622
20622
|
module.exports = exports = formatsPlugin;
|
|
20623
20623
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -21729,8 +21729,8 @@ var require_parseUtil = __commonJS({
|
|
|
21729
21729
|
var errors_js_1 = require_errors2();
|
|
21730
21730
|
var en_js_1 = __importDefault(require_en());
|
|
21731
21731
|
var makeIssue2 = (params) => {
|
|
21732
|
-
const { data, path:
|
|
21733
|
-
const fullPath = [...
|
|
21732
|
+
const { data, path: path26, errorMaps, issueData } = params;
|
|
21733
|
+
const fullPath = [...path26, ...issueData.path || []];
|
|
21734
21734
|
const fullIssue = {
|
|
21735
21735
|
...issueData,
|
|
21736
21736
|
path: fullPath
|
|
@@ -21884,11 +21884,11 @@ var require_types2 = __commonJS({
|
|
|
21884
21884
|
var parseUtil_js_1 = require_parseUtil();
|
|
21885
21885
|
var util_js_1 = require_util2();
|
|
21886
21886
|
var ParseInputLazyPath2 = class {
|
|
21887
|
-
constructor(parent, value,
|
|
21887
|
+
constructor(parent, value, path26, key) {
|
|
21888
21888
|
this._cachedPath = [];
|
|
21889
21889
|
this.parent = parent;
|
|
21890
21890
|
this.data = value;
|
|
21891
|
-
this._path =
|
|
21891
|
+
this._path = path26;
|
|
21892
21892
|
this._key = key;
|
|
21893
21893
|
}
|
|
21894
21894
|
get path() {
|
|
@@ -26389,8 +26389,8 @@ var init_stdio2 = __esm({
|
|
|
26389
26389
|
// src/constants.ts
|
|
26390
26390
|
import { createRequire } from "node:module";
|
|
26391
26391
|
function resolveVersion() {
|
|
26392
|
-
if ("3.23.
|
|
26393
|
-
return "3.23.
|
|
26392
|
+
if ("3.23.8") {
|
|
26393
|
+
return "3.23.8";
|
|
26394
26394
|
}
|
|
26395
26395
|
try {
|
|
26396
26396
|
const require2 = createRequire(import.meta.url);
|
|
@@ -27826,7 +27826,7 @@ var init_http_backend = __esm({
|
|
|
27826
27826
|
* in cloud mode we ignore it and use this.sessionId (the cloud session).
|
|
27827
27827
|
*/
|
|
27828
27828
|
async registerPeer(peerId, _sessionId, cwd, label, clientVersion, mode, _channelSessionId, capabilities, workspaceId, threadId, peerSecret) {
|
|
27829
|
-
const
|
|
27829
|
+
const path26 = PATHS.peers.replace(":sessionId", this.sessionId);
|
|
27830
27830
|
const body = {
|
|
27831
27831
|
peerId,
|
|
27832
27832
|
cwd,
|
|
@@ -27857,7 +27857,7 @@ var init_http_backend = __esm({
|
|
|
27857
27857
|
if (peerSecret !== void 0 && await relaySupports(this.http, "peer-ownership")) {
|
|
27858
27858
|
body.peerSecret = peerSecret;
|
|
27859
27859
|
}
|
|
27860
|
-
return this.http.post(
|
|
27860
|
+
return this.http.post(path26, body);
|
|
27861
27861
|
}
|
|
27862
27862
|
/**
|
|
27863
27863
|
* Deregister a peer from the cloud session.
|
|
@@ -27869,9 +27869,9 @@ var init_http_backend = __esm({
|
|
|
27869
27869
|
* local mail creds. A 404 (peer not found) resolves to `{ removed: false, ... }`, not a throw.
|
|
27870
27870
|
*/
|
|
27871
27871
|
async deregisterPeer(peerId) {
|
|
27872
|
-
const
|
|
27872
|
+
const path26 = PATHS.peer.replace(":sessionId", this.sessionId).replace(":peerId", peerId);
|
|
27873
27873
|
try {
|
|
27874
|
-
const headers = await this.http.delete(
|
|
27874
|
+
const headers = await this.http.delete(path26, {});
|
|
27875
27875
|
const mailboxDeprovisioned = headers.get(MAILBOX_DEPROVISIONED_HEADER) === "true";
|
|
27876
27876
|
return { removed: true, mailboxDeprovisioned };
|
|
27877
27877
|
} catch (err) {
|
|
@@ -27895,8 +27895,8 @@ var init_http_backend = __esm({
|
|
|
27895
27895
|
* GET /api/sessions/:sessionId/peers
|
|
27896
27896
|
*/
|
|
27897
27897
|
async listPeers() {
|
|
27898
|
-
const
|
|
27899
|
-
const result = await this.http.get(
|
|
27898
|
+
const path26 = PATHS.peers.replace(":sessionId", this.sessionId);
|
|
27899
|
+
const result = await this.http.get(path26);
|
|
27900
27900
|
return result.peers;
|
|
27901
27901
|
}
|
|
27902
27902
|
/**
|
|
@@ -27904,8 +27904,8 @@ var init_http_backend = __esm({
|
|
|
27904
27904
|
* Calls the lightweight heartbeat endpoint on the cloud relay server.
|
|
27905
27905
|
*/
|
|
27906
27906
|
async updateLastSeen(peerId) {
|
|
27907
|
-
const
|
|
27908
|
-
await this.http.post(
|
|
27907
|
+
const path26 = PATHS.heartbeat.replace(":sessionId", this.sessionId);
|
|
27908
|
+
await this.http.post(path26, { peerId });
|
|
27909
27909
|
}
|
|
27910
27910
|
/**
|
|
27911
27911
|
* Record a message in the cloud session.
|
|
@@ -27916,7 +27916,7 @@ var init_http_backend = __esm({
|
|
|
27916
27916
|
* the input record to construct a full MessageRecord.
|
|
27917
27917
|
*/
|
|
27918
27918
|
async recordMessage(record2) {
|
|
27919
|
-
const
|
|
27919
|
+
const path26 = PATHS.messages.replace(":sessionId", this.sessionId);
|
|
27920
27920
|
const body = {
|
|
27921
27921
|
fromPeerId: record2.fromPeerId,
|
|
27922
27922
|
toPeerId: record2.toPeerId,
|
|
@@ -27939,7 +27939,7 @@ var init_http_backend = __esm({
|
|
|
27939
27939
|
if (record2.attachments && record2.attachments.length > 0) {
|
|
27940
27940
|
body.attachments = record2.attachments;
|
|
27941
27941
|
}
|
|
27942
|
-
const resp = await this.http.post(
|
|
27942
|
+
const resp = await this.http.post(path26, body);
|
|
27943
27943
|
return {
|
|
27944
27944
|
...record2,
|
|
27945
27945
|
id: resp.id,
|
|
@@ -27953,7 +27953,7 @@ var init_http_backend = __esm({
|
|
|
27953
27953
|
* Supports optional peerId filter and limit (default 300).
|
|
27954
27954
|
*/
|
|
27955
27955
|
async getHistory(peerId, limit, includeRelayEchoes, metadataOnly, dedupInferredEchoes) {
|
|
27956
|
-
const
|
|
27956
|
+
const path26 = PATHS.messages.replace(":sessionId", this.sessionId);
|
|
27957
27957
|
const query = {};
|
|
27958
27958
|
if (peerId) {
|
|
27959
27959
|
query.peerId = peerId;
|
|
@@ -27968,7 +27968,7 @@ var init_http_backend = __esm({
|
|
|
27968
27968
|
if (dedupInferredEchoes) {
|
|
27969
27969
|
query.dedupInferredEchoes = "true";
|
|
27970
27970
|
}
|
|
27971
|
-
const result = await this.http.get(
|
|
27971
|
+
const result = await this.http.get(path26, query);
|
|
27972
27972
|
return result.messages;
|
|
27973
27973
|
}
|
|
27974
27974
|
/**
|
|
@@ -27979,12 +27979,12 @@ var init_http_backend = __esm({
|
|
|
27979
27979
|
* so that get-history shows the actual response (not null).
|
|
27980
27980
|
*/
|
|
27981
27981
|
async updateMessageResponse(messageId, response, durationMs, pending) {
|
|
27982
|
-
const
|
|
27982
|
+
const path26 = PATHS.message.replace(":sessionId", this.sessionId).replace(":messageId", messageId);
|
|
27983
27983
|
const body = { response, durationMs };
|
|
27984
27984
|
if (pending === true) {
|
|
27985
27985
|
body.pending = true;
|
|
27986
27986
|
}
|
|
27987
|
-
await this.http.patch(
|
|
27987
|
+
await this.http.patch(path26, body);
|
|
27988
27988
|
}
|
|
27989
27989
|
/**
|
|
27990
27990
|
* Validate a session.
|
|
@@ -28126,8 +28126,8 @@ var init_http_client = __esm({
|
|
|
28126
28126
|
* Perform an authenticated GET request.
|
|
28127
28127
|
* Appends query parameters to the URL if provided.
|
|
28128
28128
|
*/
|
|
28129
|
-
async get(
|
|
28130
|
-
const url = new URL(
|
|
28129
|
+
async get(path26, query) {
|
|
28130
|
+
const url = new URL(path26, this.baseUrl);
|
|
28131
28131
|
if (query) {
|
|
28132
28132
|
for (const [k, v] of Object.entries(query)) {
|
|
28133
28133
|
url.searchParams.set(k, v);
|
|
@@ -28142,8 +28142,8 @@ var init_http_client = __esm({
|
|
|
28142
28142
|
/**
|
|
28143
28143
|
* Perform an authenticated POST request with a JSON body.
|
|
28144
28144
|
*/
|
|
28145
|
-
async post(
|
|
28146
|
-
const url = new URL(
|
|
28145
|
+
async post(path26, body) {
|
|
28146
|
+
const url = new URL(path26, this.baseUrl);
|
|
28147
28147
|
const resp = await this.fetchWithTimeout(url, {
|
|
28148
28148
|
method: "POST",
|
|
28149
28149
|
headers: this.headers(),
|
|
@@ -28161,8 +28161,8 @@ var init_http_client = __esm({
|
|
|
28161
28161
|
* Perform an authenticated PATCH request with a JSON body.
|
|
28162
28162
|
* Used to update existing resources (e.g., message response fields).
|
|
28163
28163
|
*/
|
|
28164
|
-
async patch(
|
|
28165
|
-
const url = new URL(
|
|
28164
|
+
async patch(path26, body) {
|
|
28165
|
+
const url = new URL(path26, this.baseUrl);
|
|
28166
28166
|
const resp = await this.fetchWithTimeout(url, {
|
|
28167
28167
|
method: "PATCH",
|
|
28168
28168
|
headers: this.headers(),
|
|
@@ -28187,8 +28187,8 @@ var init_http_client = __esm({
|
|
|
28187
28187
|
* "Malformed JSON in request body" 400 from cogent-server <=3.1.2 when
|
|
28188
28188
|
* any client (including third-party tools) DELETEd a peer without a body.
|
|
28189
28189
|
*/
|
|
28190
|
-
async delete(
|
|
28191
|
-
const url = new URL(
|
|
28190
|
+
async delete(path26, body) {
|
|
28191
|
+
const url = new URL(path26, this.baseUrl);
|
|
28192
28192
|
const headers = {
|
|
28193
28193
|
"Authorization": `Bearer ${this.token}`
|
|
28194
28194
|
};
|
|
@@ -32087,6 +32087,44 @@ var init_wrapper = __esm({
|
|
|
32087
32087
|
}
|
|
32088
32088
|
});
|
|
32089
32089
|
|
|
32090
|
+
// src/cloud/poll-cursor.ts
|
|
32091
|
+
import fs11 from "node:fs";
|
|
32092
|
+
import os8 from "node:os";
|
|
32093
|
+
import path12 from "node:path";
|
|
32094
|
+
function pollCursorPath(sessionId, peerId) {
|
|
32095
|
+
return path12.join(os8.homedir(), ".cogent", "poll-cursors", `${safe(sessionId)}.${safe(peerId)}.json`);
|
|
32096
|
+
}
|
|
32097
|
+
function loadPollCursor(sessionId, peerId) {
|
|
32098
|
+
if (!sessionId || !peerId) return null;
|
|
32099
|
+
try {
|
|
32100
|
+
const raw = JSON.parse(fs11.readFileSync(pollCursorPath(sessionId, peerId), "utf-8"));
|
|
32101
|
+
return typeof raw?.lastMessageId === "string" && raw.lastMessageId ? raw.lastMessageId : null;
|
|
32102
|
+
} catch {
|
|
32103
|
+
return null;
|
|
32104
|
+
}
|
|
32105
|
+
}
|
|
32106
|
+
function savePollCursor(sessionId, peerId, lastMessageId) {
|
|
32107
|
+
if (!sessionId || !peerId || !lastMessageId) return;
|
|
32108
|
+
const p = pollCursorPath(sessionId, peerId);
|
|
32109
|
+
try {
|
|
32110
|
+
fs11.mkdirSync(path12.dirname(p), { recursive: true });
|
|
32111
|
+
fs11.writeFileSync(
|
|
32112
|
+
p,
|
|
32113
|
+
JSON.stringify({ lastMessageId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() })
|
|
32114
|
+
);
|
|
32115
|
+
} catch (err) {
|
|
32116
|
+
logger.debug(`poll-cursor: could not persist (${err.message})`);
|
|
32117
|
+
}
|
|
32118
|
+
}
|
|
32119
|
+
var safe;
|
|
32120
|
+
var init_poll_cursor = __esm({
|
|
32121
|
+
"src/cloud/poll-cursor.ts"() {
|
|
32122
|
+
"use strict";
|
|
32123
|
+
init_logger();
|
|
32124
|
+
safe = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
32125
|
+
}
|
|
32126
|
+
});
|
|
32127
|
+
|
|
32090
32128
|
// src/cloud/ws-client.ts
|
|
32091
32129
|
var CloudWsClient;
|
|
32092
32130
|
var init_ws_client = __esm({
|
|
@@ -32096,6 +32134,7 @@ var init_ws_client = __esm({
|
|
|
32096
32134
|
init_backoff();
|
|
32097
32135
|
init_ws_frames();
|
|
32098
32136
|
init_logger();
|
|
32137
|
+
init_poll_cursor();
|
|
32099
32138
|
CloudWsClient = class {
|
|
32100
32139
|
ws = null;
|
|
32101
32140
|
state = "disconnected";
|
|
@@ -32104,6 +32143,34 @@ var init_ws_client = __esm({
|
|
|
32104
32143
|
pollTimer = null;
|
|
32105
32144
|
pingTimer = null;
|
|
32106
32145
|
lastMessageId = null;
|
|
32146
|
+
/**
|
|
32147
|
+
* Advance the poll cursor AND persist it.
|
|
32148
|
+
*
|
|
32149
|
+
* Every assignment must go through here. `lastMessageId` was in-memory only, so a restart sent
|
|
32150
|
+
* no cursor and the relay replayed the whole channel ("If lastMessageId is not provided (first
|
|
32151
|
+
* poll), returns all messages") — re-injecting days-old broadcasts on every restart.
|
|
32152
|
+
*/
|
|
32153
|
+
advanceCursor(id) {
|
|
32154
|
+
if (!id) return;
|
|
32155
|
+
this.lastMessageId = id;
|
|
32156
|
+
savePollCursor(this.opts.sessionId, this.opts.peerId, id);
|
|
32157
|
+
}
|
|
32158
|
+
/**
|
|
32159
|
+
* Seed the cursor from disk when this process has not consumed anything yet.
|
|
32160
|
+
*
|
|
32161
|
+
* Only ever fills a NULL cursor: a live in-memory position is always newer than the stored one,
|
|
32162
|
+
* so it must never be overwritten by a restore.
|
|
32163
|
+
*/
|
|
32164
|
+
restoreCursor() {
|
|
32165
|
+
if (this.lastMessageId) return;
|
|
32166
|
+
const stored = loadPollCursor(this.opts.sessionId, this.opts.peerId);
|
|
32167
|
+
if (stored) {
|
|
32168
|
+
this.lastMessageId = stored;
|
|
32169
|
+
logger.info(
|
|
32170
|
+
`CloudWsClient: resuming from stored poll cursor (${stored.slice(0, 8)}\u2026) \u2014 the channel backlog before it has already been consumed and will not be replayed.`
|
|
32171
|
+
);
|
|
32172
|
+
}
|
|
32173
|
+
}
|
|
32107
32174
|
lastWsError = null;
|
|
32108
32175
|
connectionGeneration = 0;
|
|
32109
32176
|
opts;
|
|
@@ -32126,6 +32193,7 @@ var init_ws_client = __esm({
|
|
|
32126
32193
|
* Guards against empty peerId -- call setPeerId() first.
|
|
32127
32194
|
*/
|
|
32128
32195
|
connect() {
|
|
32196
|
+
this.restoreCursor();
|
|
32129
32197
|
if (!this.opts.peerId) {
|
|
32130
32198
|
logger.warn(
|
|
32131
32199
|
"CloudWsClient: Cannot connect WebSocket without peerId. Call setPeerId() first."
|
|
@@ -32277,7 +32345,7 @@ var init_ws_client = __esm({
|
|
|
32277
32345
|
* Update the last seen message ID (e.g., from HttpBackend operations).
|
|
32278
32346
|
*/
|
|
32279
32347
|
updateLastMessageId(id) {
|
|
32280
|
-
this.
|
|
32348
|
+
this.advanceCursor(id);
|
|
32281
32349
|
}
|
|
32282
32350
|
/**
|
|
32283
32351
|
* Update the auth token for reconnection.
|
|
@@ -32355,13 +32423,13 @@ var init_ws_client = __esm({
|
|
|
32355
32423
|
switch (frame.type) {
|
|
32356
32424
|
case "message":
|
|
32357
32425
|
this.opts.onMessage(frame.payload);
|
|
32358
|
-
this.
|
|
32426
|
+
this.advanceCursor(frame.payload.id);
|
|
32359
32427
|
break;
|
|
32360
32428
|
case "queued_messages": {
|
|
32361
32429
|
const msgs = frame.payload.messages;
|
|
32362
32430
|
this.opts.onMessages(msgs);
|
|
32363
32431
|
if (msgs.length > 0) {
|
|
32364
|
-
this.
|
|
32432
|
+
this.advanceCursor(msgs[msgs.length - 1].id);
|
|
32365
32433
|
}
|
|
32366
32434
|
break;
|
|
32367
32435
|
}
|
|
@@ -32391,19 +32459,20 @@ var init_ws_client = __esm({
|
|
|
32391
32459
|
}
|
|
32392
32460
|
startPolling() {
|
|
32393
32461
|
if (this.pollTimer) return;
|
|
32462
|
+
this.restoreCursor();
|
|
32394
32463
|
const poll = async () => {
|
|
32395
32464
|
try {
|
|
32396
|
-
const
|
|
32465
|
+
const path26 = `/api/sessions/${this.opts.sessionId}/poll`;
|
|
32397
32466
|
const query = {
|
|
32398
32467
|
peerId: this.opts.peerId
|
|
32399
32468
|
};
|
|
32400
32469
|
if (this.lastMessageId) {
|
|
32401
32470
|
query.lastMessageId = this.lastMessageId;
|
|
32402
32471
|
}
|
|
32403
|
-
const result = await this.opts.http.get(
|
|
32472
|
+
const result = await this.opts.http.get(path26, query);
|
|
32404
32473
|
if (result.messages && result.messages.length > 0) {
|
|
32405
32474
|
this.opts.onMessages(result.messages);
|
|
32406
|
-
this.
|
|
32475
|
+
this.advanceCursor(result.messages[result.messages.length - 1].id);
|
|
32407
32476
|
}
|
|
32408
32477
|
} catch (err) {
|
|
32409
32478
|
logger.warn(
|
|
@@ -32457,9 +32526,9 @@ var init_cloud = __esm({
|
|
|
32457
32526
|
|
|
32458
32527
|
// src/services/codex-cli.ts
|
|
32459
32528
|
import { spawn as spawn2 } from "node:child_process";
|
|
32460
|
-
import
|
|
32461
|
-
import
|
|
32462
|
-
import
|
|
32529
|
+
import fs12 from "node:fs/promises";
|
|
32530
|
+
import os9 from "node:os";
|
|
32531
|
+
import path13 from "node:path";
|
|
32463
32532
|
import { randomUUID } from "node:crypto";
|
|
32464
32533
|
import { createReadStream } from "node:fs";
|
|
32465
32534
|
import { createInterface as createInterface2 } from "node:readline";
|
|
@@ -32487,7 +32556,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32487
32556
|
const config2 = getConfig();
|
|
32488
32557
|
const effectiveTimeout = timeoutMs ?? config2.COGENT_TIMEOUT_MS;
|
|
32489
32558
|
const truncated = config2.COGENT_CHAR_LIMIT > 0 && message.length > config2.COGENT_CHAR_LIMIT ? message.slice(0, config2.COGENT_CHAR_LIMIT) + "\n...[truncated]" : message;
|
|
32490
|
-
const lastMsgFile =
|
|
32559
|
+
const lastMsgFile = path13.join(os9.tmpdir(), `cogent-codex-${randomUUID()}.txt`);
|
|
32491
32560
|
const args = [
|
|
32492
32561
|
"exec",
|
|
32493
32562
|
"resume",
|
|
@@ -32515,7 +32584,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32515
32584
|
resolve(result);
|
|
32516
32585
|
}
|
|
32517
32586
|
};
|
|
32518
|
-
const cleanupFile = () =>
|
|
32587
|
+
const cleanupFile = () => fs12.rm(lastMsgFile, { force: true }).catch(() => {
|
|
32519
32588
|
});
|
|
32520
32589
|
const timer = setTimeout(async () => {
|
|
32521
32590
|
killed = true;
|
|
@@ -32566,7 +32635,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32566
32635
|
}
|
|
32567
32636
|
let fileMessage = "";
|
|
32568
32637
|
try {
|
|
32569
|
-
fileMessage = await
|
|
32638
|
+
fileMessage = await fs12.readFile(lastMsgFile, "utf8");
|
|
32570
32639
|
} catch {
|
|
32571
32640
|
fileMessage = "";
|
|
32572
32641
|
}
|
|
@@ -32587,12 +32656,12 @@ async function listRolloutFiles(root) {
|
|
|
32587
32656
|
async function walk(dir) {
|
|
32588
32657
|
let entries;
|
|
32589
32658
|
try {
|
|
32590
|
-
entries = await
|
|
32659
|
+
entries = await fs12.readdir(dir, { withFileTypes: true });
|
|
32591
32660
|
} catch {
|
|
32592
32661
|
return;
|
|
32593
32662
|
}
|
|
32594
32663
|
for (const e of entries) {
|
|
32595
|
-
const full =
|
|
32664
|
+
const full = path13.join(dir, e.name);
|
|
32596
32665
|
if (e.isDirectory()) await walk(full);
|
|
32597
32666
|
else if (e.isFile() && e.name.endsWith(".jsonl")) out.push(full);
|
|
32598
32667
|
}
|
|
@@ -32624,19 +32693,19 @@ async function readSessionMeta(file) {
|
|
|
32624
32693
|
}
|
|
32625
32694
|
}
|
|
32626
32695
|
function codexSessionsRoot() {
|
|
32627
|
-
return
|
|
32696
|
+
return path13.join(codexHomeDir(), "sessions");
|
|
32628
32697
|
}
|
|
32629
32698
|
async function cwdCanonicals(cwd) {
|
|
32630
|
-
const resolved =
|
|
32699
|
+
const resolved = path13.resolve(cwd);
|
|
32631
32700
|
const forms = /* @__PURE__ */ new Set([resolved]);
|
|
32632
32701
|
try {
|
|
32633
|
-
forms.add(await
|
|
32702
|
+
forms.add(await fs12.realpath(resolved));
|
|
32634
32703
|
} catch {
|
|
32635
32704
|
}
|
|
32636
32705
|
return forms;
|
|
32637
32706
|
}
|
|
32638
32707
|
function metaCwdMatches(metaCwd, forms) {
|
|
32639
|
-
return forms.has(
|
|
32708
|
+
return forms.has(path13.resolve(metaCwd));
|
|
32640
32709
|
}
|
|
32641
32710
|
async function detectCurrentCodexSession(cwd) {
|
|
32642
32711
|
try {
|
|
@@ -32644,7 +32713,7 @@ async function detectCurrentCodexSession(cwd) {
|
|
|
32644
32713
|
const files = await listRolloutFiles(codexSessionsRoot());
|
|
32645
32714
|
const withStats = await Promise.all(
|
|
32646
32715
|
files.map(async (f) => {
|
|
32647
|
-
const stat = await
|
|
32716
|
+
const stat = await fs12.stat(f);
|
|
32648
32717
|
return { file: f, mtimeMs: stat.mtimeMs };
|
|
32649
32718
|
})
|
|
32650
32719
|
);
|
|
@@ -32663,7 +32732,7 @@ async function listCodexCandidates(cwd) {
|
|
|
32663
32732
|
const forms = await cwdCanonicals(cwd);
|
|
32664
32733
|
const files = await listRolloutFiles(codexSessionsRoot());
|
|
32665
32734
|
const withStats = await Promise.all(
|
|
32666
|
-
files.map(async (f) => ({ file: f, mtimeMs: (await
|
|
32735
|
+
files.map(async (f) => ({ file: f, mtimeMs: (await fs12.stat(f)).mtimeMs }))
|
|
32667
32736
|
);
|
|
32668
32737
|
const bySession = /* @__PURE__ */ new Map();
|
|
32669
32738
|
for (const { file, mtimeMs } of withStats) {
|
|
@@ -32703,12 +32772,12 @@ var init_codex_cli = __esm({
|
|
|
32703
32772
|
});
|
|
32704
32773
|
|
|
32705
32774
|
// src/services/codex-app-server.ts
|
|
32706
|
-
import
|
|
32775
|
+
import path14 from "node:path";
|
|
32707
32776
|
import { statSync } from "node:fs";
|
|
32708
|
-
import
|
|
32777
|
+
import fs13 from "node:fs/promises";
|
|
32709
32778
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
32710
32779
|
function appServerSocketPath(codexHome = codexHomeDir()) {
|
|
32711
|
-
return
|
|
32780
|
+
return path14.join(codexHome, "app-server-control", "app-server-control.sock");
|
|
32712
32781
|
}
|
|
32713
32782
|
function appServerDaemonRunning(codexHome = codexHomeDir()) {
|
|
32714
32783
|
try {
|
|
@@ -32956,7 +33025,7 @@ var init_codex_app_server = __esm({
|
|
|
32956
33025
|
});
|
|
32957
33026
|
defaultSocketExists = async (p) => {
|
|
32958
33027
|
try {
|
|
32959
|
-
await
|
|
33028
|
+
await fs13.stat(p);
|
|
32960
33029
|
return true;
|
|
32961
33030
|
} catch {
|
|
32962
33031
|
return false;
|
|
@@ -33122,14 +33191,14 @@ var init_exec_remote = __esm({
|
|
|
33122
33191
|
// src/services/wake-log.ts
|
|
33123
33192
|
import { execFileSync } from "node:child_process";
|
|
33124
33193
|
import crypto4 from "node:crypto";
|
|
33125
|
-
import
|
|
33126
|
-
import
|
|
33127
|
-
import
|
|
33194
|
+
import fs14 from "node:fs";
|
|
33195
|
+
import os10 from "node:os";
|
|
33196
|
+
import path15 from "node:path";
|
|
33128
33197
|
function hashCwd2(cwd) {
|
|
33129
|
-
return crypto4.createHash("sha256").update(
|
|
33198
|
+
return crypto4.createHash("sha256").update(path15.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33130
33199
|
}
|
|
33131
33200
|
function wakeLogPath(cwd) {
|
|
33132
|
-
return
|
|
33201
|
+
return path15.join(os10.homedir(), ".cogent", "wake-log", `${hashCwd2(cwd)}.jsonl`);
|
|
33133
33202
|
}
|
|
33134
33203
|
function git(cwd, args) {
|
|
33135
33204
|
return execFileSync("git", ["-C", cwd, ...args], {
|
|
@@ -33173,13 +33242,13 @@ function preview(message) {
|
|
|
33173
33242
|
function appendWakeRecord(record2, cwd) {
|
|
33174
33243
|
const target = wakeLogPath(cwd);
|
|
33175
33244
|
try {
|
|
33176
|
-
|
|
33245
|
+
fs14.mkdirSync(path15.dirname(target), { recursive: true });
|
|
33177
33246
|
const row = {
|
|
33178
33247
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33179
33248
|
...record2,
|
|
33180
33249
|
messagePreview: preview(record2.messagePreview ?? "")
|
|
33181
33250
|
};
|
|
33182
|
-
|
|
33251
|
+
fs14.appendFileSync(target, `${JSON.stringify(row)}
|
|
33183
33252
|
`);
|
|
33184
33253
|
pruneIfNeeded(target);
|
|
33185
33254
|
} catch {
|
|
@@ -33187,20 +33256,20 @@ function appendWakeRecord(record2, cwd) {
|
|
|
33187
33256
|
}
|
|
33188
33257
|
function pruneIfNeeded(target) {
|
|
33189
33258
|
try {
|
|
33190
|
-
const lines =
|
|
33259
|
+
const lines = fs14.readFileSync(target, "utf-8").split("\n").filter((l) => l.length > 0);
|
|
33191
33260
|
if (lines.length <= WAKE_LOG_MAX_RECORDS) return;
|
|
33192
33261
|
const kept = lines.slice(lines.length - WAKE_LOG_MAX_RECORDS);
|
|
33193
33262
|
const tmp = `${target}.tmp-${process.pid}`;
|
|
33194
|
-
|
|
33263
|
+
fs14.writeFileSync(tmp, `${kept.join("\n")}
|
|
33195
33264
|
`);
|
|
33196
|
-
|
|
33265
|
+
fs14.renameSync(tmp, target);
|
|
33197
33266
|
} catch {
|
|
33198
33267
|
}
|
|
33199
33268
|
}
|
|
33200
33269
|
function readWakeLog(cwd, limit) {
|
|
33201
33270
|
let lines;
|
|
33202
33271
|
try {
|
|
33203
|
-
lines =
|
|
33272
|
+
lines = fs14.readFileSync(wakeLogPath(cwd), "utf-8").split("\n").filter((l) => l.length > 0);
|
|
33204
33273
|
} catch {
|
|
33205
33274
|
return [];
|
|
33206
33275
|
}
|
|
@@ -33313,14 +33382,14 @@ var init_session_resolver = __esm({
|
|
|
33313
33382
|
|
|
33314
33383
|
// src/services/wake-inflight.ts
|
|
33315
33384
|
import crypto5 from "node:crypto";
|
|
33316
|
-
import
|
|
33317
|
-
import
|
|
33318
|
-
import
|
|
33385
|
+
import fs15 from "node:fs";
|
|
33386
|
+
import os11 from "node:os";
|
|
33387
|
+
import path16 from "node:path";
|
|
33319
33388
|
function hashCwd3(cwd) {
|
|
33320
|
-
return crypto5.createHash("sha256").update(
|
|
33389
|
+
return crypto5.createHash("sha256").update(path16.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33321
33390
|
}
|
|
33322
33391
|
function wakeInflightPath(peerId, cwd = process.cwd()) {
|
|
33323
|
-
return
|
|
33392
|
+
return path16.join(os11.homedir(), ".cogent", "wake-inflight", `${hashCwd3(cwd)}.${safe2(peerId)}.json`);
|
|
33324
33393
|
}
|
|
33325
33394
|
function ttlMs() {
|
|
33326
33395
|
let timeout = 3e5;
|
|
@@ -33333,17 +33402,17 @@ function ttlMs() {
|
|
|
33333
33402
|
}
|
|
33334
33403
|
function readFileSafe(p) {
|
|
33335
33404
|
try {
|
|
33336
|
-
const parsed = JSON.parse(
|
|
33405
|
+
const parsed = JSON.parse(fs15.readFileSync(p, "utf-8"));
|
|
33337
33406
|
return parsed && typeof parsed === "object" && parsed.messages ? parsed : { messages: {} };
|
|
33338
33407
|
} catch {
|
|
33339
33408
|
return { messages: {} };
|
|
33340
33409
|
}
|
|
33341
33410
|
}
|
|
33342
33411
|
function writeAtomic(p, data) {
|
|
33343
|
-
|
|
33412
|
+
fs15.mkdirSync(path16.dirname(p), { recursive: true });
|
|
33344
33413
|
const tmp = `${p}.${process.pid}.tmp`;
|
|
33345
|
-
|
|
33346
|
-
|
|
33414
|
+
fs15.writeFileSync(tmp, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
33415
|
+
fs15.renameSync(tmp, p);
|
|
33347
33416
|
}
|
|
33348
33417
|
function prune(f, now) {
|
|
33349
33418
|
for (const [id, rec] of Object.entries(f.messages)) {
|
|
@@ -33383,7 +33452,7 @@ function clearWakeInFlight(peerId, messageId, cwd = process.cwd()) {
|
|
|
33383
33452
|
logger.debug(`wake-inflight: could not clear ${messageId}: ${err}`);
|
|
33384
33453
|
}
|
|
33385
33454
|
}
|
|
33386
|
-
var INFLIGHT_MAX_MS, INFLIGHT_TIMEOUT_FACTOR,
|
|
33455
|
+
var INFLIGHT_MAX_MS, INFLIGHT_TIMEOUT_FACTOR, safe2;
|
|
33387
33456
|
var init_wake_inflight = __esm({
|
|
33388
33457
|
"src/services/wake-inflight.ts"() {
|
|
33389
33458
|
"use strict";
|
|
@@ -33391,24 +33460,24 @@ var init_wake_inflight = __esm({
|
|
|
33391
33460
|
init_logger();
|
|
33392
33461
|
INFLIGHT_MAX_MS = 18e5;
|
|
33393
33462
|
INFLIGHT_TIMEOUT_FACTOR = 3;
|
|
33394
|
-
|
|
33463
|
+
safe2 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33395
33464
|
}
|
|
33396
33465
|
});
|
|
33397
33466
|
|
|
33398
33467
|
// src/services/wake-claim.ts
|
|
33399
33468
|
import crypto6 from "node:crypto";
|
|
33400
|
-
import
|
|
33401
|
-
import
|
|
33402
|
-
import
|
|
33469
|
+
import fs16 from "node:fs";
|
|
33470
|
+
import os12 from "node:os";
|
|
33471
|
+
import path17 from "node:path";
|
|
33403
33472
|
function hashCwd4(cwd) {
|
|
33404
|
-
return crypto6.createHash("sha256").update(
|
|
33473
|
+
return crypto6.createHash("sha256").update(path17.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33405
33474
|
}
|
|
33406
33475
|
function wakeClaimPath(peerId, messageId, cwd = process.cwd()) {
|
|
33407
|
-
return
|
|
33408
|
-
|
|
33476
|
+
return path17.join(
|
|
33477
|
+
os12.homedir(),
|
|
33409
33478
|
".cogent",
|
|
33410
33479
|
"wake-claims",
|
|
33411
|
-
`${hashCwd4(cwd)}.${
|
|
33480
|
+
`${hashCwd4(cwd)}.${safe3(peerId)}.${safe3(messageId)}.json`
|
|
33412
33481
|
);
|
|
33413
33482
|
}
|
|
33414
33483
|
function ttlMs2() {
|
|
@@ -33435,22 +33504,22 @@ function claimWake(peerId, messageId, cwd = process.cwd()) {
|
|
|
33435
33504
|
const now = Date.now();
|
|
33436
33505
|
const body = () => JSON.stringify({ pid: process.pid, startedAt: now, expiresAt: now + ttlMs2() });
|
|
33437
33506
|
try {
|
|
33438
|
-
|
|
33507
|
+
fs16.mkdirSync(path17.dirname(p), { recursive: true });
|
|
33439
33508
|
try {
|
|
33440
|
-
|
|
33509
|
+
fs16.writeFileSync(p, body(), { flag: "wx" });
|
|
33441
33510
|
return true;
|
|
33442
33511
|
} catch (err) {
|
|
33443
33512
|
if (err?.code !== "EEXIST") throw err;
|
|
33444
33513
|
}
|
|
33445
33514
|
let held = null;
|
|
33446
33515
|
try {
|
|
33447
|
-
held = JSON.parse(
|
|
33516
|
+
held = JSON.parse(fs16.readFileSync(p, "utf-8"));
|
|
33448
33517
|
} catch {
|
|
33449
33518
|
held = null;
|
|
33450
33519
|
}
|
|
33451
33520
|
const expired = !held || typeof held.expiresAt !== "number" || held.expiresAt <= now;
|
|
33452
33521
|
if (!held || expired || !holderAlive(held.pid)) {
|
|
33453
|
-
|
|
33522
|
+
fs16.writeFileSync(p, body());
|
|
33454
33523
|
logger.debug(`wake-claim: took over an abandoned claim for ${messageId}`);
|
|
33455
33524
|
return true;
|
|
33456
33525
|
}
|
|
@@ -33465,11 +33534,11 @@ function claimWake(peerId, messageId, cwd = process.cwd()) {
|
|
|
33465
33534
|
}
|
|
33466
33535
|
function releaseWake(peerId, messageId, cwd = process.cwd()) {
|
|
33467
33536
|
try {
|
|
33468
|
-
|
|
33537
|
+
fs16.unlinkSync(wakeClaimPath(peerId, messageId, cwd));
|
|
33469
33538
|
} catch {
|
|
33470
33539
|
}
|
|
33471
33540
|
}
|
|
33472
|
-
var CLAIM_MAX_MS, CLAIM_TIMEOUT_FACTOR,
|
|
33541
|
+
var CLAIM_MAX_MS, CLAIM_TIMEOUT_FACTOR, safe3;
|
|
33473
33542
|
var init_wake_claim = __esm({
|
|
33474
33543
|
"src/services/wake-claim.ts"() {
|
|
33475
33544
|
"use strict";
|
|
@@ -33477,20 +33546,20 @@ var init_wake_claim = __esm({
|
|
|
33477
33546
|
init_logger();
|
|
33478
33547
|
CLAIM_MAX_MS = 18e5;
|
|
33479
33548
|
CLAIM_TIMEOUT_FACTOR = 3;
|
|
33480
|
-
|
|
33549
|
+
safe3 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33481
33550
|
}
|
|
33482
33551
|
});
|
|
33483
33552
|
|
|
33484
33553
|
// src/services/wake-lock.ts
|
|
33485
33554
|
import crypto7 from "node:crypto";
|
|
33486
|
-
import
|
|
33487
|
-
import
|
|
33488
|
-
import
|
|
33555
|
+
import fs17 from "node:fs";
|
|
33556
|
+
import os13 from "node:os";
|
|
33557
|
+
import path18 from "node:path";
|
|
33489
33558
|
function hashCwd5(cwd) {
|
|
33490
|
-
return crypto7.createHash("sha256").update(
|
|
33559
|
+
return crypto7.createHash("sha256").update(path18.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33491
33560
|
}
|
|
33492
33561
|
function wakeLockPath(cwd = process.cwd()) {
|
|
33493
|
-
return
|
|
33562
|
+
return path18.join(os13.homedir(), ".cogent", "wake-locks", `${hashCwd5(cwd)}.json`);
|
|
33494
33563
|
}
|
|
33495
33564
|
function leaseTtlMs() {
|
|
33496
33565
|
let timeout = 3e5;
|
|
@@ -33521,7 +33590,7 @@ function holderAlive2(pid) {
|
|
|
33521
33590
|
}
|
|
33522
33591
|
function readHolder(p) {
|
|
33523
33592
|
try {
|
|
33524
|
-
const held = JSON.parse(
|
|
33593
|
+
const held = JSON.parse(fs17.readFileSync(p, "utf-8"));
|
|
33525
33594
|
if (!held || typeof held.expiresAt !== "number") return null;
|
|
33526
33595
|
return held;
|
|
33527
33596
|
} catch {
|
|
@@ -33568,7 +33637,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33568
33637
|
} };
|
|
33569
33638
|
};
|
|
33570
33639
|
try {
|
|
33571
|
-
|
|
33640
|
+
fs17.mkdirSync(path18.dirname(p), { recursive: true });
|
|
33572
33641
|
} catch (err) {
|
|
33573
33642
|
return failOpen(`cannot create lock dir (${err.message})`);
|
|
33574
33643
|
}
|
|
@@ -33581,7 +33650,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33581
33650
|
expiresAt: now + leaseTtlMs()
|
|
33582
33651
|
});
|
|
33583
33652
|
try {
|
|
33584
|
-
|
|
33653
|
+
fs17.writeFileSync(p, body, { flag: "wx" });
|
|
33585
33654
|
if (contended) {
|
|
33586
33655
|
logger.info(
|
|
33587
33656
|
`Auto-relay: waited ${Date.now() - started}ms for another bridge process to finish its turn in this checkout before resuming \u2014 turns are serialised, not overlapping.`
|
|
@@ -33596,7 +33665,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33596
33665
|
const held = readHolder(p);
|
|
33597
33666
|
if (!held || held.expiresAt <= now || !holderAlive2(held.pid)) {
|
|
33598
33667
|
try {
|
|
33599
|
-
|
|
33668
|
+
fs17.writeFileSync(p, body);
|
|
33600
33669
|
} catch (err) {
|
|
33601
33670
|
return failOpen(`cannot steal abandoned lock (${err.message})`);
|
|
33602
33671
|
}
|
|
@@ -33619,7 +33688,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33619
33688
|
}
|
|
33620
33689
|
function releaseWakeLock(cwd = process.cwd()) {
|
|
33621
33690
|
try {
|
|
33622
|
-
|
|
33691
|
+
fs17.unlinkSync(wakeLockPath(cwd));
|
|
33623
33692
|
} catch {
|
|
33624
33693
|
}
|
|
33625
33694
|
}
|
|
@@ -33639,14 +33708,14 @@ var init_wake_lock = __esm({
|
|
|
33639
33708
|
|
|
33640
33709
|
// src/services/wake-ownership.ts
|
|
33641
33710
|
import crypto8 from "node:crypto";
|
|
33642
|
-
import
|
|
33643
|
-
import
|
|
33644
|
-
import
|
|
33711
|
+
import fs18 from "node:fs";
|
|
33712
|
+
import os14 from "node:os";
|
|
33713
|
+
import path19 from "node:path";
|
|
33645
33714
|
function hashCwd6(cwd) {
|
|
33646
|
-
return crypto8.createHash("sha256").update(
|
|
33715
|
+
return crypto8.createHash("sha256").update(path19.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33647
33716
|
}
|
|
33648
33717
|
function bridgeDirFor(cwd, peerId) {
|
|
33649
|
-
return
|
|
33718
|
+
return path19.join(os14.homedir(), ".cogent", "bridges", `${hashCwd6(cwd)}.${safe4(peerId)}`);
|
|
33650
33719
|
}
|
|
33651
33720
|
function pidAlive(pid) {
|
|
33652
33721
|
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return false;
|
|
@@ -33661,23 +33730,23 @@ function pidAlive(pid) {
|
|
|
33661
33730
|
function announceBridge(cwd, peerId, version2, endpoint) {
|
|
33662
33731
|
const dir = bridgeDirFor(cwd, peerId);
|
|
33663
33732
|
try {
|
|
33664
|
-
|
|
33733
|
+
fs18.mkdirSync(dir, { recursive: true });
|
|
33665
33734
|
const entry = {
|
|
33666
33735
|
pid: process.pid,
|
|
33667
33736
|
startedAt: PROCESS_STARTED_AT,
|
|
33668
33737
|
version: version2,
|
|
33669
33738
|
peerId,
|
|
33670
33739
|
endpoint,
|
|
33671
|
-
cwd:
|
|
33740
|
+
cwd: path19.resolve(cwd)
|
|
33672
33741
|
};
|
|
33673
|
-
|
|
33742
|
+
fs18.writeFileSync(path19.join(dir, `${process.pid}.json`), JSON.stringify(entry));
|
|
33674
33743
|
} catch (err) {
|
|
33675
33744
|
logger.debug(`wake-ownership: could not announce this bridge (${err.message})`);
|
|
33676
33745
|
}
|
|
33677
33746
|
}
|
|
33678
33747
|
function withdrawBridge(cwd, peerId) {
|
|
33679
33748
|
try {
|
|
33680
|
-
|
|
33749
|
+
fs18.unlinkSync(path19.join(bridgeDirFor(cwd, peerId), `${process.pid}.json`));
|
|
33681
33750
|
} catch {
|
|
33682
33751
|
}
|
|
33683
33752
|
}
|
|
@@ -33685,23 +33754,23 @@ function listLiveBridges(cwd, peerId) {
|
|
|
33685
33754
|
const dir = bridgeDirFor(cwd, peerId);
|
|
33686
33755
|
let names;
|
|
33687
33756
|
try {
|
|
33688
|
-
names =
|
|
33757
|
+
names = fs18.readdirSync(dir);
|
|
33689
33758
|
} catch {
|
|
33690
33759
|
return [];
|
|
33691
33760
|
}
|
|
33692
33761
|
const live = [];
|
|
33693
33762
|
for (const name of names) {
|
|
33694
33763
|
if (!name.endsWith(".json")) continue;
|
|
33695
|
-
const p =
|
|
33764
|
+
const p = path19.join(dir, name);
|
|
33696
33765
|
let entry = null;
|
|
33697
33766
|
try {
|
|
33698
|
-
entry = JSON.parse(
|
|
33767
|
+
entry = JSON.parse(fs18.readFileSync(p, "utf-8"));
|
|
33699
33768
|
} catch {
|
|
33700
33769
|
entry = null;
|
|
33701
33770
|
}
|
|
33702
33771
|
if (!entry || !pidAlive(entry.pid) || typeof entry.startedAt !== "number") {
|
|
33703
33772
|
try {
|
|
33704
|
-
|
|
33773
|
+
fs18.unlinkSync(p);
|
|
33705
33774
|
} catch {
|
|
33706
33775
|
}
|
|
33707
33776
|
continue;
|
|
@@ -33731,20 +33800,20 @@ function checkWakeOwnership(cwd, peerId) {
|
|
|
33731
33800
|
}
|
|
33732
33801
|
return { isOwner: true, liveCount: live.length + 1 };
|
|
33733
33802
|
}
|
|
33734
|
-
var PROCESS_STARTED_AT,
|
|
33803
|
+
var PROCESS_STARTED_AT, safe4;
|
|
33735
33804
|
var init_wake_ownership = __esm({
|
|
33736
33805
|
"src/services/wake-ownership.ts"() {
|
|
33737
33806
|
"use strict";
|
|
33738
33807
|
init_logger();
|
|
33739
33808
|
PROCESS_STARTED_AT = Date.now() - Math.floor(process.uptime() * 1e3);
|
|
33740
|
-
|
|
33809
|
+
safe4 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33741
33810
|
}
|
|
33742
33811
|
});
|
|
33743
33812
|
|
|
33744
33813
|
// src/services/stale-bridge-reaper.ts
|
|
33745
33814
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
33746
|
-
import
|
|
33747
|
-
import
|
|
33815
|
+
import fs19 from "node:fs";
|
|
33816
|
+
import path20 from "node:path";
|
|
33748
33817
|
function isBridgeCommand(argv) {
|
|
33749
33818
|
if (!argv) return false;
|
|
33750
33819
|
if (/\.test\.|-test\.mjs|scripts\//.test(argv)) return false;
|
|
@@ -33785,7 +33854,7 @@ function listProcesses() {
|
|
|
33785
33854
|
function processCwd(pid) {
|
|
33786
33855
|
try {
|
|
33787
33856
|
if (process.platform === "linux") {
|
|
33788
|
-
return
|
|
33857
|
+
return path20.resolve(fs19.readlinkSync(`/proc/${pid}/cwd`));
|
|
33789
33858
|
}
|
|
33790
33859
|
if (process.platform === "darwin") {
|
|
33791
33860
|
const out = execFileSync2("lsof", ["-a", "-d", "cwd", "-p", String(pid), "-Fn"], {
|
|
@@ -33794,7 +33863,7 @@ function processCwd(pid) {
|
|
|
33794
33863
|
stdio: ["ignore", "pipe", "ignore"]
|
|
33795
33864
|
});
|
|
33796
33865
|
const line = out.split("\n").find((l) => l.startsWith("n"));
|
|
33797
|
-
return line ?
|
|
33866
|
+
return line ? path20.resolve(line.slice(1)) : null;
|
|
33798
33867
|
}
|
|
33799
33868
|
} catch {
|
|
33800
33869
|
}
|
|
@@ -33802,9 +33871,9 @@ function processCwd(pid) {
|
|
|
33802
33871
|
}
|
|
33803
33872
|
function canonicalPath(p) {
|
|
33804
33873
|
try {
|
|
33805
|
-
return
|
|
33874
|
+
return fs19.realpathSync(path20.resolve(p));
|
|
33806
33875
|
} catch {
|
|
33807
|
-
return
|
|
33876
|
+
return path20.resolve(p);
|
|
33808
33877
|
}
|
|
33809
33878
|
}
|
|
33810
33879
|
function ancestorsOf(pid, procs) {
|
|
@@ -33820,9 +33889,9 @@ function ancestorsOf(pid, procs) {
|
|
|
33820
33889
|
function announcedPidsFor(cwd) {
|
|
33821
33890
|
const pids = /* @__PURE__ */ new Set();
|
|
33822
33891
|
try {
|
|
33823
|
-
const base =
|
|
33824
|
-
const prefix =
|
|
33825
|
-
for (const dir of
|
|
33892
|
+
const base = path20.dirname(bridgeDirFor(cwd, "x"));
|
|
33893
|
+
const prefix = path20.basename(bridgeDirFor(cwd, "x")).split(".")[0];
|
|
33894
|
+
for (const dir of fs19.readdirSync(base)) {
|
|
33826
33895
|
if (!dir.startsWith(`${prefix}.`)) continue;
|
|
33827
33896
|
const peerId = dir.slice(prefix.length + 1);
|
|
33828
33897
|
for (const e of listLiveBridges(cwd, peerId)) pids.add(e.pid);
|
|
@@ -35267,9 +35336,9 @@ __export(startup_exports, {
|
|
|
35267
35336
|
setInboxNotifier: () => setInboxNotifier,
|
|
35268
35337
|
triggerReRegistration: () => triggerReRegistration
|
|
35269
35338
|
});
|
|
35270
|
-
import
|
|
35271
|
-
import
|
|
35272
|
-
import
|
|
35339
|
+
import os15 from "node:os";
|
|
35340
|
+
import path21 from "node:path";
|
|
35341
|
+
import fs20 from "node:fs/promises";
|
|
35273
35342
|
import readline2 from "node:readline";
|
|
35274
35343
|
import { execFile as execFile5 } from "node:child_process";
|
|
35275
35344
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -35287,7 +35356,7 @@ function bindInboxNotifier() {
|
|
|
35287
35356
|
}
|
|
35288
35357
|
async function loadPersistedConfig() {
|
|
35289
35358
|
try {
|
|
35290
|
-
const raw = await
|
|
35359
|
+
const raw = await fs20.readFile(PERSIST_PATH, "utf-8");
|
|
35291
35360
|
return JSON.parse(raw);
|
|
35292
35361
|
} catch {
|
|
35293
35362
|
return {};
|
|
@@ -35295,7 +35364,7 @@ async function loadPersistedConfig() {
|
|
|
35295
35364
|
}
|
|
35296
35365
|
async function savePersistedConfig(config2) {
|
|
35297
35366
|
try {
|
|
35298
|
-
await
|
|
35367
|
+
await fs20.writeFile(PERSIST_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
|
|
35299
35368
|
} catch (err) {
|
|
35300
35369
|
const msg = err instanceof Error ? err.message : String(err);
|
|
35301
35370
|
logger.warn(`Could not save config to ${PERSIST_PATH}: ${msg}`);
|
|
@@ -35330,11 +35399,11 @@ First run detected. Where should cogent-bridge store its data?
|
|
|
35330
35399
|
});
|
|
35331
35400
|
}
|
|
35332
35401
|
async function validateStateDir(statePath) {
|
|
35333
|
-
await
|
|
35334
|
-
const testFile =
|
|
35402
|
+
await fs20.mkdir(statePath, { recursive: true });
|
|
35403
|
+
const testFile = path21.join(statePath, ".write-test");
|
|
35335
35404
|
try {
|
|
35336
|
-
await
|
|
35337
|
-
await
|
|
35405
|
+
await fs20.writeFile(testFile, "test", "utf-8");
|
|
35406
|
+
await fs20.unlink(testFile);
|
|
35338
35407
|
} catch {
|
|
35339
35408
|
throw new BridgeError(
|
|
35340
35409
|
"STARTUP_FAILED" /* STARTUP_FAILED */,
|
|
@@ -35522,10 +35591,10 @@ async function runStartup() {
|
|
|
35522
35591
|
if (envStatePath) {
|
|
35523
35592
|
statePath = envStatePath;
|
|
35524
35593
|
} else {
|
|
35525
|
-
const defaultPath =
|
|
35594
|
+
const defaultPath = path21.join(os15.homedir(), ".cogent");
|
|
35526
35595
|
statePath = await firstRunPrompt(defaultPath);
|
|
35527
35596
|
}
|
|
35528
|
-
if (!envStatePath && statePath !==
|
|
35597
|
+
if (!envStatePath && statePath !== path21.join(os15.homedir(), ".cogent")) {
|
|
35529
35598
|
process.env.COGENT_STATE_PATH = statePath;
|
|
35530
35599
|
} else if (!envStatePath) {
|
|
35531
35600
|
process.env.COGENT_STATE_PATH = statePath;
|
|
@@ -35589,7 +35658,7 @@ async function runStartup() {
|
|
|
35589
35658
|
}
|
|
35590
35659
|
initLogger(
|
|
35591
35660
|
config2.COGENT_LOG_LEVEL,
|
|
35592
|
-
|
|
35661
|
+
path21.join(config2.COGENT_STATE_PATH, "logs")
|
|
35593
35662
|
);
|
|
35594
35663
|
if (isCloud && effectiveSessionId && effectiveToken) {
|
|
35595
35664
|
cloudInbox = new MessageInbox();
|
|
@@ -35651,7 +35720,7 @@ var init_startup = __esm({
|
|
|
35651
35720
|
init_auto_relay();
|
|
35652
35721
|
UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
35653
35722
|
execFileAsync3 = promisify4(execFile5);
|
|
35654
|
-
PERSIST_PATH =
|
|
35723
|
+
PERSIST_PATH = path21.join(os15.homedir(), ".cogent-config.json");
|
|
35655
35724
|
legacyWarnEmitted = false;
|
|
35656
35725
|
cloudWsClient = null;
|
|
35657
35726
|
cloudInbox = null;
|
|
@@ -35666,12 +35735,12 @@ var init_startup = __esm({
|
|
|
35666
35735
|
|
|
35667
35736
|
// src/cloud/mail-credential-store.ts
|
|
35668
35737
|
import crypto9 from "node:crypto";
|
|
35669
|
-
import
|
|
35670
|
-
import
|
|
35671
|
-
import
|
|
35738
|
+
import fs21 from "node:fs/promises";
|
|
35739
|
+
import path22 from "node:path";
|
|
35740
|
+
import os16 from "node:os";
|
|
35672
35741
|
function defaultMailCredentialPath(cwd = process.cwd()) {
|
|
35673
|
-
const hash = crypto9.createHash("sha256").update(
|
|
35674
|
-
return
|
|
35742
|
+
const hash = crypto9.createHash("sha256").update(path22.resolve(cwd)).digest("hex").slice(0, 16);
|
|
35743
|
+
return path22.join(os16.homedir(), ".cogent", "mail-credentials", `${hash}.json`);
|
|
35675
35744
|
}
|
|
35676
35745
|
function resolveMailCredentialPath(credentialPath) {
|
|
35677
35746
|
if (credentialPath) return credentialPath;
|
|
@@ -35682,16 +35751,16 @@ function resolveMailCredentialPath(credentialPath) {
|
|
|
35682
35751
|
async function loadMailCredentials(credentialPath) {
|
|
35683
35752
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35684
35753
|
try {
|
|
35685
|
-
return JSON.parse(await
|
|
35754
|
+
return JSON.parse(await fs21.readFile(filePath, "utf-8"));
|
|
35686
35755
|
} catch {
|
|
35687
35756
|
return null;
|
|
35688
35757
|
}
|
|
35689
35758
|
}
|
|
35690
35759
|
async function saveMailCredentials(creds, credentialPath) {
|
|
35691
35760
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35692
|
-
await
|
|
35693
|
-
await
|
|
35694
|
-
await
|
|
35761
|
+
await fs21.mkdir(path22.dirname(filePath), { recursive: true, mode: 448 });
|
|
35762
|
+
await fs21.writeFile(filePath, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
|
|
35763
|
+
await fs21.chmod(filePath, 384);
|
|
35695
35764
|
}
|
|
35696
35765
|
async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
35697
35766
|
if (!mailbox?.address || !mailbox.password) return false;
|
|
@@ -35712,7 +35781,7 @@ async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
|
35712
35781
|
async function clearMailCredentials(credentialPath) {
|
|
35713
35782
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35714
35783
|
try {
|
|
35715
|
-
await
|
|
35784
|
+
await fs21.unlink(filePath);
|
|
35716
35785
|
} catch (err) {
|
|
35717
35786
|
if (err.code !== "ENOENT") throw err;
|
|
35718
35787
|
}
|
|
@@ -35861,19 +35930,60 @@ function registerRegisterPeerTool(server) {
|
|
|
35861
35930
|
storedPeerSecret = void 0;
|
|
35862
35931
|
}
|
|
35863
35932
|
}
|
|
35864
|
-
|
|
35865
|
-
|
|
35866
|
-
|
|
35867
|
-
|
|
35868
|
-
|
|
35869
|
-
|
|
35870
|
-
|
|
35871
|
-
|
|
35872
|
-
|
|
35873
|
-
|
|
35874
|
-
|
|
35875
|
-
|
|
35876
|
-
|
|
35933
|
+
let peer;
|
|
35934
|
+
try {
|
|
35935
|
+
peer = await backend.registerPeer(
|
|
35936
|
+
peerId,
|
|
35937
|
+
sessionId,
|
|
35938
|
+
cwd,
|
|
35939
|
+
label,
|
|
35940
|
+
CLIENT_VERSION,
|
|
35941
|
+
mode,
|
|
35942
|
+
channelSessionId,
|
|
35943
|
+
capabilities,
|
|
35944
|
+
workspaceId,
|
|
35945
|
+
threadId,
|
|
35946
|
+
storedPeerSecret
|
|
35947
|
+
);
|
|
35948
|
+
} catch (regErr) {
|
|
35949
|
+
const msg = regErr instanceof Error ? regErr.message : String(regErr);
|
|
35950
|
+
let recovered;
|
|
35951
|
+
if (/PEER_NOT_YOURS/.test(msg) && isCloudMode()) {
|
|
35952
|
+
try {
|
|
35953
|
+
const creds = await loadCredentials();
|
|
35954
|
+
if (creds?.ownerToken && creds.ownerToken !== creds.token && creds.endpoint && creds.sessionId) {
|
|
35955
|
+
logger.warn(
|
|
35956
|
+
`register_peer: '${peerId}' is owned by an earlier token (its peerSecret was lost by a pre-3.23.5 re-join). Re-proving ownership with the stored owner token.`
|
|
35957
|
+
);
|
|
35958
|
+
const res = await fetch(`${creds.endpoint}/api/sessions/${creds.sessionId}/peers`, {
|
|
35959
|
+
method: "POST",
|
|
35960
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${creds.ownerToken}` },
|
|
35961
|
+
body: JSON.stringify({
|
|
35962
|
+
peerId,
|
|
35963
|
+
cwd,
|
|
35964
|
+
label,
|
|
35965
|
+
type: "agent",
|
|
35966
|
+
clientVersion: CLIENT_VERSION,
|
|
35967
|
+
...mode ? { mode } : {},
|
|
35968
|
+
...capabilities ? { capabilities } : {}
|
|
35969
|
+
})
|
|
35970
|
+
});
|
|
35971
|
+
if (res.ok) {
|
|
35972
|
+
recovered = await res.json();
|
|
35973
|
+
const secret = recovered?.peerSecret;
|
|
35974
|
+
if (secret) {
|
|
35975
|
+
await saveCredentials({ ...creds, peerId, peerSecret: secret, savedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
35976
|
+
logger.info(`register_peer: ownership reclaimed for '${peerId}'; a fresh peerSecret is stored.`);
|
|
35977
|
+
}
|
|
35978
|
+
}
|
|
35979
|
+
}
|
|
35980
|
+
} catch (recoverErr) {
|
|
35981
|
+
logger.debug(`register_peer: ownership recovery failed: ${recoverErr.message}`);
|
|
35982
|
+
}
|
|
35983
|
+
}
|
|
35984
|
+
if (!recovered) throw regErr;
|
|
35985
|
+
peer = recovered;
|
|
35986
|
+
}
|
|
35877
35987
|
if (isCloudMode()) {
|
|
35878
35988
|
try {
|
|
35879
35989
|
const creds = await loadCredentials();
|
|
@@ -37390,7 +37500,12 @@ function registerJoinSessionTool(server) {
|
|
|
37390
37500
|
if (prior && prior.endpoint === endpoint && prior.sessionId === data.sessionId) {
|
|
37391
37501
|
carried = {
|
|
37392
37502
|
...prior.peerId ? { peerId: prior.peerId } : {},
|
|
37393
|
-
...prior.peerSecret ? { peerSecret: prior.peerSecret } : {}
|
|
37503
|
+
...prior.peerSecret ? { peerSecret: prior.peerSecret } : {},
|
|
37504
|
+
// Keep the token that owns the peer. A re-join mints a NEW one, and ownership is
|
|
37505
|
+
// proven by the CREATING token (or its secret) — so overwriting this field is what
|
|
37506
|
+
// turned a lost peerSecret into a permanent lockout. Prefer an ownerToken we are
|
|
37507
|
+
// already carrying; only fall back to `prior.token` the first time.
|
|
37508
|
+
...prior.ownerToken || prior.token ? { ownerToken: prior.ownerToken ?? prior.token } : {}
|
|
37394
37509
|
};
|
|
37395
37510
|
}
|
|
37396
37511
|
} catch (err) {
|
|
@@ -37677,8 +37792,8 @@ var require_cookies = __commonJS({
|
|
|
37677
37792
|
if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
|
|
37678
37793
|
return false;
|
|
37679
37794
|
}
|
|
37680
|
-
let
|
|
37681
|
-
if (
|
|
37795
|
+
let path26 = this.getPath(urlparts.pathname);
|
|
37796
|
+
if (path26.substr(0, cookie.path.length) !== cookie.path) {
|
|
37682
37797
|
return false;
|
|
37683
37798
|
}
|
|
37684
37799
|
if (cookie.secure && urlparts.protocol !== "https:") {
|
|
@@ -37738,16 +37853,16 @@ var require_cookies = __commonJS({
|
|
|
37738
37853
|
* @returns {String} Normalized path
|
|
37739
37854
|
*/
|
|
37740
37855
|
getPath(pathname) {
|
|
37741
|
-
let
|
|
37742
|
-
|
|
37743
|
-
|
|
37744
|
-
if (
|
|
37745
|
-
|
|
37856
|
+
let path26 = (pathname || "/").split("/");
|
|
37857
|
+
path26.pop();
|
|
37858
|
+
path26 = path26.join("/").trim();
|
|
37859
|
+
if (path26.charAt(0) !== "/") {
|
|
37860
|
+
path26 = "/" + path26;
|
|
37746
37861
|
}
|
|
37747
|
-
if (
|
|
37748
|
-
|
|
37862
|
+
if (path26.substr(-1) !== "/") {
|
|
37863
|
+
path26 += "/";
|
|
37749
37864
|
}
|
|
37750
|
-
return
|
|
37865
|
+
return path26;
|
|
37751
37866
|
}
|
|
37752
37867
|
};
|
|
37753
37868
|
module.exports = Cookies;
|
|
@@ -38048,15 +38163,15 @@ var require_shared = __commonJS({
|
|
|
38048
38163
|
"use strict";
|
|
38049
38164
|
var urllib = __require("url");
|
|
38050
38165
|
var util2 = __require("util");
|
|
38051
|
-
var
|
|
38166
|
+
var fs24 = __require("fs");
|
|
38052
38167
|
var nmfetch = require_fetch();
|
|
38053
38168
|
var dns = __require("dns");
|
|
38054
38169
|
var net = __require("net");
|
|
38055
|
-
var
|
|
38170
|
+
var os18 = __require("os");
|
|
38056
38171
|
var DNS_TTL = 5 * 60 * 1e3;
|
|
38057
38172
|
var networkInterfaces;
|
|
38058
38173
|
try {
|
|
38059
|
-
networkInterfaces =
|
|
38174
|
+
networkInterfaces = os18.networkInterfaces();
|
|
38060
38175
|
} catch (err) {
|
|
38061
38176
|
}
|
|
38062
38177
|
module.exports.networkInterfaces = networkInterfaces;
|
|
@@ -38434,7 +38549,7 @@ var require_shared = __commonJS({
|
|
|
38434
38549
|
}
|
|
38435
38550
|
return callback(null, parsedDataUri.data);
|
|
38436
38551
|
} else if (content.path) {
|
|
38437
|
-
return resolveStream(
|
|
38552
|
+
return resolveStream(fs24.createReadStream(content.path), callback);
|
|
38438
38553
|
}
|
|
38439
38554
|
}
|
|
38440
38555
|
if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
|
|
@@ -38558,7 +38673,7 @@ var require_shared = __commonJS({
|
|
|
38558
38673
|
var require_mime_types = __commonJS({
|
|
38559
38674
|
"node_modules/nodemailer/lib/mime-funcs/mime-types.js"(exports, module) {
|
|
38560
38675
|
"use strict";
|
|
38561
|
-
var
|
|
38676
|
+
var path26 = __require("path");
|
|
38562
38677
|
var defaultMimeType = "application/octet-stream";
|
|
38563
38678
|
var defaultExtension = "bin";
|
|
38564
38679
|
var mimeTypes = /* @__PURE__ */ new Map([
|
|
@@ -40616,7 +40731,7 @@ var require_mime_types = __commonJS({
|
|
|
40616
40731
|
if (!filename) {
|
|
40617
40732
|
return defaultMimeType;
|
|
40618
40733
|
}
|
|
40619
|
-
let parsed =
|
|
40734
|
+
let parsed = path26.parse(filename);
|
|
40620
40735
|
let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
|
|
40621
40736
|
let value = defaultMimeType;
|
|
40622
40737
|
if (extensions.has(extension)) {
|
|
@@ -42018,7 +42133,7 @@ var require_mime_node = __commonJS({
|
|
|
42018
42133
|
"node_modules/nodemailer/lib/mime-node/index.js"(exports, module) {
|
|
42019
42134
|
"use strict";
|
|
42020
42135
|
var crypto12 = __require("crypto");
|
|
42021
|
-
var
|
|
42136
|
+
var fs24 = __require("fs");
|
|
42022
42137
|
var punycode = require_punycode();
|
|
42023
42138
|
var PassThrough = __require("stream").PassThrough;
|
|
42024
42139
|
var shared = require_shared();
|
|
@@ -42733,7 +42848,7 @@ var require_mime_node = __commonJS({
|
|
|
42733
42848
|
setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
|
|
42734
42849
|
return contentStream;
|
|
42735
42850
|
}
|
|
42736
|
-
return
|
|
42851
|
+
return fs24.createReadStream(content.path);
|
|
42737
42852
|
} else if (content && typeof content.href === "string") {
|
|
42738
42853
|
if (this.disableUrlAccess) {
|
|
42739
42854
|
contentStream = new PassThrough();
|
|
@@ -43754,8 +43869,8 @@ var require_dkim = __commonJS({
|
|
|
43754
43869
|
var RelaxedBody = require_relaxed_body();
|
|
43755
43870
|
var sign = require_sign();
|
|
43756
43871
|
var PassThrough = __require("stream").PassThrough;
|
|
43757
|
-
var
|
|
43758
|
-
var
|
|
43872
|
+
var fs24 = __require("fs");
|
|
43873
|
+
var path26 = __require("path");
|
|
43759
43874
|
var crypto12 = __require("crypto");
|
|
43760
43875
|
var DKIM_ALGO = "sha256";
|
|
43761
43876
|
var MAX_MESSAGE_SIZE = 128 * 1024;
|
|
@@ -43769,7 +43884,7 @@ var require_dkim = __commonJS({
|
|
|
43769
43884
|
this.chunks = [];
|
|
43770
43885
|
this.chunklen = 0;
|
|
43771
43886
|
this.readPos = 0;
|
|
43772
|
-
this.cachePath = this.cacheDir ?
|
|
43887
|
+
this.cachePath = this.cacheDir ? path26.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
|
|
43773
43888
|
this.cache = false;
|
|
43774
43889
|
this.headers = false;
|
|
43775
43890
|
this.bodyHash = false;
|
|
@@ -43789,10 +43904,10 @@ var require_dkim = __commonJS({
|
|
|
43789
43904
|
if (!this.cache || !this.cachePath) {
|
|
43790
43905
|
return;
|
|
43791
43906
|
}
|
|
43792
|
-
|
|
43907
|
+
fs24.unlink(this.cachePath, () => false);
|
|
43793
43908
|
}
|
|
43794
43909
|
createReadCache() {
|
|
43795
|
-
this.cache =
|
|
43910
|
+
this.cache = fs24.createReadStream(this.cachePath);
|
|
43796
43911
|
this.cache.once("error", (err) => {
|
|
43797
43912
|
this.cleanup();
|
|
43798
43913
|
this.output.emit("error", err);
|
|
@@ -43848,7 +43963,7 @@ var require_dkim = __commonJS({
|
|
|
43848
43963
|
}
|
|
43849
43964
|
createWriteCache() {
|
|
43850
43965
|
this.output.usingCache = true;
|
|
43851
|
-
this.cache =
|
|
43966
|
+
this.cache = fs24.createWriteStream(this.cachePath);
|
|
43852
43967
|
this.cache.once("error", (err) => {
|
|
43853
43968
|
this.cleanup();
|
|
43854
43969
|
this.relaxedBody.unpipe(this.cache);
|
|
@@ -44775,7 +44890,7 @@ var require_smtp_connection = __commonJS({
|
|
|
44775
44890
|
var EventEmitter = __require("events").EventEmitter;
|
|
44776
44891
|
var net = __require("net");
|
|
44777
44892
|
var tls = __require("tls");
|
|
44778
|
-
var
|
|
44893
|
+
var os18 = __require("os");
|
|
44779
44894
|
var crypto12 = __require("crypto");
|
|
44780
44895
|
var DataStream = require_data_stream();
|
|
44781
44896
|
var PassThrough = __require("stream").PassThrough;
|
|
@@ -46168,7 +46283,7 @@ var require_smtp_connection = __commonJS({
|
|
|
46168
46283
|
_getHostname() {
|
|
46169
46284
|
let defaultHostname;
|
|
46170
46285
|
try {
|
|
46171
|
-
defaultHostname =
|
|
46286
|
+
defaultHostname = os18.hostname() || "";
|
|
46172
46287
|
} catch (err) {
|
|
46173
46288
|
defaultHostname = "localhost";
|
|
46174
46289
|
}
|
|
@@ -48737,13 +48852,13 @@ var require_nodemailer = __commonJS({
|
|
|
48737
48852
|
});
|
|
48738
48853
|
|
|
48739
48854
|
// src/mail/mail-sender.ts
|
|
48740
|
-
import
|
|
48741
|
-
import
|
|
48855
|
+
import fs22 from "node:fs/promises";
|
|
48856
|
+
import path23 from "node:path";
|
|
48742
48857
|
async function buildAndSendMail(sender, creds, params) {
|
|
48743
48858
|
const attachments = [];
|
|
48744
48859
|
for (const p of params.attachmentPaths ?? []) {
|
|
48745
|
-
const content = await
|
|
48746
|
-
attachments.push({ filename:
|
|
48860
|
+
const content = await fs22.readFile(p);
|
|
48861
|
+
attachments.push({ filename: path23.basename(p), content });
|
|
48747
48862
|
}
|
|
48748
48863
|
const { messageId } = await sender.send({
|
|
48749
48864
|
from: creds.address,
|
|
@@ -49132,8 +49247,8 @@ var require_req = __commonJS({
|
|
|
49132
49247
|
if (req.originalUrl) {
|
|
49133
49248
|
_req.url = req.originalUrl;
|
|
49134
49249
|
} else {
|
|
49135
|
-
const
|
|
49136
|
-
_req.url = typeof
|
|
49250
|
+
const path26 = req.path;
|
|
49251
|
+
_req.url = typeof path26 === "string" ? path26 : req.url ? req.url.path || req.url : void 0;
|
|
49137
49252
|
}
|
|
49138
49253
|
if (req.query) {
|
|
49139
49254
|
_req.query = req.query;
|
|
@@ -49298,14 +49413,14 @@ var require_redact = __commonJS({
|
|
|
49298
49413
|
}
|
|
49299
49414
|
return obj;
|
|
49300
49415
|
}
|
|
49301
|
-
function parsePath(
|
|
49416
|
+
function parsePath(path26) {
|
|
49302
49417
|
const parts = [];
|
|
49303
49418
|
let current = "";
|
|
49304
49419
|
let inBrackets = false;
|
|
49305
49420
|
let inQuotes = false;
|
|
49306
49421
|
let quoteChar = "";
|
|
49307
|
-
for (let i = 0; i <
|
|
49308
|
-
const char =
|
|
49422
|
+
for (let i = 0; i < path26.length; i++) {
|
|
49423
|
+
const char = path26[i];
|
|
49309
49424
|
if (!inBrackets && char === ".") {
|
|
49310
49425
|
if (current) {
|
|
49311
49426
|
parts.push(current);
|
|
@@ -49436,10 +49551,10 @@ var require_redact = __commonJS({
|
|
|
49436
49551
|
return current;
|
|
49437
49552
|
}
|
|
49438
49553
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
49439
|
-
for (const
|
|
49440
|
-
const parts = parsePath(
|
|
49554
|
+
for (const path26 of paths) {
|
|
49555
|
+
const parts = parsePath(path26);
|
|
49441
49556
|
if (parts.includes("*")) {
|
|
49442
|
-
redactWildcardPath(obj, parts, censor,
|
|
49557
|
+
redactWildcardPath(obj, parts, censor, path26, remove);
|
|
49443
49558
|
} else {
|
|
49444
49559
|
if (remove) {
|
|
49445
49560
|
removeKey(obj, parts);
|
|
@@ -49524,8 +49639,8 @@ var require_redact = __commonJS({
|
|
|
49524
49639
|
}
|
|
49525
49640
|
} else {
|
|
49526
49641
|
if (afterWildcard.includes("*")) {
|
|
49527
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49528
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
49642
|
+
const wrappedCensor = typeof censor === "function" ? (value, path26) => {
|
|
49643
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path26];
|
|
49529
49644
|
return censor(value, fullPath);
|
|
49530
49645
|
} : censor;
|
|
49531
49646
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -49560,8 +49675,8 @@ var require_redact = __commonJS({
|
|
|
49560
49675
|
return null;
|
|
49561
49676
|
}
|
|
49562
49677
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
49563
|
-
for (const
|
|
49564
|
-
const parts = parsePath(
|
|
49678
|
+
for (const path26 of pathsToClone) {
|
|
49679
|
+
const parts = parsePath(path26);
|
|
49565
49680
|
let current = pathStructure;
|
|
49566
49681
|
for (let i = 0; i < parts.length; i++) {
|
|
49567
49682
|
const part = parts[i];
|
|
@@ -49613,24 +49728,24 @@ var require_redact = __commonJS({
|
|
|
49613
49728
|
}
|
|
49614
49729
|
return cloneSelectively(obj, pathStructure);
|
|
49615
49730
|
}
|
|
49616
|
-
function validatePath(
|
|
49617
|
-
if (typeof
|
|
49731
|
+
function validatePath(path26) {
|
|
49732
|
+
if (typeof path26 !== "string") {
|
|
49618
49733
|
throw new Error("Paths must be (non-empty) strings");
|
|
49619
49734
|
}
|
|
49620
|
-
if (
|
|
49735
|
+
if (path26 === "") {
|
|
49621
49736
|
throw new Error("Invalid redaction path ()");
|
|
49622
49737
|
}
|
|
49623
|
-
if (
|
|
49624
|
-
throw new Error(`Invalid redaction path (${
|
|
49738
|
+
if (path26.includes("..")) {
|
|
49739
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49625
49740
|
}
|
|
49626
|
-
if (
|
|
49627
|
-
throw new Error(`Invalid redaction path (${
|
|
49741
|
+
if (path26.includes(",")) {
|
|
49742
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49628
49743
|
}
|
|
49629
49744
|
let bracketCount = 0;
|
|
49630
49745
|
let inQuotes = false;
|
|
49631
49746
|
let quoteChar = "";
|
|
49632
|
-
for (let i = 0; i <
|
|
49633
|
-
const char =
|
|
49747
|
+
for (let i = 0; i < path26.length; i++) {
|
|
49748
|
+
const char = path26[i];
|
|
49634
49749
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
49635
49750
|
if (!inQuotes) {
|
|
49636
49751
|
inQuotes = true;
|
|
@@ -49644,20 +49759,20 @@ var require_redact = __commonJS({
|
|
|
49644
49759
|
} else if (char === "]" && !inQuotes) {
|
|
49645
49760
|
bracketCount--;
|
|
49646
49761
|
if (bracketCount < 0) {
|
|
49647
|
-
throw new Error(`Invalid redaction path (${
|
|
49762
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49648
49763
|
}
|
|
49649
49764
|
}
|
|
49650
49765
|
}
|
|
49651
49766
|
if (bracketCount !== 0) {
|
|
49652
|
-
throw new Error(`Invalid redaction path (${
|
|
49767
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49653
49768
|
}
|
|
49654
49769
|
}
|
|
49655
49770
|
function validatePaths(paths) {
|
|
49656
49771
|
if (!Array.isArray(paths)) {
|
|
49657
49772
|
throw new TypeError("paths must be an array");
|
|
49658
49773
|
}
|
|
49659
|
-
for (const
|
|
49660
|
-
validatePath(
|
|
49774
|
+
for (const path26 of paths) {
|
|
49775
|
+
validatePath(path26);
|
|
49661
49776
|
}
|
|
49662
49777
|
}
|
|
49663
49778
|
function slowRedact(options = {}) {
|
|
@@ -49825,8 +49940,8 @@ var require_redaction = __commonJS({
|
|
|
49825
49940
|
if (shape[k] === null) {
|
|
49826
49941
|
o[k] = (value) => topCensor(value, [k]);
|
|
49827
49942
|
} else {
|
|
49828
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49829
|
-
return censor(value, [k, ...
|
|
49943
|
+
const wrappedCensor = typeof censor === "function" ? (value, path26) => {
|
|
49944
|
+
return censor(value, [k, ...path26]);
|
|
49830
49945
|
} : censor;
|
|
49831
49946
|
o[k] = Redact({
|
|
49832
49947
|
paths: shape[k],
|
|
@@ -50044,10 +50159,10 @@ var require_atomic_sleep = __commonJS({
|
|
|
50044
50159
|
var require_sonic_boom = __commonJS({
|
|
50045
50160
|
"node_modules/sonic-boom/index.js"(exports, module) {
|
|
50046
50161
|
"use strict";
|
|
50047
|
-
var
|
|
50162
|
+
var fs24 = __require("fs");
|
|
50048
50163
|
var EventEmitter = __require("events");
|
|
50049
50164
|
var inherits = __require("util").inherits;
|
|
50050
|
-
var
|
|
50165
|
+
var path26 = __require("path");
|
|
50051
50166
|
var sleep4 = require_atomic_sleep();
|
|
50052
50167
|
var assert2 = __require("assert");
|
|
50053
50168
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -50101,20 +50216,20 @@ var require_sonic_boom = __commonJS({
|
|
|
50101
50216
|
const mode = sonic.mode;
|
|
50102
50217
|
if (sonic.sync) {
|
|
50103
50218
|
try {
|
|
50104
|
-
if (sonic.mkdir)
|
|
50105
|
-
const fd =
|
|
50219
|
+
if (sonic.mkdir) fs24.mkdirSync(path26.dirname(file), { recursive: true });
|
|
50220
|
+
const fd = fs24.openSync(file, flags, mode);
|
|
50106
50221
|
fileOpened(null, fd);
|
|
50107
50222
|
} catch (err) {
|
|
50108
50223
|
fileOpened(err);
|
|
50109
50224
|
throw err;
|
|
50110
50225
|
}
|
|
50111
50226
|
} else if (sonic.mkdir) {
|
|
50112
|
-
|
|
50227
|
+
fs24.mkdir(path26.dirname(file), { recursive: true }, (err) => {
|
|
50113
50228
|
if (err) return fileOpened(err);
|
|
50114
|
-
|
|
50229
|
+
fs24.open(file, flags, mode, fileOpened);
|
|
50115
50230
|
});
|
|
50116
50231
|
} else {
|
|
50117
|
-
|
|
50232
|
+
fs24.open(file, flags, mode, fileOpened);
|
|
50118
50233
|
}
|
|
50119
50234
|
}
|
|
50120
50235
|
function SonicBoom(opts) {
|
|
@@ -50155,8 +50270,8 @@ var require_sonic_boom = __commonJS({
|
|
|
50155
50270
|
this.flush = flushBuffer;
|
|
50156
50271
|
this.flushSync = flushBufferSync;
|
|
50157
50272
|
this._actualWrite = actualWriteBuffer;
|
|
50158
|
-
fsWriteSync = () =>
|
|
50159
|
-
fsWrite = () =>
|
|
50273
|
+
fsWriteSync = () => fs24.writeSync(this.fd, this._writingBuf);
|
|
50274
|
+
fsWrite = () => fs24.write(this.fd, this._writingBuf, this.release);
|
|
50160
50275
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
50161
50276
|
this._writingBuf = "";
|
|
50162
50277
|
this.write = write;
|
|
@@ -50165,15 +50280,15 @@ var require_sonic_boom = __commonJS({
|
|
|
50165
50280
|
this._actualWrite = actualWrite;
|
|
50166
50281
|
fsWriteSync = () => {
|
|
50167
50282
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
50168
|
-
return
|
|
50283
|
+
return fs24.writeSync(this.fd, this._writingBuf);
|
|
50169
50284
|
}
|
|
50170
|
-
return
|
|
50285
|
+
return fs24.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50171
50286
|
};
|
|
50172
50287
|
fsWrite = () => {
|
|
50173
50288
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
50174
|
-
return
|
|
50289
|
+
return fs24.write(this.fd, this._writingBuf, this.release);
|
|
50175
50290
|
}
|
|
50176
|
-
return
|
|
50291
|
+
return fs24.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
50177
50292
|
};
|
|
50178
50293
|
} else {
|
|
50179
50294
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -50230,7 +50345,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50230
50345
|
}
|
|
50231
50346
|
}
|
|
50232
50347
|
if (this._fsync) {
|
|
50233
|
-
|
|
50348
|
+
fs24.fsyncSync(this.fd);
|
|
50234
50349
|
}
|
|
50235
50350
|
const len = this._len;
|
|
50236
50351
|
if (this._reopening) {
|
|
@@ -50344,7 +50459,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50344
50459
|
const onDrain = () => {
|
|
50345
50460
|
if (!this._fsync) {
|
|
50346
50461
|
try {
|
|
50347
|
-
|
|
50462
|
+
fs24.fsync(this.fd, (err) => {
|
|
50348
50463
|
this._flushPending = false;
|
|
50349
50464
|
cb(err);
|
|
50350
50465
|
});
|
|
@@ -50446,7 +50561,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50446
50561
|
const fd = this.fd;
|
|
50447
50562
|
this.once("ready", () => {
|
|
50448
50563
|
if (fd !== this.fd) {
|
|
50449
|
-
|
|
50564
|
+
fs24.close(fd, (err) => {
|
|
50450
50565
|
if (err) {
|
|
50451
50566
|
return this.emit("error", err);
|
|
50452
50567
|
}
|
|
@@ -50495,7 +50610,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50495
50610
|
buf = this._bufs[0];
|
|
50496
50611
|
}
|
|
50497
50612
|
try {
|
|
50498
|
-
const n = Buffer.isBuffer(buf) ?
|
|
50613
|
+
const n = Buffer.isBuffer(buf) ? fs24.writeSync(this.fd, buf) : fs24.writeSync(this.fd, buf, "utf8");
|
|
50499
50614
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
50500
50615
|
buf = releasedBufObj.writingBuf;
|
|
50501
50616
|
this._len = releasedBufObj.len;
|
|
@@ -50511,7 +50626,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50511
50626
|
}
|
|
50512
50627
|
}
|
|
50513
50628
|
try {
|
|
50514
|
-
|
|
50629
|
+
fs24.fsyncSync(this.fd);
|
|
50515
50630
|
} catch {
|
|
50516
50631
|
}
|
|
50517
50632
|
}
|
|
@@ -50532,7 +50647,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50532
50647
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
50533
50648
|
}
|
|
50534
50649
|
try {
|
|
50535
|
-
const n =
|
|
50650
|
+
const n = fs24.writeSync(this.fd, buf);
|
|
50536
50651
|
buf = buf.subarray(n);
|
|
50537
50652
|
this._len = Math.max(this._len - n, 0);
|
|
50538
50653
|
if (buf.length <= 0) {
|
|
@@ -50560,13 +50675,13 @@ var require_sonic_boom = __commonJS({
|
|
|
50560
50675
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
50561
50676
|
if (this.sync) {
|
|
50562
50677
|
try {
|
|
50563
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
50678
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs24.writeSync(this.fd, this._writingBuf) : fs24.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50564
50679
|
release(null, written);
|
|
50565
50680
|
} catch (err) {
|
|
50566
50681
|
release(err);
|
|
50567
50682
|
}
|
|
50568
50683
|
} else {
|
|
50569
|
-
|
|
50684
|
+
fs24.write(this.fd, this._writingBuf, release);
|
|
50570
50685
|
}
|
|
50571
50686
|
}
|
|
50572
50687
|
function actualWriteBuffer() {
|
|
@@ -50575,7 +50690,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50575
50690
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
50576
50691
|
if (this.sync) {
|
|
50577
50692
|
try {
|
|
50578
|
-
const written =
|
|
50693
|
+
const written = fs24.writeSync(this.fd, this._writingBuf);
|
|
50579
50694
|
release(null, written);
|
|
50580
50695
|
} catch (err) {
|
|
50581
50696
|
release(err);
|
|
@@ -50584,7 +50699,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50584
50699
|
if (kCopyBuffer) {
|
|
50585
50700
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
50586
50701
|
}
|
|
50587
|
-
|
|
50702
|
+
fs24.write(this.fd, this._writingBuf, release);
|
|
50588
50703
|
}
|
|
50589
50704
|
}
|
|
50590
50705
|
function actualClose(sonic) {
|
|
@@ -50600,12 +50715,12 @@ var require_sonic_boom = __commonJS({
|
|
|
50600
50715
|
sonic._lens = [];
|
|
50601
50716
|
assert2(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
50602
50717
|
try {
|
|
50603
|
-
|
|
50718
|
+
fs24.fsync(sonic.fd, closeWrapped);
|
|
50604
50719
|
} catch {
|
|
50605
50720
|
}
|
|
50606
50721
|
function closeWrapped() {
|
|
50607
50722
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
50608
|
-
|
|
50723
|
+
fs24.close(sonic.fd, done);
|
|
50609
50724
|
} else {
|
|
50610
50725
|
done();
|
|
50611
50726
|
}
|
|
@@ -51441,15 +51556,15 @@ var require_transport = __commonJS({
|
|
|
51441
51556
|
if (!unquoted) {
|
|
51442
51557
|
return false;
|
|
51443
51558
|
}
|
|
51444
|
-
let
|
|
51445
|
-
if (
|
|
51559
|
+
let path26 = unquoted;
|
|
51560
|
+
if (path26.startsWith("file://")) {
|
|
51446
51561
|
try {
|
|
51447
|
-
|
|
51562
|
+
path26 = fileURLToPath(path26);
|
|
51448
51563
|
} catch {
|
|
51449
51564
|
return false;
|
|
51450
51565
|
}
|
|
51451
51566
|
}
|
|
51452
|
-
return isAbsolute(
|
|
51567
|
+
return isAbsolute(path26) && !existsSync(path26);
|
|
51453
51568
|
}
|
|
51454
51569
|
function stripQuotes(value) {
|
|
51455
51570
|
const first = value[0];
|
|
@@ -53143,7 +53258,7 @@ var require_multistream = __commonJS({
|
|
|
53143
53258
|
var require_pino = __commonJS({
|
|
53144
53259
|
"node_modules/pino/pino.js"(exports, module) {
|
|
53145
53260
|
"use strict";
|
|
53146
|
-
var
|
|
53261
|
+
var os18 = __require("node:os");
|
|
53147
53262
|
var stdSerializers = require_pino_std_serializers();
|
|
53148
53263
|
var caller = require_caller();
|
|
53149
53264
|
var redaction = require_redaction();
|
|
@@ -53190,7 +53305,7 @@ var require_pino = __commonJS({
|
|
|
53190
53305
|
} = symbols;
|
|
53191
53306
|
var { epochTime, nullTime } = time3;
|
|
53192
53307
|
var { pid } = process;
|
|
53193
|
-
var hostname2 =
|
|
53308
|
+
var hostname2 = os18.hostname();
|
|
53194
53309
|
var defaultErrorSerializer = stdSerializers.err;
|
|
53195
53310
|
var defaultOptions2 = {
|
|
53196
53311
|
level: "info",
|
|
@@ -85516,15 +85631,15 @@ var require_tools2 = __commonJS({
|
|
|
85516
85631
|
* @param {String} path - Mailbox path to encode
|
|
85517
85632
|
* @returns {String} Encoded mailbox path
|
|
85518
85633
|
*/
|
|
85519
|
-
encodePath(connection,
|
|
85520
|
-
|
|
85521
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(
|
|
85634
|
+
encodePath(connection, path26) {
|
|
85635
|
+
path26 = (path26 || "").toString();
|
|
85636
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path26)) {
|
|
85522
85637
|
try {
|
|
85523
|
-
|
|
85638
|
+
path26 = iconv.encode(path26, "utf-7-imap").toString();
|
|
85524
85639
|
} catch {
|
|
85525
85640
|
}
|
|
85526
85641
|
}
|
|
85527
|
-
return
|
|
85642
|
+
return path26;
|
|
85528
85643
|
},
|
|
85529
85644
|
/**
|
|
85530
85645
|
* Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
@@ -85533,15 +85648,15 @@ var require_tools2 = __commonJS({
|
|
|
85533
85648
|
* @param {String} path - Mailbox path to decode
|
|
85534
85649
|
* @returns {String} Decoded mailbox path
|
|
85535
85650
|
*/
|
|
85536
|
-
decodePath(connection,
|
|
85537
|
-
|
|
85538
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(
|
|
85651
|
+
decodePath(connection, path26) {
|
|
85652
|
+
path26 = (path26 || "").toString();
|
|
85653
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path26)) {
|
|
85539
85654
|
try {
|
|
85540
|
-
|
|
85655
|
+
path26 = iconv.decode(Buffer.from(path26), "utf-7-imap").toString();
|
|
85541
85656
|
} catch {
|
|
85542
85657
|
}
|
|
85543
85658
|
}
|
|
85544
|
-
return
|
|
85659
|
+
return path26;
|
|
85545
85660
|
},
|
|
85546
85661
|
/**
|
|
85547
85662
|
* Normalizes a mailbox path by joining array segments with the namespace delimiter,
|
|
@@ -85552,17 +85667,17 @@ var require_tools2 = __commonJS({
|
|
|
85552
85667
|
* @param {Boolean} [skipNamespace] - If true, skips prepending the namespace prefix
|
|
85553
85668
|
* @returns {String} Normalized mailbox path
|
|
85554
85669
|
*/
|
|
85555
|
-
normalizePath(connection,
|
|
85556
|
-
if (Array.isArray(
|
|
85557
|
-
|
|
85670
|
+
normalizePath(connection, path26, skipNamespace) {
|
|
85671
|
+
if (Array.isArray(path26)) {
|
|
85672
|
+
path26 = path26.join(connection.namespace && connection.namespace.delimiter || "");
|
|
85558
85673
|
}
|
|
85559
|
-
if (
|
|
85674
|
+
if (path26.toUpperCase() === "INBOX") {
|
|
85560
85675
|
return "INBOX";
|
|
85561
85676
|
}
|
|
85562
|
-
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !
|
|
85563
|
-
|
|
85677
|
+
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path26.startsWith(connection.namespace.prefix)) {
|
|
85678
|
+
path26 = connection.namespace.prefix + path26;
|
|
85564
85679
|
}
|
|
85565
|
-
return
|
|
85680
|
+
return path26;
|
|
85566
85681
|
},
|
|
85567
85682
|
/**
|
|
85568
85683
|
* Compares two mailbox paths for equality after normalization.
|
|
@@ -85893,14 +86008,14 @@ var require_tools2 = __commonJS({
|
|
|
85893
86008
|
}
|
|
85894
86009
|
}
|
|
85895
86010
|
if (map.emailId || map.uid) {
|
|
85896
|
-
let
|
|
85897
|
-
if (/[\u0080-\uffff]/.test(
|
|
86011
|
+
let path26 = mailbox.path;
|
|
86012
|
+
if (/[\u0080-\uffff]/.test(path26)) {
|
|
85898
86013
|
try {
|
|
85899
|
-
|
|
86014
|
+
path26 = iconv.encode(path26, "utf-7-imap").toString();
|
|
85900
86015
|
} catch {
|
|
85901
86016
|
}
|
|
85902
86017
|
}
|
|
85903
|
-
map.id = map.emailId || createHash2("md5").update([
|
|
86018
|
+
map.id = map.emailId || createHash2("md5").update([path26, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
|
|
85904
86019
|
}
|
|
85905
86020
|
if (map.flags) {
|
|
85906
86021
|
let flagColor = tools.getFlagColor(map.flags);
|
|
@@ -86075,16 +86190,16 @@ var require_tools2 = __commonJS({
|
|
|
86075
86190
|
* @returns {Object} Parsed body structure tree with part numbers, types, parameters, and child nodes
|
|
86076
86191
|
*/
|
|
86077
86192
|
parseBodystructure(entry) {
|
|
86078
|
-
let walk = (node,
|
|
86079
|
-
|
|
86193
|
+
let walk = (node, path26) => {
|
|
86194
|
+
path26 = path26 || [];
|
|
86080
86195
|
let curNode = {}, i = 0, part = 0;
|
|
86081
|
-
if (
|
|
86082
|
-
curNode.part =
|
|
86196
|
+
if (path26.length) {
|
|
86197
|
+
curNode.part = path26.join(".");
|
|
86083
86198
|
}
|
|
86084
86199
|
if (Array.isArray(node[0])) {
|
|
86085
86200
|
curNode.childNodes = [];
|
|
86086
86201
|
while (Array.isArray(node[i])) {
|
|
86087
|
-
curNode.childNodes.push(walk(node[i],
|
|
86202
|
+
curNode.childNodes.push(walk(node[i], path26.concat(++part)));
|
|
86088
86203
|
i++;
|
|
86089
86204
|
}
|
|
86090
86205
|
curNode.type = "multipart/" + ((node[i++] || {}).value || "").toString().toLowerCase();
|
|
@@ -86127,7 +86242,7 @@ var require_tools2 = __commonJS({
|
|
|
86127
86242
|
// the encapsulated message shares the part number with its wrapper.
|
|
86128
86243
|
// Distinction is via suffixes: path.MIME = wrapper headers,
|
|
86129
86244
|
// path.HEADER = encapsulated message headers.
|
|
86130
|
-
walk(node[i],
|
|
86245
|
+
walk(node[i], path26)
|
|
86131
86246
|
];
|
|
86132
86247
|
}
|
|
86133
86248
|
i++;
|
|
@@ -88089,14 +88204,14 @@ var require_select = __commonJS({
|
|
|
88089
88204
|
// update into a silent no-op for the rest of the session.
|
|
88090
88205
|
permanentflags: { key: "permanentFlags", parse: (value) => Array.isArray(value) && new Set(value) }
|
|
88091
88206
|
});
|
|
88092
|
-
module.exports = async (connection,
|
|
88207
|
+
module.exports = async (connection, path26, options) => {
|
|
88093
88208
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88094
88209
|
return;
|
|
88095
88210
|
}
|
|
88096
88211
|
options = options || {};
|
|
88097
|
-
|
|
88098
|
-
if (!connection.folders.has(
|
|
88099
|
-
let folders = await connection.run("LIST", "",
|
|
88212
|
+
path26 = normalizePath(connection, path26);
|
|
88213
|
+
if (!connection.folders.has(path26)) {
|
|
88214
|
+
let folders = await connection.run("LIST", "", path26);
|
|
88100
88215
|
if (!folders) {
|
|
88101
88216
|
throw new Error("Failed to fetch folders");
|
|
88102
88217
|
}
|
|
@@ -88104,10 +88219,10 @@ var require_select = __commonJS({
|
|
|
88104
88219
|
connection.folders.set(folder.path, folder);
|
|
88105
88220
|
});
|
|
88106
88221
|
}
|
|
88107
|
-
let folderListData = connection.folders.has(
|
|
88222
|
+
let folderListData = connection.folders.has(path26) ? connection.folders.get(path26) : false;
|
|
88108
88223
|
let response;
|
|
88109
88224
|
try {
|
|
88110
|
-
let map = { path:
|
|
88225
|
+
let map = { path: path26 };
|
|
88111
88226
|
if (folderListData) {
|
|
88112
88227
|
["delimiter", "specialUse", "subscribed", "listed"].forEach((key) => {
|
|
88113
88228
|
if (folderListData[key]) {
|
|
@@ -88126,7 +88241,7 @@ var require_select = __commonJS({
|
|
|
88126
88241
|
]);
|
|
88127
88242
|
map.qresync = true;
|
|
88128
88243
|
}
|
|
88129
|
-
let encodedPath = encodePath(connection,
|
|
88244
|
+
let encodedPath = encodePath(connection, path26);
|
|
88130
88245
|
let selectCommand = {
|
|
88131
88246
|
command: !options.readOnly ? "SELECT" : "EXAMINE",
|
|
88132
88247
|
/* c8 ignore next */
|
|
@@ -88186,12 +88301,12 @@ var require_select = __commonJS({
|
|
|
88186
88301
|
// since the client's last known state. Only received when QRESYNC was requested.
|
|
88187
88302
|
// A dummy mailbox object is passed because the mailbox isn't officially open yet.
|
|
88188
88303
|
VANISHED: async (untagged) => {
|
|
88189
|
-
await connection.untaggedVanished(untagged, { path:
|
|
88304
|
+
await connection.untaggedVanished(untagged, { path: path26, uidNext: false, uidValidity: false });
|
|
88190
88305
|
},
|
|
88191
88306
|
// Untagged FETCH during SELECT/EXAMINE: only occurs with QRESYNC, delivering
|
|
88192
88307
|
// updated flags for messages that changed since the client's last modseq.
|
|
88193
88308
|
FETCH: async (untagged) => {
|
|
88194
|
-
await connection.untaggedFetch(untagged, { path:
|
|
88309
|
+
await connection.untaggedFetch(untagged, { path: path26, uidNext: false, uidValidity: false });
|
|
88195
88310
|
}
|
|
88196
88311
|
}
|
|
88197
88312
|
});
|
|
@@ -88205,13 +88320,13 @@ var require_select = __commonJS({
|
|
|
88205
88320
|
}
|
|
88206
88321
|
let currentMailbox = connection.mailbox;
|
|
88207
88322
|
connection.mailbox = false;
|
|
88208
|
-
if (currentMailbox && currentMailbox.path !==
|
|
88323
|
+
if (currentMailbox && currentMailbox.path !== path26) {
|
|
88209
88324
|
connection.emit("mailboxClose", currentMailbox);
|
|
88210
88325
|
}
|
|
88211
88326
|
connection.mailbox = map;
|
|
88212
88327
|
connection.currentSelectCommand = selectCommand;
|
|
88213
88328
|
connection.state = connection.states.SELECTED;
|
|
88214
|
-
if (!currentMailbox || currentMailbox.path !==
|
|
88329
|
+
if (!currentMailbox || currentMailbox.path !== path26) {
|
|
88215
88330
|
connection.emit("mailboxOpen", connection.mailbox);
|
|
88216
88331
|
}
|
|
88217
88332
|
response.next();
|
|
@@ -88426,17 +88541,17 @@ var require_create = __commonJS({
|
|
|
88426
88541
|
"node_modules/imapflow/lib/commands/create.js"(exports, module) {
|
|
88427
88542
|
"use strict";
|
|
88428
88543
|
var { encodePath, normalizePath, getStatusCode, enhanceCommandError } = require_tools2();
|
|
88429
|
-
module.exports = async (connection,
|
|
88544
|
+
module.exports = async (connection, path26) => {
|
|
88430
88545
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88431
88546
|
return;
|
|
88432
88547
|
}
|
|
88433
|
-
|
|
88548
|
+
path26 = normalizePath(connection, path26);
|
|
88434
88549
|
let response;
|
|
88435
88550
|
try {
|
|
88436
88551
|
let map = {
|
|
88437
|
-
path:
|
|
88552
|
+
path: path26
|
|
88438
88553
|
};
|
|
88439
|
-
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection,
|
|
88554
|
+
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88440
88555
|
let section = response.response.attributes && response.response.attributes[0] && response.response.attributes[0].section && response.response.attributes[0].section.length ? response.response.attributes[0].section : false;
|
|
88441
88556
|
if (section) {
|
|
88442
88557
|
let key;
|
|
@@ -88462,13 +88577,13 @@ var require_create = __commonJS({
|
|
|
88462
88577
|
}
|
|
88463
88578
|
map.created = true;
|
|
88464
88579
|
response.next();
|
|
88465
|
-
await connection.run("SUBSCRIBE",
|
|
88580
|
+
await connection.run("SUBSCRIBE", path26);
|
|
88466
88581
|
return map;
|
|
88467
88582
|
} catch (err) {
|
|
88468
88583
|
let errorCode = getStatusCode(err.response);
|
|
88469
88584
|
if (errorCode === "ALREADYEXISTS") {
|
|
88470
88585
|
return {
|
|
88471
|
-
path:
|
|
88586
|
+
path: path26,
|
|
88472
88587
|
created: false
|
|
88473
88588
|
};
|
|
88474
88589
|
}
|
|
@@ -88485,20 +88600,20 @@ var require_delete = __commonJS({
|
|
|
88485
88600
|
"node_modules/imapflow/lib/commands/delete.js"(exports, module) {
|
|
88486
88601
|
"use strict";
|
|
88487
88602
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88488
|
-
module.exports = async (connection,
|
|
88603
|
+
module.exports = async (connection, path26) => {
|
|
88489
88604
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88490
88605
|
return;
|
|
88491
88606
|
}
|
|
88492
|
-
|
|
88493
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88607
|
+
path26 = normalizePath(connection, path26);
|
|
88608
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path26) {
|
|
88494
88609
|
await connection.run("CLOSE");
|
|
88495
88610
|
}
|
|
88496
88611
|
let response;
|
|
88497
88612
|
try {
|
|
88498
88613
|
let map = {
|
|
88499
|
-
path:
|
|
88614
|
+
path: path26
|
|
88500
88615
|
};
|
|
88501
|
-
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection,
|
|
88616
|
+
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88502
88617
|
response.next();
|
|
88503
88618
|
return map;
|
|
88504
88619
|
} catch (err) {
|
|
@@ -88515,23 +88630,23 @@ var require_rename = __commonJS({
|
|
|
88515
88630
|
"node_modules/imapflow/lib/commands/rename.js"(exports, module) {
|
|
88516
88631
|
"use strict";
|
|
88517
88632
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88518
|
-
module.exports = async (connection,
|
|
88633
|
+
module.exports = async (connection, path26, newPath) => {
|
|
88519
88634
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88520
88635
|
return;
|
|
88521
88636
|
}
|
|
88522
|
-
|
|
88637
|
+
path26 = normalizePath(connection, path26);
|
|
88523
88638
|
newPath = normalizePath(connection, newPath);
|
|
88524
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88639
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path26) {
|
|
88525
88640
|
await connection.run("CLOSE");
|
|
88526
88641
|
}
|
|
88527
88642
|
let response;
|
|
88528
88643
|
try {
|
|
88529
88644
|
let map = {
|
|
88530
|
-
path:
|
|
88645
|
+
path: path26,
|
|
88531
88646
|
newPath
|
|
88532
88647
|
};
|
|
88533
88648
|
response = await connection.exec("RENAME", [
|
|
88534
|
-
{ type: "ATOM", value: encodePath(connection,
|
|
88649
|
+
{ type: "ATOM", value: encodePath(connection, path26) },
|
|
88535
88650
|
{ type: "ATOM", value: encodePath(connection, newPath) }
|
|
88536
88651
|
]);
|
|
88537
88652
|
response.next();
|
|
@@ -88578,14 +88693,14 @@ var require_subscribe = __commonJS({
|
|
|
88578
88693
|
"node_modules/imapflow/lib/commands/subscribe.js"(exports, module) {
|
|
88579
88694
|
"use strict";
|
|
88580
88695
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88581
|
-
module.exports = async (connection,
|
|
88696
|
+
module.exports = async (connection, path26) => {
|
|
88582
88697
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88583
88698
|
return;
|
|
88584
88699
|
}
|
|
88585
|
-
|
|
88700
|
+
path26 = normalizePath(connection, path26);
|
|
88586
88701
|
let response;
|
|
88587
88702
|
try {
|
|
88588
|
-
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88703
|
+
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88589
88704
|
response.next();
|
|
88590
88705
|
return true;
|
|
88591
88706
|
} catch (err) {
|
|
@@ -88602,14 +88717,14 @@ var require_unsubscribe = __commonJS({
|
|
|
88602
88717
|
"node_modules/imapflow/lib/commands/unsubscribe.js"(exports, module) {
|
|
88603
88718
|
"use strict";
|
|
88604
88719
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88605
|
-
module.exports = async (connection,
|
|
88720
|
+
module.exports = async (connection, path26) => {
|
|
88606
88721
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88607
88722
|
return;
|
|
88608
88723
|
}
|
|
88609
|
-
|
|
88724
|
+
path26 = normalizePath(connection, path26);
|
|
88610
88725
|
let response;
|
|
88611
88726
|
try {
|
|
88612
|
-
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88727
|
+
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88613
88728
|
response.next();
|
|
88614
88729
|
return true;
|
|
88615
88730
|
} catch (err) {
|
|
@@ -89415,11 +89530,11 @@ var require_status = __commonJS({
|
|
|
89415
89530
|
var { encodePath, normalizePath, buildStatusQueryAttributes, isRev2Active } = require_tools2();
|
|
89416
89531
|
var { parseStatusList } = require_status_fields();
|
|
89417
89532
|
var MAILBOX_UPDATERS = {
|
|
89418
|
-
messages: (value, connection,
|
|
89533
|
+
messages: (value, connection, path26) => {
|
|
89419
89534
|
let prevCount = connection.mailbox.exists;
|
|
89420
89535
|
if (prevCount !== value) {
|
|
89421
89536
|
connection.mailbox.exists = value;
|
|
89422
|
-
connection.emit("exists", { path:
|
|
89537
|
+
connection.emit("exists", { path: path26, count: value, prevCount });
|
|
89423
89538
|
}
|
|
89424
89539
|
},
|
|
89425
89540
|
uidNext: (value, connection) => {
|
|
@@ -89429,28 +89544,28 @@ var require_status = __commonJS({
|
|
|
89429
89544
|
connection.mailbox.highestModseq = value;
|
|
89430
89545
|
}
|
|
89431
89546
|
};
|
|
89432
|
-
module.exports = async (connection,
|
|
89433
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89547
|
+
module.exports = async (connection, path26, query) => {
|
|
89548
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path26) {
|
|
89434
89549
|
return false;
|
|
89435
89550
|
}
|
|
89436
|
-
|
|
89437
|
-
let encodedPath = encodePath(connection,
|
|
89551
|
+
path26 = normalizePath(connection, path26);
|
|
89552
|
+
let encodedPath = encodePath(connection, path26);
|
|
89438
89553
|
let attributes = [{ type: encodedPath.indexOf("&") >= 0 ? "STRING" : "ATOM", value: encodedPath }];
|
|
89439
89554
|
let queryAttributes = buildStatusQueryAttributes(connection, query);
|
|
89440
89555
|
let syntheticRecent = query && query.recent && isRev2Active(connection);
|
|
89441
89556
|
if (!queryAttributes.length) {
|
|
89442
|
-
return syntheticRecent ? { path:
|
|
89557
|
+
return syntheticRecent ? { path: path26, recent: 0 } : false;
|
|
89443
89558
|
}
|
|
89444
89559
|
attributes.push(queryAttributes);
|
|
89445
89560
|
let response;
|
|
89446
89561
|
try {
|
|
89447
|
-
let map = { path:
|
|
89562
|
+
let map = { path: path26 };
|
|
89448
89563
|
response = await connection.exec("STATUS", attributes, {
|
|
89449
89564
|
untagged: {
|
|
89450
89565
|
// STATUS response: * STATUS <mailbox> (<key> <value> <key> <value> ...)
|
|
89451
89566
|
// Parsed as alternating key-value pairs (i % 2 pattern).
|
|
89452
89567
|
STATUS: async (untagged) => {
|
|
89453
|
-
let updateCurrent = connection.state === connection.states.SELECTED &&
|
|
89568
|
+
let updateCurrent = connection.state === connection.states.SELECTED && path26 === connection.mailbox.path;
|
|
89454
89569
|
let list = untagged.attributes && Array.isArray(untagged.attributes[1]) ? untagged.attributes[1] : false;
|
|
89455
89570
|
if (!list) {
|
|
89456
89571
|
return;
|
|
@@ -89458,7 +89573,7 @@ var require_status = __commonJS({
|
|
|
89458
89573
|
parseStatusList(list, (key, value) => {
|
|
89459
89574
|
map[key] = value;
|
|
89460
89575
|
if (updateCurrent && MAILBOX_UPDATERS[key]) {
|
|
89461
|
-
MAILBOX_UPDATERS[key](value, connection,
|
|
89576
|
+
MAILBOX_UPDATERS[key](value, connection, path26);
|
|
89462
89577
|
}
|
|
89463
89578
|
});
|
|
89464
89579
|
}
|
|
@@ -89471,9 +89586,9 @@ var require_status = __commonJS({
|
|
|
89471
89586
|
return map;
|
|
89472
89587
|
} catch (err) {
|
|
89473
89588
|
if (err.responseStatus === "NO") {
|
|
89474
|
-
let folders = await connection.run("LIST", "",
|
|
89589
|
+
let folders = await connection.run("LIST", "", path26, { listOnly: true });
|
|
89475
89590
|
if (folders && !folders.length) {
|
|
89476
|
-
let error2 = new Error(`Mailbox doesn't exist: ${
|
|
89591
|
+
let error2 = new Error(`Mailbox doesn't exist: ${path26}`);
|
|
89477
89592
|
error2.code = "NotFound";
|
|
89478
89593
|
error2.response = err;
|
|
89479
89594
|
throw error2;
|
|
@@ -89620,15 +89735,15 @@ var require_quota = __commonJS({
|
|
|
89620
89735
|
"node_modules/imapflow/lib/commands/quota.js"(exports, module) {
|
|
89621
89736
|
"use strict";
|
|
89622
89737
|
var { encodePath, normalizePath, enhanceCommandError, parseUintValue, isUnsafeKey } = require_tools2();
|
|
89623
|
-
module.exports = async (connection,
|
|
89624
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89738
|
+
module.exports = async (connection, path26) => {
|
|
89739
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path26) {
|
|
89625
89740
|
return;
|
|
89626
89741
|
}
|
|
89627
89742
|
if (!connection.capabilities.has("QUOTA")) {
|
|
89628
89743
|
return false;
|
|
89629
89744
|
}
|
|
89630
|
-
|
|
89631
|
-
let map = { path:
|
|
89745
|
+
path26 = normalizePath(connection, path26);
|
|
89746
|
+
let map = { path: path26 };
|
|
89632
89747
|
let processQuotaResponse = (untagged) => {
|
|
89633
89748
|
let attributes = untagged.attributes && untagged.attributes[1];
|
|
89634
89749
|
if (!attributes || !attributes.length) {
|
|
@@ -89668,7 +89783,7 @@ var require_quota = __commonJS({
|
|
|
89668
89783
|
let quotaFound = false;
|
|
89669
89784
|
let response;
|
|
89670
89785
|
try {
|
|
89671
|
-
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection,
|
|
89786
|
+
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path26) }], {
|
|
89672
89787
|
untagged: {
|
|
89673
89788
|
// QUOTAROOT response tells us which quota root applies to this mailbox.
|
|
89674
89789
|
// A mailbox may have zero or one quota root.
|
|
@@ -89811,15 +89926,15 @@ var require_idle = __commonJS({
|
|
|
89811
89926
|
}
|
|
89812
89927
|
}
|
|
89813
89928
|
async function pollOnce2(connection, session) {
|
|
89814
|
-
let
|
|
89929
|
+
let path26 = connection.mailbox && connection.mailbox.path;
|
|
89815
89930
|
switch (connection.missingIdleCommand) {
|
|
89816
89931
|
case "SELECT":
|
|
89817
89932
|
connection.log.debug({ src: "c", msg: `Running SELECT to detect changes in folder`, cid: connection.id });
|
|
89818
|
-
await connection.runInternal("SELECT",
|
|
89933
|
+
await connection.runInternal("SELECT", path26, { readOnly: session.selectCommand.command === "EXAMINE" });
|
|
89819
89934
|
break;
|
|
89820
89935
|
case "STATUS": {
|
|
89821
89936
|
connection.log.debug({ src: "c", msg: `Running STATUS to detect changes in folder`, cid: connection.id });
|
|
89822
|
-
let status = await connection.runInternal("STATUS",
|
|
89937
|
+
let status = await connection.runInternal("STATUS", path26, {
|
|
89823
89938
|
messages: true,
|
|
89824
89939
|
uidNext: true,
|
|
89825
89940
|
uidValidity: true,
|
|
@@ -91506,12 +91621,12 @@ var require_imap_flow = __commonJS({
|
|
|
91506
91621
|
this.emit("flags", updateEvent);
|
|
91507
91622
|
}
|
|
91508
91623
|
}
|
|
91509
|
-
async ensureSelectedMailbox(
|
|
91510
|
-
if (!
|
|
91624
|
+
async ensureSelectedMailbox(path26) {
|
|
91625
|
+
if (!path26) {
|
|
91511
91626
|
return false;
|
|
91512
91627
|
}
|
|
91513
|
-
if (!this.mailbox || !comparePaths(this, this.mailbox.path,
|
|
91514
|
-
return await this.mailboxOpen(
|
|
91628
|
+
if (!this.mailbox || !comparePaths(this, this.mailbox.path, path26)) {
|
|
91629
|
+
return await this.mailboxOpen(path26);
|
|
91515
91630
|
}
|
|
91516
91631
|
return true;
|
|
91517
91632
|
}
|
|
@@ -91926,9 +92041,9 @@ var require_imap_flow = __commonJS({
|
|
|
91926
92041
|
* let quota = await client.getQuota();
|
|
91927
92042
|
* console.log(quota.storage.used, quota.storage.limit)
|
|
91928
92043
|
*/
|
|
91929
|
-
async getQuota(
|
|
91930
|
-
|
|
91931
|
-
return await this.run("QUOTA",
|
|
92044
|
+
async getQuota(path26) {
|
|
92045
|
+
path26 = path26 || "INBOX";
|
|
92046
|
+
return await this.run("QUOTA", path26);
|
|
91932
92047
|
}
|
|
91933
92048
|
/**
|
|
91934
92049
|
* @typedef {Object} ListResponse
|
|
@@ -92038,8 +92153,8 @@ var require_imap_flow = __commonJS({
|
|
|
92038
92153
|
* console.log(info.path);
|
|
92039
92154
|
* // "INBOX.parent.child" // assumes "INBOX." as namespace prefix and "." as delimiter
|
|
92040
92155
|
*/
|
|
92041
|
-
async mailboxCreate(
|
|
92042
|
-
return await this.run("CREATE",
|
|
92156
|
+
async mailboxCreate(path26) {
|
|
92157
|
+
return await this.run("CREATE", path26);
|
|
92043
92158
|
}
|
|
92044
92159
|
/**
|
|
92045
92160
|
* @typedef {Object} MailboxRenameResponse
|
|
@@ -92060,8 +92175,8 @@ var require_imap_flow = __commonJS({
|
|
|
92060
92175
|
* console.log(info.newPath);
|
|
92061
92176
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
92062
92177
|
*/
|
|
92063
|
-
async mailboxRename(
|
|
92064
|
-
return await this.run("RENAME",
|
|
92178
|
+
async mailboxRename(path26, newPath) {
|
|
92179
|
+
return await this.run("RENAME", path26, newPath);
|
|
92065
92180
|
}
|
|
92066
92181
|
/**
|
|
92067
92182
|
* @typedef {Object} MailboxDeleteResponse
|
|
@@ -92080,8 +92195,8 @@ var require_imap_flow = __commonJS({
|
|
|
92080
92195
|
* console.log(info.path);
|
|
92081
92196
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
92082
92197
|
*/
|
|
92083
|
-
async mailboxDelete(
|
|
92084
|
-
return await this.run("DELETE",
|
|
92198
|
+
async mailboxDelete(path26) {
|
|
92199
|
+
return await this.run("DELETE", path26);
|
|
92085
92200
|
}
|
|
92086
92201
|
/**
|
|
92087
92202
|
* Subscribes to a mailbox
|
|
@@ -92092,8 +92207,8 @@ var require_imap_flow = __commonJS({
|
|
|
92092
92207
|
* @example
|
|
92093
92208
|
* await client.mailboxSubscribe('Important stuff ❗️');
|
|
92094
92209
|
*/
|
|
92095
|
-
async mailboxSubscribe(
|
|
92096
|
-
return await this.run("SUBSCRIBE",
|
|
92210
|
+
async mailboxSubscribe(path26) {
|
|
92211
|
+
return await this.run("SUBSCRIBE", path26);
|
|
92097
92212
|
}
|
|
92098
92213
|
/**
|
|
92099
92214
|
* Unsubscribes from a mailbox
|
|
@@ -92104,8 +92219,8 @@ var require_imap_flow = __commonJS({
|
|
|
92104
92219
|
* @example
|
|
92105
92220
|
* await client.mailboxUnsubscribe('Important stuff ❗️');
|
|
92106
92221
|
*/
|
|
92107
|
-
async mailboxUnsubscribe(
|
|
92108
|
-
return await this.run("UNSUBSCRIBE",
|
|
92222
|
+
async mailboxUnsubscribe(path26) {
|
|
92223
|
+
return await this.run("UNSUBSCRIBE", path26);
|
|
92109
92224
|
}
|
|
92110
92225
|
/**
|
|
92111
92226
|
* Opens a mailbox to access messages. You can perform message operations only against an opened mailbox.
|
|
@@ -92123,8 +92238,8 @@ var require_imap_flow = __commonJS({
|
|
|
92123
92238
|
* console.log(mailbox.exists);
|
|
92124
92239
|
* // 125
|
|
92125
92240
|
*/
|
|
92126
|
-
async mailboxOpen(
|
|
92127
|
-
return await this.run("SELECT",
|
|
92241
|
+
async mailboxOpen(path26, options) {
|
|
92242
|
+
return await this.run("SELECT", path26, options);
|
|
92128
92243
|
}
|
|
92129
92244
|
/**
|
|
92130
92245
|
* Closes a previously opened mailbox
|
|
@@ -92171,8 +92286,8 @@ var require_imap_flow = __commonJS({
|
|
|
92171
92286
|
* console.log(status.unseen);
|
|
92172
92287
|
* // 123
|
|
92173
92288
|
*/
|
|
92174
|
-
async status(
|
|
92175
|
-
return await this.run("STATUS",
|
|
92289
|
+
async status(path26, query) {
|
|
92290
|
+
return await this.run("STATUS", path26, query);
|
|
92176
92291
|
}
|
|
92177
92292
|
/**
|
|
92178
92293
|
* Starts listening for new or deleted messages from the currently opened mailbox. Only required if {@link ImapFlow#disableAutoIdle} is set to `true`
|
|
@@ -92426,8 +92541,8 @@ var require_imap_flow = __commonJS({
|
|
|
92426
92541
|
* @example
|
|
92427
92542
|
* await client.append('INBOX', rawMessageBuffer, ['\\Seen'], new Date(2000, 1, 1));
|
|
92428
92543
|
*/
|
|
92429
|
-
async append(
|
|
92430
|
-
return await this.run("APPEND",
|
|
92544
|
+
async append(path26, content, flags, idate) {
|
|
92545
|
+
return await this.run("APPEND", path26, content, flags, idate) || false;
|
|
92431
92546
|
}
|
|
92432
92547
|
/**
|
|
92433
92548
|
* @typedef {Object} CopyResponseObject
|
|
@@ -93271,7 +93386,7 @@ var require_imap_flow = __commonJS({
|
|
|
93271
93386
|
await new Promise((resolve2) => setImmediate(resolve2));
|
|
93272
93387
|
}
|
|
93273
93388
|
const lock = this.locks.shift();
|
|
93274
|
-
const { resolve, reject, path:
|
|
93389
|
+
const { resolve, reject, path: path26, options, lockId } = lock;
|
|
93275
93390
|
if (lock.acquireTimer) {
|
|
93276
93391
|
clearTimeout(lock.acquireTimer);
|
|
93277
93392
|
lock.acquireTimer = null;
|
|
@@ -93287,7 +93402,7 @@ var require_imap_flow = __commonJS({
|
|
|
93287
93402
|
this.log.warn({
|
|
93288
93403
|
msg: "Mailbox lock held for a long time",
|
|
93289
93404
|
lockId: lock.lockId,
|
|
93290
|
-
path:
|
|
93405
|
+
path: path26,
|
|
93291
93406
|
heldFor: Date.now() - lock.heldAt,
|
|
93292
93407
|
/* c8 ignore next */
|
|
93293
93408
|
// the held-lock-warning diagnostic with a description set is a timing-dependent log detail
|
|
@@ -93323,52 +93438,52 @@ var require_imap_flow = __commonJS({
|
|
|
93323
93438
|
}
|
|
93324
93439
|
};
|
|
93325
93440
|
if (!this.usable || !this.socket || this.socket.destroyed) {
|
|
93326
|
-
this.log.trace({ msg: "Failed to acquire mailbox lock", path:
|
|
93441
|
+
this.log.trace({ msg: "Failed to acquire mailbox lock", path: path26, lockId, idling: this.idling });
|
|
93327
93442
|
let error2 = new Error("Connection not available");
|
|
93328
93443
|
error2.code = "NoConnection";
|
|
93329
93444
|
reject(error2);
|
|
93330
93445
|
continue;
|
|
93331
93446
|
}
|
|
93332
|
-
if (this.mailbox && this.mailbox.path ===
|
|
93447
|
+
if (this.mailbox && this.mailbox.path === path26 && !!this.mailbox.readOnly === !!options.readOnly) {
|
|
93333
93448
|
this.log.trace({
|
|
93334
93449
|
msg: "Mailbox lock acquired [existing]",
|
|
93335
|
-
path:
|
|
93450
|
+
path: path26,
|
|
93336
93451
|
lockId,
|
|
93337
93452
|
idling: this.idling,
|
|
93338
93453
|
...options.description && { description: options.description }
|
|
93339
93454
|
});
|
|
93340
93455
|
this.currentLock = lock;
|
|
93341
93456
|
armHeldTimer();
|
|
93342
|
-
resolve({ path:
|
|
93457
|
+
resolve({ path: path26, release });
|
|
93343
93458
|
break;
|
|
93344
93459
|
}
|
|
93345
93460
|
try {
|
|
93346
|
-
await this.mailboxOpen(
|
|
93461
|
+
await this.mailboxOpen(path26, options);
|
|
93347
93462
|
this.log.trace({
|
|
93348
93463
|
msg: "Mailbox lock acquired [selected]",
|
|
93349
|
-
path:
|
|
93464
|
+
path: path26,
|
|
93350
93465
|
lockId,
|
|
93351
93466
|
idling: this.idling,
|
|
93352
93467
|
...options.description && { description: options.description }
|
|
93353
93468
|
});
|
|
93354
93469
|
this.currentLock = lock;
|
|
93355
93470
|
armHeldTimer();
|
|
93356
|
-
resolve({ path:
|
|
93471
|
+
resolve({ path: path26, release });
|
|
93357
93472
|
break;
|
|
93358
93473
|
} catch (err) {
|
|
93359
93474
|
if (err.responseStatus === "NO") {
|
|
93360
93475
|
try {
|
|
93361
|
-
let folders = await this.run("LIST", "",
|
|
93476
|
+
let folders = await this.run("LIST", "", path26, { listOnly: true });
|
|
93362
93477
|
if (!folders || !folders.length) {
|
|
93363
93478
|
err.mailboxMissing = true;
|
|
93364
93479
|
}
|
|
93365
93480
|
} catch (E) {
|
|
93366
|
-
this.log.trace({ msg: "Failed to verify failed mailbox", path:
|
|
93481
|
+
this.log.trace({ msg: "Failed to verify failed mailbox", path: path26, err: E });
|
|
93367
93482
|
}
|
|
93368
93483
|
}
|
|
93369
93484
|
this.log.trace({
|
|
93370
93485
|
msg: "Failed to acquire mailbox lock",
|
|
93371
|
-
path:
|
|
93486
|
+
path: path26,
|
|
93372
93487
|
lockId,
|
|
93373
93488
|
idling: this.idling,
|
|
93374
93489
|
...options.description && { description: options.description },
|
|
@@ -93407,13 +93522,13 @@ var require_imap_flow = __commonJS({
|
|
|
93407
93522
|
* lock.release();
|
|
93408
93523
|
* }
|
|
93409
93524
|
*/
|
|
93410
|
-
getMailboxLock(
|
|
93525
|
+
getMailboxLock(path26, options) {
|
|
93411
93526
|
options = options || {};
|
|
93412
|
-
|
|
93527
|
+
path26 = normalizePath(this, path26);
|
|
93413
93528
|
let lockId = ++this.lockCounter;
|
|
93414
93529
|
this.log.trace({
|
|
93415
93530
|
msg: "Requesting lock",
|
|
93416
|
-
path:
|
|
93531
|
+
path: path26,
|
|
93417
93532
|
lockId,
|
|
93418
93533
|
...options.description && { description: options.description },
|
|
93419
93534
|
activeLock: this.currentLock ? {
|
|
@@ -93422,7 +93537,7 @@ var require_imap_flow = __commonJS({
|
|
|
93422
93537
|
} : null
|
|
93423
93538
|
});
|
|
93424
93539
|
let lockPromise = new Promise((resolve, reject) => {
|
|
93425
|
-
let lockEntry = { resolve, reject, path:
|
|
93540
|
+
let lockEntry = { resolve, reject, path: path26, options, lockId };
|
|
93426
93541
|
this.locks.push(lockEntry);
|
|
93427
93542
|
if (Number(options.acquireTimeout) > 0) {
|
|
93428
93543
|
lockEntry.acquireTimer = setTimeout(() => {
|
|
@@ -93511,16 +93626,16 @@ var require_imap_flow = __commonJS({
|
|
|
93511
93626
|
});
|
|
93512
93627
|
|
|
93513
93628
|
// src/mail/mail-fetcher.ts
|
|
93514
|
-
import
|
|
93515
|
-
import
|
|
93629
|
+
import fs23 from "node:fs/promises";
|
|
93630
|
+
import path24 from "node:path";
|
|
93516
93631
|
async function saveAttachments(attachments, downloadDir) {
|
|
93517
93632
|
if (attachments.length === 0) return [];
|
|
93518
|
-
await
|
|
93633
|
+
await fs23.mkdir(downloadDir, { recursive: true });
|
|
93519
93634
|
const saved = [];
|
|
93520
93635
|
for (const a of attachments) {
|
|
93521
|
-
const name =
|
|
93522
|
-
const savedPath =
|
|
93523
|
-
await
|
|
93636
|
+
const name = path24.basename(a.filename) || "attachment";
|
|
93637
|
+
const savedPath = path24.join(downloadDir, name);
|
|
93638
|
+
await fs23.writeFile(savedPath, a.content);
|
|
93524
93639
|
saved.push({ filename: name, savedPath, size: a.content.length });
|
|
93525
93640
|
}
|
|
93526
93641
|
return saved;
|
|
@@ -93650,8 +93765,8 @@ var init_mail_fetcher = __esm({
|
|
|
93650
93765
|
});
|
|
93651
93766
|
|
|
93652
93767
|
// src/tools/fetch-mail.ts
|
|
93653
|
-
import
|
|
93654
|
-
import
|
|
93768
|
+
import os17 from "node:os";
|
|
93769
|
+
import path25 from "node:path";
|
|
93655
93770
|
function registerFetchMailTool(server, deps = {}) {
|
|
93656
93771
|
const makeFetcher = deps.fetcherFactory ?? ((creds) => new ImapflowMailFetcher(creds));
|
|
93657
93772
|
server.registerTool(
|
|
@@ -93713,7 +93828,7 @@ var init_fetch_mail = __esm({
|
|
|
93713
93828
|
init_mail_fetcher();
|
|
93714
93829
|
init_auth_error();
|
|
93715
93830
|
init_validate();
|
|
93716
|
-
DEFAULT_DOWNLOAD_DIR =
|
|
93831
|
+
DEFAULT_DOWNLOAD_DIR = path25.join(os17.homedir(), ".cogent", "mail-downloads");
|
|
93717
93832
|
}
|
|
93718
93833
|
});
|
|
93719
93834
|
|