kicer
360169a489
仅在debug模式下才显示清空消息按钮
2026-09-05 10:26:49 +08:00
kicer
49b501da1d
调用出错的工具需要显示红色
2026-09-05 10:24:46 +08:00
kicer
72ec733a92
修改错误工具调用时候的提示词
2026-09-05 10:08:16 +08:00
kicer
734039d917
日志模块拆分 category 参数:log.xxx(category, ...args) 输出 timestamp [level] [category]
...
- log.js 签名改为 log.xxx(category, ...args);头三段为时间戳 [level] [category],后续参数(含 Error/对象)透传 console 走 util.format
- 所有调用点迁移:从 log.info('[msg] xxx') → log.info('msg', 'xxx');server 启动行无前缀,统一归入 startup
- 实测输出:2026-09-05 09:27:12.068 [debug] [sse] task-20260904-012 event: ping
2026-09-05 09:27:23 +08:00
kicer
3538526c41
工具/任务执行卡片支持删除:单删 tool 回执同步摘除父 assistant 的对应调用
...
- deleteToolMessage:删工具回执行后,把该 tool_call 从父 assistant 的 tool_calls 里摘除;纯工具轮(无文本)且无剩余调用则父行整删,避免「有调用无结果」被上游拒收
- tool_result 事件先落库再广播,带 msg_id;前端工具卡时间行(复制旁)挂 × 删除按钮,历史与实时均可删
- 删除走统一 .act-del 委托:confirm → DELETE 接口 → 重拉详情重建消息区
2026-09-05 09:10:15 +08:00
kicer
ad6ed51fd4
新增删除单条消息:DELETE /api/sessions/:id/messages/:messageId + 消息行删除按钮
...
- engine.deleteMessage:assistant 的 tool_calls 轮连带删除其 tool 回执,防孤儿 tool 行破坏协议;tool 行拒绝单独删
- 删除后库行消失,下次发给模型的历史自然不含该条(buildMessages 只看库)
- index.html:复制按钮后加删除按钮(× 图标),点击 confirm 后调接口并重拉详情重建消息区;发送成功的实时用户消息也带删除按钮
- style.css:删除按钮悬停变红、请求中禁用态
2026-09-05 09:00:30 +08:00
kicer
848937c156
AI 坏 tool call 标记 errAck:入库留痕但移出模型上下文,防模仿死循环
...
- messages 新增 type 列,参数非法(JSON 坏/缺必填)的 assistant 轮标 errAck
- buildMessages 跳过 errAck 行及其关联 tool 回执,改发一条 user 错误提示引导重新生成
- tool_calls 落库时补全缺失 id,保证与 tool 回执配对一致
- safeParse 升级为 checkToolArgs:区分非法 JSON 与缺必填,执行前统一挡下
2026-09-05 08:55:31 +08:00
kicer
9e583afaf5
修复 callModel 没透传 onMeta/onBadData 导致 SSE meta 行被丢弃
...
callModel 内部 await forEachSSEData(res, evt => {...}) 只传了 1 个参数,
opts.onMeta / opts.onBadData 永远没被接通到 forEachSSEData。结果是
forEachSSEData 收到的非 data 行(event:/id:/retry:/注释)全部被静默丢弃,
onMeta 回调从未触发。这是 893281c commit 那次'应该已经修了'的回归 bug,
由于之前的烟雾测试只覆盖了 onEvent / onText / onBadEvent,没发现 meta 链
完全断的事实。
这次用含 event:/id:/注释行的 SSE 序列烟雾测试,验证 onMeta 收到所有行。
engine.js 的 handleSseMeta 解析逻辑(a349942)此前一直正确,只是链路没
接通,这次修复后能正常按 6 条规则分发。
2026-09-05 07:29:12 +08:00
kicer
fcb69112ac
区分 usage 帧与错误帧:choices=[] 含 usage 时不再误报 onBadEvent
...
OpenAI 兼容协议在 stream_options.include_usage=true 时,最后一帧只发
usage 不带 choices(choices: [])。callModel 之前把这种帧当成错误帧调
onBadEvent,导致日志里 '[sse] 上游错误帧' 后面跟的是 token 统计 json,
误导排查方向。
判断条件改为 'choices=[] 但含 usage → 静默 return';只有 '无 usage 也无
choices' 的帧(如之前的 event: error 帧)才走 onBadEvent。
usage 提取移到 if (evt.usage) usage = evt.usage; 在 if (!choice) 守卫之前
已有的赋值语句,新逻辑在 !choice 块内复用该结果。
2026-09-05 07:25:20 +08:00
kicer
a3499429ec
SSE meta 解析规范化:handleSseMeta 按首个冒号切 k,v 分发
...
旧 onMeta 把非 data 行(event:/id:/retry:/注释/未知)原样逐行 debug,
调试时 id: 这种信息价值低的字段刷屏严重(一次对话几十条 id: 行)。
抽出 makeSseMetaHandler 工厂函数构造 handleSseMeta 回调:
1. trim 去掉所有空格
2. 按第一个 ':' 切 k, v(用 indexOf 不 split 避免值含 ':' 被破坏)
3. id → last_id = v (静默,状态保留)
4. retry → retry_time = v (静默,状态保留)
5. event → log.debug event 名 (如 event: error)
6a. k='' && v='ping' → 当作 event=ping 处理
6b. k='' 其他 → 注释行 debug
6c. 其它 → 未知字段 debug
last_id / retry_time 暂不消费,作为 state 保留供后续关联。
llm.js 完全不动(meta 解析在 engine.js 闭包内)。
2026-09-05 07:18:22 +08:00
kicer
0d5d74bcf6
SSE 错误帧识别:data 解析成功但无 choices 时调 onBadEvent
...
上游 DeepSeek 代理在某些情况下会以 SSE event: error 帧返回错误响应(如
'Assistant tool call function.arguments must be valid JSON.'),data 行本身
JSON.parse 没问题但 evt.choices 缺失。旧逻辑走 if (!choice) return 沉默跳过,
结果就是 'AI 回复 0 字' 但没有任何信号告诉调用方上游其实报了错。
callModel 在 !choice 之前调 opts.onBadEvent(evt) 把整个 evt 透传给调用方,
streamAssistant 挂上 warn 级日志把错误帧 dump 出来。
调试样例(之前看到的):
[sse] task-... 上游错误帧:{"error":{"message":"Assistant tool call
function.arguments must be valid JSON.",...},"id":0}
llm.js 仅改 1 处(callModel 回调体内 if (!choice) 块),其余调试信号不动。
2026-09-05 07:12:54 +08:00
kicer
893281c96c
SSE 本轮汇总:callModel 统计 data 帧数,streamAssistant 打 info 日志
...
定位 'AI 回复 0 字' 时单凭 finish_reason 和 aborted 区分不出 '上游没发任何
data' 和 '上游发了帧但 content 为空'。callModel 在 forEachSSEData 回调首行
累加 sseFrames 并写进返回值(不影响其他字段),streamAssistant 拿到 result
后打印一行 info:
[sse] <sessionId> 本轮汇总:帧 N,finish=<reason>,aborted=<bool>
判读:
- 帧=0 且 aborted=false:上游未发任何 data(流异常/上游 200 但 body 空)
- 帧>0 且 finish=stop 且 content 空:上游发了帧但 content 为空(罕见,模型主动空回)
- 帧>0 且 finish=length:上游被截断,需要重试或调大 max_tokens
- aborted=true:用户在流中途取消
llm.js 保持纯 IO 职责,只多返回一个计数字段,不引入 logger。
2026-09-05 06:09:28 +08:00
kicer
510eb2fa3e
SSE 调试信号:forEachSSEData 增加 onMeta/onBadData 可选回调
...
llm.js 保持纯 IO 职责:forEachSSEData 把非 data 行(event:/id:/retry:/注释)
逐行通过可选回调 onMeta 透出,把 data 行 JSON.parse 失败时通过可选回调
onBadData 透出原始字符串。流式行为不变,content/tool_calls 累加逻辑零改动。
engine.js 的 streamAssistant 在 callModel 的 options 里挂上:
- onMeta → log.debug('[sse] ...'),meta 是时间性调试信息
- onBadData → log.warn('[sse] 坏帧...'),坏帧是真异常不该静默
同时移除 saveMessage 里的 'AI 回复全文/用户消息全文' debug 块(tool_calls
JSON 刷屏、含图消息会带大段 base64 没必要),改由更底层的 SSE 调试信号
替代,方便定位 'AI 回复 0 字' 这类上游响应异常。
2026-09-05 06:04:42 +08:00
kicer
ef7aae97b7
fix system prompt
2026-09-04 22:35:52 +08:00
kicer
dab3732b50
fix tools name
2026-09-04 22:31:25 +08:00
kicer
88120d61c1
video-gen: drop duration param, restrict image_url to a single URL
...
The cogvideox-flash API does not accept a duration field — passing
one gets rejected upstream. Remove DEFAULT_DURATION, the
X-Video-Gen-Duration header parser, and the field forwarded to
Zhipu, both in code and README.
image_url was documented as accepting up to 2 URLs for first/last
frame, but the upstream schema only accepts a single string. Tighten
the zod schema to z.string().url().optional() and update README /
FAQ to make the single-URL constraint explicit.
2026-09-04 22:28:39 +08:00
kicer
1c675b2fc2
add PWA mode
2026-09-04 21:51:04 +08:00
kicer
e489fc68eb
system-prompt: 更新能力边界,把生成式媒体从 out-of-scope 移到 in-scope
...
之前 prompt 把"文生图/AI 绘画/AI 视频生成"明确列为 out of scope 并要求 AI
把这类请求直接推给第三方工具(豆包/即梦等)。但当前环境已经接入
generate_image 和 generate_video 两个 MCP 服务,这些能力实际上是 in scope
的。原 prompt 会让 AI 把可以做的事推到外面去。
本次调整:
- in scope 增加一条:"通过当前会话可用的 MCP 工具做生成式媒体",
并明确工具自己的 description 是参数/限制的唯一可信来源。
- out of scope 收窄到当前 MCP 实际未覆盖的能力(音频/3D/风格化/
换脸/抠图等——具体哪条要看 tools/list)。这样以后再加/减 MCP,
prompt 不用动。
- "如何应对 out of scope" 的措辞调整:仍然推荐第三方作为兜底,
但语气从"主动推荐"改成"如果合适就提一句"。
不写死任何 MCP 工具名,prompt 保持配置无关——前缀缓存仍然按
system-prompt.txt 整体对齐。
2026-09-04 21:38:29 +08:00
kicer
daaa01878d
video-gen: auto-expire uploaded files older than UPLOAD_TTL_HOURS
...
Adds cleanupUploads(): on startup and every hour, deletes files in
UPLOAD_DIR whose mtime is older than UPLOAD_TTL_HOURS (default 24).
Uses fs.promises + parallel stat/unlink, unref() the interval so it
never blocks process shutdown, ignore ENOENT races silently.
Storage is multer diskStorage so memory never holds a full file body,
but disk could grow without bound if uploads pile up unused. This
bounds the disk footprint without requiring a manual cron, and keeps
the 'temp upload' semantics: the URL is meant to be consumed within
the same session anyway.
README: document UPLOAD_TTL_HOURS / UPLOAD_DIR env vars, add design
note for the cleanup loop.
2026-09-04 21:34:24 +08:00
kicer
e378ad001f
video-gen: add /upload endpoint for local image upload
...
Adds POST /upload (multer diskStorage, max 8MB, image/* only) returning
a public URL under /uploads/* that can be passed directly to
generate_video.image_url. Uploads live in container temp storage and
are discarded on restart (no persistence, no auth).
generate_video tool description is now built at startup with the real
upload URL baked in (resolved from PUBLIC_BASE_URL env, falls back to
http://localhost :<port>) so the AI sees an exact curl command and
doesn't have to guess the host.
docker-compose: set PUBLIC_BASE_URL=https://video-gen.ai.foresh.com
README: new upload section, reverse-proxy note, FAQ entries
2026-09-04 20:58:51 +08:00
kicer
8ac62bedd9
mcp: 兼容 session 过期,自动重新握手
...
某些 MCP 服务在长时间空闲后会主动让旧 session 失效,下次非 initialize
请求会返回 400 并提示 missing/invalid Mcp-Session-Id。之前 mcp.js 一直
复用启动时缓存的 server.sessionId,会持续报错。
本次在 rpc() 出口处加一个最小补偿:仅当 method 不是 initialize、状态码
是 400、错误体含 'session' 时,清掉旧 id、重新跑 initialize +
notifications/initialized、再重试一次原请求。initialize 调用走当前函数
的 method !== 'initialize' 分支天然不会带旧 header,递归链路自动终止
在 initialize 那一层(不会无限循环)。
工具表(toolDefs / toolIndex)保持 init() 时的快照不变——session 重连
只换 id,不动工具表,避免工具集差异导致调用方混淆。重连失败或重连后
仍然 400 时原样向上抛错,由调用方决定如何应对。
2026-09-04 20:50:59 +08:00
kicer
cb780cfb0b
本地化 marked 渲染器:md 预览不再依赖 CDN,离线/内网环境也能正常渲染
2026-09-04 16:56:18 +08:00
kicer
710200605b
add video-gen support
2026-09-04 16:19:34 +08:00
kicer
47f7172a32
忽略技能目录下的 __pycache__
2026-09-04 16:00:45 +08:00
kicer
e3972fb25a
md2pdf技能支持Markdown表格渲染
2026-09-04 15:59:23 +08:00
kicer
e150e9c6c9
md2pdf添加图片功能支持
2026-09-04 15:16:10 +08:00
kicer
ee2fc36ffd
任务文件窗口按时间倒序排列
2026-09-04 15:04:08 +08:00
kicer
66bb97fcdf
修复批量下载手机端文件名错乱/套壳 App 无反应:放弃 blob 方案,先批量拿 token 再用服务器直链触发
...
- blob: URL 手机浏览器不认下载名(变编号/.bin),WebView 套壳不处理 blob 下载请求
- 回到与单文件下载一致的直链路径:文件名跟服务端 Content-Disposition / download-name 兜底
- 所有 download-token 先全部拿到再逐个 <a> 触发,规避首个导航打断后续 fetch(原第 2 个失败的根因)
- 逐个触发间隔 350ms,避免移动端拦截连续多次下载
2026-09-04 14:27:05 +08:00
kicer
1023ffa8fd
修复 MCP 工具调用 400:image-gen 等严格服务要求 initialize 后的请求带 Mcp-Session-Id。
...
init() 阶段先发 initialize 拿 session id 并缓存到 server.sessionId;
rpc() 在 method !== 'initialize' 且 server.sessionId 存在时自动加上 Mcp-Session-Id 头;
老服务(无 initialize 或不返回 session id)保持原行为不受影响
2026-09-04 13:17:23 +08:00
kicer
44da1dcf08
翻译成简单英语方便AI理解
2026-09-04 13:04:25 +08:00
kicer
c1eac96db1
i18n(image-gen): translate remaining AI-facing response text to English
...
Translate the four remaining content.text strings in the tool callback:
- 'no URL returned' error
- success summary (Model / Prompt / Image N)
- generation failure error
- error detail label
Style follows the short-sentence convention from baa04d9 (no extra
explanatory notes added).
2026-09-04 12:55:42 +08:00
kicer
bc53ff3129
i18n(image-gen): translate tool description & token-error text to English
...
Translate the four strings introduced in baa04d9 (\u8c03\u6574\u90e8\u5206\u63d0\u793a\u8bcd) to clear English.
Other Chinese strings in this file (success summary, image-N labels, failure detail)
were not changed in that commit and are intentionally left untouched here.
2026-09-04 12:54:33 +08:00
kicer
2455778f4a
Revert "i18n(image-gen): translate AI-facing tool response text to English"
...
This reverts commit 06a9ae7151d47e0486abad1f11353164db377d45.
2026-09-04 12:54:00 +08:00
kicer
a29ffd9aa5
i18n(image-gen): translate AI-facing tool response text to English
...
The tool result content is consumed by AI agents (Claude/Cursor/...).
Converted four user-facing strings to clear English:
- Missing-token error message
- No-URL-in-response error message
- Success summary (added expiry note for AI to act on)
- Generation-failure error message
Code comments and tool description/describes are untouched in this commit.
2026-09-04 12:52:10 +08:00
kicer
594650510b
调整部分提示词
2026-09-04 12:50:30 +08:00
kicer
eba3a3c7ff
fix(image-gen): 从 extra.requestInfo.headers 读取 token & model(修正字段路径)
...
之前 pickToken/pickModel 用的 'extra?.requestInfo?.req?.headers' 多写了一层 '.req',
SDK 实际只有 extra.requestInfo.headers(参见 webStandardStreamableHttp.js buildRequestInfo),
导致 token/model 始终为 null,AI 调用时实际走默认 model 且若未额外修过 token 则报 401。
本提交:
- 取 header 改用 extra.requestInfo.headers
- pickToken/pickModel 签名改为接收 headers 对象(去掉对 req 的依赖)
- Model 仍只在 tools/call 阶段从 header 读取,不存 session
- Model 优先级:header > DEFAULT_MODEL(已删 schema 里的 model 字段,AI 无法误传)
- README 同步更新鉴权与 model 章节
2026-09-04 12:43:23 +08:00
kicer
76aa1aa604
feat(image-gen): 移除 header 传 model 的逻辑,仅保留工具参数 → 兜底默认
...
- 删除 extractModelFromHeaders / X-Image-Gen-Model 等 header 解析路径
- model 优先级简化为单链:arguments.model → DEFAULT_MODEL (CogView-3-Flash)
- 新增 README.md,覆盖启动、客户端配置、工具用法、curl 调试、FAQ
2026-09-04 12:08:54 +08:00
kicer
f7b4e17cfe
add model参数
2026-09-04 11:17:46 +08:00
kicer
b2c683d455
add image-gen server
2026-09-04 11:13:03 +08:00
kicer
e387293f00
init mcp server
2026-09-04 11:11:32 +08:00
kicer
82a0604846
fix css
2026-09-04 10:04:38 +08:00
kicer
2d2134f437
修复底部全选复选框不显示:footer 的勾选 span 缺少 file-check class,导致 inline 元素 width/height/::after 全部失效
2026-09-04 09:59:42 +08:00
kicer
90de9ab086
任务文件全选复选框挪到 footer 左侧:去大圆按钮,改为方角 22×22 复选框,与行内 .file-check 风格统一但可区分
2026-09-04 09:57:23 +08:00
kicer
7e570012d8
任务文件面板加全选/取消全选:header 右侧增加三态切换按钮(+/−/√),与底部批量操作联动
2026-09-04 09:51:52 +08:00
kicer
cedd236dd8
修复任务文件批量下载:改用 fetch+blob 触发下载,避免 window.location.href 在多文件场景被浏览器去重/丢 cookie
2026-09-04 09:50:30 +08:00
kicer
6c4eca89dc
更改文件浏览器样式
2026-09-04 09:44:01 +08:00
kicer
32a23fa5ab
上传百分比改走正常文档流:进度条改为[轨道|百分比]横排,根治文字被裁
2026-09-04 08:53:13 +08:00
kicer
bc903fc885
修复上传进度百分比显示不全:进度轨道去掉 overflow:hidden(填充条自带圆角,无需裁剪)
2026-09-04 08:48:57 +08:00
kicer
98a98198d3
账户页去掉多余的 /api/system/status 请求:用 /api/me 的 404 判定未启用认证
2026-09-04 08:36:28 +08:00
kicer
6e785e826e
登录成功改用 location.replace 跳转并用 pageshow 兜底:历史不留 /login,杜绝侧滑 bfcache 复活登录页
2026-09-04 07:49:33 +08:00