feat: 支持 agent 发送图片给用户 (feishu_send_image)#261
Merged
Conversation
新增 FeishuClient.uploadImage / sendImage / replyImageInThread:
- uploadImage 调 im.image.create 上传图片拿 image_key
(注意该接口直接返回已解包的 { image_key },非 { code,msg,data })
- sendImage 以 msg_type:'image' 发送到会话
- replyImageInThread 以 reply_in_thread 回复到话题内
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
让 agent 把工作区里的本地图片(截图/生成图)发回当前会话。 - send-image.ts:校验路径存在/大小≤10MB/magic bytes 为图片, 上传后按 threadReplyMsgId 路由到话题或会话 - index.ts:createFeishuToolsMcpServer 增加 threadReplyMsgId 参数, 与 main-chat 同样 gate on chatId 注册 - executor.ts:透传 input.threadRootMessageId 作为话题落点 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- send-image.test.ts:覆盖成功(会话/话题)、文件不存在/过大/为空、 非图片格式、上传失败、发送失败、异常、jpg 识别等 11 个用例 - index.test.ts:补 send-image mock,校验 chatId 存在时注册(12 个工具)、 缺省时不注册 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
补齐 main-chat/send-image/message-file/message-image 四个非子开关工具, 记录图片发送落点的设计决策与 im.image.create 的解包差异。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Claude finished @lishuceo's task in 2m 46s —— View job Code Review: feishu_send_image
✅ Approved — clean, well-scoped, well-testedThis is a solid implementation of 方案 A. I verified the key risk areas and found no blocking issues. Correctness verified:
Non-blocking observations (no change required):
Note: I couldn't execute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
此前飞书集成只能读用户发来的图(
feishu_download_message_image),不能发图给用户——client.ts的发送方法只有 text/post/interactive,没有图片上传/发送能力。本 PR 实现方案 A(独立
msg_type:'image'消息),让 agent 把工作区里生成的图片(截图、图表、渲染结果)发回当前会话。改动
src/feishu/client.ts— 三个新方法:uploadImage(buf|stream)→ 调im.image.create拿image_key(该接口返回已解包的{ image_key },与其它 message 接口的{code,msg,data}不同)sendImage(chatId, imageKey)→msg_type:'image'发到会话replyImageInThread(messageId, imageKey)→reply_in_thread回复到话题src/feishu/tools/send-image.ts(新)—feishu_send_imageMCP 工具:file_path(本地绝对路径)isFile、大小 ≤ 10MB、非空、magic bytes 为图片(png/jpg/gif/webp/bmp)threadReplyMsgId路由:话题内回复到话题,否则发到会话接线 —
tools/index.ts增加threadReplyMsgId参数并 gate onchatId注册;executor.ts透传ExecuteInput.threadRootMessageId。测试
send-image.test.ts:11 个用例(成功会话/话题、文件不存在/过大/为空、非图片、上传失败、发送失败、异常、jpg 识别)index.test.ts:更新工具计数(chatId 存在=12,缺省不注册 send-image)npm run typecheck通过;npx vitest run全量 1696 通过(唯一失败的memory/quality.test.ts为数据依赖的检索质量用例,基线同样失败,与本 PR 无关)范围说明
方案 B(在 post/card 里图文混排)作为后续增强,本 PR 不含。
🤖 Generated with Claude Code