@openrouter/sdk 0.1.17 → 0.1.23
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.
- package/README.md +0 -8
- package/esm/funcs/callModel.d.ts +77 -0
- package/esm/funcs/callModel.js +100 -0
- package/esm/lib/config.d.ts +10 -2
- package/esm/lib/config.js +2 -2
- package/esm/lib/env.d.ts +13 -0
- package/esm/lib/env.js +16 -0
- package/esm/lib/response-wrapper.d.ts +116 -0
- package/esm/lib/response-wrapper.js +459 -0
- package/esm/lib/reusable-stream.d.ts +39 -0
- package/esm/lib/reusable-stream.js +173 -0
- package/esm/lib/sdks.js +2 -2
- package/esm/lib/stream-transformers.d.ts +47 -0
- package/esm/lib/stream-transformers.js +280 -0
- package/esm/lib/tool-executor.d.ts +53 -0
- package/esm/lib/tool-executor.js +181 -0
- package/esm/lib/tool-orchestrator.d.ts +50 -0
- package/esm/lib/tool-orchestrator.js +132 -0
- package/esm/lib/tool-types.d.ts +199 -0
- package/esm/lib/tool-types.js +32 -0
- package/esm/sdk/sdk.d.ts +10 -0
- package/esm/sdk/sdk.js +9 -0
- package/jsr.json +1 -1
- package/package.json +2 -16
- package/vitest.config.ts +4 -0
- package/REACT_QUERY.md +0 -296
- package/esm/react-query/_context.d.ts +0 -8
- package/esm/react-query/_context.js +0 -14
- package/esm/react-query/_types.d.ts +0 -27
- package/esm/react-query/_types.js +0 -5
- package/esm/react-query/analyticsGetUserActivity.d.ts +0 -36
- package/esm/react-query/analyticsGetUserActivity.js +0 -77
- package/esm/react-query/apiKeysCreate.d.ts +0 -20
- package/esm/react-query/apiKeysCreate.js +0 -39
- package/esm/react-query/apiKeysDelete.d.ts +0 -20
- package/esm/react-query/apiKeysDelete.js +0 -39
- package/esm/react-query/apiKeysGet.d.ts +0 -24
- package/esm/react-query/apiKeysGet.js +0 -66
- package/esm/react-query/apiKeysGetCurrentKeyMetadata.d.ts +0 -29
- package/esm/react-query/apiKeysGetCurrentKeyMetadata.js +0 -66
- package/esm/react-query/apiKeysList.d.ts +0 -37
- package/esm/react-query/apiKeysList.js +0 -69
- package/esm/react-query/apiKeysUpdate.d.ts +0 -20
- package/esm/react-query/apiKeysUpdate.js +0 -39
- package/esm/react-query/betaResponsesSend.d.ts +0 -24
- package/esm/react-query/betaResponsesSend.js +0 -42
- package/esm/react-query/chatSend.d.ts +0 -24
- package/esm/react-query/chatSend.js +0 -42
- package/esm/react-query/completionsGenerate.d.ts +0 -23
- package/esm/react-query/completionsGenerate.js +0 -42
- package/esm/react-query/creditsCreateCoinbaseCharge.d.ts +0 -25
- package/esm/react-query/creditsCreateCoinbaseCharge.js +0 -42
- package/esm/react-query/creditsGetCredits.d.ts +0 -29
- package/esm/react-query/creditsGetCredits.js +0 -66
- package/esm/react-query/embeddingsGenerate.d.ts +0 -23
- package/esm/react-query/embeddingsGenerate.js +0 -42
- package/esm/react-query/embeddingsListModels.d.ts +0 -29
- package/esm/react-query/embeddingsListModels.js +0 -66
- package/esm/react-query/endpointsList.d.ts +0 -24
- package/esm/react-query/endpointsList.js +0 -66
- package/esm/react-query/endpointsListZdrEndpoints.d.ts +0 -23
- package/esm/react-query/endpointsListZdrEndpoints.js +0 -60
- package/esm/react-query/generationsGetGeneration.d.ts +0 -30
- package/esm/react-query/generationsGetGeneration.js +0 -71
- package/esm/react-query/index.d.ts +0 -27
- package/esm/react-query/index.js +0 -30
- package/esm/react-query/modelsCount.d.ts +0 -23
- package/esm/react-query/modelsCount.js +0 -60
- package/esm/react-query/modelsList.d.ts +0 -38
- package/esm/react-query/modelsList.js +0 -69
- package/esm/react-query/modelsListForUser.d.ts +0 -24
- package/esm/react-query/modelsListForUser.js +0 -60
- package/esm/react-query/oAuthCreateAuthCode.d.ts +0 -23
- package/esm/react-query/oAuthCreateAuthCode.js +0 -42
- package/esm/react-query/oAuthExchangeAuthCodeForAPIKey.d.ts +0 -23
- package/esm/react-query/oAuthExchangeAuthCodeForAPIKey.js +0 -42
- package/esm/react-query/parametersGetParameters.d.ts +0 -38
- package/esm/react-query/parametersGetParameters.js +0 -80
- package/esm/react-query/providersList.d.ts +0 -23
- package/esm/react-query/providersList.js +0 -60
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { hasExecuteFunction, } from "./tool-types.js";
|
|
2
|
+
import { executeTool, findToolByName, } from "./tool-executor.js";
|
|
3
|
+
import { extractToolCallsFromResponse, responseHasToolCalls, } from "./stream-transformers.js";
|
|
4
|
+
/**
|
|
5
|
+
* Execute tool calls and manage multi-turn conversations
|
|
6
|
+
* This orchestrates the loop of: request -> tool calls -> execute -> send results -> repeat
|
|
7
|
+
*
|
|
8
|
+
* @param sendRequest - Function to send a request and get a response
|
|
9
|
+
* @param initialInput - Starting input for the conversation
|
|
10
|
+
* @param tools - Enhanced tools with Zod schemas and execute functions
|
|
11
|
+
* @param apiTools - Converted tools in API format (JSON Schema)
|
|
12
|
+
* @param options - Execution options
|
|
13
|
+
* @returns Result containing final response and all execution data
|
|
14
|
+
*/
|
|
15
|
+
export async function executeToolLoop(sendRequest, initialInput, tools, apiTools, options = {}) {
|
|
16
|
+
const maxRounds = options.maxRounds ?? 5;
|
|
17
|
+
const onPreliminaryResult = options.onPreliminaryResult;
|
|
18
|
+
const allResponses = [];
|
|
19
|
+
const toolExecutionResults = [];
|
|
20
|
+
let conversationInput = initialInput;
|
|
21
|
+
let currentRound = 0;
|
|
22
|
+
let currentResponse;
|
|
23
|
+
// Initial request
|
|
24
|
+
currentResponse = await sendRequest(conversationInput, apiTools);
|
|
25
|
+
allResponses.push(currentResponse);
|
|
26
|
+
// Loop until no more tool calls or max rounds reached
|
|
27
|
+
while (responseHasToolCalls(currentResponse) && currentRound < maxRounds) {
|
|
28
|
+
currentRound++;
|
|
29
|
+
// Extract tool calls from response
|
|
30
|
+
const toolCalls = extractToolCallsFromResponse(currentResponse);
|
|
31
|
+
if (toolCalls.length === 0) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
// Check if any tools have execute functions
|
|
35
|
+
const hasExecutableTools = toolCalls.some((toolCall) => {
|
|
36
|
+
const tool = findToolByName(tools, toolCall.name);
|
|
37
|
+
return tool && hasExecuteFunction(tool);
|
|
38
|
+
});
|
|
39
|
+
// If no executable tools, return (manual execution mode)
|
|
40
|
+
if (!hasExecutableTools) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
// Execute all tool calls
|
|
44
|
+
const roundResults = [];
|
|
45
|
+
for (const toolCall of toolCalls) {
|
|
46
|
+
const tool = findToolByName(tools, toolCall.name);
|
|
47
|
+
if (!tool) {
|
|
48
|
+
// Tool not found in definitions
|
|
49
|
+
roundResults.push({
|
|
50
|
+
toolCallId: toolCall.id,
|
|
51
|
+
toolName: toolCall.name,
|
|
52
|
+
result: null,
|
|
53
|
+
error: new Error(`Tool "${toolCall.name}" not found in tool definitions`),
|
|
54
|
+
});
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (!hasExecuteFunction(tool)) {
|
|
58
|
+
// Tool has no execute function - skip
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// Build turn context
|
|
62
|
+
const turnContext = {
|
|
63
|
+
numberOfTurns: currentRound,
|
|
64
|
+
messageHistory: conversationInput,
|
|
65
|
+
};
|
|
66
|
+
// Execute the tool
|
|
67
|
+
const result = await executeTool(tool, toolCall, turnContext, onPreliminaryResult);
|
|
68
|
+
roundResults.push(result);
|
|
69
|
+
}
|
|
70
|
+
toolExecutionResults.push(...roundResults);
|
|
71
|
+
// Build array input with all output from previous response plus tool results
|
|
72
|
+
// The API expects continuation via previousResponseId, not by including outputs
|
|
73
|
+
// For now, we'll keep the conversation going via previousResponseId
|
|
74
|
+
conversationInput = initialInput; // Keep original input
|
|
75
|
+
// Note: The OpenRouter Responses API uses previousResponseId for continuation
|
|
76
|
+
// Tool results are automatically associated with the previous response's tool calls
|
|
77
|
+
// Send updated conversation to API - this should use previousResponseId
|
|
78
|
+
currentResponse = await sendRequest(conversationInput, apiTools);
|
|
79
|
+
allResponses.push(currentResponse);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
finalResponse: currentResponse,
|
|
83
|
+
allResponses,
|
|
84
|
+
toolExecutionResults,
|
|
85
|
+
conversationInput,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Convert tool execution results to a map for easy lookup
|
|
90
|
+
*/
|
|
91
|
+
export function toolResultsToMap(results) {
|
|
92
|
+
const map = new Map();
|
|
93
|
+
for (const result of results) {
|
|
94
|
+
map.set(result.toolCallId, {
|
|
95
|
+
result: result.result,
|
|
96
|
+
preliminaryResults: result.preliminaryResults,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return map;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build a summary of tool executions for debugging/logging
|
|
103
|
+
*/
|
|
104
|
+
export function summarizeToolExecutions(results) {
|
|
105
|
+
const lines = [];
|
|
106
|
+
for (const result of results) {
|
|
107
|
+
if (result.error) {
|
|
108
|
+
lines.push(`❌ ${result.toolName} (${result.toolCallId}): ERROR - ${result.error.message}`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const prelimCount = result.preliminaryResults?.length ?? 0;
|
|
112
|
+
const prelimInfo = prelimCount > 0 ? ` (${prelimCount} preliminary results)` : "";
|
|
113
|
+
lines.push(`✅ ${result.toolName} (${result.toolCallId}): SUCCESS${prelimInfo}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return lines.join("\n");
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if any tool executions had errors
|
|
120
|
+
*/
|
|
121
|
+
export function hasToolExecutionErrors(results) {
|
|
122
|
+
return results.some((result) => result.error !== undefined);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get all tool execution errors
|
|
126
|
+
*/
|
|
127
|
+
export function getToolExecutionErrors(results) {
|
|
128
|
+
return results
|
|
129
|
+
.filter((result) => result.error !== undefined)
|
|
130
|
+
.map((result) => result.error);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=tool-orchestrator.js.map
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { z, type ZodType, type ZodObject, type ZodRawShape } from "zod/v4";
|
|
2
|
+
import * as models from "../models/index.js";
|
|
3
|
+
import type { OpenResponsesStreamEvent } from "../models/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Tool type enum for enhanced tools
|
|
6
|
+
*/
|
|
7
|
+
export declare enum ToolType {
|
|
8
|
+
Function = "function"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Turn context passed to tool execute functions
|
|
12
|
+
* Contains information about the current conversation state
|
|
13
|
+
*/
|
|
14
|
+
export interface TurnContext {
|
|
15
|
+
/** Number of tool execution turns so far (1-indexed: first turn = 1) */
|
|
16
|
+
numberOfTurns: number;
|
|
17
|
+
/** Current message history being sent to the API */
|
|
18
|
+
messageHistory: models.OpenResponsesInput;
|
|
19
|
+
/** Model name if request.model is set */
|
|
20
|
+
model?: string;
|
|
21
|
+
/** Model names if request.models is set */
|
|
22
|
+
models?: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Base tool function interface with inputSchema
|
|
26
|
+
*/
|
|
27
|
+
export interface BaseToolFunction<TInput extends ZodObject<ZodRawShape>> {
|
|
28
|
+
name: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
inputSchema: TInput;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Regular tool with synchronous or asynchronous execute function and optional outputSchema
|
|
34
|
+
*/
|
|
35
|
+
export interface ToolFunctionWithExecute<TInput extends ZodObject<ZodRawShape>, TOutput extends ZodType = ZodType<any>> extends BaseToolFunction<TInput> {
|
|
36
|
+
outputSchema?: TOutput;
|
|
37
|
+
execute: (params: z.infer<TInput>, context?: TurnContext) => Promise<z.infer<TOutput>> | z.infer<TOutput>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generator-based tool with async generator execute function
|
|
41
|
+
* Emits preliminary events (validated by eventSchema) during execution
|
|
42
|
+
* and a final output (validated by outputSchema) as the last emission
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* {
|
|
47
|
+
* eventSchema: z.object({ status: z.string() }), // For progress events
|
|
48
|
+
* outputSchema: z.object({ result: z.number() }), // For final output
|
|
49
|
+
* execute: async function* (params) {
|
|
50
|
+
* yield { status: "processing..." }; // Event
|
|
51
|
+
* yield { status: "almost done..." }; // Event
|
|
52
|
+
* yield { result: 42 }; // Final output (must be last)
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export interface ToolFunctionWithGenerator<TInput extends ZodObject<ZodRawShape>, TEvent extends ZodType = ZodType<any>, TOutput extends ZodType = ZodType<any>> extends BaseToolFunction<TInput> {
|
|
58
|
+
eventSchema: TEvent;
|
|
59
|
+
outputSchema: TOutput;
|
|
60
|
+
execute: (params: z.infer<TInput>, context?: TurnContext) => AsyncGenerator<z.infer<TEvent>>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Manual tool without execute function - requires manual handling by developer
|
|
64
|
+
*/
|
|
65
|
+
export interface ManualToolFunction<TInput extends ZodObject<ZodRawShape>, TOutput extends ZodType = ZodType<any>> extends BaseToolFunction<TInput> {
|
|
66
|
+
outputSchema?: TOutput;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Tool with execute function (regular or generator)
|
|
70
|
+
*/
|
|
71
|
+
export type ToolWithExecute<TInput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TOutput extends ZodType = ZodType<any>> = {
|
|
72
|
+
type: ToolType.Function;
|
|
73
|
+
function: ToolFunctionWithExecute<TInput, TOutput>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Tool with generator execute function
|
|
77
|
+
*/
|
|
78
|
+
export type ToolWithGenerator<TInput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TEvent extends ZodType = ZodType<any>, TOutput extends ZodType = ZodType<any>> = {
|
|
79
|
+
type: ToolType.Function;
|
|
80
|
+
function: ToolFunctionWithGenerator<TInput, TEvent, TOutput>;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Tool without execute function (manual handling)
|
|
84
|
+
*/
|
|
85
|
+
export type ManualTool<TInput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TOutput extends ZodType = ZodType<any>> = {
|
|
86
|
+
type: ToolType.Function;
|
|
87
|
+
function: ManualToolFunction<TInput, TOutput>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Union type of all enhanced tool types
|
|
91
|
+
*/
|
|
92
|
+
export type EnhancedTool = ToolWithExecute<any, any> | ToolWithGenerator<any, any> | ManualTool<any, any>;
|
|
93
|
+
/**
|
|
94
|
+
* Type guard to check if a tool has an execute function
|
|
95
|
+
*/
|
|
96
|
+
export declare function hasExecuteFunction(tool: EnhancedTool): tool is ToolWithExecute | ToolWithGenerator;
|
|
97
|
+
/**
|
|
98
|
+
* Type guard to check if a tool uses a generator (has eventSchema)
|
|
99
|
+
*/
|
|
100
|
+
export declare function isGeneratorTool(tool: EnhancedTool): tool is ToolWithGenerator;
|
|
101
|
+
/**
|
|
102
|
+
* Type guard to check if a tool is a regular execution tool (not generator)
|
|
103
|
+
*/
|
|
104
|
+
export declare function isRegularExecuteTool(tool: EnhancedTool): tool is ToolWithExecute;
|
|
105
|
+
/**
|
|
106
|
+
* Parsed tool call from API response
|
|
107
|
+
*/
|
|
108
|
+
export interface ParsedToolCall {
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
arguments: unknown;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Result of tool execution
|
|
115
|
+
*/
|
|
116
|
+
export interface ToolExecutionResult {
|
|
117
|
+
toolCallId: string;
|
|
118
|
+
toolName: string;
|
|
119
|
+
result: unknown;
|
|
120
|
+
preliminaryResults?: unknown[];
|
|
121
|
+
error?: Error;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Type for maxToolRounds - can be a number or a function that determines if execution should continue
|
|
125
|
+
*/
|
|
126
|
+
export type MaxToolRounds = number | ((context: TurnContext) => boolean);
|
|
127
|
+
/**
|
|
128
|
+
* Result of executeTools operation
|
|
129
|
+
*/
|
|
130
|
+
export interface ExecuteToolsResult {
|
|
131
|
+
finalResponse: any;
|
|
132
|
+
allResponses: any[];
|
|
133
|
+
toolResults: Map<string, {
|
|
134
|
+
result: unknown;
|
|
135
|
+
preliminaryResults?: unknown[];
|
|
136
|
+
}>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Standard tool format for OpenRouter API (JSON Schema based)
|
|
140
|
+
* Matches OpenResponsesRequestToolFunction structure
|
|
141
|
+
*/
|
|
142
|
+
export interface APITool {
|
|
143
|
+
type: "function";
|
|
144
|
+
name: string;
|
|
145
|
+
description?: string | null;
|
|
146
|
+
strict?: boolean | null;
|
|
147
|
+
parameters: {
|
|
148
|
+
[k: string]: any | null;
|
|
149
|
+
} | null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Tool preliminary result event emitted during generator tool execution
|
|
153
|
+
*/
|
|
154
|
+
export type ToolPreliminaryResultEvent = {
|
|
155
|
+
type: "tool.preliminary_result";
|
|
156
|
+
toolCallId: string;
|
|
157
|
+
result: unknown;
|
|
158
|
+
timestamp: number;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Enhanced stream event types for getFullResponsesStream
|
|
162
|
+
* Extends OpenResponsesStreamEvent with tool preliminary results
|
|
163
|
+
*/
|
|
164
|
+
export type EnhancedResponseStreamEvent = OpenResponsesStreamEvent | ToolPreliminaryResultEvent;
|
|
165
|
+
/**
|
|
166
|
+
* Type guard to check if an event is a tool preliminary result event
|
|
167
|
+
*/
|
|
168
|
+
export declare function isToolPreliminaryResultEvent(event: EnhancedResponseStreamEvent): event is ToolPreliminaryResultEvent;
|
|
169
|
+
/**
|
|
170
|
+
* Tool stream event types for getToolStream
|
|
171
|
+
* Includes both argument deltas and preliminary results
|
|
172
|
+
*/
|
|
173
|
+
export type ToolStreamEvent = {
|
|
174
|
+
type: "delta";
|
|
175
|
+
content: string;
|
|
176
|
+
} | {
|
|
177
|
+
type: "preliminary_result";
|
|
178
|
+
toolCallId: string;
|
|
179
|
+
result: unknown;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Chat stream event types for getFullChatStream
|
|
183
|
+
* Includes content deltas, completion events, and tool preliminary results
|
|
184
|
+
*/
|
|
185
|
+
export type ChatStreamEvent = {
|
|
186
|
+
type: "content.delta";
|
|
187
|
+
delta: string;
|
|
188
|
+
} | {
|
|
189
|
+
type: "message.complete";
|
|
190
|
+
response: any;
|
|
191
|
+
} | {
|
|
192
|
+
type: "tool.preliminary_result";
|
|
193
|
+
toolCallId: string;
|
|
194
|
+
result: unknown;
|
|
195
|
+
} | {
|
|
196
|
+
type: string;
|
|
197
|
+
event: any;
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=tool-types.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool type enum for enhanced tools
|
|
3
|
+
*/
|
|
4
|
+
export var ToolType;
|
|
5
|
+
(function (ToolType) {
|
|
6
|
+
ToolType["Function"] = "function";
|
|
7
|
+
})(ToolType || (ToolType = {}));
|
|
8
|
+
/**
|
|
9
|
+
* Type guard to check if a tool has an execute function
|
|
10
|
+
*/
|
|
11
|
+
export function hasExecuteFunction(tool) {
|
|
12
|
+
return "execute" in tool.function && typeof tool.function.execute === "function";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type guard to check if a tool uses a generator (has eventSchema)
|
|
16
|
+
*/
|
|
17
|
+
export function isGeneratorTool(tool) {
|
|
18
|
+
return "eventSchema" in tool.function;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Type guard to check if a tool is a regular execution tool (not generator)
|
|
22
|
+
*/
|
|
23
|
+
export function isRegularExecuteTool(tool) {
|
|
24
|
+
return hasExecuteFunction(tool) && !isGeneratorTool(tool);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Type guard to check if an event is a tool preliminary result event
|
|
28
|
+
*/
|
|
29
|
+
export function isToolPreliminaryResultEvent(event) {
|
|
30
|
+
return event.type === "tool.preliminary_result";
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=tool-types.js.map
|
package/esm/sdk/sdk.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ import { Models } from "./models.js";
|
|
|
12
12
|
import { OAuth } from "./oauth.js";
|
|
13
13
|
import { ParametersT } from "./parameters.js";
|
|
14
14
|
import { Providers } from "./providers.js";
|
|
15
|
+
import { ResponseWrapper } from "../lib/response-wrapper.js";
|
|
16
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
17
|
+
import { EnhancedTool, MaxToolRounds, ToolType } from "../lib/tool-types.js";
|
|
18
|
+
import * as models from "../models/index.js";
|
|
19
|
+
export { ToolType };
|
|
20
|
+
export type { EnhancedTool, MaxToolRounds };
|
|
15
21
|
export declare class OpenRouter extends ClientSDK {
|
|
16
22
|
private _beta?;
|
|
17
23
|
get beta(): Beta;
|
|
@@ -39,5 +45,9 @@ export declare class OpenRouter extends ClientSDK {
|
|
|
39
45
|
get chat(): Chat;
|
|
40
46
|
private _completions?;
|
|
41
47
|
get completions(): Completions;
|
|
48
|
+
callModel(request: Omit<models.OpenResponsesRequest, "stream" | "tools"> & {
|
|
49
|
+
tools?: EnhancedTool[] | models.OpenResponsesRequest["tools"];
|
|
50
|
+
maxToolRounds?: MaxToolRounds;
|
|
51
|
+
}, options?: RequestOptions): ResponseWrapper;
|
|
42
52
|
}
|
|
43
53
|
//# sourceMappingURL=sdk.d.ts.map
|
package/esm/sdk/sdk.js
CHANGED
|
@@ -15,6 +15,11 @@ import { Models } from "./models.js";
|
|
|
15
15
|
import { OAuth } from "./oauth.js";
|
|
16
16
|
import { ParametersT } from "./parameters.js";
|
|
17
17
|
import { Providers } from "./providers.js";
|
|
18
|
+
// #region imports
|
|
19
|
+
import { callModel as callModelFunc } from "../funcs/callModel.js";
|
|
20
|
+
import { ToolType } from "../lib/tool-types.js";
|
|
21
|
+
export { ToolType };
|
|
22
|
+
// #endregion imports
|
|
18
23
|
export class OpenRouter extends ClientSDK {
|
|
19
24
|
get beta() {
|
|
20
25
|
return (this._beta ?? (this._beta = new Beta(this._options)));
|
|
@@ -55,5 +60,9 @@ export class OpenRouter extends ClientSDK {
|
|
|
55
60
|
get completions() {
|
|
56
61
|
return (this._completions ?? (this._completions = new Completions(this._options)));
|
|
57
62
|
}
|
|
63
|
+
// #region sdk-class-body
|
|
64
|
+
callModel(request, options) {
|
|
65
|
+
return callModelFunc(this, request, options);
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
//# sourceMappingURL=sdk.js.map
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrouter/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
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": [
|
|
@@ -48,11 +48,6 @@
|
|
|
48
48
|
"types": "./esm/models/operations/index.d.ts",
|
|
49
49
|
"default": "./esm/models/operations/index.js"
|
|
50
50
|
},
|
|
51
|
-
"./react-query": {
|
|
52
|
-
"source": "./src/react-query/index.ts",
|
|
53
|
-
"types": "./esm/react-query/index.d.ts",
|
|
54
|
-
"default": "./esm/react-query/index.js"
|
|
55
|
-
},
|
|
56
51
|
"./*.js": {
|
|
57
52
|
"source": "./src/*.ts",
|
|
58
53
|
"types": "./esm/*.d.ts",
|
|
@@ -75,20 +70,11 @@
|
|
|
75
70
|
"prepublishOnly": "npm run build"
|
|
76
71
|
},
|
|
77
72
|
"peerDependencies": {
|
|
78
|
-
|
|
79
|
-
"react": "^18 || ^19",
|
|
80
|
-
"react-dom": "^18 || ^19"
|
|
81
|
-
},
|
|
82
|
-
"peerDependenciesMeta": {
|
|
83
|
-
"@tanstack/react-query": {"optional":true},
|
|
84
|
-
"react": {"optional":true},
|
|
85
|
-
"react-dom": {"optional":true}
|
|
73
|
+
|
|
86
74
|
},
|
|
87
75
|
"devDependencies": {
|
|
88
76
|
"@eslint/js": "^9.19.0",
|
|
89
|
-
"@tanstack/react-query": "^5.61.4",
|
|
90
77
|
"@types/node": "^22.13.12",
|
|
91
|
-
"@types/react": "^18.3.12",
|
|
92
78
|
"dotenv": "^16.4.7",
|
|
93
79
|
"eslint": "^9.19.0",
|
|
94
80
|
"globals": "^15.14.0",
|