local-operator-ui 0.50.10 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/main/index.js +2644 -110
- package/out/preload/index.js +44 -0
- package/out/renderer/assets/{_basePickBy-DX2vtBnL.js → _basePickBy-BVSSU18O.js} +1 -1
- package/out/renderer/assets/{_baseUniq-8nUx5tta.js → _baseUniq-B__JwgHi.js} +1 -1
- package/out/renderer/assets/{agent-details-page-BwRenXaH.js → agent-details-page-BsYVdmzO.js} +1 -1
- package/out/renderer/assets/{agent-hub-page-Bt2-_wDt.js → agent-hub-page-DZkxOIeT.js} +1 -1
- package/out/renderer/assets/{agents-page-MLOL_fjS.js → agents-page-BP23XRdh.js} +3 -3
- package/out/renderer/assets/{appearance-_LetIhUt.js → appearance-lpVg4gQj.js} +33 -33
- package/out/renderer/assets/{approvalsOverlay-CZyctJKg.js → approvalsOverlay-gydsG6RR.js} +1 -1
- package/out/renderer/assets/{arc-DY2eas1G.js → arc-CjxAaqLx.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-D43gR5TN.js → architectureDiagram-IEHRJDOE-DpQvA_J6.js} +1 -1
- package/out/renderer/assets/{avatar-cropper-DRD5tvZV.js → avatar-cropper-B6rrysn1.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-CYYT4Gq9.js → blockDiagram-JOT3LUYC-CuJf62a7.js} +1 -1
- package/out/renderer/assets/{book-open-D_8LQHNl.js → book-open-BEct2VH9.js} +1 -1
- package/out/renderer/assets/browser-page-WI5dp2f1.js +1 -0
- package/out/renderer/assets/{browser-webauthn-prompt-D_WlgxhO.js → browser-webauthn-prompt-CLC3fFA-.js} +1 -1
- package/out/renderer/assets/{building-2-tIpP_TRE.js → building-2-BqUQJLNY.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-DTMQzVkX.js → c4Diagram-VJAJSXHY-Anqh9KmL.js} +1 -1
- package/out/renderer/assets/channel-Blh5RUVy.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-xIzHcII2.js → chunk-4BMEZGHF-CsAilUXq.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-BvE5VHF9.js → chunk-A2AXSNBT-dqYk3OOP.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-DSJKMouk.js → chunk-AEK57VVT-WaYBoAz4.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-CnCHkWBv.js → chunk-D6G4REZN-CC4xFCKO.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-Dt0gFt7e.js → chunk-RZ5BOZE2-C3w1cBuM.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-BE5Ygz7W.js → chunk-XZIHB7SX-DDLDo133.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-CwrdDD9k.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-CwrdDD9k.js +1 -0
- package/out/renderer/assets/clone-Dj43Y3F4.js +1 -0
- package/out/renderer/assets/{console-mirror-DD-zCoIu.js → console-mirror-71NfT98h.js} +1 -1
- package/out/renderer/assets/{consoleCapture-heHKTAlO.js → consoleCapture-BecJOVi8.js} +1 -1
- package/out/renderer/assets/{conversation-input-sync-BYvYQk__.js → conversation-input-sync-BKSemkSj.js} +5 -5
- package/out/renderer/assets/{dagre-OKDRZEBW-BlZ2j-W_.js → dagre-OKDRZEBW-kk1xnDMk.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-Op_lwA-U.js → diagram-SSKATNLV-Ch0IbZF3.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-QpYB731n.js → diagram-VNBRO52H-BLpDkSXW.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-DcgCFCqD.js → erDiagram-Q7BY3M3F-CN9Uoq7g.js} +1 -1
- package/out/renderer/assets/{error-boundary-DlgiXR_W.js → error-boundary-CuVJfBf2.js} +2 -2
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-1yld7vlv.js → flowDiagram-4HSFHLVR-CrYhaMrG.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-BWF4c5yi.js → ganttDiagram-APWFNJXF-Uqfq1vx8.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-EbbrikBg.js → gitGraphDiagram-7IBYFJ6S-CLwypteT.js} +1 -1
- package/out/renderer/assets/{graph-B4NXXjis.js → graph-CwtsXuHO.js} +1 -1
- package/out/renderer/assets/{heart-BCK87brK.js → heart-9RVhRlFa.js} +1 -1
- package/out/renderer/assets/index-BoDLJYdZ.css +1 -0
- package/out/renderer/assets/{index-CKCRDY7e.js → index-D693hxME.js} +1 -1
- package/out/renderer/assets/{index-CrzksILW.js → index-DZyuOgxf.js} +1 -1
- package/out/renderer/assets/{index-B1_NLQUS.js → index-Hog_22vH.js} +4 -4
- package/out/renderer/assets/{index-B_QzzAzx.js → index-PBtdY_-a.js} +1 -1
- package/out/renderer/assets/infoDiagram-PH2N3AL5-C93DteXe.js +2 -0
- package/out/renderer/assets/{installer-B0kiahjw.js → installer-A0Xw5num.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-CQceKjsG.js → journeyDiagram-U35MCT3I-CYfv3Ncv.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-Cv2pg1KM.js → kanban-definition-NDS4AKOZ-BT_YdWQU.js} +1 -1
- package/out/renderer/assets/{layout-nfa7kN-L.js → layout-MPZUGFMW.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-4vR_EZHf.js → legacy-agents-page-DwdAXW0T.js} +1 -1
- package/out/renderer/assets/{library-page-BuLYPMtg.js → library-page-DLv1Vty9.js} +3 -3
- package/out/renderer/assets/{log-in-CCynzL3t.js → log-in-CndeKg-B.js} +1 -1
- package/out/renderer/assets/{mermaid.core-BHeS_iEC.js → mermaid.core-CLQz7-Qn.js} +19 -19
- package/out/renderer/assets/{mesh-page-Cx8KFod8.js → mesh-page-BFGsPg09.js} +1 -1
- package/out/renderer/assets/{messages-CB08eCJU.js → messages-Cw_Hdnl7.js} +1 -1
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-CnmYWjfj.js → mindmap-definition-ALO5MXBD-DOkeMC8X.js} +1 -1
- package/out/renderer/assets/{mini-CC0lESP8.js → mini-2ZoK9xmR.js} +1 -1
- package/out/renderer/assets/{notebook-pen-CVBxcim-.js → notebook-pen-BIz3-t17.js} +1 -1
- package/out/renderer/assets/{notifications-page-QB_iF3Bb.js → notifications-page-AfFbPkfO.js} +1 -1
- package/out/renderer/assets/{org-access-KugiSPMP.js → org-access-CjxPUBoc.js} +1 -1
- package/out/renderer/assets/{org-surface-gate-D0BIeXUd.js → org-surface-gate-Eq5OlxlI.js} +1 -1
- package/out/renderer/assets/{page-header-BxwBWZTf.js → page-header-CeJbbeKR.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-CzMSZNFh.js → pieDiagram-IB7DONF6-DOdoTFu0.js} +1 -1
- package/out/renderer/assets/{project-markdown-DZKgumvs.js → project-markdown-BJKpECAe.js} +1 -1
- package/out/renderer/assets/{projects-page-BTcQ7SHt.js → projects-page-D3of_Bxi.js} +1 -1
- package/out/renderer/assets/{publication-validation-CSLq9YnU.js → publication-validation-CDZEhXi8.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-DJpsFO5x.js → quadrantDiagram-7GDLP6J5-DQqcuqjH.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-Cnt3l_Dp.js → radar-MK3ICKWK-1gYy_tIP.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-UYiAtSf1.js → radient-auth-buttons-Ckmxjych.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-B6LQN9Qj.js → requirementDiagram-KVF5MWMF-D1TzPEUj.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-CcGxMBWT.js → sankeyDiagram-QLVOVGJD-DT2cb-OH.js} +1 -1
- package/out/renderer/assets/{schedules-page-C8l3oRyh.js → schedules-page-CvNaKbsi.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-Dbxqa-TN.js → sequenceDiagram-X6HHIX6F-CJ2X9TL2.js} +1 -1
- package/out/renderer/assets/{settings-page-Bqse7pru.js → settings-page-DW5cEUNG.js} +1 -1
- package/out/renderer/assets/{smartart-0ADFoRvV.js → smartart-EKvMQPSD.js} +1 -1
- package/out/renderer/assets/{stateDiagram-DGXRK772-CGi6OIz6.js → stateDiagram-DGXRK772-IXEjKhTD.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-0NMEsfWC.js +1 -0
- package/out/renderer/assets/{team-bridge-page-BbsuRmiK.js → team-bridge-page-DSc3F5yn.js} +20 -20
- package/out/renderer/assets/{team-bridge-scope-preference-C2e4c1br.js → team-bridge-scope-preference-BiCaCgX9.js} +1 -1
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-BsHRcICB.js → timeline-definition-BDJGKUSR-BrVErWJ5.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-puwgX4W8.js → use-download-agent-mutation-T4cjc79l.js} +1 -1
- package/out/renderer/assets/{use-session-snapshot-BSfMhkpZ.js → use-session-snapshot-BcAA9I4V.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-DUxmeIt0.js → xychartDiagram-VJFVF3MP-Co9gVA7y.js} +1 -1
- package/out/renderer/browser-approvals-overlay.html +2 -2
- package/out/renderer/console-capture.html +6 -6
- package/out/renderer/index.html +8 -8
- package/out/renderer/installer.html +5 -5
- package/out/renderer/mini.html +8 -8
- package/package.json +1 -1
- package/out/renderer/assets/browser-page-DzMgDqr4.js +0 -1
- package/out/renderer/assets/channel-CcOJV3TW.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-Emm0LqvV.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-Emm0LqvV.js +0 -1
- package/out/renderer/assets/clone-651v7dGy.js +0 -1
- package/out/renderer/assets/index-BiKEZgcN.css +0 -1
- package/out/renderer/assets/infoDiagram-PH2N3AL5-C_2n3NVi.js +0 -2
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-Beo2gD1r.js +0 -1
package/out/main/index.js
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
2
24
|
const fs = require("node:fs");
|
|
3
25
|
const path$1 = require("node:path");
|
|
4
26
|
const node_url = require("node:url");
|
|
@@ -11,9 +33,9 @@ const node_child_process = require("node:child_process");
|
|
|
11
33
|
const node_crypto = require("node:crypto");
|
|
12
34
|
const os = require("node:os");
|
|
13
35
|
const node_util = require("node:util");
|
|
36
|
+
const promises = require("node:fs/promises");
|
|
14
37
|
const dotenv = require("dotenv");
|
|
15
38
|
const electronLog = require("electron-log");
|
|
16
|
-
const promises = require("node:fs/promises");
|
|
17
39
|
const node_net = require("node:net");
|
|
18
40
|
const require$$0 = require("node:process");
|
|
19
41
|
const require$$0$1 = require("node:buffer");
|
|
@@ -59688,7 +59710,7 @@ const viUiTeamBridge = {
|
|
|
59688
59710
|
"ui.teamBridge.composer.placeholder_to": "Nhắn tin cho {name}",
|
|
59689
59711
|
"ui.teamBridge.thread.today": "Hôm nay",
|
|
59690
59712
|
"ui.teamBridge.thread.yesterday": "Hôm qua",
|
|
59691
|
-
"ui.teamBridge.builtin.general_topic": "Toàn bộ tổ chức: mọi người và tác nhân của họ. Tác nhân xem mọi tin nhắn và trả lời khi được nhắc đến bằng @ hoặc trong các luồng
|
|
59713
|
+
"ui.teamBridge.builtin.general_topic": "Toàn bộ tổ chức: mọi người và tác nhân của họ. Tác nhân xem mọi tin nhắn và trả lời khi được nhắc đến bằng @ hoặc trong các luồng mà tác nhân theo dõi.",
|
|
59692
59714
|
"ui.teamBridge.builtin.humans_topic": "Chỉ con người, không có tác nhân. Tin nhắn ở đây sẽ gửi thông báo đến từng người.",
|
|
59693
59715
|
"ui.teamBridge.builtin.agents_topic": "Chánh văn phòng của mọi đồng nghiệp. Tác nhân xem mọi tin nhắn và trả lời khi có liên quan hoặc khi được nhắc đến bằng @.",
|
|
59694
59716
|
"ui.teamBridge.section.channels_add": "Tạo kênh",
|
|
@@ -69606,6 +69628,11 @@ function appendJournalOrderIds(query2, path2, ids) {
|
|
|
69606
69628
|
}
|
|
69607
69629
|
return selected;
|
|
69608
69630
|
}
|
|
69631
|
+
const LINK_PREVIEW_MAX_URL_CHARS = 4096;
|
|
69632
|
+
const LINK_PREVIEW_ACCOUNT_MAX_CHARS = 128;
|
|
69633
|
+
const LINK_PREVIEW_ARTIFACT_ID = /^[0-9a-f]{32}$/;
|
|
69634
|
+
const LINK_PREVIEW_RESOLVE_CHANNEL = "link-preview:resolve";
|
|
69635
|
+
const LINK_PREVIEW_ARTIFACT_CHANNEL = "link-preview:artifact";
|
|
69609
69636
|
const DOT_ONLY_VARIABLE_KEY = /^\.+$/;
|
|
69610
69637
|
const PUBLICATION_FORMAT_POINT = /\p{Cf}/u;
|
|
69611
69638
|
const PUBLICATION_PATH_SEPARATOR = /[/\\:]/;
|
|
@@ -72390,6 +72417,27 @@ const desktopRequestUnion = zod.z.discriminatedUnion("op", [
|
|
|
72390
72417
|
op: zod.z.literal("team_bridge.status"),
|
|
72391
72418
|
boundary: agentMessagesBoundarySchema.optional()
|
|
72392
72419
|
}).strict(),
|
|
72420
|
+
/*
|
|
72421
|
+
* THE LINK-PREVIEW RESOLVE PROXY (`features`-free: core owns the capability, and
|
|
72422
|
+
* a resolve that is refused answers a STATE, never an error of this plane).
|
|
72423
|
+
*
|
|
72424
|
+
* The URL is length-bounded at core's own ceiling (`MAX_URL_CHARS` in
|
|
72425
|
+
* `server/routes/desktop_link_preview.py`), so a renderer value can never make
|
|
72426
|
+
* main serialize a body core refuses on size alone. `index` has a lower bound
|
|
72427
|
+
* and no upper one, deliberately mirroring the route: a position past the
|
|
72428
|
+
* per-message cap is the `cap` answer, not a shape error.
|
|
72429
|
+
*
|
|
72430
|
+
* `expectedAccountId` is the RECEIPT every Team Bridge op already carries. Main
|
|
72431
|
+
* holds no signed-in identity of its own to substitute, and core compares the
|
|
72432
|
+
* string against the identity the install actually holds and refuses a mismatch
|
|
72433
|
+
* (409), so forwarding it grants nothing.
|
|
72434
|
+
*/
|
|
72435
|
+
zod.z.object({
|
|
72436
|
+
op: zod.z.literal("team_bridge.link_preview.resolve"),
|
|
72437
|
+
url: zod.z.string().min(1).max(LINK_PREVIEW_MAX_URL_CHARS),
|
|
72438
|
+
index: zod.z.number().int().nonnegative(),
|
|
72439
|
+
expectedAccountId: id$1
|
|
72440
|
+
}).strict(),
|
|
72393
72441
|
zod.z.object({ op: zod.z.literal("settings.list") }).strict(),
|
|
72394
72442
|
zod.z.object({
|
|
72395
72443
|
op: zod.z.literal("settings.edit"),
|
|
@@ -75480,6 +75528,26 @@ function desktopEndpoint(request) {
|
|
|
75480
75528
|
method: "GET"
|
|
75481
75529
|
};
|
|
75482
75530
|
}
|
|
75531
|
+
/*
|
|
75532
|
+
* THE LINK-PREVIEW RESOLVE PROXY. A POST because the receipt travels in the
|
|
75533
|
+
* body: core takes `expected_account_id` from the body here and from a HEADER
|
|
75534
|
+
* on the artifact route, and never from a query string, so no intermediary's
|
|
75535
|
+
* log or crash report records whose preview was asked for.
|
|
75536
|
+
*
|
|
75537
|
+
* The receipt is forwarded, never derived: `expected_account_id` is what the
|
|
75538
|
+
* caller says it is, core compares it against the identity the install holds,
|
|
75539
|
+
* and a mismatch is a 409 the renderer draws as "sign in as that account".
|
|
75540
|
+
*/
|
|
75541
|
+
case "team_bridge.link_preview.resolve":
|
|
75542
|
+
return {
|
|
75543
|
+
path: "/v1/desktop/team-bridge/link-preview/resolve",
|
|
75544
|
+
method: "POST",
|
|
75545
|
+
body: {
|
|
75546
|
+
url: request.url,
|
|
75547
|
+
index: request.index,
|
|
75548
|
+
expected_account_id: request.expectedAccountId
|
|
75549
|
+
}
|
|
75550
|
+
};
|
|
75483
75551
|
case "settings.list":
|
|
75484
75552
|
return { path: "/v1/settings", method: "GET" };
|
|
75485
75553
|
case "settings.edit":
|
|
@@ -76557,11 +76625,15 @@ class AppAttentionService {
|
|
|
76557
76625
|
this.account = null;
|
|
76558
76626
|
this.cursor = void 0;
|
|
76559
76627
|
this.projection.setBridgeUnread(0, this.projection.currentGeneration);
|
|
76628
|
+
this.ports.principalChanged?.();
|
|
76560
76629
|
this.invalidate();
|
|
76561
76630
|
} else if (writes.has(op)) {
|
|
76562
76631
|
if (op.startsWith("team_bridge.")) this.invalidateBridge();
|
|
76563
76632
|
else this.invalidate();
|
|
76564
76633
|
}
|
|
76634
|
+
if (returnedPrincipal !== void 0) {
|
|
76635
|
+
this.ports.principalResolved?.(returnedPrincipal);
|
|
76636
|
+
}
|
|
76565
76637
|
}
|
|
76566
76638
|
invalidateBridge() {
|
|
76567
76639
|
if (this.stopped) return;
|
|
@@ -76664,6 +76736,7 @@ class AppAttentionService {
|
|
|
76664
76736
|
this.cursor = void 0;
|
|
76665
76737
|
this.projection.setBridgeUnread(0, projectionGeneration);
|
|
76666
76738
|
}
|
|
76739
|
+
this.ports.principalResolved?.(account);
|
|
76667
76740
|
if (!account) continue;
|
|
76668
76741
|
const unread = this.body(
|
|
76669
76742
|
await this.ports.request({
|
|
@@ -76934,7 +77007,7 @@ function toAttachment(payload) {
|
|
|
76934
77007
|
stored_path: typeof record.stored_path === "string" ? record.stored_path : null
|
|
76935
77008
|
};
|
|
76936
77009
|
}
|
|
76937
|
-
function refusalDetail(payload) {
|
|
77010
|
+
function refusalDetail$1(payload) {
|
|
76938
77011
|
if (payload === null || typeof payload !== "object") return null;
|
|
76939
77012
|
const detail = payload.detail;
|
|
76940
77013
|
if (typeof detail === "string" && detail.trim()) return detail;
|
|
@@ -77056,7 +77129,7 @@ async function uploadAttachment(input) {
|
|
|
77056
77129
|
return {
|
|
77057
77130
|
success: false,
|
|
77058
77131
|
code: "refused",
|
|
77059
|
-
error: refusalDetail(payload) ?? `The daemon refused the upload (HTTP ${response.status}).`,
|
|
77132
|
+
error: refusalDetail$1(payload) ?? `The daemon refused the upload (HTTP ${response.status}).`,
|
|
77060
77133
|
sizeBytes: size
|
|
77061
77134
|
};
|
|
77062
77135
|
}
|
|
@@ -80350,6 +80423,623 @@ class DesktopFeedRelay {
|
|
|
80350
80423
|
}
|
|
80351
80424
|
}
|
|
80352
80425
|
}
|
|
80426
|
+
const ARTIFACT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
80427
|
+
const ARTIFACT_MAX_BYTES = 64 * 1024 * 1024;
|
|
80428
|
+
const ARTIFACT_MAX_COUNT = 400;
|
|
80429
|
+
const ARTIFACT_SWEEP_INTERVAL_MS = 5 * 60 * 1e3;
|
|
80430
|
+
const ARTIFACT_MAX_BLOB_BYTES = 4 * 1024 * 1024;
|
|
80431
|
+
const ARTIFACT_ALLOWED_MIMES = /* @__PURE__ */ new Set([
|
|
80432
|
+
"image/png",
|
|
80433
|
+
"image/jpeg",
|
|
80434
|
+
"image/gif",
|
|
80435
|
+
"image/webp",
|
|
80436
|
+
"image/vnd.microsoft.icon"
|
|
80437
|
+
]);
|
|
80438
|
+
const PRINCIPAL_FINGERPRINT = /^[0-9a-f]{32}$/;
|
|
80439
|
+
const INDEX_FILE$1 = "index.json";
|
|
80440
|
+
const INDEX_VERSION$1 = 3;
|
|
80441
|
+
const DIRECTORY_MODE$1 = 448;
|
|
80442
|
+
const FILE_MODE$1 = 384;
|
|
80443
|
+
function artifactOwnerFingerprint(accountId) {
|
|
80444
|
+
return node_crypto.createHash("sha256").update(`link-preview-account\0${accountId}`).digest("hex").slice(0, 32);
|
|
80445
|
+
}
|
|
80446
|
+
class LinkPreviewArtifactCache {
|
|
80447
|
+
dir;
|
|
80448
|
+
now;
|
|
80449
|
+
ttlMs;
|
|
80450
|
+
maxBytes;
|
|
80451
|
+
maxArtifacts;
|
|
80452
|
+
sweepIntervalMs;
|
|
80453
|
+
entries = /* @__PURE__ */ new Map();
|
|
80454
|
+
residentBytes = 0;
|
|
80455
|
+
evictions = 0;
|
|
80456
|
+
hits = 0;
|
|
80457
|
+
misses = 0;
|
|
80458
|
+
foreignHits = 0;
|
|
80459
|
+
lastSweep = Number.NEGATIVE_INFINITY;
|
|
80460
|
+
opened = false;
|
|
80461
|
+
/**
|
|
80462
|
+
* The fence. Bumped by EVERY `clear()`, synchronously, before its work is queued —
|
|
80463
|
+
* that is what makes a clear a point in time rather than a pass over whatever is
|
|
80464
|
+
* indexed when its turn comes. A caller that begins a network round trip takes
|
|
80465
|
+
* `currentEpoch()` first and hands it to `store`, which refuses to write when it no
|
|
80466
|
+
* longer matches: a fetch that was in flight when the principal changed cannot
|
|
80467
|
+
* re-create the departing account's artifact afterwards.
|
|
80468
|
+
*
|
|
80469
|
+
* WHY THIS CACHE GREW A FENCE TOO, rather than only the Team Bridge image cache it
|
|
80470
|
+
* was the model for: two caches with two different answers to "what happens to the
|
|
80471
|
+
* bytes when the principal moves" is how a repository ends up with one private-byte
|
|
80472
|
+
* rule that holds and one that mostly holds. The shapes are the same on purpose.
|
|
80473
|
+
*/
|
|
80474
|
+
epoch = 0;
|
|
80475
|
+
/** The fingerprint these bytes are bound to, or `null` when nothing is bound. */
|
|
80476
|
+
boundPrincipal = null;
|
|
80477
|
+
/** The fingerprint THIS PROCESS has confirmed, or `null` until the app first names
|
|
80478
|
+
* a principal. `boundPrincipal` is loaded from disc and says what the bytes belong
|
|
80479
|
+
* to; this says what this process has verified. A fence that fired while this is
|
|
80480
|
+
* still `null` would wipe the cache on the first status of every launch, so the
|
|
80481
|
+
* fence defers to `bind` until a principal has actually been confirmed. */
|
|
80482
|
+
confirmedPrincipal = null;
|
|
80483
|
+
/** A `clear()` that arrived before `open()` finished. Honoured by `open`, and kept
|
|
80484
|
+
* if `open` fails: a later successful `open` still drops the bytes. */
|
|
80485
|
+
clearRequested = false;
|
|
80486
|
+
/** Read recency (`lastUsedAt`) has moved in memory and the index has not been
|
|
80487
|
+
* rewritten since; flushed by the throttled sweep, not per read. */
|
|
80488
|
+
indexDirty = false;
|
|
80489
|
+
/** Serializes every mutating pass, so two concurrent writers cannot interleave
|
|
80490
|
+
* a sweep with a store and leave the index accounting for a file that is gone.
|
|
80491
|
+
* `read` is queued too: a read that could be answered while a `clear` is in
|
|
80492
|
+
* flight would hand out the departing account's bytes. */
|
|
80493
|
+
queue = Promise.resolve();
|
|
80494
|
+
constructor(options) {
|
|
80495
|
+
this.dir = options.dir;
|
|
80496
|
+
this.now = options.now ?? (() => Date.now());
|
|
80497
|
+
this.ttlMs = options.ttlMs ?? ARTIFACT_TTL_MS;
|
|
80498
|
+
this.maxBytes = options.maxBytes ?? ARTIFACT_MAX_BYTES;
|
|
80499
|
+
this.maxArtifacts = options.maxArtifacts ?? ARTIFACT_MAX_COUNT;
|
|
80500
|
+
this.sweepIntervalMs = options.sweepIntervalMs ?? ARTIFACT_SWEEP_INTERVAL_MS;
|
|
80501
|
+
}
|
|
80502
|
+
/** The directory this cache owns. Named so a test can assert a file's presence
|
|
80503
|
+
* without re-deriving the path. */
|
|
80504
|
+
get directory() {
|
|
80505
|
+
return this.dir;
|
|
80506
|
+
}
|
|
80507
|
+
/** The fence value a store must carry back; see `epoch` and `store`. */
|
|
80508
|
+
currentEpoch() {
|
|
80509
|
+
return this.epoch;
|
|
80510
|
+
}
|
|
80511
|
+
/**
|
|
80512
|
+
* Create the directory, load the index, apply the principal state check, delete
|
|
80513
|
+
* files no entry describes, and apply the bounds once.
|
|
80514
|
+
*
|
|
80515
|
+
* `principal` is the account this app currently holds, when it already knows one.
|
|
80516
|
+
* `null` — the shipped launch, where the window is created long before any status
|
|
80517
|
+
* response arrives — means "not known yet", NOT "signed out": the entries are kept
|
|
80518
|
+
* and `bind` decides as soon as the app names a principal. Treating that `null` as
|
|
80519
|
+
* a sign-out would delete the cache at every start, which is the whole restart
|
|
80520
|
+
* benefit, and it would buy nothing: a read can only be answered for the fingerprint
|
|
80521
|
+
* that stored the entry, and the transition fence drops the bytes the moment an
|
|
80522
|
+
* identity actually moves.
|
|
80523
|
+
*
|
|
80524
|
+
* STARTUP IS THE ONE UNCONDITIONAL SWEEP. The interval below bounds how often a
|
|
80525
|
+
* read or write may sweep, which would otherwise let a cold cache keep expired
|
|
80526
|
+
* bytes for five minutes after launch; a process that starts with a full disk
|
|
80527
|
+
* and a stale index should not wait for a card to be drawn before it recovers
|
|
80528
|
+
* the space.
|
|
80529
|
+
*/
|
|
80530
|
+
async open(principal = null) {
|
|
80531
|
+
await promises.mkdir(this.dir, { recursive: true, mode: DIRECTORY_MODE$1 });
|
|
80532
|
+
await promises.chmod(this.dir, DIRECTORY_MODE$1).catch(() => {
|
|
80533
|
+
});
|
|
80534
|
+
await this.loadIndex();
|
|
80535
|
+
const loadedPrincipal = this.boundPrincipal;
|
|
80536
|
+
this.opened = true;
|
|
80537
|
+
await this.serialize(async () => {
|
|
80538
|
+
if (this.clearRequested) {
|
|
80539
|
+
this.clearRequested = false;
|
|
80540
|
+
await this.clearLocked();
|
|
80541
|
+
return;
|
|
80542
|
+
}
|
|
80543
|
+
if (principal !== null) {
|
|
80544
|
+
const fingerprint = artifactOwnerFingerprint(principal);
|
|
80545
|
+
let changed = loadedPrincipal !== fingerprint;
|
|
80546
|
+
for (const [id2, entry] of [...this.entries]) {
|
|
80547
|
+
if (entry.account === fingerprint) continue;
|
|
80548
|
+
this.forgetEntry(id2);
|
|
80549
|
+
changed = true;
|
|
80550
|
+
}
|
|
80551
|
+
this.boundPrincipal = fingerprint;
|
|
80552
|
+
this.confirmedPrincipal = fingerprint;
|
|
80553
|
+
if (changed) await this.persistIndex();
|
|
80554
|
+
await this.removeOrphans();
|
|
80555
|
+
await this.sweepNow();
|
|
80556
|
+
return;
|
|
80557
|
+
}
|
|
80558
|
+
await this.removeOrphans();
|
|
80559
|
+
await this.sweepNow();
|
|
80560
|
+
});
|
|
80561
|
+
this.lastSweep = this.now();
|
|
80562
|
+
}
|
|
80563
|
+
/**
|
|
80564
|
+
* THE STATE CHECK: bind these bytes to the principal the app has just confirmed.
|
|
80565
|
+
*
|
|
80566
|
+
* Wired to the attention service's own two principal sources (`principalResolved`
|
|
80567
|
+
* in `index.ts`), so it runs on a renderer status AND on the reconcile poll —
|
|
80568
|
+
* which is what makes the invariant independent of which of the two answers first.
|
|
80569
|
+
* The three outcomes, all deliberate:
|
|
80570
|
+
*
|
|
80571
|
+
* - same fingerprint: nothing happens. This is what keeps a cache across a
|
|
80572
|
+
* restart, and it is what #1721's `principalChanged`-only wiring could not do.
|
|
80573
|
+
* - a different fingerprint: the previous account's bytes are dropped.
|
|
80574
|
+
* - `null` (a VERIFIED sign-out, which is the only way `null` reaches here): the
|
|
80575
|
+
* bytes are dropped, because no identity means no identity's images.
|
|
80576
|
+
*/
|
|
80577
|
+
async bind(accountId) {
|
|
80578
|
+
if (accountId === null) {
|
|
80579
|
+
if (this.boundPrincipal !== null) await this.clear();
|
|
80580
|
+
return;
|
|
80581
|
+
}
|
|
80582
|
+
const fingerprint = artifactOwnerFingerprint(accountId);
|
|
80583
|
+
if (this.boundPrincipal === fingerprint) {
|
|
80584
|
+
this.confirmedPrincipal = fingerprint;
|
|
80585
|
+
return;
|
|
80586
|
+
}
|
|
80587
|
+
if (this.boundPrincipal !== null) await this.clear();
|
|
80588
|
+
this.boundPrincipal = fingerprint;
|
|
80589
|
+
this.confirmedPrincipal = fingerprint;
|
|
80590
|
+
await this.serialize(() => this.persistIndex());
|
|
80591
|
+
}
|
|
80592
|
+
/**
|
|
80593
|
+
* THE TRANSITION FENCE: an identity move this process has observed.
|
|
80594
|
+
*
|
|
80595
|
+
* A no-op until a principal has been CONFIRMED here, because the same signal fires
|
|
80596
|
+
* for `null -> <account>` at every launch, and a fence that wipes its own cache at
|
|
80597
|
+
* boot is not a fence — that was the #1721 wiring this replaces.
|
|
80598
|
+
*/
|
|
80599
|
+
async fence() {
|
|
80600
|
+
if (this.confirmedPrincipal === null) return;
|
|
80601
|
+
await this.clear();
|
|
80602
|
+
}
|
|
80603
|
+
/** Every cached id currently indexed, oldest use first. Diagnostics and tests
|
|
80604
|
+
* only: the bytes are addressed one id at a time. */
|
|
80605
|
+
ids() {
|
|
80606
|
+
return [...this.entries.entries()].sort((a, b) => a[1].lastUsedAt - b[1].lastUsedAt).map(([id2]) => id2);
|
|
80607
|
+
}
|
|
80608
|
+
stats() {
|
|
80609
|
+
return {
|
|
80610
|
+
entries: this.entries.size,
|
|
80611
|
+
residentBytes: this.residentBytes,
|
|
80612
|
+
evictions: this.evictions,
|
|
80613
|
+
hits: this.hits,
|
|
80614
|
+
misses: this.misses,
|
|
80615
|
+
foreignHits: this.foreignHits
|
|
80616
|
+
};
|
|
80617
|
+
}
|
|
80618
|
+
/**
|
|
80619
|
+
* The bytes for one id, for the receipt that asks, or `null`.
|
|
80620
|
+
*
|
|
80621
|
+
* An id that is not in the index is a miss without a filesystem call. An id
|
|
80622
|
+
* whose entry belongs to a DIFFERENT receipt is also a miss — and deliberately
|
|
80623
|
+
* not a deletion: the other account's entry is still the right answer for its
|
|
80624
|
+
* own card, and this request must now go and ask core, which is the authority
|
|
80625
|
+
* on whose scope names what.
|
|
80626
|
+
*
|
|
80627
|
+
* An entry that IS in the index but whose file has gone is a miss too, and the
|
|
80628
|
+
* entry is dropped, so the next lookup does not pay for the same stat. An
|
|
80629
|
+
* expired entry is a miss and is removed at the next sweep, so a read never
|
|
80630
|
+
* depends on when a sweep last ran.
|
|
80631
|
+
*/
|
|
80632
|
+
async read(id2, accountFingerprint) {
|
|
80633
|
+
if (!this.opened) return null;
|
|
80634
|
+
const epoch = this.epoch;
|
|
80635
|
+
return this.serialize(async () => {
|
|
80636
|
+
if (epoch !== this.epoch) {
|
|
80637
|
+
this.misses += 1;
|
|
80638
|
+
return null;
|
|
80639
|
+
}
|
|
80640
|
+
const entry = this.entries.get(id2);
|
|
80641
|
+
if (entry === void 0) {
|
|
80642
|
+
this.misses += 1;
|
|
80643
|
+
return null;
|
|
80644
|
+
}
|
|
80645
|
+
if (entry.account !== accountFingerprint) {
|
|
80646
|
+
this.foreignHits += 1;
|
|
80647
|
+
return null;
|
|
80648
|
+
}
|
|
80649
|
+
if (!ARTIFACT_ALLOWED_MIMES.has(entry.mime)) {
|
|
80650
|
+
this.misses += 1;
|
|
80651
|
+
return null;
|
|
80652
|
+
}
|
|
80653
|
+
if (entry.size > ARTIFACT_MAX_BLOB_BYTES) {
|
|
80654
|
+
this.forgetEntry(id2);
|
|
80655
|
+
this.misses += 1;
|
|
80656
|
+
return null;
|
|
80657
|
+
}
|
|
80658
|
+
if (this.now() - entry.storedAt >= this.ttlMs) {
|
|
80659
|
+
this.misses += 1;
|
|
80660
|
+
return null;
|
|
80661
|
+
}
|
|
80662
|
+
let bytes;
|
|
80663
|
+
try {
|
|
80664
|
+
bytes = new Uint8Array(await promises.readFile(path$1.join(this.dir, id2)));
|
|
80665
|
+
} catch {
|
|
80666
|
+
this.forgetEntry(id2);
|
|
80667
|
+
this.misses += 1;
|
|
80668
|
+
return null;
|
|
80669
|
+
}
|
|
80670
|
+
if (bytes.byteLength !== entry.size) {
|
|
80671
|
+
this.forgetEntry(id2);
|
|
80672
|
+
this.misses += 1;
|
|
80673
|
+
return null;
|
|
80674
|
+
}
|
|
80675
|
+
entry.lastUsedAt = this.now();
|
|
80676
|
+
this.indexDirty = true;
|
|
80677
|
+
this.hits += 1;
|
|
80678
|
+
void this.maybeSweep();
|
|
80679
|
+
return { mime: entry.mime, bytes };
|
|
80680
|
+
});
|
|
80681
|
+
}
|
|
80682
|
+
/**
|
|
80683
|
+
* Keep one blob for one receipt, then re-apply the bounds if they are exceeded.
|
|
80684
|
+
*
|
|
80685
|
+
* A blob over `ARTIFACT_MAX_BLOB_BYTES` is refused before anything is written:
|
|
80686
|
+
* storing it would evict several legitimate artifacts to hold something core
|
|
80687
|
+
* would never have produced. So is a mime outside `ARTIFACT_ALLOWED_MIMES` and
|
|
80688
|
+
* an id that is not one (see the header's note on `image/svg+xml` and on the
|
|
80689
|
+
* file name being a path segment).
|
|
80690
|
+
*/
|
|
80691
|
+
async store(id2, mime, bytes, accountFingerprint, epoch = this.epoch) {
|
|
80692
|
+
if (!this.opened) return;
|
|
80693
|
+
if (bytes.byteLength === 0 || bytes.byteLength > ARTIFACT_MAX_BLOB_BYTES)
|
|
80694
|
+
return;
|
|
80695
|
+
if (!ARTIFACT_ALLOWED_MIMES.has(mime)) return;
|
|
80696
|
+
if (!LINK_PREVIEW_ARTIFACT_ID.test(id2)) return;
|
|
80697
|
+
await this.serialize(async () => {
|
|
80698
|
+
if (epoch !== this.epoch) {
|
|
80699
|
+
return;
|
|
80700
|
+
}
|
|
80701
|
+
const path2 = path$1.join(this.dir, id2);
|
|
80702
|
+
const temp = `${path2}.${process.pid}.${node_crypto.randomBytes(6).toString("hex")}.tmp`;
|
|
80703
|
+
try {
|
|
80704
|
+
await promises.writeFile(temp, bytes, { mode: FILE_MODE$1 });
|
|
80705
|
+
await promises.rename(temp, path2);
|
|
80706
|
+
} catch {
|
|
80707
|
+
await promises.rm(temp, { force: true }).catch(() => {
|
|
80708
|
+
});
|
|
80709
|
+
return;
|
|
80710
|
+
}
|
|
80711
|
+
const at = this.now();
|
|
80712
|
+
this.rememberEntry(id2, {
|
|
80713
|
+
mime,
|
|
80714
|
+
size: bytes.byteLength,
|
|
80715
|
+
storedAt: at,
|
|
80716
|
+
// A fresh blob is the newest thing here: its storedAt starts its TTL,
|
|
80717
|
+
// and its lastUsedAt is now, so it is the last thing an LRU pass takes.
|
|
80718
|
+
lastUsedAt: at,
|
|
80719
|
+
account: accountFingerprint
|
|
80720
|
+
});
|
|
80721
|
+
this.boundPrincipal = accountFingerprint;
|
|
80722
|
+
await this.persistIndex();
|
|
80723
|
+
await this.sweepNow();
|
|
80724
|
+
});
|
|
80725
|
+
}
|
|
80726
|
+
/**
|
|
80727
|
+
* Forget specific artifacts — the "disabled"/"absent" rule's only mechanism.
|
|
80728
|
+
*
|
|
80729
|
+
* Called with the ids a preview was holding, so the bytes cannot outlive the
|
|
80730
|
+
* card that asked for them: a cached artifact must not survive
|
|
80731
|
+
* `web_fetch.enabled: false` being turned on-after-off, and a preview that has
|
|
80732
|
+
* since answered `absent` must not keep drawing its old picture.
|
|
80733
|
+
*
|
|
80734
|
+
* Never fails a caller: a blob that cannot be deleted is dropped from the index
|
|
80735
|
+
* anyway, because an unindexed file is unreachable and the next startup's
|
|
80736
|
+
* orphan pass removes it.
|
|
80737
|
+
*/
|
|
80738
|
+
async drop(ids) {
|
|
80739
|
+
if (!this.opened || ids.length === 0) return;
|
|
80740
|
+
await this.serialize(async () => {
|
|
80741
|
+
let changed = false;
|
|
80742
|
+
for (const id2 of ids) {
|
|
80743
|
+
if (!this.forgetEntry(id2)) continue;
|
|
80744
|
+
changed = true;
|
|
80745
|
+
try {
|
|
80746
|
+
await promises.rm(path$1.join(this.dir, id2), { force: true });
|
|
80747
|
+
} catch {
|
|
80748
|
+
}
|
|
80749
|
+
}
|
|
80750
|
+
if (changed) await this.persistIndex();
|
|
80751
|
+
});
|
|
80752
|
+
}
|
|
80753
|
+
/**
|
|
80754
|
+
* Drop EVERY cached blob — the principal-transition rule.
|
|
80755
|
+
*
|
|
80756
|
+
* A sign-out or account switch must not leave the previous account's images on
|
|
80757
|
+
* disk for the remainder of their TTL. This is deliberately a full clear rather
|
|
80758
|
+
* than a per-account drop: at the moment the fence fires this process no longer
|
|
80759
|
+
* knows which receipts its entries belonged to, and keeping some of them is
|
|
80760
|
+
* worth less than the guarantee that none of them are the departing account's.
|
|
80761
|
+
*/
|
|
80762
|
+
async clear() {
|
|
80763
|
+
this.epoch += 1;
|
|
80764
|
+
if (!this.opened) {
|
|
80765
|
+
this.clearRequested = true;
|
|
80766
|
+
}
|
|
80767
|
+
await this.serialize(() => this.clearLocked());
|
|
80768
|
+
}
|
|
80769
|
+
/**
|
|
80770
|
+
* The wipe itself, always inside the queue: forget every entry, write the empty
|
|
80771
|
+
* index, then delete every file the (now empty) index does not describe.
|
|
80772
|
+
*
|
|
80773
|
+
* Unlink AFTER the index is clean: an interrupted clear then leaves orphans (which
|
|
80774
|
+
* startup collects) rather than live entries with no files. `removeOrphans` also
|
|
80775
|
+
* collects files `loadIndex` never admitted, which is what lets a pre-open clear
|
|
80776
|
+
* empty a directory whose index has not been read yet.
|
|
80777
|
+
*/
|
|
80778
|
+
async clearLocked() {
|
|
80779
|
+
const ids = [...this.entries.keys()];
|
|
80780
|
+
for (const id2 of ids) this.forgetEntry(id2);
|
|
80781
|
+
this.boundPrincipal = null;
|
|
80782
|
+
this.confirmedPrincipal = null;
|
|
80783
|
+
this.indexDirty = false;
|
|
80784
|
+
await this.persistIndex();
|
|
80785
|
+
await this.removeOrphans();
|
|
80786
|
+
}
|
|
80787
|
+
/** Apply the bounds now, whatever the interval says. */
|
|
80788
|
+
async sweep() {
|
|
80789
|
+
if (!this.opened) return;
|
|
80790
|
+
await this.serialize(async () => {
|
|
80791
|
+
await this.sweepNow();
|
|
80792
|
+
this.lastSweep = this.now();
|
|
80793
|
+
});
|
|
80794
|
+
}
|
|
80795
|
+
/**
|
|
80796
|
+
* Give up one entry and its bytes from the accounting.
|
|
80797
|
+
*
|
|
80798
|
+
* THE ONLY PLACE `residentBytes` MAY DECREASE, and it decreases exactly when
|
|
80799
|
+
* this call actually removed the entry — `Map.delete` is the witness. The
|
|
80800
|
+
* sibling bug this replaces read an entry, awaited a file read, then subtracted
|
|
80801
|
+
* unconditionally, so two racing misses subtracted one entry twice and the byte
|
|
80802
|
+
* ceiling stopped firing. No `await` may appear between the delete and the
|
|
80803
|
+
* subtract.
|
|
80804
|
+
*/
|
|
80805
|
+
forgetEntry(id2) {
|
|
80806
|
+
const entry = this.entries.get(id2);
|
|
80807
|
+
if (entry === void 0) return false;
|
|
80808
|
+
this.entries.delete(id2);
|
|
80809
|
+
this.residentBytes -= entry.size;
|
|
80810
|
+
return true;
|
|
80811
|
+
}
|
|
80812
|
+
/** The only place `residentBytes` may increase, paired with `forgetEntry`. */
|
|
80813
|
+
rememberEntry(id2, entry) {
|
|
80814
|
+
this.forgetEntry(id2);
|
|
80815
|
+
this.entries.set(id2, entry);
|
|
80816
|
+
this.residentBytes += entry.size;
|
|
80817
|
+
}
|
|
80818
|
+
async maybeSweep() {
|
|
80819
|
+
if (this.now() - this.lastSweep < this.sweepIntervalMs) return;
|
|
80820
|
+
this.lastSweep = this.now();
|
|
80821
|
+
await this.serialize(async () => {
|
|
80822
|
+
await this.sweepNow();
|
|
80823
|
+
if (this.indexDirty) await this.persistIndex();
|
|
80824
|
+
}).catch(() => {
|
|
80825
|
+
});
|
|
80826
|
+
}
|
|
80827
|
+
async sweepNow() {
|
|
80828
|
+
const at = this.now();
|
|
80829
|
+
let changed = false;
|
|
80830
|
+
for (const [id2, entry] of [...this.entries]) {
|
|
80831
|
+
if (at - entry.storedAt < this.ttlMs) continue;
|
|
80832
|
+
if (this.forgetEntry(id2)) {
|
|
80833
|
+
await this.unlink(id2);
|
|
80834
|
+
changed = true;
|
|
80835
|
+
}
|
|
80836
|
+
}
|
|
80837
|
+
while (this.entries.size > this.maxArtifacts || this.residentBytes > this.maxBytes) {
|
|
80838
|
+
const oldest = this.ids()[0];
|
|
80839
|
+
if (oldest === void 0) break;
|
|
80840
|
+
if (!this.forgetEntry(oldest)) break;
|
|
80841
|
+
this.evictions += 1;
|
|
80842
|
+
await this.unlink(oldest);
|
|
80843
|
+
changed = true;
|
|
80844
|
+
}
|
|
80845
|
+
if (changed || this.indexDirty) await this.persistIndex();
|
|
80846
|
+
}
|
|
80847
|
+
async unlink(id2) {
|
|
80848
|
+
try {
|
|
80849
|
+
await promises.rm(path$1.join(this.dir, id2), { force: true });
|
|
80850
|
+
} catch {
|
|
80851
|
+
}
|
|
80852
|
+
}
|
|
80853
|
+
async loadIndex() {
|
|
80854
|
+
let raw;
|
|
80855
|
+
try {
|
|
80856
|
+
raw = await promises.readFile(path$1.join(this.dir, INDEX_FILE$1), "utf8");
|
|
80857
|
+
} catch {
|
|
80858
|
+
return;
|
|
80859
|
+
}
|
|
80860
|
+
let document;
|
|
80861
|
+
try {
|
|
80862
|
+
document = JSON.parse(raw);
|
|
80863
|
+
} catch {
|
|
80864
|
+
return;
|
|
80865
|
+
}
|
|
80866
|
+
if (typeof document !== "object" || document === null || document.version !== INDEX_VERSION$1 || typeof document.entries !== "object" || document.entries === null)
|
|
80867
|
+
return;
|
|
80868
|
+
const principal = document.principal;
|
|
80869
|
+
if (principal !== null && (typeof principal !== "string" || !PRINCIPAL_FINGERPRINT.test(principal)))
|
|
80870
|
+
return;
|
|
80871
|
+
for (const [id2, entry] of Object.entries(
|
|
80872
|
+
document.entries
|
|
80873
|
+
)) {
|
|
80874
|
+
if (!isIndexEntry$1(entry)) continue;
|
|
80875
|
+
if (principal !== null && entry.account !== principal) continue;
|
|
80876
|
+
if (!LINK_PREVIEW_ARTIFACT_ID.test(id2)) continue;
|
|
80877
|
+
this.entries.set(id2, { ...entry });
|
|
80878
|
+
this.residentBytes += entry.size;
|
|
80879
|
+
}
|
|
80880
|
+
this.boundPrincipal = principal;
|
|
80881
|
+
}
|
|
80882
|
+
/**
|
|
80883
|
+
* Write the index beside the blobs, atomically.
|
|
80884
|
+
*
|
|
80885
|
+
* A failure here is absorbed on purpose. The cost of an unpersisted index is one
|
|
80886
|
+
* cold startup — every file becomes an orphan and is deleted, which loses cached
|
|
80887
|
+
* bytes and nothing else — while throwing would turn "the disk is full" into an
|
|
80888
|
+
* IPC rejection on a card that drew fine a moment ago.
|
|
80889
|
+
*/
|
|
80890
|
+
async persistIndex() {
|
|
80891
|
+
const document = {
|
|
80892
|
+
version: INDEX_VERSION$1,
|
|
80893
|
+
principal: this.boundPrincipal,
|
|
80894
|
+
entries: Object.fromEntries(this.entries)
|
|
80895
|
+
};
|
|
80896
|
+
const path2 = path$1.join(this.dir, INDEX_FILE$1);
|
|
80897
|
+
const temp = `${path2}.${process.pid}.${node_crypto.randomBytes(6).toString("hex")}.tmp`;
|
|
80898
|
+
try {
|
|
80899
|
+
await promises.writeFile(temp, JSON.stringify(document), { mode: FILE_MODE$1 });
|
|
80900
|
+
await promises.rename(temp, path2);
|
|
80901
|
+
this.indexDirty = false;
|
|
80902
|
+
} catch {
|
|
80903
|
+
await promises.rm(temp, { force: true }).catch(() => {
|
|
80904
|
+
});
|
|
80905
|
+
}
|
|
80906
|
+
}
|
|
80907
|
+
/** Delete every file this index does not describe, so an interrupted `store`
|
|
80908
|
+
* cannot leak storage past the bounds. `index.json` and in-flight temps are
|
|
80909
|
+
* never touched. */
|
|
80910
|
+
async removeOrphans() {
|
|
80911
|
+
let names;
|
|
80912
|
+
try {
|
|
80913
|
+
names = await promises.readdir(this.dir);
|
|
80914
|
+
} catch {
|
|
80915
|
+
return;
|
|
80916
|
+
}
|
|
80917
|
+
for (const name of names) {
|
|
80918
|
+
if (name === INDEX_FILE$1) continue;
|
|
80919
|
+
if (this.entries.has(name)) continue;
|
|
80920
|
+
try {
|
|
80921
|
+
await promises.rm(path$1.join(this.dir, name), { recursive: true, force: true });
|
|
80922
|
+
} catch {
|
|
80923
|
+
}
|
|
80924
|
+
}
|
|
80925
|
+
}
|
|
80926
|
+
serialize(work) {
|
|
80927
|
+
const next = this.queue.then(work, work);
|
|
80928
|
+
this.queue = next.catch(() => {
|
|
80929
|
+
});
|
|
80930
|
+
return next;
|
|
80931
|
+
}
|
|
80932
|
+
}
|
|
80933
|
+
function previewKeyFor(accountFingerprint, url) {
|
|
80934
|
+
return node_crypto.createHash("sha256").update(`link-preview\0${accountFingerprint}\0${url}`).digest("hex");
|
|
80935
|
+
}
|
|
80936
|
+
function isIndexEntry$1(value) {
|
|
80937
|
+
if (typeof value !== "object" || value === null) return false;
|
|
80938
|
+
const entry = value;
|
|
80939
|
+
return typeof entry.mime === "string" && entry.mime.length > 0 && entry.mime.length <= 128 && typeof entry.size === "number" && Number.isInteger(entry.size) && entry.size > 0 && // The same ceiling `store` applies. Without it a hand-edited row claiming 2^53
|
|
80940
|
+
// would evict the cache on every store and make `read` load a file of that size;
|
|
80941
|
+
// the memory bound must rest on this cache's own constant, not on a row.
|
|
80942
|
+
entry.size <= ARTIFACT_MAX_BLOB_BYTES && typeof entry.storedAt === "number" && Number.isFinite(entry.storedAt) && typeof entry.lastUsedAt === "number" && Number.isFinite(entry.lastUsedAt) && typeof entry.account === "string" && entry.account.length === 32;
|
|
80943
|
+
}
|
|
80944
|
+
const DECIMAL_LENGTH$1 = /^\d+$/;
|
|
80945
|
+
const MAX_REFUSAL_BODY_BYTES = 4096;
|
|
80946
|
+
function failure(status2, code) {
|
|
80947
|
+
return {
|
|
80948
|
+
status: status2,
|
|
80949
|
+
kind: "error",
|
|
80950
|
+
detail: "That preview image is not available.",
|
|
80951
|
+
...code === void 0 ? {} : { refusal: { code } }
|
|
80952
|
+
};
|
|
80953
|
+
}
|
|
80954
|
+
async function refusalCode(response) {
|
|
80955
|
+
if (!response.body) return void 0;
|
|
80956
|
+
let text2;
|
|
80957
|
+
try {
|
|
80958
|
+
const reader = response.body.getReader();
|
|
80959
|
+
const chunks = [];
|
|
80960
|
+
let size = 0;
|
|
80961
|
+
for (; ; ) {
|
|
80962
|
+
const { done, value } = await reader.read();
|
|
80963
|
+
if (done) break;
|
|
80964
|
+
size += value.byteLength;
|
|
80965
|
+
if (size > MAX_REFUSAL_BODY_BYTES) {
|
|
80966
|
+
await reader.cancel().catch(() => {
|
|
80967
|
+
});
|
|
80968
|
+
return void 0;
|
|
80969
|
+
}
|
|
80970
|
+
chunks.push(value);
|
|
80971
|
+
}
|
|
80972
|
+
reader.releaseLock();
|
|
80973
|
+
const data = new Uint8Array(size);
|
|
80974
|
+
let offset = 0;
|
|
80975
|
+
for (const chunk of chunks) {
|
|
80976
|
+
data.set(chunk, offset);
|
|
80977
|
+
offset += chunk.byteLength;
|
|
80978
|
+
}
|
|
80979
|
+
text2 = new TextDecoder().decode(data);
|
|
80980
|
+
} catch {
|
|
80981
|
+
return void 0;
|
|
80982
|
+
}
|
|
80983
|
+
try {
|
|
80984
|
+
const body2 = JSON.parse(text2);
|
|
80985
|
+
const detail = body2?.detail;
|
|
80986
|
+
if (typeof detail !== "object" || detail === null) return void 0;
|
|
80987
|
+
const code = detail.code;
|
|
80988
|
+
return typeof code === "string" && code.length <= 64 ? code : void 0;
|
|
80989
|
+
} catch {
|
|
80990
|
+
return void 0;
|
|
80991
|
+
}
|
|
80992
|
+
}
|
|
80993
|
+
async function readLinkPreviewArtifact(response) {
|
|
80994
|
+
if (response.status !== 200) {
|
|
80995
|
+
const code = response.status === 404 ? await refusalCode(response) : void 0;
|
|
80996
|
+
return failure(response.status, code);
|
|
80997
|
+
}
|
|
80998
|
+
const mime = (response.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase();
|
|
80999
|
+
if (!ARTIFACT_ALLOWED_MIMES.has(mime)) {
|
|
81000
|
+
await response.body?.cancel().catch(() => {
|
|
81001
|
+
});
|
|
81002
|
+
return failure(422);
|
|
81003
|
+
}
|
|
81004
|
+
const length = response.headers.get("content-length");
|
|
81005
|
+
if (length !== null) {
|
|
81006
|
+
if (!DECIMAL_LENGTH$1.test(length)) return failure(422);
|
|
81007
|
+
if (Number(length) > ARTIFACT_MAX_BLOB_BYTES) {
|
|
81008
|
+
await response.body?.cancel().catch(() => {
|
|
81009
|
+
});
|
|
81010
|
+
return failure(413);
|
|
81011
|
+
}
|
|
81012
|
+
}
|
|
81013
|
+
if (!response.body) return failure(422);
|
|
81014
|
+
const reader = response.body.getReader();
|
|
81015
|
+
const chunks = [];
|
|
81016
|
+
let size = 0;
|
|
81017
|
+
try {
|
|
81018
|
+
for (; ; ) {
|
|
81019
|
+
const { done, value } = await reader.read();
|
|
81020
|
+
if (done) break;
|
|
81021
|
+
size += value.byteLength;
|
|
81022
|
+
if (size > ARTIFACT_MAX_BLOB_BYTES) {
|
|
81023
|
+
await reader.cancel().catch(() => {
|
|
81024
|
+
});
|
|
81025
|
+
return failure(413);
|
|
81026
|
+
}
|
|
81027
|
+
chunks.push(value);
|
|
81028
|
+
}
|
|
81029
|
+
} catch {
|
|
81030
|
+
return failure(503);
|
|
81031
|
+
} finally {
|
|
81032
|
+
reader.releaseLock();
|
|
81033
|
+
}
|
|
81034
|
+
if (size === 0) return failure(422);
|
|
81035
|
+
const data = new Uint8Array(size);
|
|
81036
|
+
let offset = 0;
|
|
81037
|
+
for (const chunk of chunks) {
|
|
81038
|
+
data.set(chunk, offset);
|
|
81039
|
+
offset += chunk.byteLength;
|
|
81040
|
+
}
|
|
81041
|
+
return { status: 200, kind: "bytes", mimeType: mime, data };
|
|
81042
|
+
}
|
|
80353
81043
|
const IMAGE_CAP = 5 * 1024 * 1024;
|
|
80354
81044
|
const DECIMAL_LENGTH = /^\d+$/;
|
|
80355
81045
|
async function readOwnerAuditAttachment(response) {
|
|
@@ -80405,6 +81095,508 @@ async function readOwnerAuditAttachment(response) {
|
|
|
80405
81095
|
reader.releaseLock();
|
|
80406
81096
|
}
|
|
80407
81097
|
}
|
|
81098
|
+
const TEAM_BRIDGE_IMAGE_TTL_MS$1 = 7 * 24 * 60 * 60 * 1e3;
|
|
81099
|
+
const TEAM_BRIDGE_IMAGE_MAX_BYTES$1 = 128 * 1024 * 1024;
|
|
81100
|
+
const TEAM_BRIDGE_IMAGE_MAX_COUNT = 500;
|
|
81101
|
+
const TEAM_BRIDGE_IMAGE_SWEEP_INTERVAL_MS = 5 * 60 * 1e3;
|
|
81102
|
+
const TEAM_BRIDGE_IMAGE_MAX_BLOB_BYTES = 5 * 1024 * 1024;
|
|
81103
|
+
const TEAM_BRIDGE_IMAGE_ALLOWED_MIMES = /* @__PURE__ */ new Set([
|
|
81104
|
+
"image/png",
|
|
81105
|
+
"image/jpeg"
|
|
81106
|
+
]);
|
|
81107
|
+
const TEAM_BRIDGE_IMAGE_KEY = /^[0-9a-f]{64}$/;
|
|
81108
|
+
const INDEX_FILE = "index.json";
|
|
81109
|
+
const INDEX_VERSION = 1;
|
|
81110
|
+
const DIRECTORY_MODE = 448;
|
|
81111
|
+
const FILE_MODE = 384;
|
|
81112
|
+
const FINGERPRINT = /^[0-9a-f]{32}$/;
|
|
81113
|
+
function teamBridgeImageAccountFingerprint(accountId) {
|
|
81114
|
+
return node_crypto.createHash("sha256").update(`team-bridge-image-account\0${accountId}`).digest("hex").slice(0, 32);
|
|
81115
|
+
}
|
|
81116
|
+
function teamBridgeImageKey(receipt) {
|
|
81117
|
+
const account = teamBridgeImageAccountFingerprint(receipt.expectedAccountId);
|
|
81118
|
+
return node_crypto.createHash("sha256").update(
|
|
81119
|
+
`team-bridge-image\0${account}\0${receipt.tenantId}\0${receipt.conversationId}\0${receipt.messageId}\0${receipt.attachmentId}`
|
|
81120
|
+
).digest("hex");
|
|
81121
|
+
}
|
|
81122
|
+
class TeamBridgeImageCache {
|
|
81123
|
+
dir;
|
|
81124
|
+
now;
|
|
81125
|
+
ttlMs;
|
|
81126
|
+
maxBytes;
|
|
81127
|
+
maxCount;
|
|
81128
|
+
sweepIntervalMs;
|
|
81129
|
+
entries = /* @__PURE__ */ new Map();
|
|
81130
|
+
residentBytes = 0;
|
|
81131
|
+
evictions = 0;
|
|
81132
|
+
hits = 0;
|
|
81133
|
+
misses = 0;
|
|
81134
|
+
foreignHits = 0;
|
|
81135
|
+
lastSweep = Number.NEGATIVE_INFINITY;
|
|
81136
|
+
opened = false;
|
|
81137
|
+
/**
|
|
81138
|
+
* The fence. Bumped by EVERY `clear()`, synchronously, before its work is
|
|
81139
|
+
* queued — that is what makes a clear a point in time rather than a pass over
|
|
81140
|
+
* whatever is indexed when its turn comes. A caller that begins a network round
|
|
81141
|
+
* trip takes `currentEpoch()` first and hands it to `store`, which refuses to
|
|
81142
|
+
* write when it no longer matches: a fetch that was in flight when the principal
|
|
81143
|
+
* changed cannot re-create the departed account's file afterwards.
|
|
81144
|
+
*/
|
|
81145
|
+
epoch = 0;
|
|
81146
|
+
/**
|
|
81147
|
+
* The fingerprint the bytes on disk are bound to, or `null` when nothing is
|
|
81148
|
+
* bound (an empty cache, a wiped one, or one that has never stored).
|
|
81149
|
+
*/
|
|
81150
|
+
boundPrincipal = null;
|
|
81151
|
+
/**
|
|
81152
|
+
* The fingerprint THIS PROCESS has confirmed, or `null` until the app first
|
|
81153
|
+
* names a principal.
|
|
81154
|
+
*
|
|
81155
|
+
* WHY IT IS NOT `boundPrincipal`. `boundPrincipal` is loaded from the index at
|
|
81156
|
+
* startup, so it says what the bytes belong to, not what this process has
|
|
81157
|
+
* verified. A transition fence that fired while `confirmedPrincipal` is still
|
|
81158
|
+
* `null` would wipe the cache on the first status of every launch — the attention
|
|
81159
|
+
* service reports `null -> <account>` at every start — so the fence defers to
|
|
81160
|
+
* `bind` until a principal has actually been confirmed here.
|
|
81161
|
+
*/
|
|
81162
|
+
confirmedPrincipal = null;
|
|
81163
|
+
/** A `clear()` that arrived before `open()` finished. Honoured by `open`, and
|
|
81164
|
+
* kept if `open` fails: a later successful `open` still drops the bytes. */
|
|
81165
|
+
clearRequested = false;
|
|
81166
|
+
/** Read recency (`lastUsedAt`) has moved in memory and the index has not been
|
|
81167
|
+
* rewritten since; flushed by the throttled sweep, not per read. */
|
|
81168
|
+
indexDirty = false;
|
|
81169
|
+
/** Serializes every mutating pass, so two concurrent writers cannot interleave
|
|
81170
|
+
* a sweep with a store and leave the index accounting for a file that is gone.
|
|
81171
|
+
* `read` is queued too, exactly as the link-preview neighbour queues it: a read that
|
|
81172
|
+
* could be answered while a `clear` is in flight would hand out the departing
|
|
81173
|
+
* account's bytes (see the header's third rule). */
|
|
81174
|
+
queue = Promise.resolve();
|
|
81175
|
+
constructor(options) {
|
|
81176
|
+
this.dir = options.dir;
|
|
81177
|
+
this.now = options.now ?? (() => Date.now());
|
|
81178
|
+
this.ttlMs = options.ttlMs ?? TEAM_BRIDGE_IMAGE_TTL_MS$1;
|
|
81179
|
+
this.maxBytes = options.maxBytes ?? TEAM_BRIDGE_IMAGE_MAX_BYTES$1;
|
|
81180
|
+
this.maxCount = options.maxCount ?? TEAM_BRIDGE_IMAGE_MAX_COUNT;
|
|
81181
|
+
this.sweepIntervalMs = options.sweepIntervalMs ?? TEAM_BRIDGE_IMAGE_SWEEP_INTERVAL_MS;
|
|
81182
|
+
}
|
|
81183
|
+
/** The directory this cache owns. Named so a test can assert a file's presence
|
|
81184
|
+
* without re-deriving the path. */
|
|
81185
|
+
get directory() {
|
|
81186
|
+
return this.dir;
|
|
81187
|
+
}
|
|
81188
|
+
/** The fence value a store must carry back; see `epoch` and `store`. */
|
|
81189
|
+
currentEpoch() {
|
|
81190
|
+
return this.epoch;
|
|
81191
|
+
}
|
|
81192
|
+
/**
|
|
81193
|
+
* Create the directory, load the index, apply the principal state check, delete
|
|
81194
|
+
* files no entry describes, and apply the bounds once.
|
|
81195
|
+
*
|
|
81196
|
+
* `principal` is the account this app currently holds, when it already knows one.
|
|
81197
|
+
* `null` — the shipped launch, where the window is created long before any status
|
|
81198
|
+
* response arrives — means "not known yet", NOT "signed out": the entries are
|
|
81199
|
+
* kept and `bind` decides as soon as the app names a principal. Treating that
|
|
81200
|
+
* `null` as a sign-out would delete the cache at every start, which is the whole
|
|
81201
|
+
* benefit the feature exists for, and it would buy nothing — a read can only be
|
|
81202
|
+
* answered for the fingerprint that stored the entry, and the transition fence
|
|
81203
|
+
* drops the bytes the moment an identity actually moves.
|
|
81204
|
+
*/
|
|
81205
|
+
async open(principal = null) {
|
|
81206
|
+
await promises.mkdir(this.dir, { recursive: true, mode: DIRECTORY_MODE });
|
|
81207
|
+
await promises.chmod(this.dir, DIRECTORY_MODE).catch(() => {
|
|
81208
|
+
});
|
|
81209
|
+
await this.loadIndex();
|
|
81210
|
+
const loadedPrincipal = this.boundPrincipal;
|
|
81211
|
+
this.opened = true;
|
|
81212
|
+
await this.serialize(async () => {
|
|
81213
|
+
if (this.clearRequested) {
|
|
81214
|
+
this.clearRequested = false;
|
|
81215
|
+
await this.clearLocked();
|
|
81216
|
+
return;
|
|
81217
|
+
}
|
|
81218
|
+
if (principal !== null) {
|
|
81219
|
+
const fingerprint = teamBridgeImageAccountFingerprint(principal);
|
|
81220
|
+
let changed = loadedPrincipal !== fingerprint;
|
|
81221
|
+
for (const [key, entry] of [...this.entries]) {
|
|
81222
|
+
if (entry.account === fingerprint) continue;
|
|
81223
|
+
this.forgetEntry(key);
|
|
81224
|
+
changed = true;
|
|
81225
|
+
}
|
|
81226
|
+
this.boundPrincipal = fingerprint;
|
|
81227
|
+
this.confirmedPrincipal = fingerprint;
|
|
81228
|
+
if (changed) await this.persistIndex();
|
|
81229
|
+
await this.removeOrphans();
|
|
81230
|
+
await this.sweepNow();
|
|
81231
|
+
return;
|
|
81232
|
+
}
|
|
81233
|
+
this.boundPrincipal = loadedPrincipal;
|
|
81234
|
+
await this.removeOrphans();
|
|
81235
|
+
await this.sweepNow();
|
|
81236
|
+
});
|
|
81237
|
+
this.lastSweep = this.now();
|
|
81238
|
+
}
|
|
81239
|
+
/**
|
|
81240
|
+
* THE STATE CHECK: bind these bytes to the principal the app has just confirmed.
|
|
81241
|
+
*
|
|
81242
|
+
* Wired to the attention service's own two principal sources (`principalResolved`
|
|
81243
|
+
* in `index.ts`), so it runs on a renderer status AND on the reconcile poll —
|
|
81244
|
+
* which is what makes the invariant independent of which of the two answers
|
|
81245
|
+
* first. The three outcomes, all deliberate:
|
|
81246
|
+
*
|
|
81247
|
+
* - same fingerprint: nothing happens. This is what keeps a cache across a
|
|
81248
|
+
* restart.
|
|
81249
|
+
* - a different fingerprint: the previous account's bytes are dropped.
|
|
81250
|
+
* - `null` (a VERIFIED sign-out, which is the only way `null` reaches here):
|
|
81251
|
+
* the bytes are dropped, because no identity means no identity's images.
|
|
81252
|
+
*/
|
|
81253
|
+
async bind(accountId) {
|
|
81254
|
+
if (accountId === null) {
|
|
81255
|
+
if (this.boundPrincipal !== null) await this.clear();
|
|
81256
|
+
return;
|
|
81257
|
+
}
|
|
81258
|
+
const fingerprint = teamBridgeImageAccountFingerprint(accountId);
|
|
81259
|
+
if (this.boundPrincipal === fingerprint) {
|
|
81260
|
+
this.confirmedPrincipal = fingerprint;
|
|
81261
|
+
return;
|
|
81262
|
+
}
|
|
81263
|
+
if (this.boundPrincipal !== null) await this.clear();
|
|
81264
|
+
this.boundPrincipal = fingerprint;
|
|
81265
|
+
this.confirmedPrincipal = fingerprint;
|
|
81266
|
+
await this.serialize(() => this.persistIndex());
|
|
81267
|
+
}
|
|
81268
|
+
/**
|
|
81269
|
+
* THE TRANSITION FENCE: an identity move this process has observed.
|
|
81270
|
+
*
|
|
81271
|
+
* A no-op until a principal has been CONFIRMED here, because the same signal
|
|
81272
|
+
* fires for `null -> <account>` at every launch, and a fence that wipes its own
|
|
81273
|
+
* cache at boot is not a fence. Once confirmed, a transition drops everything —
|
|
81274
|
+
* the departing account's bytes must not survive, and at that moment this
|
|
81275
|
+
* process does not know which entries were its.
|
|
81276
|
+
*/
|
|
81277
|
+
async fence() {
|
|
81278
|
+
if (this.confirmedPrincipal === null) return;
|
|
81279
|
+
await this.clear();
|
|
81280
|
+
}
|
|
81281
|
+
/**
|
|
81282
|
+
* The bytes for one key, for the receipt that asks, or `null`.
|
|
81283
|
+
*
|
|
81284
|
+
* QUEUED, and that is a correctness requirement rather than tidiness: a clear is
|
|
81285
|
+
* a point in time (its epoch bumps in the caller's tick), and a read that began
|
|
81286
|
+
* before it must not be answered from an entry the clear has condemned. The epoch
|
|
81287
|
+
* is captured here, before the queue, and re-checked inside it.
|
|
81288
|
+
*
|
|
81289
|
+
* A key that is not in the index is a miss without a filesystem call. A key whose
|
|
81290
|
+
* entry belongs to a DIFFERENT receipt is also a miss — and deliberately not a
|
|
81291
|
+
* deletion, for the reason the header gives. An entry that IS in the index but
|
|
81292
|
+
* whose file has gone is a miss too, and the entry is dropped, so the next lookup
|
|
81293
|
+
* does not pay for the same stat. An expired entry is a miss and is removed at the
|
|
81294
|
+
* next sweep, so a read never depends on when a sweep last ran.
|
|
81295
|
+
*/
|
|
81296
|
+
async read(key, accountFingerprint) {
|
|
81297
|
+
if (!this.opened || !TEAM_BRIDGE_IMAGE_KEY.test(key)) return null;
|
|
81298
|
+
const epoch = this.epoch;
|
|
81299
|
+
return this.serialize(async () => {
|
|
81300
|
+
if (epoch !== this.epoch) {
|
|
81301
|
+
this.misses += 1;
|
|
81302
|
+
return null;
|
|
81303
|
+
}
|
|
81304
|
+
const entry = this.entries.get(key);
|
|
81305
|
+
if (entry === void 0) {
|
|
81306
|
+
this.misses += 1;
|
|
81307
|
+
return null;
|
|
81308
|
+
}
|
|
81309
|
+
if (entry.account !== accountFingerprint) {
|
|
81310
|
+
this.foreignHits += 1;
|
|
81311
|
+
return null;
|
|
81312
|
+
}
|
|
81313
|
+
if (!TEAM_BRIDGE_IMAGE_ALLOWED_MIMES.has(entry.mime)) {
|
|
81314
|
+
this.misses += 1;
|
|
81315
|
+
return null;
|
|
81316
|
+
}
|
|
81317
|
+
if (entry.size > TEAM_BRIDGE_IMAGE_MAX_BLOB_BYTES) {
|
|
81318
|
+
this.forgetEntry(key);
|
|
81319
|
+
this.misses += 1;
|
|
81320
|
+
return null;
|
|
81321
|
+
}
|
|
81322
|
+
if (this.now() - entry.storedAt >= this.ttlMs) {
|
|
81323
|
+
this.misses += 1;
|
|
81324
|
+
return null;
|
|
81325
|
+
}
|
|
81326
|
+
let bytes;
|
|
81327
|
+
try {
|
|
81328
|
+
bytes = new Uint8Array(await promises.readFile(path$1.join(this.dir, key)));
|
|
81329
|
+
} catch {
|
|
81330
|
+
this.forgetEntry(key);
|
|
81331
|
+
this.misses += 1;
|
|
81332
|
+
return null;
|
|
81333
|
+
}
|
|
81334
|
+
if (bytes.byteLength !== entry.size) {
|
|
81335
|
+
this.forgetEntry(key);
|
|
81336
|
+
this.misses += 1;
|
|
81337
|
+
return null;
|
|
81338
|
+
}
|
|
81339
|
+
entry.lastUsedAt = this.now();
|
|
81340
|
+
this.indexDirty = true;
|
|
81341
|
+
this.hits += 1;
|
|
81342
|
+
void this.maybeSweep();
|
|
81343
|
+
return { mime: entry.mime, bytes };
|
|
81344
|
+
});
|
|
81345
|
+
}
|
|
81346
|
+
/**
|
|
81347
|
+
* Keep one image for one receipt, then re-apply the bounds if they are exceeded.
|
|
81348
|
+
*
|
|
81349
|
+
* `epoch` MUST be the value `currentEpoch()` returned BEFORE the caller began its
|
|
81350
|
+
* network round trip. A `store` whose epoch has moved is refused: the clear that
|
|
81351
|
+
* moved it emptied the directory, and writing now would re-create the departing
|
|
81352
|
+
* account's image on disk for the rest of the TTL. The default is right only for a
|
|
81353
|
+
* caller that had no round trip in between (a test, or a future synchronous
|
|
81354
|
+
* source); the relay always passes the captured value.
|
|
81355
|
+
*
|
|
81356
|
+
* A blob over {@link TEAM_BRIDGE_IMAGE_MAX_BLOB_BYTES} is refused before anything
|
|
81357
|
+
* is written, and so is a mime outside {@link TEAM_BRIDGE_IMAGE_ALLOWED_MIMES} and
|
|
81358
|
+
* a key that is not one (see the header on `image/svg+xml` and on the file name
|
|
81359
|
+
* being a path segment). Nothing here can fail a caller: an image that cannot be
|
|
81360
|
+
* stored still draws.
|
|
81361
|
+
*/
|
|
81362
|
+
async store(key, mime, bytes, accountFingerprint, epoch = this.epoch) {
|
|
81363
|
+
if (!this.opened) return;
|
|
81364
|
+
if (bytes.byteLength === 0 || bytes.byteLength > TEAM_BRIDGE_IMAGE_MAX_BLOB_BYTES)
|
|
81365
|
+
return;
|
|
81366
|
+
if (!TEAM_BRIDGE_IMAGE_ALLOWED_MIMES.has(mime)) return;
|
|
81367
|
+
if (!TEAM_BRIDGE_IMAGE_KEY.test(key)) return;
|
|
81368
|
+
await this.serialize(async () => {
|
|
81369
|
+
if (epoch !== this.epoch) {
|
|
81370
|
+
return;
|
|
81371
|
+
}
|
|
81372
|
+
const path2 = path$1.join(this.dir, key);
|
|
81373
|
+
const temp = `${path2}.${process.pid}.${node_crypto.randomBytes(6).toString("hex")}.tmp`;
|
|
81374
|
+
try {
|
|
81375
|
+
await promises.writeFile(temp, bytes, { mode: FILE_MODE });
|
|
81376
|
+
await promises.rename(temp, path2);
|
|
81377
|
+
} catch {
|
|
81378
|
+
await promises.rm(temp, { force: true }).catch(() => {
|
|
81379
|
+
});
|
|
81380
|
+
return;
|
|
81381
|
+
}
|
|
81382
|
+
const at = this.now();
|
|
81383
|
+
this.rememberEntry(key, {
|
|
81384
|
+
mime,
|
|
81385
|
+
size: bytes.byteLength,
|
|
81386
|
+
storedAt: at,
|
|
81387
|
+
// A fresh blob is the newest thing here: its storedAt starts its TTL, and
|
|
81388
|
+
// its lastUsedAt is now, so it is the last thing an LRU pass takes.
|
|
81389
|
+
lastUsedAt: at,
|
|
81390
|
+
account: accountFingerprint
|
|
81391
|
+
});
|
|
81392
|
+
this.boundPrincipal = accountFingerprint;
|
|
81393
|
+
await this.persistIndex();
|
|
81394
|
+
await this.sweepNow();
|
|
81395
|
+
});
|
|
81396
|
+
}
|
|
81397
|
+
/**
|
|
81398
|
+
* Drop EVERY cached image — the principal-transition rule, and the unconditional
|
|
81399
|
+
* form a test drives.
|
|
81400
|
+
*
|
|
81401
|
+
* A sign-out or account switch must not leave the previous account's images on
|
|
81402
|
+
* disk for the remainder of a 7-day TTL. Deliberately a full clear rather than a
|
|
81403
|
+
* per-account drop: at the moment the fence fires this process no longer knows
|
|
81404
|
+
* which receipts its entries belonged to, and keeping some of them is worth less
|
|
81405
|
+
* than the guarantee that none of them are the departing account's.
|
|
81406
|
+
*
|
|
81407
|
+
* THE EPOCH BUMPS FIRST, in the caller's tick, before anything is queued: that is
|
|
81408
|
+
* what makes this a fence instead of a pass. A store already in flight sees the
|
|
81409
|
+
* new value and refuses; a read already queued sees it and misses. Then the work
|
|
81410
|
+
* is queued like every other mutation, so it cannot interleave with a sweep.
|
|
81411
|
+
*
|
|
81412
|
+
* A clear that arrives before `open()` settles is not dropped: it is remembered
|
|
81413
|
+
* and the open honours it, and it also wipes what is on disk right now, so the
|
|
81414
|
+
* bytes are gone even if `open()` never succeeds.
|
|
81415
|
+
*/
|
|
81416
|
+
async clear() {
|
|
81417
|
+
this.epoch += 1;
|
|
81418
|
+
if (!this.opened) {
|
|
81419
|
+
this.clearRequested = true;
|
|
81420
|
+
await this.serialize(() => this.clearLocked());
|
|
81421
|
+
return;
|
|
81422
|
+
}
|
|
81423
|
+
await this.serialize(() => this.clearLocked());
|
|
81424
|
+
}
|
|
81425
|
+
/** Every cached key currently indexed, oldest use first. Diagnostics and tests
|
|
81426
|
+
* only: the bytes are addressed one key at a time. */
|
|
81427
|
+
ids() {
|
|
81428
|
+
return [...this.entries.entries()].sort((a, b) => a[1].lastUsedAt - b[1].lastUsedAt).map(([key]) => key);
|
|
81429
|
+
}
|
|
81430
|
+
/** Numbers only, and never on the wire. */
|
|
81431
|
+
stats() {
|
|
81432
|
+
return {
|
|
81433
|
+
entries: this.entries.size,
|
|
81434
|
+
residentBytes: this.residentBytes,
|
|
81435
|
+
evictions: this.evictions,
|
|
81436
|
+
hits: this.hits,
|
|
81437
|
+
misses: this.misses,
|
|
81438
|
+
foreignHits: this.foreignHits
|
|
81439
|
+
};
|
|
81440
|
+
}
|
|
81441
|
+
/**
|
|
81442
|
+
* The wipe itself, always inside the queue: forget every entry, write the empty
|
|
81443
|
+
* index, then delete every file the (now empty) index does not describe.
|
|
81444
|
+
*
|
|
81445
|
+
* Unlink AFTER the index is clean: an interrupted clear then leaves orphans
|
|
81446
|
+
* (which startup collects) rather than live entries with no files.
|
|
81447
|
+
*/
|
|
81448
|
+
async clearLocked() {
|
|
81449
|
+
const keys = [...this.entries.keys()];
|
|
81450
|
+
for (const key of keys) this.forgetEntry(key);
|
|
81451
|
+
this.boundPrincipal = null;
|
|
81452
|
+
this.confirmedPrincipal = null;
|
|
81453
|
+
this.indexDirty = false;
|
|
81454
|
+
await this.persistIndex();
|
|
81455
|
+
await this.removeOrphans();
|
|
81456
|
+
}
|
|
81457
|
+
/**
|
|
81458
|
+
* The ONLY place `residentBytes` may decrease, and it decreases exactly when this
|
|
81459
|
+
* call actually removed the entry — `Map.delete` is the witness. The sibling bug
|
|
81460
|
+
* this replaces read an entry, awaited a file read, then subtracted
|
|
81461
|
+
* unconditionally, so two racing misses subtracted one entry twice and the byte
|
|
81462
|
+
* ceiling stopped firing. No `await` may appear between the delete and the
|
|
81463
|
+
* subtract.
|
|
81464
|
+
*/
|
|
81465
|
+
forgetEntry(key) {
|
|
81466
|
+
const entry = this.entries.get(key);
|
|
81467
|
+
if (entry === void 0) return false;
|
|
81468
|
+
this.entries.delete(key);
|
|
81469
|
+
this.residentBytes -= entry.size;
|
|
81470
|
+
return true;
|
|
81471
|
+
}
|
|
81472
|
+
/** The only place `residentBytes` may increase, paired with `forgetEntry`. */
|
|
81473
|
+
rememberEntry(key, entry) {
|
|
81474
|
+
this.forgetEntry(key);
|
|
81475
|
+
this.entries.set(key, entry);
|
|
81476
|
+
this.residentBytes += entry.size;
|
|
81477
|
+
}
|
|
81478
|
+
async maybeSweep() {
|
|
81479
|
+
if (this.now() - this.lastSweep < this.sweepIntervalMs) return;
|
|
81480
|
+
this.lastSweep = this.now();
|
|
81481
|
+
await this.serialize(async () => {
|
|
81482
|
+
await this.sweepNow();
|
|
81483
|
+
if (this.indexDirty) await this.persistIndex();
|
|
81484
|
+
}).catch(() => {
|
|
81485
|
+
});
|
|
81486
|
+
}
|
|
81487
|
+
async sweepNow() {
|
|
81488
|
+
const at = this.now();
|
|
81489
|
+
let changed = false;
|
|
81490
|
+
for (const [key, entry] of [...this.entries]) {
|
|
81491
|
+
if (at - entry.storedAt < this.ttlMs) continue;
|
|
81492
|
+
if (this.forgetEntry(key)) {
|
|
81493
|
+
await this.unlink(key);
|
|
81494
|
+
changed = true;
|
|
81495
|
+
}
|
|
81496
|
+
}
|
|
81497
|
+
while (this.entries.size > this.maxCount || this.residentBytes > this.maxBytes) {
|
|
81498
|
+
const oldest = this.ids()[0];
|
|
81499
|
+
if (oldest === void 0) break;
|
|
81500
|
+
if (!this.forgetEntry(oldest)) break;
|
|
81501
|
+
this.evictions += 1;
|
|
81502
|
+
await this.unlink(oldest);
|
|
81503
|
+
changed = true;
|
|
81504
|
+
}
|
|
81505
|
+
if (changed || this.indexDirty) await this.persistIndex();
|
|
81506
|
+
}
|
|
81507
|
+
async unlink(key) {
|
|
81508
|
+
try {
|
|
81509
|
+
await promises.rm(path$1.join(this.dir, key), { force: true });
|
|
81510
|
+
} catch {
|
|
81511
|
+
}
|
|
81512
|
+
}
|
|
81513
|
+
async loadIndex() {
|
|
81514
|
+
let raw;
|
|
81515
|
+
try {
|
|
81516
|
+
raw = await promises.readFile(path$1.join(this.dir, INDEX_FILE), "utf8");
|
|
81517
|
+
} catch {
|
|
81518
|
+
return;
|
|
81519
|
+
}
|
|
81520
|
+
let document;
|
|
81521
|
+
try {
|
|
81522
|
+
document = JSON.parse(raw);
|
|
81523
|
+
} catch {
|
|
81524
|
+
return;
|
|
81525
|
+
}
|
|
81526
|
+
if (typeof document !== "object" || document === null || document.version !== INDEX_VERSION || typeof document.entries !== "object" || document.entries === null)
|
|
81527
|
+
return;
|
|
81528
|
+
const principal = document.principal;
|
|
81529
|
+
if (principal !== null && (typeof principal !== "string" || !FINGERPRINT.test(principal)))
|
|
81530
|
+
return;
|
|
81531
|
+
for (const [key, entry] of Object.entries(
|
|
81532
|
+
document.entries
|
|
81533
|
+
)) {
|
|
81534
|
+
if (!isIndexEntry(entry)) continue;
|
|
81535
|
+
if (!TEAM_BRIDGE_IMAGE_KEY.test(key)) continue;
|
|
81536
|
+
if (principal !== null && entry.account !== principal) continue;
|
|
81537
|
+
this.entries.set(key, { ...entry });
|
|
81538
|
+
this.residentBytes += entry.size;
|
|
81539
|
+
}
|
|
81540
|
+
this.boundPrincipal = principal;
|
|
81541
|
+
}
|
|
81542
|
+
/**
|
|
81543
|
+
* Write the index beside the images, atomically.
|
|
81544
|
+
*
|
|
81545
|
+
* A failure here is absorbed on purpose. The cost of an unpersisted index is one
|
|
81546
|
+
* cold startup — every file becomes an orphan and is deleted, which loses cached
|
|
81547
|
+
* bytes and nothing else — while throwing would turn "the disk is full" into an
|
|
81548
|
+
* IPC rejection on an image that drew fine a moment ago.
|
|
81549
|
+
*/
|
|
81550
|
+
async persistIndex() {
|
|
81551
|
+
const document = {
|
|
81552
|
+
version: INDEX_VERSION,
|
|
81553
|
+
principal: this.boundPrincipal,
|
|
81554
|
+
entries: Object.fromEntries(this.entries)
|
|
81555
|
+
};
|
|
81556
|
+
const path2 = path$1.join(this.dir, INDEX_FILE);
|
|
81557
|
+
const temp = `${path2}.${process.pid}.${node_crypto.randomBytes(6).toString("hex")}.tmp`;
|
|
81558
|
+
try {
|
|
81559
|
+
await promises.writeFile(temp, JSON.stringify(document), { mode: FILE_MODE });
|
|
81560
|
+
await promises.rename(temp, path2);
|
|
81561
|
+
this.indexDirty = false;
|
|
81562
|
+
} catch {
|
|
81563
|
+
await promises.rm(temp, { force: true }).catch(() => {
|
|
81564
|
+
});
|
|
81565
|
+
}
|
|
81566
|
+
}
|
|
81567
|
+
/** Delete every file this index does not describe, so an interrupted `store`
|
|
81568
|
+
* cannot leak storage past the bounds. `index.json` is never touched. */
|
|
81569
|
+
async removeOrphans() {
|
|
81570
|
+
let names;
|
|
81571
|
+
try {
|
|
81572
|
+
names = await promises.readdir(this.dir);
|
|
81573
|
+
} catch {
|
|
81574
|
+
return;
|
|
81575
|
+
}
|
|
81576
|
+
for (const name of names) {
|
|
81577
|
+
if (name === INDEX_FILE) continue;
|
|
81578
|
+
if (this.entries.has(name)) continue;
|
|
81579
|
+
try {
|
|
81580
|
+
await promises.rm(path$1.join(this.dir, name), { recursive: true, force: true });
|
|
81581
|
+
} catch {
|
|
81582
|
+
}
|
|
81583
|
+
}
|
|
81584
|
+
}
|
|
81585
|
+
serialize(work) {
|
|
81586
|
+
const next = this.queue.then(work, work);
|
|
81587
|
+
this.queue = next.catch(() => {
|
|
81588
|
+
});
|
|
81589
|
+
return next;
|
|
81590
|
+
}
|
|
81591
|
+
}
|
|
81592
|
+
function isIndexEntry(value) {
|
|
81593
|
+
if (typeof value !== "object" || value === null) return false;
|
|
81594
|
+
const entry = value;
|
|
81595
|
+
return typeof entry.mime === "string" && entry.mime.length > 0 && entry.mime.length <= 128 && typeof entry.size === "number" && Number.isInteger(entry.size) && entry.size > 0 && // The same ceiling `store` applies. Without it a hand-edited row claiming
|
|
81596
|
+
// 2^53 would evict the cache on every store and make `read` load a file of that
|
|
81597
|
+
// size; the relay's memory bound must rest on its own constant, not on a row.
|
|
81598
|
+
entry.size <= TEAM_BRIDGE_IMAGE_MAX_BLOB_BYTES && typeof entry.storedAt === "number" && Number.isFinite(entry.storedAt) && typeof entry.lastUsedAt === "number" && Number.isFinite(entry.lastUsedAt) && typeof entry.account === "string" && entry.account.length === 32;
|
|
81599
|
+
}
|
|
80408
81600
|
const NOTIFICATION_INITIALS = /^[\p{L}\p{N}]{0,2}$/u;
|
|
80409
81601
|
const id = zod.z.string().min(1).max(128).regex(/^[a-zA-Z0-9_-]+$/);
|
|
80410
81602
|
const MAX_UPLOAD_BYTES = 16 * 1024 * 1024;
|
|
@@ -80679,6 +81871,25 @@ const mediaRequestSchema = zod.z.discriminatedUnion("op", [
|
|
|
80679
81871
|
op: zod.z.literal("notification_sounds.upload"),
|
|
80680
81872
|
fileName: zod.z.string().min(1).max(255),
|
|
80681
81873
|
name: zod.z.string().min(1).max(200).optional()
|
|
81874
|
+
}).strict(),
|
|
81875
|
+
/*
|
|
81876
|
+
* ONE CACHED LINK-PREVIEW ARTIFACT, by the id core derived for it.
|
|
81877
|
+
*
|
|
81878
|
+
* THE ID IS SHAPED HERE, not merely passed through: it is a PATH SEGMENT on this
|
|
81879
|
+
* request and a FILE NAME in main's artifact cache, so one check in front of both
|
|
81880
|
+
* is cheaper than a path bug. `[0-9a-f]{32}` mirrors core's own
|
|
81881
|
+
* `ARTIFACT_ID_PATTERN`, which the artifact route and the store both re-check.
|
|
81882
|
+
*
|
|
81883
|
+
* `expectedAccountId` travels as the `X-Link-Preview-Account` HEADER below, never
|
|
81884
|
+
* as a query parameter: this is a GET, and a GET's URL is the one thing every
|
|
81885
|
+
* intermediary writes down. Core answers 404 when the caller's scope does not
|
|
81886
|
+
* name the id - indistinguishable from "gone" by design — and 422 for a
|
|
81887
|
+
* malformed one.
|
|
81888
|
+
*/
|
|
81889
|
+
zod.z.object({
|
|
81890
|
+
op: zod.z.literal("team_bridge.link_preview.artifact"),
|
|
81891
|
+
id: zod.z.string().regex(LINK_PREVIEW_ARTIFACT_ID),
|
|
81892
|
+
expectedAccountId: zod.z.string().min(1).max(128)
|
|
80682
81893
|
}).strict()
|
|
80683
81894
|
]);
|
|
80684
81895
|
function endpoint(request) {
|
|
@@ -80813,6 +82024,22 @@ function endpoint(request) {
|
|
|
80813
82024
|
path: `/v1/desktop/team-bridge/accounts/${request.accountId}/avatar?${new URLSearchParams({ v: request.hash, size: String(request.size), expected_account_id: request.expectedAccountId })}`,
|
|
80814
82025
|
method: "GET"
|
|
80815
82026
|
};
|
|
82027
|
+
/*
|
|
82028
|
+
* One cached link-preview artifact id (core's scope-derived hash).
|
|
82029
|
+
*
|
|
82030
|
+
* The path segment is the id and nothing else: no query string at all, because
|
|
82031
|
+
* the account receipt this route needs travels as the `X-Link-Preview-Account`
|
|
82032
|
+
* HEADER (see the header block in `requestDesktopMediaOutcome`) - a GET's URL is
|
|
82033
|
+
* written down by every intermediary, and an account id does not belong there.
|
|
82034
|
+
* `encodeURIComponent` is belt over the schema's `[0-9a-f]{32}`: the schema is
|
|
82035
|
+
* this client's check, and a hand-built request must not be able to turn an id
|
|
82036
|
+
* into a path fragment either.
|
|
82037
|
+
*/
|
|
82038
|
+
case "team_bridge.link_preview.artifact":
|
|
82039
|
+
return {
|
|
82040
|
+
path: `/v1/desktop/team-bridge/link-preview/artifact/${encodeURIComponent(request.id)}`,
|
|
82041
|
+
method: "GET"
|
|
82042
|
+
};
|
|
80816
82043
|
}
|
|
80817
82044
|
}
|
|
80818
82045
|
function scalarParams(params) {
|
|
@@ -80826,7 +82053,14 @@ function scalarParams(params) {
|
|
|
80826
82053
|
}
|
|
80827
82054
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
80828
82055
|
}
|
|
80829
|
-
|
|
82056
|
+
function imageCacheAddress(request) {
|
|
82057
|
+
if (request.op !== "team_bridge.attachment") return null;
|
|
82058
|
+
return {
|
|
82059
|
+
key: teamBridgeImageKey(request),
|
|
82060
|
+
fingerprint: teamBridgeImageAccountFingerprint(request.expectedAccountId)
|
|
82061
|
+
};
|
|
82062
|
+
}
|
|
82063
|
+
async function requestDesktopMediaOutcome(input, bytes, backendUrl, token, imageCache) {
|
|
80830
82064
|
const parsed = mediaRequestSchema.safeParse(input);
|
|
80831
82065
|
if (!parsed.success || parsed.data.op === "team_bridge.notification_avatar" && (parsed.data.avatar && parsed.data.avatar.account_id !== parsed.data.accountId || // An agent's picture is never drawn on a person, and one banner
|
|
80832
82066
|
// never names both pictures (core refuses either; so do we, first).
|
|
@@ -80873,9 +82107,39 @@ async function requestDesktopMediaOutcome(input, bytes, backendUrl, token) {
|
|
|
80873
82107
|
};
|
|
80874
82108
|
}
|
|
80875
82109
|
const target2 = endpoint(request);
|
|
82110
|
+
const imageAddress = imageCache ? imageCacheAddress(request) : null;
|
|
82111
|
+
const imageEpoch = imageCache && imageAddress ? imageCache.currentEpoch() : 0;
|
|
82112
|
+
if (imageCache && imageAddress) {
|
|
82113
|
+
const cached2 = await imageCache.read(
|
|
82114
|
+
imageAddress.key,
|
|
82115
|
+
imageAddress.fingerprint
|
|
82116
|
+
);
|
|
82117
|
+
if (cached2) {
|
|
82118
|
+
return {
|
|
82119
|
+
response: {
|
|
82120
|
+
status: 200,
|
|
82121
|
+
kind: "bytes",
|
|
82122
|
+
mimeType: cached2.mime,
|
|
82123
|
+
data: cached2.bytes
|
|
82124
|
+
},
|
|
82125
|
+
/*
|
|
82126
|
+
* `answered: false`, and that is not a detail: `answered` is "fetch
|
|
82127
|
+
* resolved" (`desktop-transport.ts`), and `backend-service.ts` feeds it
|
|
82128
|
+
* straight into `recordTransportAnswer()`, which resets the probe-miss
|
|
82129
|
+
* counter and stamps fresh transport evidence for 30 s. A hit contacted
|
|
82130
|
+
* no daemon, so claiming it did would keep a DEAD daemon looking alive for
|
|
82131
|
+
* as long as images keep being read, and none of this app's detach and
|
|
82132
|
+
* re-discovery would ever fire (review round 1, F-1). The bytes are still
|
|
82133
|
+
* a valid answer to the caller - they stand on the receipt the daemon once
|
|
82134
|
+
* gave - but they are not evidence that anything is listening.
|
|
82135
|
+
*/
|
|
82136
|
+
answered: false
|
|
82137
|
+
};
|
|
82138
|
+
}
|
|
82139
|
+
}
|
|
80876
82140
|
let body2;
|
|
80877
82141
|
let contentType;
|
|
80878
|
-
if (request.op === "account.profile" || request.op === "account.avatar.delete" || request.op === "agent.export" || request.op === "agent.avatar" || request.op === "agent.avatar.delete" || request.op === "sessions.attachment" || request.op === "subagents.attachment" || request.op === "sessions.attachment.waveform" || request.op === "sessions.supplementDocument" || request.op === "library.content" || request.op === "library.thumbnail" || request.op === "library.waveform" || request.op === "notification_sounds.audio" || request.op === "team_bridge.attachment" || request.op === "team_bridge.owner_audit.attachment" || request.op === "team_bridge.avatar" || request.op === "team_bridge.endpoint_avatar" || request.op === "team_bridge.notification_avatar") {
|
|
82142
|
+
if (request.op === "account.profile" || request.op === "account.avatar.delete" || request.op === "agent.export" || request.op === "agent.avatar" || request.op === "agent.avatar.delete" || request.op === "sessions.attachment" || request.op === "subagents.attachment" || request.op === "sessions.attachment.waveform" || request.op === "sessions.supplementDocument" || request.op === "library.content" || request.op === "library.thumbnail" || request.op === "library.waveform" || request.op === "notification_sounds.audio" || request.op === "team_bridge.attachment" || request.op === "team_bridge.owner_audit.attachment" || request.op === "team_bridge.avatar" || request.op === "team_bridge.endpoint_avatar" || request.op === "team_bridge.link_preview.artifact" || request.op === "team_bridge.notification_avatar") {
|
|
80879
82143
|
body2 = void 0;
|
|
80880
82144
|
} else if (request.op === "team_bridge.attachment.upload" || request.op === "account.avatar.put" || request.op === "agent.avatar.put") {
|
|
80881
82145
|
if (!bytes || bytes.byteLength === 0) {
|
|
@@ -80928,6 +82192,14 @@ async function requestDesktopMediaOutcome(input, bytes, backendUrl, token) {
|
|
|
80928
82192
|
// #3363 forwards the name only in file mode; it is display content,
|
|
80929
82193
|
// never a filesystem path or a declared MIME/safety claim.
|
|
80930
82194
|
...request.op === "team_bridge.attachment.upload" && request.mode === "file" && request.fileName ? { "X-Bridge-File-Name": encodeURIComponent(request.fileName) } : {},
|
|
82195
|
+
/*
|
|
82196
|
+
* The artifact route's account RECEIPT, as a header and only as a header
|
|
82197
|
+
* (core's `ACCOUNT_RECEIPT_HEADER`). The preview endpoints take the account
|
|
82198
|
+
* this session claims so core can refuse a mismatch; on this GET there is no
|
|
82199
|
+
* body to carry it and a query string would put it in every log between here
|
|
82200
|
+
* and the daemon, which is precisely what core's route refuses to do.
|
|
82201
|
+
*/
|
|
82202
|
+
...request.op === "team_bridge.link_preview.artifact" ? { "X-Link-Preview-Account": request.expectedAccountId } : {},
|
|
80931
82203
|
Authorization: `Bearer ${token}`
|
|
80932
82204
|
},
|
|
80933
82205
|
body: body2,
|
|
@@ -80941,6 +82213,12 @@ async function requestDesktopMediaOutcome(input, bytes, backendUrl, token) {
|
|
|
80941
82213
|
});
|
|
80942
82214
|
answered = true;
|
|
80943
82215
|
const responseType = response.headers.get("content-type") ?? "";
|
|
82216
|
+
if (request.op === "team_bridge.link_preview.artifact") {
|
|
82217
|
+
return {
|
|
82218
|
+
response: await readLinkPreviewArtifact(response),
|
|
82219
|
+
answered: true
|
|
82220
|
+
};
|
|
82221
|
+
}
|
|
80944
82222
|
if (request.op === "team_bridge.owner_audit.attachment") {
|
|
80945
82223
|
return {
|
|
80946
82224
|
response: await readOwnerAuditAttachment(response),
|
|
@@ -81109,11 +82387,30 @@ async function requestDesktopMediaOutcome(input, bytes, backendUrl, token) {
|
|
|
81109
82387
|
answered: true
|
|
81110
82388
|
};
|
|
81111
82389
|
}
|
|
82390
|
+
if (imageCache && imageAddress && response.status === 200) {
|
|
82391
|
+
await imageCache.store(
|
|
82392
|
+
imageAddress.key,
|
|
82393
|
+
// The NORMALISED header, which is the spelling the allowlist above
|
|
82394
|
+
// compared: `image/png; charset=binary` is kept as `image/png`.
|
|
82395
|
+
(responseType.split(";")[0] ?? "").trim().toLowerCase(),
|
|
82396
|
+
buffer,
|
|
82397
|
+
imageAddress.fingerprint,
|
|
82398
|
+
imageEpoch
|
|
82399
|
+
);
|
|
82400
|
+
}
|
|
81112
82401
|
return {
|
|
81113
82402
|
response: {
|
|
81114
82403
|
status: response.status,
|
|
81115
82404
|
kind: "bytes",
|
|
81116
|
-
|
|
82405
|
+
/*
|
|
82406
|
+
* THIS OP REPORTS ONE SPELLING, hit or miss. A hit carries the index's
|
|
82407
|
+
* normalised mime, so the miss normalises the header too - otherwise the
|
|
82408
|
+
* same image is described as `image/png; charset=binary` uncached and
|
|
82409
|
+
* `image/png` cached, which is an observable difference between two
|
|
82410
|
+
* answers for one receipt. Every other op keeps the header verbatim
|
|
82411
|
+
* (review round 1, NIT-2).
|
|
82412
|
+
*/
|
|
82413
|
+
mimeType: request.op === "team_bridge.attachment" ? (responseType.split(";")[0] ?? "").trim().toLowerCase() : responseType || "application/octet-stream",
|
|
81117
82414
|
data: buffer
|
|
81118
82415
|
},
|
|
81119
82416
|
answered: true
|
|
@@ -83882,6 +85179,18 @@ class BackendServiceManager {
|
|
|
83882
85179
|
* configuration and not a cache to be second-guessed.
|
|
83883
85180
|
*/
|
|
83884
85181
|
desktopToken = process.env.LOCAL_OPERATOR_DESKTOP_TOKEN || null;
|
|
85182
|
+
/**
|
|
85183
|
+
* The Team Bridge image cache (`../team-bridge-image-cache`), attached by
|
|
85184
|
+
* `src/main/index.ts` once the app is ready.
|
|
85185
|
+
*
|
|
85186
|
+
* WHY A SETTER RATHER THAN A CONSTRUCTOR OPTION. This manager is constructed at
|
|
85187
|
+
* module load (`index.ts`), before there is a `userData` path to put a cache
|
|
85188
|
+
* directory under; the cache is built in the ready block beside the link-preview
|
|
85189
|
+
* one. `null` - a test, a rig, or a process that never attached one - means the
|
|
85190
|
+
* relay has no cache and every read is a fetch, which is the behaviour before
|
|
85191
|
+
* this existed.
|
|
85192
|
+
*/
|
|
85193
|
+
teamBridgeImages = null;
|
|
83885
85194
|
/** Authenticated SSE relay for canonical session events. Recreated when the
|
|
83886
85195
|
* backend URL rotates (external-backend discovery) or the desktop token does
|
|
83887
85196
|
* (every managed start mints one), and dropped outright by `stop()`.
|
|
@@ -83955,6 +85264,16 @@ class BackendServiceManager {
|
|
|
83955
85264
|
* outlive the backend it described.
|
|
83956
85265
|
*/
|
|
83957
85266
|
backendReadyObserver = null;
|
|
85267
|
+
/**
|
|
85268
|
+
* Attach the Team Bridge image cache, once, from the ready block that owns it.
|
|
85269
|
+
*
|
|
85270
|
+
* Called from the same place that owns the cache's lifetime, so there is one
|
|
85271
|
+
* owner for "does this process cache message images". Idempotent, and passing
|
|
85272
|
+
* `null` detaches it - useful to a test, never used by the app.
|
|
85273
|
+
*/
|
|
85274
|
+
attachTeamBridgeImageCache(cache) {
|
|
85275
|
+
this.teamBridgeImages = cache;
|
|
85276
|
+
}
|
|
83958
85277
|
onBackendReady(observer) {
|
|
83959
85278
|
this.backendReadyObserver = observer;
|
|
83960
85279
|
}
|
|
@@ -84197,7 +85516,8 @@ class BackendServiceManager {
|
|
|
84197
85516
|
input,
|
|
84198
85517
|
bytes,
|
|
84199
85518
|
this.backendUrl,
|
|
84200
|
-
this.desktopToken
|
|
85519
|
+
this.desktopToken,
|
|
85520
|
+
this.teamBridgeImages
|
|
84201
85521
|
).then(({ response, answered }) => {
|
|
84202
85522
|
if (answered) this.daemonState.recordTransportAnswer();
|
|
84203
85523
|
return response;
|
|
@@ -86170,11 +87490,11 @@ class BackendServiceManager {
|
|
|
86170
87490
|
if (!expected) {
|
|
86171
87491
|
const ok = await this.checkHealth();
|
|
86172
87492
|
if (ok) return { kind: "identified" };
|
|
86173
|
-
const
|
|
87493
|
+
const failure2 = this.lastHealthFailure;
|
|
86174
87494
|
return {
|
|
86175
|
-
kind:
|
|
86176
|
-
cause:
|
|
86177
|
-
detail:
|
|
87495
|
+
kind: failure2 === null || failure2 === "refused" ? "failed" : "unanswered",
|
|
87496
|
+
cause: failure2 ?? "other",
|
|
87497
|
+
detail: failure2 === null ? `${this.backendUrl}${HEALTH_PATH$1} answered a status this app does not accept` : `No answer from ${this.backendUrl}${HEALTH_PATH$1}`
|
|
86178
87498
|
};
|
|
86179
87499
|
}
|
|
86180
87500
|
const probe = await probeIdentity(this.backendUrl, expected, {
|
|
@@ -87755,14 +89075,14 @@ class BackendInstaller {
|
|
|
87755
89075
|
if (!this.hasLivePreparationWindow()) return;
|
|
87756
89076
|
const subject = `${captured}
|
|
87757
89077
|
${error instanceof Error ? error.message : String(error ?? "")}`;
|
|
87758
|
-
const
|
|
89078
|
+
const failure2 = {
|
|
87759
89079
|
phase: this.lastPhase,
|
|
87760
89080
|
reason: setupFailureCause(subject) ?? installFailureSentence(this.lastPhase),
|
|
87761
89081
|
detail,
|
|
87762
89082
|
exitCode
|
|
87763
89083
|
};
|
|
87764
89084
|
this.failureOnScreen = true;
|
|
87765
|
-
this.sendInstallProgress({ kind: "failed", phase:
|
|
89085
|
+
this.sendInstallProgress({ kind: "failed", phase: failure2.phase, failure: failure2 });
|
|
87766
89086
|
}
|
|
87767
89087
|
/**
|
|
87768
89088
|
* Wait for the window to settle a failure it is showing.
|
|
@@ -88756,7 +90076,22 @@ const METHODS$1 = [
|
|
|
88756
90076
|
// on an app that predates it instead of sending an unknown method.
|
|
88757
90077
|
"hover",
|
|
88758
90078
|
// DOM/native and page-owned ARIA selection; never an OS popup.
|
|
88759
|
-
"select"
|
|
90079
|
+
"select",
|
|
90080
|
+
// Write one form control's value and read it back: a native <select> by
|
|
90081
|
+
// label or value, an <input>/<textarea> through the prototype setter (so a
|
|
90082
|
+
// framework's instance tracker cannot swallow the update), `input` then
|
|
90083
|
+
// `change` dispatched. Appended here so no existing method index moves.
|
|
90084
|
+
"setvalue",
|
|
90085
|
+
// Clipboard write through the HOST rather than through a page permission:
|
|
90086
|
+
// the element's bytes are read in an isolated world and written from the main
|
|
90087
|
+
// process, and the answer is a receipt (chars, a 16-hex sha256, verified) that
|
|
90088
|
+
// carries no text at all. APPENDED (after `setvalue`, which main landed first)
|
|
90089
|
+
// so no existing method's index moves on this host, the same rule `hover`
|
|
90090
|
+
// follows above: the Python mirror places it in its own group and the wire is
|
|
90091
|
+
// by NAME, so `isMethod` admits it either way, and HOST_CAPABILITIES is what
|
|
90092
|
+
// refuses it on a host that predates it instead of a version bump (an additive
|
|
90093
|
+
// method must not close an already-released peer with `proto_mismatch`).
|
|
90094
|
+
"copy"
|
|
88760
90095
|
];
|
|
88761
90096
|
const METHOD_SET = new Set(METHODS$1);
|
|
88762
90097
|
function isMethod(value) {
|
|
@@ -88797,7 +90132,16 @@ const ERROR_CODES = [
|
|
|
88797
90132
|
// for the same reason METHODS is: this list is what `rpc.ts` narrows a raised
|
|
88798
90133
|
// code against, and an unknown code is silently dropped by the session's model —
|
|
88799
90134
|
// a command that hangs rather than one that fails.
|
|
88800
|
-
...CONSOLE_ERROR_CODES
|
|
90135
|
+
...CONSOLE_ERROR_CODES,
|
|
90136
|
+
// `copy`'s two refusals, in `protocol.py`'s order (the `ErrorCode` enum the
|
|
90137
|
+
// generated `protocol.gen.ts` carries). They arrived with the action: an element
|
|
90138
|
+
// that exists but has no text is not a missing element, and a clipboard the OS
|
|
90139
|
+
// refused is not a host fault, and collapsing either into a code that means
|
|
90140
|
+
// something else is how a caller's correction advice goes wrong. Additive in the
|
|
90141
|
+
// safe direction — this host emits them, and only a session that knows the
|
|
90142
|
+
// vocabulary reads them.
|
|
90143
|
+
"empty_element_text",
|
|
90144
|
+
"clipboard_write_failed"
|
|
88801
90145
|
];
|
|
88802
90146
|
const HOST_CAPABILITIES = [
|
|
88803
90147
|
"console_resources",
|
|
@@ -88818,6 +90162,11 @@ const HOST_CAPABILITIES = [
|
|
|
88818
90162
|
// the extension/cmux hosts and older desktop apps must be refused by capability.
|
|
88819
90163
|
"hover",
|
|
88820
90164
|
"select",
|
|
90165
|
+
// Writing a value into a form control. On the same list as `select` for the
|
|
90166
|
+
// same reason: an app build that predates it answers the frame with a bare
|
|
90167
|
+
// `internal`, which a caller can only read as "the bridge broke"; the
|
|
90168
|
+
// capability turns that peer into a typed refusal instead.
|
|
90169
|
+
"setvalue",
|
|
88821
90170
|
// Session-scoped network capture. DESKTOP-ONLY: the extension's debugger is
|
|
88822
90171
|
// attached only for the duration of an action, so it holds no standing session
|
|
88823
90172
|
// to keep a `Network` subscription on. The backend therefore gates these four
|
|
@@ -88837,7 +90186,17 @@ const HOST_CAPABILITIES = [
|
|
|
88837
90186
|
"record_size",
|
|
88838
90187
|
// High-quality recording (quality on record_start) is not a method either; the
|
|
88839
90188
|
// harness capability-gates the one param on this name.
|
|
88840
|
-
"record_quality"
|
|
90189
|
+
"record_quality",
|
|
90190
|
+
// Clipboard write, served by the DESKTOP app's browser host only: the copy is
|
|
90191
|
+
// a Node-side `clipboard.writeText` in the host's main process, which a
|
|
90192
|
+
// browser extension has no equivalent of (an extension's clipboard API is
|
|
90193
|
+
// user-gesture-bound and cannot be driven from a service worker), and the
|
|
90194
|
+
// cmux host drives a panel it does not own the process of. Advertising it here
|
|
90195
|
+
// is what lets the harness refuse `copy` by CAPABILITY on the extension, the
|
|
90196
|
+
// cmux host and any desktop build that predates this one — the `download`
|
|
90197
|
+
// precedent — instead of sending a method the peer answers `internal` for or,
|
|
90198
|
+
// worse, never answers at all.
|
|
90199
|
+
"copy"
|
|
88841
90200
|
];
|
|
88842
90201
|
const RUN_DIRNAME = path$1.join("run", "ui-browser");
|
|
88843
90202
|
const STATE_FILENAME = "host.json";
|
|
@@ -89218,9 +90577,9 @@ function requireDirectives() {
|
|
|
89218
90577
|
this.tags = Object.assign({}, Directives.defaultTags, tags2);
|
|
89219
90578
|
}
|
|
89220
90579
|
clone() {
|
|
89221
|
-
const
|
|
89222
|
-
|
|
89223
|
-
return
|
|
90580
|
+
const copy2 = new Directives(this.yaml, this.tags);
|
|
90581
|
+
copy2.docStart = this.docStart;
|
|
90582
|
+
return copy2;
|
|
89224
90583
|
}
|
|
89225
90584
|
/**
|
|
89226
90585
|
* During parsing, get a Directives instance for the current document and
|
|
@@ -89532,10 +90891,10 @@ function requireNode() {
|
|
|
89532
90891
|
}
|
|
89533
90892
|
/** Create a copy of this node. */
|
|
89534
90893
|
clone() {
|
|
89535
|
-
const
|
|
90894
|
+
const copy2 = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
89536
90895
|
if (this.range)
|
|
89537
|
-
|
|
89538
|
-
return
|
|
90896
|
+
copy2.range = this.range.slice();
|
|
90897
|
+
return copy2;
|
|
89539
90898
|
}
|
|
89540
90899
|
/** A plain JavaScript representation of this node. */
|
|
89541
90900
|
toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
@@ -89813,13 +91172,13 @@ function requireCollection() {
|
|
|
89813
91172
|
* @param schema - If defined, overwrites the original's schema
|
|
89814
91173
|
*/
|
|
89815
91174
|
clone(schema2) {
|
|
89816
|
-
const
|
|
91175
|
+
const copy2 = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
89817
91176
|
if (schema2)
|
|
89818
|
-
|
|
89819
|
-
|
|
91177
|
+
copy2.schema = schema2;
|
|
91178
|
+
copy2.items = copy2.items.map((it) => identity2.isNode(it) || identity2.isPair(it) ? it.clone(schema2) : it);
|
|
89820
91179
|
if (this.range)
|
|
89821
|
-
|
|
89822
|
-
return
|
|
91180
|
+
copy2.range = this.range.slice();
|
|
91181
|
+
return copy2;
|
|
89823
91182
|
}
|
|
89824
91183
|
/**
|
|
89825
91184
|
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
@@ -92229,9 +93588,9 @@ function requireSchema() {
|
|
|
92229
93588
|
this.sortMapEntries = typeof sortMapEntries === "function" ? sortMapEntries : sortMapEntries === true ? sortMapEntriesByKey : null;
|
|
92230
93589
|
}
|
|
92231
93590
|
clone() {
|
|
92232
|
-
const
|
|
92233
|
-
|
|
92234
|
-
return
|
|
93591
|
+
const copy2 = Object.create(Schema2.prototype, Object.getOwnPropertyDescriptors(this));
|
|
93592
|
+
copy2.tags = this.tags.slice();
|
|
93593
|
+
return copy2;
|
|
92235
93594
|
}
|
|
92236
93595
|
};
|
|
92237
93596
|
Schema.Schema = Schema$1;
|
|
@@ -92373,21 +93732,21 @@ function requireDocument() {
|
|
|
92373
93732
|
* Custom Node values that inherit from `Object` still refer to their original instances.
|
|
92374
93733
|
*/
|
|
92375
93734
|
clone() {
|
|
92376
|
-
const
|
|
93735
|
+
const copy2 = Object.create(Document2.prototype, {
|
|
92377
93736
|
[identity2.NODE_TYPE]: { value: identity2.DOC }
|
|
92378
93737
|
});
|
|
92379
|
-
|
|
92380
|
-
|
|
92381
|
-
|
|
92382
|
-
|
|
92383
|
-
|
|
93738
|
+
copy2.commentBefore = this.commentBefore;
|
|
93739
|
+
copy2.comment = this.comment;
|
|
93740
|
+
copy2.errors = this.errors.slice();
|
|
93741
|
+
copy2.warnings = this.warnings.slice();
|
|
93742
|
+
copy2.options = Object.assign({}, this.options);
|
|
92384
93743
|
if (this.directives)
|
|
92385
|
-
|
|
92386
|
-
|
|
92387
|
-
|
|
93744
|
+
copy2.directives = this.directives.clone();
|
|
93745
|
+
copy2.schema = this.schema.clone();
|
|
93746
|
+
copy2.contents = identity2.isNode(this.contents) ? this.contents.clone(copy2.schema) : this.contents;
|
|
92388
93747
|
if (this.range)
|
|
92389
|
-
|
|
92390
|
-
return
|
|
93748
|
+
copy2.range = this.range.slice();
|
|
93749
|
+
return copy2;
|
|
92391
93750
|
}
|
|
92392
93751
|
/** Adds a value to the document. */
|
|
92393
93752
|
add(value) {
|
|
@@ -97057,11 +98416,11 @@ class ByteLog {
|
|
|
97057
98416
|
}
|
|
97058
98417
|
append(bytes) {
|
|
97059
98418
|
if (bytes.length === 0) return;
|
|
97060
|
-
const
|
|
97061
|
-
this.chunks.push({ offset: this.end, bytes:
|
|
97062
|
-
this.retained +=
|
|
97063
|
-
this.end +=
|
|
97064
|
-
this.trim(
|
|
98419
|
+
const copy2 = Uint8Array.from(bytes);
|
|
98420
|
+
this.chunks.push({ offset: this.end, bytes: copy2 });
|
|
98421
|
+
this.retained += copy2.length;
|
|
98422
|
+
this.end += copy2.length;
|
|
98423
|
+
this.trim(copy2.length);
|
|
97065
98424
|
}
|
|
97066
98425
|
/**
|
|
97067
98426
|
* Read the retained bytes from `from` onward.
|
|
@@ -100331,8 +101690,8 @@ function loadNodePty() {
|
|
|
100331
101690
|
typeof __filename === "string" ? __filename : require("url").pathToFileURL(__filename).href
|
|
100332
101691
|
);
|
|
100333
101692
|
const namespace = requireFrom(PTY_PACKAGE);
|
|
100334
|
-
const
|
|
100335
|
-
if (typeof
|
|
101693
|
+
const module2 = "spawn" in namespace ? namespace : namespace.default;
|
|
101694
|
+
if (typeof module2?.spawn !== "function") {
|
|
100336
101695
|
cached = { ok: false, reason: "node-pty loaded but exports no spawn()" };
|
|
100337
101696
|
return cached;
|
|
100338
101697
|
}
|
|
@@ -100340,7 +101699,7 @@ function loadNodePty() {
|
|
|
100340
101699
|
platform: process.platform,
|
|
100341
101700
|
arch: process.arch
|
|
100342
101701
|
});
|
|
100343
|
-
cached = { ok: true, root, helper, module };
|
|
101702
|
+
cached = { ok: true, root, helper, module: module2 };
|
|
100344
101703
|
return cached;
|
|
100345
101704
|
} catch (error) {
|
|
100346
101705
|
cached = {
|
|
@@ -100350,7 +101709,7 @@ function loadNodePty() {
|
|
|
100350
101709
|
return cached;
|
|
100351
101710
|
}
|
|
100352
101711
|
}
|
|
100353
|
-
function spawnPty(
|
|
101712
|
+
function spawnPty(module2, options, onHeal) {
|
|
100354
101713
|
const load = cached;
|
|
100355
101714
|
if (load?.ok) {
|
|
100356
101715
|
const report = ensureSpawnHelperExecutable(load.root, {
|
|
@@ -100359,7 +101718,7 @@ function spawnPty(module, options, onHeal) {
|
|
|
100359
101718
|
});
|
|
100360
101719
|
if (report.healed) onHeal?.(report);
|
|
100361
101720
|
}
|
|
100362
|
-
return
|
|
101721
|
+
return module2.spawn(options.file, options.args, {
|
|
100363
101722
|
// The surface's own name, so a program that asks what terminal it is on gets
|
|
100364
101723
|
// the pinned answer the window's TERM already declares (design 6.6).
|
|
100365
101724
|
name: "xterm-256color",
|
|
@@ -105403,6 +106762,430 @@ function observeBrowserLocale(window) {
|
|
|
105403
106762
|
}
|
|
105404
106763
|
});
|
|
105405
106764
|
}
|
|
106765
|
+
const CLIPBOARD_BINDING = "__localOperatorClipboardWrite";
|
|
106766
|
+
const CLIPBOARD_ACK = "__localOperatorClipboardAck";
|
|
106767
|
+
const CLIPBOARD_SENTINEL = "__localOperatorClipboardShim";
|
|
106768
|
+
const CLIPBOARD_SHIM_MAX_BYTES = 1048576;
|
|
106769
|
+
const CLIPBOARD_ACK_TIMEOUT_MS = 5e3;
|
|
106770
|
+
const CLIPBOARD_ARM_WINDOW_MS = 2e3;
|
|
106771
|
+
const PAYLOAD_SEPARATOR = "\n";
|
|
106772
|
+
function clipboardShimSource() {
|
|
106773
|
+
const config = JSON.stringify({
|
|
106774
|
+
binding: CLIPBOARD_BINDING,
|
|
106775
|
+
ack: CLIPBOARD_ACK,
|
|
106776
|
+
sentinel: CLIPBOARD_SENTINEL,
|
|
106777
|
+
maxBytes: CLIPBOARD_SHIM_MAX_BYTES,
|
|
106778
|
+
timeoutMs: CLIPBOARD_ACK_TIMEOUT_MS
|
|
106779
|
+
});
|
|
106780
|
+
return `(function (config) {
|
|
106781
|
+
"use strict";
|
|
106782
|
+
var clipboard = navigator.clipboard;
|
|
106783
|
+
if (!clipboard || typeof clipboard.writeText !== "function") return;
|
|
106784
|
+
|
|
106785
|
+
// IDEMPOTENT BY A LOCKED SENTINEL: a second install is a no-op, and the page
|
|
106786
|
+
// cannot flip the flag to force one (a re-install would wrap the wrapper, and a
|
|
106787
|
+
// page that could clear it could make any later install believe this document
|
|
106788
|
+
// was never covered).
|
|
106789
|
+
if (window[config.sentinel] === true) return;
|
|
106790
|
+
try {
|
|
106791
|
+
Object.defineProperty(window, config.sentinel, {
|
|
106792
|
+
value: true,
|
|
106793
|
+
configurable: false,
|
|
106794
|
+
writable: false,
|
|
106795
|
+
// Not even enumerable: a page walking globalThis keys learns nothing about
|
|
106796
|
+
// whether this document is covered.
|
|
106797
|
+
enumerable: false,
|
|
106798
|
+
});
|
|
106799
|
+
} catch (error) {
|
|
106800
|
+
// Something non-configurable already owns the name. Leave the document alone
|
|
106801
|
+
// rather than install a second wrapper whose sentinel we cannot own.
|
|
106802
|
+
return;
|
|
106803
|
+
}
|
|
106804
|
+
|
|
106805
|
+
var nativeWriteText = clipboard.writeText.bind(clipboard);
|
|
106806
|
+
var nativeWrite = typeof clipboard.write === "function" ? clipboard.write.bind(clipboard) : null;
|
|
106807
|
+
var nativeQuery = typeof navigator.permissions?.query === "function" ? navigator.permissions.query.bind(navigator.permissions) : null;
|
|
106808
|
+
var pending = new Map();
|
|
106809
|
+
var nextId = 1;
|
|
106810
|
+
|
|
106811
|
+
function refuses(message, name) {
|
|
106812
|
+
return Promise.reject(new DOMException(message, name || "NotAllowedError"));
|
|
106813
|
+
}
|
|
106814
|
+
|
|
106815
|
+
// The host calls this through CDP, in THIS world, with an id it was given. A
|
|
106816
|
+
// page may call it too, with any id it likes: that settles the page's own
|
|
106817
|
+
// promise and changes nothing else, because whether a write HAPPENED was
|
|
106818
|
+
// decided in main before this was ever called.
|
|
106819
|
+
window[config.ack] = function (id, ok) {
|
|
106820
|
+
var settled = pending.get(id);
|
|
106821
|
+
if (!settled) return;
|
|
106822
|
+
pending.delete(id);
|
|
106823
|
+
clearTimeout(settled.timer);
|
|
106824
|
+
if (ok) settled.resolve();
|
|
106825
|
+
else settled.reject(new DOMException("the host did not allow the clipboard write", "NotAllowedError"));
|
|
106826
|
+
};
|
|
106827
|
+
|
|
106828
|
+
// UTF-8 length without TextEncoder: the host re-measures with Buffer.byteLength
|
|
106829
|
+
// before it writes, so this is only the fast pre-check the page sees first.
|
|
106830
|
+
function sizeOf(text) {
|
|
106831
|
+
var bytes = 0;
|
|
106832
|
+
for (var i = 0; i < text.length; i += 1) {
|
|
106833
|
+
var code = text.charCodeAt(i);
|
|
106834
|
+
if (code < 0x80) bytes += 1;
|
|
106835
|
+
else if (code < 0x800) bytes += 2;
|
|
106836
|
+
else if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {
|
|
106837
|
+
var next = text.charCodeAt(i + 1);
|
|
106838
|
+
if (next >= 0xdc00 && next <= 0xdfff) { bytes += 4; i += 1; } else bytes += 3;
|
|
106839
|
+
} else bytes += 3;
|
|
106840
|
+
}
|
|
106841
|
+
return bytes;
|
|
106842
|
+
}
|
|
106843
|
+
|
|
106844
|
+
/*
|
|
106845
|
+
* NO GESTURE JUDGEMENT HERE, deliberately. This world's
|
|
106846
|
+
* navigator.userActivation, Date.now and JSON.stringify are all page-patchable,
|
|
106847
|
+
* so a check made here is not a control. The host asks the ISOLATED world
|
|
106848
|
+
* instead; this function's only job is to carry the bytes and settle the
|
|
106849
|
+
* promise on the host's answer.
|
|
106850
|
+
*/
|
|
106851
|
+
function writeThroughHost(text) {
|
|
106852
|
+
var size = sizeOf(text);
|
|
106853
|
+
if (size > config.maxBytes) {
|
|
106854
|
+
return refuses("the text is too large to copy (" + size + " bytes)", "QuotaExceededError");
|
|
106855
|
+
}
|
|
106856
|
+
var send = window[config.binding];
|
|
106857
|
+
if (typeof send !== "function") {
|
|
106858
|
+
// No binding means no host in this document (an older host, a world the
|
|
106859
|
+
// program reached before the binding existed): keep the native behaviour.
|
|
106860
|
+
return nativeWriteText(text);
|
|
106861
|
+
}
|
|
106862
|
+
var id = nextId++;
|
|
106863
|
+
return new Promise(function (resolve, reject) {
|
|
106864
|
+
var timer = setTimeout(function () {
|
|
106865
|
+
pending.delete(id);
|
|
106866
|
+
reject(new DOMException("the host did not confirm the clipboard write", "NotAllowedError"));
|
|
106867
|
+
}, config.timeoutMs);
|
|
106868
|
+
pending.set(id, { resolve: resolve, reject: reject, timer: timer });
|
|
106869
|
+
try {
|
|
106870
|
+
// ONE argument, by concatenation: the id, a newline, the text. No JSON in
|
|
106871
|
+
// the payload path, so there is no captured helper for a page to swap.
|
|
106872
|
+
send(id + ${JSON.stringify(PAYLOAD_SEPARATOR)} + String(text));
|
|
106873
|
+
} catch (error) {
|
|
106874
|
+
clearTimeout(timer);
|
|
106875
|
+
pending.delete(id);
|
|
106876
|
+
reject(new DOMException("the host refused the clipboard write", "NotAllowedError"));
|
|
106877
|
+
}
|
|
106878
|
+
});
|
|
106879
|
+
}
|
|
106880
|
+
|
|
106881
|
+
function installWriteText() {
|
|
106882
|
+
try {
|
|
106883
|
+
Object.defineProperty(clipboard, "writeText", {
|
|
106884
|
+
value: function writeText(text) {
|
|
106885
|
+
return writeThroughHost(String(text === null || text === undefined ? "" : text));
|
|
106886
|
+
},
|
|
106887
|
+
configurable: true,
|
|
106888
|
+
writable: true,
|
|
106889
|
+
});
|
|
106890
|
+
} catch (error) {
|
|
106891
|
+
/* an unwritable clipboard keeps the native behaviour */
|
|
106892
|
+
}
|
|
106893
|
+
}
|
|
106894
|
+
|
|
106895
|
+
function installWrite() {
|
|
106896
|
+
if (!nativeWrite) return;
|
|
106897
|
+
try {
|
|
106898
|
+
Object.defineProperty(clipboard, "write", {
|
|
106899
|
+
value: function write(items) {
|
|
106900
|
+
var list = Array.isArray(items) ? items : [items];
|
|
106901
|
+
var first = list[0];
|
|
106902
|
+
// TEXT ONLY. Anything else (an image, an unknown type) falls through to
|
|
106903
|
+
// the native path, which fails exactly as it does today: the host will
|
|
106904
|
+
// not be talked into copying bytes it never inspected.
|
|
106905
|
+
if (list.length !== 1 || !first || typeof first.getType !== "function") {
|
|
106906
|
+
return nativeWrite(items);
|
|
106907
|
+
}
|
|
106908
|
+
var types = first.types;
|
|
106909
|
+
if (!types || Array.prototype.indexOf.call(types, "text/plain") === -1) {
|
|
106910
|
+
return nativeWrite(items);
|
|
106911
|
+
}
|
|
106912
|
+
return Promise.resolve(first.getType("text/plain"))
|
|
106913
|
+
.then(function (blob) { return blob.text(); })
|
|
106914
|
+
.then(function (text) { return writeThroughHost(String(text)); });
|
|
106915
|
+
},
|
|
106916
|
+
configurable: true,
|
|
106917
|
+
writable: true,
|
|
106918
|
+
});
|
|
106919
|
+
} catch (error) {
|
|
106920
|
+
/* as above */
|
|
106921
|
+
}
|
|
106922
|
+
}
|
|
106923
|
+
|
|
106924
|
+
function statusFor(state) {
|
|
106925
|
+
return {
|
|
106926
|
+
state: state,
|
|
106927
|
+
onchange: null,
|
|
106928
|
+
addEventListener: function () {},
|
|
106929
|
+
removeEventListener: function () {},
|
|
106930
|
+
dispatchEvent: function () { return true; },
|
|
106931
|
+
};
|
|
106932
|
+
}
|
|
106933
|
+
|
|
106934
|
+
function installPermissionQuery() {
|
|
106935
|
+
if (!nativeQuery) return;
|
|
106936
|
+
try {
|
|
106937
|
+
Object.defineProperty(navigator.permissions, "query", {
|
|
106938
|
+
value: function query(descriptor) {
|
|
106939
|
+
var name = descriptor && descriptor.name;
|
|
106940
|
+
// REPORTED CAPABILITY, NOT A CHROMIUM PERMISSION: pages feature-detect a
|
|
106941
|
+
// write with this name before attempting one, and the honest answer for a
|
|
106942
|
+
// document where the write above is installed is "granted" — the host
|
|
106943
|
+
// decides each write. The READ name is deliberately untouched, so it
|
|
106944
|
+
// keeps answering the truth (denied).
|
|
106945
|
+
if (name === "clipboard-write") return Promise.resolve(statusFor("granted"));
|
|
106946
|
+
return nativeQuery(descriptor);
|
|
106947
|
+
},
|
|
106948
|
+
configurable: true,
|
|
106949
|
+
writable: true,
|
|
106950
|
+
});
|
|
106951
|
+
} catch (error) {
|
|
106952
|
+
/* as above */
|
|
106953
|
+
}
|
|
106954
|
+
}
|
|
106955
|
+
|
|
106956
|
+
installWriteText();
|
|
106957
|
+
installWrite();
|
|
106958
|
+
installPermissionQuery();
|
|
106959
|
+
})(${config});`;
|
|
106960
|
+
}
|
|
106961
|
+
const views = /* @__PURE__ */ new Map();
|
|
106962
|
+
const hostNow = () => performance.now();
|
|
106963
|
+
async function installClipboardShim(cdp, contents, webContentsId, options = {}) {
|
|
106964
|
+
const previous = views.get(webContentsId);
|
|
106965
|
+
if (previous) {
|
|
106966
|
+
previous.dispose();
|
|
106967
|
+
views.delete(webContentsId);
|
|
106968
|
+
}
|
|
106969
|
+
const source = clipboardShimSource();
|
|
106970
|
+
const state2 = {
|
|
106971
|
+
dispose: () => void 0,
|
|
106972
|
+
contexts: /* @__PURE__ */ new Map(),
|
|
106973
|
+
isolated: /* @__PURE__ */ new Map(),
|
|
106974
|
+
log: options.log
|
|
106975
|
+
};
|
|
106976
|
+
views.set(webContentsId, state2);
|
|
106977
|
+
const apply = async (contextId) => {
|
|
106978
|
+
if (contextId === void 0) {
|
|
106979
|
+
await cdp.send(contents, "Page.enable", {});
|
|
106980
|
+
await cdp.send(contents, "Runtime.addBinding", {
|
|
106981
|
+
name: CLIPBOARD_BINDING
|
|
106982
|
+
});
|
|
106983
|
+
await cdp.send(contents, "Page.addScriptToEvaluateOnNewDocument", {
|
|
106984
|
+
source
|
|
106985
|
+
});
|
|
106986
|
+
}
|
|
106987
|
+
await cdp.send(contents, "Runtime.evaluate", {
|
|
106988
|
+
expression: source,
|
|
106989
|
+
returnByValue: true,
|
|
106990
|
+
...contextId === void 0 ? {} : { contextId }
|
|
106991
|
+
});
|
|
106992
|
+
};
|
|
106993
|
+
const refreshMainFrame = async () => {
|
|
106994
|
+
try {
|
|
106995
|
+
const tree = await cdp.send(contents, "Page.getFrameTree", {});
|
|
106996
|
+
const id2 = tree?.frameTree?.frame?.id;
|
|
106997
|
+
if (typeof id2 === "string" && id2) state2.mainFrameId = id2;
|
|
106998
|
+
} catch {
|
|
106999
|
+
}
|
|
107000
|
+
};
|
|
107001
|
+
let reinstalling = false;
|
|
107002
|
+
state2.dispose = cdp.subscribe(webContentsId, (method, params) => {
|
|
107003
|
+
if (method === "Runtime.bindingCalled") {
|
|
107004
|
+
if (String(params.name ?? "") !== CLIPBOARD_BINDING) return;
|
|
107005
|
+
void answerBinding(cdp, contents, webContentsId, state2, params);
|
|
107006
|
+
return;
|
|
107007
|
+
}
|
|
107008
|
+
if (method === "Runtime.executionContextCreated") {
|
|
107009
|
+
const context = params.context ?? {};
|
|
107010
|
+
if (typeof context.id !== "number") return;
|
|
107011
|
+
const frameId = context.auxData?.frameId;
|
|
107012
|
+
if (typeof frameId === "string") {
|
|
107013
|
+
state2.contexts.set(context.id, {
|
|
107014
|
+
frameId,
|
|
107015
|
+
isDefault: context.auxData?.isDefault === true
|
|
107016
|
+
});
|
|
107017
|
+
}
|
|
107018
|
+
if (context.auxData?.isDefault !== true) return;
|
|
107019
|
+
if (reinstalling || contents.isDestroyed()) return;
|
|
107020
|
+
reinstalling = true;
|
|
107021
|
+
void apply(context.id).catch((error) => {
|
|
107022
|
+
options.log?.(
|
|
107023
|
+
`[browser] could not install the page clipboard write on view ${webContentsId}: ${error instanceof Error ? error.message : String(error)}`
|
|
107024
|
+
);
|
|
107025
|
+
}).finally(() => {
|
|
107026
|
+
reinstalling = false;
|
|
107027
|
+
});
|
|
107028
|
+
return;
|
|
107029
|
+
}
|
|
107030
|
+
if (method === "Runtime.executionContextDestroyed") {
|
|
107031
|
+
const id2 = params.executionContextId;
|
|
107032
|
+
if (typeof id2 === "number") {
|
|
107033
|
+
const known = state2.contexts.get(id2);
|
|
107034
|
+
state2.contexts.delete(id2);
|
|
107035
|
+
if (known) state2.isolated.delete(known.frameId);
|
|
107036
|
+
}
|
|
107037
|
+
return;
|
|
107038
|
+
}
|
|
107039
|
+
if (method === "Runtime.executionContextsCleared") {
|
|
107040
|
+
state2.contexts.clear();
|
|
107041
|
+
state2.isolated.clear();
|
|
107042
|
+
return;
|
|
107043
|
+
}
|
|
107044
|
+
if (method === "Page.frameNavigated") {
|
|
107045
|
+
const frame = params.frame ?? {};
|
|
107046
|
+
if (frame.parentId === void 0 && typeof frame.id === "string") {
|
|
107047
|
+
state2.mainFrameId = frame.id;
|
|
107048
|
+
}
|
|
107049
|
+
}
|
|
107050
|
+
});
|
|
107051
|
+
try {
|
|
107052
|
+
await apply();
|
|
107053
|
+
await refreshMainFrame();
|
|
107054
|
+
} catch (error) {
|
|
107055
|
+
state2.dispose();
|
|
107056
|
+
views.delete(webContentsId);
|
|
107057
|
+
throw error;
|
|
107058
|
+
}
|
|
107059
|
+
}
|
|
107060
|
+
function armHostClipboardWrite(webContentsId, frameId, windowMs = CLIPBOARD_ARM_WINDOW_MS) {
|
|
107061
|
+
const state2 = views.get(webContentsId);
|
|
107062
|
+
if (!state2) return false;
|
|
107063
|
+
const frame = frameId ?? state2.mainFrameId;
|
|
107064
|
+
if (!frame) return false;
|
|
107065
|
+
state2.arm = { frameId: frame, expiresAt: hostNow() + windowMs };
|
|
107066
|
+
return true;
|
|
107067
|
+
}
|
|
107068
|
+
function clearHostClipboardArm(webContentsId) {
|
|
107069
|
+
const state2 = views.get(webContentsId);
|
|
107070
|
+
if (state2) state2.arm = void 0;
|
|
107071
|
+
}
|
|
107072
|
+
async function writeVerdict(cdp, contents, state2, frameId) {
|
|
107073
|
+
let activated = false;
|
|
107074
|
+
try {
|
|
107075
|
+
const contextId = await isolatedContextFor(cdp, contents, state2, frameId);
|
|
107076
|
+
const reply = await cdp.send(
|
|
107077
|
+
contents,
|
|
107078
|
+
"Runtime.evaluate",
|
|
107079
|
+
{
|
|
107080
|
+
expression: "navigator.userActivation.isActive === true",
|
|
107081
|
+
contextId,
|
|
107082
|
+
returnByValue: true
|
|
107083
|
+
}
|
|
107084
|
+
);
|
|
107085
|
+
activated = reply?.result?.value === true;
|
|
107086
|
+
} catch (error) {
|
|
107087
|
+
return {
|
|
107088
|
+
allowed: false,
|
|
107089
|
+
reason: `could not verify user activation (${error instanceof Error ? error.message : String(error)})`
|
|
107090
|
+
};
|
|
107091
|
+
}
|
|
107092
|
+
if (activated) {
|
|
107093
|
+
clearHostClipboardArmView(state2);
|
|
107094
|
+
return { allowed: true, reason: "user activation" };
|
|
107095
|
+
}
|
|
107096
|
+
const arm = state2.arm;
|
|
107097
|
+
if (arm && arm.frameId === frameId && arm.expiresAt > hostNow()) {
|
|
107098
|
+
clearHostClipboardArmView(state2);
|
|
107099
|
+
return { allowed: true, reason: "agent click arm" };
|
|
107100
|
+
}
|
|
107101
|
+
return {
|
|
107102
|
+
allowed: false,
|
|
107103
|
+
reason: arm ? arm.frameId === frameId ? "the agent-click arm has expired" : "the agent-click arm was minted for another frame" : "no user activation in this frame and no agent-click arm"
|
|
107104
|
+
};
|
|
107105
|
+
}
|
|
107106
|
+
function clearHostClipboardArmView(state2) {
|
|
107107
|
+
state2.arm = void 0;
|
|
107108
|
+
}
|
|
107109
|
+
async function isolatedContextFor(cdp, contents, state2, frameId) {
|
|
107110
|
+
const cached2 = state2.isolated.get(frameId);
|
|
107111
|
+
if (cached2 !== void 0) return cached2;
|
|
107112
|
+
const created = await cdp.send(
|
|
107113
|
+
contents,
|
|
107114
|
+
"Page.createIsolatedWorld",
|
|
107115
|
+
{
|
|
107116
|
+
frameId,
|
|
107117
|
+
// A NAME, not a secret: the world is identified by frame and name, and
|
|
107118
|
+
// nothing about this gate depends on the name being unforgeable.
|
|
107119
|
+
worldName: "local-operator-clipboard"
|
|
107120
|
+
}
|
|
107121
|
+
);
|
|
107122
|
+
const contextId = created?.executionContextId;
|
|
107123
|
+
if (typeof contextId !== "number") {
|
|
107124
|
+
throw new Error("Page.createIsolatedWorld returned no executionContextId");
|
|
107125
|
+
}
|
|
107126
|
+
state2.isolated.set(frameId, contextId);
|
|
107127
|
+
return contextId;
|
|
107128
|
+
}
|
|
107129
|
+
async function answerBinding(cdp, contents, webContentsId, state2, params) {
|
|
107130
|
+
const contextId = params.executionContextId;
|
|
107131
|
+
const ack = (id22, ok) => {
|
|
107132
|
+
if (typeof contextId !== "number") return;
|
|
107133
|
+
void cdp.send(contents, "Runtime.evaluate", {
|
|
107134
|
+
expression: `${CLIPBOARD_ACK}(${id22}, ${ok ? "true" : "false"})`,
|
|
107135
|
+
contextId,
|
|
107136
|
+
returnByValue: true
|
|
107137
|
+
}).catch(() => void 0);
|
|
107138
|
+
};
|
|
107139
|
+
const raw = String(params.payload ?? "");
|
|
107140
|
+
const splitAt = raw.indexOf(PAYLOAD_SEPARATOR);
|
|
107141
|
+
if (splitAt <= 0) return;
|
|
107142
|
+
const id2 = Number(raw.slice(0, splitAt));
|
|
107143
|
+
if (!Number.isSafeInteger(id2)) return;
|
|
107144
|
+
const text2 = raw.slice(splitAt + PAYLOAD_SEPARATOR.length);
|
|
107145
|
+
const known = typeof contextId === "number" ? state2.contexts.get(contextId) : void 0;
|
|
107146
|
+
if (!known) {
|
|
107147
|
+
state2.log?.(
|
|
107148
|
+
`[browser] refused a page clipboard write on view ${webContentsId}: unknown execution context`
|
|
107149
|
+
);
|
|
107150
|
+
ack(id2, false);
|
|
107151
|
+
return;
|
|
107152
|
+
}
|
|
107153
|
+
if (state2.mainFrameId !== void 0 && known.frameId !== state2.mainFrameId) {
|
|
107154
|
+
state2.log?.(
|
|
107155
|
+
`[browser] refused a page clipboard write on view ${webContentsId}: frame ${known.frameId} is not the main frame (main-frame-only by design)`
|
|
107156
|
+
);
|
|
107157
|
+
ack(id2, false);
|
|
107158
|
+
return;
|
|
107159
|
+
}
|
|
107160
|
+
const verdict = await writeVerdict(cdp, contents, state2, known.frameId);
|
|
107161
|
+
if (!verdict.allowed) {
|
|
107162
|
+
state2.log?.(
|
|
107163
|
+
`[browser] refused a page clipboard write on view ${webContentsId} (frame ${known.frameId}): ${verdict.reason}`
|
|
107164
|
+
);
|
|
107165
|
+
ack(id2, false);
|
|
107166
|
+
return;
|
|
107167
|
+
}
|
|
107168
|
+
if (Buffer.byteLength(text2, "utf8") > CLIPBOARD_SHIM_MAX_BYTES) {
|
|
107169
|
+
state2.log?.(
|
|
107170
|
+
`[browser] refused a page clipboard write on view ${webContentsId}: over the ${CLIPBOARD_SHIM_MAX_BYTES}-byte cap`
|
|
107171
|
+
);
|
|
107172
|
+
ack(id2, false);
|
|
107173
|
+
return;
|
|
107174
|
+
}
|
|
107175
|
+
try {
|
|
107176
|
+
const { clipboard } = await import("electron");
|
|
107177
|
+
await clipboard.writeText(text2);
|
|
107178
|
+
state2.log?.(
|
|
107179
|
+
`[browser] wrote a page clipboard copy on view ${webContentsId} (frame ${known.frameId}, ${verdict.reason})`
|
|
107180
|
+
);
|
|
107181
|
+
ack(id2, true);
|
|
107182
|
+
} catch (error) {
|
|
107183
|
+
state2.log?.(
|
|
107184
|
+
`[browser] the clipboard refused a page write on view ${webContentsId}: ${error instanceof Error ? error.message : String(error)}`
|
|
107185
|
+
);
|
|
107186
|
+
ack(id2, false);
|
|
107187
|
+
}
|
|
107188
|
+
}
|
|
105406
107189
|
function requesterOf(params, requestId2) {
|
|
105407
107190
|
const supplied = typeof params.requester === "string" ? params.requester.trim() : "";
|
|
105408
107191
|
return supplied.startsWith("session:") ? supplied : requestId2;
|
|
@@ -107885,6 +109668,15 @@ class CdpPool {
|
|
|
107885
109668
|
},
|
|
107886
109669
|
CDP_DEADLINE_MS
|
|
107887
109670
|
);
|
|
109671
|
+
try {
|
|
109672
|
+
await installClipboardShim(this, contents, contents.id, {
|
|
109673
|
+
log: this.options.log
|
|
109674
|
+
});
|
|
109675
|
+
} catch (error) {
|
|
109676
|
+
this.options.log?.(
|
|
109677
|
+
`[browser] could not install the page clipboard write on view ${contents.id}: ${error instanceof Error ? error.message : String(error)}`
|
|
109678
|
+
);
|
|
109679
|
+
}
|
|
107888
109680
|
} catch (error) {
|
|
107889
109681
|
this.forget(contents.id);
|
|
107890
109682
|
throw error;
|
|
@@ -108897,6 +110689,25 @@ function stateSuffix(node) {
|
|
|
108897
110689
|
if (truthy(property("disabled"))) markers.push("disabled");
|
|
108898
110690
|
return markers.length ? ` [${markers.join("] [")}]` : "";
|
|
108899
110691
|
}
|
|
110692
|
+
const VALUE_BEARING = /* @__PURE__ */ new Set(["combobox", "option", "listbox", "textbox", "spinbutton", "searchbox", "slider"]);
|
|
110693
|
+
const VALUE_CLIP = 40;
|
|
110694
|
+
const MASK_ONLY = /^\u2022+$/u;
|
|
110695
|
+
function valueSuffix(node, name) {
|
|
110696
|
+
const role = String(node.role?.value ?? "");
|
|
110697
|
+
if (!VALUE_BEARING.has(role)) return "";
|
|
110698
|
+
const property = (propertyName) => node.properties?.find((entry) => entry.name === propertyName)?.value.value;
|
|
110699
|
+
const protectedField = property("protected");
|
|
110700
|
+
if (protectedField === true || protectedField === "true") return "";
|
|
110701
|
+
const valuetext = property("valuetext");
|
|
110702
|
+
const preferred = typeof valuetext === "string" && valuetext.trim() ? valuetext : node.value?.value;
|
|
110703
|
+
if (typeof preferred !== "string" && typeof preferred !== "number") return "";
|
|
110704
|
+
const collapsed = String(preferred).replace(/\s+/g, " ").trim();
|
|
110705
|
+
if (!collapsed || MASK_ONLY.test(collapsed)) return "";
|
|
110706
|
+
if (collapsed === name.replace(/\s+/g, " ").trim()) return "";
|
|
110707
|
+
const points = Array.from(collapsed);
|
|
110708
|
+
const clipped = points.length > VALUE_CLIP ? `${points.slice(0, VALUE_CLIP).join("")}…` : collapsed;
|
|
110709
|
+
return ` = ${JSON.stringify(clipped)}`;
|
|
110710
|
+
}
|
|
108900
110711
|
function compactAX(nodes, epoch, options = {}) {
|
|
108901
110712
|
const byId = new Map(nodes.map((node) => [node.nodeId, node]));
|
|
108902
110713
|
const refs = {};
|
|
@@ -108935,7 +110746,7 @@ function compactAX(nodes, epoch, options = {}) {
|
|
|
108935
110746
|
}
|
|
108936
110747
|
if (inside2) {
|
|
108937
110748
|
const shown = depth - (scopeAt ?? 0);
|
|
108938
|
-
lines.push(`${" ".repeat(shown)}- ${role || "node"}${name ? ` ${JSON.stringify(name)}` : ""}${ref ? ` [${ref}]` : ""}${stateSuffix(node)}`);
|
|
110749
|
+
lines.push(`${" ".repeat(shown)}- ${role || "node"}${name ? ` ${JSON.stringify(name)}` : ""}${ref ? ` [${ref}]` : ""}${stateSuffix(node)}${valueSuffix(node, name)}`);
|
|
108939
110750
|
}
|
|
108940
110751
|
}
|
|
108941
110752
|
for (const child of node.childIds ?? []) {
|
|
@@ -109057,6 +110868,132 @@ async function read(ctx, params) {
|
|
|
109057
110868
|
ctx.registry.touch(record);
|
|
109058
110869
|
return { text: String(text2), ...pageOf(record.view) };
|
|
109059
110870
|
}
|
|
110871
|
+
const COPY_TEXT_FUNCTION = `function (selector) {
|
|
110872
|
+
const matches = document.querySelectorAll(selector);
|
|
110873
|
+
if (matches.length !== 1) {
|
|
110874
|
+
return {
|
|
110875
|
+
status: matches.length === 0 ? "missing" : "ambiguous",
|
|
110876
|
+
count: matches.length,
|
|
110877
|
+
matches: Array.prototype.slice.call(matches, 0, 5).map(function (node) {
|
|
110878
|
+
return {
|
|
110879
|
+
tag: String(node.tagName || "").toLowerCase(),
|
|
110880
|
+
id: String(node.id || ""),
|
|
110881
|
+
name: String((node.getAttribute && node.getAttribute("name")) || ""),
|
|
110882
|
+
};
|
|
110883
|
+
}),
|
|
110884
|
+
};
|
|
110885
|
+
}
|
|
110886
|
+
const element = matches[0];
|
|
110887
|
+
const tag = String(element.tagName || "").toLowerCase();
|
|
110888
|
+
const field = tag === "input" || tag === "textarea" || tag === "select";
|
|
110889
|
+
const raw = field ? element.value : element.textContent;
|
|
110890
|
+
return {
|
|
110891
|
+
status: "ok",
|
|
110892
|
+
count: 1,
|
|
110893
|
+
tag: tag,
|
|
110894
|
+
id: String(element.id || ""),
|
|
110895
|
+
name: String((element.getAttribute && element.getAttribute("name")) || ""),
|
|
110896
|
+
text: field ? String(raw === null || raw === undefined ? "" : raw) : String(raw === null || raw === undefined ? "" : raw).trim(),
|
|
110897
|
+
};
|
|
110898
|
+
}`;
|
|
110899
|
+
async function copy(ctx, params) {
|
|
110900
|
+
const selector = stringParam(params, "selector");
|
|
110901
|
+
if (!selector) {
|
|
110902
|
+
throw new BridgeCommandError("internal", "copy needs a selector", {
|
|
110903
|
+
reason: "invalid_arguments"
|
|
110904
|
+
});
|
|
110905
|
+
}
|
|
110906
|
+
const record = ctx.registry.requireSurface(params.tab);
|
|
110907
|
+
const code = `(${COPY_TEXT_FUNCTION})(${JSON.stringify(selector)})`;
|
|
110908
|
+
let answer;
|
|
110909
|
+
try {
|
|
110910
|
+
answer = await deadline(
|
|
110911
|
+
record.view.webContents.executeJavaScriptInIsolatedWorld(
|
|
110912
|
+
ISOLATED_WORLD_ID,
|
|
110913
|
+
[{ code }]
|
|
110914
|
+
),
|
|
110915
|
+
SCRIPTING_DEADLINE_MS,
|
|
110916
|
+
`copy(${selector})`
|
|
110917
|
+
);
|
|
110918
|
+
} catch (error) {
|
|
110919
|
+
if (error instanceof Error && INVALID_SELECTOR.test(error.message)) {
|
|
110920
|
+
throw new BridgeCommandError(
|
|
110921
|
+
"element_not_found",
|
|
110922
|
+
`selector ${selector} is not valid`
|
|
110923
|
+
);
|
|
110924
|
+
}
|
|
110925
|
+
throw error;
|
|
110926
|
+
}
|
|
110927
|
+
const read2 = answer && typeof answer === "object" ? answer : {};
|
|
110928
|
+
if (read2.status === "missing") {
|
|
110929
|
+
throw new BridgeCommandError(
|
|
110930
|
+
"element_not_found",
|
|
110931
|
+
`selector ${selector} matched nothing`
|
|
110932
|
+
);
|
|
110933
|
+
}
|
|
110934
|
+
if (read2.status === "ambiguous") {
|
|
110935
|
+
const count = typeof read2.count === "number" ? read2.count : 0;
|
|
110936
|
+
throw new BridgeCommandError(
|
|
110937
|
+
"element_not_found",
|
|
110938
|
+
`selector ${selector} matched ${count} elements; copy needs exactly one`,
|
|
110939
|
+
{
|
|
110940
|
+
reason: "ambiguous_selector",
|
|
110941
|
+
count,
|
|
110942
|
+
matches: Array.isArray(read2.matches) ? read2.matches : []
|
|
110943
|
+
}
|
|
110944
|
+
);
|
|
110945
|
+
}
|
|
110946
|
+
if (read2.status !== "ok" || typeof read2.text !== "string") {
|
|
110947
|
+
throw new BridgeCommandError(
|
|
110948
|
+
"internal",
|
|
110949
|
+
`copy could not read the element ${selector} names`,
|
|
110950
|
+
{ reason: "unreadable_answer" }
|
|
110951
|
+
);
|
|
110952
|
+
}
|
|
110953
|
+
if (!read2.text) {
|
|
110954
|
+
throw new BridgeCommandError(
|
|
110955
|
+
"empty_element_text",
|
|
110956
|
+
`selector ${selector} matched an element with no text to copy`,
|
|
110957
|
+
{ reason: "empty_text" }
|
|
110958
|
+
);
|
|
110959
|
+
}
|
|
110960
|
+
const text2 = read2.text;
|
|
110961
|
+
const { clipboard } = await import("electron");
|
|
110962
|
+
try {
|
|
110963
|
+
await clipboard.writeText(text2);
|
|
110964
|
+
} catch (error) {
|
|
110965
|
+
throw new BridgeCommandError(
|
|
110966
|
+
"clipboard_write_failed",
|
|
110967
|
+
`the clipboard refused the text of ${selector}: ${error instanceof Error ? error.message : String(error)}`,
|
|
110968
|
+
{ reason: "clipboard_write_failed" }
|
|
110969
|
+
);
|
|
110970
|
+
}
|
|
110971
|
+
let verified = false;
|
|
110972
|
+
try {
|
|
110973
|
+
verified = await clipboard.readText() === text2;
|
|
110974
|
+
} catch {
|
|
110975
|
+
verified = false;
|
|
110976
|
+
}
|
|
110977
|
+
const receipt = {
|
|
110978
|
+
// `chars` is the character count a reader expects (code points, so an emoji
|
|
110979
|
+
// counts once), not `String.length`'s UTF-16 units: the audience for this
|
|
110980
|
+
// number is a person checking a key came across whole.
|
|
110981
|
+
chars: Array.from(text2).length,
|
|
110982
|
+
// THE FINGERPRINT IS THE POINT OF THE RECEIPT: it lets a caller prove WHICH
|
|
110983
|
+
// bytes landed on the clipboard without ever holding them, and it is what
|
|
110984
|
+
// makes `lop secret set` verifiable later — re-copy the same element, compare
|
|
110985
|
+
// the hash, and know the value is the one already stored.
|
|
110986
|
+
sha256: node_crypto.createHash("sha256").update(text2, "utf8").digest("hex").slice(0, 16),
|
|
110987
|
+
element: {
|
|
110988
|
+
tag: typeof read2.tag === "string" ? read2.tag : "",
|
|
110989
|
+
id: typeof read2.id === "string" ? read2.id : "",
|
|
110990
|
+
name: typeof read2.name === "string" ? read2.name : ""
|
|
110991
|
+
},
|
|
110992
|
+
verified
|
|
110993
|
+
};
|
|
110994
|
+
ctx.registry.touch(record);
|
|
110995
|
+
return { ...receipt };
|
|
110996
|
+
}
|
|
109060
110997
|
async function snapshot(ctx, params) {
|
|
109061
110998
|
const record = ctx.registry.requireSurface(params.tab);
|
|
109062
110999
|
const contents = record.view.webContents;
|
|
@@ -110059,6 +111996,8 @@ async function click(ctx, params) {
|
|
|
110059
111996
|
navigationSeen = true;
|
|
110060
111997
|
};
|
|
110061
111998
|
contents.on("did-start-navigation", onStart);
|
|
111999
|
+
const armableTarget = node.sessionId === void 0;
|
|
112000
|
+
if (armableTarget) armHostClipboardWrite(contents.id, node.frame?.frameId);
|
|
110062
112001
|
try {
|
|
110063
112002
|
await sendIn(ctx, contents, node.sessionId, "Runtime.callFunctionOn", {
|
|
110064
112003
|
objectId: node.objectId,
|
|
@@ -110067,6 +112006,7 @@ async function click(ctx, params) {
|
|
|
110067
112006
|
});
|
|
110068
112007
|
await sleep(1200);
|
|
110069
112008
|
} finally {
|
|
112009
|
+
if (armableTarget) clearHostClipboardArm(contents.id);
|
|
110070
112010
|
contents.removeListener("did-start-navigation", onStart);
|
|
110071
112011
|
}
|
|
110072
112012
|
if (navigationSeen) {
|
|
@@ -110489,10 +112429,10 @@ async function query(ctx, params) {
|
|
|
110489
112429
|
ctx.registry.touch(record);
|
|
110490
112430
|
return { ...result, ...pageOf(record.view) };
|
|
110491
112431
|
}
|
|
110492
|
-
function selectPage(mode, requested) {
|
|
112432
|
+
const SELECT_PAGE_SOURCE = `function selectPage(mode, requested) {
|
|
110493
112433
|
const doc = this.ownerDocument;
|
|
110494
112434
|
const win = doc.defaultView;
|
|
110495
|
-
const
|
|
112435
|
+
const clip = (text) => text.slice(0, 120);
|
|
110496
112436
|
const native = this instanceof win.HTMLSelectElement;
|
|
110497
112437
|
const kind = native ? "native" : "aria";
|
|
110498
112438
|
if (!native && !this.matches(
|
|
@@ -110505,8 +112445,8 @@ function selectPage(mode, requested) {
|
|
|
110505
112445
|
if (mode === "trigger") return { status: "ready", kind };
|
|
110506
112446
|
let root = this;
|
|
110507
112447
|
if (!native && !this.matches('[role="listbox"]')) {
|
|
110508
|
-
const ids = (this.getAttribute("aria-controls") || this.getAttribute("aria-owns") || "").split(
|
|
110509
|
-
const controlled = ids.map((
|
|
112448
|
+
const ids = (this.getAttribute("aria-controls") || this.getAttribute("aria-owns") || "").split(/\\s+/).filter(Boolean);
|
|
112449
|
+
const controlled = ids.map((id) => doc.getElementById(id)).filter((el) => !!el);
|
|
110510
112450
|
const candidates = controlled.length ? controlled : Array.from(doc.querySelectorAll('[role="listbox"]')).filter(
|
|
110511
112451
|
(el) => el.getClientRects().length > 0
|
|
110512
112452
|
);
|
|
@@ -110521,8 +112461,8 @@ function selectPage(mode, requested) {
|
|
|
110521
112461
|
}));
|
|
110522
112462
|
const available = facts.slice(0, 50).map((fact) => ({
|
|
110523
112463
|
...fact,
|
|
110524
|
-
label:
|
|
110525
|
-
value:
|
|
112464
|
+
label: clip(fact.label),
|
|
112465
|
+
value: clip(fact.value)
|
|
110526
112466
|
}));
|
|
110527
112467
|
const multiple = native ? this.multiple : root.getAttribute("aria-multiselectable") === "true";
|
|
110528
112468
|
if (mode === "describe") return { status: "ready", kind, multiple };
|
|
@@ -110565,8 +112505,12 @@ function selectPage(mode, requested) {
|
|
|
110565
112505
|
win.HTMLSelectElement.prototype,
|
|
110566
112506
|
"selectedIndex"
|
|
110567
112507
|
).set.call(this, indexes[0] ?? -1);
|
|
110568
|
-
this.dispatchEvent(
|
|
110569
|
-
|
|
112508
|
+
this.dispatchEvent(
|
|
112509
|
+
new win.Event("input", { bubbles: true, composed: true })
|
|
112510
|
+
);
|
|
112511
|
+
this.dispatchEvent(
|
|
112512
|
+
new win.Event("change", { bubbles: true, composed: true })
|
|
112513
|
+
);
|
|
110570
112514
|
}
|
|
110571
112515
|
const selected = facts.filter(
|
|
110572
112516
|
(o) => native ? elements[o.index].selected : elements[o.index].getAttribute("aria-selected") === "true"
|
|
@@ -110583,7 +112527,141 @@ function selectPage(mode, requested) {
|
|
|
110583
112527
|
verified,
|
|
110584
112528
|
available
|
|
110585
112529
|
};
|
|
110586
|
-
}
|
|
112530
|
+
}`;
|
|
112531
|
+
const SETVALUE_PAGE_SOURCE = `function setvaluePage(requested) {
|
|
112532
|
+
const doc = this.ownerDocument;
|
|
112533
|
+
const win = doc.defaultView;
|
|
112534
|
+
const clip = (text) => text.slice(0, 120);
|
|
112535
|
+
const value = typeof requested === "string" ? requested : "";
|
|
112536
|
+
const element = this;
|
|
112537
|
+
const tag = element.tagName;
|
|
112538
|
+
const isSelect = this instanceof win.HTMLSelectElement;
|
|
112539
|
+
const isTextarea = this instanceof win.HTMLTextAreaElement;
|
|
112540
|
+
const isInput = this instanceof win.HTMLInputElement;
|
|
112541
|
+
const dispatch = (target) => {
|
|
112542
|
+
target.dispatchEvent(
|
|
112543
|
+
new win.Event("input", { bubbles: true, composed: true })
|
|
112544
|
+
);
|
|
112545
|
+
target.dispatchEvent(
|
|
112546
|
+
new win.Event("change", { bubbles: true, composed: true })
|
|
112547
|
+
);
|
|
112548
|
+
};
|
|
112549
|
+
if (!isSelect && !isTextarea && !isInput) {
|
|
112550
|
+
return { status: "not_a_form_control", tag: tag.toLowerCase() };
|
|
112551
|
+
}
|
|
112552
|
+
if (isInput && this.type === "file") {
|
|
112553
|
+
return { status: "file_input" };
|
|
112554
|
+
}
|
|
112555
|
+
if (isInput && ["checkbox", "radio"].includes(this.type)) {
|
|
112556
|
+
return {
|
|
112557
|
+
status: "not_a_value_control",
|
|
112558
|
+
tag: tag.toLowerCase(),
|
|
112559
|
+
input_type: this.type
|
|
112560
|
+
};
|
|
112561
|
+
}
|
|
112562
|
+
if (this.matches(":disabled, [aria-disabled=true]") || this.closest("[inert]")) {
|
|
112563
|
+
return { status: "disabled", tag: tag.toLowerCase() };
|
|
112564
|
+
}
|
|
112565
|
+
if ((isInput || isTextarea) && this.readOnly) {
|
|
112566
|
+
return { status: "readonly", tag: tag.toLowerCase() };
|
|
112567
|
+
}
|
|
112568
|
+
if (isSelect) {
|
|
112569
|
+
const select = this;
|
|
112570
|
+
const options = Array.from(select.options);
|
|
112571
|
+
const facts = options.map((option, index) => ({
|
|
112572
|
+
index,
|
|
112573
|
+
label: (option.label || option.textContent || "").trim(),
|
|
112574
|
+
value: option.value
|
|
112575
|
+
}));
|
|
112576
|
+
const available = facts.slice(0, 50).map((fact) => ({
|
|
112577
|
+
...fact,
|
|
112578
|
+
label: clip(fact.label),
|
|
112579
|
+
value: clip(fact.value)
|
|
112580
|
+
}));
|
|
112581
|
+
const needle = value.trim();
|
|
112582
|
+
const tiers = [
|
|
112583
|
+
(fact) => fact.label === needle,
|
|
112584
|
+
(fact) => fact.label.toLowerCase() === needle.toLowerCase(),
|
|
112585
|
+
(fact) => fact.value === needle
|
|
112586
|
+
];
|
|
112587
|
+
let matches = [];
|
|
112588
|
+
for (const tier of tiers) {
|
|
112589
|
+
matches = facts.filter(tier);
|
|
112590
|
+
if (matches.length) break;
|
|
112591
|
+
}
|
|
112592
|
+
if (!matches.length) return { status: "option_not_found", available };
|
|
112593
|
+
if (select.multiple && matches.length !== 1) {
|
|
112594
|
+
return { status: "option_ambiguous", available, matches: matches.length };
|
|
112595
|
+
}
|
|
112596
|
+
const chosen = matches[0];
|
|
112597
|
+
const matched = {
|
|
112598
|
+
index: chosen.index,
|
|
112599
|
+
label: clip(chosen.label),
|
|
112600
|
+
value: clip(chosen.value)
|
|
112601
|
+
};
|
|
112602
|
+
if (options[chosen.index].matches(":disabled, [aria-disabled=true]") || options[chosen.index].closest("optgroup[disabled], [inert]")) {
|
|
112603
|
+
return { status: "disabled", kind: "select", available, matched };
|
|
112604
|
+
}
|
|
112605
|
+
const selectProto = win.HTMLSelectElement.prototype;
|
|
112606
|
+
Object.getOwnPropertyDescriptor(selectProto, "value").set.call(select, chosen.value);
|
|
112607
|
+
Object.getOwnPropertyDescriptor(selectProto, "selectedIndex").set.call(select, chosen.index);
|
|
112608
|
+
dispatch(select);
|
|
112609
|
+
const readBack2 = select.value;
|
|
112610
|
+
return {
|
|
112611
|
+
status: "ready",
|
|
112612
|
+
kind: "select",
|
|
112613
|
+
value: readBack2,
|
|
112614
|
+
verified: readBack2 === chosen.value,
|
|
112615
|
+
matched,
|
|
112616
|
+
available
|
|
112617
|
+
};
|
|
112618
|
+
}
|
|
112619
|
+
const proto = isTextarea ? win.HTMLTextAreaElement.prototype : win.HTMLInputElement.prototype;
|
|
112620
|
+
const setValue = (input) => Object.getOwnPropertyDescriptor(proto, "value").set.call(this, input);
|
|
112621
|
+
const inputType = isInput ? this.type : "";
|
|
112622
|
+
const sanitized = {
|
|
112623
|
+
date: "YYYY-MM-DD",
|
|
112624
|
+
time: "HH:MM or HH:MM:SS",
|
|
112625
|
+
"datetime-local": "YYYY-MM-DDTHH:MM",
|
|
112626
|
+
month: "YYYY-MM",
|
|
112627
|
+
week: "YYYY-Www",
|
|
112628
|
+
number: "a number",
|
|
112629
|
+
range: "a number between the control's min and max",
|
|
112630
|
+
color: "#rrggbb"
|
|
112631
|
+
};
|
|
112632
|
+
const expected = sanitized[inputType];
|
|
112633
|
+
const priorValue = this.value;
|
|
112634
|
+
setValue(value);
|
|
112635
|
+
const sampled = this.value;
|
|
112636
|
+
const sameValue = (stored) => inputType === "color" ? stored.toLowerCase() === value.toLowerCase() : stored === value;
|
|
112637
|
+
if (value !== "" && expected && !sameValue(sampled)) {
|
|
112638
|
+
setValue(priorValue);
|
|
112639
|
+
return {
|
|
112640
|
+
status: "value_rejected",
|
|
112641
|
+
tag: tag.toLowerCase(),
|
|
112642
|
+
input_type: inputType,
|
|
112643
|
+
expected
|
|
112644
|
+
};
|
|
112645
|
+
}
|
|
112646
|
+
dispatch(this);
|
|
112647
|
+
const readBack = this.value;
|
|
112648
|
+
if (inputType === "password") {
|
|
112649
|
+
return {
|
|
112650
|
+
status: "ready",
|
|
112651
|
+
kind: "input",
|
|
112652
|
+
type: "password",
|
|
112653
|
+
redacted: true,
|
|
112654
|
+
verified: sameValue(readBack)
|
|
112655
|
+
};
|
|
112656
|
+
}
|
|
112657
|
+
return {
|
|
112658
|
+
status: "ready",
|
|
112659
|
+
kind: isTextarea ? "textarea" : "input",
|
|
112660
|
+
type: inputType,
|
|
112661
|
+
value: readBack,
|
|
112662
|
+
verified: sameValue(readBack)
|
|
112663
|
+
};
|
|
112664
|
+
}`;
|
|
110587
112665
|
async function select(ctx, params) {
|
|
110588
112666
|
const target2 = stringParam(params, "selector") || stringParam(params, "ref");
|
|
110589
112667
|
const options = params.options;
|
|
@@ -110608,7 +112686,8 @@ async function select(ctx, params) {
|
|
|
110608
112686
|
"Runtime.callFunctionOn",
|
|
110609
112687
|
{
|
|
110610
112688
|
objectId: node.objectId,
|
|
110611
|
-
|
|
112689
|
+
// Committed source, never `.toString()`: see the import's note.
|
|
112690
|
+
functionDeclaration: SELECT_PAGE_SOURCE,
|
|
110612
112691
|
arguments: [{ value: mode }, { value: choices }],
|
|
110613
112692
|
returnByValue: true
|
|
110614
112693
|
}
|
|
@@ -110683,7 +112762,7 @@ async function select(ctx, params) {
|
|
|
110683
112762
|
"Runtime.callFunctionOn",
|
|
110684
112763
|
{
|
|
110685
112764
|
objectId: node.objectId,
|
|
110686
|
-
functionDeclaration:
|
|
112765
|
+
functionDeclaration: SELECT_PAGE_SOURCE,
|
|
110687
112766
|
arguments: [{ value: "option" }, { value: options }],
|
|
110688
112767
|
returnByValue: false
|
|
110689
112768
|
}
|
|
@@ -110732,6 +112811,60 @@ async function select(ctx, params) {
|
|
|
110732
112811
|
...pageOf(record.view)
|
|
110733
112812
|
};
|
|
110734
112813
|
}
|
|
112814
|
+
async function setvalue(ctx, params) {
|
|
112815
|
+
const target2 = stringParam(params, "selector") || stringParam(params, "ref");
|
|
112816
|
+
const text2 = params.text;
|
|
112817
|
+
if (!target2 || typeof text2 !== "string") {
|
|
112818
|
+
throw new BridgeCommandError(
|
|
112819
|
+
"internal",
|
|
112820
|
+
"setvalue needs a selector and a text value",
|
|
112821
|
+
{ reason: "invalid_arguments" }
|
|
112822
|
+
);
|
|
112823
|
+
}
|
|
112824
|
+
const record = ctx.registry.requireSurface(params.tab);
|
|
112825
|
+
const contents = record.view.webContents;
|
|
112826
|
+
const node = await resolveNode(ctx, record, target2, { scroll: false });
|
|
112827
|
+
const out = await sendIn(
|
|
112828
|
+
ctx,
|
|
112829
|
+
contents,
|
|
112830
|
+
node.sessionId,
|
|
112831
|
+
"Runtime.callFunctionOn",
|
|
112832
|
+
{
|
|
112833
|
+
objectId: node.objectId,
|
|
112834
|
+
functionDeclaration: SETVALUE_PAGE_SOURCE,
|
|
112835
|
+
arguments: [{ value: text2 }],
|
|
112836
|
+
returnByValue: true
|
|
112837
|
+
}
|
|
112838
|
+
);
|
|
112839
|
+
const result = out.result?.value;
|
|
112840
|
+
if (!result)
|
|
112841
|
+
throw new BridgeCommandError(
|
|
112842
|
+
"element_not_found",
|
|
112843
|
+
"the setvalue target disappeared before it could be written"
|
|
112844
|
+
);
|
|
112845
|
+
if (result.status !== "ready") {
|
|
112846
|
+
const message = result.status === "not_a_value_control" ? "setvalue cannot toggle a checkbox or radio: its state is checked, not a value. Use click to toggle it." : result.status === "value_rejected" ? `setvalue refused: ${result.status} — this ${result.input_type} field did not take the value; it accepts ${result.expected}` : `setvalue refused: ${result.status}`;
|
|
112847
|
+
throw new BridgeCommandError("element_not_found", message, {
|
|
112848
|
+
reason: result.status,
|
|
112849
|
+
...result.available ? { available: result.available } : {},
|
|
112850
|
+
...result.tag ? { tag: result.tag } : {},
|
|
112851
|
+
...result.input_type ? { input_type: result.input_type } : {},
|
|
112852
|
+
...result.expected ? { expected: result.expected } : {}
|
|
112853
|
+
});
|
|
112854
|
+
}
|
|
112855
|
+
ctx.registry.touch(record);
|
|
112856
|
+
return {
|
|
112857
|
+
kind: result.kind,
|
|
112858
|
+
// A password field answers without its value; everything else answers with
|
|
112859
|
+
// the read-back, always present so a caller never has to distinguish
|
|
112860
|
+
// "absent" from "empty".
|
|
112861
|
+
...result.redacted ? {} : { value: result.value ?? "" },
|
|
112862
|
+
verified: result.verified ?? false,
|
|
112863
|
+
...result.type ? { input_type: result.type } : {},
|
|
112864
|
+
...result.matched ? { matched: result.matched } : {},
|
|
112865
|
+
...pageOf(record.view)
|
|
112866
|
+
};
|
|
112867
|
+
}
|
|
110735
112868
|
const MAX_AGENT_TABS = 8;
|
|
110736
112869
|
const BACKGROUND_VIEWPORT = {
|
|
110737
112870
|
x: 0,
|
|
@@ -112578,11 +114711,18 @@ const DOCUMENT_SCOPED = /* @__PURE__ */ new Set([
|
|
|
112578
114711
|
"ancestors",
|
|
112579
114712
|
"snapshot",
|
|
112580
114713
|
// `query` is a read of the CURRENT document's DOM (CSS in, descriptors out),
|
|
112581
|
-
// so it is authorized
|
|
112582
|
-
//
|
|
112583
|
-
//
|
|
112584
|
-
//
|
|
114714
|
+
// so it is authorized on entry and again on the result exactly as `read` is:
|
|
114715
|
+
// an answer that raced a navigation it did not cause must be discarded, not
|
|
114716
|
+
// reported as the new page's (agent review round 2 on the query slice — the
|
|
114717
|
+
// action was missing from BOTH sets).
|
|
112585
114718
|
"query",
|
|
114719
|
+
// `copy` reads an element's text out of the CURRENT document and puts it on the
|
|
114720
|
+
// user's clipboard, which is the strongest reason in this set to hold it to the
|
|
114721
|
+
// entry document: an answer that raced an autonomous navigation would mean the
|
|
114722
|
+
// clipboard now holds text from a document the agent was never approved for,
|
|
114723
|
+
// and the receipt would describe it as the approved page's. It is NOT a
|
|
114724
|
+
// NAVIGATING_ACTION — copying drives no click and fetches nothing — so the
|
|
114725
|
+
// per-hop Document gate stays off, exactly as it does for `read`.
|
|
112586
114726
|
"screenshot",
|
|
112587
114727
|
"click",
|
|
112588
114728
|
"type",
|
|
@@ -112591,8 +114731,14 @@ const DOCUMENT_SCOPED = /* @__PURE__ */ new Set([
|
|
|
112591
114731
|
// stack, so it is authorized on entry and on the result exactly like `click`.
|
|
112592
114732
|
"hover",
|
|
112593
114733
|
"select",
|
|
114734
|
+
// `setvalue` writes into a control on the CURRENT document and reports the
|
|
114735
|
+
// value it read back from it, so it is authorized on entry and on the result
|
|
114736
|
+
// exactly as `select` is: an answer that raced a navigation it did not cause
|
|
114737
|
+
// must be discarded, never reported as the new page's.
|
|
114738
|
+
"setvalue",
|
|
112594
114739
|
"scroll",
|
|
112595
114740
|
"logs",
|
|
114741
|
+
"copy",
|
|
112596
114742
|
// `download` names a control on the CURRENT document (the link or button that
|
|
112597
114743
|
// starts the file) and `upload` names a file input on it, so both are authorized
|
|
112598
114744
|
// against that document on entry and again on the result. BOTH are in the
|
|
@@ -112628,6 +114774,11 @@ const NAVIGATING_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
112628
114774
|
// landing on success OR throw, and restore if unapproved. No native popup,
|
|
112629
114775
|
// no agent-initiated document request to intercept with Fetch.
|
|
112630
114776
|
"select",
|
|
114777
|
+
// A `setvalue` change handler can navigate exactly like a select change: an
|
|
114778
|
+
// auto-submitting form turns a write into a navigation. Adopt/authorize the
|
|
114779
|
+
// landing on success OR throw, restore if unapproved, and stay OUT of
|
|
114780
|
+
// NAVIGATION_ACTIONS for the reason below: the write fetches nothing itself.
|
|
114781
|
+
"setvalue",
|
|
112631
114782
|
"download",
|
|
112632
114783
|
"upload"
|
|
112633
114784
|
]);
|
|
@@ -112650,6 +114801,7 @@ const TAB_SCOPED = /* @__PURE__ */ new Set([
|
|
|
112650
114801
|
"press",
|
|
112651
114802
|
"hover",
|
|
112652
114803
|
"select",
|
|
114804
|
+
"setvalue",
|
|
112653
114805
|
"scroll",
|
|
112654
114806
|
"logs",
|
|
112655
114807
|
"close",
|
|
@@ -112661,6 +114813,11 @@ const TAB_SCOPED = /* @__PURE__ */ new Set([
|
|
|
112661
114813
|
// which call.
|
|
112662
114814
|
"download",
|
|
112663
114815
|
"upload",
|
|
114816
|
+
// `copy` resolves a selector against ONE tab's document and writes what it finds
|
|
114817
|
+
// to a process-wide clipboard, so two concurrent copies on one tab would leave
|
|
114818
|
+
// the clipboard holding whichever finished last while both receipts claimed
|
|
114819
|
+
// success. The lane is what makes "the bytes this answer describes" true.
|
|
114820
|
+
"copy",
|
|
112664
114821
|
// Network capture is TAB-scoped and deliberately NOT `DOCUMENT_SCOPED`, for the
|
|
112665
114822
|
// same reason `logs` is not: its answer describes the tab's TRAFFIC (which
|
|
112666
114823
|
// spans documents, redirects and third-party subresources), not the document
|
|
@@ -112932,10 +115089,14 @@ class BrowserHost {
|
|
|
112932
115089
|
return hover(this, params);
|
|
112933
115090
|
case "select":
|
|
112934
115091
|
return select(this, params);
|
|
115092
|
+
case "setvalue":
|
|
115093
|
+
return setvalue(this, params);
|
|
112935
115094
|
case "download":
|
|
112936
115095
|
return download(this, params);
|
|
112937
115096
|
case "upload":
|
|
112938
115097
|
return upload(this, params);
|
|
115098
|
+
case "copy":
|
|
115099
|
+
return copy(this, params);
|
|
112939
115100
|
case "network_start":
|
|
112940
115101
|
return networkStart(this, params, requestId2);
|
|
112941
115102
|
case "network_stop":
|
|
@@ -113016,9 +115177,9 @@ class BrowserHost {
|
|
|
113016
115177
|
* something, and presenting one as a failure would make the panel cry wolf on
|
|
113017
115178
|
* every redirect (see `isReportableLoadFailure`).
|
|
113018
115179
|
*/
|
|
113019
|
-
recordLoadFailure(tabId,
|
|
115180
|
+
recordLoadFailure(tabId, failure2) {
|
|
113020
115181
|
if (!this.registry.get(tabId)) return;
|
|
113021
|
-
this.loadFailures.set(tabId,
|
|
115182
|
+
this.loadFailures.set(tabId, failure2);
|
|
113022
115183
|
this.onChanged();
|
|
113023
115184
|
}
|
|
113024
115185
|
/** The next navigation on this tab is under way, so the last failure is stale. */
|
|
@@ -113299,10 +115460,10 @@ class BrowserHost {
|
|
|
113299
115460
|
};
|
|
113300
115461
|
if (action === "reload") record.view.webContents.reload();
|
|
113301
115462
|
else {
|
|
113302
|
-
const
|
|
115463
|
+
const copy2 = await this.createUserTab(null, url, (created) => {
|
|
113303
115464
|
destinationId = created.tabId;
|
|
113304
115465
|
});
|
|
113305
|
-
destinationId =
|
|
115466
|
+
destinationId = copy2.tabId;
|
|
113306
115467
|
}
|
|
113307
115468
|
this.onChanged();
|
|
113308
115469
|
return { status: "completed", action, tabId: destinationId };
|
|
@@ -114577,6 +116738,57 @@ class DownloadArmer {
|
|
|
114577
116738
|
capture.finish?.();
|
|
114578
116739
|
}
|
|
114579
116740
|
}
|
|
116741
|
+
/**
|
|
116742
|
+
* Decide a page action the session refused before any download could start.
|
|
116743
|
+
*
|
|
116744
|
+
* The page-opened popup is the case that exists (operator report, 2026-11-06): a
|
|
116745
|
+
* page that downloads THROUGH a popup can be stopped long before
|
|
116746
|
+
* `will-download` fires — `decidePopup` denies the scheme, the live-window cap
|
|
116747
|
+
* or a dead opener, and `routePopup` denies a link tab's depth — and the armed
|
|
116748
|
+
* call then waited out its whole budget and answered "no download started
|
|
116749
|
+
* within 120s". That sentence describes a call that saw nothing; this one
|
|
116750
|
+
* describes a page the host said no to, and nothing was saved either way. The
|
|
116751
|
+
* difference is that the model is now told which.
|
|
116752
|
+
*
|
|
116753
|
+
* `reason` is the policy's own short token (`scheme`, `cap`, `link_depth`, …),
|
|
116754
|
+
* never the url: this sentence reaches the model and the audit row, and a popup
|
|
116755
|
+
* url is routinely a signed link whose query string is the credential.
|
|
116756
|
+
*/
|
|
116757
|
+
noteRefusedPopup(tabId, reason) {
|
|
116758
|
+
const capture = this.captures.get(tabId);
|
|
116759
|
+
if (!capture || capture.settled) return;
|
|
116760
|
+
capture.refusals.push(
|
|
116761
|
+
`refused: the page opened a popup and the host denied it (${reason}); any download it would have started was not saved`
|
|
116762
|
+
);
|
|
116763
|
+
this.options.log(
|
|
116764
|
+
`[browser] noted a denied popup on tab ${tabId} for the armed download call (${reason})`
|
|
116765
|
+
);
|
|
116766
|
+
}
|
|
116767
|
+
/**
|
|
116768
|
+
* The tab a download BELONGS to: the direct lookup, else one hop up.
|
|
116769
|
+
*
|
|
116770
|
+
* WHY THE HOP EXISTS (operator report, 2026-11-06). `will-download` reports the
|
|
116771
|
+
* webContents that started the item, and a popup WINDOW — the shape a page's
|
|
116772
|
+
* `window.open` produces, and the shape a signed-in "generate a key file" flow
|
|
116773
|
+
* uses — is not a registry tab, so the direct lookup answered null and the
|
|
116774
|
+
* download was cancelled with "no download call is armed on this tab" while the
|
|
116775
|
+
* tab that opened it sat armed and waiting. The relationship the popup was
|
|
116776
|
+
* created under (`routePopup` reads the same opener) is what decides which arm
|
|
116777
|
+
* owns it, so one hop up is the honest attribution.
|
|
116778
|
+
*
|
|
116779
|
+
* WHY ONE HOP AND NOT A WALK. `wirePopup` gives a popup WINDOW a deny-all open
|
|
116780
|
+
* handler, so a window cannot open a window, and the only other child shape — a
|
|
116781
|
+
* link — is a registry tab, which the direct lookup answers first. Walking
|
|
116782
|
+
* further would let a download be decided by a tab two generations away from the
|
|
116783
|
+
* page that started it: reported against a call that never touched that page,
|
|
116784
|
+
* and captured under a directory composed for a different session.
|
|
116785
|
+
*/
|
|
116786
|
+
ownerTab(webContentsId) {
|
|
116787
|
+
const direct = this.options.tabForWebContents(webContentsId);
|
|
116788
|
+
if (direct !== null) return direct;
|
|
116789
|
+
const opener = this.options.openerWebContentsId?.(webContentsId) ?? null;
|
|
116790
|
+
return opener === null ? null : this.options.tabForWebContents(opener);
|
|
116791
|
+
}
|
|
114580
116792
|
/**
|
|
114581
116793
|
* Decide one download attempt. THE ONLY ENTRY POINT `profile.ts` calls.
|
|
114582
116794
|
*
|
|
@@ -114585,7 +116797,7 @@ class DownloadArmer {
|
|
|
114585
116797
|
* plain text), then the CAP before the write, then the save path.
|
|
114586
116798
|
*/
|
|
114587
116799
|
decide(item, webContentsId) {
|
|
114588
|
-
const tabId = this.
|
|
116800
|
+
const tabId = this.ownerTab(webContentsId);
|
|
114589
116801
|
let capture = tabId === null ? void 0 : this.captures.get(tabId);
|
|
114590
116802
|
if (!capture || capture.settled) {
|
|
114591
116803
|
capture = (tabId !== null ? this.humanCapture(tabId) : null) ?? void 0;
|
|
@@ -115241,7 +117453,7 @@ class StartupRollback {
|
|
|
115241
117453
|
}
|
|
115242
117454
|
const MAX_START_ATTEMPTS = 3;
|
|
115243
117455
|
async function startWithRetries(options) {
|
|
115244
|
-
let
|
|
117456
|
+
let failure2 = new Error("The browser window closed before startup.");
|
|
115245
117457
|
for (let attempt = 1; attempt <= MAX_START_ATTEMPTS; attempt += 1) {
|
|
115246
117458
|
if (options.cancelled()) break;
|
|
115247
117459
|
options.publish({
|
|
@@ -115254,7 +117466,7 @@ async function startWithRetries(options) {
|
|
|
115254
117466
|
try {
|
|
115255
117467
|
return await options.start();
|
|
115256
117468
|
} catch (error) {
|
|
115257
|
-
|
|
117469
|
+
failure2 = error;
|
|
115258
117470
|
options.log(
|
|
115259
117471
|
`[browser] startup attempt ${attempt}/${MAX_START_ATTEMPTS} failed: ${String(error)}`
|
|
115260
117472
|
);
|
|
@@ -115270,7 +117482,7 @@ async function startWithRetries(options) {
|
|
|
115270
117482
|
// idempotent on re-registration, which is what makes the control safe.
|
|
115271
117483
|
canRetry: true
|
|
115272
117484
|
});
|
|
115273
|
-
throw
|
|
117485
|
+
throw failure2;
|
|
115274
117486
|
}
|
|
115275
117487
|
function numberOrThrow(value, name) {
|
|
115276
117488
|
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
@@ -116476,30 +118688,40 @@ function browserStoragePath(browserSession) {
|
|
|
116476
118688
|
}
|
|
116477
118689
|
function installBrowserSessionHandlers(browserSession, hooks = {}) {
|
|
116478
118690
|
browserSession.setUserAgent(browserUserAgent());
|
|
118691
|
+
const report = (source, webContentsId, permission, origin) => {
|
|
118692
|
+
hooks.onPermissionRequested?.({
|
|
118693
|
+
webContentsId: webContentsId ?? -1,
|
|
118694
|
+
origin,
|
|
118695
|
+
permission,
|
|
118696
|
+
granted: false,
|
|
118697
|
+
source
|
|
118698
|
+
});
|
|
118699
|
+
return false;
|
|
118700
|
+
};
|
|
116479
118701
|
browserSession.setPermissionRequestHandler(
|
|
116480
|
-
(
|
|
116481
|
-
|
|
116482
|
-
|
|
116483
|
-
|
|
116484
|
-
|
|
116485
|
-
|
|
116486
|
-
|
|
118702
|
+
(webContents, permission, callback, details) => {
|
|
118703
|
+
callback(
|
|
118704
|
+
report(
|
|
118705
|
+
"request",
|
|
118706
|
+
webContents?.id ?? null,
|
|
118707
|
+
permission,
|
|
118708
|
+
typeof details?.requestingUrl === "string" ? details.requestingUrl : ""
|
|
118709
|
+
)
|
|
118710
|
+
);
|
|
116487
118711
|
}
|
|
116488
118712
|
);
|
|
116489
118713
|
browserSession.setPermissionCheckHandler(
|
|
116490
|
-
(
|
|
116491
|
-
|
|
116492
|
-
|
|
116493
|
-
|
|
116494
|
-
|
|
116495
|
-
|
|
116496
|
-
|
|
116497
|
-
|
|
116498
|
-
|
|
116499
|
-
|
|
116500
|
-
|
|
116501
|
-
return false;
|
|
116502
|
-
}
|
|
118714
|
+
(webContents, permission, requestingOrigin, details) => report(
|
|
118715
|
+
"check",
|
|
118716
|
+
webContents?.id ?? null,
|
|
118717
|
+
permission,
|
|
118718
|
+
// Electron calls this handler with an empty origin during the
|
|
118719
|
+
// per-webContents startup probes (media, geolocation, app install), so the
|
|
118720
|
+
// documented `requestingUrl` is preferred when it is there: an
|
|
118721
|
+
// "(unknown origin)" line for a probe the PAGE caused is exactly the line
|
|
118722
|
+
// somebody needs when a site's permission stops working.
|
|
118723
|
+
requestingOrigin || details?.requestingUrl || ""
|
|
118724
|
+
)
|
|
116503
118725
|
);
|
|
116504
118726
|
const onDownload = (event, item, webContents) => {
|
|
116505
118727
|
const webContentsId = webContents?.id ?? -1;
|
|
@@ -118063,8 +120285,8 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118063
120285
|
for (const spawned of registry.unadoptedLinkTabs(tabId))
|
|
118064
120286
|
registry.destroy(spawned.tabId);
|
|
118065
120287
|
addressOverlay?.onTabReleased(tabId);
|
|
118066
|
-
const view =
|
|
118067
|
-
|
|
120288
|
+
const view = views2.get(tabId);
|
|
120289
|
+
views2.delete(tabId);
|
|
118068
120290
|
downloads.forget(tabId);
|
|
118069
120291
|
const release = cdp.detach(webContentsId).finally(() => releaseView(options.window, view));
|
|
118070
120292
|
releases.add(release);
|
|
@@ -118160,6 +120382,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118160
120382
|
log2(
|
|
118161
120383
|
`[browser] refused a popup from a driven page: ${details.url} (${decision.reason})`
|
|
118162
120384
|
);
|
|
120385
|
+
downloads.noteRefusedPopup(tabId, decision.reason);
|
|
118163
120386
|
return { action: "deny" };
|
|
118164
120387
|
}
|
|
118165
120388
|
pendingOpens.push({
|
|
@@ -118257,12 +120480,19 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118257
120480
|
log2(
|
|
118258
120481
|
`[browser] tab ${tabId} opened a popup: ${seen}, route=window, presentation=${routed.presentation})`
|
|
118259
120482
|
);
|
|
118260
|
-
|
|
120483
|
+
const childId = child.webContents.id;
|
|
120484
|
+
popupOpener.set(childId, contents.id);
|
|
120485
|
+
child.on("closed", () => popupOpener.delete(childId));
|
|
120486
|
+
wirePopup(child, popupChildren, routed.presentation, tabId);
|
|
118261
120487
|
return;
|
|
118262
120488
|
}
|
|
118263
120489
|
log2(
|
|
118264
120490
|
`[browser] refused a popup from a driven page: ${details.url} (${routed.route === "deny" ? routed.reason : "opener_gone"})`
|
|
118265
120491
|
);
|
|
120492
|
+
downloads.noteRefusedPopup(
|
|
120493
|
+
tabId,
|
|
120494
|
+
routed.route === "deny" ? routed.reason : "opener_gone"
|
|
120495
|
+
);
|
|
118266
120496
|
child.destroy();
|
|
118267
120497
|
});
|
|
118268
120498
|
const onWillNavigate = (event, rawUrl) => {
|
|
@@ -118381,12 +120611,13 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118381
120611
|
host.clearLoadFailure(tabId);
|
|
118382
120612
|
releaseTab(tabId, contents.id);
|
|
118383
120613
|
});
|
|
118384
|
-
}, wirePopup = function(child, popupChildren, presentation) {
|
|
120614
|
+
}, wirePopup = function(child, popupChildren, presentation, tabId) {
|
|
118385
120615
|
popupChildren.add(child);
|
|
118386
120616
|
child.on("closed", () => popupChildren.delete(child));
|
|
118387
120617
|
const childContents = child.webContents;
|
|
118388
120618
|
childContents.setWindowOpenHandler((childDetails) => {
|
|
118389
120619
|
log2(`[browser] refused a popup from a popup: ${childDetails.url}`);
|
|
120620
|
+
downloads.noteRefusedPopup(tabId, "popup_from_popup");
|
|
118390
120621
|
return { action: "deny" };
|
|
118391
120622
|
});
|
|
118392
120623
|
const onWillNavigate = (event, rawUrl) => {
|
|
@@ -118466,8 +120697,14 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118466
120697
|
};
|
|
118467
120698
|
const browserSession = resolveBrowserSession();
|
|
118468
120699
|
let registryForDownloads = null;
|
|
120700
|
+
const popupOpener = /* @__PURE__ */ new Map();
|
|
118469
120701
|
const downloads = new DownloadArmer({
|
|
118470
120702
|
tabForWebContents: (webContentsId) => registryForDownloads?.byWebContents(webContentsId)?.tabId ?? null,
|
|
120703
|
+
// The one-hop attribution for a download a popup started: the popup is not a
|
|
120704
|
+
// registry tab, so the direct lookup above misses and this answers with the
|
|
120705
|
+
// tab whose arm decides. See `popupOpener` for why the relationship is
|
|
120706
|
+
// recorded by this host rather than read from Electron's `opener`.
|
|
120707
|
+
openerWebContentsId: (webContentsId) => popupOpener.get(webContentsId) ?? null,
|
|
118471
120708
|
// WHO OWNED THE TAB, recorded on the decision (review round 2, U10). Read from
|
|
118472
120709
|
// the registry at the moment the note is written, because the row may render it
|
|
118473
120710
|
// after the tab is closed — and "· on another tab" about a tab that no longer
|
|
@@ -118496,7 +120733,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118496
120733
|
{
|
|
118497
120734
|
onPermissionRequested: (details) => {
|
|
118498
120735
|
log2(
|
|
118499
|
-
`[browser] denied
|
|
120736
|
+
`[browser] ${details.granted ? "granted" : "denied"} ${details.permission} (${details.source}) from ${details.origin || "(unknown origin)"}`
|
|
118500
120737
|
);
|
|
118501
120738
|
},
|
|
118502
120739
|
onDownload: (item, webContentsId) => downloads.decide(item, webContentsId),
|
|
@@ -118592,7 +120829,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118592
120829
|
});
|
|
118593
120830
|
const cdp = new CdpPool({ log: log2 });
|
|
118594
120831
|
rollback.add(() => cdp.close());
|
|
118595
|
-
const
|
|
120832
|
+
const views2 = /* @__PURE__ */ new Map();
|
|
118596
120833
|
const releases = /* @__PURE__ */ new Set();
|
|
118597
120834
|
let stateWriter = null;
|
|
118598
120835
|
let notifyAddressOverlayHealth = () => {
|
|
@@ -118696,7 +120933,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118696
120933
|
const registry = new TabRegistry(
|
|
118697
120934
|
(_createOptions, tabId) => {
|
|
118698
120935
|
const view = buildView(options.window);
|
|
118699
|
-
|
|
120936
|
+
views2.set(tabId, view);
|
|
118700
120937
|
wireView(view, tabId);
|
|
118701
120938
|
return view;
|
|
118702
120939
|
},
|
|
@@ -119277,7 +121514,7 @@ function isAdmittedSender(event, admitted) {
|
|
|
119277
121514
|
(candidate) => candidate.window !== null && !candidate.window.isDestroyed() && event.sender === candidate.window.webContents && event.senderFrame === candidate.window.webContents.mainFrame && trustedDesktopFrame(event.senderFrame.url, candidate.url)
|
|
119278
121515
|
);
|
|
119279
121516
|
}
|
|
119280
|
-
function registerDesktopIPC(window, expectedUrl, request, streams, media, notifier, noteLeftSession, onKeymapSettingEdited, additionalWindows, supplementMounts2, teamBridgeNotifier, onLanguageSettingEdited, admitDesktopRequest) {
|
|
121517
|
+
function registerDesktopIPC(window, expectedUrl, request, streams, media, notifier, noteLeftSession, onKeymapSettingEdited, additionalWindows, supplementMounts2, teamBridgeNotifier, onLanguageSettingEdited, admitDesktopRequest, linkPreview) {
|
|
119281
121518
|
const opened = /* @__PURE__ */ new Map();
|
|
119282
121519
|
function authorize(event) {
|
|
119283
121520
|
const admitted = [
|
|
@@ -119399,6 +121636,16 @@ function registerDesktopIPC(window, expectedUrl, request, streams, media, notifi
|
|
|
119399
121636
|
return media(input, payload);
|
|
119400
121637
|
});
|
|
119401
121638
|
}
|
|
121639
|
+
if (linkPreview) {
|
|
121640
|
+
electron.ipcMain.handle(LINK_PREVIEW_RESOLVE_CHANNEL, (event, input) => {
|
|
121641
|
+
authorize(event);
|
|
121642
|
+
return linkPreview.resolve(input);
|
|
121643
|
+
});
|
|
121644
|
+
electron.ipcMain.handle(LINK_PREVIEW_ARTIFACT_CHANNEL, (event, input) => {
|
|
121645
|
+
authorize(event);
|
|
121646
|
+
return linkPreview.artifact(input);
|
|
121647
|
+
});
|
|
121648
|
+
}
|
|
119402
121649
|
electron.ipcMain.handle(
|
|
119403
121650
|
"desktop-open-authorization",
|
|
119404
121651
|
async (event, operationId, reopen = false) => {
|
|
@@ -120667,6 +122914,240 @@ function isProcessAlive(pid) {
|
|
|
120667
122914
|
return error.code !== "ESRCH";
|
|
120668
122915
|
}
|
|
120669
122916
|
}
|
|
122917
|
+
const ABSENT_REASONS = /* @__PURE__ */ new Set([
|
|
122918
|
+
"cap",
|
|
122919
|
+
"no-metadata",
|
|
122920
|
+
"local-or-private",
|
|
122921
|
+
"unsupported-scheme",
|
|
122922
|
+
"blocked-host",
|
|
122923
|
+
"content-type",
|
|
122924
|
+
"too-large",
|
|
122925
|
+
"not-html",
|
|
122926
|
+
"disabled"
|
|
122927
|
+
]);
|
|
122928
|
+
const FORGET_INDEX_LIMIT = 256;
|
|
122929
|
+
class ForgetIndex {
|
|
122930
|
+
ids = /* @__PURE__ */ new Map();
|
|
122931
|
+
record(accountFingerprint, url, artifactIds) {
|
|
122932
|
+
if (artifactIds.length === 0) return;
|
|
122933
|
+
const key = previewKeyFor(accountFingerprint, url);
|
|
122934
|
+
this.ids.delete(key);
|
|
122935
|
+
this.ids.set(key, artifactIds);
|
|
122936
|
+
while (this.ids.size > FORGET_INDEX_LIMIT) {
|
|
122937
|
+
const oldest = this.ids.keys().next();
|
|
122938
|
+
if (oldest.done === true) break;
|
|
122939
|
+
this.ids.delete(oldest.value);
|
|
122940
|
+
}
|
|
122941
|
+
}
|
|
122942
|
+
/** The ids this preview was holding, and forget them: one refusal per preview
|
|
122943
|
+
* needs them once, and a later resolve re-records a fresh answer. */
|
|
122944
|
+
take(accountFingerprint, url) {
|
|
122945
|
+
const key = previewKeyFor(accountFingerprint, url);
|
|
122946
|
+
const held = this.ids.get(key);
|
|
122947
|
+
this.ids.delete(key);
|
|
122948
|
+
return held ?? [];
|
|
122949
|
+
}
|
|
122950
|
+
}
|
|
122951
|
+
function boundedString(value, max) {
|
|
122952
|
+
if (typeof value !== "string") return null;
|
|
122953
|
+
const trimmed = value.trim();
|
|
122954
|
+
if (trimmed.length === 0 || trimmed.length > max) return null;
|
|
122955
|
+
return trimmed;
|
|
122956
|
+
}
|
|
122957
|
+
function isResolveRequest(value) {
|
|
122958
|
+
if (typeof value !== "object" || value === null) return false;
|
|
122959
|
+
const request = value;
|
|
122960
|
+
if (boundedString(request.url, LINK_PREVIEW_MAX_URL_CHARS) === null)
|
|
122961
|
+
return false;
|
|
122962
|
+
if (typeof request.index !== "number" || !Number.isSafeInteger(request.index) || request.index < 0)
|
|
122963
|
+
return false;
|
|
122964
|
+
return boundedString(request.expectedAccountId, LINK_PREVIEW_ACCOUNT_MAX_CHARS) !== null;
|
|
122965
|
+
}
|
|
122966
|
+
function isArtifactRequest(value) {
|
|
122967
|
+
if (typeof value !== "object" || value === null) return false;
|
|
122968
|
+
const request = value;
|
|
122969
|
+
if (typeof request.id !== "string") return false;
|
|
122970
|
+
if (!LINK_PREVIEW_ARTIFACT_ID.test(request.id)) return false;
|
|
122971
|
+
return boundedString(request.expectedAccountId, LINK_PREVIEW_ACCOUNT_MAX_CHARS) !== null;
|
|
122972
|
+
}
|
|
122973
|
+
function optionalText(value) {
|
|
122974
|
+
return typeof value === "string" ? value : null;
|
|
122975
|
+
}
|
|
122976
|
+
function toArtifact(value) {
|
|
122977
|
+
if (typeof value !== "object" || value === null) return null;
|
|
122978
|
+
const artifact = value;
|
|
122979
|
+
if (typeof artifact.id !== "string") return null;
|
|
122980
|
+
if (!LINK_PREVIEW_ARTIFACT_ID.test(artifact.id)) return null;
|
|
122981
|
+
const mime = boundedString(artifact.mime, 128);
|
|
122982
|
+
if (mime === null) return null;
|
|
122983
|
+
return { id: artifact.id, mime };
|
|
122984
|
+
}
|
|
122985
|
+
function toImage(value) {
|
|
122986
|
+
const base = toArtifact(value);
|
|
122987
|
+
if (base === null) return null;
|
|
122988
|
+
const image2 = value;
|
|
122989
|
+
const dimension = (candidate) => typeof candidate === "number" && Number.isInteger(candidate) && candidate > 0 && candidate <= 1e5 ? candidate : null;
|
|
122990
|
+
return {
|
|
122991
|
+
...base,
|
|
122992
|
+
width: dimension(image2.width),
|
|
122993
|
+
height: dimension(image2.height)
|
|
122994
|
+
};
|
|
122995
|
+
}
|
|
122996
|
+
function toPreview(value) {
|
|
122997
|
+
if (typeof value !== "object" || value === null) return null;
|
|
122998
|
+
const preview = value;
|
|
122999
|
+
const url = boundedString(preview.url, LINK_PREVIEW_MAX_URL_CHARS);
|
|
123000
|
+
if (url === null) return null;
|
|
123001
|
+
const image2 = toImage(preview.image);
|
|
123002
|
+
return {
|
|
123003
|
+
url,
|
|
123004
|
+
// Core omits a field that is absent (`response_model_exclude_none`), so
|
|
123005
|
+
// "not there" and "null" mean the same thing and both become `null` here:
|
|
123006
|
+
// one absence spelling is what the renderer's union declares.
|
|
123007
|
+
title: optionalText(preview.title),
|
|
123008
|
+
description: optionalText(preview.description),
|
|
123009
|
+
siteName: optionalText(preview.siteName),
|
|
123010
|
+
favicon: toArtifact(preview.favicon),
|
|
123011
|
+
image: image2 === null ? null : {
|
|
123012
|
+
id: image2.id,
|
|
123013
|
+
mime: image2.mime,
|
|
123014
|
+
width: image2.width,
|
|
123015
|
+
height: image2.height
|
|
123016
|
+
}
|
|
123017
|
+
};
|
|
123018
|
+
}
|
|
123019
|
+
function absentReason(value) {
|
|
123020
|
+
return typeof value === "string" && ABSENT_REASONS.has(value) ? value : "no-metadata";
|
|
123021
|
+
}
|
|
123022
|
+
function mapResolution(result) {
|
|
123023
|
+
if (typeof result !== "object" || result === null)
|
|
123024
|
+
return { kind: "error", retryable: true };
|
|
123025
|
+
const resolution = result;
|
|
123026
|
+
if (resolution.kind === "ready") {
|
|
123027
|
+
const preview = toPreview(resolution.preview);
|
|
123028
|
+
return preview === null ? { kind: "error", retryable: true } : { kind: "ready", preview };
|
|
123029
|
+
}
|
|
123030
|
+
if (resolution.kind === "absent")
|
|
123031
|
+
return { kind: "absent", reason: absentReason(resolution.reason) };
|
|
123032
|
+
if (resolution.kind === "error")
|
|
123033
|
+
return { kind: "error", retryable: resolution.retryable === true };
|
|
123034
|
+
return { kind: "error", retryable: true };
|
|
123035
|
+
}
|
|
123036
|
+
function retryAfterMs(detail) {
|
|
123037
|
+
if (typeof detail !== "object" || detail === null) return void 0;
|
|
123038
|
+
const seconds = detail.retry_after_seconds;
|
|
123039
|
+
if (typeof seconds !== "number" || !Number.isFinite(seconds))
|
|
123040
|
+
return void 0;
|
|
123041
|
+
if (seconds < 0) return void 0;
|
|
123042
|
+
return Math.min(Math.ceil(seconds * 1e3), 6e4);
|
|
123043
|
+
}
|
|
123044
|
+
function refusalDetail(body2) {
|
|
123045
|
+
if (typeof body2 !== "object" || body2 === null) return void 0;
|
|
123046
|
+
return body2.detail;
|
|
123047
|
+
}
|
|
123048
|
+
function envelopeResult(body2) {
|
|
123049
|
+
if (typeof body2 !== "object" || body2 === null) return void 0;
|
|
123050
|
+
return body2.result;
|
|
123051
|
+
}
|
|
123052
|
+
function artifactRefusalCode(answer) {
|
|
123053
|
+
return answer.kind === "error" ? answer.refusal?.code : void 0;
|
|
123054
|
+
}
|
|
123055
|
+
const RATE_LIMITED = 429;
|
|
123056
|
+
function createLinkPreviewService(options) {
|
|
123057
|
+
const { transport, cache } = options;
|
|
123058
|
+
const forget = new ForgetIndex();
|
|
123059
|
+
async function resolve(input) {
|
|
123060
|
+
if (!isResolveRequest(input))
|
|
123061
|
+
return { kind: "absent", reason: "unsupported-scheme" };
|
|
123062
|
+
const { url, index, expectedAccountId } = input;
|
|
123063
|
+
const accountFingerprint = artifactOwnerFingerprint(expectedAccountId);
|
|
123064
|
+
let answer;
|
|
123065
|
+
try {
|
|
123066
|
+
answer = await transport.request({
|
|
123067
|
+
op: "team_bridge.link_preview.resolve",
|
|
123068
|
+
url,
|
|
123069
|
+
index,
|
|
123070
|
+
expectedAccountId
|
|
123071
|
+
});
|
|
123072
|
+
} catch {
|
|
123073
|
+
return { kind: "error", retryable: true };
|
|
123074
|
+
}
|
|
123075
|
+
if (answer.status === RATE_LIMITED) {
|
|
123076
|
+
const delay2 = retryAfterMs(refusalDetail(answer.body));
|
|
123077
|
+
return {
|
|
123078
|
+
kind: "error",
|
|
123079
|
+
retryable: true,
|
|
123080
|
+
...delay2 === void 0 ? {} : { retryAfterMs: delay2 }
|
|
123081
|
+
};
|
|
123082
|
+
}
|
|
123083
|
+
if (answer.status !== 200)
|
|
123084
|
+
return {
|
|
123085
|
+
kind: "error",
|
|
123086
|
+
retryable: !(answer.status >= 400 && answer.status < 500)
|
|
123087
|
+
};
|
|
123088
|
+
const mapped = mapResolution(envelopeResult(answer.body));
|
|
123089
|
+
if (mapped.kind === "ready") {
|
|
123090
|
+
const preview = mapped.preview;
|
|
123091
|
+
forget.record(
|
|
123092
|
+
artifactOwnerFingerprint(expectedAccountId),
|
|
123093
|
+
url,
|
|
123094
|
+
[preview.favicon?.id, preview.image?.id].filter(
|
|
123095
|
+
(candidate) => typeof candidate === "string"
|
|
123096
|
+
)
|
|
123097
|
+
);
|
|
123098
|
+
return mapped;
|
|
123099
|
+
}
|
|
123100
|
+
if (mapped.kind === "absent") {
|
|
123101
|
+
const held = forget.take(accountFingerprint, url);
|
|
123102
|
+
if (held.length > 0) await cache?.drop(held);
|
|
123103
|
+
}
|
|
123104
|
+
return mapped;
|
|
123105
|
+
}
|
|
123106
|
+
async function artifact(input) {
|
|
123107
|
+
if (!isArtifactRequest(input))
|
|
123108
|
+
return { kind: "error", code: "invalid-request", status: 400 };
|
|
123109
|
+
const { id: id2, expectedAccountId } = input;
|
|
123110
|
+
const accountFingerprint = artifactOwnerFingerprint(expectedAccountId);
|
|
123111
|
+
const cached2 = await cache?.read(id2, accountFingerprint);
|
|
123112
|
+
if (cached2 !== void 0 && cached2 !== null)
|
|
123113
|
+
return { kind: "bytes", data: cached2.bytes, mimeType: cached2.mime };
|
|
123114
|
+
const epoch = cache?.currentEpoch() ?? 0;
|
|
123115
|
+
let answer;
|
|
123116
|
+
try {
|
|
123117
|
+
answer = await transport.media({
|
|
123118
|
+
op: "team_bridge.link_preview.artifact",
|
|
123119
|
+
id: id2,
|
|
123120
|
+
expectedAccountId
|
|
123121
|
+
});
|
|
123122
|
+
} catch {
|
|
123123
|
+
return { kind: "error", code: "io", status: 503 };
|
|
123124
|
+
}
|
|
123125
|
+
if (answer.kind === "bytes") {
|
|
123126
|
+
await cache?.store(
|
|
123127
|
+
id2,
|
|
123128
|
+
answer.mimeType,
|
|
123129
|
+
answer.data,
|
|
123130
|
+
accountFingerprint,
|
|
123131
|
+
epoch
|
|
123132
|
+
);
|
|
123133
|
+
return { kind: "bytes", data: answer.data, mimeType: answer.mimeType };
|
|
123134
|
+
}
|
|
123135
|
+
if (answer.status === 404)
|
|
123136
|
+
return {
|
|
123137
|
+
kind: "error",
|
|
123138
|
+
code: artifactRefusalCode(answer) === "artifact_not_found" ? "not-found" : "io",
|
|
123139
|
+
status: answer.status
|
|
123140
|
+
};
|
|
123141
|
+
if (answer.status === 409)
|
|
123142
|
+
return { kind: "error", code: "account-mismatch", status: 409 };
|
|
123143
|
+
if (answer.status === 401 || answer.status === 403)
|
|
123144
|
+
return { kind: "error", code: "unauthorized", status: answer.status };
|
|
123145
|
+
if (answer.status === 422)
|
|
123146
|
+
return { kind: "error", code: "invalid-request", status: 422 };
|
|
123147
|
+
return { kind: "error", code: "io", status: answer.status };
|
|
123148
|
+
}
|
|
123149
|
+
return { resolve, artifact };
|
|
123150
|
+
}
|
|
120670
123151
|
function deviceLocaleFor(appLike) {
|
|
120671
123152
|
const read2 = (value) => {
|
|
120672
123153
|
if (typeof value === "string")
|
|
@@ -123114,8 +125595,8 @@ function reportFromPayload(payload) {
|
|
|
123114
125595
|
daemons: daemonEntries
|
|
123115
125596
|
};
|
|
123116
125597
|
if (typeof raw.ok === "boolean") report.ok = raw.ok;
|
|
123117
|
-
const
|
|
123118
|
-
if (
|
|
125598
|
+
const failure2 = failureFromPayload(raw.failure);
|
|
125599
|
+
if (failure2) report.failure = failure2;
|
|
123119
125600
|
return report;
|
|
123120
125601
|
}
|
|
123121
125602
|
function failureFromPayload(value) {
|
|
@@ -132293,8 +134774,48 @@ electron.app.whenReady().then(async () => {
|
|
|
132293
134774
|
clear: () => {
|
|
132294
134775
|
publishBadge({ unreadCount: 0, pending: false }, void 0, false);
|
|
132295
134776
|
nativeBadge.reset();
|
|
134777
|
+
},
|
|
134778
|
+
// Fire-and-forget: the sign-out must not wait on a directory sweep. A delete that
|
|
134779
|
+
// fails is retried by the next `clear()` and otherwise waits for the NEXT LAUNCH:
|
|
134780
|
+
// this process reaps orphaned files in `open()` and in every `clearLocked()`, and
|
|
134781
|
+
// nowhere else (review round 1, F-4; corrected in round 2). Both caches are
|
|
134782
|
+
// constructed just below this statement — see why there, beside those
|
|
134783
|
+
// constructions — and these closures only reach them when a transition actually
|
|
134784
|
+
// fires, which is after this synchronous block has finished.
|
|
134785
|
+
principalChanged: () => {
|
|
134786
|
+
void linkPreviewArtifacts.fence();
|
|
134787
|
+
void teamBridgeImages.fence();
|
|
134788
|
+
},
|
|
134789
|
+
/*
|
|
134790
|
+
* THE SAME PRINCIPAL, AS A STATE RATHER THAN ONLY AS AN EVENT.
|
|
134791
|
+
*
|
|
134792
|
+
* `principalChanged` above is fired from one witness (`observeResponse`), so it
|
|
134793
|
+
* never fires for a principal that changed while this process was closed, and
|
|
134794
|
+
* it fires spuriously at every launch. This port carries the answer instead:
|
|
134795
|
+
* fired from a renderer status AND from the reconcile poll, it lets the image
|
|
134796
|
+
* cache bind its bytes to the principal the app can actually see, and drop
|
|
134797
|
+
* them when that is a different account or a verified sign-out.
|
|
134798
|
+
*/
|
|
134799
|
+
principalResolved: (accountId) => {
|
|
134800
|
+
void linkPreviewArtifacts.bind(accountId);
|
|
134801
|
+
void teamBridgeImages.bind(accountId);
|
|
132296
134802
|
}
|
|
132297
134803
|
});
|
|
134804
|
+
const linkPreviewArtifacts = new LinkPreviewArtifactCache({
|
|
134805
|
+
// The documented home: <userData>/cache/link-previews, one file per
|
|
134806
|
+
// artifact id with an `index.json` beside them.
|
|
134807
|
+
dir: path$1.join(electron.app.getPath("userData"), "cache", "link-previews")
|
|
134808
|
+
});
|
|
134809
|
+
void linkPreviewArtifacts.open().catch(() => {
|
|
134810
|
+
});
|
|
134811
|
+
const teamBridgeImages = new TeamBridgeImageCache({
|
|
134812
|
+
// The documented home: <userData>/cache/team-bridge-images, one hashed file
|
|
134813
|
+
// per receipt with an `index.json` beside them.
|
|
134814
|
+
dir: path$1.join(electron.app.getPath("userData"), "cache", "team-bridge-images")
|
|
134815
|
+
});
|
|
134816
|
+
void teamBridgeImages.open().catch(() => {
|
|
134817
|
+
});
|
|
134818
|
+
backendService.attachTeamBridgeImageCache(teamBridgeImages);
|
|
132298
134819
|
refreshAppIconBadge = () => {
|
|
132299
134820
|
if (process.platform === "win32") nativeBadge.invalidateOverlayTarget();
|
|
132300
134821
|
appAttention.projection.refresh();
|
|
@@ -132674,6 +135195,13 @@ electron.app.whenReady().then(async () => {
|
|
|
132674
135195
|
},
|
|
132675
135196
|
(m) => logger.warn(m, LogFileType.BACKEND)
|
|
132676
135197
|
);
|
|
135198
|
+
const linkPreview = createLinkPreviewService({
|
|
135199
|
+
transport: {
|
|
135200
|
+
request: (input) => sendDesktop(input),
|
|
135201
|
+
media: (input) => backendService.requestDesktopMedia(input, null)
|
|
135202
|
+
},
|
|
135203
|
+
cache: linkPreviewArtifacts
|
|
135204
|
+
});
|
|
132677
135205
|
registerDesktopIPC(
|
|
132678
135206
|
() => mainWindow,
|
|
132679
135207
|
rendererUrl,
|
|
@@ -132727,7 +135255,13 @@ electron.app.whenReady().then(async () => {
|
|
|
132727
135255
|
() => {
|
|
132728
135256
|
void mainLocale.refresh();
|
|
132729
135257
|
},
|
|
132730
|
-
(input) => recordingShortcut.admit(input)
|
|
135258
|
+
(input) => recordingShortcut.admit(input),
|
|
135259
|
+
/*
|
|
135260
|
+
* The link-preview proxy, LAST for the reason the signature's own note gives:
|
|
135261
|
+
* every earlier caller passes these positionally. It rides the same sender
|
|
135262
|
+
* gate as every other channel above it.
|
|
135263
|
+
*/
|
|
135264
|
+
linkPreview
|
|
132731
135265
|
);
|
|
132732
135266
|
const recordingSenders = () => [
|
|
132733
135267
|
...mainWindow === null ? [] : [{ window: mainWindow, url: rendererUrl }],
|
|
@@ -132803,9 +135337,9 @@ electron.app.whenReady().then(async () => {
|
|
|
132803
135337
|
async (_, filePath) => {
|
|
132804
135338
|
const resolved = resolveUserPath(filePath);
|
|
132805
135339
|
try {
|
|
132806
|
-
const
|
|
132807
|
-
if (
|
|
132808
|
-
return { ok: false, resolved, error:
|
|
135340
|
+
const failure2 = await electron.shell.openPath(resolved);
|
|
135341
|
+
if (failure2) {
|
|
135342
|
+
return { ok: false, resolved, error: failure2 };
|
|
132809
135343
|
}
|
|
132810
135344
|
return { ok: true, resolved };
|
|
132811
135345
|
} catch (error) {
|