keel-agent 0.124.0 → 0.125.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/packages/keel/src/adapters/sdk/prompt-render.js +5 -2
  3. package/dist/packages/keel/src/app/core-engine.js +16 -0
  4. package/dist/packages/keel/src/app/engine-dismiss.js +44 -0
  5. package/dist/packages/keel/src/app/session-registry.js +7 -1
  6. package/dist/packages/keel/src/app/subagent-runtime.js +8 -1
  7. package/dist/packages/keel/src/tool-catalog.js +5 -5
  8. package/dist/server/core-settings-adapter.js +48 -13
  9. package/dist/server/device-center/bot-chat.js +25 -0
  10. package/dist/server/device-center/bot-home.js +6 -0
  11. package/dist/server/device-center/bot-prompt.js +110 -0
  12. package/dist/server/device-center/bots.js +12 -0
  13. package/dist/server/device-center/execution-system-prompt.js +28 -13
  14. package/dist/server/device-center/local.js +126 -2
  15. package/dist/server/index.js +1 -0
  16. package/dist/server/universal/universal-session.js +8 -1
  17. package/package.json +1 -1
  18. package/web/dist/.build-assets.json +1 -1
  19. package/web/dist/assets/{BgTasksModal-D9NVLipp.js → BgTasksModal-B58Pn34o.js} +1 -1
  20. package/web/dist/assets/{BgTasksModal-CeowQkSk.js → BgTasksModal-DlRMULTX.js} +1 -1
  21. package/web/dist/assets/{BottomDock-DnXJHyg7.js → BottomDock-ix2rdS6N.js} +1 -1
  22. package/web/dist/assets/{CanvasStudio-D_RAeDdS.js → CanvasStudio-BRCkVMbW.js} +1 -1
  23. package/web/dist/assets/{CanvasStudio-BRWqZIVu.js → CanvasStudio-Cjxb3q3B.js} +1 -1
  24. package/web/dist/assets/{DeviceCenter-USAoAkin.js → DeviceCenter-BWMmB-CF.js} +1 -1
  25. package/web/dist/assets/{DeviceCenter-d49w4XXm.js → DeviceCenter-DfLlGGBZ.js} +1 -1
  26. package/web/dist/assets/{DeviceExecutionSettings-2hoZaBQ0.js → DeviceExecutionSettings-BjduyZOy.js} +1 -1
  27. package/web/dist/assets/DeviceGroupSection-B98LzFoj.js +7 -0
  28. package/web/dist/assets/DeviceGroupSection-BD3CKMFH.js +7 -0
  29. package/web/dist/assets/{DeviceGroups-BPE61M6w.js → DeviceGroups-C_lcfK5h.js} +1 -1
  30. package/web/dist/assets/DeviceGroups-ob27f-Ha.js +1 -0
  31. package/web/dist/assets/{Dropdown-DAiTWOzs.js → Dropdown-C8yx9mqF.js} +1 -1
  32. package/web/dist/assets/{FilePreview-CtSZWiJB.js → FilePreview-OxK_pI6p.js} +1 -1
  33. package/web/dist/assets/{FilePreview-xePo9QMY.js → FilePreview-inPVGc1j.js} +1 -1
  34. package/web/dist/assets/{GlobalSearchModal-CQhENYtf.js → GlobalSearchModal-3g1PplIg.js} +1 -1
  35. package/web/dist/assets/GlobalSearchModal-DG-HC0vV.js +1 -0
  36. package/web/dist/assets/{GroupConversation-DXDC1d3x.js → GroupConversation-BJnwTtT2.js} +2 -2
  37. package/web/dist/assets/{GroupConversation-CFv2RYwI.js → GroupConversation-Clt5o_lo.js} +1 -1
  38. package/web/dist/assets/{GroupWorkItems-BeZvaxV9.js → GroupWorkItems-7yTbAr_f.js} +1 -1
  39. package/web/dist/assets/{ModelConfigModal-drDDlawe.js → ModelConfigModal-CNnEGfep.js} +1 -1
  40. package/web/dist/assets/{ModelConfigModal-BI6ekcG4.js → ModelConfigModal-CYqDNXap.js} +1 -1
  41. package/web/dist/assets/{NativeCliPanel-B029dN9l.js → NativeCliPanel-B407C4qC.js} +1 -1
  42. package/web/dist/assets/{NativeCliPanel-BsehkHXc.js → NativeCliPanel-CVbFXUSf.js} +1 -1
  43. package/web/dist/assets/{PiSetupModal-D46ea4Wb.js → PiSetupModal-CrjDf0j6.js} +1 -1
  44. package/web/dist/assets/{ProviderOAuthControls-t8myaqZa.js → ProviderOAuthControls-Crhc6icP.js} +1 -1
  45. package/web/dist/assets/{SCMPanel-DUrKyvGV.js → SCMPanel-DuRJx0nl.js} +1 -1
  46. package/web/dist/assets/{SCMPanel-BKgGm9au.js → SCMPanel-rUAKnxBo.js} +1 -1
  47. package/web/dist/assets/SettingsModal-B3Q5EoVC.js +29 -0
  48. package/web/dist/assets/{SettingsModal-Bn0GTNgo.js → SettingsModal-CnJsUyvi.js} +1 -1
  49. package/web/dist/assets/{TermXterm-2oOzNy1G.js → TermXterm-BDLmWqim.js} +1 -1
  50. package/web/dist/assets/{TermXterm-D_VbvSyY.js → TermXterm-DhbhRp0B.js} +1 -1
  51. package/web/dist/assets/{TerminalPanel-CJ4ykxfy.js → TerminalPanel-D6oMxabb.js} +1 -1
  52. package/web/dist/assets/{TerminalPanel-mTL87sXL.js → TerminalPanel-Ds_hnvxz.js} +1 -1
  53. package/web/dist/assets/{ThemeMarketModal-B55xZq9j.js → ThemeMarketModal-5lH7k1in.js} +1 -1
  54. package/web/dist/assets/{ThemeMarketModal-EahvoJAf.js → ThemeMarketModal-WSOd5c6j.js} +1 -1
  55. package/web/dist/assets/{TuiOverlayModal-B2B5yRVf.js → TuiOverlayModal-Dh_HsAvo.js} +1 -1
  56. package/web/dist/assets/{TuiOverlayModal-C1uwsm1r.js → TuiOverlayModal-dKDCTdt8.js} +1 -1
  57. package/web/dist/assets/{api-client-CGqoOWHJ.js → api-client-BbDlV0jR.js} +1 -1
  58. package/web/dist/assets/{canvas-client-LIotRrYf.js → canvas-client-OwhfLxJx.js} +1 -1
  59. package/web/dist/assets/{desktop-BHN7gNP2.js → desktop-D1lGoY5p.js} +1 -1
  60. package/web/dist/assets/{fi-DjvtEEnZ.js → fi-CcqqfamG.js} +6 -6
  61. package/web/dist/assets/index-BQb8EOhk.js +410 -0
  62. package/web/dist/assets/index-Dbv9RJwm.js +410 -0
  63. package/web/dist/assets/index-xAdOV6os.css +1 -0
  64. package/web/dist/assets/{plugin-host-VdvQxFkv.js → plugin-host-DjGRLyyK.js} +1 -1
  65. package/web/dist/assets/{theme-DGfXszyo.js → theme-Dl8KLbt-.js} +1 -1
  66. package/web/dist/assets/use-copy-feedback-B3di-fnu.js +1 -0
  67. package/web/dist/index.html +11 -10
  68. package/web/dist/sw.js +1 -1
  69. package/web/dist/assets/DeviceGroupSection-CRdMGDwE.js +0 -7
  70. package/web/dist/assets/GlobalSearchModal-DpHvykpb.js +0 -1
  71. package/web/dist/assets/SettingsModal-ComFBXCj.js +0 -29
  72. package/web/dist/assets/index-4-PoF3xB.css +0 -1
  73. package/web/dist/assets/index-CXTnvcJF.js +0 -409
  74. package/web/dist/assets/index-Y0yKgBrc.js +0 -409
@@ -6,9 +6,15 @@ import { createMobileNotificationForwarder } from "./mobile-notification-forward
6
6
  import { getLocalBotOptions } from "./bot-catalog.js";
7
7
  import { applyLocalBotPreset } from "./bot-presets.js";
8
8
  import { listBotChatTranscripts } from "./bot-chat.js";
9
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
9
+ import { getAgentDir, loadSkills } from "@earendil-works/pi-coding-agent";
10
10
  import { resolveDraftReview } from "./bot-creation-tool.js";
11
- import { botMemoryRoot, createBotMemory } from "./bot-memory.js";
11
+ import { botMemoryRoot, buildBotMemoryInjection, createBotMemory } from "./bot-memory.js";
12
+ import { composeBotSystemPrompt, resolveBotPromptSections } from "./bot-prompt.js";
13
+ import { getBotExecutionInstructions } from "./execution-instructions.js";
14
+ import { BUILTIN_SOUL, resolveSectionTexts } from "../prompt-composer.js";
15
+ import { buildPlatformConstraints } from "../platform-constraints.js";
16
+ import { isRemoteWorkspaceUri } from "../../packages/keel/src/remote-workspace.js";
17
+ import { formatCwdForPrompt } from "../remote-ssh-service.js";
12
18
  import { appendIdentityChange } from "./bot-identity.js";
13
19
  import { exportBotHome, importBotHome, parseBotHomeBundle } from "./bot-home.js";
14
20
  import { ALL_AGENT_TOOL_ENTRIES } from "../tool-manager.js";
@@ -1113,6 +1119,8 @@ export async function installLocalDeviceCenter(options) {
1113
1119
  "skills",
1114
1120
  "mcpServers",
1115
1121
  "enabled",
1122
+ "useGlobalPrompt",
1123
+ "promptSections",
1116
1124
  // GET 会回传这两个字段(身份台账 / 存量元数据),编辑时必须允许原样带回:
1117
1125
  // 客户端把读到的 Bot 改一改再 POST 是正常用法。写入时身份由服务端重盖。
1118
1126
  "identity",
@@ -1204,6 +1212,120 @@ export async function installLocalDeviceCenter(options) {
1204
1212
  res.off("close", cancel);
1205
1213
  }
1206
1214
  });
1215
+ options.app.post("/api/device-center/local-bot-prompt-preview", async (req, res) => {
1216
+ if ((req.headers.origin || req.headers["sec-fetch-site"] === "cross-site") &&
1217
+ !allowsLocalWriteOrigin(req.headers.origin, req.headers.host, allowOrigins)) {
1218
+ res.status(403).json({ code: "LOCAL_ONLY", error: "Same-origin request required" });
1219
+ return;
1220
+ }
1221
+ res.setHeader("Cache-Control", "no-store");
1222
+ try {
1223
+ const body = (req.body && typeof req.body === "object" ? req.body : {});
1224
+ const agentDir = options.botCatalog?.agentDir ?? getAgentDir();
1225
+ const fallbackCwd = options.botCatalog?.defaultCwd ?? process.cwd();
1226
+ const requestedCwd = typeof body.cwd === "string" && body.cwd.trim() ? body.cwd.trim() : fallbackCwd;
1227
+ let cwd = requestedCwd;
1228
+ try {
1229
+ cwd = await validateDeviceProject(requestedCwd, options.dataDir);
1230
+ }
1231
+ catch {
1232
+ cwd = requestedCwd;
1233
+ }
1234
+ const isRemote = isRemoteWorkspaceUri(cwd);
1235
+ const readOpt = async (p) => {
1236
+ try {
1237
+ return await readFile(p, "utf8");
1238
+ }
1239
+ catch {
1240
+ return "";
1241
+ }
1242
+ };
1243
+ const selectedTools = Array.isArray(body.tools)
1244
+ ? body.tools.filter((v) => typeof v === "string")
1245
+ : [];
1246
+ const selectedSkillNames = Array.isArray(body.skills)
1247
+ ? body.skills.filter((v) => typeof v === "string")
1248
+ : [];
1249
+ const toolSnippets = {};
1250
+ for (const entry of ALL_AGENT_TOOL_ENTRIES) {
1251
+ if (selectedTools.includes(entry.name)) {
1252
+ toolSnippets[entry.name] = entry.name;
1253
+ }
1254
+ }
1255
+ let skills = [];
1256
+ if (!isRemote && selectedSkillNames.length > 0) {
1257
+ try {
1258
+ const loaded = loadSkills({ cwd, agentDir, skillPaths: [], includeDefaults: true });
1259
+ const allowSet = new Set(selectedSkillNames);
1260
+ skills = loaded.skills
1261
+ .filter((s) => allowSet.has(s.name))
1262
+ .map((s) => ({ name: s.name, description: s.description ?? "", filePath: s.filePath ?? "" }));
1263
+ }
1264
+ catch { }
1265
+ }
1266
+ const systemFile = isRemote
1267
+ ? await readOpt(join(agentDir, "SYSTEM.md"))
1268
+ : (await readOpt(join(cwd, ".pi", "SYSTEM.md"))) || (await readOpt(join(agentDir, "SYSTEM.md")));
1269
+ const appendFile = isRemote
1270
+ ? await readOpt(join(agentDir, "APPEND_SYSTEM.md"))
1271
+ : (await readOpt(join(cwd, ".pi", "APPEND_SYSTEM.md"))) || (await readOpt(join(agentDir, "APPEND_SYSTEM.md")));
1272
+ const contextFiles = [];
1273
+ for (const candidate of isRemote
1274
+ ? [join(agentDir, "AGENTS.md")]
1275
+ : [join(agentDir, "AGENTS.md"), join(cwd, "AGENTS.md"), join(cwd, "CLAUDE.md")]) {
1276
+ const content = await readOpt(candidate);
1277
+ if (content.trim())
1278
+ contextFiles.push({ path: candidate, content });
1279
+ }
1280
+ const sectionTexts = resolveSectionTexts({
1281
+ cwd: formatCwdForPrompt(cwd),
1282
+ systemPromptFile: systemFile || undefined,
1283
+ builtinSoul: BUILTIN_SOUL,
1284
+ selectedTools,
1285
+ toolSnippets,
1286
+ appendFiles: appendFile.trim() ? [appendFile] : [],
1287
+ markersGuidance: "",
1288
+ contextFiles,
1289
+ skills,
1290
+ lang: "zh",
1291
+ });
1292
+ let memoryBlock;
1293
+ if (typeof body.id === "string" && body.id.trim()) {
1294
+ try {
1295
+ const root = botMemoryRoot(options.dataDir, body.id.trim());
1296
+ memoryBlock = (await buildBotMemoryInjection(createBotMemory({ root }), {
1297
+ cwd,
1298
+ searchable: selectedTools.includes("memory"),
1299
+ }))?.text;
1300
+ }
1301
+ catch { }
1302
+ }
1303
+ const selectedSections = resolveBotPromptSections({
1304
+ promptSections: Array.isArray(body.promptSections)
1305
+ ? body.promptSections.filter((v) => typeof v === "string")
1306
+ : undefined,
1307
+ useGlobalPrompt: typeof body.useGlobalPrompt === "boolean" ? body.useGlobalPrompt : undefined,
1308
+ });
1309
+ const preview = composeBotSystemPrompt({
1310
+ sectionTexts,
1311
+ promptOverrides: options.getGlobalPromptOverrides?.(),
1312
+ botSystemPrompt: typeof body.systemPrompt === "string" ? body.systemPrompt : "",
1313
+ executionInstructions: getBotExecutionInstructions(false, true),
1314
+ memoryBlock,
1315
+ constraints: isRemote
1316
+ ? buildPlatformConstraints({ remoteCwd: cwd, planMode: false, delegateMode: false })
1317
+ : undefined,
1318
+ selectedSections,
1319
+ });
1320
+ res.json(preview);
1321
+ }
1322
+ catch (error) {
1323
+ res.status(500).json({
1324
+ code: "BOT_PROMPT_PREVIEW_FAILED",
1325
+ error: error instanceof Error ? error.message : "Failed to preview Bot prompt",
1326
+ });
1327
+ }
1328
+ });
1207
1329
  async function scaffoldBotHome(bot, draft) {
1208
1330
  const memoryRoot = botMemoryRoot(options.dataDir, bot.id);
1209
1331
  await mkdir(join(options.dataDir, "bot-agents", bot.id, "identity"), { recursive: true });
@@ -1501,6 +1623,8 @@ export async function installLocalDeviceCenter(options) {
1501
1623
  name: bundle.bot.name,
1502
1624
  description: bundle.bot.description,
1503
1625
  systemPrompt: bundle.bot.systemPrompt,
1626
+ ...(bundle.bot.useGlobalPrompt !== undefined ? { useGlobalPrompt: bundle.bot.useGlobalPrompt } : {}),
1627
+ ...(bundle.bot.promptSections !== undefined ? { promptSections: bundle.bot.promptSections } : {}),
1504
1628
  cwd,
1505
1629
  ...(bundle.bot.model ? { model: bundle.bot.model } : {}),
1506
1630
  tools,
@@ -1205,6 +1205,7 @@ const deviceCenter = await installLocalDeviceCenter({
1205
1205
  // dev 的 Vite 代理(页面 origin ≠ 后端 Host)由这里显式放行;生产反向代理通常同源。
1206
1206
  allowOrigins: ALLOW_ORIGINS,
1207
1207
  lanAccess: deviceLanAccess,
1208
+ getGlobalPromptOverrides: () => sharedStateStore.getSettings("").promptOverrides,
1208
1209
  botCatalog: {
1209
1210
  defaultCwd: CWD,
1210
1211
  dataDir: DATA_DIR,
@@ -288,8 +288,15 @@ export class UniversalSession {
288
288
  origin.conv.updatedAt = Date.now();
289
289
  if (!origin.conv.isEphemeral)
290
290
  this.store.queueWrite(origin.cwd, origin.conv);
291
- if (this.cwd === origin.cwd)
291
+ this.stateStore?.saveSessionTitle(origin.cwd, convId, title);
292
+ if (normalizePathKey(this.cwd) === normalizePathKey(origin.cwd)) {
293
+ this.emitConversations();
292
294
  this.flushSnapshot();
295
+ void this.refreshSessions();
296
+ }
297
+ else {
298
+ void this.pushSessionsForCwd(origin.cwd);
299
+ }
293
300
  },
294
301
  refreshMarkers: () => this.flushSnapshot(),
295
302
  onActionsChange: (convId) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel-agent",
3
- "version": "0.124.0",
3
+ "version": "0.125.0",
4
4
  "description": "Just open your browser to get all your work done — browser cockpit for AI coding agents (chat, code, files, terminal, Git in one tab)",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -1 +1 @@
1
- ["index-Y0yKgBrc.js","BgTasksModal-CeowQkSk.js","BottomDock-DnXJHyg7.js","CanvasStudio-BRWqZIVu.js","DeviceCenter-USAoAkin.js","DeviceExecutionSettings-2hoZaBQ0.js","DeviceGroupSection-CRdMGDwE.js","DeviceGroups-BPE61M6w.js","Dropdown-DAiTWOzs.js","FilePreview-CtSZWiJB.js","GlobalSearchModal-DpHvykpb.js","GroupConversation-DXDC1d3x.js","GroupWorkItems-BeZvaxV9.js","ModelConfigModal-BI6ekcG4.js","NativeCliPanel-BsehkHXc.js","PiSetupModal-D46ea4Wb.js","ProviderOAuthControls-t8myaqZa.js","SCMPanel-BKgGm9au.js","SettingsModal-Bn0GTNgo.js","TermXterm-D_VbvSyY.js","TerminalPanel-mTL87sXL.js","ThemeMarketModal-B55xZq9j.js","TuiOverlayModal-C1uwsm1r.js","api-client-CGqoOWHJ.js","app-globals-wu8LLlnA.js","canvas-client-LIotRrYf.js","composer-bridge-CImnjDHq.js","context-menu-state-CEfR7_Lz.js","desktop-BHN7gNP2.js","es-DWMIuDU2.js","fi-DjvtEEnZ.js","group-view-state-CGCzYF8k.js","markdown-BggnuQ4H.js","math-1uRJCsA9.js","overlay-stack-BHdOmj3G.js","plugin-host-VdvQxFkv.js","react-CR5VJ85Q.js","rolldown-runtime-hePW80VL.js","shortcut-stack-hhrDyRBn.js","theme-DGfXszyo.js","use-click-outside-CHRhq6cL.js","use-floating-panel-tvvfNgvg.js","uuid-BzDIGCwP.js","xterm-Cf5xxe4g.js","DeviceGroupSection-B9yl5D4j.css","GroupConversation-wV-lmZkz.css","KaTeX_AMS-Regular-BQhdFMY1.woff2","KaTeX_AMS-Regular-DMm9YOAa.woff","KaTeX_AMS-Regular-DRggAlZN.ttf","KaTeX_Caligraphic-Bold-ATXxdsX0.ttf","KaTeX_Caligraphic-Bold-BEiXGLvX.woff","KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2","KaTeX_Caligraphic-Regular-CTRA-rTL.woff","KaTeX_Caligraphic-Regular-Di6jR-x-.woff2","KaTeX_Caligraphic-Regular-wX97UBjC.ttf","KaTeX_Fraktur-Bold-BdnERNNW.ttf","KaTeX_Fraktur-Bold-BsDP51OF.woff","KaTeX_Fraktur-Bold-CL6g_b3V.woff2","KaTeX_Fraktur-Regular-CB_wures.ttf","KaTeX_Fraktur-Regular-CTYiF6lA.woff2","KaTeX_Fraktur-Regular-Dxdc4cR9.woff","KaTeX_Main-Bold-Cx986IdX.woff2","KaTeX_Main-Bold-Jm3AIy58.woff","KaTeX_Main-Bold-waoOVXN0.ttf","KaTeX_Main-BoldItalic-DxDJ3AOS.woff2","KaTeX_Main-BoldItalic-DzxPMmG6.ttf","KaTeX_Main-BoldItalic-SpSLRI95.woff","KaTeX_Main-Italic-3WenGoN9.ttf","KaTeX_Main-Italic-BMLOBm91.woff","KaTeX_Main-Italic-NWA7e6Wa.woff2","KaTeX_Main-Regular-B22Nviop.woff2","KaTeX_Main-Regular-Dr94JaBh.woff","KaTeX_Main-Regular-ypZvNtVU.ttf","KaTeX_Math-BoldItalic-B3XSjfu4.ttf","KaTeX_Math-BoldItalic-CZnvNsCZ.woff2","KaTeX_Math-BoldItalic-iY-2wyZ7.woff","KaTeX_Math-Italic-DA0__PXp.woff","KaTeX_Math-Italic-flOr_0UB.ttf","KaTeX_Math-Italic-t53AETM-.woff2","KaTeX_SansSerif-Bold-CFMepnvq.ttf","KaTeX_SansSerif-Bold-D1sUS0GD.woff2","KaTeX_SansSerif-Bold-DbIhKOiC.woff","KaTeX_SansSerif-Italic-C3H0VqGB.woff2","KaTeX_SansSerif-Italic-DN2j7dab.woff","KaTeX_SansSerif-Italic-YYjJ1zSn.ttf","KaTeX_SansSerif-Regular-BNo7hRIc.ttf","KaTeX_SansSerif-Regular-CS6fqUqJ.woff","KaTeX_SansSerif-Regular-DDBCnlJ7.woff2","KaTeX_Script-Regular-C5JkGWo-.ttf","KaTeX_Script-Regular-D3wIWfF6.woff2","KaTeX_Script-Regular-D5yQViql.woff","KaTeX_Size1-Regular-C195tn64.woff","KaTeX_Size1-Regular-Dbsnue_I.ttf","KaTeX_Size1-Regular-mCD8mA8B.woff2","KaTeX_Size2-Regular-B7gKUWhC.ttf","KaTeX_Size2-Regular-Dy4dx90m.woff2","KaTeX_Size2-Regular-oD1tc_U0.woff","KaTeX_Size3-Regular-CTq5MqoE.woff","KaTeX_Size3-Regular-DgpXs0kz.ttf","KaTeX_Size4-Regular-BF-4gkZK.woff","KaTeX_Size4-Regular-DWFBv043.ttf","KaTeX_Size4-Regular-Dl5lxZxV.woff2","KaTeX_Typewriter-Regular-C0xS9mPB.woff","KaTeX_Typewriter-Regular-CO6r4hn1.woff2","KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf","SCMPanel-BVYmayDJ.css","SettingsModal-Cy5lRC97.css","index-4-PoF3xB.css","markdown-C8LL_u4z.css","math-BorAY7qD.css","xterm-B1njb2Cr.css"]
1
+ ["index-BQb8EOhk.js","BgTasksModal-B58Pn34o.js","BottomDock-ix2rdS6N.js","CanvasStudio-Cjxb3q3B.js","DeviceCenter-BWMmB-CF.js","DeviceExecutionSettings-BjduyZOy.js","DeviceGroupSection-BD3CKMFH.js","DeviceGroups-C_lcfK5h.js","Dropdown-C8yx9mqF.js","FilePreview-inPVGc1j.js","GlobalSearchModal-DG-HC0vV.js","GroupConversation-BJnwTtT2.js","GroupWorkItems-7yTbAr_f.js","ModelConfigModal-CYqDNXap.js","NativeCliPanel-B407C4qC.js","PiSetupModal-CrjDf0j6.js","ProviderOAuthControls-Crhc6icP.js","SCMPanel-DuRJx0nl.js","SettingsModal-B3Q5EoVC.js","TermXterm-DhbhRp0B.js","TerminalPanel-Ds_hnvxz.js","ThemeMarketModal-WSOd5c6j.js","TuiOverlayModal-Dh_HsAvo.js","api-client-BbDlV0jR.js","app-globals-wu8LLlnA.js","canvas-client-OwhfLxJx.js","composer-bridge-CImnjDHq.js","context-menu-state-CEfR7_Lz.js","desktop-D1lGoY5p.js","es-DWMIuDU2.js","fi-CcqqfamG.js","group-view-state-CGCzYF8k.js","markdown-BggnuQ4H.js","math-1uRJCsA9.js","overlay-stack-BHdOmj3G.js","plugin-host-DjGRLyyK.js","react-CR5VJ85Q.js","rolldown-runtime-hePW80VL.js","shortcut-stack-hhrDyRBn.js","theme-Dl8KLbt-.js","use-click-outside-CHRhq6cL.js","use-copy-feedback-B3di-fnu.js","use-floating-panel-tvvfNgvg.js","uuid-BzDIGCwP.js","xterm-Cf5xxe4g.js","DeviceGroupSection-B9yl5D4j.css","GroupConversation-wV-lmZkz.css","KaTeX_AMS-Regular-BQhdFMY1.woff2","KaTeX_AMS-Regular-DMm9YOAa.woff","KaTeX_AMS-Regular-DRggAlZN.ttf","KaTeX_Caligraphic-Bold-ATXxdsX0.ttf","KaTeX_Caligraphic-Bold-BEiXGLvX.woff","KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2","KaTeX_Caligraphic-Regular-CTRA-rTL.woff","KaTeX_Caligraphic-Regular-Di6jR-x-.woff2","KaTeX_Caligraphic-Regular-wX97UBjC.ttf","KaTeX_Fraktur-Bold-BdnERNNW.ttf","KaTeX_Fraktur-Bold-BsDP51OF.woff","KaTeX_Fraktur-Bold-CL6g_b3V.woff2","KaTeX_Fraktur-Regular-CB_wures.ttf","KaTeX_Fraktur-Regular-CTYiF6lA.woff2","KaTeX_Fraktur-Regular-Dxdc4cR9.woff","KaTeX_Main-Bold-Cx986IdX.woff2","KaTeX_Main-Bold-Jm3AIy58.woff","KaTeX_Main-Bold-waoOVXN0.ttf","KaTeX_Main-BoldItalic-DxDJ3AOS.woff2","KaTeX_Main-BoldItalic-DzxPMmG6.ttf","KaTeX_Main-BoldItalic-SpSLRI95.woff","KaTeX_Main-Italic-3WenGoN9.ttf","KaTeX_Main-Italic-BMLOBm91.woff","KaTeX_Main-Italic-NWA7e6Wa.woff2","KaTeX_Main-Regular-B22Nviop.woff2","KaTeX_Main-Regular-Dr94JaBh.woff","KaTeX_Main-Regular-ypZvNtVU.ttf","KaTeX_Math-BoldItalic-B3XSjfu4.ttf","KaTeX_Math-BoldItalic-CZnvNsCZ.woff2","KaTeX_Math-BoldItalic-iY-2wyZ7.woff","KaTeX_Math-Italic-DA0__PXp.woff","KaTeX_Math-Italic-flOr_0UB.ttf","KaTeX_Math-Italic-t53AETM-.woff2","KaTeX_SansSerif-Bold-CFMepnvq.ttf","KaTeX_SansSerif-Bold-D1sUS0GD.woff2","KaTeX_SansSerif-Bold-DbIhKOiC.woff","KaTeX_SansSerif-Italic-C3H0VqGB.woff2","KaTeX_SansSerif-Italic-DN2j7dab.woff","KaTeX_SansSerif-Italic-YYjJ1zSn.ttf","KaTeX_SansSerif-Regular-BNo7hRIc.ttf","KaTeX_SansSerif-Regular-CS6fqUqJ.woff","KaTeX_SansSerif-Regular-DDBCnlJ7.woff2","KaTeX_Script-Regular-C5JkGWo-.ttf","KaTeX_Script-Regular-D3wIWfF6.woff2","KaTeX_Script-Regular-D5yQViql.woff","KaTeX_Size1-Regular-C195tn64.woff","KaTeX_Size1-Regular-Dbsnue_I.ttf","KaTeX_Size1-Regular-mCD8mA8B.woff2","KaTeX_Size2-Regular-B7gKUWhC.ttf","KaTeX_Size2-Regular-Dy4dx90m.woff2","KaTeX_Size2-Regular-oD1tc_U0.woff","KaTeX_Size3-Regular-CTq5MqoE.woff","KaTeX_Size3-Regular-DgpXs0kz.ttf","KaTeX_Size4-Regular-BF-4gkZK.woff","KaTeX_Size4-Regular-DWFBv043.ttf","KaTeX_Size4-Regular-Dl5lxZxV.woff2","KaTeX_Typewriter-Regular-C0xS9mPB.woff","KaTeX_Typewriter-Regular-CO6r4hn1.woff2","KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf","SCMPanel-BVYmayDJ.css","SettingsModal-Cy5lRC97.css","index-xAdOV6os.css","markdown-C8LL_u4z.css","math-BorAY7qD.css","xterm-B1njb2Cr.css"]
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ft as t,Jt as n,Mt as r,gn as i,sn as a,ut as o,vn as s}from"./fi-DjvtEEnZ.js";import{i as c,t as l}from"./react-CR5VJ85Q.js";import{t as u}from"./app-globals-wu8LLlnA.js";import{Vt as d,W as f,Wt as p,X as m}from"./index-CXTnvcJF.js";var h=e(c(),1),g=l();function _(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function v({servers:e,projectScripts:c,onClose:l,plugins:v=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=s(),{locale:w}=i();(0,h.useEffect)(()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},[]);let T=(0,h.useMemo)(()=>e.filter(e=>(e.kind??(e.taskId?`plugin`:`port`))===`job`),[e]),E=(0,h.useMemo)(()=>{let e=new Set;for(let t of T){let n=/npm run ([A-Za-z0-9 _.:-]+)/.exec(t.command??``);n&&e.add(n[1])}return e},[T]),D=(0,h.useMemo)(()=>Object.entries(c?.scripts??{}),[c]),O=(0,h.useMemo)(()=>(d(p(v),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[v,w,C]),[k,A]=(0,h.useState)(new Set),j=e=>{let t=e.taskId??String(e.port);A(e=>new Set(e).add(t));let n=e.kind??(e.taskId?`plugin`:`port`);u(n===`plugin`||n===`job`?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),u({type:`list_bg_servers`}),setTimeout(()=>u({type:`list_bg_servers`}),1500),setTimeout(()=>u({type:`list_bg_servers`}),4e3),setTimeout(()=>{A(e=>{let n=new Set(e);return n.delete(t),n})},8e3)};return(0,g.jsxs)(m,{className:`bg-task-modal bg-task-modal-a`,onClose:l,showCloseButton:!1,children:[(0,g.jsxs)(`div`,{className:`bg-task-head`,children:[(0,g.jsxs)(`div`,{className:`bg-task-title`,children:[(0,g.jsx)(o,{"aria-hidden":!0}),(0,g.jsx)(`span`,{children:C(`bgTasks`)}),e.length>0&&(0,g.jsxs)(`em`,{className:`bg-task-count`,children:[e.length,` 运行`]})]}),(0,g.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRefresh`),onClick:()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`close`),onClick:l,children:(0,g.jsx)(a,{})})]})]}),(0,g.jsxs)(`div`,{className:`bg-task-body`,children:[e.length===0&&D.length===0?(0,g.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,g.jsx)(o,{}),(0,g.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,g.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):null,e.length>0&&(0,g.jsx)(`div`,{className:`bg-task-running`,children:e.map(e=>{let n=e.kind??(e.taskId?`plugin`:`port`),r=n===`plugin`,i=n===`job`,a=e.taskId??String(e.port),o=r?e.plugin:i?e.name||C(`bgTaskJobKind`):`:${e.port}`,s=[e.name&&!i?e.name:null,r&&e.status?e.status:null,C(`bgTaskSince`)+` `+_(e.since,C),!r&&e.pid?`${C(`bgTaskPid`)} ${e.pid}`:null].filter(Boolean).join(` · `);return(0,g.jsxs)(`div`,{className:`bg-task-run-card`,title:e.command||void 0,children:[(0,g.jsx)(`span`,{className:`bg-task-dot`,"aria-hidden":!0}),(0,g.jsxs)(`div`,{className:`bg-task-run-main`,children:[(0,g.jsx)(`div`,{className:`bg-task-run-name`,children:o}),(0,g.jsx)(`div`,{className:`bg-task-run-sub`,children:s})]}),(0,g.jsxs)(`div`,{className:`bg-task-run-actions`,children:[n===`port`&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn ${e.keep?`active`:``}`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>u({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:`📌`}),i&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRestart`),onClick:()=>u({type:`restart_bg_job`,taskId:e.taskId??``}),children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn danger sm`,disabled:k.has(e.taskId??String(e.port)),onClick:()=>j(e),children:k.has(e.taskId??String(e.port))?C(`bgTaskStopping`):C(`bgTaskStop`)})]})]},a)})}),D.length>0&&(0,g.jsxs)(`div`,{className:`bg-task-scripts`,children:[(0,g.jsxs)(`div`,{className:`bg-task-kicker`,children:[(0,g.jsx)(`span`,{children:C(`bgTaskQuickStart`)}),c?.cwd?(0,g.jsx)(`span`,{className:`bg-task-cwd mono`,title:c.cwd,children:c.cwd}):null]}),(0,g.jsx)(`div`,{className:`bg-task-script-list`,children:D.map(([e,t])=>{let n=E.has(e);return(0,g.jsxs)(`div`,{className:`bg-task-script-row`,title:t,children:[(0,g.jsxs)(`div`,{className:`bg-task-script-cmd mono`,children:[(0,g.jsx)(`span`,{className:`bg-task-npm`,children:`npm run `}),(0,g.jsx)(`span`,{className:`bg-task-script-name`,children:e})]}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn sm ${n?``:`primary`}`,disabled:n,onClick:()=>u({type:`start_bg_script`,script:e}),children:n?C(`bgTaskRunning`):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(r,{"aria-hidden":!0}),` `,C(`bgTaskStart`)]})})]},e)})})]}),O.map(e=>{let t=v.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,g.jsx)(`div`,{className:`bg-task-plugin-panel`,children:(0,g.jsx)(f,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,g.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)})]}),(0,g.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,g.jsxs)(`label`,{className:`bg-task-cleanup`,title:C(`bgTaskCleanupHint`),children:[(0,g.jsx)(`span`,{children:C(`bgTaskCleanup`)}),(0,g.jsxs)(`select`,{className:`bg-task-select`,value:String(S),onChange:e=>u({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,g.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,g.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,g.jsx)(`span`,{className:`sp`}),(0,g.jsxs)(`button`,{type:`button`,className:`btn bg-task-btn ghost danger sm`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>u({type:`kill_background_servers`}),children:[(0,g.jsx)(n,{"aria-hidden":!0}),` `,C(`bgTaskStopAll`)]})]})]})}export{v as BgTasksModal};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ft as t,Jt as n,Mt as r,gn as i,sn as a,ut as o,vn as s}from"./fi-CcqqfamG.js";import{i as c,t as l}from"./react-CR5VJ85Q.js";import{t as u}from"./app-globals-wu8LLlnA.js";import{Ht as d,W as f,X as p,zt as m}from"./index-BQb8EOhk.js";var h=e(c(),1),g=l();function _(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function v({servers:e,projectScripts:c,onClose:l,plugins:v=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=s(),{locale:w}=i();(0,h.useEffect)(()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},[]);let T=(0,h.useMemo)(()=>e.filter(e=>(e.kind??(e.taskId?`plugin`:`port`))===`job`),[e]),E=(0,h.useMemo)(()=>{let e=new Set;for(let t of T){let n=/npm run ([A-Za-z0-9 _.:-]+)/.exec(t.command??``);n&&e.add(n[1])}return e},[T]),D=(0,h.useMemo)(()=>Object.entries(c?.scripts??{}),[c]),O=(0,h.useMemo)(()=>(m(d(v),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[v,w,C]),[k,A]=(0,h.useState)(new Set),j=e=>{let t=e.taskId??String(e.port);A(e=>new Set(e).add(t));let n=e.kind??(e.taskId?`plugin`:`port`);u(n===`plugin`||n===`job`?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),u({type:`list_bg_servers`}),setTimeout(()=>u({type:`list_bg_servers`}),1500),setTimeout(()=>u({type:`list_bg_servers`}),4e3),setTimeout(()=>{A(e=>{let n=new Set(e);return n.delete(t),n})},8e3)};return(0,g.jsxs)(p,{className:`bg-task-modal bg-task-modal-a`,onClose:l,showCloseButton:!1,children:[(0,g.jsxs)(`div`,{className:`bg-task-head`,children:[(0,g.jsxs)(`div`,{className:`bg-task-title`,children:[(0,g.jsx)(o,{"aria-hidden":!0}),(0,g.jsx)(`span`,{children:C(`bgTasks`)}),e.length>0&&(0,g.jsxs)(`em`,{className:`bg-task-count`,children:[e.length,` 运行`]})]}),(0,g.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRefresh`),onClick:()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`close`),onClick:l,children:(0,g.jsx)(a,{})})]})]}),(0,g.jsxs)(`div`,{className:`bg-task-body`,children:[e.length===0&&D.length===0?(0,g.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,g.jsx)(o,{}),(0,g.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,g.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):null,e.length>0&&(0,g.jsx)(`div`,{className:`bg-task-running`,children:e.map(e=>{let n=e.kind??(e.taskId?`plugin`:`port`),r=n===`plugin`,i=n===`job`,a=e.taskId??String(e.port),o=r?e.plugin:i?e.name||C(`bgTaskJobKind`):`:${e.port}`,s=[e.name&&!i?e.name:null,r&&e.status?e.status:null,C(`bgTaskSince`)+` `+_(e.since,C),!r&&e.pid?`${C(`bgTaskPid`)} ${e.pid}`:null].filter(Boolean).join(` · `);return(0,g.jsxs)(`div`,{className:`bg-task-run-card`,title:e.command||void 0,children:[(0,g.jsx)(`span`,{className:`bg-task-dot`,"aria-hidden":!0}),(0,g.jsxs)(`div`,{className:`bg-task-run-main`,children:[(0,g.jsx)(`div`,{className:`bg-task-run-name`,children:o}),(0,g.jsx)(`div`,{className:`bg-task-run-sub`,children:s})]}),(0,g.jsxs)(`div`,{className:`bg-task-run-actions`,children:[n===`port`&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn ${e.keep?`active`:``}`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>u({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:`📌`}),i&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRestart`),onClick:()=>u({type:`restart_bg_job`,taskId:e.taskId??``}),children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn danger sm`,disabled:k.has(e.taskId??String(e.port)),onClick:()=>j(e),children:k.has(e.taskId??String(e.port))?C(`bgTaskStopping`):C(`bgTaskStop`)})]})]},a)})}),D.length>0&&(0,g.jsxs)(`div`,{className:`bg-task-scripts`,children:[(0,g.jsxs)(`div`,{className:`bg-task-kicker`,children:[(0,g.jsx)(`span`,{children:C(`bgTaskQuickStart`)}),c?.cwd?(0,g.jsx)(`span`,{className:`bg-task-cwd mono`,title:c.cwd,children:c.cwd}):null]}),(0,g.jsx)(`div`,{className:`bg-task-script-list`,children:D.map(([e,t])=>{let n=E.has(e);return(0,g.jsxs)(`div`,{className:`bg-task-script-row`,title:t,children:[(0,g.jsxs)(`div`,{className:`bg-task-script-cmd mono`,children:[(0,g.jsx)(`span`,{className:`bg-task-npm`,children:`npm run `}),(0,g.jsx)(`span`,{className:`bg-task-script-name`,children:e})]}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn sm ${n?``:`primary`}`,disabled:n,onClick:()=>u({type:`start_bg_script`,script:e}),children:n?C(`bgTaskRunning`):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(r,{"aria-hidden":!0}),` `,C(`bgTaskStart`)]})})]},e)})})]}),O.map(e=>{let t=v.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,g.jsx)(`div`,{className:`bg-task-plugin-panel`,children:(0,g.jsx)(f,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,g.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)})]}),(0,g.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,g.jsxs)(`label`,{className:`bg-task-cleanup`,title:C(`bgTaskCleanupHint`),children:[(0,g.jsx)(`span`,{children:C(`bgTaskCleanup`)}),(0,g.jsxs)(`select`,{className:`bg-task-select`,value:String(S),onChange:e=>u({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,g.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,g.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,g.jsx)(`span`,{className:`sp`}),(0,g.jsxs)(`button`,{type:`button`,className:`btn bg-task-btn ghost danger sm`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>u({type:`kill_background_servers`}),children:[(0,g.jsx)(n,{"aria-hidden":!0}),` `,C(`bgTaskStopAll`)]})]})]})}export{v as BgTasksModal};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ft as t,Jt as n,Mt as r,gn as i,sn as a,ut as o,vn as s}from"./fi-DjvtEEnZ.js";import{i as c,t as l}from"./react-CR5VJ85Q.js";import{t as u}from"./app-globals-wu8LLlnA.js";import{Vt as d,W as f,Wt as p,X as m}from"./index-Y0yKgBrc.js";var h=e(c(),1),g=l();function _(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function v({servers:e,projectScripts:c,onClose:l,plugins:v=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=s(),{locale:w}=i();(0,h.useEffect)(()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},[]);let T=(0,h.useMemo)(()=>e.filter(e=>(e.kind??(e.taskId?`plugin`:`port`))===`job`),[e]),E=(0,h.useMemo)(()=>{let e=new Set;for(let t of T){let n=/npm run ([A-Za-z0-9 _.:-]+)/.exec(t.command??``);n&&e.add(n[1])}return e},[T]),D=(0,h.useMemo)(()=>Object.entries(c?.scripts??{}),[c]),O=(0,h.useMemo)(()=>(d(p(v),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[v,w,C]),[k,A]=(0,h.useState)(new Set),j=e=>{let t=e.taskId??String(e.port);A(e=>new Set(e).add(t));let n=e.kind??(e.taskId?`plugin`:`port`);u(n===`plugin`||n===`job`?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),u({type:`list_bg_servers`}),setTimeout(()=>u({type:`list_bg_servers`}),1500),setTimeout(()=>u({type:`list_bg_servers`}),4e3),setTimeout(()=>{A(e=>{let n=new Set(e);return n.delete(t),n})},8e3)};return(0,g.jsxs)(m,{className:`bg-task-modal bg-task-modal-a`,onClose:l,showCloseButton:!1,children:[(0,g.jsxs)(`div`,{className:`bg-task-head`,children:[(0,g.jsxs)(`div`,{className:`bg-task-title`,children:[(0,g.jsx)(o,{"aria-hidden":!0}),(0,g.jsx)(`span`,{children:C(`bgTasks`)}),e.length>0&&(0,g.jsxs)(`em`,{className:`bg-task-count`,children:[e.length,` 运行`]})]}),(0,g.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRefresh`),onClick:()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`close`),onClick:l,children:(0,g.jsx)(a,{})})]})]}),(0,g.jsxs)(`div`,{className:`bg-task-body`,children:[e.length===0&&D.length===0?(0,g.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,g.jsx)(o,{}),(0,g.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,g.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):null,e.length>0&&(0,g.jsx)(`div`,{className:`bg-task-running`,children:e.map(e=>{let n=e.kind??(e.taskId?`plugin`:`port`),r=n===`plugin`,i=n===`job`,a=e.taskId??String(e.port),o=r?e.plugin:i?e.name||C(`bgTaskJobKind`):`:${e.port}`,s=[e.name&&!i?e.name:null,r&&e.status?e.status:null,C(`bgTaskSince`)+` `+_(e.since,C),!r&&e.pid?`${C(`bgTaskPid`)} ${e.pid}`:null].filter(Boolean).join(` · `);return(0,g.jsxs)(`div`,{className:`bg-task-run-card`,title:e.command||void 0,children:[(0,g.jsx)(`span`,{className:`bg-task-dot`,"aria-hidden":!0}),(0,g.jsxs)(`div`,{className:`bg-task-run-main`,children:[(0,g.jsx)(`div`,{className:`bg-task-run-name`,children:o}),(0,g.jsx)(`div`,{className:`bg-task-run-sub`,children:s})]}),(0,g.jsxs)(`div`,{className:`bg-task-run-actions`,children:[n===`port`&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn ${e.keep?`active`:``}`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>u({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:`📌`}),i&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRestart`),onClick:()=>u({type:`restart_bg_job`,taskId:e.taskId??``}),children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn danger sm`,disabled:k.has(e.taskId??String(e.port)),onClick:()=>j(e),children:k.has(e.taskId??String(e.port))?C(`bgTaskStopping`):C(`bgTaskStop`)})]})]},a)})}),D.length>0&&(0,g.jsxs)(`div`,{className:`bg-task-scripts`,children:[(0,g.jsxs)(`div`,{className:`bg-task-kicker`,children:[(0,g.jsx)(`span`,{children:C(`bgTaskQuickStart`)}),c?.cwd?(0,g.jsx)(`span`,{className:`bg-task-cwd mono`,title:c.cwd,children:c.cwd}):null]}),(0,g.jsx)(`div`,{className:`bg-task-script-list`,children:D.map(([e,t])=>{let n=E.has(e);return(0,g.jsxs)(`div`,{className:`bg-task-script-row`,title:t,children:[(0,g.jsxs)(`div`,{className:`bg-task-script-cmd mono`,children:[(0,g.jsx)(`span`,{className:`bg-task-npm`,children:`npm run `}),(0,g.jsx)(`span`,{className:`bg-task-script-name`,children:e})]}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn sm ${n?``:`primary`}`,disabled:n,onClick:()=>u({type:`start_bg_script`,script:e}),children:n?C(`bgTaskRunning`):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(r,{"aria-hidden":!0}),` `,C(`bgTaskStart`)]})})]},e)})})]}),O.map(e=>{let t=v.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,g.jsx)(`div`,{className:`bg-task-plugin-panel`,children:(0,g.jsx)(f,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,g.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)})]}),(0,g.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,g.jsxs)(`label`,{className:`bg-task-cleanup`,title:C(`bgTaskCleanupHint`),children:[(0,g.jsx)(`span`,{children:C(`bgTaskCleanup`)}),(0,g.jsxs)(`select`,{className:`bg-task-select`,value:String(S),onChange:e=>u({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,g.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,g.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,g.jsx)(`span`,{className:`sp`}),(0,g.jsxs)(`button`,{type:`button`,className:`btn bg-task-btn ghost danger sm`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>u({type:`kill_background_servers`}),children:[(0,g.jsx)(n,{"aria-hidden":!0}),` `,C(`bgTaskStopAll`)]})]})]})}export{v as BgTasksModal};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ft as t,Jt as n,Mt as r,gn as i,sn as a,ut as o,vn as s}from"./fi-CcqqfamG.js";import{i as c,t as l}from"./react-CR5VJ85Q.js";import{t as u}from"./app-globals-wu8LLlnA.js";import{Vt as d,W as f,Wt as p,X as m}from"./index-Dbv9RJwm.js";var h=e(c(),1),g=l();function _(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function v({servers:e,projectScripts:c,onClose:l,plugins:v=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=s(),{locale:w}=i();(0,h.useEffect)(()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},[]);let T=(0,h.useMemo)(()=>e.filter(e=>(e.kind??(e.taskId?`plugin`:`port`))===`job`),[e]),E=(0,h.useMemo)(()=>{let e=new Set;for(let t of T){let n=/npm run ([A-Za-z0-9 _.:-]+)/.exec(t.command??``);n&&e.add(n[1])}return e},[T]),D=(0,h.useMemo)(()=>Object.entries(c?.scripts??{}),[c]),O=(0,h.useMemo)(()=>(d(p(v),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[v,w,C]),[k,A]=(0,h.useState)(new Set),j=e=>{let t=e.taskId??String(e.port);A(e=>new Set(e).add(t));let n=e.kind??(e.taskId?`plugin`:`port`);u(n===`plugin`||n===`job`?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),u({type:`list_bg_servers`}),setTimeout(()=>u({type:`list_bg_servers`}),1500),setTimeout(()=>u({type:`list_bg_servers`}),4e3),setTimeout(()=>{A(e=>{let n=new Set(e);return n.delete(t),n})},8e3)};return(0,g.jsxs)(m,{className:`bg-task-modal bg-task-modal-a`,onClose:l,showCloseButton:!1,children:[(0,g.jsxs)(`div`,{className:`bg-task-head`,children:[(0,g.jsxs)(`div`,{className:`bg-task-title`,children:[(0,g.jsx)(o,{"aria-hidden":!0}),(0,g.jsx)(`span`,{children:C(`bgTasks`)}),e.length>0&&(0,g.jsxs)(`em`,{className:`bg-task-count`,children:[e.length,` 运行`]})]}),(0,g.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRefresh`),onClick:()=>{u({type:`list_bg_servers`}),u({type:`project_scripts`})},children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`close`),onClick:l,children:(0,g.jsx)(a,{})})]})]}),(0,g.jsxs)(`div`,{className:`bg-task-body`,children:[e.length===0&&D.length===0?(0,g.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,g.jsx)(o,{}),(0,g.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,g.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):null,e.length>0&&(0,g.jsx)(`div`,{className:`bg-task-running`,children:e.map(e=>{let n=e.kind??(e.taskId?`plugin`:`port`),r=n===`plugin`,i=n===`job`,a=e.taskId??String(e.port),o=r?e.plugin:i?e.name||C(`bgTaskJobKind`):`:${e.port}`,s=[e.name&&!i?e.name:null,r&&e.status?e.status:null,C(`bgTaskSince`)+` `+_(e.since,C),!r&&e.pid?`${C(`bgTaskPid`)} ${e.pid}`:null].filter(Boolean).join(` · `);return(0,g.jsxs)(`div`,{className:`bg-task-run-card`,title:e.command||void 0,children:[(0,g.jsx)(`span`,{className:`bg-task-dot`,"aria-hidden":!0}),(0,g.jsxs)(`div`,{className:`bg-task-run-main`,children:[(0,g.jsx)(`div`,{className:`bg-task-run-name`,children:o}),(0,g.jsx)(`div`,{className:`bg-task-run-sub`,children:s})]}),(0,g.jsxs)(`div`,{className:`bg-task-run-actions`,children:[n===`port`&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn ${e.keep?`active`:``}`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>u({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:`📌`}),i&&(0,g.jsx)(`button`,{type:`button`,className:`bg-task-icon-btn`,title:C(`bgTaskRestart`),onClick:()=>u({type:`restart_bg_job`,taskId:e.taskId??``}),children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn danger sm`,disabled:k.has(e.taskId??String(e.port)),onClick:()=>j(e),children:k.has(e.taskId??String(e.port))?C(`bgTaskStopping`):C(`bgTaskStop`)})]})]},a)})}),D.length>0&&(0,g.jsxs)(`div`,{className:`bg-task-scripts`,children:[(0,g.jsxs)(`div`,{className:`bg-task-kicker`,children:[(0,g.jsx)(`span`,{children:C(`bgTaskQuickStart`)}),c?.cwd?(0,g.jsx)(`span`,{className:`bg-task-cwd mono`,title:c.cwd,children:c.cwd}):null]}),(0,g.jsx)(`div`,{className:`bg-task-script-list`,children:D.map(([e,t])=>{let n=E.has(e);return(0,g.jsxs)(`div`,{className:`bg-task-script-row`,title:t,children:[(0,g.jsxs)(`div`,{className:`bg-task-script-cmd mono`,children:[(0,g.jsx)(`span`,{className:`bg-task-npm`,children:`npm run `}),(0,g.jsx)(`span`,{className:`bg-task-script-name`,children:e})]}),(0,g.jsx)(`button`,{type:`button`,className:`btn bg-task-btn sm ${n?``:`primary`}`,disabled:n,onClick:()=>u({type:`start_bg_script`,script:e}),children:n?C(`bgTaskRunning`):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(r,{"aria-hidden":!0}),` `,C(`bgTaskStart`)]})})]},e)})})]}),O.map(e=>{let t=v.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,g.jsx)(`div`,{className:`bg-task-plugin-panel`,children:(0,g.jsx)(f,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,g.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)})]}),(0,g.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,g.jsxs)(`label`,{className:`bg-task-cleanup`,title:C(`bgTaskCleanupHint`),children:[(0,g.jsx)(`span`,{children:C(`bgTaskCleanup`)}),(0,g.jsxs)(`select`,{className:`bg-task-select`,value:String(S),onChange:e=>u({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,g.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,g.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,g.jsx)(`span`,{className:`sp`}),(0,g.jsxs)(`button`,{type:`button`,className:`btn bg-task-btn ghost danger sm`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>u({type:`kill_background_servers`}),children:[(0,g.jsx)(n,{"aria-hidden":!0}),` `,C(`bgTaskStopAll`)]})]})]})}export{v as BgTasksModal};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,E as n,sn as r,vn as i}from"./fi-DjvtEEnZ.js";import{i as a,t as o}from"./react-CR5VJ85Q.js";var s=e(a(),1),c=o(),l=`pi-web-ui:bottom-dock-h`,u=`pi-web-ui:term-drawer-h`,d=180,f=318;function p(){try{let e=localStorage.getItem(l)??localStorage.getItem(u),t=e===null?NaN:Number(e);if(Number.isFinite(t)&&t>=d)return t}catch{}return f}function m({open:e,collapsed:a,onToggleCollapse:o,onHide:u,tabs:m,activeId:h,onSelectTab:g}){let _=i(),v=(0,s.useRef)(null),[y,b]=(0,s.useState)(p),[x,S]=(0,s.useState)(!1),C=m.length>1,w=m.find(e=>e.id===h)??m[0];(0,s.useEffect)(()=>{if(!x)try{localStorage.setItem(l,String(Math.round(y)))}catch{}},[y,x]);let T=(0,s.useCallback)(()=>{let e=v.current?.parentElement?.clientHeight??window.innerHeight;return Math.max(220,Math.round(e*.7))},[]),E=(0,s.useCallback)(e=>{e.preventDefault();let t=e.currentTarget,n=e.clientY,r=y,i=T(),a=r;t.setPointerCapture(e.pointerId),S(!0),document.body.classList.add(`td-resizing`);let o=e=>{a=Math.min(i,Math.max(d,Math.round(r+(n-e.clientY)))),b(a)},s=()=>{t.removeEventListener(`pointermove`,o),t.removeEventListener(`pointerup`,s),t.removeEventListener(`pointercancel`,s),document.body.classList.remove(`td-resizing`),S(!1);try{localStorage.setItem(l,String(a))}catch{}};t.addEventListener(`pointermove`,o),t.addEventListener(`pointerup`,s),t.addEventListener(`pointercancel`,s)},[y,T]),D=(0,s.useCallback)(()=>{b(e=>e>358?f:Math.round(T()*.82))},[T]);return m.length===0?null:(0,c.jsxs)(`section`,{ref:v,className:`term-drawer bottom-dock${e?``:` closed`}${e&&a?` collapsed`:``}${x?` dragging`:``}`,style:{"--td-h":`${Math.round(y)}px`},"aria-label":w?.label??_(`terminal`),"aria-expanded":e,children:[(0,c.jsx)(`div`,{className:`td-grip`,role:`separator`,"aria-orientation":`horizontal`,title:_(`termDrawerResizeTip`),onPointerDown:E,onDoubleClick:D}),C&&(0,c.jsxs)(`div`,{className:`bd-head`,children:[(0,c.jsx)(`div`,{className:`bd-tabs`,role:`tablist`,children:m.map(e=>(0,c.jsx)(`button`,{type:`button`,role:`tab`,className:`bd-tab${e.id===w?.id?` on`:``}`,"aria-selected":e.id===w?.id,title:e.hint??e.label,onClick:()=>g(e.id),children:e.label},e.id))}),(0,c.jsxs)(`div`,{className:`bd-acts`,children:[(0,c.jsx)(`button`,{type:`button`,className:`icon-btn`,title:_(a?`termDrawerExpand`:`termDrawerCollapse`),onClick:o,children:a?(0,c.jsx)(n,{}):(0,c.jsx)(t,{})}),(0,c.jsx)(`button`,{type:`button`,className:`icon-btn`,title:_(`termDrawerHide`),onClick:u,children:(0,c.jsx)(r,{})})]})]}),C?(0,c.jsx)(`div`,{className:`bd-panes`,children:m.map(e=>(0,c.jsx)(`div`,{className:`bd-pane${e.id===w?.id?``:` hidden`}`,children:e.element},e.id))}):w.element]})}export{m as BottomDock};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,E as n,sn as r,vn as i}from"./fi-CcqqfamG.js";import{i as a,t as o}from"./react-CR5VJ85Q.js";var s=e(a(),1),c=o(),l=`pi-web-ui:bottom-dock-h`,u=`pi-web-ui:term-drawer-h`,d=180,f=318;function p(){try{let e=localStorage.getItem(l)??localStorage.getItem(u),t=e===null?NaN:Number(e);if(Number.isFinite(t)&&t>=d)return t}catch{}return f}function m({open:e,collapsed:a,onToggleCollapse:o,onHide:u,tabs:m,activeId:h,onSelectTab:g}){let _=i(),v=(0,s.useRef)(null),[y,b]=(0,s.useState)(p),[x,S]=(0,s.useState)(!1),C=m.length>1,w=m.find(e=>e.id===h)??m[0];(0,s.useEffect)(()=>{if(!x)try{localStorage.setItem(l,String(Math.round(y)))}catch{}},[y,x]);let T=(0,s.useCallback)(()=>{let e=v.current?.parentElement?.clientHeight??window.innerHeight;return Math.max(220,Math.round(e*.7))},[]),E=(0,s.useCallback)(e=>{e.preventDefault();let t=e.currentTarget,n=e.clientY,r=y,i=T(),a=r;t.setPointerCapture(e.pointerId),S(!0),document.body.classList.add(`td-resizing`);let o=e=>{a=Math.min(i,Math.max(d,Math.round(r+(n-e.clientY)))),b(a)},s=()=>{t.removeEventListener(`pointermove`,o),t.removeEventListener(`pointerup`,s),t.removeEventListener(`pointercancel`,s),document.body.classList.remove(`td-resizing`),S(!1);try{localStorage.setItem(l,String(a))}catch{}};t.addEventListener(`pointermove`,o),t.addEventListener(`pointerup`,s),t.addEventListener(`pointercancel`,s)},[y,T]),D=(0,s.useCallback)(()=>{b(e=>e>358?f:Math.round(T()*.82))},[T]);return m.length===0?null:(0,c.jsxs)(`section`,{ref:v,className:`term-drawer bottom-dock${e?``:` closed`}${e&&a?` collapsed`:``}${x?` dragging`:``}`,style:{"--td-h":`${Math.round(y)}px`},"aria-label":w?.label??_(`terminal`),"aria-expanded":e,children:[(0,c.jsx)(`div`,{className:`td-grip`,role:`separator`,"aria-orientation":`horizontal`,title:_(`termDrawerResizeTip`),onPointerDown:E,onDoubleClick:D}),C&&(0,c.jsxs)(`div`,{className:`bd-head`,children:[(0,c.jsx)(`div`,{className:`bd-tabs`,role:`tablist`,children:m.map(e=>(0,c.jsx)(`button`,{type:`button`,role:`tab`,className:`bd-tab${e.id===w?.id?` on`:``}`,"aria-selected":e.id===w?.id,title:e.hint??e.label,onClick:()=>g(e.id),children:e.label},e.id))}),(0,c.jsxs)(`div`,{className:`bd-acts`,children:[(0,c.jsx)(`button`,{type:`button`,className:`icon-btn`,title:_(a?`termDrawerExpand`:`termDrawerCollapse`),onClick:o,children:a?(0,c.jsx)(n,{}):(0,c.jsx)(t,{})}),(0,c.jsx)(`button`,{type:`button`,className:`icon-btn`,title:_(`termDrawerHide`),onClick:u,children:(0,c.jsx)(r,{})})]})]}),C?(0,c.jsx)(`div`,{className:`bd-panes`,children:m.map(e=>(0,c.jsx)(`div`,{className:`bd-pane${e.id===w?.id?``:` hidden`}`,children:e.element},e.id))}):w.element]})}export{m as BottomDock};
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$t as n,Bt as r,It as i,Jt as a,L as o,Lt as s,Mt as c,N as l,Pt as u,U as d,X as f,Xt as ee,Y as te,Z as p,_n as m,an as ne,b as h,bn as g,ln as _,n as v,qt as y,sn as re,t as ie,un as b,vn as ae,vt as oe,wt as x,x as S,xt as C}from"./fi-DjvtEEnZ.js";import{i as w,r as T,t as se}from"./react-CR5VJ85Q.js";import{t as E}from"./use-floating-panel-tvvfNgvg.js";import{p as ce}from"./DeviceGroupSection-CRdMGDwE.js";import{t as D}from"./uuid-BzDIGCwP.js";import{t as O}from"./app-globals-wu8LLlnA.js";import{n as le,t as ue}from"./composer-bridge-CImnjDHq.js";import{It as de,pt as fe,y as k}from"./index-CXTnvcJF.js";import{toPng as A}from"./es-DWMIuDU2.js";import{t as pe}from"./canvas-client-LIotRrYf.js";function j(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let{key:t,vars:n}=e;return typeof t==`string`&&t.length>0&&(n===void 0||typeof n==`object`&&!!n&&!Array.isArray(n)&&Object.values(n).every(e=>typeof e==`string`||typeof e==`number`&&Number.isFinite(e)))}function M(e,t,n){return j(e)&&Object.hasOwn(g,e.key)?n(e.key,e.vars):t??``}function me(e){return{handoff:e(`canvas.edges.type.handoff`),review:e(`canvas.edges.type.review`),parallel:e(`canvas.edges.type.parallel`),loop_back:e(`canvas.edges.type.loop_back`),condition_true:e(`canvas.edges.type.condition_true`),condition_false:e(`canvas.edges.type.condition_false`),approve:e(`canvas.edges.type.approve`),reject:e(`canvas.edges.type.reject`)}}var N=e(w(),1),P=[{id:`architect`,category:`architecture`,icon:`🏛️`,description:`Sketch types, signatures, and module structure before code, then stay in the loop while implementation fills in. Use for /architect, 'architect this', 'design this', or non-trivial work where jumping to code would lock in the wrong shape.`,content:`# Architect
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$t as n,Bt as r,It as i,Jt as a,L as o,Lt as s,Mt as c,N as l,Pt as u,U as d,X as f,Xt as ee,Y as te,Z as p,_n as m,an as ne,b as h,bn as g,ln as _,n as v,qt as y,sn as re,t as ie,un as b,vn as ae,vt as oe,wt as x,x as S,xt as C}from"./fi-CcqqfamG.js";import{i as w,r as T,t as se}from"./react-CR5VJ85Q.js";import{t as E}from"./use-floating-panel-tvvfNgvg.js";import{p as ce}from"./DeviceGroupSection-B98LzFoj.js";import{t as D}from"./uuid-BzDIGCwP.js";import{t as O}from"./app-globals-wu8LLlnA.js";import{n as le,t as ue}from"./composer-bridge-CImnjDHq.js";import{It as de,pt as fe,y as k}from"./index-Dbv9RJwm.js";import{toPng as A}from"./es-DWMIuDU2.js";import{t as pe}from"./canvas-client-OwhfLxJx.js";function j(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let{key:t,vars:n}=e;return typeof t==`string`&&t.length>0&&(n===void 0||typeof n==`object`&&!!n&&!Array.isArray(n)&&Object.values(n).every(e=>typeof e==`string`||typeof e==`number`&&Number.isFinite(e)))}function M(e,t,n){return j(e)&&Object.hasOwn(g,e.key)?n(e.key,e.vars):t??``}function me(e){return{handoff:e(`canvas.edges.type.handoff`),review:e(`canvas.edges.type.review`),parallel:e(`canvas.edges.type.parallel`),loop_back:e(`canvas.edges.type.loop_back`),condition_true:e(`canvas.edges.type.condition_true`),condition_false:e(`canvas.edges.type.condition_false`),approve:e(`canvas.edges.type.approve`),reject:e(`canvas.edges.type.reject`)}}var N=e(w(),1),P=[{id:`architect`,category:`architecture`,icon:`🏛️`,description:`Sketch types, signatures, and module structure before code, then stay in the loop while implementation fills in. Use for /architect, 'architect this', 'design this', or non-trivial work where jumping to code would lock in the wrong shape.`,content:`# Architect
2
2
 
3
3
  Sketch types, function signatures, class shapes, and module boundaries with \`not implemented\` bodies and pseudocode. Synthesize across multiple model perspectives, then fill in code against the chosen sketch.
4
4
 
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$t as n,Bt as r,It as i,Jt as a,L as o,Lt as s,Mt as c,N as l,Pt as u,U as d,X as f,Xt as ee,Y as te,Z as p,_n as m,an as ne,b as h,bn as g,ln as _,n as v,qt as y,sn as re,t as ie,un as b,vn as ae,vt as oe,wt as x,x as S,xt as C}from"./fi-DjvtEEnZ.js";import{i as w,r as T,t as se}from"./react-CR5VJ85Q.js";import{t as E}from"./use-floating-panel-tvvfNgvg.js";import{p as ce}from"./DeviceGroupSection-CRdMGDwE.js";import{t as D}from"./uuid-BzDIGCwP.js";import{t as O}from"./app-globals-wu8LLlnA.js";import{n as le,t as ue}from"./composer-bridge-CImnjDHq.js";import{It as de,pt as fe,y as k}from"./index-Y0yKgBrc.js";import{toPng as A}from"./es-DWMIuDU2.js";import{t as pe}from"./canvas-client-LIotRrYf.js";function j(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let{key:t,vars:n}=e;return typeof t==`string`&&t.length>0&&(n===void 0||typeof n==`object`&&!!n&&!Array.isArray(n)&&Object.values(n).every(e=>typeof e==`string`||typeof e==`number`&&Number.isFinite(e)))}function M(e,t,n){return j(e)&&Object.hasOwn(g,e.key)?n(e.key,e.vars):t??``}function me(e){return{handoff:e(`canvas.edges.type.handoff`),review:e(`canvas.edges.type.review`),parallel:e(`canvas.edges.type.parallel`),loop_back:e(`canvas.edges.type.loop_back`),condition_true:e(`canvas.edges.type.condition_true`),condition_false:e(`canvas.edges.type.condition_false`),approve:e(`canvas.edges.type.approve`),reject:e(`canvas.edges.type.reject`)}}var N=e(w(),1),P=[{id:`architect`,category:`architecture`,icon:`🏛️`,description:`Sketch types, signatures, and module structure before code, then stay in the loop while implementation fills in. Use for /architect, 'architect this', 'design this', or non-trivial work where jumping to code would lock in the wrong shape.`,content:`# Architect
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$t as n,Bt as r,It as i,Jt as a,L as o,Lt as s,Mt as c,N as l,Pt as u,U as d,X as f,Xt as ee,Y as te,Z as p,_n as m,an as ne,b as h,bn as g,ln as _,n as v,qt as y,sn as re,t as ie,un as b,vn as ae,vt as oe,wt as x,x as S,xt as C}from"./fi-CcqqfamG.js";import{i as w,r as T,t as se}from"./react-CR5VJ85Q.js";import{t as E}from"./use-floating-panel-tvvfNgvg.js";import{p as ce}from"./DeviceGroupSection-BD3CKMFH.js";import{t as D}from"./uuid-BzDIGCwP.js";import{t as O}from"./app-globals-wu8LLlnA.js";import{n as le,t as ue}from"./composer-bridge-CImnjDHq.js";import{n as de}from"./use-copy-feedback-B3di-fnu.js";import{pt as fe,y as k}from"./index-BQb8EOhk.js";import{toPng as A}from"./es-DWMIuDU2.js";import{t as pe}from"./canvas-client-OwhfLxJx.js";function j(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let{key:t,vars:n}=e;return typeof t==`string`&&t.length>0&&(n===void 0||typeof n==`object`&&!!n&&!Array.isArray(n)&&Object.values(n).every(e=>typeof e==`string`||typeof e==`number`&&Number.isFinite(e)))}function M(e,t,n){return j(e)&&Object.hasOwn(g,e.key)?n(e.key,e.vars):t??``}function me(e){return{handoff:e(`canvas.edges.type.handoff`),review:e(`canvas.edges.type.review`),parallel:e(`canvas.edges.type.parallel`),loop_back:e(`canvas.edges.type.loop_back`),condition_true:e(`canvas.edges.type.condition_true`),condition_false:e(`canvas.edges.type.condition_false`),approve:e(`canvas.edges.type.approve`),reject:e(`canvas.edges.type.reject`)}}var N=e(w(),1),P=[{id:`architect`,category:`architecture`,icon:`🏛️`,description:`Sketch types, signatures, and module structure before code, then stay in the loop while implementation fills in. Use for /architect, 'architect this', 'design this', or non-trivial work where jumping to code would lock in the wrong shape.`,content:`# Architect
2
2
 
3
3
  Sketch types, function signatures, class shapes, and module boundaries with \`not implemented\` bodies and pseudocode. Synthesize across multiple model perspectives, then fill in code against the chosen sketch.
4
4
 
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,Et as n,Fn as r,Ft as i,H as a,N as o,Pt as s,W as c,Wt as l,an as u,b as d,ft as f,it as p,kn as m,sn as h,st as g,vn as ee,xt as _}from"./fi-DjvtEEnZ.js";import{i as v,r as y,t as b}from"./react-CR5VJ85Q.js";import{a as te,i as x,n as S}from"./api-client-CGqoOWHJ.js";import{o as ne}from"./DeviceGroupSection-CRdMGDwE.js";import{ct as C,f as w,in as T}from"./index-Y0yKgBrc.js";import{t as E}from"./DeviceExecutionSettings-2hoZaBQ0.js";import{n as re,t as D}from"./GroupWorkItems-BeZvaxV9.js";var O=e(v(),1);async function ie(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var k=b();function A(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function ae({plugin:e,epoch:t,onManageGroups:n}){let r=ee(),[i,a]=(0,O.useState)(null),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(0),{id:u,name:d,version:f,hasClient:p,error:m,isolated:h}=e??{},g=(0,O.useMemo)(()=>u?{id:u,name:d??u,version:f,hasClient:p??!1,error:m,isolated:h}:void 0,[u,d,f,p,m,h]);(0,O.useEffect)(()=>{let e=!1;if(a(null),s(!1),g&&!g.error&&g.hasClient)return C(g,t,{retry:c>0}).then(t=>{e||(A(t)?a({info:g,module:t}):s(!0))}),()=>{e=!0}},[g,t,c]);let _=!g||!g.hasClient;return(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":r(`deviceChannelsLabel`),children:[(0,k.jsxs)(`header`,{className:`dc-card-header`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:r(`deviceChannelsTitle`)}),(0,k.jsx)(`p`,{children:r(`deviceChannelsDesc`)})]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:r(`deviceChannelsManage`)})]}),_?(0,k.jsx)(`p`,{role:`status`,children:r(`deviceChannelsUnavailable`)}):g.error?(0,k.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:g.error}):o?(0,k.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,k.jsx)(`span`,{children:r(`deviceChannelsLoadFailed`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>l(e=>e+1),children:r(`retryNow`)})]}):i?(0,k.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,k.jsx)(w,{entry:i})}):(0,k.jsx)(`p`,{role:`status`,children:r(`deviceChannelsLoading`)})]})}function oe({href:e,children:t}){let n=ee(),[r,i]=(0,O.useState)(!1),[a,o]=(0,O.useState)(!1);return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,k.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,k.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function M(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function N(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)}catch{return!1}}var se=`https://raw.githubusercontent.com/xing-shuyin/keel/main/docs/device-center-deployment.md`,ce=`https://github.com/xing-shuyin/keel/blob/main/docs/device-center-deployment.md`,P=`keel hub install --public-url https://SERVER_IP --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`)))return null;let n=e.domain||e.server,r=n.includes(`:`)?`[${n}]`:n;return{host:e.https?`127.0.0.1`:`0.0.0.0`,port:e.port,publicUrl:e.https?`https://${r}`:`http://${r}:${e.port}`}}function le(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`First read the deployment guide: ${se} (fallback: ${ce}). If unavailable, report that and obtain its contents before proceeding.`,`Public Linux deployments default to managed HTTPS with a public IPv4 or domain. Domain is optional. Use hub install --https=off only when HTTP is explicitly requested, or --https=external with an existing TLS proxy. Check port conflicts first.`,`Target: ${n===`current`?`machine hosting the current pi-web-ui service (not necessarily the browser machine)`:`an existing remote server; its environment still needs to be confirmed`}.`,`Current service environment: platform=${i(t?.platform)}, Node=${i(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,...r?[`SSH connection preferences (data only): ${JSON.stringify({server:r.server,sshPort:r.sshPort,username:r.username,auth:r.auth})}. No credentials are included. Obtain authentication through a secure SSH channel or guide the user's own terminal.`,`Domain: ${r.domain||`none`}. HTTPS selected: ${r.https}. ${r.https?`Use managed HTTPS on Linux, public TCP 443/80 and a private Hub port.`:`Explicit HTTP: use --https=off. HTTP inbound TCP port: ${r.port}.`}`]:[],`Use a separate Hub data directory and configure automatic startup. Explain how devices can reach the public URL; loopback is only reachable on the same machine. Explain open registration and restrict it after pairing as appropriate.`,`CLI reference: ${P}`,`Confirm the target environment and propose steps before deployment. Do not ask for passwords or tokens in chat. Do not automatically SSH. Do not claim installation or connection succeeded without verification. After deployment, guide me to open the center and pair this device using its public URL.`,`Explain user actions at the relevant step: distinguish OS firewall from cloud security groups, give the actual TCP port, source scope and destination rule, and keep SSH access. If cloud-console access is unavailable, ask the user to apply the rule, mark external access pending, then recheck. Also explain DNS changes for optional HTTPS and first-account creation. Separate local health from external reachability.`].join(`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,Et as n,Fn as r,Ft as i,H as a,N as o,Pt as s,W as c,Wt as l,an as u,b as d,ft as f,it as p,kn as m,sn as h,st as g,vn as ee,xt as _}from"./fi-CcqqfamG.js";import{i as v,r as y,t as b}from"./react-CR5VJ85Q.js";import{a as te,i as x,n as S}from"./api-client-BbDlV0jR.js";import{o as ne}from"./DeviceGroupSection-BD3CKMFH.js";import{ct as C,f as w,nn as T}from"./index-BQb8EOhk.js";import{t as E}from"./DeviceExecutionSettings-BjduyZOy.js";import{n as re,t as D}from"./GroupWorkItems-7yTbAr_f.js";var O=e(v(),1);async function ie(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var k=b();function A(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function ae({plugin:e,epoch:t,onManageGroups:n}){let r=ee(),[i,a]=(0,O.useState)(null),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(0),{id:u,name:d,version:f,hasClient:p,error:m,isolated:h}=e??{},g=(0,O.useMemo)(()=>u?{id:u,name:d??u,version:f,hasClient:p??!1,error:m,isolated:h}:void 0,[u,d,f,p,m,h]);(0,O.useEffect)(()=>{let e=!1;if(a(null),s(!1),g&&!g.error&&g.hasClient)return C(g,t,{retry:c>0}).then(t=>{e||(A(t)?a({info:g,module:t}):s(!0))}),()=>{e=!0}},[g,t,c]);let _=!g||!g.hasClient;return(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":r(`deviceChannelsLabel`),children:[(0,k.jsxs)(`header`,{className:`dc-card-header`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:r(`deviceChannelsTitle`)}),(0,k.jsx)(`p`,{children:r(`deviceChannelsDesc`)})]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:r(`deviceChannelsManage`)})]}),_?(0,k.jsx)(`p`,{role:`status`,children:r(`deviceChannelsUnavailable`)}):g.error?(0,k.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:g.error}):o?(0,k.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,k.jsx)(`span`,{children:r(`deviceChannelsLoadFailed`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>l(e=>e+1),children:r(`retryNow`)})]}):i?(0,k.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,k.jsx)(w,{entry:i})}):(0,k.jsx)(`p`,{role:`status`,children:r(`deviceChannelsLoading`)})]})}function oe({href:e,children:t}){let n=ee(),[r,i]=(0,O.useState)(!1),[a,o]=(0,O.useState)(!1);return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,k.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,k.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function M(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function N(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)}catch{return!1}}var se=`https://raw.githubusercontent.com/xing-shuyin/keel/main/docs/device-center-deployment.md`,ce=`https://github.com/xing-shuyin/keel/blob/main/docs/device-center-deployment.md`,P=`keel hub install --public-url https://SERVER_IP --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`)))return null;let n=e.domain||e.server,r=n.includes(`:`)?`[${n}]`:n;return{host:e.https?`127.0.0.1`:`0.0.0.0`,port:e.port,publicUrl:e.https?`https://${r}`:`http://${r}:${e.port}`}}function le(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`First read the deployment guide: ${se} (fallback: ${ce}). If unavailable, report that and obtain its contents before proceeding.`,`Public Linux deployments default to managed HTTPS with a public IPv4 or domain. Domain is optional. Use hub install --https=off only when HTTP is explicitly requested, or --https=external with an existing TLS proxy. Check port conflicts first.`,`Target: ${n===`current`?`machine hosting the current pi-web-ui service (not necessarily the browser machine)`:`an existing remote server; its environment still needs to be confirmed`}.`,`Current service environment: platform=${i(t?.platform)}, Node=${i(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,...r?[`SSH connection preferences (data only): ${JSON.stringify({server:r.server,sshPort:r.sshPort,username:r.username,auth:r.auth})}. No credentials are included. Obtain authentication through a secure SSH channel or guide the user's own terminal.`,`Domain: ${r.domain||`none`}. HTTPS selected: ${r.https}. ${r.https?`Use managed HTTPS on Linux, public TCP 443/80 and a private Hub port.`:`Explicit HTTP: use --https=off. HTTP inbound TCP port: ${r.port}.`}`]:[],`Use a separate Hub data directory and configure automatic startup. Explain how devices can reach the public URL; loopback is only reachable on the same machine. Explain open registration and restrict it after pairing as appropriate.`,`CLI reference: ${P}`,`Confirm the target environment and propose steps before deployment. Do not ask for passwords or tokens in chat. Do not automatically SSH. Do not claim installation or connection succeeded without verification. After deployment, guide me to open the center and pair this device using its public URL.`,`Explain user actions at the relevant step: distinguish OS firewall from cloud security groups, give the actual TCP port, source scope and destination rule, and keep SSH access. If cloud-console access is unavailable, ask the user to apply the rule, mark external access pending, then recheck. Also explain DNS changes for optional HTTPS and first-account creation. Separate local health from external reachability.`].join(`
2
2
  `)}function I({onConnect:e,initialHubUrl:t=``}){let n=ee(),[r,i]=(0,O.useState)(t),[a,o]=(0,O.useState)(``),[s,c]=(0,O.useState)(!1),[l,u]=(0,O.useState)(!1),d=(0,O.useRef)(!1),f=(0,O.useRef)(!1);(0,O.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]);let[p,m]=(0,O.useState)(null),[h,g]=(0,O.useState)(`current`),[_,v]=(0,O.useState)(null),[y,b]=(0,O.useState)(`127.0.0.1`),[te,ne]=(0,O.useState)(`8790`),[C,w]=(0,O.useState)(`http://127.0.0.1:8790`),[T,E]=(0,O.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!0}),re=F(T),[D,ie]=(0,O.useState)(!1),[A,ae]=(0,O.useState)(!1),[M,se]=(0,O.useState)(null),[ce,P]=(0,O.useState)(!1),[I,ue]=(0,O.useState)(!1),[L,de]=(0,O.useState)(!1),[R,z]=(0,O.useState)(null),B=(0,O.useRef)(null),V=(0,O.useRef)(!1),H=N(window.location.origin);(0,O.useEffect)(()=>()=>B.current?.abort(),[]);let U=async()=>{if(V.current)return;B.current?.abort();let e=new AbortController;B.current=e,P(!1),ue(!1),de(!1);try{let t=await S(`/api/device-center/setup`,{signal:e.signal});if(!t.ok)throw Error();let n=await t.json();if(!n||typeof n.platform!=`string`||typeof n.nodeVersion!=`string`||typeof n.dataDir!=`string`||typeof n.cliPath!=`string`||!j({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;v(n),n.installation?.installed?(b(n.installation.host??`127.0.0.1`),ne(String(n.installation.port)),w(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):_||(ne(String(n.defaultPort)),w(n.defaultPublicUrl))}catch{e.signal.aborted||(P(!0),de(!0))}finally{e.signal.aborted||ue(!0)}},W=async()=>{let e={host:y,port:Number(te),publicUrl:C};if(V.current||!H||!_||!I||L||_.busy||_.installation?.installed||!j(e))return;V.current=!0,B.current?.abort(),ie(!0),P(!1),o(``);let t=new AbortController;B.current=t;try{let n=await S(`/api/device-center/setup`,{body:{...e,allowRegistration:!0},signal:t.signal});if(n.status===409){v(e=>e&&{...e,busy:!0}),V.current=!1,ie(!1),await U();return}if(!n.ok){let e=await x(n);throw Error(e.error.slice(0,4096))}let r=await n.json();if(!j({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||z(r)}catch(e){t.signal.aborted||(P(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{V.current=!1,t.signal.aborted||ie(!1)}},G=async()=>{if(V.current||!H||!_||!I||L||_.busy||D||A)return;V.current=!0,B.current?.abort(),ae(!0),P(!1),o(``),se(null);let e=new AbortController;B.current=e;try{let t=await S(`/api/device-center/setup/update`,{method:`POST`,signal:e.signal});if(!t.ok){let e=await x(t);throw Error(e.error.slice(0,4096))}let r=await t.json();e.signal.aborted||(se(r.output||n(`deviceSetupUpdateSuccess`)),await U())}catch(t){e.signal.aborted||(P(!0),o(t instanceof Error?t.message.slice(0,4096):``))}finally{V.current=!1,e.signal.aborted||ae(!1)}},K=_?.installation,q=!!K?.installed,J=q&&K.running&&K.owned,Y=h===`remote`?re:{host:y,port:Number(te),publicUrl:C},X=!!Y&&j(Y);return(0,k.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,k.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(`button`,{className:`dc-button`,disabled:D,"aria-pressed":p===`connect`,onClick:()=>m(`connect`),children:n(`deviceSetupConnect`)}),(0,k.jsx)(`button`,{className:`dc-button`,disabled:D,"aria-pressed":p===`create`,onClick:()=>{m(`create`),!_&&H&&U()},children:n(`deviceSetupCreate`)})]}),p===`connect`&&(0,k.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,k.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,k.jsx)(`button`,{className:`dc-button is-primary`,disabled:!j({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),p===`create`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,k.jsxs)(`select`,{disabled:D,value:h,onChange:e=>g(e.target.value),children:[(0,k.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,k.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`p`,{children:n(h===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),h===`current`&&(0,k.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,k.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),_&&(0,k.jsxs)(`dl`,{children:[(0,k.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,k.jsxs)(`dd`,{children:[_.platform,` · Node `,_.nodeVersion]}),(0,k.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,k.jsx)(`dd`,{children:_.dataDir}),(0,k.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,k.jsx)(`dd`,{children:_.cliPath})]}),!H&&(0,k.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupBackground`)}),q&&(0,k.jsxs)(`div`,{role:`status`,children:[(0,k.jsx)(`h4`,{children:n(J?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,k.jsx)(`p`,{children:K.publicUrl}),J&&X&&K.publicUrl?(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(oe,{href:K.publicUrl,children:n(`deviceHubOpenHub`)}),(0,k.jsx)(`button`,{className:`dc-button`,onClick:()=>e(K.publicUrl),children:n(`deviceSetupPair`)}),H&&(0,k.jsx)(`button`,{className:`dc-button`,disabled:D||A,onClick:()=>void G(),children:n(A?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
3
  pi-web-ui hub --help`}),H&&(0,k.jsx)(`button`,{className:`dc-button is-primary`,disabled:D||A,onClick:()=>void G(),children:n(A?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),M&&(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:M.slice(0,16e3)})]}),_?.busy&&(0,k.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),H&&(0,k.jsx)(`button`,{className:`dc-button`,disabled:D||!I,onClick:()=>void U(),children:n(I?`deviceSetupRetry`:`deviceHubWorking`)})]}),h===`remote`?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,k.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:T.server,onChange:e=>E({...T,server:e.target.value.trim()})})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,k.jsx)(`input`,{type:`number`,min:1,max:65535,value:T.sshPort,onChange:e=>E({...T,sshPort:Number(e.target.value)})})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,k.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:T.username,onChange:e=>E({...T,username:e.target.value})})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,k.jsxs)(`select`,{value:T.auth,onChange:e=>E({...T,auth:e.target.value}),children:[(0,k.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,k.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,k.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,k.jsx)(`input`,{type:`number`,min:1024,max:65535,value:T.port,onChange:e=>E({...T,port:Number(e.target.value)})})]})]}),(0,k.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,k.jsxs)(`details`,{children:[(0,k.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,k.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:T.domain,onChange:e=>E({...T,domain:e.target.value.trim()})})]}),(0,k.jsxs)(`label`,{children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:T.https,onChange:e=>E({...T,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,k.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,k.jsxs)(`p`,{children:[(0,k.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,re?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,k.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,k.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,T.https?`443 / 80`:String(T.port))}),(0,k.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,k.jsx)(`a`,{href:`https://github.com/xing-shuyin/keel/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,k.jsx)(`input`,{disabled:D||!!R,maxLength:253,value:y,onChange:e=>b(e.target.value)})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,k.jsx)(`input`,{disabled:D||!!R,type:`number`,min:1024,max:65535,value:te,onChange:e=>ne(e.target.value)})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,k.jsx)(`input`,{disabled:D||!!R,maxLength:2048,value:C,onChange:e=>w(e.target.value)})]})]}),(0,k.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,k.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,k.jsx)(`p`,{role:`alert`,children:n(h===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[h===`current`&&!R&&!q&&(0,k.jsx)(`button`,{className:`dc-button is-primary`,disabled:D||!H||!_||!I||L||!!_.busy||!X,onClick:()=>void W(),children:n(D?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,k.jsx)(`button`,{className:`dc-button`,disabled:D||s||!X,onClick:()=>{if(!X||!Y||d.current)return;d.current=!0,c(!0),u(!1);let e=e=>{d.current=!1,f.current&&(c(!1),u(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:le(Y,_,h,h===`remote`?T:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(h===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,k.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),s&&(0,k.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),l&&(0,k.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),ce&&(0,k.jsxs)(`div`,{role:`alert`,children:[(0,k.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),R&&(0,k.jsxs)(`div`,{role:`status`,children:[(0,k.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:R.output.slice(0,16e3)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(oe,{href:R.publicUrl,children:n(`deviceHubOpenHub`)}),(0,k.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(R.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var ue=y(),L=`pi-web-ui:device-groups-changed`;function de(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function R(e,t,n){return te(`/api/device-center/${e}`,{body:n,signal:t})}function z({bindingKey:e=``}){return(0,k.jsx)(B,{},e)}function B(){let e=ee(),[n,r]=(0,O.useState)([]),[o,c]=(0,O.useState)([]),[l,f]=(0,O.useState)(!0),[p,m]=(0,O.useState)(``),[g,v]=(0,O.useState)(``),[y,b]=(0,O.useState)(0),[te,x]=(0,O.useState)(!1),[S,ne]=(0,O.useState)(``),[C,w]=(0,O.useState)([]),[T,E]=(0,O.useState)(``),[ie,A]=(0,O.useState)(null),[ae,oe]=(0,O.useState)(``),[j,M]=(0,O.useState)([]),[N,se]=(0,O.useState)(``),[ce,P]=(0,O.useState)(null),[F,le]=(0,O.useState)(``),[I,z]=(0,O.useState)(!1),[B,V]=(0,O.useState)(null),H=n.find(e=>e.id===B?.roomId),U=(0,O.useRef)(0),W=(0,O.useRef)(null),G=(0,O.useRef)(null);function K(){++U.current,W.current?.abort(),b(e=>e+1)}function q(){G.current?.abort();let e=new AbortController;return G.current=e,e}(0,O.useEffect)(()=>()=>G.current?.abort(),[]),(0,O.useEffect)(()=>{let e=++U.current,t=new AbortController;W.current=t;async function n(){try{let[n,i]=await Promise.all([R(`rooms`,t.signal),R(`bots`,t.signal)]);if(U.current!==e||t.signal.aborted)return;let a=Array.isArray(n.rooms)?n.rooms:[];r(a),V(e=>e&&a.some(t=>t.id===e.roomId)?e:null),c(Array.isArray(i.bots)?i.bots:[]),m(``)}catch(n){U.current===e&&!t.signal.aborted&&m(n instanceof Error?n.message:String(n))}finally{U.current===e&&!t.signal.aborted&&f(!1)}}return n(),()=>{t.abort()}},[y]),(0,O.useEffect)(()=>{let e=()=>K();return window.addEventListener(L,e),()=>window.removeEventListener(L,e)},[]);async function J(t){if(t.preventDefault(),!S.trim()||I)return;z(!0),m(``),v(``);let n=q();try{let t=C.includes(T)?T:``,i=await R(`rooms`,n.signal,{name:S.trim(),botIds:C,...t?{primaryBotId:t}:{}});if(n.signal.aborted)return;r(e=>[...e.filter(e=>e.id!==i.room.id),i.room]),x(!1),ne(``),w([]),E(``),v(e(`deviceGroupManagerCreateSuccess`)),window.dispatchEvent(new CustomEvent(L))}catch(e){n.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||z(!1)}}function Y(e){A(e.id),oe(e.name),M([...e.botIds]),se(e.primaryBotId??``),P(null),x(!1),m(``),v(``)}function X(){A(null)}async function Z(t){if(I)return;let i=n.find(e=>e.id===t);if(!i)return;let a=ae.trim();if(!a)return;z(!0),m(``),v(``);let o=q();try{if(a!==i.name&&(await R(`rooms/${encodeURIComponent(t)}/rename`,o.signal,{name:a}),o.signal.aborted))return;let n=j.includes(N)?N:null,s=await R(`rooms/${encodeURIComponent(t)}/members`,o.signal,{botIds:j,primaryBotId:n});if(o.signal.aborted)return;let c={...s.room,name:a};r(e=>e.map(e=>e.id===t?c:e)),X(),v(e(`deviceGroupManagerMembersSaved`)),window.dispatchEvent(new CustomEvent(L))}catch(e){o.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{o.signal.aborted||z(!1)}}async function Q(t){if(!F.trim()||I)return;z(!0),m(``),v(``);let n=q();try{if(await R(`rooms/${encodeURIComponent(t)}/rename`,n.signal,{name:F.trim()}),n.signal.aborted)return;r(e=>e.map(e=>e.id===t?{...e,name:F.trim()}:e)),P(null),v(e(`deviceGroupManagerRenameSuccess`)),window.dispatchEvent(new CustomEvent(L))}catch(e){n.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||z(!1)}}async function fe(t){if(I||!window.confirm(e(`deviceGroupManagerDeleteConfirm`,{name:t.name})))return;z(!0),m(``),v(``);let n=q();try{if(await R(`rooms/${encodeURIComponent(t.id)}/delete`,n.signal,{}),n.signal.aborted)return;V(e=>e?.roomId===t.id?null:e),r(e=>e.filter(e=>e.id!==t.id)),ie===t.id&&X(),ce===t.id&&P(null),v(e(`deviceGroupManagerDeleteSuccess`)),window.dispatchEvent(new CustomEvent(L))}catch(e){n.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||z(!1)}}return(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":e(`deviceGroupManagerTitle`),children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(u,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`h2`,{children:[e(`deviceGroupManagerTitle`),` · `,n.length]}),(0,k.jsx)(`p`,{children:e(`deviceGroupManagerDescription`)})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,k.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:I,onClick:()=>{x(e=>!e),A(null),P(null),ne(``),w([]),E(``)},children:[(0,k.jsx)(s,{"aria-hidden":!0}),e(`deviceGroupManagerCreate`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":e(`deviceGroupManagerRefresh`),onClick:K,children:(0,k.jsx)(i,{})})]})]}),p&&(0,k.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:p}),g&&(0,k.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,k.jsx)(d,{"aria-hidden":!0}),g]}),te&&(0,k.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:J,children:[(0,k.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,k.jsx)(`h3`,{children:e(`deviceGroupManagerCreate`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:I,children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`close`)]})]}),(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:e(`deviceGroupManagerNameLabel`)}),(0,k.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:e(`deviceGroupManagerNamePlaceholder`),onChange:e=>ne(e.target.value),disabled:I,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,k.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:e(`deviceGroupManagerSelectMembers`)}),(0,k.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,k.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:e(`deviceGroupManagerNoBotsCreate`)}):o.map(t=>(0,k.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:C.includes(t.id),disabled:I||!t.enabled,onChange:e=>{w(n=>e.target.checked?[...n,t.id]:n.filter(e=>e!==t.id))}}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:t.name}),(0,k.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[t.online?e(`deviceHubOnline`):e(`deviceHubOffline`),t.enabled?``:e(`deviceGroupManagerDisabledSuffix`)]})]})]},t.id))})]}),C.length>0&&(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:e(`deviceGroupManagerLegacyPrimary`)}),(0,k.jsxs)(`select`,{id:`dg-manager-new-primary`,value:C.includes(T)?T:``,onChange:e=>E(e.target.value),disabled:I,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,k.jsx)(`option`,{value:``,children:e(`deviceGroupManagerNoPrimary`)}),o.filter(e=>C.includes(e.id)).map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:I||!S.trim(),children:[(0,k.jsx)(d,{"aria-hidden":!0}),e(I?`deviceGroupManagerCreating`:`deviceGroupManagerCreateSubmit`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:I,children:e(`cancel`)})]})]}),(()=>{let t=ie;if(!t)return null;let r=n.find(e=>e.id===t);return(0,ue.createPortal)((0,k.jsx)(`div`,{className:`modal-backdrop`,onClick:()=>{I||X()},children:(0,k.jsxs)(`div`,{className:`dc-card device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`${e(`edit`)} · ${r?.name??t}`,onClick:e=>e.stopPropagation(),style:{minWidth:`min(480px, 92vw)`},children:[(0,k.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,k.jsxs)(`h3`,{children:[e(`edit`),` · `,r?.name??t]}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>X(),disabled:I,children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`close`)]})]}),r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-edit-name`,children:e(`deviceGroupManagerNameLabel`)}),(0,k.jsx)(`input`,{id:`dg-manager-edit-name`,type:`text`,maxLength:80,value:ae,onChange:e=>oe(e.target.value),disabled:I,placeholder:e(`deviceGroupManagerRenamePlaceholder`),style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,k.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:e(`deviceGroupManagerSelectMembers`)}),(0,k.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`220px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,k.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:e(`deviceGroupManagerNoBots`)}):o.map(t=>(0,k.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:j.includes(t.id),disabled:I,onChange:e=>{M(n=>e.target.checked?[...n,t.id]:n.filter(e=>e!==t.id))}}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:t.name}),(0,k.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[t.online?e(`deviceHubOnline`):e(`deviceHubOffline`),t.enabled?``:e(`deviceGroupManagerDisabledSuffix`)]})]})]},t.id))})]}),!r.router?.enabled&&(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:e(`deviceGroupManagerLegacyPrimary`)}),(0,k.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:j.includes(N)?N:``,onChange:e=>se(e.target.value),disabled:I,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,k.jsx)(`option`,{value:``,children:e(`deviceGroupManagerNoPrimary`)}),o.filter(e=>j.includes(e.id)).map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:I||!ae.trim(),onClick:()=>void Z(t),children:[(0,k.jsx)(d,{"aria-hidden":!0}),e(I?`saving`:`deviceGroupManagerSaveMembers`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>X(),disabled:I,children:e(`cancel`)})]})]}):(0,k.jsx)(`p`,{role:`status`,children:e(`loading`)})]})}),document.body)})(),l&&(0,k.jsx)(`p`,{role:`status`,children:e(`loading`)}),!l&&n.length===0&&(0,k.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:e(`deviceGroupManagerEmpty`)}),(0,k.jsx)(`div`,{className:`dd-list`,children:n.map(n=>{let r=ce===n.id,i=o.filter(e=>n.botIds.includes(e.id)),s=o.find(e=>e.id===n.primaryBotId);return(0,k.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,k.jsx)(`span`,{className:`dc-device-icon`,children:(0,k.jsx)(u,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,k.jsx)(`strong`,{children:n.name}),(0,k.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,k.jsx)(`span`,{children:e(`deviceGroupManagerBotCount`,{count:n.botIds.length,members:i.length?`: ${i.map(e=>e.name).join(`, `)}`:``})}),n.router?.enabled&&(0,k.jsxs)(`span`,{children:[`AI Router · `,n.router.deviceId,` · `,n.router.model,` · `,n.router.thinkingLevel]}),!n.router?.enabled&&s&&(0,k.jsx)(`span`,{style:{color:`var(--accent)`},children:e(`deviceGroupManagerPrimaryBadge`,{name:s.name})})]})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:e(`deviceGroupManagerOpenChat`),onClick:()=>de(n.id),children:[(0,k.jsx)(_,{"aria-hidden":!0}),e(`deviceGroupManagerOpenChat`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":B?.roomId===n.id&&B.kind===`router`,onClick:()=>V({roomId:n.id,kind:`router`}),children:`AI Router`}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":B?.roomId===n.id&&B.kind===`work`,onClick:()=>V({roomId:n.id,kind:`work`}),children:e(`deviceGroupManagerWorkItems`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,title:e(`edit`),onClick:()=>Y(n),children:[(0,k.jsx)(u,{"aria-hidden":!0}),e(`edit`)]}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,title:e(`deviceGroupManagerRename`),onClick:()=>{r?P(null):(P(n.id),le(n.name))},children:[(0,k.jsx)(a,{"aria-hidden":!0}),e(`deviceGroupManagerRename`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:e(`deviceGroupManagerDelete`),disabled:I,onClick:()=>void fe(n),children:(0,k.jsx)(t,{"aria-hidden":!0})})]}),r&&(0,k.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:e=>{e.preventDefault(),Q(n.id)},children:[(0,k.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:I,value:F,onChange:e=>le(e.target.value),placeholder:e(`deviceGroupManagerRenamePlaceholder`),style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,k.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:I||!F.trim(),children:[(0,k.jsx)(d,{"aria-hidden":!0}),e(`save`)]}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:I,onClick:()=>P(null),children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`cancel`)]})]})]},n.id)})}),H&&B&&(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":e(`deviceGroupManagerSettingsAria`),children:[(0,k.jsxs)(`div`,{className:`dg-heading`,children:[(0,k.jsx)(`h3`,{children:H.name}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(`button`,{type:`button`,className:`dc-button${B.kind===`router`?` is-primary`:``}`,"aria-pressed":B.kind===`router`,onClick:()=>V({roomId:H.id,kind:`router`}),children:`AI Router`}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button${B.kind===`work`?` is-primary`:``}`,"aria-pressed":B.kind===`work`,onClick:()=>V({roomId:H.id,kind:`work`}),children:e(`deviceGroupManagerWorkItems`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>V(null),children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`close`)]})]})]}),B.kind===`router`?(0,k.jsx)(re,{roomId:H.id,router:H.router,disabled:I,onSaved:K},H.id):(0,k.jsx)(D,{roomId:H.id,disabled:I},H.id)]})]})}var V=class extends Error{status;constructor(e,t){super(t),this.status=e}};function H(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function U(){let e=ee(),[t,a]=(0,O.useState)(null),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(!1),[u,d]=(0,O.useState)(!1),[f,p]=(0,O.useState)(!1),h=(0,O.useRef)(0),g=(0,O.useRef)(null);async function _(e,t){if(g.current)return;let n=++h.current,i=new AbortController;g.current=i,s(!0),l(!1);try{let o=await fetch(r(m(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:i.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(h.current!==n||i.signal.aborted)return;if(o.status===403){d(!0),a(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(h.current!==n||i.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);a(e=>e&&{...e,permissions:{supported:!0,screen:s.screen,accessibility:s.accessibility}}),p(!0)}else{if(typeof s?.os!=`string`||typeof s.enabled!=`boolean`||typeof s.environmentEnabled!=`boolean`||typeof s.supported!=`boolean`)throw Error(`Invalid desktop status`);a(s)}}catch{h.current===n&&!i.signal.aborted&&l(!0)}finally{h.current===n&&!i.signal.aborted&&(g.current=null,s(!1))}}return(0,O.useEffect)(()=>(_(`status`),()=>{h.current++,g.current?.abort(),g.current=null}),[]),(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":e(`deviceCenterLocalDesktopTitle`),"aria-busy":o,children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(n,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:e(`deviceCenterLocalDesktopTitle`)}),(0,k.jsx)(`p`,{children:e(`deviceCenterLocalDesktopHint`)})]})]}),u?(0,k.jsx)(`p`,{role:`status`,children:e(`deviceCenterLocalOnly`)}):(0,k.jsxs)(k.Fragment,{children:[t&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{id:`dc-desktop-label`,children:e(`deviceCenterRemoteDesktopEnable`)}),(0,k.jsx)(`p`,{children:e(t.enabled?`deviceCenterRemoteDesktopEnabled`:`deviceCenterRemoteDesktopDisabled`)})]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-toggle${t.enabled?` is-on`:``}`,role:`switch`,"aria-checked":t.enabled,"aria-labelledby":`dc-desktop-label`,disabled:o||t.environmentEnabled||!t.supported&&!t.enabled,onClick:()=>void _(`enable`,{enabled:!t.enabled}),children:(0,k.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!t.supported&&(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteDesktopUnsupported`)}),t.environmentEnabled&&(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteDesktopManaged`)}),t.os===`darwin`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteDesktopPermissionHint`)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||t.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`screen`}),children:e(`deviceCenterGrantScreenRecording`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||t.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`control`}),children:e(`deviceCenterGrantRemoteControl`)})]}),t.permissions?.screen===!0&&(0,k.jsx)(`p`,{children:e(`deviceCenterScreenRecordingGranted`)}),t.permissions?.accessibility===!0&&(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteControlGranted`)}),f&&(0,k.jsx)(`p`,{role:`status`,children:e(`deviceCenterPermissionRequested`)})]})]}),c&&(0,k.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:e(`deviceCenterRemoteDesktopUpdateFailed`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void _(`status`),children:[(0,k.jsx)(i,{"aria-hidden":!0}),e(o?`deviceHubWorking`:`deviceCenterRefreshRemoteDesktop`)]})]})]})}function W({pathCompletions:e=[],plugins:t=[],pluginsEpoch:r=0}){let a=ee(),[s,m]=(0,O.useState)(`devices`),[h,_]=(0,O.useState)(null),[v,y]=(0,O.useState)(``),[b,x]=(0,O.useState)(``),[S,C]=(0,O.useState)(null),[w,re]=(0,O.useState)(Date.now()),[D,A]=(0,O.useState)(null),[j,M]=(0,O.useState)(``),[N,se]=(0,O.useState)(``),[ce,P]=(0,O.useState)(``),[F,le]=(0,O.useState)(!1),ue=(0,O.useRef)(!1),[L,de]=(0,O.useState)(!1),[R,B]=(0,O.useState)(!0),W=(0,O.useRef)(!1),G=(0,O.useRef)(0),K=(0,O.useRef)(new Set),q=(0,O.useRef)(!1),J=(0,O.useRef)(!1),Y=(0,O.useRef)(null),X=(0,O.useRef)(a);X.current=a,(0,O.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&Y.current?.deviceId===t.detail.deviceId&&(_(e=>e&&{...e,remark:t.detail.remark}),Y.current&&(Y.current.remark=t.detail.remark))};return window.addEventListener(`pi-web-ui:device-remark-updated`,e),()=>window.removeEventListener(`pi-web-ui:device-remark-updated`,e)},[]);async function Z(e,t){let n=new AbortController;K.current.add(n);try{return await te(`/api/device-center/${e}`,{body:t,signal:n.signal,errorFor:e=>new V(e.status,e.serverError||X.current(`deviceHubRequestFailed`,{status:e.status}))})}finally{K.current.delete(n)}}function Q(e){return W.current&&G.current===e}function fe(e){return e instanceof V&&e.status===403?(de(!0),X.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:X.current(`deviceHubNetworkError`)}function pe(e){Y.current=e,_(e),J.current||(x(e.name),y(e.hubUrl??``))}async function me(){let e=G.current;try{let t=await Z(`status`);if(!Q(e)||q.current)return;pe(t),se(``),de(!1)}catch(t){Q(e)&&se(fe(t))}finally{Q(e)&&B(!1)}}(0,O.useEffect)(()=>{W.current=!0;let e=!1,t,n=async()=>{await me(),!e&&W.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,W.current=!1,G.current++,clearTimeout(t);for(let e of K.current)e.abort()}},[]),(0,O.useEffect)(()=>{if(!S)return;let e=G.current,t=!1,n,r=setInterval(()=>re(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=S.expiresAt)){try{let n=await Z(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await Z(`status`);if(t||!Q(e))return;J.current=!1,pe(n),C(null),M(``),P(``);return}M(``)}catch(n){!t&&Q(e)&&M(`${X.current(`deviceHubPollError`)} ${fe(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[S]);async function he(){if(q.current)return;let e=H(v.trim());if(!e){M(a(`deviceHubInvalidUrl`));return}if(!b.trim()||b.trim().length>80){M(a(`deviceHubInvalidName`));return}let t=++G.current;q.current=!0,A(`pair`),M(``),P(``),C(null);try{let n=await Z(`pair`,{hubUrl:e,name:b.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!H(n.hubUrl))throw Error(a(`deviceHubPairError`));re(Date.now()),C(n)}catch(e){Q(t)&&M(`${a(`deviceHubPairError`)} ${fe(e)}`)}finally{Q(t)&&(q.current=!1,A(null))}}async function ge(){let e=Y.current;if(!e?.deviceId||q.current)return;let t=++G.current;q.current=!0,A(`permission`),M(``),P(``),pe({...e,allowExecution:!e.allowExecution});try{await Z(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&P(a(`deviceHubSaved`))}catch(n){Q(t)&&(pe(e),M(`${a(`deviceHubPermissionError`)} ${fe(n)}`))}finally{Q(t)&&(q.current=!1,A(null))}}async function _e(){let e=Y.current;if(!e?.deviceId||q.current||!window.confirm(a(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++G.current;q.current=!0,A(`disconnect`),M(``),P(``);try{if(await Z(`disconnect`,{}),!Q(t))return;J.current=!1,pe({name:e.name,allowExecution:!1,connected:!1}),C(null)}catch(e){Q(t)&&M(`${a(`deviceHubDisconnectError`)} ${fe(e)}`)}finally{Q(t)&&(q.current=!1,A(null))}}async function ve(){if(ue.current||D||!$||!h?.hubUrl||!window.confirm(a(`deviceHubConfirmUpgrade`)))return;let e=G.current;ue.current=!0,le(!0),M(``),P(``);try{let t=await Z(`upgrade-hub`,{});if(!t.ok)throw Error(`Hub upgrade was not accepted`);await ie(t.job,{isCurrent:()=>Q(e),poll:async e=>(await Z(`upgrade-hub-status`,{id:e})).job}),Q(e)&&(P(a(`deviceHubUpgradeSuccess`)),await me())}catch(t){Q(e)&&M(t instanceof Error?t.message:a(`deviceHubNetworkError`))}finally{ue.current=!1,Q(e)&&le(!1)}}async function ye(){if(!S)return;let e=G.current;try{await navigator.clipboard.writeText(S.code),Q(e)&&P(a(`deviceHubCopied`))}catch{Q(e)&&M(a(`deviceHubCopyFailed`))}}let $=!!h?.deviceId,be=H($?h?.hubUrl??``:S?.hubUrl??``),xe=Math.max(0,Math.ceil(((S?.expiresAt??0)-w)/1e3)),Se=`${Math.floor(xe/60)}:${String(xe%60).padStart(2,`0`)}`,Ce=be?(0,k.jsxs)(oe,{href:be,children:[(0,k.jsx)(c,{"aria-hidden":!0}),a(`deviceHubOpenHub`)]}):null;return(0,k.jsxs)(`section`,{className:`dc-page`,"aria-label":a(`deviceHubTitle`),children:[(0,k.jsxs)(`header`,{className:`dc-header`,children:[(0,k.jsxs)(`div`,{className:`dc-heading`,children:[(0,k.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,k.jsx)(n,{"aria-hidden":!0}),a(`deviceHubTitle`)]}),(0,k.jsx)(`h1`,{children:a(`deviceHubTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceHubSubtitle`)})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[$&&Ce,(0,k.jsxs)(`span`,{className:`dc-status ${$?h?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,k.jsx)(`span`,{className:`dc-status-dot`}),a($?h?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,k.jsxs)(`div`,{className:`dc-layout`,children:[(0,k.jsx)(`nav`,{className:`dc-sidebar`,"aria-label":a(`deviceCenterNavLabel`),children:[[`devices`,n,a(`deviceCenterNavDevices`)],[`groups`,u,a(`deviceCenterGroupsTitle`)],[`channels`,g,a(`deviceCenterExternalChannelsTitle`)]].map(([e,t,n])=>(0,k.jsxs)(`button`,{type:`button`,className:`dc-nav-item${s===e?` is-active`:``}`,"aria-pressed":s===e,onClick:()=>m(e),children:[(0,k.jsx)(t,{"aria-hidden":!0}),n]},e))}),(0,k.jsxs)(`main`,{className:`dc-content`,children:[R&&(0,k.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubLoading`)]}),(L||N)&&(0,k.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,k.jsx)(`span`,{children:L?a(`deviceHubLocalOnly`):`${a(`deviceHubStatusError`)} ${N}`}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void me(),children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubRetry`)]})]}),j&&!L&&(0,k.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:j}),ce&&(0,k.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,k.jsx)(d,{"aria-hidden":!0}),ce]}),s!==`devices`&&(!$||L)&&(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsx)(`h2`,{children:a(s===`groups`?`deviceCenterGroupsTitle`:`deviceCenterExternalChannelsTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceCenterConnectFirstHint`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button is-primary`,onClick:()=>m(`devices`),children:a(`deviceCenterGoConnectDevice`)})]}),s===`groups`&&$&&!L&&(0,k.jsx)(z,{},`groups:${h?.hubUrl??``}:${h?.deviceId??``}`),s===`channels`&&$&&!L&&(0,k.jsx)(ae,{plugin:t.find(e=>e.id===`superagent`),epoch:r,onManageGroups:()=>m(`groups`)},`channels:${h?.hubUrl??``}:${h?.deviceId??``}`),s===`devices`&&(0,k.jsxs)(k.Fragment,{children:[!$&&(h||L)&&(0,k.jsx)(I,{initialHubUrl:v,onConnect:e=>{if(L){P(a(`deviceHubLocalOnly`));return}J.current=!0,y(e)}}),h&&!L&&!$&&(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(f,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:a(`deviceHubPairTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceHubPairHint`)})]})]}),(0,k.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,k.jsxs)(`li`,{className:S?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,k.jsx)(`span`,{className:`dc-step-number`,children:S&&t===0?(0,k.jsx)(d,{"aria-hidden":!0}):t+1}),(0,k.jsx)(`span`,{children:a(e)})]},e))}),(0,k.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),he()},children:[(0,k.jsxs)(`div`,{className:`dc-field`,children:[(0,k.jsx)(`label`,{htmlFor:`dc-hub-url`,children:a(`deviceHubHubUrl`)}),(0,k.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:a(`deviceHubHubPlaceholder`),value:v,disabled:!!S||!!D,onChange:e=>{J.current=!0,y(e.target.value)}})]}),(0,k.jsxs)(`div`,{className:`dc-field`,children:[(0,k.jsx)(`label`,{htmlFor:`dc-device-name`,children:a(`deviceHubName`)}),(0,k.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:a(`deviceHubNamePlaceholder`),value:b,disabled:!!S||!!D,onChange:e=>{J.current=!0,x(e.target.value)}})]}),!S&&(0,k.jsx)(`div`,{className:`dc-actions`,children:(0,k.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!D,children:[(0,k.jsx)(f,{"aria-hidden":!0}),a(D?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),S&&(0,k.jsxs)(`div`,{className:`dc-pairing`,children:[(0,k.jsx)(`span`,{className:`dc-code-label`,children:a(`deviceHubCode`)}),(0,k.jsxs)(`div`,{className:`dc-code-row`,children:[(0,k.jsx)(`code`,{className:`dc-code`,children:S.code}),(0,k.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":a(`deviceHubCopy`),onClick:()=>void ye(),children:(0,k.jsx)(o,{"aria-hidden":!0})})]}),(0,k.jsx)(`div`,{className:`dc-pair-meta`,children:a(xe?`deviceHubExpires`:`deviceHubExpired`,{time:Se})}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[Ce,(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!D,onClick:()=>{++G.current,C(null),M(``),P(``)},children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubNewCode`)]})]}),xe>0&&(0,k.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubWaiting`)]})]})]}),$&&h&&!L&&(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,k.jsx)(`span`,{className:`dc-device-icon`,children:(0,k.jsx)(n,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:h.remark?.trim()||h.name}),(0,k.jsx)(`p`,{children:h.remark?.trim()?`${h.name} · ${a(`deviceHubDeviceTitle`)}`:a(`deviceHubDeviceTitle`)})]})]}),(0,k.jsxs)(`dl`,{className:`dc-details`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`dt`,{children:a(`deviceHubDeviceId`)}),(0,k.jsx)(`dd`,{children:h.deviceId})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`dt`,{children:a(`deviceHubHubUrl`)}),(0,k.jsx)(`dd`,{children:h.hubUrl})]})]}),(0,k.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:F||!!D,onClick:()=>void ve(),children:[(0,k.jsx)(i,{className:F?`spin`:``,"aria-hidden":!0}),a(F?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&h?.hubUrl&&h.deviceId&&!L&&(0,k.jsx)(T,{hubUrl:h.hubUrl,currentDeviceId:h.deviceId},`directory:${h.hubUrl}:${h.deviceId}`),!L&&(0,k.jsx)(ne,{},`bots:${h?.hubUrl??``}:${h?.deviceId??`unpaired`}`),(0,k.jsx)(U,{}),$&&h&&!L&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(l,{"aria-hidden":!0})}),(0,k.jsx)(`div`,{children:(0,k.jsx)(`h2`,{children:a(`deviceHubPermissions`)})})]}),(0,k.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{id:`dc-permission-label`,children:a(`deviceHubPermissionLabel`)}),(0,k.jsx)(`p`,{id:`dc-permission-hint`,children:a(`deviceHubPermissionHint`)})]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-toggle${h.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":h.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!D,onClick:()=>void ge(),children:(0,k.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,k.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:a(D===`permission`?`deviceHubSaving`:h.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,k.jsx)(E,{hubUrl:h?.hubUrl,deviceId:h?.deviceId,onNotice:P}),(0,k.jsxs)(`details`,{className:`dc-advanced`,children:[(0,k.jsx)(`summary`,{children:a(`deviceHubAdvanced`)}),(0,k.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,k.jsx)(`h3`,{children:a(`deviceHubDisconnect`)}),(0,k.jsx)(`p`,{children:a(`deviceHubDisconnectHint`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!D,onClick:()=>void _e(),children:a(D===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,k.jsxs)(`aside`,{className:`dc-help`,children:[(0,k.jsx)(p,{className:`dc-help-icon`,"aria-hidden":!0}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{children:a(`deviceHubHelpTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceHubHelpText`)})]})]})]})]})]})]})}export{W as DeviceCenter};