dsh-connect-workbuddy 5.15.2 → 5.17.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
@@ -110,6 +110,30 @@ window.__ModuleLoader__.load({
110
110
  const WORKBUDDY_OAUTH_PATH = "/plugins/dsh-connect-workbuddy/oauth";
111
111
  /** Query parameter selecting which pool batch action a request means. */
112
112
  const WORKBUDDY_POOL_ACTION_PARAM = "action";
113
+ /**
114
+ * 设备头设置(「虚拟值 / 真实值」+ 每账号的覆盖参数)。
115
+ *
116
+ * 一条路由两种方法,因为读和写描述的是同一份文档:
117
+ * - `GET` → `{ mode, accounts }`,卡片渲染切换项与每行的齿轮状态;
118
+ * - `POST` → 立即生效(不像账号池那样有草稿):`{ kind: 'mode', mode }` 或
119
+ * `{ kind: 'account', accountId, machineId?, sessionId? }`。
120
+ *
121
+ * POST + loopback-only:写的是"这台机器对外声称自己是谁",和凭据写入同级。
122
+ * 之所以不挂在账号池的 `/pool` 下面:那份草稿是"点保存才生效"的偏好,而这里的
123
+ * 两个动作都是即时生效,混在一条路由里会让"保存"按钮的语义变得说不清。
124
+ */
125
+ const WORKBUDDY_DEVICE_PROFILE_PATH = "/plugins/dsh-connect-workbuddy/device-profile";
126
+ /**
127
+ * 真实设备参数(本机安装的桌面端 Turing Shield SDK)的状态与取值。
128
+ *
129
+ * - `GET` → `{ tier, sdk, token }`,`token` 只有掩码与长度。
130
+ * - `POST ?action=refresh` → 强制重取一次,再返回同一形状。
131
+ * - `POST ?action=reveal` → `{ token }`,完整值,**只在用户显式点击时**。
132
+ *
133
+ * 为什么把"完整值"单独做成一个动作:这是一枚能代表这台机器的凭据,卡片是
134
+ * 一个会被截图、被贴进 issue 的界面。默认只给掩码,复制/查看各要一次显式动作。
135
+ */
136
+ const WORKBUDDY_DEVICE_SDK_PATH = "/plugins/dsh-connect-workbuddy/device-sdk";
113
137
  /** How long the card waits between polls while the user is scanning. */
114
138
  const OAUTH_POLL_INTERVAL_MS = 2e3;
115
139
  /**
@@ -2026,6 +2050,316 @@ window.__ModuleLoader__.load({
2026
2050
  });
2027
2051
  }
2028
2052
  //#endregion
2053
+ //#region src/client/device-profile.ts
2054
+ /** 与 Host 侧同一条规则:36 个小写十六进制字符。 */
2055
+ const DEVICE_ID_PATTERN = /^[0-9a-f]{36}$/u;
2056
+ /** Whether `value` is a well-formed device id (as the Host will accept it). */
2057
+ function isDeviceId(value) {
2058
+ return DEVICE_ID_PATTERN.test(value);
2059
+ }
2060
+ /**
2061
+ * 造一个 36 字符的小写十六进制 id(「一键随机」用的就是它)。
2062
+ *
2063
+ * 用 `crypto.getRandomValues` 而不是 `Math.random`:随机值会被当成设备身份发出去,
2064
+ * 一个可预测的序列不是"随机",而是"两台机器撞在一起"。18 字节与派生值的熵一致。
2065
+ */
2066
+ function randomDeviceId() {
2067
+ const bytes = /* @__PURE__ */ new Uint8Array(18);
2068
+ crypto.getRandomValues(bytes);
2069
+ return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
2070
+ }
2071
+ /**
2072
+ * Normalize one Host answer. Shared by the GET and the POST: two copies of this
2073
+ * coercion is how the two answers start disagreeing.
2074
+ *
2075
+ * 派生值逐条校验形状:它是画在输入框正下方的 36 位串,混进一个 undefined 会
2076
+ * 直接渲染成 "undefined",比不显示更糟。Host 与本页面同源,这里不做安全意义上的
2077
+ * 校验,只是不让半截数据变成可见的胡说。
2078
+ */
2079
+ function normalizeSettings(body) {
2080
+ const accounts = typeof body.accounts === "object" && body.accounts !== null ? body.accounts : {};
2081
+ const derived = {};
2082
+ if (typeof body.derived === "object" && body.derived !== null) for (const [accountId, entry] of Object.entries(body.derived)) {
2083
+ const machineId = entry?.machineId;
2084
+ const sessionId = entry?.sessionId;
2085
+ if (typeof machineId !== "string" || typeof sessionId !== "string") continue;
2086
+ if (!isDeviceId(machineId) || !isDeviceId(sessionId)) continue;
2087
+ derived[accountId] = {
2088
+ machineId,
2089
+ sessionId
2090
+ };
2091
+ }
2092
+ return {
2093
+ mode: body.mode === "real" ? "real" : "virtual",
2094
+ accounts,
2095
+ ...body.derived === void 0 ? {} : { derived },
2096
+ sdkDir: typeof body.sdkDir === "string" ? body.sdkDir : "",
2097
+ sdkFallbackToVirtual: body.sdkFallbackToVirtual !== false
2098
+ };
2099
+ }
2100
+ /**
2101
+ * GET the current settings.
2102
+ *
2103
+ * `undefined` means "this Host has no such route" (404/503) — a different answer
2104
+ * from "the Host has one and it says virtual/empty". The card uses that to HIDE
2105
+ * the toggle and the row gears instead of rendering controls that cannot work;
2106
+ * `EMPTY_DEVICE_SETTINGS` is only the initial value before the first read.
2107
+ */
2108
+ async function fetchDeviceSettings(path) {
2109
+ const response = await fetch(path, {
2110
+ headers: { accept: "application/json" },
2111
+ credentials: "same-origin"
2112
+ });
2113
+ if (response.status === 404 || response.status === 503) return void 0;
2114
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
2115
+ return normalizeSettings(await response.json());
2116
+ }
2117
+ /** POST one mutation and return the settings the Host now holds. */
2118
+ async function post$1(path, body) {
2119
+ const response = await fetch(path, {
2120
+ method: "POST",
2121
+ headers: {
2122
+ "content-type": "application/json",
2123
+ accept: "application/json"
2124
+ },
2125
+ credentials: "same-origin",
2126
+ body: JSON.stringify(body)
2127
+ });
2128
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
2129
+ return normalizeSettings(await response.json());
2130
+ }
2131
+ /** Switch the tier. 「真实值」is remembered but changes no outbound byte until P3. */
2132
+ function putDeviceMode(path, mode) {
2133
+ return post$1(path, {
2134
+ kind: "mode",
2135
+ mode
2136
+ });
2137
+ }
2138
+ /**
2139
+ * Save one account's overrides.
2140
+ *
2141
+ * `''` clears a field (back to the derived value) and `undefined` leaves it alone —
2142
+ * that distinction is why the dialog sends only the fields the user touched.
2143
+ */
2144
+ function putDeviceProfile(path, accountId, values) {
2145
+ return post$1(path, {
2146
+ kind: "account",
2147
+ accountId,
2148
+ ...values
2149
+ });
2150
+ }
2151
+ /**
2152
+ * Save the SDK directory and/or the fallback switch (作者意见 #1 / #2).
2153
+ *
2154
+ * `undefined` leaves a field alone, exactly like {@link putDeviceProfile}: the
2155
+ * panel has two independent controls, and saving one must not write the other
2156
+ * back to a stale value. `sdkDir: ''` clears the override and returns to
2157
+ * automatic discovery — a different intent from "leave it alone".
2158
+ */
2159
+ function putDeviceSdk(path, values) {
2160
+ return post$1(path, {
2161
+ kind: "sdk",
2162
+ ...values
2163
+ });
2164
+ }
2165
+ //#endregion
2166
+ //#region src/client/DeviceProfileDialog.tsx
2167
+ /**
2168
+ * 一个账号的"虚拟设备参数"弹窗(设置里齿轮点开的那个)。
2169
+ *
2170
+ * ## 为什么是弹窗,而不是行内展开
2171
+ *
2172
+ * 每行已经有「测试 / 移除」两个按钮和一段探针文本,再展开两块输入框会把表格
2173
+ * 挤成表单。这里改的是"这台机器对外声称自己是谁",属于低频但高影响的编辑,
2174
+ * 适合一个能一眼看完、且必须显式确认的面板。
2175
+ *
2176
+ * ## 为什么字段是"可清空"的
2177
+ *
2178
+ * 留空 = 按本机盐自动派生。清空某一项就恢复自动,而不是要求用户先记住原来的
2179
+ * 派生值——派生值本来就是不可逆推的 36 位十六进制,让人"填回去"是不可能的。
2180
+ *
2181
+ * ## P3 的那一行为什么现在就出现
2182
+ *
2183
+ * 真实设备 Token 的取值链(Turing Shield SDK / 文件)与档位互斥规则都还没实现,
2184
+ * 但入口要预留:用户在看到「真实值(P3)」这个选项时,需要在这个弹窗里看到
2185
+ * "它将来的位置在哪"。禁用 + 一句说明,比一个将来突然冒出来的输入框诚实。
2186
+ *
2187
+ * @module dsh-connect-workbuddy/client/DeviceProfileDialog
2188
+ */
2189
+ function DeviceProfileDialog(props) {
2190
+ const { t, accountName, saved, derived, derivedNote, saving, error, onCancel, onSave } = props;
2191
+ const [machineId, setMachineId] = (0, react.useState)(saved.machineId);
2192
+ const [sessionId, setSessionId] = (0, react.useState)(saved.sessionId);
2193
+ const firstField = (0, react.useRef)(null);
2194
+ (0, react.useEffect)(() => {
2195
+ const onKeyDown = (event) => {
2196
+ if (event.key === "Escape") onCancel();
2197
+ };
2198
+ window.addEventListener("keydown", onKeyDown);
2199
+ return () => window.removeEventListener("keydown", onKeyDown);
2200
+ }, [onCancel]);
2201
+ (0, react.useEffect)(() => {
2202
+ firstField.current?.focus();
2203
+ }, []);
2204
+ const machineInvalid = machineId !== "" && !isDeviceId(machineId);
2205
+ const sessionInvalid = sessionId !== "" && !isDeviceId(sessionId);
2206
+ const canSave = !saving && !machineInvalid && !sessionInvalid;
2207
+ const field = (labelKey, value, onChange, invalid, derivedValue, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
2208
+ className: "dsm-workbuddy-device-field",
2209
+ children: [
2210
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2211
+ className: "dsm-workbuddy-device-field-label",
2212
+ children: t(labelKey)
2213
+ }),
2214
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2215
+ ref,
2216
+ type: "text",
2217
+ className: `dsm-workbuddy-device-input${invalid ? " dsm-workbuddy-device-input-bad" : ""}`,
2218
+ value,
2219
+ spellCheck: false,
2220
+ autoComplete: "off",
2221
+ placeholder: t("row.deviceFieldPlaceholder"),
2222
+ "aria-invalid": invalid ? true : void 0,
2223
+ onChange: (event) => onChange(event.target.value.trim().toLowerCase())
2224
+ }),
2225
+ value !== "" || derivedValue === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2226
+ className: "dsm-workbuddy-device-derived",
2227
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("row.deviceDerivedNow") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: derivedValue })]
2228
+ }),
2229
+ invalid ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2230
+ className: "dsm-workbuddy-device-error",
2231
+ children: t("row.deviceInvalid")
2232
+ }) : null
2233
+ ]
2234
+ });
2235
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2236
+ className: "dsm-workbuddy-device-backdrop",
2237
+ role: "presentation",
2238
+ onClick: (event) => {
2239
+ if (event.target === event.currentTarget) onCancel();
2240
+ },
2241
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2242
+ className: "dsm-workbuddy-device-dialog",
2243
+ role: "dialog",
2244
+ "aria-modal": "true",
2245
+ "aria-label": t("row.deviceDialogTitle", { accountName }),
2246
+ children: [
2247
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
2248
+ className: "dsm-workbuddy-device-title",
2249
+ children: t("row.deviceDialogTitle", { accountName })
2250
+ }),
2251
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2252
+ className: "dsm-workbuddy-hint",
2253
+ children: t("row.deviceDialogIntro")
2254
+ }),
2255
+ field("row.deviceMachineLabel", machineId, setMachineId, machineInvalid, derived?.machineId, firstField),
2256
+ field("row.deviceSessionLabel", sessionId, setSessionId, sessionInvalid, derived?.sessionId),
2257
+ derived !== void 0 || derivedNote === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2258
+ className: "dsm-workbuddy-device-derived-missing",
2259
+ children: t(derivedNote)
2260
+ }),
2261
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2262
+ className: "dsm-workbuddy-device-random-row",
2263
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2264
+ type: "button",
2265
+ className: "dsm-btn dsm-btn-outline",
2266
+ onClick: () => {
2267
+ setMachineId(randomDeviceId());
2268
+ setSessionId(randomDeviceId());
2269
+ },
2270
+ children: t("row.deviceRandom")
2271
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2272
+ className: "dsm-workbuddy-hint",
2273
+ children: t("row.deviceRandomHint")
2274
+ })]
2275
+ }),
2276
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2277
+ className: "dsm-workbuddy-device-p3",
2278
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2279
+ className: "dsm-workbuddy-device-p3-label",
2280
+ children: t("row.deviceDialogP3")
2281
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2282
+ className: "dsm-workbuddy-hint",
2283
+ children: t("row.deviceDialogP3Hint")
2284
+ })]
2285
+ }),
2286
+ error === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2287
+ className: "dsm-workbuddy-device-error",
2288
+ children: error
2289
+ }),
2290
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2291
+ className: "dsm-workbuddy-device-dialog-actions",
2292
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2293
+ type: "button",
2294
+ className: "dsm-btn dsm-btn-outline",
2295
+ onClick: onCancel,
2296
+ disabled: saving,
2297
+ children: t("row.deviceDialogCancel")
2298
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2299
+ type: "button",
2300
+ className: "dsm-btn dsm-btn-outline",
2301
+ disabled: !canSave,
2302
+ onClick: () => onSave({
2303
+ machineId,
2304
+ sessionId
2305
+ }),
2306
+ children: saving ? t("row.deviceDialogSaving") : t("row.deviceDialogSave")
2307
+ })]
2308
+ })
2309
+ ]
2310
+ })
2311
+ });
2312
+ }
2313
+ /**
2314
+ * 「真实值」档下点齿轮时看到的那一句话。
2315
+ *
2316
+ * 为什么齿轮仍然可点:一个真正 `disabled` 的按钮点不动,用户只会以为是界面坏了;
2317
+ * 这里要回答的是"为什么不让我改"——那必须有一次点击才能说出口。视觉上置灰
2318
+ * (`dsm-workbuddy-device-gear-off`)表达"现在用不了",点击表达"原因是什么"。
2319
+ */
2320
+ function DeviceModeBlockedDialog(props) {
2321
+ const { t, onClose } = props;
2322
+ (0, react.useEffect)(() => {
2323
+ const onKeyDown = (event) => {
2324
+ if (event.key === "Escape") onClose();
2325
+ };
2326
+ window.addEventListener("keydown", onKeyDown);
2327
+ return () => window.removeEventListener("keydown", onKeyDown);
2328
+ }, [onClose]);
2329
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2330
+ className: "dsm-workbuddy-device-backdrop",
2331
+ role: "presentation",
2332
+ onClick: (event) => {
2333
+ if (event.target === event.currentTarget) onClose();
2334
+ },
2335
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2336
+ className: "dsm-workbuddy-device-dialog",
2337
+ role: "dialog",
2338
+ "aria-modal": "true",
2339
+ "aria-label": t("row.deviceModeRealBlockedTitle"),
2340
+ children: [
2341
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
2342
+ className: "dsm-workbuddy-device-title",
2343
+ children: t("row.deviceModeRealBlockedTitle")
2344
+ }),
2345
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2346
+ className: "dsm-workbuddy-hint",
2347
+ children: t("row.deviceModeRealBlocked")
2348
+ }),
2349
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2350
+ className: "dsm-workbuddy-device-dialog-actions",
2351
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2352
+ type: "button",
2353
+ className: "dsm-btn dsm-btn-outline",
2354
+ onClick: onClose,
2355
+ children: t("row.deviceDialogCancel")
2356
+ })
2357
+ })
2358
+ ]
2359
+ })
2360
+ });
2361
+ }
2362
+ //#endregion
2029
2363
  //#region src/client/ndjson.ts
2030
2364
  /**
2031
2365
  * Read a newline-delimited JSON body, one object at a time.
@@ -2760,6 +3094,7 @@ window.__ModuleLoader__.load({
2760
3094
  */
2761
3095
  function AccountPool(props) {
2762
3096
  const { t, region, pool, settingsScope, siblingBusy, onBusyChange, onSaved, onRefresh, onRescan, rescanning, onSelectAccount, selectingAccount, accountTools } = props;
3097
+ const { deviceMode, deviceProfiles, deviceDerived, onDeviceModeChange, onSaveDeviceProfile } = props;
2763
3098
  const [draft, setDraft] = (0, react.useState)(null);
2764
3099
  const [saving, setSaving] = (0, react.useState)(false);
2765
3100
  const [saveError, setSaveError] = (0, react.useState)(void 0);
@@ -2772,6 +3107,18 @@ window.__ModuleLoader__.load({
2772
3107
  }, [region]);
2773
3108
  const [draftRegion, setDraftRegion] = (0, react.useState)(void 0);
2774
3109
  const [orderRulesOpen, setOrderRulesOpen] = (0, react.useState)(false);
3110
+ /**
3111
+ * 设备头编辑器:哪个账号、是否在保存、上一次失败的原因。
3112
+ *
3113
+ * `undefined` = 弹窗关着。分开存 `saving`/`error` 而不是塞进同一个对象,是因为
3114
+ * 保存失败时弹窗必须**保持打开**并保留用户填的值——关掉再重开一次,填写内容
3115
+ * 就全没了。
3116
+ */
3117
+ const [deviceEditing, setDeviceEditing] = (0, react.useState)(void 0);
3118
+ const [deviceSaving, setDeviceSaving] = (0, react.useState)(false);
3119
+ const [deviceError, setDeviceError] = (0, react.useState)(void 0);
3120
+ const [deviceBlockedOpen, setDeviceBlockedOpen] = (0, react.useState)(false);
3121
+ const [deviceModeBusy, setDeviceModeBusy] = (0, react.useState)(false);
2775
3122
  const mounted = (0, react.useRef)(true);
2776
3123
  (0, react.useEffect)(() => {
2777
3124
  mounted.current = true;
@@ -3356,6 +3703,50 @@ window.__ModuleLoader__.load({
3356
3703
  open: orderRulesOpen,
3357
3704
  onToggle: (event) => setOrderRulesOpen(event.currentTarget.open)
3358
3705
  }, (0, react.createElement)("summary", { className: "dsm-workbuddy-pool-order-rules-summary" }, t("row.poolOrderRulesTitle")), (0, react.createElement)("div", { className: "dsm-workbuddy-pool-order-rules-body" }, (0, react.createElement)("p", { className: "dsm-workbuddy-pool-note" }, t("row.poolOrderRulesIntro")), (0, react.createElement)("ol", { className: "dsm-workbuddy-pool-order-rules-list" }, ...ORDER_RULE_KEYS.map((key) => (0, react.createElement)("li", { key }, t(key)))), (0, react.createElement)("p", { className: "dsm-workbuddy-pool-order-rules-why" }, t("row.poolOrderWhy")), (0, react.createElement)("p", { className: "dsm-workbuddy-pool-note" }, t("row.poolOrderBadgeNote"))));
3706
+ /**
3707
+ * 切换设备头档位。**即时生效**,不走草稿:这个开关决定每一行那个齿轮是否可用,
3708
+ * 如果它要等一次「保存」才生效,用户会先看到齿轮没反应、再去找保存按钮。
3709
+ */
3710
+ const changeDeviceMode = async (mode) => {
3711
+ if (onDeviceModeChange === void 0 || deviceModeBusy || mode === deviceMode) return;
3712
+ setDeviceModeBusy(true);
3713
+ setActionError(void 0);
3714
+ try {
3715
+ await onDeviceModeChange(mode);
3716
+ } catch (error) {
3717
+ if (mounted.current) setActionError(error instanceof Error ? error.message : t("row.requestFailed"));
3718
+ } finally {
3719
+ if (mounted.current) setDeviceModeBusy(false);
3720
+ }
3721
+ };
3722
+ /** 保存一个账号的覆盖值;失败时让弹窗留着、把原因放在里面。 */
3723
+ const saveDeviceProfileFor = async (accountId, values) => {
3724
+ if (onSaveDeviceProfile === void 0) return;
3725
+ setDeviceSaving(true);
3726
+ setDeviceError(void 0);
3727
+ try {
3728
+ await onSaveDeviceProfile(accountId, values);
3729
+ if (mounted.current) setDeviceEditing(void 0);
3730
+ } catch (error) {
3731
+ if (mounted.current) setDeviceError(error instanceof Error ? error.message : t("row.requestFailed"));
3732
+ } finally {
3733
+ if (mounted.current) setDeviceSaving(false);
3734
+ }
3735
+ };
3736
+ /**
3737
+ * 弹窗的派生值那一块。
3738
+ *
3739
+ * 三种情况必须分开,因为它们对用户的含义完全不同:
3740
+ * - 有值 → 直接显示"留空会发这个";
3741
+ * - 整块缺席 → Host 没算(旧版本、或本机没有设备盐),这时一个头都不发;
3742
+ * - 有这块但这行没有 → 这个账号没有 uid,算不出来,同样不发设备头。
3743
+ * 合成一句"暂无"会把"本机不可用"和"这个账号不可用"混成同一件事。
3744
+ */
3745
+ const derivedPropsFor = (accountId) => {
3746
+ if (deviceDerived === void 0) return { derivedNote: "row.deviceDerivedUnavailable" };
3747
+ const entry = deviceDerived[accountId];
3748
+ return entry === void 0 ? { derivedNote: "row.deviceDerivedNoUid" } : { derived: entry };
3749
+ };
3359
3750
  return (0, react.createElement)("section", { className: "dsm-workbuddy-pool" }, rowBusyAction === "remove" ? (0, react.createElement)(BusyOverlay, {
3360
3751
  visible: true,
3361
3752
  message: t("row.poolRowRemoving"),
@@ -3414,7 +3805,20 @@ window.__ModuleLoader__.load({
3414
3805
  className: "dsm-btn dsm-btn-outline",
3415
3806
  disabled: rescanning === true,
3416
3807
  onClick: onRescan
3417
- }, rescanning === true ? t("row.accountsScanning") : t("row.accountsRescan")))), (0, react.createElement)("div", { className: `dsm-workbuddy-pool-table${pool.checkinSupported ? " dsm-workbuddy-pool-table-checkin" : ""}` }, (0, react.createElement)("div", { className: "dsm-workbuddy-pool-row dsm-workbuddy-pool-row-head" }, (0, react.createElement)("span", null, t("row.poolColumnAccount")), (0, react.createElement)("span", null, t("row.poolColumnCredits")), (0, react.createElement)("span", null, t("row.poolColumnProbe")), pool.checkinSupported ? (0, react.createElement)("span", null, t("row.poolColumnCheckin")) : null, (0, react.createElement)("span", null)), ...(() => {
3808
+ }, rescanning === true ? t("row.accountsScanning") : t("row.accountsRescan")))), deviceMode === void 0 || onDeviceModeChange === void 0 ? null : (0, react.createElement)("div", { className: "dsm-workbuddy-device-mode" }, (0, react.createElement)("span", { className: "dsm-workbuddy-device-mode-title" }, t("row.deviceModeTitle")), (0, react.createElement)("span", {
3809
+ className: "dsm-workbuddy-device-mode-seg",
3810
+ role: "group",
3811
+ "aria-label": t("row.deviceModeTitle")
3812
+ }, ...["virtual", "real"].map((mode) => (0, react.createElement)("button", {
3813
+ key: mode,
3814
+ type: "button",
3815
+ className: `dsm-workbuddy-device-seg-btn${deviceMode === mode ? " dsm-workbuddy-device-seg-on" : ""}`,
3816
+ "aria-pressed": deviceMode === mode,
3817
+ disabled: deviceModeBusy,
3818
+ onClick: () => {
3819
+ changeDeviceMode(mode);
3820
+ }
3821
+ }, t(mode === "virtual" ? "row.deviceModeVirtual" : "row.deviceModeReal")))), (0, react.createElement)("span", { className: "dsm-workbuddy-hint" }, deviceMode === "real" ? t("row.deviceModeHintReal") : t("row.deviceModeHintVirtual"))), (0, react.createElement)("div", { className: `dsm-workbuddy-pool-table${pool.checkinSupported ? " dsm-workbuddy-pool-table-checkin" : ""}` }, (0, react.createElement)("div", { className: "dsm-workbuddy-pool-row dsm-workbuddy-pool-row-head" }, (0, react.createElement)("span", null, t("row.poolColumnAccount")), (0, react.createElement)("span", null, t("row.poolColumnCredits")), (0, react.createElement)("span", null, t("row.poolColumnProbe")), pool.checkinSupported ? (0, react.createElement)("span", null, t("row.poolColumnCheckin")) : null, (0, react.createElement)("span", null)), ...(() => {
3418
3822
  const ordered = sortAccountsByOrder(pool.accounts, orderIds);
3419
3823
  let memberSeen = 0;
3420
3824
  let memberTotal = 0;
@@ -3445,6 +3849,18 @@ window.__ModuleLoader__.load({
3445
3849
  onRemove: () => {
3446
3850
  runRowRemove(account.accountId, account.accountName);
3447
3851
  },
3852
+ ...onSaveDeviceProfile === void 0 ? {} : { onEditDevice: () => {
3853
+ if (deviceMode === "real") {
3854
+ setDeviceBlockedOpen(true);
3855
+ return;
3856
+ }
3857
+ setDeviceError(void 0);
3858
+ setDeviceEditing({
3859
+ accountId: account.accountId,
3860
+ name: account.accountName
3861
+ });
3862
+ } },
3863
+ deviceGearBlocked: deviceMode === "real",
3448
3864
  onClaim: (kind, title, creditNum) => {
3449
3865
  runRowClaim(account.accountId, account.accountName, kind, title, creditNum);
3450
3866
  },
@@ -3522,11 +3938,31 @@ window.__ModuleLoader__.load({
3522
3938
  logStore.set(region, []);
3523
3939
  setLog([]);
3524
3940
  }
3525
- }));
3941
+ }), deviceEditing === void 0 ? null : (0, react.createElement)(DeviceProfileDialog, {
3942
+ t,
3943
+ accountName: deviceEditing.name,
3944
+ saved: {
3945
+ machineId: deviceProfiles?.[deviceEditing.accountId]?.machineId ?? "",
3946
+ sessionId: deviceProfiles?.[deviceEditing.accountId]?.sessionId ?? ""
3947
+ },
3948
+ ...derivedPropsFor(deviceEditing.accountId),
3949
+ saving: deviceSaving,
3950
+ ...deviceError === void 0 ? {} : { error: deviceError },
3951
+ onCancel: () => {
3952
+ setDeviceEditing(void 0);
3953
+ setDeviceError(void 0);
3954
+ },
3955
+ onSave: (values) => {
3956
+ saveDeviceProfileFor(deviceEditing.accountId, values);
3957
+ }
3958
+ }), deviceBlockedOpen ? (0, react.createElement)(DeviceModeBlockedDialog, {
3959
+ t,
3960
+ onClose: () => setDeviceBlockedOpen(false)
3961
+ }) : null);
3526
3962
  }
3527
3963
  /** One account's row. */
3528
3964
  function renderAccountRow(input) {
3529
- const { t, account, checked, canEdit, checkinSupported, onToggle, busy, rowBusy, testDisabled, targetHint, onTest, onRemove, onClaim, rowBusyAction, claimBusy, orderIndex, orderIsManual, moveEnabled, onMoveUp, onMoveDown, moveUpDisabled, moveDownDisabled, poolModelId } = input;
3965
+ const { t, account, checked, canEdit, checkinSupported, onToggle, busy, rowBusy, testDisabled, targetHint, onTest, onRemove, onClaim, rowBusyAction, claimBusy, orderIndex, orderIsManual, moveEnabled, onMoveUp, onMoveDown, moveUpDisabled, moveDownDisabled, poolModelId, onEditDevice, deviceGearBlocked } = input;
3530
3966
  const name = account.accountName === "" ? t("row.accountUnnamed") : account.accountName;
3531
3967
  const excluded = exclusionText(t, account.excludedBy);
3532
3968
  const probe = account.probe;
@@ -3605,7 +4041,14 @@ window.__ModuleLoader__.load({
3605
4041
  }, (0, react.createElement)("span", { className: "dsm-workbuddy-pool-probe-main" }, probeLine), probeLabel === void 0 && age === void 0 ? null : (0, react.createElement)("span", { className: "dsm-workbuddy-pool-probe-prov" }, probeLabel === void 0 ? null : (0, react.createElement)("span", { className: probeLabel.className }, probeLabel.text), probeLabel === void 0 || age === void 0 ? null : (0, react.createElement)("span", { className: "dsm-workbuddy-pool-prov-sep" }, "·"), age === void 0 ? null : (0, react.createElement)("span", { className: "dsm-workbuddy-pool-prov-age" }, age), probe !== void 0 && probe.modelId !== poolModelId ? (0, react.createElement)("span", { className: "dsm-workbuddy-pool-prov-model" }, probe.modelId === void 0 ? t("row.poolProbeModelUnknown") : t("row.poolProbeModel", { model: probe.modelId })) : null)), checkinSupported ? (0, react.createElement)("span", { className: "dsm-workbuddy-pool-checkin" }, account.enterprise === true ? (0, react.createElement)("span", { className: "dsm-workbuddy-pool-unknown" }, t("row.poolCheckinEnterprise")) : account.checkedInToday === void 0 ? (0, react.createElement)("span", {
3606
4042
  className: "dsm-workbuddy-pool-unknown",
3607
4043
  title: t("row.poolNeverTested")
3608
- }, t("row.poolCheckinUnknown")) : account.checkedInToday ? (0, react.createElement)("span", { className: "dsm-workbuddy-pool-checked" }, t("row.poolCheckedIn")) : t("row.poolNotCheckedIn")) : null, (0, react.createElement)("span", { className: "dsm-workbuddy-pool-row-actions" }, (0, react.createElement)("button", {
4044
+ }, t("row.poolCheckinUnknown")) : account.checkedInToday ? (0, react.createElement)("span", { className: "dsm-workbuddy-pool-checked" }, t("row.poolCheckedIn")) : t("row.poolNotCheckedIn")) : null, (0, react.createElement)("span", { className: "dsm-workbuddy-pool-row-actions" }, onEditDevice === void 0 ? null : (0, react.createElement)("button", {
4045
+ type: "button",
4046
+ className: `dsm-btn dsm-btn-outline dsm-workbuddy-pool-small-btn dsm-workbuddy-device-gear${deviceGearBlocked ? " dsm-workbuddy-device-gear-off" : ""}`,
4047
+ "aria-disabled": deviceGearBlocked ? true : void 0,
4048
+ title: deviceGearBlocked ? t("row.deviceGearBlockedHint") : t("row.deviceGearHint"),
4049
+ "aria-label": t("row.deviceGearAria", { accountName: name }),
4050
+ onClick: onEditDevice
4051
+ }, "⚙"), (0, react.createElement)("button", {
3609
4052
  type: "button",
3610
4053
  className: "dsm-btn dsm-btn-outline dsm-workbuddy-pool-small-btn",
3611
4054
  disabled: rowBusy || testDisabled,
@@ -3751,6 +4194,448 @@ window.__ModuleLoader__.load({
3751
4194
  })), orderIds).map((entry) => entry.account);
3752
4195
  }
3753
4196
  //#endregion
4197
+ //#region src/client/device-sdk.ts
4198
+ function normalize(body) {
4199
+ if (typeof body !== "object" || body === null) return void 0;
4200
+ const record = body;
4201
+ const sdk = record["sdk"];
4202
+ const token = record["token"];
4203
+ if (typeof sdk !== "object" || sdk === null || typeof token !== "object" || token === null) return void 0;
4204
+ const sdkRecord = sdk;
4205
+ const tokenRecord = token;
4206
+ const sdkState = sdkRecord["state"];
4207
+ const tokenState = tokenRecord["state"];
4208
+ return {
4209
+ tier: record["tier"] === "real" ? "real" : "virtual",
4210
+ sdk: {
4211
+ state: sdkState === "ready" || sdkState === "unsupported" || sdkState === "missing" || sdkState === "error" ? sdkState : "error",
4212
+ bundle: typeof sdkRecord["bundle"] === "string" ? sdkRecord["bundle"] : "",
4213
+ path: typeof sdkRecord["path"] === "string" ? sdkRecord["path"] : "",
4214
+ platform: typeof sdkRecord["platform"] === "string" ? sdkRecord["platform"] : "",
4215
+ arch: typeof sdkRecord["arch"] === "string" ? sdkRecord["arch"] : "",
4216
+ runtime: typeof sdkRecord["runtime"] === "string" ? sdkRecord["runtime"] : "",
4217
+ ...typeof sdkRecord["reason"] === "string" ? { reason: sdkRecord["reason"] } : {}
4218
+ },
4219
+ token: {
4220
+ state: tokenState === "ok" || tokenState === "stale" || tokenState === "unavailable" || tokenState === "idle" ? tokenState : "unavailable",
4221
+ masked: typeof tokenRecord["masked"] === "string" ? tokenRecord["masked"] : "",
4222
+ length: typeof tokenRecord["length"] === "number" ? tokenRecord["length"] : 0,
4223
+ ...typeof tokenRecord["fetchedAtMs"] === "number" ? { fetchedAtMs: tokenRecord["fetchedAtMs"] } : {},
4224
+ ...typeof tokenRecord["lastAttemptMs"] === "number" ? { lastAttemptMs: tokenRecord["lastAttemptMs"] } : {},
4225
+ ...typeof tokenRecord["reason"] === "string" ? { reason: tokenRecord["reason"] } : {}
4226
+ }
4227
+ };
4228
+ }
4229
+ /** 读状态。`undefined` = 这个 Host 没有这条路由(404/503),面板该整块隐藏。 */
4230
+ async function fetchDeviceSdk(path) {
4231
+ const response = await fetch(path, {
4232
+ headers: { accept: "application/json" },
4233
+ credentials: "same-origin"
4234
+ });
4235
+ if (response.status === 404 || response.status === 503) return void 0;
4236
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
4237
+ return normalize(await response.json());
4238
+ }
4239
+ async function post(path, action) {
4240
+ const response = await fetch(`${path}?action=${action}`, {
4241
+ method: "POST",
4242
+ headers: { accept: "application/json" },
4243
+ credentials: "same-origin"
4244
+ });
4245
+ if (response.status === 409) return void 0;
4246
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
4247
+ return response.json();
4248
+ }
4249
+ /** 强制重取一次(会真的跑一次 SDK)。 */
4250
+ async function refreshDeviceSdk(path) {
4251
+ return normalize(await post(path, "refresh"));
4252
+ }
4253
+ /** 取完整值。只在用户点「显示」或「复制」时调用。 */
4254
+ async function revealDeviceSdk(path) {
4255
+ const body = await post(path, "reveal");
4256
+ if (typeof body !== "object" || body === null) return void 0;
4257
+ const token = body["token"];
4258
+ return typeof token === "string" && token !== "" ? token : void 0;
4259
+ }
4260
+ //#endregion
4261
+ //#region src/client/DeviceSdkPanel.tsx
4262
+ /**
4263
+ * 卡片「SDK」分区:这台机器能不能取到真实设备参数,以及取到的是什么。
4264
+ *
4265
+ * ## 为什么它单独一页,而不是塞进「诊断」
4266
+ *
4267
+ * 诊断页是"出问题时贴给开发看的一屏事实",只读、不含操作。这一页有操作(重取、
4268
+ * 显示、复制),而且用户会在**没出问题**的时候来看它——切到「真实值」之后第一件
4269
+ * 事就是确认"真的连上了吗、值是什么"。把这两种意图混在一页,诊断页就再也没法
4270
+ * 保持"只读"这条约定。
4271
+ *
4272
+ * ## 为什么默认是星号
4273
+ *
4274
+ * 完整 token 能代表这台机器。这一页会被截图、会被贴进 issue,所以默认只给掩码;
4275
+ * 「显示」与「复制」各要一次点击,Host 也只为这两次点击返回完整值
4276
+ * (`POST ?action=reveal`,见 `src/status-paths.ts`)。
4277
+ *
4278
+ * @module dsh-connect-workbuddy/client/DeviceSdkPanel
4279
+ */
4280
+ /** How one row reads: the label on the left, the value on the right. */
4281
+ function Row(props) {
4282
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4283
+ className: "dsm-workbuddy-diag-row",
4284
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4285
+ className: "dsm-workbuddy-diag-label",
4286
+ children: props.label
4287
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4288
+ className: `dsm-workbuddy-diag-value${props.mono === true ? " dsm-workbuddy-diag-mono" : ""}`,
4289
+ children: props.children
4290
+ })]
4291
+ });
4292
+ }
4293
+ /** `12m ago` / `just now`, in the card's existing style. */
4294
+ function describeAge(t, ageMs) {
4295
+ if (ageMs < 6e4) return t("sdk.ageJustNow");
4296
+ const minutes = Math.floor(ageMs / 6e4);
4297
+ if (minutes < 60) return t("sdk.ageMinutes", { count: minutes });
4298
+ return t("sdk.ageHours", {
4299
+ count: Math.floor(minutes / 60),
4300
+ rest: minutes % 60
4301
+ });
4302
+ }
4303
+ function DeviceSdkPanel(props) {
4304
+ const { t, path, settingsPath } = props;
4305
+ const [report, setReport] = (0, react.useState)(void 0);
4306
+ const [loading, setLoading] = (0, react.useState)(true);
4307
+ const [busy, setBusy] = (0, react.useState)(false);
4308
+ const [error, setError] = (0, react.useState)(void 0);
4309
+ /** 完整值:只在用户点过「显示」或「复制」之后才在内存里存在。 */
4310
+ const [value, setValue] = (0, react.useState)(void 0);
4311
+ const [copied, setCopied] = (0, react.useState)(false);
4312
+ /**
4313
+ * 设置里的 SDK 目录与回退开关(作者意见 #1 / #2)。
4314
+ *
4315
+ * `undefined` = 还没读回来(或这个 Host 没有设置路由)。两种情况都按"不渲染编辑
4316
+ * 控件"处理:一个初值为空串的输入框看起来像"用户清空过目录",而那与实际状态
4317
+ * (走自动发现)相反。
4318
+ */
4319
+ const [sdkDir, setSdkDir] = (0, react.useState)(void 0);
4320
+ const [fallback, setFallback] = (0, react.useState)(void 0);
4321
+ const [draftDir, setDraftDir] = (0, react.useState)("");
4322
+ const [savingDir, setSavingDir] = (0, react.useState)(false);
4323
+ const [savingFallback, setSavingFallback] = (0, react.useState)(false);
4324
+ const [savedNote, setSavedNote] = (0, react.useState)(false);
4325
+ const load = (0, react.useCallback)(async (refresh) => {
4326
+ if (path === "") return;
4327
+ setBusy(true);
4328
+ setError(void 0);
4329
+ try {
4330
+ const next = refresh ? await refreshDeviceSdk(path) : await fetchDeviceSdk(path);
4331
+ setReport(next);
4332
+ if (refresh) {
4333
+ setValue(void 0);
4334
+ setCopied(false);
4335
+ }
4336
+ } catch (cause) {
4337
+ setError(cause instanceof Error ? cause.message : String(cause));
4338
+ } finally {
4339
+ setBusy(false);
4340
+ setLoading(false);
4341
+ }
4342
+ }, [path]);
4343
+ /**
4344
+ * 读设置。与 SDK 状态**分两次**取,理由与 `settingsPath` 分开一样:两者可以
4345
+ * 各自缺席,而合成一次请求会让"设置路由没有"顺带把 SDK 状态也变成错误。
4346
+ */
4347
+ const loadSettings = (0, react.useCallback)(async () => {
4348
+ if (settingsPath === "") return;
4349
+ try {
4350
+ const settings = await fetchDeviceSettings(settingsPath);
4351
+ if (settings === void 0) return;
4352
+ setSdkDir(settings.sdkDir);
4353
+ setFallback(settings.sdkFallbackToVirtual);
4354
+ setDraftDir(settings.sdkDir);
4355
+ } catch {}
4356
+ }, [settingsPath]);
4357
+ (0, react.useEffect)(() => {
4358
+ load(false);
4359
+ }, [load]);
4360
+ (0, react.useEffect)(() => {
4361
+ loadSettings();
4362
+ }, [loadSettings]);
4363
+ /**
4364
+ * 「已加载、没取过」不该停在屏幕上。
4365
+ *
4366
+ * 启动时的后台预热要起一个子进程再等一次网络(约几百毫秒),而这一页是在用户
4367
+ * 点开标签时挂载的——两者偶尔会撞在一起,那一瞬间读到的就是 idle。这里做有限次
4368
+ * 复查(最多 5 次、每次 1.2 秒):预热一落地,这一行自己变成"可用",而不是要用户
4369
+ * 手动点一次「重新获取」。上限是必须的——预热真的失败时,无限轮询只是一台一直
4370
+ * 发 GET 的机器。
4371
+ */
4372
+ const idlePolls = (0, react.useRef)(0);
4373
+ (0, react.useEffect)(() => {
4374
+ if (path === "") return;
4375
+ if (report?.sdk.state !== "ready" || report.token.state !== "idle") return;
4376
+ if (idlePolls.current >= 5) return;
4377
+ idlePolls.current += 1;
4378
+ const timer = window.setTimeout(() => {
4379
+ fetchDeviceSdk(path).then((next) => {
4380
+ if (next !== void 0) setReport(next);
4381
+ }).catch(() => {});
4382
+ }, 1200);
4383
+ return () => window.clearTimeout(timer);
4384
+ }, [path, report]);
4385
+ if (path === "") return null;
4386
+ if (loading) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4387
+ className: "dsm-workbuddy-panel-note",
4388
+ children: t("sdk.loading")
4389
+ });
4390
+ if (report === void 0 && error === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4391
+ className: "dsm-workbuddy-panel-note",
4392
+ children: t("sdk.unavailable")
4393
+ });
4394
+ const toggle = async () => {
4395
+ if (value !== void 0) {
4396
+ setValue(void 0);
4397
+ return;
4398
+ }
4399
+ setError(void 0);
4400
+ try {
4401
+ const full = await revealDeviceSdk(path);
4402
+ if (full === void 0) setError(t("sdk.noValue"));
4403
+ else setValue(full);
4404
+ } catch (cause) {
4405
+ setError(cause instanceof Error ? cause.message : String(cause));
4406
+ }
4407
+ };
4408
+ const copy = async () => {
4409
+ setError(void 0);
4410
+ try {
4411
+ const full = value ?? await revealDeviceSdk(path);
4412
+ if (full === void 0) {
4413
+ setError(t("sdk.noValue"));
4414
+ return;
4415
+ }
4416
+ await navigator.clipboard.writeText(full);
4417
+ setCopied(true);
4418
+ window.setTimeout(() => {
4419
+ setCopied(false);
4420
+ }, 2e3);
4421
+ } catch (cause) {
4422
+ setError(cause instanceof Error ? cause.message : String(cause));
4423
+ }
4424
+ };
4425
+ /**
4426
+ * 保存目录:写盘之后**立刻重探一次**。
4427
+ *
4428
+ * 只写不重探会让用户看见"已保存"而状态行还是旧的——那正是这条意见要消掉的
4429
+ * 迷雾(`dirSource` 让新目录下一次 `probe` 就生效,所以这里必须主动触发那一次)。
4430
+ */
4431
+ const saveDir = async () => {
4432
+ if (settingsPath === "") return;
4433
+ setSavingDir(true);
4434
+ setError(void 0);
4435
+ setSavedNote(false);
4436
+ try {
4437
+ const next = await putDeviceSdk(settingsPath, { sdkDir: draftDir.trim() });
4438
+ setSdkDir(next.sdkDir);
4439
+ setDraftDir(next.sdkDir);
4440
+ setSavedNote(true);
4441
+ await load(true);
4442
+ } catch (cause) {
4443
+ setError(cause instanceof Error ? cause.message : String(cause));
4444
+ } finally {
4445
+ setSavingDir(false);
4446
+ }
4447
+ };
4448
+ const saveFallback = async (value) => {
4449
+ if (settingsPath === "") return;
4450
+ setSavingFallback(true);
4451
+ setError(void 0);
4452
+ try {
4453
+ const next = await putDeviceSdk(settingsPath, { sdkFallbackToVirtual: value });
4454
+ setFallback(next.sdkFallbackToVirtual);
4455
+ } catch (cause) {
4456
+ setError(cause instanceof Error ? cause.message : String(cause));
4457
+ } finally {
4458
+ setSavingFallback(false);
4459
+ }
4460
+ };
4461
+ const sdk = report?.sdk;
4462
+ const token = report?.token;
4463
+ const stateKey = sdk?.state === "ready" ? token?.state === "ok" ? "sdk.statusReady" : token?.state === "stale" ? "sdk.statusStale" : "sdk.statusNoToken" : sdk?.state === "missing" ? "sdk.statusMissing" : sdk?.state === "unsupported" ? "sdk.statusUnsupported" : "sdk.statusError";
4464
+ const stateOk = sdk?.state === "ready" && token?.state === "ok";
4465
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
4466
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4467
+ className: "dsm-workbuddy-panel-note",
4468
+ children: t("sdk.hint")
4469
+ }),
4470
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4471
+ className: "dsm-workbuddy-diag",
4472
+ children: [
4473
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Row, {
4474
+ label: t("sdk.state"),
4475
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4476
+ className: `dsm-workbuddy-sdk-dot${stateOk ? " dsm-workbuddy-sdk-dot-ok" : ""}`,
4477
+ "aria-hidden": "true"
4478
+ }), t(stateKey)]
4479
+ }),
4480
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Row, {
4481
+ label: t("sdk.bundle"),
4482
+ mono: true,
4483
+ children: sdk === void 0 || sdk.bundle === "" ? t("sdk.unknown") : `${sdk.bundle} · ${sdk.path}`
4484
+ }),
4485
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Row, {
4486
+ label: t("sdk.runtime"),
4487
+ mono: true,
4488
+ children: sdk === void 0 || sdk.runtime === "" ? t("sdk.unknown") : sdk.runtime
4489
+ }),
4490
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Row, {
4491
+ label: t("sdk.fetched"),
4492
+ children: token?.fetchedAtMs === void 0 ? t("sdk.never") : `${new Date(token.fetchedAtMs).toLocaleTimeString()} (${describeAge(t, Date.now() - token.fetchedAtMs)})`
4493
+ }),
4494
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Row, {
4495
+ label: t("sdk.tier"),
4496
+ children: report?.tier === "real" ? t("sdk.tierReal") : t("sdk.tierVirtual")
4497
+ })
4498
+ ]
4499
+ }),
4500
+ sdk !== void 0 && sdk.reason !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4501
+ className: "dsm-workbuddy-device-error",
4502
+ children: sdk.reason
4503
+ }) : null,
4504
+ token !== void 0 && token.reason !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4505
+ className: "dsm-workbuddy-device-error",
4506
+ children: token.reason
4507
+ }) : null,
4508
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4509
+ className: "dsm-workbuddy-device-field",
4510
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4511
+ className: "dsm-workbuddy-device-field-label",
4512
+ children: t("sdk.valueLabel")
4513
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
4514
+ className: "dsm-workbuddy-sdk-value",
4515
+ "aria-label": t("sdk.valueLabel"),
4516
+ children: token === void 0 || token.length === 0 ? t("sdk.noValue") : value ?? `${token.masked}${token.length === 0 ? "" : ` (${t("sdk.length", { count: token.length })})`}`
4517
+ })]
4518
+ }),
4519
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4520
+ className: "dsm-workbuddy-device-random-row",
4521
+ children: [
4522
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4523
+ type: "button",
4524
+ className: "dsm-btn dsm-btn-outline",
4525
+ disabled: busy || token === void 0 || token.length === 0,
4526
+ onClick: () => {
4527
+ toggle();
4528
+ },
4529
+ children: value === void 0 ? t("sdk.reveal") : t("sdk.hide")
4530
+ }),
4531
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4532
+ type: "button",
4533
+ className: "dsm-btn dsm-btn-outline",
4534
+ disabled: busy || token === void 0 || token.length === 0,
4535
+ onClick: () => {
4536
+ copy();
4537
+ },
4538
+ children: copied ? t("sdk.copied") : t("sdk.copy")
4539
+ }),
4540
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4541
+ type: "button",
4542
+ className: "dsm-btn dsm-btn-outline",
4543
+ disabled: busy,
4544
+ onClick: () => {
4545
+ load(true);
4546
+ },
4547
+ children: busy ? t("sdk.refreshing") : t("sdk.refresh")
4548
+ })
4549
+ ]
4550
+ }),
4551
+ settingsPath === "" || sdkDir === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
4552
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4553
+ className: "dsm-workbuddy-device-field",
4554
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4555
+ className: "dsm-workbuddy-device-field-label",
4556
+ children: t("sdk.dirLabel")
4557
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4558
+ className: "dsm-workbuddy-sdk-dir-row",
4559
+ children: [
4560
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
4561
+ type: "text",
4562
+ className: "dsm-workbuddy-device-input dsm-workbuddy-sdk-dir-input",
4563
+ value: draftDir,
4564
+ placeholder: t("sdk.dirPlaceholder"),
4565
+ spellCheck: false,
4566
+ autoComplete: "off",
4567
+ "aria-label": t("sdk.dirLabel"),
4568
+ onChange: (event) => {
4569
+ setDraftDir(event.target.value);
4570
+ setSavedNote(false);
4571
+ }
4572
+ }),
4573
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4574
+ type: "button",
4575
+ className: "dsm-btn dsm-btn-outline",
4576
+ disabled: savingDir || draftDir.trim() === sdkDir,
4577
+ onClick: () => {
4578
+ saveDir();
4579
+ },
4580
+ children: savingDir ? t("sdk.dirSaving") : t("sdk.dirSave")
4581
+ }),
4582
+ sdkDir === "" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4583
+ type: "button",
4584
+ className: "dsm-btn dsm-btn-outline",
4585
+ disabled: savingDir,
4586
+ onClick: () => {
4587
+ setDraftDir("");
4588
+ (async () => {
4589
+ setSavingDir(true);
4590
+ setError(void 0);
4591
+ try {
4592
+ const next = await putDeviceSdk(settingsPath, { sdkDir: "" });
4593
+ setSdkDir(next.sdkDir);
4594
+ setDraftDir("");
4595
+ setSavedNote(true);
4596
+ await load(true);
4597
+ } catch (cause) {
4598
+ setError(cause instanceof Error ? cause.message : String(cause));
4599
+ } finally {
4600
+ setSavingDir(false);
4601
+ }
4602
+ })();
4603
+ },
4604
+ children: t("sdk.dirClear")
4605
+ })
4606
+ ]
4607
+ })]
4608
+ }),
4609
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
4610
+ className: "dsm-workbuddy-hint",
4611
+ children: [savedNote ? `${t("sdk.dirSaved")} ` : "", t("sdk.dirHint")]
4612
+ }),
4613
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4614
+ className: "dsm-workbuddy-device-random-row",
4615
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
4616
+ className: "dsm-workbuddy-sdk-switch",
4617
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
4618
+ type: "checkbox",
4619
+ checked: fallback ?? true,
4620
+ disabled: savingFallback || fallback === void 0,
4621
+ onChange: (event) => {
4622
+ saveFallback(event.target.checked);
4623
+ }
4624
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("sdk.fallbackLabel") })]
4625
+ })
4626
+ }),
4627
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4628
+ className: "dsm-workbuddy-hint",
4629
+ children: t("sdk.fallbackHint")
4630
+ })
4631
+ ] }),
4632
+ error === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4633
+ className: "dsm-workbuddy-device-error",
4634
+ children: error
4635
+ })
4636
+ ] });
4637
+ }
4638
+ //#endregion
3754
4639
  //#region src/client/OAuthSignIn.tsx
3755
4640
  /**
3756
4641
  * The card's OAuth QR sign-in section: one resting bar row plus a dialog
@@ -5829,6 +6714,136 @@ window.__ModuleLoader__.load({
5829
6714
  @keyframes dsm-workbuddy-veil-spin{to{transform:rotate(360deg)}}
5830
6715
  @keyframes dsm-workbuddy-veil-dash{0%{stroke-dasharray:12 150;stroke-dashoffset:0}50%{stroke-dasharray:24 150;stroke-dashoffset:-6}to{stroke-dasharray:12 150;stroke-dashoffset:0}}
5831
6716
  @media (prefers-reduced-motion: reduce){.dsm-workbuddy-veil-spinner{animation:none}.dsm-workbuddy-veil-spinner-arc{animation:none;stroke-dasharray:18 150;stroke-dashoffset:-3}}
6717
+
6718
+ /* ---- 设备头档位与逐账号参数弹窗 ------------------------------------------
6719
+ 档位那一行贴着账号表:它同时决定"这台机器对外声称自己是谁"和"每行的齿轮能
6720
+ 不能用",埋进「更多设置」会让齿轮看起来时好时坏。
6721
+ 弹窗用 fixed 遮罩而不是行内展开:每行已经有两个按钮和一段探针文本,再展开
6722
+ 两块输入框会把表格挤成表单;而且这些值必须显式确认,误点不该直接生效。 */
6723
+ .dsm-workbuddy-device-mode{
6724
+ display:flex;flex-wrap:wrap;align-items:center;gap:8px;
6725
+ margin:10px 0 2px;
6726
+ }
6727
+ .dsm-workbuddy-device-mode-title{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary,#e8e9ed)}
6728
+ .dsm-workbuddy-device-mode-seg{
6729
+ display:inline-flex;border:1px solid var(--dsw-alias-border-l2,#3a3d45);
6730
+ border-radius:999px;overflow:hidden;
6731
+ }
6732
+ /* 分段控件:两个按钮共享一条边框,选中态用底色而不是描边——描边会让"选中"
6733
+ 与"聚焦"看起来一样,键盘操作时分不清光标在哪。 */
6734
+ .dsm-workbuddy-device-seg-btn{
6735
+ appearance:none;border:0;background:transparent;cursor:pointer;
6736
+ padding:2px 10px;font:inherit;font-size:12px;line-height:20px;
6737
+ color:var(--dsw-alias-label-secondary,#b8bcc4);
6738
+ }
6739
+ /* 悬停必须排除选中项:btn:hover 的选择器权重比 .seg-on 高,不排除的话鼠标
6740
+ 一划过去,选中的那一格就会被换成半透明底,看起来像"选中被取消了"。 */
6741
+ .dsm-workbuddy-device-seg-btn:hover:not(:disabled):not(.dsm-workbuddy-device-seg-on){background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12))}
6742
+ .dsm-workbuddy-device-seg-btn:disabled{opacity:.55;cursor:default}
6743
+ /* 选中态用"前景色做底、底色做字"这一对,而不是品牌色底 + 白字。
6744
+ 原因写在截图里:暗色主题下 --dsw-alias-brand-primary 本身就是一枚浅色,
6745
+ 白字落上去等于整格消失(用户看到的是一个空白胶囊)。把两者绑成反相关系后,
6746
+ 亮色主题是深底浅字、暗色主题是浅底深字,任何主题都不可能出现同色叠同色——
6747
+ 因为这两个变量按定义就互为背景与文字。 */
6748
+ .dsm-workbuddy-device-seg-on{
6749
+ background:var(--dsw-alias-label-primary,#ededed);
6750
+ color:var(--dsw-alias-bg-base,#181818);
6751
+ font-weight:600;
6752
+ }
6753
+ /* 兜底:万一宿主没注入 bg-base,回落值也得跟着主题走,否则亮色主题下会变成
6754
+ "深底 + 深字"。变量在的时候这一段不生效。 */
6755
+ @media (prefers-color-scheme: light){
6756
+ .dsm-workbuddy-device-seg-on{background:var(--dsw-alias-label-primary,#202020);color:var(--dsw-alias-bg-base,#fff)}
6757
+ }
6758
+ /* 齿轮:置灰只表达"现在用不了",仍然可点——点了会说明原因。 */
6759
+ .dsm-workbuddy-device-gear{line-height:1;padding:0 6px}
6760
+ .dsm-workbuddy-device-gear-off{opacity:.45}
6761
+ .dsm-workbuddy-device-backdrop{
6762
+ position:fixed;inset:0;z-index:70;
6763
+ display:flex;align-items:center;justify-content:center;
6764
+ padding:16px;
6765
+ background:var(--dsw-alias-bg-mask-1,rgba(0,0,0,.32));
6766
+ backdrop-filter:var(--dsw-mask-blur);
6767
+ }
6768
+ .dsm-workbuddy-device-dialog{
6769
+ width:min(460px,100%);max-height:calc(100vh - 32px);overflow:auto;
6770
+ padding:16px;
6771
+ border:1px solid var(--dsw-alias-border-l2,#3a3d45);border-radius:12px;
6772
+ background:var(--dsw-alias-bg-layer-3,var(--dsw-alias-bg-l1,#1b1d23));
6773
+ color:var(--dsw-alias-label-primary,#e8e9ed);
6774
+ box-shadow:0 12px 40px rgba(0,0,0,.35);
6775
+ }
6776
+ .dsm-workbuddy-device-title{margin:0 0 8px;font-size:13px;font-weight:600}
6777
+ .dsm-workbuddy-device-field{display:flex;flex-direction:column;gap:4px;margin:10px 0}
6778
+ .dsm-workbuddy-device-field-label{font-size:12px;color:var(--dsw-alias-label-secondary,#b8bcc4)}
6779
+ .dsm-workbuddy-device-input{
6780
+ font:inherit;font-size:12px;line-height:20px;
6781
+ font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
6782
+ padding:4px 8px;border-radius:6px;
6783
+ color:var(--dsw-alias-label-primary,#e8e9ed);
6784
+ background:var(--dsw-alias-bg-l1,transparent);
6785
+ border:1px solid var(--dsw-alias-border-l2,#3a3d45);
6786
+ }
6787
+
6788
+ /* SDK 目录输入行(作者意见 #1):输入框吃掉剩余宽度,按钮不换行。
6789
+ 与 .dsm-workbuddy-device-input 同一套外观,只改布局——单独一条而不是复用
6790
+ 弹窗那条,是因为这里旁边还有 1~2 个按钮,而弹窗里是上下堆叠。 */
6791
+ .dsm-workbuddy-sdk-dir-row{display:flex;align-items:center;gap:8px;margin:2px 0 4px}
6792
+ .dsm-workbuddy-sdk-dir-input{flex:1 1 auto;min-width:0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
6793
+ /* 回退开关:勾选框交回平台(accent-color),方框尺寸/圆角/勾形不由我们画。 */
6794
+ .dsm-workbuddy-sdk-switch{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--dsw-alias-label-primary,#e8e9ed);cursor:pointer}
6795
+ .dsm-workbuddy-sdk-switch input{accent-color:var(--dsw-alias-brand-primary,#5686fe)}
6796
+ .dsm-workbuddy-device-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary,#5686fe)}
6797
+ .dsm-workbuddy-device-input-bad{border-color:var(--dsw-alias-label-error,#e5534b)}
6798
+ .dsm-workbuddy-device-error{color:var(--dsw-alias-label-error,#e5534b);font-size:12px;margin:4px 0 0}
6799
+ .dsm-workbuddy-device-random-row{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:6px 0 12px}
6800
+ /* P3 的占位行:虚线边框 + 降低对比度,读起来是"位置已经留好,还没接线"。
6801
+ 标题用 label-primary 而不是 label-dimmed:它是这一段的主语("真实设备
6802
+ Token"),dimmed 在亮色主题下几乎和背景同色,在暗色主题下又只剩一层灰雾。
6803
+ 虚线边框已经表达了"占位",不需要再靠文字颜色降级。 */
6804
+ .dsm-workbuddy-device-p3{
6805
+ display:flex;flex-direction:column;gap:2px;margin:0 0 12px;padding:8px 10px;
6806
+ border:1px dashed var(--dsw-alias-border-l2,#3a3d45);border-radius:8px;
6807
+ }
6808
+ .dsm-workbuddy-device-p3-label{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary,#e8e9ed)}
6809
+ .dsm-workbuddy-device-p3 .dsm-workbuddy-hint{color:var(--dsw-alias-label-secondary,#b8bcc4)}
6810
+ /* 自动派生值:只在对应输入框为空时出现,所以它承担的是"你留空会发生什么"这个
6811
+ 答案,必须能被复制走。等宽 + 可整段选中最省事(user-select:all 一次点击就
6812
+ 选中整串 36 位 id,比再放一个复制按钮少一次交互,也不用管剪贴板权限)。 */
6813
+ .dsm-workbuddy-device-derived{
6814
+ display:flex;flex-wrap:wrap;align-items:baseline;gap:6px;
6815
+ font-size:11px;line-height:16px;
6816
+ color:var(--dsw-alias-label-secondary,#b8bcc4);
6817
+ }
6818
+ .dsm-workbuddy-device-derived code{
6819
+ font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
6820
+ font-size:11px;line-height:16px;
6821
+ color:var(--dsw-alias-label-primary,#e8e9ed);
6822
+ word-break:break-all;user-select:all;
6823
+ }
6824
+ .dsm-workbuddy-device-derived-missing{color:var(--dsw-alias-label-secondary,#b8bcc4);font-size:11px}
6825
+ .dsm-workbuddy-device-dialog-actions{display:flex;gap:8px;justify-content:flex-end;flex-wrap:wrap}
6826
+
6827
+ /* ---- 「SDK」分区:连接状态与真实取值 --------------------------------------
6828
+ 状态点用 6px 圆点而不是图标:这一行已经有文字说清楚状态,圆点只负责"一眼"。
6829
+ token 块必须能换行——真实 token 一千多字符,不换行会把面板撑出一条横向滚动,
6830
+ 而横向滚动条会让"复制"按钮跑出视口。 */
6831
+ .dsm-workbuddy-sdk-dot{
6832
+ display:inline-block;width:6px;height:6px;margin-right:6px;border-radius:50%;
6833
+ background:var(--dsw-alias-label-error,#e5534b);vertical-align:middle;
6834
+ }
6835
+ .dsm-workbuddy-sdk-dot-ok{background:var(--dsw-alias-label-success,#3fb950)}
6836
+ .dsm-workbuddy-sdk-value{
6837
+ display:block;max-height:96px;overflow:auto;
6838
+ font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
6839
+ font-size:11px;line-height:16px;
6840
+ word-break:break-all;white-space:pre-wrap;
6841
+ padding:4px 8px;border-radius:6px;
6842
+ color:var(--dsw-alias-label-primary,#e8e9ed);
6843
+ background:var(--dsw-alias-bg-l1,transparent);
6844
+ border:1px solid var(--dsw-alias-border-l2,#3a3d45);
6845
+ }
6846
+
5832
6847
  `;
5833
6848
  /**
5834
6849
  * Composer credit readout styles, injected by the readout component itself.
@@ -6691,6 +7706,13 @@ window.__ModuleLoader__.load({
6691
7706
  * — the two save buttons are serialized to make that impossible.
6692
7707
  */
6693
7708
  const [poolBusy, setPoolBusy] = (0, react.useState)(false);
7709
+ /**
7710
+ * 设备头设置:`undefined` = 还没读到 / 这台 Host 没有这条路由。
7711
+ *
7712
+ * 两种"没有值"必须合并成同一个信号(不渲染控件),因为卡片无论哪种情况都不该
7713
+ * 显示一个点不动的开关;区别只在实现上:前者下一轮轮询会补上,后者永远不会。
7714
+ */
7715
+ const [deviceSettings, setDeviceSettings] = (0, react.useState)(void 0);
6694
7716
  /** A refused account write (silently unpersisted settings on a locked file). */
6695
7717
  const [accountError, setAccountError] = (0, react.useState)(void 0);
6696
7718
  /** Region whose on/off checkbox write is in flight, so its box can't race. */
@@ -6998,6 +8020,36 @@ window.__ModuleLoader__.load({
6998
8020
  status.status
6999
8021
  ]);
7000
8022
  /**
8023
+ * 设备头设置:卡片打开时读一次。
8024
+ *
8025
+ * 不跟 60 秒轮询走:这份文档只在用户自己点开关或保存齿轮时变,定时重读只是
8026
+ * 每分钟多一次请求。每次写完都把 Host 的返回值直接放进状态(见下面两个
8027
+ * handler),所以这个标签页看到的永远是最新写入的那一份。
8028
+ */
8029
+ (0, react.useEffect)(() => {
8030
+ if (!open) return;
8031
+ let cancelled = false;
8032
+ (async () => {
8033
+ try {
8034
+ const settings = await fetchDeviceSettings(WORKBUDDY_DEVICE_PROFILE_PATH);
8035
+ if (!cancelled && mounted.current) setDeviceSettings(settings);
8036
+ } catch {}
8037
+ })();
8038
+ return () => {
8039
+ cancelled = true;
8040
+ };
8041
+ }, [open]);
8042
+ /** 切档:Host 是唯一真源,所以用它的返回值覆盖本地状态,而不是猜一个。 */
8043
+ const changeDeviceMode = async (mode) => {
8044
+ const settings = await putDeviceMode(WORKBUDDY_DEVICE_PROFILE_PATH, mode);
8045
+ if (mounted.current) setDeviceSettings(settings);
8046
+ };
8047
+ /** 保存一个账号的覆盖值。抛错由 AccountPool 接住并留在弹窗里。 */
8048
+ const saveDeviceProfile = async (accountId, values) => {
8049
+ const settings = await putDeviceProfile(WORKBUDDY_DEVICE_PROFILE_PATH, accountId, values);
8050
+ if (mounted.current) setDeviceSettings(settings);
8051
+ };
8052
+ /**
7001
8053
  * Recover from a failed status read without a close/reopen.
7002
8054
  *
7003
8055
  * Keyed on the document identity (`loaded`), not on `status.status`: every
@@ -8716,6 +9768,18 @@ window.__ModuleLoader__.load({
8716
9768
  setPanel("diag");
8717
9769
  },
8718
9770
  children: t("row.panelDiag")
9771
+ }),
9772
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
9773
+ type: "button",
9774
+ role: "tab",
9775
+ id: "dsm-workbuddy-tab-sdk",
9776
+ "aria-controls": "dsm-workbuddy-panel-sdk",
9777
+ "aria-selected": panel === "sdk",
9778
+ className: `dsm-workbuddy-panel-tab${panel === "sdk" ? " dsm-workbuddy-panel-tab-active" : ""}`,
9779
+ onClick: () => {
9780
+ setPanel("sdk");
9781
+ },
9782
+ children: t("row.panelSdk")
8719
9783
  })
8720
9784
  ]
8721
9785
  }) : null,
@@ -8797,7 +9861,14 @@ window.__ModuleLoader__.load({
8797
9861
  siblingBusy: saving || togglingRegion !== void 0,
8798
9862
  onBusyChange: setPoolBusy,
8799
9863
  onSaved: async () => await refreshUsage(activeRegion) !== void 0,
8800
- onRefresh: () => refreshUsage(activeRegion)
9864
+ onRefresh: () => refreshUsage(activeRegion),
9865
+ ...deviceSettings === void 0 ? {} : {
9866
+ deviceMode: deviceSettings.mode,
9867
+ deviceProfiles: deviceSettings.accounts,
9868
+ ...deviceSettings.derived === void 0 ? {} : { deviceDerived: deviceSettings.derived },
9869
+ onDeviceModeChange: changeDeviceMode,
9870
+ onSaveDeviceProfile: saveDeviceProfile
9871
+ }
8801
9872
  })
8802
9873
  ] }) : null
8803
9874
  ]
@@ -9237,6 +10308,18 @@ window.__ModuleLoader__.load({
9237
10308
  children: t("row.diagHint")
9238
10309
  })] })
9239
10310
  }),
10311
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
10312
+ className: "dsm-workbuddy-panel",
10313
+ role: "tabpanel",
10314
+ id: "dsm-workbuddy-panel-sdk",
10315
+ "aria-labelledby": "dsm-workbuddy-tab-sdk",
10316
+ hidden: !signedIn || panel !== "sdk",
10317
+ children: panel === "sdk" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DeviceSdkPanel, {
10318
+ t,
10319
+ path: WORKBUDDY_DEVICE_SDK_PATH,
10320
+ settingsPath: WORKBUDDY_DEVICE_PROFILE_PATH
10321
+ }) : null
10322
+ }),
9240
10323
  status.status === "signed-out" && loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
9241
10324
  className: "dsm-workbuddy-usage-text",
9242
10325
  role: "status",
@@ -11322,6 +12405,72 @@ window.__ModuleLoader__.load({
11322
12405
  "row.poolRowRemoved": "{accountName}: hidden from the list. 「Detect accounts again」 re-adds it; the desktop app stays signed in.",
11323
12406
  "row.poolRowRemoving": "Removing the account…",
11324
12407
  "row.poolRowRemoveDesktopOnly": "{accountName}: hidden from the list — this account comes from the desktop app's own sign-in, which is left untouched. 「Detect accounts again」 re-adds it.",
12408
+ "row.deviceModeTitle": "Device identity",
12409
+ "row.deviceModeVirtual": "Virtual",
12410
+ "row.deviceModeReal": "Real",
12411
+ "row.deviceModeHintVirtual": "Every account presents a virtual device id derived from this machine. Use the gear on a row to set one by hand.",
12412
+ "row.deviceModeHintReal": "Every account presents this machine's real device, signed by the WorkBuddy desktop SDK installed here. The gear is off — one real machine cannot be given two different ids. If the SDK is unavailable, no device header is sent at all (see 「SDK」).",
12413
+ "row.deviceGearHint": "Edit this account's device id (X-Machine-ID / X-Session-ID)",
12414
+ "row.deviceGearBlockedHint": "Only available in the Virtual tier",
12415
+ "row.deviceGearAria": "Edit device parameters for {accountName}",
12416
+ "row.deviceModeRealBlockedTitle": "Switch to Virtual first",
12417
+ "row.deviceModeRealBlocked": "In the Real tier every account shares one real device, so there is nothing per-account to set. Switch the device identity to 「Virtual」 and open the gear again.",
12418
+ "row.deviceDialogTitle": "Device parameters · {accountName}",
12419
+ "row.deviceDialogIntro": "These two values are the X-Machine-ID / X-Session-ID this account presents upstream. Leave a field empty to keep deriving it from this machine's salt — the value that will be sent is shown under the field.",
12420
+ "row.deviceMachineLabel": "Machine ID (X-Machine-ID)",
12421
+ "row.deviceSessionLabel": "Session ID (X-Session-ID)",
12422
+ "row.deviceFieldPlaceholder": "Empty = derived automatically",
12423
+ "row.deviceDerivedNow": "Derived now:",
12424
+ "row.deviceDerivedUnavailable": "No derived value to show — this machine has no device salt yet, so no X-Machine-ID / X-Session-ID is sent.",
12425
+ "row.deviceDerivedNoUid": "This account has no uid, so nothing can be derived for it — it sends no X-Machine-ID / X-Session-ID.",
12426
+ "row.deviceRandom": "Randomize",
12427
+ "row.deviceRandomHint": "Fills both with random 36-character ids",
12428
+ "row.deviceDialogP3": "Real device token",
12429
+ "row.deviceDialogP3Hint": "Signed by the Turing Shield SDK of the WorkBuddy desktop app installed here. The Real tier uses it for every account; it is not editable here — see the 「SDK」 section.",
12430
+ "row.deviceDialogCancel": "Cancel",
12431
+ "row.deviceDialogSave": "Save",
12432
+ "row.deviceDialogSaving": "Saving…",
12433
+ "row.deviceInvalid": "Needs 36 lowercase hex characters (0-9a-f)",
12434
+ "row.panelSdk": "SDK",
12435
+ "sdk.hint": "The real device token this machine signs through the installed WorkBuddy desktop SDK. Every account sends this one value in the Real tier; the Virtual tier never sends it (the token is still kept warm so this page always shows the current one).",
12436
+ "sdk.loading": "Asking the SDK…",
12437
+ "sdk.unavailable": "This Host build has no SDK route — real device parameters are not available here. The Virtual tier still works.",
12438
+ "sdk.state": "Connection",
12439
+ "sdk.statusReady": "Working",
12440
+ "sdk.statusStale": "Reachable, but the last fetch failed — serving the previous token",
12441
+ "sdk.statusNoToken": "SDK loaded, no token yet — open 「Refresh」",
12442
+ "sdk.statusMissing": "No installed WorkBuddy desktop SDK found on this machine",
12443
+ "sdk.statusUnsupported": "The SDK refused this platform",
12444
+ "sdk.statusError": "The SDK could not be loaded",
12445
+ "sdk.bundle": "SDK",
12446
+ "sdk.runtime": "Runtime",
12447
+ "sdk.fetched": "Last fetched",
12448
+ "sdk.tier": "Tier in use",
12449
+ "sdk.tierReal": "Real — accounts send this token",
12450
+ "sdk.tierVirtual": "Virtual — this token is not sent",
12451
+ "sdk.valueLabel": "X-Device-Token",
12452
+ "sdk.noValue": "No token available",
12453
+ "sdk.length": "{count} chars",
12454
+ "sdk.reveal": "Show",
12455
+ "sdk.hide": "Hide",
12456
+ "sdk.copy": "Copy",
12457
+ "sdk.copied": "Copied",
12458
+ "sdk.refresh": "Fetch again",
12459
+ "sdk.refreshing": "Fetching…",
12460
+ "sdk.never": "Never",
12461
+ "sdk.unknown": "Unknown",
12462
+ "sdk.ageJustNow": "just now",
12463
+ "sdk.ageMinutes": "{count}m ago",
12464
+ "sdk.ageHours": "{count}h {rest}m ago",
12465
+ "sdk.dirLabel": "SDK directory",
12466
+ "sdk.dirPlaceholder": "Empty = find the installed desktop app automatically",
12467
+ "sdk.dirSave": "Save",
12468
+ "sdk.dirSaving": "Saving…",
12469
+ "sdk.dirSaved": "Saved.",
12470
+ "sdk.dirClear": "Clear",
12471
+ "sdk.dirHint": "Point this at the desktop app's native/turing-sdk folder, not the folder holding WorkBuddy.exe. Saving re-probes immediately; a wrong path turns the state above into \"not found\" with that path shown, never a silent fall back to discovery. WORKBUDDY_TURING_SDK_DIR still wins.",
12472
+ "sdk.fallbackLabel": "Fall back to the virtual device when no real one is available",
12473
+ "sdk.fallbackHint": "On: when the SDK is unavailable (no desktop app, wrong directory, no token) the plugin sends the salt-derived virtual device pair instead, and the tier shown changes to “Virtual” with it — it never claims to be real. Off: no device header is sent at all, which is what the Real tier did before this switch.",
11325
12474
  "row.upstreamHint": "These change what the gateway sees, not which provider serves the call. All of them are sampled when the plugin mounts, so reload the plugin (or restart DSH) after changing one.",
11326
12475
  "row.usageIdentityLabel": "Make the usage page record these calls like the official client",
11327
12476
  "row.usageIdentityHint": "Adds the X-IDE-* headers (which fill the 使用端 column, otherwise blank) and sends conversation ids as 32-hex UUIDv7. Display alignment only: the User-Agent and the request body never change. Off by default because the evidence comes from a reporter, not from this plugin.",
@@ -11762,6 +12911,72 @@ window.__ModuleLoader__.load({
11762
12911
  "row.poolRowRemoved": "{accountName}:已从列表中隐藏。点「重新检测账号」会重新加入,桌面 App 的登录不受影响。",
11763
12912
  "row.poolRowRemoving": "正在删除账号…",
11764
12913
  "row.poolRowRemoveDesktopOnly": "{accountName}:已从列表中隐藏——这个账号来自桌面 App 自己的登录,该登录未被改动。点「重新检测账号」会重新加入。",
12914
+ "row.deviceModeTitle": "设备头",
12915
+ "row.deviceModeVirtual": "虚拟值",
12916
+ "row.deviceModeReal": "真实值",
12917
+ "row.deviceModeHintVirtual": "每个账号使用一台按本机盐派生的虚拟设备。点某行右侧的齿轮可以手工指定它的值。",
12918
+ "row.deviceModeHintReal": "所有账号共用这台机器真实的设备,由本机安装的 WorkBuddy 桌面端 SDK 签发。齿轮已关闭——一台真机不能有两个不同的 id。SDK 不可用时一个设备头都不发(见「SDK」分区)。",
12919
+ "row.deviceGearHint": "编辑这个账号的设备标识(X-Machine-ID / X-Session-ID)",
12920
+ "row.deviceGearBlockedHint": "只在「虚拟值」档下可用",
12921
+ "row.deviceGearAria": "编辑 {accountName} 的设备参数",
12922
+ "row.deviceModeRealBlockedTitle": "请先切回「虚拟值」",
12923
+ "row.deviceModeRealBlocked": "「真实值」档下所有账号共用这台机器的真实设备,没有\"这个账号\"的参数可改。把设备头切回「虚拟值」后再点齿轮。",
12924
+ "row.deviceDialogTitle": "设备参数 · {accountName}",
12925
+ "row.deviceDialogIntro": "这两个值就是该账号发给上游的 X-Machine-ID / X-Session-ID。留空表示继续按本机盐自动派生,字段下方会显示真正会发出去的那个值。",
12926
+ "row.deviceMachineLabel": "机器 ID(X-Machine-ID)",
12927
+ "row.deviceSessionLabel": "会话 ID(X-Session-ID)",
12928
+ "row.deviceFieldPlaceholder": "留空 = 自动派生",
12929
+ "row.deviceDerivedNow": "当前派生值:",
12930
+ "row.deviceDerivedUnavailable": "没有可显示的派生值——本机还没有设备盐,因此不会发送 X-Machine-ID / X-Session-ID。",
12931
+ "row.deviceDerivedNoUid": "这个账号没有 uid,算不出派生值,因此不会发送 X-Machine-ID / X-Session-ID。",
12932
+ "row.deviceRandom": "一键随机",
12933
+ "row.deviceRandomHint": "一次给两项各填一个 36 位随机 id",
12934
+ "row.deviceDialogP3": "真实设备 Token",
12935
+ "row.deviceDialogP3Hint": "由本机安装的桌面端 Turing Shield SDK 签发。「真实值」档下所有账号用它;它不在这里编辑——见「SDK」分区。",
12936
+ "row.deviceDialogCancel": "取消",
12937
+ "row.deviceDialogSave": "保存",
12938
+ "row.deviceDialogSaving": "保存中…",
12939
+ "row.deviceInvalid": "需要 36 个十六进制字符(0-9a-f)",
12940
+ "row.panelSdk": "SDK",
12941
+ "sdk.hint": "这台机器通过本机安装的桌面端 SDK 签发的真实设备 token。「真实值」档下所有账号都发这一个值;「虚拟值」档不发送它(仍会后台预热,所以这一页随时能看到当前值)。",
12942
+ "sdk.loading": "正在询问 SDK…",
12943
+ "sdk.unavailable": "这个 Host 版本没有 SDK 路由——这里拿不到真实设备参数。「虚拟值」档不受影响。",
12944
+ "sdk.state": "连接状态",
12945
+ "sdk.statusReady": "正常",
12946
+ "sdk.statusStale": "能连上,但最近一次取数失败——仍在使用上一枚 token",
12947
+ "sdk.statusNoToken": "SDK 已加载,还没取到 token——点「重新获取」",
12948
+ "sdk.statusMissing": "未在本机找到已安装的 WorkBuddy 桌面端 SDK",
12949
+ "sdk.statusUnsupported": "SDK 拒绝了这个平台",
12950
+ "sdk.statusError": "SDK 加载失败",
12951
+ "sdk.bundle": "SDK",
12952
+ "sdk.runtime": "运行时",
12953
+ "sdk.fetched": "最近取到",
12954
+ "sdk.tier": "当前档位",
12955
+ "sdk.tierReal": "真实值——账号发的就是它",
12956
+ "sdk.tierVirtual": "虚拟值——这枚 token 不发出去",
12957
+ "sdk.valueLabel": "X-Device-Token",
12958
+ "sdk.noValue": "还没有可用的 token",
12959
+ "sdk.length": "{count} 字符",
12960
+ "sdk.reveal": "显示",
12961
+ "sdk.hide": "隐藏",
12962
+ "sdk.copy": "复制",
12963
+ "sdk.copied": "已复制",
12964
+ "sdk.refresh": "重新获取",
12965
+ "sdk.refreshing": "获取中…",
12966
+ "sdk.never": "从未",
12967
+ "sdk.unknown": "未知",
12968
+ "sdk.ageJustNow": "刚刚",
12969
+ "sdk.ageMinutes": "{count} 分钟前",
12970
+ "sdk.ageHours": "{count} 小时 {rest} 分前",
12971
+ "sdk.dirLabel": "SDK 目录",
12972
+ "sdk.dirPlaceholder": "留空 = 自动查找本机安装的桌面端",
12973
+ "sdk.dirSave": "保存",
12974
+ "sdk.dirSaving": "保存中…",
12975
+ "sdk.dirSaved": "已保存。",
12976
+ "sdk.dirClear": "清除",
12977
+ "sdk.dirHint": "填的是桌面端里 native/turing-sdk 那一层目录,不是 WorkBuddy.exe 所在目录。保存后会立刻重新检测;填错时上面的状态会变成「未找到」并带上这个路径,不会静默回退到自动查找。环境变量 WORKBUDDY_TURING_SDK_DIR 优先级更高。",
12978
+ "sdk.fallbackLabel": "取不到真实设备时退回虚拟值",
12979
+ "sdk.fallbackHint": "开启时:SDK 不可用(没装桌面端、目录填错、token 取不到)就改发按本机盐派生的虚拟设备对,档位显示也会跟着变成「虚拟值」——不静默冒充。关闭时:一个设备头都不发,那是「真实值」档原本的行为。",
11765
12980
  "row.upstreamHint": "这一组改的是网关看到什么,不是由哪个 provider 提供服务。四项都在插件挂载时采样,改完需重载插件或重启 DSH。",
11766
12981
  "row.usageIdentityLabel": "让用量页把调用记成官方客户端的样子",
11767
12982
  "row.usageIdentityHint": "补上 X-IDE-* 头(「使用端」那一列就不会空白),并把会话 id 改成 32 位十六进制 UUIDv7。只影响显示:User-Agent 与请求正文永不变。默认关闭——证据来自报告者,本插件未在真机复现。",