tagword-codeagent 1.1.6__py3-none-any.whl

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 (173) hide show
  1. codeagent/__init__.py +10 -0
  2. codeagent/__main__.py +13 -0
  3. codeagent/cli/__init__.py +13 -0
  4. codeagent/cli/entrypoint.py +161 -0
  5. codeagent/cli/main.py +979 -0
  6. codeagent/core/__init__.py +2 -0
  7. codeagent/core/attachments.py +342 -0
  8. codeagent/core/audio_models.py +50 -0
  9. codeagent/core/bootstrap.py +178 -0
  10. codeagent/core/default_presets.py +159 -0
  11. codeagent/core/env.py +106 -0
  12. codeagent/core/folder_picker.py +151 -0
  13. codeagent/core/image_understanding.py +90 -0
  14. codeagent/core/models.py +6 -0
  15. codeagent/core/paths.py +238 -0
  16. codeagent/core/pricing.py +107 -0
  17. codeagent/core/process_ports.py +258 -0
  18. codeagent/core/seed_bridge.py +21 -0
  19. codeagent/core/settings.py +98 -0
  20. codeagent/core/speech_synth.py +330 -0
  21. codeagent/core/team_config.py +247 -0
  22. codeagent/core/team_manager.py +245 -0
  23. codeagent/core/token_counter.py +41 -0
  24. codeagent/core/tts_voices.py +103 -0
  25. codeagent/core/usage_billing.py +72 -0
  26. codeagent/core/vision_models.py +93 -0
  27. codeagent/memory/diary.py +144 -0
  28. codeagent/persona_defaults/README.md +12 -0
  29. codeagent/persona_defaults/agent.md +352 -0
  30. codeagent/persona_defaults/identity.md +29 -0
  31. codeagent/persona_defaults/memory.md +4 -0
  32. codeagent/persona_defaults/skills.md +325 -0
  33. codeagent/persona_defaults/soul.md +38 -0
  34. codeagent/persona_defaults/tools.md +41 -0
  35. codeagent/persona_defaults/user.md +18 -0
  36. codeagent/runtime/__init__.py +11 -0
  37. codeagent/runtime/agent_context.py +6 -0
  38. codeagent/runtime/agent_runtime.py +21 -0
  39. codeagent/runtime/compact_prompt.py +9 -0
  40. codeagent/runtime/compact_state.py +40 -0
  41. codeagent/runtime/llm_worker.py +132 -0
  42. codeagent/runtime/orchestrator.py +161 -0
  43. codeagent/runtime/prompt_enrichment.py +324 -0
  44. codeagent/runtime/session_manager.py +30 -0
  45. codeagent/runtime/task_split.py +38 -0
  46. codeagent/runtime/turn_loop.py +13 -0
  47. codeagent/runtime/worker.py +48 -0
  48. codeagent/server/__init__.py +505 -0
  49. codeagent/server/app_factory.py +1292 -0
  50. codeagent/server/attachment_api.py +261 -0
  51. codeagent/server/hub.py +175 -0
  52. codeagent/server/icon.png +0 -0
  53. codeagent/server/self_healing.py +143 -0
  54. codeagent/server/team_engine.py +243 -0
  55. codeagent/server/tts_api.py +51 -0
  56. codeagent/server/webui_api_app.py +3180 -0
  57. codeagent/skills/__init__.py +2 -0
  58. codeagent/skills/select.py +144 -0
  59. codeagent/tools/__init__.py +6 -0
  60. codeagent/tools/agent_tools.py +10 -0
  61. codeagent/web/__init__.py +1 -0
  62. codeagent/web/__pycache__/__init__.cpython-313.pyc +0 -0
  63. codeagent/web/__pycache__/app.cpython-313.pyc +0 -0
  64. codeagent/web/__pycache__/auth_impl.cpython-313.pyc +0 -0
  65. codeagent/web/auth_impl.py +326 -0
  66. codeagent/web/static/00-marked.min.js +6 -0
  67. codeagent/web/static/00-mermaid.min.js +2314 -0
  68. codeagent/web/static/00-purify.min.js +3 -0
  69. codeagent/web/static/00-storage.js +83 -0
  70. codeagent/web/static/00-utils.js +51 -0
  71. codeagent/web/static/01-theme.css +96 -0
  72. codeagent/web/static/01a-scroll.js +86 -0
  73. codeagent/web/static/01b-think.js +62 -0
  74. codeagent/web/static/01c-session-identity.js +81 -0
  75. codeagent/web/static/01c-session-thinking.js +61 -0
  76. codeagent/web/static/01c-session-tree-menus.js +349 -0
  77. codeagent/web/static/01c-session-tree.js +531 -0
  78. codeagent/web/static/01c-session-utilities.js +83 -0
  79. codeagent/web/static/01c-vision-model.js +132 -0
  80. codeagent/web/static/01d-image-gen-model.js +84 -0
  81. codeagent/web/static/01e-audio-model.js +97 -0
  82. codeagent/web/static/01f-compose-ui.js +88 -0
  83. codeagent/web/static/01g-tts-settings.js +128 -0
  84. codeagent/web/static/01h-music-model.js +85 -0
  85. codeagent/web/static/01i-model-stack.js +291 -0
  86. codeagent/web/static/01j-video-gen-model.js +85 -0
  87. codeagent/web/static/01k-model-stack-bootstrap.js +66 -0
  88. codeagent/web/static/01k-model-stack-state.js +209 -0
  89. codeagent/web/static/01q-inflight.js +195 -0
  90. codeagent/web/static/02-reset.css +22 -0
  91. codeagent/web/static/02-session-ui.js +201 -0
  92. codeagent/web/static/03-layout-p1.css +2 -0
  93. codeagent/web/static/03-layout-p2.css +2 -0
  94. codeagent/web/static/03a-links-stream.js +88 -0
  95. codeagent/web/static/03b-stream-text.js +119 -0
  96. codeagent/web/static/03c-render-bubble.js +520 -0
  97. codeagent/web/static/03d-agent-bubble.js +126 -0
  98. codeagent/web/static/03e-tool-trace.js +182 -0
  99. codeagent/web/static/03f-timeline.js +54 -0
  100. codeagent/web/static/03g-bubble-tts.js +292 -0
  101. codeagent/web/static/04-components-p1.css +1 -0
  102. codeagent/web/static/04-components-p2b.css +1 -0
  103. codeagent/web/static/04-components-p3.css +2 -0
  104. codeagent/web/static/04-components-p4.css +1 -0
  105. codeagent/web/static/04-components-p5.css +1 -0
  106. codeagent/web/static/04-components-p6.css +58 -0
  107. codeagent/web/static/04-components-p7.css +4 -0
  108. codeagent/web/static/04-components-p8.css +1 -0
  109. codeagent/web/static/04-components-p9.css +1 -0
  110. codeagent/web/static/04-ws-connect.js +351 -0
  111. codeagent/web/static/04-ws-helpers.js +116 -0
  112. codeagent/web/static/05-chat-p1.css +1058 -0
  113. codeagent/web/static/05-chat-p2.css +1 -0
  114. codeagent/web/static/05-chat-p3.css +295 -0
  115. codeagent/web/static/05a-session-history.js +176 -0
  116. codeagent/web/static/05b-session-list.js +114 -0
  117. codeagent/web/static/05c-dialog.js +123 -0
  118. codeagent/web/static/05d-project-create.js +172 -0
  119. codeagent/web/static/05e-project-remote.js +143 -0
  120. codeagent/web/static/06-chat.js +552 -0
  121. codeagent/web/static/06-utilities.css +181 -0
  122. codeagent/web/static/06b-attachments.js +304 -0
  123. codeagent/web/static/06c-camera.js +488 -0
  124. codeagent/web/static/07-activity-bar.css +127 -0
  125. codeagent/web/static/09-git-p1.css +1 -0
  126. codeagent/web/static/09-git-p2.css +1 -0
  127. codeagent/web/static/09a-init-bind.js +110 -0
  128. codeagent/web/static/09b-panel-toggle.js +80 -0
  129. codeagent/web/static/09c-api-refresh.js +100 -0
  130. codeagent/web/static/09d-status-log.js +80 -0
  131. codeagent/web/static/09e-commit.js +80 -0
  132. codeagent/web/static/09f-remote.js +93 -0
  133. codeagent/web/static/11a-cron-parse.js +117 -0
  134. codeagent/web/static/11b-cron-panel.js +100 -0
  135. codeagent/web/static/11c-cron-card.js +133 -0
  136. codeagent/web/static/11d-cron-form.js +105 -0
  137. codeagent/web/static/11e-env-config.js +168 -0
  138. codeagent/web/static/11f-env-llm-a-state.js +136 -0
  139. codeagent/web/static/11f-env-llm-b-form.js +409 -0
  140. codeagent/web/static/11f-env-llm-c-board.js +322 -0
  141. codeagent/web/static/11g-env-paths-git.js +973 -0
  142. codeagent/web/static/11h-env-mcp-a-state.js +161 -0
  143. codeagent/web/static/11h-env-mcp-b-form.js +229 -0
  144. codeagent/web/static/11h-env-mcp-c-board.js +565 -0
  145. codeagent/web/static/12-plugins.js +127 -0
  146. codeagent/web/static/13a-skills.js +156 -0
  147. codeagent/web/static/13a-todo-utils.js +140 -0
  148. codeagent/web/static/13b-todo-fetch.js +106 -0
  149. codeagent/web/static/13b-tools.js +127 -0
  150. codeagent/web/static/13c-todo-crud.js +92 -0
  151. codeagent/web/static/14-activity-bar.js +177 -0
  152. codeagent/web/static/15-plans.css +194 -0
  153. codeagent/web/static/15-plans.js +219 -0
  154. codeagent/web/static/16-mobile.css +612 -0
  155. codeagent/web/static/16-mobile.js +178 -0
  156. codeagent/web/static/17-preset-ux.css +287 -0
  157. codeagent/web/static/18-agent-mgr.css +616 -0
  158. codeagent/web/static/18-agent-mgr.js +204 -0
  159. codeagent/web/static/24-health-dashboard.js +68 -0
  160. codeagent/web/static/99-brand-polish.css +152 -0
  161. codeagent/web/static/body.html +824 -0
  162. codeagent/web/static/setup/setup_form.html +171 -0
  163. codeagent/web/static/setup/setup_head.html +100 -0
  164. codeagent/web/static/setup/setup_tail.html +264 -0
  165. codeagent/web/static/setup/setup_test.html +38 -0
  166. codeagent/web/web_login.html +265 -0
  167. codeagent/web/webui.html +35 -0
  168. tagword_codeagent-1.1.6.dist-info/METADATA +273 -0
  169. tagword_codeagent-1.1.6.dist-info/RECORD +173 -0
  170. tagword_codeagent-1.1.6.dist-info/WHEEL +5 -0
  171. tagword_codeagent-1.1.6.dist-info/entry_points.txt +3 -0
  172. tagword_codeagent-1.1.6.dist-info/licenses/LICENSE +21 -0
  173. tagword_codeagent-1.1.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,349 @@
1
+ /* ================================================================
2
+ * 01c-session-tree-menus.js
3
+ * 项目树右键菜单 + 目录关联对话框 + 项目/会话重命名/删除:
4
+ * - showProjectContextMenu / showSessionContextMenu / closeContextMenu
5
+ * - closeProjectDirectoryDialog / showProjectDirectoryDialog
6
+ * - copyToClipboard / renameProject / deleteProject / deleteSession
7
+ *
8
+ * 依赖 01c-session-tree.js 的:
9
+ * treePid / findProjDiv / refreshSessionsUnderProject / syncTreeProjectActiveHighlight
10
+ * / syncTreeSessionActiveHighlight / refreshProjects
11
+ * 依赖 01c-session-identity.js 的:
12
+ * agentId / projectId / sessionId / saveProjectIdForAgent / _sidStorageKey
13
+ * / oaRandomUUID
14
+ *
15
+ * 按字母序:'01c-session-tree-menus.js' 中字符 '-' (0x2D) < '01c-session-tree.js'
16
+ * 字符 '.' (0x2E),所以 menus 文件实际在 tree 文件**之后**加载;
17
+ * function hoisting 保证本文件函数可被 tree 内部引用。
18
+ * ================================================================ */
19
+
20
+ function closeProjectDirectoryDialog() {
21
+ var el = document.getElementById('projectDirDialog');
22
+ if (el) el.remove();
23
+ }
24
+
25
+ /** 侧栏项目 ⋮ 菜单:设置/查看工作目录 */
26
+ function showProjectDirectoryDialog(pid) {
27
+ closeProjectDirectoryDialog();
28
+ var k = treePid(pid);
29
+ var curPath = getTreeProjectPath(k);
30
+
31
+ var root = document.createElement('div');
32
+ root.id = 'projectDirDialog';
33
+ root.className = 'modal-overlay';
34
+ root.style.display = 'flex';
35
+
36
+ var dlg = document.createElement('div');
37
+ dlg.className = 'modal-dialog';
38
+ dlg.addEventListener('click', function(ev) { ev.stopPropagation(); });
39
+
40
+ var header = document.createElement('div');
41
+ header.className = 'modal-dialog__header';
42
+ var title = document.createElement('span');
43
+ title.className = 'modal-dialog__title';
44
+ title.textContent = '项目目录';
45
+ var btnClose = document.createElement('button');
46
+ btnClose.type = 'button';
47
+ btnClose.className = 'modal-dialog__close';
48
+ btnClose.innerHTML = '&times;';
49
+ btnClose.setAttribute('aria-label', '关闭');
50
+ header.appendChild(title);
51
+ header.appendChild(btnClose);
52
+
53
+ var body = document.createElement('div');
54
+ body.className = 'modal-dialog__body';
55
+ var field = document.createElement('div');
56
+ field.className = 'modal-field';
57
+ var lab = document.createElement('label');
58
+ lab.className = 'modal-field__label';
59
+ lab.setAttribute('for', 'inpProjectDirPath');
60
+ lab.textContent = '文件系统路径';
61
+ var row = document.createElement('div');
62
+ row.className = 'modal-field__input-row';
63
+ var inp = document.createElement('input');
64
+ inp.type = 'text';
65
+ inp.id = 'inpProjectDirPath';
66
+ inp.className = 'modal-field__input';
67
+ inp.placeholder = '例如:/Users/kun/my-project';
68
+ inp.value = curPath;
69
+ var btnBrowse = document.createElement('button');
70
+ btnBrowse.type = 'button';
71
+ btnBrowse.className = 'modal-btn modal-btn--browse';
72
+ btnBrowse.title = '浏览选择目录';
73
+ btnBrowse.textContent = '📁 浏览';
74
+ row.appendChild(inp);
75
+ row.appendChild(btnBrowse);
76
+ var hint = document.createElement('p');
77
+ hint.className = 'modal-field__hint';
78
+ hint.textContent = '设置工作目录后,文件树和 Git 面板可直接操作项目文件';
79
+ field.appendChild(lab);
80
+ field.appendChild(row);
81
+ field.appendChild(hint);
82
+ body.appendChild(field);
83
+
84
+ var footer = document.createElement('div');
85
+ footer.className = 'modal-dialog__footer';
86
+ var btnCancel = document.createElement('button');
87
+ btnCancel.type = 'button';
88
+ btnCancel.className = 'modal-btn modal-btn--cancel';
89
+ btnCancel.textContent = '取消';
90
+ var btnSave = document.createElement('button');
91
+ btnSave.type = 'button';
92
+ btnSave.className = 'modal-btn modal-btn--confirm';
93
+ btnSave.textContent = '保存';
94
+ footer.appendChild(btnCancel);
95
+ footer.appendChild(btnSave);
96
+
97
+ dlg.appendChild(header);
98
+ dlg.appendChild(body);
99
+ dlg.appendChild(footer);
100
+ root.appendChild(dlg);
101
+ document.body.appendChild(root);
102
+
103
+ function close() { closeProjectDirectoryDialog(); }
104
+ btnClose.addEventListener('click', close);
105
+ btnCancel.addEventListener('click', close);
106
+ root.addEventListener('click', function(ev) {
107
+ if (ev.target === root) close();
108
+ });
109
+ btnSave.addEventListener('click', async function() {
110
+ var newPath = inp.value.trim();
111
+ btnSave.disabled = true;
112
+ try {
113
+ var r = await fetch('/api/ui/projects/path', {
114
+ method: 'POST',
115
+ headers: { 'Content-Type': 'application/json' },
116
+ credentials: 'same-origin',
117
+ body: JSON.stringify({ agent_id: agentId, project_id: k, path: newPath }),
118
+ });
119
+ if (!r.ok) throw new Error((await r.json()).detail || r.statusText);
120
+ var resp = await r.json();
121
+ var resolvedPath = resp.project ? resp.project.path : newPath;
122
+ if (treeProjectsCache && treeProjectsCache.aid === agentId) {
123
+ for (var i = 0; i < treeProjectsCache.projects.length; i++) {
124
+ if (treePid(treeProjectsCache.projects[i].id) === k) {
125
+ treeProjectsCache.projects[i].path = resolvedPath;
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ close();
131
+ window.dispatchEvent(new CustomEvent('project-changed', {detail: {projectId: k}}));
132
+ } catch (e) {
133
+ alert('保存失败:' + String(e.message || e));
134
+ btnSave.disabled = false;
135
+ }
136
+ });
137
+ if (typeof btnBrowse === 'object' && btnBrowse) {
138
+ btnBrowse.addEventListener('click', function() {
139
+ btnBrowse.textContent = '⏳ 选择中…';
140
+ btnBrowse.disabled = true;
141
+ fetch('/api/ui/pick-directory', { method: 'POST', credentials: 'same-origin' })
142
+ .then(function(r) { return r.json(); })
143
+ .then(function(j) {
144
+ if (j.path) inp.value = j.path;
145
+ else if (j.hint) console.warn('pick-directory:', j.hint);
146
+ else if (j.detail) console.warn('pick-directory:', j.detail);
147
+ })
148
+ .catch(function(e) { console.error('pick-directory error:', e); })
149
+ .finally(function() {
150
+ btnBrowse.textContent = '📁 浏览';
151
+ btnBrowse.disabled = false;
152
+ });
153
+ });
154
+ }
155
+ }
156
+
157
+ function showProjectContextMenu(e, pid, name) {
158
+ closeContextMenu();
159
+ var menu = document.createElement('div');
160
+ menu.className = 'tree-context-menu';
161
+ menu.setAttribute('data-menu', 'project');
162
+ var items = [
163
+ { label: '工作目录', act: 'dir' },
164
+ { label: '重命名', act: 'rename' },
165
+ { label: '删除项目', act: 'delete', danger: true },
166
+ ];
167
+ items.forEach(function(it) {
168
+ var btn = document.createElement('button');
169
+ btn.type = 'button';
170
+ btn.className = 'tree-context-menu__item' + (it.danger ? ' tree-context-menu__item--danger' : '');
171
+ btn.textContent = it.label;
172
+ btn.addEventListener('click', function(ev) {
173
+ ev.stopPropagation();
174
+ closeContextMenu();
175
+ if (it.act === 'dir') showProjectDirectoryDialog(pid);
176
+ else if (it.act === 'rename') renameProject(pid, name);
177
+ else if (it.act === 'delete') deleteProject(pid);
178
+ });
179
+ menu.appendChild(btn);
180
+ });
181
+ var x = (e && e.clientX) || 80;
182
+ var y = (e && e.clientY) || 80;
183
+ menu.style.left = Math.min(x, window.innerWidth - 200) + 'px';
184
+ menu.style.top = Math.min(y, window.innerHeight - 200) + 'px';
185
+ document.body.appendChild(menu);
186
+
187
+ var overlay = document.createElement('div');
188
+ overlay.className = 'tree-overlay';
189
+ overlay.addEventListener('click', closeContextMenu);
190
+ document.body.appendChild(overlay);
191
+ menu.dataset.overlay = '1';
192
+ }
193
+
194
+ function showSessionContextMenu(e, sid, pid) {
195
+ closeContextMenu();
196
+ var menu = document.createElement('div');
197
+ menu.className = 'tree-context-menu';
198
+ menu.setAttribute('data-menu', 'session');
199
+ var items = [
200
+ { label: '复制会话 ID', act: 'copy-id' },
201
+ { label: '归档', act: 'archive' },
202
+ { label: '删除', act: 'delete', danger: true },
203
+ ];
204
+ items.forEach(function(it) {
205
+ var btn = document.createElement('button');
206
+ btn.type = 'button';
207
+ btn.className = 'tree-context-menu__item' + (it.danger ? ' tree-context-menu__item--danger' : '');
208
+ btn.textContent = it.label;
209
+ btn.addEventListener('click', function(ev) {
210
+ ev.stopPropagation();
211
+ closeContextMenu();
212
+ if (it.act === 'copy-id') {
213
+ try { navigator.clipboard.writeText(sid); }
214
+ catch (_) {
215
+ var ta = document.createElement('textarea');
216
+ ta.value = sid; ta.style.position = 'fixed'; ta.style.opacity = '0';
217
+ document.body.appendChild(ta); ta.select(); document.execCommand('copy');
218
+ document.body.removeChild(ta);
219
+ }
220
+ if (typeof systemMsg === 'function') systemMsg('info', '已复制会话 ID:' + sid);
221
+ } else if (it.act === 'archive') {
222
+ if (!confirm('确定归档此会话?文件将移到 sessions/archived/。')) return;
223
+ fetch('/api/ui/session/archive', {
224
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin',
225
+ body: JSON.stringify({ session_id: sid, agent_id: agentId })
226
+ }).then(function(r) {
227
+ if (!r.ok) alert('归档失败');
228
+ else if (typeof refreshSessionsUnderProject === 'function') refreshSessionsUnderProject(pid);
229
+ }).catch(function() { alert('归档失败'); });
230
+ } else if (it.act === 'delete') {
231
+ deleteSession(sid, pid);
232
+ }
233
+ });
234
+ menu.appendChild(btn);
235
+ });
236
+ var x = (e && e.clientX) || 80;
237
+ var y = (e && e.clientY) || 80;
238
+ menu.style.left = Math.min(x, window.innerWidth - 200) + 'px';
239
+ menu.style.top = Math.min(y, window.innerHeight - 200) + 'px';
240
+ document.body.appendChild(menu);
241
+
242
+ var overlay = document.createElement('div');
243
+ overlay.className = 'tree-overlay';
244
+ overlay.addEventListener('click', closeContextMenu);
245
+ document.body.appendChild(overlay);
246
+ menu.dataset.overlay = '1';
247
+ }
248
+
249
+ function closeContextMenu() {
250
+ document.querySelectorAll('.tree-context-menu').forEach(function(m) { m.remove(); });
251
+ document.querySelectorAll('.tree-overlay').forEach(function(o) { o.remove(); });
252
+ }
253
+
254
+ function copyToClipboard(text) {
255
+ if (navigator.clipboard) {
256
+ navigator.clipboard.writeText(text);
257
+ return;
258
+ }
259
+ var ta = document.createElement('textarea');
260
+ ta.value = text; ta.style.position = 'fixed'; ta.style.opacity = '0';
261
+ document.body.appendChild(ta); ta.select(); document.execCommand('copy');
262
+ document.body.removeChild(ta);
263
+ }
264
+
265
+ function renameProject(pid, currentName) {
266
+ var newName = prompt('重命名项目:', currentName || '');
267
+ if (newName == null) return;
268
+ newName = String(newName).trim();
269
+ if (!newName || newName === currentName) return;
270
+ fetch('/api/ui/projects/rename', {
271
+ method: 'POST',
272
+ headers: { 'Content-Type': 'application/json' },
273
+ credentials: 'same-origin',
274
+ body: JSON.stringify({ agent_id: agentId, project_id: pid, name: newName })
275
+ }).then(function(r) {
276
+ if (r.ok) {
277
+ if (treeProjectsCache && treeProjectsCache.aid === agentId) {
278
+ for (var i = 0; i < treeProjectsCache.projects.length; i++) {
279
+ if (treePid(treeProjectsCache.projects[i].id) === treePid(pid)) {
280
+ treeProjectsCache.projects[i].name = newName;
281
+ break;
282
+ }
283
+ }
284
+ }
285
+ var projDiv = findProjDiv(pid);
286
+ if (projDiv) {
287
+ var name = projDiv.querySelector('.tree-project__name');
288
+ if (name) name.textContent = newName;
289
+ }
290
+ } else alert('重命名失败');
291
+ }).catch(function() { alert('重命名失败'); });
292
+ }
293
+
294
+ function deleteProject(pid) {
295
+ if (!confirm('确定删除项目及其下所有会话?此操作不可恢复。')) return;
296
+ fetch('/api/ui/projects/delete', {
297
+ method: 'POST',
298
+ headers: { 'Content-Type': 'application/json' },
299
+ credentials: 'same-origin',
300
+ body: JSON.stringify({ agent_id: agentId, project_id: pid })
301
+ }).then(function(r) {
302
+ if (r.ok) {
303
+ if (treePid(projectId) === treePid(pid)) {
304
+ projectId = ''; treeProjectActiveId = ''; saveProjectIdForAgent(agentId, '');
305
+ }
306
+ delete treeExpanded[treePid(pid)];
307
+ if (treeProjectsCache && treeProjectsCache.aid === agentId) {
308
+ treeProjectsCache.projects = treeProjectsCache.projects.filter(function(p) {
309
+ return treePid(p.id) !== treePid(pid);
310
+ });
311
+ }
312
+ var treeEl = document.getElementById('projectTree');
313
+ var pdiv = findProjDiv(pid);
314
+ if (pdiv) pdiv.remove();
315
+ if (treeEl && !treeEl.querySelector('.tree-project')) {
316
+ treeEl.innerHTML = '<div class="project-tree__empty">暂无项目,点击下方按钮新建</div>';
317
+ }
318
+ syncTreeProjectActiveHighlight();
319
+ } else alert('删除失败');
320
+ }).catch(function() { alert('删除失败'); });
321
+ }
322
+
323
+ function deleteSession(sid, pid) {
324
+ if (!confirm('确定删除此会话吗?')) return;
325
+ fetch('/api/ui/session/delete', {
326
+ method: 'POST',
327
+ headers: {'Content-Type': 'application/json'},
328
+ credentials: 'same-origin',
329
+ body: JSON.stringify({ session_id: sid, agent_id: agentId })
330
+ }).then(function(r) {
331
+ if (r.ok) {
332
+ if (sessionId === sid) {
333
+ if (typeof saveMsgDraft === 'function') saveMsgDraft();
334
+ sessionId = oaRandomUUID();
335
+ localStorage.setItem(_sidStorageKey(agentId, pid || projectId), sessionId);
336
+ if (typeof msg !== 'undefined' && msg) msg.value = '';
337
+ log.innerHTML = '';
338
+ try { reconnectWsForSession(); } catch (_) {}
339
+ }
340
+ refreshSessionsUnderProject(pid || projectId);
341
+ syncTreeSessionActiveHighlight();
342
+ // 未分类会话删除后可能空了,刷新项目列表以移除虚拟项目
343
+ if ((pid || projectId) === '__unassigned__' && typeof refreshProjects === 'function') {
344
+ refreshProjects();
345
+ }
346
+ if (typeof refreshSessionList === 'function') refreshSessionList().catch(function() {});
347
+ } else alert('删除失败');
348
+ }).catch(function() { alert('删除失败'); });
349
+ }