@openrouter/sdk 1.5.55 → 1.5.57

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.
Files changed (104) hide show
  1. package/esm/lib/config.d.ts +2 -2
  2. package/esm/lib/config.js +2 -2
  3. package/esm/models/additionaltoolsitem.d.ts +5 -4
  4. package/esm/models/additionaltoolsitem.js +3 -0
  5. package/esm/models/alignmentresponsesrejected.d.ts +4 -1
  6. package/esm/models/alignmentresponsesrejected.js +6 -0
  7. package/esm/models/byokproviderslug.d.ts +1 -0
  8. package/esm/models/byokproviderslug.js +1 -0
  9. package/esm/models/createworkspacerequest.d.ts +1 -0
  10. package/esm/models/createworkspacerequest.js +1 -0
  11. package/esm/models/decisionschoicequestion.d.ts +4 -4
  12. package/esm/models/decisionschoicequestion.js +1 -5
  13. package/esm/models/decisionsnoulquestion.d.ts +12 -12
  14. package/esm/models/decisionsnoulquestion.js +3 -7
  15. package/esm/models/decisionsscorequestion.d.ts +4 -4
  16. package/esm/models/decisionsscorequestion.js +1 -5
  17. package/esm/models/imagegenerationproviderpreferences.d.ts +6 -0
  18. package/esm/models/imagegenerationproviderpreferences.js +1 -0
  19. package/esm/models/imagegenerationrequest.d.ts +51 -4
  20. package/esm/models/imagegenerationrequest.js +32 -1
  21. package/esm/models/index.d.ts +6 -0
  22. package/esm/models/index.js +6 -0
  23. package/esm/models/mcpapprovalrequestitem.d.ts +7 -0
  24. package/esm/models/mcpapprovalrequestitem.js +19 -1
  25. package/esm/models/mcpcallitem.d.ts +17 -1
  26. package/esm/models/mcpcallitem.js +18 -0
  27. package/esm/models/mcpservertool.d.ts +78 -69
  28. package/esm/models/mcpservertool.js +135 -105
  29. package/esm/models/mcpservertoolopenrouter.d.ts +28 -0
  30. package/esm/models/mcpservertoolopenrouter.js +20 -0
  31. package/esm/models/mcpservertoolparameters.d.ts +152 -0
  32. package/esm/models/mcpservertoolparameters.js +134 -0
  33. package/esm/models/openairesponsestoolchoiceunion.d.ts +3 -2
  34. package/esm/models/openairesponsestoolchoiceunion.js +3 -0
  35. package/esm/models/operations/listbyokkeys.d.ts +1 -0
  36. package/esm/models/operations/listbyokkeys.js +1 -0
  37. package/esm/models/outputitemmcpapprovalrequest.d.ts +14 -0
  38. package/esm/models/outputitemmcpapprovalrequest.js +23 -0
  39. package/esm/models/outputitemmcpcall.d.ts +74 -0
  40. package/esm/models/outputitemmcpcall.js +94 -0
  41. package/esm/models/outputitemmcplisttools.d.ts +25 -0
  42. package/esm/models/outputitemmcplisttools.js +37 -0
  43. package/esm/models/outputitems.d.ts +3 -0
  44. package/esm/models/outputitems.js +2 -0
  45. package/esm/models/providername.d.ts +1 -0
  46. package/esm/models/providername.js +1 -0
  47. package/esm/models/provideroptions.d.ts +6 -0
  48. package/esm/models/provideroptions.js +1 -0
  49. package/esm/models/providerresponse.d.ts +1 -0
  50. package/esm/models/providerresponse.js +1 -0
  51. package/esm/models/responsesrequest.d.ts +9 -0
  52. package/esm/models/responsesrequest.js +3 -0
  53. package/esm/models/toolchoicemcp.d.ts +33 -0
  54. package/esm/models/toolchoicemcp.js +42 -0
  55. package/esm/models/toolsearchoutputitem.d.ts +5 -4
  56. package/esm/models/toolsearchoutputitem.js +3 -0
  57. package/esm/models/updateworkspacerequest.d.ts +1 -0
  58. package/esm/models/updateworkspacerequest.js +1 -0
  59. package/esm/models/videogenerationrequest.d.ts +6 -0
  60. package/esm/models/videogenerationrequest.js +1 -0
  61. package/esm/sdk/sdk.d.ts +0 -9
  62. package/esm/sdk/sdk.js +1 -7
  63. package/jsr.json +1 -1
  64. package/package.json +5 -5
  65. package/esm/funcs/call-model.d.ts +0 -67
  66. package/esm/funcs/call-model.js +0 -98
  67. package/esm/lib/anthropic-compat.d.ts +0 -51
  68. package/esm/lib/anthropic-compat.js +0 -222
  69. package/esm/lib/async-params.d.ts +0 -107
  70. package/esm/lib/async-params.js +0 -88
  71. package/esm/lib/chat-compat.d.ts +0 -47
  72. package/esm/lib/chat-compat.js +0 -111
  73. package/esm/lib/claude-constants.d.ts +0 -22
  74. package/esm/lib/claude-constants.js +0 -20
  75. package/esm/lib/claude-type-guards.d.ts +0 -10
  76. package/esm/lib/claude-type-guards.js +0 -70
  77. package/esm/lib/conversation-state.d.ts +0 -63
  78. package/esm/lib/conversation-state.js +0 -210
  79. package/esm/lib/model-result.d.ts +0 -373
  80. package/esm/lib/model-result.js +0 -1414
  81. package/esm/lib/next-turn-params.d.ts +0 -30
  82. package/esm/lib/next-turn-params.js +0 -135
  83. package/esm/lib/reusable-stream.d.ts +0 -39
  84. package/esm/lib/reusable-stream.js +0 -192
  85. package/esm/lib/stop-conditions.d.ts +0 -80
  86. package/esm/lib/stop-conditions.js +0 -104
  87. package/esm/lib/stream-transformers.d.ts +0 -118
  88. package/esm/lib/stream-transformers.js +0 -852
  89. package/esm/lib/stream-type-guards.d.ts +0 -49
  90. package/esm/lib/stream-type-guards.js +0 -85
  91. package/esm/lib/tool-context.d.ts +0 -68
  92. package/esm/lib/tool-context.js +0 -175
  93. package/esm/lib/tool-event-broadcaster.d.ts +0 -44
  94. package/esm/lib/tool-event-broadcaster.js +0 -146
  95. package/esm/lib/tool-executor.d.ts +0 -74
  96. package/esm/lib/tool-executor.js +0 -267
  97. package/esm/lib/tool-orchestrator.d.ts +0 -52
  98. package/esm/lib/tool-orchestrator.js +0 -180
  99. package/esm/lib/tool-types.d.ts +0 -573
  100. package/esm/lib/tool-types.js +0 -80
  101. package/esm/lib/tool.d.ts +0 -108
  102. package/esm/lib/tool.js +0 -74
  103. package/esm/lib/turn-context.d.ts +0 -52
  104. package/esm/lib/turn-context.js +0 -59
@@ -1,70 +0,0 @@
1
- import { ClaudeContentBlockType, NonClaudeMessageRole, } from "./claude-constants.js";
2
- function isRecord(value) {
3
- return value !== null && typeof value === "object" && !Array.isArray(value);
4
- }
5
- function isNonClaudeRole(role) {
6
- return (role === NonClaudeMessageRole.System ||
7
- role === NonClaudeMessageRole.Developer ||
8
- role === NonClaudeMessageRole.Tool);
9
- }
10
- function isClaudeToolResultBlock(block) {
11
- if (!isRecord(block))
12
- return false;
13
- return block["type"] === ClaudeContentBlockType.ToolResult;
14
- }
15
- function isClaudeImageBlockWithSource(block) {
16
- if (!isRecord(block))
17
- return false;
18
- return (block["type"] === ClaudeContentBlockType.Image &&
19
- "source" in block &&
20
- isRecord(block["source"]));
21
- }
22
- function isClaudeToolUseBlockWithId(block) {
23
- if (!isRecord(block))
24
- return false;
25
- return (block["type"] === ClaudeContentBlockType.ToolUse &&
26
- "id" in block &&
27
- typeof block["id"] === "string");
28
- }
29
- function hasClaudeSpecificBlocks(content) {
30
- for (const block of content) {
31
- if (isClaudeToolResultBlock(block))
32
- return true;
33
- if (isClaudeImageBlockWithSource(block))
34
- return true;
35
- if (isClaudeToolUseBlockWithId(block))
36
- return true;
37
- }
38
- return false;
39
- }
40
- /**
41
- * Check if input is in Claude message format
42
- * Uses structural analysis to detect Claude-specific patterns
43
- *
44
- * @param input - Input to check
45
- * @returns True if input appears to be Claude format
46
- */
47
- export function isClaudeStyleMessages(input) {
48
- if (!Array.isArray(input) || input.length === 0) {
49
- return false;
50
- }
51
- for (const msg of input) {
52
- if (!isRecord(msg))
53
- continue;
54
- if (!("role" in msg))
55
- continue;
56
- if ("type" in msg)
57
- continue; // Claude messages don't have top-level "type"
58
- // If we find a non-Claude role, it's not Claude format
59
- if (isNonClaudeRole(msg["role"])) {
60
- return false;
61
- }
62
- // If we find Claude-specific content blocks, it's Claude format
63
- const content = msg["content"];
64
- if (Array.isArray(content) && hasClaudeSpecificBlocks(content)) {
65
- return true;
66
- }
67
- }
68
- return false;
69
- }
70
- //# sourceMappingURL=claude-type-guards.js.map
@@ -1,63 +0,0 @@
1
- import type { FunctionCallOutputItem } from '../models/functioncalloutputitem.js';
2
- import type { InputsUnion, InputsUnion1 } from '../models/inputsunion.js';
3
- import type { OpenResponsesResult } from '../models/openresponsesresult.js';
4
- import type { ConversationState, ParsedToolCall, Tool, TurnContext, UnsentToolResult } from './tool-types.js';
5
- /**
6
- * Generate a unique ID for a conversation
7
- * Uses crypto.randomUUID if available, falls back to timestamp + random
8
- */
9
- export declare function generateConversationId(): string;
10
- /**
11
- * Create an initial conversation state
12
- * @param id - Optional custom ID, generates one if not provided
13
- */
14
- export declare function createInitialState<TTools extends readonly Tool[] = readonly Tool[]>(id?: string): ConversationState<TTools>;
15
- /**
16
- * Update a conversation state with new values
17
- * Automatically updates the updatedAt timestamp
18
- */
19
- export declare function updateState<TTools extends readonly Tool[] = readonly Tool[]>(state: ConversationState<TTools>, updates: Partial<Omit<ConversationState<TTools>, 'id' | 'createdAt' | 'updatedAt'>>): ConversationState<TTools>;
20
- /**
21
- * Append new items to the message history
22
- */
23
- export declare function appendToMessages(current: InputsUnion, newItems: InputsUnion1[]): InputsUnion;
24
- /**
25
- * Check if a tool call requires approval
26
- * @param toolCall - The tool call to check
27
- * @param tools - Available tools
28
- * @param context - Turn context for the approval check
29
- * @param callLevelCheck - Optional call-level approval function (overrides tool-level), can be async
30
- */
31
- export declare function toolRequiresApproval<TTools extends readonly Tool[]>(toolCall: ParsedToolCall<TTools[number]>, tools: TTools, context: TurnContext, callLevelCheck?: (toolCall: ParsedToolCall<TTools[number]>, context: TurnContext) => boolean | Promise<boolean>): Promise<boolean>;
32
- /**
33
- * Partition tool calls into those requiring approval and those that can auto-execute
34
- * @param toolCalls - Tool calls to partition
35
- * @param tools - Available tools
36
- * @param context - Turn context for the approval check
37
- * @param callLevelCheck - Optional call-level approval function (overrides tool-level), can be async
38
- */
39
- export declare function partitionToolCalls<TTools extends readonly Tool[]>(toolCalls: ParsedToolCall<TTools[number]>[], tools: TTools, context: TurnContext, callLevelCheck?: (toolCall: ParsedToolCall<TTools[number]>, context: TurnContext) => boolean | Promise<boolean>): Promise<{
40
- requiresApproval: ParsedToolCall<TTools[number]>[];
41
- autoExecute: ParsedToolCall<TTools[number]>[];
42
- }>;
43
- /**
44
- * Create an unsent tool result from a successful execution
45
- */
46
- export declare function createUnsentResult<TTools extends readonly Tool[] = readonly Tool[]>(callId: string, name: string, output: unknown): UnsentToolResult<TTools>;
47
- /**
48
- * Create an unsent tool result from a rejection
49
- */
50
- export declare function createRejectedResult<TTools extends readonly Tool[] = readonly Tool[]>(callId: string, name: string, reason?: string): UnsentToolResult<TTools>;
51
- /**
52
- * Convert unsent tool results to API format for sending to the model
53
- */
54
- export declare function unsentResultsToAPIFormat(results: UnsentToolResult[]): FunctionCallOutputItem[];
55
- /**
56
- * Extract text content from a response
57
- */
58
- export declare function extractTextFromResponse(response: OpenResponsesResult): string;
59
- /**
60
- * Extract tool calls from a response
61
- */
62
- export declare function extractToolCallsFromResponse<TTools extends readonly Tool[]>(response: OpenResponsesResult): ParsedToolCall<TTools[number]>[];
63
- //# sourceMappingURL=conversation-state.d.ts.map
@@ -1,210 +0,0 @@
1
- import { normalizeInputToArray } from './turn-context.js';
2
- /**
3
- * Type guard to verify an object is a valid UnsentToolResult
4
- */
5
- function isValidUnsentToolResult(obj) {
6
- if (typeof obj !== 'object' || obj === null)
7
- return false;
8
- return ('callId' in obj &&
9
- typeof obj.callId === 'string' &&
10
- 'name' in obj &&
11
- typeof obj.name === 'string' &&
12
- 'output' in obj);
13
- }
14
- /**
15
- * Type guard to verify an object is a valid ParsedToolCall
16
- */
17
- function isValidParsedToolCall(obj) {
18
- if (typeof obj !== 'object' || obj === null)
19
- return false;
20
- return ('id' in obj &&
21
- typeof obj.id === 'string' &&
22
- 'name' in obj &&
23
- typeof obj.name === 'string' &&
24
- 'arguments' in obj);
25
- }
26
- /**
27
- * Generate a unique ID for a conversation
28
- * Uses crypto.randomUUID if available, falls back to timestamp + random
29
- */
30
- export function generateConversationId() {
31
- if (typeof crypto !== 'undefined' && crypto.randomUUID) {
32
- return `conv_${crypto.randomUUID()}`;
33
- }
34
- // Fallback for environments without crypto.randomUUID
35
- return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
36
- }
37
- /**
38
- * Create an initial conversation state
39
- * @param id - Optional custom ID, generates one if not provided
40
- */
41
- export function createInitialState(id) {
42
- const now = Date.now();
43
- return {
44
- id: id ?? generateConversationId(),
45
- messages: [],
46
- status: 'in_progress',
47
- createdAt: now,
48
- updatedAt: now,
49
- };
50
- }
51
- /**
52
- * Update a conversation state with new values
53
- * Automatically updates the updatedAt timestamp
54
- */
55
- export function updateState(state, updates) {
56
- return {
57
- ...state,
58
- ...updates,
59
- updatedAt: Date.now(),
60
- };
61
- }
62
- /**
63
- * Append new items to the message history
64
- */
65
- export function appendToMessages(current, newItems) {
66
- const currentArray = normalizeInputToArray(current);
67
- return [...currentArray, ...newItems];
68
- }
69
- /**
70
- * Check if a tool call requires approval
71
- * @param toolCall - The tool call to check
72
- * @param tools - Available tools
73
- * @param context - Turn context for the approval check
74
- * @param callLevelCheck - Optional call-level approval function (overrides tool-level), can be async
75
- */
76
- export async function toolRequiresApproval(toolCall, tools, context, callLevelCheck) {
77
- // Call-level check takes precedence
78
- if (callLevelCheck) {
79
- return callLevelCheck(toolCall, context);
80
- }
81
- // Fall back to tool-level setting
82
- const tool = tools.find(t => t.function.name === toolCall.name);
83
- if (!tool)
84
- return false;
85
- const requireApproval = tool.function.requireApproval;
86
- // If it's a function, call it with the tool's arguments and context
87
- if (typeof requireApproval === 'function') {
88
- return requireApproval(toolCall.arguments, context);
89
- }
90
- // Otherwise treat as boolean
91
- return requireApproval ?? false;
92
- }
93
- /**
94
- * Partition tool calls into those requiring approval and those that can auto-execute
95
- * @param toolCalls - Tool calls to partition
96
- * @param tools - Available tools
97
- * @param context - Turn context for the approval check
98
- * @param callLevelCheck - Optional call-level approval function (overrides tool-level), can be async
99
- */
100
- export async function partitionToolCalls(toolCalls, tools, context, callLevelCheck) {
101
- const requiresApproval = [];
102
- const autoExecute = [];
103
- for (const tc of toolCalls) {
104
- if (await toolRequiresApproval(tc, tools, context, callLevelCheck)) {
105
- requiresApproval.push(tc);
106
- }
107
- else {
108
- autoExecute.push(tc);
109
- }
110
- }
111
- return { requiresApproval, autoExecute };
112
- }
113
- /**
114
- * Create an unsent tool result from a successful execution
115
- */
116
- export function createUnsentResult(callId, name, output) {
117
- const result = { callId, name, output };
118
- if (!isValidUnsentToolResult(result)) {
119
- throw new Error('Invalid UnsentToolResult structure');
120
- }
121
- return result;
122
- }
123
- /**
124
- * Create an unsent tool result from a rejection
125
- */
126
- export function createRejectedResult(callId, name, reason) {
127
- const result = {
128
- callId,
129
- name,
130
- output: null,
131
- error: reason ?? 'Tool call rejected by user',
132
- };
133
- if (!isValidUnsentToolResult(result)) {
134
- throw new Error('Invalid UnsentToolResult structure');
135
- }
136
- return result;
137
- }
138
- /**
139
- * Convert unsent tool results to API format for sending to the model
140
- */
141
- export function unsentResultsToAPIFormat(results) {
142
- return results.map(r => ({
143
- type: 'function_call_output',
144
- id: `output_${r.callId}`,
145
- callId: r.callId,
146
- output: r.error
147
- ? JSON.stringify({ error: r.error })
148
- : JSON.stringify(r.output),
149
- }));
150
- }
151
- /**
152
- * Extract text content from a response
153
- */
154
- export function extractTextFromResponse(response) {
155
- if (!response.output) {
156
- return '';
157
- }
158
- const outputs = Array.isArray(response.output) ? response.output : [response.output];
159
- const textParts = [];
160
- for (const item of outputs) {
161
- if (item.type === 'message' && 'content' in item && item.content) {
162
- for (const content of item.content) {
163
- if (content.type === 'output_text' && 'text' in content && content.text) {
164
- textParts.push(content.text);
165
- }
166
- }
167
- }
168
- }
169
- return textParts.join('');
170
- }
171
- /**
172
- * Extract tool calls from a response
173
- */
174
- export function extractToolCallsFromResponse(response) {
175
- if (!response.output) {
176
- return [];
177
- }
178
- const outputs = Array.isArray(response.output) ? response.output : [response.output];
179
- const toolCalls = [];
180
- for (const item of outputs) {
181
- if (item.type !== 'function_call' || !('arguments' in item)) {
182
- continue;
183
- }
184
- let parsedArguments;
185
- if (typeof item.arguments === 'string') {
186
- try {
187
- parsedArguments = JSON.parse(item.arguments);
188
- }
189
- catch (error) {
190
- // Log warning and skip malformed tool call, similar to stream-transformers.ts
191
- console.warn(`Failed to parse arguments for tool call "${'name' in item ? item.name : 'unknown'}": ${error instanceof Error ? error.message : String(error)}`);
192
- continue;
193
- }
194
- }
195
- else {
196
- parsedArguments = item.arguments;
197
- }
198
- const toolCall = {
199
- id: ('callId' in item ? item.callId : undefined) ?? item.id ?? '',
200
- name: ('name' in item ? item.name : undefined) ?? '',
201
- arguments: parsedArguments,
202
- };
203
- if (!isValidParsedToolCall(toolCall)) {
204
- throw new Error(`Invalid tool call structure for tool: ${toolCall.name}`);
205
- }
206
- toolCalls.push(toolCall);
207
- }
208
- return toolCalls;
209
- }
210
- //# sourceMappingURL=conversation-state.js.map