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
parent 7a024ce7fd
commit 09d4acce4c

View File

@@ -29,7 +29,6 @@ import type {
AgentPermissionResponse,
AgentPermissionUpdate,
AgentPersistenceHandle,
AgentPromptContentBlock,
AgentPromptInput,
AgentRunOptions,
AgentRunResult,
@@ -788,26 +787,25 @@ class ClaudeAgentSession implements AgentSession {
}
private toSdkUserMessage(prompt: AgentPromptInput): SDKUserMessage {
const content = Array.isArray(prompt)
? prompt.flatMap((chunk: AgentPromptContentBlock) => {
if (chunk.type === "text") {
return [{ type: "text", text: chunk.text }];
}
if (chunk.type === "image") {
return [
{
type: "image",
source: {
type: "base64",
media_type: chunk.mimeType,
data: chunk.data,
},
},
];
}
return [];
})
: [{ type: "text", text: prompt }];
const content: Array<{ type: "text"; text: string } | { type: "image"; source: { type: "base64"; media_type: string; data: string } }> = [];
if (Array.isArray(prompt)) {
for (const chunk of prompt) {
if (chunk.type === "text") {
content.push({ type: "text", text: chunk.text });
} else if (chunk.type === "image") {
content.push({
type: "image",
source: {
type: "base64",
media_type: chunk.mimeType,
data: chunk.data,
},
});
}
}
} else {
content.push({ type: "text", text: prompt });
}
return {
type: "user",