Skip to content

Commit bca560a

Browse files
committed
feat(basic-host): handle non-text content blocks in display
- Add formatContentBlock helper for text, image, audio, resource types - Show placeholders like <image: image/png> for non-text content - Apply to both messages and model context display
1 parent d222cca commit bca560a

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

examples/basic-host/src/index.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,24 @@ function AppIFramePanel({ toolCallInfo, isDestroying, onTeardownComplete }: AppI
367367
});
368368
}, [isDestroying, onTeardownComplete]);
369369

370-
// Extract text from context for display
371-
const contextText = modelContext?.content
372-
?.filter((c): c is { type: "text"; text: string } => c.type === "text" && !!c.text)
373-
.map((c) => c.text)
374-
.join("\n") ?? "";
370+
// Format content blocks - handle text, images, resources, etc.
371+
const formatContentBlock = (c: { type: string; [key: string]: unknown }) => {
372+
switch (c.type) {
373+
case "text":
374+
return (c as { type: "text"; text: string }).text;
375+
case "image":
376+
return `<image: ${(c as { mimeType?: string }).mimeType ?? "unknown"}>`;
377+
case "audio":
378+
return `<audio: ${(c as { mimeType?: string }).mimeType ?? "unknown"}>`;
379+
case "resource":
380+
return `<resource: ${(c as { resource?: { uri?: string } }).resource?.uri ?? "unknown"}>`;
381+
default:
382+
return `<${c.type}>`;
383+
}
384+
};
385+
386+
// Format context for display
387+
const contextText = modelContext?.content?.map(formatContentBlock).join("\n") ?? "";
375388
const contextJson = modelContext?.structuredContent
376389
? JSON.stringify(modelContext.structuredContent, null, 2)
377390
: "";
@@ -380,13 +393,10 @@ function AppIFramePanel({ toolCallInfo, isDestroying, onTeardownComplete }: AppI
380393
const inputJson = JSON.stringify(toolCallInfo.input, null, 2);
381394
const resultJson = toolResult ? JSON.stringify(toolResult, null, 2) : null;
382395

383-
// Format messages - extract text from content blocks
396+
// Format messages
384397
const formatMessage = (m: AppMessage) => {
385-
const text = m.content
386-
.filter((c): c is { type: "text"; text: string } => c.type === "text")
387-
.map((c) => c.text)
388-
.join("\n");
389-
return `[${m.role}] ${text}`;
398+
const content = m.content.map(formatContentBlock).join("\n");
399+
return `[${m.role}] ${content}`;
390400
};
391401
const messagesText = messages.map(formatMessage).join("\n\n");
392402

0 commit comments

Comments
 (0)