fix: enable image attachments in chat messages for Claude API

Images were previously converted to markdown data URLs which Claude API
treats as plain text, not as actual images.

Changes:
- Add parseMessageWithAttachments() that returns {message, images[]}
- Pass images through the stack to session.prompt() as content blocks
- Filter null/empty attachments before parsing
- Strip data URL prefix if client sends it

This enables iOS and other clients to send images that Claude can actually see.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cristip73
2026-01-10 19:17:32 +02:00
committed by Peter Steinberger
parent 0279f09459
commit c4e76eb635
5 changed files with 156 additions and 42 deletions

View File

@@ -8,7 +8,12 @@ import type {
AgentTool,
ThinkingLevel,
} from "@mariozechner/pi-agent-core";
import type { Api, AssistantMessage, Model } from "@mariozechner/pi-ai";
import type {
Api,
AssistantMessage,
ImageContent,
Model,
} from "@mariozechner/pi-ai";
import {
createAgentSession,
discoverAuthStorage,
@@ -1009,6 +1014,8 @@ export async function runEmbeddedPiAgent(params: {
config?: ClawdbotConfig;
skillsSnapshot?: SkillSnapshot;
prompt: string;
/** Optional image attachments for multimodal messages. */
images?: ImageContent[];
provider?: string;
model?: string;
authProfileId?: string;
@@ -1434,7 +1441,9 @@ export async function runEmbeddedPiAgent(params: {
`embedded run prompt start: runId=${params.runId} sessionId=${params.sessionId}`,
);
try {
await session.prompt(params.prompt);
await session.prompt(params.prompt, {
images: params.images,
});
} catch (err) {
promptError = err;
} finally {