local-operator-ui 0.50.11 → 0.51.1
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 +1866 -161
- package/out/renderer/assets/{_basePickBy-BLy0hAlE.js → _basePickBy-Cb7CCjss.js} +1 -1
- package/out/renderer/assets/{_baseUniq-BlUN8jcK.js → _baseUniq-BApGlX12.js} +1 -1
- package/out/renderer/assets/{agent-details-page-zixz-_vD.js → agent-details-page-BhYOjjGp.js} +1 -1
- package/out/renderer/assets/{agent-hub-page-P_sP_k41.js → agent-hub-page--gvclInE.js} +1 -1
- package/out/renderer/assets/{agents-page-DPOxT5wB.js → agents-page-BuL31v-m.js} +3 -3
- package/out/renderer/assets/{appearance-Qga5xSRf.js → appearance-BtC6_ySm.js} +19 -19
- package/out/renderer/assets/{approvalsOverlay-BHW3Rvqd.css → approvalsOverlay-CAjdhWyk.css} +1 -1
- package/out/renderer/assets/{approvalsOverlay-CZyctJKg.js → approvalsOverlay-mHKr0l1j.js} +1 -1
- package/out/renderer/assets/{arc-CKz4vCBx.js → arc-DwjLIhaD.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-DDmEvrZz.js → architectureDiagram-IEHRJDOE-BooZz6yo.js} +1 -1
- package/out/renderer/assets/{avatar-cropper-B3O2UQ4z.js → avatar-cropper-BZsvK3cw.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-kK7lzVNf.js → blockDiagram-JOT3LUYC-B0fALjML.js} +1 -1
- package/out/renderer/assets/{book-open-D_8LQHNl.js → book-open-Bd_iNfoU.js} +1 -1
- package/out/renderer/assets/browser-page-C9xHpNYC.js +1 -0
- package/out/renderer/assets/{browser-webauthn-prompt-sbqb2NuE.js → browser-webauthn-prompt-CmtAfgeh.js} +1 -1
- package/out/renderer/assets/{building-2-tIpP_TRE.js → building-2-C2cryJ_o.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-B13qzZI6.js → c4Diagram-VJAJSXHY-BQ-_GlTM.js} +1 -1
- package/out/renderer/assets/channel-BMHLQJFu.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-KQ6Ich_0.js → chunk-4BMEZGHF-CfT0w73q.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-BOSW6JNN.js → chunk-A2AXSNBT-Bo9xc75F.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-BFiOlLeI.js → chunk-AEK57VVT-CBXHKvAW.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-Duqv7Gtd.js → chunk-D6G4REZN-BQCjmvaM.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-CxQXd5a3.js → chunk-RZ5BOZE2-CvF0e6hC.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-BvHuOcY9.js → chunk-XZIHB7SX-BJjHkrF_.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-BV0oCouL.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-BV0oCouL.js +1 -0
- package/out/renderer/assets/clone-D8jbt9C6.js +1 -0
- package/out/renderer/assets/{console-mirror-UuPaWNT9.js → console-mirror-YSayqe62.js} +1 -1
- package/out/renderer/assets/{consoleCapture-DxgVtQTa.js → consoleCapture-DUHIWp-n.js} +1 -1
- package/out/renderer/assets/{conversation-input-sync-Bgr8dwlL.js → conversation-input-sync-atWR17wI.js} +17 -17
- package/out/renderer/assets/{dagre-OKDRZEBW-bct7NIzI.js → dagre-OKDRZEBW-C9cWJEJd.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-CboqZw4Q.js → diagram-SSKATNLV-5bNCKdgb.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-BWcPI7Vj.js → diagram-VNBRO52H-C799B_J5.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-aMzdjVpu.js → erDiagram-Q7BY3M3F-BV-Laqrx.js} +1 -1
- package/out/renderer/assets/{error-boundary-DlgiXR_W.js → error-boundary-VEzedOoH.js} +2 -2
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-B5nx2Zz_.js → flowDiagram-4HSFHLVR-Ck-gp7wb.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-D7iAjZPD.js → ganttDiagram-APWFNJXF-CfkqblvS.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-CAO-egov.js → gitGraphDiagram-7IBYFJ6S-No55XYeM.js} +1 -1
- package/out/renderer/assets/{graph-BwZqKwz1.js → graph-C1EVHxRL.js} +1 -1
- package/out/renderer/assets/{heart-BCK87brK.js → heart-DMUI3SKo.js} +1 -1
- package/out/renderer/assets/{index-B_QzzAzx.js → index-BuFQJ9Mf.js} +1 -1
- package/out/renderer/assets/{index-BBh_v05R.js → index-By7e-w5j.js} +1 -1
- package/out/renderer/assets/index-C-3hvHdK.css +1 -0
- package/out/renderer/assets/{index-BHTIrrxr.js → index-DXo5w6mT.js} +29 -29
- package/out/renderer/assets/{index-BMeH2cyS.js → index-hlPx4ocq.js} +1 -1
- package/out/renderer/assets/infoDiagram-PH2N3AL5-FXFSvwcW.js +2 -0
- package/out/renderer/assets/{installer-B0kiahjw.js → installer-CkfIYba-.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-QVb22GnB.js → journeyDiagram-U35MCT3I-D0Xg6_R4.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-Bp0ZUbAp.js → kanban-definition-NDS4AKOZ-zNoG8sv7.js} +1 -1
- package/out/renderer/assets/{layout-DUnvuTZc.js → layout-BbrFA2C_.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-c2t8MEkp.js → legacy-agents-page-XOgfLesS.js} +1 -1
- package/out/renderer/assets/{library-page-F7ADbfmd.js → library-page-BjWg0UNZ.js} +3 -3
- package/out/renderer/assets/{log-in-CCynzL3t.js → log-in-DqnRQgIy.js} +1 -1
- package/out/renderer/assets/{mermaid.core-BfNYlkXX.js → mermaid.core-VbO_OKTu.js} +19 -19
- package/out/renderer/assets/{mesh-page-CvIbs7-5.js → mesh-page-CaeD35Y0.js} +1 -1
- package/out/renderer/assets/{messages-CB08eCJU.js → messages-Cw_Hdnl7.js} +1 -1
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-3NA6_2Ql.js → mindmap-definition-ALO5MXBD-BiKaBtve.js} +1 -1
- package/out/renderer/assets/{mini-BL2LzBx5.js → mini-BeaDBXy5.js} +1 -1
- package/out/renderer/assets/{notebook-pen-CVBxcim-.js → notebook-pen-DJc4ppox.js} +1 -1
- package/out/renderer/assets/{notifications-page-BgURqgB7.js → notifications-page-DaMYoJpT.js} +1 -1
- package/out/renderer/assets/{org-access-yiseHO4_.js → org-access-DOzJPEl1.js} +1 -1
- package/out/renderer/assets/{org-surface-gate-DdlWGcie.js → org-surface-gate-Bn5IX58N.js} +1 -1
- package/out/renderer/assets/{page-header-BxwBWZTf.js → page-header-BUXWTPFV.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-7pP_uvEZ.js → pieDiagram-IB7DONF6-BVroJe0x.js} +1 -1
- package/out/renderer/assets/{project-markdown-D7sDv_F9.js → project-markdown-Dav8M2zu.js} +1 -1
- package/out/renderer/assets/{projects-page-BzIoEJ4J.js → projects-page-BzD1-8pV.js} +2 -2
- package/out/renderer/assets/{publication-validation-Q2TXU7EB.js → publication-validation-DoArrPRs.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-CBq_sdux.js → quadrantDiagram-7GDLP6J5-BRskutVZ.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-Bljpe7MY.js → radar-MK3ICKWK-CziculHL.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-BoSljNKo.js → radient-auth-buttons-rZov31ZH.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-CmlCCtjU.js → requirementDiagram-KVF5MWMF-CdZcWn7x.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-Do-Nnqcd.js → sankeyDiagram-QLVOVGJD-Sc6evN1k.js} +1 -1
- package/out/renderer/assets/{schedules-page-NLQ_Mrfi.js → schedules-page-R8pwitO-.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-mgHxN5Et.js → sequenceDiagram-X6HHIX6F-DPZ-_IKl.js} +1 -1
- package/out/renderer/assets/{settings-page-DOpmbZPP.js → settings-page---3j4dyG.js} +3 -3
- package/out/renderer/assets/{smartart-DG_SI8w4.js → smartart-D-YIFxZ-.js} +1 -1
- package/out/renderer/assets/{stateDiagram-DGXRK772-Djmv2Wqx.js → stateDiagram-DGXRK772-CWYxfFPS.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-7lkCcCLZ.js +1 -0
- package/out/renderer/assets/team-bridge-page-BIKJX5tx.js +60 -0
- package/out/renderer/assets/{team-bridge-scope-preference-DPQ0LEA3.js → team-bridge-scope-preference-BdnnNlqq.js} +1 -1
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-DDf_IruO.js → timeline-definition-BDJGKUSR-yFUzTobJ.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-H9VyjHin.js → use-download-agent-mutation-DVccRLQt.js} +1 -1
- package/out/renderer/assets/{use-session-snapshot-CSozG8-n.js → use-session-snapshot-C63UEDto.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-fubriRGW.js → xychartDiagram-VJFVF3MP-DfWPiSE0.js} +1 -1
- package/out/renderer/browser-approvals-overlay.html +3 -3
- 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-Djb1cs7X.js +0 -1
- package/out/renderer/assets/channel-OAMn7bvt.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-B4BAeQra.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-B4BAeQra.js +0 -1
- package/out/renderer/assets/clone-fvWkTbP4.js +0 -1
- package/out/renderer/assets/index-BiKEZgcN.css +0 -1
- package/out/renderer/assets/infoDiagram-PH2N3AL5-DcXivpas.js +0 -2
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-C2e3f6R2.js +0 -1
- package/out/renderer/assets/team-bridge-page-Da-0rKFD.js +0 -60
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");
|
|
@@ -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",
|
|
@@ -76609,6 +76631,9 @@ class AppAttentionService {
|
|
|
76609
76631
|
if (op.startsWith("team_bridge.")) this.invalidateBridge();
|
|
76610
76632
|
else this.invalidate();
|
|
76611
76633
|
}
|
|
76634
|
+
if (returnedPrincipal !== void 0) {
|
|
76635
|
+
this.ports.principalResolved?.(returnedPrincipal);
|
|
76636
|
+
}
|
|
76612
76637
|
}
|
|
76613
76638
|
invalidateBridge() {
|
|
76614
76639
|
if (this.stopped) return;
|
|
@@ -76711,6 +76736,7 @@ class AppAttentionService {
|
|
|
76711
76736
|
this.cursor = void 0;
|
|
76712
76737
|
this.projection.setBridgeUnread(0, projectionGeneration);
|
|
76713
76738
|
}
|
|
76739
|
+
this.ports.principalResolved?.(account);
|
|
76714
76740
|
if (!account) continue;
|
|
76715
76741
|
const unread = this.body(
|
|
76716
76742
|
await this.ports.request({
|
|
@@ -80409,10 +80435,11 @@ const ARTIFACT_ALLOWED_MIMES = /* @__PURE__ */ new Set([
|
|
|
80409
80435
|
"image/webp",
|
|
80410
80436
|
"image/vnd.microsoft.icon"
|
|
80411
80437
|
]);
|
|
80412
|
-
const
|
|
80413
|
-
const
|
|
80414
|
-
const
|
|
80415
|
-
const
|
|
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;
|
|
80416
80443
|
function artifactOwnerFingerprint(accountId) {
|
|
80417
80444
|
return node_crypto.createHash("sha256").update(`link-preview-account\0${accountId}`).digest("hex").slice(0, 32);
|
|
80418
80445
|
}
|
|
@@ -80431,10 +80458,38 @@ class LinkPreviewArtifactCache {
|
|
|
80431
80458
|
foreignHits = 0;
|
|
80432
80459
|
lastSweep = Number.NEGATIVE_INFINITY;
|
|
80433
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;
|
|
80434
80489
|
/** Serializes every mutating pass, so two concurrent writers cannot interleave
|
|
80435
80490
|
* a sweep with a store and leave the index accounting for a file that is gone.
|
|
80436
|
-
* `read` is
|
|
80437
|
-
*
|
|
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. */
|
|
80438
80493
|
queue = Promise.resolve();
|
|
80439
80494
|
constructor(options) {
|
|
80440
80495
|
this.dir = options.dir;
|
|
@@ -80449,9 +80504,22 @@ class LinkPreviewArtifactCache {
|
|
|
80449
80504
|
get directory() {
|
|
80450
80505
|
return this.dir;
|
|
80451
80506
|
}
|
|
80507
|
+
/** The fence value a store must carry back; see `epoch` and `store`. */
|
|
80508
|
+
currentEpoch() {
|
|
80509
|
+
return this.epoch;
|
|
80510
|
+
}
|
|
80452
80511
|
/**
|
|
80453
|
-
* Create the directory, load the index,
|
|
80454
|
-
* apply the bounds once.
|
|
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.
|
|
80455
80523
|
*
|
|
80456
80524
|
* STARTUP IS THE ONE UNCONDITIONAL SWEEP. The interval below bounds how often a
|
|
80457
80525
|
* read or write may sweep, which would otherwise let a cold cache keep expired
|
|
@@ -80459,18 +80527,79 @@ class LinkPreviewArtifactCache {
|
|
|
80459
80527
|
* and a stale index should not wait for a card to be drawn before it recovers
|
|
80460
80528
|
* the space.
|
|
80461
80529
|
*/
|
|
80462
|
-
async open() {
|
|
80463
|
-
await promises.mkdir(this.dir, { recursive: true, mode: DIRECTORY_MODE });
|
|
80464
|
-
await promises.chmod(this.dir, DIRECTORY_MODE).catch(() => {
|
|
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(() => {
|
|
80465
80533
|
});
|
|
80466
80534
|
await this.loadIndex();
|
|
80535
|
+
const loadedPrincipal = this.boundPrincipal;
|
|
80536
|
+
this.opened = true;
|
|
80467
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
|
+
}
|
|
80468
80558
|
await this.removeOrphans();
|
|
80469
80559
|
await this.sweepNow();
|
|
80470
80560
|
});
|
|
80471
|
-
this.opened = true;
|
|
80472
80561
|
this.lastSweep = this.now();
|
|
80473
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
|
+
}
|
|
80474
80603
|
/** Every cached id currently indexed, oldest use first. Diagnostics and tests
|
|
80475
80604
|
* only: the bytes are addressed one id at a time. */
|
|
80476
80605
|
ids() {
|
|
@@ -80502,35 +80631,53 @@ class LinkPreviewArtifactCache {
|
|
|
80502
80631
|
*/
|
|
80503
80632
|
async read(id2, accountFingerprint) {
|
|
80504
80633
|
if (!this.opened) return null;
|
|
80505
|
-
const
|
|
80506
|
-
|
|
80507
|
-
this.
|
|
80508
|
-
|
|
80509
|
-
|
|
80510
|
-
|
|
80511
|
-
this.
|
|
80512
|
-
|
|
80513
|
-
|
|
80514
|
-
|
|
80515
|
-
|
|
80516
|
-
|
|
80517
|
-
|
|
80518
|
-
|
|
80519
|
-
|
|
80520
|
-
|
|
80521
|
-
|
|
80522
|
-
|
|
80523
|
-
|
|
80524
|
-
|
|
80525
|
-
|
|
80526
|
-
|
|
80527
|
-
|
|
80528
|
-
|
|
80529
|
-
|
|
80530
|
-
|
|
80531
|
-
|
|
80532
|
-
|
|
80533
|
-
|
|
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
|
+
});
|
|
80534
80681
|
}
|
|
80535
80682
|
/**
|
|
80536
80683
|
* Keep one blob for one receipt, then re-apply the bounds if they are exceeded.
|
|
@@ -80541,17 +80688,20 @@ class LinkPreviewArtifactCache {
|
|
|
80541
80688
|
* an id that is not one (see the header's note on `image/svg+xml` and on the
|
|
80542
80689
|
* file name being a path segment).
|
|
80543
80690
|
*/
|
|
80544
|
-
async store(id2, mime, bytes, accountFingerprint) {
|
|
80691
|
+
async store(id2, mime, bytes, accountFingerprint, epoch = this.epoch) {
|
|
80545
80692
|
if (!this.opened) return;
|
|
80546
80693
|
if (bytes.byteLength === 0 || bytes.byteLength > ARTIFACT_MAX_BLOB_BYTES)
|
|
80547
80694
|
return;
|
|
80548
80695
|
if (!ARTIFACT_ALLOWED_MIMES.has(mime)) return;
|
|
80549
80696
|
if (!LINK_PREVIEW_ARTIFACT_ID.test(id2)) return;
|
|
80550
80697
|
await this.serialize(async () => {
|
|
80698
|
+
if (epoch !== this.epoch) {
|
|
80699
|
+
return;
|
|
80700
|
+
}
|
|
80551
80701
|
const path2 = path$1.join(this.dir, id2);
|
|
80552
80702
|
const temp = `${path2}.${process.pid}.${node_crypto.randomBytes(6).toString("hex")}.tmp`;
|
|
80553
80703
|
try {
|
|
80554
|
-
await promises.writeFile(temp, bytes, { mode: FILE_MODE });
|
|
80704
|
+
await promises.writeFile(temp, bytes, { mode: FILE_MODE$1 });
|
|
80555
80705
|
await promises.rename(temp, path2);
|
|
80556
80706
|
} catch {
|
|
80557
80707
|
await promises.rm(temp, { force: true }).catch(() => {
|
|
@@ -80568,6 +80718,7 @@ class LinkPreviewArtifactCache {
|
|
|
80568
80718
|
lastUsedAt: at,
|
|
80569
80719
|
account: accountFingerprint
|
|
80570
80720
|
});
|
|
80721
|
+
this.boundPrincipal = accountFingerprint;
|
|
80571
80722
|
await this.persistIndex();
|
|
80572
80723
|
await this.sweepNow();
|
|
80573
80724
|
});
|
|
@@ -80609,18 +80760,29 @@ class LinkPreviewArtifactCache {
|
|
|
80609
80760
|
* worth less than the guarantee that none of them are the departing account's.
|
|
80610
80761
|
*/
|
|
80611
80762
|
async clear() {
|
|
80612
|
-
|
|
80613
|
-
|
|
80614
|
-
|
|
80615
|
-
|
|
80616
|
-
|
|
80617
|
-
|
|
80618
|
-
|
|
80619
|
-
|
|
80620
|
-
|
|
80621
|
-
|
|
80622
|
-
|
|
80623
|
-
|
|
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();
|
|
80624
80786
|
}
|
|
80625
80787
|
/** Apply the bounds now, whatever the interval says. */
|
|
80626
80788
|
async sweep() {
|
|
@@ -80656,7 +80818,10 @@ class LinkPreviewArtifactCache {
|
|
|
80656
80818
|
async maybeSweep() {
|
|
80657
80819
|
if (this.now() - this.lastSweep < this.sweepIntervalMs) return;
|
|
80658
80820
|
this.lastSweep = this.now();
|
|
80659
|
-
await this.serialize(
|
|
80821
|
+
await this.serialize(async () => {
|
|
80822
|
+
await this.sweepNow();
|
|
80823
|
+
if (this.indexDirty) await this.persistIndex();
|
|
80824
|
+
}).catch(() => {
|
|
80660
80825
|
});
|
|
80661
80826
|
}
|
|
80662
80827
|
async sweepNow() {
|
|
@@ -80677,7 +80842,7 @@ class LinkPreviewArtifactCache {
|
|
|
80677
80842
|
await this.unlink(oldest);
|
|
80678
80843
|
changed = true;
|
|
80679
80844
|
}
|
|
80680
|
-
if (changed) await this.persistIndex();
|
|
80845
|
+
if (changed || this.indexDirty) await this.persistIndex();
|
|
80681
80846
|
}
|
|
80682
80847
|
async unlink(id2) {
|
|
80683
80848
|
try {
|
|
@@ -80688,7 +80853,7 @@ class LinkPreviewArtifactCache {
|
|
|
80688
80853
|
async loadIndex() {
|
|
80689
80854
|
let raw;
|
|
80690
80855
|
try {
|
|
80691
|
-
raw = await promises.readFile(path$1.join(this.dir, INDEX_FILE), "utf8");
|
|
80856
|
+
raw = await promises.readFile(path$1.join(this.dir, INDEX_FILE$1), "utf8");
|
|
80692
80857
|
} catch {
|
|
80693
80858
|
return;
|
|
80694
80859
|
}
|
|
@@ -80698,16 +80863,21 @@ class LinkPreviewArtifactCache {
|
|
|
80698
80863
|
} catch {
|
|
80699
80864
|
return;
|
|
80700
80865
|
}
|
|
80701
|
-
if (typeof document !== "object" || document === null || document.version !== INDEX_VERSION || typeof document.entries !== "object" || document.entries === null)
|
|
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)))
|
|
80702
80870
|
return;
|
|
80703
80871
|
for (const [id2, entry] of Object.entries(
|
|
80704
80872
|
document.entries
|
|
80705
80873
|
)) {
|
|
80706
|
-
if (!isIndexEntry(entry)) continue;
|
|
80874
|
+
if (!isIndexEntry$1(entry)) continue;
|
|
80875
|
+
if (principal !== null && entry.account !== principal) continue;
|
|
80707
80876
|
if (!LINK_PREVIEW_ARTIFACT_ID.test(id2)) continue;
|
|
80708
80877
|
this.entries.set(id2, { ...entry });
|
|
80709
80878
|
this.residentBytes += entry.size;
|
|
80710
80879
|
}
|
|
80880
|
+
this.boundPrincipal = principal;
|
|
80711
80881
|
}
|
|
80712
80882
|
/**
|
|
80713
80883
|
* Write the index beside the blobs, atomically.
|
|
@@ -80719,14 +80889,16 @@ class LinkPreviewArtifactCache {
|
|
|
80719
80889
|
*/
|
|
80720
80890
|
async persistIndex() {
|
|
80721
80891
|
const document = {
|
|
80722
|
-
version: INDEX_VERSION,
|
|
80892
|
+
version: INDEX_VERSION$1,
|
|
80893
|
+
principal: this.boundPrincipal,
|
|
80723
80894
|
entries: Object.fromEntries(this.entries)
|
|
80724
80895
|
};
|
|
80725
|
-
const path2 = path$1.join(this.dir, INDEX_FILE);
|
|
80896
|
+
const path2 = path$1.join(this.dir, INDEX_FILE$1);
|
|
80726
80897
|
const temp = `${path2}.${process.pid}.${node_crypto.randomBytes(6).toString("hex")}.tmp`;
|
|
80727
80898
|
try {
|
|
80728
|
-
await promises.writeFile(temp, JSON.stringify(document), { mode: FILE_MODE });
|
|
80899
|
+
await promises.writeFile(temp, JSON.stringify(document), { mode: FILE_MODE$1 });
|
|
80729
80900
|
await promises.rename(temp, path2);
|
|
80901
|
+
this.indexDirty = false;
|
|
80730
80902
|
} catch {
|
|
80731
80903
|
await promises.rm(temp, { force: true }).catch(() => {
|
|
80732
80904
|
});
|
|
@@ -80743,7 +80915,7 @@ class LinkPreviewArtifactCache {
|
|
|
80743
80915
|
return;
|
|
80744
80916
|
}
|
|
80745
80917
|
for (const name of names) {
|
|
80746
|
-
if (name === INDEX_FILE) continue;
|
|
80918
|
+
if (name === INDEX_FILE$1) continue;
|
|
80747
80919
|
if (this.entries.has(name)) continue;
|
|
80748
80920
|
try {
|
|
80749
80921
|
await promises.rm(path$1.join(this.dir, name), { recursive: true, force: true });
|
|
@@ -80761,10 +80933,13 @@ class LinkPreviewArtifactCache {
|
|
|
80761
80933
|
function previewKeyFor(accountFingerprint, url) {
|
|
80762
80934
|
return node_crypto.createHash("sha256").update(`link-preview\0${accountFingerprint}\0${url}`).digest("hex");
|
|
80763
80935
|
}
|
|
80764
|
-
function isIndexEntry(value) {
|
|
80936
|
+
function isIndexEntry$1(value) {
|
|
80765
80937
|
if (typeof value !== "object" || value === null) return false;
|
|
80766
80938
|
const entry = value;
|
|
80767
|
-
return typeof entry.mime === "string" && entry.mime.length > 0 && entry.mime.length <= 128 && typeof entry.size === "number" && Number.isInteger(entry.size) && entry.size
|
|
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;
|
|
80768
80943
|
}
|
|
80769
80944
|
const DECIMAL_LENGTH$1 = /^\d+$/;
|
|
80770
80945
|
const MAX_REFUSAL_BODY_BYTES = 4096;
|
|
@@ -80920,6 +81095,508 @@ async function readOwnerAuditAttachment(response) {
|
|
|
80920
81095
|
reader.releaseLock();
|
|
80921
81096
|
}
|
|
80922
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
|
+
}
|
|
80923
81600
|
const NOTIFICATION_INITIALS = /^[\p{L}\p{N}]{0,2}$/u;
|
|
80924
81601
|
const id = zod.z.string().min(1).max(128).regex(/^[a-zA-Z0-9_-]+$/);
|
|
80925
81602
|
const MAX_UPLOAD_BYTES = 16 * 1024 * 1024;
|
|
@@ -81376,7 +82053,14 @@ function scalarParams(params) {
|
|
|
81376
82053
|
}
|
|
81377
82054
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
81378
82055
|
}
|
|
81379
|
-
|
|
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) {
|
|
81380
82064
|
const parsed = mediaRequestSchema.safeParse(input);
|
|
81381
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
|
|
81382
82066
|
// never names both pictures (core refuses either; so do we, first).
|
|
@@ -81423,6 +82107,36 @@ async function requestDesktopMediaOutcome(input, bytes, backendUrl, token) {
|
|
|
81423
82107
|
};
|
|
81424
82108
|
}
|
|
81425
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
|
+
}
|
|
81426
82140
|
let body2;
|
|
81427
82141
|
let contentType;
|
|
81428
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") {
|
|
@@ -81673,11 +82387,30 @@ async function requestDesktopMediaOutcome(input, bytes, backendUrl, token) {
|
|
|
81673
82387
|
answered: true
|
|
81674
82388
|
};
|
|
81675
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
|
+
}
|
|
81676
82401
|
return {
|
|
81677
82402
|
response: {
|
|
81678
82403
|
status: response.status,
|
|
81679
82404
|
kind: "bytes",
|
|
81680
|
-
|
|
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",
|
|
81681
82414
|
data: buffer
|
|
81682
82415
|
},
|
|
81683
82416
|
answered: true
|
|
@@ -84446,6 +85179,18 @@ class BackendServiceManager {
|
|
|
84446
85179
|
* configuration and not a cache to be second-guessed.
|
|
84447
85180
|
*/
|
|
84448
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;
|
|
84449
85194
|
/** Authenticated SSE relay for canonical session events. Recreated when the
|
|
84450
85195
|
* backend URL rotates (external-backend discovery) or the desktop token does
|
|
84451
85196
|
* (every managed start mints one), and dropped outright by `stop()`.
|
|
@@ -84519,6 +85264,16 @@ class BackendServiceManager {
|
|
|
84519
85264
|
* outlive the backend it described.
|
|
84520
85265
|
*/
|
|
84521
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
|
+
}
|
|
84522
85277
|
onBackendReady(observer) {
|
|
84523
85278
|
this.backendReadyObserver = observer;
|
|
84524
85279
|
}
|
|
@@ -84761,7 +85516,8 @@ class BackendServiceManager {
|
|
|
84761
85516
|
input,
|
|
84762
85517
|
bytes,
|
|
84763
85518
|
this.backendUrl,
|
|
84764
|
-
this.desktopToken
|
|
85519
|
+
this.desktopToken,
|
|
85520
|
+
this.teamBridgeImages
|
|
84765
85521
|
).then(({ response, answered }) => {
|
|
84766
85522
|
if (answered) this.daemonState.recordTransportAnswer();
|
|
84767
85523
|
return response;
|
|
@@ -89320,7 +90076,22 @@ const METHODS$1 = [
|
|
|
89320
90076
|
// on an app that predates it instead of sending an unknown method.
|
|
89321
90077
|
"hover",
|
|
89322
90078
|
// DOM/native and page-owned ARIA selection; never an OS popup.
|
|
89323
|
-
"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"
|
|
89324
90095
|
];
|
|
89325
90096
|
const METHOD_SET = new Set(METHODS$1);
|
|
89326
90097
|
function isMethod(value) {
|
|
@@ -89361,7 +90132,16 @@ const ERROR_CODES = [
|
|
|
89361
90132
|
// for the same reason METHODS is: this list is what `rpc.ts` narrows a raised
|
|
89362
90133
|
// code against, and an unknown code is silently dropped by the session's model —
|
|
89363
90134
|
// a command that hangs rather than one that fails.
|
|
89364
|
-
...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"
|
|
89365
90145
|
];
|
|
89366
90146
|
const HOST_CAPABILITIES = [
|
|
89367
90147
|
"console_resources",
|
|
@@ -89382,6 +90162,11 @@ const HOST_CAPABILITIES = [
|
|
|
89382
90162
|
// the extension/cmux hosts and older desktop apps must be refused by capability.
|
|
89383
90163
|
"hover",
|
|
89384
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",
|
|
89385
90170
|
// Session-scoped network capture. DESKTOP-ONLY: the extension's debugger is
|
|
89386
90171
|
// attached only for the duration of an action, so it holds no standing session
|
|
89387
90172
|
// to keep a `Network` subscription on. The backend therefore gates these four
|
|
@@ -89401,7 +90186,17 @@ const HOST_CAPABILITIES = [
|
|
|
89401
90186
|
"record_size",
|
|
89402
90187
|
// High-quality recording (quality on record_start) is not a method either; the
|
|
89403
90188
|
// harness capability-gates the one param on this name.
|
|
89404
|
-
"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"
|
|
89405
90200
|
];
|
|
89406
90201
|
const RUN_DIRNAME = path$1.join("run", "ui-browser");
|
|
89407
90202
|
const STATE_FILENAME = "host.json";
|
|
@@ -89782,9 +90577,9 @@ function requireDirectives() {
|
|
|
89782
90577
|
this.tags = Object.assign({}, Directives.defaultTags, tags2);
|
|
89783
90578
|
}
|
|
89784
90579
|
clone() {
|
|
89785
|
-
const
|
|
89786
|
-
|
|
89787
|
-
return
|
|
90580
|
+
const copy2 = new Directives(this.yaml, this.tags);
|
|
90581
|
+
copy2.docStart = this.docStart;
|
|
90582
|
+
return copy2;
|
|
89788
90583
|
}
|
|
89789
90584
|
/**
|
|
89790
90585
|
* During parsing, get a Directives instance for the current document and
|
|
@@ -90096,10 +90891,10 @@ function requireNode() {
|
|
|
90096
90891
|
}
|
|
90097
90892
|
/** Create a copy of this node. */
|
|
90098
90893
|
clone() {
|
|
90099
|
-
const
|
|
90894
|
+
const copy2 = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
90100
90895
|
if (this.range)
|
|
90101
|
-
|
|
90102
|
-
return
|
|
90896
|
+
copy2.range = this.range.slice();
|
|
90897
|
+
return copy2;
|
|
90103
90898
|
}
|
|
90104
90899
|
/** A plain JavaScript representation of this node. */
|
|
90105
90900
|
toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
@@ -90377,13 +91172,13 @@ function requireCollection() {
|
|
|
90377
91172
|
* @param schema - If defined, overwrites the original's schema
|
|
90378
91173
|
*/
|
|
90379
91174
|
clone(schema2) {
|
|
90380
|
-
const
|
|
91175
|
+
const copy2 = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
90381
91176
|
if (schema2)
|
|
90382
|
-
|
|
90383
|
-
|
|
91177
|
+
copy2.schema = schema2;
|
|
91178
|
+
copy2.items = copy2.items.map((it) => identity2.isNode(it) || identity2.isPair(it) ? it.clone(schema2) : it);
|
|
90384
91179
|
if (this.range)
|
|
90385
|
-
|
|
90386
|
-
return
|
|
91180
|
+
copy2.range = this.range.slice();
|
|
91181
|
+
return copy2;
|
|
90387
91182
|
}
|
|
90388
91183
|
/**
|
|
90389
91184
|
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
@@ -92793,9 +93588,9 @@ function requireSchema() {
|
|
|
92793
93588
|
this.sortMapEntries = typeof sortMapEntries === "function" ? sortMapEntries : sortMapEntries === true ? sortMapEntriesByKey : null;
|
|
92794
93589
|
}
|
|
92795
93590
|
clone() {
|
|
92796
|
-
const
|
|
92797
|
-
|
|
92798
|
-
return
|
|
93591
|
+
const copy2 = Object.create(Schema2.prototype, Object.getOwnPropertyDescriptors(this));
|
|
93592
|
+
copy2.tags = this.tags.slice();
|
|
93593
|
+
return copy2;
|
|
92799
93594
|
}
|
|
92800
93595
|
};
|
|
92801
93596
|
Schema.Schema = Schema$1;
|
|
@@ -92937,21 +93732,21 @@ function requireDocument() {
|
|
|
92937
93732
|
* Custom Node values that inherit from `Object` still refer to their original instances.
|
|
92938
93733
|
*/
|
|
92939
93734
|
clone() {
|
|
92940
|
-
const
|
|
93735
|
+
const copy2 = Object.create(Document2.prototype, {
|
|
92941
93736
|
[identity2.NODE_TYPE]: { value: identity2.DOC }
|
|
92942
93737
|
});
|
|
92943
|
-
|
|
92944
|
-
|
|
92945
|
-
|
|
92946
|
-
|
|
92947
|
-
|
|
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);
|
|
92948
93743
|
if (this.directives)
|
|
92949
|
-
|
|
92950
|
-
|
|
92951
|
-
|
|
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;
|
|
92952
93747
|
if (this.range)
|
|
92953
|
-
|
|
92954
|
-
return
|
|
93748
|
+
copy2.range = this.range.slice();
|
|
93749
|
+
return copy2;
|
|
92955
93750
|
}
|
|
92956
93751
|
/** Adds a value to the document. */
|
|
92957
93752
|
add(value) {
|
|
@@ -97621,11 +98416,11 @@ class ByteLog {
|
|
|
97621
98416
|
}
|
|
97622
98417
|
append(bytes) {
|
|
97623
98418
|
if (bytes.length === 0) return;
|
|
97624
|
-
const
|
|
97625
|
-
this.chunks.push({ offset: this.end, bytes:
|
|
97626
|
-
this.retained +=
|
|
97627
|
-
this.end +=
|
|
97628
|
-
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);
|
|
97629
98424
|
}
|
|
97630
98425
|
/**
|
|
97631
98426
|
* Read the retained bytes from `from` onward.
|
|
@@ -100895,8 +101690,8 @@ function loadNodePty() {
|
|
|
100895
101690
|
typeof __filename === "string" ? __filename : require("url").pathToFileURL(__filename).href
|
|
100896
101691
|
);
|
|
100897
101692
|
const namespace = requireFrom(PTY_PACKAGE);
|
|
100898
|
-
const
|
|
100899
|
-
if (typeof
|
|
101693
|
+
const module2 = "spawn" in namespace ? namespace : namespace.default;
|
|
101694
|
+
if (typeof module2?.spawn !== "function") {
|
|
100900
101695
|
cached = { ok: false, reason: "node-pty loaded but exports no spawn()" };
|
|
100901
101696
|
return cached;
|
|
100902
101697
|
}
|
|
@@ -100904,7 +101699,7 @@ function loadNodePty() {
|
|
|
100904
101699
|
platform: process.platform,
|
|
100905
101700
|
arch: process.arch
|
|
100906
101701
|
});
|
|
100907
|
-
cached = { ok: true, root, helper, module };
|
|
101702
|
+
cached = { ok: true, root, helper, module: module2 };
|
|
100908
101703
|
return cached;
|
|
100909
101704
|
} catch (error) {
|
|
100910
101705
|
cached = {
|
|
@@ -100914,7 +101709,7 @@ function loadNodePty() {
|
|
|
100914
101709
|
return cached;
|
|
100915
101710
|
}
|
|
100916
101711
|
}
|
|
100917
|
-
function spawnPty(
|
|
101712
|
+
function spawnPty(module2, options, onHeal) {
|
|
100918
101713
|
const load = cached;
|
|
100919
101714
|
if (load?.ok) {
|
|
100920
101715
|
const report = ensureSpawnHelperExecutable(load.root, {
|
|
@@ -100923,7 +101718,7 @@ function spawnPty(module, options, onHeal) {
|
|
|
100923
101718
|
});
|
|
100924
101719
|
if (report.healed) onHeal?.(report);
|
|
100925
101720
|
}
|
|
100926
|
-
return
|
|
101721
|
+
return module2.spawn(options.file, options.args, {
|
|
100927
101722
|
// The surface's own name, so a program that asks what terminal it is on gets
|
|
100928
101723
|
// the pinned answer the window's TERM already declares (design 6.6).
|
|
100929
101724
|
name: "xterm-256color",
|
|
@@ -105967,6 +106762,430 @@ function observeBrowserLocale(window) {
|
|
|
105967
106762
|
}
|
|
105968
106763
|
});
|
|
105969
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
|
+
}
|
|
105970
107189
|
function requesterOf(params, requestId2) {
|
|
105971
107190
|
const supplied = typeof params.requester === "string" ? params.requester.trim() : "";
|
|
105972
107191
|
return supplied.startsWith("session:") ? supplied : requestId2;
|
|
@@ -108449,6 +109668,15 @@ class CdpPool {
|
|
|
108449
109668
|
},
|
|
108450
109669
|
CDP_DEADLINE_MS
|
|
108451
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
|
+
}
|
|
108452
109680
|
} catch (error) {
|
|
108453
109681
|
this.forget(contents.id);
|
|
108454
109682
|
throw error;
|
|
@@ -109461,6 +110689,25 @@ function stateSuffix(node) {
|
|
|
109461
110689
|
if (truthy(property("disabled"))) markers.push("disabled");
|
|
109462
110690
|
return markers.length ? ` [${markers.join("] [")}]` : "";
|
|
109463
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
|
+
}
|
|
109464
110711
|
function compactAX(nodes, epoch, options = {}) {
|
|
109465
110712
|
const byId = new Map(nodes.map((node) => [node.nodeId, node]));
|
|
109466
110713
|
const refs = {};
|
|
@@ -109499,7 +110746,7 @@ function compactAX(nodes, epoch, options = {}) {
|
|
|
109499
110746
|
}
|
|
109500
110747
|
if (inside2) {
|
|
109501
110748
|
const shown = depth - (scopeAt ?? 0);
|
|
109502
|
-
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)}`);
|
|
109503
110750
|
}
|
|
109504
110751
|
}
|
|
109505
110752
|
for (const child of node.childIds ?? []) {
|
|
@@ -109621,6 +110868,132 @@ async function read(ctx, params) {
|
|
|
109621
110868
|
ctx.registry.touch(record);
|
|
109622
110869
|
return { text: String(text2), ...pageOf(record.view) };
|
|
109623
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
|
+
}
|
|
109624
110997
|
async function snapshot(ctx, params) {
|
|
109625
110998
|
const record = ctx.registry.requireSurface(params.tab);
|
|
109626
110999
|
const contents = record.view.webContents;
|
|
@@ -110623,6 +111996,8 @@ async function click(ctx, params) {
|
|
|
110623
111996
|
navigationSeen = true;
|
|
110624
111997
|
};
|
|
110625
111998
|
contents.on("did-start-navigation", onStart);
|
|
111999
|
+
const armableTarget = node.sessionId === void 0;
|
|
112000
|
+
if (armableTarget) armHostClipboardWrite(contents.id, node.frame?.frameId);
|
|
110626
112001
|
try {
|
|
110627
112002
|
await sendIn(ctx, contents, node.sessionId, "Runtime.callFunctionOn", {
|
|
110628
112003
|
objectId: node.objectId,
|
|
@@ -110631,6 +112006,7 @@ async function click(ctx, params) {
|
|
|
110631
112006
|
});
|
|
110632
112007
|
await sleep(1200);
|
|
110633
112008
|
} finally {
|
|
112009
|
+
if (armableTarget) clearHostClipboardArm(contents.id);
|
|
110634
112010
|
contents.removeListener("did-start-navigation", onStart);
|
|
110635
112011
|
}
|
|
110636
112012
|
if (navigationSeen) {
|
|
@@ -111053,10 +112429,10 @@ async function query(ctx, params) {
|
|
|
111053
112429
|
ctx.registry.touch(record);
|
|
111054
112430
|
return { ...result, ...pageOf(record.view) };
|
|
111055
112431
|
}
|
|
111056
|
-
function selectPage(mode, requested) {
|
|
112432
|
+
const SELECT_PAGE_SOURCE = `function selectPage(mode, requested) {
|
|
111057
112433
|
const doc = this.ownerDocument;
|
|
111058
112434
|
const win = doc.defaultView;
|
|
111059
|
-
const
|
|
112435
|
+
const clip = (text) => text.slice(0, 120);
|
|
111060
112436
|
const native = this instanceof win.HTMLSelectElement;
|
|
111061
112437
|
const kind = native ? "native" : "aria";
|
|
111062
112438
|
if (!native && !this.matches(
|
|
@@ -111069,8 +112445,8 @@ function selectPage(mode, requested) {
|
|
|
111069
112445
|
if (mode === "trigger") return { status: "ready", kind };
|
|
111070
112446
|
let root = this;
|
|
111071
112447
|
if (!native && !this.matches('[role="listbox"]')) {
|
|
111072
|
-
const ids = (this.getAttribute("aria-controls") || this.getAttribute("aria-owns") || "").split(
|
|
111073
|
-
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);
|
|
111074
112450
|
const candidates = controlled.length ? controlled : Array.from(doc.querySelectorAll('[role="listbox"]')).filter(
|
|
111075
112451
|
(el) => el.getClientRects().length > 0
|
|
111076
112452
|
);
|
|
@@ -111085,8 +112461,8 @@ function selectPage(mode, requested) {
|
|
|
111085
112461
|
}));
|
|
111086
112462
|
const available = facts.slice(0, 50).map((fact) => ({
|
|
111087
112463
|
...fact,
|
|
111088
|
-
label:
|
|
111089
|
-
value:
|
|
112464
|
+
label: clip(fact.label),
|
|
112465
|
+
value: clip(fact.value)
|
|
111090
112466
|
}));
|
|
111091
112467
|
const multiple = native ? this.multiple : root.getAttribute("aria-multiselectable") === "true";
|
|
111092
112468
|
if (mode === "describe") return { status: "ready", kind, multiple };
|
|
@@ -111129,8 +112505,12 @@ function selectPage(mode, requested) {
|
|
|
111129
112505
|
win.HTMLSelectElement.prototype,
|
|
111130
112506
|
"selectedIndex"
|
|
111131
112507
|
).set.call(this, indexes[0] ?? -1);
|
|
111132
|
-
this.dispatchEvent(
|
|
111133
|
-
|
|
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
|
+
);
|
|
111134
112514
|
}
|
|
111135
112515
|
const selected = facts.filter(
|
|
111136
112516
|
(o) => native ? elements[o.index].selected : elements[o.index].getAttribute("aria-selected") === "true"
|
|
@@ -111147,7 +112527,141 @@ function selectPage(mode, requested) {
|
|
|
111147
112527
|
verified,
|
|
111148
112528
|
available
|
|
111149
112529
|
};
|
|
111150
|
-
}
|
|
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
|
+
}`;
|
|
111151
112665
|
async function select(ctx, params) {
|
|
111152
112666
|
const target2 = stringParam(params, "selector") || stringParam(params, "ref");
|
|
111153
112667
|
const options = params.options;
|
|
@@ -111172,7 +112686,8 @@ async function select(ctx, params) {
|
|
|
111172
112686
|
"Runtime.callFunctionOn",
|
|
111173
112687
|
{
|
|
111174
112688
|
objectId: node.objectId,
|
|
111175
|
-
|
|
112689
|
+
// Committed source, never `.toString()`: see the import's note.
|
|
112690
|
+
functionDeclaration: SELECT_PAGE_SOURCE,
|
|
111176
112691
|
arguments: [{ value: mode }, { value: choices }],
|
|
111177
112692
|
returnByValue: true
|
|
111178
112693
|
}
|
|
@@ -111247,7 +112762,7 @@ async function select(ctx, params) {
|
|
|
111247
112762
|
"Runtime.callFunctionOn",
|
|
111248
112763
|
{
|
|
111249
112764
|
objectId: node.objectId,
|
|
111250
|
-
functionDeclaration:
|
|
112765
|
+
functionDeclaration: SELECT_PAGE_SOURCE,
|
|
111251
112766
|
arguments: [{ value: "option" }, { value: options }],
|
|
111252
112767
|
returnByValue: false
|
|
111253
112768
|
}
|
|
@@ -111296,6 +112811,60 @@ async function select(ctx, params) {
|
|
|
111296
112811
|
...pageOf(record.view)
|
|
111297
112812
|
};
|
|
111298
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
|
+
}
|
|
111299
112868
|
const MAX_AGENT_TABS = 8;
|
|
111300
112869
|
const BACKGROUND_VIEWPORT = {
|
|
111301
112870
|
x: 0,
|
|
@@ -113142,11 +114711,18 @@ const DOCUMENT_SCOPED = /* @__PURE__ */ new Set([
|
|
|
113142
114711
|
"ancestors",
|
|
113143
114712
|
"snapshot",
|
|
113144
114713
|
// `query` is a read of the CURRENT document's DOM (CSS in, descriptors out),
|
|
113145
|
-
// so it is authorized
|
|
113146
|
-
//
|
|
113147
|
-
//
|
|
113148
|
-
//
|
|
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).
|
|
113149
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`.
|
|
113150
114726
|
"screenshot",
|
|
113151
114727
|
"click",
|
|
113152
114728
|
"type",
|
|
@@ -113155,8 +114731,14 @@ const DOCUMENT_SCOPED = /* @__PURE__ */ new Set([
|
|
|
113155
114731
|
// stack, so it is authorized on entry and on the result exactly like `click`.
|
|
113156
114732
|
"hover",
|
|
113157
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",
|
|
113158
114739
|
"scroll",
|
|
113159
114740
|
"logs",
|
|
114741
|
+
"copy",
|
|
113160
114742
|
// `download` names a control on the CURRENT document (the link or button that
|
|
113161
114743
|
// starts the file) and `upload` names a file input on it, so both are authorized
|
|
113162
114744
|
// against that document on entry and again on the result. BOTH are in the
|
|
@@ -113192,6 +114774,11 @@ const NAVIGATING_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
113192
114774
|
// landing on success OR throw, and restore if unapproved. No native popup,
|
|
113193
114775
|
// no agent-initiated document request to intercept with Fetch.
|
|
113194
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",
|
|
113195
114782
|
"download",
|
|
113196
114783
|
"upload"
|
|
113197
114784
|
]);
|
|
@@ -113214,6 +114801,7 @@ const TAB_SCOPED = /* @__PURE__ */ new Set([
|
|
|
113214
114801
|
"press",
|
|
113215
114802
|
"hover",
|
|
113216
114803
|
"select",
|
|
114804
|
+
"setvalue",
|
|
113217
114805
|
"scroll",
|
|
113218
114806
|
"logs",
|
|
113219
114807
|
"close",
|
|
@@ -113225,6 +114813,11 @@ const TAB_SCOPED = /* @__PURE__ */ new Set([
|
|
|
113225
114813
|
// which call.
|
|
113226
114814
|
"download",
|
|
113227
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",
|
|
113228
114821
|
// Network capture is TAB-scoped and deliberately NOT `DOCUMENT_SCOPED`, for the
|
|
113229
114822
|
// same reason `logs` is not: its answer describes the tab's TRAFFIC (which
|
|
113230
114823
|
// spans documents, redirects and third-party subresources), not the document
|
|
@@ -113496,10 +115089,14 @@ class BrowserHost {
|
|
|
113496
115089
|
return hover(this, params);
|
|
113497
115090
|
case "select":
|
|
113498
115091
|
return select(this, params);
|
|
115092
|
+
case "setvalue":
|
|
115093
|
+
return setvalue(this, params);
|
|
113499
115094
|
case "download":
|
|
113500
115095
|
return download(this, params);
|
|
113501
115096
|
case "upload":
|
|
113502
115097
|
return upload(this, params);
|
|
115098
|
+
case "copy":
|
|
115099
|
+
return copy(this, params);
|
|
113503
115100
|
case "network_start":
|
|
113504
115101
|
return networkStart(this, params, requestId2);
|
|
113505
115102
|
case "network_stop":
|
|
@@ -113863,10 +115460,10 @@ class BrowserHost {
|
|
|
113863
115460
|
};
|
|
113864
115461
|
if (action === "reload") record.view.webContents.reload();
|
|
113865
115462
|
else {
|
|
113866
|
-
const
|
|
115463
|
+
const copy2 = await this.createUserTab(null, url, (created) => {
|
|
113867
115464
|
destinationId = created.tabId;
|
|
113868
115465
|
});
|
|
113869
|
-
destinationId =
|
|
115466
|
+
destinationId = copy2.tabId;
|
|
113870
115467
|
}
|
|
113871
115468
|
this.onChanged();
|
|
113872
115469
|
return { status: "completed", action, tabId: destinationId };
|
|
@@ -115141,6 +116738,57 @@ class DownloadArmer {
|
|
|
115141
116738
|
capture.finish?.();
|
|
115142
116739
|
}
|
|
115143
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
|
+
}
|
|
115144
116792
|
/**
|
|
115145
116793
|
* Decide one download attempt. THE ONLY ENTRY POINT `profile.ts` calls.
|
|
115146
116794
|
*
|
|
@@ -115149,7 +116797,7 @@ class DownloadArmer {
|
|
|
115149
116797
|
* plain text), then the CAP before the write, then the save path.
|
|
115150
116798
|
*/
|
|
115151
116799
|
decide(item, webContentsId) {
|
|
115152
|
-
const tabId = this.
|
|
116800
|
+
const tabId = this.ownerTab(webContentsId);
|
|
115153
116801
|
let capture = tabId === null ? void 0 : this.captures.get(tabId);
|
|
115154
116802
|
if (!capture || capture.settled) {
|
|
115155
116803
|
capture = (tabId !== null ? this.humanCapture(tabId) : null) ?? void 0;
|
|
@@ -117040,30 +118688,40 @@ function browserStoragePath(browserSession) {
|
|
|
117040
118688
|
}
|
|
117041
118689
|
function installBrowserSessionHandlers(browserSession, hooks = {}) {
|
|
117042
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
|
+
};
|
|
117043
118701
|
browserSession.setPermissionRequestHandler(
|
|
117044
|
-
(
|
|
117045
|
-
|
|
117046
|
-
|
|
117047
|
-
|
|
117048
|
-
|
|
117049
|
-
|
|
117050
|
-
|
|
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
|
+
);
|
|
117051
118711
|
}
|
|
117052
118712
|
);
|
|
117053
118713
|
browserSession.setPermissionCheckHandler(
|
|
117054
|
-
(
|
|
117055
|
-
|
|
117056
|
-
|
|
117057
|
-
|
|
117058
|
-
|
|
117059
|
-
|
|
117060
|
-
|
|
117061
|
-
|
|
117062
|
-
|
|
117063
|
-
|
|
117064
|
-
|
|
117065
|
-
return false;
|
|
117066
|
-
}
|
|
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
|
+
)
|
|
117067
118725
|
);
|
|
117068
118726
|
const onDownload = (event, item, webContents) => {
|
|
117069
118727
|
const webContentsId = webContents?.id ?? -1;
|
|
@@ -118627,8 +120285,8 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118627
120285
|
for (const spawned of registry.unadoptedLinkTabs(tabId))
|
|
118628
120286
|
registry.destroy(spawned.tabId);
|
|
118629
120287
|
addressOverlay?.onTabReleased(tabId);
|
|
118630
|
-
const view =
|
|
118631
|
-
|
|
120288
|
+
const view = views2.get(tabId);
|
|
120289
|
+
views2.delete(tabId);
|
|
118632
120290
|
downloads.forget(tabId);
|
|
118633
120291
|
const release = cdp.detach(webContentsId).finally(() => releaseView(options.window, view));
|
|
118634
120292
|
releases.add(release);
|
|
@@ -118724,6 +120382,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118724
120382
|
log2(
|
|
118725
120383
|
`[browser] refused a popup from a driven page: ${details.url} (${decision.reason})`
|
|
118726
120384
|
);
|
|
120385
|
+
downloads.noteRefusedPopup(tabId, decision.reason);
|
|
118727
120386
|
return { action: "deny" };
|
|
118728
120387
|
}
|
|
118729
120388
|
pendingOpens.push({
|
|
@@ -118821,12 +120480,19 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118821
120480
|
log2(
|
|
118822
120481
|
`[browser] tab ${tabId} opened a popup: ${seen}, route=window, presentation=${routed.presentation})`
|
|
118823
120482
|
);
|
|
118824
|
-
|
|
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);
|
|
118825
120487
|
return;
|
|
118826
120488
|
}
|
|
118827
120489
|
log2(
|
|
118828
120490
|
`[browser] refused a popup from a driven page: ${details.url} (${routed.route === "deny" ? routed.reason : "opener_gone"})`
|
|
118829
120491
|
);
|
|
120492
|
+
downloads.noteRefusedPopup(
|
|
120493
|
+
tabId,
|
|
120494
|
+
routed.route === "deny" ? routed.reason : "opener_gone"
|
|
120495
|
+
);
|
|
118830
120496
|
child.destroy();
|
|
118831
120497
|
});
|
|
118832
120498
|
const onWillNavigate = (event, rawUrl) => {
|
|
@@ -118945,12 +120611,13 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
118945
120611
|
host.clearLoadFailure(tabId);
|
|
118946
120612
|
releaseTab(tabId, contents.id);
|
|
118947
120613
|
});
|
|
118948
|
-
}, wirePopup = function(child, popupChildren, presentation) {
|
|
120614
|
+
}, wirePopup = function(child, popupChildren, presentation, tabId) {
|
|
118949
120615
|
popupChildren.add(child);
|
|
118950
120616
|
child.on("closed", () => popupChildren.delete(child));
|
|
118951
120617
|
const childContents = child.webContents;
|
|
118952
120618
|
childContents.setWindowOpenHandler((childDetails) => {
|
|
118953
120619
|
log2(`[browser] refused a popup from a popup: ${childDetails.url}`);
|
|
120620
|
+
downloads.noteRefusedPopup(tabId, "popup_from_popup");
|
|
118954
120621
|
return { action: "deny" };
|
|
118955
120622
|
});
|
|
118956
120623
|
const onWillNavigate = (event, rawUrl) => {
|
|
@@ -119030,8 +120697,14 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
119030
120697
|
};
|
|
119031
120698
|
const browserSession = resolveBrowserSession();
|
|
119032
120699
|
let registryForDownloads = null;
|
|
120700
|
+
const popupOpener = /* @__PURE__ */ new Map();
|
|
119033
120701
|
const downloads = new DownloadArmer({
|
|
119034
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,
|
|
119035
120708
|
// WHO OWNED THE TAB, recorded on the decision (review round 2, U10). Read from
|
|
119036
120709
|
// the registry at the moment the note is written, because the row may render it
|
|
119037
120710
|
// after the tab is closed — and "· on another tab" about a tab that no longer
|
|
@@ -119060,7 +120733,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
119060
120733
|
{
|
|
119061
120734
|
onPermissionRequested: (details) => {
|
|
119062
120735
|
log2(
|
|
119063
|
-
`[browser] denied
|
|
120736
|
+
`[browser] ${details.granted ? "granted" : "denied"} ${details.permission} (${details.source}) from ${details.origin || "(unknown origin)"}`
|
|
119064
120737
|
);
|
|
119065
120738
|
},
|
|
119066
120739
|
onDownload: (item, webContentsId) => downloads.decide(item, webContentsId),
|
|
@@ -119156,7 +120829,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
119156
120829
|
});
|
|
119157
120830
|
const cdp = new CdpPool({ log: log2 });
|
|
119158
120831
|
rollback.add(() => cdp.close());
|
|
119159
|
-
const
|
|
120832
|
+
const views2 = /* @__PURE__ */ new Map();
|
|
119160
120833
|
const releases = /* @__PURE__ */ new Set();
|
|
119161
120834
|
let stateWriter = null;
|
|
119162
120835
|
let notifyAddressOverlayHealth = () => {
|
|
@@ -119260,7 +120933,7 @@ async function initializeBrowserHost(options, bindings) {
|
|
|
119260
120933
|
const registry = new TabRegistry(
|
|
119261
120934
|
(_createOptions, tabId) => {
|
|
119262
120935
|
const view = buildView(options.window);
|
|
119263
|
-
|
|
120936
|
+
views2.set(tabId, view);
|
|
119264
120937
|
wireView(view, tabId);
|
|
119265
120938
|
return view;
|
|
119266
120939
|
},
|
|
@@ -121438,6 +123111,7 @@ function createLinkPreviewService(options) {
|
|
|
121438
123111
|
const cached2 = await cache?.read(id2, accountFingerprint);
|
|
121439
123112
|
if (cached2 !== void 0 && cached2 !== null)
|
|
121440
123113
|
return { kind: "bytes", data: cached2.bytes, mimeType: cached2.mime };
|
|
123114
|
+
const epoch = cache?.currentEpoch() ?? 0;
|
|
121441
123115
|
let answer;
|
|
121442
123116
|
try {
|
|
121443
123117
|
answer = await transport.media({
|
|
@@ -121449,7 +123123,13 @@ function createLinkPreviewService(options) {
|
|
|
121449
123123
|
return { kind: "error", code: "io", status: 503 };
|
|
121450
123124
|
}
|
|
121451
123125
|
if (answer.kind === "bytes") {
|
|
121452
|
-
await cache?.store(
|
|
123126
|
+
await cache?.store(
|
|
123127
|
+
id2,
|
|
123128
|
+
answer.mimeType,
|
|
123129
|
+
answer.data,
|
|
123130
|
+
accountFingerprint,
|
|
123131
|
+
epoch
|
|
123132
|
+
);
|
|
121453
123133
|
return { kind: "bytes", data: answer.data, mimeType: answer.mimeType };
|
|
121454
123134
|
}
|
|
121455
123135
|
if (answer.status === 404)
|
|
@@ -133095,13 +134775,30 @@ electron.app.whenReady().then(async () => {
|
|
|
133095
134775
|
publishBadge({ unreadCount: 0, pending: false }, void 0, false);
|
|
133096
134776
|
nativeBadge.reset();
|
|
133097
134777
|
},
|
|
133098
|
-
// Fire-and-forget: the sign-out must not wait on a directory sweep
|
|
133099
|
-
//
|
|
133100
|
-
//
|
|
133101
|
-
//
|
|
133102
|
-
//
|
|
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.
|
|
133103
134785
|
principalChanged: () => {
|
|
133104
|
-
void linkPreviewArtifacts.
|
|
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);
|
|
133105
134802
|
}
|
|
133106
134803
|
});
|
|
133107
134804
|
const linkPreviewArtifacts = new LinkPreviewArtifactCache({
|
|
@@ -133111,6 +134808,14 @@ electron.app.whenReady().then(async () => {
|
|
|
133111
134808
|
});
|
|
133112
134809
|
void linkPreviewArtifacts.open().catch(() => {
|
|
133113
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);
|
|
133114
134819
|
refreshAppIconBadge = () => {
|
|
133115
134820
|
if (process.platform === "win32") nativeBadge.invalidateOverlayTarget();
|
|
133116
134821
|
appAttention.projection.refresh();
|