dsh-team-bots 0.2.465 → 0.3.64
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/NOTICE +5 -0
- package/README.md +8 -2
- package/docs/README.zh.md +8 -2
- package/docs/assets/global-config.png +0 -0
- package/docs/assets/global-config.zh.png +0 -0
- package/docs/assets/tasks.png +0 -0
- package/docs/assets/tasks.zh.png +0 -0
- package/docs/assets/usage.png +0 -0
- package/docs/assets/usage.zh.png +0 -0
- package/package.json +8 -2
- package/src/api.js +16 -2
- package/src/config.js +193 -8
- package/src/db-migrations.js +53 -4
- package/src/db.js +37 -3
- package/src/http.js +20 -1
- package/src/runtime.js +16 -1
- package/src/seed-bots.js +4 -0
- package/src/service.js +21 -2
- package/src/services/approvals.js +276 -8
- package/src/services/bot-quota.js +54 -0
- package/src/services/bots.js +8 -0
- package/src/services/chat.js +54 -5
- package/src/services/core.js +31 -2
- package/src/services/memory.js +112 -25
- package/src/services/model-fallback.js +55 -15
- package/src/services/projects.js +13 -2
- package/src/services/run-finish.js +44 -11
- package/src/services/runs.js +15 -7
- package/src/services/runtime/prompt.js +31 -6
- package/src/services/runtime/session.js +87 -25
- package/src/services/scheduler.js +26 -5
- package/src/services/system.js +162 -10
- package/src/services/task-dispatch.js +24 -0
- package/src/services/task-notify.js +18 -0
- package/src/services/task-review.js +102 -23
- package/src/services/task-runs.js +31 -3
- package/src/services/tasks.js +91 -3
- package/src/tools.js +20 -14
- package/ui/app.js +7 -10
- package/ui/i18n/en/chat.js +2 -0
- package/ui/i18n/en/common.js +10 -0
- package/ui/i18n/en/settings.js +76 -1
- package/ui/i18n/en/tasks.js +3 -0
- package/ui/i18n/zh/chat.js +2 -0
- package/ui/i18n/zh/common.js +10 -0
- package/ui/i18n/zh/settings.js +76 -1
- package/ui/i18n/zh/tasks.js +3 -0
- package/ui/modules/api.js +9 -1
- package/ui/modules/cards.js +6 -3
- package/ui/modules/chat.js +1 -1
- package/ui/modules/composer.js +6 -1
- package/ui/modules/events-board.js +48 -0
- package/ui/modules/events-misc.js +43 -0
- package/ui/modules/events-submit.js +20 -0
- package/ui/modules/form-validation.js +204 -0
- package/ui/modules/global-pages.js +8 -5
- package/ui/modules/modal-forms.js +4 -4
- package/ui/modules/modal-layer.js +4 -1
- package/ui/modules/page-shell.js +10 -7
- package/ui/modules/permissions.js +99 -0
- package/ui/modules/settings.js +108 -26
- package/ui/modules/state.js +10 -0
- package/ui/modules/task-menu.js +147 -0
- package/ui/modules/tasks.js +11 -10
- package/ui/modules/util.js +43 -6
- package/ui/styles/a11y.css +13 -0
- package/ui/styles/base.css +57 -11
- package/ui/styles/buttons.css +46 -6
- package/ui/styles/cards.css +90 -0
- package/ui/styles/chat.css +23 -2
- package/ui/styles/global-config.css +7 -4
- package/ui/styles/modal.css +28 -0
- package/ui/styles/settings.css +23 -1
- package/ui/styles/tasks.css +51 -1
- package/ui/styles/toast.css +18 -11
- package/ui/styles/usage.css +2 -0
- package/ui/styles/wide.css +5 -0
- package/docs/assets/channel-redesign.png +0 -0
- package/docs/assets/global-config-dark.png +0 -0
- package/docs/assets/global-config-light.png +0 -0
- package/docs/assets/global-config-light.zh.png +0 -0
- package/docs/assets/global-config-redesign.png +0 -0
- package/docs/assets/secrets-redesign.png +0 -0
- package/docs/assets/usage-redesign-global.png +0 -0
package/src/services/chat.js
CHANGED
|
@@ -150,11 +150,21 @@ export const chatMethods = {
|
|
|
150
150
|
: null
|
|
151
151
|
if (replyTo && !replyMessage) throw badRequest('引用的消息不存在')
|
|
152
152
|
const mentions = parseMentions(body, members)
|
|
153
|
-
//
|
|
154
|
-
|
|
153
|
+
// 群聊回复模式(吸收 dsh-agent-team 关注/取关理念,复用既有 reply_mode 字段):
|
|
154
|
+
// owner_first = 显式目标缺省时总监兜底(原行为);everyone = 无显式目标时全员响应;
|
|
155
|
+
// mentioned_only = 无显式 @/引用目标不唤醒任何 bot,消息留群给人看——直接信号
|
|
156
|
+
// (@mention、引用回复)在所有模式下都照旧直达。
|
|
157
|
+
const explicitTarget = mentions.length > 0
|
|
155
158
|
? mentions
|
|
156
|
-
: members.filter(bot => bot.id === (replyMessage?.sender_type === 'bot' ? replyMessage.sender_id :
|
|
157
|
-
|
|
159
|
+
: members.filter(bot => bot.id === (replyMessage?.sender_type === 'bot' ? replyMessage.sender_id : null))
|
|
160
|
+
const group = this.groupOf(projectId)
|
|
161
|
+
const replyMode = group?.reply_mode ?? 'owner_first'
|
|
162
|
+
const fallback = replyMode === 'everyone'
|
|
163
|
+
? members
|
|
164
|
+
: replyMode === 'mentioned_only'
|
|
165
|
+
? []
|
|
166
|
+
: members.filter(bot => bot.id === project.owner_bot_id)
|
|
167
|
+
const targets = (explicitTarget.length > 0 ? explicitTarget : fallback).slice(0, 3)
|
|
158
168
|
const messageId = this.insertMessage({
|
|
159
169
|
projectId,
|
|
160
170
|
senderType: actor.type,
|
|
@@ -164,6 +174,16 @@ export const chatMethods = {
|
|
|
164
174
|
replyToId: replyMessage?.id ?? null,
|
|
165
175
|
images,
|
|
166
176
|
})
|
|
177
|
+
// mentioned_only 的环境消息(无显式 @/引用):不立即唤醒任何 bot,但总监默认 1 秒后
|
|
178
|
+
// 自动接单——发送回传带 runBots=[总监],UI 立刻立起总监的思考气泡(乐观排队行,
|
|
179
|
+
// typing-linger 复用),真实运行 1 秒后入列接管气泡。
|
|
180
|
+
const ambientDirectorClaim = replyMode === 'mentioned_only'
|
|
181
|
+
&& explicitTarget.length === 0
|
|
182
|
+
&& targets.length === 0
|
|
183
|
+
&& members.some(bot => bot.id === project.owner_bot_id)
|
|
184
|
+
if (ambientDirectorClaim) {
|
|
185
|
+
setTimeout(() => { this.claimAmbientMessage(project.id, project.owner_bot_id, messageId) }, 1_000)
|
|
186
|
+
}
|
|
167
187
|
for (const bot of targets) {
|
|
168
188
|
this.enqueueOutbox({
|
|
169
189
|
kind: 'chat_run',
|
|
@@ -179,7 +199,36 @@ export const chatMethods = {
|
|
|
179
199
|
void considerVisionProxy(this, { bot, message: { id: messageId, project_id: project.id } })
|
|
180
200
|
}
|
|
181
201
|
void this.tick()
|
|
182
|
-
|
|
202
|
+
// 环境接单的回传:runBots 带总监供 UI 立思考气泡;真实运行由 1 秒后的接单入列。
|
|
203
|
+
// 保持与旧版一致的单一返回形态(条件展开会改变推断并破坏调用方类型)。
|
|
204
|
+
return {
|
|
205
|
+
messageId,
|
|
206
|
+
runBots: ambientDirectorClaim ? [project.owner_bot_id] : targets.map(bot => bot.id),
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
// mentioned_only 环境消息的延迟接单(1 秒):到点复核后按标准 chat_run 幂等键入列——
|
|
211
|
+
// 幂等键 `chat:<msg>:<bot>` 保证期间任何路径已派生同一运行时这里是 no-op。复核条件
|
|
212
|
+
// (总监可用、项目未归档、消息仍在)不满足则静默放弃,接单失败只 warn。
|
|
213
|
+
claimAmbientMessage(projectId, botId, messageId) {
|
|
214
|
+
try {
|
|
215
|
+
const project = this.store.get("SELECT id FROM projects WHERE id = ? AND status = 'active'", projectId)
|
|
216
|
+
const bot = this.store.get("SELECT id FROM bots WHERE id = ? AND status = 'active'", botId)
|
|
217
|
+
const message = this.store.get("SELECT id FROM messages WHERE id = ? AND project_id = ?", messageId, projectId)
|
|
218
|
+
if (!project || !bot || !message) return false
|
|
219
|
+
this.enqueueOutbox({
|
|
220
|
+
kind: 'chat_run',
|
|
221
|
+
payload: { projectId, botId, messageId },
|
|
222
|
+
projectId,
|
|
223
|
+
sourceId: messageId,
|
|
224
|
+
idempotencyKey: `chat:${messageId}:${botId}`,
|
|
225
|
+
})
|
|
226
|
+
void this.tick()
|
|
227
|
+
return true
|
|
228
|
+
} catch (error ) {
|
|
229
|
+
this.logger.warn?.('dsh-team: 环境消息延迟接单失败 %s: %s', messageId, error?.message ?? error)
|
|
230
|
+
return false
|
|
231
|
+
}
|
|
183
232
|
},
|
|
184
233
|
|
|
185
234
|
// /clear:清空本群全部聊天记录。任务、记忆等不受影响;操作进审计。
|
package/src/services/core.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// 本文件只放方法体,方法挂到 TeamService 原型上(见 src/service.js 的 defineMethods 调用),
|
|
4
4
|
// 因此方法体内的 this 与拆分前完全一致。
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { validateRuntimeSettingValue, RUNTIME_SETTING_DEFS, RUNTIME_SETTING_KEYS, runtimeSettingsView as runtimeSettingsRows,
|
|
7
|
+
effectiveReviewIdleMinutes, effectiveRunLimits, envExplicit, RUN_LIMIT_RANGES, RUN_TIMEOUT_KEY, STALL_WATCHDOG_KEY, APPROVAL_TIMEOUT_KEY, QUESTION_TIMEOUT_KEY, REVIEW_TIMEOUT_KEY, UI_LANGUAGE_KEY, UI_LANGUAGE_VALUES, REVIEW_AUTO_CLOSE_KEY, REVIEW_ESCALATE_KEY, REVIEW_ESCALATE_RANGE, REVIEW_IDLE_MINUTES_KEY, REVIEW_IDLE_MINUTES_RANGE } from '../config.js'
|
|
7
8
|
import { badRequest, conflict, notFound } from '../errors.js'
|
|
8
9
|
import { ensureDirResilient, ensureSkillRoot } from '../paths.js'
|
|
9
10
|
import { seedModelPrices } from '../pricing.js'
|
|
@@ -19,6 +20,7 @@ import { ensureTaskSandboxSchema } from './task-sandbox-schema.js'
|
|
|
19
20
|
import { ensureWechatTriggerSchema } from './wechat-trigger-schema.js'
|
|
20
21
|
import { ensureExternalTriggerSchema } from './external-trigger-schema.js'
|
|
21
22
|
import { PROMPT_SEGMENT_DEFAULTS, PROMPT_SEGMENT_MAX_CHARS, PROMPT_TRIO_BUDGET, parsePromptOverrides, promptOverridesHash, taskGuidanceTrioLength } from './runtime/prompt.js'
|
|
23
|
+
import { effectiveReviewTimeoutMinutes } from './runtime/session.js'
|
|
22
24
|
import { id, jsonParse, nowIso } from '../util.js'
|
|
23
25
|
|
|
24
26
|
|
|
@@ -213,8 +215,11 @@ export const coreMethods = {
|
|
|
213
215
|
'memory_review', 'chat_memory_review',
|
|
214
216
|
RUN_TIMEOUT_KEY, STALL_WATCHDOG_KEY,
|
|
215
217
|
APPROVAL_TIMEOUT_KEY, QUESTION_TIMEOUT_KEY,
|
|
218
|
+
REVIEW_TIMEOUT_KEY,
|
|
216
219
|
UI_LANGUAGE_KEY,
|
|
217
220
|
REVIEW_IDLE_MINUTES_KEY, REVIEW_AUTO_CLOSE_KEY, REVIEW_ESCALATE_KEY,
|
|
221
|
+
// 运行参数目录(全局设置「运行参数」卡):所有运行期 DSH_TEAM_* 变量的可配置键域。
|
|
222
|
+
...RUNTIME_SETTING_KEYS,
|
|
218
223
|
]
|
|
219
224
|
const values = {}
|
|
220
225
|
for (const key of keys) values[key] = this.store.setting(key, '')
|
|
@@ -233,6 +238,9 @@ export const coreMethods = {
|
|
|
233
238
|
runTimeoutEnv: limits.runTimeoutEnv,
|
|
234
239
|
stallTimeoutEnv: limits.stallTimeoutEnv,
|
|
235
240
|
reviewIdleMinutes,
|
|
241
|
+
// 验收分档时效(DSHBOTS-364):默认 0 = 关闭分档、跟随全局;设置页随行回显。
|
|
242
|
+
reviewTimeoutMinutes: effectiveReviewTimeoutMinutes(key => this.store.setting(key)),
|
|
243
|
+
reviewTimeoutEnv: envExplicit('DSH_TEAM_REVIEW_TIMEOUT_MINUTES'),
|
|
236
244
|
}
|
|
237
245
|
},
|
|
238
246
|
updateSettings(patch, actor = this.actor(), expectedRevision = undefined) {
|
|
@@ -312,6 +320,14 @@ export const coreMethods = {
|
|
|
312
320
|
if (!UI_LANGUAGE_VALUES.includes(raw)) throw badRequest(`${UI_LANGUAGE_KEY} 必须是 ${UI_LANGUAGE_VALUES.join('/')}`)
|
|
313
321
|
values[UI_LANGUAGE_KEY] = raw
|
|
314
322
|
}
|
|
323
|
+
// 运行参数目录通用校验:空串 = 清除保存值回默认;非空按 kind 校验并规范化落库。
|
|
324
|
+
for (const def of RUNTIME_SETTING_DEFS) {
|
|
325
|
+
const value = values[def.key]
|
|
326
|
+
if (value === undefined || value === '') continue
|
|
327
|
+
const check = validateRuntimeSettingValue(def, value)
|
|
328
|
+
if (!check.ok) throw badRequest(`运行参数 ${def.key}(${def.env}):${check.error}`)
|
|
329
|
+
values[def.key] = check.normalized
|
|
330
|
+
}
|
|
315
331
|
this.store.transaction(() => {
|
|
316
332
|
for (const [key, value] of Object.entries(values)) this.store.setSetting(key, value)
|
|
317
333
|
// 乐观并发令牌随保存推进(B2/DSHBOTS-325):settings_revision 不是 settingsView 键,
|
|
@@ -330,6 +346,13 @@ export const coreMethods = {
|
|
|
330
346
|
return this.settingsView()
|
|
331
347
|
},
|
|
332
348
|
|
|
349
|
+
// 运行参数目录展示视图(全局设置「运行参数」卡):每条 env 的保存值/生效值/默认值/
|
|
350
|
+
// env 覆盖标志。effective 取自存活覆盖视图,与所有消费点同源。
|
|
351
|
+
runtimeSettingsView() {
|
|
352
|
+
// default 列必须取启动配置(baseConfig),不能取覆盖视图,否则「默认值」列会跟着保存值变。
|
|
353
|
+
return { rows: runtimeSettingsRows(this.baseConfig ?? this.config, key => this.store.setting(key)) }
|
|
354
|
+
},
|
|
355
|
+
|
|
333
356
|
// 可编辑提示词段(B1/DSHBOTS-324):只读视图。defaultChanged = 覆盖保存时的内置默认
|
|
334
357
|
// 指纹与当前默认不一致(升级改了默认文本),UI 据此给「保留我的文本 / 恢复新默认」取舍。
|
|
335
358
|
promptSegmentsView() {
|
|
@@ -389,7 +412,9 @@ export const coreMethods = {
|
|
|
389
412
|
start() {
|
|
390
413
|
if (this.started) return
|
|
391
414
|
this.started = true
|
|
392
|
-
|
|
415
|
+
// 周期拍走空载门:空闲时降频为一次索引计数,有工作立即恢复全量拍;
|
|
416
|
+
// 事件唤醒(各入队路径的 void this.tick())不经此门。
|
|
417
|
+
this.timer = setInterval(() => void this.tickIdleGate(), this.config.schedulerIntervalMs)
|
|
393
418
|
this.timer.unref?.()
|
|
394
419
|
setTimeout(() => void this.tick(), 300).unref?.()
|
|
395
420
|
},
|
|
@@ -397,6 +422,10 @@ export const coreMethods = {
|
|
|
397
422
|
if (this.timer) clearInterval(this.timer)
|
|
398
423
|
this.timer = null
|
|
399
424
|
this.started = false
|
|
425
|
+
// 在途审批定时器一并清空:abort 监听由宿主信号持有无法摘除(迟到结算已由
|
|
426
|
+
// settleApproval 容错),但停机后不得再由自身定时器主动触发写库。
|
|
427
|
+
for (const pending of this.approvalPending?.values() ?? []) clearTimeout(pending.timer)
|
|
428
|
+
this.approvalPending?.clear()
|
|
400
429
|
void this.wechat?.stop()
|
|
401
430
|
void this.feishu?.stop()
|
|
402
431
|
},
|
package/src/services/memory.js
CHANGED
|
@@ -12,7 +12,12 @@ import { id, jsonParse, nowIso, redactSecrets, text, sanitizeFilename } from '..
|
|
|
12
12
|
// 记忆上限(DSHBOTS-339):bot/project 作用域 active 记忆硬顶 MEMORY_CAP 条;触顶后新增被拒,
|
|
13
13
|
// 须先整理到 MEMORY_COMPACT_TO 条以内才恢复放行(滞回,避免在阈值附近反复开关)。team 作用域不限。
|
|
14
14
|
export const MEMORY_CAP = 64
|
|
15
|
-
|
|
15
|
+
// 恢复线(DSHBOTS-360):触顶后须整理到 ≤MEMORY_COMPACT_TO 条才恢复新增(滞回带宽度 10 条)。
|
|
16
|
+
// 取 MEMORY_CAP−10:滞回带要宽过单轮最大突发,否则一轮自动沉淀就能把刚整理出的余量再次吃满。
|
|
17
|
+
// 10 条恰好覆盖记忆审查单轮最大突发(parseMemoryReview ≤10 条);规则沉淀(learnFromTask ≤2 条)
|
|
18
|
+
// 与审查同轮发生时会略超,属已知余量收紧,必要时可再放宽。早期取 33(≈CAP/2)等于强制腰斩,过苛:
|
|
19
|
+
// 61 条需清 28 条才解锁,恢复线本身成了新的阻塞源。
|
|
20
|
+
export const MEMORY_COMPACT_TO = MEMORY_CAP - 10
|
|
16
21
|
// 单条记忆篇幅上限(owner 补充):content 不得超过 256 字。
|
|
17
22
|
export const MEMORY_MAX_CHARS = 256
|
|
18
23
|
|
|
@@ -154,15 +159,48 @@ export const memoryMethods = {
|
|
|
154
159
|
// 审查模型覆盖:配置了专用模型对时随运行下发(runs.model_* 三列既有通道,
|
|
155
160
|
// startRun 的 modelOverrideFor 消费);未配置为 NULL,沿用 Bot 主模型。
|
|
156
161
|
const target = memoryReviewModelTarget(this.config)
|
|
162
|
+
// DSHBOTS-358:记忆审查属内部运行,同样接额度路由——主 provider 耗尽时走备用模型;
|
|
163
|
+
// 主备都耗尽则不带模型覆盖,留 queued 等恢复(调度器额度闸门兜底)。
|
|
164
|
+
// 专用审查模型配在别的 provider 且该 provider 未耗尽时,专用模型优先。
|
|
165
|
+
const routing = this.quotaRoutingForBot(bot)
|
|
166
|
+
let reviewProvider = target?.provider ?? null
|
|
167
|
+
let reviewModel = target?.model ?? null
|
|
168
|
+
let reviewEffort = null
|
|
169
|
+
if (routing.mode === 'fallback') {
|
|
170
|
+
reviewProvider = routing.provider
|
|
171
|
+
reviewModel = routing.model
|
|
172
|
+
reviewEffort = routing.effort ?? null
|
|
173
|
+
} else if (routing.mode === 'wait') {
|
|
174
|
+
const dedicated = target ? this.botQuotaState(bot.id, target.provider) : null
|
|
175
|
+
if (!target || dedicated?.exhausted) {
|
|
176
|
+
reviewProvider = null
|
|
177
|
+
reviewModel = null
|
|
178
|
+
}
|
|
179
|
+
}
|
|
157
180
|
const reviewRunId = id('run')
|
|
158
181
|
const createdAt = nowIso()
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
182
|
+
try {
|
|
183
|
+
this.store.run(
|
|
184
|
+
`INSERT INTO runs(id, project_id, bot_id, task_id, kind, mode, trigger_type, trigger_ref, status,
|
|
185
|
+
attempt, idempotency_key, model_provider, model_model, model_effort, queued_at)
|
|
186
|
+
VALUES (?, ?, ?, NULL, 'memory_review', 'read', 'memory_review', ?, 'queued', 1, ?, ?, ?, ?, ?)`,
|
|
187
|
+
reviewRunId, project.id, bot.id, sourceRunId, `memory_review:${sourceRunId}`,
|
|
188
|
+
reviewProvider, reviewModel, reviewEffort, createdAt,
|
|
189
|
+
)
|
|
190
|
+
} catch (error) {
|
|
191
|
+
// memory_review 占 bot 串行域但入队点无 busy 闸(来源运行收尾/交付路径):同 (bot,
|
|
192
|
+
// 工作区) 已有活跃运行(如任务交付后新 chat 已排队)时 INSERT 撞 one_active_run_per_bot。
|
|
193
|
+
// 审查是尽力而为的治理动作,撞车降级为跳过(调用方按 null 走沉淀兜底/忽略),不把
|
|
194
|
+
// 收尾路径打成异常(生产实测:finishRun 尾部抛 UNIQUE 导致运行收尾报「异常」)。
|
|
195
|
+
if (this.isRunBotUniqueViolation(error)) {
|
|
196
|
+
this.logger?.warn?.(
|
|
197
|
+
'dsh-team: 记忆审查入队撞 bot 串行域(bot=%s run=%s source=%s),本次跳过',
|
|
198
|
+
bot?.id, reviewRunId, sourceRunId,
|
|
199
|
+
)
|
|
200
|
+
return null
|
|
201
|
+
}
|
|
202
|
+
throw error
|
|
203
|
+
}
|
|
166
204
|
this.store.run(
|
|
167
205
|
'INSERT INTO run_events(id, run_id, type, message, created_at) VALUES (?, ?, ?, ?, ?)',
|
|
168
206
|
id('evt'), reviewRunId, 'queued', '任务交付完成,触发记忆审查', createdAt,
|
|
@@ -193,6 +231,11 @@ export const memoryMethods = {
|
|
|
193
231
|
const source = `run:${sourceRunId}`
|
|
194
232
|
let applied = 0
|
|
195
233
|
let deduped = 0
|
|
234
|
+
// 拒写留痕(DSHBOTS-360):审查写入被拒时把拒因带内化——写进 run_events,
|
|
235
|
+
// 不再只丢一条系统日志(run_events 只说「写入 0 条」而无人知道为什么,锁定期会无限期无人处理)。
|
|
236
|
+
let rejected = 0
|
|
237
|
+
let capacityRejected = 0
|
|
238
|
+
const rejectReasons = []
|
|
196
239
|
// 同一次审查里重复的条目、以及同一来源重复触发的审查,写入前都按来源+内容去重。
|
|
197
240
|
const seen = new Set()
|
|
198
241
|
for (const item of items) {
|
|
@@ -231,14 +274,23 @@ export const memoryMethods = {
|
|
|
231
274
|
})
|
|
232
275
|
applied += 1
|
|
233
276
|
} catch (writeError ) {
|
|
234
|
-
|
|
277
|
+
rejected += 1
|
|
278
|
+
const reason = String(writeError?.message ?? writeError)
|
|
279
|
+
// 容量锁(conflict 409)与其它拒因分开计数:容量锁意味着作用域处在整理锁定期,需要人处理。
|
|
280
|
+
if (writeError?.status === 409) capacityRejected += 1
|
|
281
|
+
if (rejectReasons.length < 3) rejectReasons.push(reason)
|
|
282
|
+
// 同主题覆盖写降级属可选能力:owner 未点头,本卡不实现(不改写既有条目、不把被拒条目转 pending 堆积)。
|
|
283
|
+
this.logger.warn?.('dsh-team: 记忆审查写入失败:%s', reason)
|
|
235
284
|
}
|
|
236
285
|
}
|
|
286
|
+
const rejectNote = rejected
|
|
287
|
+
? `,拒写 ${rejected} 条${capacityRejected ? `(其中 ${capacityRejected} 条因容量锁被拒)` : ''}:${rejectReasons.join(';')}`
|
|
288
|
+
: ''
|
|
237
289
|
this.store.run(
|
|
238
290
|
'INSERT INTO run_events(id, run_id, type, message, created_at) VALUES (?, ?, ?, ?, ?)',
|
|
239
|
-
id('evt'), reviewRun.id, 'reviewed', `记忆审查完成,写入 ${applied} 条${deduped ? `,去重 ${deduped} 条` : ''}`, nowIso(),
|
|
291
|
+
id('evt'), reviewRun.id, 'reviewed', `记忆审查完成,写入 ${applied} 条${deduped ? `,去重 ${deduped} 条` : ''}${rejectNote}`, nowIso(),
|
|
240
292
|
)
|
|
241
|
-
return { applied, deduped }
|
|
293
|
+
return { applied, deduped, rejected, capacityRejected }
|
|
242
294
|
},
|
|
243
295
|
|
|
244
296
|
// 记忆写入权限:用户可写任意作用域;Bot 只能写自己的记忆、是成员的项目记忆,
|
|
@@ -279,7 +331,8 @@ export const memoryMethods = {
|
|
|
279
331
|
},
|
|
280
332
|
memoryCapacityMessage(scopeType, scopeId, count, latched = false) {
|
|
281
333
|
const label = scopeType === 'bot' ? `Bot(${scopeId})` : `项目(${scopeId})`
|
|
282
|
-
// 锁定带(滞回标志在、
|
|
334
|
+
// 锁定带(滞回标志在、(MEMORY_COMPACT_TO, MEMORY_CAP) 之间):如实说明此前触顶、现处整理锁定期,
|
|
335
|
+
// 不得谎称「已达 N/64」。
|
|
283
336
|
if (latched) {
|
|
284
337
|
return `${label}记忆此前触顶 ${MEMORY_CAP} 条上限,现处整理锁定期(当前 ${count} 条),新增被拒绝;需整理到 ≤${MEMORY_COMPACT_TO} 条恢复新增:去废弃(team_memory_cleanup 清理已闭环任务或过时主题)、去冗与融合(同主题 team_memory_write 覆盖写、合并相近条目);同主题覆盖写不受影响。`
|
|
285
338
|
}
|
|
@@ -409,7 +462,8 @@ export const memoryMethods = {
|
|
|
409
462
|
const keyword = text(query, 200).trim()
|
|
410
463
|
const limitN = Math.min(100, Math.max(1, Number(limit) || 20))
|
|
411
464
|
let rows
|
|
412
|
-
|
|
465
|
+
// trigram 分词器无法匹配不足 3 字符的关键词(如中文「发版」两字),短词走 LIKE 子串兜底。
|
|
466
|
+
if (keyword && this.store.ftsEnabled && keyword.length >= 3) {
|
|
413
467
|
const match = `"${keyword.replace(/"/g, '""')}"`
|
|
414
468
|
rows = this.store.all(
|
|
415
469
|
`SELECT m.* FROM memories_fts f JOIN memories m ON m.id = f.memory_id
|
|
@@ -512,17 +566,53 @@ export const memoryMethods = {
|
|
|
512
566
|
// 三入口共用 ownerContextFor 权威鉴权(仅项目总监,单聊/成员拒绝);
|
|
513
567
|
// 不改宿主 team_remember 语义,插件层独立封装。
|
|
514
568
|
|
|
515
|
-
//
|
|
516
|
-
|
|
569
|
+
// 记忆工具上下文:任意项目群 Bot 可自管自己的 bot 域(成员 Bot 触顶后的合法自救通道,
|
|
570
|
+
// 总监可经 bot 点名代管任意 Bot);project/team 域仍只归总监(ownerContextFor 同款判定)。
|
|
571
|
+
memoryActorFor(sessionId) {
|
|
572
|
+
const binding = this.store.get('SELECT * FROM session_bindings WHERE session_id = ?', sessionId)
|
|
573
|
+
if (!binding) throw forbidden('只有项目群中的 Bot 可以执行该操作')
|
|
574
|
+
const project = binding.project_id ? this.projectRow(binding.project_id) : null
|
|
575
|
+
return {
|
|
576
|
+
binding,
|
|
577
|
+
project,
|
|
578
|
+
actor: { type: 'bot', id: binding.bot_id },
|
|
579
|
+
isOwner: Boolean(project && project.owner_bot_id === binding.bot_id),
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
resolveMemoryScopeFor(sessionId, input) {
|
|
583
|
+
const ctx = this.memoryActorFor(sessionId)
|
|
584
|
+
const scopeType = ['bot', 'project', 'team'].includes(input.scope) ? input.scope : null
|
|
585
|
+
if (!scopeType) throw badRequest('记忆作用域无效')
|
|
586
|
+
if (ctx.isOwner) {
|
|
587
|
+
const resolved = this.resolveOwnerMemoryScope(ctx, input.scope, input.bot)
|
|
588
|
+
return { ...resolved, actor: ctx.actor, project: ctx.project, isOwner: true }
|
|
589
|
+
}
|
|
590
|
+
// 成员:只放行自己的 bot 域;点名参数仅接受自己(点名他人即拒绝)。
|
|
591
|
+
if (scopeType !== 'bot') {
|
|
592
|
+
throw forbidden('成员只能管理自己的 bot 域记忆;项目/团队域的整理请由项目总监执行')
|
|
593
|
+
}
|
|
594
|
+
if (input.bot != null && String(input.bot).trim() !== '') {
|
|
595
|
+
const named = this.resolveBotForQuota(input.bot)
|
|
596
|
+
if (named.id !== ctx.binding.bot_id) throw forbidden('Bot 只能点名管理自己的记忆')
|
|
597
|
+
}
|
|
598
|
+
return { scopeType, scopeId: ctx.binding.bot_id, actor: ctx.actor, project: ctx.project, isOwner: false }
|
|
599
|
+
},
|
|
600
|
+
|
|
601
|
+
// 把 scope 枚举解析到总监会话所在的具体作用域:bot=总监自己(bot_ref 点名时为该 Bot,
|
|
602
|
+
// 成员 Bot 超限整理的合法通道——resolveBotForQuota 按 id 或精确名解析,任意总监可点名),
|
|
603
|
+
// project=会话项目,team=全团队。
|
|
604
|
+
resolveOwnerMemoryScope(ownerCtx, scope, botRef = null) {
|
|
517
605
|
const scopeType = ['bot', 'project', 'team'].includes(scope) ? scope : null
|
|
518
606
|
if (!scopeType) throw badRequest('记忆作用域无效')
|
|
519
|
-
|
|
607
|
+
let scopeId = scopeType === 'project' ? ownerCtx.project.id : scopeType === 'team' ? 'team' : ownerCtx.binding.bot_id
|
|
608
|
+
if (scopeType === 'bot' && botRef != null && String(botRef).trim() !== '') {
|
|
609
|
+
scopeId = this.resolveBotForQuota(botRef).id
|
|
610
|
+
}
|
|
520
611
|
return { scopeType, scopeId }
|
|
521
612
|
},
|
|
522
613
|
|
|
523
|
-
memoryListFromBot(sessionId, input
|
|
524
|
-
const
|
|
525
|
-
const { scopeType, scopeId } = this.resolveOwnerMemoryScope(ownerCtx, input.scope ?? 'project')
|
|
614
|
+
memoryListFromBot(sessionId, input = {}) {
|
|
615
|
+
const { scopeType, scopeId } = this.resolveMemoryScopeFor(sessionId, { scope: 'project', ...input })
|
|
526
616
|
const keyword = text(input.topic, 200).trim()
|
|
527
617
|
const limitN = Math.min(200, Math.max(1, Number(input.limit) || 50))
|
|
528
618
|
const like = `%${keyword}%`
|
|
@@ -539,9 +629,7 @@ export const memoryMethods = {
|
|
|
539
629
|
// 写入/同名覆盖:同 scope+topic 已有 active 记忆时原地更新(revision+1、事件留痕),
|
|
540
630
|
// 不再叠新条;无同名时走 createMemory 正常创建。
|
|
541
631
|
memoryWriteFromBot(sessionId, input) {
|
|
542
|
-
const
|
|
543
|
-
const { scopeType, scopeId } = this.resolveOwnerMemoryScope(ownerCtx, input.scope)
|
|
544
|
-
const actor = ownerCtx.actor
|
|
632
|
+
const { scopeType, scopeId, actor } = this.resolveMemoryScopeFor(sessionId, input)
|
|
545
633
|
const topic = text(input.topic, 120)
|
|
546
634
|
if (!topic) throw badRequest('缺少记忆主题')
|
|
547
635
|
const existing = this.store.get(
|
|
@@ -584,13 +672,12 @@ export const memoryMethods = {
|
|
|
584
672
|
// before 与 topics/task 可组合,按 AND 交集收窄;三者全缺即拒绝(不做「全清」缺省)。
|
|
585
673
|
// 逐条 memory_events 留痕 + 一笔 memory.cleanup 审计列出被清条目。
|
|
586
674
|
memoryCleanupFromBot(sessionId, input) {
|
|
587
|
-
const
|
|
588
|
-
const { project, actor } = ownerCtx
|
|
589
|
-
const { scopeType, scopeId } = this.resolveOwnerMemoryScope(ownerCtx, input.scope)
|
|
675
|
+
const { scopeType, scopeId, project, actor } = this.resolveMemoryScopeFor(sessionId, input)
|
|
590
676
|
const topics = (Array.isArray(input.topics) ? input.topics : []).map(item => text(item, 120)).filter(Boolean)
|
|
591
677
|
let taskLabel = null
|
|
592
678
|
let taskTopics = []
|
|
593
679
|
if (input.task) {
|
|
680
|
+
if (!project) throw forbidden('单聊会话不在项目中,无法按任务口径清理')
|
|
594
681
|
const task = this.resolveBotTask(project, input.task)
|
|
595
682
|
if (!['done', 'canceled'].includes(task.status)) {
|
|
596
683
|
throw badRequest(`仅已闭环(done/canceled)任务的历史记录可清理,${project.key}-${task.number} 当前为 ${task.status}`)
|
|
@@ -32,6 +32,21 @@ export const PROVIDER_UNAVAILABLE_CODES = new Set([
|
|
|
32
32
|
// 额度耗尽不在此列——它没有可等的短窗口,必须换模型。
|
|
33
33
|
const WAITABLE_CODES = new Set(['RATE_LIMIT', 'QUOTA'])
|
|
34
34
|
|
|
35
|
+
// 可派生备用运行的内部运行种类(DSHBOTS-358):任务运行 + 总监验收/受阻处理 + 记忆审查。
|
|
36
|
+
// 这些运行都在项目工作台内部流转,重跑不会重复打扰用户,因此与任务运行同口径切备用模型。
|
|
37
|
+
// 聊天类(chat / solo_chat / dm / vision 等)不在此列:自动重跑会重复发消息、打扰用户。
|
|
38
|
+
export const INTERNAL_FALLBACK_KINDS = new Set(['task', 'review', 'handle', 'memory_review'])
|
|
39
|
+
|
|
40
|
+
// 运行链标识:任务链按 task_id,记忆审查链按来源运行 id(memory_review 不挂任务)。
|
|
41
|
+
function fallbackChainKey(run ) {
|
|
42
|
+
if (!run) return null
|
|
43
|
+
if (run.kind === 'memory_review') {
|
|
44
|
+
return run.trigger_ref ? { scope: 'memory', sourceRunId: run.trigger_ref } : null
|
|
45
|
+
}
|
|
46
|
+
if (run.task_id) return { scope: 'task', taskId: run.task_id }
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
35
50
|
export function isProviderUnavailableCode(code) {
|
|
36
51
|
return Boolean(code) && PROVIDER_UNAVAILABLE_CODES.has(String(code).toUpperCase())
|
|
37
52
|
}
|
|
@@ -63,12 +78,22 @@ export const modelFallbackMethods = {
|
|
|
63
78
|
},
|
|
64
79
|
|
|
65
80
|
// 这条运行链是否已经用过备用模型(每条链只切一次)。
|
|
81
|
+
// 链按运行种类分桶(DSHBOTS-358):任务链、验收链、受阻处理链、记忆审查链各自独立——
|
|
82
|
+
// 施工轮用过备用不代表总监验收轮不能再切,反之亦然。
|
|
66
83
|
fallbackUsedInChain(run) {
|
|
67
84
|
if (run?.model_provider) return true
|
|
68
|
-
|
|
85
|
+
const chain = fallbackChainKey(run)
|
|
86
|
+
if (!chain) return false
|
|
87
|
+
if (chain.scope === 'memory') {
|
|
88
|
+
const row = this.store.get(
|
|
89
|
+
`SELECT id FROM runs WHERE kind = 'memory_review' AND trigger_ref = ? AND model_provider IS NOT NULL LIMIT 1`,
|
|
90
|
+
chain.sourceRunId,
|
|
91
|
+
)
|
|
92
|
+
return Boolean(row)
|
|
93
|
+
}
|
|
69
94
|
const row = this.store.get(
|
|
70
|
-
'SELECT id FROM runs WHERE task_id = ? AND model_provider IS NOT NULL LIMIT 1',
|
|
71
|
-
run.
|
|
95
|
+
'SELECT id FROM runs WHERE kind = ? AND task_id = ? AND model_provider IS NOT NULL LIMIT 1',
|
|
96
|
+
run.kind, chain.taskId,
|
|
72
97
|
)
|
|
73
98
|
return Boolean(row)
|
|
74
99
|
},
|
|
@@ -78,28 +103,43 @@ export const modelFallbackMethods = {
|
|
|
78
103
|
const fallback = this.botFallbackModel(bot)
|
|
79
104
|
if (!fallback) return null
|
|
80
105
|
if (!shouldFallbackOn(error)) return null
|
|
81
|
-
//
|
|
82
|
-
if (run.kind
|
|
106
|
+
// 只对内部运行派生(DSHBOTS-358):私信/群聊/单聊自动重跑会重复发消息、打扰用户。
|
|
107
|
+
if (!INTERNAL_FALLBACK_KINDS.has(run.kind)) return null
|
|
108
|
+
const chain = fallbackChainKey(run)
|
|
109
|
+
if (!chain) return null
|
|
83
110
|
if (this.fallbackUsedInChain(run)) return null
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
111
|
+
if (chain.scope === 'task') {
|
|
112
|
+
const task = this.store.get('SELECT * FROM tasks WHERE id = ?', chain.taskId)
|
|
113
|
+
if (!task || ['done', 'canceled'].includes(task.status)) return null
|
|
114
|
+
// 任务已有排队/运行中的运行(唯一索引 one_active_run_per_task)就不再派生。
|
|
115
|
+
const active = this.store.get(
|
|
116
|
+
"SELECT id FROM runs WHERE task_id = ? AND status IN ('queued', 'running')",
|
|
117
|
+
chain.taskId,
|
|
118
|
+
)
|
|
119
|
+
if (active) return null
|
|
120
|
+
} else {
|
|
121
|
+
// 记忆审查链:同一条来源运行已有排队/运行中的审查运行就不再派生。
|
|
122
|
+
const active = this.store.get(
|
|
123
|
+
"SELECT id FROM runs WHERE kind = 'memory_review' AND trigger_ref = ? AND status IN ('queued', 'running')",
|
|
124
|
+
chain.sourceRunId,
|
|
125
|
+
)
|
|
126
|
+
if (active) return null
|
|
127
|
+
}
|
|
92
128
|
const runId = id('run')
|
|
93
129
|
const createdAt = nowIso()
|
|
94
130
|
const attempt = (Number(run.attempt) || 1) + 1
|
|
131
|
+
// 派生运行沿用原运行的种类与形态(DSHBOTS-358):验收/受阻处理/记忆审查各自保持
|
|
132
|
+
// 原有语义与提示词通道,只是换一套模型重跑同一条链。
|
|
133
|
+
const kind = run.kind
|
|
134
|
+
const mode = run.mode ?? (kind === 'task' ? 'write' : 'read')
|
|
95
135
|
try {
|
|
96
136
|
this.store.transaction(() => {
|
|
97
137
|
this.store.run(
|
|
98
138
|
`INSERT INTO runs(id, project_id, bot_id, task_id, parent_run_id, kind, mode, write_scopes, trigger_type,
|
|
99
139
|
trigger_ref, status, attempt, idempotency_key, model_provider, model_model, model_effort, queued_at)
|
|
100
|
-
VALUES (?, ?, ?, ?, ?,
|
|
140
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'queued', ?, ?, ?, ?, ?, ?)`,
|
|
101
141
|
runId, run.project_id, run.bot_id, run.task_id, run.id,
|
|
102
|
-
|
|
142
|
+
kind, mode, run.write_scopes ?? null,
|
|
103
143
|
run.trigger_type, run.trigger_ref, attempt, `model_fallback:${run.id}`,
|
|
104
144
|
fallback.provider, fallback.model, fallback.effort, createdAt,
|
|
105
145
|
)
|
package/src/services/projects.js
CHANGED
|
@@ -7,6 +7,7 @@ import { readdirSync, rmSync, statSync } from 'node:fs'
|
|
|
7
7
|
import { dirname, join, resolve } from 'node:path'
|
|
8
8
|
import { homedir } from 'node:os'
|
|
9
9
|
import { badRequest, conflict, forbidden, notFound } from '../errors.js'
|
|
10
|
+
import { REVIEWER_BOT_NAME } from '../seed-bots.js'
|
|
10
11
|
import { ensureBotTmpDirs, ensureExternalDir, ensureProjectWorkspace } from '../paths.js'
|
|
11
12
|
import { clampNumber, id, nowIso, parseDisabledSkills, projectKey, slugify, text } from '../util.js'
|
|
12
13
|
|
|
@@ -277,7 +278,17 @@ export const projectsMethods = {
|
|
|
277
278
|
const projectId = id('prj')
|
|
278
279
|
const groupId = id('grp')
|
|
279
280
|
const createdAt = nowIso()
|
|
280
|
-
|
|
281
|
+
// 成员默认(DSHBOTS-365):不显式指定成员的新群自动带入种子 reviewer——验收核验
|
|
282
|
+
// 优先落到质量评审角色上,总监只裁决。显式 memberIds 是用户裁剪过的名单,不擅自加人;
|
|
283
|
+
// 用户事后移除 reviewer 即回落总监自行核验(spawnReviewDelegate 兜底)。
|
|
284
|
+
const explicitMembers = Array.isArray(input.memberIds)
|
|
285
|
+
const memberIds = [...new Set([owner.id, ...(explicitMembers ? input.memberIds : [])])]
|
|
286
|
+
if (!explicitMembers) {
|
|
287
|
+
const reviewer = this.store.get(
|
|
288
|
+
"SELECT id FROM bots WHERE name = ? AND status = 'active'", REVIEWER_BOT_NAME,
|
|
289
|
+
)
|
|
290
|
+
if (reviewer && reviewer.id !== owner.id) memberIds.push(reviewer.id)
|
|
291
|
+
}
|
|
281
292
|
for (const botId of memberIds) this.botRow(botId)
|
|
282
293
|
await ensureProjectWorkspace(this.config.workspace, slug)
|
|
283
294
|
const productionDir = await this.resolveProductionDir(input.productionDir)
|
|
@@ -350,7 +361,7 @@ export const projectsMethods = {
|
|
|
350
361
|
updates.status = patch.status
|
|
351
362
|
}
|
|
352
363
|
if (patch.replyMode !== undefined) {
|
|
353
|
-
if (!['owner_first', 'everyone'].includes(patch.replyMode)) throw badRequest('群聊回复模式无效')
|
|
364
|
+
if (!['owner_first', 'everyone', 'mentioned_only'].includes(patch.replyMode)) throw badRequest('群聊回复模式无效')
|
|
354
365
|
}
|
|
355
366
|
const ownerId = updates.owner_bot_id ?? project.owner_bot_id
|
|
356
367
|
const memberIds = patch.memberIds === undefined
|
|
@@ -36,6 +36,10 @@ const FAILURE_CATEGORY_NOTICES = {
|
|
|
36
36
|
rate_limited: { label: '限流', summary: '上游限流,已按退避策略自动处理。' },
|
|
37
37
|
sandbox_denied: { label: '沙箱拒绝', summary: '文件或命令操作被沙箱策略拒绝。' },
|
|
38
38
|
timeout: { label: '超时', summary: '上游响应超时。' },
|
|
39
|
+
// DSHBOTS-364:本机时效中止/停滞收割与上游超时分开报——此前一律归「上游响应超时」,
|
|
40
|
+
// 把自家看门狗/分档时效的动作误报成 provider 故障,误导排查方向。
|
|
41
|
+
run_timeout: { label: '时效', summary: '运行超过时效上限被中止(非上游故障)。' },
|
|
42
|
+
stalled: { label: '停滞', summary: '运行长时间无进展,已被看门狗中止。' },
|
|
39
43
|
network: { label: '网络', summary: '网络瞬态失败,已按退避策略自动重试。' },
|
|
40
44
|
blocked: { label: '会话受阻', summary: '宿主拒绝执行该会话(可能已被归档),未产生任何模型输出。' },
|
|
41
45
|
internal: { label: '内部错误', summary: '服务内部错误。' },
|
|
@@ -46,6 +50,8 @@ export function classifyFailure(error) {
|
|
|
46
50
|
if (isQuotaExhausted(error)) return FAILURE_CATEGORY_NOTICES.quota
|
|
47
51
|
if (isRateLimitError(error)) return FAILURE_CATEGORY_NOTICES.rate_limited
|
|
48
52
|
if (SANDBOX_DENIED_PATTERN.test(raw)) return FAILURE_CATEGORY_NOTICES.sandbox_denied
|
|
53
|
+
if (error?.code === 'RUN_TIMEOUT') return FAILURE_CATEGORY_NOTICES.run_timeout
|
|
54
|
+
if (error?.code === 'RUN_STALLED') return FAILURE_CATEGORY_NOTICES.stalled
|
|
49
55
|
if (TIMEOUT_PATTERN.test(raw)) return FAILURE_CATEGORY_NOTICES.timeout
|
|
50
56
|
if (isTransientNetworkError(error)) return FAILURE_CATEGORY_NOTICES.network
|
|
51
57
|
if (error?.code === 'SESSION_BLOCKED') return FAILURE_CATEGORY_NOTICES.blocked
|
|
@@ -67,6 +73,11 @@ export const runFinishMethods = {
|
|
|
67
73
|
if (attentionPending) return false
|
|
68
74
|
const current = this.taskRow(task.id)
|
|
69
75
|
if (current.status !== 'in_review') return false
|
|
76
|
+
// 核验分档:只读档交付免自动核验(与验收闸门豁免同口径);审计留痕便于核对漏审。
|
|
77
|
+
if (this.readOnlyDelivery(run, current)) {
|
|
78
|
+
this.audit({ type: 'system', id: 'system' }, 'review.auto_delegate', 'task', task.id, { skipped: 'read_only' })
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
70
81
|
const owner = project.owner_bot_id
|
|
71
82
|
? this.store.get("SELECT id FROM bots WHERE id = ? AND status = 'active'", project.owner_bot_id)
|
|
72
83
|
: null
|
|
@@ -223,7 +234,22 @@ export const runFinishMethods = {
|
|
|
223
234
|
return
|
|
224
235
|
}
|
|
225
236
|
if (run.kind === 'memory_review') {
|
|
226
|
-
|
|
237
|
+
// DSHBOTS-358:记忆审查撞 provider 额度墙时切备用模型重跑同一条审查链,
|
|
238
|
+
// 规则沉淀兜底留到备用链也失败时再做,避免同一次交付落两份记忆。
|
|
239
|
+
const fallback = status === 'failed'
|
|
240
|
+
? this.spawnModelFallback({ run: refreshed, bot, error })
|
|
241
|
+
: null
|
|
242
|
+
if (fallback) {
|
|
243
|
+
this.insertMessage({
|
|
244
|
+
projectId: run.project_id,
|
|
245
|
+
senderType: 'bot',
|
|
246
|
+
senderId: bot.id,
|
|
247
|
+
body: `已达限额(${error?.code ?? '未知错误'}),已切换备用模型 ${fallback.fallback.ref} 继续记忆审查。`,
|
|
248
|
+
runId,
|
|
249
|
+
})
|
|
250
|
+
} else {
|
|
251
|
+
await this.completeMemoryReview(run, status === 'succeeded' ? cleanOutput : '', error)
|
|
252
|
+
}
|
|
227
253
|
if (this.rate[run.project_id]) delete this.rate[run.project_id]
|
|
228
254
|
return
|
|
229
255
|
}
|
|
@@ -281,7 +307,21 @@ export const runFinishMethods = {
|
|
|
281
307
|
}
|
|
282
308
|
if (run.kind === 'review' || run.kind === 'handle') {
|
|
283
309
|
const label = run.kind === 'review' ? '验收' : '受阻处理'
|
|
284
|
-
|
|
310
|
+
// DSHBOTS-358:总监验收/受阻处理撞 provider 额度墙时切备用模型重跑同一条链
|
|
311
|
+
// (与任务运行同口径);派生成功就不发失败消息、不触发退回重派链。
|
|
312
|
+
const fallback = status === 'failed'
|
|
313
|
+
? this.spawnModelFallback({ run: refreshed, bot, error })
|
|
314
|
+
: null
|
|
315
|
+
if (fallback) {
|
|
316
|
+
this.insertMessage({
|
|
317
|
+
projectId: project.id,
|
|
318
|
+
senderType: 'bot',
|
|
319
|
+
senderId: bot.id,
|
|
320
|
+
body: `已达限额(${error?.code ?? '未知错误'}),已切换备用模型 ${fallback.fallback.ref} 继续${label}。`,
|
|
321
|
+
taskId: run.task_id,
|
|
322
|
+
runId,
|
|
323
|
+
})
|
|
324
|
+
} else if (run.task_id) {
|
|
285
325
|
// 委派核验运行(DSHBOTS-107)成功时,结论以任务评论写回(复用 addComment 通道:
|
|
286
326
|
// 评论+事件+审计一次落全)。不改任务状态、不代为裁决——accept/return 仍归 owner。
|
|
287
327
|
if (run.trigger_type === 'review_delegate' && status === 'succeeded' && cleanOutput) {
|
|
@@ -343,11 +383,7 @@ export const runFinishMethods = {
|
|
|
343
383
|
// 子代理施工硬闸已解除(原 DSHBOTS-311):交付不再要求子代理施工账目,
|
|
344
384
|
// 施工方式由 bot 自选(亲做或派「bot 名+任务号」子代理),账本(D-294)仍照记。
|
|
345
385
|
this.store.transaction(() => {
|
|
346
|
-
this.
|
|
347
|
-
`UPDATE tasks SET status = 'in_review', version = version + 1, updated_at = ?
|
|
348
|
-
WHERE id = ? AND status NOT IN ('done', 'canceled')`,
|
|
349
|
-
endedAt, task.id,
|
|
350
|
-
)
|
|
386
|
+
this.setTaskStatus(task.id, 'in_review', { type: 'bot', id: bot.id })
|
|
351
387
|
this.store.run(
|
|
352
388
|
'INSERT INTO task_comments(id, task_id, author_type, author_id, body, created_at) VALUES (?, ?, ?, ?, ?, ?)',
|
|
353
389
|
id('cmt'), task.id, 'bot', bot.id,
|
|
@@ -479,10 +515,7 @@ export const runFinishMethods = {
|
|
|
479
515
|
runId,
|
|
480
516
|
})
|
|
481
517
|
} else if (run.task_id) {
|
|
482
|
-
this.
|
|
483
|
-
"UPDATE tasks SET status = 'blocked', version = version + 1, updated_at = ? WHERE id = ? AND status NOT IN ('done', 'canceled')",
|
|
484
|
-
endedAt, run.task_id,
|
|
485
|
-
)
|
|
518
|
+
this.setTaskStatus(run.task_id, 'blocked', { type: 'bot', id: bot.id })
|
|
486
519
|
this.addTaskEvent(run.task_id, 'run_failed', { type: 'bot', id: bot.id }, { runId, error })
|
|
487
520
|
// 额度耗尽没有「退避后自动重试」这回事:主备都限额就是终点,任务转受阻。
|
|
488
521
|
const quotaNote = quotaExhausted
|