sycommon-python-lib 0.2.12a4__py3-none-any.whl → 0.2.12a6__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.
- sycommon/devchat/_page.html +606 -0
- sycommon/devchat/handler.py +300 -16
- sycommon/devchat/login.py +223 -0
- sycommon/devchat/store.py +2 -1
- sycommon/devchat/tasks.py +160 -10
- {sycommon_python_lib-0.2.12a4.dist-info → sycommon_python_lib-0.2.12a6.dist-info}/METADATA +1 -1
- {sycommon_python_lib-0.2.12a4.dist-info → sycommon_python_lib-0.2.12a6.dist-info}/RECORD +10 -8
- {sycommon_python_lib-0.2.12a4.dist-info → sycommon_python_lib-0.2.12a6.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.2.12a4.dist-info → sycommon_python_lib-0.2.12a6.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.2.12a4.dist-info → sycommon_python_lib-0.2.12a6.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>DevChat 开发协作</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
--navy: #0f0966; --blue: #185fa5; --blue-bg: #e6f1fb;
|
|
10
|
+
--teal: #0f6e56; --teal-bg: #e1f5ee; --orange: #e68615; --orange-bg: #faeeda;
|
|
11
|
+
--red: #a32d2d; --red-bg: #fcebeb;
|
|
12
|
+
--ink: #1f2329; --ink-2: #4b5563; --ink-3: #8a919c;
|
|
13
|
+
--line: #e5e7eb; --bg: #f6f7f9; --card: #fff; --r: 10px;
|
|
14
|
+
}
|
|
15
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
16
|
+
html, body { height: 100%; font-family: 'PingFang SC','Microsoft YaHei','Segoe UI',sans-serif; color: var(--ink); font-size: 14px; background: var(--bg); }
|
|
17
|
+
body.standalone { display: flex; flex-direction: column; }
|
|
18
|
+
body.embedded { background: transparent; overflow: hidden; }
|
|
19
|
+
|
|
20
|
+
/* 悬浮球(嵌入模式) */
|
|
21
|
+
.dc-fab {
|
|
22
|
+
position: fixed; right: 22px; bottom: 22px; width: 52px; height: 52px;
|
|
23
|
+
border-radius: 50%; background: var(--navy); color: #fff; border: none; cursor: pointer;
|
|
24
|
+
font-size: 22px; display: none; align-items: center; justify-content: center;
|
|
25
|
+
box-shadow: 0 6px 18px rgba(15,9,102,.35); z-index: 2147483000; transition: transform .15s;
|
|
26
|
+
}
|
|
27
|
+
.dc-fab:hover { transform: scale(1.06); }
|
|
28
|
+
.dc-fab .dc-fab-badge {
|
|
29
|
+
position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 4px;
|
|
30
|
+
border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
|
|
31
|
+
display: none;
|
|
32
|
+
}
|
|
33
|
+
.dc-fab .dc-fab-badge.show { display: block; }
|
|
34
|
+
body.embedded .dc-fab { display: flex; }
|
|
35
|
+
|
|
36
|
+
/* 面板 */
|
|
37
|
+
.dc-panel {
|
|
38
|
+
display: none; flex-direction: column;
|
|
39
|
+
width: 380px; height: 520px; max-height: calc(100vh - 44px);
|
|
40
|
+
background: var(--card); border: 1px solid var(--line); border-radius: 14px;
|
|
41
|
+
box-shadow: 0 12px 40px rgba(31,35,41,.22); overflow: hidden; z-index: 2147483001;
|
|
42
|
+
}
|
|
43
|
+
body.standalone .dc-panel { display: flex; width: 100%; height: 100%; max-height: none; border: none; border-radius: 0; }
|
|
44
|
+
body.embedded .dc-panel.open { display: flex; position: fixed; right: 22px; bottom: 86px; }
|
|
45
|
+
|
|
46
|
+
.dc-head {
|
|
47
|
+
display: flex; align-items: center; gap: 8px; padding: 12px 14px;
|
|
48
|
+
background: var(--navy); color: #fff; flex-shrink: 0;
|
|
49
|
+
}
|
|
50
|
+
.dc-head .dc-title { font-weight: 700; font-size: 14px; flex: 1; }
|
|
51
|
+
.dc-head .dc-sub { font-size: 11px; opacity: .75; }
|
|
52
|
+
.dc-head button {
|
|
53
|
+
background: rgba(255,255,255,.15); border: none; color: #fff; border-radius: 6px;
|
|
54
|
+
padding: 3px 9px; cursor: pointer; font-size: 12px;
|
|
55
|
+
}
|
|
56
|
+
.dc-head button:hover { background: rgba(255,255,255,.28); }
|
|
57
|
+
|
|
58
|
+
.dc-statusbar {
|
|
59
|
+
display: flex; align-items: center; gap: 6px; padding: 6px 14px;
|
|
60
|
+
background: var(--blue-bg); color: var(--blue); font-size: 12px; flex-shrink: 0;
|
|
61
|
+
}
|
|
62
|
+
.dc-statusbar.busy { background: var(--orange-bg); color: var(--orange); }
|
|
63
|
+
.dc-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
|
|
64
|
+
.dc-dot.pulse { animation: dcPulse 1.2s infinite; }
|
|
65
|
+
@keyframes dcPulse { 50% { opacity: .3; } }
|
|
66
|
+
|
|
67
|
+
.dc-messages { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
|
|
68
|
+
.dc-msg { max-width: 86%; }
|
|
69
|
+
.dc-msg.user { align-self: flex-end; }
|
|
70
|
+
.dc-msg-name { font-size: 11px; color: var(--ink-3); margin-bottom: 3px; }
|
|
71
|
+
.dc-msg.user .dc-msg-name { text-align: right; }
|
|
72
|
+
.dc-msg-bubble {
|
|
73
|
+
padding: 8px 11px; border-radius: 10px; background: var(--bg);
|
|
74
|
+
white-space: pre-wrap; word-break: break-word; line-height: 1.55; font-size: 13px;
|
|
75
|
+
}
|
|
76
|
+
.dc-msg.user .dc-msg-bubble { background: var(--navy); color: #fff; }
|
|
77
|
+
.dc-msg.claude .dc-msg-bubble { background: var(--teal-bg); border: 1px solid #cbe9de; }
|
|
78
|
+
.dc-msg.system .dc-msg-bubble { background: var(--orange-bg); color: #8a5508; font-size: 12px; }
|
|
79
|
+
|
|
80
|
+
.dc-tool {
|
|
81
|
+
align-self: flex-start; font-size: 11px; color: var(--ink-3);
|
|
82
|
+
background: var(--bg); border: 1px dashed var(--line); border-radius: 6px; padding: 2px 8px;
|
|
83
|
+
max-width: 86%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
84
|
+
}
|
|
85
|
+
.dc-typing {
|
|
86
|
+
align-self: flex-start; font-size: 12px; color: var(--teal); padding: 0 2px;
|
|
87
|
+
display: flex; gap: 4px; align-items: center;
|
|
88
|
+
}
|
|
89
|
+
.dc-typing .dc-caret { display: inline-block; width: 7px; background: var(--teal); animation: dcBlink .8s infinite; height: 13px; }
|
|
90
|
+
@keyframes dcBlink { 50% { opacity: 0; } }
|
|
91
|
+
|
|
92
|
+
.dc-compose { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); flex-shrink: 0; background: #fff; }
|
|
93
|
+
.dc-compose textarea {
|
|
94
|
+
flex: 1; resize: none; border: 1px solid var(--line); border-radius: 8px;
|
|
95
|
+
padding: 7px 10px; font: inherit; height: 58px; outline: none;
|
|
96
|
+
}
|
|
97
|
+
.dc-compose textarea:focus { border-color: var(--blue); }
|
|
98
|
+
.dc-send-col { display: flex; flex-direction: column; gap: 6px; justify-content: flex-end; }
|
|
99
|
+
.dc-btn {
|
|
100
|
+
border: none; border-radius: 8px; padding: 7px 14px; cursor: pointer;
|
|
101
|
+
font: inherit; font-size: 13px; background: var(--navy); color: #fff;
|
|
102
|
+
}
|
|
103
|
+
.dc-btn:disabled { opacity: .5; cursor: not-allowed; }
|
|
104
|
+
.dc-btn.ghost { background: var(--orange-bg); color: #8a5508; font-size: 12px; padding: 5px 10px; }
|
|
105
|
+
.dc-btn.ghost:disabled { background: var(--line); color: var(--ink-3); }
|
|
106
|
+
.dc-hint { font-size: 11px; color: var(--ink-3); padding: 0 14px 8px; flex-shrink: 0; }
|
|
107
|
+
|
|
108
|
+
/* ===== 需求队列(左栏任务卡) ===== */
|
|
109
|
+
.dc-tabs { display: flex; border-bottom: 1px solid var(--line); flex-shrink: 0; }
|
|
110
|
+
.dc-tab {
|
|
111
|
+
flex: 1; padding: 8px 0; text-align: center; font-size: 12px; color: var(--ink-2);
|
|
112
|
+
background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent;
|
|
113
|
+
font-family: inherit;
|
|
114
|
+
}
|
|
115
|
+
.dc-tab.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }
|
|
116
|
+
.dc-tab .dc-tab-count {
|
|
117
|
+
display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 3px;
|
|
118
|
+
border-radius: 8px; background: var(--bg); font-size: 10px; color: var(--ink-2);
|
|
119
|
+
}
|
|
120
|
+
.dc-tasks { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
|
|
121
|
+
.dc-task {
|
|
122
|
+
border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
|
|
123
|
+
background: #fff; display: flex; flex-direction: column; gap: 5px;
|
|
124
|
+
}
|
|
125
|
+
.dc-task.s-queued { border-left: 3px solid var(--ink-3); }
|
|
126
|
+
.dc-task.s-running { border-left: 3px solid var(--blue); background: var(--blue-bg); }
|
|
127
|
+
.dc-task.s-done { border-left: 3px solid var(--teal); }
|
|
128
|
+
.dc-task.s-error,
|
|
129
|
+
.dc-task.s-cancelled { border-left: 3px solid var(--red); background: var(--red-bg); }
|
|
130
|
+
.dc-task-top { display: flex; align-items: center; gap: 6px; }
|
|
131
|
+
.dc-task-title {
|
|
132
|
+
flex: 1; font-size: 12px; color: var(--ink); overflow: hidden;
|
|
133
|
+
text-overflow: ellipsis; white-space: nowrap;
|
|
134
|
+
}
|
|
135
|
+
.dc-pill {
|
|
136
|
+
font-size: 10px; padding: 1px 8px; border-radius: 8px; white-space: nowrap;
|
|
137
|
+
display: inline-flex; align-items: center; gap: 4px;
|
|
138
|
+
}
|
|
139
|
+
.dc-pill.p-queued { background: var(--bg); color: var(--ink-2); }
|
|
140
|
+
.dc-pill.p-running { background: #d9e8f7; color: var(--blue); }
|
|
141
|
+
.dc-pill.p-running .dc-mini-spin { animation: dcPulse 1s infinite; }
|
|
142
|
+
.dc-pill.p-done { background: var(--teal-bg); color: var(--teal); }
|
|
143
|
+
.dc-pill.p-error, .dc-pill.p-cancelled { background: var(--red-bg); color: var(--red); }
|
|
144
|
+
.dc-task-meta { font-size: 10px; color: var(--ink-3); display: flex; gap: 8px; }
|
|
145
|
+
.dc-task-err { font-size: 10px; color: var(--red); word-break: break-all; }
|
|
146
|
+
.dc-task .dc-task-cancel {
|
|
147
|
+
border: none; background: none; color: var(--ink-3); cursor: pointer; font-size: 12px;
|
|
148
|
+
padding: 0 2px;
|
|
149
|
+
}
|
|
150
|
+
.dc-task .dc-task-cancel:hover { color: var(--red); }
|
|
151
|
+
</style>
|
|
152
|
+
</head>
|
|
153
|
+
<body class="standalone">
|
|
154
|
+
<button class="dc-fab" id="dcFab" aria-label="打开 DevChat 开发协作">
|
|
155
|
+
<span aria-hidden="true">💬</span>
|
|
156
|
+
<span class="dc-fab-badge" id="dcBadge">1</span>
|
|
157
|
+
</button>
|
|
158
|
+
|
|
159
|
+
<div class="dc-panel" id="dcPanel" role="dialog" aria-label="DevChat 开发协作面板">
|
|
160
|
+
<!-- 登录视图(LDAP 模式未登录;登录后隐藏) -->
|
|
161
|
+
<div class="dc-login" id="dcLoginView" style="display:none;flex:1;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:24px">
|
|
162
|
+
<div style="font-size:30px">🤖</div>
|
|
163
|
+
<div style="font-weight:700;font-size:15px">DevChat 登录(LDAP 域账号)</div>
|
|
164
|
+
<input id="dcLoginUser" placeholder="域账号(如 osulcode.xiao)" autocomplete="username"
|
|
165
|
+
style="width:100%;max-width:300px;padding:8px 10px;border:1px solid var(--line);border-radius:8px;font:inherit;outline:none">
|
|
166
|
+
<input id="dcLoginPass" type="password" placeholder="密码" autocomplete="current-password"
|
|
167
|
+
style="width:100%;max-width:300px;padding:8px 10px;border:1px solid var(--line);border-radius:8px;font:inherit;outline:none">
|
|
168
|
+
<div id="dcLoginErr" style="font-size:12px;color:var(--red);min-height:16px"></div>
|
|
169
|
+
<button id="dcLoginBtn" class="dc-btn" style="width:100%;max-width:300px">登录</button>
|
|
170
|
+
<div style="font-size:11px;color:var(--ink-3)">登录一次后同一浏览器 7 天内免登录;提交人将记录到每条需求</div>
|
|
171
|
+
</div>
|
|
172
|
+
<div id="dcMainView" style="display:none;flex-direction:column;flex:1;min-height:0">
|
|
173
|
+
<div class="dc-head">
|
|
174
|
+
<div style="flex:1">
|
|
175
|
+
<div class="dc-title">DevChat 开发协作</div>
|
|
176
|
+
<div class="dc-sub" id="dcSub">群聊 · claude code 在编队里</div>
|
|
177
|
+
</div>
|
|
178
|
+
<button id="dcRestartBtn" title="重建并重启服务(仅管理员)" style="display:none">⟳ 重启服务</button>
|
|
179
|
+
<button id="dcCloseBtn" title="收起" style="display:none">—</button>
|
|
180
|
+
</div>
|
|
181
|
+
<div class="dc-statusbar" id="dcStatus"><span class="dc-dot"></span><span id="dcStatusText">连接中…</span></div>
|
|
182
|
+
<div class="dc-tabs">
|
|
183
|
+
<button class="dc-tab active" id="dcTabChat" data-tab="chat">群聊</button>
|
|
184
|
+
<button class="dc-tab" id="dcTabTasks" data-tab="tasks">需求队列 <span class="dc-tab-count" id="dcTaskCount">0</span></button>
|
|
185
|
+
</div>
|
|
186
|
+
<div class="dc-messages" id="dcMessages" aria-live="polite"></div>
|
|
187
|
+
<div class="dc-tasks" id="dcTasks" style="display:none" aria-label="需求队列"></div>
|
|
188
|
+
<div class="dc-hint" id="dcHint">claude 在本机项目目录执行开发任务;所有打开本页的人共享此群聊。</div>
|
|
189
|
+
<div class="dc-compose">
|
|
190
|
+
<div id="dcAttachRow" style="display:none;flex-wrap:wrap;gap:4px"></div>
|
|
191
|
+
<textarea id="dcInput" placeholder="给 claude 派个开发任务…(Enter 发送 / Shift+Enter 换行,📎 附件)"></textarea>
|
|
192
|
+
<div class="dc-send-col">
|
|
193
|
+
<input type="file" id="dcFileInput" multiple style="display:none"
|
|
194
|
+
accept="image/*,.txt,.md,.json,.yaml,.yml,.csv,.log,.xml,.html,.js,.ts,.py,.go,.java,.sql,.pdf,.doc,.docx,.xls,.xlsx,.zip,.tar,.gz">
|
|
195
|
+
<button class="dc-btn ghost" id="dcAttachBtn" title="选择文件/图片附件">📎</button>
|
|
196
|
+
<button class="dc-btn ghost" id="dcStopBtn" style="display:none">停止</button>
|
|
197
|
+
<button class="dc-btn" id="dcSendBtn">发送</button>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
</div><!-- /dcMainView -->
|
|
201
|
+
</div>
|
|
202
|
+
|
|
203
|
+
<script>
|
|
204
|
+
(function () {
|
|
205
|
+
'use strict';
|
|
206
|
+
|
|
207
|
+
// ── 嵌入模式判定 ──
|
|
208
|
+
var params = new URLSearchParams(location.search);
|
|
209
|
+
var embedded = params.get('embed') === '1' || window.self !== window.top;
|
|
210
|
+
if (embedded) {
|
|
211
|
+
document.body.classList.remove('standalone');
|
|
212
|
+
document.body.classList.add('embedded');
|
|
213
|
+
document.getElementById('dcCloseBtn').style.display = '';
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var BASE = (params.get('base') || '').replace(/\/+$/, '');
|
|
217
|
+
function url(p) { return BASE + p; }
|
|
218
|
+
|
|
219
|
+
var $ = function (id) { return document.getElementById(id); };
|
|
220
|
+
var fab = $('dcFab'), panel = $('dcPanel'), badge = $('dcBadge');
|
|
221
|
+
var msgs = $('dcMessages'), input = $('dcInput'), sendBtn = $('dcSendBtn');
|
|
222
|
+
var stopBtn = $('dcStopBtn'), restartBtn = $('dcRestartBtn'), closeBtn = $('dcCloseBtn');
|
|
223
|
+
var statusBar = $('dcStatus'), statusText = $('dcStatusText'), sub = $('dcSub');
|
|
224
|
+
|
|
225
|
+
var state = {
|
|
226
|
+
open: !embedded, running: false, isAdmin: false, unread: 0, seenTs: 0,
|
|
227
|
+
typingEl: null, es: null, bootedAt: Date.now(),
|
|
228
|
+
tasks: [], activeTab: 'chat'
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// ── 任务队列(需求状态卡:排队/进行中/完成) ──
|
|
232
|
+
var STATUS_LABEL = { queued: '排队等待', running: '进行中', done: '完成', error: '失败', cancelled: '已取消' };
|
|
233
|
+
function fmtDuration(ms) {
|
|
234
|
+
if (!ms || ms <= 0) return '';
|
|
235
|
+
var s = Math.round(ms / 1000);
|
|
236
|
+
if (s < 60) return s + 's';
|
|
237
|
+
return Math.floor(s / 60) + 'm' + (s % 60) + 's';
|
|
238
|
+
}
|
|
239
|
+
function fmtTaskTime(iso) {
|
|
240
|
+
try {
|
|
241
|
+
var d = toDate(iso);
|
|
242
|
+
if (Number.isNaN(d.getTime())) return '';
|
|
243
|
+
return d.toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });
|
|
244
|
+
} catch (e) { return ''; }
|
|
245
|
+
}
|
|
246
|
+
function renderTasks() {
|
|
247
|
+
var box = $('dcTasks');
|
|
248
|
+
var counts = { queued: 0, running: 0, done: 0, error: 0, cancelled: 0 };
|
|
249
|
+
state.tasks.forEach(function (t) { counts[t.status] = (counts[t.status] || 0) + 1; });
|
|
250
|
+
$('dcTaskCount').textContent = String(counts.queued + counts.running);
|
|
251
|
+
box.innerHTML = '';
|
|
252
|
+
if (!state.tasks.length) {
|
|
253
|
+
var empty = document.createElement('div');
|
|
254
|
+
empty.className = 'dc-task-meta';
|
|
255
|
+
empty.textContent = '还没有需求。在「群聊」里给 claude 发一条任务,这里会出现它的状态卡。';
|
|
256
|
+
box.appendChild(empty);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
state.tasks.forEach(function (t) {
|
|
260
|
+
var card = document.createElement('div');
|
|
261
|
+
card.className = 'dc-task s-' + t.status;
|
|
262
|
+
var top = document.createElement('div');
|
|
263
|
+
top.className = 'dc-task-top';
|
|
264
|
+
var title = document.createElement('div');
|
|
265
|
+
title.className = 'dc-task-title';
|
|
266
|
+
title.textContent = (t.prompt || '').slice(0, 60) || '(空需求)';
|
|
267
|
+
title.title = t.prompt || '';
|
|
268
|
+
var pill = document.createElement('span');
|
|
269
|
+
pill.className = 'dc-pill p-' + t.status;
|
|
270
|
+
pill.textContent = (t.status === 'running' ? '⏳ ' : '') + (STATUS_LABEL[t.status] || t.status);
|
|
271
|
+
top.appendChild(title); top.appendChild(pill);
|
|
272
|
+
if (t.status === 'queued') {
|
|
273
|
+
// 排队任务:走任务删除(只影响这一条),绝不能调全局 /stop —
|
|
274
|
+
// 那会取消【正在跑的】任务,与本卡意图正好相反。
|
|
275
|
+
var del = document.createElement('button');
|
|
276
|
+
del.className = 'dc-task-cancel';
|
|
277
|
+
del.textContent = '✕';
|
|
278
|
+
del.title = '删除这条排队需求';
|
|
279
|
+
del.addEventListener('click', function () {
|
|
280
|
+
post('/devchat/tasks/delete', { id: t.id }).then(function () { loadTasks(); });
|
|
281
|
+
});
|
|
282
|
+
top.appendChild(del);
|
|
283
|
+
} else if (t.status === 'running') {
|
|
284
|
+
var stop = document.createElement('button');
|
|
285
|
+
stop.className = 'dc-task-cancel';
|
|
286
|
+
stop.textContent = '✕';
|
|
287
|
+
stop.title = '停止正在执行的这条需求';
|
|
288
|
+
stop.addEventListener('click', function () {
|
|
289
|
+
post('/devchat/stop', {}).then(function () { loadTasks(); refreshStatus(); });
|
|
290
|
+
});
|
|
291
|
+
top.appendChild(stop);
|
|
292
|
+
}
|
|
293
|
+
card.appendChild(top);
|
|
294
|
+
var meta = document.createElement('div');
|
|
295
|
+
meta.className = 'dc-task-meta';
|
|
296
|
+
var dur = t.duration_ms ? fmtDuration(t.duration_ms) : (t.status === 'running' ? '进行中' : '');
|
|
297
|
+
meta.textContent = '#' + String(t.seq).slice(-6) + ' · ' + (t.requester || '?') + ' · ' + fmtTaskTime(t.created_at) + (dur ? ' · ' + dur : '');
|
|
298
|
+
card.appendChild(meta);
|
|
299
|
+
if (t.error) {
|
|
300
|
+
var err = document.createElement('div');
|
|
301
|
+
err.className = 'dc-task-err';
|
|
302
|
+
err.textContent = t.error;
|
|
303
|
+
card.appendChild(err);
|
|
304
|
+
}
|
|
305
|
+
box.appendChild(card);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function loadTasks() {
|
|
309
|
+
return fetch(url('/devchat/tasks?limit=100'), { credentials: 'include' })
|
|
310
|
+
.then(function (r) { return r.json(); })
|
|
311
|
+
.then(function (d) { state.tasks = d.tasks || []; renderTasks(); })
|
|
312
|
+
.catch(function () {});
|
|
313
|
+
}
|
|
314
|
+
// ── tab 切换(切到任务列表也滚到底:最新执行历史在底部) ──
|
|
315
|
+
function switchTab(name) {
|
|
316
|
+
state.activeTab = name;
|
|
317
|
+
$('dcTabChat').classList.toggle('active', name === 'chat');
|
|
318
|
+
$('dcTabTasks').classList.toggle('active', name === 'tasks');
|
|
319
|
+
msgs.style.display = name === 'chat' ? '' : 'none';
|
|
320
|
+
$('dcTasks').style.display = name === 'tasks' ? '' : 'none';
|
|
321
|
+
$('dcHint').style.display = name === 'chat' ? '' : 'none';
|
|
322
|
+
requestAnimationFrame(function () { requestAnimationFrame(function () {
|
|
323
|
+
var box = name === 'tasks' ? $('dcTasks') : msgs;
|
|
324
|
+
if (box) box.scrollTop = box.scrollHeight;
|
|
325
|
+
}); });
|
|
326
|
+
}
|
|
327
|
+
$('dcTabChat').addEventListener('click', function () { switchTab('chat'); });
|
|
328
|
+
$('dcTabTasks').addEventListener('click', function () { switchTab('tasks'); loadTasks(); });
|
|
329
|
+
|
|
330
|
+
// ── 面板开合 ──
|
|
331
|
+
function renderOpen() {
|
|
332
|
+
if (embedded) panel.classList.toggle('open', state.open);
|
|
333
|
+
if (state.open) { state.unread = 0; renderBadge(); scrollBottom(); }
|
|
334
|
+
}
|
|
335
|
+
function renderBadge() {
|
|
336
|
+
if (!embedded) return;
|
|
337
|
+
badge.textContent = state.unread > 9 ? '9+' : String(state.unread);
|
|
338
|
+
badge.classList.toggle('show', !state.open && state.unread > 0);
|
|
339
|
+
}
|
|
340
|
+
fab.addEventListener('click', function () { state.open = !state.open; renderOpen(); });
|
|
341
|
+
closeBtn.addEventListener('click', function () { state.open = false; renderOpen(); });
|
|
342
|
+
|
|
343
|
+
// ── 状态 ──
|
|
344
|
+
function setRunning(r) {
|
|
345
|
+
state.running = r;
|
|
346
|
+
statusBar.classList.toggle('busy', r);
|
|
347
|
+
statusText.textContent = r ? 'claude 执行中…(实时进度见下方)' : 'claude 空闲 · 可派任务';
|
|
348
|
+
var dot = statusBar.querySelector('.dc-dot');
|
|
349
|
+
if (dot) dot.classList.toggle('pulse', r);
|
|
350
|
+
stopBtn.style.display = r ? '' : 'none';
|
|
351
|
+
sendBtn.disabled = false;
|
|
352
|
+
sub.textContent = r ? '群聊 · claude code 工作中' : '群聊 · claude code 在编队里';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ── 消息渲染 ──
|
|
356
|
+
function scrollBottom() { msgs.scrollTop = msgs.scrollHeight; }
|
|
357
|
+
// 后端 created_at 是 epoch 秒(SSE 本地构造的是 ISO 串):数字且
|
|
358
|
+
// < 1e12 视为秒 → 乘 1000;其余(Date 可直接解析的串)原样。
|
|
359
|
+
function toDate(v) {
|
|
360
|
+
var n = typeof v === 'number' ? v : Number(v);
|
|
361
|
+
if (!Number.isNaN(n) && v !== null && v !== '' && !/[^0-9.]/.test(String(v))) {
|
|
362
|
+
return new Date(n < 1e12 ? n * 1000 : n);
|
|
363
|
+
}
|
|
364
|
+
return new Date(v);
|
|
365
|
+
}
|
|
366
|
+
function fmtTime(iso) {
|
|
367
|
+
try { var d = toDate(iso); if (Number.isNaN(d.getTime())) return ''; return d.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }); } catch (e) { return ''; }
|
|
368
|
+
}
|
|
369
|
+
function appendMessage(m) {
|
|
370
|
+
var wrap = document.createElement('div');
|
|
371
|
+
wrap.className = 'dc-msg ' + (m.sender_role || 'system');
|
|
372
|
+
var name = document.createElement('div');
|
|
373
|
+
name.className = 'dc-msg-name';
|
|
374
|
+
name.textContent = (m.sender_name || m.sender_role || '?') + ' · ' + fmtTime(m.created_at);
|
|
375
|
+
var bubble = document.createElement('div');
|
|
376
|
+
bubble.className = 'dc-msg-bubble';
|
|
377
|
+
bubble.textContent = m.content || '';
|
|
378
|
+
wrap.appendChild(name); wrap.appendChild(bubble);
|
|
379
|
+
clearTyping();
|
|
380
|
+
msgs.appendChild(wrap);
|
|
381
|
+
if (wrap.offsetTop < msgs.scrollTop || wrap.offsetTop > msgs.scrollTop + msgs.clientHeight - 80 || state.open) scrollBottom();
|
|
382
|
+
if (m.created_at && toDate(m.created_at).getTime() > state.seenTs) {
|
|
383
|
+
state.seenTs = toDate(m.created_at).getTime();
|
|
384
|
+
}
|
|
385
|
+
if (!state.open && embedded) { state.unread++; renderBadge(); }
|
|
386
|
+
}
|
|
387
|
+
function appendToolLine(tool, phase) {
|
|
388
|
+
var el = document.createElement('div');
|
|
389
|
+
el.className = 'dc-tool';
|
|
390
|
+
el.textContent = (phase === 'call' ? '🔧 ' : '✓ ') + (tool || 'tool');
|
|
391
|
+
msgs.appendChild(el);
|
|
392
|
+
if (state.open) scrollBottom();
|
|
393
|
+
}
|
|
394
|
+
function showTyping(chunk) {
|
|
395
|
+
if (!state.typingEl) {
|
|
396
|
+
state.typingEl = document.createElement('div');
|
|
397
|
+
state.typingEl.className = 'dc-typing';
|
|
398
|
+
state.typingEl.innerHTML = '<span class="dc-typing-text"></span><span class="dc-caret"></span>';
|
|
399
|
+
msgs.appendChild(state.typingEl);
|
|
400
|
+
}
|
|
401
|
+
var t = state.typingEl.querySelector('.dc-typing-text');
|
|
402
|
+
t.textContent = (t.textContent || '') + chunk;
|
|
403
|
+
if (t.textContent.length > 400) t.textContent = t.textContent.slice(-400);
|
|
404
|
+
if (state.open) scrollBottom();
|
|
405
|
+
}
|
|
406
|
+
function clearTyping() {
|
|
407
|
+
if (state.typingEl && state.typingEl.parentNode) state.typingEl.parentNode.removeChild(state.typingEl);
|
|
408
|
+
state.typingEl = null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// ── API ──
|
|
412
|
+
function post(p, body) {
|
|
413
|
+
return fetch(url(p), {
|
|
414
|
+
method: 'POST', credentials: 'include',
|
|
415
|
+
headers: { 'Content-Type': 'application/json' },
|
|
416
|
+
body: JSON.stringify(body || {})
|
|
417
|
+
}).then(function (r) { return r.json().catch(function () { return {}; }); });
|
|
418
|
+
}
|
|
419
|
+
function loadHistory() {
|
|
420
|
+
return fetch(url('/devchat/messages?limit=200'), { credentials: 'include' })
|
|
421
|
+
.then(function (r) { return r.json(); })
|
|
422
|
+
.then(function (d) {
|
|
423
|
+
(d.messages || []).forEach(function (m) {
|
|
424
|
+
// 过滤掉本页 boot 前很久的系统重复提示可选;全量展示(群聊语义)
|
|
425
|
+
appendMessage(m);
|
|
426
|
+
});
|
|
427
|
+
setRunning(!!d.running);
|
|
428
|
+
if (d.session_id) state.sessionId = d.session_id;
|
|
429
|
+
}).catch(function () { statusText.textContent = '历史加载失败'; });
|
|
430
|
+
}
|
|
431
|
+
function refreshStatus() {
|
|
432
|
+
fetch(url('/devchat/status'), { credentials: 'include' })
|
|
433
|
+
.then(function (r) { return r.json(); })
|
|
434
|
+
.then(function (d) {
|
|
435
|
+
state.isAdmin = !!d.is_admin;
|
|
436
|
+
restartBtn.style.display = state.isAdmin ? '' : 'none';
|
|
437
|
+
setRunning(!!d.running);
|
|
438
|
+
sub.textContent = (d.viewers || 1) + ' 人在线 · ' + (d.running ? 'claude 工作中' : 'claude 空闲');
|
|
439
|
+
}).catch(function () {});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// ── SSE ──
|
|
443
|
+
function connect() {
|
|
444
|
+
if (state.es) { state.es.close(); state.es = null; }
|
|
445
|
+
var es = new EventSource(url('/devchat/stream'));
|
|
446
|
+
state.es = es;
|
|
447
|
+
es.onopen = function () { statusText.textContent = state.running ? 'claude 执行中…' : '已连接 · claude 空闲'; };
|
|
448
|
+
es.onerror = function () {
|
|
449
|
+
statusText.textContent = '连接断开,重连中…';
|
|
450
|
+
es.close(); if (state.es === es) state.es = null;
|
|
451
|
+
setTimeout(connect, 3000);
|
|
452
|
+
};
|
|
453
|
+
es.onmessage = function (e) {
|
|
454
|
+
var d; try { d = JSON.parse(e.data); } catch (err) { return; }
|
|
455
|
+
switch (d.type) {
|
|
456
|
+
case 'hello':
|
|
457
|
+
setRunning(!!d.running);
|
|
458
|
+
if (d.session_id) state.sessionId = d.session_id;
|
|
459
|
+
break;
|
|
460
|
+
case 'message': appendMessage(d.message || {}); break;
|
|
461
|
+
case 'typing': showTyping(d.content || ''); break;
|
|
462
|
+
case 'tool': appendToolLine(d.tool, d.phase); break;
|
|
463
|
+
case 'status': setRunning(d.state === 'running'); break;
|
|
464
|
+
case 'done':
|
|
465
|
+
setRunning(false);
|
|
466
|
+
if (d.state === 'success') restartBtn.style.display = state.isAdmin ? '' : 'none';
|
|
467
|
+
break;
|
|
468
|
+
case 'error':
|
|
469
|
+
clearTyping();
|
|
470
|
+
appendMessage({ sender_role: 'system', sender_name: 'devchat', content: '⚠ ' + (d.message || '未知错误'), created_at: new Date().toISOString() });
|
|
471
|
+
break;
|
|
472
|
+
case 'restarting':
|
|
473
|
+
clearTyping();
|
|
474
|
+
appendMessage({ sender_role: 'system', sender_name: 'devchat', content: '♻ ' + (d.message || '服务重启中…'), created_at: new Date().toISOString() });
|
|
475
|
+
statusText.textContent = '服务重启中,稍后自动重连…';
|
|
476
|
+
setTimeout(function () { location.reload(); }, 6000);
|
|
477
|
+
break;
|
|
478
|
+
case 'tasks':
|
|
479
|
+
state.tasks = d.tasks || [];
|
|
480
|
+
renderTasks();
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// ── 发送 ──
|
|
487
|
+
// ── 附件(文件/图片):选择 → 上传 → 路径清单拼进消息文本 ──
|
|
488
|
+
var attachRow = $('dcAttachRow'), fileInput = $('dcFileInput');
|
|
489
|
+
var attachments = []; // {name}
|
|
490
|
+
$('dcAttachBtn').addEventListener('click', function () { fileInput.click(); });
|
|
491
|
+
fileInput.addEventListener('change', function () {
|
|
492
|
+
Array.prototype.slice.call(fileInput.files || []).forEach(function (f) {
|
|
493
|
+
if (attachments.length < 5) attachments.push(f);
|
|
494
|
+
});
|
|
495
|
+
fileInput.value = '';
|
|
496
|
+
renderAttachments();
|
|
497
|
+
});
|
|
498
|
+
function renderAttachments() {
|
|
499
|
+
attachRow.style.display = attachments.length ? 'flex' : 'none';
|
|
500
|
+
attachRow.innerHTML = '';
|
|
501
|
+
attachments.forEach(function (f, i) {
|
|
502
|
+
var tag = document.createElement('span');
|
|
503
|
+
tag.style.cssText = 'font-size:11px;color:#4b5563;background:#f6f7f9;border:1px solid #e5e7eb;border-radius:6px;padding:1px 6px;cursor:pointer';
|
|
504
|
+
tag.textContent = (f.type && f.type.indexOf('image/') === 0 ? '🖼 ' : '📄 ') + f.name + ' ✕';
|
|
505
|
+
tag.title = '点击移除';
|
|
506
|
+
tag.addEventListener('click', function () {
|
|
507
|
+
attachments.splice(i, 1); renderAttachments();
|
|
508
|
+
});
|
|
509
|
+
attachRow.appendChild(tag);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
function uploadAttachment(f) {
|
|
513
|
+
var form = new FormData();
|
|
514
|
+
form.append('file', f);
|
|
515
|
+
return fetch(url('/devchat/upload'), { method: 'POST', credentials: 'include', body: form })
|
|
516
|
+
.then(function (r) { return r.json(); })
|
|
517
|
+
.then(function (d) {
|
|
518
|
+
if (d.path) return d.path;
|
|
519
|
+
appendMessage({ sender_role: 'system', sender_name: 'devchat', content: '⚠ 上传失败:' + f.name, created_at: new Date().toISOString() });
|
|
520
|
+
return null;
|
|
521
|
+
})
|
|
522
|
+
.catch(function () { return null; });
|
|
523
|
+
}
|
|
524
|
+
function send() {
|
|
525
|
+
var text = input.value.trim();
|
|
526
|
+
if (!text) return;
|
|
527
|
+
sendBtn.disabled = true;
|
|
528
|
+
var pre = attachments.length
|
|
529
|
+
? Promise.all(attachments.map(uploadAttachment))
|
|
530
|
+
: Promise.resolve([]);
|
|
531
|
+
pre.then(function (paths) {
|
|
532
|
+
attachments = []; renderAttachments();
|
|
533
|
+
paths = paths.filter(Boolean);
|
|
534
|
+
if (paths.length) {
|
|
535
|
+
text += '\n\n[附件](可用 Read 工具直接查看):\n' + paths.map(function (p) { return '- ' + p; }).join('\n');
|
|
536
|
+
}
|
|
537
|
+
return post('/devchat/send', { content: text }).then(function (d) {
|
|
538
|
+
if (d.started) { setRunning(true); input.value = ''; }
|
|
539
|
+
else if (d.detail) {
|
|
540
|
+
appendMessage({ sender_role: 'system', sender_name: 'devchat', content: d.detail, created_at: new Date().toISOString() });
|
|
541
|
+
}
|
|
542
|
+
sendBtn.disabled = false;
|
|
543
|
+
});
|
|
544
|
+
}).catch(function () { sendBtn.disabled = false; });
|
|
545
|
+
}
|
|
546
|
+
sendBtn.addEventListener('click', send);
|
|
547
|
+
input.addEventListener('keydown', function (e) {
|
|
548
|
+
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); }
|
|
549
|
+
});
|
|
550
|
+
stopBtn.addEventListener('click', function () {
|
|
551
|
+
post('/devchat/stop', {}).then(function () { refreshStatus(); });
|
|
552
|
+
});
|
|
553
|
+
restartBtn.addEventListener('click', function () {
|
|
554
|
+
if (!confirm('重建并重启当前服务?(构建失败不会重启)')) return;
|
|
555
|
+
restartBtn.disabled = true;
|
|
556
|
+
post('/devchat/restart', {}).then(function (d) {
|
|
557
|
+
if (!d.detail || d.detail.indexOf('已安排') < 0) { restartBtn.disabled = false; alert(d.detail || '重启失败'); }
|
|
558
|
+
}).catch(function () { restartBtn.disabled = false; });
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
// ── 启动 ──
|
|
562
|
+
// 登录态分流:数据端点 401 = LDAP 模式未登录 → 登录视图挡住面板主体。
|
|
563
|
+
var loginView = $('dcLoginView'), mainView = $('dcMainView');
|
|
564
|
+
var loginUser = $('dcLoginUser'), loginPass = $('dcLoginPass'),
|
|
565
|
+
loginBtn = $('dcLoginBtn'), loginErr = $('dcLoginErr');
|
|
566
|
+
var authRequired = false;
|
|
567
|
+
function checkAuth() {
|
|
568
|
+
return fetch(url('/devchat/messages?limit=1'), { credentials: 'include' })
|
|
569
|
+
.then(function (r) {
|
|
570
|
+
if (r.status === 401) { authRequired = true; showLogin(true); return false; }
|
|
571
|
+
showLogin(false); return true;
|
|
572
|
+
}).catch(function () { showLogin(false); return true; });
|
|
573
|
+
}
|
|
574
|
+
function showLogin(req) {
|
|
575
|
+
loginView.style.display = req ? 'flex' : 'none';
|
|
576
|
+
mainView.style.display = req ? 'none' : 'flex';
|
|
577
|
+
}
|
|
578
|
+
function doLogin() {
|
|
579
|
+
var u = (loginUser.value || '').trim(), p = loginPass.value || '';
|
|
580
|
+
if (!u || !p) { loginErr.textContent = '请输入用户名和密码'; return; }
|
|
581
|
+
loginBtn.disabled = true; loginErr.textContent = '';
|
|
582
|
+
fetch(url('/devchat/login'), {
|
|
583
|
+
method: 'POST', credentials: 'include',
|
|
584
|
+
headers: { 'Content-Type': 'application/json' },
|
|
585
|
+
body: JSON.stringify({ username: u, password: p })
|
|
586
|
+
}).then(function (r) { return r.json().catch(function () { return {}; }); })
|
|
587
|
+
.then(function (d) {
|
|
588
|
+
loginBtn.disabled = false;
|
|
589
|
+
if (d.success) { loginPass.value = ''; checkAuth().then(function (ok) { if (ok) boot(); }); }
|
|
590
|
+
else loginErr.textContent = d.error || '登录失败';
|
|
591
|
+
}).catch(function () { loginBtn.disabled = false; loginErr.textContent = '登录请求失败,请检查连接'; });
|
|
592
|
+
}
|
|
593
|
+
loginBtn.addEventListener('click', doLogin);
|
|
594
|
+
loginPass.addEventListener('keydown', function (e) { if (e.key === 'Enter') doLogin(); });
|
|
595
|
+
function boot() {
|
|
596
|
+
renderOpen();
|
|
597
|
+
loadTasks();
|
|
598
|
+
loadHistory().then(refreshStatus).then(connect);
|
|
599
|
+
setInterval(refreshStatus, 15000);
|
|
600
|
+
setInterval(function () { if (state.activeTab === 'tasks') loadTasks(); }, 10000);
|
|
601
|
+
}
|
|
602
|
+
checkAuth().then(function (ok) { if (ok) boot(); });
|
|
603
|
+
})();
|
|
604
|
+
</script>
|
|
605
|
+
</body>
|
|
606
|
+
</html>
|