Skip to content

fix(agent): support tool calls in fromChatMessages and fix input typing - #123

Open
warun7 wants to merge 1 commit into
OpenRouterTeam:mainfrom
warun7:fix/from-chat-messages-tool-calls-and-input-type
Open

fix(agent): support tool calls in fromChatMessages and fix input typing#123
warun7 wants to merge 1 commit into
OpenRouterTeam:mainfrom
warun7:fix/from-chat-messages-tool-calls-and-input-type

Conversation

@warun7

@warun7 warun7 commented Sep 4, 2026

Copy link
Copy Markdown

Fixes #11, Fixes #41

Summary of Changes

  1. Tool Calls Support in fromChatMessages (TypeScript fromChatMessages does not properly interpret function_calls #11):

    • When an assistant message contains tool calls (toolCalls or tool_calls), properly emit corresponding function_call items.
    • If the assistant message also has non-empty text content, preserve it before the function_call items; if content is empty/null, omit the blank assistant message so only the tool calls are emitted.
    • Handle both camelCase (toolCalls, toolCallId) and snake_case (tool_calls, tool_call_id) inputs.
    • Safely stringify object arguments if provided.
  2. callModel Input Type Compatibility (fromChatMessages does not produce correct object for input in callModel #41):

    • Widened BaseCallModelInput['input'] to FieldOrAsyncFunction<models.InputsUnion | Item[]>.
    • Allows passing fromChatMessages(...) and fromClaudeMessages(...) directly to callModel without TypeScript errors.
  3. Tests & Changeset:

    • Added unit tests covering assistant tool calls conversion, snake_case aliases, and callModel typing.
    • Added changeset for @openrouter/agent (patch).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fromChatMessages does not produce correct object for input in callModel TypeScript fromChatMessages does not properly interpret function_calls

1 participant