Skip to content

飞书:收件箱显示头像、读图把图片直接给模型、渠道能发图 - #22

Merged
NginxL merged 6 commits into
mainfrom
feat-upstream-align-1121
Nov 24, 2026
Merged

NginxL merged 6 commits into
mainfrom
feat-upstream-align-1121

Conversation

@NginxL

@NginxL NginxL commented Nov 24, 2026

Copy link
Copy Markdown
Owner

做了什么

对齐 Persona 上游的三项新能力(只改飞书;微信扩展因为 core 改动跟着升版本,行为不变)。

1. 头像(nwverse/persona#10923、#11627)

  • 收件箱的每一行带上会话头像 InboxThing.avatar:群用群头像,私聊用对方的头像;会话页 thread.page 的 chat.avatar 也带上。
  • 头像值是飞书头像的 https 地址 {file_host}/static-resource/v1/<key>~?image_size=240x240…。这个地址不用登录态就能取到(实测匿名返回 200 和 240×240 的 JPEG),Persona 自己去抓、缓存,不经过扩展的 thread.media。
  • key 的来源:群取 chats.PullChatsByIdsRequest 返回的 avatar.key;私聊如果会话本身没有头像,就用 chatters.PullChattersByIdsRequest 查对方的 avatar.key。
  • core 部分:
    • 后端声明 has_avatars 后,收件箱读到还没有头像、或头像已经超过一天的会话,就在后台去问(每轮最多 30 个,失败的一小时后再问),收件箱的读取不会等它。
    • 问到新的或变了的头像,就发 connector.changed(inbox),让 hub 重新读这些行。
    • 头像存在单独的 avatars 表里,不改旧表,回滚也安全;换账号时一起清掉;后台刷新只写头像,不动会话的其他字段(比如静音)。
  • 微信后端不声明 has_avatars,所以不问、不带头像。

2. 读图时把图片直接给模型(nwverse/persona#8511)

  • initialize 时记下 hub.capabilities。hub 列出 tool_images 时,matefeishu_media 的结果会多带 images,模型直接看到图片,本地文件路径照常给出。
  • 新增 core/openmate_core/modelimages.py,按 hub 的限制处理图片:单张 1 MiB、单边 2000px,每次合计最多 16 张、4 MiB、800 万像素。
    • 不超限的原样发送。
    • 超限的或 GIF/表情先缩成 1568px 的 JPEG:有 Pillow 用 Pillow(LarkAgentX 的环境里有),否则用 macOS 的 sips。
    • 都做不到的就不附上,在文字里说明原因。
  • hub 没列 tool_images 时,只回文字,和以前一样。

3. 渠道发图(nwverse/persona#11986,images_out)

  • 飞书后端实现 send_image,流程照飞书网页端:
    1. 把图片 POST 到 {file_host}/api/image(multipart 字段 image,带会话 cookie),拿到 pan.PutImageResponse.cryptoToken。
    2. 用 PutMessageRequest(type=5,content.cryptoToken)发出。
    3. 消息落在哪里(话题、引用、话题群)完全复用文字的 send()。
    • 上传失败就是 SendRejected,什么都没发。
  • 飞书的渠道声明 images_out: true,channel.send 的 images 跟在文字后面发,落在文字所在的位置:
    • 文字和每张图片各自有一条发送记录,同一个 ref 重发时只补发没发出去的部分。
    • 被拒的图片可以重试;结果不确定的不再重发。
    • 不是 PNG/JPEG 的图片丢掉。
  • 图片在渠道会话里的回显(IMAGE 类型,可能比消息 id 先到)先登记为“正在发的图片”,不会被当成用户说的话转交给 Persona。
  • /agent 回复带的图片也改成跟文字落在同一处(只在后端声明 image_threads 时)。微信不声明,仍然发到会话里。

核实:只回 /agent 请求的守卫(larkx 0.2.1,nwverse/persona-extensions#533)

  • OpenMate 的 channel.send 带 reply_to 时,被回复的消息必须是从渠道会话转交过的行(channel_msgs.dir == "in"),否则就是 cannot_send。
  • 补了一条回归测试 test_an_answer_only_to_a_line_handed_over_not_to_any_line_of_the_users。回复以下几类消息都会被拒:渠道之前发出的回答、工具发出去的回显、别的 AI 写的行。

怎么验证的

  • bash scripts/test.sh 全部通过;另外用 OPENMATE_LARKX_PYTHON 指向真实的 LarkAgentX,冒烟测试也通过:用真 protobuf 核对了 IMAGE 包、上传回包里的长 token、头像地址。
  • 新测试:
    • tests/test_avatars.py
    • tests/test_modelimages.py
    • tests/test_feishu_media.py(3 条)
    • tests/test_channel.py(PicturesOutTest 5 条,守卫 1 条)
    • tests/test_agent_image.py(1 条)
    • extensions/openmate-feishu/tests/test_larkagentx.py(PictureTest 4 条)
  • 在旧代码上跑这些新测试,确认会失败。
  • 线上实测见 PR 评论(升级到新版本后补)。

没做什么

  • 微信不发图、不带头像,行为不变。
  • 上游的第 3、4 项(@自己唤起、真 @人)已经在 openmate-feishu 0.11.41 / 0.11.43 上线,这次不做。
  • 群里每个发言人的头像(会话页里逐条消息的 sender avatar)不做,只给会话本身的头像。

🤖 Generated with Claude Code

NginxL and others added 6 commits November 24, 2026 23:16
… the channel sends pictures

- Inbox rows and conversation pages carry the chat's picture (InboxThing.avatar, nwverse/persona#10923): a
  group's own, a direct chat's other person's, as Feishu's https address by its key. The core asks a backend
  with has_avatars in the background, once a day per chat, and tells the Inbox when one changed. Kept in a table
  of its own; another account's sign-in forgets them. WeChat's backend says none: nothing asked, rows as before.
- matefeishu_media hands the pictures themselves to the model when the hub lists tool_images
  (nwverse/persona#8511), within the hub's limits (modelimages: drawn again smaller with Pillow or sips, else
  left out and said so).
- The Feishu channel declares images_out (nwverse/persona#11986): channel.send's pictures follow the text, where
  it was asked, each once. The backend uploads a picture as the web client does (the file host's /api/image,
  its cryptoToken) and sends it where a text would go; an /agent reply's picture goes where its text went.
  A picture's echo in the channel chat is never the user's line.
- The guard that an answer goes only under a line handed over (larkx 0.2.1, nwverse/persona-extensions#533)
  holds; a regression test covers the cases of #531.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a ref only to its chat, pictures checked whole

- send_image posts only with the session that uploaded the picture (another account's sign-in meanwhile:
  nothing sent); pictures take to_chat as their text does.
- channel.send: a picture's journal key is a namespace of its own (no text ref can share it); what is left of a
  ref goes only to the chat its first part went to; a replay answers the same id; pictures that are all no
  PNG or JPEG with no text are invalid_params; no answer under a line Persona refused.
- A picture's echo is marked only where the channel sends pictures (WeChat's: never), and only while it is sent.
- matefeishu_media gives the bytes it downloaded (never read back from the file), and nothing fetched while
  another account signed in.
- modelimages: with Pillow, a picture goes as it is only when it decodes whole, has one frame and no EXIF turn;
  a huge one is not drawn again; one drawn again stays upright.
- Avatars: a record without the field (or a direct chat whose other person is not known) says nothing, so a
  known picture stays; a list's row asks nothing of the service.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…once, WeChat's echo ids as before

- An /agent reply's picture is keyed by the request the reply names, as its text is: asked again after it went
  under a follow-up, it is not sent a second time under the first request.
- A channel picture's journal key is its bytes (Persona may give a ref's pictures again in another order); in a
  group showing topics, the pictures of a push go into the topic its first part opened.
- A picture's echo id is written as before on every platform; only the standing-in while it is sent is the
  channel's with images_out, and an outcome not known keeps it standing.
- The reply guard is as it was (WeChat unchanged).
- The Feishu session is taken before the file is read; matefeishu_media writes nothing for an account signed
  out meanwhile; a page opened asks for its chat's picture; a direct chat kept from a list asks for its person's
  picture on its own read; a picture too big for Pillow is not handed to sips either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e is two, pictures checked to their end

- An /agent reply's picture is keyed by its reply (the request it names and its text) and its bytes: the same
  reply asked again never sends it twice, another reply's picture is its own.
- A channel.send's pictures are keyed by their bytes and their turn among equal ones (the same picture twice is
  sent twice); a picture whose outcome is not known stands for its echo two minutes, not ten.
- No picture goes, and matefeishu_media fetches nothing, while a sign-in is being taken in.
- The core asks a chat's picture of the service now (chat_picture), never of a row kept from a list.
- modelimages: a PNG or JPEG cut before its end is not sent as it is; Pillow's refusal of a huge picture keeps it
  from sips too; a 16-bit picture drawn again keeps its levels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t as before)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he Inbox, pictures straight to the model, the Feishu channel sends pictures

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NginxL
NginxL merged commit ba84cf1 into main Nov 24, 2026
@NginxL

NginxL commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

线上实测(openmate-feishu 0.11.44 / openmate-wechat 0.1.42)

  • hub 在 2026-11-25 02:48 自动升级:manager 日志 upgraded itself from 0.11.43 to 0.11.44、from 0.1.41 to 0.1.42;运行中的安装目录是 openmate-feishu/0.11.44/、openmate-wechat/0.1.42/。升级后日志里飞书扩展没有 error / traceback。
  • 头像:扩展库 avatars 表有 113 行,全部是 https://…/static-resource/v1/… 地址;Persona App 收件箱里飞书会话的行已经显示头像(用户确认)。
  • 读图直接给模型:对一张 1080×2348 的 JPEG(单边超过 2000px)调 matefeishu_media,结果里带了缩小后的图片,模型直接看到了内容;对一张 1076×330 的 PNG 原样附上。
  • 渠道发图:在话题模式测试群里由用户本人发 /agent 用 Python 画一张简单的三步流程图…连图一起回复给我。回复的文字和 PNG(1076×330)都落在这条 /agent 开的话题里(两条消息的 话题= 都是请求的根消息);图片的回显没有被当成用户的话转给 Persona。
  • 没有实测:没有 reply_to 的 channel.send 推送发图(这次走的是 /agent 回复带图的路径,只靠单测覆盖);@ 真人由后续的实际发送顺带实测。

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant