personal-bot 0.2.3 → 0.2.5

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 (234) hide show
  1. package/CONTEXT.md +13 -7
  2. package/README.md +46 -9
  3. package/README.zh-CN.md +46 -9
  4. package/bin/pbot.mjs +3 -0
  5. package/docs/README.md +4 -1
  6. package/docs/agent-collaboration.md +26 -12
  7. package/docs/architecture-guidelines.md +2 -2
  8. package/docs/capability-design.md +6 -4
  9. package/docs/dsh-implementation-plan.md +158 -0
  10. package/docs/dsh-support-proposal.md +314 -0
  11. package/docs/dsh.md +103 -0
  12. package/docs/file-storage.md +14 -9
  13. package/docs/history.md +29 -18
  14. package/docs/installation-design.md +226 -0
  15. package/docs/interaction-design.md +13 -0
  16. package/docs/release.md +5 -5
  17. package/docs/technical-design.md +29 -15
  18. package/docs/validation.md +53 -3
  19. package/lib/client.js +1071 -0
  20. package/lib/common/files.d.ts +2 -0
  21. package/lib/common/files.js +44 -0
  22. package/lib/common/json.d.ts +6 -0
  23. package/lib/common/json.js +16 -0
  24. package/lib/common/markdown.d.ts +5 -0
  25. package/lib/common/markdown.js +26 -0
  26. package/lib/common/package-source.js +16 -0
  27. package/lib/common/paths.d.ts +1 -0
  28. package/lib/common/paths.js +2 -0
  29. package/lib/common/validation.d.ts +3 -0
  30. package/lib/common/validation.js +14 -0
  31. package/lib/common/version.d.ts +3 -0
  32. package/lib/common/version.js +13 -0
  33. package/lib/dsh.d.ts +4 -0
  34. package/lib/dsh.js +22 -0
  35. package/lib/extension/dsh/agent-events.d.ts +24 -0
  36. package/lib/extension/dsh/agent-events.js +242 -0
  37. package/lib/extension/dsh/agent-runtime.d.ts +49 -0
  38. package/lib/extension/dsh/agent-runtime.js +348 -0
  39. package/lib/extension/dsh/command.d.ts +4 -0
  40. package/lib/extension/dsh/command.js +83 -0
  41. package/lib/extension/dsh/files.d.ts +5 -0
  42. package/lib/extension/dsh/files.js +67 -0
  43. package/lib/extension/dsh/history.d.ts +15 -0
  44. package/lib/extension/dsh/history.js +88 -0
  45. package/lib/extension/dsh/management.d.ts +21 -0
  46. package/lib/extension/dsh/management.js +217 -0
  47. package/lib/extension/dsh/workspace.d.ts +48 -0
  48. package/lib/extension/dsh/workspace.js +290 -0
  49. package/lib/extension/setup-cli.js +136 -0
  50. package/lib/extension/setup-guard.js +11 -0
  51. package/lib/integrations/agent-resources.d.ts +1 -0
  52. package/lib/integrations/agent-resources.js +18 -0
  53. package/lib/integrations/dsh/dsh-agents.d.ts +30 -0
  54. package/lib/integrations/dsh/dsh-agents.js +104 -0
  55. package/lib/integrations/dsh/history-summary.d.ts +11 -0
  56. package/lib/integrations/dsh/history-summary.js +40 -0
  57. package/lib/integrations/dsh/history.d.ts +16 -0
  58. package/lib/integrations/dsh/history.js +156 -0
  59. package/lib/integrations/dsh/input.d.ts +21 -0
  60. package/lib/integrations/dsh/input.js +62 -0
  61. package/lib/integrations/dsh/messages.d.ts +36 -0
  62. package/lib/integrations/dsh/messages.js +11 -0
  63. package/lib/integrations/dsh/notifications.d.ts +8 -0
  64. package/lib/integrations/dsh/notifications.js +55 -0
  65. package/lib/integrations/dsh/resources.d.ts +10 -0
  66. package/lib/integrations/dsh/resources.js +41 -0
  67. package/lib/integrations/dsh/schema.d.ts +7 -0
  68. package/lib/integrations/dsh/schema.js +28 -0
  69. package/lib/integrations/dsh/session.d.ts +14 -0
  70. package/lib/integrations/dsh/session.js +59 -0
  71. package/lib/integrations/history-summary.d.ts +2 -0
  72. package/lib/integrations/history-summary.js +21 -0
  73. package/lib/integrations/installation/pi-bridge.js +131 -0
  74. package/lib/integrations/installation/pi-setup.js +193 -0
  75. package/lib/integrations/installation/processes.js +155 -0
  76. package/lib/integrations/installation/workspace.js +21 -0
  77. package/lib/integrations/process.d.ts +14 -0
  78. package/lib/integrations/process.js +48 -0
  79. package/lib/integrations/python-activation.d.ts +2 -0
  80. package/lib/integrations/python-activation.js +29 -0
  81. package/lib/integrations/team-context.d.ts +18 -0
  82. package/lib/integrations/team-context.js +57 -0
  83. package/lib/model/agent.d.ts +92 -0
  84. package/lib/model/agent.js +1 -0
  85. package/lib/model/history.d.ts +43 -0
  86. package/lib/model/history.js +1 -0
  87. package/lib/model/team.d.ts +85 -0
  88. package/lib/model/team.js +1 -0
  89. package/lib/services/agents/agent-notices.d.ts +13 -0
  90. package/lib/services/agents/agent-notices.js +25 -0
  91. package/lib/services/agents/agent-run.d.ts +39 -0
  92. package/lib/services/agents/agent-run.js +138 -0
  93. package/lib/services/agents/agent-service.d.ts +166 -0
  94. package/lib/services/agents/agent-service.js +325 -0
  95. package/lib/services/agents/team-service.d.ts +168 -0
  96. package/lib/services/agents/team-service.js +343 -0
  97. package/lib/services/history/history-service.d.ts +103 -0
  98. package/lib/services/history/history-service.js +269 -0
  99. package/lib/services/installation/setup-service.js +121 -0
  100. package/lib/services/workspace/python-environment-service.d.ts +15 -0
  101. package/lib/services/workspace/python-environment-service.js +50 -0
  102. package/lib/services/workspace/workspace-files.d.ts +2 -0
  103. package/lib/services/workspace/workspace-files.js +17 -0
  104. package/lib/services/workspace/workspace-preparation.d.ts +2 -0
  105. package/lib/services/workspace/workspace-preparation.js +18 -0
  106. package/lib/storage/agent-files.d.ts +30 -0
  107. package/lib/storage/agent-files.js +166 -0
  108. package/lib/storage/atomic-json.d.ts +11 -0
  109. package/lib/storage/atomic-json.js +101 -0
  110. package/lib/storage/file-access.d.ts +2 -0
  111. package/lib/storage/file-access.js +26 -0
  112. package/lib/storage/history-files.d.ts +10 -0
  113. package/lib/storage/history-files.js +63 -0
  114. package/lib/storage/team-files.d.ts +16 -0
  115. package/lib/storage/team-files.js +111 -0
  116. package/lib/tools/agents/actions.d.ts +52 -0
  117. package/lib/tools/agents/actions.js +49 -0
  118. package/lib/tools/agents/contract.d.ts +163 -0
  119. package/lib/tools/agents/contract.js +56 -0
  120. package/lib/tools/agents/dsh-contract.d.ts +52 -0
  121. package/lib/tools/agents/dsh-contract.js +15 -0
  122. package/lib/tools/agents/dsh-tool.d.ts +5 -0
  123. package/lib/tools/agents/dsh-tool.js +38 -0
  124. package/lib/tools/history/actions.d.ts +70 -0
  125. package/lib/tools/history/actions.js +7 -0
  126. package/lib/tools/history/contract.d.ts +81 -0
  127. package/lib/tools/history/contract.js +32 -0
  128. package/lib/tools/history/dsh-tool.d.ts +4 -0
  129. package/lib/tools/history/dsh-tool.js +22 -0
  130. package/lib/tools/result.d.ts +18 -0
  131. package/lib/tools/result.js +10 -0
  132. package/lib/tools/teams/actions.d.ts +24 -0
  133. package/lib/tools/teams/actions.js +38 -0
  134. package/lib/tools/teams/contract.d.ts +232 -0
  135. package/lib/tools/teams/contract.js +67 -0
  136. package/lib/tools/teams/dsh-tool.d.ts +8 -0
  137. package/lib/tools/teams/dsh-tool.js +49 -0
  138. package/lib/ui/dsh/attachments.d.ts +5 -0
  139. package/lib/ui/dsh/attachments.js +39 -0
  140. package/lib/ui/dsh/elements.d.ts +17 -0
  141. package/lib/ui/dsh/elements.js +79 -0
  142. package/lib/ui/dsh/index.d.ts +4 -0
  143. package/lib/ui/dsh/index.js +13 -0
  144. package/lib/ui/dsh/management.d.ts +4 -0
  145. package/lib/ui/dsh/management.js +711 -0
  146. package/lib/ui/dsh/remote.d.ts +15 -0
  147. package/lib/ui/dsh/remote.js +11 -0
  148. package/lib/ui/dsh/styles.d.ts +1 -0
  149. package/lib/ui/dsh/styles.js +132 -0
  150. package/lib/ui/presentation.d.ts +3 -0
  151. package/lib/ui/presentation.js +12 -0
  152. package/lib/ui/setup.js +52 -0
  153. package/npm-shrinkwrap.json +11118 -783
  154. package/package.json +113 -9
  155. package/python/README.md +6 -6
  156. package/resources/agents/coordinator.md +1 -1
  157. package/resources/dsh/cordis.patch.yml +3 -0
  158. package/resources/installer/plugins.json +16 -0
  159. package/resources/prompts/workspace.md +1 -1
  160. package/resources/references/compute.md +1 -1
  161. package/resources/references/task-conductor.md +6 -4
  162. package/resources/skills/provider-connections/SKILL.md +10 -0
  163. package/scripts/README.md +13 -1
  164. package/src/common/package-source.ts +16 -0
  165. package/src/dsh.ts +22 -0
  166. package/src/extension/agent-events.ts +51 -46
  167. package/src/extension/agents-command.ts +48 -34
  168. package/src/extension/command.ts +42 -23
  169. package/src/extension/dsh/agent-events.ts +148 -0
  170. package/src/extension/dsh/agent-runtime.ts +251 -0
  171. package/src/extension/dsh/command.ts +78 -0
  172. package/src/extension/dsh/files.ts +61 -0
  173. package/src/extension/dsh/history.ts +69 -0
  174. package/src/extension/dsh/management.ts +108 -0
  175. package/src/extension/dsh/workspace.ts +206 -0
  176. package/src/extension/events.ts +6 -4
  177. package/src/extension/history.ts +15 -12
  178. package/src/extension/setup-cli.ts +109 -0
  179. package/src/extension/setup-guard.ts +12 -0
  180. package/src/extension/subagent-entry.ts +34 -63
  181. package/src/extension/teams-command.ts +53 -46
  182. package/src/integrations/{pi/agent-resources.ts → agent-resources.ts} +2 -2
  183. package/src/integrations/dsh/dsh-agents.ts +97 -0
  184. package/src/integrations/dsh/history-summary.ts +43 -0
  185. package/src/integrations/dsh/history.ts +76 -0
  186. package/src/integrations/dsh/input.ts +66 -0
  187. package/src/integrations/dsh/messages.ts +22 -0
  188. package/src/integrations/dsh/notifications.ts +46 -0
  189. package/src/integrations/dsh/resources.ts +44 -0
  190. package/src/integrations/dsh/schema.ts +26 -0
  191. package/src/integrations/dsh/session.ts +67 -0
  192. package/src/integrations/history-summary.ts +20 -0
  193. package/src/integrations/installation/pi-bridge.ts +107 -0
  194. package/src/integrations/installation/pi-setup.ts +162 -0
  195. package/src/integrations/installation/processes.ts +124 -0
  196. package/src/integrations/installation/workspace.ts +18 -0
  197. package/src/integrations/pi/history.ts +4 -14
  198. package/src/integrations/pi/pi-agents.ts +17 -6
  199. package/src/integrations/pi/team-context.ts +6 -58
  200. package/src/integrations/team-context.ts +60 -0
  201. package/src/model/agent.ts +2 -0
  202. package/src/model/history.ts +3 -1
  203. package/src/pbot.ts +1 -1
  204. package/src/services/agents/agent-notices.ts +28 -0
  205. package/src/services/agents/agent-run.ts +114 -0
  206. package/src/services/agents/agent-service.ts +127 -64
  207. package/src/services/history/history-service.ts +120 -59
  208. package/src/services/installation/setup-service.ts +145 -0
  209. package/src/storage/agent-files.ts +17 -4
  210. package/src/storage/history-files.ts +30 -5
  211. package/src/tools/agents/actions.ts +47 -0
  212. package/src/tools/agents/contract.ts +8 -5
  213. package/src/tools/agents/dsh-contract.ts +16 -0
  214. package/src/tools/agents/dsh-tool.ts +41 -0
  215. package/src/tools/agents/tool.ts +7 -43
  216. package/src/tools/history/actions.ts +9 -0
  217. package/src/tools/history/contract.ts +34 -0
  218. package/src/tools/history/dsh-tool.ts +22 -0
  219. package/src/tools/history/tool.ts +7 -30
  220. package/src/tools/teams/actions.ts +38 -0
  221. package/src/tools/teams/contract.ts +7 -3
  222. package/src/tools/teams/dsh-tool.ts +55 -0
  223. package/src/tools/teams/tool.ts +6 -31
  224. package/src/ui/agent-display.ts +7 -4
  225. package/src/ui/dsh/attachments.ts +42 -0
  226. package/src/ui/dsh/elements.ts +50 -0
  227. package/src/ui/dsh/index.ts +18 -0
  228. package/src/ui/dsh/management.ts +412 -0
  229. package/src/ui/dsh/remote.ts +20 -0
  230. package/src/ui/dsh/styles.ts +132 -0
  231. package/src/ui/pi/menu.ts +37 -0
  232. package/src/ui/pi/reader.ts +46 -0
  233. package/src/ui/presentation.ts +12 -0
  234. package/src/ui/setup.ts +40 -0
package/lib/client.js ADDED
@@ -0,0 +1,1071 @@
1
+ window.__ModuleLoader__.load({ id: "personal-bot", factory: (require) => { var module = { exports: {} }; var exports = module.exports;
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name2 in all)
9
+ __defProp(target, name2, { get: all[name2], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/ui/dsh/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ apply: () => apply,
25
+ inject: () => inject,
26
+ name: () => name
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/common/json.ts
31
+ function object(value2) {
32
+ return value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
33
+ }
34
+ function canonical(value2) {
35
+ if (value2 === null || typeof value2 === "boolean" || typeof value2 === "string") return JSON.stringify(value2);
36
+ if (typeof value2 === "number" && Number.isFinite(value2)) return JSON.stringify(value2);
37
+ if (Array.isArray(value2)) return "[" + value2.map(canonical).join(",") + "]";
38
+ if (object(value2) && (Object.getPrototypeOf(value2) === Object.prototype || Object.getPrototypeOf(value2) === null)) {
39
+ return "{" + Object.keys(value2).sort().map((key) => JSON.stringify(key) + ":" + canonical(value2[key])).join(",") + "}";
40
+ }
41
+ throw new Error("\u9700\u8981\u6709\u9650\u3001\u53EF\u5E8F\u5217\u5316\u7684 JSON \u503C\u3002");
42
+ }
43
+ function json(value2) {
44
+ return JSON.parse(canonical(value2));
45
+ }
46
+
47
+ // src/ui/dsh/remote.ts
48
+ var value = { mode: "strict", typeSymbol: "personal-bot#Json", create: () => ({ parse: json }) };
49
+ var pbotReadRemote = {
50
+ package: "personal-bot",
51
+ descriptors: ["snapshot", "expert", "team", "history"].map((method) => ({
52
+ id: "personal-bot#PbotManagement." + method,
53
+ service: "pbotManagement",
54
+ namespace: "pbot",
55
+ method,
56
+ invocation: { kind: "direct" },
57
+ parameters: [{ name: "request", wire: "request", source: "json", codec: value }],
58
+ cancellation: { parameter: "signal" },
59
+ result: value
60
+ }))
61
+ };
62
+
63
+ // src/ui/dsh/attachments.ts
64
+ var images = /* @__PURE__ */ new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
65
+ function encodedImage(file, signal) {
66
+ signal.throwIfAborted();
67
+ return new Promise((resolve, reject) => {
68
+ const reader = new FileReader(), abort = () => reader.abort();
69
+ signal.addEventListener("abort", abort, { once: true });
70
+ reader.onloadend = () => signal.removeEventListener("abort", abort);
71
+ reader.onerror = () => reject(reader.error ?? new Error("\u56FE\u7247\u8BFB\u53D6\u5931\u8D25\u3002"));
72
+ reader.onabort = () => reject(signal.reason ?? new DOMException("\u56FE\u7247\u8BFB\u53D6\u5DF2\u53D6\u6D88\u3002", "AbortError"));
73
+ reader.onload = () => {
74
+ if (typeof reader.result !== "string") reject(new Error("\u56FE\u7247\u8BFB\u53D6\u5931\u8D25\u3002"));
75
+ else resolve(reader.result.slice(reader.result.indexOf(",") + 1));
76
+ };
77
+ reader.readAsDataURL(file);
78
+ });
79
+ }
80
+ async function commandAttachments(ctx, sessionId, files, signal, progress) {
81
+ if (files.length > 32) throw new Error("\u4E00\u6B21\u6700\u591A\u9644\u52A0 32 \u4E2A\u6587\u4EF6\u3002");
82
+ const attachments = [];
83
+ for (const file of files) {
84
+ signal.throwIfAborted();
85
+ progress("\u6B63\u5728\u51C6\u5907\u9644\u4EF6\uFF1A" + file.name);
86
+ if (images.has(file.type)) {
87
+ attachments.push({ type: "image", mediaType: file.type, name: file.name, data: await encodedImage(file, signal) });
88
+ } else {
89
+ const result = await ctx.fileUpload.upload(
90
+ sessionId,
91
+ file,
92
+ file.name,
93
+ signal,
94
+ (value2) => progress(`\u6B63\u5728\u4E0A\u4F20 ${file.name}\uFF1A${value2.loaded} / ${value2.total ?? file.size} \u5B57\u8282`)
95
+ );
96
+ if (!result.ok) throw new Error(result.error.message);
97
+ attachments.push({ type: "file", receiptId: result.value.receiptId });
98
+ }
99
+ }
100
+ signal.throwIfAborted();
101
+ return attachments;
102
+ }
103
+
104
+ // src/ui/presentation.ts
105
+ var states = {
106
+ starting: "\u542F\u52A8\u4E2D",
107
+ busy: "\u6267\u884C\u4E2D",
108
+ idle: "\u5F85\u547D",
109
+ stopping: "\u505C\u6B62\u4E2D",
110
+ stopped: "\u5DF2\u505C\u6B62",
111
+ error: "\u9700\u8981\u5904\u7406",
112
+ running: "\u8FDB\u884C\u4E2D",
113
+ paused: "\u5DF2\u6682\u505C",
114
+ finished: "\u5DF2\u7ED3\u675F",
115
+ completed: "\u5DF2\u5B8C\u6210",
116
+ failed: "\u5931\u8D25",
117
+ cancelled: "\u5DF2\u53D6\u6D88",
118
+ interrupted: "\u5DF2\u4E2D\u65AD",
119
+ ready: "\u5DF2\u5C31\u7EEA",
120
+ preparing: "\u51C6\u5907\u4E2D",
121
+ unprepared: "\u672A\u51C6\u5907",
122
+ open: "\u5F85\u5B89\u6392",
123
+ closed: "\u5DF2\u5173\u95ED"
124
+ };
125
+ var stateLabel = (state) => states[String(state)] ?? String(state ?? "\u672A\u77E5");
126
+
127
+ // src/ui/dsh/elements.ts
128
+ var record = (value2) => {
129
+ if (!object(value2)) throw new Error("\u7BA1\u7406\u6570\u636E\u65E0\u6548\u3002");
130
+ return value2;
131
+ };
132
+ var rows = (value2) => Array.isArray(value2) ? value2.map(record) : [];
133
+ var text = (value2) => value2 === null || value2 === void 0 ? "" : String(value2);
134
+ var objectInput = (value2) => record(JSON.parse(value2 || "{}"));
135
+ var lines = (value2) => value2.split(/\r?\n/).map((item) => item.trim()).filter(Boolean);
136
+ function element(tag, content = "", className = "") {
137
+ const node = document.createElement(tag);
138
+ node.textContent = content;
139
+ node.className = className;
140
+ return node;
141
+ }
142
+ function block(value2) {
143
+ return element("pre", typeof value2 === "string" ? value2 : JSON.stringify(value2, null, 2), "pbot-prose");
144
+ }
145
+ function note(value2) {
146
+ return element("p", value2, "pbot-muted");
147
+ }
148
+ function group(parent, className = "pbot-stack") {
149
+ const node = element("div", "", className);
150
+ parent.append(node);
151
+ return node;
152
+ }
153
+ function details(parent, title) {
154
+ const node = element("details", "", "pbot-disclosure");
155
+ node.append(element("summary", title));
156
+ parent.append(node);
157
+ return node;
158
+ }
159
+ function field(parent, label, multiline = false, value2 = "") {
160
+ const wrapper = element("label", "", "pbot-field"), input = multiline ? element("textarea") : element("input");
161
+ wrapper.append(element("span", label));
162
+ input.value = value2;
163
+ input.setAttribute("aria-label", label);
164
+ if (input instanceof HTMLTextAreaElement) input.rows = 3;
165
+ wrapper.append(input);
166
+ parent.append(wrapper);
167
+ return input;
168
+ }
169
+ function select(parent, label, values) {
170
+ const wrapper = element("label", "", "pbot-field"), input = element("select");
171
+ wrapper.append(element("span", label));
172
+ input.setAttribute("aria-label", label);
173
+ for (const [value2, title] of values) {
174
+ const option = element("option", title);
175
+ option.value = value2;
176
+ input.append(option);
177
+ }
178
+ wrapper.append(input);
179
+ parent.append(wrapper);
180
+ return input;
181
+ }
182
+ function badge(state) {
183
+ const node = element("span", stateLabel(state), "pbot-badge");
184
+ node.dataset.state = text(state);
185
+ return node;
186
+ }
187
+ function facts(values) {
188
+ const node = element("dl", "", "pbot-facts");
189
+ for (const [label, value2] of values) node.append(element("dt", label), element("dd", text(value2) || "\u2014"));
190
+ return node;
191
+ }
192
+ function empty(title, description) {
193
+ const node = element("div", "", "pbot-empty");
194
+ node.append(element("h3", title), note(description));
195
+ return node;
196
+ }
197
+ function pageTitle(parent, title, description) {
198
+ const node = element("header", "", "pbot-page-title");
199
+ node.append(element("h2", title));
200
+ if (description) node.append(note(description));
201
+ parent.append(node);
202
+ return node;
203
+ }
204
+ function time(value2) {
205
+ const date = new Date(typeof value2 === "number" ? value2 : text(value2));
206
+ return Number.isNaN(date.getTime()) ? "" : date.toLocaleString(void 0, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
207
+ }
208
+
209
+ // src/ui/dsh/styles.ts
210
+ var managementStyles = `
211
+ .pbot-management {
212
+ --pbot-bg: var(--dsw-alias-bg-base, #f8f9fb);
213
+ --pbot-surface: var(--dsw-alias-bg-layer-1, #fff);
214
+ --pbot-ink: var(--dsw-alias-label-primary, #20232b);
215
+ --pbot-muted: var(--dsw-alias-label-secondary, #696e79);
216
+ --pbot-line: var(--dsw-alias-border-l2, #e3e5eb);
217
+ --pbot-accent: var(--dsw-alias-brand-primary, #4d6bfe);
218
+ --pbot-tint: color-mix(in srgb, var(--pbot-accent) 9%, var(--pbot-surface));
219
+ --pbot-danger: var(--dsw-alias-state-error-primary, #c93535);
220
+ width: min(1180px, calc(100vw - 48px)); height: min(820px, calc(100dvh - 64px));
221
+ max-width: none; max-height: none; padding: 0; margin: auto; overflow: hidden;
222
+ border: 1px solid var(--pbot-line); border-radius: 12px; color: var(--pbot-ink); background: var(--pbot-surface);
223
+ box-shadow: 0 12px 40px #0002; font: 14px/1.55 var(--dsw-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
224
+ }
225
+ .pbot-management::backdrop { background: #10182866; }
226
+ .pbot-management *, .pbot-management *::before, .pbot-management *::after { box-sizing: border-box; }
227
+ .pbot-management [hidden] { display: none !important; }
228
+ .pbot-management h2, .pbot-management h3, .pbot-management h4, .pbot-management p { margin: 0; }
229
+ .pbot-management h2 { font-size: 21px; font-weight: 600; }
230
+ .pbot-management h3 { font-size: 16px; font-weight: 600; }
231
+ .pbot-management h4 { font-size: 14px; font-weight: 600; }
232
+ .pbot-management button, .pbot-management input, .pbot-management textarea, .pbot-management select { font: inherit; color: inherit; }
233
+ .pbot-management button { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 7px 13px; border: 1px solid var(--pbot-line); border-radius: 8px; background: var(--pbot-surface); cursor: pointer; line-height: 1.4; }
234
+ .pbot-management button:hover:not(:disabled) { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }
235
+ .pbot-management button:disabled { opacity: .45; cursor: not-allowed; }
236
+ .pbot-management :is(button, input, textarea, select, summary):focus-visible { outline: 2px solid var(--pbot-accent); outline-offset: 3px; }
237
+ .pbot-management button.pbot-primary { background: var(--pbot-accent); border-color: var(--pbot-accent); color: var(--pbot-surface); font-weight: 600; }
238
+ .pbot-management button.pbot-primary:hover:not(:disabled) { filter: brightness(.94); background: var(--pbot-accent); }
239
+ .pbot-management button.pbot-quiet { border-color: transparent; background: transparent; }
240
+ .pbot-management button.pbot-danger { color: var(--pbot-danger); }
241
+ .pbot-management button[data-busy=true]::after { content: "\u2026"; }
242
+ .pbot-shell { height: 100%; display: grid; grid-template-columns: 178px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
243
+ .pbot-header { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--pbot-line); }
244
+ .pbot-brand { font-size: 16px; font-weight: 650; letter-spacing: -.3px; }
245
+ .pbot-location { color: var(--pbot-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; max-width: 65vw; }
246
+ .pbot-header-copy { min-width: 0; flex: 1; }
247
+ .pbot-management .pbot-close { width: 34px; padding: 0; font-size: 22px; }
248
+ .pbot-nav { display: flex; flex-direction: column; gap: 6px; padding: 22px 12px; background: var(--pbot-bg); border-right: 1px solid var(--pbot-line); }
249
+ .pbot-nav button { text-align: left; justify-content: space-between; border-color: transparent; background: transparent; padding: 11px 12px; color: var(--pbot-muted); }
250
+ .pbot-nav button[aria-selected=true] { color: var(--pbot-accent); background: var(--pbot-tint); font-weight: 600; }
251
+ .pbot-nav small { font-size: 11px; font-variant-numeric: tabular-nums; opacity: .8; }
252
+ .pbot-main { min-width: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 26px 28px; }
253
+ .pbot-page-title { margin-bottom: 22px; display: grid; gap: 5px; }
254
+ .pbot-muted { color: var(--pbot-muted); font-size: 13px; overflow-wrap: anywhere; }
255
+ .pbot-footer { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 10px 22px; border-top: 1px solid var(--pbot-line); color: var(--pbot-muted); font-size: 12px; }
256
+ .pbot-footer > span { flex: 1; }
257
+ .pbot-footer button { min-height: 28px; padding: 4px 9px; font-size: 12px; }
258
+ .pbot-notice { position: sticky; top: -26px; z-index: 2; padding: 12px 14px; margin: -6px 0 18px; border: 1px solid var(--pbot-line); border-left: 3px solid var(--pbot-accent); background: var(--pbot-surface); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow-y: auto; }
259
+ .pbot-notice[data-tone=error] { border-left-color: var(--pbot-danger); }
260
+ .pbot-notice:empty { display: none; }
261
+ .pbot-stack { display: grid; gap: 16px; }
262
+ .pbot-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
263
+ .pbot-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
264
+ .pbot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
265
+ .pbot-counts { margin: -8px 0 20px !important; }
266
+ .pbot-setting { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 0; border-top: 1px solid var(--pbot-line); }
267
+ .pbot-setting > div { min-width: 0; }
268
+ .pbot-setting h3 { margin-bottom: 8px; }
269
+ .pbot-setting > button { flex-shrink: 0; }
270
+ .pbot-card { padding: 18px; border: 1px solid var(--pbot-line); border-radius: 12px; background: var(--pbot-surface); min-width: 0; }
271
+ .pbot-card > :is(h3, .pbot-between) { margin-bottom: 12px; }
272
+ .pbot-badge { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; color: var(--pbot-muted); background: var(--pbot-bg); padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; }
273
+ .pbot-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
274
+ .pbot-badge:is([data-state=busy],[data-state=running],[data-state=starting],[data-state=preparing]) { color: var(--pbot-accent); background: var(--pbot-tint); }
275
+ .pbot-badge:is([data-state=error],[data-state=failed]) { color: var(--pbot-danger); }
276
+ .pbot-badge:is([data-state=ready],[data-state=completed]) { color: var(--dsw-alias-state-success-primary, #26834b); }
277
+ .pbot-badge:is([data-state=paused],[data-state=stopping]) { color: var(--dsw-alias-state-warn-label, #9a6500); }
278
+ .pbot-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 18px; margin: 12px 0; font-size: 13px; }
279
+ .pbot-facts dt { color: var(--pbot-muted); }
280
+ .pbot-facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
281
+ .pbot-disclosure { margin: 16px 0; padding: 12px 14px; border: 1px solid var(--pbot-line); border-radius: 10px; }
282
+ .pbot-disclosure > summary { cursor: pointer; font-size: 13px; font-weight: 550; }
283
+ .pbot-disclosure[open] > summary { margin-bottom: 16px; }
284
+ .pbot-disclosure .pbot-disclosure { background: var(--pbot-bg); }
285
+ .pbot-field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; font-size: 13px; }
286
+ .pbot-field > span { font-weight: 500; }
287
+ .pbot-field :is(input,textarea,select) { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--pbot-line); border-radius: 7px; background: var(--pbot-surface); line-height: 1.5; }
288
+ .pbot-field input[type=file] { padding: 7px; font-size: 12px; }
289
+ .pbot-field input::file-selector-button { border: 0; padding: 5px 8px; margin-right: 10px; border-radius: 4px; background: var(--pbot-tint); color: var(--pbot-ink); cursor: pointer; }
290
+ .pbot-field textarea { resize: vertical; min-height: 84px; }
291
+ .pbot-field input::placeholder, .pbot-field textarea::placeholder { color: var(--pbot-muted); opacity: .8; }
292
+ .pbot-split { display: grid; grid-template-columns: minmax(180px, 230px) minmax(0, 1fr); gap: 22px; align-items: start; }
293
+ .pbot-list { display: grid; align-content: start; grid-auto-rows: max-content; gap: 6px; max-height: 470px; overflow-y: auto; padding: 3px; }
294
+ .pbot-management .pbot-list-item { display: block; width: 100%; text-align: left; padding: 12px; border: 1px solid transparent; min-width: 0; }
295
+ .pbot-list-item[aria-pressed=true] { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }
296
+ .pbot-list-item strong { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
297
+ .pbot-list-item .pbot-muted { margin-top: 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
298
+ .pbot-empty { padding: 38px 20px; border: 1px dashed var(--pbot-line); border-radius: 12px; text-align: center; display: grid; gap: 8px; }
299
+ .pbot-empty h3 { font-weight: 550; }
300
+ .pbot-empty button { justify-self: center; margin-top: 10px; }
301
+ .pbot-detail { min-width: 0; display: grid; gap: 18px; }
302
+ .pbot-detail-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
303
+ .pbot-prose { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 10px 0; line-height: 1.7; }
304
+ .pbot-raw { font: 12px/1.6 ui-monospace, SFMono-Regular, monospace; max-height: 340px; overflow: auto; }
305
+ .pbot-transcript { margin-top: 14px; }
306
+ .pbot-event { border-left: 2px solid var(--pbot-line); padding: 0 0 0 14px; margin: 18px 0; }
307
+ .pbot-event .pbot-prose { font-size: 13px; }
308
+ .pbot-event .pbot-row, .pbot-message .pbot-row { justify-content: space-between; }
309
+ .pbot-management .pbot-pagination { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0; color: var(--pbot-muted); font-size: 12px; }
310
+ .pbot-pagination button { font-size: 12px; min-height: 30px; padding: 5px 9px; }
311
+ .pbot-message { padding: 16px 0; border-bottom: 1px solid var(--pbot-line); }
312
+ .pbot-message:last-child { border-bottom: 0; }
313
+ .pbot-message .pbot-prose { font-size: 13px; }
314
+ .pbot-search { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto; gap: 12px; align-items: end; }
315
+ .pbot-search .pbot-field { margin: 0; }
316
+ .pbot-search > button { margin-bottom: 2px; }
317
+ .pbot-history-results { display: grid; gap: 10px; margin: 18px 0; }
318
+ .pbot-history-results article { border: 1px solid var(--pbot-line); border-radius: 10px; padding: 16px; }
319
+ .pbot-history-results article[aria-current=true] { border-color: var(--pbot-accent); }
320
+ .pbot-warning { border-left: 3px solid var(--dsw-alias-state-warn-primary, #ab7a15); padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
321
+ @media (max-width: 800px) {
322
+ .pbot-management { width: calc(100vw - 24px); height: calc(100dvh - 32px); border-radius: 12px; }
323
+ .pbot-shell { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr) auto; }
324
+ .pbot-nav { flex-direction: row; padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--pbot-line); }
325
+ .pbot-nav button { flex: 1; justify-content: center; padding: 8px; }
326
+ .pbot-nav small { display: none; }
327
+ .pbot-main { padding: 22px 18px; }
328
+ .pbot-notice { top: -22px; }
329
+ .pbot-header { padding: 14px 18px; }
330
+ .pbot-split { grid-template-columns: minmax(150px, 190px) minmax(0, 1fr); gap: 16px; }
331
+ }
332
+ @media (max-width: 600px) {
333
+ .pbot-management { width: calc(100vw - 12px); height: calc(100dvh - 16px); }
334
+ .pbot-grid, .pbot-split { grid-template-columns: minmax(0, 1fr); }
335
+ .pbot-list { max-height: 215px; }
336
+ .pbot-search { grid-template-columns: minmax(0, 1fr) 110px; }
337
+ .pbot-search > button { grid-column: 1 / -1; }
338
+ .pbot-footer { padding: 8px 14px; }
339
+ .pbot-location { max-width: 68vw; }
340
+ }
341
+ `;
342
+
343
+ // src/ui/dsh/management.ts
344
+ function showManagement(ctx, parentSessionId) {
345
+ const opener = document.activeElement, dialog = element("dialog"), style = element("style");
346
+ dialog.className = "pbot-management";
347
+ dialog.setAttribute("aria-label", "Personal Bot \u5DE5\u4F5C\u53F0");
348
+ style.textContent = managementStyles;
349
+ const shell = group(dialog, "pbot-shell"), header = element("header", "", "pbot-header");
350
+ shell.append(header);
351
+ const heading = group(header, "pbot-header-copy");
352
+ heading.append(element("div", "Personal Bot", "pbot-brand"));
353
+ const location = element("p", "\u6B63\u5728\u8BFB\u53D6\u5DE5\u4F5C\u533A\u2026", "pbot-location");
354
+ heading.append(location);
355
+ const nav = element("nav", "", "pbot-nav"), main = element("main", "", "pbot-main"), footer = element("footer", "", "pbot-footer");
356
+ nav.setAttribute("role", "tablist");
357
+ nav.setAttribute("aria-label", "\u5DE5\u4F5C\u53F0\u5BFC\u822A");
358
+ const notice = element("div", "", "pbot-notice"), connection = element("span", "\u6B63\u5728\u8FDE\u63A5\u2026");
359
+ notice.setAttribute("role", "status");
360
+ main.append(notice);
361
+ footer.append(connection);
362
+ shell.append(nav, main, footer);
363
+ dialog.prepend(style);
364
+ const lifetime = new AbortController();
365
+ let closed = false, timer, tab = "status";
366
+ let snapshot, expertId = "", teamId = "", expertOffset;
367
+ let snapshotRevision = 0, expertRevision = 0, teamRevision = 0, historyRevision = 0, recordRevision = 0;
368
+ let expertPageKey = "", teamPageKey = "", pollError = false;
369
+ const sections = /* @__PURE__ */ new Map(), tabs = /* @__PURE__ */ new Map(), tabCounts = /* @__PURE__ */ new Map();
370
+ function inform(message, tone = "info") {
371
+ if (closed) return;
372
+ notice.textContent = message;
373
+ notice.dataset.tone = tone;
374
+ notice.setAttribute("role", tone === "error" ? "alert" : "status");
375
+ }
376
+ function enabled(button2, value2) {
377
+ button2.dataset.unavailable = String(!value2);
378
+ button2.disabled = !value2 || button2.dataset.busy === "true";
379
+ }
380
+ async function attempt(button2, action) {
381
+ if (button2.dataset.busy === "true") return;
382
+ button2.dataset.busy = "true";
383
+ button2.disabled = true;
384
+ button2.setAttribute("aria-busy", "true");
385
+ try {
386
+ await action();
387
+ } catch (error) {
388
+ if (!lifetime.signal.aborted) inform(error instanceof Error ? error.message : String(error), "error");
389
+ } finally {
390
+ if (!closed) {
391
+ delete button2.dataset.busy;
392
+ button2.removeAttribute("aria-busy");
393
+ button2.disabled = button2.dataset.unavailable === "true";
394
+ }
395
+ }
396
+ }
397
+ function button(parent, title, action, className = "") {
398
+ const node = element("button", title, className);
399
+ node.type = "button";
400
+ node.addEventListener("click", () => {
401
+ void attempt(node, action);
402
+ });
403
+ parent.append(node);
404
+ return node;
405
+ }
406
+ function submit(form2, title, action) {
407
+ const node = element("button", title, "pbot-primary");
408
+ node.type = "submit";
409
+ form2.append(node);
410
+ form2.addEventListener("submit", (event) => {
411
+ event.preventDefault();
412
+ void attempt(node, action);
413
+ });
414
+ return node;
415
+ }
416
+ function form(parent) {
417
+ const node = element("form");
418
+ parent.append(node);
419
+ return node;
420
+ }
421
+ function activate(id) {
422
+ tab = id;
423
+ for (const [key, section2] of sections) section2.hidden = key !== id;
424
+ for (const [key, item] of tabs) {
425
+ item.setAttribute("aria-selected", String(key === id));
426
+ item.tabIndex = key === id ? 0 : -1;
427
+ }
428
+ main.scrollTop = 0;
429
+ }
430
+ function section(id, title) {
431
+ const node = element("section");
432
+ node.hidden = id !== tab;
433
+ node.id = `pbot-panel-${id}`;
434
+ node.setAttribute("role", "tabpanel");
435
+ node.setAttribute("aria-labelledby", `pbot-tab-${id}`);
436
+ main.append(node);
437
+ sections.set(id, node);
438
+ const control = button(nav, title, () => activate(id));
439
+ control.id = `pbot-tab-${id}`;
440
+ control.setAttribute("role", "tab");
441
+ control.setAttribute("aria-controls", node.id);
442
+ control.setAttribute("aria-selected", String(id === tab));
443
+ control.tabIndex = id === tab ? 0 : -1;
444
+ const count = element("small");
445
+ count.setAttribute("aria-hidden", "true");
446
+ control.append(count);
447
+ tabCounts.set(id, count);
448
+ tabs.set(id, control);
449
+ return node;
450
+ }
451
+ nav.addEventListener("keydown", (event) => {
452
+ const controls = [...tabs.values()], current = controls.indexOf(document.activeElement);
453
+ if (current < 0) return;
454
+ const index = event.key === "Home" ? 0 : event.key === "End" ? controls.length - 1 : ["ArrowRight", "ArrowDown"].includes(event.key) ? (current + 1) % controls.length : ["ArrowLeft", "ArrowUp"].includes(event.key) ? (current + controls.length - 1) % controls.length : -1;
455
+ if (index < 0) return;
456
+ event.preventDefault();
457
+ const id = [...tabs.keys()][index];
458
+ activate(id);
459
+ controls[index].focus();
460
+ });
461
+ async function query(method, input) {
462
+ lifetime.signal.throwIfAborted();
463
+ const result = await ctx.remote.pbot[method](json({ parentSessionId, ...input === void 0 ? {} : { input } }), lifetime.signal);
464
+ if (!result.ok) throw new Error(result.error.message);
465
+ lifetime.signal.throwIfAborted();
466
+ return record(result.value);
467
+ }
468
+ async function command(verb, input, message = "\u64CD\u4F5C\u5DF2\u63A5\u7EB3\u3002", attachments = []) {
469
+ const result = await ctx.remote.commands.execute(parentSessionId, "/pbot " + verb + (input === void 0 ? "" : " " + JSON.stringify(input)), attachments);
470
+ if (!result.ok) throw new Error(result.error.message + "\uFF1B\u5982\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u8BF7\u5148\u5237\u65B0\u8BB0\u5F55\u786E\u8BA4\u64CD\u4F5C\u662F\u5426\u5DF2\u63A5\u7EB3\u3002");
471
+ if (!result.value) throw new Error("\u7BA1\u7406\u547D\u4EE4\u672A\u88AB\u63A5\u7EB3\u3002");
472
+ if (result.value.result.kind === "error") throw new Error(result.value.result.text);
473
+ inform(message);
474
+ if (!closed) {
475
+ try {
476
+ await refresh();
477
+ } catch (error) {
478
+ inform("\u64CD\u4F5C\u5DF2\u63A5\u7EB3\uFF1B\u5237\u65B0\u72B6\u6001\u672A\u6210\u529F\uFF1A" + String(error), "error");
479
+ }
480
+ }
481
+ return result.value.result.text ?? "";
482
+ }
483
+ const status = section("status", "\u5DE5\u4F5C\u533A");
484
+ pageTitle(status, "\u5DE5\u4F5C\u533A", "");
485
+ const counts = note(""), workspaceInfo = group(status);
486
+ status.querySelector("header").after(counts);
487
+ counts.classList.add("pbot-counts");
488
+ const materials = group(status, "pbot-setting");
489
+ materials.append(element("h3", "\u8D44\u6599\u76EE\u5F55"));
490
+ button(materials, "\u51C6\u5907\u76EE\u5F55", async () => {
491
+ await command("init", void 0, "\u8D44\u6599\u76EE\u5F55\u5DF2\u51C6\u5907\u3002");
492
+ });
493
+ const pythonCard = group(status, "pbot-setting"), pythonInfo = group(pythonCard);
494
+ const pythonButton = button(pythonCard, "\u51C6\u5907 Python", async () => {
495
+ await command("python setup", void 0, "Python \u51C6\u5907\u5B8C\u6210\u3002");
496
+ });
497
+ const diagnostic = details(status, "\u73AF\u5883\u8BE6\u60C5"), statusBody = block("");
498
+ statusBody.classList.add("pbot-raw");
499
+ diagnostic.append(statusBody);
500
+ const experts = section("experts", "\u4E13\u5BB6");
501
+ pageTitle(experts, "\u4E13\u5BB6", "");
502
+ const create = details(experts, "\u521B\u5EFA\u4E13\u5BB6"), createForm = form(create), newName = field(createForm, "\u540D\u79F0"), initial = field(createForm, "\u4EFB\u52A1\uFF08\u53EF\u9009\uFF09", true);
503
+ newName.placeholder = "\u4F8B\u5982\uFF1A\u7814\u7A76\u5458";
504
+ initial.placeholder = "\u4EFB\u52A1\u76EE\u6807\u4E0E\u4EA4\u4ED8\u8981\u6C42";
505
+ const options = details(createForm, "\u6A21\u578B\u4E0E\u9009\u9879"), modelFields = group(options, "pbot-grid");
506
+ options.querySelector("summary").after(note("\u7559\u7A7A\u6CBF\u7528\u5F53\u524D\u4F1A\u8BDD\u3002"));
507
+ const provider = field(modelFields, "Provider"), model = field(modelFields, "\u6A21\u578B");
508
+ const effort = field(options, "Reasoning effort"), cwd = field(options, "\u5DE5\u4F5C\u76EE\u5F55");
509
+ const files = field(options, "\u6587\u4EF6\u8DEF\u5F84\uFF08\u6BCF\u884C\u4E00\u4E2A\uFF09", true);
510
+ const advanced = field(details(options, "\u5176\u4ED6\u9009\u9879"), "JSON", true, "{}");
511
+ submit(createForm, "\u521B\u5EFA", async () => {
512
+ const args = {
513
+ ...objectInput(advanced.value),
514
+ action: "start",
515
+ ...newName.value ? { name: newName.value } : {},
516
+ ...initial.value ? { message: initial.value } : {},
517
+ ...provider.value ? { provider: provider.value } : {},
518
+ ...model.value ? { model: model.value } : {},
519
+ ...effort.value ? { thinking: effort.value } : {},
520
+ ...cwd.value ? { cwd: cwd.value } : {},
521
+ ...lines(files.value).length ? { files: lines(files.value) } : {}
522
+ };
523
+ const output = objectInput(await command("agent", args, "\u4E13\u5BB6\u5DF2\u521B\u5EFA\u3002"));
524
+ if (initial.value === (args.message ?? "")) initial.value = "";
525
+ create.open = false;
526
+ await chooseExpert(text(output.agentId));
527
+ });
528
+ const expertSplit = group(experts, "pbot-split"), expertAside = group(expertSplit), expertFilter = field(expertAside, "\u7B5B\u9009\u4E13\u5BB6");
529
+ expertFilter.placeholder = "\u540D\u79F0\u6216\u72B6\u6001";
530
+ const expertList = group(expertAside, "pbot-list");
531
+ expertList.setAttribute("aria-label", "\u4E13\u5BB6\u5217\u8868");
532
+ const expertDetail = group(expertSplit, "pbot-detail"), expertEmpty = empty("\u9009\u62E9\u4E13\u5BB6", "\u67E5\u770B\u8BB0\u5F55\u6216\u53D1\u9001\u6D88\u606F\u3002");
533
+ expertDetail.append(expertEmpty);
534
+ const expertPanel = group(expertDetail);
535
+ expertPanel.hidden = true;
536
+ const expertHeading = group(expertPanel, "pbot-detail-title"), expertTitle = element("h3"), expertBadge = element("span");
537
+ expertHeading.append(expertTitle, expertBadge);
538
+ const expertInfo = group(expertPanel), expertError = element("p", "", "pbot-warning");
539
+ expertPanel.append(expertError);
540
+ expertError.hidden = true;
541
+ const expertControls = group(expertPanel, "pbot-row"), requireExpert = () => {
542
+ if (!expertId) throw new Error("\u8BF7\u5148\u9009\u62E9\u4E13\u5BB6\u3002");
543
+ return expertId;
544
+ };
545
+ const stopButton = button(expertControls, "\u505C\u6B62\u4E13\u5BB6", async () => {
546
+ await command("agent", { action: "stop", agentId: requireExpert() }, "\u5DF2\u8BF7\u6C42\u505C\u6B62\u4E13\u5BB6\u3002");
547
+ await loadExpert();
548
+ }, "pbot-danger");
549
+ const editExpert = details(expertPanel, "\u540D\u79F0\u4E0E\u4F1A\u8BDD\u8BE6\u60C5"), renameForm = form(editExpert), rename = field(renameForm, "\u65B0\u540D\u79F0");
550
+ rename.required = true;
551
+ submit(renameForm, "\u91CD\u547D\u540D", async () => {
552
+ await command("agent", { action: "rename", agentId: requireExpert(), name: rename.value }, "\u4E13\u5BB6\u540D\u79F0\u5DF2\u66F4\u65B0\u3002");
553
+ await loadExpert();
554
+ });
555
+ const expertState = block("");
556
+ expertState.classList.add("pbot-raw");
557
+ editExpert.append(expertState);
558
+ const resume = details(expertPanel, "\u6062\u590D\u4E13\u5BB6"), resumeForm = form(resume), resumeText = field(resumeForm, "\u65B0\u4EFB\u52A1", true);
559
+ resumeText.required = true;
560
+ const resumeButton = submit(resumeForm, "\u6062\u590D\u5E76\u53D1\u9001\u65B0\u4EFB\u52A1", async () => {
561
+ const message = resumeText.value;
562
+ await command("agent", { action: "resume", agentId: requireExpert(), message }, "\u4E13\u5BB6\u5DF2\u6062\u590D\uFF0C\u65B0\u4EFB\u52A1\u5DF2\u6392\u961F\u3002");
563
+ if (resumeText.value === message) resumeText.value = "";
564
+ await loadExpert();
565
+ });
566
+ const chatCard = group(expertPanel, "pbot-card");
567
+ chatCard.append(element("h3", "\u4EBA\u5DE5\u5BF9\u8BDD"), note("\u53D1\u9001\u524D\u6682\u505C\u56E2\u961F\u65B0\u5B89\u6392\u3002"));
568
+ const chatForm = form(chatCard), chat = field(chatForm, "\u6D88\u606F", true);
569
+ chat.maxLength = 24e3;
570
+ chat.placeholder = "\u8865\u5145\u8D44\u6599\u3001\u8C03\u6574\u65B9\u5411\uFF0C\u6216\u63D0\u51FA\u65B0\u95EE\u9898\u2026";
571
+ const delivery = select(chatForm, "\u6295\u9012\u65F6\u673A", [["steer", "\u4E0B\u4E00\u4E2A\u5B89\u5168\u6B65\u9AA4"], ["followUp", "\u4E0B\u4E00\u8F6E"]]);
572
+ const localFiles = field(chatForm, "\u9644\u4EF6");
573
+ localFiles.type = "file";
574
+ localFiles.multiple = true;
575
+ const chatFiles = field(details(chatForm, "\u670D\u52A1\u5668\u6587\u4EF6"), "\u8DEF\u5F84\uFF08\u6BCF\u884C\u4E00\u4E2A\uFF09", true);
576
+ const expertDrafts = /* @__PURE__ */ new Map();
577
+ function clearSentDraft(id, input, paths, chosen) {
578
+ const draft = expertDrafts.get(id);
579
+ if (draft) {
580
+ if (draft.text === input.text) draft.text = "";
581
+ if (draft.paths === paths) draft.paths = "";
582
+ if (draft.files.length === chosen.length && draft.files.every((file, index) => file === chosen[index])) draft.files = [];
583
+ }
584
+ }
585
+ const sendButton = submit(chatForm, "\u53D1\u9001\u4EBA\u5DE5\u6D88\u606F", async () => {
586
+ const id = requireExpert(), fileText = chatFiles.value, files2 = lines(fileText), chosen = Array.from(localFiles.files ?? []);
587
+ if (files2.length && chosen.length) throw new Error("\u4E00\u6B21\u5BF9\u8BDD\u8BF7\u9009\u62E9\u670D\u52A1\u5668\u6587\u4EF6\u6216\u672C\u673A\u9644\u4EF6\uFF0C\u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\u3002");
588
+ if (!chat.value.trim() && !files2.length && !chosen.length) {
589
+ chat.focus();
590
+ throw new Error("\u8BF7\u8F93\u5165\u6D88\u606F\u6216\u6DFB\u52A0\u9644\u4EF6\u3002");
591
+ }
592
+ const input = { agentId: id, text: chat.value, delivery: delivery.value, files: files2 };
593
+ const attachments = await commandAttachments(ctx, parentSessionId, chosen, lifetime.signal, inform);
594
+ lifetime.signal.throwIfAborted();
595
+ await command("chat", input, "\u6D88\u606F\u5DF2\u6392\u961F\uFF0C\u4E13\u5BB6\u4F1A\u5728\u6240\u9009\u65F6\u673A\u63A5\u6536\u3002", attachments);
596
+ clearSentDraft(id, input, fileText, chosen);
597
+ if (expertId === id) {
598
+ if (chat.value === input.text) chat.value = "";
599
+ if (chatFiles.value === fileText) chatFiles.value = "";
600
+ const current = Array.from(localFiles.files ?? []);
601
+ if (current.length === chosen.length && current.every((file, index) => file === chosen[index])) localFiles.value = "";
602
+ await loadExpert();
603
+ }
604
+ });
605
+ const transcript = group(expertPanel, "pbot-transcript");
606
+ transcript.append(element("h3", "\u5BF9\u8BDD\u4E0E\u6D3B\u52A8"));
607
+ const recordControls = group(transcript, "pbot-pagination"), eventList = group(transcript), rawEvents = details(transcript, "\u5168\u90E8\u539F\u751F\u4E8B\u4EF6"), rawEventList = group(rawEvents);
608
+ const eventDetail = details(transcript, "\u5B8C\u6574\u8BB0\u5F55"), eventBody = block(""), eventPaging = element("div", "", "pbot-pagination");
609
+ eventDetail.append(eventBody, eventPaging);
610
+ eventDetail.hidden = true;
611
+ async function chooseExpert(id) {
612
+ if (id !== expertId) {
613
+ if (expertId) expertDrafts.set(expertId, { text: chat.value, delivery: delivery.value, paths: chatFiles.value, files: Array.from(localFiles.files ?? []) });
614
+ const draft = expertDrafts.get(id);
615
+ chat.value = draft?.text ?? "";
616
+ delivery.value = draft?.delivery ?? "steer";
617
+ chatFiles.value = draft?.paths ?? "";
618
+ const transfer = new DataTransfer();
619
+ for (const file of draft?.files ?? []) transfer.items.add(file);
620
+ localFiles.files = transfer.files;
621
+ rename.value = "";
622
+ resumeText.value = "";
623
+ }
624
+ expertId = id;
625
+ expertOffset = void 0;
626
+ expertPageKey = "";
627
+ ++recordRevision;
628
+ ++expertRevision;
629
+ eventBody.textContent = "";
630
+ eventDetail.hidden = true;
631
+ eventPaging.replaceChildren();
632
+ expertPanel.hidden = true;
633
+ expertEmpty.hidden = false;
634
+ expertEmpty.replaceChildren(note("\u6B63\u5728\u8BFB\u53D6\u4E13\u5BB6\u8BB0\u5F55\u2026"));
635
+ renderLists();
636
+ await loadExpert();
637
+ }
638
+ function showExpert(agent) {
639
+ expertTitle.textContent = text(agent.name);
640
+ expertBadge.replaceChildren(badge(agent.state));
641
+ expertPanel.hidden = false;
642
+ expertEmpty.hidden = true;
643
+ const config = object(agent.options) ? agent.options : {};
644
+ expertInfo.replaceChildren(note(text(agent.activity) || "\u7B49\u5F85\u65B0\u7684\u4EFB\u52A1\u3002"), facts([["\u6A21\u578B", config.model || "\u7EE7\u627F\u7236\u4F1A\u8BDD"], ["\u5DE5\u4F5C\u76EE\u5F55", agent.cwd]]));
645
+ expertState.textContent = JSON.stringify(agent, null, 2);
646
+ expertError.textContent = text(agent.error);
647
+ expertError.hidden = !agent.error;
648
+ const alive = agent.alive === true, owned = agent.owned === true;
649
+ enabled(stopButton, owned && alive && agent.state !== "stopping");
650
+ enabled(sendButton, owned && alive && !["starting", "stopping"].includes(text(agent.state)));
651
+ enabled(resumeButton, owned && !alive);
652
+ resume.hidden = alive;
653
+ }
654
+ async function loadRecord(seq, offset = 0, format = "text") {
655
+ const revision = ++recordRevision, id = requireExpert(), data = await query("expert", { agentId: id, seq, textOffset: offset, format });
656
+ if (id !== expertId || revision !== recordRevision) return;
657
+ eventDetail.hidden = false;
658
+ eventDetail.open = true;
659
+ eventBody.textContent = text(data.text);
660
+ eventBody.classList.toggle("pbot-raw", format === "json");
661
+ eventPaging.replaceChildren(element("span", `\u8BB0\u5F55 ${seq} \xB7 ${offset + 1}\u2013${offset + text(data.text).length} / ${data.totalLength}`));
662
+ button(eventPaging, format === "text" ? "\u67E5\u770B\u539F\u59CB\u4E8B\u4EF6" : "\u67E5\u770B\u6B63\u6587", () => loadRecord(seq, 0, format === "text" ? "json" : "text"));
663
+ if (offset) button(eventPaging, "\u4ECE\u5934\u8BFB\u53D6", () => loadRecord(seq, 0, format));
664
+ if (typeof data.nextOffset === "number") button(eventPaging, "\u7EE7\u7EED\u8BFB\u53D6", () => loadRecord(seq, data.nextOffset, format));
665
+ }
666
+ async function loadExpert() {
667
+ if (!expertId) return;
668
+ const revision = ++expertRevision, id = expertId, data = await query("expert", { agentId: id, ...expertOffset === void 0 ? {} : { offset: expertOffset } });
669
+ if (id !== expertId || revision !== expertRevision) return;
670
+ showExpert(record(data.agent));
671
+ const actualOffset = Number(data.offset), key = `${id}:${data.cursor}:${actualOffset}`;
672
+ if (key === expertPageKey) return;
673
+ expertPageKey = key;
674
+ recordControls.replaceChildren();
675
+ button(recordControls, "\u6700\u65B0\u8BB0\u5F55", async () => {
676
+ expertOffset = void 0;
677
+ await loadExpert();
678
+ });
679
+ if (actualOffset > 0) button(recordControls, "\u4E0A\u4E00\u9875", async () => {
680
+ expertOffset = Math.max(0, actualOffset - 30);
681
+ await loadExpert();
682
+ });
683
+ if (typeof data.nextOffset === "number") button(recordControls, "\u4E0B\u4E00\u9875", async () => {
684
+ expertOffset = data.nextOffset;
685
+ await loadExpert();
686
+ });
687
+ recordControls.append(element("span", `${data.total} \u6761\u8BB0\u5F55 \xB7 \u4ECE ${actualOffset + 1} \u5F00\u59CB`));
688
+ const expanded = new Set(Array.from(rawEventList.querySelectorAll("details[open]")).map((item) => item.dataset.seq));
689
+ eventList.replaceChildren();
690
+ rawEventList.replaceChildren();
691
+ const labels = { "user/message": "\u8F93\u5165", "assistant/message": "\u4E13\u5BB6\u56DE\u590D", "tool/result": "\u5DE5\u5177\u7ED3\u679C", "turn/end": "\u672C\u8F6E\u7ED3\u675F" };
692
+ for (const event of rows(data.events)) {
693
+ const seq = Number(event.seq), label = event.type === "user/message" ? event.source === "user" ? "\u8F93\u5165" : event.source === "pbot-input" ? "\u4EFB\u52A1" : void 0 : labels[text(event.type)];
694
+ if (label && text(event.preview)) {
695
+ const item2 = element("article", "", "pbot-event"), meta = group(item2, "pbot-row");
696
+ meta.append(element("h4", label), note(time(event.time)));
697
+ item2.append(block(event.preview));
698
+ button(item2, "\u9605\u8BFB\u5168\u6587", () => loadRecord(seq), "pbot-quiet");
699
+ eventList.append(item2);
700
+ }
701
+ const item = details(rawEventList, `${seq} \xB7 ${event.type} \xB7 ${time(event.time)}`);
702
+ item.dataset.seq = text(seq);
703
+ item.open = expanded.has(text(seq));
704
+ item.append(block(event.preview));
705
+ button(item, "\u8BFB\u53D6\u4E8B\u4EF6", () => loadRecord(seq, 0, "json"));
706
+ }
707
+ if (!eventList.childElementCount) eventList.append(empty("\u8FD8\u6CA1\u6709\u5BF9\u8BDD\u5185\u5BB9", "\u53D1\u9001\u4EFB\u52A1\u540E\uFF0C\u53EF\u5728\u8FD9\u91CC\u67E5\u770B\u4E13\u5BB6\u7684\u56DE\u590D\u4E0E\u5DE5\u5177\u7ED3\u679C\u3002"));
708
+ }
709
+ const teams = section("teams", "\u56E2\u961F");
710
+ pageTitle(teams, "\u56E2\u961F", "");
711
+ const createTeam = details(teams, "\u521B\u5EFA\u56E2\u961F"), teamForm = form(createTeam), teamName = field(teamForm, "\u56E2\u961F\u540D\u79F0"), brief = field(teamForm, "\u5171\u540C\u76EE\u6807", true);
712
+ teamName.required = true;
713
+ brief.required = true;
714
+ teamName.placeholder = "\u4F8B\u5982\uFF1A\u6295\u8D44\u7814\u7A76\u5C0F\u7EC4";
715
+ teamForm.append(note("\u4E3A\u6210\u5458\u586B\u5199\u804C\u8D23\uFF0C\u7559\u7A7A\u5219\u4E0D\u52A0\u5165\u3002"));
716
+ const memberFields = group(teamForm);
717
+ submit(teamForm, "\u521B\u5EFA\u56E2\u961F", async () => {
718
+ const members = Array.from(memberFields.querySelectorAll("input[data-agent-id]")).filter((input) => input.value.trim()).map((input) => ({ agentId: input.dataset.agentId, role: input.value }));
719
+ const value2 = objectInput(await command("team", { action: "create", name: teamName.value, brief: brief.value, members }, "\u56E2\u961F\u5DF2\u521B\u5EFA\uFF0C\u53EF\u4EE5\u5B89\u6392\u9996\u4E2A\u6279\u6B21\u3002"));
720
+ createTeam.open = false;
721
+ await chooseTeam(text(value2.teamId));
722
+ });
723
+ const teamSplit = group(teams, "pbot-split"), teamList = group(teamSplit, "pbot-list"), teamDetail = group(teamSplit, "pbot-detail");
724
+ teamList.setAttribute("aria-label", "\u56E2\u961F\u5217\u8868");
725
+ const teamEmpty = empty("\u9009\u62E9\u56E2\u961F", "\u67E5\u770B\u8FDB\u5C55\u4E0E\u516C\u5171\u6D88\u606F\u3002"), teamPanel = group(teamDetail);
726
+ teamDetail.prepend(teamEmpty);
727
+ teamPanel.hidden = true;
728
+ const teamHeading = group(teamPanel, "pbot-detail-title"), teamTitle = element("h3"), teamBadge = element("span");
729
+ teamHeading.append(teamTitle, teamBadge);
730
+ const teamInfo = group(teamPanel), teamState = block("");
731
+ teamState.classList.add("pbot-raw");
732
+ const teamControls = group(teamPanel, "pbot-row"), requireTeam = () => {
733
+ if (!teamId) throw new Error("\u8BF7\u5148\u9009\u62E9\u56E2\u961F\u3002");
734
+ return teamId;
735
+ };
736
+ const pauseButton = button(teamControls, "\u6682\u505C\u65B0\u5B89\u6392", async () => {
737
+ await command("team", { action: "pause", teamId: requireTeam() }, "\u5DF2\u6682\u505C\u65B0\u5B89\u6392\uFF1B\u5728\u9014\u4EFB\u52A1\u4ECD\u53EF\u80FD\u5B8C\u6210\u3002");
738
+ await loadTeam();
739
+ });
740
+ const teamConfig = details(teamPanel, "\u6210\u5458\u4E0E\u56E2\u961F\u8BE6\u60C5");
741
+ teamConfig.append(teamState);
742
+ const closeTeamButton = button(teamConfig, "\u5173\u95ED\u56E2\u961F", async () => {
743
+ await command("team", { action: "close", teamId: requireTeam() }, "\u56E2\u961F\u5DF2\u5173\u95ED\uFF0C\u6210\u5458\u4E13\u5BB6\u4ECD\u53EF\u72EC\u7ACB\u4F7F\u7528\u3002");
744
+ await loadTeam();
745
+ }, "pbot-danger");
746
+ const batch = details(teamPanel, "\u65B0\u6279\u6B21"), batchForm = form(batch), instruction = field(batchForm, "\u4EFB\u52A1\u4E0E\u4EA4\u4ED8\u8981\u6C42", true);
747
+ instruction.required = true;
748
+ const batchOptions = group(batchForm, "pbot-grid"), mode = select(batchOptions, "\u8BA8\u8BBA\u6A21\u5F0F", [["roundRobin", "\u8F6E\u6D41\u8BA8\u8BBA"], ["parallel", "\u5E76\u884C\u8F6E\u6B21"]]);
749
+ const rounds = field(batchOptions, "\u6BCF\u4F4D\u6210\u5458\u8F6E\u6570", false, "2"), concurrency = field(batchOptions, "\u5E76\u53D1\u4E0A\u9650", false, "1"), timeout = field(batchOptions, "\u6574\u6279\u671F\u9650\uFF08\u79D2\uFF09", false, "900");
750
+ for (const [input, max] of [[rounds, 10], [concurrency, 50], [timeout, 86400]]) {
751
+ input.setAttribute("type", "number");
752
+ input.setAttribute("min", "1");
753
+ input.setAttribute("max", text(max));
754
+ input.required = true;
755
+ }
756
+ const runButton = submit(batchForm, "\u5F00\u59CB\u65B0\u6279\u6B21", async () => {
757
+ await command("team", {
758
+ action: "run",
759
+ teamId: requireTeam(),
760
+ instruction: instruction.value,
761
+ mode: mode.value,
762
+ rounds: Number(rounds.value),
763
+ maxConcurrent: Number(concurrency.value),
764
+ timeoutSeconds: Number(timeout.value)
765
+ }, "\u65B0\u6279\u6B21\u5DF2\u5F00\u59CB\u3002");
766
+ await loadTeam();
767
+ });
768
+ const publicCard = group(teamPanel, "pbot-card");
769
+ const postForm = form(publicCard), post = field(postForm, "\u516C\u5171\u6D88\u606F", true);
770
+ post.required = true;
771
+ const replyTo = field(details(postForm, "\u56DE\u590D\u6D88\u606F"), "\u56DE\u590D\u5E8F\u53F7");
772
+ replyTo.setAttribute("type", "number");
773
+ replyTo.setAttribute("min", "1");
774
+ const postButton = submit(postForm, "\u53D1\u5E03\u516C\u5171\u6D88\u606F", async () => {
775
+ const id = requireTeam(), message = post.value;
776
+ await command("post", { teamId: id, text: message, ...replyTo.value ? { replyTo: Number(replyTo.value) } : {} }, "\u516C\u5171\u6D88\u606F\u5DF2\u53D1\u5E03\u3002");
777
+ if (teamId === id && post.value === message) post.value = "";
778
+ const draft = teamDrafts.get(id);
779
+ if (draft?.text === message) draft.text = "";
780
+ await loadTeam();
781
+ });
782
+ const teamMessages = group(teamPanel), teamPaging = group(teamPanel, "pbot-pagination");
783
+ let teamAfter = 0, teamPage = { afterSeq: 0 };
784
+ const teamDrafts = /* @__PURE__ */ new Map();
785
+ async function chooseTeam(id) {
786
+ if (id !== teamId) {
787
+ if (teamId) teamDrafts.set(teamId, { text: post.value, reply: replyTo.value, instruction: instruction.value, mode: mode.value, rounds: rounds.value, concurrency: concurrency.value, timeout: timeout.value });
788
+ const draft = teamDrafts.get(id);
789
+ post.value = draft?.text ?? "";
790
+ replyTo.value = draft?.reply ?? "";
791
+ instruction.value = draft?.instruction ?? "";
792
+ mode.value = draft?.mode ?? "roundRobin";
793
+ rounds.value = draft?.rounds ?? "2";
794
+ concurrency.value = draft?.concurrency ?? "1";
795
+ timeout.value = draft?.timeout ?? "900";
796
+ }
797
+ teamId = id;
798
+ teamAfter = 0;
799
+ teamPageKey = "";
800
+ ++teamRevision;
801
+ teamPanel.hidden = true;
802
+ teamEmpty.hidden = false;
803
+ teamEmpty.replaceChildren(note("\u6B63\u5728\u8BFB\u53D6\u56E2\u961F\u8BB0\u5F55\u2026"));
804
+ renderLists();
805
+ await loadTeam({ afterSeq: 0 });
806
+ }
807
+ async function loadTeam(nextPage) {
808
+ if (!teamId) return;
809
+ if (nextPage) teamPage = nextPage;
810
+ const page = teamPage, id = teamId;
811
+ const revision = ++teamRevision, data = await query("team", { teamId: id, ...page });
812
+ if (id !== teamId || revision !== teamRevision) return;
813
+ const team = record(data.team), messages = record(data.page), run = object(team.run) ? team.run : void 0;
814
+ teamPanel.hidden = false;
815
+ teamEmpty.hidden = true;
816
+ teamTitle.textContent = text(team.name);
817
+ teamBadge.replaceChildren(badge(team.closed ? "closed" : run?.state ?? "open"));
818
+ teamInfo.replaceChildren(block(team.brief), facts([
819
+ ["\u6210\u5458", rows(team.members).map((member) => `${member.name} \xB7 ${member.role}`).join("\n")],
820
+ ["\u6279\u6B21\u8FDB\u5C55", run ? `\u5DF2\u5B89\u6392 ${run.scheduled} \xB7 \u5DF2\u4EA4\u4ED8 ${run.published} \xB7 \u5728\u9014 ${team.activeCount}` : "\u5C1A\u672A\u5F00\u59CB"],
821
+ ...run?.reason ? [["\u6682\u505C\u539F\u56E0", run.reason]] : []
822
+ ]));
823
+ teamState.textContent = JSON.stringify(team, null, 2);
824
+ enabled(pauseButton, !team.closed && run?.state === "running");
825
+ enabled(closeTeamButton, !team.closed);
826
+ enabled(runButton, !team.closed && run?.state !== "running" && Number(team.activeCount) === 0);
827
+ enabled(postButton, !team.closed);
828
+ const key = JSON.stringify([id, page, messages]);
829
+ if (key === teamPageKey) return;
830
+ teamPageKey = key;
831
+ teamMessages.replaceChildren();
832
+ teamPaging.replaceChildren();
833
+ for (const message of rows(messages.messages)) {
834
+ const author = record(message.author), item = element("article", "", "pbot-message"), meta = group(item, "pbot-row");
835
+ meta.append(element("h4", text(author.name)), note(`#${message.seq}${message.replyTo ? ` \xB7 \u56DE\u590D #${message.replyTo}` : ""}`));
836
+ item.append(block(message.text));
837
+ if (typeof message.nextOffset === "number") button(item, "\u7EE7\u7EED\u8BFB\u53D6\u8FD9\u6761\u6D88\u606F", () => loadTeam({ seq: message.seq, offset: message.nextOffset }), "pbot-quiet");
838
+ teamMessages.append(item);
839
+ }
840
+ if (!teamMessages.childElementCount) teamMessages.append(empty("\u8FD8\u6CA1\u6709\u516C\u5171\u6D88\u606F", "\u53D1\u5E03\u8D44\u6599\u6216\u5F00\u542F\u6279\u6B21\u540E\uFF0C\u6210\u5458\u4F1A\u5728\u8FD9\u91CC\u5171\u4EAB\u7ED3\u679C\u3002"));
841
+ button(teamPaging, "\u4ECE\u7B2C\u4E00\u6761\u8BFB\u53D6", async () => {
842
+ teamAfter = 0;
843
+ await loadTeam({ afterSeq: 0 });
844
+ });
845
+ if (typeof messages.nextAfterSeq === "number") button(teamPaging, "\u540E\u7EED\u6D88\u606F", async () => {
846
+ teamAfter = messages.nextAfterSeq;
847
+ await loadTeam({ afterSeq: teamAfter });
848
+ });
849
+ if (page.seq !== void 0) button(teamPaging, "\u8FD4\u56DE\u6D88\u606F\u5217\u8868", () => loadTeam({ afterSeq: teamAfter }));
850
+ }
851
+ const history = section("history", "\u5386\u53F2");
852
+ pageTitle(history, "\u5386\u53F2", "");
853
+ const searchForm = form(history);
854
+ searchForm.className = "pbot-search";
855
+ const historyQuery = field(searchForm, "\u5173\u952E\u8BCD"), host = select(searchForm, "\u6765\u6E90", [["", "\u5168\u90E8"], ["pi", "Pi"], ["dsh", "dsh"]]);
856
+ historyQuery.placeholder = "\u7559\u7A7A\u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD";
857
+ submit(searchForm, "\u67E5\u8BE2", () => searchHistory());
858
+ const dateFilters = details(history, "\u65F6\u95F4\u8303\u56F4"), dateGrid = group(dateFilters, "pbot-grid");
859
+ const historyFrom = field(dateGrid, "\u5F00\u59CB\u65F6\u95F4"), historyTo = field(dateGrid, "\u7ED3\u675F\u65F6\u95F4");
860
+ for (const input of [historyFrom, historyTo]) input.type = "datetime-local";
861
+ const historyBody = group(history, "pbot-history-results"), historyPaging = group(history, "pbot-pagination"), historyNode = group(history, "pbot-card");
862
+ historyNode.hidden = true;
863
+ historyBody.append(empty("\u67E5\u8BE2\u5386\u53F2", "\u8F93\u5165\u5173\u952E\u8BCD\uFF0C\u6216\u7559\u7A7A\u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD\u3002"));
864
+ let historySearch = {};
865
+ function warnings(parent, values) {
866
+ if (Array.isArray(values)) {
867
+ for (const warning of values) if (warning) parent.append(element("p", text(warning), "pbot-warning"));
868
+ }
869
+ }
870
+ async function searchHistory(offset = 0, keepFilters = false) {
871
+ if (!keepFilters) historySearch = {
872
+ query: historyQuery.value,
873
+ ...host.value ? { host: host.value } : {},
874
+ ...historyFrom.value ? { from: new Date(historyFrom.value).toISOString() } : {},
875
+ ...historyTo.value ? { to: new Date(historyTo.value).toISOString() } : {}
876
+ };
877
+ const revision = ++historyRevision, data = await query("history", { action: "search", ...historySearch, offset });
878
+ if (revision !== historyRevision) return;
879
+ historyNode.hidden = true;
880
+ historyBody.replaceChildren(note(`\u5171 ${data.total} \u9879`));
881
+ warnings(historyBody, data.warnings);
882
+ historyPaging.replaceChildren();
883
+ for (const match of rows(data.matches)) {
884
+ const item = element("article"), meta = group(item, "pbot-between");
885
+ item.dataset.id = text(match.id);
886
+ item.dataset.host = text(match.host);
887
+ meta.append(element("h4", text(match.name)), element("span", text(match.host), "pbot-badge"));
888
+ item.append(note(`${time(match.from)} \xB7 ${match.kind === "session" ? "\u4F1A\u8BDD" : match.kind === "summary" ? "\u6458\u8981" : "\u95EE\u7B54"}`), block(match.snippet || match.preview));
889
+ button(item, "\u8BFB\u53D6", () => readHistory(text(match.id), text(match.host)), "pbot-quiet");
890
+ historyBody.append(item);
891
+ }
892
+ if (!rows(data.matches).length) historyBody.append(empty("\u6CA1\u6709\u627E\u5230\u5339\u914D\u5185\u5BB9", "\u8BD5\u8BD5\u66F4\u77ED\u7684\u5173\u952E\u8BCD\uFF0C\u6216\u8C03\u6574\u6765\u6E90\u548C\u65F6\u95F4\u8303\u56F4\u3002"));
893
+ if (offset) button(historyPaging, "\u4E0A\u4E00\u9875", () => searchHistory(Math.max(0, offset - 20), true));
894
+ if (typeof data.nextOffset === "number") button(historyPaging, "\u4E0B\u4E00\u9875", () => searchHistory(data.nextOffset, true));
895
+ }
896
+ async function readHistory(id, source, offset = 0, childrenOffset = 0) {
897
+ const revision = ++historyRevision, data = await query("history", { action: "read", id, host: source, offset, childrenOffset });
898
+ if (revision !== historyRevision) return;
899
+ const node = record(data.node);
900
+ historyNode.hidden = false;
901
+ historyNode.replaceChildren(
902
+ element("h3", text(node.name)),
903
+ note(`${text(node.host)} \xB7 ${time(node.from)} \xB7 ${node.completed ? "\u539F\u4EA4\u4E92\u5DF2\u5B8C\u6210" : "\u539F\u4EA4\u4E92\u672A\u786E\u8BA4\u5B8C\u6210"}`),
904
+ block(node.text || "\u6458\u8981\u5C1A\u672A\u751F\u6210\uFF0C\u53EF\u5C55\u5F00\u4E0B\u7EA7\u8BB0\u5F55\u9605\u8BFB\u539F\u6587\u3002")
905
+ );
906
+ warnings(historyNode, data.warnings);
907
+ for (const item of historyBody.querySelectorAll("article")) item.setAttribute("aria-current", String(item.dataset.id === id && item.dataset.host === source));
908
+ const paging = group(historyNode, "pbot-pagination");
909
+ if (offset) button(paging, "\u6B63\u6587\u5F00\u5934", () => readHistory(id, source, 0, childrenOffset));
910
+ if (typeof node.nextOffset === "number") button(paging, "\u7EE7\u7EED\u6B63\u6587", () => readHistory(id, source, node.nextOffset, childrenOffset));
911
+ for (const [label, values] of [["\u4E0A\u7EA7\u6458\u8981", node.parents], ["\u4E0B\u7EA7\u8BB0\u5F55", node.children]]) {
912
+ if (!rows(values).length) continue;
913
+ const related = group(historyNode, "pbot-stack");
914
+ related.append(element("h4", label));
915
+ for (const item of rows(values)) button(related, text(item.preview || item.name), () => readHistory(text(item.id), text(item.host)), "pbot-quiet");
916
+ }
917
+ if (childrenOffset) button(paging, "\u9996\u6279\u4E0B\u7EA7", () => readHistory(id, source, offset));
918
+ if (typeof node.nextChildrenOffset === "number") button(paging, "\u66F4\u591A\u4E0B\u7EA7", () => readHistory(id, source, offset, node.nextChildrenOffset));
919
+ const provenance = block(node.source);
920
+ provenance.classList.add("pbot-raw");
921
+ details(historyNode, "\u539F\u59CB\u6765\u6E90\u4F4D\u7F6E").append(provenance);
922
+ historyNode.scrollIntoView({ block: "start" });
923
+ }
924
+ const expertButtons = /* @__PURE__ */ new Map(), teamButtons = /* @__PURE__ */ new Map();
925
+ function syncList(container, buttons, values, kind) {
926
+ const ids = new Set(values.map((value2) => text(value2[kind + "Id"])));
927
+ for (const [id, node] of buttons) if (!ids.has(id)) {
928
+ node.remove();
929
+ buttons.delete(id);
930
+ }
931
+ container.querySelector(":scope > .pbot-empty")?.remove();
932
+ for (const value2 of values) {
933
+ const id = text(value2[kind + "Id"]), state = kind === "agent" ? value2.state : value2.closed ? "closed" : object(value2.run) ? value2.run.state : "open";
934
+ let node = buttons.get(id);
935
+ if (!node) {
936
+ node = button(container, "", () => kind === "agent" ? chooseExpert(id) : chooseTeam(id), "pbot-list-item");
937
+ buttons.set(id, node);
938
+ }
939
+ node.setAttribute("aria-label", text(value2.name));
940
+ node.setAttribute("aria-pressed", String(id === (kind === "agent" ? expertId : teamId)));
941
+ const signature = JSON.stringify([value2.name, state, value2.activity, value2.brief]);
942
+ if (node.dataset.content !== signature) {
943
+ node.dataset.content = signature;
944
+ node.replaceChildren();
945
+ const row = group(node, "pbot-between");
946
+ row.append(element("strong", text(value2.name)), badge(state));
947
+ if (kind === "team" || !["idle", "stopped"].includes(text(state))) node.append(note(text(kind === "agent" ? value2.activity : value2.brief)));
948
+ }
949
+ node.hidden = kind === "agent" && !`${value2.name} ${stateLabel(state)}`.toLowerCase().includes(expertFilter.value.trim().toLowerCase());
950
+ }
951
+ if (!values.length || [...buttons.values()].every((node) => node.hidden)) {
952
+ container.append(empty(values.length ? "\u6CA1\u6709\u5339\u914D\u7684\u4E13\u5BB6" : kind === "agent" ? "\u8FD8\u6CA1\u6709\u4E13\u5BB6" : "\u8FD8\u6CA1\u6709\u56E2\u961F", values.length ? "\u8C03\u6574\u540D\u79F0\u6216\u72B6\u6001\u5173\u952E\u8BCD\u3002" : kind === "agent" ? "\u5C55\u5F00\u4E0A\u65B9\u201C\u521B\u5EFA\u4E13\u5BB6\u201D\u5F00\u59CB\u3002" : "\u5148\u521B\u5EFA\u4E13\u5BB6\uFF0C\u518D\u4E3A\u6210\u5458\u5206\u914D\u804C\u8D23\u3002"));
953
+ }
954
+ }
955
+ function renderLists() {
956
+ if (!snapshot) return;
957
+ syncList(expertList, expertButtons, rows(snapshot.agents), "agent");
958
+ syncList(teamList, teamButtons, rows(snapshot.teams), "team");
959
+ }
960
+ expertFilter.addEventListener("input", renderLists);
961
+ function renderSnapshot() {
962
+ if (!snapshot) return;
963
+ location.textContent = text(snapshot.workspaceRoot).split(/[\\/]/).filter(Boolean).at(-1) ?? "";
964
+ location.title = text(snapshot.workspaceRoot);
965
+ const agents = rows(snapshot.agents), teams2 = rows(snapshot.teams), python = record(snapshot.python), history2 = record(snapshot.history);
966
+ tabCounts.get("experts").textContent = text(agents.length);
967
+ tabCounts.get("teams").textContent = text(teams2.length);
968
+ const active = agents.filter((agent) => ["starting", "busy", "stopping"].includes(text(agent.state))).length;
969
+ counts.textContent = `\u4E13\u5BB6 ${agents.length} \xB7 \u6267\u884C\u4E2D ${active} \xB7 \u56E2\u961F ${teams2.length}`;
970
+ const model2 = object(snapshot.model) ? snapshot.model : {};
971
+ workspaceInfo.replaceChildren(facts([
972
+ ["\u5DE5\u4F5C\u533A", snapshot.workspaceRoot],
973
+ ["\u6A21\u578B", model2.model || "\u5C1A\u672A\u9009\u62E9"],
974
+ ["Provider", model2.provider || "\u2014"],
975
+ ["\u5386\u53F2", history2.organizing ? "\u6574\u7406\u4E2D" : history2.pending === null ? "\u67E5\u8BE2\u65F6\u66F4\u65B0\u7D22\u5F15" : `${history2.pending} \u9879\u5F85\u6574\u7406`]
976
+ ]));
977
+ pythonInfo.replaceChildren(element("h3", "Python"), badge(python.state));
978
+ if (python.error) pythonInfo.append(element("p", text(python.error), "pbot-warning"));
979
+ enabled(pythonButton, python.state !== "preparing");
980
+ const { agents: _agents, teams: _teams, ...summary } = snapshot;
981
+ statusBody.textContent = JSON.stringify(summary, null, 2);
982
+ if (snapshot.controlError) inform(text(snapshot.controlError), "error");
983
+ renderLists();
984
+ const owned = agents.filter((value2) => value2.owned), ids = new Set(owned.map((agent) => text(agent.agentId)));
985
+ for (const input of memberFields.querySelectorAll("input[data-agent-id]")) if (!ids.has(input.dataset.agentId)) input.parentElement?.remove();
986
+ memberFields.querySelector(":scope > p")?.remove();
987
+ for (const agent of owned) {
988
+ const id = text(agent.agentId);
989
+ let input = Array.from(memberFields.querySelectorAll("input[data-agent-id]")).find((input2) => input2.dataset.agentId === id);
990
+ if (!input) {
991
+ input = field(memberFields, `${agent.name} \xB7 \u804C\u8D23`);
992
+ input.dataset.agentId = id;
993
+ }
994
+ const label = `${agent.name} \xB7 \u804C\u8D23`;
995
+ input.setAttribute("aria-label", label);
996
+ input.parentElement.querySelector("span").textContent = label;
997
+ }
998
+ if (!owned.length) memberFields.append(note("\u8FD8\u6CA1\u6709\u53EF\u52A0\u5165\u7684\u4E13\u5BB6\uFF0C\u8BF7\u5148\u5728\u4E13\u5BB6\u9875\u521B\u5EFA\u3002"));
999
+ }
1000
+ async function refresh() {
1001
+ const revision = ++snapshotRevision, value2 = await query("snapshot");
1002
+ if (revision !== snapshotRevision) return;
1003
+ snapshot = value2;
1004
+ renderSnapshot();
1005
+ connection.textContent = "\u5DF2\u8FDE\u63A5 \xB7 \u72B6\u6001\u81EA\u52A8\u66F4\u65B0";
1006
+ }
1007
+ button(footer, "\u5237\u65B0\u72B6\u6001", refresh, "pbot-quiet");
1008
+ const close = button(header, "\xD7", () => dispose(), "pbot-close pbot-quiet");
1009
+ close.setAttribute("aria-label", "\u5173\u95ED\u5DE5\u4F5C\u53F0");
1010
+ close.title = "\u5173\u95ED \xB7 Esc";
1011
+ const dispose = ctx.effect(() => {
1012
+ document.body.append(dialog);
1013
+ dialog.showModal();
1014
+ tabs.get("status").focus();
1015
+ return () => {
1016
+ closed = true;
1017
+ lifetime.abort();
1018
+ if (timer !== void 0) window.clearTimeout(timer);
1019
+ dialog.close();
1020
+ dialog.remove();
1021
+ if (opener instanceof HTMLElement && opener.isConnected) opener.focus();
1022
+ };
1023
+ });
1024
+ dialog.addEventListener("cancel", (event) => {
1025
+ event.preventDefault();
1026
+ void dispose();
1027
+ });
1028
+ async function poll() {
1029
+ try {
1030
+ await refresh();
1031
+ if (tab === "experts" && expertId) await loadExpert();
1032
+ if (tab === "teams" && teamId) await loadTeam();
1033
+ if (pollError) {
1034
+ inform("\u8FDE\u63A5\u5DF2\u6062\u590D\uFF0C\u72B6\u6001\u5DF2\u66F4\u65B0\u3002");
1035
+ pollError = false;
1036
+ }
1037
+ } catch (error) {
1038
+ if (!closed) {
1039
+ connection.textContent = "\u8FDE\u63A5\u4E2D\u65AD \xB7 \u6B63\u5728\u91CD\u8BD5";
1040
+ if (!pollError) inform("\u8BFB\u53D6\u72B6\u6001\u5931\u8D25\uFF1A" + String(error), "error");
1041
+ pollError = true;
1042
+ }
1043
+ } finally {
1044
+ if (!closed) timer = window.setTimeout(() => {
1045
+ void poll();
1046
+ }, 2e3);
1047
+ }
1048
+ }
1049
+ void poll();
1050
+ }
1051
+
1052
+ // src/ui/dsh/index.ts
1053
+ var name = "personal-bot";
1054
+ var inject = ["remote"];
1055
+ async function apply(ctx) {
1056
+ ctx.remote.$mount(pbotReadRemote);
1057
+ await ctx.plugin({
1058
+ name: "pbot-management-view",
1059
+ inject: ["commandUi", "remote", "remote.commands", "remote.pbot", "fileUpload"],
1060
+ apply(view) {
1061
+ view.commandUi.decorate({
1062
+ name: "pbot",
1063
+ available: () => true,
1064
+ ui: { kind: "action", run: (session) => {
1065
+ showManagement(view, session.sessionId);
1066
+ } }
1067
+ });
1068
+ }
1069
+ });
1070
+ }
1071
+ return module.exports; } });