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 @@
1
+ /* ============ Tool trace inside bubble ============ */.bubble-agent .oa-tool-trace { margin-top: var(--sp-3); font-size: 12px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-subtle); overflow: hidden;}.bubble-agent .oa-tool-trace > summary { cursor: pointer; padding: 6px 10px; font-weight: 550; color: var(--text-secondary); user-select: none; list-style: none; font-size: 11.5px; display: flex; align-items: center; gap: 6px;}.bubble-agent .oa-tool-trace > summary::-webkit-details-marker { display: none; }.bubble-agent .oa-tool-trace > summary::before { content: ''; display: inline-block; width: 0; height: 0; border-left: 4px solid var(--text-muted); border-top: 3px solid transparent; border-bottom: 3px solid transparent; transition: transform 0.15s ease;}.bubble-agent .oa-tool-trace[open] > summary::before { transform: rotate(90deg); }.bubble-agent .oa-tool-trace-pre { margin: 0; padding: 10px 12px; max-height: 40vh; overflow: auto; font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; border-top: 1px solid var(--border); background: var(--bg-panel); font-family: var(--font-mono);}/* ============ Live tool call card ============ */details.oa-live-tool { display: block; position: relative; overflow: visible;}details.oa-live-tool > summary { list-style: none; cursor: pointer; user-select: none; display: flex; align-items: center; gap: 8px; padding: 4px 6px; margin: 0; border-radius: var(--r-sm); transition: background-color 0.15s ease;}details.oa-live-tool > summary::-webkit-details-marker { display: none; }details.oa-live-tool > summary::after { content: ''; width: 0; height: 0; margin-left: auto; border-left: 4px solid var(--text-muted); border-top: 3px solid transparent; border-bottom: 3px solid transparent; transition: transform 0.15s ease; flex: 0 0 auto;}details.oa-live-tool[open] > summary::after { transform: rotate(90deg); }details.oa-live-tool > summary:hover { background: var(--bg-panel); }details.oa-live-tool .oa-live-tool-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}details.oa-live-tool .oa-live-tool-spinner { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: var(--accent, #4f46e5); box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #4f46e5) 55%, transparent); transition: background-color 0.2s ease, box-shadow 0.2s ease;}details.oa-live-tool.is-running .oa-live-tool-spinner { animation: oa-pulse 1.15s ease-in-out infinite;}details.oa-live-tool.is-running > summary { background: linear-gradient(90deg, color-mix(in srgb, var(--accent, #4f46e5) 7%, transparent) 0%, color-mix(in srgb, var(--accent, #4f46e5) 14%, transparent) 40%, color-mix(in srgb, var(--accent, #4f46e5) 7%, transparent) 100%); background-size: 200% 100%; animation: oa-shimmer 2.2s linear infinite;}details.oa-live-tool:not(.is-running) .oa-live-tool-spinner { background: color-mix(in srgb, var(--text-muted) 60%, transparent); box-shadow: none;}details.oa-live-tool .oa-tool-trace-pre { margin: 8px 0 0; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px; font-family: var(--font-mono); font-size: 11.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; max-height: 40vh; overflow: auto;}
@@ -0,0 +1,295 @@
1
+ /* ============ Compose ============ */.compose { flex-shrink: 0; padding: var(--sp-3) var(--sp-8) var(--sp-5); background: linear-gradient(to top, var(--bg) 78%, transparent);}.compose__box { max-width: 820px; margin: 0 auto; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--r-2xl); box-shadow: var(--shadow-sm); transition: border-color 0.15s ease, box-shadow 0.2s ease; display: flex; flex-direction: column; overflow: hidden;}#msg { width: 100%; min-height: 44px; max-height: 220px; border: none; background: transparent; color: var(--text); font-size: 13.5px; font-family: inherit; line-height: 1.55; resize: none; outline: none;}#msg::placeholder { color: var(--text-subtle); }.compose__hint { margin-right: auto; font-size: 11px; color: var(--text-subtle); font-family: var(--font-mono); padding-left: 6px; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}.compose__hint kbd { display: inline-block; padding: 1px 5px; border-radius: var(--r-xs); border: 1px solid var(--border); background: var(--bg-subtle); font-size: 10px; font-family: inherit; color: var(--text-muted); line-height: 1.4;}.compose__model-select { font-size: inherit; font-family: inherit; background: transparent; color: var(--text-secondary); border: none; cursor: pointer; max-width: 120px; vertical-align: baseline; padding: 0; margin: 0; appearance: auto; -webkit-appearance: auto;}.compose__model-select:hover { color: var(--text); }.compose__model-select option { background: var(--bg-panel); color: var(--text); }/* ============ Session running state indicator ============ */
2
+
3
+ /* 通道指示点 — 基础样式 */
4
+ .sess-item__channel-dot {
5
+ display: inline-block;
6
+ width: 8px;
7
+ height: 8px;
8
+ border-radius: 50%;
9
+ background: var(--border-strong);
10
+ flex-shrink: 0;
11
+ transition: background 0.2s ease, box-shadow 0.2s ease;
12
+ }
13
+
14
+ /* 会话列表行 — 运行中状态 */
15
+ .sess-row.is-running {
16
+ position: relative;
17
+ }
18
+ .sess-row.is-running .sess-item-main {
19
+ background: var(--accent-softer);
20
+ }
21
+ .sess-row.is-running .sess-item__channel-dot {
22
+ background: var(--success);
23
+ box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
24
+ animation: sess-running-pulse 1.4s ease-in-out infinite;
25
+ }
26
+ .sess-row.is-running .sess-item__title {
27
+ color: var(--accent);
28
+ font-weight: 600;
29
+ }
30
+ /* ============ 会话「已完成」状态(刚结束运行,绿色实心不闪烁) ============ */
31
+ .sess-row.is-completed .sess-item__channel-dot {
32
+ background: var(--success);
33
+ box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.18);
34
+ animation: none;
35
+ }
36
+ .sess-row.is-completed .sess-item__title {
37
+ color: var(--success);
38
+ font-weight: 600;
39
+ }
40
+ .sess-row.is-completed .sess-item-main {
41
+ background: color-mix(in srgb, var(--success) 6%, transparent);
42
+ }
43
+ /* 树状视图 — 已完成状态 */
44
+ .tree-session.is-completed .tree-session__indicator {
45
+ background: var(--success);
46
+ box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.18);
47
+ animation: none;
48
+ }
49
+ .tree-session.is-completed .tree-session__title {
50
+ color: var(--success);
51
+ font-weight: 600;
52
+ }
53
+
54
+ /* 树状视图 — 运行中状态 */
55
+ .tree-session.is-running .tree-session__row {
56
+ background: var(--accent-softer);
57
+ }
58
+ .tree-session.is-running .tree-session__indicator {
59
+ background: var(--success);
60
+ box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
61
+ animation: sess-running-pulse 1.4s ease-in-out infinite;
62
+ }
63
+ .tree-session.is-running .tree-session__title {
64
+ color: var(--accent);
65
+ font-weight: 600;
66
+ }
67
+ @keyframes sess-running-pulse {
68
+ 0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.45); }
69
+ 50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
70
+ 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
71
+ }
72
+
73
+ /* topbar session-id-chip 运行态 */
74
+ .chat-running .session-id-chip::before {
75
+ background: var(--success);
76
+ animation: sess-running-pulse 1.4s ease-in-out infinite;
77
+ }
78
+
79
+ /* ============ Token / 上下文占用指示器 ============ */
80
+ .token-usage {
81
+ display: inline-flex;
82
+ align-items: center;
83
+ gap: 5px;
84
+ font-family: var(--font-mono);
85
+ color: var(--text-subtle);
86
+ padding: 3px 8px 3px 6px;
87
+ border-radius: var(--r-sm);
88
+ border: 1px solid var(--border);
89
+ background: var(--bg-subtle);
90
+ cursor: default;
91
+ white-space: nowrap;
92
+ user-select: none;
93
+ -webkit-user-select: none;
94
+ transition: border-color 0.25s ease, background 0.25s ease;
95
+ }
96
+ .token-usage:hover {
97
+ background: var(--bg-hover);
98
+ border-color: var(--border-strong);
99
+ }
100
+ .token-usage__icon {
101
+ flex-shrink: 0;
102
+ color: var(--text-muted);
103
+ }
104
+ .token-usage--seg {
105
+ gap: 6px;
106
+ }
107
+ .token-usage__segs {
108
+ display: inline-flex;
109
+ align-items: center;
110
+ gap: 2px;
111
+ flex-shrink: 0;
112
+ }
113
+ .token-usage__seg {
114
+ display: block;
115
+ width: 10px;
116
+ height: 8px;
117
+ border-radius: 2px;
118
+ background: var(--border);
119
+ transition: background-color 0.25s ease, transform 0.2s ease;
120
+ }
121
+ .token-usage__seg.is-on {
122
+ background: var(--accent);
123
+ }
124
+ .token-usage__pct {
125
+ min-width: 28px;
126
+ font-size: 10.5px;
127
+ font-weight: 500;
128
+ font-variant-numeric: tabular-nums;
129
+ text-align: right;
130
+ color: var(--text-secondary);
131
+ line-height: 1;
132
+ }
133
+ .token-usage.is-warm .token-usage__seg.is-on {
134
+ background: #d97706;
135
+ }
136
+ .token-usage.is-warm .token-usage__pct,
137
+ .token-usage.is-warm .token-usage__icon {
138
+ color: #d97706;
139
+ }
140
+ .token-usage.is-hot {
141
+ border-color: rgba(220, 38, 38, 0.35);
142
+ background: var(--danger-soft);
143
+ }
144
+ .token-usage.is-hot .token-usage__seg.is-on {
145
+ background: #dc2626;
146
+ }
147
+ .token-usage.is-hot .token-usage__pct,
148
+ .token-usage.is-hot .token-usage__icon {
149
+ color: #dc2626;
150
+ }
151
+
152
+ /* ============ New message floating button ============ */.new-msg-btn { position: sticky; bottom: 0; align-self: center; z-index: 20; display: inline-flex; align-items: center; gap: 6px; padding: 7px 16px; margin: -38px 0 4px; border: 1px solid var(--border-strong); border-radius: 20px; background: var(--bg-panel); color: var(--accent); font-size: 12.5px; font-weight: 500; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.12); transition: opacity 0.2s ease, transform 0.2s ease; user-select: none; -webkit-user-select: none;}.new-msg-btn:hover { background: var(--bg-hover); box-shadow: 0 3px 14px rgba(0,0,0,0.18); transform: translateY(-1px);}.new-msg-btn:active { transform: translateY(0);}.new-msg-btn__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0;}
153
+ /* ============ Camera modal (real-time camera + recorder) ============ */
154
+ .camera-modal__dialog {
155
+ max-width: 720px;
156
+ width: min(720px, 92vw);
157
+ }
158
+ .camera-modal__body {
159
+ display: flex;
160
+ flex-direction: column;
161
+ gap: 10px;
162
+ padding: 12px 16px 0;
163
+ }
164
+ .camera-modal__mode {
165
+ display: inline-flex;
166
+ align-self: flex-start;
167
+ border: 1px solid var(--border);
168
+ border-radius: 999px;
169
+ padding: 2px;
170
+ background: var(--bg-panel);
171
+ gap: 2px;
172
+ }
173
+ .camera-modal__mode-btn {
174
+ border: 0;
175
+ background: transparent;
176
+ color: var(--text-muted, #9ca3af);
177
+ padding: 4px 14px;
178
+ font-size: 12.5px;
179
+ border-radius: 999px;
180
+ cursor: pointer;
181
+ transition: background 0.15s ease, color 0.15s ease;
182
+ }
183
+ .camera-modal__mode-btn:hover { color: var(--text); }
184
+ .camera-modal__mode-btn.is-active {
185
+ background: var(--accent, #6366f1);
186
+ color: #fff;
187
+ }
188
+ .camera-modal__stage {
189
+ position: relative;
190
+ background: #000;
191
+ border-radius: 8px;
192
+ overflow: hidden;
193
+ min-height: 280px;
194
+ display: flex;
195
+ align-items: center;
196
+ justify-content: center;
197
+ }
198
+ .camera-modal__video {
199
+ width: 100%;
200
+ max-height: 60vh;
201
+ object-fit: contain;
202
+ background: #000;
203
+ display: block;
204
+ }
205
+ .camera-modal__video--mirror {
206
+ transform: scaleX(-1);
207
+ }
208
+ .camera-modal__footer[hidden] {
209
+ display: none !important;
210
+ }
211
+ .camera-modal__status {
212
+ position: absolute;
213
+ left: 0; right: 0; bottom: 0;
214
+ margin: 0;
215
+ padding: 6px 12px;
216
+ background: rgba(0,0,0,0.55);
217
+ color: #fff;
218
+ font-size: 12px;
219
+ text-align: center;
220
+ }
221
+ .camera-modal__fallback {
222
+ position: absolute;
223
+ left: 50%;
224
+ bottom: 36px;
225
+ transform: translateX(-50%);
226
+ z-index: 2;
227
+ }
228
+ .camera-modal__rec-indicator {
229
+ position: absolute;
230
+ top: 10px;
231
+ left: 10px;
232
+ display: inline-flex;
233
+ align-items: center;
234
+ gap: 6px;
235
+ padding: 4px 10px;
236
+ border-radius: 999px;
237
+ background: rgba(0,0,0,0.6);
238
+ color: #fff;
239
+ font-size: 12px;
240
+ font-variant-numeric: tabular-nums;
241
+ }
242
+ .camera-modal__rec-dot {
243
+ width: 8px;
244
+ height: 8px;
245
+ border-radius: 50%;
246
+ background: #ef4444;
247
+ animation: camera-rec-pulse 1s ease-in-out infinite;
248
+ }
249
+ @keyframes camera-rec-pulse {
250
+ 0%, 100% { opacity: 1; }
251
+ 50% { opacity: 0.35; }
252
+ }
253
+
254
+ /* ==============================
255
+ * 上下文历史面板 (ctx-history)
256
+ * ============================== */
257
+ .ctx-history {
258
+ margin: 10px 16px;
259
+ border: 1px solid var(--border, #ddd);
260
+ border-radius: 6px;
261
+ background: var(--bg-secondary, #fafafa);
262
+ font-size: 12px;
263
+ overflow: hidden;
264
+ }
265
+ .ctx-history__header {
266
+ padding: 6px 10px;
267
+ cursor: pointer;
268
+ user-select: none;
269
+ font-weight: 500;
270
+ color: var(--text-primary, #333);
271
+ }
272
+ .ctx-history__header:hover {
273
+ background: var(--bg-hover, #f0f0f0);
274
+ }
275
+ .ctx-history__table {
276
+ width: 100%;
277
+ border-collapse: collapse;
278
+ font-size: 11px;
279
+ }
280
+ .ctx-history__table th,
281
+ .ctx-history__table td {
282
+ padding: 4px 8px;
283
+ text-align: right;
284
+ border-top: 1px solid var(--border, #eee);
285
+ }
286
+ .ctx-history__table th {
287
+ background: var(--bg-tertiary, #f0f0f0);
288
+ font-weight: 600;
289
+ color: var(--text-secondary, #666);
290
+ text-align: right;
291
+ }
292
+ .ctx-history__table th:first-child,
293
+ .ctx-history__table td:first-child {
294
+ text-align: center;
295
+ }
@@ -0,0 +1,176 @@
1
+ /* ================================================================
2
+ * 05a-session-history.js
3
+ * - Session history loading (loadSessionHistoryIntoLog)
4
+ * - Older history paging (loadOlderSessionHistoryChunk)
5
+ * - Session list fetch / refresh (refreshSessionList)
6
+ * - Session list bindings (bindSessListOnce)
7
+ * - Web UI sessions initialization (initWebUiSessions)
8
+ * - Logout
9
+ * ================================================================ */
10
+
11
+ (function () {
12
+ const btn = document.getElementById('btnLogout');
13
+ if (!btn) return;
14
+ btn.addEventListener('click', async () => {
15
+ try { await fetch('/api/ui/auth/logout', { method: 'POST', credentials: 'same-origin' }); } catch (_) {}
16
+ tryRemoveSS(STORAGE_KEYS.WS_TOKEN);
17
+ location.href = '/';
18
+ });
19
+ })();
20
+
21
+ // ---------------- Session history loading ----------------
22
+
23
+ function bindHistoryPagingOnce() {
24
+ if (historyPagingBound || !log) return;
25
+ historyPagingBound = true;
26
+ log.addEventListener('scroll', () => {
27
+ if (!historyHasMoreOlder || historyLoadingOlder) return;
28
+ if (log.scrollTop > 120) return;
29
+ if (historyScrollTimer) return;
30
+ historyScrollTimer = setTimeout(() => {
31
+ historyScrollTimer = null;
32
+ if (!historyHasMoreOlder || historyLoadingOlder) return;
33
+ if (log.scrollTop > 120) return;
34
+ loadOlderSessionHistoryChunk();
35
+ }, 120);
36
+ }, { passive: true });
37
+ }
38
+
39
+ async function parseJsonResponse(r) {
40
+ const text = await r.text();
41
+ if (!text) return {};
42
+ try {
43
+ return JSON.parse(text);
44
+ } catch (e) {
45
+ var hint = (text || '').replace(/\s+/g, ' ').trim().slice(0, 240);
46
+ throw new SyntaxError('响应不是 JSON(HTTP ' + r.status + '):' + hint);
47
+ }
48
+ }
49
+
50
+ async function loadOlderSessionHistoryChunk() {
51
+ if (!webuiSessionsEnabled || !historyHasMoreOlder || historyLoadingOlder ||
52
+ historyFirstBlockIndex == null || historyFirstBlockIndex <= 0) return;
53
+ historyLoadingOlder = true;
54
+ const oldH = log.scrollHeight;
55
+ const oldT = log.scrollTop;
56
+ try {
57
+ const r = await fetch('/api/ui/session/history?session_id=' + encodeURIComponent(sessionId) +
58
+ '&agent_id=' + encodeURIComponent(agentId) + projectQuerySuffix() +
59
+ '&before_block_index=' + encodeURIComponent(String(historyFirstBlockIndex)));
60
+ const j = await parseJsonResponse(r);
61
+ if (!r.ok) throw new Error(j.detail || r.statusText);
62
+ const rows = j.messages || [];
63
+ rows.slice().reverse().forEach((m) => {
64
+ const ts = m.ts;
65
+ const idx = m.idx;
66
+ const o = { at: ts, prepend: true, idx: idx };
67
+ if (m.role === 'user') bubble('user', m.content || m.text || '', Object.assign(o, { attachments: m.attachments || [] }));
68
+ else {
69
+ // 拆分渲染:工具链各自独立展示,保持与实时执行一致的样式
70
+ var fn = (typeof bubbleAgentWithSplitToolTrace === 'function')
71
+ ? bubbleAgentWithSplitToolTrace : bubble;
72
+ if (fn !== bubble) {
73
+ fn(m.content || '', m.tool_trace || [], o);
74
+ } else {
75
+ bubble('agent', m.content || '', Object.assign({ toolTrace: m.tool_trace || [] }, o));
76
+ }
77
+ }
78
+ });
79
+ if (j.first_block_index != null) historyFirstBlockIndex = j.first_block_index;
80
+ historyHasMoreOlder = !!j.has_more_older;
81
+ const fixTop = () => { log.scrollTop = oldT + (log.scrollHeight - oldH); };
82
+ fixTop();
83
+ requestAnimationFrame(() => { requestAnimationFrame(fixTop); });
84
+ } catch (e) { systemMsg('err', '加载更早记录失败:' + String(e)); }
85
+ finally { historyLoadingOlder = false; }
86
+ }
87
+
88
+ async function loadSessionHistoryIntoLog(skipTreeRefresh) {
89
+ try {
90
+ if (typeof resetTokenUsageCache === 'function') resetTokenUsageCache();
91
+ // 立即用持久化的 context_usage 恢复指示器,避免在历史加载完成前变成 1% 误显示
92
+ try {
93
+ const cuRow = (lastSessionsCache || []).find((r) => r.session_id === sessionId);
94
+ const cu = cuRow && cuRow.context_usage;
95
+ if (cu && typeof updateTokenUsage === 'function') {
96
+ var cuPt = (typeof pickContextUsageTokens === 'function')
97
+ ? pickContextUsageTokens(cu) : (Number(cu.prompt_tokens) || 0);
98
+ if (cuPt > 0) {
99
+ updateTokenUsage({ prompt_tokens: cuPt, peak_prompt_tokens: cu.peak_prompt_tokens });
100
+ }
101
+ }
102
+ } catch (_) {}
103
+ const r = await fetch('/api/ui/session/history?session_id=' + encodeURIComponent(sessionId) +
104
+ '&agent_id=' + encodeURIComponent(agentId) + projectQuerySuffix());
105
+ const j = await parseJsonResponse(r);
106
+ if (!r.ok) throw new Error(j.detail || r.statusText);
107
+ log.innerHTML = '';
108
+ resetAgentReplyDedupe();
109
+ historyFirstBlockIndex = j.first_block_index != null ? j.first_block_index : null;
110
+ historyHasMoreOlder = !!j.has_more_older;
111
+ bindHistoryPagingOnce();
112
+ if (j.truncated_start || j.has_more_older) {
113
+ systemMsg('info', '历史较长:默认只载入最近若干轮对话;上滑到顶部可继续加载更早内容。', { skipScroll: true });
114
+ }
115
+ const rows = j.messages || [];
116
+ rows.forEach((m) => {
117
+ const ts = m.ts;
118
+ const idx = m.idx;
119
+ const skip = { skipScroll: true, at: ts, idx: idx };
120
+ if (m.role === 'user') bubble('user', m.content || m.text || '', Object.assign(skip, { attachments: m.attachments || [] }));
121
+ else {
122
+ // 拆分渲染:工具链各自独立展示
123
+ var fn2 = (typeof bubbleAgentWithSplitToolTrace === 'function')
124
+ ? bubbleAgentWithSplitToolTrace : bubble;
125
+ if (fn2 !== bubble) {
126
+ fn2(m.content || '', m.tool_trace || [], skip);
127
+ } else {
128
+ bubble('agent', m.content || '', Object.assign({ toolTrace: m.tool_trace || [] }, skip));
129
+ }
130
+ }
131
+ });
132
+ // 滚动到底部:双重 rAF 确保 DOM 渲染完成后滚动,再加 setTimeout 兜底(图片等异步渲染可能延迟布局)
133
+ (function scrollLogAfterRender() {
134
+ requestAnimationFrame(() => {
135
+ requestAnimationFrame(() => {
136
+ scrollLogForce();
137
+ setTimeout(scrollLogForce, 80);
138
+ });
139
+ });
140
+ })();
141
+ // 历史加载完成后用持久化的 context_usage 校正指示器
142
+ try {
143
+ const cu = j && j.context_usage;
144
+ if (cu && typeof updateTokenUsage === 'function') {
145
+ var histPt = (typeof pickContextUsageTokens === 'function')
146
+ ? pickContextUsageTokens(cu) : (Number(cu.prompt_tokens) || 0);
147
+ if (histPt > 0) {
148
+ updateTokenUsage({ prompt_tokens: histPt, peak_prompt_tokens: cu.peak_prompt_tokens });
149
+ }
150
+ } else if (typeof recalcTokenUsageFromDom === 'function') {
151
+ setTimeout(recalcTokenUsageFromDom, 100);
152
+ }
153
+ } catch (_) {}
154
+ // 加载侧边栏费用汇总
155
+ if (j.accumulated_usage && typeof updateSidebarCost === 'function') {
156
+ updateSidebarCost(j.accumulated_usage);
157
+ }
158
+ await refreshSessionList();
159
+ if (!skipTreeRefresh && typeof refreshSessionsUnderProject === 'function') {
160
+ refreshSessionsUnderProject(projectId);
161
+ }
162
+ const row = lastSessionsCache.find((r) => r.session_id === sessionId);
163
+ markSessionReadByCount(sessionId, row ? (row.message_count || 0) : 0);
164
+ } catch (e) {
165
+ historyFirstBlockIndex = null;
166
+ historyHasMoreOlder = false;
167
+ systemMsg('err', '载入会话记录失败:' + String(e));
168
+ }
169
+ }
170
+
171
+ // ---------------- Session list fetch / sync ----------------
172
+
173
+ async function refreshSessionList() {
174
+ const listEl = document.getElementById('sessList');
175
+ try {
176
+ const r = await fetch('/api/ui/sessions?limit=80&agent_id=' + encodeURIComponent(agentId) + projectQuerySuffix());
@@ -0,0 +1,114 @@
1
+ if (!r.ok) throw new Error((await r.json()).detail || r.statusText);
2
+ const j = await r.json();
3
+ const cur = sessionId;
4
+ lastSessionsCache = j.sessions || [];
5
+ ensureReadBaseline(lastSessionsCache);
6
+ if (listEl) {
7
+ listEl.innerHTML = '';
8
+ const pin = pinSessionToTopOnce;
9
+ let rows = orderSessionsWithPinFirst(lastSessionsCache, pin);
10
+ if (!rows.some((x) => x.session_id === cur)) {
11
+ rows = [{ session_id: cur, message_count: 0, display_title: '新对话', channel: 'Web 聊天', preview: '' }].concat(rows);
12
+ }
13
+ rows.forEach((row) => listEl.appendChild(buildSessListItem(row)));
14
+ highlightSessList(cur);
15
+ }
16
+ pinSessionToTopOnce = '';
17
+ updateMainHeaderForSession(cur);
18
+ // DOM 重建后重新应用每个会话的运行/已完成状态(避免 restoreRunningSessions 时序竞争)
19
+ requestAnimationFrame(function() {
20
+ (lastSessionsCache || []).forEach(function(r) {
21
+ if (typeof applySessionRunningState === 'function') applySessionRunningState(r.session_id);
22
+ if (typeof applySessionCompletedState === 'function') applySessionCompletedState(r.session_id);
23
+ });
24
+ });
25
+ } catch (e) {
26
+ }
27
+ }
28
+
29
+
30
+ // ---------------- Session list event binding ----------------
31
+
32
+ function bindSessListOnce() {
33
+ const listEl = document.getElementById('sessList');
34
+ if (!listEl || listEl.dataset.bound === '1') return;
35
+ listEl.dataset.bound = '1';
36
+ listEl.addEventListener('click', async (ev) => {
37
+ const actBtn = ev.target.closest('[data-sess-act]');
38
+ if (actBtn) {
39
+ ev.preventDefault(); ev.stopPropagation();
40
+ const rowEl = actBtn.closest('.sess-row');
41
+ const sid = rowEl && rowEl.getAttribute('data-session-id');
42
+ const act = actBtn.getAttribute('data-sess-act');
43
+ if (!sid || !act) return;
44
+ const titleHint = (rowEl.querySelector('.sess-item__title') && rowEl.querySelector('.sess-item__title').textContent) || sid;
45
+ try {
46
+ if (act === 'archive') {
47
+ if (!confirm('确定归档「' + titleHint + '」?文件将移到 sessions/archived/。')) return;
48
+ const r = await fetch('/api/ui/session/archive', {
49
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin',
50
+ body: JSON.stringify({ session_id: sid, agent_id: agentId })
51
+ });
52
+ const j = await r.json().catch(() => ({}));
53
+ if (!r.ok) throw new Error(j.detail || r.statusText);
54
+ } else if (act === 'delete') {
55
+ if (!confirm('确定删除「' + titleHint + '」?此操作不可恢复。')) return;
56
+ const r = await fetch('/api/ui/session/delete', {
57
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin',
58
+ body: JSON.stringify({ session_id: sid, agent_id: agentId })
59
+ });
60
+ const j = await r.json().catch(() => ({}));
61
+ if (!r.ok) throw new Error(j.detail || r.statusText);
62
+ } else if (act === 'copy-id') {
63
+ try { await navigator.clipboard.writeText(sid); systemMsg('info', '已复制会话 ID:' + sid); }
64
+ catch (_) {
65
+ const ta = document.createElement('textarea');
66
+ ta.value = sid; ta.style.position = 'fixed'; ta.style.opacity = '0';
67
+ document.body.appendChild(ta); ta.select(); document.execCommand('copy');
68
+ document.body.removeChild(ta); systemMsg('info', '已复制会话 ID:' + sid);
69
+ }
70
+ return;
71
+ }
72
+ } catch (e) { alert(String(e)); return; }
73
+ removeSessionReadBaseline(sid);
74
+ // 存档/删除旧会话时:保存当前草稿,新建会话后清空输入
75
+ if (sessionId === sid) {
76
+ if (typeof saveMsgDraft === 'function') saveMsgDraft();
77
+ sessionId = oaRandomUUID();
78
+ localStorage.setItem(_sidStorageKey(agentId, projectId), sessionId);
79
+ updateComposerButtons(); log.innerHTML = ''; resetAgentReplyDedupe(); reconnectWsForSession();
80
+ if (typeof msg !== 'undefined' && msg) msg.value = '';
81
+ }
82
+ await refreshSessionList();
83
+ highlightSessList(sessionId);
84
+ updateMainHeaderForSession(sessionId);
85
+ await loadSessionHistoryIntoLog(true);
86
+ if (typeof activatePage === 'function') activatePage('chat');
87
+ return;
88
+ }
89
+ const btn = ev.target.closest('.sess-item-main');
90
+ if (!btn) return;
91
+ const sid = btn.getAttribute('data-session-id');
92
+ if (!sid) return;
93
+ // 切换会话:保存当前草稿,恢复目标会话草稿
94
+ if (typeof saveMsgDraft === 'function') saveMsgDraft();
95
+ sessionId = sid;
96
+ localStorage.setItem(_sidStorageKey(agentId, projectId), sessionId);
97
+ updateComposerButtons();
98
+ if (typeof restoreMsgDraft === 'function') restoreMsgDraft(sid);
99
+ const row = lastSessionsCache.find((r) => r.session_id === sid);
100
+ markSessionReadByCount(sid, row ? (row.message_count || 0) : 0);
101
+ reconnectWsForSession(); resetAgentReplyDedupe();
102
+ highlightSessList(sid); updateMainHeaderForSession(sid);
103
+ refreshSessionList().catch(() => {});
104
+ if (typeof activatePage === 'function') activatePage('chat');
105
+ });
106
+ }
107
+
108
+ // ---------------- Web UI sessions initialization ----------------
109
+
110
+ async function initWebUiSessions() {
111
+ // 页面刷新后先恢复正在运行中的会话状态(心跳指示)
112
+ await restoreRunningSessions();
113
+ const sidebar = document.getElementById('chatSidebar');
114
+ const fs = document.getElementById('fieldsetChatSessions');