dsh-team-bots 0.3.80 → 0.3.105
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.
- package/cordis.patch.yml +100 -0
- package/index.js +5 -2
- package/package.json +1 -1
- package/src/api.js +5 -1
- package/src/db-migrations.js +5 -1
- package/src/db.js +52 -0
- package/src/feishu/channel.js +15 -11
- package/src/feishu/format.js +37 -1
- package/src/runtime.js +13 -1
- package/src/service.js +5 -0
- package/src/services/approvals.js +7 -2
- package/src/services/bots.js +8 -1
- package/src/services/chat-stores.js +564 -0
- package/src/services/chat.js +60 -28
- package/src/services/core.js +33 -12
- package/src/services/feishu.js +1 -1
- package/src/services/memory.js +14 -12
- package/src/services/model-fallback.js +3 -1
- package/src/services/notify.js +18 -8
- package/src/services/projects.js +25 -19
- package/src/services/questions.js +37 -12
- package/src/services/review-watchdog.js +31 -12
- package/src/services/run-finish.js +21 -14
- package/src/services/runs.js +29 -41
- package/src/services/runtime/context-window.js +6 -4
- package/src/services/runtime/lifecycle.js +1 -0
- package/src/services/runtime/prompt.js +21 -9
- package/src/services/runtime/sandbox-policy.js +1 -1
- package/src/services/runtime/session.js +27 -15
- package/src/services/runtime/trajectory.js +3 -1
- package/src/services/scheduler.js +48 -49
- package/src/services/system.js +9 -7
- package/src/services/task-review.js +27 -19
- package/src/services/task-runs.js +40 -21
- package/src/services/tasks.js +18 -10
- package/src/services/terminal.js +25 -14
- package/src/services/vision-proxy.js +67 -9
- package/src/services/wechat.js +24 -8
- package/src/subagent-ledger.js +23 -6
- package/src/usage-reconcile.js +93 -32
- package/src/usage.js +125 -50
- package/src/util.js +17 -0
- package/src/wechat/channel.js +3 -1
- package/src/wechat/commands.js +13 -1
- package/ui/modules/events-click.js +14 -1
- package/ui/modules/file-preview.js +22 -10
- package/ui/modules/markdown.js +10 -8
- package/ui/modules/tasks.js +1 -1
- package/ui/styles/cards.css +13 -0
- package/ui/styles/modal.css +4 -0
|
@@ -9,7 +9,7 @@ import { exportUsageCsv, switchUsageWindow, usageMode } from './usage.js'
|
|
|
9
9
|
import { focusApprovalCard, focusQuestionCard, questionDraftSelection, questionSelectOption } from './cards.js'
|
|
10
10
|
import { loadSoloDetail } from './chat.js'
|
|
11
11
|
import { searchMemories } from './tasks.js'
|
|
12
|
-
import { openFilePreview } from './file-preview.js'
|
|
12
|
+
import { ARTIFACT_IMAGE, openFilePreview } from './file-preview.js'
|
|
13
13
|
import { handleBoardAction } from './events-board.js'
|
|
14
14
|
import { refresh, renderKeepingChatScroll, render, beginChatPending, endChatPending } from '../app.js'
|
|
15
15
|
|
|
@@ -28,6 +28,19 @@ document.addEventListener('click', async (event) => {
|
|
|
28
28
|
openInlineImage(bubbleImg)
|
|
29
29
|
return
|
|
30
30
|
}
|
|
31
|
+
// 本地文件链接(markdown.ts 把消息里的相对路径图片/链接统一改写成 /api/dsh-team/file):
|
|
32
|
+
// 点击不跳页,按扩展分流——图片扩展进现有查看器,其余进交付产物同款文本预览弹层,
|
|
33
|
+
// 非白名单类型由弹层显示加载失败;中键/Ctrl 点仍走浏览器原生新窗口。
|
|
34
|
+
const fileLink = (event.target ).closest?.('a[href^="/api/dsh-team/file"]')
|
|
35
|
+
if (fileLink) {
|
|
36
|
+
event.preventDefault()
|
|
37
|
+
const href = fileLink.getAttribute('href') ?? ''
|
|
38
|
+
let linkPath = ''
|
|
39
|
+
try { linkPath = new URL(href, location.href).searchParams.get('path') ?? '' } catch { /* 非法 href 按无路径处理 */ }
|
|
40
|
+
if (linkPath && ARTIFACT_IMAGE.test(linkPath)) openInlineImage({ currentSrc: href, getAttribute: () => '' })
|
|
41
|
+
else await openFilePreview(href, linkPath)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
31
44
|
const target = (event.target ).closest('[data-action]')
|
|
32
45
|
if (!target) return
|
|
33
46
|
const action = target.dataset.action
|
|
@@ -2,6 +2,7 @@ import { state } from './state.js'
|
|
|
2
2
|
import { attr, esc } from './util.js'
|
|
3
3
|
import { t } from './i18n.js'
|
|
4
4
|
import { modalShell, renderModalLayer } from './modal-layer.js'
|
|
5
|
+
import { mdChatScope, richText } from './markdown.js'
|
|
5
6
|
|
|
6
7
|
// file-preview-logic:start —— 文本预览纯逻辑(tests/file-preview.test.js 抽取此块断言)。
|
|
7
8
|
// 白名单与后端 chatFile 的文本扩展同口径;SVG 可执行脚本、.env 常带密钥,永不入列。
|
|
@@ -11,6 +12,11 @@ const PREVIEW_MAX_LINES = 2000
|
|
|
11
12
|
function isPreviewableText(path) {
|
|
12
13
|
return FILE_TEXT_EXT.test(String(path ?? ''))
|
|
13
14
|
}
|
|
15
|
+
// markdown 扩展走渲染预览(richText 管线),与纯文本展示分开。
|
|
16
|
+
const FILE_MD_EXT = /\.(md|markdown)$/i
|
|
17
|
+
function isMarkdownPath(path) {
|
|
18
|
+
return FILE_MD_EXT.test(String(path ?? ''))
|
|
19
|
+
}
|
|
14
20
|
// 超限截断:256KB 与 2000 行先到先裁;弹层只提示,不改写内容本身。
|
|
15
21
|
function clipPreviewText(text) {
|
|
16
22
|
const source = String(text ?? '')
|
|
@@ -38,8 +44,8 @@ const artifactFileUrl = (runId, path) =>
|
|
|
38
44
|
const artifactExt = (path) =>
|
|
39
45
|
(String(path).match(/\.([a-z0-9]+)$/i)?.[1] ?? 'file').toUpperCase().slice(0, 6)
|
|
40
46
|
|
|
41
|
-
//
|
|
42
|
-
//
|
|
47
|
+
// 文件预览弹层:文本走 textContent 通道;markdown 走与聊天气泡同一条 richText
|
|
48
|
+
// 消毒管线(marked → DOMPurify),不经手拼 HTML。footer 保留「新窗口打开」。
|
|
43
49
|
function modalFilePreview(modal) {
|
|
44
50
|
const path = String(modal?.path ?? '')
|
|
45
51
|
if (modal?.error) {
|
|
@@ -53,34 +59,40 @@ function modalFilePreview(modal) {
|
|
|
53
59
|
return modalShell({
|
|
54
60
|
title: path || t("文件预览"),
|
|
55
61
|
subtitle: modal?.truncated ? t("文件较大,已截断,仅显示开头部分。") : '',
|
|
56
|
-
body:
|
|
62
|
+
body: modal?.kind === 'md'
|
|
63
|
+
? '<div class="comment-body" id="dsh-file-preview-md"></div>'
|
|
64
|
+
: '<pre class="detail-pre" id="dsh-file-preview-pre"></pre>',
|
|
57
65
|
footer: `<button class="btn" data-action="close-modal">${t("关闭")}</button><button class="btn" data-action="open-artifact" data-url="${attr(modal?.url ?? '')}">${t("新窗口打开")}</button>`,
|
|
58
66
|
size: 'wide',
|
|
59
67
|
})
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
//
|
|
70
|
+
// 正文水合:把已取回的内容写进占位节点。滚动守卫可能把补拍延后约 120ms,
|
|
63
71
|
// 首拍未命中节点时短重试,避免补拍后弹层空白。
|
|
64
72
|
function hydrateFilePreview(retry = 3) {
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
if (state.modal?.type !== 'file-preview') return
|
|
74
|
+
const isMd = state.modal.kind === 'md'
|
|
75
|
+
const node = document.getElementById(isMd ? 'dsh-file-preview-md' : 'dsh-file-preview-pre')
|
|
76
|
+
if (!node) {
|
|
67
77
|
if (retry > 0) setTimeout(() => hydrateFilePreview(retry - 1), 150)
|
|
68
78
|
return
|
|
69
79
|
}
|
|
70
|
-
if (
|
|
80
|
+
if (isMd) node.innerHTML = richText(state.modal.content ?? '', mdChatScope())
|
|
81
|
+
else node.textContent = state.modal.content ?? ''
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
async function openFilePreview(url, path) {
|
|
74
85
|
if (!url) return
|
|
75
|
-
|
|
86
|
+
const kind = isMarkdownPath(path) ? 'md' : 'text'
|
|
87
|
+
state.modal = { type: 'file-preview', loading: true, kind, title: String(path ?? '').split('/').pop() || t("文件预览"), url, path }
|
|
76
88
|
renderModalLayer()
|
|
77
89
|
try {
|
|
78
90
|
const res = await fetch(url)
|
|
79
91
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
|
80
92
|
const { body, truncated } = clipPreviewText(await res.text())
|
|
81
|
-
state.modal = { type: 'file-preview', url, path, content: body, truncated }
|
|
93
|
+
state.modal = { type: 'file-preview', kind, url, path, content: body, truncated }
|
|
82
94
|
} catch (error ) {
|
|
83
|
-
state.modal = { type: 'file-preview', url, path, error: String(error?.message ?? error) }
|
|
95
|
+
state.modal = { type: 'file-preview', kind, url, path, error: String(error?.message ?? error) }
|
|
84
96
|
}
|
|
85
97
|
renderModalLayer()
|
|
86
98
|
hydrateFilePreview()
|
package/ui/modules/markdown.js
CHANGED
|
@@ -3,13 +3,15 @@ import { esc, inSoloContext, botById, pageProject } from './util.js'
|
|
|
3
3
|
import { t } from './i18n.js'
|
|
4
4
|
|
|
5
5
|
// markdown-render:start —— 聊天 markdown 渲染纯逻辑(tests/markdown.test.js 抽取此块断言)。
|
|
6
|
-
// 管线固定:md →
|
|
6
|
+
// 管线固定:md → mdRewriteFileSources → marked.parse → DOMPurify.sanitize → innerHTML。
|
|
7
7
|
// 消毒不可绕:marked 或 DOMPurify 缺席、或 DOMPurify.isSupported=false(node/损坏安装)时
|
|
8
8
|
// mdCreateRenderer 返回 null,调用方回退 esc 纯文本,绝不裸插 HTML。
|
|
9
|
-
//
|
|
9
|
+
// 工作区相对路径的图片与文件链接都改写成 GET /api/dsh-team/file(服务端再做 MIME 白名单与防穿越),
|
|
10
|
+
// 与 DSH 宿主一致:消息里的本地文件引用可预览,而不是按页面 URL 解析成死链。
|
|
10
11
|
const MD_SCHEME = /^(?:[a-z][a-z0-9+.-]*:|#|\/\/)/i
|
|
11
|
-
//
|
|
12
|
-
|
|
12
|
+
// 图片/链接语法同构:(!?) 前缀区分两种语法;href 允许含空格(到标题或右括号前止),
|
|
13
|
+
// 标题可为 "..." / '...' / (...)。单遍匹配,已改写的图片 URL 不会被链接分支二次处理。
|
|
14
|
+
const MD_MEDIA = /(!?)\[([^\]]*)\]\(([^)\n]*?)(?:\s+("[^"]*"|'[^']*'|\([^)]*\)))?\s*\)/g
|
|
13
15
|
// 只剥尾部标题:含空格的路径若被标题正则误切会丢文件名,故仅匹配整段结尾的引号/括号标题。
|
|
14
16
|
const MD_IMAGE_TITLE = /\s+("[^"]*"|'[^']*'|\([^)]*\))$/
|
|
15
17
|
function mdImageTarget(inner) {
|
|
@@ -46,10 +48,10 @@ function mdImageFileUrl(href, scope) {
|
|
|
46
48
|
params.set('path', rel)
|
|
47
49
|
return `/api/dsh-team/file?${params.toString()}`
|
|
48
50
|
}
|
|
49
|
-
function
|
|
50
|
-
return String(source ?? '').replace(
|
|
51
|
+
function mdRewriteFileSources(source, scope) {
|
|
52
|
+
return String(source ?? '').replace(MD_MEDIA, (whole, bang, label, inner) => {
|
|
51
53
|
const url = mdImageFileUrl(mdImageTarget(inner), scope)
|
|
52
|
-
return url ? `${
|
|
54
|
+
return url ? `${bang}[${label}](${url})` : whole
|
|
53
55
|
})
|
|
54
56
|
}
|
|
55
57
|
function mdCreateRenderer(deps) {
|
|
@@ -81,7 +83,7 @@ function mdCreateRenderer(deps) {
|
|
|
81
83
|
cache.set(key, hit)
|
|
82
84
|
return hit
|
|
83
85
|
}
|
|
84
|
-
const html = marked.parse(
|
|
86
|
+
const html = marked.parse(mdRewriteFileSources(body, scope), { gfm: true, breaks: true })
|
|
85
87
|
const safe = DOMPurify.sanitize(html, { USE_PROFILES: { html: true } })
|
|
86
88
|
cache.set(key, safe)
|
|
87
89
|
if (cache.size > MD_RENDER_CACHE_MAX) cache.delete(cache.keys().next().value)
|
package/ui/modules/tasks.js
CHANGED
|
@@ -384,7 +384,7 @@ function renderBots() {
|
|
|
384
384
|
<div class="bot-card-head">
|
|
385
385
|
${avatar(bot, 'lg')}
|
|
386
386
|
<div class="bot-card-title"><strong>${esc(bot.name)}</strong><span>${esc(bot.role || t("通用成员"))}</span></div>
|
|
387
|
-
<span class="bot-status ${attr(bot.status)}">${esc(BOT_STATUS[bot.status] ?? bot.status)}</span>
|
|
387
|
+
<span class="bot-status ${bot.status === 'active' ? (bot.busy ? 'busy' : 'idle') : attr(bot.status)}">${esc(bot.status === 'active' ? (bot.busy ? t("任务中") : t("空闲中")) : (BOT_STATUS[bot.status] ?? bot.status))}</span>
|
|
388
388
|
</div>
|
|
389
389
|
<div class="bot-model"><span>${esc(bot.modelRef ?? t("未配置模型"))}${bot.effort ? ` · ${esc(EFFORT[bot.effort] ?? bot.effort)}` : ''}</span>${bot.quota?.exhausted ? `<span class="quota-badge">${t("额度耗尽")}</span>` : ''}</div>
|
|
390
390
|
<div class="bot-metrics"><span><strong>${bot.openTasks}</strong> ${t("任务")}</span><span class="dot-sep"></span><span><strong>${bot.memoryCount}</strong> ${t("记忆")}</span><span class="dot-sep"></span><span><strong>${bot.stats.succeeded}</strong> ${t("次成功")}</span></div>
|
package/ui/styles/cards.css
CHANGED
|
@@ -108,6 +108,19 @@
|
|
|
108
108
|
.bot-status.active::before {
|
|
109
109
|
background: var(--green);
|
|
110
110
|
}
|
|
111
|
+
/* 工作负载态(总览 bots 卡片):任务中琥珀、空闲中绿——与项目成员卡的 pill 同色语义。 */
|
|
112
|
+
.bot-status.busy {
|
|
113
|
+
color: var(--ink-3);
|
|
114
|
+
}
|
|
115
|
+
.bot-status.busy::before {
|
|
116
|
+
background: var(--star);
|
|
117
|
+
}
|
|
118
|
+
.bot-status.idle {
|
|
119
|
+
color: var(--ink-3);
|
|
120
|
+
}
|
|
121
|
+
.bot-status.idle::before {
|
|
122
|
+
background: var(--green);
|
|
123
|
+
}
|
|
111
124
|
.bot-status.paused {
|
|
112
125
|
color: var(--ink-3);
|
|
113
126
|
}
|