Skip to content

Commit e442a2c

Browse files
Matt Appersonclaude
andcommitted
fix: support both EnhancedTool and API tool types in getResponse
Allow getResponse to accept either EnhancedTool[] (with Zod schemas and execute functions) or the standard API tool union types. The function now: 1. Detects tool type by checking for inputSchema in first tool 2. Converts EnhancedTool[] to API format for the request 3. Passes only EnhancedTools to ResponseWrapper for auto-execution 4. Allows standard API tools to pass through unchanged This resolves TypeScript errors in CI where tools were incorrectly constrained to only EnhancedTool type. All tests pass (21 passed, 2 skipped). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 71dff17 commit e442a2c

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/funcs/getResponse.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,30 @@ import { convertEnhancedToolsToAPIFormat } from "../lib/tool-executor.js";
7474
*/
7575
export function getResponse(
7676
client: OpenRouterCore,
77-
request: Omit<models.OpenResponsesRequest, "stream"> & {
78-
tools?: EnhancedTool[];
77+
request: Omit<models.OpenResponsesRequest, "stream" | "tools"> & {
78+
tools?: EnhancedTool[] | models.OpenResponsesRequest["tools"];
7979
maxToolRounds?: MaxToolRounds;
8080
},
8181
options?: RequestOptions,
8282
): ResponseWrapper {
8383
const { tools, maxToolRounds, ...apiRequest } = request;
8484

85-
// Convert enhanced tools to API format if provided
86-
const apiTools = tools ? convertEnhancedToolsToAPIFormat(tools) : undefined;
85+
// Separate enhanced tools from API tools
86+
let isEnhancedTools = false;
87+
if (tools && tools.length > 0) {
88+
const firstTool = tools[0] as any;
89+
isEnhancedTools = "function" in firstTool && firstTool.function && "inputSchema" in firstTool.function;
90+
}
91+
const enhancedTools = isEnhancedTools ? (tools as EnhancedTool[]) : undefined;
92+
93+
// Convert enhanced tools to API format if provided, otherwise use tools as-is
94+
const apiTools = enhancedTools ? convertEnhancedToolsToAPIFormat(enhancedTools) : (tools as models.OpenResponsesRequest["tools"]);
8795

8896
// Build the request with converted tools
89-
const finalRequest = {
97+
const finalRequest: models.OpenResponsesRequest = {
9098
...apiRequest,
9199
...(apiTools && { tools: apiTools }),
92-
};
100+
} as models.OpenResponsesRequest;
93101

94102
const wrapperOptions: {
95103
client: OpenRouterCore;
@@ -103,8 +111,9 @@ export function getResponse(
103111
options: options ?? {},
104112
};
105113

106-
if (tools) {
107-
wrapperOptions.tools = tools;
114+
// Only pass enhanced tools to wrapper (needed for auto-execution)
115+
if (enhancedTools) {
116+
wrapperOptions.tools = enhancedTools;
108117
}
109118

110119
if (maxToolRounds !== undefined) {

src/sdk/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ export class OpenRouter extends ClientSDK {
119119
* ```
120120
*/
121121
getResponse(
122-
request: Omit<models.OpenResponsesRequest, "stream"> & {
123-
tools?: EnhancedTool[];
122+
request: Omit<models.OpenResponsesRequest, "stream" | "tools"> & {
123+
tools?: EnhancedTool[] | models.OpenResponsesRequest["tools"];
124124
maxToolRounds?: MaxToolRounds;
125125
},
126126
options?: RequestOptions,

0 commit comments

Comments
 (0)