From 682b41db79c2eaa8c241099afa4373ef99f7038f Mon Sep 17 00:00:00 2001 From: Matt Apperson Date: Thu, 9 Apr 2026 10:04:50 -0400 Subject: [PATCH 1/3] feat: re-export SDK model types and add clean item type aliases Consumers no longer need to depend on @openrouter/sdk directly to annotate variables with types used in this package's public API. - Re-export 28 SDK types (request/response, message, multimodal content, output items, error event) from the main entry point - Add user-friendly item type aliases (Item, AssistantMessageItem, CallFunctionToolItem, etc.) via new src/lib/item-types.ts --- src/index.ts | 64 +++++++++++++++++++++++++++++++++++++++ src/lib/item-types.ts | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/lib/item-types.ts diff --git a/src/index.ts b/src/index.ts index ac4fdbf..c20d5c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,67 @@ +// SDK type re-exports — every SDK type used in this package's public API +// so consumers don't need to depend on @openrouter/sdk directly. + +export type { RequestOptions } from '@openrouter/sdk/lib/sdks'; + +export type { + // Core request/response + BaseInputsUnion, + InputsUnion, + OpenResponsesResult, + ResponsesRequest, + StreamEvents, + Usage, + + // Message & item types + ChatAssistantMessage, + ChatMessages, + EasyInputMessage, + EasyInputMessageContentUnion1, + EasyInputMessageRoleUnion, + FunctionCallItem, + FunctionCallOutputItem, + InputMessageItem, + OutputMessage, + + // Content input types (multimodal) + InputAudio, + InputFile, + InputImage, + InputText, + InputVideo, + + // Output item types (StreamableOutputItem members) + OutputFileSearchCallItem, + OutputFunctionCallItem, + OutputImageGenerationCallItem, + OutputReasoningItem, + OutputWebSearchCallItem, + + // Response output content + ResponseOutputText, + + // Error event + ErrorEvent, +} from '@openrouter/sdk/models'; + +// Clean item type aliases +export type { + AssistantMessageItem, + CallFileSearchItem, + CallFunctionToolItem, + CallImageGenerationItem, + CallWebSearchItem, + DeveloperMessageItem, + ErrorItem, + FunctionProgressItem, + FunctionResultItem, + Item, + NewUserMessageItem, + ReasoningItem, + SystemMessageItem, + UserMessageItem, +} from './lib/item-types.js'; + // Message format compatibility helpers // High-level model calling diff --git a/src/lib/item-types.ts b/src/lib/item-types.ts new file mode 100644 index 0000000..78c0d4c --- /dev/null +++ b/src/lib/item-types.ts @@ -0,0 +1,69 @@ +import type { + EasyInputMessage, + ErrorEvent, + FunctionCallItem, + FunctionCallOutputItem, + OutputFileSearchCallItem, + OutputImageGenerationCallItem, + OutputMessage, + OutputReasoningItem, + OutputWebSearchCallItem, +} from '@openrouter/sdk/models'; +import type { ToolPreliminaryResultEvent } from './tool-types.js'; + +type WithID = T & { id: string }; + +/** A function call initiated by the model */ +export type CallFunctionToolItem = FunctionCallItem; + +/** An assistant message in the response output */ +export type AssistantMessageItem = OutputMessage; + +/** A new user message (input, no id) */ +export type NewUserMessageItem = EasyInputMessage & { role: 'user' }; + +/** A user message with an id (from conversation history) */ +export type UserMessageItem = WithID & { role: 'user' }; + +/** A system message with an id */ +export type SystemMessageItem = WithID & { role: 'system' }; + +/** A developer message with an id */ +export type DeveloperMessageItem = WithID & { role: 'developer' }; + +/** Reasoning output from the model */ +export type ReasoningItem = OutputReasoningItem; + +/** A file search call in the response output */ +export type CallFileSearchItem = OutputFileSearchCallItem; + +/** The output from a function call execution */ +export type FunctionResultItem = WithID; + +/** A preliminary result event emitted during tool execution */ +export type FunctionProgressItem = WithID; + +/** A web search call in the response output */ +export type CallWebSearchItem = OutputWebSearchCallItem; + +/** An image generation call in the response output */ +export type CallImageGenerationItem = OutputImageGenerationCallItem; + +/** A streaming error event */ +export type ErrorItem = WithID; + +/** Union of all item types */ +export type Item = + | AssistantMessageItem + | UserMessageItem + | SystemMessageItem + | DeveloperMessageItem + | NewUserMessageItem + | CallFunctionToolItem + | ReasoningItem + | CallFileSearchItem + | FunctionResultItem + | FunctionProgressItem + | CallWebSearchItem + | CallImageGenerationItem + | ErrorItem; From 08dfa3cf343e0adfddd8bb7a285f32af32fef3e4 Mon Sep 17 00:00:00 2001 From: Matt Apperson Date: Thu, 9 Apr 2026 10:24:36 -0400 Subject: [PATCH 2/3] fix: correct item type aliases to match SDK runtime types - Use OutputFunctionCallItem (output) instead of FunctionCallItem (input) for CallFunctionToolItem - Drop WithID from FunctionResultItem, FunctionProgressItem, and ErrorItem where it fabricated or narrowed id fields not matching runtime values - Document WithID convention and Item union non-exhaustiveness --- src/lib/item-types.ts | 47 +++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/lib/item-types.ts b/src/lib/item-types.ts index 78c0d4c..0a05364 100644 --- a/src/lib/item-types.ts +++ b/src/lib/item-types.ts @@ -1,9 +1,9 @@ import type { EasyInputMessage, ErrorEvent, - FunctionCallItem, FunctionCallOutputItem, OutputFileSearchCallItem, + OutputFunctionCallItem, OutputImageGenerationCallItem, OutputMessage, OutputReasoningItem, @@ -11,24 +11,29 @@ import type { } from '@openrouter/sdk/models'; import type { ToolPreliminaryResultEvent } from './tool-types.js'; +/** + * Adds a required `id` field to a type, representing an item that has been + * persisted in conversation history (as opposed to newly created input). + * This is a local convention — the SDK's `EasyInputMessage` has no `id` field. + */ type WithID = T & { id: string }; /** A function call initiated by the model */ -export type CallFunctionToolItem = FunctionCallItem; +export type CallFunctionToolItem = OutputFunctionCallItem; /** An assistant message in the response output */ export type AssistantMessageItem = OutputMessage; -/** A new user message (input, no id) */ +/** A new user message for input (not yet persisted, no id) */ export type NewUserMessageItem = EasyInputMessage & { role: 'user' }; -/** A user message with an id (from conversation history) */ +/** A user message from conversation history (has an assigned id) */ export type UserMessageItem = WithID & { role: 'user' }; -/** A system message with an id */ +/** A system message from conversation history (has an assigned id) */ export type SystemMessageItem = WithID & { role: 'system' }; -/** A developer message with an id */ +/** A developer message from conversation history (has an assigned id) */ export type DeveloperMessageItem = WithID & { role: 'developer' }; /** Reasoning output from the model */ @@ -37,11 +42,18 @@ export type ReasoningItem = OutputReasoningItem; /** A file search call in the response output */ export type CallFileSearchItem = OutputFileSearchCallItem; -/** The output from a function call execution */ -export type FunctionResultItem = WithID; +/** + * The output from a function call execution. + * `FunctionCallOutputItem` already declares `id?: string | null | undefined`, + * so no `WithID` wrapper is needed. + */ +export type FunctionResultItem = FunctionCallOutputItem; -/** A preliminary result event emitted during tool execution */ -export type FunctionProgressItem = WithID; +/** + * A preliminary result event emitted during tool execution. + * `ToolPreliminaryResultEvent` uses `toolCallId` (not `id`) for identification. + */ +export type FunctionProgressItem = ToolPreliminaryResultEvent; /** A web search call in the response output */ export type CallWebSearchItem = OutputWebSearchCallItem; @@ -49,10 +61,19 @@ export type CallWebSearchItem = OutputWebSearchCallItem; /** An image generation call in the response output */ export type CallImageGenerationItem = OutputImageGenerationCallItem; -/** A streaming error event */ -export type ErrorItem = WithID; +/** + * A streaming error event. + * `ErrorEvent` has no `id` field; it uses `code`, `message`, `param`, and `sequenceNumber`. + */ +export type ErrorItem = ErrorEvent; -/** Union of all item types */ +/** + * Union of all item types used by this package. + * + * This is not exhaustive over every possible SDK output item type — + * server tool items (e.g. `OutputDatetimeItem`, `OutputServerToolItem`) + * are not included. Extend this union if you need to handle those. + */ export type Item = | AssistantMessageItem | UserMessageItem From 7bf56c8d1188ed67d36706e8465b8f6bae6b6770 Mon Sep 17 00:00:00 2001 From: Matt Apperson Date: Thu, 9 Apr 2026 10:25:57 -0400 Subject: [PATCH 3/3] style: fix biome formatting --- src/index.ts | 23 +++++++++-------------- src/lib/item-types.ts | 20 +++++++++++++++----- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/index.ts b/src/index.ts index c20d5c5..78673ad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,42 +6,37 @@ export type { RequestOptions } from '@openrouter/sdk/lib/sdks'; export type { // Core request/response BaseInputsUnion, - InputsUnion, - OpenResponsesResult, - ResponsesRequest, - StreamEvents, - Usage, - // Message & item types ChatAssistantMessage, ChatMessages, EasyInputMessage, EasyInputMessageContentUnion1, EasyInputMessageRoleUnion, + // Error event + ErrorEvent, FunctionCallItem, FunctionCallOutputItem, - InputMessageItem, - OutputMessage, - // Content input types (multimodal) InputAudio, InputFile, InputImage, + InputMessageItem, + InputsUnion, InputText, InputVideo, - + OpenResponsesResult, // Output item types (StreamableOutputItem members) OutputFileSearchCallItem, OutputFunctionCallItem, OutputImageGenerationCallItem, + OutputMessage, OutputReasoningItem, OutputWebSearchCallItem, - // Response output content ResponseOutputText, - - // Error event - ErrorEvent, + ResponsesRequest, + StreamEvents, + Usage, } from '@openrouter/sdk/models'; // Clean item type aliases diff --git a/src/lib/item-types.ts b/src/lib/item-types.ts index 0a05364..9720d99 100644 --- a/src/lib/item-types.ts +++ b/src/lib/item-types.ts @@ -16,7 +16,9 @@ import type { ToolPreliminaryResultEvent } from './tool-types.js'; * persisted in conversation history (as opposed to newly created input). * This is a local convention — the SDK's `EasyInputMessage` has no `id` field. */ -type WithID = T & { id: string }; +type WithID = T & { + id: string; +}; /** A function call initiated by the model */ export type CallFunctionToolItem = OutputFunctionCallItem; @@ -25,16 +27,24 @@ export type CallFunctionToolItem = OutputFunctionCallItem; export type AssistantMessageItem = OutputMessage; /** A new user message for input (not yet persisted, no id) */ -export type NewUserMessageItem = EasyInputMessage & { role: 'user' }; +export type NewUserMessageItem = EasyInputMessage & { + role: 'user'; +}; /** A user message from conversation history (has an assigned id) */ -export type UserMessageItem = WithID & { role: 'user' }; +export type UserMessageItem = WithID & { + role: 'user'; +}; /** A system message from conversation history (has an assigned id) */ -export type SystemMessageItem = WithID & { role: 'system' }; +export type SystemMessageItem = WithID & { + role: 'system'; +}; /** A developer message from conversation history (has an assigned id) */ -export type DeveloperMessageItem = WithID & { role: 'developer' }; +export type DeveloperMessageItem = WithID & { + role: 'developer'; +}; /** Reasoning output from the model */ export type ReasoningItem = OutputReasoningItem;