@openrouter/sdk 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,14 @@ import { RequestOptions } from "../lib/sdks.js";
3
3
  import { ResponseWrapper } from "../lib/response-wrapper.js";
4
4
  import * as models from "../models/index.js";
5
5
  import { EnhancedTool, MaxToolRounds } from "../lib/tool-types.js";
6
+ /**
7
+ * Input type that accepts both chat-style messages and responses-style input
8
+ */
9
+ export type CallModelInput = models.OpenResponsesInput | models.Message[];
10
+ /**
11
+ * Tool type that accepts chat-style, responses-style, or enhanced tools
12
+ */
13
+ export type CallModelTools = EnhancedTool[] | models.ToolDefinitionJson[] | models.OpenResponsesRequest["tools"];
6
14
  /**
7
15
  * Get a response with multiple consumption patterns
8
16
  *
@@ -71,8 +79,9 @@ import { EnhancedTool, MaxToolRounds } from "../lib/tool-types.js";
71
79
  * }
72
80
  * ```
73
81
  */
74
- export declare function callModel(client: OpenRouterCore, request: Omit<models.OpenResponsesRequest, "stream" | "tools"> & {
75
- tools?: EnhancedTool[] | models.OpenResponsesRequest["tools"];
82
+ export declare function callModel(client: OpenRouterCore, request: Omit<models.OpenResponsesRequest, "stream" | "tools" | "input"> & {
83
+ input?: CallModelInput;
84
+ tools?: CallModelTools;
76
85
  maxToolRounds?: MaxToolRounds;
77
86
  }, options?: RequestOptions): ResponseWrapper;
78
87
  //# sourceMappingURL=callModel.d.ts.map
@@ -1,5 +1,88 @@
1
1
  import { ResponseWrapper } from "../lib/response-wrapper.js";
2
2
  import { convertEnhancedToolsToAPIFormat } from "../lib/tool-executor.js";
3
+ /**
4
+ * Check if input is chat-style messages (Message[])
5
+ */
6
+ function isChatStyleMessages(input) {
7
+ if (!Array.isArray(input))
8
+ return false;
9
+ if (input.length === 0)
10
+ return false;
11
+ const first = input[0];
12
+ // Chat-style messages have role but no 'type' field at top level
13
+ // Responses-style items have 'type' field (like 'message', 'function_call', etc.)
14
+ return first && 'role' in first && !('type' in first);
15
+ }
16
+ /**
17
+ * Check if tools are chat-style (ToolDefinitionJson[])
18
+ */
19
+ function isChatStyleTools(tools) {
20
+ if (!Array.isArray(tools))
21
+ return false;
22
+ if (tools.length === 0)
23
+ return false;
24
+ const first = tools[0];
25
+ // Chat-style tools have nested 'function' property with 'name' inside
26
+ // Enhanced tools have 'function' with 'inputSchema'
27
+ // Responses-style tools have 'name' at top level
28
+ return first && 'function' in first && first.function && 'name' in first.function && !('inputSchema' in first.function);
29
+ }
30
+ /**
31
+ * Convert chat-style tools to responses-style
32
+ */
33
+ function convertChatToResponsesTools(tools) {
34
+ return tools.map((tool) => ({
35
+ type: "function",
36
+ name: tool.function.name,
37
+ description: tool.function.description ?? null,
38
+ strict: tool.function.strict ?? null,
39
+ parameters: tool.function.parameters ?? null,
40
+ }));
41
+ }
42
+ /**
43
+ * Convert chat-style messages to responses-style input
44
+ */
45
+ function convertChatToResponsesInput(messages) {
46
+ return messages.map((msg) => {
47
+ // Extract extra fields like cache_control
48
+ const { role, content, ...extraFields } = msg;
49
+ if (role === "tool") {
50
+ const toolMsg = msg;
51
+ return {
52
+ type: "function_call_output",
53
+ callId: toolMsg.toolCallId,
54
+ output: typeof toolMsg.content === "string" ? toolMsg.content : JSON.stringify(toolMsg.content),
55
+ ...extraFields,
56
+ };
57
+ }
58
+ // Handle assistant messages with tool calls
59
+ if (role === "assistant") {
60
+ const assistantMsg = msg;
61
+ // If it has tool calls, we need to convert them
62
+ // For now, just convert the content part
63
+ return {
64
+ role: "assistant",
65
+ content: typeof assistantMsg.content === "string"
66
+ ? assistantMsg.content
67
+ : assistantMsg.content === null
68
+ ? ""
69
+ : JSON.stringify(assistantMsg.content),
70
+ ...extraFields,
71
+ };
72
+ }
73
+ // System, user, developer messages
74
+ const convertedContent = typeof content === "string"
75
+ ? content
76
+ : content === null || content === undefined
77
+ ? ""
78
+ : JSON.stringify(content);
79
+ return {
80
+ role: role,
81
+ content: convertedContent,
82
+ ...extraFields,
83
+ };
84
+ });
85
+ }
3
86
  /**
4
87
  * Get a response with multiple consumption patterns
5
88
  *
@@ -69,16 +152,35 @@ import { convertEnhancedToolsToAPIFormat } from "../lib/tool-executor.js";
69
152
  * ```
70
153
  */
71
154
  export function callModel(client, request, options) {
72
- const { tools, maxToolRounds, ...apiRequest } = request;
73
- // Separate enhanced tools from API tools
155
+ const { tools, maxToolRounds, input, ...restRequest } = request;
156
+ // Convert chat-style messages to responses-style input if needed
157
+ const convertedInput = input && isChatStyleMessages(input)
158
+ ? convertChatToResponsesInput(input)
159
+ : input;
160
+ const apiRequest = {
161
+ ...restRequest,
162
+ input: convertedInput,
163
+ };
164
+ // Determine tool type and convert as needed
74
165
  let isEnhancedTools = false;
75
- if (tools && tools.length > 0) {
166
+ let isChatTools = false;
167
+ if (tools && Array.isArray(tools) && tools.length > 0) {
76
168
  const firstTool = tools[0];
77
169
  isEnhancedTools = "function" in firstTool && firstTool.function && "inputSchema" in firstTool.function;
170
+ isChatTools = !isEnhancedTools && isChatStyleTools(tools);
78
171
  }
79
172
  const enhancedTools = isEnhancedTools ? tools : undefined;
80
- // Convert enhanced tools to API format if provided, otherwise use tools as-is
81
- const apiTools = enhancedTools ? convertEnhancedToolsToAPIFormat(enhancedTools) : tools;
173
+ // Convert tools to API format based on their type
174
+ let apiTools;
175
+ if (enhancedTools) {
176
+ apiTools = convertEnhancedToolsToAPIFormat(enhancedTools);
177
+ }
178
+ else if (isChatTools) {
179
+ apiTools = convertChatToResponsesTools(tools);
180
+ }
181
+ else {
182
+ apiTools = tools;
183
+ }
82
184
  // Build the request with converted tools
83
185
  const finalRequest = {
84
186
  ...apiRequest,
@@ -45,8 +45,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
45
45
  export declare const SDK_METADATA: {
46
46
  readonly language: "typescript";
47
47
  readonly openapiDocVersion: "1.0.0";
48
- readonly sdkVersion: "0.1.24";
48
+ readonly sdkVersion: "0.1.25";
49
49
  readonly genVersion: "2.760.2";
50
- readonly userAgent: "speakeasy-sdk/typescript 0.1.24 2.760.2 1.0.0 @openrouter/sdk";
50
+ readonly userAgent: "speakeasy-sdk/typescript 0.1.25 2.760.2 1.0.0 @openrouter/sdk";
51
51
  };
52
52
  //# sourceMappingURL=config.d.ts.map
package/esm/lib/config.js CHANGED
@@ -25,8 +25,8 @@ export function serverURLFromOptions(options) {
25
25
  export const SDK_METADATA = {
26
26
  language: "typescript",
27
27
  openapiDocVersion: "1.0.0",
28
- sdkVersion: "0.1.24",
28
+ sdkVersion: "0.1.25",
29
29
  genVersion: "2.760.2",
30
- userAgent: "speakeasy-sdk/typescript 0.1.24 2.760.2 1.0.0 @openrouter/sdk",
30
+ userAgent: "speakeasy-sdk/typescript 0.1.25 2.760.2 1.0.0 @openrouter/sdk",
31
31
  };
32
32
  //# sourceMappingURL=config.js.map
package/esm/sdk/sdk.d.ts CHANGED
@@ -45,8 +45,9 @@ export declare class OpenRouter extends ClientSDK {
45
45
  get chat(): Chat;
46
46
  private _completions?;
47
47
  get completions(): Completions;
48
- callModel(request: Omit<models.OpenResponsesRequest, "stream" | "tools"> & {
49
- tools?: EnhancedTool[] | models.OpenResponsesRequest["tools"];
48
+ callModel(request: Omit<models.OpenResponsesRequest, "stream" | "tools" | "input"> & {
49
+ input?: import("../funcs/callModel.js").CallModelInput;
50
+ tools?: import("../funcs/callModel.js").CallModelTools;
50
51
  maxToolRounds?: MaxToolRounds;
51
52
  }, options?: RequestOptions): ResponseWrapper;
52
53
  }
package/jsr.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  {
4
4
  "name": "@openrouter/sdk",
5
- "version": "0.1.24",
5
+ "version": "0.1.25",
6
6
  "exports": {
7
7
  ".": "./src/index.ts",
8
8
  "./models/errors": "./src/models/errors/index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrouter/sdk",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "author": "OpenRouter",
5
5
  "description": "The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.",
6
6
  "keywords": [