Clean up Claude agent SDK message conversion

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-12-29 11:02:02 +07:00
co-authored by Claude Opus 4.5
parent 7a024ce7fd
commit 09d4acce4c
@@ -29,7 +29,6 @@ import type {
AgentPermissionResponse, AgentPermissionResponse,
AgentPermissionUpdate, AgentPermissionUpdate,
AgentPersistenceHandle, AgentPersistenceHandle,
AgentPromptContentBlock,
AgentPromptInput, AgentPromptInput,
AgentRunOptions, AgentRunOptions,
AgentRunResult, AgentRunResult,
@@ -788,26 +787,25 @@ class ClaudeAgentSession implements AgentSession {
} }
private toSdkUserMessage(prompt: AgentPromptInput): SDKUserMessage { private toSdkUserMessage(prompt: AgentPromptInput): SDKUserMessage {
const content = Array.isArray(prompt) const content: Array<{ type: "text"; text: string } | { type: "image"; source: { type: "base64"; media_type: string; data: string } }> = [];
? prompt.flatMap((chunk: AgentPromptContentBlock) => { if (Array.isArray(prompt)) {
for (const chunk of prompt) {
if (chunk.type === "text") { if (chunk.type === "text") {
return [{ type: "text", text: chunk.text }]; content.push({ type: "text", text: chunk.text });
} } else if (chunk.type === "image") {
if (chunk.type === "image") { content.push({
return [
{
type: "image", type: "image",
source: { source: {
type: "base64", type: "base64",
media_type: chunk.mimeType, media_type: chunk.mimeType,
data: chunk.data, data: chunk.data,
}, },
}, });
]; }
}
} else {
content.push({ type: "text", text: prompt });
} }
return [];
})
: [{ type: "text", text: prompt }];
return { return {
type: "user", type: "user",