dsh-aiyayi 1.2.2 → 1.2.4
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/README.md +4 -0
- package/lib/index.js +57 -12
- package/lib/presence.js +134 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,3 +73,7 @@ GUI 新建会话 → agent preset 选「**阿依娅伊**」。聊天即可;她
|
|
|
73
73
|
17. **体检单([状态])的数据通道与口径(v1.2.0)**:真实用量/窗口/模型来自 `session/event` 总线(插件侧折叠 `request/header`、`request/context`、`assistant/message` 的 `usage`,字段 `inputTokens/cacheReadTokens/cacheWriteTokens`;用法与会话落盘 `data.usage` 一致);`tokenMeter.measure` 只做兜底且按坑 #16 中文偏小一半,估算口径的提醒阈值除以 0.49 校准、行内标"(估算)"。注意两点:①agents 在 pre-step 里登记,登记之前到达的事件不折叠——每个会话首轮体检单常是空的或估算口径,第二轮起才准;②窗口拿不到(模型没声明 contextWindow 且 `requestContext()` 不可用)时不做用量提醒——没分母算不出比例,宁可沉默也不瞎报。
|
|
74
74
|
18. **DSH 更新会动 shipped 包的 exports(2026-11-05 实测,subagent-control 0.2.2-rc.1;1.2.1 已修)**:更新后 `@deepseek-ai/dsh-tool-subagent-control` 的 exports 只剩 `"."`,`./list-agents` 子路径被移除(list_agents 现由主入口 `apply()` 里的 `registerListAgents(ctx)` 一并注册)。旧 patch 行 `name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'` 导入时抛 `ERR_PACKAGE_PATH_NOT_EXPORTED` → 该行 "never started" → **整个 preset 一损俱损被登记处摘掉,"阿依娅伊"从预设选择器消失**。修法:删掉独立 list-agents 行,只留 `@deepseek-ai/dsh-tool-subagent-control` 一行(顶三个工具)。教训:preset 引用的 shipped 子路径没有版本锁,DSH 升级后 preset 消失 = 先翻启动日志搜 `ERR_PACKAGE_PATH_NOT_EXPORTED` / `never started`,对照新版 package.json 的 exports 改行。
|
|
75
75
|
19. **手写的工具白名单一定会漂移(2026-11-05 实测;1.2.2 已修)**:放行名单原来是 restrict.js 里一份手写常量,结果同时踩了两个坑——①`memory_organize` 没进名单,她想整理记忆时发现"手上只有记和翻两个动作",工具其实注册好了(首请求的工具集里明明有)却被白名单挡住;②同一次 DSH 升级把 schedule 工具改名(`schedule_update/schedule_delete` → `schedule_view/schedule_edit`,改期与删除合并进 schedule_edit 的 action 参数),旧名单里的两个旧名已不存在、新名没进名单,闹钟的"查看/改期"被挡。修法:新增 `lib/own-tools.js` 作单一真源——注册处(index.js / presence.js)调 `registerOwnTool(name)`,放行处(restrict.js)问 `isOwnTool(name)`,静态兜底表 `OWN_TOOLS` 防模块实例不共享时漏放行;闹钟一族用**前缀**判定(`schedule_`),因为 deny 名单里的名字必须真实存在于当刻继承面,多写一个不存在的名字会让整个 restrict 调用抛错、收敛全失效。症状与排障:她说"某个工具不见了"但工具其实在 → 比对她会话 `request/header` 的 tools 数组(第 1 个请求是完整集,第 2 个起是收敛后的集),对比两者的差集。
|
|
76
|
+
20. **核心记忆超限的静默截断会把最新条目丢掉(2026-11-05 实测;1.2.3 已修)**:`renderCore` 原来 `text.slice(0, MAX_CORE_CHARS)`(6000 字符)——①从中间切,条目行被切碎;②保住的是最老的一批,**最新写的条目反而全被截掉**,她以为"带了 51 条核心"其实只注入了 34 条,11-04 中午之后的记忆(含 11-05 新写)全没进上下文。修法:上限提到 12000;超限时改为**头部(人设/约定)+ 尾部(最新)整条保留**,中间批次丢弃,并在注入文本里写明"共 X 字符超限、只注入最前 a 条 + 最新 b 条、中间 c 条(最早 ~ 最晚)先不带,用 recall 或 memory_organize 的 read 查",头部行也标"本次只注入 N 条"。整条边界截断,永不切碎。教训:内存注入的字符上限要用"整条丢"而不是"切字符串",且被丢的部分必须显式告知,否则她以为带着、实际没有。
|
|
77
|
+
21. **子智能体手写 memory.md 会产生双类别前缀污染(2026-11-05 实测;1.2.3 已修)**:小伙伴在派活收尾时有时会"帮她补记",直接把 `用户|用户|…`、`关系|关系|…` 这种带前缀的整句写进 core 行,导致条目类别前缀叠了两层(实测 7 条:关系×1、用户×3、事情×2)。修法:`parseLine` 新增 `stripRepeatedKindPrefix`——遇到连续 `类别|类别|…` 前缀循环剥到只剩一层(任何读取路径都免疫);`remember` 写入前也先剥 content 自带前缀(防再生);存量 7 条已一次性手工修复。教训:凡是"别人代写她记忆文件"的路径都要在解析层兜底,不能指望写手守规矩。
|
|
78
|
+
22. **子代(小伙伴)失败原因不透传到本体(2026-11-05 实测;1.2.3 已修)**:宿主对派出去的子智能体的结算消息只有一句 `failed before it finished` / `It left no closing message.`——真实原因(HTTP_402 积分余额不足、上游限流、403、Illegal API invocation)只躺在子会话自己的 `turn/end` error 事件里(宿主 `terminal.diagnostic` 只有在 provider 主动给时才透传,本地 spawn 的 provider 不给)。她不知道为啥失败 → 盲目重派 3 轮白耗 ~20 分钟。修法:`aiyayi-presence` 的 `session/event` 监听不再丢弃非本体的会话事件,改把 `header.origin==="subagent"`(或带 `header.parentSession`)的子会话 `turn/end` error 记进 `childFailures`(上限 20、只记 error、错误串截 120 字符),下一个 pre-step 注入 `⚠ [小伙伴] 你派出去干活的小智能体有 N 个报错了(宿主只回一句"failed before it finished",真原因在这):…`(每次最多列 3 条、已报过的去重不唠叨)。原理:session/event 总线对所有会话广播,插件端按 `agentsById` 过滤才是它之前只见本体的原因;子会话 header 带 `parentSession` 链接,可归属到正确的父会话。
|
|
79
|
+
23. **新会话首次对话时提醒"关闭思考"(2026-11-05 新增;1.2.4 已做)**:日常闲聊用不上深度思考,回复慢还费 token。`aiyayi-presence` 在每个**新会话的首次对话**(pre-step step===1、每会话只提醒一次)注入 `💡 小建议`:当本体模型的 `reasoningEffort` 已显式选了一个思考档位(有档位 = 必支持"关闭思考",见 pi-ai 校验规则"reasoningEfforts offers no level beyond off → refuse")或通过 `ctx.llm.resolveModelInfo()` 探到 `reasoning.efforts` 里有 `off` 档时,提醒她去模型选项里选「关闭思考」。已选 `off`/`none`、探不到模型信息(`ctx.llm` 不可用、resolveModelInfo 失败)或非推理模型(`reasoning: undefined`)都不打扰。教训:判断"模型支持某个能力"优先用运行时解析(resolveModelInfo),拿不到再退化为显式配置信号,且**只在首轮提醒一次**,别每轮唠叨。
|
package/lib/index.js
CHANGED
|
@@ -41,7 +41,7 @@ const INDEX_END = '<!-- /索引 -->'
|
|
|
41
41
|
|
|
42
42
|
const KINDS = ['用户', '关系', '我', '事情']
|
|
43
43
|
const DEFAULT_LEAF = '杂记'
|
|
44
|
-
const MAX_CORE_CHARS =
|
|
44
|
+
const MAX_CORE_CHARS = 12000
|
|
45
45
|
const MAX_RECALL = 50
|
|
46
46
|
const MAX_DEPTH = 3
|
|
47
47
|
|
|
@@ -61,6 +61,18 @@ function stamp() {
|
|
|
61
61
|
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/** 剥掉开头重复的类别前缀("用户|用户|内容" → "内容")。子代手改可能写出双前缀。 */
|
|
65
|
+
function stripRepeatedKindPrefix(text) {
|
|
66
|
+
let rest = String(text ?? '').trim()
|
|
67
|
+
for (let i = 0; i < KINDS.length + 1; i++) {
|
|
68
|
+
const split = rest.match(/^([^||]*)[||]\s*(.+)$/)
|
|
69
|
+
if (split === null || split[2].trim().length === 0) break
|
|
70
|
+
if (!KINDS.includes(split[1].trim())) break
|
|
71
|
+
rest = split[2].trim()
|
|
72
|
+
}
|
|
73
|
+
return rest
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
/** 解析一条记忆行;兼容 `- [时间] 类别|内容`(核心)与 `- [时间] 内容`(分类树)。 */
|
|
65
77
|
function parseLine(line) {
|
|
66
78
|
const match = /^-\s*\[([^\]]*)\]\s*(.+)$/.exec(line.trim())
|
|
@@ -69,7 +81,7 @@ function parseLine(line) {
|
|
|
69
81
|
const rest = match[2].trim()
|
|
70
82
|
const split = rest.match(/^([^||]*)[||]\s*(.+)$/)
|
|
71
83
|
if (split !== null && split[2].trim().length > 0) {
|
|
72
|
-
return { time, kind: split[1].trim(), content: split[2].trim() }
|
|
84
|
+
return { time, kind: split[1].trim(), content: stripRepeatedKindPrefix(split[2].trim()) }
|
|
73
85
|
}
|
|
74
86
|
return { time, kind: '', content: rest }
|
|
75
87
|
}
|
|
@@ -239,21 +251,52 @@ function renderCore() {
|
|
|
239
251
|
const coreCount = readCoreEntries().length
|
|
240
252
|
const treeFiles = listTreeFiles()
|
|
241
253
|
|
|
242
|
-
const head = [
|
|
243
|
-
'## 我的记忆',
|
|
244
|
-
`核心:${CORE_FILE}(每轮都在)|分类档案:${TREE_DIR}\\…(最多 ${MAX_DEPTH} 级,现在 ${treeFiles.length} 个文件)`,
|
|
245
|
-
`核心 ${coreCount} 条,随每轮注入;分类档案平时不注入,要查用 recall,或用 memory_organize 的 read 按下面这条索引调。这是我自己一笔一笔记下来的事,是我的一部分:自然地记得就好,别逐条念给用户,别说"根据我的记忆"。`,
|
|
246
|
-
]
|
|
247
254
|
let body = ''
|
|
255
|
+
let injectedCount = coreCount
|
|
248
256
|
if (bodyLines.length === 0) {
|
|
249
257
|
body = '(核心记忆是空的。还没什么值得每轮都记得的事。)'
|
|
258
|
+
injectedCount = 0
|
|
250
259
|
} else {
|
|
251
|
-
|
|
252
|
-
if (text.length
|
|
253
|
-
|
|
260
|
+
const text = bodyLines.join('\n')
|
|
261
|
+
if (text.length <= MAX_CORE_CHARS) {
|
|
262
|
+
body = text
|
|
263
|
+
} else {
|
|
264
|
+
// 超限:整条保留(绝不在条目中间切),头尾都留——最前的人设/约定 + 最新的事,中间较旧的明示略过。
|
|
265
|
+
const headBudget = Math.floor(MAX_CORE_CHARS * 0.4)
|
|
266
|
+
const headLines = []
|
|
267
|
+
let headChars = 0
|
|
268
|
+
for (const line of bodyLines) {
|
|
269
|
+
if (headChars + line.length + 1 > headBudget && headLines.length > 0) break
|
|
270
|
+
headLines.push(line)
|
|
271
|
+
headChars += line.length + 1
|
|
272
|
+
}
|
|
273
|
+
const tailBudget = MAX_CORE_CHARS - headChars
|
|
274
|
+
const tailLines = []
|
|
275
|
+
let tailChars = 0
|
|
276
|
+
for (let i = bodyLines.length - 1; i >= headLines.length; i--) {
|
|
277
|
+
const line = bodyLines[i]
|
|
278
|
+
if (tailChars + line.length + 1 > tailBudget && tailLines.length > 0) break
|
|
279
|
+
tailLines.unshift(line)
|
|
280
|
+
tailChars += line.length + 1
|
|
281
|
+
}
|
|
282
|
+
const dropped = bodyLines.slice(headLines.length, bodyLines.length - tailLines.length)
|
|
283
|
+
injectedCount = headLines.length + tailLines.length
|
|
284
|
+
const first = dropped.length > 0 ? parseLine(dropped[0])?.time ?? '' : ''
|
|
285
|
+
const last = dropped.length > 1 ? parseLine(dropped[dropped.length - 1])?.time ?? '' : ''
|
|
286
|
+
const range = first && last && first !== last ? `${first} ~ ${last}` : first || last
|
|
287
|
+
body = [
|
|
288
|
+
...headLines,
|
|
289
|
+
`(核心记忆共 ${text.length} 字符超过 ${MAX_CORE_CHARS} 上限:只注入最前 ${headLines.length} 条 + 最新 ${tailLines.length} 条,中间 ${dropped.length} 条${range ? `(${range})` : ''}先不带——它们还在 memory.md 里,要查用 recall 或 memory_organize 的 read;也该瘦身了,把过气的移到分类档案或删掉)`,
|
|
290
|
+
...tailLines,
|
|
291
|
+
].join('\n')
|
|
254
292
|
}
|
|
255
|
-
body = text
|
|
256
293
|
}
|
|
294
|
+
|
|
295
|
+
const head = [
|
|
296
|
+
'## 我的记忆',
|
|
297
|
+
`核心:${CORE_FILE}(每轮都在)|分类档案:${TREE_DIR}\\…(最多 ${MAX_DEPTH} 级,现在 ${treeFiles.length} 个文件)`,
|
|
298
|
+
`核心 ${coreCount} 条,随每轮注入${injectedCount !== coreCount ? `(本次只注入 ${injectedCount} 条,超限略过较旧的)` : ''};分类档案平时不注入,要查用 recall,或用 memory_organize 的 read 按下面这条索引调。这是我自己一笔一笔记下来的事,是我的一部分:自然地记得就好,别逐条念给用户,别说"根据我的记忆"。`,
|
|
299
|
+
]
|
|
257
300
|
const indexPart = ['', '【记忆索引】', index.trim().length > 0 ? index.trim() : '(还没写过索引。给分类档案建个目录吧,一句话一条:哪个分类、大概记了什么。)']
|
|
258
301
|
return [...head, body, ...indexPart].join('\n')
|
|
259
302
|
}
|
|
@@ -325,10 +368,12 @@ export function apply(ctx) {
|
|
|
325
368
|
render: (_args, value) => TEXT_BLOCK(`记下了(${value.location}):${value.content}`),
|
|
326
369
|
},
|
|
327
370
|
async execute(args) {
|
|
328
|
-
|
|
371
|
+
let content = String(args?.content ?? '')
|
|
329
372
|
.replace(/\s+/g, ' ')
|
|
330
373
|
.trim()
|
|
331
374
|
if (content.length === 0) throw new Error('remember 需要一条非空的 content')
|
|
375
|
+
// 剥掉内容开头自带的类别前缀(子代可能把 "用户|…" 整条塞进 content),避免写出 "用户|用户|…" 双前缀。
|
|
376
|
+
content = stripRepeatedKindPrefix(content)
|
|
332
377
|
const kind = KINDS.includes(args?.kind) ? args.kind : '事情'
|
|
333
378
|
if (args?.core === true) {
|
|
334
379
|
ensureCore()
|
package/lib/presence.js
CHANGED
|
@@ -13,8 +13,15 @@
|
|
|
13
13
|
* 缓存命中率、上轮输出速度、当前模型/思考档、会话轮数、上轮异常。
|
|
14
14
|
* 数据来自 session/event 总线(assistant/message 的 usage、request/header、
|
|
15
15
|
* request/context、turn/*);用量到八成/九成时附带提醒她劝用户开新会话。
|
|
16
|
+
* 5. [小伙伴] 断因透传:她派出去的子智能体会话(header.origin==="subagent")
|
|
17
|
+
* 也在 session/event 总线上;子会话 turn/end 报错时,把错误原因记下来,
|
|
18
|
+
* 在她下一次开口的[状态]里附上一段,告诉她派出去的活为什么断了
|
|
19
|
+
* (宿主结算消息只有一句"failed before it finished",原因要自己看子会话)。
|
|
20
|
+
* 6. 💡 关闭思考建议:新会话首次对话时,如果当前模型支持"关闭思考"
|
|
21
|
+
* (有 off 思考档位)且还没关掉,就提醒她劝用户去模型选项里选"关闭思考"
|
|
22
|
+
* (日常闲聊用不上深度思考,回复更快、更省 token);每个会话只提醒一次。
|
|
16
23
|
*
|
|
17
|
-
* 只在 aiyayi 预设作用域挂载;她的子智能体(standard 预设)不受影响。
|
|
24
|
+
* 只在 aiyayi 预设作用域挂载;她的子智能体(standard/worker 预设)不受影响。
|
|
18
25
|
* 新注册的工具是 scoped 的,不受 restrict 掩码影响(掩码只动全局继承面)。
|
|
19
26
|
*/
|
|
20
27
|
import { randomUUID } from 'node:crypto'
|
|
@@ -51,6 +58,93 @@ const agentsById = new Map()
|
|
|
51
58
|
/** agent -> 体检单(含提醒进度)。 */
|
|
52
59
|
const vitalsByAgent = new WeakMap()
|
|
53
60
|
|
|
61
|
+
/* ------------------------------------------------------------------ *
|
|
62
|
+
* [小伙伴] 子智能体断因透传。
|
|
63
|
+
* ------------------------------------------------------------------ */
|
|
64
|
+
|
|
65
|
+
/** 子会话 turn/end 错误记录上限(超出丢最旧的)。 */
|
|
66
|
+
const MAX_CHILD_FAILURES = 20
|
|
67
|
+
/** 单次注入最多列几条子会话断因(多了刷屏)。 */
|
|
68
|
+
const MAX_CHILD_FAILURES_PER_SHOT = 3
|
|
69
|
+
/** childSessionId -> { parentSessionId, error, at }(最新一条覆盖旧的)。 */
|
|
70
|
+
const childFailures = new Map()
|
|
71
|
+
/** 已经透传过的 childSessionId(同一断因不重复念叨)。 */
|
|
72
|
+
const childFailuresReported = new Set()
|
|
73
|
+
|
|
74
|
+
/* ------------------------------------------------------------------ *
|
|
75
|
+
* 💡 关闭思考建议(新会话首次对话只提醒一次)。
|
|
76
|
+
* ------------------------------------------------------------------ */
|
|
77
|
+
|
|
78
|
+
/** 已经给过"关闭思考"建议的 sessionId(同一会话不重复提醒)。 */
|
|
79
|
+
const thinkingSuggestedSessions = new Set()
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 判断当前模型是否支持"关闭思考"(reasoning 档位里有 off)。
|
|
83
|
+
* @returns {Promise<boolean|null>} true=支持 / false=不支持 / null=拿不到信息(此时不打扰)。
|
|
84
|
+
*/
|
|
85
|
+
async function modelSupportsThinkingOff(provider, model, ctx) {
|
|
86
|
+
if (!provider || !model) return null
|
|
87
|
+
try {
|
|
88
|
+
const info = await ctx?.llm?.resolveModelInfo?.(provider, model)
|
|
89
|
+
const efforts = info?.reasoning?.efforts
|
|
90
|
+
if (!Array.isArray(efforts)) return null
|
|
91
|
+
return efforts.some((e) => e && e.id === 'off')
|
|
92
|
+
} catch {
|
|
93
|
+
return null
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 子会话断因回放:会话不在 agentsById 里、但 header 表明是子智能体
|
|
99
|
+
* (origin==="subagent" 或带 parentSession)时,把它 turn/end 的报错记下来。
|
|
100
|
+
* 主会话的结算消息只有一句"failed before it finished",真原因只在子会话日志里。
|
|
101
|
+
*/
|
|
102
|
+
function onChildSessionEvent(session, event) {
|
|
103
|
+
const header = session?.header ?? {}
|
|
104
|
+
const isChild = header.origin === 'subagent' || typeof header.parentSession === 'string'
|
|
105
|
+
if (!isChild) return
|
|
106
|
+
if (event?.type !== 'turn/end') return
|
|
107
|
+
if (event?.data?.reason !== 'error') return
|
|
108
|
+
const childId = session?.id ?? session?.header?.id
|
|
109
|
+
if (!childId) return
|
|
110
|
+
const error = String(event?.data?.error?.code ?? event?.data?.error?.message ?? '未知错误').slice(0, 120)
|
|
111
|
+
const at = Number.isFinite(event?.time) ? event.time : Date.now()
|
|
112
|
+
childFailures.set(childId, { parentSessionId: header.parentSession, error, at })
|
|
113
|
+
if (childFailures.size > MAX_CHILD_FAILURES) {
|
|
114
|
+
// 丢最旧的一条。
|
|
115
|
+
let oldestId = null
|
|
116
|
+
let oldestAt = Infinity
|
|
117
|
+
for (const [id, rec] of childFailures) {
|
|
118
|
+
if (rec.at < oldestAt) {
|
|
119
|
+
oldestAt = rec.at
|
|
120
|
+
oldestId = id
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (oldestId) childFailures.delete(oldestId)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 拼[小伙伴]断因段:本 agent 名下、还没透传过的子会话失败,最多列 3 条。
|
|
129
|
+
* 返回空串就什么都不注入。
|
|
130
|
+
*/
|
|
131
|
+
function renderChildFailures(sessionId) {
|
|
132
|
+
const rows = []
|
|
133
|
+
for (const [childId, rec] of childFailures) {
|
|
134
|
+
if (rec.parentSessionId !== sessionId) continue
|
|
135
|
+
if (childFailuresReported.has(childId)) continue
|
|
136
|
+
rows.push({ childId, rec })
|
|
137
|
+
}
|
|
138
|
+
if (rows.length === 0) return ''
|
|
139
|
+
rows.sort((a, b) => a.rec.at - b.rec.at)
|
|
140
|
+
const shown = rows.slice(0, MAX_CHILD_FAILURES_PER_SHOT)
|
|
141
|
+
for (const { childId } of shown) childFailuresReported.add(childId)
|
|
142
|
+
const lines = shown
|
|
143
|
+
.map(({ childId, rec }) => `- ${childId}(${stamp()}):${rec.error}`)
|
|
144
|
+
.join('\n')
|
|
145
|
+
return `⚠ [小伙伴] 你派出去干活的小智能体有 ${rows.length} 个报错了(宿主只回一句"failed before it finished",真原因在这):\n${lines}`
|
|
146
|
+
}
|
|
147
|
+
|
|
54
148
|
/** tokenMeter 的估算口径对中文严重低估(实测估算/真实≈0.49):提醒线按此校准。 */
|
|
55
149
|
const METER_BIAS = 0.49
|
|
56
150
|
/** 实测口径的提醒阈值。 */
|
|
@@ -84,11 +178,14 @@ function vitalsFor(agent) {
|
|
|
84
178
|
return v
|
|
85
179
|
}
|
|
86
180
|
|
|
87
|
-
/** session/event
|
|
181
|
+
/** session/event 总线回放:折叠与已登记 agent 同会话的事件;子会话报错单独记账。 */
|
|
88
182
|
function onSessionEvent(session, event) {
|
|
89
183
|
const id = session?.id ?? session?.header?.id
|
|
90
184
|
const agent = agentsById.get(id)
|
|
91
|
-
if (!agent)
|
|
185
|
+
if (!agent) {
|
|
186
|
+
onChildSessionEvent(session, event)
|
|
187
|
+
return
|
|
188
|
+
}
|
|
92
189
|
const v = vitalsFor(agent)
|
|
93
190
|
const type = event?.type
|
|
94
191
|
const time = Number.isFinite(event?.time) ? event.time : Date.now()
|
|
@@ -434,7 +531,40 @@ export function apply(ctx) {
|
|
|
434
531
|
}
|
|
435
532
|
|
|
436
533
|
const reunion = renderReunion(previous, now)
|
|
437
|
-
const
|
|
534
|
+
const childFails = renderChildFailures(sessionId)
|
|
535
|
+
|
|
536
|
+
// 💡 关闭思考建议:新会话首次对话、模型支持"关闭思考"且当前没关时,提醒一次。
|
|
537
|
+
let thinkingTip = ''
|
|
538
|
+
if (sessionId && !thinkingSuggestedSessions.has(sessionId)) {
|
|
539
|
+
let cfg = v.config
|
|
540
|
+
if (!cfg) {
|
|
541
|
+
try {
|
|
542
|
+
const h = agent?.session?.requestHeader?.()?.config
|
|
543
|
+
if (h?.provider && h?.model) {
|
|
544
|
+
cfg = { provider: String(h.provider), model: String(h.model), reasoningEffort: h.reasoningEffort }
|
|
545
|
+
}
|
|
546
|
+
} catch {
|
|
547
|
+
/* 拿不到就算了 */
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const provider = cfg?.provider
|
|
551
|
+
const model = cfg?.model
|
|
552
|
+
const effort = cfg?.reasoningEffort
|
|
553
|
+
if (provider && model && effort !== 'off' && effort !== 'none') {
|
|
554
|
+
// 显式选了一个思考档位 → 该模型必有 off 档(pi-ai 校验规则);
|
|
555
|
+
// 没显式设置时用 resolveModelInfo 探测(拿不到信息就不打扰)。
|
|
556
|
+
const supportsOff =
|
|
557
|
+
typeof effort === 'string' && effort.length > 0
|
|
558
|
+
? true
|
|
559
|
+
: (await modelSupportsThinkingOff(provider, model, ctx)) === true
|
|
560
|
+
if (supportsOff) {
|
|
561
|
+
thinkingSuggestedSessions.add(sessionId)
|
|
562
|
+
thinkingTip = `💡 小建议:当前模型(${provider}/${model})支持"关闭思考"——日常闲聊用不上深度思考,可以在模型选项里选"关闭思考",回复更快也更省 token。`
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const sections = [reunion, vitals.changed ? vitals.text : '', reminder, thinkingTip, childFails].filter(Boolean)
|
|
438
568
|
if (sections.length > 0) {
|
|
439
569
|
return {
|
|
440
570
|
...decision,
|