pi-web-ui 0.114.0 → 0.114.2

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 (122) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/bin/pi-web-ui.mjs +15 -7
  3. package/dist/server/agent-service.js +190 -65
  4. package/dist/server/attachments.js +48 -2
  5. package/dist/server/canvas/canvas-agent-tool.js +3 -3
  6. package/dist/server/canvas/canvas-cards.js +1 -1
  7. package/dist/server/canvas/canvas-scheduled-task.js +45 -0
  8. package/dist/server/canvas/canvas-validation.js +1 -1
  9. package/dist/server/client-state.js +6 -2
  10. package/dist/server/communicate-tool.js +37 -11
  11. package/dist/server/device-center/connector.js +33 -14
  12. package/dist/server/device-center/hub-page.js +1 -1
  13. package/dist/server/device-center/hub.js +2 -1
  14. package/dist/server/device-center/local-hub.js +92 -0
  15. package/dist/server/device-center/local.js +60 -7
  16. package/dist/server/device-center/path-portal.js +1 -1
  17. package/dist/server/device-center/relay.js +45 -8
  18. package/dist/server/dispatch-domain-handlers.js +1 -0
  19. package/dist/server/dsh/dsh-agent-service.js +5 -1
  20. package/dist/server/durable/durable-event-projector.js +19 -3
  21. package/dist/server/durable/durable-models.js +134 -65
  22. package/dist/server/engine-probe.js +36 -6
  23. package/dist/server/global-loader.js +40 -2
  24. package/dist/server/index.js +56 -32
  25. package/dist/server/model-resolver.js +4 -1
  26. package/dist/server/patch-bash-process.js +125 -0
  27. package/dist/server/plugins.js +26 -2
  28. package/dist/server/preset-fields.js +7 -0
  29. package/dist/server/preset-share.js +1 -0
  30. package/dist/server/prompt-templates.js +106 -0
  31. package/dist/server/protocol-version.js +1 -1
  32. package/dist/server/resolve-global-sdk.js +2 -0
  33. package/dist/server/schedule-agent-tool.js +49 -26
  34. package/dist/server/scheduler-tasks.js +129 -11
  35. package/dist/server/settings-service.js +6 -0
  36. package/dist/server/text-quote.js +9 -0
  37. package/dist/server/tool-manager.js +2 -1
  38. package/dist/server/universal/drivers/claude-code.js +5 -0
  39. package/dist/server/universal/drivers/codex.js +336 -0
  40. package/dist/server/universal/index.js +1 -0
  41. package/dist/server/universal/universal-attachments.js +24 -1
  42. package/dist/server/universal/universal-session.js +42 -18
  43. package/docs/device-center.md +9 -3
  44. package/package.json +2 -2
  45. package/plugins/catalog.json +10 -0
  46. package/web/dist/.build-assets.json +1 -1
  47. package/web/dist/assets/BgTasksModal-BIlQ89vr.js +1 -0
  48. package/web/dist/assets/BgTasksModal-Ck2sjlPM.js +1 -0
  49. package/web/dist/assets/{CanvasStudio-BEJZE5BI.js → CanvasStudio-B3W6b_rA.js} +3 -3
  50. package/web/dist/assets/{CanvasStudio-CgUNHqos.js → CanvasStudio-Csv1Sj1-.js} +3 -3
  51. package/web/dist/assets/DeviceCenter-BQdDcO8A.js +3 -0
  52. package/web/dist/assets/DeviceCenter-CHRKL0Vy.js +3 -0
  53. package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
  54. package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
  55. package/web/dist/assets/FilePreview-B9xoU6ON.js +2 -0
  56. package/web/dist/assets/FilePreview-DUQpVZkH.js +2 -0
  57. package/web/dist/assets/GlobalSearchModal-BXEGvUZq.js +1 -0
  58. package/web/dist/assets/GlobalSearchModal-CnVPmfOI.js +1 -0
  59. package/web/dist/assets/GroupConversation-CyIpQzDd.js +1 -0
  60. package/web/dist/assets/GroupConversation-DgYV3uYS.js +1 -0
  61. package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
  62. package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
  63. package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
  64. package/web/dist/assets/SCMPanel-imYI2Ecw.js +2 -0
  65. package/web/dist/assets/SCMPanel-sVZcV7dR.js +2 -0
  66. package/web/dist/assets/SettingsModal-Xw1Yoi3_.js +20 -0
  67. package/web/dist/assets/SettingsModal-mb4e34-0.js +20 -0
  68. package/web/dist/assets/{TerminalPanel-DL20uKgU.js → TerminalPanel-CLkJJvxg.js} +2 -2
  69. package/web/dist/assets/{TerminalPanel-D6cPRFei.js → TerminalPanel-DpcIellm.js} +2 -2
  70. package/web/dist/assets/TuiOverlayModal-4-fFAZe7.js +1 -0
  71. package/web/dist/assets/TuiOverlayModal-DCu01lks.js +1 -0
  72. package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
  73. package/web/dist/assets/{desktop-DPyTy4M3.js → desktop-YguLbrX1.js} +1 -1
  74. package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
  75. package/web/dist/assets/index-Cdh3sibd.js +85 -0
  76. package/web/dist/assets/index-DDZMv6LO.css +1 -0
  77. package/web/dist/assets/index-DWw_SxRq.js +85 -0
  78. package/web/dist/assets/{plugin-host-CqA4yW6w.js → plugin-host-BRBg6zmQ.js} +1 -1
  79. package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
  80. package/web/dist/index.html +10 -9
  81. package/web/dist/sw.js +1 -1
  82. package/dist/gh-comment-781.md +0 -5
  83. package/dist/server/device-center/local-page.js +0 -17
  84. package/dist/server/device-center/smoke-preview.js +0 -3
  85. package/dist/server/durable/durable-capabilities.js +0 -11
  86. package/dist/server/markers/builtins/services.js +0 -123
  87. package/dist/server/markers/builtins/todo.js +0 -189
  88. package/dist/server/markers-list-tool.js +0 -34
  89. package/dist/server/orchestrator.js +0 -109
  90. package/dist/server/system-prompt-soul.js +0 -41
  91. package/dist/server/univer-service.js +0 -448
  92. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  93. package/dist/test-artifact.md +0 -9
  94. package/dist/test-preview-modal.md +0 -11
  95. package/dist/test-report.html +0 -20
  96. package/web/dist/assets/BgTasksModal-CS7UNzcw.js +0 -1
  97. package/web/dist/assets/BgTasksModal-Dk-tp78W.js +0 -1
  98. package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +0 -3
  99. package/web/dist/assets/DeviceCenter-CVblvhNX.js +0 -3
  100. package/web/dist/assets/Dropdown-Oug0DDte.js +0 -1
  101. package/web/dist/assets/FilePreview-CvdX6nr6.js +0 -2
  102. package/web/dist/assets/FilePreview-kCZhfBAF.js +0 -2
  103. package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +0 -1
  104. package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +0 -1
  105. package/web/dist/assets/GroupConversation-Cgo4xbpa.js +0 -1
  106. package/web/dist/assets/GroupConversation-DZ71jEi8.js +0 -1
  107. package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +0 -2
  108. package/web/dist/assets/PiSetupModal-mkWPSxMj.js +0 -1
  109. package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +0 -1
  110. package/web/dist/assets/SCMPanel-BP1TUT-V.js +0 -2
  111. package/web/dist/assets/SCMPanel-BscPm9kf.js +0 -2
  112. package/web/dist/assets/SettingsModal-C8UgMjVM.js +0 -20
  113. package/web/dist/assets/SettingsModal-VynB7jNb.js +0 -20
  114. package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +0 -1
  115. package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +0 -1
  116. package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +0 -1
  117. package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +0 -1
  118. package/web/dist/assets/app-globals-CnO6KlEM.js +0 -325
  119. package/web/dist/assets/index-CPgAH5q7.js +0 -83
  120. package/web/dist/assets/index-Cje8iugL.js +0 -83
  121. package/web/dist/assets/index-DnKeiDbj.css +0 -1
  122. package/web/dist/assets/theme-BqdAjEjF.js +0 -1
@@ -1,379 +0,0 @@
1
- /**
2
- * dsh-driver.ts — DeepSeek Harness (DSH) 引擎驱动实现(基于 Universal Agent 底座)。
3
- *
4
- * 通过 stdio JSON-RPC 与 DSH 运行时子进程通信,将 DSH 的事件流、思考过程、工具调用与
5
- * 统计信息完整映射到 Universal 底座的 AgentEventSink。
6
- *
7
- * 特性:
8
- * 1. 原生流式 Thinking 与正文增量(reasoning-delta / text-delta);
9
- * 2. 工具调用生命周期(tool/call → onToolStart, tool/result → onToolEnd);
10
- * 3. 自动计算 Token 用量与缓存命中率(normalizeDshUsage);
11
- * 4. 人在回路问卷提问桥(question.pending ↔ onAskUser);
12
- * 5. 全量接入公共模型底座(models.json 自定义端点与多密钥动态注入);
13
- * 6. 强杀中断与自愈恢复(abort → runtime.kill)。
14
- */
15
- import { randomUUID } from "node:crypto";
16
- import { homedir } from "node:os";
17
- import { join } from "node:path";
18
- import { BaseAgentDriver } from "../driver-base.js";
19
- import { DshRuntime } from "../../dsh/dsh-client.js";
20
- import { normalizeDshUsage } from "../../dsh/dsh-usage.js";
21
- import { listCustomModelsFromConfig } from "../../model-resolver.js";
22
- import { discoverDiskSkills } from "../../skill-discovery.js";
23
- const DEFAULT_MODEL = "deepseek-v4-flash";
24
- const DSH_OFFICIAL_MODELS = [
25
- { id: "deepseek-v4-flash", name: "DeepSeek V4 Flash", provider: "deepseek", vision: false },
26
- { id: "deepseek-v4-pro", name: "DeepSeek V4 Pro", provider: "deepseek", vision: false },
27
- {
28
- id: "deepseek-v4-flash-vision-exp",
29
- name: "DeepSeek V4 Flash Vision (exp)",
30
- provider: "deepseek",
31
- vision: true,
32
- },
33
- ];
34
- export class DshAgentDriver extends BaseAgentDriver {
35
- id = "dsh";
36
- name = "DeepSeek Harness";
37
- capabilities = {
38
- supportsTreeFork: false,
39
- supportsHistoryEdit: false,
40
- supportsToolPromptOverride: false,
41
- supportsModelSwitch: true,
42
- supportsThinkingLevels: true,
43
- supportsAskUser: true,
44
- };
45
- agentDir;
46
- dataDir;
47
- sessionRoot;
48
- currentModel;
49
- currentProvider;
50
- activeSessionId = null;
51
- runtime;
52
- activeSink = null;
53
- turnCompleteEmitted = false;
54
- constructor(cwd, opts) {
55
- super(cwd);
56
- this.agentDir = opts?.agentDir || process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
57
- this.dataDir = opts?.dataDir || process.env.PI_WEB_DATA_DIR || join(homedir(), ".pi-web");
58
- this.sessionRoot = opts?.sessionRoot;
59
- this.currentModel = opts?.defaultModel ?? DEFAULT_MODEL;
60
- this.currentProvider = opts?.defaultProvider ?? "deepseek";
61
- if (opts?.runtime) {
62
- this.runtime = opts.runtime;
63
- }
64
- else {
65
- this.runtime = new DshRuntime({
66
- cwd: this.cwd,
67
- provider: "deepseek-official",
68
- model: this.currentModel,
69
- modelProvider: this.currentProvider,
70
- sessionRoot: this.sessionRoot,
71
- dataDir: this.dataDir,
72
- agentDir: this.agentDir,
73
- });
74
- }
75
- this.setupNotificationHandler();
76
- }
77
- async createSession() {
78
- const sessionId = `web-${randomUUID().slice(0, 12)}`;
79
- this.activeSessionId = sessionId;
80
- return sessionId;
81
- }
82
- async resumeSession(sessionId) {
83
- this.activeSessionId = sessionId;
84
- }
85
- getActiveSessionId() {
86
- return this.activeSessionId;
87
- }
88
- getSupportedThinkingLevels() {
89
- return ["high"];
90
- }
91
- /** 绑定运行时通知事件分发到 Universal 底座的 sink */
92
- setupNotificationHandler() {
93
- this.runtime.onNotification((method, params) => {
94
- const sink = this.activeSink;
95
- if (!sink || typeof params !== "object" || params === null)
96
- return;
97
- const p = params;
98
- if (method === "session.event") {
99
- const event = p.event;
100
- if (!event)
101
- return;
102
- const type = String(event.type ?? "");
103
- const data = (event.data ?? {});
104
- switch (type) {
105
- case "assistant/chunk": {
106
- const chunk = (data.chunk ?? {});
107
- const chunkType = String(chunk.type ?? "");
108
- if (chunkType === "reasoning-delta" && chunk.text) {
109
- sink.onThinkingDelta(String(chunk.text));
110
- }
111
- else if (chunkType === "text-delta" && chunk.text) {
112
- sink.onTextDelta(String(chunk.text));
113
- }
114
- break;
115
- }
116
- case "tool/call": {
117
- const callId = String(data.id ?? `call_${Date.now()}`);
118
- const toolName = String(data.name ?? "unknown");
119
- const args = (data.args ?? {});
120
- sink.onToolStart(callId, toolName, args);
121
- break;
122
- }
123
- case "tool/result": {
124
- const message = (data.message ?? {});
125
- const contentList = Array.isArray(message.content) ? message.content : [];
126
- const tr = contentList.find((b) => b?.type === "tool-result");
127
- const callId = String(tr?.toolCallId ?? data.id ?? "");
128
- const isError = Boolean(tr?.isError ?? data.isError);
129
- const rawText = Array.isArray(tr?.content)
130
- ? tr.content.map((c) => c?.text ?? "").join("\n")
131
- : String(data.result ?? "");
132
- sink.onToolEnd(callId, {
133
- output: isError ? undefined : rawText,
134
- error: isError ? rawText : undefined,
135
- });
136
- break;
137
- }
138
- case "assistant/message": {
139
- const message = (data.message ?? {});
140
- const usage = message.usage ? normalizeDshUsage(message.usage) : null;
141
- const meta = {
142
- model: this.currentModel,
143
- usage: usage
144
- ? {
145
- inputTokens: usage.input,
146
- outputTokens: usage.output,
147
- cacheReadTokens: usage.cacheRead,
148
- cacheWriteTokens: usage.cacheWrite,
149
- }
150
- : undefined,
151
- };
152
- if (!this.turnCompleteEmitted) {
153
- this.turnCompleteEmitted = true;
154
- sink.onTurnComplete(meta);
155
- }
156
- break;
157
- }
158
- }
159
- }
160
- else if (method === "question.pending") {
161
- if (sink.onAskUser && p.id && typeof p.question === "string") {
162
- const qId = String(p.id);
163
- const qText = String(p.question);
164
- const options = Array.isArray(p.options)
165
- ? p.options
166
- : undefined;
167
- sink
168
- .onAskUser(qId, qText, options)
169
- .then((answers) => {
170
- return this.runtime.answerQuestion(qId, [
171
- { id: qId, selected: answers.selected, custom: answers.custom },
172
- ]);
173
- })
174
- .catch(() => {
175
- return this.runtime.answerQuestion(qId, [], true);
176
- });
177
- }
178
- }
179
- else if (method === "session.status") {
180
- if (p.status === "idle" && !this.turnCompleteEmitted) {
181
- this.turnCompleteEmitted = true;
182
- sink.onTurnComplete({ model: this.currentModel });
183
- }
184
- }
185
- });
186
- }
187
- async sendPrompt(prompt, attachments, sink) {
188
- this.activeSink = sink;
189
- this.turnCompleteEmitted = false;
190
- if (!this.activeSessionId) {
191
- await this.createSession();
192
- }
193
- const sessionId = this.activeSessionId;
194
- await this.runtime.start();
195
- // 构建 contentBlocks
196
- const contentBlocks = [];
197
- // 处理图片和文件附件
198
- if (attachments && attachments.length > 0) {
199
- for (const att of attachments) {
200
- if (att.imageData) {
201
- try {
202
- const name = att.name || "image.png";
203
- const mime = name.endsWith(".png")
204
- ? "image/png"
205
- : name.endsWith(".gif")
206
- ? "image/gif"
207
- : name.endsWith(".webp")
208
- ? "image/webp"
209
- : "image/jpeg";
210
- const res = await this.runtime.attachmentSave(mime, att.imageData, name);
211
- if (res.ref) {
212
- contentBlocks.push({ type: "image", attachmentRef: res.ref });
213
- }
214
- }
215
- catch {
216
- /* 回落内联 */
217
- }
218
- }
219
- else if (att.path) {
220
- contentBlocks.push({
221
- type: "text",
222
- text: `[Attachment: ${att.name || att.path}]\n${att.path}`,
223
- });
224
- }
225
- }
226
- }
227
- contentBlocks.push({ type: "text", text: prompt });
228
- let turnDoneResolve;
229
- const turnPromise = new Promise((resolve) => {
230
- turnDoneResolve = resolve;
231
- });
232
- // 代理 sink 以获知完成时点
233
- const wrappedSink = {
234
- onTextDelta: (d) => sink.onTextDelta(d),
235
- onThinkingDelta: (d) => sink.onThinkingDelta(d),
236
- onToolStart: (id, name, args) => sink.onToolStart(id, name, args),
237
- onToolUpdate: (id, out) => sink.onToolUpdate?.(id, out),
238
- onToolEnd: (id, res) => sink.onToolEnd(id, res),
239
- onAskUser: sink.onAskUser ? (id, q, opts) => sink.onAskUser(id, q, opts) : undefined,
240
- onTurnComplete: (meta) => {
241
- sink.onTurnComplete(meta);
242
- turnDoneResolve();
243
- },
244
- onError: (err) => {
245
- sink.onError(err);
246
- turnDoneResolve();
247
- },
248
- };
249
- this.activeSink = wrappedSink;
250
- try {
251
- await this.runtime.prompt(sessionId, contentBlocks);
252
- await turnPromise;
253
- }
254
- catch (err) {
255
- wrappedSink.onError(err instanceof Error ? err : new Error(String(err)));
256
- }
257
- finally {
258
- this.activeSink = null;
259
- }
260
- }
261
- async abort() {
262
- await this.runtime.kill();
263
- }
264
- async listModels() {
265
- const official = DSH_OFFICIAL_MODELS.map((m) => ({
266
- id: `deepseek/${m.id}`,
267
- name: m.name,
268
- }));
269
- let dynamic = [];
270
- try {
271
- if (this.runtime.alive) {
272
- const res = await this.runtime.listModels();
273
- dynamic = (res.models ?? []).map((m) => ({
274
- id: m.id.includes("/") ? m.id : `deepseek/${m.id}`,
275
- name: m.name || m.id,
276
- }));
277
- }
278
- }
279
- catch {
280
- /* ignore */
281
- }
282
- let custom = [];
283
- try {
284
- const customList = listCustomModelsFromConfig(this.agentDir);
285
- custom = customList.map((c) => ({
286
- id: `${c.providerId}/${c.modelId}`,
287
- name: c.name,
288
- }));
289
- }
290
- catch {
291
- /* ignore */
292
- }
293
- const seen = new Set();
294
- const result = [];
295
- for (const m of [...official, ...dynamic, ...custom]) {
296
- if (!seen.has(m.id)) {
297
- seen.add(m.id);
298
- result.push(m);
299
- }
300
- }
301
- return result;
302
- }
303
- async setModel(modelId) {
304
- const normId = modelId.trim();
305
- const hasSlash = normId.includes("/");
306
- const targetProvider = hasSlash ? normId.slice(0, normId.indexOf("/")) : "deepseek";
307
- const bareModelId = hasSlash ? normId.slice(normId.indexOf("/") + 1) : normId;
308
- this.currentModel = bareModelId;
309
- this.currentProvider = targetProvider;
310
- await this.runtime.restart(bareModelId, targetProvider);
311
- }
312
- async getSlashCommands() {
313
- return [
314
- {
315
- name: "skills",
316
- description: "查看 DeepSeek Harness 运行时与磁盘技能列表",
317
- descriptionEn: "List DeepSeek Harness runtime and disk skills",
318
- source: "extension",
319
- },
320
- {
321
- name: "clear",
322
- description: "重置 DSH 会话上下文",
323
- descriptionEn: "Reset DSH session context",
324
- source: "extension",
325
- },
326
- ];
327
- }
328
- async execSlashCommand(name, _args, context) {
329
- switch (name) {
330
- case "skills": {
331
- const skills = await this.getSkills();
332
- const summary = skills.length > 0
333
- ? `DSH 可用技能 (${skills.length}):${skills.map((s) => s.name).join(", ")}`
334
- : "DSH 当前无可用技能";
335
- const summaryEn = skills.length > 0
336
- ? `DSH skills (${skills.length}): ${skills.map((s) => s.name).join(", ")}`
337
- : "No DSH skills available";
338
- context?.emitNotice?.("info", summary, summaryEn);
339
- return true;
340
- }
341
- case "clear": {
342
- await this.createSession();
343
- context?.emitNotice?.("info", "DSH 会话上下文已重置", "DSH session context reset");
344
- return true;
345
- }
346
- default:
347
- return false;
348
- }
349
- }
350
- async getSkills() {
351
- const diskSkills = discoverDiskSkills({ cwd: this.cwd, agentDir: this.agentDir });
352
- const out = diskSkills.map((s) => ({
353
- name: s.name,
354
- description: s.description,
355
- filePath: s.filePath,
356
- }));
357
- try {
358
- if (this.runtime.alive) {
359
- const rpcSkills = await this.runtime.listSkills();
360
- for (const s of rpcSkills.skills ?? []) {
361
- if (!out.some((x) => x.name === s.name)) {
362
- out.push({
363
- name: s.name,
364
- description: s.description,
365
- filePath: "",
366
- });
367
- }
368
- }
369
- }
370
- }
371
- catch {
372
- /* ignore runtime error */
373
- }
374
- return out;
375
- }
376
- dispose() {
377
- void this.runtime.close();
378
- }
379
- }
@@ -1,9 +0,0 @@
1
- # 测试文件:验证远程直接访问与新标签页打开能力
2
-
3
- 这是一份由测试生成的文档:
4
- - **测试时间**:2025-05-18
5
- - **服务状态**:已支持纯 Web 原生化文件直连
6
- - **测试项目**:
7
- 1. 普通 Markdown 文件链接
8
- 2. HTML 报告测试
9
- 3. present_files 工具卡片在远程与本地下的按钮适配
@@ -1,11 +0,0 @@
1
- # 验证预览弹窗与下载功能
2
-
3
- 这是一份测试产物,用于验证在对话中点击链接直接打开内置预览弹窗,并从弹窗顶栏下载文件:
4
-
5
- - **测试项目**:
6
- 1. 对话正文普通链接直接唤起预览弹窗
7
- 2. 弹窗顶栏新增的「下载文件」按钮
8
- 3. 复制内容与全屏等其他工具栏交互
9
-
10
- 文件生成时间:2025-05-18
11
- 环境:pi-web-ui 远程/本地自适应环境
@@ -1,20 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="zh-CN">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>远程 HTML 报告测试</title>
6
- <style>
7
- body { font-family: sans-serif; padding: 2rem; background: #0f172a; color: #f8fafc; }
8
- .card { background: #1e293b; padding: 1.5rem; border-radius: 8px; border: 1px solid #334155; }
9
- h1 { color: #38bdf8; }
10
- button { background: #38bdf8; color: #0f172a; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-weight: bold; }
11
- </style>
12
- </head>
13
- <body>
14
- <div class="card">
15
- <h1>🎉 远程 HTML 报告沙箱正常运行!</h1>
16
- <p>这是一个能够完全在沙箱中交互并独立打开的 HTML 页面。</p>
17
- <button onclick="alert('JS 在沙箱中正常触发!')">点击测试 JavaScript 交互</button>
18
- </div>
19
- </body>
20
- </html>
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Gt as t,Tt as n,cn as r,g as i,hn as a,m as o,on as s,rn as c,t as l}from"./app-globals-CnO6KlEM.js";import{i as u,t as d}from"./react-CR5VJ85Q.js";import{J as f,Mt as p,kt as m,xt as h}from"./index-Cje8iugL.js";var g=e(u(),1),_=d();function v(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 y({servers:e,onClose:u,plugins:d=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=i(),{locale:w}=o(),[T,E]=(0,g.useState)(new Set),D=e=>E(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});(0,g.useEffect)(()=>{l({type:`list_bg_servers`})},[]);let O=(0,g.useMemo)(()=>(m(p(d),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[d,w,C]);return(0,_.jsxs)(h,{className:`bg-task-modal`,onClose:u,showCloseButton:!1,children:[(0,_.jsxs)(`div`,{className:`bg-task-head`,children:[(0,_.jsxs)(`span`,{className:`bg-task-title`,children:[(0,_.jsx)(n,{}),` `,C(`bgTasks`),e.length>0&&(0,_.jsx)(`em`,{className:`bg-task-count`,children:e.length})]}),(0,_.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`bgTaskRefresh`),onClick:()=>l({type:`list_bg_servers`}),children:(0,_.jsx)(t,{})}),(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`close`),onClick:u,children:(0,_.jsx)(a,{})})]})]}),e.length===0?(0,_.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,_.jsx)(n,{}),(0,_.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,_.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):(0,_.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let t=!!e.taskId,n=e.taskId??String(e.port);return(0,_.jsxs)(`li`,{className:`bg-task-item`,children:[(0,_.jsx)(`span`,{className:`bg-task-icon`,title:t?e.plugin:C(`bgTaskPort`)}),(0,_.jsxs)(`div`,{className:`bg-task-info`,children:[(0,_.jsxs)(`div`,{className:`bg-task-line1`,children:[t?(0,_.jsxs)(`span`,{className:`bg-task-port`,title:e.taskId,children:[`🧩 `,e.plugin]}):(0,_.jsxs)(`span`,{className:`bg-task-port`,children:[`:`,e.port]}),e.name&&(0,_.jsx)(`span`,{className:`bg-task-name`,children:e.name})]}),(0,_.jsxs)(`div`,{className:`bg-task-line2`,children:[!t&&(0,_.jsxs)(`span`,{children:[C(`bgTaskPid`),` `,e.pid]}),(0,_.jsxs)(`span`,{children:[C(`bgTaskSince`),` `,v(e.since,C)]}),t&&e.status&&(0,_.jsx)(`span`,{className:`bg-task-status`,children:e.status})]}),e.command&&(0,_.jsxs)(`button`,{type:`button`,className:`bg-task-cmd ${T.has(n)?`open`:``}`,title:`${C(`bgTaskCommand`)}: ${e.command}`,onClick:()=>D(n),children:[(0,_.jsx)(s,{}),(0,_.jsx)(`code`,{children:e.command})]})]}),!t&&(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>l({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:e.keep?`📌`:`📍`}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,title:C(`bgTaskStop`),onClick:()=>l(t?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,_.jsx)(c,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStop`)})]})]},n)})}),O.map(e=>{let t=d.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,_.jsx)(`div`,{children:(0,_.jsx)(f,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,_.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)}),(0,_.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,_.jsxs)(`div`,{className:`bg-task-cleanup-bar`,children:[(0,_.jsxs)(`label`,{className:`bg-task-cleanup-field`,title:C(`bgTaskCleanupHint`),children:[(0,_.jsx)(`span`,{className:`bg-task-cleanup-label`,children:C(`bgTaskCleanup`)}),(0,_.jsxs)(`select`,{className:`bg-task-cleanup-select`,value:String(S),onChange:e=>l({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,_.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,_.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-clean-btn`,title:C(`bgTaskCleanNowHint`),onClick:()=>l({type:`clean_bg_leftovers`}),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`span`,{children:C(`bgTaskCleanNow`)})]})]}),(0,_.jsxs)(`div`,{className:`bg-task-actions-bar`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-refresh-btn`,title:C(`bgTaskRefresh`),onClick:()=>l({type:`list_bg_servers`}),children:[(0,_.jsx)(t,{}),(0,_.jsx)(`span`,{children:C(`bgTaskRefresh`)})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>l({type:`kill_background_servers`}),children:[(0,_.jsx)(c,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStopAll`)})]})]})]})]})}export{y as BgTasksModal};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Gt as t,Tt as n,cn as r,g as i,hn as a,m as o,on as s,rn as c,t as l}from"./app-globals-CnO6KlEM.js";import{i as u,t as d}from"./react-CR5VJ85Q.js";import{J as f,Mt as p,kt as m,xt as h}from"./index-CPgAH5q7.js";var g=e(u(),1),_=d();function v(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 y({servers:e,onClose:u,plugins:d=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=i(),{locale:w}=o(),[T,E]=(0,g.useState)(new Set),D=e=>E(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});(0,g.useEffect)(()=>{l({type:`list_bg_servers`})},[]);let O=(0,g.useMemo)(()=>(m(p(d),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[d,w,C]);return(0,_.jsxs)(h,{className:`bg-task-modal`,onClose:u,showCloseButton:!1,children:[(0,_.jsxs)(`div`,{className:`bg-task-head`,children:[(0,_.jsxs)(`span`,{className:`bg-task-title`,children:[(0,_.jsx)(n,{}),` `,C(`bgTasks`),e.length>0&&(0,_.jsx)(`em`,{className:`bg-task-count`,children:e.length})]}),(0,_.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`bgTaskRefresh`),onClick:()=>l({type:`list_bg_servers`}),children:(0,_.jsx)(t,{})}),(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`close`),onClick:u,children:(0,_.jsx)(a,{})})]})]}),e.length===0?(0,_.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,_.jsx)(n,{}),(0,_.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,_.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):(0,_.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let t=!!e.taskId,n=e.taskId??String(e.port);return(0,_.jsxs)(`li`,{className:`bg-task-item`,children:[(0,_.jsx)(`span`,{className:`bg-task-icon`,title:t?e.plugin:C(`bgTaskPort`)}),(0,_.jsxs)(`div`,{className:`bg-task-info`,children:[(0,_.jsxs)(`div`,{className:`bg-task-line1`,children:[t?(0,_.jsxs)(`span`,{className:`bg-task-port`,title:e.taskId,children:[`🧩 `,e.plugin]}):(0,_.jsxs)(`span`,{className:`bg-task-port`,children:[`:`,e.port]}),e.name&&(0,_.jsx)(`span`,{className:`bg-task-name`,children:e.name})]}),(0,_.jsxs)(`div`,{className:`bg-task-line2`,children:[!t&&(0,_.jsxs)(`span`,{children:[C(`bgTaskPid`),` `,e.pid]}),(0,_.jsxs)(`span`,{children:[C(`bgTaskSince`),` `,v(e.since,C)]}),t&&e.status&&(0,_.jsx)(`span`,{className:`bg-task-status`,children:e.status})]}),e.command&&(0,_.jsxs)(`button`,{type:`button`,className:`bg-task-cmd ${T.has(n)?`open`:``}`,title:`${C(`bgTaskCommand`)}: ${e.command}`,onClick:()=>D(n),children:[(0,_.jsx)(s,{}),(0,_.jsx)(`code`,{children:e.command})]})]}),!t&&(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>l({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:e.keep?`📌`:`📍`}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,title:C(`bgTaskStop`),onClick:()=>l(t?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,_.jsx)(c,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStop`)})]})]},n)})}),O.map(e=>{let t=d.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,_.jsx)(`div`,{children:(0,_.jsx)(f,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,_.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)}),(0,_.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,_.jsxs)(`div`,{className:`bg-task-cleanup-bar`,children:[(0,_.jsxs)(`label`,{className:`bg-task-cleanup-field`,title:C(`bgTaskCleanupHint`),children:[(0,_.jsx)(`span`,{className:`bg-task-cleanup-label`,children:C(`bgTaskCleanup`)}),(0,_.jsxs)(`select`,{className:`bg-task-cleanup-select`,value:String(S),onChange:e=>l({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,_.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,_.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-clean-btn`,title:C(`bgTaskCleanNowHint`),onClick:()=>l({type:`clean_bg_leftovers`}),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`span`,{children:C(`bgTaskCleanNow`)})]})]}),(0,_.jsxs)(`div`,{className:`bg-task-actions-bar`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-refresh-btn`,title:C(`bgTaskRefresh`),onClick:()=>l({type:`list_bg_servers`}),children:[(0,_.jsx)(t,{}),(0,_.jsx)(`span`,{children:C(`bgTaskRefresh`)})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>l({type:`kill_background_servers`}),children:[(0,_.jsx)(c,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStopAll`)})]})]})]})]})}export{y as BgTasksModal};
@@ -1,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,Gt as n,L as r,Pt as i,Wt as a,Y as o,bt as s,en as c,g as l,h as u,m as d,ot as f,pn as p,x as m,xn as h,y as g,zt as _}from"./app-globals-CnO6KlEM.js";import{i as v,r as y,t as b}from"./react-CR5VJ85Q.js";import{L as x,T as S}from"./index-CPgAH5q7.js";import{t as C}from"./UniversalPathPicker-DwxwNcFw.js";var w=e(v(),1),T=b(),E={zh:{groups:`群聊`,manage:`管理成员`,save:`保存成员`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`},en:{groups:`Groups`,manage:`Manage members`,save:`Save members`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`}},D=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function O(e,t,n){let r=await fetch(m(h(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new D(r.status,i.code??``,typeof i.error==`string`?i.error:String(r.status));return i}function k(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function A({active:e=!0,navigation:t}){let{locale:n}=d(),r=E[g(n)?`zh`:`en`],[o,s]=(0,w.useState)([]),[c,l]=(0,w.useState)([]),[u,f]=(0,w.useState)(``),[m,h]=(0,w.useState)(null),[v,y]=(0,w.useState)(!0),[b,x]=(0,w.useState)(``),[S,C]=(0,w.useState)(!1),[A,j]=(0,w.useState)(!1),[M,N]=(0,w.useState)(``),[P,F]=(0,w.useState)([]),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(0),B=(0,w.useRef)(null),V=(0,w.useRef)(void 0),H=(0,w.useRef)(0),U=(0,w.useRef)(null),W=(0,w.useRef)(r);W.current=r;function G(e){let t=W.current;if(e instanceof D){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function K(){U.current?.abort(),U.current=null,L(!1)}function ee(e,t=!1){++H.current,K(),f(e),h(null),C(!1),j(t),B.current=t?e:null,F([]),y(!0),x(``),z(e=>e+1)}function q(){++H.current,K(),C(!0),j(!1),B.current=null,h(null),F([]),N(``),x(``),z(e=>e+1)}(0,w.useEffect)(()=>{let t=++H.current,n=null,r=!1,i=()=>H.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([O(`bots`,t.signal),O(`rooms`,t.signal),A&&u?O(`rooms/${encodeURIComponent(u)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;s(e.bots),l(n.rooms),h(r),r&&B.current===r.room.id&&(B.current=null,F(r.room.botIds)),x(``)}catch(e){i()&&!t.signal.aborted&&x(G(e))}finally{t.abort(),r=!1,i()&&y(!1)}}a();let o=window.setInterval(()=>void a(),3e3),c=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,c),()=>{++H.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,c)}},[e,u,A,R]),(0,w.useEffect)(()=>()=>U.current?.abort(),[]),(0,w.useEffect)(()=>{e||K()},[e]),(0,w.useEffect)(()=>{e&&t&&t.revision!==V.current&&(V.current=t.revision,t.create?q():t.roomId&&ee(t.roomId,t.manage))},[e,t?.revision]);async function J(){if(!e||U.current||(S?!M.trim():!m))return;let t=new AbortController;U.current=t,L(!0),x(``);let n=S,r=m?.room.id;try{let{room:e}=await O(n?`rooms`:`rooms/${encodeURIComponent(r)}/members`,t.signal,n?{name:M.trim(),botIds:P}:{botIds:P});if(t.signal.aborted||U.current!==t)return;l(t=>[...t.filter(t=>t.id!==e.id),e]),f(e.id),h({room:e}),C(!1),j(!1),N(``),F([]),z(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),n&&k(e.id)}catch(e){!t.signal.aborted&&U.current===t&&x(G(e))}finally{U.current===t&&(U.current=null,L(!1))}}let Y=c.find(e=>e.id===u);return(0,T.jsxs)(`section`,{className:`dg-root`,"aria-label":r.groups,children:[(0,T.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsxs)(`h2`,{children:[(0,T.jsx)(p,{}),` `,r.groups]}),(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:q,children:[(0,T.jsx)(a,{}),` `,r.create]})]}),(0,T.jsx)(`div`,{className:`dg-rooms`,children:c.map(t=>(0,T.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":t.id===u?`page`:void 0,disabled:!e,onClick:()=>{ee(t.id),k(t.id)},children:[(0,T.jsx)(i,{}),` `,t.name]},t.id))}),!v&&!c.length&&(0,T.jsx)(`p`,{className:`dg-empty`,children:r.empty})]}),(0,T.jsxs)(`div`,{className:`dc-card dg-chat`,children:[b&&(0,T.jsx)(`p`,{className:`dc-error`,role:`alert`,children:b}),v&&(0,T.jsx)(`p`,{role:`status`,children:r.loading}),S||A?(0,T.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),J()},children:[(0,T.jsx)(`h2`,{children:S?r.create:r.manage}),S&&(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`device-group-name`,children:r.name}),(0,T.jsx)(`input`,{id:`device-group-name`,value:M,onChange:e=>N(e.target.value),disabled:I||!e})]}),(0,T.jsxs)(`fieldset`,{disabled:I||!e||A&&!m,children:[(0,T.jsx)(`legend`,{children:r.devices}),o.map(e=>(0,T.jsxs)(`label`,{className:`dg-device`,children:[(0,T.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!P.includes(e.id),checked:P.includes(e.id),onChange:t=>F(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,T.jsx)(_,{}),(0,T.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?r.online:r.offline]})]},e.id))]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:I||!e||(S?!M.trim():!m),children:S?r.create:r.save}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{K(),B.current=null,C(!1),j(!1),x(``)},children:r.cancel})]})]}):Y?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`dg-title`,children:(0,T.jsxs)(`h2`,{children:[(0,T.jsx)(p,{}),` `,Y.name]})}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>k(Y.id),children:[(0,T.jsx)(i,{}),r.open]}),(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>ee(Y.id,!0),children:[(0,T.jsx)(p,{}),r.manage]})]})]}):(0,T.jsx)(`p`,{className:`dg-empty`,children:r.choose})]})]})}var j=y();function M(e,t){let n=e.trim().replace(/\\/g,`/`);if(!n)return``;let r=/^(?:[a-z]:\/|\/)/i.test(n)?n:`${t.replace(/\\/g,`/`).replace(/\/$/,``)}/${n}`,i=r.match(/^(?:[a-z]:\/|\/\/[^/]+\/[^/]+\/?|\/)/i)?.[0];if(!i)return n;let a=[];for(let e of r.slice(i.length).split(`/`))e===`..`?a.pop():e&&e!==`.`&&a.push(e);return i.replace(/\/$/,``)+`/`+a.join(`/`)}function N({title:e,entries:t,selected:n,onChange:r,disabled:i,pending:a}){let o=l(),s=(0,w.useId)(),[c,u]=(0,w.useState)(``),d=new Set(t.map(e=>e.id)),f=n.filter(e=>!d.has(e)),p=[...t,...f.map(e=>({id:e,name:e}))],m=c.trim().toLowerCase(),h=p.filter(e=>[e.name,e.id,e.description,e.path].some(e=>e?.toLowerCase().includes(m))),g=h.filter(e=>d.has(e.id)&&e.status!==`disabled`);return(0,T.jsxs)(`fieldset`,{className:`dc-bot-catalog`,disabled:i,children:[(0,T.jsxs)(`legend`,{children:[e,` `,(0,T.jsxs)(`span`,{className:`dc-bot-count`,children:[n.length,` `,o(`localBotSelected`)]})]}),(0,T.jsxs)(`div`,{className:`dc-bot-catalog-actions`,children:[(0,T.jsx)(`input`,{type:`search`,"aria-label":`${o(`localBotSearch`)} ${e}`,placeholder:o(`localBotSearch`),value:c,onChange:e=>u(e.target.value)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||!g.length,onClick:()=>r([...new Set([...n,...g.map(e=>e.id)])]),children:o(m?`localBotSelectVisible`:`localBotSelectAll`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:!n.length,onClick:()=>r([]),children:o(`localBotClear`)})]}),(0,T.jsxs)(`div`,{className:`dc-bot-catalog-list`,children:[h.map((e,t)=>(0,T.jsxs)(`label`,{className:`dc-bot-option`,htmlFor:`${s}-${t}`,children:[(0,T.jsx)(`input`,{id:`${s}-${t}`,type:`checkbox`,checked:n.includes(e.id),disabled:e.status===`disabled`&&!n.includes(e.id),onChange:t=>r(t.target.checked?[...new Set([...n,e.id])]:n.filter(t=>t!==e.id))}),(0,T.jsxs)(`span`,{children:[(0,T.jsx)(`strong`,{children:e.name}),!d.has(e.id)&&(0,T.jsx)(`small`,{children:o(a?`localBotUnverified`:`localBotUnavailable`)}),e.description&&(0,T.jsx)(`small`,{children:e.description}),e.status===`not_loaded`&&(0,T.jsx)(`small`,{children:o(`localBotMcpNotLoaded`)}),e.status===`disabled`&&(0,T.jsx)(`small`,{children:o(`localBotMcpDisabled`)}),e.source&&(0,T.jsx)(`small`,{children:e.source}),e.path&&(0,T.jsx)(`small`,{children:e.path})]})]},e.id)),!h.length&&(0,T.jsx)(`p`,{children:o(a?`localBotOptionsLoading`:`localBotNoOptions`)})]})]})}var P=e=>e.id.startsWith(`${e.provider}/`)?e.id.slice(e.provider.length+1):e.id,F=()=>({name:``,description:``,systemPrompt:``,cwd:``,tools:[],skills:[],mcpServers:[],enabled:!0});async function I(e,t,n){let r=await fetch(m(h(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json();if(!r.ok)throw Error(i.error||String(r.status));return i}function L({pathCompletions:e=[]}){let t=l(),[n,r]=(0,w.useState)([]),[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(!1),[c,u]=(0,w.useState)(``),[d,f]=(0,w.useState)(``),[p,m]=(0,w.useState)(null),[h,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(0),[S,E]=(0,w.useState)(!1),[D,O]=(0,w.useState)(`identity`),k=(0,w.useRef)(null),A=(0,w.useRef)(``),L=(0,w.useRef)(null),R=i!==null;(0,w.useEffect)(()=>{if(!R)return;let e=L.current,t=document.activeElement,n=document.body.style.overflow;return document.body.style.overflow=`hidden`,O(`identity`),e?.showModal?.(),()=>{e?.close?.(),document.body.style.overflow=n,t?.focus()}},[R]),(0,w.useEffect)(()=>{let e=new AbortController;return I(`local-bots`,e.signal).then(t=>{if(!e.signal.aborted){if(!Array.isArray(t.bots))throw Error(`Invalid Bot list`);r(t.bots)}}).catch(t=>{e.signal.aborted||u(String(t))}),()=>{e.abort(),k.current?.abort()}},[]);let z=i?.cwd;(0,w.useEffect)(()=>{if(z===void 0)return;let e=new AbortController;return v(!0),g(``),m(null),I(z?`local-bot-options?cwd=${encodeURIComponent(z)}`:`local-bot-options`,e.signal).then(n=>{if(!e.signal.aborted){if(![n.models,n.tools,n.skills,n.mcpServers,n.projects].every(Array.isArray)||!n.defaultCwd||!n.cwd)throw Error(t(`localBotOptionsInvalid`));A.current=n.defaultCwd,m(n),z||a(e=>e&&!e.cwd?{...e,cwd:n.cwd}:e)}}).catch(t=>{e.signal.aborted||g(String(t))}).finally(()=>{e.signal.aborted||v(!1)}),()=>e.abort()},[z,y]),(0,w.useEffect)(()=>{if(!S)return;let e=e=>{e.key===`Escape`&&E(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S]);async function B(e=!1){if(!i||o)return;let n=new AbortController;k.current=n,s(!0),u(``),f(``);try{let o=await I(e?`local-bots/${encodeURIComponent(i.id)}/delete`:`local-bots`,n.signal,e?{revision:i.revision}:i);if(n.signal.aborted)return;r(t=>e?t.filter(e=>e.id!==i.id):[...t.filter(e=>e.id!==o.bot.id),o.bot]),a(null),E(!1),f(o.synced===!1?t(`localBotSyncFailed`):t(`localBotSaved`))}catch(e){n.signal.aborted||u(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||s(!1)}}let V=p?.models.find(e=>e.provider===i?.model?.provider&&P(e)===i?.model?.modelId);return(0,T.jsxs)(`section`,{className:`dc-card dc-bots`,"aria-label":t(`localBotTitle`),children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsx)(`h2`,{children:t(`localBotTitle`)}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>{a(F()),u(``),E(!1)},children:t(`localBotCreate`)})]}),(0,T.jsx)(`p`,{children:t(`localBotHint`)}),c&&!i&&(0,T.jsx)(`p`,{role:`alert`,children:c}),d&&(0,T.jsx)(`p`,{role:`status`,children:d}),(0,T.jsxs)(`div`,{className:`dc-bot-workspace${i?` is-editing`:``}`,children:[(0,T.jsx)(`div`,{className:`dc-bot-list`,"aria-label":t(`localBotTitle`),children:n.map(e=>(0,T.jsxs)(`button`,{className:`dc-button dc-bot-item${i?.id===e.id?` is-selected`:``}`,"aria-pressed":i?.id===e.id,disabled:o,onClick:()=>{a(structuredClone(e)),u(``),E(!1)},children:[(0,T.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:e.name.slice(0,2).toUpperCase()}),(0,T.jsxs)(`span`,{className:`dc-bot-item-copy`,children:[(0,T.jsx)(`strong`,{children:e.name}),(0,T.jsxs)(`small`,{className:e.enabled?`is-enabled`:``,children:[e.enabled?t(`localBotEnabled`):t(`localBotDisabled`),` · r`,e.revision]})]})]},e.id))}),i&&(0,T.jsx)(`dialog`,{ref:L,className:`dc-bot-drawer`,"aria-label":t(`localBotTitle`),onCancel:e=>{e.preventDefault(),!o&&!S&&a(null)},onClick:e=>{if(e.target!==e.currentTarget||o)return;let t=e.currentTarget.getBoundingClientRect();(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&a(null)},children:(0,T.jsxs)(`form`,{className:`dc-bot-editor`,onSubmit:e=>{e.preventDefault(),B()},children:[(0,T.jsxs)(`header`,{className:`dc-bot-editor-head`,children:[(0,T.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:i.name.slice(0,2).toUpperCase()||`B`}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{children:i.name||t(`localBotCreate`)}),i.id&&(0,T.jsxs)(`small`,{children:[i.id,` · r`,i.revision]})]}),(0,T.jsxs)(`label`,{className:`dc-bot-enabled`,children:[(0,T.jsx)(`input`,{type:`checkbox`,role:`switch`,disabled:o,checked:i.enabled,onChange:e=>a({...i,enabled:e.target.checked})}),t(`localBotEnable`)]}),(0,T.jsx)(`button`,{className:`dc-button dc-bot-drawer-close`,type:`button`,"aria-label":t(`localBotCancel`),disabled:o,onClick:()=>a(null),children:`×`})]}),(0,T.jsx)(`div`,{className:`dc-bot-tabs`,role:`tablist`,"aria-label":t(`localBotTitle`),children:[[`identity`,t(`localBotIdentity`)],[`runtime`,t(`localBotRuntime`)],[`permissions`,t(`localBotPermissions`)]].map(([e,t],n,r)=>(0,T.jsx)(`button`,{type:`button`,role:`tab`,id:`bot-tab-${e}`,"aria-controls":`bot-panel-${e}`,"aria-selected":D===e,tabIndex:D===e?0:-1,onClick:()=>O(e),onKeyDown:e=>{let t=n;if(e.key===`ArrowRight`)t=(n+1)%r.length;else if(e.key===`ArrowLeft`)t=(n+r.length-1)%r.length;else if(e.key===`Home`)t=0;else if(e.key===`End`)t=r.length-1;else return;e.preventDefault(),O(r[t][0]),document.getElementById(`bot-tab-${r[t][0]}`)?.focus()},children:t},e))}),(0,T.jsxs)(`div`,{className:`dc-bot-editor-body`,children:[c&&(0,T.jsx)(`p`,{className:`dc-bot-error`,role:`alert`,children:c}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-identity`,"aria-labelledby":`bot-tab-identity`,hidden:D!==`identity`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotIdentityHint`)}),(0,T.jsxs)(`fieldset`,{className:`dc-bot-section`,disabled:o,children:[(0,T.jsx)(`legend`,{children:t(`localBotIdentity`)}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotName`),(0,T.jsx)(`input`,{required:!0,value:i.name,onChange:e=>a({...i,name:e.target.value})})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotDescription`),(0,T.jsx)(`textarea`,{rows:2,value:i.description,onChange:e=>a({...i,description:e.target.value})})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotSystemPrompt`),(0,T.jsx)(`textarea`,{rows:9,className:`dc-bot-prompt`,spellCheck:!1,value:i.systemPrompt,onChange:e=>a({...i,systemPrompt:e.target.value})})]})]}),(0,T.jsx)(`p`,{className:`dc-bot-local-note`,children:t(`localBotPrivatePrompt`)})]}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-runtime`,"aria-labelledby":`bot-tab-runtime`,hidden:D!==`runtime`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotRuntimeHint`)}),(0,T.jsxs)(`fieldset`,{className:`dc-bot-section`,disabled:o,children:[(0,T.jsx)(`legend`,{children:t(`localBotRuntime`)}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`local-bot-cwd`,children:t(`localBotCwd`)}),(0,T.jsx)(C,{inputId:`local-bot-cwd`,localOnly:!0,commitOnBlur:!0,pathCompletions:e,cwd:i.cwd,baseCwd:A.current||i.cwd,projects:p?.projects.map(e=>({...e,lastUsed:0}))??[],disabled:o,onSelectCwd:e=>a({...i,cwd:M(e,A.current||i.cwd)})})]}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:t(`localBotModel`)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,"aria-haspopup":`dialog`,onClick:()=>E(!0),children:i.model?V?.name??`${i.model.provider}/${i.model.modelId}`:t(`localBotInheritModel`)}),i.model&&(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>a({...i,model:void 0}),children:t(`localBotInheritModel`)})]}),i.model&&!V&&(0,T.jsx)(`small`,{children:t(_?`localBotUnverified`:`localBotUnavailable`)})]})]})]}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-permissions`,"aria-labelledby":`bot-tab-permissions`,hidden:D!==`permissions`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotPermissionsHint`)}),(0,T.jsxs)(`div`,{className:`dc-bot-options-status`,"aria-live":`polite`,children:[_&&(0,T.jsx)(`span`,{children:t(`localBotOptionsLoading`)}),h&&(0,T.jsx)(`span`,{role:`alert`,children:h}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:_||o,onClick:()=>b(e=>e+1),children:t(h?`deviceHubRetry`:`localBotReload`)})]}),(0,T.jsx)(`div`,{className:`dc-bot-permissions`,children:[[`tools`,t(`localBotTools`)],[`skills`,t(`localBotSkills`)],[`mcpServers`,t(`localBotMcpServers`)]].map(([e,t])=>(0,T.jsx)(N,{title:t,entries:p?.[e]??[],selected:i[e],disabled:o,pending:_||!!h,onChange:t=>a({...i,[e]:t})},e))})]})]}),(0,T.jsxs)(`footer`,{className:`dc-actions dc-bot-editor-footer`,children:[(0,T.jsx)(`button`,{className:`dc-button dc-bot-save`,disabled:o||!i.cwd||!i.name.trim(),children:t(`localBotSave`)}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>{a(null),E(!1)},children:t(`localBotCancel`)}),i.id&&(0,T.jsx)(`button`,{className:`dc-button is-danger`,type:`button`,disabled:o,onClick:()=>{window.confirm(t(`localBotDeleteConfirm`))&&B(!0)},children:t(`localBotDelete`)})]})]})})]}),i&&S&&(0,j.createPortal)((0,T.jsx)(`div`,{className:`modal-backdrop dc-bot-model-backdrop`,onClick:e=>{e.target===e.currentTarget&&E(!1)},children:(0,T.jsxs)(`div`,{className:`dc-bot-model-modal dd-menu-model`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`localBotModel`),children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsx)(`h3`,{children:t(`localBotModel`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>E(!1),children:t(`localBotCancel`)})]}),(0,T.jsx)(x,{models:p?.models??[],modelsLoading:_,defaultModel:p?.defaultModel,currentModelId:i.model?`${i.model.provider}/${i.model.modelId}`:null,active:!0,onEnsureModels:()=>{},onRefresh:()=>b(e=>e+1),onPickModel:e=>{a({...i,model:{provider:e.provider,modelId:P(e)}}),E(!1)},isRowActive:e=>e.provider===i.model?.provider&&P(e)===i.model.modelId,extraTopRow:(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>{a({...i,model:void 0}),E(!1)},children:t(`localBotInheritModel`)}),autoFocusSearch:!0,hideTitle:!0,bodyStyle:{flex:1,minHeight:0},scrollStyle:{overflowY:`auto`,minHeight:0}}),h&&(0,T.jsx)(`p`,{role:`alert`,children:h})]})}),L.current??document.body)]})}function R(e){if(!z(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 z(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 B(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 V=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url https://hub.example.com --allow-registration`;function H(e,t,n){if(!R(e))throw Error(`Invalid Hub setup`);let r=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.`,`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=${r(t?.platform)}, Node=${r(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,`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: ${V}`,`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.`].join(`
2
- `)}function U({onConnect:e,initialHubUrl:t=``}){let n=l(),[r,i]=(0,w.useState)(t),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(!1),[u,d]=(0,w.useState)(!1),f=(0,w.useRef)(!1),p=(0,w.useRef)(!1);(0,w.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[g,_]=(0,w.useState)(null),[v,y]=(0,w.useState)(`current`),[b,x]=(0,w.useState)(null),[S,C]=(0,w.useState)(`127.0.0.1`),[E,D]=(0,w.useState)(`8790`),[O,k]=(0,w.useState)(`http://127.0.0.1:8790`),[A,j]=(0,w.useState)(!1),[M,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(!1),[z,V]=(0,w.useState)(null),U=(0,w.useRef)(null),W=(0,w.useRef)(!1),G=B(window.location.origin);(0,w.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,N(!1),F(!1),L(!1);try{let t=await fetch(m(h(`/api/device-center/setup`)),{credentials:`same-origin`,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`||!R({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;x(n),n.installation?.installed?(C(n.installation.host??`127.0.0.1`),D(String(n.installation.port)),k(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):b||(D(String(n.defaultPort)),k(n.defaultPublicUrl))}catch{e.signal.aborted||(N(!0),L(!0))}finally{e.signal.aborted||F(!0)}},ee=async()=>{let e={host:S,port:Number(E),publicUrl:O};if(W.current||!G||!b||!P||I||b.busy||b.installation?.installed||!R(e))return;W.current=!0,U.current?.abort(),j(!0),N(!1),o(``);let t=new AbortController;U.current=t;try{let n=await fetch(m(h(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){x(e=>e&&{...e,busy:!0}),W.current=!1,j(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let r=await n.json();if(!R({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||V(r)}catch(e){t.signal.aborted||(N(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||j(!1)}},q=b?.installation,J=!!q?.installed,Y=J&&q.running&&q.owned,te={host:S,port:Number(E),publicUrl:O},X=R(te);return(0,T.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,T.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,disabled:A,"aria-pressed":g===`connect`,onClick:()=>_(`connect`),children:n(`deviceSetupConnect`)}),(0,T.jsx)(`button`,{className:`dc-button`,disabled:A,"aria-pressed":g===`create`,onClick:()=>{_(`create`),!b&&G&&K()},children:n(`deviceSetupCreate`)})]}),g===`connect`&&(0,T.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,disabled:!R({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),g===`create`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,T.jsxs)(`select`,{disabled:A,value:v,onChange:e=>y(e.target.value),children:[(0,T.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,T.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)}),(0,T.jsx)(`option`,{value:`none`,children:n(`deviceSetupNoServer`)})]})]}),v===`none`?(0,T.jsx)(`p`,{children:n(`deviceSetupNoServerHint`)}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(v===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),v===`current`&&(0,T.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,T.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),b&&(0,T.jsxs)(`dl`,{children:[(0,T.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,T.jsxs)(`dd`,{children:[b.platform,` · Node `,b.nodeVersion]}),(0,T.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,T.jsx)(`dd`,{children:b.dataDir}),(0,T.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,T.jsx)(`dd`,{children:b.cliPath})]}),!G&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupBackground`)}),J&&(0,T.jsxs)(`div`,{role:`status`,children:[(0,T.jsx)(`h4`,{children:n(Y?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,T.jsx)(`p`,{children:q.publicUrl}),Y&&X&&q.publicUrl?(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`a`,{className:`dc-button`,href:q.publicUrl,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceHubOpenHub`)}),(0,T.jsx)(`button`,{className:`dc-button`,onClick:()=>e(q.publicUrl),children:n(`deviceSetupPair`)})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
- pi-web-ui hub --help`})]})]}),b?.busy&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,T.jsx)(`button`,{className:`dc-button`,disabled:A||!P,onClick:()=>void K(),children:n(P?`deviceSetupRetry`:`deviceHubWorking`)})]}),(0,T.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,T.jsx)(`input`,{disabled:A||!!z,maxLength:253,value:S,onChange:e=>C(e.target.value)})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,T.jsx)(`input`,{disabled:A||!!z,type:`number`,min:1024,max:65535,value:E,onChange:e=>D(e.target.value)})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{disabled:A||!!z,maxLength:2048,value:O,onChange:e=>k(e.target.value)})]})]}),(0,T.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,T.jsx)(`p`,{role:`alert`,children:n(`deviceSetupInvalid`)}),v===`remote`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(`deviceSetupCliHint`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url https://hub.example.com --allow-registration`})]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[v===`current`&&!z&&!J&&(0,T.jsx)(`button`,{className:`dc-button is-primary`,disabled:A||!G||!b||!P||I||!!b.busy||!X,onClick:()=>void ee(),children:n(A?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,T.jsx)(`button`,{className:`dc-button`,disabled:A||s||!X,onClick:()=>{if(!X||v===`none`||f.current)return;f.current=!0,c(!0),d(!1);let e=e=>{f.current=!1,p.current&&(c(!1),d(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:H(te,b,v),onResult:e})||e(!1)}catch{e(!1)}},children:n(`deviceSetupAi`)})]}),(0,T.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),s&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,T.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),M&&(0,T.jsxs)(`div`,{role:`alert`,children:[(0,T.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),z&&(0,T.jsxs)(`div`,{role:`status`,children:[(0,T.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:z.output.slice(0,16e3)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`a`,{className:`dc-button`,href:z.publicUrl,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceHubOpenHub`)}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(z.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}function W({hubUrl:e,currentDeviceId:t}){let{locale:r}=d(),i=g(r),[a,o]=(0,w.useState)([]),[s,c]=(0,w.useState)(``),[l,u]=(0,w.useState)(0);(0,w.useEffect)(()=>{let e=!1,t,n;async function r(){t=new AbortController;try{let n=await fetch(m(h(`/api/device-center/devices`)),{signal:AbortSignal.any([t.signal,AbortSignal.timeout(15e3)]),credentials:`same-origin`});if(!n.ok)throw Error(n.status===409?i?`请重新绑定本机以读取设备列表。`:`Pair this computer again to read the device list.`:i?`无法读取设备列表,请重试。`:`Could not load devices. Try again.`);let r=await n.json();if(!Array.isArray(r.devices))throw Error(i?`设备列表格式异常。`:`Invalid device list.`);e||(o(r.devices),c(``))}catch(t){e||(o([]),c(t instanceof Error?t.message:String(t)))}finally{e||(n=setTimeout(r,5e3))}}return r(),()=>{e=!0,t?.abort(),clearTimeout(n)}},[e,t,l,i]);function p(t){try{let n=new URL(e);return![`http:`,`https:`].includes(n.protocol)||n.username||n.password?void 0:new URL(`/device/${encodeURIComponent(t)}`,n).href}catch{return}}async function v(t,n,r=!1){t.preventDefault();let a=window.open(`about:blank`,`_blank`);if(!a){c(i?`请允许弹出窗口后重试。`:`Allow popups and try again.`);return}a.opener=null;try{let t=await fetch(m(h(`/api/device-center/devices/${encodeURIComponent(n)}/open`)),{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`,credentials:`same-origin`,signal:AbortSignal.timeout(15e3)});if(!t.ok)throw Error(i?`无法打开设备,请确认设备在线且本机绑定有效。`:`Could not open the device. Check connectivity and local pairing.`);let o=await t.json(),s=new URL(o.url);if(![`http:`,`https:`].includes(s.protocol)||s.hostname!==new URL(e).hostname||s.username||s.password||!(s.pathname===`/__device/open`||s.origin===new URL(e).origin&&s.pathname===`/device/${encodeURIComponent(n)}/__open`))throw Error(`Invalid device access URL`);s.searchParams.delete(`next`),r&&s.searchParams.set(`next`,`/desktop`),a.location.replace(s.href),c(``)}catch(e){a.close(),c(e instanceof Error?e.message:String(e))}}return(0,T.jsxs)(`section`,{className:`dc-card`,"aria-label":i?`所有设备`:`All devices`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsxs)(`h2`,{children:[i?`所有设备`:`All devices`,` · `,a.length]}),(0,T.jsx)(`p`,{children:i?`同一账号下的设备,使用本机绑定授权直接访问。`:`Devices in your account. Access is authorized through this computer's pairing.`})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":i?`刷新设备`:`Refresh devices`,onClick:()=>u(e=>e+1),children:(0,T.jsx)(n,{})})]}),s&&(0,T.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:s}),(0,T.jsx)(`div`,{className:`dd-list`,children:a.map(e=>(0,T.jsxs)(`div`,{className:`dd-device`,children:[(0,T.jsx)(`span`,{className:`dc-device-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{className:`dd-identity`,children:[(0,T.jsx)(`strong`,{children:e.name}),(0,T.jsx)(`span`,{children:e.id===t?i?`本机`:`This device`:e.id})]}),(0,T.jsx)(`span`,{className:`dc-status ${e.online?`is-online`:`is-offline`}`,children:e.online?i?`在线`:`Online`:i?`离线`:`Offline`}),p(e.id)&&(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsxs)(`a`,{className:`dc-button`,href:p(e.id),target:`_blank`,rel:`noopener noreferrer`,onClick:t=>void v(t,e.id),children:[(0,T.jsx)(f,{"aria-hidden":!0}),i?`打开设备`:`Open device`]}),(0,T.jsxs)(`a`,{className:`dc-button`,href:`${p(e.id)}/desktop`,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>void v(t,e.id,!0),children:[(0,T.jsx)(_,{"aria-hidden":!0}),i?`远程桌面`:`Remote desktop`]})]})]},e.id))})]})}var G=class extends Error{status;constructor(e,t){super(t),this.status=e}};function K(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function ee(){let e=l(),t=u().startsWith(`zh`),[r,i]=(0,w.useState)(null),[a,o]=(0,w.useState)(!1),[s,c]=(0,w.useState)(!1),[d,f]=(0,w.useState)(!1),[p,g]=(0,w.useState)(!1),v=(0,w.useRef)(0),y=(0,w.useRef)(null);async function b(e,t){if(y.current)return;let n=++v.current,r=new AbortController;y.current=r,o(!0),c(!1);try{let a=await fetch(m(h(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(v.current!==n||r.signal.aborted)return;if(a.status===403){f(!0),i(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(v.current!==n||r.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),g(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);i(o)}}catch{v.current===n&&!r.signal.aborted&&c(!0)}finally{v.current===n&&!r.signal.aborted&&(y.current=null,o(!1))}}return(0,w.useEffect)(()=>(b(`status`),()=>{v.current++,y.current?.abort(),y.current=null}),[]),(0,T.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,T.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),d?(0,T.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,T.jsxs)(T.Fragment,{children:[r&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,T.jsx)(`p`,{children:r.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-toggle${r.enabled?` is-on`:``}`,role:`switch`,"aria-checked":r.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||r.environmentEnabled||!r.supported&&!r.enabled,onClick:()=>void b(`enable`,{enabled:!r.enabled}),children:(0,T.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!r.supported&&(0,T.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),r.environmentEnabled&&(0,T.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),r.os===`darwin`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:t?`点击下方按钮发起系统授权,请在这台 Mac 的系统设置中确认。授权后可能需要重启服务。`:`Use the buttons below to request system permission, then confirm in System Settings on this Mac. You may need to restart the service afterward.`}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),r.permissions?.screen===!0&&(0,T.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),r.permissions?.accessibility===!0&&(0,T.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),p&&(0,T.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),s&&(0,T.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void b(`status`),children:[(0,T.jsx)(n,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function q({pathCompletions:e=[]}){let a=l(),u=S(),[d,p]=(0,w.useState)(u.revision?`groups`:`overview`);(0,w.useEffect)(()=>{u.revision&&p(`groups`)},[u.revision]);let[g,v]=(0,w.useState)(null),[y,b]=(0,w.useState)(``),[x,C]=(0,w.useState)(``),[E,D]=(0,w.useState)(null),[O,k]=(0,w.useState)(Date.now()),[j,M]=(0,w.useState)(null),[N,P]=(0,w.useState)(``),[F,I]=(0,w.useState)(``),[R,z]=(0,w.useState)(``),[B,V]=(0,w.useState)(!1),[H,q]=(0,w.useState)(!0),J=(0,w.useRef)(!1),Y=(0,w.useRef)(0),te=(0,w.useRef)(new Set),X=(0,w.useRef)(!1),Z=(0,w.useRef)(!1),ne=(0,w.useRef)(null),re=(0,w.useRef)(a);re.current=a;async function ie(e,t){let n=new AbortController;te.current.add(n);try{let r=await fetch(m(h(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new G(r.status,typeof i.error==`string`?i.error:re.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{te.current.delete(n)}}function Q(e){return J.current&&Y.current===e}function ae(e){return e instanceof G&&e.status===403?(V(!0),re.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:re.current(`deviceHubNetworkError`)}function oe(e){ne.current=e,v(e),Z.current||(C(e.name),b(e.hubUrl??``))}async function se(){let e=Y.current;try{let t=await ie(`status`);if(!Q(e)||X.current)return;oe(t),I(``),V(!1)}catch(t){Q(e)&&I(ae(t))}finally{Q(e)&&q(!1)}}(0,w.useEffect)(()=>{J.current=!0;let e=!1,t,n=async()=>{await se(),!e&&J.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,J.current=!1,Y.current++,clearTimeout(t);for(let e of te.current)e.abort()}},[]),(0,w.useEffect)(()=>{if(!E)return;let e=Y.current,t=!1,n,r=setInterval(()=>k(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=E.expiresAt)){try{let n=await ie(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await ie(`status`);if(t||!Q(e))return;Z.current=!1,oe(n),D(null),P(``),z(``);return}P(``)}catch(n){!t&&Q(e)&&P(`${re.current(`deviceHubPollError`)} ${ae(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[E]);async function ce(){if(X.current)return;let e=K(y.trim());if(!e){P(a(`deviceHubInvalidUrl`));return}if(!x.trim()||x.trim().length>80){P(a(`deviceHubInvalidName`));return}let t=++Y.current;X.current=!0,M(`pair`),P(``),z(``),D(null);try{let n=await ie(`pair`,{hubUrl:e,name:x.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!K(n.hubUrl))throw Error(a(`deviceHubPairError`));k(Date.now()),D(n)}catch(e){Q(t)&&P(`${a(`deviceHubPairError`)} ${ae(e)}`)}finally{Q(t)&&(X.current=!1,M(null))}}async function le(){let e=ne.current;if(!e?.deviceId||X.current)return;let t=++Y.current;X.current=!0,M(`permission`),P(``),z(``),oe({...e,allowExecution:!e.allowExecution});try{await ie(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(a(`deviceHubSaved`))}catch(n){Q(t)&&(oe(e),P(`${a(`deviceHubPermissionError`)} ${ae(n)}`))}finally{Q(t)&&(X.current=!1,M(null))}}async function ue(){let e=ne.current;if(!e?.deviceId||X.current||!window.confirm(a(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;X.current=!0,M(`disconnect`),P(``),z(``);try{if(await ie(`disconnect`,{}),!Q(t))return;Z.current=!1,oe({name:e.name,allowExecution:!1,connected:!1}),D(null)}catch(e){Q(t)&&P(`${a(`deviceHubDisconnectError`)} ${ae(e)}`)}finally{Q(t)&&(X.current=!1,M(null))}}async function de(){if(!E)return;let e=Y.current;try{await navigator.clipboard.writeText(E.code),Q(e)&&z(a(`deviceHubCopied`))}catch{Q(e)&&P(a(`deviceHubCopyFailed`))}}let $=!!g?.deviceId,fe=K($?g?.hubUrl??``:E?.hubUrl??``),pe=Math.max(0,Math.ceil(((E?.expiresAt??0)-O)/1e3)),me=`${Math.floor(pe/60)}:${String(pe%60).padStart(2,`0`)}`,he=fe?(0,T.jsxs)(`a`,{className:`dc-button`,href:fe,target:`_blank`,rel:`noopener noreferrer`,children:[(0,T.jsx)(f,{"aria-hidden":!0}),a(`deviceHubOpenHub`)]}):null;return(0,T.jsxs)(`section`,{className:`dc-page`,"aria-label":a(`deviceHubTitle`),children:[(0,T.jsxs)(`header`,{className:`dc-header`,children:[(0,T.jsxs)(`div`,{className:`dc-heading`,children:[(0,T.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,T.jsx)(_,{"aria-hidden":!0}),a(`deviceHubTitle`)]}),(0,T.jsx)(`h1`,{children:a(`deviceHubTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubSubtitle`)})]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[$&&he,(0,T.jsxs)(`span`,{className:`dc-status ${$?g?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,T.jsx)(`span`,{className:`dc-status-dot`}),a($?g?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,T.jsxs)(`div`,{className:`dc-layout`,children:[(0,T.jsxs)(`nav`,{className:`dc-sidebar`,"aria-label":a(`deviceHubTitle`),children:[(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`overview`?` is-active`:``}`,"aria-current":d===`overview`?`page`:void 0,onClick:()=>p(`overview`),children:[(0,T.jsx)(_,{"aria-hidden":!0}),a(`deviceHubOverview`)]}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`groups`?` is-active`:``}`,"aria-current":d===`groups`?`page`:void 0,onClick:()=>p(`groups`),children:[(0,T.jsx)(i,{"aria-hidden":!0}),a(`deviceHubGroups`)]}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`settings`?` is-active`:``}`,"aria-current":d===`settings`?`page`:void 0,onClick:()=>p(`settings`),children:[(0,T.jsx)(t,{"aria-hidden":!0}),a(`deviceHubSettings`)]})]}),(0,T.jsxs)(`main`,{className:`dc-content`,children:[H&&(0,T.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubLoading`)]}),(B||F)&&(0,T.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,T.jsx)(`span`,{children:B?a(`deviceHubLocalOnly`):`${a(`deviceHubStatusError`)} ${F}`}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void se(),children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubRetry`)]})]}),N&&!B&&(0,T.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:N}),R&&(0,T.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,T.jsx)(r,{"aria-hidden":!0}),R]}),!$&&(g||B)&&d===`overview`&&(0,T.jsx)(U,{initialHubUrl:y,onConnect:e=>{if(B){z(a(`deviceHubLocalOnly`));return}Z.current=!0,b(e),p(`settings`)}}),$&&d===`overview`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsx)(`h3`,{children:a(`deviceSetupNext`)}),(0,T.jsx)(`p`,{children:a(`deviceSetupNextHint`)}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>p(`groups`),children:a(`deviceSetupManage`)})]}),d===`settings`&&(0,T.jsx)(ee,{}),g&&!B&&!$&&d===`settings`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(t,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:a(`deviceHubPairTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubPairHint`)})]})]}),(0,T.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,T.jsxs)(`li`,{className:E?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,T.jsx)(`span`,{className:`dc-step-number`,children:E&&t===0?(0,T.jsx)(r,{"aria-hidden":!0}):t+1}),(0,T.jsx)(`span`,{children:a(e)})]},e))}),(0,T.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ce()},children:[(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`dc-hub-url`,children:a(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:a(`deviceHubHubPlaceholder`),value:y,disabled:!!E||!!j,onChange:e=>{Z.current=!0,b(e.target.value)}})]}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`dc-device-name`,children:a(`deviceHubName`)}),(0,T.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:a(`deviceHubNamePlaceholder`),value:x,disabled:!!E||!!j,onChange:e=>{Z.current=!0,C(e.target.value)}})]}),!E&&(0,T.jsx)(`div`,{className:`dc-actions`,children:(0,T.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!j,children:[(0,T.jsx)(t,{"aria-hidden":!0}),a(j?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),E&&(0,T.jsxs)(`div`,{className:`dc-pairing`,children:[(0,T.jsx)(`span`,{className:`dc-code-label`,children:a(`deviceHubCode`)}),(0,T.jsxs)(`div`,{className:`dc-code-row`,children:[(0,T.jsx)(`code`,{className:`dc-code`,children:E.code}),(0,T.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":a(`deviceHubCopy`),onClick:()=>void de(),children:(0,T.jsx)(o,{"aria-hidden":!0})})]}),(0,T.jsx)(`div`,{className:`dc-pair-meta`,children:a(pe?`deviceHubExpires`:`deviceHubExpired`,{time:me})}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[he,(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!j,onClick:()=>{++Y.current,D(null),P(``),z(``)},children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubNewCode`)]})]}),pe>0&&(0,T.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubWaiting`)]})]})]}),$&&g&&!B&&(0,T.jsxs)(T.Fragment,{children:[d===`overview`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,T.jsx)(`span`,{className:`dc-device-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:g.name}),(0,T.jsx)(`p`,{children:a(`deviceHubDeviceTitle`)})]})]}),(0,T.jsxs)(`dl`,{className:`dc-details`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{children:a(`deviceHubDeviceId`)}),(0,T.jsx)(`dd`,{children:g.deviceId})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{children:a(`deviceHubHubUrl`)}),(0,T.jsx)(`dd`,{children:g.hubUrl})]})]})]}),d===`settings`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(c,{"aria-hidden":!0})}),(0,T.jsx)(`div`,{children:(0,T.jsx)(`h2`,{children:a(`deviceHubPermissions`)})})]}),(0,T.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{id:`dc-permission-label`,children:a(`deviceHubPermissionLabel`)}),(0,T.jsx)(`p`,{id:`dc-permission-hint`,children:a(`deviceHubPermissionHint`)})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-toggle${g.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":g.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!j,onClick:()=>void le(),children:(0,T.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,T.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:a(j===`permission`?`deviceHubSaving`:g.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),d===`settings`&&(0,T.jsxs)(`details`,{className:`dc-advanced`,children:[(0,T.jsx)(`summary`,{children:a(`deviceHubAdvanced`)}),(0,T.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,T.jsx)(`h3`,{children:a(`deviceHubDisconnect`)}),(0,T.jsx)(`p`,{children:a(`deviceHubDisconnectHint`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!j,onClick:()=>void ue(),children:a(j===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),$&&g?.hubUrl&&g.deviceId&&!B&&d!==`groups`&&(0,T.jsx)(W,{hubUrl:g.hubUrl,currentDeviceId:g.deviceId},`directory:${g.hubUrl}:${g.deviceId}`),!B&&(d===`settings`||d===`groups`)&&(0,T.jsx)(L,{pathCompletions:e},`bots:${g?.hubUrl??``}:${g?.deviceId??`unpaired`}`),d===`groups`&&(0,T.jsx)(A,{navigation:u}),(0,T.jsxs)(`aside`,{className:`dc-help`,children:[(0,T.jsx)(s,{className:`dc-help-icon`,"aria-hidden":!0}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{children:a(`deviceHubHelpTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubHelpText`)})]})]})]})]})]})}export{q as DeviceCenter};