Skip to content

Consider updating Message types #27

Description

@charlesLoder

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;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions