@openrouter/sdk 0.3.15 → 0.3.16
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/esm/index.d.ts +2 -2
- package/esm/index.js +1 -1
- package/esm/lib/config.d.ts +2 -2
- package/esm/lib/config.js +2 -2
- package/esm/lib/model-result.d.ts +5 -3
- package/esm/lib/model-result.js +42 -11
- package/esm/lib/tool-executor.js +37 -13
- package/esm/lib/tool-types.d.ts +27 -2
- package/esm/lib/tool-types.js +6 -0
- package/esm/models/outputmodality.d.ts +1 -0
- package/esm/models/outputmodality.js +1 -0
- package/esm/models/publicendpoint.d.ts +8 -0
- package/esm/models/publicendpoint.js +4 -0
- package/esm/models/publicpricing.d.ts +4 -0
- package/esm/models/publicpricing.js +2 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { CallModelInput, CallModelInputWithState, FieldOrAsyncFunction, ResolvedCallModelInput, } from './lib/async-params.js';
|
|
2
2
|
export type { Fetcher, HTTPClientOptions } from './lib/http.js';
|
|
3
|
-
export type { ChatStreamEvent, ConversationState, ConversationStatus, ResponseStreamEvent as EnhancedResponseStreamEvent, HasApprovalTools, InferToolEvent, InferToolEventsUnion, InferToolInput, InferToolOutput, ManualTool, NextTurnParamsContext, NextTurnParamsFunctions, ParsedToolCall, PartialResponse, StateAccessor, StepResult, StopCondition, StopWhen, Tool, ToolApprovalCheck, ToolExecutionResult, ToolExecutionResultUnion, ToolHasApproval, ToolPreliminaryResultEvent, ToolStreamEvent, ToolWithExecute, ToolWithGenerator, TurnContext, TypedToolCall, TypedToolCallUnion, UnsentToolResult, Warning, } from './lib/tool-types.js';
|
|
3
|
+
export type { ChatStreamEvent, ConversationState, ConversationStatus, ResponseStreamEvent as EnhancedResponseStreamEvent, HasApprovalTools, InferToolEvent, InferToolEventsUnion, InferToolInput, InferToolOutput, InferToolOutputsUnion, ManualTool, NextTurnParamsContext, NextTurnParamsFunctions, ParsedToolCall, PartialResponse, StateAccessor, StepResult, StopCondition, StopWhen, Tool, ToolApprovalCheck, ToolExecutionResult, ToolExecutionResultUnion, ToolHasApproval, ToolPreliminaryResultEvent, ToolResultEvent, ToolStreamEvent, ToolWithExecute, ToolWithGenerator, TurnContext, TypedToolCall, TypedToolCallUnion, UnsentToolResult, Warning, } from './lib/tool-types.js';
|
|
4
4
|
export type { BuildTurnContextOptions } from './lib/turn-context.js';
|
|
5
5
|
export type { ClaudeBase64ImageSource, ClaudeCacheControl, ClaudeCitationCharLocation, ClaudeCitationContentBlockLocation, ClaudeCitationPageLocation, ClaudeCitationSearchResultLocation, ClaudeCitationWebSearchResultLocation, ClaudeContentBlock, ClaudeContentBlockParam, ClaudeImageBlockParam, ClaudeMessage, ClaudeMessageParam, ClaudeRedactedThinkingBlock, ClaudeServerToolUseBlock, ClaudeStopReason, ClaudeTextBlock, ClaudeTextBlockParam, ClaudeTextCitation, ClaudeThinkingBlock, ClaudeToolResultBlockParam, ClaudeToolUseBlock, ClaudeToolUseBlockParam, ClaudeURLImageSource, ClaudeUsage, } from './models/claude-message.js';
|
|
6
6
|
export { fromClaudeMessages, toClaudeMessage } from './lib/anthropic-compat.js';
|
|
@@ -15,7 +15,7 @@ export { applyNextTurnParamsToRequest, buildNextTurnParamsContext, executeNextTu
|
|
|
15
15
|
export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed, stepCountIs, } from './lib/stop-conditions.js';
|
|
16
16
|
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
17
17
|
export { tool } from './lib/tool.js';
|
|
18
|
-
export { hasApprovalRequiredTools, hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolPreliminaryResultEvent, toolHasApprovalConfigured, ToolType, } from './lib/tool-types.js';
|
|
18
|
+
export { hasApprovalRequiredTools, hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolPreliminaryResultEvent, isToolResultEvent, toolHasApprovalConfigured, ToolType, } from './lib/tool-types.js';
|
|
19
19
|
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
20
20
|
export { appendToMessages, createInitialState, createRejectedResult, createUnsentResult, generateConversationId, partitionToolCalls, toolRequiresApproval, updateState, } from './lib/conversation-state.js';
|
|
21
21
|
export { ToolEventBroadcaster } from './lib/tool-event-broadcaster.js';
|
package/esm/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed
|
|
|
18
18
|
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
19
19
|
// Tool creation helpers
|
|
20
20
|
export { tool } from './lib/tool.js';
|
|
21
|
-
export { hasApprovalRequiredTools, hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolPreliminaryResultEvent, toolHasApprovalConfigured, ToolType, } from './lib/tool-types.js';
|
|
21
|
+
export { hasApprovalRequiredTools, hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolPreliminaryResultEvent, isToolResultEvent, toolHasApprovalConfigured, ToolType, } from './lib/tool-types.js';
|
|
22
22
|
// Turn context helpers
|
|
23
23
|
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
24
24
|
// Conversation state helpers
|
package/esm/lib/config.d.ts
CHANGED
|
@@ -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.3.
|
|
48
|
+
readonly sdkVersion: "0.3.16";
|
|
49
49
|
readonly genVersion: "2.788.4";
|
|
50
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.3.
|
|
50
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.3.16 2.788.4 1.0.0 @openrouter/sdk";
|
|
51
51
|
};
|
|
52
52
|
//# sourceMappingURL=config.d.ts.map
|
package/esm/lib/config.js
CHANGED
|
@@ -26,8 +26,8 @@ export function serverURLFromOptions(options) {
|
|
|
26
26
|
export const SDK_METADATA = {
|
|
27
27
|
language: "typescript",
|
|
28
28
|
openapiDocVersion: "1.0.0",
|
|
29
|
-
sdkVersion: "0.3.
|
|
29
|
+
sdkVersion: "0.3.16",
|
|
30
30
|
genVersion: "2.788.4",
|
|
31
|
-
userAgent: "speakeasy-sdk/typescript 0.3.
|
|
31
|
+
userAgent: "speakeasy-sdk/typescript 0.3.16 2.788.4 1.0.0 @openrouter/sdk",
|
|
32
32
|
};
|
|
33
33
|
//# sourceMappingURL=config.js.map
|
|
@@ -2,7 +2,7 @@ import type { OpenRouterCore } from '../core.js';
|
|
|
2
2
|
import type * as models from '../models/index.js';
|
|
3
3
|
import type { CallModelInput } from './async-params.js';
|
|
4
4
|
import type { RequestOptions } from './sdks.js';
|
|
5
|
-
import type { ConversationState, ResponseStreamEvent, InferToolEventsUnion, ParsedToolCall, StateAccessor, StopWhen, Tool, ToolStreamEvent, TurnContext } from './tool-types.js';
|
|
5
|
+
import type { ConversationState, ResponseStreamEvent, InferToolEventsUnion, InferToolOutputsUnion, ParsedToolCall, StateAccessor, StopWhen, Tool, ToolStreamEvent, TurnContext } from './tool-types.js';
|
|
6
6
|
export interface GetResponseOptions<TTools extends readonly Tool[]> {
|
|
7
7
|
request: CallModelInput<TTools>;
|
|
8
8
|
client: OpenRouterCore;
|
|
@@ -57,6 +57,7 @@ export declare class ModelResult<TTools extends readonly Tool[]> {
|
|
|
57
57
|
/**
|
|
58
58
|
* Get or create the tool event broadcaster (lazy initialization).
|
|
59
59
|
* Ensures only one broadcaster exists for the lifetime of this ModelResult.
|
|
60
|
+
* Broadcasts both preliminary results and final tool results.
|
|
60
61
|
*/
|
|
61
62
|
private ensureBroadcaster;
|
|
62
63
|
/**
|
|
@@ -139,6 +140,7 @@ export declare class ModelResult<TTools extends readonly Tool[]> {
|
|
|
139
140
|
/**
|
|
140
141
|
* Execute all tools in a single round.
|
|
141
142
|
* Runs each tool call sequentially and collects results for API submission.
|
|
143
|
+
* Emits tool.result events after each tool execution completes.
|
|
142
144
|
*
|
|
143
145
|
* @param toolCalls - The tool calls to execute
|
|
144
146
|
* @param turnContext - The current turn context
|
|
@@ -234,9 +236,9 @@ export declare class ModelResult<TTools extends readonly Tool[]> {
|
|
|
234
236
|
/**
|
|
235
237
|
* Stream all response events as they arrive.
|
|
236
238
|
* Multiple consumers can iterate over this stream concurrently.
|
|
237
|
-
* Preliminary tool results are streamed in REAL-TIME as generator tools yield.
|
|
239
|
+
* Preliminary tool results and tool results are streamed in REAL-TIME as generator tools yield.
|
|
238
240
|
*/
|
|
239
|
-
getFullResponsesStream(): AsyncIterableIterator<ResponseStreamEvent<InferToolEventsUnion<TTools>>>;
|
|
241
|
+
getFullResponsesStream(): AsyncIterableIterator<ResponseStreamEvent<InferToolEventsUnion<TTools>, InferToolOutputsUnion<TTools>>>;
|
|
240
242
|
/**
|
|
241
243
|
* Stream only text deltas as they arrive.
|
|
242
244
|
* This filters the full event stream to only yield text content.
|
package/esm/lib/model-result.js
CHANGED
|
@@ -93,6 +93,7 @@ export class ModelResult {
|
|
|
93
93
|
/**
|
|
94
94
|
* Get or create the tool event broadcaster (lazy initialization).
|
|
95
95
|
* Ensures only one broadcaster exists for the lifetime of this ModelResult.
|
|
96
|
+
* Broadcasts both preliminary results and final tool results.
|
|
96
97
|
*/
|
|
97
98
|
ensureBroadcaster() {
|
|
98
99
|
if (!this.toolEventBroadcaster) {
|
|
@@ -300,6 +301,7 @@ export class ModelResult {
|
|
|
300
301
|
/**
|
|
301
302
|
* Execute all tools in a single round.
|
|
302
303
|
* Runs each tool call sequentially and collects results for API submission.
|
|
304
|
+
* Emits tool.result events after each tool execution completes.
|
|
303
305
|
*
|
|
304
306
|
* @param toolCalls - The tool calls to execute
|
|
305
307
|
* @param turnContext - The current turn context
|
|
@@ -311,17 +313,33 @@ export class ModelResult {
|
|
|
311
313
|
const tool = this.options.tools?.find((t) => t.function.name === toolCall.name);
|
|
312
314
|
if (!tool || !hasExecuteFunction(tool))
|
|
313
315
|
continue;
|
|
316
|
+
// Track preliminary results for this specific tool call
|
|
317
|
+
const preliminaryResultsForCall = [];
|
|
314
318
|
// Create callback for real-time preliminary results
|
|
315
319
|
const onPreliminaryResult = this.toolEventBroadcaster
|
|
316
320
|
? (callId, resultValue) => {
|
|
321
|
+
// Track preliminary results for the tool.result event
|
|
322
|
+
const typedResult = resultValue;
|
|
323
|
+
preliminaryResultsForCall.push(typedResult);
|
|
324
|
+
// Emit preliminary result event
|
|
317
325
|
this.toolEventBroadcaster?.push({
|
|
318
326
|
type: 'preliminary_result',
|
|
319
327
|
toolCallId: callId,
|
|
320
|
-
result:
|
|
328
|
+
result: typedResult,
|
|
321
329
|
});
|
|
322
330
|
}
|
|
323
331
|
: undefined;
|
|
324
332
|
const result = await executeTool(tool, toolCall, turnContext, onPreliminaryResult);
|
|
333
|
+
// Emit tool.result event with final result and any preliminary results
|
|
334
|
+
if (this.toolEventBroadcaster) {
|
|
335
|
+
const toolResultEvent = {
|
|
336
|
+
type: 'tool_result',
|
|
337
|
+
toolCallId: toolCall.id,
|
|
338
|
+
result: (result.error ? { error: result.error.message } : result.result),
|
|
339
|
+
...(preliminaryResultsForCall.length > 0 && { preliminaryResults: preliminaryResultsForCall }),
|
|
340
|
+
};
|
|
341
|
+
this.toolEventBroadcaster.push(toolResultEvent);
|
|
342
|
+
}
|
|
325
343
|
toolResults.push({
|
|
326
344
|
type: 'function_call_output',
|
|
327
345
|
id: `output_${toolCall.id}`,
|
|
@@ -799,7 +817,7 @@ export class ModelResult {
|
|
|
799
817
|
/**
|
|
800
818
|
* Stream all response events as they arrive.
|
|
801
819
|
* Multiple consumers can iterate over this stream concurrently.
|
|
802
|
-
* Preliminary tool results are streamed in REAL-TIME as generator tools yield.
|
|
820
|
+
* Preliminary tool results and tool results are streamed in REAL-TIME as generator tools yield.
|
|
803
821
|
*/
|
|
804
822
|
getFullResponsesStream() {
|
|
805
823
|
return async function* () {
|
|
@@ -819,14 +837,25 @@ export class ModelResult {
|
|
|
819
837
|
for await (const event of consumer) {
|
|
820
838
|
yield event;
|
|
821
839
|
}
|
|
822
|
-
// Yield tool
|
|
840
|
+
// Yield tool events as they arrive (real-time!)
|
|
823
841
|
for await (const event of toolEventConsumer) {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
842
|
+
if (event.type === 'preliminary_result') {
|
|
843
|
+
yield {
|
|
844
|
+
type: 'tool.preliminary_result',
|
|
845
|
+
toolCallId: event.toolCallId,
|
|
846
|
+
result: event.result,
|
|
847
|
+
timestamp: Date.now(),
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
else if (event.type === 'tool_result') {
|
|
851
|
+
yield {
|
|
852
|
+
type: 'tool.result',
|
|
853
|
+
toolCallId: event.toolCallId,
|
|
854
|
+
result: event.result,
|
|
855
|
+
timestamp: Date.now(),
|
|
856
|
+
...(event.preliminaryResults && { preliminaryResults: event.preliminaryResults }),
|
|
857
|
+
};
|
|
858
|
+
}
|
|
830
859
|
}
|
|
831
860
|
// Ensure execution completed (handles errors)
|
|
832
861
|
await executionPromise;
|
|
@@ -916,9 +945,11 @@ export class ModelResult {
|
|
|
916
945
|
content: delta,
|
|
917
946
|
};
|
|
918
947
|
}
|
|
919
|
-
// Yield
|
|
948
|
+
// Yield only preliminary_result events (filter out tool_result events)
|
|
920
949
|
for await (const event of toolEventConsumer) {
|
|
921
|
-
|
|
950
|
+
if (event.type === 'preliminary_result') {
|
|
951
|
+
yield event;
|
|
952
|
+
}
|
|
922
953
|
}
|
|
923
954
|
// Ensure execution completed (handles errors)
|
|
924
955
|
await executionPromise;
|
package/esm/lib/tool-executor.js
CHANGED
|
@@ -87,6 +87,14 @@ export function validateToolInput(schema, args) {
|
|
|
87
87
|
export function validateToolOutput(schema, result) {
|
|
88
88
|
return z4.parse(schema, result);
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Try to validate a value against a Zod schema without throwing
|
|
92
|
+
* @returns true if validation succeeds, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
function tryValidate(schema, value) {
|
|
95
|
+
const result = z4.safeParse(schema, value);
|
|
96
|
+
return result.success;
|
|
97
|
+
}
|
|
90
98
|
/**
|
|
91
99
|
* Parse tool call arguments from JSON string
|
|
92
100
|
*/
|
|
@@ -150,29 +158,45 @@ export async function executeGeneratorTool(tool, toolCall, context, onPreliminar
|
|
|
150
158
|
// Validate input - the schema validation ensures type safety at runtime
|
|
151
159
|
// The inputSchema's inferred type matches the execute function's parameter type by construction
|
|
152
160
|
const validatedInput = validateToolInput(tool.function.inputSchema, toolCall.arguments);
|
|
153
|
-
//
|
|
161
|
+
// Stream preliminary results in realtime
|
|
162
|
+
// Final result is identified by: matches outputSchema BUT NOT eventSchema
|
|
163
|
+
// All other yields are preliminary results (validated against eventSchema)
|
|
164
|
+
// If no explicit final result is found, the last emitted value is used as the final result
|
|
154
165
|
const preliminaryResults = [];
|
|
155
|
-
let
|
|
166
|
+
let finalResult = undefined;
|
|
167
|
+
let hasFinalResult = false;
|
|
168
|
+
let lastEmittedValue = undefined;
|
|
156
169
|
let hasEmittedValue = false;
|
|
157
170
|
for await (const event of tool.function.execute(validatedInput, context)) {
|
|
171
|
+
lastEmittedValue = event;
|
|
158
172
|
hasEmittedValue = true;
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
// Try to determine if this is the final result:
|
|
174
|
+
// It must match outputSchema but NOT match eventSchema
|
|
175
|
+
const matchesOutputSchema = tryValidate(tool.function.outputSchema, event);
|
|
176
|
+
const matchesEventSchema = tryValidate(tool.function.eventSchema, event);
|
|
177
|
+
if (matchesOutputSchema && !matchesEventSchema && !hasFinalResult) {
|
|
178
|
+
// This is the final result - matches output but not event schema
|
|
179
|
+
finalResult = validateToolOutput(tool.function.outputSchema, event);
|
|
180
|
+
hasFinalResult = true;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// This is a preliminary result - validate against eventSchema and emit in realtime
|
|
184
|
+
const validatedPreliminary = validateToolOutput(tool.function.eventSchema, event);
|
|
185
|
+
preliminaryResults.push(validatedPreliminary);
|
|
186
|
+
if (onPreliminaryResult) {
|
|
187
|
+
onPreliminaryResult(toolCall.id, validatedPreliminary);
|
|
188
|
+
}
|
|
166
189
|
}
|
|
167
190
|
}
|
|
168
191
|
// Generator must emit at least one value
|
|
169
192
|
if (!hasEmittedValue) {
|
|
170
193
|
throw new Error(`Generator tool "${toolCall.name}" completed without emitting any values`);
|
|
171
194
|
}
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
195
|
+
// If no explicit final result was found (no yield matched outputSchema but not eventSchema),
|
|
196
|
+
// use the last emitted value as the final result
|
|
197
|
+
if (!hasFinalResult) {
|
|
198
|
+
finalResult = validateToolOutput(tool.function.outputSchema, lastEmittedValue);
|
|
199
|
+
}
|
|
176
200
|
return {
|
|
177
201
|
toolCallId: toolCall.id,
|
|
178
202
|
toolName: toolCall.name,
|
package/esm/lib/tool-types.d.ts
CHANGED
|
@@ -175,6 +175,13 @@ export type TypedToolCallUnion<T extends readonly Tool[]> = {
|
|
|
175
175
|
export type ToolExecutionResultUnion<T extends readonly Tool[]> = {
|
|
176
176
|
[K in keyof T]: T[K] extends Tool ? ToolExecutionResult<T[K]> : never;
|
|
177
177
|
}[number];
|
|
178
|
+
/**
|
|
179
|
+
* Union of output types for all tools in a tuple
|
|
180
|
+
* Used for typing tool result events
|
|
181
|
+
*/
|
|
182
|
+
export type InferToolOutputsUnion<T extends readonly Tool[]> = {
|
|
183
|
+
[K in keyof T]: T[K] extends Tool ? InferToolOutput<T[K]> : never;
|
|
184
|
+
}[number];
|
|
178
185
|
/**
|
|
179
186
|
* Extracts the event type from a generator tool definition
|
|
180
187
|
* Returns `never` for non-generator tools
|
|
@@ -300,16 +307,34 @@ export type ToolPreliminaryResultEvent<TEvent = unknown> = {
|
|
|
300
307
|
result: TEvent;
|
|
301
308
|
timestamp: number;
|
|
302
309
|
};
|
|
310
|
+
/**
|
|
311
|
+
* Tool result event emitted when a tool execution completes
|
|
312
|
+
* Contains the final result and any preliminary results that were emitted
|
|
313
|
+
* @template TResult - The result type from the tool's outputSchema
|
|
314
|
+
* @template TPreliminaryResults - The event type from generator tools' eventSchema
|
|
315
|
+
*/
|
|
316
|
+
export type ToolResultEvent<TResult = unknown, TPreliminaryResults = unknown> = {
|
|
317
|
+
type: 'tool.result';
|
|
318
|
+
toolCallId: string;
|
|
319
|
+
result: TResult;
|
|
320
|
+
timestamp: number;
|
|
321
|
+
preliminaryResults?: TPreliminaryResults[];
|
|
322
|
+
};
|
|
303
323
|
/**
|
|
304
324
|
* Enhanced stream event types for getFullResponsesStream
|
|
305
|
-
* Extends OpenResponsesStreamEvent with tool preliminary results
|
|
325
|
+
* Extends OpenResponsesStreamEvent with tool preliminary results and tool results
|
|
306
326
|
* @template TEvent - The event type from generator tools
|
|
327
|
+
* @template TResult - The result type from tool execution
|
|
307
328
|
*/
|
|
308
|
-
export type ResponseStreamEvent<TEvent = unknown> = OpenResponsesStreamEvent | ToolPreliminaryResultEvent<TEvent>;
|
|
329
|
+
export type ResponseStreamEvent<TEvent = unknown, TResult = unknown> = OpenResponsesStreamEvent | ToolPreliminaryResultEvent<TEvent> | ToolResultEvent<TResult, TEvent>;
|
|
309
330
|
/**
|
|
310
331
|
* Type guard to check if an event is a tool preliminary result event
|
|
311
332
|
*/
|
|
312
333
|
export declare function isToolPreliminaryResultEvent<TEvent = unknown>(event: ResponseStreamEvent<TEvent>): event is ToolPreliminaryResultEvent<TEvent>;
|
|
334
|
+
/**
|
|
335
|
+
* Type guard to check if an event is a tool result event
|
|
336
|
+
*/
|
|
337
|
+
export declare function isToolResultEvent<TResult = unknown, TPreliminaryResults = unknown>(event: ResponseStreamEvent<TPreliminaryResults, TResult>): event is ToolResultEvent<TResult, TPreliminaryResults>;
|
|
313
338
|
/**
|
|
314
339
|
* Tool stream event types for getToolStream
|
|
315
340
|
* Includes both argument deltas and preliminary results
|
package/esm/lib/tool-types.js
CHANGED
|
@@ -35,6 +35,12 @@ export function isManualTool(tool) {
|
|
|
35
35
|
export function isToolPreliminaryResultEvent(event) {
|
|
36
36
|
return event.type === 'tool.preliminary_result';
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Type guard to check if an event is a tool result event
|
|
40
|
+
*/
|
|
41
|
+
export function isToolResultEvent(event) {
|
|
42
|
+
return event.type === 'tool.result';
|
|
43
|
+
}
|
|
38
44
|
/**
|
|
39
45
|
* Type guard to check if a tool has approval configured at runtime
|
|
40
46
|
*/
|
|
@@ -35,6 +35,10 @@ export type Pricing = {
|
|
|
35
35
|
* A value in string format that is a large number
|
|
36
36
|
*/
|
|
37
37
|
audio?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* A value in string format that is a large number
|
|
40
|
+
*/
|
|
41
|
+
audioOutput?: string | undefined;
|
|
38
42
|
/**
|
|
39
43
|
* A value in string format that is a large number
|
|
40
44
|
*/
|
|
@@ -74,6 +78,10 @@ export type PublicEndpointQuantization = OpenEnum<typeof PublicEndpointQuantizat
|
|
|
74
78
|
*/
|
|
75
79
|
export type PublicEndpoint = {
|
|
76
80
|
name: string;
|
|
81
|
+
/**
|
|
82
|
+
* The unique identifier for the model (permaslug)
|
|
83
|
+
*/
|
|
84
|
+
modelId: string;
|
|
77
85
|
modelName: string;
|
|
78
86
|
contextLength: number;
|
|
79
87
|
pricing: Pricing;
|
|
@@ -30,6 +30,7 @@ export const Pricing$inboundSchema = z.object({
|
|
|
30
30
|
image_token: z.string().optional(),
|
|
31
31
|
image_output: z.string().optional(),
|
|
32
32
|
audio: z.string().optional(),
|
|
33
|
+
audio_output: z.string().optional(),
|
|
33
34
|
input_audio_cache: z.string().optional(),
|
|
34
35
|
web_search: z.string().optional(),
|
|
35
36
|
internal_reasoning: z.string().optional(),
|
|
@@ -40,6 +41,7 @@ export const Pricing$inboundSchema = z.object({
|
|
|
40
41
|
return remap$(v, {
|
|
41
42
|
"image_token": "imageToken",
|
|
42
43
|
"image_output": "imageOutput",
|
|
44
|
+
"audio_output": "audioOutput",
|
|
43
45
|
"input_audio_cache": "inputAudioCache",
|
|
44
46
|
"web_search": "webSearch",
|
|
45
47
|
"internal_reasoning": "internalReasoning",
|
|
@@ -55,6 +57,7 @@ export const PublicEndpointQuantization$inboundSchema = openEnums.inboundSchema(
|
|
|
55
57
|
/** @internal */
|
|
56
58
|
export const PublicEndpoint$inboundSchema = z.object({
|
|
57
59
|
name: z.string(),
|
|
60
|
+
model_id: z.string(),
|
|
58
61
|
model_name: z.string(),
|
|
59
62
|
context_length: z.number(),
|
|
60
63
|
pricing: z.lazy(() => Pricing$inboundSchema),
|
|
@@ -71,6 +74,7 @@ export const PublicEndpoint$inboundSchema = z.object({
|
|
|
71
74
|
throughput_last_30m: z.nullable(PercentileStats$inboundSchema),
|
|
72
75
|
}).transform((v) => {
|
|
73
76
|
return remap$(v, {
|
|
77
|
+
"model_id": "modelId",
|
|
74
78
|
"model_name": "modelName",
|
|
75
79
|
"context_length": "contextLength",
|
|
76
80
|
"provider_name": "providerName",
|
|
@@ -33,6 +33,10 @@ export type PublicPricing = {
|
|
|
33
33
|
* A value in string format that is a large number
|
|
34
34
|
*/
|
|
35
35
|
audio?: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* A value in string format that is a large number
|
|
38
|
+
*/
|
|
39
|
+
audioOutput?: string | undefined;
|
|
36
40
|
/**
|
|
37
41
|
* A value in string format that is a large number
|
|
38
42
|
*/
|
|
@@ -15,6 +15,7 @@ export const PublicPricing$inboundSchema = z
|
|
|
15
15
|
image_token: z.string().optional(),
|
|
16
16
|
image_output: z.string().optional(),
|
|
17
17
|
audio: z.string().optional(),
|
|
18
|
+
audio_output: z.string().optional(),
|
|
18
19
|
input_audio_cache: z.string().optional(),
|
|
19
20
|
web_search: z.string().optional(),
|
|
20
21
|
internal_reasoning: z.string().optional(),
|
|
@@ -25,6 +26,7 @@ export const PublicPricing$inboundSchema = z
|
|
|
25
26
|
return remap$(v, {
|
|
26
27
|
"image_token": "imageToken",
|
|
27
28
|
"image_output": "imageOutput",
|
|
29
|
+
"audio_output": "audioOutput",
|
|
28
30
|
"input_audio_cache": "inputAudioCache",
|
|
29
31
|
"web_search": "webSearch",
|
|
30
32
|
"internal_reasoning": "internalReasoning",
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrouter/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16",
|
|
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": [
|