Consider updating message types to conform a little more closely to OpenAI's Chat Completion Messages.
Claude suggested something like this. Not totally sure but maybe there are some better ergonomics
// Improved message types that better align with industry standards
// while maintaining your existing functionality
export type ConversationState = "idle" | "assistant_responding" | "error";
export type Role = "assistant" | "system" | "user";
export type Media = {
id: string;
src: string;
type: "fragment" | "image";
caption?: string;
};
// Content types - unified approach for all message types
export interface TextContentBlock {
type: "text";
text: string;
}
export interface MediaContentBlock {
type: "media";
media: Media;
}
export interface ToolUseContentBlock {
type: "tool_use";
id: string;
name: string;
input: Record<string, unknown>;
}
export interface ToolResultContentBlock {
type: "tool_result";
tool_use_id: string;
content: string;
is_error?: boolean;
}
// Union of all content block types
export type ContentBlock =
| TextContentBlock
| MediaContentBlock
| ToolUseContentBlock
| ToolResultContentBlock;
// Standardized message interfaces - all use consistent content array pattern
export interface UserMessage {
role: "user";
content: (TextContentBlock | MediaContentBlock)[];
}
export interface AssistantMessage {
role: "assistant";
content: (TextContentBlock | ToolUseContentBlock)[];
}
export interface SystemMessage {
role: "system";
content: TextContentBlock[];
}
export type Message = UserMessage | AssistantMessage | SystemMessage;
Consider updating message types to conform a little more closely to OpenAI's Chat Completion Messages.
Claude suggested something like this. Not totally sure but maybe there are some better ergonomics