picoclaw/pkg
Guoguo cb1e1a3595
fix(feishu): fix image download with API fallback and post image support (#2708)
* fix(feishu): fix image download with API fallback and post image support

- Add Image.Get API fallback when MessageResource.Get fails (different
  permission scope: im:resource vs im:message:readonly)
- Extract and download images from post (rich text) messages
- Extract images from interactive card messages
- Deduplicate post image keys across locales
- Add comprehensive tests for new helpers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(media): add image path tags alongside base64 for LLM file access

Images are still base64-encoded into msg.Media for multimodal LLMs,
but now also get [image:path] tags injected into message content so
the LLM knows the local file path for save/forward operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor(media): only auto-inject images for tool results, not user messages

Channel-received images (role=user) now get path tags only, letting
the LLM decide whether to view via load_image or just operate on
the file. Tool result images (role=tool, e.g. load_image) are
base64-encoded into a synthetic user message appended after the tool
message, since many LLM APIs don't support image_url in tool messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(media): preserve tool-message ordering for multi-tool-call scenarios

Move synthetic user message (carrying base64 tool images) to after the
entire contiguous tool-message block instead of immediately after each
tool message. This preserves the assistant→tool→tool ordering required
by OpenAI-compatible APIs.

Also fix load_image to use generic [image: photo] placeholder so
injectPathTags can properly replace it with the actual path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(test): update load_image test for [image: photo] placeholder

The test was checking ForLLM for the media:// ref, but load_image now
emits the generic [image: photo] placeholder instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(media): match all channel image placeholders in injectPathTags

Different channels emit different placeholder formats — Telegram/Feishu
use [image: photo], WeCom/WeChat/Line use bare [image], QQ/Discord use
[image: <filename>]. The previous string-match code only handled
[image: photo], so for the other channels the path tag was appended as
a duplicate, producing content like "[image] [image:/path]".

Switch to per-type regex that matches all generic placeholder shapes
while leaving path tags ([image:/path]) untouched. Also fixes the same
issue for [audio], [video], [file] tags. Added test coverage for the
various placeholder shapes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(media): skip path tag append for JSON content (Feishu cards/posts)

When content is structured JSON (interactive cards, post messages),
injectPathTags now skips the fallback append — only placeholder
replacement is attempted. This prevents corrupting JSON payloads
like {"schema":"2.0",...} with appended [image:/path] tags.

Adds looksLikeJSON() helper and three test cases covering JSON
objects, arrays, and an end-to-end resolveMediaRefs scenario with
Feishu card content.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(media): prepend path tags for JSON content, narrow looksLikeJSON

Two fixes from code review:

1. looksLikeJSON now only checks for '{' prefix (not '['), avoiding
   false positives on regular text like "[update] see attached".

2. For JSON content (Feishu cards/posts), path tags are prepended
   before the JSON instead of being silently dropped. This ensures
   the LLM can discover attached images via the path tag while the
   JSON payload stays valid for downstream parsing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-30 11:08:00 +08:00
..
agent fix(feishu): fix image download with API fallback and post image support (#2708) 2026-04-30 11:08:00 +08:00
audio refactor: support explicit provider field in model list entries (#2609) 2026-04-22 11:28:47 +08:00
auth fix(auth): canonicalize Google Antigravity provider and enhance credential management (#2599) 2026-04-21 16:28:29 +08:00
bus feat(agent): add context usage ring indicator and /context command (#2537) 2026-04-21 16:30:02 +08:00
channels fix(feishu): fix image download with API fallback and post image support (#2708) 2026-04-30 11:08:00 +08:00
commands fix lint 2026-04-21 11:01:04 +02:00
config feat(config): wire serial tool into runtime and dashboard 2026-04-28 12:56:27 +08:00
constants refactor: replace bool map with set-style map for internal channels (#472) 2026-02-19 11:48:17 +01:00
credential refactor config and security to simplified the structure (#2068) 2026-03-28 00:03:34 +08:00
cron refactor(cron): remove deliver and type params, unify agent execution path (#2147) 2026-03-29 22:52:34 +08:00
devices refactor(runtime): drop non-session legacy context compatibility 2026-04-01 20:56:48 +08:00
fileutil Merge pull request #1829 from perhapzz/test/add-fileutil-health-tests 2026-03-26 10:42:13 +01:00
gateway refactor(web): secure Pico websocket access behind launcher auth 2026-04-20 10:11:03 +08:00
health fix(host): modernize default host selection order 2026-04-14 14:03:23 +08:00
heartbeat refactor(runtime): drop non-session legacy context compatibility 2026-04-01 20:56:48 +08:00
identity fix(identity): support negative integers in isNumeric for Telegram group IDs 2026-03-21 17:09:02 +07:00
isolation fix: treat PID=1 as stale in PID file singleton check, fix govet shadow, add .gitattributes (#2642) 2026-04-24 15:26:34 +08:00
logger unify all panic event to panic log file (#2250) 2026-04-01 23:26:49 +08:00
mcp fix(mcp): retry tool calls on lost HTTP sessions and fix client lifecycle 2026-04-24 20:20:57 +02:00
media Fix 1886 media cleanup policy (#1887) 2026-03-23 12:13:59 +08:00
memory fix(message): ignore transient assistant thoughts in message count and history truncation 2026-04-25 12:26:28 +08:00
migrate refactor(config): make config.Channel to multiple instance support 2026-04-13 22:21:21 +08:00
netbind fix(web): address latest Copilot review points 2026-04-14 23:39:59 +08:00
pid fix: treat PID=1 as stale in PID file singleton check, fix govet shadow, add .gitattributes (#2642) 2026-04-24 15:26:34 +08:00
providers Merge pull request #2657 from lc6464/fix-deepseek-v4-thinking-history 2026-04-25 15:08:48 +08:00
routing feat(routing): add ordered dispatch rules 2026-04-01 22:13:04 +08:00
seahorse test(seahorse): add TestTriggerMigration for old-DB trigger upgrade path 2026-04-13 11:37:50 +08:00
session fix(reasoning): persist canonical history for DeepSeek and web chat 2026-04-24 21:45:41 +08:00
skills refactor skills registries and add GitHub-backed skill discovery (#2442) 2026-04-14 15:14:16 +08:00
state refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
tokenizer feat(seahorse): implement short-term memory engine (LCM) (#2285) 2026-04-05 09:05:16 +08:00
tools fix(feishu): fix image download with API fallback and post image support (#2708) 2026-04-30 11:08:00 +08:00
updater fix(updater): retry release fetches (#2511) 2026-04-14 10:44:21 +08:00
utils fix(tool-feedback): dedupe duplicate content and keep full explanations 2026-04-26 00:40:55 +08:00
env.go Merge branch 'main' into version 2026-03-19 18:04:58 +08:00