pi-web-ui 0.116.0 → 0.117.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 (155) hide show
  1. package/CHANGELOG.md +38 -4
  2. package/bin/device-hub-cli.mjs +26 -3
  3. package/bin/pi-web-ui.mjs +138 -70
  4. package/dist/server/agent-service-daemon.js +52 -6
  5. package/dist/server/agent-service.js +495 -141
  6. package/dist/server/canvas/canvas-workspace.js +18 -86
  7. package/dist/server/client-state.js +35 -6
  8. package/dist/server/compaction-markers.js +43 -24
  9. package/dist/server/dangling-tools.js +172 -16
  10. package/dist/server/device-center/bot-execution.js +48 -1
  11. package/dist/server/device-center/collab-service.js +26 -8
  12. package/dist/server/device-center/collab-tool.js +394 -18
  13. package/dist/server/device-center/connector.js +107 -37
  14. package/dist/server/device-center/delivery-authority.js +98 -0
  15. package/dist/server/device-center/delivery-subject.js +30 -0
  16. package/dist/server/device-center/device-integration.js +453 -183
  17. package/dist/server/device-center/execution-guides.js +15 -5
  18. package/dist/server/device-center/executor.js +47 -5
  19. package/dist/server/device-center/hub-conversations.js +14 -4
  20. package/dist/server/device-center/hub-deliveries.js +120 -15
  21. package/dist/server/device-center/hub-integration.js +655 -334
  22. package/dist/server/device-center/hub-page.js +5 -4
  23. package/dist/server/device-center/hub-setup.js +23 -1
  24. package/dist/server/device-center/hub-transaction-log.js +197 -0
  25. package/dist/server/device-center/hub.js +772 -354
  26. package/dist/server/device-center/integration-verification.js +113 -0
  27. package/dist/server/device-center/local-hub.js +6 -2
  28. package/dist/server/device-center/local-publication.js +423 -0
  29. package/dist/server/device-center/local-verification-job.js +97 -0
  30. package/dist/server/device-center/local-verification.js +274 -0
  31. package/dist/server/device-center/local.js +107 -12
  32. package/dist/server/device-center/main.js +4 -1
  33. package/dist/server/device-center/partition-log.js +62 -25
  34. package/dist/server/device-center/publication-journal.js +312 -0
  35. package/dist/server/device-center/publish-intent.js +379 -0
  36. package/dist/server/device-center/relay.js +134 -24
  37. package/dist/server/device-center/runtime.js +426 -42
  38. package/dist/server/device-center/store.js +225 -47
  39. package/dist/server/device-center/task-outcome.js +81 -0
  40. package/dist/server/device-center/task-recovery.js +603 -178
  41. package/dist/server/device-center/task-settlement.js +353 -0
  42. package/dist/server/device-center/task-workspace.js +443 -0
  43. package/dist/server/device-center/verification-limits.js +10 -0
  44. package/dist/server/device-center/work-contract.js +995 -0
  45. package/dist/server/dispatch-domain-handlers.js +15 -0
  46. package/dist/server/dsh/dsh-agent-service.js +9 -2
  47. package/dist/server/index.js +26 -1
  48. package/dist/server/patch-node-pty.js +3 -2
  49. package/dist/server/patch-remote-catalog.js +3 -2
  50. package/dist/server/preset-fields.js +17 -1
  51. package/dist/server/preset-share.js +1 -0
  52. package/dist/server/protocol-version.js +1 -1
  53. package/dist/server/quick-ask-settings.js +28 -0
  54. package/dist/server/quick-ask.js +164 -0
  55. package/dist/server/resolve-global-sdk.js +61 -11
  56. package/dist/server/scheduler-tasks.js +35 -8
  57. package/dist/server/session-list-scan.js +223 -0
  58. package/dist/server/session-open.js +93 -0
  59. package/dist/server/session-parser.js +4 -0
  60. package/dist/server/session-scan.js +90 -38
  61. package/dist/server/settings-service.js +9 -1
  62. package/dist/server/soft-cap.js +5 -0
  63. package/dist/server/transcript-prepare.js +73 -0
  64. package/dist/server/universal/drivers/claude-code.js +98 -34
  65. package/dist/server/universal/universal-session.js +4 -0
  66. package/dist/server/workspace-handle.js +428 -0
  67. package/docs/architecture-plugins.md +18 -5
  68. package/docs/device-center.md +30 -22
  69. package/package.json +3 -4
  70. package/plugin-sdk/README.md +16 -8
  71. package/plugin-sdk/client.d.ts +27 -0
  72. package/plugin-sdk/client.mjs +82 -0
  73. package/plugin-sdk/index.d.ts +10 -0
  74. package/plugin-sdk/index.mjs +4 -683
  75. package/plugin-sdk/package.json +15 -4
  76. package/plugin-sdk/testing.d.ts +10 -0
  77. package/plugin-sdk/testing.mjs +566 -0
  78. package/themes/flow-cristallo.css +168 -0
  79. package/themes/flow-ink.css +169 -0
  80. package/themes/flow-obsidian.css +169 -0
  81. package/themes/flow-zurich.css +169 -0
  82. package/web/dist/.build-assets.json +1 -1
  83. package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-BjNRIUIc.js} +1 -1
  84. package/web/dist/assets/{BgTasksModal-C0i3O1FT.js → BgTasksModal-C0zuU8FE.js} +1 -1
  85. package/web/dist/assets/{CanvasStudio-B8thymBN.js → CanvasStudio-BWvdmJ0M.js} +3 -3
  86. package/web/dist/assets/{CanvasStudio-zSxyIx1R.js → CanvasStudio-VQFjmTGq.js} +3 -3
  87. package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
  88. package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
  89. package/web/dist/assets/{DeviceExecutionSettings-q5Ik8oXg.js → DeviceExecutionSettings-BLP1Su5G.js} +1 -1
  90. package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
  91. package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
  92. package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CQtstPGv.js} +1 -1
  93. package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
  94. package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
  95. package/web/dist/assets/{GlobalSearchModal-BWgU8yPd.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
  96. package/web/dist/assets/{GlobalSearchModal-F7fNimKk.js → GlobalSearchModal-DGv_WINq.js} +1 -1
  97. package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
  98. package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
  99. package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-ChTW8o1m.js} +1 -1
  100. package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
  101. package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
  102. package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-BX5rUuoI.js} +1 -1
  103. package/web/dist/assets/{ProviderOAuthControls-BGSBIKD7.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
  104. package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
  105. package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
  106. package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
  107. package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
  108. package/web/dist/assets/{TerminalPanel-DDavKvFr.js → TerminalPanel-D4By_RVc.js} +2 -2
  109. package/web/dist/assets/{TerminalPanel-0CYvD72B.js → TerminalPanel-lZw8-i3j.js} +2 -2
  110. package/web/dist/assets/{TuiOverlayModal-BsA-QTvN.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
  111. package/web/dist/assets/{TuiOverlayModal-DzoVQBuG.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
  112. package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
  113. package/web/dist/assets/{canvas-client-CUnXlQYX.js → canvas-client-BY6ojmle.js} +1 -1
  114. package/web/dist/assets/{desktop-aAKpvKJV.js → desktop-CV6KKp9R.js} +1 -1
  115. package/web/dist/assets/index-BawF7ZP5.js +397 -0
  116. package/web/dist/assets/index-BoGCoq5X.js +397 -0
  117. package/web/dist/assets/index-CVW9FoY2.css +1 -0
  118. package/web/dist/assets/{plugin-host-BRWib9DF.js → plugin-host-Dn8Dd6SC.js} +1 -1
  119. package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
  120. package/web/dist/assets/{theme-D2l_mLNo.js → theme-D_bihpdN.js} +1 -1
  121. package/web/dist/index.html +11 -11
  122. package/web/dist/sw.js +1 -1
  123. package/dist/gh-comment-781.md +0 -5
  124. package/dist/server/device-center/local-page.js +0 -17
  125. package/dist/server/device-center/smoke-preview.js +0 -3
  126. package/dist/server/durable/durable-capabilities.js +0 -11
  127. package/dist/server/markers/builtins/services.js +0 -123
  128. package/dist/server/markers/builtins/todo.js +0 -189
  129. package/dist/server/markers-list-tool.js +0 -34
  130. package/dist/server/orchestrator.js +0 -109
  131. package/dist/server/patch-turn-end-boundary.js +0 -77
  132. package/dist/server/system-prompt-soul.js +0 -41
  133. package/dist/server/univer-service.js +0 -448
  134. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  135. package/dist/test-artifact.md +0 -9
  136. package/dist/test-preview-modal.md +0 -11
  137. package/dist/test-report.html +0 -20
  138. package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
  139. package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
  140. package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
  141. package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
  142. package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
  143. package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
  144. package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
  145. package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
  146. package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
  147. package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
  148. package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
  149. package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
  150. package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
  151. package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
  152. package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
  153. package/web/dist/assets/index-C6DwztqE.css +0 -1
  154. package/web/dist/assets/index-CuN802Sj.js +0 -93
  155. package/web/dist/assets/index-EH5Fw9fa.js +0 -93
@@ -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,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Cn as r,Dn as i,Dt as a,H as o,Jt as s,Mt as ee,Rt as c,Tn as l,Z as u,bn as te,bt as d,cn as f,nn as p,pt as m,un as h,vn as g,yn as _,zt as v}from"./app-globals-CZxzGvIo.js";import{i as y,t as b}from"./react-CR5VJ85Q.js";import{Vt as ne,gt as re}from"./index-EH5Fw9fa.js";import{t as x}from"./DeviceExecutionSettings-q5Ik8oXg.js";var S=e(y(),1),C=b();function w({href:e,children:t}){let n=te(),[r,i]=(0,S.useState)(!1),[a,o]=(0,S.useState)(!1);return(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,C.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function T(e){if(!E(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 E(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 D(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 O=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,k=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,A=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function j(e){let t=e=>e.includes(`:`)?E(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?E(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(`:`))||e.https&&!e.domain)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 M(e,t,n,r){if(!T(e))throw Error(`Invalid Hub setup`);if(r){let t=j(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: ${O} (fallback: ${k}). If unavailable, report that and obtain its contents before proceeding.`,`Default to HTTP with the server IP and requested port. Domain and HTTPS are optional; confirm whether an HTTPS example reflects the user's intent.`,`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 explicitly selected: ${r.https}. HTTP inbound TCP port: ${r.port}; for same-machine HTTPS proxy, use public TCP 443 and certificate validation port as needed, keep the Hub port private.`]:[],`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: ${A}`,`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
- `)}function ie({onConnect:e,initialHubUrl:t=``}){let n=te(),[r,a]=(0,S.useState)(t),[o,s]=(0,S.useState)(``),[ee,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),f=(0,S.useRef)(!1),p=(0,S.useRef)(!1);(0,S.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[m,h]=(0,S.useState)(null),[g,_]=(0,S.useState)(`current`),[v,y]=(0,S.useState)(null),[b,ne]=(0,S.useState)(`127.0.0.1`),[re,x]=(0,S.useState)(`8790`),[E,O]=(0,S.useState)(`http://127.0.0.1:8790`),[k,A]=(0,S.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ie=j(k),[N,P]=(0,S.useState)(!1),[F,I]=(0,S.useState)(!1),[L,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(null),U=(0,S.useRef)(null),W=(0,S.useRef)(!1),G=D(window.location.origin);(0,S.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,I(!1),R(!1),B(!1);try{let t=await fetch(l(i(`/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`||!T({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;y(n),n.installation?.installed?(ne(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),O(n.installation.publicUrl??``),a(n.installation.publicUrl??``)):v||(x(String(n.defaultPort)),O(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),B(!0))}finally{e.signal.aborted||R(!0)}},q=async()=>{let e={host:b,port:Number(re),publicUrl:E};if(W.current||!G||!v||!L||z||v.busy||v.installation?.installed||!T(e))return;W.current=!0,U.current?.abort(),P(!0),I(!1),s(``);let t=new AbortController;U.current=t;try{let n=await fetch(l(i(`/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){y(e=>e&&{...e,busy:!0}),W.current=!1,P(!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(!T({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||H(r)}catch(e){t.signal.aborted||(I(!0),s(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||P(!1)}},J=v?.installation,Y=!!J?.installed,X=Y&&J.running&&J.owned,Z=g===`remote`?ie:{host:b,port:Number(re),publicUrl:E},Q=!!Z&&T(Z);return(0,C.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,C.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&G&&K()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,C.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>a(e.target.value),placeholder:`https://hub.example.com`})]}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:!T({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,C.jsxs)(`select`,{disabled:N,value:g,onChange:e=>_(e.target.value),children:[(0,C.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,C.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,C.jsxs)(`dl`,{children:[(0,C.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,C.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,C.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,C.jsx)(`dd`,{children:v.dataDir}),(0,C.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,C.jsx)(`dd`,{children:v.cliPath})]}),!G&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupBackground`)}),Y&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(X?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,C.jsx)(`p`,{children:J.publicUrl}),X&&Q&&J.publicUrl?(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
- pi-web-ui hub --help`})]})]}),v?.busy&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||!L,onClick:()=>void K(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:k.server,onChange:e=>A({...k,server:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,C.jsx)(`input`,{type:`number`,min:1,max:65535,value:k.sshPort,onChange:e=>A({...k,sshPort:Number(e.target.value)})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:k.username,onChange:e=>A({...k,username:e.target.value})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,C.jsxs)(`select`,{value:k.auth,onChange:e=>A({...k,auth:e.target.value}),children:[(0,C.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,C.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,C.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,C.jsx)(`input`,{type:`number`,min:1024,max:65535,value:k.port,onChange:e=>A({...k,port:Number(e.target.value)})})]})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,C.jsxs)(`details`,{children:[(0,C.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,C.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:k.domain,onChange:e=>A({...k,domain:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:k.https,onChange:e=>A({...k,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,C.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ie?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,k.https?`443 / 80`:String(k.port))}),(0,C.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,C.jsx)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:253,value:b,onChange:e=>ne(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,C.jsx)(`input`,{disabled:N||!!V,type:`number`,min:1024,max:65535,value:re,onChange:e=>x(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:2048,value:E,onChange:e=>O(e.target.value)})]})]}),(0,C.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!Q&&(0,C.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!V&&!Y&&(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:N||!G||!v||!L||z||!!v.busy||!Q,onClick:()=>void q(),children:n(N?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||ee||!Q,onClick:()=>{if(!Q||!Z||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:M(Z,v,g,g===`remote`?k:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,C.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),F&&(0,C.jsxs)(`div`,{role:`alert`,children:[(0,C.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),V&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var N=`pi-web-ui:device-groups-changed`;function P(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function F(e,t,n){let r=await fetch(l(i(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||a.message||`Request failed (${r.status})`);return a}function I(){let{locale:e}=g(),t=r(e),[i,o]=(0,S.useState)([]),[s,ee]=(0,S.useState)([]),[l,te]=(0,S.useState)(!0),[d,m]=(0,S.useState)(``),[_,y]=(0,S.useState)(``),[b,ne]=(0,S.useState)(0),[re,x]=(0,S.useState)(!1),[w,T]=(0,S.useState)(``),[E,D]=(0,S.useState)([]),[O,k]=(0,S.useState)(``),[A,j]=(0,S.useState)(null),[M,ie]=(0,S.useState)([]),[I,L]=(0,S.useState)(``),[R,z]=(0,S.useState)(null),[B,V]=(0,S.useState)(``),[H,U]=(0,S.useState)(!1),W=(0,S.useRef)(0);(0,S.useEffect)(()=>{let e=++W.current,t=new AbortController;async function n(){try{let[n,r]=await Promise.all([F(`rooms`,t.signal),F(`bots`,t.signal)]);if(W.current!==e||t.signal.aborted)return;o(Array.isArray(n.rooms)?n.rooms:[]),ee(Array.isArray(r.bots)?r.bots:[]),m(``)}catch(n){W.current===e&&!t.signal.aborted&&m(n instanceof Error?n.message:String(n))}finally{W.current===e&&!t.signal.aborted&&te(!1)}}return n(),()=>{t.abort()}},[b]),(0,S.useEffect)(()=>{let e=()=>ne(e=>e+1);return window.addEventListener(N,e),()=>window.removeEventListener(N,e)},[]);async function G(e){if(e.preventDefault(),!w.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{let e=E.includes(O)?O:``,r=await F(`rooms`,n.signal,{name:w.trim(),botIds:E,...e?{primaryBotId:e}:{}});o(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),T(``),D([]),k(``),y(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}function K(e){j(e.id),ie([...e.botIds]),L(e.primaryBotId??``),z(null),x(!1),m(``),y(``)}async function q(e){if(H)return;U(!0),m(``),y(``);let n=new AbortController;try{let r=M.includes(I)?I:null,i=await F(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});o(t=>t.map(t=>t.id===e?i.room:t)),j(null),y(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function J(e){if(!B.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:B.trim()}),o(t=>t.map(t=>t.id===e?{...t,name:B.trim()}:t)),z(null),y(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function Y(e){if(H||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),o(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),R===e.id&&z(null),y(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}return(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,i.length]}),(0,C.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>{x(e=>!e),j(null),z(null),T(``),D([]),k(``)},children:[(0,C.jsx)(c,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:()=>ne(e=>e+1),children:(0,C.jsx)(v,{})})]})]}),d&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:d}),_&&(0,C.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),_]}),re&&(0,C.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:G,children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,C.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:w,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>T(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot,请先创建 Bot。`:`No Bots available. Please create a Bot first.`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:E.includes(e.id),disabled:H||!e.enabled,onChange:t=>{D(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),E.length>0&&(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-new-primary`,value:E.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>E.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!w.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:t?`取消`:`Cancel`})]})]}),A&&(0,C.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,i.find(e=>e.id===A)?.name]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:H,onChange:t=>{ie(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(I)?I:``,onChange:e=>L(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>M.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>void q(A),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:t?`取消`:`Cancel`})]})]}),l&&(0,C.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!l&&i.length===0&&(0,C.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:t?`还没有群聊,点击上方“新建群聊”开始协作。`:`No groups yet. Click 'Create Group' above to get started.`}),(0,C.jsx)(`div`,{className:`dd-list`,children:i.map(e=>{let r=R===e.id,i=s.filter(t=>e.botIds.includes(t.id)),o=s.find(t=>t.id===e.primaryBotId);return(0,C.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,C.jsx)(`span`,{children:t?`${e.botIds.length} 个 Bot${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`:`${e.botIds.length} Bots${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`}),o&&(0,C.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${o.name}]`:`[Primary: ${o.name}]`})]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>P(e.id),children:[(0,C.jsx)(a,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>K(e),children:[(0,C.jsx)(f,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?z(null):(z(e.id),V(e.name))},children:[(0,C.jsx)(u,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:H,onClick:()=>void Y(e),children:(0,C.jsx)(p,{"aria-hidden":!0})})]}),r&&(0,C.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),J(e.id)},children:[(0,C.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:H,value:B,onChange:e=>V(e.target.value),placeholder:t?`输入新群名称`:`Enter new name`,style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!B.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:H,onClick:()=>z(null),children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})})]})}var L=class extends Error{status;constructor(e,t){super(t),this.status=e}};function R(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function z(){let e=te(),t=_().startsWith(`zh`),[n,r]=(0,S.useState)(null),[a,o]=(0,S.useState)(!1),[s,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),[f,p]=(0,S.useState)(!1),m=(0,S.useRef)(0),h=(0,S.useRef)(null);async function g(e,t){if(h.current)return;let n=++m.current,a=new AbortController;h.current=a,o(!0),c(!1);try{let o=await fetch(l(i(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(m.current!==n||a.signal.aborted)return;if(o.status===403){d(!0),r(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(m.current!==n||a.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);r(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`);r(s)}}catch{m.current===n&&!a.signal.aborted&&c(!0)}finally{m.current===n&&!a.signal.aborted&&(h.current=null,o(!1))}}return(0,S.useEffect)(()=>(g(`status`),()=>{m.current++,h.current?.abort(),h.current=null}),[]),(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,C.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),u?(0,C.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,C.jsxs)(C.Fragment,{children:[n&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,C.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,C.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,C.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,C.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,C.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),f&&(0,C.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),s&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void g(`status`),children:[(0,C.jsx)(v,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function B({pathCompletions:e=[]}){let r=te(),[a,c]=(0,S.useState)(null),[u,f]=(0,S.useState)(``),[p,h]=(0,S.useState)(``),[g,_]=(0,S.useState)(null),[y,b]=(0,S.useState)(!1),[T,E]=(0,S.useState)(Date.now()),[D,O]=(0,S.useState)(null),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)(``),[N,P]=(0,S.useState)(``),[F,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(!0),U=(0,S.useRef)(!1),W=(0,S.useRef)(0),G=(0,S.useRef)(new Set),K=(0,S.useRef)(!1),q=(0,S.useRef)(!1),J=(0,S.useRef)(null),Y=(0,S.useRef)(r);Y.current=r,(0,S.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&J.current?.deviceId===t.detail.deviceId&&(c(e=>e&&{...e,remark:t.detail.remark}),J.current&&(J.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 X(e,t){let n=new AbortController;G.current.add(n);try{let r=await fetch(l(i(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw new L(r.status,typeof a.error==`string`?a.error:Y.current(`deviceHubRequestFailed`,{status:r.status}));return a}finally{G.current.delete(n)}}function Z(e){return U.current&&W.current===e}function Q(e){return e instanceof L&&e.status===403?(B(!0),Y.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:Y.current(`deviceHubNetworkError`)}function ae(e){J.current=e,c(e),q.current||(h(e.name),f(e.hubUrl??``))}async function oe(){let e=W.current;try{let t=await X(`status`);if(!Z(e)||K.current)return;ae(t),M(``),B(!1)}catch(t){Z(e)&&M(Q(t))}finally{Z(e)&&H(!1)}}(0,S.useEffect)(()=>{U.current=!0;let e=!1,t,n=async()=>{await oe(),!e&&U.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,U.current=!1,W.current++,clearTimeout(t);for(let e of G.current)e.abort()}},[]),(0,S.useEffect)(()=>{if(!g)return;let e=W.current,t=!1,n,r=setInterval(()=>E(Date.now()),1e3),i=async()=>{if(!(t||!Z(e)||Date.now()>=g.expiresAt)){try{let n=await X(`poll`,{});if(t||!Z(e))return;if(n.paired){let n=await X(`status`);if(t||!Z(e))return;q.current=!1,ae(n),_(null),A(``),P(``);return}A(``)}catch(n){!t&&Z(e)&&A(`${Y.current(`deviceHubPollError`)} ${Q(n)}`)}!t&&Z(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[g]);async function se(){if(K.current)return;let e=R(u.trim());if(!e){A(r(`deviceHubInvalidUrl`));return}if(!p.trim()||p.trim().length>80){A(r(`deviceHubInvalidName`));return}let t=++W.current;K.current=!0,O(`pair`),A(``),P(``),_(null);try{let n=await X(`pair`,{hubUrl:e,name:p.trim()});if(!Z(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!R(n.hubUrl))throw Error(r(`deviceHubPairError`));E(Date.now()),_(n)}catch(e){Z(t)&&A(`${r(`deviceHubPairError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ce(){let e=J.current;if(!e?.deviceId||K.current)return;let t=++W.current;K.current=!0,O(`permission`),A(``),P(``),ae({...e,allowExecution:!e.allowExecution});try{await X(`execution`,{allowExecution:!e.allowExecution}),Z(t)&&P(r(`deviceHubSaved`))}catch(n){Z(t)&&(ae(e),A(`${r(`deviceHubPermissionError`)} ${Q(n)}`))}finally{Z(t)&&(K.current=!1,O(null))}}async function le(){let e=J.current;if(!e?.deviceId||K.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++W.current;K.current=!0,O(`disconnect`),A(``),P(``);try{if(await X(`disconnect`,{}),!Z(t))return;q.current=!1,ae({name:e.name,allowExecution:!1,connected:!1}),_(null)}catch(e){Z(t)&&A(`${r(`deviceHubDisconnectError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ue(){if(!g)return;let e=W.current;try{await navigator.clipboard.writeText(g.code),Z(e)&&P(r(`deviceHubCopied`))}catch{Z(e)&&A(r(`deviceHubCopyFailed`))}}let $=!!a?.deviceId,de=R($?a?.hubUrl??``:g?.hubUrl??``),fe=Math.max(0,Math.ceil(((g?.expiresAt??0)-T)/1e3)),pe=`${Math.floor(fe/60)}:${String(fe%60).padStart(2,`0`)}`,me=de?(0,C.jsxs)(w,{href:de,children:[(0,C.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,C.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,C.jsxs)(`header`,{className:`dc-header`,children:[(0,C.jsxs)(`div`,{className:`dc-heading`,children:[(0,C.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,C.jsx)(ee,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,C.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[$&&me,(0,C.jsxs)(`span`,{className:`dc-status ${$?a?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,C.jsx)(`span`,{className:`dc-status-dot`}),r($?a?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,C.jsx)(`div`,{className:`dc-layout`,style:{display:`block`},children:(0,C.jsxs)(`main`,{className:`dc-content`,children:[V&&(0,C.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(F||j)&&(0,C.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,C.jsx)(`span`,{children:F?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${j}`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void oe(),children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),k&&!F&&(0,C.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:k}),N&&(0,C.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),N]}),!$&&(a||F)&&(0,C.jsx)(ie,{initialHubUrl:u,onConnect:e=>{if(F){P(r(`deviceHubLocalOnly`));return}q.current=!0,f(e),b(!0)}}),a&&!F&&!$&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(d,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,C.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,C.jsxs)(`li`,{className:g?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,C.jsx)(`span`,{className:`dc-step-number`,children:g&&t===0?(0,C.jsx)(n,{"aria-hidden":!0}):t+1}),(0,C.jsx)(`span`,{children:r(e)})]},e))}),(0,C.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),se()},children:[(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:u,disabled:!!g||!!D,onChange:e=>{q.current=!0,f(e.target.value)}})]}),(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,C.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:p,disabled:!!g||!!D,onChange:e=>{q.current=!0,h(e.target.value)}})]}),!g&&(0,C.jsx)(`div`,{className:`dc-actions`,children:(0,C.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!D,children:[(0,C.jsx)(d,{"aria-hidden":!0}),r(D?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),g&&(0,C.jsxs)(`div`,{className:`dc-pairing`,children:[(0,C.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,C.jsxs)(`div`,{className:`dc-code-row`,children:[(0,C.jsx)(`code`,{className:`dc-code`,children:g.code}),(0,C.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void ue(),children:(0,C.jsx)(o,{"aria-hidden":!0})})]}),(0,C.jsx)(`div`,{className:`dc-pair-meta`,children:r(fe?`deviceHubExpires`:`deviceHubExpired`,{time:pe})}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[me,(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!D,onClick:()=>{++W.current,_(null),A(``),P(``)},children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),fe>0&&(0,C.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&a&&!F&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:a.remark?.trim()||a.name}),(0,C.jsx)(`p`,{children:a.remark?.trim()?`${a.name} · ${r(`deviceHubDeviceTitle`)}`:r(`deviceHubDeviceTitle`)})]})]}),(0,C.jsxs)(`dl`,{className:`dc-details`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,C.jsx)(`dd`,{children:a.deviceId})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`dd`,{children:a.hubUrl})]})]})]}),$&&a?.hubUrl&&a.deviceId&&!F&&(0,C.jsx)(ne,{hubUrl:a.hubUrl,currentDeviceId:a.deviceId},`directory:${a.hubUrl}:${a.deviceId}`),!F&&(0,C.jsx)(re,{pathCompletions:e},`bots:${a?.hubUrl??``}:${a?.deviceId??`unpaired`}`),$&&!F&&(0,C.jsx)(I,{}),(0,C.jsx)(z,{}),$&&a&&!F&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(s,{"aria-hidden":!0})}),(0,C.jsx)(`div`,{children:(0,C.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,C.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${a.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":a.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!D,onClick:()=>void ce(),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,C.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(D===`permission`?`deviceHubSaving`:a.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,C.jsx)(x,{hubUrl:a?.hubUrl,deviceId:a?.deviceId,onNotice:P}),(0,C.jsxs)(`details`,{className:`dc-advanced`,children:[(0,C.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,C.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,C.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,C.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!D,onClick:()=>void le(),children:r(D===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,C.jsxs)(`aside`,{className:`dc-help`,children:[(0,C.jsx)(m,{className:`dc-help-icon`,"aria-hidden":!0}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})})]})}export{B as DeviceCenter};
@@ -1,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Cn as r,Dn as i,Dt as a,H as o,Jt as s,Mt as ee,Rt as c,Tn as l,Z as u,bn as te,bt as d,cn as f,nn as p,pt as m,un as h,vn as g,yn as _,zt as v}from"./app-globals-CZxzGvIo.js";import{i as y,t as b}from"./react-CR5VJ85Q.js";import{Vt as ne,gt as re}from"./index-CuN802Sj.js";import{t as x}from"./DeviceExecutionSettings-q5Ik8oXg.js";var S=e(y(),1),C=b();function w({href:e,children:t}){let n=te(),[r,i]=(0,S.useState)(!1),[a,o]=(0,S.useState)(!1);return(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,C.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function T(e){if(!E(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 E(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 D(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 O=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,k=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,A=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function j(e){let t=e=>e.includes(`:`)?E(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?E(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(`:`))||e.https&&!e.domain)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 M(e,t,n,r){if(!T(e))throw Error(`Invalid Hub setup`);if(r){let t=j(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: ${O} (fallback: ${k}). If unavailable, report that and obtain its contents before proceeding.`,`Default to HTTP with the server IP and requested port. Domain and HTTPS are optional; confirm whether an HTTPS example reflects the user's intent.`,`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 explicitly selected: ${r.https}. HTTP inbound TCP port: ${r.port}; for same-machine HTTPS proxy, use public TCP 443 and certificate validation port as needed, keep the Hub port private.`]:[],`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: ${A}`,`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
- `)}function ie({onConnect:e,initialHubUrl:t=``}){let n=te(),[r,a]=(0,S.useState)(t),[o,s]=(0,S.useState)(``),[ee,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),f=(0,S.useRef)(!1),p=(0,S.useRef)(!1);(0,S.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[m,h]=(0,S.useState)(null),[g,_]=(0,S.useState)(`current`),[v,y]=(0,S.useState)(null),[b,ne]=(0,S.useState)(`127.0.0.1`),[re,x]=(0,S.useState)(`8790`),[E,O]=(0,S.useState)(`http://127.0.0.1:8790`),[k,A]=(0,S.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ie=j(k),[N,P]=(0,S.useState)(!1),[F,I]=(0,S.useState)(!1),[L,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(null),U=(0,S.useRef)(null),W=(0,S.useRef)(!1),G=D(window.location.origin);(0,S.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,I(!1),R(!1),B(!1);try{let t=await fetch(l(i(`/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`||!T({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;y(n),n.installation?.installed?(ne(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),O(n.installation.publicUrl??``),a(n.installation.publicUrl??``)):v||(x(String(n.defaultPort)),O(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),B(!0))}finally{e.signal.aborted||R(!0)}},q=async()=>{let e={host:b,port:Number(re),publicUrl:E};if(W.current||!G||!v||!L||z||v.busy||v.installation?.installed||!T(e))return;W.current=!0,U.current?.abort(),P(!0),I(!1),s(``);let t=new AbortController;U.current=t;try{let n=await fetch(l(i(`/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){y(e=>e&&{...e,busy:!0}),W.current=!1,P(!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(!T({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||H(r)}catch(e){t.signal.aborted||(I(!0),s(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||P(!1)}},J=v?.installation,Y=!!J?.installed,X=Y&&J.running&&J.owned,Z=g===`remote`?ie:{host:b,port:Number(re),publicUrl:E},Q=!!Z&&T(Z);return(0,C.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,C.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&G&&K()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,C.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>a(e.target.value),placeholder:`https://hub.example.com`})]}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:!T({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,C.jsxs)(`select`,{disabled:N,value:g,onChange:e=>_(e.target.value),children:[(0,C.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,C.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,C.jsxs)(`dl`,{children:[(0,C.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,C.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,C.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,C.jsx)(`dd`,{children:v.dataDir}),(0,C.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,C.jsx)(`dd`,{children:v.cliPath})]}),!G&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupBackground`)}),Y&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(X?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,C.jsx)(`p`,{children:J.publicUrl}),X&&Q&&J.publicUrl?(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
- pi-web-ui hub --help`})]})]}),v?.busy&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||!L,onClick:()=>void K(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:k.server,onChange:e=>A({...k,server:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,C.jsx)(`input`,{type:`number`,min:1,max:65535,value:k.sshPort,onChange:e=>A({...k,sshPort:Number(e.target.value)})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:k.username,onChange:e=>A({...k,username:e.target.value})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,C.jsxs)(`select`,{value:k.auth,onChange:e=>A({...k,auth:e.target.value}),children:[(0,C.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,C.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,C.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,C.jsx)(`input`,{type:`number`,min:1024,max:65535,value:k.port,onChange:e=>A({...k,port:Number(e.target.value)})})]})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,C.jsxs)(`details`,{children:[(0,C.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,C.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:k.domain,onChange:e=>A({...k,domain:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:k.https,onChange:e=>A({...k,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,C.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ie?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,k.https?`443 / 80`:String(k.port))}),(0,C.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,C.jsx)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:253,value:b,onChange:e=>ne(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,C.jsx)(`input`,{disabled:N||!!V,type:`number`,min:1024,max:65535,value:re,onChange:e=>x(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:2048,value:E,onChange:e=>O(e.target.value)})]})]}),(0,C.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!Q&&(0,C.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!V&&!Y&&(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:N||!G||!v||!L||z||!!v.busy||!Q,onClick:()=>void q(),children:n(N?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||ee||!Q,onClick:()=>{if(!Q||!Z||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:M(Z,v,g,g===`remote`?k:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,C.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),F&&(0,C.jsxs)(`div`,{role:`alert`,children:[(0,C.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),V&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var N=`pi-web-ui:device-groups-changed`;function P(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function F(e,t,n){let r=await fetch(l(i(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||a.message||`Request failed (${r.status})`);return a}function I(){let{locale:e}=g(),t=r(e),[i,o]=(0,S.useState)([]),[s,ee]=(0,S.useState)([]),[l,te]=(0,S.useState)(!0),[d,m]=(0,S.useState)(``),[_,y]=(0,S.useState)(``),[b,ne]=(0,S.useState)(0),[re,x]=(0,S.useState)(!1),[w,T]=(0,S.useState)(``),[E,D]=(0,S.useState)([]),[O,k]=(0,S.useState)(``),[A,j]=(0,S.useState)(null),[M,ie]=(0,S.useState)([]),[I,L]=(0,S.useState)(``),[R,z]=(0,S.useState)(null),[B,V]=(0,S.useState)(``),[H,U]=(0,S.useState)(!1),W=(0,S.useRef)(0);(0,S.useEffect)(()=>{let e=++W.current,t=new AbortController;async function n(){try{let[n,r]=await Promise.all([F(`rooms`,t.signal),F(`bots`,t.signal)]);if(W.current!==e||t.signal.aborted)return;o(Array.isArray(n.rooms)?n.rooms:[]),ee(Array.isArray(r.bots)?r.bots:[]),m(``)}catch(n){W.current===e&&!t.signal.aborted&&m(n instanceof Error?n.message:String(n))}finally{W.current===e&&!t.signal.aborted&&te(!1)}}return n(),()=>{t.abort()}},[b]),(0,S.useEffect)(()=>{let e=()=>ne(e=>e+1);return window.addEventListener(N,e),()=>window.removeEventListener(N,e)},[]);async function G(e){if(e.preventDefault(),!w.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{let e=E.includes(O)?O:``,r=await F(`rooms`,n.signal,{name:w.trim(),botIds:E,...e?{primaryBotId:e}:{}});o(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),T(``),D([]),k(``),y(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}function K(e){j(e.id),ie([...e.botIds]),L(e.primaryBotId??``),z(null),x(!1),m(``),y(``)}async function q(e){if(H)return;U(!0),m(``),y(``);let n=new AbortController;try{let r=M.includes(I)?I:null,i=await F(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});o(t=>t.map(t=>t.id===e?i.room:t)),j(null),y(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function J(e){if(!B.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:B.trim()}),o(t=>t.map(t=>t.id===e?{...t,name:B.trim()}:t)),z(null),y(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function Y(e){if(H||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),o(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),R===e.id&&z(null),y(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}return(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,i.length]}),(0,C.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>{x(e=>!e),j(null),z(null),T(``),D([]),k(``)},children:[(0,C.jsx)(c,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:()=>ne(e=>e+1),children:(0,C.jsx)(v,{})})]})]}),d&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:d}),_&&(0,C.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),_]}),re&&(0,C.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:G,children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,C.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:w,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>T(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot,请先创建 Bot。`:`No Bots available. Please create a Bot first.`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:E.includes(e.id),disabled:H||!e.enabled,onChange:t=>{D(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),E.length>0&&(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-new-primary`,value:E.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>E.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!w.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:t?`取消`:`Cancel`})]})]}),A&&(0,C.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,i.find(e=>e.id===A)?.name]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:H,onChange:t=>{ie(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(I)?I:``,onChange:e=>L(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>M.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>void q(A),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:t?`取消`:`Cancel`})]})]}),l&&(0,C.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!l&&i.length===0&&(0,C.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:t?`还没有群聊,点击上方“新建群聊”开始协作。`:`No groups yet. Click 'Create Group' above to get started.`}),(0,C.jsx)(`div`,{className:`dd-list`,children:i.map(e=>{let r=R===e.id,i=s.filter(t=>e.botIds.includes(t.id)),o=s.find(t=>t.id===e.primaryBotId);return(0,C.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,C.jsx)(`span`,{children:t?`${e.botIds.length} 个 Bot${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`:`${e.botIds.length} Bots${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`}),o&&(0,C.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${o.name}]`:`[Primary: ${o.name}]`})]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>P(e.id),children:[(0,C.jsx)(a,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>K(e),children:[(0,C.jsx)(f,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?z(null):(z(e.id),V(e.name))},children:[(0,C.jsx)(u,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:H,onClick:()=>void Y(e),children:(0,C.jsx)(p,{"aria-hidden":!0})})]}),r&&(0,C.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),J(e.id)},children:[(0,C.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:H,value:B,onChange:e=>V(e.target.value),placeholder:t?`输入新群名称`:`Enter new name`,style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!B.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:H,onClick:()=>z(null),children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})})]})}var L=class extends Error{status;constructor(e,t){super(t),this.status=e}};function R(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function z(){let e=te(),t=_().startsWith(`zh`),[n,r]=(0,S.useState)(null),[a,o]=(0,S.useState)(!1),[s,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),[f,p]=(0,S.useState)(!1),m=(0,S.useRef)(0),h=(0,S.useRef)(null);async function g(e,t){if(h.current)return;let n=++m.current,a=new AbortController;h.current=a,o(!0),c(!1);try{let o=await fetch(l(i(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(m.current!==n||a.signal.aborted)return;if(o.status===403){d(!0),r(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(m.current!==n||a.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);r(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`);r(s)}}catch{m.current===n&&!a.signal.aborted&&c(!0)}finally{m.current===n&&!a.signal.aborted&&(h.current=null,o(!1))}}return(0,S.useEffect)(()=>(g(`status`),()=>{m.current++,h.current?.abort(),h.current=null}),[]),(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,C.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),u?(0,C.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,C.jsxs)(C.Fragment,{children:[n&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,C.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,C.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,C.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,C.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,C.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),f&&(0,C.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),s&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void g(`status`),children:[(0,C.jsx)(v,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function B({pathCompletions:e=[]}){let r=te(),[a,c]=(0,S.useState)(null),[u,f]=(0,S.useState)(``),[p,h]=(0,S.useState)(``),[g,_]=(0,S.useState)(null),[y,b]=(0,S.useState)(!1),[T,E]=(0,S.useState)(Date.now()),[D,O]=(0,S.useState)(null),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)(``),[N,P]=(0,S.useState)(``),[F,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(!0),U=(0,S.useRef)(!1),W=(0,S.useRef)(0),G=(0,S.useRef)(new Set),K=(0,S.useRef)(!1),q=(0,S.useRef)(!1),J=(0,S.useRef)(null),Y=(0,S.useRef)(r);Y.current=r,(0,S.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&J.current?.deviceId===t.detail.deviceId&&(c(e=>e&&{...e,remark:t.detail.remark}),J.current&&(J.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 X(e,t){let n=new AbortController;G.current.add(n);try{let r=await fetch(l(i(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw new L(r.status,typeof a.error==`string`?a.error:Y.current(`deviceHubRequestFailed`,{status:r.status}));return a}finally{G.current.delete(n)}}function Z(e){return U.current&&W.current===e}function Q(e){return e instanceof L&&e.status===403?(B(!0),Y.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:Y.current(`deviceHubNetworkError`)}function ae(e){J.current=e,c(e),q.current||(h(e.name),f(e.hubUrl??``))}async function oe(){let e=W.current;try{let t=await X(`status`);if(!Z(e)||K.current)return;ae(t),M(``),B(!1)}catch(t){Z(e)&&M(Q(t))}finally{Z(e)&&H(!1)}}(0,S.useEffect)(()=>{U.current=!0;let e=!1,t,n=async()=>{await oe(),!e&&U.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,U.current=!1,W.current++,clearTimeout(t);for(let e of G.current)e.abort()}},[]),(0,S.useEffect)(()=>{if(!g)return;let e=W.current,t=!1,n,r=setInterval(()=>E(Date.now()),1e3),i=async()=>{if(!(t||!Z(e)||Date.now()>=g.expiresAt)){try{let n=await X(`poll`,{});if(t||!Z(e))return;if(n.paired){let n=await X(`status`);if(t||!Z(e))return;q.current=!1,ae(n),_(null),A(``),P(``);return}A(``)}catch(n){!t&&Z(e)&&A(`${Y.current(`deviceHubPollError`)} ${Q(n)}`)}!t&&Z(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[g]);async function se(){if(K.current)return;let e=R(u.trim());if(!e){A(r(`deviceHubInvalidUrl`));return}if(!p.trim()||p.trim().length>80){A(r(`deviceHubInvalidName`));return}let t=++W.current;K.current=!0,O(`pair`),A(``),P(``),_(null);try{let n=await X(`pair`,{hubUrl:e,name:p.trim()});if(!Z(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!R(n.hubUrl))throw Error(r(`deviceHubPairError`));E(Date.now()),_(n)}catch(e){Z(t)&&A(`${r(`deviceHubPairError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ce(){let e=J.current;if(!e?.deviceId||K.current)return;let t=++W.current;K.current=!0,O(`permission`),A(``),P(``),ae({...e,allowExecution:!e.allowExecution});try{await X(`execution`,{allowExecution:!e.allowExecution}),Z(t)&&P(r(`deviceHubSaved`))}catch(n){Z(t)&&(ae(e),A(`${r(`deviceHubPermissionError`)} ${Q(n)}`))}finally{Z(t)&&(K.current=!1,O(null))}}async function le(){let e=J.current;if(!e?.deviceId||K.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++W.current;K.current=!0,O(`disconnect`),A(``),P(``);try{if(await X(`disconnect`,{}),!Z(t))return;q.current=!1,ae({name:e.name,allowExecution:!1,connected:!1}),_(null)}catch(e){Z(t)&&A(`${r(`deviceHubDisconnectError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ue(){if(!g)return;let e=W.current;try{await navigator.clipboard.writeText(g.code),Z(e)&&P(r(`deviceHubCopied`))}catch{Z(e)&&A(r(`deviceHubCopyFailed`))}}let $=!!a?.deviceId,de=R($?a?.hubUrl??``:g?.hubUrl??``),fe=Math.max(0,Math.ceil(((g?.expiresAt??0)-T)/1e3)),pe=`${Math.floor(fe/60)}:${String(fe%60).padStart(2,`0`)}`,me=de?(0,C.jsxs)(w,{href:de,children:[(0,C.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,C.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,C.jsxs)(`header`,{className:`dc-header`,children:[(0,C.jsxs)(`div`,{className:`dc-heading`,children:[(0,C.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,C.jsx)(ee,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,C.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[$&&me,(0,C.jsxs)(`span`,{className:`dc-status ${$?a?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,C.jsx)(`span`,{className:`dc-status-dot`}),r($?a?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,C.jsx)(`div`,{className:`dc-layout`,style:{display:`block`},children:(0,C.jsxs)(`main`,{className:`dc-content`,children:[V&&(0,C.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(F||j)&&(0,C.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,C.jsx)(`span`,{children:F?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${j}`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void oe(),children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),k&&!F&&(0,C.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:k}),N&&(0,C.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),N]}),!$&&(a||F)&&(0,C.jsx)(ie,{initialHubUrl:u,onConnect:e=>{if(F){P(r(`deviceHubLocalOnly`));return}q.current=!0,f(e),b(!0)}}),a&&!F&&!$&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(d,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,C.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,C.jsxs)(`li`,{className:g?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,C.jsx)(`span`,{className:`dc-step-number`,children:g&&t===0?(0,C.jsx)(n,{"aria-hidden":!0}):t+1}),(0,C.jsx)(`span`,{children:r(e)})]},e))}),(0,C.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),se()},children:[(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:u,disabled:!!g||!!D,onChange:e=>{q.current=!0,f(e.target.value)}})]}),(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,C.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:p,disabled:!!g||!!D,onChange:e=>{q.current=!0,h(e.target.value)}})]}),!g&&(0,C.jsx)(`div`,{className:`dc-actions`,children:(0,C.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!D,children:[(0,C.jsx)(d,{"aria-hidden":!0}),r(D?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),g&&(0,C.jsxs)(`div`,{className:`dc-pairing`,children:[(0,C.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,C.jsxs)(`div`,{className:`dc-code-row`,children:[(0,C.jsx)(`code`,{className:`dc-code`,children:g.code}),(0,C.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void ue(),children:(0,C.jsx)(o,{"aria-hidden":!0})})]}),(0,C.jsx)(`div`,{className:`dc-pair-meta`,children:r(fe?`deviceHubExpires`:`deviceHubExpired`,{time:pe})}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[me,(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!D,onClick:()=>{++W.current,_(null),A(``),P(``)},children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),fe>0&&(0,C.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&a&&!F&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:a.remark?.trim()||a.name}),(0,C.jsx)(`p`,{children:a.remark?.trim()?`${a.name} · ${r(`deviceHubDeviceTitle`)}`:r(`deviceHubDeviceTitle`)})]})]}),(0,C.jsxs)(`dl`,{className:`dc-details`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,C.jsx)(`dd`,{children:a.deviceId})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`dd`,{children:a.hubUrl})]})]})]}),$&&a?.hubUrl&&a.deviceId&&!F&&(0,C.jsx)(ne,{hubUrl:a.hubUrl,currentDeviceId:a.deviceId},`directory:${a.hubUrl}:${a.deviceId}`),!F&&(0,C.jsx)(re,{pathCompletions:e},`bots:${a?.hubUrl??``}:${a?.deviceId??`unpaired`}`),$&&!F&&(0,C.jsx)(I,{}),(0,C.jsx)(z,{}),$&&a&&!F&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(s,{"aria-hidden":!0})}),(0,C.jsx)(`div`,{children:(0,C.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,C.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${a.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":a.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!D,onClick:()=>void ce(),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,C.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(D===`permission`?`deviceHubSaving`:a.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,C.jsx)(x,{hubUrl:a?.hubUrl,deviceId:a?.deviceId,onNotice:P}),(0,C.jsxs)(`details`,{className:`dc-advanced`,children:[(0,C.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,C.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,C.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,C.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!D,onClick:()=>void le(),children:r(D===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,C.jsxs)(`aside`,{className:`dc-help`,children:[(0,C.jsx)(m,{className:`dc-help-icon`,"aria-hidden":!0}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})})]})}export{B as DeviceCenter};