dsh-deeppilot 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -28,508 +28,1356 @@ window.__ModuleLoader__.load({
28
28
  }) : target, mod));
29
29
  //#endregion
30
30
  let react = require("react");
31
- let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
32
- //#region node_modules/qrcode/lib/can-promise.js
33
- var require_can_promise = /* @__PURE__ */ __commonJSMin(((exports, module) => {
34
- module.exports = function() {
35
- return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
36
- };
37
- }));
38
- //#endregion
39
- //#region node_modules/qrcode/lib/core/utils.js
40
- var require_utils$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
41
- let toSJISFunction;
42
- const CODEWORDS_COUNT = [
43
- 0,
44
- 26,
45
- 44,
46
- 70,
47
- 100,
48
- 134,
49
- 172,
50
- 196,
51
- 242,
52
- 292,
53
- 346,
54
- 404,
55
- 466,
56
- 532,
57
- 581,
58
- 655,
59
- 733,
60
- 815,
61
- 901,
62
- 991,
63
- 1085,
64
- 1156,
65
- 1258,
66
- 1364,
67
- 1474,
68
- 1588,
69
- 1706,
70
- 1828,
71
- 1921,
72
- 2051,
73
- 2185,
74
- 2323,
75
- 2465,
76
- 2611,
77
- 2761,
78
- 2876,
79
- 3034,
80
- 3196,
81
- 3362,
82
- 3532,
83
- 3706
84
- ];
85
- /**
86
- * Returns the QR Code size for the specified version
87
- *
88
- * @param {Number} version QR Code version
89
- * @return {Number} size of QR code
90
- */
91
- exports.getSymbolSize = function getSymbolSize(version) {
92
- if (!version) throw new Error("\"version\" cannot be null or undefined");
93
- if (version < 1 || version > 40) throw new Error("\"version\" should be in range from 1 to 40");
94
- return version * 4 + 17;
95
- };
96
- /**
97
- * Returns the total number of codewords used to store data and EC information.
98
- *
99
- * @param {Number} version QR Code version
100
- * @return {Number} Data length in bits
101
- */
102
- exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
103
- return CODEWORDS_COUNT[version];
104
- };
105
- /**
106
- * Encode data with Bose-Chaudhuri-Hocquenghem
107
- *
108
- * @param {Number} data Value to encode
109
- * @return {Number} Encoded value
110
- */
111
- exports.getBCHDigit = function(data) {
112
- let digit = 0;
113
- while (data !== 0) {
114
- digit++;
115
- data >>>= 1;
31
+ //#region src/client/snapshot-store.ts
32
+ function createSnapshotStore(initial) {
33
+ let snapshot = initial;
34
+ const listeners = /* @__PURE__ */ new Set();
35
+ return {
36
+ getSnapshot: () => snapshot,
37
+ subscribe(listener) {
38
+ listeners.add(listener);
39
+ return () => listeners.delete(listener);
40
+ },
41
+ set(value) {
42
+ if (Object.is(value, snapshot)) return;
43
+ snapshot = value;
44
+ for (const listener of listeners) listener();
116
45
  }
117
- return digit;
118
- };
119
- exports.setToSJISFunction = function setToSJISFunction(f) {
120
- if (typeof f !== "function") throw new Error("\"toSJISFunc\" is not a valid function.");
121
- toSJISFunction = f;
122
- };
123
- exports.isKanjiModeEnabled = function() {
124
- return typeof toSJISFunction !== "undefined";
125
- };
126
- exports.toSJIS = function toSJIS(kanji) {
127
- return toSJISFunction(kanji);
128
46
  };
129
- }));
47
+ }
130
48
  //#endregion
131
- //#region node_modules/qrcode/lib/core/error-correction-level.js
132
- var require_error_correction_level = /* @__PURE__ */ __commonJSMin(((exports) => {
133
- exports.L = { bit: 1 };
134
- exports.M = { bit: 0 };
135
- exports.Q = { bit: 3 };
136
- exports.H = { bit: 2 };
137
- function fromString(string) {
138
- if (typeof string !== "string") throw new Error("Param is not a string");
139
- switch (string.toLowerCase()) {
140
- case "l":
141
- case "low": return exports.L;
142
- case "m":
143
- case "medium": return exports.M;
144
- case "q":
145
- case "quartile": return exports.Q;
146
- case "h":
147
- case "high": return exports.H;
148
- default: throw new Error("Unknown EC Level: " + string);
149
- }
49
+ //#region src/device-auth.ts
50
+ const DEVICE_SCOPES = [
51
+ "sessions.read",
52
+ "prompt.send",
53
+ "sessions.manage",
54
+ "interactions.respond",
55
+ "notifications.register"
56
+ ];
57
+ const DEFAULT_DEVICE_SCOPES = DEVICE_SCOPES;
58
+ function normalizeDeviceScopes(value) {
59
+ if (!Array.isArray(value)) return [...DEFAULT_DEVICE_SCOPES];
60
+ const allowed = new Set(DEVICE_SCOPES);
61
+ return [...new Set(value.filter((scope) => typeof scope === "string" && allowed.has(scope)))];
62
+ }
63
+ //#endregion
64
+ //#region src/report-wire.ts
65
+ /** The npm package identity both contribution registrations claim. */
66
+ const REPORT_REMOTE_PACKAGE = "dsh-deeppilot";
67
+ /** Canonical `<namespace>/<method>` endpoint of the report Remote. */
68
+ const REPORT_ENDPOINT = "deeppilot/report";
69
+ const BEGIN_PAIRING_ENDPOINT = "deeppilot/beginPairing";
70
+ const REVOKE_DEVICE_ENDPOINT = "deeppilot/revokeDevice";
71
+ const SET_DEVICE_SCOPES_ENDPOINT = "deeppilot/setDeviceScopes";
72
+ function reject(field) {
73
+ throw new TypeError(`deeppilot/report result: invalid ${field}`);
74
+ }
75
+ function str(source, key, field) {
76
+ const value = source[key];
77
+ if (typeof value !== "string") reject(field);
78
+ return value;
79
+ }
80
+ /**
81
+ * Non-negative integer: counters and timestamps (activeConnections,
82
+ * historyBufferMax, updatedAt, lastSeenTs, protocolVersion, etc.). A bare
83
+ * `typeof number` check accepts 1.5, -1, and 1e20 — all of which then
84
+ * surface verbatim on the settings page and break any sort or arithmetic
85
+ * the UI does.
86
+ */
87
+ function int(source, key, field) {
88
+ const value = source[key];
89
+ if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value < 0) reject(field);
90
+ return value;
91
+ }
92
+ function bool(source, key, field) {
93
+ const value = source[key];
94
+ if (typeof value !== "boolean") reject(field);
95
+ return value;
96
+ }
97
+ function rec(value, field) {
98
+ if (typeof value !== "object" || value === null || Array.isArray(value)) reject(field);
99
+ return value;
100
+ }
101
+ function parseDevice(value) {
102
+ const s = rec(value, "device");
103
+ let apns;
104
+ if (s.apns !== void 0) {
105
+ const a = rec(s.apns, "device.apns");
106
+ const environment = str(a, "environment", "device.apns.environment");
107
+ if (environment !== "development" && environment !== "production") reject("device.apns.environment");
108
+ apns = {
109
+ environment,
110
+ updatedAt: int(a, "updatedAt", "device.apns.updatedAt")
111
+ };
150
112
  }
151
- exports.isValid = function isValid(level) {
152
- return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
113
+ return {
114
+ deviceId: str(s, "deviceId", "device.deviceId"),
115
+ deviceName: str(s, "deviceName", "device.deviceName"),
116
+ appVersion: str(s, "appVersion", "device.appVersion"),
117
+ firstSeenTs: int(s, "firstSeenTs", "device.firstSeenTs"),
118
+ lastSeenTs: int(s, "lastSeenTs", "device.lastSeenTs"),
119
+ fingerprint: str(s, "fingerprint", "device.fingerprint"),
120
+ scopes: normalizeDeviceScopes(s.scopes),
121
+ ...s.revokedAt !== void 0 ? { revokedAt: int(s, "revokedAt", "device.revokedAt") } : {},
122
+ ...apns ? { apns } : {}
153
123
  };
154
- exports.from = function from(value, defaultValue) {
155
- if (exports.isValid(value)) return value;
156
- try {
157
- return fromString(value);
158
- } catch (e) {
159
- return defaultValue;
160
- }
124
+ }
125
+ function parseRemote(value) {
126
+ const s = rec(value, "remote");
127
+ const provider = str(s, "provider", "remote.provider");
128
+ const phase = str(s, "phase", "remote.phase");
129
+ if (provider !== "tailscale-funnel") reject("remote.provider");
130
+ if (![
131
+ "disabled",
132
+ "starting",
133
+ "login_required",
134
+ "online",
135
+ "error",
136
+ "unavailable",
137
+ "stopped"
138
+ ].includes(phase)) reject("remote.phase");
139
+ const publicURL = s.publicURL;
140
+ const authURL = s.authURL;
141
+ const message = s.message;
142
+ if (publicURL !== void 0 && typeof publicURL !== "string") reject("remote.publicURL");
143
+ if (authURL !== void 0 && typeof authURL !== "string") reject("remote.authURL");
144
+ if (message !== void 0 && typeof message !== "string") reject("remote.message");
145
+ return {
146
+ provider,
147
+ phase,
148
+ ...typeof publicURL === "string" ? { publicURL } : {},
149
+ ...typeof authURL === "string" ? { authURL } : {},
150
+ ...typeof message === "string" ? { message } : {},
151
+ updatedAt: int(s, "updatedAt", "remote.updatedAt")
161
152
  };
162
- }));
163
- //#endregion
164
- //#region node_modules/qrcode/lib/core/bit-buffer.js
165
- var require_bit_buffer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
166
- function BitBuffer() {
167
- this.buffer = [];
168
- this.length = 0;
153
+ }
154
+ function parseRelayTestStep(value) {
155
+ const st = rec(value, "step");
156
+ const id = str(st, "id", "step.id");
157
+ if (id !== "health" && id !== "enroll") reject("step.id");
158
+ const latencyMs = st.latencyMs;
159
+ if (latencyMs !== void 0) {
160
+ if (typeof latencyMs !== "number" || !Number.isFinite(latencyMs) || !Number.isInteger(latencyMs) || latencyMs < 0) reject("step.latencyMs");
169
161
  }
170
- BitBuffer.prototype = {
171
- get: function(index) {
172
- const bufIndex = Math.floor(index / 8);
173
- return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
174
- },
175
- put: function(num, length) {
176
- for (let i = 0; i < length; i++) this.putBit((num >>> length - i - 1 & 1) === 1);
177
- },
178
- getLengthInBits: function() {
179
- return this.length;
180
- },
181
- putBit: function(bit) {
182
- const bufIndex = Math.floor(this.length / 8);
183
- if (this.buffer.length <= bufIndex) this.buffer.push(0);
184
- if (bit) this.buffer[bufIndex] |= 128 >>> this.length % 8;
185
- this.length++;
186
- }
162
+ return {
163
+ id,
164
+ ok: bool(st, "ok", "step.ok"),
165
+ message: str(st, "message", "step.message"),
166
+ ...typeof latencyMs === "number" ? { latencyMs } : {}
187
167
  };
188
- module.exports = BitBuffer;
189
- }));
190
- //#endregion
191
- //#region node_modules/qrcode/lib/core/bit-matrix.js
192
- var require_bit_matrix = /* @__PURE__ */ __commonJSMin(((exports, module) => {
193
- /**
194
- * Helper class to handle QR Code symbol modules
195
- *
196
- * @param {Number} size Symbol size
197
- */
198
- function BitMatrix(size) {
199
- if (!size || size < 1) throw new Error("BitMatrix size must be defined and greater than 0");
200
- this.size = size;
201
- this.data = new Uint8Array(size * size);
202
- this.reservedBit = new Uint8Array(size * size);
203
- }
204
- /**
205
- * Set bit value at specified location
206
- * If reserved flag is set, this bit will be ignored during masking process
207
- *
208
- * @param {Number} row
209
- * @param {Number} col
210
- * @param {Boolean} value
211
- * @param {Boolean} reserved
212
- */
213
- BitMatrix.prototype.set = function(row, col, value, reserved) {
214
- const index = row * this.size + col;
215
- this.data[index] = value;
216
- if (reserved) this.reservedBit[index] = true;
217
- };
218
- /**
219
- * Returns bit value at specified location
220
- *
221
- * @param {Number} row
222
- * @param {Number} col
223
- * @return {Boolean}
224
- */
225
- BitMatrix.prototype.get = function(row, col) {
226
- return this.data[row * this.size + col];
168
+ }
169
+ function parseRelayTestResult(value) {
170
+ const s = rec(value, "result");
171
+ const overall = str(s, "overall", "overall");
172
+ if (overall !== "ok" && overall !== "failed") reject("overall");
173
+ const stepsRaw = s.steps;
174
+ if (!Array.isArray(stepsRaw)) reject("steps");
175
+ return {
176
+ url: str(s, "url", "url"),
177
+ overall,
178
+ tokenIssued: bool(s, "tokenIssued", "tokenIssued"),
179
+ steps: stepsRaw.map(parseRelayTestStep)
227
180
  };
228
- /**
229
- * Applies xor operator at specified location
230
- * (used during masking process)
231
- *
232
- * @param {Number} row
233
- * @param {Number} col
234
- * @param {Boolean} value
235
- */
236
- BitMatrix.prototype.xor = function(row, col, value) {
237
- this.data[row * this.size + col] ^= value;
181
+ }
182
+ function parsePushTestResult(value) {
183
+ const s = rec(value, "result");
184
+ const transport = str(s, "transport", "transport");
185
+ if (transport !== "apns" && transport !== "relay" && transport !== "none") reject("transport");
186
+ const overall = str(s, "overall", "overall");
187
+ if (![
188
+ "sent",
189
+ "failed",
190
+ "no-targets",
191
+ "not-configured"
192
+ ].includes(overall)) reject("overall");
193
+ const resultsRaw = s.results;
194
+ if (!Array.isArray(resultsRaw)) reject("results");
195
+ const results = resultsRaw.map((value) => {
196
+ const r = rec(value, "device result");
197
+ const reason = r.reason;
198
+ const tokenFingerprint = r.tokenFingerprint;
199
+ return {
200
+ name: str(r, "name", "result.name"),
201
+ environment: str(r, "environment", "result.environment"),
202
+ outcome: str(r, "outcome", "result.outcome"),
203
+ ...typeof reason === "string" && reason.length > 0 ? { reason } : {},
204
+ ...typeof tokenFingerprint === "string" && /^[0-9a-f]{10}$/.test(tokenFingerprint) ? { tokenFingerprint } : {}
205
+ };
206
+ });
207
+ const message = s.message;
208
+ return {
209
+ transport,
210
+ overall,
211
+ ...typeof message === "string" && message.length > 0 ? { message } : {},
212
+ results
238
213
  };
239
- /**
240
- * Check if bit at specified location is reserved
241
- *
242
- * @param {Number} row
243
- * @param {Number} col
244
- * @return {Boolean}
245
- */
246
- BitMatrix.prototype.isReserved = function(row, col) {
247
- return this.reservedBit[row * this.size + col];
214
+ }
215
+ function parseReport(value) {
216
+ const s = rec(value, "report");
217
+ const devices = s.devices;
218
+ const lanAddresses = s.lanAddresses;
219
+ if (!Array.isArray(devices)) reject("devices");
220
+ if (!Array.isArray(lanAddresses) || lanAddresses.some((value) => typeof value !== "string")) reject("lanAddresses");
221
+ const releaseUrl = s.releaseUrl;
222
+ return {
223
+ protocolVersion: int(s, "protocolVersion", "protocolVersion"),
224
+ serverVersion: str(s, "serverVersion", "serverVersion"),
225
+ pluginVersion: str(s, "pluginVersion", "pluginVersion"),
226
+ ...s.updateAvailable === true ? { updateAvailable: true } : {},
227
+ ...typeof releaseUrl === "string" && releaseUrl.length > 0 ? { releaseUrl } : {},
228
+ enabled: bool(s, "enabled", "enabled"),
229
+ identityPath: str(s, "identityPath", "identityPath"),
230
+ pairingReady: bool(s, "pairingReady", "pairingReady"),
231
+ activeConnections: int(s, "activeConnections", "activeConnections"),
232
+ historyBufferMax: int(s, "historyBufferMax", "historyBufferMax"),
233
+ debug: bool(s, "debug", "debug"),
234
+ lanAddresses,
235
+ remote: parseRemote(s.remote),
236
+ devices: devices.map(parseDevice)
248
237
  };
249
- module.exports = BitMatrix;
250
- }));
251
- //#endregion
252
- //#region node_modules/qrcode/lib/core/alignment-pattern.js
253
- var require_alignment_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
254
- /**
255
- * Alignment pattern are fixed reference pattern in defined positions
256
- * in a matrix symbology, which enables the decode software to re-synchronise
257
- * the coordinate mapping of the image modules in the event of moderate amounts
258
- * of distortion of the image.
259
- *
260
- * Alignment patterns are present only in QR Code symbols of version 2 or larger
261
- * and their number depends on the symbol version.
262
- */
263
- const getSymbolSize = require_utils$1().getSymbolSize;
264
- /**
265
- * Calculate the row/column coordinates of the center module of each alignment pattern
266
- * for the specified QR Code version.
267
- *
268
- * The alignment patterns are positioned symmetrically on either side of the diagonal
269
- * running from the top left corner of the symbol to the bottom right corner.
270
- *
271
- * Since positions are simmetrical only half of the coordinates are returned.
272
- * Each item of the array will represent in turn the x and y coordinate.
273
- * @see {@link getPositions}
274
- *
275
- * @param {Number} version QR Code version
276
- * @return {Array} Array of coordinate
277
- */
278
- exports.getRowColCoords = function getRowColCoords(version) {
279
- if (version === 1) return [];
280
- const posCount = Math.floor(version / 7) + 2;
281
- const size = getSymbolSize(version);
282
- const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
283
- const positions = [size - 7];
284
- for (let i = 1; i < posCount - 1; i++) positions[i] = positions[i - 1] - intervals;
285
- positions.push(6);
286
- return positions.reverse();
238
+ }
239
+ const reportSchema = { parse: parseReport };
240
+ const relayTestSchema = { parse: parseRelayTestResult };
241
+ const pushTestSchema = { parse: parsePushTestResult };
242
+ const pairingGrantSchema = { parse(value) {
243
+ const s = rec(value, "pairing grant");
244
+ const code = str(s, "code", "pairingGrant.code");
245
+ if (code.length < 32) reject("pairingGrant.code");
246
+ return {
247
+ code,
248
+ expiresAt: int(s, "expiresAt", "pairingGrant.expiresAt"),
249
+ audience: str(s, "audience", "pairingGrant.audience")
287
250
  };
288
- /**
289
- * Returns an array containing the positions of each alignment pattern.
290
- * Each array's element represent the center point of the pattern as (x, y) coordinates
291
- *
292
- * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
293
- * and filtering out the items that overlaps with finder pattern
294
- *
295
- * @example
296
- * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
297
- * The alignment patterns, therefore, are to be centered on (row, column)
298
- * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
299
- * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
300
- * and are not therefore used for alignment patterns.
301
- *
302
- * let pos = getPositions(7)
303
- * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
304
- *
305
- * @param {Number} version QR Code version
306
- * @return {Array} Array of coordinates
307
- */
308
- exports.getPositions = function getPositions(version) {
309
- const coords = [];
310
- const pos = exports.getRowColCoords(version);
311
- const posLength = pos.length;
312
- for (let i = 0; i < posLength; i++) for (let j = 0; j < posLength; j++) {
313
- if (i === 0 && j === 0 || i === 0 && j === posLength - 1 || i === posLength - 1 && j === 0) continue;
314
- coords.push([pos[i], pos[j]]);
251
+ } };
252
+ const deviceIdSchema = { parse(value) {
253
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(value)) reject("deviceId");
254
+ return value;
255
+ } };
256
+ const scopesSchema = { parse(value) {
257
+ if (!Array.isArray(value) || value.some((scope) => typeof scope !== "string" || !DEVICE_SCOPES.includes(scope))) reject("scopes");
258
+ return normalizeDeviceScopes(value);
259
+ } };
260
+ const REPORT_REMOTE_CONTRIBUTION = {
261
+ package: REPORT_REMOTE_PACKAGE,
262
+ descriptors: [
263
+ {
264
+ id: `${REPORT_REMOTE_PACKAGE}#${REPORT_ENDPOINT}`,
265
+ service: "deeppilotReport",
266
+ namespace: "deeppilot",
267
+ method: "report",
268
+ invocation: { kind: "direct" },
269
+ parameters: [],
270
+ result: {
271
+ mode: "strict",
272
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#DeepPilotReport`,
273
+ schema: reportSchema
274
+ }
275
+ },
276
+ {
277
+ id: `${REPORT_REMOTE_PACKAGE}#${BEGIN_PAIRING_ENDPOINT}`,
278
+ service: "deeppilotReport",
279
+ namespace: "deeppilot",
280
+ method: "beginPairing",
281
+ invocation: { kind: "direct" },
282
+ parameters: [],
283
+ result: {
284
+ mode: "strict",
285
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#PairingGrantSnapshot`,
286
+ schema: pairingGrantSchema
287
+ }
288
+ },
289
+ {
290
+ id: `${REPORT_REMOTE_PACKAGE}#${REVOKE_DEVICE_ENDPOINT}`,
291
+ service: "deeppilotReport",
292
+ namespace: "deeppilot",
293
+ method: "revokeDevice",
294
+ invocation: { kind: "direct" },
295
+ parameters: [{
296
+ name: "deviceId",
297
+ wire: "deviceId",
298
+ source: "json",
299
+ codec: {
300
+ mode: "strict",
301
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#DeviceId`,
302
+ schema: deviceIdSchema
303
+ }
304
+ }],
305
+ result: {
306
+ mode: "strict",
307
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#Boolean`,
308
+ schema: { parse(value) {
309
+ if (typeof value !== "boolean") reject("boolean");
310
+ return value;
311
+ } }
312
+ }
313
+ },
314
+ {
315
+ id: `${REPORT_REMOTE_PACKAGE}#${SET_DEVICE_SCOPES_ENDPOINT}`,
316
+ service: "deeppilotReport",
317
+ namespace: "deeppilot",
318
+ method: "setDeviceScopes",
319
+ invocation: { kind: "direct" },
320
+ parameters: [{
321
+ name: "deviceId",
322
+ wire: "deviceId",
323
+ source: "json",
324
+ codec: {
325
+ mode: "strict",
326
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#DeviceId`,
327
+ schema: deviceIdSchema
328
+ }
329
+ }, {
330
+ name: "scopes",
331
+ wire: "scopes",
332
+ source: "json",
333
+ codec: {
334
+ mode: "strict",
335
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#DeviceScopes`,
336
+ schema: scopesSchema
337
+ }
338
+ }],
339
+ result: {
340
+ mode: "strict",
341
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#DeviceScopes`,
342
+ schema: scopesSchema
343
+ }
344
+ },
345
+ {
346
+ id: `${REPORT_REMOTE_PACKAGE}#deeppilot/testRelay`,
347
+ service: "deeppilotReport",
348
+ namespace: "deeppilot",
349
+ method: "testRelay",
350
+ invocation: { kind: "direct" },
351
+ parameters: [],
352
+ result: {
353
+ mode: "strict",
354
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#RelayTestResult`,
355
+ schema: relayTestSchema
356
+ }
357
+ },
358
+ {
359
+ id: `${REPORT_REMOTE_PACKAGE}#deeppilot/testPush`,
360
+ service: "deeppilotReport",
361
+ namespace: "deeppilot",
362
+ method: "testPush",
363
+ invocation: { kind: "direct" },
364
+ parameters: [],
365
+ result: {
366
+ mode: "strict",
367
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#PushTestResult`,
368
+ schema: pushTestSchema
369
+ }
315
370
  }
316
- return coords;
317
- };
318
- }));
371
+ ]
372
+ };
319
373
  //#endregion
320
- //#region node_modules/qrcode/lib/core/finder-pattern.js
321
- var require_finder_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
322
- const getSymbolSize = require_utils$1().getSymbolSize;
323
- const FINDER_PATTERN_SIZE = 7;
324
- /**
325
- * Returns an array containing the positions of each finder pattern.
326
- * Each array's element represent the top-left point of the pattern as (x, y) coordinates
327
- *
328
- * @param {Number} version QR Code version
329
- * @return {Array} Array of coordinates
330
- */
331
- exports.getPositions = function getPositions(version) {
332
- const size = getSymbolSize(version);
333
- return [
334
- [0, 0],
335
- [size - FINDER_PATTERN_SIZE, 0],
336
- [0, size - FINDER_PATTERN_SIZE]
337
- ];
374
+ //#region src/client/report-mount.ts
375
+ /** Mount the contribution and resolve the namespace service it installs. */
376
+ async function mountReportRemote(remote, resolveNamespace) {
377
+ const dispose = await remote.$mount(REPORT_REMOTE_CONTRIBUTION);
378
+ const namespace = resolveNamespace();
379
+ if (namespace === void 0) {
380
+ await dispose();
381
+ throw new Error("remote.deeppilot 未注册");
382
+ }
383
+ return {
384
+ namespace,
385
+ dispose
338
386
  };
339
- }));
387
+ }
340
388
  //#endregion
341
- //#region node_modules/qrcode/lib/core/mask-pattern.js
342
- var require_mask_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
343
- /**
344
- * Data mask pattern reference
345
- * @type {Object}
346
- */
347
- exports.Patterns = {
348
- PATTERN000: 0,
349
- PATTERN001: 1,
350
- PATTERN010: 2,
351
- PATTERN011: 3,
352
- PATTERN100: 4,
353
- PATTERN101: 5,
354
- PATTERN110: 6,
355
- PATTERN111: 7
356
- };
357
- /**
358
- * Weighted penalty scores for the undesirable features
359
- * @type {Object}
360
- */
361
- const PenaltyScores = {
362
- N1: 3,
363
- N2: 3,
364
- N3: 40,
365
- N4: 10
389
+ //#region src/client/i18n.ts
390
+ /** Single namespace shared with the host's locale registry, so other
391
+ * host-side modules (if any) can translate the same keys. */
392
+ const DEEPPILOT_LOCALE_NS = "settings.deeppilot";
393
+ /**
394
+ * Single source of truth. Every key here MUST have a translation in every
395
+ * supported locale; the i18n.test.ts "table parity" check enforces that.
396
+ *
397
+ * Shape: `{ locale: { key: value } }` — the same shape `dsh-client-locale`'s
398
+ * `register(namespace, table)` accepts (and the same shape we already used
399
+ * at the bottom of client/index.ts before this module existed).
400
+ *
401
+ * Naming convention: `<section>.<field>` (two dotted segments, lowercase,
402
+ * ASCII-only). Names longer than two segments are reserved for future
403
+ * sub-section splits and intentionally absent today.
404
+ */
405
+ const TABLES = {
406
+ zh: {
407
+ "nav": "DeepPilot",
408
+ "meta.title": "DeepPilot",
409
+ "meta.intro": "把 iPhone 与这台电脑上的 DeepSeek Harness(DSH)连接起来(协议 v2)。",
410
+ "meta.refresh": "刷新",
411
+ "master.title": "DeepPilot 连接",
412
+ "master.loading": "正在读取配置…",
413
+ "master.on": "已开启:接受手机连接。",
414
+ "master.off": "已关闭:不接受手机连接。",
415
+ "remote.title": "远程连接(Tailscale Funnel)",
416
+ "remote.on": "已配置:内嵌 Funnel 会自动启动并同步状态。",
417
+ "remote.off": "关闭:仅保留局域网连接。",
418
+ "remote.openAuth": "打开授权页面",
419
+ "remote.advancedSettings": "高级设置",
420
+ "remote.limitTitle": "每个公网来源的连接上限",
421
+ "remote.limitDescription": "默认 8,范围 1–16。应用后 Funnel 会重启,已有远程连接将短暂重连。",
422
+ "remote.limitApply": "应用",
423
+ "remote.limitApplied": "连接上限已保存,远程入口正在重新加载。",
424
+ "remote.limitInvalid": "请输入 1–16 之间的整数。",
425
+ "remote.limitFailed": "连接上限保存失败:",
426
+ "phase.disabled": "未启用",
427
+ "phase.starting": "正在启动",
428
+ "phase.login_required": "等待 Tailscale 授权",
429
+ "phase.online": "远程连接已就绪",
430
+ "phase.error": "远程连接失败",
431
+ "phase.unavailable": "远程 helper 不可用",
432
+ "phase.stopped": "已停止",
433
+ "phase.unknown": "状态未知",
434
+ "panel.activeConnections": "当前连接",
435
+ "panel.identity": "设备身份认证",
436
+ "panel.identityReady": "v2 已就绪",
437
+ "panel.identityNotReady": "不可用",
438
+ "panel.token": "配对 Token",
439
+ "panel.tokenReady": "已就绪",
440
+ "panel.tokenNotReady": "未生成",
441
+ "panel.tokenMasked": "••••••••••••",
442
+ "panel.tokenAction.show": "显示",
443
+ "panel.tokenAction.hide": "隐藏",
444
+ "panel.tokenAction.copy": "复制",
445
+ "panel.tokenAction.rotate": "更换",
446
+ "panel.tokenAction.rotateConfirm": "确认更换?",
447
+ "panel.tokenAction.showing": "读取中…",
448
+ "panel.tokenAction.rotating": "更换中…",
449
+ "panel.tokenAutoHidden": "Token 已自动隐藏",
450
+ "panel.tokenCopied": "已复制到剪贴板",
451
+ "panel.tokenCopyFailed": "复制失败:",
452
+ "panel.tokenRevealFailed": "Token 读取失败:",
453
+ "panel.tokenRotateWarning": "更换会使当前 Token 立即失效、断开所有手机连接;5 秒内再次点击确认。",
454
+ "panel.tokenRotated": "新 Token 已生效,旧 Token 已失效;请重新配对所有设备。",
455
+ "panel.tokenRotateFailed": "更换失败:",
456
+ "pair.qrPanelTitle": "扫码添加当前手机",
457
+ "pair.kind.public": "公网",
458
+ "pair.kind.lan": "内网",
459
+ "pair.noAddress": "没有可用地址",
460
+ "pair.noAddressHelp": "未发现可供手机访问的局域网地址,请确认这台电脑已连接局域网。",
461
+ "pair.qrAlt": "DeepPilot 配对二维码",
462
+ "pair.qrShow": "显示二维码",
463
+ "pair.qrHide": "隐藏二维码",
464
+ "pair.qrGenerating": "生成中…",
465
+ "pair.qrAutoHidden": "配对二维码已自动隐藏",
466
+ "pair.qrFailed": "二维码生成失败:",
467
+ "pair.codeLabel": "配对码(模拟器可手动输入)",
468
+ "pair.codeCopyDone": "配对码已复制",
469
+ "pair.codeCopyFailed": "配对码复制失败:",
470
+ "pair.publicCopyDone": "公网地址已复制",
471
+ "pair.publicCopyFailed": "复制失败:",
472
+ "pair.qrHint": "二维码包含{kind}地址和一次性配对码;配对码 5 分钟后失效,二维码将在 60 秒后自动隐藏。",
473
+ "advanced.summary": "高级信息",
474
+ "advanced.protocolVersion": "协议版本",
475
+ "advanced.serverVersion": "服务器版本",
476
+ "advanced.tokenPath": "Token 路径",
477
+ "advanced.identityPath": "设备注册表路径",
478
+ "advanced.bufferMax": "重放缓冲上限",
479
+ "advanced.frames": " 帧",
480
+ "push.relayTitle": "离线推送中继",
481
+ "push.testRelay": "测试访问与注册",
482
+ "push.testPush": "发送测试通知",
483
+ "push.relayTesting": "测试中…",
484
+ "push.pushSending": "发送中…",
485
+ "push.relayDefault": "验证 Mac 到推送中继的连通性与自动注册是否正常。",
486
+ "push.pushDefault": "向所有已注册设备强制发送一条真实推送(不受在线状态与分类开关影响)。",
487
+ "push.relayOk": "通过",
488
+ "push.relayBad": "存在问题",
489
+ "push.relayUrlEmpty": "(未启用)",
490
+ "push.pushSent": "已送达",
491
+ "push.pushFailed": "发送失败",
492
+ "push.pushNoTargets": "无已注册设备",
493
+ "push.pushNotEnabled": "推送未启用",
494
+ "push.relayStep.health": "服务可达",
495
+ "push.relayStep.enroll": "自动注册",
496
+ "push.prefix.ok": "✓ ",
497
+ "push.prefix.fail": "✗ ",
498
+ "devices.title": "设备",
499
+ "devices.col.name": "设备",
500
+ "devices.col.appVersion": "App 版本",
501
+ "devices.col.push": "离线推送",
502
+ "devices.col.lastSeen": "最近在线",
503
+ "devices.col.fingerprint": "密钥指纹",
504
+ "devices.col.actions": "操作",
505
+ "devices.revoke": "删除",
506
+ "devices.revokeConfirm": "确定删除设备“{name}”吗?该设备会立即断开,再次使用时需要重新配对。",
507
+ "devices.revoked": "设备已删除",
508
+ "devices.revokeFailed": "设备删除失败:",
509
+ "devices.pushRegistered": "已注册(",
510
+ "devices.pushNotRegistered": "未注册",
511
+ "devices.pushEnvProduction": "生产",
512
+ "devices.pushEnvDevelopment": "开发",
513
+ "devices.empty": "还没有 v2 设备。请在 iPhone 上扫描一次性配对二维码。",
514
+ "help.remoteTitle": "远程连接帮助",
515
+ "help.recommended": "推荐设置流程",
516
+ "help.step1": "先打开\"DeepPilot 连接\",再打开\"远程连接(Tailscale Funnel)\"。",
517
+ "help.step2": "状态变为\"等待 Tailscale 授权\"后,点击\"打开授权页面\"。",
518
+ "help.step3": "使用有权管理此 Tailnet 的账号登录,并按授权页提示启用 Funnel。通常需要 Owner、Admin 或 Network admin 权限。",
519
+ "help.step4": "返回此页面并点击\"刷新\"。远程连接标题旁出现绿点后,即可扫描下方二维码添加手机。",
520
+ "help.funnelHint": "插件已内嵌 Tailscale 网络组件,这台电脑和手机都不需要另外安装 Tailscale App;但首次启用仍需由 Tailnet 管理员授权。",
521
+ "help.httpsTitle": "授权页未自动完成时:开启 HTTPS",
522
+ "help.httpsStep1": "打开 Tailscale 管理后台的 Network → DNS。",
523
+ "help.httpsStep2": "确认 MagicDNS 已开启。",
524
+ "help.httpsStep3": "在 HTTPS Certificates 中点击 Enable HTTPS。",
525
+ "help.httpsHint": "启用 HTTPS 后,设备的完整域名会写入公开的证书透明度日志。如果设备名包含敏感信息,请先在 Tailscale 中重命名设备。",
526
+ "help.allowTitle": "授权页未自动完成时:允许 Funnel",
527
+ "help.allowBody": "打开 Access controls → Definitions,选择 Node attributes。在现有 nodeAttrs 数组中追加下面这一项;不要覆盖已有访问规则,也不要创建第二个 nodeAttrs 顶层字段。",
528
+ "help.allowHint": "保存策略后回到本页刷新。公共 DNS 和权限变更可能需要几分钟生效。",
529
+ "help.faqTitle": "常见问题",
530
+ "help.faq1": "提示\"HTTPS must be enabled\":完成上面的 HTTPS Certificates 设置。",
531
+ "help.faq2": "\"Funnel not available\":确认 nodeAttrs 已保存,并且当前节点属于规则的 target。",
532
+ "help.faq3": "已有公网地址但手机超时:等待几分钟后重试,同时确认这台电脑未休眠、DSH 正在运行,再重新扫描最新二维码。",
533
+ "help.faq4": "没有公网地址:检查 Tailscale 授权是否完成,然后点击\"刷新\"或重启 DSH。",
534
+ "help.securityTitle": "安全说明",
535
+ "help.security1": "Funnel 公网地址可从互联网访问,但连接必须使用已配对设备的 P-256 私钥签名;不要分享仍在有效期内的配对二维码。",
536
+ "help.security2": "丢失设备时可在设备列表中单独删除;该设备会立即断开,不影响其他手机。",
537
+ "help.security3": "插件只通过 Funnel 转发 /phone、/phone/pair 和 /phone/health,不会新增 3098 端口。",
538
+ "help.security4": "局域网连接沿用 DSH 的 3080 端口;仅在可信网络中使用,不建议直接把 3080 暴露到公网。",
539
+ "help.security5": "关闭远程连接开关会停止 Funnel,但不会影响可用的局域网连接。",
540
+ "help.funnelDocs": "Tailscale Funnel 官方文档",
541
+ "help.docsPrefix": "更多信息:",
542
+ "diag.remoteUnavailable": "remote 服务不可用",
543
+ "diag.remoteUnmounted": "report remote 未挂载",
544
+ "diag.mountFailed": "报告远程未挂载(remote mount 失败)— 请确认宿主包含 typert 组合",
545
+ "diag.mountFailedShort": "remote mount 失败: ",
546
+ "diag.callFailed": "report remote 调用失败",
547
+ "diag.settingsUnavailable": "设置命名空间不可用(settingsScope 未提供)",
548
+ "diag.missingReportHook": "useDeepPilotReport hook 缺失",
549
+ "diag.missingEnabledHook": "useDeepPilotEnabled hook 缺失",
550
+ "diag.missingRemoteEnabledHook": "useDeepPilotRemoteEnabled hook 缺失",
551
+ "diag.missingRemoteLimitHook": "useDeepPilotRemoteConnectionLimit hook 缺失",
552
+ "diag.missingRefresh": "refresh 回调缺失",
553
+ "diag.missingReveal": "beginPairing 回调缺失",
554
+ "diag.missingRotate": "revokeDevice 回调缺失",
555
+ "diag.missingTestRelay": "testRelay 回调缺失",
556
+ "diag.missingTestPush": "testPush 回调缺失",
557
+ "diag.missingSetEnabled": "setDeepPilotEnabled 回调缺失",
558
+ "diag.missingSetRemote": "setDeepPilotRemoteEnabled 回调缺失",
559
+ "diag.missingSetRemoteLimit": "setDeepPilotRemoteConnectionLimit 回调缺失",
560
+ "diag.renderError": "渲染异常: ",
561
+ "diag.prefix": "diag: ",
562
+ "clipboard.rejected": "浏览器拒绝了剪贴板写入",
563
+ "push.staleHost": "宿主插件版本较旧,不支持推送测试",
564
+ "push.staleHostRelay": "宿主插件版本较旧,不支持中继测试",
565
+ "push.staleHostPush": "宿主插件版本较旧,不支持推送测试 — 请更新 dsh-deeppilot",
566
+ "push.staleHostPushRelay": "宿主插件版本较旧,不支持中继测试 — 请更新 dsh-deeppilot",
567
+ "update.badge": "有新版本"
568
+ },
569
+ en: {
570
+ "nav": "DeepPilot",
571
+ "meta.title": "DeepPilot",
572
+ "meta.intro": "Connect your iPhone to DeepSeek Harness (DSH) on this Mac (protocol v2).",
573
+ "meta.refresh": "Refresh",
574
+ "master.title": "DeepPilot connection",
575
+ "master.loading": "Loading settings…",
576
+ "master.on": "On: accepting phone connections.",
577
+ "master.off": "Off: not accepting phone connections.",
578
+ "remote.title": "Remote connection (Tailscale Funnel)",
579
+ "remote.on": "Configured: the embedded Funnel will start and sync state automatically.",
580
+ "remote.off": "Off: LAN connections only.",
581
+ "remote.openAuth": "Open authorization page",
582
+ "remote.advancedSettings": "Advanced settings",
583
+ "remote.limitTitle": "Connections per public source",
584
+ "remote.limitDescription": "Default 8; range 1–16. Applying restarts Funnel and briefly reconnects existing remote clients.",
585
+ "remote.limitApply": "Apply",
586
+ "remote.limitApplied": "Connection limit saved; the remote endpoint is reloading.",
587
+ "remote.limitInvalid": "Enter an integer from 1 to 16.",
588
+ "remote.limitFailed": "Failed to save connection limit: ",
589
+ "phase.disabled": "Disabled",
590
+ "phase.starting": "Starting",
591
+ "phase.login_required": "Awaiting Tailscale authorization",
592
+ "phase.online": "Remote connection ready",
593
+ "phase.error": "Remote connection failed",
594
+ "phase.unavailable": "Remote helper unavailable",
595
+ "phase.stopped": "Stopped",
596
+ "phase.unknown": "Status unknown",
597
+ "panel.activeConnections": "Active connections",
598
+ "panel.identity": "Device authentication",
599
+ "panel.identityReady": "v2 ready",
600
+ "panel.identityNotReady": "Unavailable",
601
+ "panel.token": "Pairing token",
602
+ "panel.tokenReady": "Ready",
603
+ "panel.tokenNotReady": "Not generated",
604
+ "panel.tokenMasked": "••••••••••••",
605
+ "panel.tokenAction.show": "Show",
606
+ "panel.tokenAction.hide": "Hide",
607
+ "panel.tokenAction.copy": "Copy",
608
+ "panel.tokenAction.rotate": "Rotate",
609
+ "panel.tokenAction.rotateConfirm": "Confirm rotate?",
610
+ "panel.tokenAction.showing": "Reading…",
611
+ "panel.tokenAction.rotating": "Rotating…",
612
+ "panel.tokenAutoHidden": "Token auto-hidden",
613
+ "panel.tokenCopied": "Copied to clipboard",
614
+ "panel.tokenCopyFailed": "Copy failed: ",
615
+ "panel.tokenRevealFailed": "Token reveal failed: ",
616
+ "panel.tokenRotateWarning": "Rotation invalidates the current token immediately and drops every paired phone. Click again within 5s to confirm.",
617
+ "panel.tokenRotated": "New token active, old token invalidated. Please re-pair every device.",
618
+ "panel.tokenRotateFailed": "Rotation failed: ",
619
+ "pair.qrPanelTitle": "Scan to pair this phone",
620
+ "pair.kind.public": "Public",
621
+ "pair.kind.lan": "LAN",
622
+ "pair.noAddress": "No address available",
623
+ "pair.noAddressHelp": "No LAN address reachable from a phone. Make sure this Mac is on the local network.",
624
+ "pair.qrAlt": "DeepPilot pairing QR code",
625
+ "pair.qrShow": "Show QR code",
626
+ "pair.qrHide": "Hide QR code",
627
+ "pair.qrGenerating": "Generating…",
628
+ "pair.qrAutoHidden": "Pairing QR auto-hidden",
629
+ "pair.qrFailed": "QR generation failed: ",
630
+ "pair.codeLabel": "Pairing code (enter manually in Simulator)",
631
+ "pair.codeCopyDone": "Pairing code copied",
632
+ "pair.codeCopyFailed": "Failed to copy pairing code: ",
633
+ "pair.publicCopyDone": "Public URL copied",
634
+ "pair.publicCopyFailed": "Copy failed: ",
635
+ "pair.qrHint": "The QR contains a {kind} address and a single-use pairing code. The code expires after 5 minutes; the QR auto-hides after 60 seconds.",
636
+ "advanced.summary": "Advanced info",
637
+ "advanced.protocolVersion": "Protocol version",
638
+ "advanced.serverVersion": "Server version",
639
+ "advanced.tokenPath": "Token path",
640
+ "advanced.identityPath": "Device registry path",
641
+ "advanced.bufferMax": "Replay buffer cap",
642
+ "advanced.frames": " frames",
643
+ "push.relayTitle": "Offline push relay",
644
+ "push.testRelay": "Test reach & enroll",
645
+ "push.testPush": "Send test notification",
646
+ "push.relayTesting": "Testing…",
647
+ "push.pushSending": "Sending…",
648
+ "push.relayDefault": "Verify Mac → push relay connectivity and zero-touch enrollment.",
649
+ "push.pushDefault": "Force one real push to every registered device (ignores online state and category switches).",
650
+ "push.relayOk": "OK",
651
+ "push.relayBad": "Issues found",
652
+ "push.relayUrlEmpty": "(disabled)",
653
+ "push.pushSent": "Delivered",
654
+ "push.pushFailed": "Send failed",
655
+ "push.pushNoTargets": "No registered devices",
656
+ "push.pushNotEnabled": "Push not enabled",
657
+ "push.relayStep.health": "Service reachable",
658
+ "push.relayStep.enroll": "Auto enrollment",
659
+ "push.prefix.ok": "✓ ",
660
+ "push.prefix.fail": "✗ ",
661
+ "devices.title": "Devices",
662
+ "devices.col.name": "Device",
663
+ "devices.col.appVersion": "App version",
664
+ "devices.col.push": "Push",
665
+ "devices.col.lastSeen": "Last seen",
666
+ "devices.col.fingerprint": "Key fingerprint",
667
+ "devices.col.actions": "Actions",
668
+ "devices.revoke": "Delete",
669
+ "devices.revokeConfirm": "Delete “{name}”? It will disconnect immediately and must pair again before reconnecting.",
670
+ "devices.revoked": "Device deleted",
671
+ "devices.revokeFailed": "Failed to delete device: ",
672
+ "devices.pushRegistered": "Registered (",
673
+ "devices.pushNotRegistered": "Not registered",
674
+ "devices.pushEnvProduction": "Production",
675
+ "devices.pushEnvDevelopment": "Development",
676
+ "devices.empty": "No v2 devices yet. Scan a single-use pairing QR code in DeepPilot on iPhone.",
677
+ "help.remoteTitle": "Remote connection help",
678
+ "help.recommended": "Recommended setup",
679
+ "help.step1": "Turn on \"DeepPilot connection\" first, then \"Remote connection (Tailscale Funnel)\".",
680
+ "help.step2": "When the status shows \"Awaiting Tailscale authorization\", click \"Open authorization page\".",
681
+ "help.step3": "Sign in with an account that can manage this Tailnet and follow the on-page prompts to enable Funnel. Owner / Admin / Network admin is usually required.",
682
+ "help.step4": "Come back to this page and click \"Refresh\". When a green dot appears next to the remote title, scan the QR code below to add your phone.",
683
+ "help.funnelHint": "The plugin bundles the Tailscale networking stack, so neither this Mac nor the phone needs the Tailscale app — but a Tailnet administrator must approve first-time use.",
684
+ "help.httpsTitle": "If authorization does not complete: enable HTTPS",
685
+ "help.httpsStep1": "Open the Tailscale admin console → Network → DNS.",
686
+ "help.httpsStep2": "Confirm MagicDNS is enabled.",
687
+ "help.httpsStep3": "In HTTPS Certificates click Enable HTTPS.",
688
+ "help.httpsHint": "Enabling HTTPS publishes the device hostname to public certificate transparency logs. Rename the device in Tailscale first if its name is sensitive.",
689
+ "help.allowTitle": "If authorization does not complete: allow Funnel",
690
+ "help.allowBody": "Open Access controls → Definitions, select Node attributes. Append the snippet below to your existing nodeAttrs array; do not overwrite other access rules and do not add a second top-level nodeAttrs field.",
691
+ "help.allowHint": "Save the policy and refresh this page. Public DNS and policy changes can take a few minutes to propagate.",
692
+ "help.faqTitle": "Frequently asked questions",
693
+ "help.faq1": "\"HTTPS must be enabled\" — finish the HTTPS Certificates steps above.",
694
+ "help.faq2": "\"Funnel not available\" — make sure the nodeAttrs snippet is saved and this node is in the rule's target.",
695
+ "help.faq3": "Public URL exists but the phone times out: wait a few minutes, confirm the Mac is awake and DSH is running, then re-scan the latest QR code.",
696
+ "help.faq4": "No public URL: check that Tailscale authorization completed, then click \"Refresh\" or restart DSH.",
697
+ "help.securityTitle": "Security notes",
698
+ "help.security1": "A Funnel URL is public, but every connection requires a signature from a paired device P-256 private key. Do not share a pairing QR while it is valid.",
699
+ "help.security2": "If a device is lost, delete only that device from the list. It disconnects immediately; other phones stay paired.",
700
+ "help.security3": "The plugin only forwards /phone, /phone/pair, and /phone/health through Funnel; no new port 3098 is opened.",
701
+ "help.security4": "LAN connections reuse DSH's existing 3080 port. Use them only on trusted networks; do not expose 3080 directly to the public Internet.",
702
+ "help.security5": "Disabling the remote switch stops Funnel but does not affect any LAN connection you already have.",
703
+ "help.funnelDocs": "Tailscale Funnel docs",
704
+ "help.docsPrefix": "More info: ",
705
+ "diag.remoteUnavailable": "remote service unavailable",
706
+ "diag.remoteUnmounted": "report remote not mounted",
707
+ "diag.mountFailed": "Report remote not mounted (mount failed) — confirm the host includes the typert composition",
708
+ "diag.mountFailedShort": "remote mount failed: ",
709
+ "diag.callFailed": "report remote call failed",
710
+ "diag.settingsUnavailable": "Settings namespace unavailable (settingsScope not provided)",
711
+ "diag.missingReportHook": "useDeepPilotReport hook missing",
712
+ "diag.missingEnabledHook": "useDeepPilotEnabled hook missing",
713
+ "diag.missingRemoteEnabledHook": "useDeepPilotRemoteEnabled hook missing",
714
+ "diag.missingRemoteLimitHook": "useDeepPilotRemoteConnectionLimit hook missing",
715
+ "diag.missingRefresh": "refresh callback missing",
716
+ "diag.missingReveal": "beginPairing callback missing",
717
+ "diag.missingRotate": "revokeDevice callback missing",
718
+ "diag.missingTestRelay": "testRelay callback missing",
719
+ "diag.missingTestPush": "testPush callback missing",
720
+ "diag.missingSetEnabled": "setDeepPilotEnabled callback missing",
721
+ "diag.missingSetRemote": "setDeepPilotRemoteEnabled callback missing",
722
+ "diag.missingSetRemoteLimit": "setDeepPilotRemoteConnectionLimit callback missing",
723
+ "diag.renderError": "Render error: ",
724
+ "diag.prefix": "diag: ",
725
+ "clipboard.rejected": "Clipboard write rejected by the browser",
726
+ "push.staleHost": "Host plugin is too old for push testing",
727
+ "push.staleHostRelay": "Host plugin is too old for relay testing",
728
+ "push.staleHostPush": "Host plugin is too old for push testing — please update dsh-deeppilot",
729
+ "push.staleHostPushRelay": "Host plugin is too old for relay testing — please update dsh-deeppilot",
730
+ "update.badge": "New version available"
731
+ }
732
+ };
733
+ Object.keys(TABLES.zh);
734
+ /** Substitute every `{name}` in `template` with `String(vars[name])`. The
735
+ * host bind() does not interpolate, so we always run the result through
736
+ * here for any key the caller asked to format. Numeric / object placeholders
737
+ * are coerced to strings; missing placeholders are left intact so a
738
+ * missing key is visible in the rendered output. */
739
+ function interpolate(template, vars) {
740
+ if (!vars) return template;
741
+ return template.replace(/\{(\w+)\}/g, (match, name) => {
742
+ const value = vars[name];
743
+ if (value === void 0) return match;
744
+ return String(value);
745
+ });
746
+ }
747
+ /** Detect the active language from the locale snapshot or browser hints. */
748
+ function detectLocale(ctx) {
749
+ try {
750
+ const active = ctx.locale?.getSnapshot?.().active;
751
+ if (active === "zh" || active?.toLowerCase().startsWith("zh-")) return "zh";
752
+ if (active === "en" || active?.toLowerCase().startsWith("en-")) return "en";
753
+ } catch {}
754
+ if ((typeof document === "undefined" ? "" : document.documentElement.lang).toLowerCase().startsWith("zh")) return "zh";
755
+ if ((typeof navigator === "undefined" ? [] : navigator.languages).some((language) => language.toLowerCase().startsWith("zh"))) return "zh";
756
+ return "en";
757
+ }
758
+ /**
759
+ * Invoke the translation function supplied to a locale-aware slot. Keeping
760
+ * this adapter distinct from `t(ctx, ...)` prevents a translator function
761
+ * from being mistaken for a Cordis Context, which previously forced every
762
+ * settings-page lookup through the English no-host fallback.
763
+ */
764
+ function translateWith(translator, key, vars) {
765
+ if (typeof translator !== "function") return key;
766
+ return translator(key, vars);
767
+ }
768
+ /** Translation function. Callers always go through this — never the
769
+ * underlying locale face — so the substitution / fallback path stays in
770
+ * one place. `ctx` may be omitted (offline / SSR / tests) and we resolve
771
+ * to en automatically. */
772
+ function t(ctx, key, vars) {
773
+ const anyCtx = ctx;
774
+ let template;
775
+ if (anyCtx?.locale) try {
776
+ template = anyCtx.locale.bind(DEEPPILOT_LOCALE_NS)(key);
777
+ } catch {
778
+ template = void 0;
779
+ }
780
+ if (template === void 0 || template === key) {
781
+ const locale = detectLocale(anyCtx ?? { locale: void 0 });
782
+ template = TABLES[locale][key] ?? TABLES.zh[key] ?? TABLES.en[key] ?? key;
783
+ }
784
+ return interpolate(template, vars);
785
+ }
786
+ /** Register both dictionaries and return the host-owned disposer. */
787
+ function registerLocale(ctx) {
788
+ const anyCtx = ctx;
789
+ if (anyCtx.locale === void 0) return () => {};
790
+ return anyCtx.locale.register(DEEPPILOT_LOCALE_NS, {
791
+ zh: TABLES.zh,
792
+ en: TABLES.en
793
+ });
794
+ }
795
+ //#endregion
796
+ //#region src/client/styles.ts
797
+ const CSS = [
798
+ ".pbb-section{max-width:720px;color:var(--dsw-alias-label-primary);display:flex;flex-direction:column;gap:12px}",
799
+ ".pbb-title{margin:0;font-size:18px;font-weight:600}",
800
+ ".pbb-intro{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5;margin:0}",
801
+ ".pbb-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;padding:4px 16px}",
802
+ ".pbb-field{display:flex;flex-direction:column;gap:6px;padding:12px 0}",
803
+ ".pbb-field+.pbb-field{border-top:1px solid var(--dsw-alias-border-l2)}",
804
+ ".pbb-row{display:flex;align-items:center;gap:8px}",
805
+ ".pbb-label{flex:1;font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary);min-width:0}",
806
+ ".pbb-value{font-size:13px;color:var(--dsw-alias-label-secondary);word-break:break-all;text-align:right}",
807
+ ".pbb-badge{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;white-space:nowrap}",
808
+ ".pbb-ok{color:var(--dsw-alias-state-success-primary,var(--dsw-alias-label-secondary));font-weight:500}",
809
+ ".pbb-bad{color:var(--dsw-alias-label-error);font-weight:500}",
810
+ ".pbb-table{width:100%;border-collapse:collapse;font-size:12px}",
811
+ ".pbb-table th{color:var(--dsw-alias-label-tertiary);text-align:left;font-weight:500;padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l2)}",
812
+ ".pbb-table td{padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary)}",
813
+ ".pbb-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:0}",
814
+ ".pbb-diag{font-size:11px;color:var(--dsw-alias-label-tertiary);margin:0;line-height:1.5}",
815
+ ".pbb-diagBad{color:var(--dsw-alias-label-error)}",
816
+ ".pbb-refresh{font:inherit;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:none;border:none;padding:0}",
817
+ ".pbb-refresh:hover:not(:disabled){color:var(--dsw-alias-label-primary)}",
818
+ ".pbb-refresh:disabled{cursor:default;opacity:.5}",
819
+ ".pbb-tokenRow{flex-wrap:wrap}",
820
+ ".pbb-token{max-width:100%;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-secondary);word-break:break-all}",
821
+ ".pbb-tokenActions{display:flex;align-items:center;gap:8px}",
822
+ ".pbb-action{font:inherit;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:none;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;padding:3px 8px}",
823
+ ".pbb-action:hover:not(:disabled){color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-module-platform)}",
824
+ ".pbb-action:disabled{cursor:default;opacity:.5}",
825
+ ".pbb-actionDanger:not(:disabled){color:#fff;background:var(--dsw-alias-label-error);border-color:var(--dsw-alias-label-error)}",
826
+ ".pbb-qrPanel{display:flex;flex-direction:column;align-items:center;gap:9px;padding:12px 0 4px}",
827
+ ".pbb-qrImage{width:240px;height:240px;max-width:100%;background:#fff;border-radius:10px;padding:8px;box-sizing:border-box}",
828
+ ".pbb-pairCodeBlock{width:min(100%,420px);display:flex;flex-direction:column;gap:5px}",
829
+ ".pbb-pairCodeLabel{font-size:11px;color:var(--dsw-alias-label-tertiary);text-align:center}",
830
+ ".pbb-pairCodeRow{display:flex;align-items:center;justify-content:center;gap:8px;flex-wrap:wrap}",
831
+ ".pbb-pairCode{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:15px;line-height:1.4;letter-spacing:.04em;color:var(--dsw-alias-label-primary);word-break:break-all;text-align:center;user-select:all}",
832
+ ".pbb-qrHint{max-width:420px;text-align:center;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary);margin:0}",
833
+ ".pbb-switchRow{padding:12px 0;display:flex;align-items:center;gap:12px}",
834
+ ".pbb-switchRow+.pbb-field{border-top:1px solid var(--dsw-alias-border-l2)}",
835
+ ".pbb-switchText{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}",
836
+ ".pbb-switchTitle{font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary)}",
837
+ ".pbb-dotRow{display:flex;align-items:center;gap:7px}",
838
+ ".pbb-dot{width:8px;height:8px;border-radius:50%;background:var(--dsw-alias-label-tertiary);flex:none}",
839
+ ".pbb-dotOk{background:var(--dsw-alias-state-success-primary,#22a06b)}",
840
+ ".pbb-dotWarn{background:var(--dsw-alias-state-warning-primary,#e2b203)}",
841
+ ".pbb-dotBad{background:var(--dsw-alias-label-error)}",
842
+ ".pbb-rowAction{display:flex;gap:8px;margin-top:4px}",
843
+ ".pbb-switchDesc{font-size:11px;color:var(--dsw-alias-label-tertiary);line-height:1.4}",
844
+ ".pbb-switch{appearance:none;-webkit-appearance:none;width:38px;height:22px;border-radius:999px;background:var(--dsw-alias-bg-module-platform);border:1px solid var(--dsw-alias-border-l2);position:relative;cursor:pointer;padding:0;flex:none;transition:background .15s ease}",
845
+ ".pbb-switch::after{content:\"\";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-secondary);transition:transform .15s ease,background .15s ease}",
846
+ ".pbb-switchOn{background:var(--dsw-alias-state-success-primary,var(--dsw-alias-label-secondary))}",
847
+ ".pbb-switchOn::after{transform:translateX(16px);background:#fff}",
848
+ ".pbb-switch:disabled{opacity:.5;cursor:default}",
849
+ ".pbb-limitRow{border-top:1px solid var(--dsw-alias-border-l2);padding:12px 0;display:flex;align-items:center;gap:12px}",
850
+ ".pbb-limitNested{border-top:0;padding:0}",
851
+ ".pbb-limitControl{display:flex;align-items:center;gap:8px;flex:none}",
852
+ ".pbb-numberInput{width:72px;box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;padding:5px 8px}",
853
+ ".pbb-numberInput:focus{outline:2px solid var(--dsw-alias-state-success-primary,#22a06b);outline-offset:1px}",
854
+ ".pbb-numberInput:disabled{opacity:.5}",
855
+ ".pbb-help{border-top:1px solid var(--dsw-alias-border-l2);padding:12px 0}",
856
+ ".pbb-help summary{cursor:pointer;color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;user-select:none}",
857
+ ".pbb-help summary:hover{color:var(--dsw-alias-label-secondary)}",
858
+ ".pbb-helpBody{display:flex;flex-direction:column;gap:14px;padding:12px 0 2px}",
859
+ ".pbb-helpSection{display:flex;flex-direction:column;gap:6px}",
860
+ ".pbb-helpHeading{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}",
861
+ ".pbb-helpList{margin:0;padding-left:20px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.6}",
862
+ ".pbb-helpList li+li{margin-top:4px}",
863
+ ".pbb-helpText{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.6}",
864
+ ".pbb-helpCode{display:block;margin:2px 0 0;padding:10px;overflow:auto;white-space:pre-wrap;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-primary);font:11px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}",
865
+ ".pbb-helpLink{color:var(--dsw-alias-label-secondary);text-decoration:underline;text-underline-offset:2px}",
866
+ ".pbb-versionFooter{display:flex;justify-content:center;align-items:center;gap:8px;font-size:11px;color:var(--dsw-alias-label-tertiary);padding:8px 0 4px;line-height:1.4}",
867
+ ".pbb-versionFooter a{color:var(--dsw-alias-state-success-primary,#22a06b);text-decoration:none}",
868
+ ".pbb-versionFooter a:hover{text-decoration:underline;text-underline-offset:2px}"
869
+ ].join("\n");
870
+ function injectCss() {
871
+ if (typeof document === "undefined") return;
872
+ const id = "dsh-deeppilot/page.css";
873
+ if (document.querySelector("style[data-plugin-css=\"" + id + "\"]") !== null) return;
874
+ const tag = document.createElement("style");
875
+ tag.setAttribute("data-plugin-css", id);
876
+ tag.textContent = CSS;
877
+ document.head.appendChild(tag);
878
+ }
879
+ //#endregion
880
+ //#region node_modules/qrcode/lib/can-promise.js
881
+ var require_can_promise = /* @__PURE__ */ __commonJSMin(((exports, module) => {
882
+ module.exports = function() {
883
+ return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
366
884
  };
885
+ }));
886
+ //#endregion
887
+ //#region node_modules/qrcode/lib/core/utils.js
888
+ var require_utils$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
889
+ let toSJISFunction;
890
+ const CODEWORDS_COUNT = [
891
+ 0,
892
+ 26,
893
+ 44,
894
+ 70,
895
+ 100,
896
+ 134,
897
+ 172,
898
+ 196,
899
+ 242,
900
+ 292,
901
+ 346,
902
+ 404,
903
+ 466,
904
+ 532,
905
+ 581,
906
+ 655,
907
+ 733,
908
+ 815,
909
+ 901,
910
+ 991,
911
+ 1085,
912
+ 1156,
913
+ 1258,
914
+ 1364,
915
+ 1474,
916
+ 1588,
917
+ 1706,
918
+ 1828,
919
+ 1921,
920
+ 2051,
921
+ 2185,
922
+ 2323,
923
+ 2465,
924
+ 2611,
925
+ 2761,
926
+ 2876,
927
+ 3034,
928
+ 3196,
929
+ 3362,
930
+ 3532,
931
+ 3706
932
+ ];
367
933
  /**
368
- * Check if mask pattern value is valid
934
+ * Returns the QR Code size for the specified version
369
935
  *
370
- * @param {Number} mask Mask pattern
371
- * @return {Boolean} true if valid, false otherwise
936
+ * @param {Number} version QR Code version
937
+ * @return {Number} size of QR code
372
938
  */
373
- exports.isValid = function isValid(mask) {
374
- return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
939
+ exports.getSymbolSize = function getSymbolSize(version) {
940
+ if (!version) throw new Error("\"version\" cannot be null or undefined");
941
+ if (version < 1 || version > 40) throw new Error("\"version\" should be in range from 1 to 40");
942
+ return version * 4 + 17;
375
943
  };
376
944
  /**
377
- * Returns mask pattern from a value.
378
- * If value is not valid, returns undefined
945
+ * Returns the total number of codewords used to store data and EC information.
379
946
  *
380
- * @param {Number|String} value Mask pattern value
381
- * @return {Number} Valid mask pattern or undefined
947
+ * @param {Number} version QR Code version
948
+ * @return {Number} Data length in bits
382
949
  */
383
- exports.from = function from(value) {
384
- return exports.isValid(value) ? parseInt(value, 10) : void 0;
950
+ exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
951
+ return CODEWORDS_COUNT[version];
385
952
  };
386
953
  /**
387
- * Find adjacent modules in row/column with the same color
388
- * and assign a penalty value.
954
+ * Encode data with Bose-Chaudhuri-Hocquenghem
389
955
  *
390
- * Points: N1 + i
391
- * i is the amount by which the number of adjacent modules of the same color exceeds 5
956
+ * @param {Number} data Value to encode
957
+ * @return {Number} Encoded value
392
958
  */
393
- exports.getPenaltyN1 = function getPenaltyN1(data) {
394
- const size = data.size;
395
- let points = 0;
396
- let sameCountCol = 0;
397
- let sameCountRow = 0;
398
- let lastCol = null;
399
- let lastRow = null;
400
- for (let row = 0; row < size; row++) {
401
- sameCountCol = sameCountRow = 0;
402
- lastCol = lastRow = null;
403
- for (let col = 0; col < size; col++) {
404
- let module$1 = data.get(row, col);
405
- if (module$1 === lastCol) sameCountCol++;
406
- else {
407
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
408
- lastCol = module$1;
409
- sameCountCol = 1;
410
- }
411
- module$1 = data.get(col, row);
412
- if (module$1 === lastRow) sameCountRow++;
413
- else {
414
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
415
- lastRow = module$1;
416
- sameCountRow = 1;
417
- }
418
- }
419
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
420
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
959
+ exports.getBCHDigit = function(data) {
960
+ let digit = 0;
961
+ while (data !== 0) {
962
+ digit++;
963
+ data >>>= 1;
421
964
  }
422
- return points;
965
+ return digit;
423
966
  };
424
- /**
425
- * Find 2x2 blocks with the same color and assign a penalty value
967
+ exports.setToSJISFunction = function setToSJISFunction(f) {
968
+ if (typeof f !== "function") throw new Error("\"toSJISFunc\" is not a valid function.");
969
+ toSJISFunction = f;
970
+ };
971
+ exports.isKanjiModeEnabled = function() {
972
+ return typeof toSJISFunction !== "undefined";
973
+ };
974
+ exports.toSJIS = function toSJIS(kanji) {
975
+ return toSJISFunction(kanji);
976
+ };
977
+ }));
978
+ //#endregion
979
+ //#region node_modules/qrcode/lib/core/error-correction-level.js
980
+ var require_error_correction_level = /* @__PURE__ */ __commonJSMin(((exports) => {
981
+ exports.L = { bit: 1 };
982
+ exports.M = { bit: 0 };
983
+ exports.Q = { bit: 3 };
984
+ exports.H = { bit: 2 };
985
+ function fromString(string) {
986
+ if (typeof string !== "string") throw new Error("Param is not a string");
987
+ switch (string.toLowerCase()) {
988
+ case "l":
989
+ case "low": return exports.L;
990
+ case "m":
991
+ case "medium": return exports.M;
992
+ case "q":
993
+ case "quartile": return exports.Q;
994
+ case "h":
995
+ case "high": return exports.H;
996
+ default: throw new Error("Unknown EC Level: " + string);
997
+ }
998
+ }
999
+ exports.isValid = function isValid(level) {
1000
+ return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
1001
+ };
1002
+ exports.from = function from(value, defaultValue) {
1003
+ if (exports.isValid(value)) return value;
1004
+ try {
1005
+ return fromString(value);
1006
+ } catch (e) {
1007
+ return defaultValue;
1008
+ }
1009
+ };
1010
+ }));
1011
+ //#endregion
1012
+ //#region node_modules/qrcode/lib/core/bit-buffer.js
1013
+ var require_bit_buffer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1014
+ function BitBuffer() {
1015
+ this.buffer = [];
1016
+ this.length = 0;
1017
+ }
1018
+ BitBuffer.prototype = {
1019
+ get: function(index) {
1020
+ const bufIndex = Math.floor(index / 8);
1021
+ return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
1022
+ },
1023
+ put: function(num, length) {
1024
+ for (let i = 0; i < length; i++) this.putBit((num >>> length - i - 1 & 1) === 1);
1025
+ },
1026
+ getLengthInBits: function() {
1027
+ return this.length;
1028
+ },
1029
+ putBit: function(bit) {
1030
+ const bufIndex = Math.floor(this.length / 8);
1031
+ if (this.buffer.length <= bufIndex) this.buffer.push(0);
1032
+ if (bit) this.buffer[bufIndex] |= 128 >>> this.length % 8;
1033
+ this.length++;
1034
+ }
1035
+ };
1036
+ module.exports = BitBuffer;
1037
+ }));
1038
+ //#endregion
1039
+ //#region node_modules/qrcode/lib/core/bit-matrix.js
1040
+ var require_bit_matrix = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1041
+ /**
1042
+ * Helper class to handle QR Code symbol modules
426
1043
  *
427
- * Points: N2 * (m - 1) * (n - 1)
1044
+ * @param {Number} size Symbol size
428
1045
  */
429
- exports.getPenaltyN2 = function getPenaltyN2(data) {
430
- const size = data.size;
431
- let points = 0;
432
- for (let row = 0; row < size - 1; row++) for (let col = 0; col < size - 1; col++) {
433
- const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
434
- if (last === 4 || last === 0) points++;
435
- }
436
- return points * PenaltyScores.N2;
1046
+ function BitMatrix(size) {
1047
+ if (!size || size < 1) throw new Error("BitMatrix size must be defined and greater than 0");
1048
+ this.size = size;
1049
+ this.data = new Uint8Array(size * size);
1050
+ this.reservedBit = new Uint8Array(size * size);
1051
+ }
1052
+ /**
1053
+ * Set bit value at specified location
1054
+ * If reserved flag is set, this bit will be ignored during masking process
1055
+ *
1056
+ * @param {Number} row
1057
+ * @param {Number} col
1058
+ * @param {Boolean} value
1059
+ * @param {Boolean} reserved
1060
+ */
1061
+ BitMatrix.prototype.set = function(row, col, value, reserved) {
1062
+ const index = row * this.size + col;
1063
+ this.data[index] = value;
1064
+ if (reserved) this.reservedBit[index] = true;
437
1065
  };
438
1066
  /**
439
- * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
440
- * preceded or followed by light area 4 modules wide
1067
+ * Returns bit value at specified location
441
1068
  *
442
- * Points: N3 * number of pattern found
1069
+ * @param {Number} row
1070
+ * @param {Number} col
1071
+ * @return {Boolean}
443
1072
  */
444
- exports.getPenaltyN3 = function getPenaltyN3(data) {
445
- const size = data.size;
446
- let points = 0;
447
- let bitsCol = 0;
448
- let bitsRow = 0;
449
- for (let row = 0; row < size; row++) {
450
- bitsCol = bitsRow = 0;
451
- for (let col = 0; col < size; col++) {
452
- bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
453
- if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
454
- bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
455
- if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
456
- }
457
- }
458
- return points * PenaltyScores.N3;
1073
+ BitMatrix.prototype.get = function(row, col) {
1074
+ return this.data[row * this.size + col];
459
1075
  };
460
1076
  /**
461
- * Calculate proportion of dark modules in entire symbol
1077
+ * Applies xor operator at specified location
1078
+ * (used during masking process)
462
1079
  *
463
- * Points: N4 * k
1080
+ * @param {Number} row
1081
+ * @param {Number} col
1082
+ * @param {Boolean} value
1083
+ */
1084
+ BitMatrix.prototype.xor = function(row, col, value) {
1085
+ this.data[row * this.size + col] ^= value;
1086
+ };
1087
+ /**
1088
+ * Check if bit at specified location is reserved
464
1089
  *
465
- * k is the rating of the deviation of the proportion of dark modules
466
- * in the symbol from 50% in steps of 5%
1090
+ * @param {Number} row
1091
+ * @param {Number} col
1092
+ * @return {Boolean}
467
1093
  */
468
- exports.getPenaltyN4 = function getPenaltyN4(data) {
469
- let darkCount = 0;
470
- const modulesCount = data.data.length;
471
- for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
472
- return Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10) * PenaltyScores.N4;
1094
+ BitMatrix.prototype.isReserved = function(row, col) {
1095
+ return this.reservedBit[row * this.size + col];
473
1096
  };
1097
+ module.exports = BitMatrix;
1098
+ }));
1099
+ //#endregion
1100
+ //#region node_modules/qrcode/lib/core/alignment-pattern.js
1101
+ var require_alignment_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
474
1102
  /**
475
- * Return mask value at given position
1103
+ * Alignment pattern are fixed reference pattern in defined positions
1104
+ * in a matrix symbology, which enables the decode software to re-synchronise
1105
+ * the coordinate mapping of the image modules in the event of moderate amounts
1106
+ * of distortion of the image.
476
1107
  *
477
- * @param {Number} maskPattern Pattern reference value
478
- * @param {Number} i Row
479
- * @param {Number} j Column
480
- * @return {Boolean} Mask value
1108
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
1109
+ * and their number depends on the symbol version.
481
1110
  */
482
- function getMaskAt(maskPattern, i, j) {
483
- switch (maskPattern) {
484
- case exports.Patterns.PATTERN000: return (i + j) % 2 === 0;
485
- case exports.Patterns.PATTERN001: return i % 2 === 0;
486
- case exports.Patterns.PATTERN010: return j % 3 === 0;
487
- case exports.Patterns.PATTERN011: return (i + j) % 3 === 0;
488
- case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
489
- case exports.Patterns.PATTERN101: return i * j % 2 + i * j % 3 === 0;
490
- case exports.Patterns.PATTERN110: return (i * j % 2 + i * j % 3) % 2 === 0;
491
- case exports.Patterns.PATTERN111: return (i * j % 3 + (i + j) % 2) % 2 === 0;
492
- default: throw new Error("bad maskPattern:" + maskPattern);
493
- }
494
- }
1111
+ const getSymbolSize = require_utils$1().getSymbolSize;
495
1112
  /**
496
- * Apply a mask pattern to a BitMatrix
1113
+ * Calculate the row/column coordinates of the center module of each alignment pattern
1114
+ * for the specified QR Code version.
497
1115
  *
498
- * @param {Number} pattern Pattern reference number
499
- * @param {BitMatrix} data BitMatrix data
1116
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
1117
+ * running from the top left corner of the symbol to the bottom right corner.
1118
+ *
1119
+ * Since positions are simmetrical only half of the coordinates are returned.
1120
+ * Each item of the array will represent in turn the x and y coordinate.
1121
+ * @see {@link getPositions}
1122
+ *
1123
+ * @param {Number} version QR Code version
1124
+ * @return {Array} Array of coordinate
500
1125
  */
501
- exports.applyMask = function applyMask(pattern, data) {
502
- const size = data.size;
503
- for (let col = 0; col < size; col++) for (let row = 0; row < size; row++) {
504
- if (data.isReserved(row, col)) continue;
505
- data.xor(row, col, getMaskAt(pattern, row, col));
506
- }
1126
+ exports.getRowColCoords = function getRowColCoords(version) {
1127
+ if (version === 1) return [];
1128
+ const posCount = Math.floor(version / 7) + 2;
1129
+ const size = getSymbolSize(version);
1130
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
1131
+ const positions = [size - 7];
1132
+ for (let i = 1; i < posCount - 1; i++) positions[i] = positions[i - 1] - intervals;
1133
+ positions.push(6);
1134
+ return positions.reverse();
507
1135
  };
508
1136
  /**
509
- * Returns the best mask pattern for data
1137
+ * Returns an array containing the positions of each alignment pattern.
1138
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
510
1139
  *
511
- * @param {BitMatrix} data
512
- * @return {Number} Mask pattern reference number
1140
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
1141
+ * and filtering out the items that overlaps with finder pattern
1142
+ *
1143
+ * @example
1144
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
1145
+ * The alignment patterns, therefore, are to be centered on (row, column)
1146
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
1147
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
1148
+ * and are not therefore used for alignment patterns.
1149
+ *
1150
+ * let pos = getPositions(7)
1151
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
1152
+ *
1153
+ * @param {Number} version QR Code version
1154
+ * @return {Array} Array of coordinates
513
1155
  */
514
- exports.getBestMask = function getBestMask(data, setupFormatFunc) {
515
- const numPatterns = Object.keys(exports.Patterns).length;
516
- let bestPattern = 0;
517
- let lowerPenalty = Infinity;
518
- for (let p = 0; p < numPatterns; p++) {
519
- setupFormatFunc(p);
520
- exports.applyMask(p, data);
521
- const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
522
- exports.applyMask(p, data);
523
- if (penalty < lowerPenalty) {
524
- lowerPenalty = penalty;
525
- bestPattern = p;
526
- }
1156
+ exports.getPositions = function getPositions(version) {
1157
+ const coords = [];
1158
+ const pos = exports.getRowColCoords(version);
1159
+ const posLength = pos.length;
1160
+ for (let i = 0; i < posLength; i++) for (let j = 0; j < posLength; j++) {
1161
+ if (i === 0 && j === 0 || i === 0 && j === posLength - 1 || i === posLength - 1 && j === 0) continue;
1162
+ coords.push([pos[i], pos[j]]);
527
1163
  }
528
- return bestPattern;
1164
+ return coords;
529
1165
  };
530
1166
  }));
531
1167
  //#endregion
532
- //#region node_modules/qrcode/lib/core/error-correction-code.js
1168
+ //#region node_modules/qrcode/lib/core/finder-pattern.js
1169
+ var require_finder_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
1170
+ const getSymbolSize = require_utils$1().getSymbolSize;
1171
+ const FINDER_PATTERN_SIZE = 7;
1172
+ /**
1173
+ * Returns an array containing the positions of each finder pattern.
1174
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
1175
+ *
1176
+ * @param {Number} version QR Code version
1177
+ * @return {Array} Array of coordinates
1178
+ */
1179
+ exports.getPositions = function getPositions(version) {
1180
+ const size = getSymbolSize(version);
1181
+ return [
1182
+ [0, 0],
1183
+ [size - FINDER_PATTERN_SIZE, 0],
1184
+ [0, size - FINDER_PATTERN_SIZE]
1185
+ ];
1186
+ };
1187
+ }));
1188
+ //#endregion
1189
+ //#region node_modules/qrcode/lib/core/mask-pattern.js
1190
+ var require_mask_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
1191
+ /**
1192
+ * Data mask pattern reference
1193
+ * @type {Object}
1194
+ */
1195
+ exports.Patterns = {
1196
+ PATTERN000: 0,
1197
+ PATTERN001: 1,
1198
+ PATTERN010: 2,
1199
+ PATTERN011: 3,
1200
+ PATTERN100: 4,
1201
+ PATTERN101: 5,
1202
+ PATTERN110: 6,
1203
+ PATTERN111: 7
1204
+ };
1205
+ /**
1206
+ * Weighted penalty scores for the undesirable features
1207
+ * @type {Object}
1208
+ */
1209
+ const PenaltyScores = {
1210
+ N1: 3,
1211
+ N2: 3,
1212
+ N3: 40,
1213
+ N4: 10
1214
+ };
1215
+ /**
1216
+ * Check if mask pattern value is valid
1217
+ *
1218
+ * @param {Number} mask Mask pattern
1219
+ * @return {Boolean} true if valid, false otherwise
1220
+ */
1221
+ exports.isValid = function isValid(mask) {
1222
+ return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
1223
+ };
1224
+ /**
1225
+ * Returns mask pattern from a value.
1226
+ * If value is not valid, returns undefined
1227
+ *
1228
+ * @param {Number|String} value Mask pattern value
1229
+ * @return {Number} Valid mask pattern or undefined
1230
+ */
1231
+ exports.from = function from(value) {
1232
+ return exports.isValid(value) ? parseInt(value, 10) : void 0;
1233
+ };
1234
+ /**
1235
+ * Find adjacent modules in row/column with the same color
1236
+ * and assign a penalty value.
1237
+ *
1238
+ * Points: N1 + i
1239
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
1240
+ */
1241
+ exports.getPenaltyN1 = function getPenaltyN1(data) {
1242
+ const size = data.size;
1243
+ let points = 0;
1244
+ let sameCountCol = 0;
1245
+ let sameCountRow = 0;
1246
+ let lastCol = null;
1247
+ let lastRow = null;
1248
+ for (let row = 0; row < size; row++) {
1249
+ sameCountCol = sameCountRow = 0;
1250
+ lastCol = lastRow = null;
1251
+ for (let col = 0; col < size; col++) {
1252
+ let module$1 = data.get(row, col);
1253
+ if (module$1 === lastCol) sameCountCol++;
1254
+ else {
1255
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
1256
+ lastCol = module$1;
1257
+ sameCountCol = 1;
1258
+ }
1259
+ module$1 = data.get(col, row);
1260
+ if (module$1 === lastRow) sameCountRow++;
1261
+ else {
1262
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
1263
+ lastRow = module$1;
1264
+ sameCountRow = 1;
1265
+ }
1266
+ }
1267
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
1268
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
1269
+ }
1270
+ return points;
1271
+ };
1272
+ /**
1273
+ * Find 2x2 blocks with the same color and assign a penalty value
1274
+ *
1275
+ * Points: N2 * (m - 1) * (n - 1)
1276
+ */
1277
+ exports.getPenaltyN2 = function getPenaltyN2(data) {
1278
+ const size = data.size;
1279
+ let points = 0;
1280
+ for (let row = 0; row < size - 1; row++) for (let col = 0; col < size - 1; col++) {
1281
+ const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
1282
+ if (last === 4 || last === 0) points++;
1283
+ }
1284
+ return points * PenaltyScores.N2;
1285
+ };
1286
+ /**
1287
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
1288
+ * preceded or followed by light area 4 modules wide
1289
+ *
1290
+ * Points: N3 * number of pattern found
1291
+ */
1292
+ exports.getPenaltyN3 = function getPenaltyN3(data) {
1293
+ const size = data.size;
1294
+ let points = 0;
1295
+ let bitsCol = 0;
1296
+ let bitsRow = 0;
1297
+ for (let row = 0; row < size; row++) {
1298
+ bitsCol = bitsRow = 0;
1299
+ for (let col = 0; col < size; col++) {
1300
+ bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
1301
+ if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
1302
+ bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
1303
+ if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
1304
+ }
1305
+ }
1306
+ return points * PenaltyScores.N3;
1307
+ };
1308
+ /**
1309
+ * Calculate proportion of dark modules in entire symbol
1310
+ *
1311
+ * Points: N4 * k
1312
+ *
1313
+ * k is the rating of the deviation of the proportion of dark modules
1314
+ * in the symbol from 50% in steps of 5%
1315
+ */
1316
+ exports.getPenaltyN4 = function getPenaltyN4(data) {
1317
+ let darkCount = 0;
1318
+ const modulesCount = data.data.length;
1319
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
1320
+ return Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10) * PenaltyScores.N4;
1321
+ };
1322
+ /**
1323
+ * Return mask value at given position
1324
+ *
1325
+ * @param {Number} maskPattern Pattern reference value
1326
+ * @param {Number} i Row
1327
+ * @param {Number} j Column
1328
+ * @return {Boolean} Mask value
1329
+ */
1330
+ function getMaskAt(maskPattern, i, j) {
1331
+ switch (maskPattern) {
1332
+ case exports.Patterns.PATTERN000: return (i + j) % 2 === 0;
1333
+ case exports.Patterns.PATTERN001: return i % 2 === 0;
1334
+ case exports.Patterns.PATTERN010: return j % 3 === 0;
1335
+ case exports.Patterns.PATTERN011: return (i + j) % 3 === 0;
1336
+ case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
1337
+ case exports.Patterns.PATTERN101: return i * j % 2 + i * j % 3 === 0;
1338
+ case exports.Patterns.PATTERN110: return (i * j % 2 + i * j % 3) % 2 === 0;
1339
+ case exports.Patterns.PATTERN111: return (i * j % 3 + (i + j) % 2) % 2 === 0;
1340
+ default: throw new Error("bad maskPattern:" + maskPattern);
1341
+ }
1342
+ }
1343
+ /**
1344
+ * Apply a mask pattern to a BitMatrix
1345
+ *
1346
+ * @param {Number} pattern Pattern reference number
1347
+ * @param {BitMatrix} data BitMatrix data
1348
+ */
1349
+ exports.applyMask = function applyMask(pattern, data) {
1350
+ const size = data.size;
1351
+ for (let col = 0; col < size; col++) for (let row = 0; row < size; row++) {
1352
+ if (data.isReserved(row, col)) continue;
1353
+ data.xor(row, col, getMaskAt(pattern, row, col));
1354
+ }
1355
+ };
1356
+ /**
1357
+ * Returns the best mask pattern for data
1358
+ *
1359
+ * @param {BitMatrix} data
1360
+ * @return {Number} Mask pattern reference number
1361
+ */
1362
+ exports.getBestMask = function getBestMask(data, setupFormatFunc) {
1363
+ const numPatterns = Object.keys(exports.Patterns).length;
1364
+ let bestPattern = 0;
1365
+ let lowerPenalty = Infinity;
1366
+ for (let p = 0; p < numPatterns; p++) {
1367
+ setupFormatFunc(p);
1368
+ exports.applyMask(p, data);
1369
+ const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
1370
+ exports.applyMask(p, data);
1371
+ if (penalty < lowerPenalty) {
1372
+ lowerPenalty = penalty;
1373
+ bestPattern = p;
1374
+ }
1375
+ }
1376
+ return bestPattern;
1377
+ };
1378
+ }));
1379
+ //#endregion
1380
+ //#region node_modules/qrcode/lib/core/error-correction-code.js
533
1381
  var require_error_correction_code = /* @__PURE__ */ __commonJSMin(((exports) => {
534
1382
  const ECLevel = require_error_correction_level();
535
1383
  const EC_BLOCKS_TABLE = [
@@ -2202,891 +3050,349 @@ window.__ModuleLoader__.load({
2202
3050
  }
2203
3051
  return createSymbol(data, version, errorCorrectionLevel, mask);
2204
3052
  };
2205
- }));
2206
- //#endregion
2207
- //#region node_modules/qrcode/lib/renderer/utils.js
2208
- var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
2209
- function hex2rgba(hex) {
2210
- if (typeof hex === "number") hex = hex.toString();
2211
- if (typeof hex !== "string") throw new Error("Color should be defined as hex string");
2212
- let hexCode = hex.slice().replace("#", "").split("");
2213
- if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) throw new Error("Invalid hex color: " + hex);
2214
- if (hexCode.length === 3 || hexCode.length === 4) hexCode = Array.prototype.concat.apply([], hexCode.map(function(c) {
2215
- return [c, c];
2216
- }));
2217
- if (hexCode.length === 6) hexCode.push("F", "F");
2218
- const hexValue = parseInt(hexCode.join(""), 16);
2219
- return {
2220
- r: hexValue >> 24 & 255,
2221
- g: hexValue >> 16 & 255,
2222
- b: hexValue >> 8 & 255,
2223
- a: hexValue & 255,
2224
- hex: "#" + hexCode.slice(0, 6).join("")
2225
- };
2226
- }
2227
- exports.getOptions = function getOptions(options) {
2228
- if (!options) options = {};
2229
- if (!options.color) options.color = {};
2230
- const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
2231
- const width = options.width && options.width >= 21 ? options.width : void 0;
2232
- const scale = options.scale || 4;
2233
- return {
2234
- width,
2235
- scale: width ? 4 : scale,
2236
- margin,
2237
- color: {
2238
- dark: hex2rgba(options.color.dark || "#000000ff"),
2239
- light: hex2rgba(options.color.light || "#ffffffff")
2240
- },
2241
- type: options.type,
2242
- rendererOpts: options.rendererOpts || {}
2243
- };
2244
- };
2245
- exports.getScale = function getScale(qrSize, opts) {
2246
- return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
2247
- };
2248
- exports.getImageWidth = function getImageWidth(qrSize, opts) {
2249
- const scale = exports.getScale(qrSize, opts);
2250
- return Math.floor((qrSize + opts.margin * 2) * scale);
2251
- };
2252
- exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
2253
- const size = qr.modules.size;
2254
- const data = qr.modules.data;
2255
- const scale = exports.getScale(size, opts);
2256
- const symbolSize = Math.floor((size + opts.margin * 2) * scale);
2257
- const scaledMargin = opts.margin * scale;
2258
- const palette = [opts.color.light, opts.color.dark];
2259
- for (let i = 0; i < symbolSize; i++) for (let j = 0; j < symbolSize; j++) {
2260
- let posDst = (i * symbolSize + j) * 4;
2261
- let pxColor = opts.color.light;
2262
- if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2263
- const iSrc = Math.floor((i - scaledMargin) / scale);
2264
- const jSrc = Math.floor((j - scaledMargin) / scale);
2265
- pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
2266
- }
2267
- imgData[posDst++] = pxColor.r;
2268
- imgData[posDst++] = pxColor.g;
2269
- imgData[posDst++] = pxColor.b;
2270
- imgData[posDst] = pxColor.a;
2271
- }
2272
- };
2273
- }));
2274
- //#endregion
2275
- //#region node_modules/qrcode/lib/renderer/canvas.js
2276
- var require_canvas = /* @__PURE__ */ __commonJSMin(((exports) => {
2277
- const Utils = require_utils();
2278
- function clearCanvas(ctx, canvas, size) {
2279
- ctx.clearRect(0, 0, canvas.width, canvas.height);
2280
- if (!canvas.style) canvas.style = {};
2281
- canvas.height = size;
2282
- canvas.width = size;
2283
- canvas.style.height = size + "px";
2284
- canvas.style.width = size + "px";
2285
- }
2286
- function getCanvasElement() {
2287
- try {
2288
- return document.createElement("canvas");
2289
- } catch (e) {
2290
- throw new Error("You need to specify a canvas element");
2291
- }
2292
- }
2293
- exports.render = function render(qrData, canvas, options) {
2294
- let opts = options;
2295
- let canvasEl = canvas;
2296
- if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
2297
- opts = canvas;
2298
- canvas = void 0;
2299
- }
2300
- if (!canvas) canvasEl = getCanvasElement();
2301
- opts = Utils.getOptions(opts);
2302
- const size = Utils.getImageWidth(qrData.modules.size, opts);
2303
- const ctx = canvasEl.getContext("2d");
2304
- const image = ctx.createImageData(size, size);
2305
- Utils.qrToImageData(image.data, qrData, opts);
2306
- clearCanvas(ctx, canvasEl, size);
2307
- ctx.putImageData(image, 0, 0);
2308
- return canvasEl;
2309
- };
2310
- exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
2311
- let opts = options;
2312
- if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
2313
- opts = canvas;
2314
- canvas = void 0;
2315
- }
2316
- if (!opts) opts = {};
2317
- const canvasEl = exports.render(qrData, canvas, opts);
2318
- const type = opts.type || "image/png";
2319
- const rendererOpts = opts.rendererOpts || {};
2320
- return canvasEl.toDataURL(type, rendererOpts.quality);
2321
- };
2322
- }));
2323
- //#endregion
2324
- //#region node_modules/qrcode/lib/renderer/svg-tag.js
2325
- var require_svg_tag = /* @__PURE__ */ __commonJSMin(((exports) => {
2326
- const Utils = require_utils();
2327
- function getColorAttrib(color, attrib) {
2328
- const alpha = color.a / 255;
2329
- const str = attrib + "=\"" + color.hex + "\"";
2330
- return alpha < 1 ? str + " " + attrib + "-opacity=\"" + alpha.toFixed(2).slice(1) + "\"" : str;
2331
- }
2332
- function svgCmd(cmd, x, y) {
2333
- let str = cmd + x;
2334
- if (typeof y !== "undefined") str += " " + y;
2335
- return str;
2336
- }
2337
- function qrToPath(data, size, margin) {
2338
- let path = "";
2339
- let moveBy = 0;
2340
- let newRow = false;
2341
- let lineLength = 0;
2342
- for (let i = 0; i < data.length; i++) {
2343
- const col = Math.floor(i % size);
2344
- const row = Math.floor(i / size);
2345
- if (!col && !newRow) newRow = true;
2346
- if (data[i]) {
2347
- lineLength++;
2348
- if (!(i > 0 && col > 0 && data[i - 1])) {
2349
- path += newRow ? svgCmd("M", col + margin, .5 + row + margin) : svgCmd("m", moveBy, 0);
2350
- moveBy = 0;
2351
- newRow = false;
2352
- }
2353
- if (!(col + 1 < size && data[i + 1])) {
2354
- path += svgCmd("h", lineLength);
2355
- lineLength = 0;
2356
- }
2357
- } else moveBy++;
2358
- }
2359
- return path;
2360
- }
2361
- exports.render = function render(qrData, options, cb) {
2362
- const opts = Utils.getOptions(options);
2363
- const size = qrData.modules.size;
2364
- const data = qrData.modules.data;
2365
- const qrcodesize = size + opts.margin * 2;
2366
- const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + " d=\"M0 0h" + qrcodesize + "v" + qrcodesize + "H0z\"/>";
2367
- const path = "<path " + getColorAttrib(opts.color.dark, "stroke") + " d=\"" + qrToPath(data, size, opts.margin) + "\"/>";
2368
- const viewBox = "viewBox=\"0 0 " + qrcodesize + " " + qrcodesize + "\"";
2369
- const svgTag = "<svg xmlns=\"http://www.w3.org/2000/svg\" " + (!opts.width ? "" : "width=\"" + opts.width + "\" height=\"" + opts.width + "\" ") + viewBox + " shape-rendering=\"crispEdges\">" + bg + path + "</svg>\n";
2370
- if (typeof cb === "function") cb(null, svgTag);
2371
- return svgTag;
2372
- };
2373
- }));
2374
- //#endregion
2375
- //#region src/pairing-qr.ts
2376
- var import_browser = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
2377
- const canPromise = require_can_promise();
2378
- const QRCode = require_qrcode();
2379
- const CanvasRenderer = require_canvas();
2380
- const SvgRenderer = require_svg_tag();
2381
- function renderCanvas(renderFunc, canvas, text, opts, cb) {
2382
- const args = [].slice.call(arguments, 1);
2383
- const argsNum = args.length;
2384
- const isLastArgCb = typeof args[argsNum - 1] === "function";
2385
- if (!isLastArgCb && !canPromise()) throw new Error("Callback required as last argument");
2386
- if (isLastArgCb) {
2387
- if (argsNum < 2) throw new Error("Too few arguments provided");
2388
- if (argsNum === 2) {
2389
- cb = text;
2390
- text = canvas;
2391
- canvas = opts = void 0;
2392
- } else if (argsNum === 3) {
2393
- if (canvas.getContext && typeof cb === "undefined") {
2394
- cb = opts;
2395
- opts = void 0;
2396
- } else {
2397
- cb = opts;
2398
- opts = text;
2399
- text = canvas;
2400
- canvas = void 0;
2401
- }
2402
- }
2403
- } else {
2404
- if (argsNum < 1) throw new Error("Too few arguments provided");
2405
- if (argsNum === 1) {
2406
- text = canvas;
2407
- canvas = opts = void 0;
2408
- } else if (argsNum === 2 && !canvas.getContext) {
2409
- opts = text;
2410
- text = canvas;
2411
- canvas = void 0;
2412
- }
2413
- return new Promise(function(resolve, reject) {
2414
- try {
2415
- resolve(renderFunc(QRCode.create(text, opts), canvas, opts));
2416
- } catch (e) {
2417
- reject(e);
2418
- }
2419
- });
2420
- }
2421
- try {
2422
- const data = QRCode.create(text, opts);
2423
- cb(null, renderFunc(data, canvas, opts));
2424
- } catch (e) {
2425
- cb(e);
2426
- }
2427
- }
2428
- exports.create = QRCode.create;
2429
- exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
2430
- exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
2431
- exports.toString = renderCanvas.bind(null, function(data, _, opts) {
2432
- return SvgRenderer.render(data, opts);
2433
- });
2434
- })))(), 1);
2435
- /**
2436
- * Protocol-v1 compatibility identifier used by the TestFlight build currently
2437
- * under review. This is wire data, not the plugin or product display name.
2438
- */
2439
- const PAIRING_QR_TYPE = "dsh-pocket-pairing";
2440
- function isLoopbackHostname(hostname) {
2441
- const normalized = hostname.toLowerCase();
2442
- return normalized === "localhost" || normalized.endsWith(".localhost") || normalized === "[::1]" || normalized === "::1" || normalized.startsWith("127.");
2443
- }
2444
- /** Prefer an online Funnel; otherwise turn the current web origin into a LAN target. */
2445
- function selectPairingTarget(remote, lanAddresses, currentOrigin) {
2446
- let origin;
2447
- try {
2448
- if (currentOrigin) origin = new URL(currentOrigin);
2449
- } catch {}
2450
- if (remote.publicURL && origin?.origin === remote.publicURL) return {
2451
- host: remote.publicURL,
2452
- kind: "public"
2453
- };
2454
- if (remote.phase === "online" && remote.publicURL) return {
2455
- host: remote.publicURL,
2456
- kind: "public"
2457
- };
2458
- if (origin && ["http:", "https:"].includes(origin.protocol) && !isLoopbackHostname(origin.hostname)) return {
2459
- host: origin.origin,
2460
- kind: "lan"
2461
- };
2462
- const address = lanAddresses[0];
2463
- if (!address) return null;
2464
- return {
2465
- host: `${origin?.protocol === "https:" ? "https:" : "http:"}//${address}${origin?.port ? `:${origin.port}` : ""}`,
2466
- kind: "lan"
2467
- };
2468
- }
2469
- /** Encode an out-of-band pairing payload without putting the token in a URL. */
2470
- function encodePairingQRPayload(host, token) {
2471
- const normalizedHost = host.trim();
2472
- const parsed = new URL(normalizedHost);
2473
- if (![
2474
- "http:",
2475
- "https:",
2476
- "ws:",
2477
- "wss:"
2478
- ].includes(parsed.protocol) || parsed.hostname === "" || parsed.username !== "" || parsed.password !== "") throw new TypeError("pairing QR requires a valid HTTP(S)/WS(S) host");
2479
- if (token.trim().length < 32) throw new TypeError("pairing token is invalid");
2480
- const payload = {
2481
- v: 1,
2482
- type: PAIRING_QR_TYPE,
2483
- host: normalizedHost,
2484
- token: token.trim()
2485
- };
2486
- return JSON.stringify(payload);
2487
- }
2488
- //#endregion
2489
- //#region src/report-wire.ts
2490
- /** The npm package identity both contribution registrations claim. */
2491
- const REPORT_REMOTE_PACKAGE = "dsh-deeppilot";
2492
- /** Canonical `<namespace>/<method>` endpoint of the report Remote. */
2493
- const REPORT_ENDPOINT = "deeppilot/report";
2494
- /** Explicit, user-triggered endpoint for revealing the pairing secret. */
2495
- const REVEAL_TOKEN_ENDPOINT = "deeppilot/revealToken";
2496
- /**
2497
- * Explicit, user-triggered endpoint that replaces the pairing secret. The old
2498
- * token stops working immediately; the fresh one is returned so the page can
2499
- * show/QR it right away.
2500
- */
2501
- const ROTATE_TOKEN_ENDPOINT = "deeppilot/rotateToken";
2502
- function reject(field) {
2503
- throw new TypeError(`deeppilot/report result: invalid ${field}`);
2504
- }
2505
- function str(source, key, field) {
2506
- const value = source[key];
2507
- if (typeof value !== "string") reject(field);
2508
- return value;
2509
- }
2510
- function num(source, key, field) {
2511
- const value = source[key];
2512
- if (typeof value !== "number" || !Number.isFinite(value)) reject(field);
2513
- return value;
2514
- }
2515
- function bool(source, key, field) {
2516
- const value = source[key];
2517
- if (typeof value !== "boolean") reject(field);
2518
- return value;
2519
- }
2520
- function rec(value, field) {
2521
- if (typeof value !== "object" || value === null || Array.isArray(value)) reject(field);
2522
- return value;
2523
- }
2524
- function parseDevice(value) {
2525
- const s = rec(value, "device");
2526
- let apns;
2527
- if (s.apns !== void 0) {
2528
- const a = rec(s.apns, "device.apns");
2529
- const environment = str(a, "environment", "device.apns.environment");
2530
- if (environment !== "development" && environment !== "production") reject("device.apns.environment");
2531
- apns = {
2532
- environment,
2533
- updatedAt: num(a, "updatedAt", "device.apns.updatedAt")
2534
- };
2535
- }
2536
- return {
2537
- deviceId: str(s, "deviceId", "device.deviceId"),
2538
- deviceName: str(s, "deviceName", "device.deviceName"),
2539
- appVersion: str(s, "appVersion", "device.appVersion"),
2540
- firstSeenTs: num(s, "firstSeenTs", "device.firstSeenTs"),
2541
- lastSeenTs: num(s, "lastSeenTs", "device.lastSeenTs"),
2542
- ...apns ? { apns } : {}
2543
- };
2544
- }
2545
- function parseRemote(value) {
2546
- const s = rec(value, "remote");
2547
- const provider = str(s, "provider", "remote.provider");
2548
- const phase = str(s, "phase", "remote.phase");
2549
- if (provider !== "tailscale-funnel") reject("remote.provider");
2550
- if (![
2551
- "disabled",
2552
- "starting",
2553
- "login_required",
2554
- "online",
2555
- "error",
2556
- "unavailable",
2557
- "stopped"
2558
- ].includes(phase)) reject("remote.phase");
2559
- const publicURL = s.publicURL;
2560
- const authURL = s.authURL;
2561
- const message = s.message;
2562
- if (publicURL !== void 0 && typeof publicURL !== "string") reject("remote.publicURL");
2563
- if (authURL !== void 0 && typeof authURL !== "string") reject("remote.authURL");
2564
- if (message !== void 0 && typeof message !== "string") reject("remote.message");
2565
- return {
2566
- provider,
2567
- phase,
2568
- ...typeof publicURL === "string" ? { publicURL } : {},
2569
- ...typeof authURL === "string" ? { authURL } : {},
2570
- ...typeof message === "string" ? { message } : {},
2571
- updatedAt: num(s, "updatedAt", "remote.updatedAt")
2572
- };
2573
- }
2574
- function parseRelayTestStep(value) {
2575
- const st = rec(value, "step");
2576
- const id = str(st, "id", "step.id");
2577
- if (id !== "health" && id !== "enroll") reject("step.id");
2578
- const latencyMs = st.latencyMs;
2579
- if (latencyMs !== void 0 && typeof latencyMs !== "number") reject("step.latencyMs");
2580
- return {
2581
- id,
2582
- ok: bool(st, "ok", "step.ok"),
2583
- message: str(st, "message", "step.message"),
2584
- ...typeof latencyMs === "number" ? { latencyMs } : {}
2585
- };
2586
- }
2587
- function parseRelayTestResult(value) {
2588
- const s = rec(value, "result");
2589
- const overall = str(s, "overall", "overall");
2590
- if (overall !== "ok" && overall !== "failed") reject("overall");
2591
- const stepsRaw = s.steps;
2592
- if (!Array.isArray(stepsRaw)) reject("steps");
2593
- return {
2594
- url: str(s, "url", "url"),
2595
- overall,
2596
- tokenIssued: bool(s, "tokenIssued", "tokenIssued"),
2597
- steps: stepsRaw.map(parseRelayTestStep)
2598
- };
2599
- }
2600
- function parsePushTestResult(value) {
2601
- const s = rec(value, "result");
2602
- const transport = str(s, "transport", "transport");
2603
- if (transport !== "apns" && transport !== "relay" && transport !== "none") reject("transport");
2604
- const overall = str(s, "overall", "overall");
2605
- if (![
2606
- "sent",
2607
- "failed",
2608
- "no-targets",
2609
- "not-configured"
2610
- ].includes(overall)) reject("overall");
2611
- const resultsRaw = s.results;
2612
- if (!Array.isArray(resultsRaw)) reject("results");
2613
- const results = resultsRaw.map((value) => {
2614
- const r = rec(value, "device result");
2615
- const reason = r.reason;
2616
- const tokenFingerprint = r.tokenFingerprint;
2617
- return {
2618
- name: str(r, "name", "result.name"),
2619
- environment: str(r, "environment", "result.environment"),
2620
- outcome: str(r, "outcome", "result.outcome"),
2621
- ...typeof reason === "string" && reason.length > 0 ? { reason } : {},
2622
- ...typeof tokenFingerprint === "string" && /^[0-9a-f]{1,32}$/.test(tokenFingerprint) ? { tokenFingerprint } : {}
2623
- };
2624
- });
2625
- const message = s.message;
2626
- return {
2627
- transport,
2628
- overall,
2629
- ...typeof message === "string" && message.length > 0 ? { message } : {},
2630
- results
2631
- };
2632
- }
2633
- function parseReport(value) {
2634
- const s = rec(value, "report");
2635
- const devices = s.devices;
2636
- const lanAddresses = s.lanAddresses;
2637
- if (!Array.isArray(devices)) reject("devices");
2638
- if (!Array.isArray(lanAddresses) || lanAddresses.some((value) => typeof value !== "string")) reject("lanAddresses");
2639
- const releaseUrl = s.releaseUrl;
2640
- return {
2641
- protocolVersion: num(s, "protocolVersion", "protocolVersion"),
2642
- serverVersion: str(s, "serverVersion", "serverVersion"),
2643
- pluginVersion: str(s, "pluginVersion", "pluginVersion"),
2644
- ...s.updateAvailable === true ? { updateAvailable: true } : {},
2645
- ...typeof releaseUrl === "string" && releaseUrl.length > 0 ? { releaseUrl } : {},
2646
- enabled: bool(s, "enabled", "enabled"),
2647
- tokenPath: str(s, "tokenPath", "tokenPath"),
2648
- tokenReady: bool(s, "tokenReady", "tokenReady"),
2649
- activeConnections: num(s, "activeConnections", "activeConnections"),
2650
- historyBufferMax: num(s, "historyBufferMax", "historyBufferMax"),
2651
- debug: bool(s, "debug", "debug"),
2652
- lanAddresses,
2653
- remote: parseRemote(s.remote),
2654
- devices: devices.map(parseDevice)
2655
- };
2656
- }
2657
- const reportSchema = { parse: parseReport };
2658
- const relayTestSchema = { parse: parseRelayTestResult };
2659
- const pushTestSchema = { parse: parsePushTestResult };
2660
- const pairingTokenSchema = { parse(value) {
2661
- if (typeof value !== "string" || value.length < 32) throw new TypeError("deeppilot/revealToken result: invalid token");
2662
- return value;
2663
- } };
2664
- const REPORT_REMOTE_CONTRIBUTION = {
2665
- package: REPORT_REMOTE_PACKAGE,
2666
- descriptors: [
2667
- {
2668
- id: `${REPORT_REMOTE_PACKAGE}#${REPORT_ENDPOINT}`,
2669
- service: "deeppilotReport",
2670
- namespace: "deeppilot",
2671
- method: "report",
2672
- invocation: { kind: "direct" },
2673
- parameters: [],
2674
- result: {
2675
- mode: "strict",
2676
- typeSymbol: `${REPORT_REMOTE_PACKAGE}#DeepPilotReport`,
2677
- schema: reportSchema
2678
- }
2679
- },
2680
- {
2681
- id: `${REPORT_REMOTE_PACKAGE}#${REVEAL_TOKEN_ENDPOINT}`,
2682
- service: "deeppilotReport",
2683
- namespace: "deeppilot",
2684
- method: "revealToken",
2685
- invocation: { kind: "direct" },
2686
- parameters: [],
2687
- result: {
2688
- mode: "strict",
2689
- typeSymbol: `${REPORT_REMOTE_PACKAGE}#PairingToken`,
2690
- schema: pairingTokenSchema
2691
- }
2692
- },
2693
- {
2694
- id: `${REPORT_REMOTE_PACKAGE}#${ROTATE_TOKEN_ENDPOINT}`,
2695
- service: "deeppilotReport",
2696
- namespace: "deeppilot",
2697
- method: "rotateToken",
2698
- invocation: { kind: "direct" },
2699
- parameters: [],
2700
- result: {
2701
- mode: "strict",
2702
- typeSymbol: `${REPORT_REMOTE_PACKAGE}#PairingToken`,
2703
- schema: pairingTokenSchema
2704
- }
2705
- },
2706
- {
2707
- id: `${REPORT_REMOTE_PACKAGE}#deeppilot/testRelay`,
2708
- service: "deeppilotReport",
2709
- namespace: "deeppilot",
2710
- method: "testRelay",
2711
- invocation: { kind: "direct" },
2712
- parameters: [],
2713
- result: {
2714
- mode: "strict",
2715
- typeSymbol: `${REPORT_REMOTE_PACKAGE}#RelayTestResult`,
2716
- schema: relayTestSchema
2717
- }
2718
- },
2719
- {
2720
- id: `${REPORT_REMOTE_PACKAGE}#deeppilot/testPush`,
2721
- service: "deeppilotReport",
2722
- namespace: "deeppilot",
2723
- method: "testPush",
2724
- invocation: { kind: "direct" },
2725
- parameters: [],
2726
- result: {
2727
- mode: "strict",
2728
- typeSymbol: `${REPORT_REMOTE_PACKAGE}#PushTestResult`,
2729
- schema: pushTestSchema
2730
- }
2731
- }
2732
- ]
2733
- };
3053
+ }));
2734
3054
  //#endregion
2735
- //#region src/client/report-mount.ts
2736
- /** Mount the contribution and resolve the namespace service it installs. */
2737
- async function mountReportRemote(remote, resolveNamespace) {
2738
- const dispose = await remote.$mount(REPORT_REMOTE_CONTRIBUTION);
2739
- const namespace = resolveNamespace();
2740
- if (namespace === void 0) {
2741
- await dispose();
2742
- throw new Error("remote.deeppilot 未注册");
3055
+ //#region node_modules/qrcode/lib/renderer/utils.js
3056
+ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
3057
+ function hex2rgba(hex) {
3058
+ if (typeof hex === "number") hex = hex.toString();
3059
+ if (typeof hex !== "string") throw new Error("Color should be defined as hex string");
3060
+ let hexCode = hex.slice().replace("#", "").split("");
3061
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) throw new Error("Invalid hex color: " + hex);
3062
+ if (hexCode.length === 3 || hexCode.length === 4) hexCode = Array.prototype.concat.apply([], hexCode.map(function(c) {
3063
+ return [c, c];
3064
+ }));
3065
+ if (hexCode.length === 6) hexCode.push("F", "F");
3066
+ const hexValue = parseInt(hexCode.join(""), 16);
3067
+ return {
3068
+ r: hexValue >> 24 & 255,
3069
+ g: hexValue >> 16 & 255,
3070
+ b: hexValue >> 8 & 255,
3071
+ a: hexValue & 255,
3072
+ hex: "#" + hexCode.slice(0, 6).join("")
3073
+ };
2743
3074
  }
2744
- return {
2745
- namespace,
2746
- dispose
3075
+ exports.getOptions = function getOptions(options) {
3076
+ if (!options) options = {};
3077
+ if (!options.color) options.color = {};
3078
+ const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
3079
+ const width = options.width && options.width >= 21 ? options.width : void 0;
3080
+ const scale = options.scale || 4;
3081
+ return {
3082
+ width,
3083
+ scale: width ? 4 : scale,
3084
+ margin,
3085
+ color: {
3086
+ dark: hex2rgba(options.color.dark || "#000000ff"),
3087
+ light: hex2rgba(options.color.light || "#ffffffff")
3088
+ },
3089
+ type: options.type,
3090
+ rendererOpts: options.rendererOpts || {}
3091
+ };
2747
3092
  };
2748
- }
2749
- //#endregion
2750
- //#region src/client/index.ts
2751
- const CSS = [
2752
- ".pbb-section{max-width:720px;color:var(--dsw-alias-label-primary);display:flex;flex-direction:column;gap:12px}",
2753
- ".pbb-title{margin:0;font-size:18px;font-weight:600}",
2754
- ".pbb-intro{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5;margin:0}",
2755
- ".pbb-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;padding:4px 16px}",
2756
- ".pbb-field{display:flex;flex-direction:column;gap:6px;padding:12px 0}",
2757
- ".pbb-field+.pbb-field{border-top:1px solid var(--dsw-alias-border-l2)}",
2758
- ".pbb-row{display:flex;align-items:center;gap:8px}",
2759
- ".pbb-label{flex:1;font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary);min-width:0}",
2760
- ".pbb-value{font-size:13px;color:var(--dsw-alias-label-secondary);word-break:break-all;text-align:right}",
2761
- ".pbb-badge{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;white-space:nowrap}",
2762
- ".pbb-ok{color:var(--dsw-alias-state-success-primary,var(--dsw-alias-label-secondary));font-weight:500}",
2763
- ".pbb-bad{color:var(--dsw-alias-label-error);font-weight:500}",
2764
- ".pbb-table{width:100%;border-collapse:collapse;font-size:12px}",
2765
- ".pbb-table th{color:var(--dsw-alias-label-tertiary);text-align:left;font-weight:500;padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l2)}",
2766
- ".pbb-table td{padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary)}",
2767
- ".pbb-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:0}",
2768
- ".pbb-diag{font-size:11px;color:var(--dsw-alias-label-tertiary);margin:0;line-height:1.5}",
2769
- ".pbb-diagBad{color:var(--dsw-alias-label-error)}",
2770
- ".pbb-refresh{font:inherit;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:none;border:none;padding:0}",
2771
- ".pbb-refresh:hover:not(:disabled){color:var(--dsw-alias-label-primary)}",
2772
- ".pbb-refresh:disabled{cursor:default;opacity:.5}",
2773
- ".pbb-tokenRow{flex-wrap:wrap}",
2774
- ".pbb-token{max-width:100%;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-secondary);word-break:break-all}",
2775
- ".pbb-tokenActions{display:flex;align-items:center;gap:8px}",
2776
- ".pbb-action{font:inherit;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:none;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;padding:3px 8px}",
2777
- ".pbb-action:hover:not(:disabled){color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-module-platform)}",
2778
- ".pbb-action:disabled{cursor:default;opacity:.5}",
2779
- ".pbb-actionDanger:not(:disabled){color:#fff;background:var(--dsw-alias-label-error);border-color:var(--dsw-alias-label-error)}",
2780
- ".pbb-qrPanel{display:flex;flex-direction:column;align-items:center;gap:9px;padding:12px 0 4px}",
2781
- ".pbb-qrImage{width:240px;height:240px;max-width:100%;background:#fff;border-radius:10px;padding:8px;box-sizing:border-box}",
2782
- ".pbb-qrHint{max-width:420px;text-align:center;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary);margin:0}",
2783
- ".pbb-switchRow{padding:12px 0;display:flex;align-items:center;gap:12px}",
2784
- ".pbb-switchRow+.pbb-field{border-top:1px solid var(--dsw-alias-border-l2)}",
2785
- ".pbb-switchText{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}",
2786
- ".pbb-switchTitle{font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary)}",
2787
- ".pbb-dotRow{display:flex;align-items:center;gap:7px}",
2788
- ".pbb-dot{width:8px;height:8px;border-radius:50%;background:var(--dsw-alias-label-tertiary);flex:none}",
2789
- ".pbb-dotOk{background:var(--dsw-alias-state-success-primary,#22a06b)}",
2790
- ".pbb-dotWarn{background:var(--dsw-alias-state-warning-primary,#e2b203)}",
2791
- ".pbb-dotBad{background:var(--dsw-alias-label-error)}",
2792
- ".pbb-rowAction{display:flex;gap:8px;margin-top:4px}",
2793
- ".pbb-switchDesc{font-size:11px;color:var(--dsw-alias-label-tertiary);line-height:1.4}",
2794
- ".pbb-switch{appearance:none;-webkit-appearance:none;width:38px;height:22px;border-radius:999px;background:var(--dsw-alias-bg-module-platform);border:1px solid var(--dsw-alias-border-l2);position:relative;cursor:pointer;padding:0;flex:none;transition:background .15s ease}",
2795
- ".pbb-switch::after{content:\"\";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-secondary);transition:transform .15s ease,background .15s ease}",
2796
- ".pbb-switchOn{background:var(--dsw-alias-state-success-primary,var(--dsw-alias-label-secondary))}",
2797
- ".pbb-switchOn::after{transform:translateX(16px);background:#fff}",
2798
- ".pbb-switch:disabled{opacity:.5;cursor:default}",
2799
- ".pbb-help{border-top:1px solid var(--dsw-alias-border-l2);padding:12px 0}",
2800
- ".pbb-help summary{cursor:pointer;color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;user-select:none}",
2801
- ".pbb-help summary:hover{color:var(--dsw-alias-label-secondary)}",
2802
- ".pbb-helpBody{display:flex;flex-direction:column;gap:14px;padding:12px 0 2px}",
2803
- ".pbb-helpSection{display:flex;flex-direction:column;gap:6px}",
2804
- ".pbb-helpHeading{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}",
2805
- ".pbb-helpList{margin:0;padding-left:20px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.6}",
2806
- ".pbb-helpList li+li{margin-top:4px}",
2807
- ".pbb-helpText{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.6}",
2808
- ".pbb-helpCode{display:block;margin:2px 0 0;padding:10px;overflow:auto;white-space:pre-wrap;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-primary);font:11px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}",
2809
- ".pbb-helpLink{color:var(--dsw-alias-label-secondary);text-decoration:underline;text-underline-offset:2px}",
2810
- ".pbb-versionFooter{display:flex;justify-content:center;align-items:center;gap:8px;font-size:11px;color:var(--dsw-alias-label-tertiary);padding:8px 0 4px;line-height:1.4}",
2811
- ".pbb-versionFooter a{color:var(--dsw-alias-state-success-primary,#22a06b);text-decoration:none}",
2812
- ".pbb-versionFooter a:hover{text-decoration:underline;text-underline-offset:2px}"
2813
- ].join("\n");
2814
- function injectCss() {
2815
- if (typeof document === "undefined") return;
2816
- if (document.querySelector("style[data-plugin-css=\"dsh-deeppilot/page.css\"]") !== null) return;
2817
- const tag = document.createElement("style");
2818
- tag.dataset.plugin = "dsh-deeppilot";
2819
- tag.textContent = CSS;
2820
- document.head.appendChild(tag);
2821
- }
2822
- async function writeClipboard(value) {
2823
- try {
2824
- await navigator.clipboard.writeText(value);
2825
- return;
2826
- } catch {}
2827
- const textarea = document.createElement("textarea");
2828
- textarea.value = value;
2829
- textarea.style.position = "fixed";
2830
- textarea.style.opacity = "0";
2831
- document.body.appendChild(textarea);
2832
- textarea.select();
2833
- const copied = document.execCommand("copy");
2834
- textarea.remove();
2835
- if (!copied) throw new Error("浏览器拒绝了剪贴板写入");
2836
- }
2837
- /** Polls the report remote and owns the page state transitions. */
2838
- var ReportController = class {
2839
- fetchReport;
2840
- listeners = /* @__PURE__ */ new Set();
2841
- snap = {
2842
- status: "loading",
2843
- report: null,
2844
- message: ""
3093
+ exports.getScale = function getScale(qrSize, opts) {
3094
+ return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
2845
3095
  };
2846
- constructor(fetchReport) {
2847
- this.fetchReport = fetchReport;
2848
- }
2849
- state() {
2850
- return this.snap;
2851
- }
2852
- subscribe(listener) {
2853
- this.listeners.add(listener);
2854
- return () => this.listeners.delete(listener);
2855
- }
2856
- dispose() {
2857
- this.listeners.clear();
3096
+ exports.getImageWidth = function getImageWidth(qrSize, opts) {
3097
+ const scale = exports.getScale(qrSize, opts);
3098
+ return Math.floor((qrSize + opts.margin * 2) * scale);
3099
+ };
3100
+ exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
3101
+ const size = qr.modules.size;
3102
+ const data = qr.modules.data;
3103
+ const scale = exports.getScale(size, opts);
3104
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
3105
+ const scaledMargin = opts.margin * scale;
3106
+ const palette = [opts.color.light, opts.color.dark];
3107
+ for (let i = 0; i < symbolSize; i++) for (let j = 0; j < symbolSize; j++) {
3108
+ let posDst = (i * symbolSize + j) * 4;
3109
+ let pxColor = opts.color.light;
3110
+ if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
3111
+ const iSrc = Math.floor((i - scaledMargin) / scale);
3112
+ const jSrc = Math.floor((j - scaledMargin) / scale);
3113
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
3114
+ }
3115
+ imgData[posDst++] = pxColor.r;
3116
+ imgData[posDst++] = pxColor.g;
3117
+ imgData[posDst++] = pxColor.b;
3118
+ imgData[posDst] = pxColor.a;
3119
+ }
3120
+ };
3121
+ }));
3122
+ //#endregion
3123
+ //#region node_modules/qrcode/lib/renderer/canvas.js
3124
+ var require_canvas = /* @__PURE__ */ __commonJSMin(((exports) => {
3125
+ const Utils = require_utils();
3126
+ function clearCanvas(ctx, canvas, size) {
3127
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
3128
+ if (!canvas.style) canvas.style = {};
3129
+ canvas.height = size;
3130
+ canvas.width = size;
3131
+ canvas.style.height = size + "px";
3132
+ canvas.style.width = size + "px";
2858
3133
  }
2859
- async refresh() {
3134
+ function getCanvasElement() {
2860
3135
  try {
2861
- const report = await this.fetchReport();
2862
- this.snap = report !== null ? {
2863
- status: "ready",
2864
- report,
2865
- message: ""
2866
- } : {
2867
- status: "error",
2868
- report: null,
2869
- message: "报告远程未挂载(remote mount 失败)— 请确认宿主包含 typert 组合"
2870
- };
2871
- } catch (error) {
2872
- this.snap = {
2873
- status: "error",
2874
- report: null,
2875
- message: error instanceof Error ? error.message : String(error)
2876
- };
3136
+ return document.createElement("canvas");
3137
+ } catch (e) {
3138
+ throw new Error("You need to specify a canvas element");
2877
3139
  }
2878
- this.emit();
2879
3140
  }
2880
- emit() {
2881
- for (const listener of [...this.listeners]) try {
2882
- listener();
2883
- } catch {}
3141
+ exports.render = function render(qrData, canvas, options) {
3142
+ let opts = options;
3143
+ let canvasEl = canvas;
3144
+ if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
3145
+ opts = canvas;
3146
+ canvas = void 0;
3147
+ }
3148
+ if (!canvas) canvasEl = getCanvasElement();
3149
+ opts = Utils.getOptions(opts);
3150
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
3151
+ const ctx = canvasEl.getContext("2d");
3152
+ const image = ctx.createImageData(size, size);
3153
+ Utils.qrToImageData(image.data, qrData, opts);
3154
+ clearCanvas(ctx, canvasEl, size);
3155
+ ctx.putImageData(image, 0, 0);
3156
+ return canvasEl;
3157
+ };
3158
+ exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
3159
+ let opts = options;
3160
+ if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
3161
+ opts = canvas;
3162
+ canvas = void 0;
3163
+ }
3164
+ if (!opts) opts = {};
3165
+ const canvasEl = exports.render(qrData, canvas, opts);
3166
+ const type = opts.type || "image/png";
3167
+ const rendererOpts = opts.rendererOpts || {};
3168
+ return canvasEl.toDataURL(type, rendererOpts.quality);
3169
+ };
3170
+ }));
3171
+ //#endregion
3172
+ //#region node_modules/qrcode/lib/renderer/svg-tag.js
3173
+ var require_svg_tag = /* @__PURE__ */ __commonJSMin(((exports) => {
3174
+ const Utils = require_utils();
3175
+ function getColorAttrib(color, attrib) {
3176
+ const alpha = color.a / 255;
3177
+ const str = attrib + "=\"" + color.hex + "\"";
3178
+ return alpha < 1 ? str + " " + attrib + "-opacity=\"" + alpha.toFixed(2).slice(1) + "\"" : str;
3179
+ }
3180
+ function svgCmd(cmd, x, y) {
3181
+ let str = cmd + x;
3182
+ if (typeof y !== "undefined") str += " " + y;
3183
+ return str;
3184
+ }
3185
+ function qrToPath(data, size, margin) {
3186
+ let path = "";
3187
+ let moveBy = 0;
3188
+ let newRow = false;
3189
+ let lineLength = 0;
3190
+ for (let i = 0; i < data.length; i++) {
3191
+ const col = Math.floor(i % size);
3192
+ const row = Math.floor(i / size);
3193
+ if (!col && !newRow) newRow = true;
3194
+ if (data[i]) {
3195
+ lineLength++;
3196
+ if (!(i > 0 && col > 0 && data[i - 1])) {
3197
+ path += newRow ? svgCmd("M", col + margin, .5 + row + margin) : svgCmd("m", moveBy, 0);
3198
+ moveBy = 0;
3199
+ newRow = false;
3200
+ }
3201
+ if (!(col + 1 < size && data[i + 1])) {
3202
+ path += svgCmd("h", lineLength);
3203
+ lineLength = 0;
3204
+ }
3205
+ } else moveBy++;
3206
+ }
3207
+ return path;
2884
3208
  }
2885
- };
2886
- const inject = [
2887
- "slots",
2888
- "locale",
2889
- "remote",
2890
- "settingsScope"
2891
- ];
2892
- function apply(ctx) {
2893
- if (typeof document !== "undefined") injectCss();
2894
- const anyCtx = ctx;
2895
- anyCtx.locale?.register("settings.deeppilot", {
2896
- zh: { nav: "DeepPilot" },
2897
- en: { nav: "DeepPilot" }
2898
- });
2899
- let namespace;
2900
- let mountError;
2901
- const fetchReport = async () => {
2902
- if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2903
- const result = await namespace.report();
2904
- if (!result.ok) throw new Error(result.error.message ?? "report remote 调用失败");
2905
- return result.value;
3209
+ exports.render = function render(qrData, options, cb) {
3210
+ const opts = Utils.getOptions(options);
3211
+ const size = qrData.modules.size;
3212
+ const data = qrData.modules.data;
3213
+ const qrcodesize = size + opts.margin * 2;
3214
+ const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + " d=\"M0 0h" + qrcodesize + "v" + qrcodesize + "H0z\"/>";
3215
+ const path = "<path " + getColorAttrib(opts.color.dark, "stroke") + " d=\"" + qrToPath(data, size, opts.margin) + "\"/>";
3216
+ const viewBox = "viewBox=\"0 0 " + qrcodesize + " " + qrcodesize + "\"";
3217
+ const svgTag = "<svg xmlns=\"http://www.w3.org/2000/svg\" " + (!opts.width ? "" : "width=\"" + opts.width + "\" height=\"" + opts.width + "\" ") + viewBox + " shape-rendering=\"crispEdges\">" + bg + path + "</svg>\n";
3218
+ if (typeof cb === "function") cb(null, svgTag);
3219
+ return svgTag;
2906
3220
  };
2907
- const controller = new ReportController(fetchReport);
2908
- ctx.effect(() => () => controller.dispose(), "dsh-deeppilot: report controller");
2909
- const store = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)(controller.state());
2910
- controller.subscribe(() => store.set(controller.state()));
2911
- ctx.effect(() => {
2912
- let cancelled = false;
2913
- let unmount;
2914
- if (anyCtx.remote === void 0) {
2915
- mountError = "remote 服务不可用";
2916
- controller.refresh();
2917
- return () => {};
2918
- }
2919
- mountReportRemote(anyCtx.remote, () => ctx.get("remote.deeppilot")).then((mounted) => {
2920
- if (cancelled) {
2921
- mounted.dispose();
2922
- return;
3221
+ }));
3222
+ //#endregion
3223
+ //#region src/pairing-qr.ts
3224
+ var import_browser = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
3225
+ const canPromise = require_can_promise();
3226
+ const QRCode = require_qrcode();
3227
+ const CanvasRenderer = require_canvas();
3228
+ const SvgRenderer = require_svg_tag();
3229
+ function renderCanvas(renderFunc, canvas, text, opts, cb) {
3230
+ const args = [].slice.call(arguments, 1);
3231
+ const argsNum = args.length;
3232
+ const isLastArgCb = typeof args[argsNum - 1] === "function";
3233
+ if (!isLastArgCb && !canPromise()) throw new Error("Callback required as last argument");
3234
+ if (isLastArgCb) {
3235
+ if (argsNum < 2) throw new Error("Too few arguments provided");
3236
+ if (argsNum === 2) {
3237
+ cb = text;
3238
+ text = canvas;
3239
+ canvas = opts = void 0;
3240
+ } else if (argsNum === 3) {
3241
+ if (canvas.getContext && typeof cb === "undefined") {
3242
+ cb = opts;
3243
+ opts = void 0;
3244
+ } else {
3245
+ cb = opts;
3246
+ opts = text;
3247
+ text = canvas;
3248
+ canvas = void 0;
3249
+ }
2923
3250
  }
2924
- namespace = mounted.namespace;
2925
- unmount = mounted.dispose;
2926
- mountError = void 0;
2927
- controller.refresh();
2928
- }, (error) => {
2929
- mountError = error instanceof Error ? error.message : String(error);
2930
- controller.refresh();
2931
- });
2932
- return () => {
2933
- cancelled = true;
2934
- namespace = void 0;
2935
- if (unmount !== void 0) unmount();
2936
- };
2937
- }, "dsh-deeppilot: report remote mount");
2938
- const revealPairingToken = async () => {
2939
- if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2940
- const result = await namespace.revealToken();
2941
- if (!result.ok) throw new Error(result.error.message ?? "Token 读取失败");
2942
- return result.value;
2943
- };
2944
- const sendTestPush = async () => {
2945
- if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2946
- if (typeof namespace.testPush !== "function") throw new Error("宿主插件版本较旧,不支持推送测试 — 请更新 dsh-deeppilot");
2947
- const result = await namespace.testPush();
2948
- if (!result.ok) throw new Error(result.error.message ?? "推送测试失败");
2949
- return result.value;
2950
- };
2951
- const testRelayConnection = async () => {
2952
- if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2953
- if (typeof namespace.testRelay !== "function") throw new Error("宿主插件版本较旧,不支持中继测试 — 请更新 dsh-deeppilot");
2954
- const result = await namespace.testRelay();
2955
- if (!result.ok) throw new Error(result.error.message ?? "中继测试失败");
2956
- return result.value;
2957
- };
2958
- const rotatePairingToken = async () => {
2959
- if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2960
- const result = await namespace.rotateToken();
2961
- if (!result.ok) throw new Error(result.error.message ?? "Token 更换失败");
2962
- return result.value;
2963
- };
2964
- const enabledStore = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
2965
- status: "loading",
2966
- enabled: true
3251
+ } else {
3252
+ if (argsNum < 1) throw new Error("Too few arguments provided");
3253
+ if (argsNum === 1) {
3254
+ text = canvas;
3255
+ canvas = opts = void 0;
3256
+ } else if (argsNum === 2 && !canvas.getContext) {
3257
+ opts = text;
3258
+ text = canvas;
3259
+ canvas = void 0;
3260
+ }
3261
+ return new Promise(function(resolve, reject) {
3262
+ try {
3263
+ resolve(renderFunc(QRCode.create(text, opts), canvas, opts));
3264
+ } catch (e) {
3265
+ reject(e);
3266
+ }
3267
+ });
3268
+ }
3269
+ try {
3270
+ const data = QRCode.create(text, opts);
3271
+ cb(null, renderFunc(data, canvas, opts));
3272
+ } catch (e) {
3273
+ cb(e);
3274
+ }
3275
+ }
3276
+ exports.create = QRCode.create;
3277
+ exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
3278
+ exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
3279
+ exports.toString = renderCanvas.bind(null, function(data, _, opts) {
3280
+ return SvgRenderer.render(data, opts);
2967
3281
  });
2968
- const scope = anyCtx.settingsScope?.bind({ namespace: "deeppilot" });
2969
- const adoptEnabled = () => {
2970
- if (scope === void 0) return;
2971
- const snap = scope.getSnapshot();
2972
- if (snap.status === "ready" && snap.value !== void 0) enabledStore.set({
2973
- status: "ready",
2974
- enabled: snap.value.enabled !== false
2975
- });
2976
- else if (snap.status === "unavailable") enabledStore.set({
2977
- status: "unavailable",
2978
- enabled: true
2979
- });
3282
+ })))(), 1);
3283
+ const PAIRING_QR_TYPE = "deeppilot-pairing";
3284
+ function isLoopbackHostname(hostname) {
3285
+ const normalized = hostname.toLowerCase();
3286
+ return normalized === "localhost" || normalized.endsWith(".localhost") || normalized === "[::1]" || normalized === "::1" || normalized.startsWith("127.");
3287
+ }
3288
+ /** Prefer an online Funnel; otherwise turn the current web origin into a LAN target. */
3289
+ function selectPairingTarget(remote, lanAddresses, currentOrigin) {
3290
+ let origin;
3291
+ try {
3292
+ if (currentOrigin) origin = new URL(currentOrigin);
3293
+ } catch {}
3294
+ if (remote.publicURL && origin?.origin === remote.publicURL) return {
3295
+ host: remote.publicURL,
3296
+ kind: "public"
2980
3297
  };
2981
- if (scope !== void 0) {
2982
- scope.subscribe(adoptEnabled);
2983
- adoptEnabled();
2984
- }
2985
- const setDeepPilotEnabled = (value) => {
2986
- enabledStore.set({
2987
- status: "ready",
2988
- enabled: value
2989
- });
2990
- if (scope !== void 0) scope.set("enabled", value);
3298
+ if (remote.phase === "online" && remote.publicURL) return {
3299
+ host: remote.publicURL,
3300
+ kind: "public"
2991
3301
  };
2992
- const remoteEnabledStore = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
2993
- status: "loading",
2994
- enabled: false
2995
- });
2996
- const adoptRemoteEnabled = () => {
2997
- if (scope === void 0) return;
2998
- const snap = scope.getSnapshot();
2999
- if (snap.status === "ready") remoteEnabledStore.set({
3000
- status: "ready",
3001
- enabled: snap.value?.remote?.enabled === true
3002
- });
3003
- else if (snap.status === "unavailable") remoteEnabledStore.set({
3004
- status: "unavailable",
3005
- enabled: false
3006
- });
3302
+ if (origin && ["http:", "https:"].includes(origin.protocol) && !isLoopbackHostname(origin.hostname)) return {
3303
+ host: origin.origin,
3304
+ kind: "lan"
3007
3305
  };
3008
- if (scope !== void 0) {
3009
- scope.subscribe(adoptRemoteEnabled);
3010
- adoptRemoteEnabled();
3011
- }
3012
- const setDeepPilotRemoteEnabled = (value) => {
3013
- remoteEnabledStore.set({
3014
- status: "ready",
3015
- enabled: value
3016
- });
3017
- if (scope === void 0) return;
3018
- const currentRemote = scope.getSnapshot().value?.remote ?? {};
3019
- scope.set("remote", {
3020
- ...currentRemote,
3021
- enabled: value
3022
- });
3306
+ const address = lanAddresses[0];
3307
+ if (!address) return null;
3308
+ return {
3309
+ host: `${origin?.protocol === "https:" ? "https:" : "http:"}//${address}${origin?.port ? `:${origin.port}` : ""}`,
3310
+ kind: "lan"
3023
3311
  };
3024
- anyCtx.slots?.inject("settings.section", () => anyCtx.slots.register({
3025
- name: "settings.section",
3026
- id: "deeppilot",
3027
- order: 13,
3028
- label: () => {
3029
- const bind = anyCtx.locale?.bind("settings.deeppilot");
3030
- return bind ? bind("nav") : "DeepPilot";
3031
- },
3032
- locale: "settings.deeppilot",
3033
- inject: () => ({
3034
- hooks: {
3035
- deepPilotReport: store,
3036
- deepPilotEnabled: enabledStore,
3037
- deepPilotRemoteEnabled: remoteEnabledStore
3038
- },
3039
- refresh: () => {
3040
- controller.refresh();
3041
- },
3042
- revealPairingToken,
3043
- rotatePairingToken,
3044
- testRelay: testRelayConnection,
3045
- testPush: sendTestPush,
3046
- setDeepPilotEnabled,
3047
- setDeepPilotRemoteEnabled
3048
- })
3049
- }, DeepPilotSettingsPage));
3050
3312
  }
3051
- /** Visual state of the embedded Funnel: a colored dot plus its spoken label. */
3313
+ /** Encode a short-lived, single-use pairing grant without URL credentials. */
3314
+ function encodePairingQRPayload(host, grant) {
3315
+ const normalizedHost = host.trim();
3316
+ const parsed = new URL(normalizedHost);
3317
+ if (![
3318
+ "http:",
3319
+ "https:",
3320
+ "ws:",
3321
+ "wss:"
3322
+ ].includes(parsed.protocol) || parsed.hostname === "" || parsed.username !== "" || parsed.password !== "") throw new TypeError("pairing QR requires a valid HTTP(S)/WS(S) host");
3323
+ if (grant.code.trim().length < 32 || !Number.isInteger(grant.expiresAt) || grant.expiresAt <= Date.now()) throw new TypeError("pairing grant is invalid or expired");
3324
+ if (!grant.audience.startsWith("deeppilot:")) throw new TypeError("pairing audience is invalid");
3325
+ const payload = {
3326
+ v: 2,
3327
+ type: PAIRING_QR_TYPE,
3328
+ host: normalizedHost,
3329
+ code: grant.code.trim(),
3330
+ expiresAt: grant.expiresAt,
3331
+ audience: grant.audience
3332
+ };
3333
+ return JSON.stringify(payload);
3334
+ }
3335
+ function normalizeFunnelConnectionLimit(value) {
3336
+ return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 16 ? value : 8;
3337
+ }
3338
+ //#endregion
3339
+ //#region src/client/settings-page.ts
3340
+ async function writeClipboard(t, value) {
3341
+ try {
3342
+ await navigator.clipboard.writeText(value);
3343
+ return;
3344
+ } catch {}
3345
+ const textarea = document.createElement("textarea");
3346
+ textarea.value = value;
3347
+ textarea.style.position = "fixed";
3348
+ textarea.style.opacity = "0";
3349
+ document.body.appendChild(textarea);
3350
+ textarea.select();
3351
+ const copied = document.execCommand("copy");
3352
+ textarea.remove();
3353
+ if (!copied) throw new Error(t("clipboard.rejected"));
3354
+ }
3355
+ /** Visual state of the embedded Funnel: a colored dot plus its spoken label.
3356
+ * The label is a function because the surrounding constant lives at module
3357
+ * scope where the locale-bound t() is not in scope; the page resolves the
3358
+ * label at render time via t(props.t, ...). */
3052
3359
  const REMOTE_PHASE_META = {
3053
3360
  disabled: {
3054
3361
  dot: "",
3055
- label: "未启用"
3362
+ labelKey: "phase.disabled"
3056
3363
  },
3057
3364
  starting: {
3058
3365
  dot: " pbb-dotWarn",
3059
- label: "正在启动"
3366
+ labelKey: "phase.starting"
3060
3367
  },
3061
3368
  login_required: {
3062
3369
  dot: " pbb-dotWarn",
3063
- label: "等待 Tailscale 授权"
3370
+ labelKey: "phase.login_required"
3064
3371
  },
3065
3372
  online: {
3066
3373
  dot: " pbb-dotOk",
3067
- label: "远程连接已就绪"
3374
+ labelKey: "phase.online"
3068
3375
  },
3069
3376
  error: {
3070
3377
  dot: " pbb-dotBad",
3071
- label: "远程连接失败"
3378
+ labelKey: "phase.error"
3072
3379
  },
3073
3380
  unavailable: {
3074
3381
  dot: " pbb-dotBad",
3075
- label: "远程 helper 不可用"
3382
+ labelKey: "phase.unavailable"
3076
3383
  },
3077
3384
  stopped: {
3078
3385
  dot: "",
3079
- label: "已停止"
3386
+ labelKey: "phase.stopped"
3080
3387
  }
3081
3388
  };
3082
3389
  /** Slot component: hooks come from the slot renderer, named use<Key>. */
3083
3390
  function DeepPilotSettingsPage(props) {
3084
- const [revealedToken, setRevealedToken] = (0, react.useState)(null);
3085
- const [tokenBusy, setTokenBusy] = (0, react.useState)(false);
3086
- const [tokenMessage, setTokenMessage] = (0, react.useState)("");
3087
- const [rotateArmed, setRotateArmed] = (0, react.useState)(false);
3088
- const [remoteMessage, setRemoteMessage] = (0, react.useState)("");
3391
+ const [addressMessage, setAddressMessage] = (0, react.useState)("");
3392
+ const [remoteLimitDraft, setRemoteLimitDraft] = (0, react.useState)(String(8));
3393
+ const [remoteLimitMessage, setRemoteLimitMessage] = (0, react.useState)("");
3089
3394
  const [qrDataURL, setQRDataURL] = (0, react.useState)(null);
3395
+ const [pairingGrant, setPairingGrant] = (0, react.useState)(null);
3090
3396
  const [qrBusy, setQRBusy] = (0, react.useState)(false);
3091
3397
  const [qrMessage, setQRMessage] = (0, react.useState)("");
3092
3398
  const [relayTestBusy, setRelayTestBusy] = (0, react.useState)(false);
@@ -3095,6 +3401,8 @@ window.__ModuleLoader__.load({
3095
3401
  const [pushTestBusy, setPushTestBusy] = (0, react.useState)(false);
3096
3402
  const [pushTestResult, setPushTestResult] = (0, react.useState)(null);
3097
3403
  const [pushTestError, setPushTestError] = (0, react.useState)("");
3404
+ const [deviceBusy, setDeviceBusy] = (0, react.useState)(null);
3405
+ const [deviceMessage, setDeviceMessage] = (0, react.useState)("");
3098
3406
  (0, react.useEffect)(() => {
3099
3407
  if (typeof props.refresh !== "function") return;
3100
3408
  props.refresh();
@@ -3104,7 +3412,7 @@ window.__ModuleLoader__.load({
3104
3412
  const sendPushTest = () => {
3105
3413
  if (pushTestBusy) return;
3106
3414
  if (typeof props.testPush !== "function") {
3107
- setPushTestError("宿主插件版本较旧,不支持推送测试");
3415
+ setPushTestError(translateWith(props.t, "push.staleHost"));
3108
3416
  return;
3109
3417
  }
3110
3418
  setPushTestBusy(true);
@@ -3120,7 +3428,7 @@ window.__ModuleLoader__.load({
3120
3428
  const runRelayTest = () => {
3121
3429
  if (relayTestBusy) return;
3122
3430
  if (typeof props.testRelay !== "function") {
3123
- setRelayTestError("宿主插件版本较旧,不支持中继测试");
3431
+ setRelayTestError(translateWith(props.t, "push.staleHostRelay"));
3124
3432
  return;
3125
3433
  }
3126
3434
  setRelayTestBusy(true);
@@ -3134,33 +3442,21 @@ window.__ModuleLoader__.load({
3134
3442
  });
3135
3443
  };
3136
3444
  (0, react.useEffect)(() => {
3137
- if (revealedToken === null) return;
3138
- const timer = globalThis.setTimeout(() => {
3139
- setRevealedToken(null);
3140
- setTokenMessage("Token 已自动隐藏");
3141
- }, 3e4);
3142
- return () => globalThis.clearTimeout(timer);
3143
- }, [revealedToken]);
3144
- (0, react.useEffect)(() => {
3145
- if (!tokenMessage) return;
3146
- const timer = globalThis.setTimeout(() => setTokenMessage(""), 4e3);
3147
- return () => globalThis.clearTimeout(timer);
3148
- }, [tokenMessage]);
3149
- (0, react.useEffect)(() => {
3150
- if (!rotateArmed) return;
3151
- const timer = globalThis.setTimeout(() => setRotateArmed(false), 5e3);
3445
+ if (!addressMessage) return;
3446
+ const timer = globalThis.setTimeout(() => setAddressMessage(""), 2500);
3152
3447
  return () => globalThis.clearTimeout(timer);
3153
- }, [rotateArmed]);
3448
+ }, [addressMessage]);
3154
3449
  (0, react.useEffect)(() => {
3155
- if (!remoteMessage) return;
3156
- const timer = globalThis.setTimeout(() => setRemoteMessage(""), 2500);
3450
+ if (!remoteLimitMessage) return;
3451
+ const timer = globalThis.setTimeout(() => setRemoteLimitMessage(""), 4e3);
3157
3452
  return () => globalThis.clearTimeout(timer);
3158
- }, [remoteMessage]);
3453
+ }, [remoteLimitMessage]);
3159
3454
  (0, react.useEffect)(() => {
3160
3455
  if (qrDataURL === null) return;
3161
3456
  const timer = globalThis.setTimeout(() => {
3162
3457
  setQRDataURL(null);
3163
- setQRMessage("配对二维码已自动隐藏");
3458
+ setPairingGrant(null);
3459
+ setQRMessage(translateWith(props.t, "pair.qrAutoHidden"));
3164
3460
  }, 6e4);
3165
3461
  return () => globalThis.clearTimeout(timer);
3166
3462
  }, [qrDataURL]);
@@ -3175,10 +3471,12 @@ window.__ModuleLoader__.load({
3175
3471
  let switchReady = false;
3176
3472
  let remoteEnabled = false;
3177
3473
  let remoteSwitchReady = false;
3474
+ let remoteConnectionLimit = 8;
3475
+ let remoteConnectionLimitReady = false;
3178
3476
  let failed = false;
3179
3477
  try {
3180
3478
  if (typeof props.useDeepPilotReport !== "function") {
3181
- diag.push("useDeepPilotReport hook 缺失");
3479
+ diag.push(translateWith(props.t, "diag.missingReportHook"));
3182
3480
  failed = true;
3183
3481
  } else {
3184
3482
  const state = props.useDeepPilotReport((s) => s);
@@ -3192,140 +3490,144 @@ window.__ModuleLoader__.load({
3192
3490
  const state = props.useDeepPilotEnabled((s) => s);
3193
3491
  enabled = state.enabled;
3194
3492
  switchReady = state.status === "ready";
3195
- if (state.status === "unavailable") diag.push("设置命名空间不可用(settingsScope 未提供)");
3196
- } else diag.push("useDeepPilotEnabled hook 缺失");
3197
- if (typeof props.refresh !== "function") diag.push("refresh 回调缺失");
3198
- if (typeof props.revealPairingToken !== "function") diag.push("revealPairingToken 回调缺失");
3199
- if (typeof props.rotatePairingToken !== "function") diag.push("rotatePairingToken 回调缺失");
3200
- if (typeof props.testRelay !== "function") diag.push("testRelay 回调缺失");
3201
- if (typeof props.testPush !== "function") diag.push("testPush 回调缺失");
3202
- if (typeof props.setDeepPilotEnabled !== "function") diag.push("setDeepPilotEnabled 回调缺失");
3493
+ if (state.status === "unavailable") diag.push(translateWith(props.t, "diag.settingsUnavailable"));
3494
+ } else diag.push(translateWith(props.t, "diag.missingEnabledHook"));
3495
+ if (typeof props.refresh !== "function") diag.push(translateWith(props.t, "diag.missingRefresh"));
3496
+ if (typeof props.beginPairing !== "function") diag.push(translateWith(props.t, "diag.missingReveal"));
3497
+ if (typeof props.revokeDevice !== "function") diag.push(translateWith(props.t, "diag.missingRotate"));
3498
+ if (typeof props.testRelay !== "function") diag.push(translateWith(props.t, "diag.missingTestRelay"));
3499
+ if (typeof props.testPush !== "function") diag.push(translateWith(props.t, "diag.missingTestPush"));
3500
+ if (typeof props.setDeepPilotEnabled !== "function") diag.push(translateWith(props.t, "diag.missingSetEnabled"));
3203
3501
  if (typeof props.useDeepPilotRemoteEnabled === "function") {
3204
3502
  const state = props.useDeepPilotRemoteEnabled((s) => s);
3205
3503
  remoteEnabled = state.enabled;
3206
3504
  remoteSwitchReady = state.status === "ready";
3207
- } else diag.push("useDeepPilotRemoteEnabled hook 缺失");
3208
- if (typeof props.setDeepPilotRemoteEnabled !== "function") diag.push("setDeepPilotRemoteEnabled 回调缺失");
3505
+ } else diag.push(translateWith(props.t, "diag.missingRemoteEnabledHook"));
3506
+ if (typeof props.setDeepPilotRemoteEnabled !== "function") diag.push(translateWith(props.t, "diag.missingSetRemote"));
3507
+ if (typeof props.useDeepPilotRemoteConnectionLimit === "function") {
3508
+ const state = props.useDeepPilotRemoteConnectionLimit((s) => s);
3509
+ remoteConnectionLimit = state.value;
3510
+ remoteConnectionLimitReady = state.status === "ready";
3511
+ } else diag.push(translateWith(props.t, "diag.missingRemoteLimitHook"));
3512
+ if (typeof props.setDeepPilotRemoteConnectionLimit !== "function") diag.push(translateWith(props.t, "diag.missingSetRemoteLimit"));
3209
3513
  } catch (error) {
3210
- diag.push("渲染异常: " + (error instanceof Error ? error.message : String(error)));
3514
+ diag.push(translateWith(props.t, "diag.renderError") + (error instanceof Error ? error.message : String(error)));
3211
3515
  failed = true;
3212
3516
  }
3213
- const pairingTarget = report === null ? null : selectPairingTarget(report.remote, report.lanAddresses, typeof window === "undefined" ? void 0 : window.location.origin);
3214
3517
  (0, react.useEffect)(() => {
3215
- setQRDataURL(null);
3216
- }, [pairingTarget?.host]);
3217
- const toggleToken = () => {
3218
- if (revealedToken !== null) {
3219
- setRevealedToken(null);
3220
- setTokenMessage("");
3221
- return;
3222
- }
3223
- if (typeof props.revealPairingToken !== "function") return;
3224
- setTokenBusy(true);
3225
- setTokenMessage("");
3226
- props.revealPairingToken().then((token) => {
3227
- setRevealedToken(token);
3228
- }, (error) => {
3229
- setTokenMessage("Token 读取失败:" + (error instanceof Error ? error.message : String(error)));
3230
- }).finally(() => setTokenBusy(false));
3231
- };
3232
- const copyToken = () => {
3233
- if (typeof props.revealPairingToken !== "function") return;
3234
- setTokenBusy(true);
3235
- setTokenMessage("");
3236
- (revealedToken !== null ? Promise.resolve(revealedToken) : props.revealPairingToken()).then((value) => writeClipboard(value)).then(() => setTokenMessage("已复制到剪贴板"), (error) => {
3237
- setTokenMessage("复制失败:" + (error instanceof Error ? error.message : String(error)));
3238
- }).finally(() => setTokenBusy(false));
3239
- };
3240
- const rotateToken = () => {
3241
- if (typeof props.rotatePairingToken !== "function") return;
3242
- if (!rotateArmed) {
3243
- setRotateArmed(true);
3244
- setRevealedToken(null);
3245
- setQRDataURL(null);
3246
- setTokenMessage("更换会使当前 Token 立即失效、断开所有手机连接;5 秒内再次点击确认。");
3518
+ setRemoteLimitDraft(String(remoteConnectionLimit));
3519
+ }, [remoteConnectionLimit]);
3520
+ const parsedRemoteLimit = Number(remoteLimitDraft);
3521
+ const remoteLimitValid = Number.isInteger(parsedRemoteLimit) && parsedRemoteLimit >= 1 && parsedRemoteLimit <= 16;
3522
+ const applyRemoteLimit = () => {
3523
+ if (!remoteLimitValid || typeof props.setDeepPilotRemoteConnectionLimit !== "function") {
3524
+ setRemoteLimitMessage(translateWith(props.t, "remote.limitInvalid"));
3247
3525
  return;
3248
3526
  }
3249
- setRotateArmed(false);
3250
- setTokenBusy(true);
3251
- setTokenMessage("");
3252
- props.rotatePairingToken().then((token) => {
3253
- setRevealedToken(token);
3254
- setTokenMessage("新 Token 已生效,旧 Token 已失效;请重新配对所有设备。");
3527
+ setRemoteLimitMessage("");
3528
+ props.setDeepPilotRemoteConnectionLimit(parsedRemoteLimit).then(() => {
3529
+ setRemoteLimitMessage(translateWith(props.t, "remote.limitApplied"));
3255
3530
  }, (error) => {
3256
- setTokenMessage("更换失败:" + (error instanceof Error ? error.message : String(error)));
3257
- }).finally(() => setTokenBusy(false));
3531
+ setRemoteLimitMessage(translateWith(props.t, "remote.limitFailed") + (error instanceof Error ? error.message : String(error)));
3532
+ });
3258
3533
  };
3534
+ const pairingTarget = report === null ? null : selectPairingTarget(report.remote, report.lanAddresses, typeof window === "undefined" ? void 0 : window.location.origin);
3535
+ (0, react.useEffect)(() => {
3536
+ setQRDataURL(null);
3537
+ setPairingGrant(null);
3538
+ }, [pairingTarget?.host]);
3259
3539
  const copyRemoteURL = (url) => {
3260
- setRemoteMessage("");
3261
- writeClipboard(url).then(() => {
3262
- setRemoteMessage("公网地址已复制");
3540
+ setAddressMessage("");
3541
+ writeClipboard(props.t, url).then(() => {
3542
+ setAddressMessage(translateWith(props.t, "pair.publicCopyDone"));
3263
3543
  }, (error) => {
3264
- setRemoteMessage("复制失败:" + (error instanceof Error ? error.message : String(error)));
3544
+ setAddressMessage(translateWith(props.t, "pair.publicCopyFailed") + (error instanceof Error ? error.message : String(error)));
3265
3545
  });
3266
3546
  };
3267
3547
  const showPairingQR = () => {
3268
- if (typeof props.revealPairingToken !== "function" || pairingTarget === null) return;
3548
+ if (typeof props.beginPairing !== "function" || pairingTarget === null) return;
3269
3549
  setQRBusy(true);
3270
3550
  setQRMessage("");
3271
3551
  setQRDataURL(null);
3272
- props.revealPairingToken().then((pairingToken) => import_browser.toString(encodePairingQRPayload(pairingTarget.host, pairingToken), {
3273
- type: "svg",
3274
- errorCorrectionLevel: "M",
3275
- margin: 2,
3276
- width: 512
3277
- })).then((svg) => setQRDataURL("data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg)), (error) => {
3278
- setQRMessage("二维码生成失败:" + (error instanceof Error ? error.message : String(error)));
3552
+ setPairingGrant(null);
3553
+ props.beginPairing().then(async (grant) => ({
3554
+ grant,
3555
+ svg: await import_browser.toString(encodePairingQRPayload(pairingTarget.host, grant), {
3556
+ type: "svg",
3557
+ errorCorrectionLevel: "M",
3558
+ margin: 2,
3559
+ width: 512
3560
+ })
3561
+ })).then(({ grant, svg }) => {
3562
+ setPairingGrant(grant);
3563
+ setQRDataURL("data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg));
3564
+ }, (error) => {
3565
+ setQRMessage(translateWith(props.t, "pair.qrFailed") + (error instanceof Error ? error.message : String(error)));
3279
3566
  }).finally(() => setQRBusy(false));
3280
3567
  };
3568
+ const hidePairingQR = () => {
3569
+ setQRDataURL(null);
3570
+ setPairingGrant(null);
3571
+ };
3572
+ const copyPairingCode = () => {
3573
+ if (pairingGrant === null) return;
3574
+ setQRMessage("");
3575
+ writeClipboard(props.t, pairingGrant.code).then(() => {
3576
+ setQRMessage(translateWith(props.t, "pair.codeCopyDone"));
3577
+ }, (error) => {
3578
+ setQRMessage(translateWith(props.t, "pair.codeCopyFailed") + (error instanceof Error ? error.message : String(error)));
3579
+ });
3580
+ };
3281
3581
  const primaryRows = [];
3282
3582
  const advancedRows = [];
3283
3583
  if (report !== null) {
3284
3584
  primaryRows.push((0, react.createElement)("div", {
3285
3585
  className: "pbb-field",
3286
3586
  key: "conn"
3287
- }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "当前连接"), (0, react.createElement)("span", { className: "pbb-value" }, String(report.activeConnections)))), (0, react.createElement)("div", {
3587
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "panel.activeConnections")), (0, react.createElement)("span", { className: "pbb-value" }, String(report.activeConnections)))), (0, react.createElement)("div", {
3288
3588
  className: "pbb-field",
3289
- key: "token"
3290
- }, (0, react.createElement)("div", { className: "pbb-row pbb-tokenRow" }, (0, react.createElement)("span", { className: "pbb-label" }, "配对 Token"), (0, react.createElement)("code", { className: "pbb-token " + (report.tokenReady ? "pbb-ok" : "pbb-bad") }, report.tokenReady ? revealedToken ?? "••••••••••••" : "未生成"), report.tokenReady ? (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("button", {
3291
- type: "button",
3292
- className: "pbb-action",
3293
- disabled: tokenBusy,
3294
- onClick: toggleToken
3295
- }, tokenBusy ? "读取中…" : revealedToken === null ? "显示" : "隐藏"), (0, react.createElement)("button", {
3296
- type: "button",
3297
- className: "pbb-action",
3298
- disabled: tokenBusy,
3299
- onClick: copyToken
3300
- }, "复制"), (0, react.createElement)("button", {
3301
- type: "button",
3302
- className: "pbb-action" + (rotateArmed ? " pbb-actionDanger" : ""),
3303
- disabled: tokenBusy,
3304
- onClick: rotateToken
3305
- }, rotateArmed ? "确认更换?" : tokenBusy ? "更换中…" : "更换")) : null), tokenMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, tokenMessage) : null));
3589
+ key: "identity"
3590
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "panel.identity")), (0, react.createElement)("code", { className: "pbb-token " + (report.pairingReady ? "pbb-ok" : "pbb-bad") }, report.pairingReady ? translateWith(props.t, "panel.identityReady") : translateWith(props.t, "panel.identityNotReady")))));
3306
3591
  advancedRows.push((0, react.createElement)("div", {
3307
3592
  className: "pbb-field",
3308
3593
  key: "proto"
3309
- }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "协议版本"), (0, react.createElement)("span", { className: "pbb-value" }, "v" + String(report.protocolVersion)))), (0, react.createElement)("div", {
3594
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "advanced.protocolVersion")), (0, react.createElement)("span", { className: "pbb-value" }, "v" + String(report.protocolVersion)))), (0, react.createElement)("div", {
3310
3595
  className: "pbb-field",
3311
3596
  key: "server"
3312
- }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "服务器版本"), (0, react.createElement)("span", { className: "pbb-value" }, report.serverVersion))), (0, react.createElement)("div", {
3597
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "advanced.serverVersion")), (0, react.createElement)("span", { className: "pbb-value" }, report.serverVersion))), (0, react.createElement)("div", {
3313
3598
  className: "pbb-field",
3314
3599
  key: "path"
3315
- }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "Token 路径"), (0, react.createElement)("span", { className: "pbb-value" }, report.tokenPath))), (0, react.createElement)("div", {
3600
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "advanced.identityPath")), (0, react.createElement)("span", { className: "pbb-value" }, report.identityPath))), (0, react.createElement)("div", {
3316
3601
  className: "pbb-field",
3317
3602
  key: "buffer"
3318
- }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "重放缓冲上限"), (0, react.createElement)("span", { className: "pbb-value" }, String(report.historyBufferMax) + " "))));
3603
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "advanced.bufferMax")), (0, react.createElement)("span", { className: "pbb-value" }, String(report.historyBufferMax) + translateWith(props.t, "advanced.frames")))));
3319
3604
  }
3320
- const deviceTable = report !== null && report.devices.length > 0 ? (0, react.createElement)("table", { className: "pbb-table" }, (0, react.createElement)("thead", null, (0, react.createElement)("tr", null, (0, react.createElement)("th", null, "设备"), (0, react.createElement)("th", null, "App 版本"), (0, react.createElement)("th", null, "离线推送"), (0, react.createElement)("th", null, "最近在线"))), (0, react.createElement)("tbody", null, report.devices.map((d) => (0, react.createElement)("tr", { key: d.deviceId }, (0, react.createElement)("td", null, d.deviceName), (0, react.createElement)("td", null, d.appVersion), (0, react.createElement)("td", null, d.apns ? "已注册(" + (d.apns.environment === "production" ? "生产" : "开发") + ")" : "未注册"), (0, react.createElement)("td", null, new Date(d.lastSeenTs).toLocaleString()))))) : (0, react.createElement)("p", { className: "pbb-empty" }, "还没有设备配对过。在 iPhone 上的 DeepPilot App 中扫码或填入本机地址与 Token 即可配对。");
3321
- const switchTitle = "DeepPilot 连接";
3322
- const switchDesc = switchReady ? enabled ? "已开启:接受手机连接。" : "已关闭:不接受手机连接。" : "正在读取配置…";
3605
+ const revokeDevice = (deviceId, name) => {
3606
+ if (typeof props.revokeDevice !== "function") return;
3607
+ if (typeof window !== "undefined" && !window.confirm(translateWith(props.t, "devices.revokeConfirm", { name }))) return;
3608
+ setDeviceBusy(deviceId);
3609
+ setDeviceMessage("");
3610
+ props.revokeDevice(deviceId).then(() => {
3611
+ setDeviceMessage(translateWith(props.t, "devices.revoked"));
3612
+ }, (error) => {
3613
+ setDeviceMessage(translateWith(props.t, "devices.revokeFailed") + (error instanceof Error ? error.message : String(error)));
3614
+ }).finally(() => setDeviceBusy(null));
3615
+ };
3616
+ const visibleDevices = report?.devices.filter((device) => device.revokedAt === void 0) ?? [];
3617
+ const deviceTable = visibleDevices.length > 0 ? (0, react.createElement)("table", { className: "pbb-table" }, (0, react.createElement)("thead", null, (0, react.createElement)("tr", null, (0, react.createElement)("th", null, translateWith(props.t, "devices.col.name")), (0, react.createElement)("th", null, translateWith(props.t, "devices.col.fingerprint")), (0, react.createElement)("th", null, translateWith(props.t, "devices.col.lastSeen")), (0, react.createElement)("th", null, translateWith(props.t, "devices.col.actions")))), (0, react.createElement)("tbody", null, visibleDevices.map((d) => (0, react.createElement)("tr", { key: d.deviceId }, (0, react.createElement)("td", null, d.deviceName, (0, react.createElement)("div", { className: "pbb-diag" }, d.appVersion)), (0, react.createElement)("td", null, (0, react.createElement)("code", { className: "pbb-token" }, d.fingerprint.slice(0, 12))), (0, react.createElement)("td", null, new Date(d.lastSeenTs).toLocaleString()), (0, react.createElement)("td", null, (0, react.createElement)("button", {
3618
+ type: "button",
3619
+ className: "pbb-action pbb-actionDanger",
3620
+ disabled: deviceBusy === d.deviceId,
3621
+ onClick: () => revokeDevice(d.deviceId, d.deviceName)
3622
+ }, translateWith(props.t, "devices.revoke"))))))) : (0, react.createElement)("p", { className: "pbb-empty" }, translateWith(props.t, "devices.empty"));
3623
+ const switchTitle = translateWith(props.t, "master.title");
3624
+ const switchDesc = switchReady ? enabled ? translateWith(props.t, "master.on") : translateWith(props.t, "master.off") : translateWith(props.t, "master.loading");
3323
3625
  return (0, react.createElement)("div", { className: "pbb-section" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("h2", { className: "pbb-title" }, "DeepPilot"), (0, react.createElement)("div", { style: { flex: "1" } }), (0, react.createElement)("button", {
3324
3626
  className: "pbb-refresh",
3325
3627
  onClick: () => {
3326
3628
  if (typeof props.refresh === "function") props.refresh();
3327
3629
  }
3328
- }, "刷新")), (0, react.createElement)("p", { className: "pbb-intro" }, "把 iPhone 与这台电脑上的 DeepSeek Harness(DSH)连接起来(协议 v1)。"), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-switchRow" }, (0, react.createElement)("div", { className: "pbb-switchText" }, (0, react.createElement)("span", { className: "pbb-switchTitle" }, switchTitle), (0, react.createElement)("span", { className: "pbb-switchDesc" }, switchDesc)), (0, react.createElement)("button", {
3630
+ }, translateWith(props.t, "meta.refresh"))), (0, react.createElement)("p", { className: "pbb-intro" }, translateWith(props.t, "meta.intro")), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-switchRow" }, (0, react.createElement)("div", { className: "pbb-switchText" }, (0, react.createElement)("span", { className: "pbb-switchTitle" }, switchTitle), (0, react.createElement)("span", { className: "pbb-switchDesc" }, switchDesc)), (0, react.createElement)("button", {
3329
3631
  type: "button",
3330
3632
  role: "switch",
3331
3633
  "aria-checked": enabled,
@@ -3338,65 +3640,387 @@ window.__ModuleLoader__.load({
3338
3640
  })), (0, react.createElement)("div", { className: "pbb-switchRow" }, (0, react.createElement)("div", { className: "pbb-switchText" }, (0, react.createElement)("span", { className: "pbb-switchTitle pbb-dotRow" }, (0, react.createElement)("span", {
3339
3641
  className: "pbb-dot" + (report !== null ? REMOTE_PHASE_META[report.remote.phase].dot : ""),
3340
3642
  role: "img",
3341
- "aria-label": report !== null ? REMOTE_PHASE_META[report.remote.phase].label : "状态未知",
3342
- title: report !== null ? REMOTE_PHASE_META[report.remote.phase].label : void 0
3343
- }), "远程连接(Tailscale Funnel)"), (0, react.createElement)("span", { className: "pbb-switchDesc" }, remoteSwitchReady ? remoteEnabled ? "已配置:内嵌 Funnel 会自动启动并同步状态。" : "关闭:仅保留局域网连接。" : "正在读取配置…"), report !== null && report.remote.phase === "login_required" && typeof report.remote.authURL === "string" && report.remote.authURL.startsWith("https://") ? (0, react.createElement)("div", { className: "pbb-rowAction" }, (0, react.createElement)("a", {
3643
+ "aria-label": report !== null ? translateWith(props.t, REMOTE_PHASE_META[report.remote.phase].labelKey) : translateWith(props.t, "phase.unknown"),
3644
+ title: report !== null ? translateWith(props.t, REMOTE_PHASE_META[report.remote.phase].labelKey) : void 0
3645
+ }), translateWith(props.t, "remote.title")), (0, react.createElement)("span", { className: "pbb-switchDesc" }, remoteSwitchReady ? remoteEnabled ? translateWith(props.t, "remote.on") : translateWith(props.t, "remote.off") : translateWith(props.t, "master.loading")), report !== null && report.remote.phase === "login_required" && typeof report.remote.authURL === "string" && report.remote.authURL.startsWith("https://") ? (0, react.createElement)("div", { className: "pbb-rowAction" }, (0, react.createElement)("a", {
3344
3646
  className: "pbb-action",
3345
3647
  href: report.remote.authURL,
3346
3648
  target: "_blank",
3347
3649
  rel: "noreferrer"
3348
- }, "打开授权页面")) : null, report !== null && report.remote.message && (report.remote.phase === "error" || report.remote.phase === "unavailable") ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, report.remote.message) : null, remoteMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, remoteMessage) : null), (0, react.createElement)("button", {
3650
+ }, translateWith(props.t, "remote.openAuth"))) : null, report !== null && report.remote.message && (report.remote.phase === "error" || report.remote.phase === "unavailable") ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, report.remote.message) : null), (0, react.createElement)("button", {
3349
3651
  type: "button",
3350
3652
  role: "switch",
3351
3653
  "aria-checked": remoteEnabled,
3352
- "aria-label": "远程连接",
3654
+ "aria-label": translateWith(props.t, "remote.title"),
3353
3655
  disabled: !remoteSwitchReady,
3354
3656
  className: "pbb-switch" + (remoteEnabled ? " pbb-switchOn" : ""),
3355
3657
  onClick: () => {
3356
3658
  if (typeof props.setDeepPilotRemoteEnabled === "function") props.setDeepPilotRemoteEnabled(!remoteEnabled);
3357
3659
  }
3358
- })), (0, react.createElement)("details", { className: "pbb-help" }, (0, react.createElement)("summary", null, "远程连接帮助"), (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "推荐设置流程"), (0, react.createElement)("ol", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "先打开“DeepPilot 连接”,再打开“远程连接(Tailscale Funnel)”。"), (0, react.createElement)("li", null, "状态变为“等待 Tailscale 授权”后,点击“打开授权页面”。"), (0, react.createElement)("li", null, "使用有权管理此 Tailnet 的账号登录,并按授权页提示启用 Funnel。通常需要 Owner、Admin 或 Network admin 权限。"), (0, react.createElement)("li", null, "返回此页面并点击“刷新”。远程连接标题旁出现绿点后,即可扫描下方二维码添加手机。")), (0, react.createElement)("p", { className: "pbb-helpText" }, "插件已内嵌 Tailscale 网络组件,这台电脑和手机都不需要另外安装 Tailscale App;但首次启用仍需由 Tailnet 管理员授权。")), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "授权页未自动完成时:开启 HTTPS"), (0, react.createElement)("ol", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "打开 Tailscale 管理后台的 Network → DNS。"), (0, react.createElement)("li", null, "确认 MagicDNS 已开启。"), (0, react.createElement)("li", null, "在 HTTPS Certificates 中点击 Enable HTTPS。")), (0, react.createElement)("p", { className: "pbb-helpText" }, "启用 HTTPS 后,设备的完整域名会写入公开的证书透明度日志。如果设备名包含敏感信息,请先在 Tailscale 中重命名设备。")), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "授权页未自动完成时:允许 Funnel"), (0, react.createElement)("p", { className: "pbb-helpText" }, "打开 Access controls → Definitions,选择 Node attributes。在现有 nodeAttrs 数组中追加下面这一项;不要覆盖已有访问规则,也不要创建第二个 nodeAttrs 顶层字段。"), (0, react.createElement)("code", { className: "pbb-helpCode" }, "\"nodeAttrs\": [\n {\n \"target\": [\"autogroup:member\"],\n \"attr\": [\"funnel\"],\n },\n],"), (0, react.createElement)("p", { className: "pbb-helpText" }, "保存策略后回到本页刷新。公共 DNS 和权限变更可能需要几分钟生效。")), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "常见问题"), (0, react.createElement)("ul", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "提示“HTTPS must be enabled”:完成上面的 HTTPS Certificates 设置。"), (0, react.createElement)("li", null, "提示“Funnel not available”:确认 nodeAttrs 已保存,并且当前节点属于规则的 target。"), (0, react.createElement)("li", null, "已有公网地址但手机超时:等待几分钟后重试,同时确认这台电脑未休眠、DSH 正在运行,再重新扫描最新二维码。"), (0, react.createElement)("li", null, "没有公网地址:检查 Tailscale 授权是否完成,然后点击“刷新”或重启 DSH。"))), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "安全说明"), (0, react.createElement)("ul", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "Funnel 公网地址可从互联网访问,但手机接口仍需要配对 Token。不要分享二维码、Token 或包含它们的截图。"), (0, react.createElement)("li", null, "怀疑 Token 泄露时,点击上方“更换”生成新 Token:旧 Token 立即失效,所有已连接设备会被断开并需要重新配对。"), (0, react.createElement)("li", null, "插件只通过 Funnel 转发 /phone 和 /phone/health,不会新增 3098 端口。"), (0, react.createElement)("li", null, "局域网连接沿用 DSH 的 3080 端口;仅在可信网络中使用,不建议直接把 3080 暴露到公网。"), (0, react.createElement)("li", null, "关闭远程连接开关会停止 Funnel,但不会影响可用的局域网连接。")), (0, react.createElement)("p", { className: "pbb-helpText" }, "更多信息:", (0, react.createElement)("a", {
3660
+ })), (0, react.createElement)("details", { className: "pbb-help" }, (0, react.createElement)("summary", null, translateWith(props.t, "remote.advancedSettings")), (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-limitRow pbb-limitNested" }, (0, react.createElement)("div", { className: "pbb-switchText" }, (0, react.createElement)("label", {
3661
+ className: "pbb-switchTitle",
3662
+ htmlFor: "deeppilot-funnel-source-limit"
3663
+ }, translateWith(props.t, "remote.limitTitle")), (0, react.createElement)("span", { className: "pbb-switchDesc" }, translateWith(props.t, "remote.limitDescription")), !remoteLimitValid ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, translateWith(props.t, "remote.limitInvalid")) : remoteLimitMessage ? (0, react.createElement)("p", { className: "pbb-diag" + (remoteLimitMessage.startsWith(translateWith(props.t, "remote.limitFailed")) ? " pbb-diagBad" : "") }, remoteLimitMessage) : null), (0, react.createElement)("div", { className: "pbb-limitControl" }, (0, react.createElement)("input", {
3664
+ id: "deeppilot-funnel-source-limit",
3665
+ className: "pbb-numberInput",
3666
+ type: "number",
3667
+ min: 1,
3668
+ max: 16,
3669
+ step: 1,
3670
+ inputMode: "numeric",
3671
+ value: remoteLimitDraft,
3672
+ disabled: !remoteConnectionLimitReady,
3673
+ "aria-label": translateWith(props.t, "remote.limitTitle"),
3674
+ onChange: (event) => setRemoteLimitDraft(event.currentTarget.value),
3675
+ onKeyDown: (event) => {
3676
+ if (event.key === "Enter") {
3677
+ event.preventDefault();
3678
+ applyRemoteLimit();
3679
+ }
3680
+ }
3681
+ }), (0, react.createElement)("button", {
3682
+ type: "button",
3683
+ className: "pbb-action",
3684
+ disabled: !remoteConnectionLimitReady || !remoteLimitValid || parsedRemoteLimit === remoteConnectionLimit,
3685
+ onClick: applyRemoteLimit
3686
+ }, translateWith(props.t, "remote.limitApply")))))), (0, react.createElement)("details", { className: "pbb-help" }, (0, react.createElement)("summary", null, translateWith(props.t, "help.remoteTitle")), (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, translateWith(props.t, "help.recommended")), (0, react.createElement)("ol", { className: "pbb-helpList" }, (0, react.createElement)("li", null, translateWith(props.t, "help.step1")), (0, react.createElement)("li", null, translateWith(props.t, "help.step2")), (0, react.createElement)("li", null, translateWith(props.t, "help.step3")), (0, react.createElement)("li", null, translateWith(props.t, "help.step4"))), (0, react.createElement)("p", { className: "pbb-helpText" }, translateWith(props.t, "help.funnelHint"))), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, translateWith(props.t, "help.httpsTitle")), (0, react.createElement)("ol", { className: "pbb-helpList" }, (0, react.createElement)("li", null, translateWith(props.t, "help.httpsStep1")), (0, react.createElement)("li", null, translateWith(props.t, "help.httpsStep2")), (0, react.createElement)("li", null, translateWith(props.t, "help.httpsStep3"))), (0, react.createElement)("p", { className: "pbb-helpText" }, translateWith(props.t, "help.httpsHint"))), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, translateWith(props.t, "help.allowTitle")), (0, react.createElement)("p", { className: "pbb-helpText" }, translateWith(props.t, "help.allowBody")), (0, react.createElement)("code", { className: "pbb-helpCode" }, "\"nodeAttrs\": [\n {\n \"target\": [\"autogroup:member\"],\n \"attr\": [\"funnel\"],\n },\n],"), (0, react.createElement)("p", { className: "pbb-helpText" }, translateWith(props.t, "help.allowHint"))), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, translateWith(props.t, "help.faqTitle")), (0, react.createElement)("ul", { className: "pbb-helpList" }, (0, react.createElement)("li", null, translateWith(props.t, "help.faq1")), (0, react.createElement)("li", null, translateWith(props.t, "help.faq2")), (0, react.createElement)("li", null, translateWith(props.t, "help.faq3")), (0, react.createElement)("li", null, translateWith(props.t, "help.faq4")))), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, translateWith(props.t, "help.securityTitle")), (0, react.createElement)("ul", { className: "pbb-helpList" }, (0, react.createElement)("li", null, translateWith(props.t, "help.security1")), (0, react.createElement)("li", null, translateWith(props.t, "help.security2")), (0, react.createElement)("li", null, translateWith(props.t, "help.security3")), (0, react.createElement)("li", null, translateWith(props.t, "help.security4")), (0, react.createElement)("li", null, translateWith(props.t, "help.security5"))), (0, react.createElement)("p", { className: "pbb-helpText" }, translateWith(props.t, "help.docsPrefix"), (0, react.createElement)("a", {
3359
3687
  className: "pbb-helpLink",
3360
3688
  href: "https://tailscale.com/docs/features/tailscale-funnel",
3361
3689
  target: "_blank",
3362
3690
  rel: "noreferrer"
3363
- }, "Tailscale Funnel 官方文档")))))), report === null ? null : (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "扫码添加当前手机"), pairingTarget === null ? (0, react.createElement)("span", { className: "pbb-value pbb-bad" }, "没有可用地址") : (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("span", { className: "pbb-badge" }, pairingTarget.kind === "public" ? "公网" : "内网"), (0, react.createElement)("button", {
3691
+ }, translateWith(props.t, "help.funnelDocs"))))))), report === null ? null : (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "pair.qrPanelTitle")), pairingTarget === null ? (0, react.createElement)("span", { className: "pbb-value pbb-bad" }, translateWith(props.t, "pair.noAddress")) : (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("span", { className: "pbb-badge" }, pairingTarget.kind === "public" ? translateWith(props.t, "pair.kind.public") : translateWith(props.t, "pair.kind.lan")), (0, react.createElement)("button", {
3364
3692
  type: "button",
3365
3693
  className: "pbb-action",
3366
- disabled: qrBusy || !report.tokenReady,
3694
+ disabled: qrBusy || !report.pairingReady,
3367
3695
  onClick: () => {
3368
3696
  if (qrDataURL === null) showPairingQR();
3369
- else setQRDataURL(null);
3697
+ else hidePairingQR();
3370
3698
  }
3371
- }, qrBusy ? "生成中…" : qrDataURL === null ? "显示二维码" : "隐藏二维码"))), pairingTarget === null ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, "未发现可供手机访问的局域网地址,请确认这台电脑已连接局域网。") : null, qrMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, qrMessage) : null, pairingTarget === null || qrDataURL === null ? null : (0, react.createElement)("div", { className: "pbb-qrPanel" }, (0, react.createElement)("img", {
3699
+ }, qrBusy ? translateWith(props.t, "pair.qrGenerating") : qrDataURL === null ? translateWith(props.t, "pair.qrShow") : translateWith(props.t, "pair.qrHide")))), pairingTarget === null ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, translateWith(props.t, "pair.noAddressHelp")) : null, qrMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, qrMessage) : null, pairingTarget === null || qrDataURL === null || pairingGrant === null ? null : (0, react.createElement)("div", { className: "pbb-qrPanel" }, (0, react.createElement)("img", {
3372
3700
  className: "pbb-qrImage",
3373
3701
  src: qrDataURL,
3374
- alt: "DeepPilot 配对二维码"
3375
- }), (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("code", { className: "pbb-token" }, pairingTarget.host), (0, react.createElement)("button", {
3702
+ alt: translateWith(props.t, "pair.qrAlt")
3703
+ }), (0, react.createElement)("div", { className: "pbb-pairCodeBlock" }, (0, react.createElement)("span", { className: "pbb-pairCodeLabel" }, translateWith(props.t, "pair.codeLabel")), (0, react.createElement)("div", { className: "pbb-pairCodeRow" }, (0, react.createElement)("code", { className: "pbb-pairCode" }, pairingGrant.code), (0, react.createElement)("button", {
3704
+ type: "button",
3705
+ className: "pbb-action",
3706
+ onClick: copyPairingCode
3707
+ }, translateWith(props.t, "panel.tokenAction.copy")))), (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("code", { className: "pbb-token" }, pairingTarget.host), (0, react.createElement)("button", {
3376
3708
  type: "button",
3377
3709
  className: "pbb-action",
3378
3710
  onClick: () => copyRemoteURL(pairingTarget.host)
3379
- }, "复制")), (0, react.createElement)("p", { className: "pbb-qrHint" }, `二维码包含${pairingTarget.kind === "public" ? "公网" : "内网"}地址和配对 Token,将在 60 秒后自动隐藏。`)))), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, primaryRows, advancedRows.length > 0 ? (0, react.createElement)("details", { className: "pbb-help" }, (0, react.createElement)("summary", null, "高级信息"), (0, react.createElement)("div", { className: "pbb-helpBody" }, advancedRows)) : null)), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "离线推送中继"), (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("button", {
3711
+ }, translateWith(props.t, "panel.tokenAction.copy"))), addressMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, addressMessage) : null, (0, react.createElement)("p", { className: "pbb-qrHint" }, translateWith(props.t, "pair.qrHint", { kind: pairingTarget.kind === "public" ? translateWith(props.t, "pair.kind.public") : translateWith(props.t, "pair.kind.lan") }))))), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, primaryRows, advancedRows.length > 0 ? (0, react.createElement)("details", { className: "pbb-help" }, (0, react.createElement)("summary", null, translateWith(props.t, "advanced.summary")), (0, react.createElement)("div", { className: "pbb-helpBody" }, advancedRows)) : null)), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "push.relayTitle")), (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("button", {
3380
3712
  type: "button",
3381
3713
  className: "pbb-action",
3382
3714
  disabled: relayTestBusy,
3383
3715
  onClick: runRelayTest
3384
- }, relayTestBusy ? "测试中…" : "测试访问与注册"), (0, react.createElement)("button", {
3716
+ }, relayTestBusy ? translateWith(props.t, "push.relayTesting") : translateWith(props.t, "push.testRelay")), (0, react.createElement)("button", {
3385
3717
  type: "button",
3386
3718
  className: "pbb-action",
3387
3719
  disabled: pushTestBusy,
3388
3720
  onClick: sendPushTest
3389
- }, pushTestBusy ? "发送中…" : "发送测试通知"))), relayTestError ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, relayTestError) : null, relayTestResult === null ? (0, react.createElement)("p", { className: "pbb-diag" }, "验证 Mac 到推送中继的连通性与自动注册是否正常。") : (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, relayTestResult.url || "(未启用)"), (0, react.createElement)("code", { className: "pbb-token " + (relayTestResult.overall === "ok" ? "pbb-ok" : "pbb-bad") }, relayTestResult.overall === "ok" ? "通过" : "存在问题")), relayTestResult.steps.map((step, index) => (0, react.createElement)("p", {
3721
+ }, pushTestBusy ? translateWith(props.t, "push.pushSending") : translateWith(props.t, "push.testPush")))), relayTestError ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, relayTestError) : null, relayTestResult === null ? (0, react.createElement)("p", { className: "pbb-diag" }, translateWith(props.t, "push.relayDefault")) : (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, relayTestResult.url || translateWith(props.t, "push.relayUrlEmpty")), (0, react.createElement)("code", { className: "pbb-token " + (relayTestResult.overall === "ok" ? "pbb-ok" : "pbb-bad") }, relayTestResult.overall === "ok" ? translateWith(props.t, "push.relayOk") : translateWith(props.t, "push.relayBad"))), relayTestResult.steps.map((step, index) => (0, react.createElement)("p", {
3390
3722
  className: "pbb-diag",
3391
3723
  key: String(index)
3392
- }, (step.ok ? "✓ " : "✗ ") + (step.id === "health" ? "服务可达" : "自动注册") + (step.latencyMs !== void 0 ? ` (${String(step.latencyMs)}ms)` : "") + " — " + step.message))), pushTestError ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, pushTestError) : null, pushTestResult === null ? (0, react.createElement)("p", { className: "pbb-diag" }, "向所有已注册设备强制发送一条真实推送(不受在线状态与分类开关影响)。") : (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("code", { className: "pbb-token " + (pushTestResult.overall === "sent" ? "pbb-ok" : pushTestResult.overall === "failed" ? "pbb-bad" : "") }, pushTestResult.overall === "sent" ? "已送达" : pushTestResult.overall === "failed" ? "发送失败" : pushTestResult.overall === "no-targets" ? "无已注册设备" : "推送未启用")), pushTestResult.message ? (0, react.createElement)("p", { className: "pbb-diag" }, pushTestResult.message) : null, pushTestResult.results.map((r, index) => (0, react.createElement)("p", {
3724
+ }, (step.ok ? "✓ " : "✗ ") + (step.id === "health" ? translateWith(props.t, "push.relayStep.health") : translateWith(props.t, "push.relayStep.enroll")) + (step.latencyMs !== void 0 ? ` (${String(step.latencyMs)}ms)` : "") + " — " + step.message))), pushTestError ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, pushTestError) : null, pushTestResult === null ? (0, react.createElement)("p", { className: "pbb-diag" }, translateWith(props.t, "push.pushDefault")) : (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("code", { className: "pbb-token " + (pushTestResult.overall === "sent" ? "pbb-ok" : pushTestResult.overall === "failed" ? "pbb-bad" : "") }, pushTestResult.overall === "sent" ? translateWith(props.t, "push.pushSent") : pushTestResult.overall === "failed" ? translateWith(props.t, "push.pushFailed") : pushTestResult.overall === "no-targets" ? translateWith(props.t, "push.pushNoTargets") : translateWith(props.t, "push.pushNotEnabled"))), pushTestResult.message ? (0, react.createElement)("p", { className: "pbb-diag" }, pushTestResult.message) : null, pushTestResult.results.map((r, index) => (0, react.createElement)("p", {
3393
3725
  className: "pbb-diag",
3394
3726
  key: String(index)
3395
- }, (r.outcome === "sent" ? "✓ " : "✗ ") + r.name + " [" + r.environment + "] — " + r.outcome + (r.reason ? "(" + r.reason + ")" : "") + (r.tokenFingerprint ? " token:" + r.tokenFingerprint + "…" : "")))))), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "已配对设备"), (0, react.createElement)("span", { className: "pbb-badge" }, String(report !== null ? report.devices.length : 0))), deviceTable)), report === null ? null : (0, react.createElement)("div", { className: "pbb-versionFooter" }, (0, react.createElement)("span", null, "DeepPilot v" + report.pluginVersion), report.updateAvailable === true ? (0, react.createElement)("a", {
3727
+ }, (r.outcome === "sent" ? "✓ " : "✗ ") + r.name + " [" + r.environment + "] — " + r.outcome + (r.reason ? "(" + r.reason + ")" : "") + (r.tokenFingerprint ? " token:" + r.tokenFingerprint + "…" : "")))))), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, translateWith(props.t, "devices.title")), (0, react.createElement)("span", { className: "pbb-badge" }, String(visibleDevices.length))), deviceMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, deviceMessage) : null, deviceTable)), report === null ? null : (0, react.createElement)("div", { className: "pbb-versionFooter" }, (0, react.createElement)("span", null, "DeepPilot v" + report.pluginVersion), report.updateAvailable === true ? (0, react.createElement)("a", {
3396
3728
  href: typeof report.releaseUrl === "string" && /^https:\/\//.test(report.releaseUrl) ? report.releaseUrl : "https://github.com/Mars-Sea/dsh-deeppilot/releases",
3397
3729
  target: "_blank",
3398
3730
  rel: "noreferrer"
3399
- }, "有新版本") : null), diag.length > 0 ? (0, react.createElement)("p", { className: "pbb-diag" + (failed ? " pbb-diagBad" : "") }, "diag: " + diag.join(" | ")) : null);
3731
+ }, translateWith(props.t, "update.badge")) : null), diag.length > 0 ? (0, react.createElement)("p", { className: "pbb-diag" + (failed ? " pbb-diagBad" : "") }, translateWith(props.t, "diag.prefix") + diag.join(" | ")) : null);
3732
+ }
3733
+ //#endregion
3734
+ //#region src/client/index.ts
3735
+ /** Polls the report remote and owns the page state transitions. */
3736
+ var ReportController = class {
3737
+ fetchReport;
3738
+ t;
3739
+ listeners = /* @__PURE__ */ new Set();
3740
+ snap = {
3741
+ status: "loading",
3742
+ report: null,
3743
+ message: ""
3744
+ };
3745
+ constructor(fetchReport, t) {
3746
+ this.fetchReport = fetchReport;
3747
+ this.t = t;
3748
+ }
3749
+ state() {
3750
+ return this.snap;
3751
+ }
3752
+ subscribe(listener) {
3753
+ this.listeners.add(listener);
3754
+ return () => this.listeners.delete(listener);
3755
+ }
3756
+ dispose() {
3757
+ this.listeners.clear();
3758
+ }
3759
+ async refresh() {
3760
+ try {
3761
+ const report = await this.fetchReport();
3762
+ this.snap = report !== null ? {
3763
+ status: "ready",
3764
+ report,
3765
+ message: ""
3766
+ } : {
3767
+ status: "error",
3768
+ report: null,
3769
+ message: this.t("diag.mountFailed")
3770
+ };
3771
+ } catch (error) {
3772
+ this.snap = {
3773
+ status: "error",
3774
+ report: null,
3775
+ message: error instanceof Error ? error.message : String(error)
3776
+ };
3777
+ }
3778
+ this.emit();
3779
+ }
3780
+ emit() {
3781
+ for (const listener of [...this.listeners]) try {
3782
+ listener();
3783
+ } catch {}
3784
+ }
3785
+ };
3786
+ const inject = [
3787
+ "slots",
3788
+ "locale",
3789
+ "remote",
3790
+ "settingsScope"
3791
+ ];
3792
+ function apply(ctx) {
3793
+ if (typeof document !== "undefined") injectCss();
3794
+ const anyCtx = ctx;
3795
+ ctx.effect(() => registerLocale(ctx), "dsh-deeppilot: locale dictionaries");
3796
+ let namespace;
3797
+ let mountError;
3798
+ const fetchReport = async () => {
3799
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? t(ctx, "diag.mountFailedShort") + mountError : t(ctx, "diag.remoteUnmounted"));
3800
+ const result = await namespace.report();
3801
+ if (!result.ok) throw new Error(result.error.message ?? t(ctx, "diag.callFailed"));
3802
+ return result.value;
3803
+ };
3804
+ const tPage = (key, vars) => t(ctx, key, vars);
3805
+ const controller = new ReportController(fetchReport, tPage);
3806
+ ctx.effect(() => () => controller.dispose(), "dsh-deeppilot: report controller");
3807
+ const store = createSnapshotStore(controller.state());
3808
+ controller.subscribe(() => store.set(controller.state()));
3809
+ ctx.effect(() => {
3810
+ let cancelled = false;
3811
+ let unmount;
3812
+ if (anyCtx.remote === void 0) {
3813
+ mountError = t(ctx, "diag.remoteUnavailable");
3814
+ controller.refresh();
3815
+ return () => {};
3816
+ }
3817
+ mountReportRemote(anyCtx.remote, () => ctx.get("remote.deeppilot")).then((mounted) => {
3818
+ if (cancelled) {
3819
+ mounted.dispose();
3820
+ return;
3821
+ }
3822
+ namespace = mounted.namespace;
3823
+ unmount = mounted.dispose;
3824
+ mountError = void 0;
3825
+ controller.refresh();
3826
+ }, (error) => {
3827
+ mountError = error instanceof Error ? error.message : String(error);
3828
+ controller.refresh();
3829
+ });
3830
+ return () => {
3831
+ cancelled = true;
3832
+ namespace = void 0;
3833
+ if (unmount !== void 0) unmount();
3834
+ };
3835
+ }, "dsh-deeppilot: report remote mount");
3836
+ const beginPairing = async () => {
3837
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? t(ctx, "diag.mountFailedShort") + mountError : t(ctx, "diag.remoteUnmounted"));
3838
+ const result = await namespace.beginPairing();
3839
+ if (!result.ok) throw new Error(result.error.message ?? t(ctx, "pair.qrFailed"));
3840
+ return result.value;
3841
+ };
3842
+ const revokeDevice = async (deviceId) => {
3843
+ if (namespace === void 0) throw new Error(t(ctx, "diag.remoteUnmounted"));
3844
+ const result = await namespace.revokeDevice(deviceId);
3845
+ if (!result.ok || result.value !== true) throw new Error(result.ok ? t(ctx, "devices.revokeFailed") : result.error.message ?? t(ctx, "devices.revokeFailed"));
3846
+ await controller.refresh();
3847
+ };
3848
+ const sendTestPush = async () => {
3849
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? t(ctx, "diag.mountFailedShort") + mountError : t(ctx, "diag.remoteUnmounted"));
3850
+ if (typeof namespace.testPush !== "function") throw new Error(t(ctx, "push.staleHostPush"));
3851
+ const result = await namespace.testPush();
3852
+ if (!result.ok) throw new Error(result.error.message ?? t(ctx, "push.pushFailed"));
3853
+ return result.value;
3854
+ };
3855
+ const testRelayConnection = async () => {
3856
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? t(ctx, "diag.mountFailedShort") + mountError : t(ctx, "diag.remoteUnmounted"));
3857
+ if (typeof namespace.testRelay !== "function") throw new Error(t(ctx, "push.staleHostPushRelay"));
3858
+ const result = await namespace.testRelay();
3859
+ if (!result.ok) throw new Error(result.error.message ?? t(ctx, "push.relayBad"));
3860
+ return result.value;
3861
+ };
3862
+ const enabledStore = createSnapshotStore({
3863
+ status: "loading",
3864
+ enabled: true
3865
+ });
3866
+ const scope = anyCtx.settingsScope?.bind({ namespace: "deeppilot" });
3867
+ const adoptEnabled = () => {
3868
+ if (scope === void 0) return;
3869
+ const snap = scope.getSnapshot();
3870
+ if (snap.status === "ready" && snap.value !== void 0) enabledStore.set({
3871
+ status: "ready",
3872
+ enabled: snap.value.enabled !== false
3873
+ });
3874
+ else if (snap.status === "unavailable") enabledStore.set({
3875
+ status: "unavailable",
3876
+ enabled: true
3877
+ });
3878
+ };
3879
+ if (scope !== void 0) {
3880
+ scope.subscribe(adoptEnabled);
3881
+ adoptEnabled();
3882
+ }
3883
+ const lastConfirmedEnabled = () => {
3884
+ const snap = scope?.getSnapshot();
3885
+ if (snap?.status === "ready" && snap.value !== void 0) return snap.value.enabled !== false;
3886
+ return enabledStore.getSnapshot().enabled;
3887
+ };
3888
+ const lastConfirmedRemoteEnabled = () => {
3889
+ const snap = scope?.getSnapshot();
3890
+ if (snap?.status === "ready") return snap.value?.remote?.enabled === true;
3891
+ return remoteEnabledStore.getSnapshot().enabled;
3892
+ };
3893
+ const lastConfirmedRemoteConnectionLimit = () => {
3894
+ const snap = scope?.getSnapshot();
3895
+ if (snap?.status === "ready") return normalizeFunnelConnectionLimit(snap.value?.remote?.maxConnectionsPerSource);
3896
+ return remoteConnectionLimitStore.getSnapshot().value;
3897
+ };
3898
+ const setDeepPilotEnabled = (value) => {
3899
+ const previous = lastConfirmedEnabled();
3900
+ enabledStore.set({
3901
+ status: "ready",
3902
+ enabled: value
3903
+ });
3904
+ if (scope === void 0) return;
3905
+ scope.set("enabled", value).then(() => {}, (error) => {
3906
+ enabledStore.set({
3907
+ status: "ready",
3908
+ enabled: previous
3909
+ });
3910
+ const message = error instanceof Error ? error.message : String(error);
3911
+ console.error("[deeppilot] failed to persist enabled=" + String(value) + ": " + message);
3912
+ });
3913
+ };
3914
+ const remoteEnabledStore = createSnapshotStore({
3915
+ status: "loading",
3916
+ enabled: false
3917
+ });
3918
+ const remoteConnectionLimitStore = createSnapshotStore({
3919
+ status: "loading",
3920
+ value: 8
3921
+ });
3922
+ const adoptRemoteEnabled = () => {
3923
+ if (scope === void 0) return;
3924
+ const snap = scope.getSnapshot();
3925
+ if (snap.status === "ready") {
3926
+ remoteEnabledStore.set({
3927
+ status: "ready",
3928
+ enabled: snap.value?.remote?.enabled === true
3929
+ });
3930
+ remoteConnectionLimitStore.set({
3931
+ status: "ready",
3932
+ value: normalizeFunnelConnectionLimit(snap.value?.remote?.maxConnectionsPerSource)
3933
+ });
3934
+ } else if (snap.status === "unavailable") {
3935
+ remoteEnabledStore.set({
3936
+ status: "unavailable",
3937
+ enabled: false
3938
+ });
3939
+ remoteConnectionLimitStore.set({
3940
+ status: "unavailable",
3941
+ value: 8
3942
+ });
3943
+ }
3944
+ };
3945
+ if (scope !== void 0) {
3946
+ scope.subscribe(adoptRemoteEnabled);
3947
+ adoptRemoteEnabled();
3948
+ }
3949
+ const setDeepPilotRemoteEnabled = (value) => {
3950
+ const previous = lastConfirmedRemoteEnabled();
3951
+ remoteEnabledStore.set({
3952
+ status: "ready",
3953
+ enabled: value
3954
+ });
3955
+ if (scope === void 0) return;
3956
+ const currentRemote = scope.getSnapshot().value?.remote ?? {};
3957
+ scope.set("remote", {
3958
+ ...currentRemote,
3959
+ enabled: value
3960
+ }).then(() => {}, (error) => {
3961
+ remoteEnabledStore.set({
3962
+ status: "ready",
3963
+ enabled: previous
3964
+ });
3965
+ const message = error instanceof Error ? error.message : String(error);
3966
+ console.error("[deeppilot] failed to persist remote.enabled=" + String(value) + ": " + message);
3967
+ });
3968
+ };
3969
+ const setDeepPilotRemoteConnectionLimit = async (value) => {
3970
+ const next = normalizeFunnelConnectionLimit(value);
3971
+ if (next !== value) throw new RangeError("maxConnectionsPerSource must be an integer between 1 and 16");
3972
+ if (scope === void 0) throw new Error("settings scope unavailable");
3973
+ const previous = lastConfirmedRemoteConnectionLimit();
3974
+ remoteConnectionLimitStore.set({
3975
+ status: "ready",
3976
+ value: next
3977
+ });
3978
+ const currentRemote = scope.getSnapshot().value?.remote ?? {};
3979
+ try {
3980
+ await scope.set("remote", {
3981
+ ...currentRemote,
3982
+ maxConnectionsPerSource: next
3983
+ });
3984
+ } catch (error) {
3985
+ remoteConnectionLimitStore.set({
3986
+ status: "ready",
3987
+ value: previous
3988
+ });
3989
+ const message = error instanceof Error ? error.message : String(error);
3990
+ console.error("[deeppilot] failed to persist remote.maxConnectionsPerSource=" + String(next) + ": " + message);
3991
+ throw error;
3992
+ }
3993
+ };
3994
+ if (anyCtx.slots === void 0) console.error("[deeppilot] settings slots service unavailable; the DeepPilot section will not appear");
3995
+ anyCtx.slots?.inject("settings.section", () => anyCtx.slots.register({
3996
+ name: "settings.section",
3997
+ id: "deeppilot",
3998
+ order: 13,
3999
+ label: () => {
4000
+ const bind = anyCtx.locale?.bind("settings.deeppilot");
4001
+ return bind ? bind("nav") : "DeepPilot";
4002
+ },
4003
+ locale: "settings.deeppilot",
4004
+ inject: () => ({
4005
+ hooks: {
4006
+ deepPilotReport: store,
4007
+ deepPilotEnabled: enabledStore,
4008
+ deepPilotRemoteEnabled: remoteEnabledStore,
4009
+ deepPilotRemoteConnectionLimit: remoteConnectionLimitStore
4010
+ },
4011
+ refresh: () => {
4012
+ controller.refresh();
4013
+ },
4014
+ beginPairing,
4015
+ revokeDevice,
4016
+ testRelay: testRelayConnection,
4017
+ testPush: sendTestPush,
4018
+ setDeepPilotEnabled,
4019
+ setDeepPilotRemoteEnabled,
4020
+ setDeepPilotRemoteConnectionLimit,
4021
+ t: (key, vars) => t(ctx, key, vars)
4022
+ })
4023
+ }, DeepPilotSettingsPage));
3400
4024
  }
3401
4025
  //#endregion
3402
4026
  exports.DeepPilotSettingsPage = DeepPilotSettingsPage;