Skip to content

[claude-code] Implement Anthropic MessageParam → Agent SDK prompt conversion #758

Description

@edelauna

Parent issue

#756

Depends on

#757

Context

The @anthropic-ai/claude-agent-sdk query() function accepts options.input_messages as MessageParam[] (same shape as the Anthropic SDK). This issue implements the conversion layer and validates edge cases before the core handler is built in the next issue.

Files

  • src/api/providers/claude-code-messages.ts (new)
  • src/api/providers/__tests__/claude-code-messages.spec.ts (new)

Work

  • convertToClaudeCodeMessages(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): { system: string, messages: MessageParam[] } — pass-through for text content, strip or warn on unsupported block types
  • Handle multi-turn conversations (alternating user/assistant)
  • Handle image content blocks (pass base64 through; document that the CLI must support vision)
  • Handle tool use and tool result blocks (pass through as-is — Agent SDK accepts native Anthropic tool format)

Tests

  • Text-only single-turn round-trip
  • Multi-turn conversation preserves message order
  • Image content blocks are passed through
  • Tool use / tool result blocks are passed through
  • Empty messages array returns only system prompt

Acceptance criteria

  • convertToClaudeCodeMessages is exported and fully typed
  • All tests pass
  • No runtime dependency on @anthropic-ai/claude-agent-sdk in this file (pure transformation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions