@essentialai/cogent-bridge-bundled 3.23.7 → 3.23.9
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 +487 -380
- 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.9") {
|
|
26393
|
+
return "3.23.9";
|
|
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,14 +32134,52 @@ 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";
|
|
32102
32141
|
backoff;
|
|
32103
32142
|
reconnectTimer = null;
|
|
32104
32143
|
pollTimer = null;
|
|
32144
|
+
/**
|
|
32145
|
+
* DELIVERY-PATH EVIDENCE. Before 3.23.9 a poll failure was caught and only logger.warn'd, so the
|
|
32146
|
+
* bridge had no idea whether its FALLBACK delivery path worked — and `healthy` could not be
|
|
32147
|
+
* computed honestly because the data did not exist. Captured evidence that nothing reads is the
|
|
32148
|
+
* defect shape this codebase keeps hitting.
|
|
32149
|
+
*/
|
|
32150
|
+
lastPollOkAt = null;
|
|
32151
|
+
lastPollError = null;
|
|
32152
|
+
lastWsErrorSticky = null;
|
|
32105
32153
|
pingTimer = null;
|
|
32106
32154
|
lastMessageId = null;
|
|
32155
|
+
/**
|
|
32156
|
+
* Advance the poll cursor AND persist it.
|
|
32157
|
+
*
|
|
32158
|
+
* Every assignment must go through here. `lastMessageId` was in-memory only, so a restart sent
|
|
32159
|
+
* no cursor and the relay replayed the whole channel ("If lastMessageId is not provided (first
|
|
32160
|
+
* poll), returns all messages") — re-injecting days-old broadcasts on every restart.
|
|
32161
|
+
*/
|
|
32162
|
+
advanceCursor(id) {
|
|
32163
|
+
if (!id) return;
|
|
32164
|
+
this.lastMessageId = id;
|
|
32165
|
+
savePollCursor(this.opts.sessionId, this.opts.peerId, id);
|
|
32166
|
+
}
|
|
32167
|
+
/**
|
|
32168
|
+
* Seed the cursor from disk when this process has not consumed anything yet.
|
|
32169
|
+
*
|
|
32170
|
+
* Only ever fills a NULL cursor: a live in-memory position is always newer than the stored one,
|
|
32171
|
+
* so it must never be overwritten by a restore.
|
|
32172
|
+
*/
|
|
32173
|
+
restoreCursor() {
|
|
32174
|
+
if (this.lastMessageId) return;
|
|
32175
|
+
const stored = loadPollCursor(this.opts.sessionId, this.opts.peerId);
|
|
32176
|
+
if (stored) {
|
|
32177
|
+
this.lastMessageId = stored;
|
|
32178
|
+
logger.info(
|
|
32179
|
+
`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.`
|
|
32180
|
+
);
|
|
32181
|
+
}
|
|
32182
|
+
}
|
|
32107
32183
|
lastWsError = null;
|
|
32108
32184
|
connectionGeneration = 0;
|
|
32109
32185
|
opts;
|
|
@@ -32126,6 +32202,7 @@ var init_ws_client = __esm({
|
|
|
32126
32202
|
* Guards against empty peerId -- call setPeerId() first.
|
|
32127
32203
|
*/
|
|
32128
32204
|
connect() {
|
|
32205
|
+
this.restoreCursor();
|
|
32129
32206
|
if (!this.opts.peerId) {
|
|
32130
32207
|
logger.warn(
|
|
32131
32208
|
"CloudWsClient: Cannot connect WebSocket without peerId. Call setPeerId() first."
|
|
@@ -32151,6 +32228,7 @@ var init_ws_client = __esm({
|
|
|
32151
32228
|
this.ws = ws;
|
|
32152
32229
|
ws.on("open", () => {
|
|
32153
32230
|
if (generation !== this.connectionGeneration || this.ws !== ws) return;
|
|
32231
|
+
this.lastWsErrorSticky = null;
|
|
32154
32232
|
this.setState("connected");
|
|
32155
32233
|
this.backoff.reset();
|
|
32156
32234
|
this.stopPolling();
|
|
@@ -32207,6 +32285,7 @@ var init_ws_client = __esm({
|
|
|
32207
32285
|
ws.on("error", (err) => {
|
|
32208
32286
|
if (generation !== this.connectionGeneration || this.ws !== ws) return;
|
|
32209
32287
|
this.lastWsError = err.message;
|
|
32288
|
+
this.lastWsErrorSticky = err.message;
|
|
32210
32289
|
logger.error(`CloudWsClient: WebSocket error: ${err.message}`);
|
|
32211
32290
|
});
|
|
32212
32291
|
}
|
|
@@ -32270,6 +32349,18 @@ var init_ws_client = __esm({
|
|
|
32270
32349
|
* ISO string. Survives reconnects, same as `getLastFrameAt()`.
|
|
32271
32350
|
* Audit L2.
|
|
32272
32351
|
*/
|
|
32352
|
+
/**
|
|
32353
|
+
* What this bridge's DELIVERY situation actually is — the input `healthy` needs in order to
|
|
32354
|
+
* describe THIS BRIDGE rather than the relay's uptime.
|
|
32355
|
+
*/
|
|
32356
|
+
getDeliveryDiagnostics() {
|
|
32357
|
+
return {
|
|
32358
|
+
pollActive: this.pollTimer !== null,
|
|
32359
|
+
lastPollOkAt: this.lastPollOkAt,
|
|
32360
|
+
lastPollError: this.lastPollError,
|
|
32361
|
+
lastWsError: this.lastWsErrorSticky
|
|
32362
|
+
};
|
|
32363
|
+
}
|
|
32273
32364
|
getLastFrameAtMs() {
|
|
32274
32365
|
return this.lastFrameAt;
|
|
32275
32366
|
}
|
|
@@ -32277,7 +32368,7 @@ var init_ws_client = __esm({
|
|
|
32277
32368
|
* Update the last seen message ID (e.g., from HttpBackend operations).
|
|
32278
32369
|
*/
|
|
32279
32370
|
updateLastMessageId(id) {
|
|
32280
|
-
this.
|
|
32371
|
+
this.advanceCursor(id);
|
|
32281
32372
|
}
|
|
32282
32373
|
/**
|
|
32283
32374
|
* Update the auth token for reconnection.
|
|
@@ -32355,13 +32446,13 @@ var init_ws_client = __esm({
|
|
|
32355
32446
|
switch (frame.type) {
|
|
32356
32447
|
case "message":
|
|
32357
32448
|
this.opts.onMessage(frame.payload);
|
|
32358
|
-
this.
|
|
32449
|
+
this.advanceCursor(frame.payload.id);
|
|
32359
32450
|
break;
|
|
32360
32451
|
case "queued_messages": {
|
|
32361
32452
|
const msgs = frame.payload.messages;
|
|
32362
32453
|
this.opts.onMessages(msgs);
|
|
32363
32454
|
if (msgs.length > 0) {
|
|
32364
|
-
this.
|
|
32455
|
+
this.advanceCursor(msgs[msgs.length - 1].id);
|
|
32365
32456
|
}
|
|
32366
32457
|
break;
|
|
32367
32458
|
}
|
|
@@ -32391,24 +32482,26 @@ var init_ws_client = __esm({
|
|
|
32391
32482
|
}
|
|
32392
32483
|
startPolling() {
|
|
32393
32484
|
if (this.pollTimer) return;
|
|
32485
|
+
this.restoreCursor();
|
|
32394
32486
|
const poll = async () => {
|
|
32395
32487
|
try {
|
|
32396
|
-
const
|
|
32488
|
+
const path26 = `/api/sessions/${this.opts.sessionId}/poll`;
|
|
32397
32489
|
const query = {
|
|
32398
32490
|
peerId: this.opts.peerId
|
|
32399
32491
|
};
|
|
32400
32492
|
if (this.lastMessageId) {
|
|
32401
32493
|
query.lastMessageId = this.lastMessageId;
|
|
32402
32494
|
}
|
|
32403
|
-
const result = await this.opts.http.get(
|
|
32495
|
+
const result = await this.opts.http.get(path26, query);
|
|
32404
32496
|
if (result.messages && result.messages.length > 0) {
|
|
32405
32497
|
this.opts.onMessages(result.messages);
|
|
32406
|
-
this.
|
|
32498
|
+
this.advanceCursor(result.messages[result.messages.length - 1].id);
|
|
32407
32499
|
}
|
|
32500
|
+
this.lastPollOkAt = Date.now();
|
|
32501
|
+
this.lastPollError = null;
|
|
32408
32502
|
} catch (err) {
|
|
32409
|
-
|
|
32410
|
-
|
|
32411
|
-
);
|
|
32503
|
+
this.lastPollError = err instanceof Error ? err.message : String(err);
|
|
32504
|
+
logger.warn(`CloudWsClient: Poll failed: ${this.lastPollError}`);
|
|
32412
32505
|
}
|
|
32413
32506
|
};
|
|
32414
32507
|
void poll();
|
|
@@ -32457,9 +32550,9 @@ var init_cloud = __esm({
|
|
|
32457
32550
|
|
|
32458
32551
|
// src/services/codex-cli.ts
|
|
32459
32552
|
import { spawn as spawn2 } from "node:child_process";
|
|
32460
|
-
import
|
|
32461
|
-
import
|
|
32462
|
-
import
|
|
32553
|
+
import fs12 from "node:fs/promises";
|
|
32554
|
+
import os9 from "node:os";
|
|
32555
|
+
import path13 from "node:path";
|
|
32463
32556
|
import { randomUUID } from "node:crypto";
|
|
32464
32557
|
import { createReadStream } from "node:fs";
|
|
32465
32558
|
import { createInterface as createInterface2 } from "node:readline";
|
|
@@ -32487,7 +32580,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32487
32580
|
const config2 = getConfig();
|
|
32488
32581
|
const effectiveTimeout = timeoutMs ?? config2.COGENT_TIMEOUT_MS;
|
|
32489
32582
|
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 =
|
|
32583
|
+
const lastMsgFile = path13.join(os9.tmpdir(), `cogent-codex-${randomUUID()}.txt`);
|
|
32491
32584
|
const args = [
|
|
32492
32585
|
"exec",
|
|
32493
32586
|
"resume",
|
|
@@ -32515,7 +32608,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32515
32608
|
resolve(result);
|
|
32516
32609
|
}
|
|
32517
32610
|
};
|
|
32518
|
-
const cleanupFile = () =>
|
|
32611
|
+
const cleanupFile = () => fs12.rm(lastMsgFile, { force: true }).catch(() => {
|
|
32519
32612
|
});
|
|
32520
32613
|
const timer = setTimeout(async () => {
|
|
32521
32614
|
killed = true;
|
|
@@ -32566,7 +32659,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32566
32659
|
}
|
|
32567
32660
|
let fileMessage = "";
|
|
32568
32661
|
try {
|
|
32569
|
-
fileMessage = await
|
|
32662
|
+
fileMessage = await fs12.readFile(lastMsgFile, "utf8");
|
|
32570
32663
|
} catch {
|
|
32571
32664
|
fileMessage = "";
|
|
32572
32665
|
}
|
|
@@ -32587,12 +32680,12 @@ async function listRolloutFiles(root) {
|
|
|
32587
32680
|
async function walk(dir) {
|
|
32588
32681
|
let entries;
|
|
32589
32682
|
try {
|
|
32590
|
-
entries = await
|
|
32683
|
+
entries = await fs12.readdir(dir, { withFileTypes: true });
|
|
32591
32684
|
} catch {
|
|
32592
32685
|
return;
|
|
32593
32686
|
}
|
|
32594
32687
|
for (const e of entries) {
|
|
32595
|
-
const full =
|
|
32688
|
+
const full = path13.join(dir, e.name);
|
|
32596
32689
|
if (e.isDirectory()) await walk(full);
|
|
32597
32690
|
else if (e.isFile() && e.name.endsWith(".jsonl")) out.push(full);
|
|
32598
32691
|
}
|
|
@@ -32624,19 +32717,19 @@ async function readSessionMeta(file) {
|
|
|
32624
32717
|
}
|
|
32625
32718
|
}
|
|
32626
32719
|
function codexSessionsRoot() {
|
|
32627
|
-
return
|
|
32720
|
+
return path13.join(codexHomeDir(), "sessions");
|
|
32628
32721
|
}
|
|
32629
32722
|
async function cwdCanonicals(cwd) {
|
|
32630
|
-
const resolved =
|
|
32723
|
+
const resolved = path13.resolve(cwd);
|
|
32631
32724
|
const forms = /* @__PURE__ */ new Set([resolved]);
|
|
32632
32725
|
try {
|
|
32633
|
-
forms.add(await
|
|
32726
|
+
forms.add(await fs12.realpath(resolved));
|
|
32634
32727
|
} catch {
|
|
32635
32728
|
}
|
|
32636
32729
|
return forms;
|
|
32637
32730
|
}
|
|
32638
32731
|
function metaCwdMatches(metaCwd, forms) {
|
|
32639
|
-
return forms.has(
|
|
32732
|
+
return forms.has(path13.resolve(metaCwd));
|
|
32640
32733
|
}
|
|
32641
32734
|
async function detectCurrentCodexSession(cwd) {
|
|
32642
32735
|
try {
|
|
@@ -32644,7 +32737,7 @@ async function detectCurrentCodexSession(cwd) {
|
|
|
32644
32737
|
const files = await listRolloutFiles(codexSessionsRoot());
|
|
32645
32738
|
const withStats = await Promise.all(
|
|
32646
32739
|
files.map(async (f) => {
|
|
32647
|
-
const stat = await
|
|
32740
|
+
const stat = await fs12.stat(f);
|
|
32648
32741
|
return { file: f, mtimeMs: stat.mtimeMs };
|
|
32649
32742
|
})
|
|
32650
32743
|
);
|
|
@@ -32663,7 +32756,7 @@ async function listCodexCandidates(cwd) {
|
|
|
32663
32756
|
const forms = await cwdCanonicals(cwd);
|
|
32664
32757
|
const files = await listRolloutFiles(codexSessionsRoot());
|
|
32665
32758
|
const withStats = await Promise.all(
|
|
32666
|
-
files.map(async (f) => ({ file: f, mtimeMs: (await
|
|
32759
|
+
files.map(async (f) => ({ file: f, mtimeMs: (await fs12.stat(f)).mtimeMs }))
|
|
32667
32760
|
);
|
|
32668
32761
|
const bySession = /* @__PURE__ */ new Map();
|
|
32669
32762
|
for (const { file, mtimeMs } of withStats) {
|
|
@@ -32703,12 +32796,12 @@ var init_codex_cli = __esm({
|
|
|
32703
32796
|
});
|
|
32704
32797
|
|
|
32705
32798
|
// src/services/codex-app-server.ts
|
|
32706
|
-
import
|
|
32799
|
+
import path14 from "node:path";
|
|
32707
32800
|
import { statSync } from "node:fs";
|
|
32708
|
-
import
|
|
32801
|
+
import fs13 from "node:fs/promises";
|
|
32709
32802
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
32710
32803
|
function appServerSocketPath(codexHome = codexHomeDir()) {
|
|
32711
|
-
return
|
|
32804
|
+
return path14.join(codexHome, "app-server-control", "app-server-control.sock");
|
|
32712
32805
|
}
|
|
32713
32806
|
function appServerDaemonRunning(codexHome = codexHomeDir()) {
|
|
32714
32807
|
try {
|
|
@@ -32956,7 +33049,7 @@ var init_codex_app_server = __esm({
|
|
|
32956
33049
|
});
|
|
32957
33050
|
defaultSocketExists = async (p) => {
|
|
32958
33051
|
try {
|
|
32959
|
-
await
|
|
33052
|
+
await fs13.stat(p);
|
|
32960
33053
|
return true;
|
|
32961
33054
|
} catch {
|
|
32962
33055
|
return false;
|
|
@@ -33122,14 +33215,14 @@ var init_exec_remote = __esm({
|
|
|
33122
33215
|
// src/services/wake-log.ts
|
|
33123
33216
|
import { execFileSync } from "node:child_process";
|
|
33124
33217
|
import crypto4 from "node:crypto";
|
|
33125
|
-
import
|
|
33126
|
-
import
|
|
33127
|
-
import
|
|
33218
|
+
import fs14 from "node:fs";
|
|
33219
|
+
import os10 from "node:os";
|
|
33220
|
+
import path15 from "node:path";
|
|
33128
33221
|
function hashCwd2(cwd) {
|
|
33129
|
-
return crypto4.createHash("sha256").update(
|
|
33222
|
+
return crypto4.createHash("sha256").update(path15.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33130
33223
|
}
|
|
33131
33224
|
function wakeLogPath(cwd) {
|
|
33132
|
-
return
|
|
33225
|
+
return path15.join(os10.homedir(), ".cogent", "wake-log", `${hashCwd2(cwd)}.jsonl`);
|
|
33133
33226
|
}
|
|
33134
33227
|
function git(cwd, args) {
|
|
33135
33228
|
return execFileSync("git", ["-C", cwd, ...args], {
|
|
@@ -33173,13 +33266,13 @@ function preview(message) {
|
|
|
33173
33266
|
function appendWakeRecord(record2, cwd) {
|
|
33174
33267
|
const target = wakeLogPath(cwd);
|
|
33175
33268
|
try {
|
|
33176
|
-
|
|
33269
|
+
fs14.mkdirSync(path15.dirname(target), { recursive: true });
|
|
33177
33270
|
const row = {
|
|
33178
33271
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33179
33272
|
...record2,
|
|
33180
33273
|
messagePreview: preview(record2.messagePreview ?? "")
|
|
33181
33274
|
};
|
|
33182
|
-
|
|
33275
|
+
fs14.appendFileSync(target, `${JSON.stringify(row)}
|
|
33183
33276
|
`);
|
|
33184
33277
|
pruneIfNeeded(target);
|
|
33185
33278
|
} catch {
|
|
@@ -33187,20 +33280,20 @@ function appendWakeRecord(record2, cwd) {
|
|
|
33187
33280
|
}
|
|
33188
33281
|
function pruneIfNeeded(target) {
|
|
33189
33282
|
try {
|
|
33190
|
-
const lines =
|
|
33283
|
+
const lines = fs14.readFileSync(target, "utf-8").split("\n").filter((l) => l.length > 0);
|
|
33191
33284
|
if (lines.length <= WAKE_LOG_MAX_RECORDS) return;
|
|
33192
33285
|
const kept = lines.slice(lines.length - WAKE_LOG_MAX_RECORDS);
|
|
33193
33286
|
const tmp = `${target}.tmp-${process.pid}`;
|
|
33194
|
-
|
|
33287
|
+
fs14.writeFileSync(tmp, `${kept.join("\n")}
|
|
33195
33288
|
`);
|
|
33196
|
-
|
|
33289
|
+
fs14.renameSync(tmp, target);
|
|
33197
33290
|
} catch {
|
|
33198
33291
|
}
|
|
33199
33292
|
}
|
|
33200
33293
|
function readWakeLog(cwd, limit) {
|
|
33201
33294
|
let lines;
|
|
33202
33295
|
try {
|
|
33203
|
-
lines =
|
|
33296
|
+
lines = fs14.readFileSync(wakeLogPath(cwd), "utf-8").split("\n").filter((l) => l.length > 0);
|
|
33204
33297
|
} catch {
|
|
33205
33298
|
return [];
|
|
33206
33299
|
}
|
|
@@ -33313,14 +33406,14 @@ var init_session_resolver = __esm({
|
|
|
33313
33406
|
|
|
33314
33407
|
// src/services/wake-inflight.ts
|
|
33315
33408
|
import crypto5 from "node:crypto";
|
|
33316
|
-
import
|
|
33317
|
-
import
|
|
33318
|
-
import
|
|
33409
|
+
import fs15 from "node:fs";
|
|
33410
|
+
import os11 from "node:os";
|
|
33411
|
+
import path16 from "node:path";
|
|
33319
33412
|
function hashCwd3(cwd) {
|
|
33320
|
-
return crypto5.createHash("sha256").update(
|
|
33413
|
+
return crypto5.createHash("sha256").update(path16.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33321
33414
|
}
|
|
33322
33415
|
function wakeInflightPath(peerId, cwd = process.cwd()) {
|
|
33323
|
-
return
|
|
33416
|
+
return path16.join(os11.homedir(), ".cogent", "wake-inflight", `${hashCwd3(cwd)}.${safe2(peerId)}.json`);
|
|
33324
33417
|
}
|
|
33325
33418
|
function ttlMs() {
|
|
33326
33419
|
let timeout = 3e5;
|
|
@@ -33333,17 +33426,17 @@ function ttlMs() {
|
|
|
33333
33426
|
}
|
|
33334
33427
|
function readFileSafe(p) {
|
|
33335
33428
|
try {
|
|
33336
|
-
const parsed = JSON.parse(
|
|
33429
|
+
const parsed = JSON.parse(fs15.readFileSync(p, "utf-8"));
|
|
33337
33430
|
return parsed && typeof parsed === "object" && parsed.messages ? parsed : { messages: {} };
|
|
33338
33431
|
} catch {
|
|
33339
33432
|
return { messages: {} };
|
|
33340
33433
|
}
|
|
33341
33434
|
}
|
|
33342
33435
|
function writeAtomic(p, data) {
|
|
33343
|
-
|
|
33436
|
+
fs15.mkdirSync(path16.dirname(p), { recursive: true });
|
|
33344
33437
|
const tmp = `${p}.${process.pid}.tmp`;
|
|
33345
|
-
|
|
33346
|
-
|
|
33438
|
+
fs15.writeFileSync(tmp, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
33439
|
+
fs15.renameSync(tmp, p);
|
|
33347
33440
|
}
|
|
33348
33441
|
function prune(f, now) {
|
|
33349
33442
|
for (const [id, rec] of Object.entries(f.messages)) {
|
|
@@ -33383,7 +33476,7 @@ function clearWakeInFlight(peerId, messageId, cwd = process.cwd()) {
|
|
|
33383
33476
|
logger.debug(`wake-inflight: could not clear ${messageId}: ${err}`);
|
|
33384
33477
|
}
|
|
33385
33478
|
}
|
|
33386
|
-
var INFLIGHT_MAX_MS, INFLIGHT_TIMEOUT_FACTOR,
|
|
33479
|
+
var INFLIGHT_MAX_MS, INFLIGHT_TIMEOUT_FACTOR, safe2;
|
|
33387
33480
|
var init_wake_inflight = __esm({
|
|
33388
33481
|
"src/services/wake-inflight.ts"() {
|
|
33389
33482
|
"use strict";
|
|
@@ -33391,24 +33484,24 @@ var init_wake_inflight = __esm({
|
|
|
33391
33484
|
init_logger();
|
|
33392
33485
|
INFLIGHT_MAX_MS = 18e5;
|
|
33393
33486
|
INFLIGHT_TIMEOUT_FACTOR = 3;
|
|
33394
|
-
|
|
33487
|
+
safe2 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33395
33488
|
}
|
|
33396
33489
|
});
|
|
33397
33490
|
|
|
33398
33491
|
// src/services/wake-claim.ts
|
|
33399
33492
|
import crypto6 from "node:crypto";
|
|
33400
|
-
import
|
|
33401
|
-
import
|
|
33402
|
-
import
|
|
33493
|
+
import fs16 from "node:fs";
|
|
33494
|
+
import os12 from "node:os";
|
|
33495
|
+
import path17 from "node:path";
|
|
33403
33496
|
function hashCwd4(cwd) {
|
|
33404
|
-
return crypto6.createHash("sha256").update(
|
|
33497
|
+
return crypto6.createHash("sha256").update(path17.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33405
33498
|
}
|
|
33406
33499
|
function wakeClaimPath(peerId, messageId, cwd = process.cwd()) {
|
|
33407
|
-
return
|
|
33408
|
-
|
|
33500
|
+
return path17.join(
|
|
33501
|
+
os12.homedir(),
|
|
33409
33502
|
".cogent",
|
|
33410
33503
|
"wake-claims",
|
|
33411
|
-
`${hashCwd4(cwd)}.${
|
|
33504
|
+
`${hashCwd4(cwd)}.${safe3(peerId)}.${safe3(messageId)}.json`
|
|
33412
33505
|
);
|
|
33413
33506
|
}
|
|
33414
33507
|
function ttlMs2() {
|
|
@@ -33435,22 +33528,22 @@ function claimWake(peerId, messageId, cwd = process.cwd()) {
|
|
|
33435
33528
|
const now = Date.now();
|
|
33436
33529
|
const body = () => JSON.stringify({ pid: process.pid, startedAt: now, expiresAt: now + ttlMs2() });
|
|
33437
33530
|
try {
|
|
33438
|
-
|
|
33531
|
+
fs16.mkdirSync(path17.dirname(p), { recursive: true });
|
|
33439
33532
|
try {
|
|
33440
|
-
|
|
33533
|
+
fs16.writeFileSync(p, body(), { flag: "wx" });
|
|
33441
33534
|
return true;
|
|
33442
33535
|
} catch (err) {
|
|
33443
33536
|
if (err?.code !== "EEXIST") throw err;
|
|
33444
33537
|
}
|
|
33445
33538
|
let held = null;
|
|
33446
33539
|
try {
|
|
33447
|
-
held = JSON.parse(
|
|
33540
|
+
held = JSON.parse(fs16.readFileSync(p, "utf-8"));
|
|
33448
33541
|
} catch {
|
|
33449
33542
|
held = null;
|
|
33450
33543
|
}
|
|
33451
33544
|
const expired = !held || typeof held.expiresAt !== "number" || held.expiresAt <= now;
|
|
33452
33545
|
if (!held || expired || !holderAlive(held.pid)) {
|
|
33453
|
-
|
|
33546
|
+
fs16.writeFileSync(p, body());
|
|
33454
33547
|
logger.debug(`wake-claim: took over an abandoned claim for ${messageId}`);
|
|
33455
33548
|
return true;
|
|
33456
33549
|
}
|
|
@@ -33465,11 +33558,11 @@ function claimWake(peerId, messageId, cwd = process.cwd()) {
|
|
|
33465
33558
|
}
|
|
33466
33559
|
function releaseWake(peerId, messageId, cwd = process.cwd()) {
|
|
33467
33560
|
try {
|
|
33468
|
-
|
|
33561
|
+
fs16.unlinkSync(wakeClaimPath(peerId, messageId, cwd));
|
|
33469
33562
|
} catch {
|
|
33470
33563
|
}
|
|
33471
33564
|
}
|
|
33472
|
-
var CLAIM_MAX_MS, CLAIM_TIMEOUT_FACTOR,
|
|
33565
|
+
var CLAIM_MAX_MS, CLAIM_TIMEOUT_FACTOR, safe3;
|
|
33473
33566
|
var init_wake_claim = __esm({
|
|
33474
33567
|
"src/services/wake-claim.ts"() {
|
|
33475
33568
|
"use strict";
|
|
@@ -33477,20 +33570,20 @@ var init_wake_claim = __esm({
|
|
|
33477
33570
|
init_logger();
|
|
33478
33571
|
CLAIM_MAX_MS = 18e5;
|
|
33479
33572
|
CLAIM_TIMEOUT_FACTOR = 3;
|
|
33480
|
-
|
|
33573
|
+
safe3 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33481
33574
|
}
|
|
33482
33575
|
});
|
|
33483
33576
|
|
|
33484
33577
|
// src/services/wake-lock.ts
|
|
33485
33578
|
import crypto7 from "node:crypto";
|
|
33486
|
-
import
|
|
33487
|
-
import
|
|
33488
|
-
import
|
|
33579
|
+
import fs17 from "node:fs";
|
|
33580
|
+
import os13 from "node:os";
|
|
33581
|
+
import path18 from "node:path";
|
|
33489
33582
|
function hashCwd5(cwd) {
|
|
33490
|
-
return crypto7.createHash("sha256").update(
|
|
33583
|
+
return crypto7.createHash("sha256").update(path18.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33491
33584
|
}
|
|
33492
33585
|
function wakeLockPath(cwd = process.cwd()) {
|
|
33493
|
-
return
|
|
33586
|
+
return path18.join(os13.homedir(), ".cogent", "wake-locks", `${hashCwd5(cwd)}.json`);
|
|
33494
33587
|
}
|
|
33495
33588
|
function leaseTtlMs() {
|
|
33496
33589
|
let timeout = 3e5;
|
|
@@ -33521,7 +33614,7 @@ function holderAlive2(pid) {
|
|
|
33521
33614
|
}
|
|
33522
33615
|
function readHolder(p) {
|
|
33523
33616
|
try {
|
|
33524
|
-
const held = JSON.parse(
|
|
33617
|
+
const held = JSON.parse(fs17.readFileSync(p, "utf-8"));
|
|
33525
33618
|
if (!held || typeof held.expiresAt !== "number") return null;
|
|
33526
33619
|
return held;
|
|
33527
33620
|
} catch {
|
|
@@ -33568,7 +33661,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33568
33661
|
} };
|
|
33569
33662
|
};
|
|
33570
33663
|
try {
|
|
33571
|
-
|
|
33664
|
+
fs17.mkdirSync(path18.dirname(p), { recursive: true });
|
|
33572
33665
|
} catch (err) {
|
|
33573
33666
|
return failOpen(`cannot create lock dir (${err.message})`);
|
|
33574
33667
|
}
|
|
@@ -33581,7 +33674,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33581
33674
|
expiresAt: now + leaseTtlMs()
|
|
33582
33675
|
});
|
|
33583
33676
|
try {
|
|
33584
|
-
|
|
33677
|
+
fs17.writeFileSync(p, body, { flag: "wx" });
|
|
33585
33678
|
if (contended) {
|
|
33586
33679
|
logger.info(
|
|
33587
33680
|
`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 +33689,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33596
33689
|
const held = readHolder(p);
|
|
33597
33690
|
if (!held || held.expiresAt <= now || !holderAlive2(held.pid)) {
|
|
33598
33691
|
try {
|
|
33599
|
-
|
|
33692
|
+
fs17.writeFileSync(p, body);
|
|
33600
33693
|
} catch (err) {
|
|
33601
33694
|
return failOpen(`cannot steal abandoned lock (${err.message})`);
|
|
33602
33695
|
}
|
|
@@ -33619,7 +33712,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33619
33712
|
}
|
|
33620
33713
|
function releaseWakeLock(cwd = process.cwd()) {
|
|
33621
33714
|
try {
|
|
33622
|
-
|
|
33715
|
+
fs17.unlinkSync(wakeLockPath(cwd));
|
|
33623
33716
|
} catch {
|
|
33624
33717
|
}
|
|
33625
33718
|
}
|
|
@@ -33639,14 +33732,14 @@ var init_wake_lock = __esm({
|
|
|
33639
33732
|
|
|
33640
33733
|
// src/services/wake-ownership.ts
|
|
33641
33734
|
import crypto8 from "node:crypto";
|
|
33642
|
-
import
|
|
33643
|
-
import
|
|
33644
|
-
import
|
|
33735
|
+
import fs18 from "node:fs";
|
|
33736
|
+
import os14 from "node:os";
|
|
33737
|
+
import path19 from "node:path";
|
|
33645
33738
|
function hashCwd6(cwd) {
|
|
33646
|
-
return crypto8.createHash("sha256").update(
|
|
33739
|
+
return crypto8.createHash("sha256").update(path19.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33647
33740
|
}
|
|
33648
33741
|
function bridgeDirFor(cwd, peerId) {
|
|
33649
|
-
return
|
|
33742
|
+
return path19.join(os14.homedir(), ".cogent", "bridges", `${hashCwd6(cwd)}.${safe4(peerId)}`);
|
|
33650
33743
|
}
|
|
33651
33744
|
function pidAlive(pid) {
|
|
33652
33745
|
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return false;
|
|
@@ -33661,23 +33754,23 @@ function pidAlive(pid) {
|
|
|
33661
33754
|
function announceBridge(cwd, peerId, version2, endpoint) {
|
|
33662
33755
|
const dir = bridgeDirFor(cwd, peerId);
|
|
33663
33756
|
try {
|
|
33664
|
-
|
|
33757
|
+
fs18.mkdirSync(dir, { recursive: true });
|
|
33665
33758
|
const entry = {
|
|
33666
33759
|
pid: process.pid,
|
|
33667
33760
|
startedAt: PROCESS_STARTED_AT,
|
|
33668
33761
|
version: version2,
|
|
33669
33762
|
peerId,
|
|
33670
33763
|
endpoint,
|
|
33671
|
-
cwd:
|
|
33764
|
+
cwd: path19.resolve(cwd)
|
|
33672
33765
|
};
|
|
33673
|
-
|
|
33766
|
+
fs18.writeFileSync(path19.join(dir, `${process.pid}.json`), JSON.stringify(entry));
|
|
33674
33767
|
} catch (err) {
|
|
33675
33768
|
logger.debug(`wake-ownership: could not announce this bridge (${err.message})`);
|
|
33676
33769
|
}
|
|
33677
33770
|
}
|
|
33678
33771
|
function withdrawBridge(cwd, peerId) {
|
|
33679
33772
|
try {
|
|
33680
|
-
|
|
33773
|
+
fs18.unlinkSync(path19.join(bridgeDirFor(cwd, peerId), `${process.pid}.json`));
|
|
33681
33774
|
} catch {
|
|
33682
33775
|
}
|
|
33683
33776
|
}
|
|
@@ -33685,23 +33778,23 @@ function listLiveBridges(cwd, peerId) {
|
|
|
33685
33778
|
const dir = bridgeDirFor(cwd, peerId);
|
|
33686
33779
|
let names;
|
|
33687
33780
|
try {
|
|
33688
|
-
names =
|
|
33781
|
+
names = fs18.readdirSync(dir);
|
|
33689
33782
|
} catch {
|
|
33690
33783
|
return [];
|
|
33691
33784
|
}
|
|
33692
33785
|
const live = [];
|
|
33693
33786
|
for (const name of names) {
|
|
33694
33787
|
if (!name.endsWith(".json")) continue;
|
|
33695
|
-
const p =
|
|
33788
|
+
const p = path19.join(dir, name);
|
|
33696
33789
|
let entry = null;
|
|
33697
33790
|
try {
|
|
33698
|
-
entry = JSON.parse(
|
|
33791
|
+
entry = JSON.parse(fs18.readFileSync(p, "utf-8"));
|
|
33699
33792
|
} catch {
|
|
33700
33793
|
entry = null;
|
|
33701
33794
|
}
|
|
33702
33795
|
if (!entry || !pidAlive(entry.pid) || typeof entry.startedAt !== "number") {
|
|
33703
33796
|
try {
|
|
33704
|
-
|
|
33797
|
+
fs18.unlinkSync(p);
|
|
33705
33798
|
} catch {
|
|
33706
33799
|
}
|
|
33707
33800
|
continue;
|
|
@@ -33731,20 +33824,20 @@ function checkWakeOwnership(cwd, peerId) {
|
|
|
33731
33824
|
}
|
|
33732
33825
|
return { isOwner: true, liveCount: live.length + 1 };
|
|
33733
33826
|
}
|
|
33734
|
-
var PROCESS_STARTED_AT,
|
|
33827
|
+
var PROCESS_STARTED_AT, safe4;
|
|
33735
33828
|
var init_wake_ownership = __esm({
|
|
33736
33829
|
"src/services/wake-ownership.ts"() {
|
|
33737
33830
|
"use strict";
|
|
33738
33831
|
init_logger();
|
|
33739
33832
|
PROCESS_STARTED_AT = Date.now() - Math.floor(process.uptime() * 1e3);
|
|
33740
|
-
|
|
33833
|
+
safe4 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33741
33834
|
}
|
|
33742
33835
|
});
|
|
33743
33836
|
|
|
33744
33837
|
// src/services/stale-bridge-reaper.ts
|
|
33745
33838
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
33746
|
-
import
|
|
33747
|
-
import
|
|
33839
|
+
import fs19 from "node:fs";
|
|
33840
|
+
import path20 from "node:path";
|
|
33748
33841
|
function isBridgeCommand(argv) {
|
|
33749
33842
|
if (!argv) return false;
|
|
33750
33843
|
if (/\.test\.|-test\.mjs|scripts\//.test(argv)) return false;
|
|
@@ -33785,7 +33878,7 @@ function listProcesses() {
|
|
|
33785
33878
|
function processCwd(pid) {
|
|
33786
33879
|
try {
|
|
33787
33880
|
if (process.platform === "linux") {
|
|
33788
|
-
return
|
|
33881
|
+
return path20.resolve(fs19.readlinkSync(`/proc/${pid}/cwd`));
|
|
33789
33882
|
}
|
|
33790
33883
|
if (process.platform === "darwin") {
|
|
33791
33884
|
const out = execFileSync2("lsof", ["-a", "-d", "cwd", "-p", String(pid), "-Fn"], {
|
|
@@ -33794,7 +33887,7 @@ function processCwd(pid) {
|
|
|
33794
33887
|
stdio: ["ignore", "pipe", "ignore"]
|
|
33795
33888
|
});
|
|
33796
33889
|
const line = out.split("\n").find((l) => l.startsWith("n"));
|
|
33797
|
-
return line ?
|
|
33890
|
+
return line ? path20.resolve(line.slice(1)) : null;
|
|
33798
33891
|
}
|
|
33799
33892
|
} catch {
|
|
33800
33893
|
}
|
|
@@ -33802,9 +33895,9 @@ function processCwd(pid) {
|
|
|
33802
33895
|
}
|
|
33803
33896
|
function canonicalPath(p) {
|
|
33804
33897
|
try {
|
|
33805
|
-
return
|
|
33898
|
+
return fs19.realpathSync(path20.resolve(p));
|
|
33806
33899
|
} catch {
|
|
33807
|
-
return
|
|
33900
|
+
return path20.resolve(p);
|
|
33808
33901
|
}
|
|
33809
33902
|
}
|
|
33810
33903
|
function ancestorsOf(pid, procs) {
|
|
@@ -33820,9 +33913,9 @@ function ancestorsOf(pid, procs) {
|
|
|
33820
33913
|
function announcedPidsFor(cwd) {
|
|
33821
33914
|
const pids = /* @__PURE__ */ new Set();
|
|
33822
33915
|
try {
|
|
33823
|
-
const base =
|
|
33824
|
-
const prefix =
|
|
33825
|
-
for (const dir of
|
|
33916
|
+
const base = path20.dirname(bridgeDirFor(cwd, "x"));
|
|
33917
|
+
const prefix = path20.basename(bridgeDirFor(cwd, "x")).split(".")[0];
|
|
33918
|
+
for (const dir of fs19.readdirSync(base)) {
|
|
33826
33919
|
if (!dir.startsWith(`${prefix}.`)) continue;
|
|
33827
33920
|
const peerId = dir.slice(prefix.length + 1);
|
|
33828
33921
|
for (const e of listLiveBridges(cwd, peerId)) pids.add(e.pid);
|
|
@@ -35267,9 +35360,9 @@ __export(startup_exports, {
|
|
|
35267
35360
|
setInboxNotifier: () => setInboxNotifier,
|
|
35268
35361
|
triggerReRegistration: () => triggerReRegistration
|
|
35269
35362
|
});
|
|
35270
|
-
import
|
|
35271
|
-
import
|
|
35272
|
-
import
|
|
35363
|
+
import os15 from "node:os";
|
|
35364
|
+
import path21 from "node:path";
|
|
35365
|
+
import fs20 from "node:fs/promises";
|
|
35273
35366
|
import readline2 from "node:readline";
|
|
35274
35367
|
import { execFile as execFile5 } from "node:child_process";
|
|
35275
35368
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -35287,7 +35380,7 @@ function bindInboxNotifier() {
|
|
|
35287
35380
|
}
|
|
35288
35381
|
async function loadPersistedConfig() {
|
|
35289
35382
|
try {
|
|
35290
|
-
const raw = await
|
|
35383
|
+
const raw = await fs20.readFile(PERSIST_PATH, "utf-8");
|
|
35291
35384
|
return JSON.parse(raw);
|
|
35292
35385
|
} catch {
|
|
35293
35386
|
return {};
|
|
@@ -35295,7 +35388,7 @@ async function loadPersistedConfig() {
|
|
|
35295
35388
|
}
|
|
35296
35389
|
async function savePersistedConfig(config2) {
|
|
35297
35390
|
try {
|
|
35298
|
-
await
|
|
35391
|
+
await fs20.writeFile(PERSIST_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
|
|
35299
35392
|
} catch (err) {
|
|
35300
35393
|
const msg = err instanceof Error ? err.message : String(err);
|
|
35301
35394
|
logger.warn(`Could not save config to ${PERSIST_PATH}: ${msg}`);
|
|
@@ -35330,11 +35423,11 @@ First run detected. Where should cogent-bridge store its data?
|
|
|
35330
35423
|
});
|
|
35331
35424
|
}
|
|
35332
35425
|
async function validateStateDir(statePath) {
|
|
35333
|
-
await
|
|
35334
|
-
const testFile =
|
|
35426
|
+
await fs20.mkdir(statePath, { recursive: true });
|
|
35427
|
+
const testFile = path21.join(statePath, ".write-test");
|
|
35335
35428
|
try {
|
|
35336
|
-
await
|
|
35337
|
-
await
|
|
35429
|
+
await fs20.writeFile(testFile, "test", "utf-8");
|
|
35430
|
+
await fs20.unlink(testFile);
|
|
35338
35431
|
} catch {
|
|
35339
35432
|
throw new BridgeError(
|
|
35340
35433
|
"STARTUP_FAILED" /* STARTUP_FAILED */,
|
|
@@ -35522,10 +35615,10 @@ async function runStartup() {
|
|
|
35522
35615
|
if (envStatePath) {
|
|
35523
35616
|
statePath = envStatePath;
|
|
35524
35617
|
} else {
|
|
35525
|
-
const defaultPath =
|
|
35618
|
+
const defaultPath = path21.join(os15.homedir(), ".cogent");
|
|
35526
35619
|
statePath = await firstRunPrompt(defaultPath);
|
|
35527
35620
|
}
|
|
35528
|
-
if (!envStatePath && statePath !==
|
|
35621
|
+
if (!envStatePath && statePath !== path21.join(os15.homedir(), ".cogent")) {
|
|
35529
35622
|
process.env.COGENT_STATE_PATH = statePath;
|
|
35530
35623
|
} else if (!envStatePath) {
|
|
35531
35624
|
process.env.COGENT_STATE_PATH = statePath;
|
|
@@ -35589,7 +35682,7 @@ async function runStartup() {
|
|
|
35589
35682
|
}
|
|
35590
35683
|
initLogger(
|
|
35591
35684
|
config2.COGENT_LOG_LEVEL,
|
|
35592
|
-
|
|
35685
|
+
path21.join(config2.COGENT_STATE_PATH, "logs")
|
|
35593
35686
|
);
|
|
35594
35687
|
if (isCloud && effectiveSessionId && effectiveToken) {
|
|
35595
35688
|
cloudInbox = new MessageInbox();
|
|
@@ -35651,7 +35744,7 @@ var init_startup = __esm({
|
|
|
35651
35744
|
init_auto_relay();
|
|
35652
35745
|
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
35746
|
execFileAsync3 = promisify4(execFile5);
|
|
35654
|
-
PERSIST_PATH =
|
|
35747
|
+
PERSIST_PATH = path21.join(os15.homedir(), ".cogent-config.json");
|
|
35655
35748
|
legacyWarnEmitted = false;
|
|
35656
35749
|
cloudWsClient = null;
|
|
35657
35750
|
cloudInbox = null;
|
|
@@ -35666,12 +35759,12 @@ var init_startup = __esm({
|
|
|
35666
35759
|
|
|
35667
35760
|
// src/cloud/mail-credential-store.ts
|
|
35668
35761
|
import crypto9 from "node:crypto";
|
|
35669
|
-
import
|
|
35670
|
-
import
|
|
35671
|
-
import
|
|
35762
|
+
import fs21 from "node:fs/promises";
|
|
35763
|
+
import path22 from "node:path";
|
|
35764
|
+
import os16 from "node:os";
|
|
35672
35765
|
function defaultMailCredentialPath(cwd = process.cwd()) {
|
|
35673
|
-
const hash = crypto9.createHash("sha256").update(
|
|
35674
|
-
return
|
|
35766
|
+
const hash = crypto9.createHash("sha256").update(path22.resolve(cwd)).digest("hex").slice(0, 16);
|
|
35767
|
+
return path22.join(os16.homedir(), ".cogent", "mail-credentials", `${hash}.json`);
|
|
35675
35768
|
}
|
|
35676
35769
|
function resolveMailCredentialPath(credentialPath) {
|
|
35677
35770
|
if (credentialPath) return credentialPath;
|
|
@@ -35682,16 +35775,16 @@ function resolveMailCredentialPath(credentialPath) {
|
|
|
35682
35775
|
async function loadMailCredentials(credentialPath) {
|
|
35683
35776
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35684
35777
|
try {
|
|
35685
|
-
return JSON.parse(await
|
|
35778
|
+
return JSON.parse(await fs21.readFile(filePath, "utf-8"));
|
|
35686
35779
|
} catch {
|
|
35687
35780
|
return null;
|
|
35688
35781
|
}
|
|
35689
35782
|
}
|
|
35690
35783
|
async function saveMailCredentials(creds, credentialPath) {
|
|
35691
35784
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35692
|
-
await
|
|
35693
|
-
await
|
|
35694
|
-
await
|
|
35785
|
+
await fs21.mkdir(path22.dirname(filePath), { recursive: true, mode: 448 });
|
|
35786
|
+
await fs21.writeFile(filePath, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
|
|
35787
|
+
await fs21.chmod(filePath, 384);
|
|
35695
35788
|
}
|
|
35696
35789
|
async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
35697
35790
|
if (!mailbox?.address || !mailbox.password) return false;
|
|
@@ -35712,7 +35805,7 @@ async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
|
35712
35805
|
async function clearMailCredentials(credentialPath) {
|
|
35713
35806
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35714
35807
|
try {
|
|
35715
|
-
await
|
|
35808
|
+
await fs21.unlink(filePath);
|
|
35716
35809
|
} catch (err) {
|
|
35717
35810
|
if (err.code !== "ENOENT") throw err;
|
|
35718
35811
|
}
|
|
@@ -37065,12 +37158,14 @@ function registerHealthCheckTool(server) {
|
|
|
37065
37158
|
const backend = getBackend();
|
|
37066
37159
|
const result = await backend.checkHealth();
|
|
37067
37160
|
let wsConnected = false;
|
|
37161
|
+
let delivery = null;
|
|
37068
37162
|
let wsLastFrameAt = null;
|
|
37069
37163
|
let wsLastFrameAtMs = null;
|
|
37070
37164
|
try {
|
|
37071
37165
|
const startup = await Promise.resolve().then(() => (init_startup(), startup_exports));
|
|
37072
37166
|
if (startup.cloudWsClient) {
|
|
37073
37167
|
wsConnected = startup.cloudWsClient.isConnected();
|
|
37168
|
+
delivery = startup.cloudWsClient.getDeliveryDiagnostics?.() ?? null;
|
|
37074
37169
|
wsLastFrameAt = startup.cloudWsClient.getLastFrameAt();
|
|
37075
37170
|
wsLastFrameAtMs = startup.cloudWsClient.getLastFrameAtMs();
|
|
37076
37171
|
}
|
|
@@ -37108,8 +37203,20 @@ function registerHealthCheckTool(server) {
|
|
|
37108
37203
|
}
|
|
37109
37204
|
}
|
|
37110
37205
|
const updateAvailable = getLastNudge();
|
|
37206
|
+
const relayHealthy = result.healthy !== false;
|
|
37207
|
+
let deliveryPath = "unknown";
|
|
37208
|
+
if (cloud && delivery) {
|
|
37209
|
+
deliveryPath = wsConnected ? "websocket" : delivery.pollActive && !delivery.lastPollError ? "poll" : "none";
|
|
37210
|
+
} else if (cloud && wsConnected) {
|
|
37211
|
+
deliveryPath = "websocket";
|
|
37212
|
+
}
|
|
37213
|
+
const registered = autoRelay.getDiagnostics().registered;
|
|
37214
|
+
const deliveryBroken = cloud && registered && deliveryPath === "none";
|
|
37215
|
+
const unhealthyReason = deliveryBroken ? `registered as a cloud peer but NO delivery path is working (websocket down${delivery?.lastWsError ? `: ${delivery.lastWsError}` : ""}; poll ${delivery?.lastPollError ? `failing: ${delivery.lastPollError}` : "inactive"}) \u2014 messages addressed to this peer cannot reach it` : null;
|
|
37111
37216
|
const enriched = {
|
|
37112
37217
|
...JSON.parse(JSON.stringify(result)),
|
|
37218
|
+
healthy: relayHealthy && !deliveryBroken,
|
|
37219
|
+
...unhealthyReason ? { unhealthyReason } : {},
|
|
37113
37220
|
clientVersion: SERVER_VERSION,
|
|
37114
37221
|
...updateAvailable ? { updateAvailable } : {},
|
|
37115
37222
|
runtimeMode: cloud ? "cloud" : "local",
|
|
@@ -37129,7 +37236,7 @@ function registerHealthCheckTool(server) {
|
|
|
37129
37236
|
// on HttpBackend; null when the /api/health fetch fails. Keep the
|
|
37130
37237
|
// key cloud-gated for shape consistency with wsHealth (local mode
|
|
37131
37238
|
// never has an upstream relay version to report).
|
|
37132
|
-
...cloud ? { wsHealth, relayVersion } : {}
|
|
37239
|
+
...cloud ? { wsHealth, relayVersion, deliveryPath, lastWsError: delivery?.lastWsError ?? null } : {}
|
|
37133
37240
|
},
|
|
37134
37241
|
autoRelay: autoRelay.getDiagnostics()
|
|
37135
37242
|
};
|
|
@@ -37723,8 +37830,8 @@ var require_cookies = __commonJS({
|
|
|
37723
37830
|
if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
|
|
37724
37831
|
return false;
|
|
37725
37832
|
}
|
|
37726
|
-
let
|
|
37727
|
-
if (
|
|
37833
|
+
let path26 = this.getPath(urlparts.pathname);
|
|
37834
|
+
if (path26.substr(0, cookie.path.length) !== cookie.path) {
|
|
37728
37835
|
return false;
|
|
37729
37836
|
}
|
|
37730
37837
|
if (cookie.secure && urlparts.protocol !== "https:") {
|
|
@@ -37784,16 +37891,16 @@ var require_cookies = __commonJS({
|
|
|
37784
37891
|
* @returns {String} Normalized path
|
|
37785
37892
|
*/
|
|
37786
37893
|
getPath(pathname) {
|
|
37787
|
-
let
|
|
37788
|
-
|
|
37789
|
-
|
|
37790
|
-
if (
|
|
37791
|
-
|
|
37894
|
+
let path26 = (pathname || "/").split("/");
|
|
37895
|
+
path26.pop();
|
|
37896
|
+
path26 = path26.join("/").trim();
|
|
37897
|
+
if (path26.charAt(0) !== "/") {
|
|
37898
|
+
path26 = "/" + path26;
|
|
37792
37899
|
}
|
|
37793
|
-
if (
|
|
37794
|
-
|
|
37900
|
+
if (path26.substr(-1) !== "/") {
|
|
37901
|
+
path26 += "/";
|
|
37795
37902
|
}
|
|
37796
|
-
return
|
|
37903
|
+
return path26;
|
|
37797
37904
|
}
|
|
37798
37905
|
};
|
|
37799
37906
|
module.exports = Cookies;
|
|
@@ -38094,15 +38201,15 @@ var require_shared = __commonJS({
|
|
|
38094
38201
|
"use strict";
|
|
38095
38202
|
var urllib = __require("url");
|
|
38096
38203
|
var util2 = __require("util");
|
|
38097
|
-
var
|
|
38204
|
+
var fs24 = __require("fs");
|
|
38098
38205
|
var nmfetch = require_fetch();
|
|
38099
38206
|
var dns = __require("dns");
|
|
38100
38207
|
var net = __require("net");
|
|
38101
|
-
var
|
|
38208
|
+
var os18 = __require("os");
|
|
38102
38209
|
var DNS_TTL = 5 * 60 * 1e3;
|
|
38103
38210
|
var networkInterfaces;
|
|
38104
38211
|
try {
|
|
38105
|
-
networkInterfaces =
|
|
38212
|
+
networkInterfaces = os18.networkInterfaces();
|
|
38106
38213
|
} catch (err) {
|
|
38107
38214
|
}
|
|
38108
38215
|
module.exports.networkInterfaces = networkInterfaces;
|
|
@@ -38480,7 +38587,7 @@ var require_shared = __commonJS({
|
|
|
38480
38587
|
}
|
|
38481
38588
|
return callback(null, parsedDataUri.data);
|
|
38482
38589
|
} else if (content.path) {
|
|
38483
|
-
return resolveStream(
|
|
38590
|
+
return resolveStream(fs24.createReadStream(content.path), callback);
|
|
38484
38591
|
}
|
|
38485
38592
|
}
|
|
38486
38593
|
if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
|
|
@@ -38604,7 +38711,7 @@ var require_shared = __commonJS({
|
|
|
38604
38711
|
var require_mime_types = __commonJS({
|
|
38605
38712
|
"node_modules/nodemailer/lib/mime-funcs/mime-types.js"(exports, module) {
|
|
38606
38713
|
"use strict";
|
|
38607
|
-
var
|
|
38714
|
+
var path26 = __require("path");
|
|
38608
38715
|
var defaultMimeType = "application/octet-stream";
|
|
38609
38716
|
var defaultExtension = "bin";
|
|
38610
38717
|
var mimeTypes = /* @__PURE__ */ new Map([
|
|
@@ -40662,7 +40769,7 @@ var require_mime_types = __commonJS({
|
|
|
40662
40769
|
if (!filename) {
|
|
40663
40770
|
return defaultMimeType;
|
|
40664
40771
|
}
|
|
40665
|
-
let parsed =
|
|
40772
|
+
let parsed = path26.parse(filename);
|
|
40666
40773
|
let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
|
|
40667
40774
|
let value = defaultMimeType;
|
|
40668
40775
|
if (extensions.has(extension)) {
|
|
@@ -42064,7 +42171,7 @@ var require_mime_node = __commonJS({
|
|
|
42064
42171
|
"node_modules/nodemailer/lib/mime-node/index.js"(exports, module) {
|
|
42065
42172
|
"use strict";
|
|
42066
42173
|
var crypto12 = __require("crypto");
|
|
42067
|
-
var
|
|
42174
|
+
var fs24 = __require("fs");
|
|
42068
42175
|
var punycode = require_punycode();
|
|
42069
42176
|
var PassThrough = __require("stream").PassThrough;
|
|
42070
42177
|
var shared = require_shared();
|
|
@@ -42779,7 +42886,7 @@ var require_mime_node = __commonJS({
|
|
|
42779
42886
|
setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
|
|
42780
42887
|
return contentStream;
|
|
42781
42888
|
}
|
|
42782
|
-
return
|
|
42889
|
+
return fs24.createReadStream(content.path);
|
|
42783
42890
|
} else if (content && typeof content.href === "string") {
|
|
42784
42891
|
if (this.disableUrlAccess) {
|
|
42785
42892
|
contentStream = new PassThrough();
|
|
@@ -43800,8 +43907,8 @@ var require_dkim = __commonJS({
|
|
|
43800
43907
|
var RelaxedBody = require_relaxed_body();
|
|
43801
43908
|
var sign = require_sign();
|
|
43802
43909
|
var PassThrough = __require("stream").PassThrough;
|
|
43803
|
-
var
|
|
43804
|
-
var
|
|
43910
|
+
var fs24 = __require("fs");
|
|
43911
|
+
var path26 = __require("path");
|
|
43805
43912
|
var crypto12 = __require("crypto");
|
|
43806
43913
|
var DKIM_ALGO = "sha256";
|
|
43807
43914
|
var MAX_MESSAGE_SIZE = 128 * 1024;
|
|
@@ -43815,7 +43922,7 @@ var require_dkim = __commonJS({
|
|
|
43815
43922
|
this.chunks = [];
|
|
43816
43923
|
this.chunklen = 0;
|
|
43817
43924
|
this.readPos = 0;
|
|
43818
|
-
this.cachePath = this.cacheDir ?
|
|
43925
|
+
this.cachePath = this.cacheDir ? path26.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
|
|
43819
43926
|
this.cache = false;
|
|
43820
43927
|
this.headers = false;
|
|
43821
43928
|
this.bodyHash = false;
|
|
@@ -43835,10 +43942,10 @@ var require_dkim = __commonJS({
|
|
|
43835
43942
|
if (!this.cache || !this.cachePath) {
|
|
43836
43943
|
return;
|
|
43837
43944
|
}
|
|
43838
|
-
|
|
43945
|
+
fs24.unlink(this.cachePath, () => false);
|
|
43839
43946
|
}
|
|
43840
43947
|
createReadCache() {
|
|
43841
|
-
this.cache =
|
|
43948
|
+
this.cache = fs24.createReadStream(this.cachePath);
|
|
43842
43949
|
this.cache.once("error", (err) => {
|
|
43843
43950
|
this.cleanup();
|
|
43844
43951
|
this.output.emit("error", err);
|
|
@@ -43894,7 +44001,7 @@ var require_dkim = __commonJS({
|
|
|
43894
44001
|
}
|
|
43895
44002
|
createWriteCache() {
|
|
43896
44003
|
this.output.usingCache = true;
|
|
43897
|
-
this.cache =
|
|
44004
|
+
this.cache = fs24.createWriteStream(this.cachePath);
|
|
43898
44005
|
this.cache.once("error", (err) => {
|
|
43899
44006
|
this.cleanup();
|
|
43900
44007
|
this.relaxedBody.unpipe(this.cache);
|
|
@@ -44821,7 +44928,7 @@ var require_smtp_connection = __commonJS({
|
|
|
44821
44928
|
var EventEmitter = __require("events").EventEmitter;
|
|
44822
44929
|
var net = __require("net");
|
|
44823
44930
|
var tls = __require("tls");
|
|
44824
|
-
var
|
|
44931
|
+
var os18 = __require("os");
|
|
44825
44932
|
var crypto12 = __require("crypto");
|
|
44826
44933
|
var DataStream = require_data_stream();
|
|
44827
44934
|
var PassThrough = __require("stream").PassThrough;
|
|
@@ -46214,7 +46321,7 @@ var require_smtp_connection = __commonJS({
|
|
|
46214
46321
|
_getHostname() {
|
|
46215
46322
|
let defaultHostname;
|
|
46216
46323
|
try {
|
|
46217
|
-
defaultHostname =
|
|
46324
|
+
defaultHostname = os18.hostname() || "";
|
|
46218
46325
|
} catch (err) {
|
|
46219
46326
|
defaultHostname = "localhost";
|
|
46220
46327
|
}
|
|
@@ -48783,13 +48890,13 @@ var require_nodemailer = __commonJS({
|
|
|
48783
48890
|
});
|
|
48784
48891
|
|
|
48785
48892
|
// src/mail/mail-sender.ts
|
|
48786
|
-
import
|
|
48787
|
-
import
|
|
48893
|
+
import fs22 from "node:fs/promises";
|
|
48894
|
+
import path23 from "node:path";
|
|
48788
48895
|
async function buildAndSendMail(sender, creds, params) {
|
|
48789
48896
|
const attachments = [];
|
|
48790
48897
|
for (const p of params.attachmentPaths ?? []) {
|
|
48791
|
-
const content = await
|
|
48792
|
-
attachments.push({ filename:
|
|
48898
|
+
const content = await fs22.readFile(p);
|
|
48899
|
+
attachments.push({ filename: path23.basename(p), content });
|
|
48793
48900
|
}
|
|
48794
48901
|
const { messageId } = await sender.send({
|
|
48795
48902
|
from: creds.address,
|
|
@@ -49178,8 +49285,8 @@ var require_req = __commonJS({
|
|
|
49178
49285
|
if (req.originalUrl) {
|
|
49179
49286
|
_req.url = req.originalUrl;
|
|
49180
49287
|
} else {
|
|
49181
|
-
const
|
|
49182
|
-
_req.url = typeof
|
|
49288
|
+
const path26 = req.path;
|
|
49289
|
+
_req.url = typeof path26 === "string" ? path26 : req.url ? req.url.path || req.url : void 0;
|
|
49183
49290
|
}
|
|
49184
49291
|
if (req.query) {
|
|
49185
49292
|
_req.query = req.query;
|
|
@@ -49344,14 +49451,14 @@ var require_redact = __commonJS({
|
|
|
49344
49451
|
}
|
|
49345
49452
|
return obj;
|
|
49346
49453
|
}
|
|
49347
|
-
function parsePath(
|
|
49454
|
+
function parsePath(path26) {
|
|
49348
49455
|
const parts = [];
|
|
49349
49456
|
let current = "";
|
|
49350
49457
|
let inBrackets = false;
|
|
49351
49458
|
let inQuotes = false;
|
|
49352
49459
|
let quoteChar = "";
|
|
49353
|
-
for (let i = 0; i <
|
|
49354
|
-
const char =
|
|
49460
|
+
for (let i = 0; i < path26.length; i++) {
|
|
49461
|
+
const char = path26[i];
|
|
49355
49462
|
if (!inBrackets && char === ".") {
|
|
49356
49463
|
if (current) {
|
|
49357
49464
|
parts.push(current);
|
|
@@ -49482,10 +49589,10 @@ var require_redact = __commonJS({
|
|
|
49482
49589
|
return current;
|
|
49483
49590
|
}
|
|
49484
49591
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
49485
|
-
for (const
|
|
49486
|
-
const parts = parsePath(
|
|
49592
|
+
for (const path26 of paths) {
|
|
49593
|
+
const parts = parsePath(path26);
|
|
49487
49594
|
if (parts.includes("*")) {
|
|
49488
|
-
redactWildcardPath(obj, parts, censor,
|
|
49595
|
+
redactWildcardPath(obj, parts, censor, path26, remove);
|
|
49489
49596
|
} else {
|
|
49490
49597
|
if (remove) {
|
|
49491
49598
|
removeKey(obj, parts);
|
|
@@ -49570,8 +49677,8 @@ var require_redact = __commonJS({
|
|
|
49570
49677
|
}
|
|
49571
49678
|
} else {
|
|
49572
49679
|
if (afterWildcard.includes("*")) {
|
|
49573
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49574
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
49680
|
+
const wrappedCensor = typeof censor === "function" ? (value, path26) => {
|
|
49681
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path26];
|
|
49575
49682
|
return censor(value, fullPath);
|
|
49576
49683
|
} : censor;
|
|
49577
49684
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -49606,8 +49713,8 @@ var require_redact = __commonJS({
|
|
|
49606
49713
|
return null;
|
|
49607
49714
|
}
|
|
49608
49715
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
49609
|
-
for (const
|
|
49610
|
-
const parts = parsePath(
|
|
49716
|
+
for (const path26 of pathsToClone) {
|
|
49717
|
+
const parts = parsePath(path26);
|
|
49611
49718
|
let current = pathStructure;
|
|
49612
49719
|
for (let i = 0; i < parts.length; i++) {
|
|
49613
49720
|
const part = parts[i];
|
|
@@ -49659,24 +49766,24 @@ var require_redact = __commonJS({
|
|
|
49659
49766
|
}
|
|
49660
49767
|
return cloneSelectively(obj, pathStructure);
|
|
49661
49768
|
}
|
|
49662
|
-
function validatePath(
|
|
49663
|
-
if (typeof
|
|
49769
|
+
function validatePath(path26) {
|
|
49770
|
+
if (typeof path26 !== "string") {
|
|
49664
49771
|
throw new Error("Paths must be (non-empty) strings");
|
|
49665
49772
|
}
|
|
49666
|
-
if (
|
|
49773
|
+
if (path26 === "") {
|
|
49667
49774
|
throw new Error("Invalid redaction path ()");
|
|
49668
49775
|
}
|
|
49669
|
-
if (
|
|
49670
|
-
throw new Error(`Invalid redaction path (${
|
|
49776
|
+
if (path26.includes("..")) {
|
|
49777
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49671
49778
|
}
|
|
49672
|
-
if (
|
|
49673
|
-
throw new Error(`Invalid redaction path (${
|
|
49779
|
+
if (path26.includes(",")) {
|
|
49780
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49674
49781
|
}
|
|
49675
49782
|
let bracketCount = 0;
|
|
49676
49783
|
let inQuotes = false;
|
|
49677
49784
|
let quoteChar = "";
|
|
49678
|
-
for (let i = 0; i <
|
|
49679
|
-
const char =
|
|
49785
|
+
for (let i = 0; i < path26.length; i++) {
|
|
49786
|
+
const char = path26[i];
|
|
49680
49787
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
49681
49788
|
if (!inQuotes) {
|
|
49682
49789
|
inQuotes = true;
|
|
@@ -49690,20 +49797,20 @@ var require_redact = __commonJS({
|
|
|
49690
49797
|
} else if (char === "]" && !inQuotes) {
|
|
49691
49798
|
bracketCount--;
|
|
49692
49799
|
if (bracketCount < 0) {
|
|
49693
|
-
throw new Error(`Invalid redaction path (${
|
|
49800
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49694
49801
|
}
|
|
49695
49802
|
}
|
|
49696
49803
|
}
|
|
49697
49804
|
if (bracketCount !== 0) {
|
|
49698
|
-
throw new Error(`Invalid redaction path (${
|
|
49805
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49699
49806
|
}
|
|
49700
49807
|
}
|
|
49701
49808
|
function validatePaths(paths) {
|
|
49702
49809
|
if (!Array.isArray(paths)) {
|
|
49703
49810
|
throw new TypeError("paths must be an array");
|
|
49704
49811
|
}
|
|
49705
|
-
for (const
|
|
49706
|
-
validatePath(
|
|
49812
|
+
for (const path26 of paths) {
|
|
49813
|
+
validatePath(path26);
|
|
49707
49814
|
}
|
|
49708
49815
|
}
|
|
49709
49816
|
function slowRedact(options = {}) {
|
|
@@ -49871,8 +49978,8 @@ var require_redaction = __commonJS({
|
|
|
49871
49978
|
if (shape[k] === null) {
|
|
49872
49979
|
o[k] = (value) => topCensor(value, [k]);
|
|
49873
49980
|
} else {
|
|
49874
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49875
|
-
return censor(value, [k, ...
|
|
49981
|
+
const wrappedCensor = typeof censor === "function" ? (value, path26) => {
|
|
49982
|
+
return censor(value, [k, ...path26]);
|
|
49876
49983
|
} : censor;
|
|
49877
49984
|
o[k] = Redact({
|
|
49878
49985
|
paths: shape[k],
|
|
@@ -50090,10 +50197,10 @@ var require_atomic_sleep = __commonJS({
|
|
|
50090
50197
|
var require_sonic_boom = __commonJS({
|
|
50091
50198
|
"node_modules/sonic-boom/index.js"(exports, module) {
|
|
50092
50199
|
"use strict";
|
|
50093
|
-
var
|
|
50200
|
+
var fs24 = __require("fs");
|
|
50094
50201
|
var EventEmitter = __require("events");
|
|
50095
50202
|
var inherits = __require("util").inherits;
|
|
50096
|
-
var
|
|
50203
|
+
var path26 = __require("path");
|
|
50097
50204
|
var sleep4 = require_atomic_sleep();
|
|
50098
50205
|
var assert2 = __require("assert");
|
|
50099
50206
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -50147,20 +50254,20 @@ var require_sonic_boom = __commonJS({
|
|
|
50147
50254
|
const mode = sonic.mode;
|
|
50148
50255
|
if (sonic.sync) {
|
|
50149
50256
|
try {
|
|
50150
|
-
if (sonic.mkdir)
|
|
50151
|
-
const fd =
|
|
50257
|
+
if (sonic.mkdir) fs24.mkdirSync(path26.dirname(file), { recursive: true });
|
|
50258
|
+
const fd = fs24.openSync(file, flags, mode);
|
|
50152
50259
|
fileOpened(null, fd);
|
|
50153
50260
|
} catch (err) {
|
|
50154
50261
|
fileOpened(err);
|
|
50155
50262
|
throw err;
|
|
50156
50263
|
}
|
|
50157
50264
|
} else if (sonic.mkdir) {
|
|
50158
|
-
|
|
50265
|
+
fs24.mkdir(path26.dirname(file), { recursive: true }, (err) => {
|
|
50159
50266
|
if (err) return fileOpened(err);
|
|
50160
|
-
|
|
50267
|
+
fs24.open(file, flags, mode, fileOpened);
|
|
50161
50268
|
});
|
|
50162
50269
|
} else {
|
|
50163
|
-
|
|
50270
|
+
fs24.open(file, flags, mode, fileOpened);
|
|
50164
50271
|
}
|
|
50165
50272
|
}
|
|
50166
50273
|
function SonicBoom(opts) {
|
|
@@ -50201,8 +50308,8 @@ var require_sonic_boom = __commonJS({
|
|
|
50201
50308
|
this.flush = flushBuffer;
|
|
50202
50309
|
this.flushSync = flushBufferSync;
|
|
50203
50310
|
this._actualWrite = actualWriteBuffer;
|
|
50204
|
-
fsWriteSync = () =>
|
|
50205
|
-
fsWrite = () =>
|
|
50311
|
+
fsWriteSync = () => fs24.writeSync(this.fd, this._writingBuf);
|
|
50312
|
+
fsWrite = () => fs24.write(this.fd, this._writingBuf, this.release);
|
|
50206
50313
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
50207
50314
|
this._writingBuf = "";
|
|
50208
50315
|
this.write = write;
|
|
@@ -50211,15 +50318,15 @@ var require_sonic_boom = __commonJS({
|
|
|
50211
50318
|
this._actualWrite = actualWrite;
|
|
50212
50319
|
fsWriteSync = () => {
|
|
50213
50320
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
50214
|
-
return
|
|
50321
|
+
return fs24.writeSync(this.fd, this._writingBuf);
|
|
50215
50322
|
}
|
|
50216
|
-
return
|
|
50323
|
+
return fs24.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50217
50324
|
};
|
|
50218
50325
|
fsWrite = () => {
|
|
50219
50326
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
50220
|
-
return
|
|
50327
|
+
return fs24.write(this.fd, this._writingBuf, this.release);
|
|
50221
50328
|
}
|
|
50222
|
-
return
|
|
50329
|
+
return fs24.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
50223
50330
|
};
|
|
50224
50331
|
} else {
|
|
50225
50332
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -50276,7 +50383,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50276
50383
|
}
|
|
50277
50384
|
}
|
|
50278
50385
|
if (this._fsync) {
|
|
50279
|
-
|
|
50386
|
+
fs24.fsyncSync(this.fd);
|
|
50280
50387
|
}
|
|
50281
50388
|
const len = this._len;
|
|
50282
50389
|
if (this._reopening) {
|
|
@@ -50390,7 +50497,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50390
50497
|
const onDrain = () => {
|
|
50391
50498
|
if (!this._fsync) {
|
|
50392
50499
|
try {
|
|
50393
|
-
|
|
50500
|
+
fs24.fsync(this.fd, (err) => {
|
|
50394
50501
|
this._flushPending = false;
|
|
50395
50502
|
cb(err);
|
|
50396
50503
|
});
|
|
@@ -50492,7 +50599,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50492
50599
|
const fd = this.fd;
|
|
50493
50600
|
this.once("ready", () => {
|
|
50494
50601
|
if (fd !== this.fd) {
|
|
50495
|
-
|
|
50602
|
+
fs24.close(fd, (err) => {
|
|
50496
50603
|
if (err) {
|
|
50497
50604
|
return this.emit("error", err);
|
|
50498
50605
|
}
|
|
@@ -50541,7 +50648,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50541
50648
|
buf = this._bufs[0];
|
|
50542
50649
|
}
|
|
50543
50650
|
try {
|
|
50544
|
-
const n = Buffer.isBuffer(buf) ?
|
|
50651
|
+
const n = Buffer.isBuffer(buf) ? fs24.writeSync(this.fd, buf) : fs24.writeSync(this.fd, buf, "utf8");
|
|
50545
50652
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
50546
50653
|
buf = releasedBufObj.writingBuf;
|
|
50547
50654
|
this._len = releasedBufObj.len;
|
|
@@ -50557,7 +50664,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50557
50664
|
}
|
|
50558
50665
|
}
|
|
50559
50666
|
try {
|
|
50560
|
-
|
|
50667
|
+
fs24.fsyncSync(this.fd);
|
|
50561
50668
|
} catch {
|
|
50562
50669
|
}
|
|
50563
50670
|
}
|
|
@@ -50578,7 +50685,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50578
50685
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
50579
50686
|
}
|
|
50580
50687
|
try {
|
|
50581
|
-
const n =
|
|
50688
|
+
const n = fs24.writeSync(this.fd, buf);
|
|
50582
50689
|
buf = buf.subarray(n);
|
|
50583
50690
|
this._len = Math.max(this._len - n, 0);
|
|
50584
50691
|
if (buf.length <= 0) {
|
|
@@ -50606,13 +50713,13 @@ var require_sonic_boom = __commonJS({
|
|
|
50606
50713
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
50607
50714
|
if (this.sync) {
|
|
50608
50715
|
try {
|
|
50609
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
50716
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs24.writeSync(this.fd, this._writingBuf) : fs24.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50610
50717
|
release(null, written);
|
|
50611
50718
|
} catch (err) {
|
|
50612
50719
|
release(err);
|
|
50613
50720
|
}
|
|
50614
50721
|
} else {
|
|
50615
|
-
|
|
50722
|
+
fs24.write(this.fd, this._writingBuf, release);
|
|
50616
50723
|
}
|
|
50617
50724
|
}
|
|
50618
50725
|
function actualWriteBuffer() {
|
|
@@ -50621,7 +50728,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50621
50728
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
50622
50729
|
if (this.sync) {
|
|
50623
50730
|
try {
|
|
50624
|
-
const written =
|
|
50731
|
+
const written = fs24.writeSync(this.fd, this._writingBuf);
|
|
50625
50732
|
release(null, written);
|
|
50626
50733
|
} catch (err) {
|
|
50627
50734
|
release(err);
|
|
@@ -50630,7 +50737,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50630
50737
|
if (kCopyBuffer) {
|
|
50631
50738
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
50632
50739
|
}
|
|
50633
|
-
|
|
50740
|
+
fs24.write(this.fd, this._writingBuf, release);
|
|
50634
50741
|
}
|
|
50635
50742
|
}
|
|
50636
50743
|
function actualClose(sonic) {
|
|
@@ -50646,12 +50753,12 @@ var require_sonic_boom = __commonJS({
|
|
|
50646
50753
|
sonic._lens = [];
|
|
50647
50754
|
assert2(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
50648
50755
|
try {
|
|
50649
|
-
|
|
50756
|
+
fs24.fsync(sonic.fd, closeWrapped);
|
|
50650
50757
|
} catch {
|
|
50651
50758
|
}
|
|
50652
50759
|
function closeWrapped() {
|
|
50653
50760
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
50654
|
-
|
|
50761
|
+
fs24.close(sonic.fd, done);
|
|
50655
50762
|
} else {
|
|
50656
50763
|
done();
|
|
50657
50764
|
}
|
|
@@ -51487,15 +51594,15 @@ var require_transport = __commonJS({
|
|
|
51487
51594
|
if (!unquoted) {
|
|
51488
51595
|
return false;
|
|
51489
51596
|
}
|
|
51490
|
-
let
|
|
51491
|
-
if (
|
|
51597
|
+
let path26 = unquoted;
|
|
51598
|
+
if (path26.startsWith("file://")) {
|
|
51492
51599
|
try {
|
|
51493
|
-
|
|
51600
|
+
path26 = fileURLToPath(path26);
|
|
51494
51601
|
} catch {
|
|
51495
51602
|
return false;
|
|
51496
51603
|
}
|
|
51497
51604
|
}
|
|
51498
|
-
return isAbsolute(
|
|
51605
|
+
return isAbsolute(path26) && !existsSync(path26);
|
|
51499
51606
|
}
|
|
51500
51607
|
function stripQuotes(value) {
|
|
51501
51608
|
const first = value[0];
|
|
@@ -53189,7 +53296,7 @@ var require_multistream = __commonJS({
|
|
|
53189
53296
|
var require_pino = __commonJS({
|
|
53190
53297
|
"node_modules/pino/pino.js"(exports, module) {
|
|
53191
53298
|
"use strict";
|
|
53192
|
-
var
|
|
53299
|
+
var os18 = __require("node:os");
|
|
53193
53300
|
var stdSerializers = require_pino_std_serializers();
|
|
53194
53301
|
var caller = require_caller();
|
|
53195
53302
|
var redaction = require_redaction();
|
|
@@ -53236,7 +53343,7 @@ var require_pino = __commonJS({
|
|
|
53236
53343
|
} = symbols;
|
|
53237
53344
|
var { epochTime, nullTime } = time3;
|
|
53238
53345
|
var { pid } = process;
|
|
53239
|
-
var hostname2 =
|
|
53346
|
+
var hostname2 = os18.hostname();
|
|
53240
53347
|
var defaultErrorSerializer = stdSerializers.err;
|
|
53241
53348
|
var defaultOptions2 = {
|
|
53242
53349
|
level: "info",
|
|
@@ -85562,15 +85669,15 @@ var require_tools2 = __commonJS({
|
|
|
85562
85669
|
* @param {String} path - Mailbox path to encode
|
|
85563
85670
|
* @returns {String} Encoded mailbox path
|
|
85564
85671
|
*/
|
|
85565
|
-
encodePath(connection,
|
|
85566
|
-
|
|
85567
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(
|
|
85672
|
+
encodePath(connection, path26) {
|
|
85673
|
+
path26 = (path26 || "").toString();
|
|
85674
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path26)) {
|
|
85568
85675
|
try {
|
|
85569
|
-
|
|
85676
|
+
path26 = iconv.encode(path26, "utf-7-imap").toString();
|
|
85570
85677
|
} catch {
|
|
85571
85678
|
}
|
|
85572
85679
|
}
|
|
85573
|
-
return
|
|
85680
|
+
return path26;
|
|
85574
85681
|
},
|
|
85575
85682
|
/**
|
|
85576
85683
|
* Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
@@ -85579,15 +85686,15 @@ var require_tools2 = __commonJS({
|
|
|
85579
85686
|
* @param {String} path - Mailbox path to decode
|
|
85580
85687
|
* @returns {String} Decoded mailbox path
|
|
85581
85688
|
*/
|
|
85582
|
-
decodePath(connection,
|
|
85583
|
-
|
|
85584
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(
|
|
85689
|
+
decodePath(connection, path26) {
|
|
85690
|
+
path26 = (path26 || "").toString();
|
|
85691
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path26)) {
|
|
85585
85692
|
try {
|
|
85586
|
-
|
|
85693
|
+
path26 = iconv.decode(Buffer.from(path26), "utf-7-imap").toString();
|
|
85587
85694
|
} catch {
|
|
85588
85695
|
}
|
|
85589
85696
|
}
|
|
85590
|
-
return
|
|
85697
|
+
return path26;
|
|
85591
85698
|
},
|
|
85592
85699
|
/**
|
|
85593
85700
|
* Normalizes a mailbox path by joining array segments with the namespace delimiter,
|
|
@@ -85598,17 +85705,17 @@ var require_tools2 = __commonJS({
|
|
|
85598
85705
|
* @param {Boolean} [skipNamespace] - If true, skips prepending the namespace prefix
|
|
85599
85706
|
* @returns {String} Normalized mailbox path
|
|
85600
85707
|
*/
|
|
85601
|
-
normalizePath(connection,
|
|
85602
|
-
if (Array.isArray(
|
|
85603
|
-
|
|
85708
|
+
normalizePath(connection, path26, skipNamespace) {
|
|
85709
|
+
if (Array.isArray(path26)) {
|
|
85710
|
+
path26 = path26.join(connection.namespace && connection.namespace.delimiter || "");
|
|
85604
85711
|
}
|
|
85605
|
-
if (
|
|
85712
|
+
if (path26.toUpperCase() === "INBOX") {
|
|
85606
85713
|
return "INBOX";
|
|
85607
85714
|
}
|
|
85608
|
-
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !
|
|
85609
|
-
|
|
85715
|
+
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path26.startsWith(connection.namespace.prefix)) {
|
|
85716
|
+
path26 = connection.namespace.prefix + path26;
|
|
85610
85717
|
}
|
|
85611
|
-
return
|
|
85718
|
+
return path26;
|
|
85612
85719
|
},
|
|
85613
85720
|
/**
|
|
85614
85721
|
* Compares two mailbox paths for equality after normalization.
|
|
@@ -85939,14 +86046,14 @@ var require_tools2 = __commonJS({
|
|
|
85939
86046
|
}
|
|
85940
86047
|
}
|
|
85941
86048
|
if (map.emailId || map.uid) {
|
|
85942
|
-
let
|
|
85943
|
-
if (/[\u0080-\uffff]/.test(
|
|
86049
|
+
let path26 = mailbox.path;
|
|
86050
|
+
if (/[\u0080-\uffff]/.test(path26)) {
|
|
85944
86051
|
try {
|
|
85945
|
-
|
|
86052
|
+
path26 = iconv.encode(path26, "utf-7-imap").toString();
|
|
85946
86053
|
} catch {
|
|
85947
86054
|
}
|
|
85948
86055
|
}
|
|
85949
|
-
map.id = map.emailId || createHash2("md5").update([
|
|
86056
|
+
map.id = map.emailId || createHash2("md5").update([path26, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
|
|
85950
86057
|
}
|
|
85951
86058
|
if (map.flags) {
|
|
85952
86059
|
let flagColor = tools.getFlagColor(map.flags);
|
|
@@ -86121,16 +86228,16 @@ var require_tools2 = __commonJS({
|
|
|
86121
86228
|
* @returns {Object} Parsed body structure tree with part numbers, types, parameters, and child nodes
|
|
86122
86229
|
*/
|
|
86123
86230
|
parseBodystructure(entry) {
|
|
86124
|
-
let walk = (node,
|
|
86125
|
-
|
|
86231
|
+
let walk = (node, path26) => {
|
|
86232
|
+
path26 = path26 || [];
|
|
86126
86233
|
let curNode = {}, i = 0, part = 0;
|
|
86127
|
-
if (
|
|
86128
|
-
curNode.part =
|
|
86234
|
+
if (path26.length) {
|
|
86235
|
+
curNode.part = path26.join(".");
|
|
86129
86236
|
}
|
|
86130
86237
|
if (Array.isArray(node[0])) {
|
|
86131
86238
|
curNode.childNodes = [];
|
|
86132
86239
|
while (Array.isArray(node[i])) {
|
|
86133
|
-
curNode.childNodes.push(walk(node[i],
|
|
86240
|
+
curNode.childNodes.push(walk(node[i], path26.concat(++part)));
|
|
86134
86241
|
i++;
|
|
86135
86242
|
}
|
|
86136
86243
|
curNode.type = "multipart/" + ((node[i++] || {}).value || "").toString().toLowerCase();
|
|
@@ -86173,7 +86280,7 @@ var require_tools2 = __commonJS({
|
|
|
86173
86280
|
// the encapsulated message shares the part number with its wrapper.
|
|
86174
86281
|
// Distinction is via suffixes: path.MIME = wrapper headers,
|
|
86175
86282
|
// path.HEADER = encapsulated message headers.
|
|
86176
|
-
walk(node[i],
|
|
86283
|
+
walk(node[i], path26)
|
|
86177
86284
|
];
|
|
86178
86285
|
}
|
|
86179
86286
|
i++;
|
|
@@ -88135,14 +88242,14 @@ var require_select = __commonJS({
|
|
|
88135
88242
|
// update into a silent no-op for the rest of the session.
|
|
88136
88243
|
permanentflags: { key: "permanentFlags", parse: (value) => Array.isArray(value) && new Set(value) }
|
|
88137
88244
|
});
|
|
88138
|
-
module.exports = async (connection,
|
|
88245
|
+
module.exports = async (connection, path26, options) => {
|
|
88139
88246
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88140
88247
|
return;
|
|
88141
88248
|
}
|
|
88142
88249
|
options = options || {};
|
|
88143
|
-
|
|
88144
|
-
if (!connection.folders.has(
|
|
88145
|
-
let folders = await connection.run("LIST", "",
|
|
88250
|
+
path26 = normalizePath(connection, path26);
|
|
88251
|
+
if (!connection.folders.has(path26)) {
|
|
88252
|
+
let folders = await connection.run("LIST", "", path26);
|
|
88146
88253
|
if (!folders) {
|
|
88147
88254
|
throw new Error("Failed to fetch folders");
|
|
88148
88255
|
}
|
|
@@ -88150,10 +88257,10 @@ var require_select = __commonJS({
|
|
|
88150
88257
|
connection.folders.set(folder.path, folder);
|
|
88151
88258
|
});
|
|
88152
88259
|
}
|
|
88153
|
-
let folderListData = connection.folders.has(
|
|
88260
|
+
let folderListData = connection.folders.has(path26) ? connection.folders.get(path26) : false;
|
|
88154
88261
|
let response;
|
|
88155
88262
|
try {
|
|
88156
|
-
let map = { path:
|
|
88263
|
+
let map = { path: path26 };
|
|
88157
88264
|
if (folderListData) {
|
|
88158
88265
|
["delimiter", "specialUse", "subscribed", "listed"].forEach((key) => {
|
|
88159
88266
|
if (folderListData[key]) {
|
|
@@ -88172,7 +88279,7 @@ var require_select = __commonJS({
|
|
|
88172
88279
|
]);
|
|
88173
88280
|
map.qresync = true;
|
|
88174
88281
|
}
|
|
88175
|
-
let encodedPath = encodePath(connection,
|
|
88282
|
+
let encodedPath = encodePath(connection, path26);
|
|
88176
88283
|
let selectCommand = {
|
|
88177
88284
|
command: !options.readOnly ? "SELECT" : "EXAMINE",
|
|
88178
88285
|
/* c8 ignore next */
|
|
@@ -88232,12 +88339,12 @@ var require_select = __commonJS({
|
|
|
88232
88339
|
// since the client's last known state. Only received when QRESYNC was requested.
|
|
88233
88340
|
// A dummy mailbox object is passed because the mailbox isn't officially open yet.
|
|
88234
88341
|
VANISHED: async (untagged) => {
|
|
88235
|
-
await connection.untaggedVanished(untagged, { path:
|
|
88342
|
+
await connection.untaggedVanished(untagged, { path: path26, uidNext: false, uidValidity: false });
|
|
88236
88343
|
},
|
|
88237
88344
|
// Untagged FETCH during SELECT/EXAMINE: only occurs with QRESYNC, delivering
|
|
88238
88345
|
// updated flags for messages that changed since the client's last modseq.
|
|
88239
88346
|
FETCH: async (untagged) => {
|
|
88240
|
-
await connection.untaggedFetch(untagged, { path:
|
|
88347
|
+
await connection.untaggedFetch(untagged, { path: path26, uidNext: false, uidValidity: false });
|
|
88241
88348
|
}
|
|
88242
88349
|
}
|
|
88243
88350
|
});
|
|
@@ -88251,13 +88358,13 @@ var require_select = __commonJS({
|
|
|
88251
88358
|
}
|
|
88252
88359
|
let currentMailbox = connection.mailbox;
|
|
88253
88360
|
connection.mailbox = false;
|
|
88254
|
-
if (currentMailbox && currentMailbox.path !==
|
|
88361
|
+
if (currentMailbox && currentMailbox.path !== path26) {
|
|
88255
88362
|
connection.emit("mailboxClose", currentMailbox);
|
|
88256
88363
|
}
|
|
88257
88364
|
connection.mailbox = map;
|
|
88258
88365
|
connection.currentSelectCommand = selectCommand;
|
|
88259
88366
|
connection.state = connection.states.SELECTED;
|
|
88260
|
-
if (!currentMailbox || currentMailbox.path !==
|
|
88367
|
+
if (!currentMailbox || currentMailbox.path !== path26) {
|
|
88261
88368
|
connection.emit("mailboxOpen", connection.mailbox);
|
|
88262
88369
|
}
|
|
88263
88370
|
response.next();
|
|
@@ -88472,17 +88579,17 @@ var require_create = __commonJS({
|
|
|
88472
88579
|
"node_modules/imapflow/lib/commands/create.js"(exports, module) {
|
|
88473
88580
|
"use strict";
|
|
88474
88581
|
var { encodePath, normalizePath, getStatusCode, enhanceCommandError } = require_tools2();
|
|
88475
|
-
module.exports = async (connection,
|
|
88582
|
+
module.exports = async (connection, path26) => {
|
|
88476
88583
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88477
88584
|
return;
|
|
88478
88585
|
}
|
|
88479
|
-
|
|
88586
|
+
path26 = normalizePath(connection, path26);
|
|
88480
88587
|
let response;
|
|
88481
88588
|
try {
|
|
88482
88589
|
let map = {
|
|
88483
|
-
path:
|
|
88590
|
+
path: path26
|
|
88484
88591
|
};
|
|
88485
|
-
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection,
|
|
88592
|
+
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88486
88593
|
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;
|
|
88487
88594
|
if (section) {
|
|
88488
88595
|
let key;
|
|
@@ -88508,13 +88615,13 @@ var require_create = __commonJS({
|
|
|
88508
88615
|
}
|
|
88509
88616
|
map.created = true;
|
|
88510
88617
|
response.next();
|
|
88511
|
-
await connection.run("SUBSCRIBE",
|
|
88618
|
+
await connection.run("SUBSCRIBE", path26);
|
|
88512
88619
|
return map;
|
|
88513
88620
|
} catch (err) {
|
|
88514
88621
|
let errorCode = getStatusCode(err.response);
|
|
88515
88622
|
if (errorCode === "ALREADYEXISTS") {
|
|
88516
88623
|
return {
|
|
88517
|
-
path:
|
|
88624
|
+
path: path26,
|
|
88518
88625
|
created: false
|
|
88519
88626
|
};
|
|
88520
88627
|
}
|
|
@@ -88531,20 +88638,20 @@ var require_delete = __commonJS({
|
|
|
88531
88638
|
"node_modules/imapflow/lib/commands/delete.js"(exports, module) {
|
|
88532
88639
|
"use strict";
|
|
88533
88640
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88534
|
-
module.exports = async (connection,
|
|
88641
|
+
module.exports = async (connection, path26) => {
|
|
88535
88642
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88536
88643
|
return;
|
|
88537
88644
|
}
|
|
88538
|
-
|
|
88539
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88645
|
+
path26 = normalizePath(connection, path26);
|
|
88646
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path26) {
|
|
88540
88647
|
await connection.run("CLOSE");
|
|
88541
88648
|
}
|
|
88542
88649
|
let response;
|
|
88543
88650
|
try {
|
|
88544
88651
|
let map = {
|
|
88545
|
-
path:
|
|
88652
|
+
path: path26
|
|
88546
88653
|
};
|
|
88547
|
-
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection,
|
|
88654
|
+
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88548
88655
|
response.next();
|
|
88549
88656
|
return map;
|
|
88550
88657
|
} catch (err) {
|
|
@@ -88561,23 +88668,23 @@ var require_rename = __commonJS({
|
|
|
88561
88668
|
"node_modules/imapflow/lib/commands/rename.js"(exports, module) {
|
|
88562
88669
|
"use strict";
|
|
88563
88670
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88564
|
-
module.exports = async (connection,
|
|
88671
|
+
module.exports = async (connection, path26, newPath) => {
|
|
88565
88672
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88566
88673
|
return;
|
|
88567
88674
|
}
|
|
88568
|
-
|
|
88675
|
+
path26 = normalizePath(connection, path26);
|
|
88569
88676
|
newPath = normalizePath(connection, newPath);
|
|
88570
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88677
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path26) {
|
|
88571
88678
|
await connection.run("CLOSE");
|
|
88572
88679
|
}
|
|
88573
88680
|
let response;
|
|
88574
88681
|
try {
|
|
88575
88682
|
let map = {
|
|
88576
|
-
path:
|
|
88683
|
+
path: path26,
|
|
88577
88684
|
newPath
|
|
88578
88685
|
};
|
|
88579
88686
|
response = await connection.exec("RENAME", [
|
|
88580
|
-
{ type: "ATOM", value: encodePath(connection,
|
|
88687
|
+
{ type: "ATOM", value: encodePath(connection, path26) },
|
|
88581
88688
|
{ type: "ATOM", value: encodePath(connection, newPath) }
|
|
88582
88689
|
]);
|
|
88583
88690
|
response.next();
|
|
@@ -88624,14 +88731,14 @@ var require_subscribe = __commonJS({
|
|
|
88624
88731
|
"node_modules/imapflow/lib/commands/subscribe.js"(exports, module) {
|
|
88625
88732
|
"use strict";
|
|
88626
88733
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88627
|
-
module.exports = async (connection,
|
|
88734
|
+
module.exports = async (connection, path26) => {
|
|
88628
88735
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88629
88736
|
return;
|
|
88630
88737
|
}
|
|
88631
|
-
|
|
88738
|
+
path26 = normalizePath(connection, path26);
|
|
88632
88739
|
let response;
|
|
88633
88740
|
try {
|
|
88634
|
-
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88741
|
+
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88635
88742
|
response.next();
|
|
88636
88743
|
return true;
|
|
88637
88744
|
} catch (err) {
|
|
@@ -88648,14 +88755,14 @@ var require_unsubscribe = __commonJS({
|
|
|
88648
88755
|
"node_modules/imapflow/lib/commands/unsubscribe.js"(exports, module) {
|
|
88649
88756
|
"use strict";
|
|
88650
88757
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88651
|
-
module.exports = async (connection,
|
|
88758
|
+
module.exports = async (connection, path26) => {
|
|
88652
88759
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88653
88760
|
return;
|
|
88654
88761
|
}
|
|
88655
|
-
|
|
88762
|
+
path26 = normalizePath(connection, path26);
|
|
88656
88763
|
let response;
|
|
88657
88764
|
try {
|
|
88658
|
-
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88765
|
+
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88659
88766
|
response.next();
|
|
88660
88767
|
return true;
|
|
88661
88768
|
} catch (err) {
|
|
@@ -89461,11 +89568,11 @@ var require_status = __commonJS({
|
|
|
89461
89568
|
var { encodePath, normalizePath, buildStatusQueryAttributes, isRev2Active } = require_tools2();
|
|
89462
89569
|
var { parseStatusList } = require_status_fields();
|
|
89463
89570
|
var MAILBOX_UPDATERS = {
|
|
89464
|
-
messages: (value, connection,
|
|
89571
|
+
messages: (value, connection, path26) => {
|
|
89465
89572
|
let prevCount = connection.mailbox.exists;
|
|
89466
89573
|
if (prevCount !== value) {
|
|
89467
89574
|
connection.mailbox.exists = value;
|
|
89468
|
-
connection.emit("exists", { path:
|
|
89575
|
+
connection.emit("exists", { path: path26, count: value, prevCount });
|
|
89469
89576
|
}
|
|
89470
89577
|
},
|
|
89471
89578
|
uidNext: (value, connection) => {
|
|
@@ -89475,28 +89582,28 @@ var require_status = __commonJS({
|
|
|
89475
89582
|
connection.mailbox.highestModseq = value;
|
|
89476
89583
|
}
|
|
89477
89584
|
};
|
|
89478
|
-
module.exports = async (connection,
|
|
89479
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89585
|
+
module.exports = async (connection, path26, query) => {
|
|
89586
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path26) {
|
|
89480
89587
|
return false;
|
|
89481
89588
|
}
|
|
89482
|
-
|
|
89483
|
-
let encodedPath = encodePath(connection,
|
|
89589
|
+
path26 = normalizePath(connection, path26);
|
|
89590
|
+
let encodedPath = encodePath(connection, path26);
|
|
89484
89591
|
let attributes = [{ type: encodedPath.indexOf("&") >= 0 ? "STRING" : "ATOM", value: encodedPath }];
|
|
89485
89592
|
let queryAttributes = buildStatusQueryAttributes(connection, query);
|
|
89486
89593
|
let syntheticRecent = query && query.recent && isRev2Active(connection);
|
|
89487
89594
|
if (!queryAttributes.length) {
|
|
89488
|
-
return syntheticRecent ? { path:
|
|
89595
|
+
return syntheticRecent ? { path: path26, recent: 0 } : false;
|
|
89489
89596
|
}
|
|
89490
89597
|
attributes.push(queryAttributes);
|
|
89491
89598
|
let response;
|
|
89492
89599
|
try {
|
|
89493
|
-
let map = { path:
|
|
89600
|
+
let map = { path: path26 };
|
|
89494
89601
|
response = await connection.exec("STATUS", attributes, {
|
|
89495
89602
|
untagged: {
|
|
89496
89603
|
// STATUS response: * STATUS <mailbox> (<key> <value> <key> <value> ...)
|
|
89497
89604
|
// Parsed as alternating key-value pairs (i % 2 pattern).
|
|
89498
89605
|
STATUS: async (untagged) => {
|
|
89499
|
-
let updateCurrent = connection.state === connection.states.SELECTED &&
|
|
89606
|
+
let updateCurrent = connection.state === connection.states.SELECTED && path26 === connection.mailbox.path;
|
|
89500
89607
|
let list = untagged.attributes && Array.isArray(untagged.attributes[1]) ? untagged.attributes[1] : false;
|
|
89501
89608
|
if (!list) {
|
|
89502
89609
|
return;
|
|
@@ -89504,7 +89611,7 @@ var require_status = __commonJS({
|
|
|
89504
89611
|
parseStatusList(list, (key, value) => {
|
|
89505
89612
|
map[key] = value;
|
|
89506
89613
|
if (updateCurrent && MAILBOX_UPDATERS[key]) {
|
|
89507
|
-
MAILBOX_UPDATERS[key](value, connection,
|
|
89614
|
+
MAILBOX_UPDATERS[key](value, connection, path26);
|
|
89508
89615
|
}
|
|
89509
89616
|
});
|
|
89510
89617
|
}
|
|
@@ -89517,9 +89624,9 @@ var require_status = __commonJS({
|
|
|
89517
89624
|
return map;
|
|
89518
89625
|
} catch (err) {
|
|
89519
89626
|
if (err.responseStatus === "NO") {
|
|
89520
|
-
let folders = await connection.run("LIST", "",
|
|
89627
|
+
let folders = await connection.run("LIST", "", path26, { listOnly: true });
|
|
89521
89628
|
if (folders && !folders.length) {
|
|
89522
|
-
let error2 = new Error(`Mailbox doesn't exist: ${
|
|
89629
|
+
let error2 = new Error(`Mailbox doesn't exist: ${path26}`);
|
|
89523
89630
|
error2.code = "NotFound";
|
|
89524
89631
|
error2.response = err;
|
|
89525
89632
|
throw error2;
|
|
@@ -89666,15 +89773,15 @@ var require_quota = __commonJS({
|
|
|
89666
89773
|
"node_modules/imapflow/lib/commands/quota.js"(exports, module) {
|
|
89667
89774
|
"use strict";
|
|
89668
89775
|
var { encodePath, normalizePath, enhanceCommandError, parseUintValue, isUnsafeKey } = require_tools2();
|
|
89669
|
-
module.exports = async (connection,
|
|
89670
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89776
|
+
module.exports = async (connection, path26) => {
|
|
89777
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path26) {
|
|
89671
89778
|
return;
|
|
89672
89779
|
}
|
|
89673
89780
|
if (!connection.capabilities.has("QUOTA")) {
|
|
89674
89781
|
return false;
|
|
89675
89782
|
}
|
|
89676
|
-
|
|
89677
|
-
let map = { path:
|
|
89783
|
+
path26 = normalizePath(connection, path26);
|
|
89784
|
+
let map = { path: path26 };
|
|
89678
89785
|
let processQuotaResponse = (untagged) => {
|
|
89679
89786
|
let attributes = untagged.attributes && untagged.attributes[1];
|
|
89680
89787
|
if (!attributes || !attributes.length) {
|
|
@@ -89714,7 +89821,7 @@ var require_quota = __commonJS({
|
|
|
89714
89821
|
let quotaFound = false;
|
|
89715
89822
|
let response;
|
|
89716
89823
|
try {
|
|
89717
|
-
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection,
|
|
89824
|
+
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path26) }], {
|
|
89718
89825
|
untagged: {
|
|
89719
89826
|
// QUOTAROOT response tells us which quota root applies to this mailbox.
|
|
89720
89827
|
// A mailbox may have zero or one quota root.
|
|
@@ -89857,15 +89964,15 @@ var require_idle = __commonJS({
|
|
|
89857
89964
|
}
|
|
89858
89965
|
}
|
|
89859
89966
|
async function pollOnce2(connection, session) {
|
|
89860
|
-
let
|
|
89967
|
+
let path26 = connection.mailbox && connection.mailbox.path;
|
|
89861
89968
|
switch (connection.missingIdleCommand) {
|
|
89862
89969
|
case "SELECT":
|
|
89863
89970
|
connection.log.debug({ src: "c", msg: `Running SELECT to detect changes in folder`, cid: connection.id });
|
|
89864
|
-
await connection.runInternal("SELECT",
|
|
89971
|
+
await connection.runInternal("SELECT", path26, { readOnly: session.selectCommand.command === "EXAMINE" });
|
|
89865
89972
|
break;
|
|
89866
89973
|
case "STATUS": {
|
|
89867
89974
|
connection.log.debug({ src: "c", msg: `Running STATUS to detect changes in folder`, cid: connection.id });
|
|
89868
|
-
let status = await connection.runInternal("STATUS",
|
|
89975
|
+
let status = await connection.runInternal("STATUS", path26, {
|
|
89869
89976
|
messages: true,
|
|
89870
89977
|
uidNext: true,
|
|
89871
89978
|
uidValidity: true,
|
|
@@ -91552,12 +91659,12 @@ var require_imap_flow = __commonJS({
|
|
|
91552
91659
|
this.emit("flags", updateEvent);
|
|
91553
91660
|
}
|
|
91554
91661
|
}
|
|
91555
|
-
async ensureSelectedMailbox(
|
|
91556
|
-
if (!
|
|
91662
|
+
async ensureSelectedMailbox(path26) {
|
|
91663
|
+
if (!path26) {
|
|
91557
91664
|
return false;
|
|
91558
91665
|
}
|
|
91559
|
-
if (!this.mailbox || !comparePaths(this, this.mailbox.path,
|
|
91560
|
-
return await this.mailboxOpen(
|
|
91666
|
+
if (!this.mailbox || !comparePaths(this, this.mailbox.path, path26)) {
|
|
91667
|
+
return await this.mailboxOpen(path26);
|
|
91561
91668
|
}
|
|
91562
91669
|
return true;
|
|
91563
91670
|
}
|
|
@@ -91972,9 +92079,9 @@ var require_imap_flow = __commonJS({
|
|
|
91972
92079
|
* let quota = await client.getQuota();
|
|
91973
92080
|
* console.log(quota.storage.used, quota.storage.limit)
|
|
91974
92081
|
*/
|
|
91975
|
-
async getQuota(
|
|
91976
|
-
|
|
91977
|
-
return await this.run("QUOTA",
|
|
92082
|
+
async getQuota(path26) {
|
|
92083
|
+
path26 = path26 || "INBOX";
|
|
92084
|
+
return await this.run("QUOTA", path26);
|
|
91978
92085
|
}
|
|
91979
92086
|
/**
|
|
91980
92087
|
* @typedef {Object} ListResponse
|
|
@@ -92084,8 +92191,8 @@ var require_imap_flow = __commonJS({
|
|
|
92084
92191
|
* console.log(info.path);
|
|
92085
92192
|
* // "INBOX.parent.child" // assumes "INBOX." as namespace prefix and "." as delimiter
|
|
92086
92193
|
*/
|
|
92087
|
-
async mailboxCreate(
|
|
92088
|
-
return await this.run("CREATE",
|
|
92194
|
+
async mailboxCreate(path26) {
|
|
92195
|
+
return await this.run("CREATE", path26);
|
|
92089
92196
|
}
|
|
92090
92197
|
/**
|
|
92091
92198
|
* @typedef {Object} MailboxRenameResponse
|
|
@@ -92106,8 +92213,8 @@ var require_imap_flow = __commonJS({
|
|
|
92106
92213
|
* console.log(info.newPath);
|
|
92107
92214
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
92108
92215
|
*/
|
|
92109
|
-
async mailboxRename(
|
|
92110
|
-
return await this.run("RENAME",
|
|
92216
|
+
async mailboxRename(path26, newPath) {
|
|
92217
|
+
return await this.run("RENAME", path26, newPath);
|
|
92111
92218
|
}
|
|
92112
92219
|
/**
|
|
92113
92220
|
* @typedef {Object} MailboxDeleteResponse
|
|
@@ -92126,8 +92233,8 @@ var require_imap_flow = __commonJS({
|
|
|
92126
92233
|
* console.log(info.path);
|
|
92127
92234
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
92128
92235
|
*/
|
|
92129
|
-
async mailboxDelete(
|
|
92130
|
-
return await this.run("DELETE",
|
|
92236
|
+
async mailboxDelete(path26) {
|
|
92237
|
+
return await this.run("DELETE", path26);
|
|
92131
92238
|
}
|
|
92132
92239
|
/**
|
|
92133
92240
|
* Subscribes to a mailbox
|
|
@@ -92138,8 +92245,8 @@ var require_imap_flow = __commonJS({
|
|
|
92138
92245
|
* @example
|
|
92139
92246
|
* await client.mailboxSubscribe('Important stuff ❗️');
|
|
92140
92247
|
*/
|
|
92141
|
-
async mailboxSubscribe(
|
|
92142
|
-
return await this.run("SUBSCRIBE",
|
|
92248
|
+
async mailboxSubscribe(path26) {
|
|
92249
|
+
return await this.run("SUBSCRIBE", path26);
|
|
92143
92250
|
}
|
|
92144
92251
|
/**
|
|
92145
92252
|
* Unsubscribes from a mailbox
|
|
@@ -92150,8 +92257,8 @@ var require_imap_flow = __commonJS({
|
|
|
92150
92257
|
* @example
|
|
92151
92258
|
* await client.mailboxUnsubscribe('Important stuff ❗️');
|
|
92152
92259
|
*/
|
|
92153
|
-
async mailboxUnsubscribe(
|
|
92154
|
-
return await this.run("UNSUBSCRIBE",
|
|
92260
|
+
async mailboxUnsubscribe(path26) {
|
|
92261
|
+
return await this.run("UNSUBSCRIBE", path26);
|
|
92155
92262
|
}
|
|
92156
92263
|
/**
|
|
92157
92264
|
* Opens a mailbox to access messages. You can perform message operations only against an opened mailbox.
|
|
@@ -92169,8 +92276,8 @@ var require_imap_flow = __commonJS({
|
|
|
92169
92276
|
* console.log(mailbox.exists);
|
|
92170
92277
|
* // 125
|
|
92171
92278
|
*/
|
|
92172
|
-
async mailboxOpen(
|
|
92173
|
-
return await this.run("SELECT",
|
|
92279
|
+
async mailboxOpen(path26, options) {
|
|
92280
|
+
return await this.run("SELECT", path26, options);
|
|
92174
92281
|
}
|
|
92175
92282
|
/**
|
|
92176
92283
|
* Closes a previously opened mailbox
|
|
@@ -92217,8 +92324,8 @@ var require_imap_flow = __commonJS({
|
|
|
92217
92324
|
* console.log(status.unseen);
|
|
92218
92325
|
* // 123
|
|
92219
92326
|
*/
|
|
92220
|
-
async status(
|
|
92221
|
-
return await this.run("STATUS",
|
|
92327
|
+
async status(path26, query) {
|
|
92328
|
+
return await this.run("STATUS", path26, query);
|
|
92222
92329
|
}
|
|
92223
92330
|
/**
|
|
92224
92331
|
* Starts listening for new or deleted messages from the currently opened mailbox. Only required if {@link ImapFlow#disableAutoIdle} is set to `true`
|
|
@@ -92472,8 +92579,8 @@ var require_imap_flow = __commonJS({
|
|
|
92472
92579
|
* @example
|
|
92473
92580
|
* await client.append('INBOX', rawMessageBuffer, ['\\Seen'], new Date(2000, 1, 1));
|
|
92474
92581
|
*/
|
|
92475
|
-
async append(
|
|
92476
|
-
return await this.run("APPEND",
|
|
92582
|
+
async append(path26, content, flags, idate) {
|
|
92583
|
+
return await this.run("APPEND", path26, content, flags, idate) || false;
|
|
92477
92584
|
}
|
|
92478
92585
|
/**
|
|
92479
92586
|
* @typedef {Object} CopyResponseObject
|
|
@@ -93317,7 +93424,7 @@ var require_imap_flow = __commonJS({
|
|
|
93317
93424
|
await new Promise((resolve2) => setImmediate(resolve2));
|
|
93318
93425
|
}
|
|
93319
93426
|
const lock = this.locks.shift();
|
|
93320
|
-
const { resolve, reject, path:
|
|
93427
|
+
const { resolve, reject, path: path26, options, lockId } = lock;
|
|
93321
93428
|
if (lock.acquireTimer) {
|
|
93322
93429
|
clearTimeout(lock.acquireTimer);
|
|
93323
93430
|
lock.acquireTimer = null;
|
|
@@ -93333,7 +93440,7 @@ var require_imap_flow = __commonJS({
|
|
|
93333
93440
|
this.log.warn({
|
|
93334
93441
|
msg: "Mailbox lock held for a long time",
|
|
93335
93442
|
lockId: lock.lockId,
|
|
93336
|
-
path:
|
|
93443
|
+
path: path26,
|
|
93337
93444
|
heldFor: Date.now() - lock.heldAt,
|
|
93338
93445
|
/* c8 ignore next */
|
|
93339
93446
|
// the held-lock-warning diagnostic with a description set is a timing-dependent log detail
|
|
@@ -93369,52 +93476,52 @@ var require_imap_flow = __commonJS({
|
|
|
93369
93476
|
}
|
|
93370
93477
|
};
|
|
93371
93478
|
if (!this.usable || !this.socket || this.socket.destroyed) {
|
|
93372
|
-
this.log.trace({ msg: "Failed to acquire mailbox lock", path:
|
|
93479
|
+
this.log.trace({ msg: "Failed to acquire mailbox lock", path: path26, lockId, idling: this.idling });
|
|
93373
93480
|
let error2 = new Error("Connection not available");
|
|
93374
93481
|
error2.code = "NoConnection";
|
|
93375
93482
|
reject(error2);
|
|
93376
93483
|
continue;
|
|
93377
93484
|
}
|
|
93378
|
-
if (this.mailbox && this.mailbox.path ===
|
|
93485
|
+
if (this.mailbox && this.mailbox.path === path26 && !!this.mailbox.readOnly === !!options.readOnly) {
|
|
93379
93486
|
this.log.trace({
|
|
93380
93487
|
msg: "Mailbox lock acquired [existing]",
|
|
93381
|
-
path:
|
|
93488
|
+
path: path26,
|
|
93382
93489
|
lockId,
|
|
93383
93490
|
idling: this.idling,
|
|
93384
93491
|
...options.description && { description: options.description }
|
|
93385
93492
|
});
|
|
93386
93493
|
this.currentLock = lock;
|
|
93387
93494
|
armHeldTimer();
|
|
93388
|
-
resolve({ path:
|
|
93495
|
+
resolve({ path: path26, release });
|
|
93389
93496
|
break;
|
|
93390
93497
|
}
|
|
93391
93498
|
try {
|
|
93392
|
-
await this.mailboxOpen(
|
|
93499
|
+
await this.mailboxOpen(path26, options);
|
|
93393
93500
|
this.log.trace({
|
|
93394
93501
|
msg: "Mailbox lock acquired [selected]",
|
|
93395
|
-
path:
|
|
93502
|
+
path: path26,
|
|
93396
93503
|
lockId,
|
|
93397
93504
|
idling: this.idling,
|
|
93398
93505
|
...options.description && { description: options.description }
|
|
93399
93506
|
});
|
|
93400
93507
|
this.currentLock = lock;
|
|
93401
93508
|
armHeldTimer();
|
|
93402
|
-
resolve({ path:
|
|
93509
|
+
resolve({ path: path26, release });
|
|
93403
93510
|
break;
|
|
93404
93511
|
} catch (err) {
|
|
93405
93512
|
if (err.responseStatus === "NO") {
|
|
93406
93513
|
try {
|
|
93407
|
-
let folders = await this.run("LIST", "",
|
|
93514
|
+
let folders = await this.run("LIST", "", path26, { listOnly: true });
|
|
93408
93515
|
if (!folders || !folders.length) {
|
|
93409
93516
|
err.mailboxMissing = true;
|
|
93410
93517
|
}
|
|
93411
93518
|
} catch (E) {
|
|
93412
|
-
this.log.trace({ msg: "Failed to verify failed mailbox", path:
|
|
93519
|
+
this.log.trace({ msg: "Failed to verify failed mailbox", path: path26, err: E });
|
|
93413
93520
|
}
|
|
93414
93521
|
}
|
|
93415
93522
|
this.log.trace({
|
|
93416
93523
|
msg: "Failed to acquire mailbox lock",
|
|
93417
|
-
path:
|
|
93524
|
+
path: path26,
|
|
93418
93525
|
lockId,
|
|
93419
93526
|
idling: this.idling,
|
|
93420
93527
|
...options.description && { description: options.description },
|
|
@@ -93453,13 +93560,13 @@ var require_imap_flow = __commonJS({
|
|
|
93453
93560
|
* lock.release();
|
|
93454
93561
|
* }
|
|
93455
93562
|
*/
|
|
93456
|
-
getMailboxLock(
|
|
93563
|
+
getMailboxLock(path26, options) {
|
|
93457
93564
|
options = options || {};
|
|
93458
|
-
|
|
93565
|
+
path26 = normalizePath(this, path26);
|
|
93459
93566
|
let lockId = ++this.lockCounter;
|
|
93460
93567
|
this.log.trace({
|
|
93461
93568
|
msg: "Requesting lock",
|
|
93462
|
-
path:
|
|
93569
|
+
path: path26,
|
|
93463
93570
|
lockId,
|
|
93464
93571
|
...options.description && { description: options.description },
|
|
93465
93572
|
activeLock: this.currentLock ? {
|
|
@@ -93468,7 +93575,7 @@ var require_imap_flow = __commonJS({
|
|
|
93468
93575
|
} : null
|
|
93469
93576
|
});
|
|
93470
93577
|
let lockPromise = new Promise((resolve, reject) => {
|
|
93471
|
-
let lockEntry = { resolve, reject, path:
|
|
93578
|
+
let lockEntry = { resolve, reject, path: path26, options, lockId };
|
|
93472
93579
|
this.locks.push(lockEntry);
|
|
93473
93580
|
if (Number(options.acquireTimeout) > 0) {
|
|
93474
93581
|
lockEntry.acquireTimer = setTimeout(() => {
|
|
@@ -93557,16 +93664,16 @@ var require_imap_flow = __commonJS({
|
|
|
93557
93664
|
});
|
|
93558
93665
|
|
|
93559
93666
|
// src/mail/mail-fetcher.ts
|
|
93560
|
-
import
|
|
93561
|
-
import
|
|
93667
|
+
import fs23 from "node:fs/promises";
|
|
93668
|
+
import path24 from "node:path";
|
|
93562
93669
|
async function saveAttachments(attachments, downloadDir) {
|
|
93563
93670
|
if (attachments.length === 0) return [];
|
|
93564
|
-
await
|
|
93671
|
+
await fs23.mkdir(downloadDir, { recursive: true });
|
|
93565
93672
|
const saved = [];
|
|
93566
93673
|
for (const a of attachments) {
|
|
93567
|
-
const name =
|
|
93568
|
-
const savedPath =
|
|
93569
|
-
await
|
|
93674
|
+
const name = path24.basename(a.filename) || "attachment";
|
|
93675
|
+
const savedPath = path24.join(downloadDir, name);
|
|
93676
|
+
await fs23.writeFile(savedPath, a.content);
|
|
93570
93677
|
saved.push({ filename: name, savedPath, size: a.content.length });
|
|
93571
93678
|
}
|
|
93572
93679
|
return saved;
|
|
@@ -93696,8 +93803,8 @@ var init_mail_fetcher = __esm({
|
|
|
93696
93803
|
});
|
|
93697
93804
|
|
|
93698
93805
|
// src/tools/fetch-mail.ts
|
|
93699
|
-
import
|
|
93700
|
-
import
|
|
93806
|
+
import os17 from "node:os";
|
|
93807
|
+
import path25 from "node:path";
|
|
93701
93808
|
function registerFetchMailTool(server, deps = {}) {
|
|
93702
93809
|
const makeFetcher = deps.fetcherFactory ?? ((creds) => new ImapflowMailFetcher(creds));
|
|
93703
93810
|
server.registerTool(
|
|
@@ -93759,7 +93866,7 @@ var init_fetch_mail = __esm({
|
|
|
93759
93866
|
init_mail_fetcher();
|
|
93760
93867
|
init_auth_error();
|
|
93761
93868
|
init_validate();
|
|
93762
|
-
DEFAULT_DOWNLOAD_DIR =
|
|
93869
|
+
DEFAULT_DOWNLOAD_DIR = path25.join(os17.homedir(), ".cogent", "mail-downloads");
|
|
93763
93870
|
}
|
|
93764
93871
|
});
|
|
93765
93872
|
|