@openrouter/sdk 0.1.27 → 0.2.6

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 (143) hide show
  1. package/biome.json +171 -0
  2. package/esm/funcs/callModel.d.ts +7 -7
  3. package/esm/funcs/callModel.js +35 -23
  4. package/esm/funcs/oAuthCreateAuthorizationUrl.d.ts +3 -3
  5. package/esm/funcs/oAuthCreateAuthorizationUrl.js +30 -14
  6. package/esm/funcs/oAuthCreateSHA256CodeChallenge.d.ts +2 -2
  7. package/esm/funcs/oAuthCreateSHA256CodeChallenge.js +13 -12
  8. package/esm/hooks/registration.d.ts +2 -2
  9. package/esm/hooks/registration.js +1 -2
  10. package/esm/lib/config.d.ts +3 -3
  11. package/esm/lib/config.js +3 -3
  12. package/esm/lib/encodings.d.ts +1 -0
  13. package/esm/lib/encodings.js +12 -1
  14. package/esm/lib/response-wrapper.d.ts +5 -5
  15. package/esm/lib/response-wrapper.js +76 -55
  16. package/esm/lib/reusable-stream.js +26 -7
  17. package/esm/lib/stream-transformers.d.ts +3 -3
  18. package/esm/lib/stream-transformers.js +43 -41
  19. package/esm/lib/tool-executor.d.ts +9 -9
  20. package/esm/lib/tool-executor.js +9 -9
  21. package/esm/lib/tool-orchestrator.d.ts +3 -3
  22. package/esm/lib/tool-orchestrator.js +6 -8
  23. package/esm/lib/tool-types.d.ts +26 -25
  24. package/esm/lib/tool-types.js +3 -3
  25. package/esm/models/chatcompletionfinishreason.d.ts +13 -0
  26. package/esm/models/chatcompletionfinishreason.js +14 -0
  27. package/esm/models/chatgenerationparams.d.ts +4 -4
  28. package/esm/models/chatgenerationparams.js +4 -4
  29. package/esm/models/chatmessagecontentitem.d.ts +2 -19
  30. package/esm/models/chatmessagecontentitem.js +6 -9
  31. package/esm/models/chatmessagecontentitemcachecontrol.d.ts +29 -0
  32. package/esm/models/chatmessagecontentitemcachecontrol.js +33 -0
  33. package/esm/models/chatmessagecontentitemtext.d.ts +3 -0
  34. package/esm/models/chatmessagecontentitemtext.js +12 -0
  35. package/esm/models/chatmessagecontentitemvideo.d.ts +23 -11
  36. package/esm/models/chatmessagecontentitemvideo.js +24 -11
  37. package/esm/models/chatresponsechoice.d.ts +1 -21
  38. package/esm/models/chatresponsechoice.js +1 -25
  39. package/esm/models/chatstreamingchoice.d.ts +16 -0
  40. package/esm/models/chatstreamingchoice.js +24 -0
  41. package/esm/models/chatstreamingresponsechunk.d.ts +1 -1
  42. package/esm/models/chatstreamingresponsechunk.js +1 -1
  43. package/esm/models/completionchoice.d.ts +2 -0
  44. package/esm/models/completionchoice.js +3 -0
  45. package/esm/models/completioncreateparams.d.ts +4 -4
  46. package/esm/models/completioncreateparams.js +4 -4
  47. package/esm/models/completionresponse.d.ts +1 -0
  48. package/esm/models/completionresponse.js +1 -0
  49. package/esm/models/filecitation.d.ts +2 -11
  50. package/esm/models/filecitation.js +2 -9
  51. package/esm/models/filepath.d.ts +2 -11
  52. package/esm/models/filepath.js +2 -10
  53. package/esm/models/index.d.ts +3 -2
  54. package/esm/models/index.js +3 -2
  55. package/esm/models/message.d.ts +2 -2
  56. package/esm/models/message.js +1 -1
  57. package/esm/models/openairesponsesannotation.d.ts +2 -2
  58. package/esm/models/openairesponsesannotation.js +2 -2
  59. package/esm/models/openairesponsesinputunion.d.ts +5 -45
  60. package/esm/models/openairesponsesinputunion.js +20 -20
  61. package/esm/models/openairesponsesrefusalcontent.d.ts +2 -11
  62. package/esm/models/openairesponsesrefusalcontent.js +2 -9
  63. package/esm/models/openresponseseasyinputmessage.d.ts +6 -54
  64. package/esm/models/openresponseseasyinputmessage.js +12 -12
  65. package/esm/models/openresponseserrorevent.d.ts +1 -8
  66. package/esm/models/openresponseserrorevent.js +1 -6
  67. package/esm/models/openresponsesimagegencallcompleted.d.ts +1 -8
  68. package/esm/models/openresponsesimagegencallcompleted.js +1 -6
  69. package/esm/models/openresponsesimagegencallgenerating.d.ts +1 -8
  70. package/esm/models/openresponsesimagegencallgenerating.js +1 -6
  71. package/esm/models/openresponsesimagegencallinprogress.d.ts +1 -8
  72. package/esm/models/openresponsesimagegencallinprogress.js +1 -6
  73. package/esm/models/openresponsesimagegencallpartialimage.d.ts +1 -8
  74. package/esm/models/openresponsesimagegencallpartialimage.js +1 -6
  75. package/esm/models/openresponsesinputmessageitem.d.ts +4 -36
  76. package/esm/models/openresponsesinputmessageitem.js +8 -8
  77. package/esm/models/openresponsesnonstreamingresponse.d.ts +1 -7
  78. package/esm/models/openresponsesnonstreamingresponse.js +1 -6
  79. package/esm/models/openresponsesreasoningdeltaevent.d.ts +1 -8
  80. package/esm/models/openresponsesreasoningdeltaevent.js +1 -6
  81. package/esm/models/openresponsesreasoningdoneevent.d.ts +1 -8
  82. package/esm/models/openresponsesreasoningdoneevent.js +1 -6
  83. package/esm/models/openresponsesreasoningsummarypartaddedevent.d.ts +1 -8
  84. package/esm/models/openresponsesreasoningsummarypartaddedevent.js +1 -6
  85. package/esm/models/openresponsesreasoningsummarytextdeltaevent.d.ts +1 -8
  86. package/esm/models/openresponsesreasoningsummarytextdeltaevent.js +1 -6
  87. package/esm/models/openresponsesreasoningsummarytextdoneevent.d.ts +1 -8
  88. package/esm/models/openresponsesreasoningsummarytextdoneevent.js +1 -6
  89. package/esm/models/openresponsesrequest.d.ts +26 -44
  90. package/esm/models/openresponsesrequest.js +15 -32
  91. package/esm/models/openresponsesstreamevent.d.ts +30 -125
  92. package/esm/models/openresponsesstreamevent.js +34 -119
  93. package/esm/models/openresponseswebsearch20250826tool.d.ts +2 -11
  94. package/esm/models/openresponseswebsearch20250826tool.js +2 -9
  95. package/esm/models/openresponseswebsearchpreview20250311tool.d.ts +2 -11
  96. package/esm/models/openresponseswebsearchpreview20250311tool.js +2 -9
  97. package/esm/models/openresponseswebsearchpreviewtool.d.ts +2 -11
  98. package/esm/models/openresponseswebsearchpreviewtool.js +2 -9
  99. package/esm/models/openresponseswebsearchtool.d.ts +2 -11
  100. package/esm/models/openresponseswebsearchtool.js +2 -9
  101. package/esm/models/operations/createembeddings.d.ts +4 -16
  102. package/esm/models/operations/createembeddings.js +2 -13
  103. package/esm/models/operations/getcredits.d.ts +16 -1
  104. package/esm/models/operations/getcredits.js +17 -1
  105. package/esm/models/operations/getparameters.d.ts +5 -1
  106. package/esm/models/operations/getparameters.js +5 -1
  107. package/esm/models/providername.d.ts +5 -1
  108. package/esm/models/providername.js +5 -1
  109. package/esm/models/responseformattextconfig.d.ts +2 -2
  110. package/esm/models/responseformattextconfig.js +2 -2
  111. package/esm/models/responseinputaudio.d.ts +3 -11
  112. package/esm/models/responseinputaudio.js +2 -9
  113. package/esm/models/responseinputfile.d.ts +2 -11
  114. package/esm/models/responseinputfile.js +2 -9
  115. package/esm/models/responseinputimage.d.ts +3 -11
  116. package/esm/models/responseinputimage.js +2 -9
  117. package/esm/models/responseinputtext.d.ts +2 -11
  118. package/esm/models/responseinputtext.js +2 -9
  119. package/esm/models/responseoutputtext.d.ts +2 -11
  120. package/esm/models/responseoutputtext.js +2 -9
  121. package/esm/models/responsesformatjsonobject.d.ts +2 -11
  122. package/esm/models/responsesformatjsonobject.js +2 -9
  123. package/esm/models/responsesformattext.d.ts +2 -11
  124. package/esm/models/responsesformattext.js +2 -9
  125. package/esm/models/responsesformattextjsonschemaconfig.d.ts +2 -11
  126. package/esm/models/responsesformattextjsonschemaconfig.js +2 -9
  127. package/esm/models/responsesoutputitem.d.ts +13 -1
  128. package/esm/models/responsesoutputitem.js +6 -6
  129. package/esm/models/urlcitation.d.ts +2 -11
  130. package/esm/models/urlcitation.js +2 -9
  131. package/esm/sdk/oauth.d.ts +2 -2
  132. package/esm/sdk/oauth.js +2 -3
  133. package/esm/sdk/sdk.d.ts +9 -8
  134. package/esm/types/unrecognized.d.ts +7 -1
  135. package/esm/types/unrecognized.js +9 -1
  136. package/jsr.json +1 -1
  137. package/package.json +1 -1
  138. package/tsconfig.json +0 -1
  139. package/vitest.config.ts +14 -8
  140. package/esm/models/chatmessagecontentitemfile.d.ts +0 -36
  141. package/esm/models/chatmessagecontentitemfile.js +0 -51
  142. package/esm/models/videourl.d.ts +0 -17
  143. package/esm/models/videourl.js +0 -21
package/biome.json ADDED
@@ -0,0 +1,171 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.3.8/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true,
7
+ "defaultBranch": "main"
8
+ },
9
+ "files": {
10
+ "ignoreUnknown": false,
11
+ "includes": [
12
+ "**",
13
+ "./.vscode/extensions/**",
14
+ "!**/*.json",
15
+ "!**/*.test.ts.snap",
16
+ "!**/logger.ts"
17
+ ]
18
+ },
19
+ "formatter": {
20
+ "enabled": true,
21
+ "indentStyle": "space",
22
+ "indentWidth": 2,
23
+ "lineWidth": 100,
24
+ "expand": "always",
25
+ "attributePosition": "multiline"
26
+ },
27
+ "assist": {
28
+ "actions": {
29
+ "source": {
30
+ "organizeImports": {
31
+ "level": "on",
32
+ "options": {
33
+ "groups": [
34
+ {
35
+ "type": true
36
+ },
37
+ ":BLANK_LINE:",
38
+ {
39
+ "type": false
40
+ },
41
+ [
42
+ ":NODE:"
43
+ ],
44
+ ":BLANK_LINE:",
45
+ [
46
+ "!@openrouter-monorepo/**"
47
+ ],
48
+ ":BLANK_LINE:",
49
+ [
50
+ "@openrouter-monorepo/**",
51
+ "@/**"
52
+ ],
53
+ ":BLANK_LINE:",
54
+ ":ALIAS:"
55
+ ]
56
+ }
57
+ }
58
+ }
59
+ }
60
+ },
61
+ "linter": {
62
+ "enabled": true,
63
+ "rules": {
64
+ "recommended": true,
65
+ "nursery": {
66
+ "noFloatingPromises": "off"
67
+ },
68
+ "a11y": {
69
+ "useSemanticElements": "off"
70
+ },
71
+ "complexity": {
72
+ "useLiteralKeys": "off",
73
+ "noExtraBooleanCast": "off",
74
+ "noForEach": "off",
75
+ "noBannedTypes": "error",
76
+ "noUselessSwitchCase": "off"
77
+ },
78
+ "style": {
79
+ "noNonNullAssertion": "off",
80
+ "useNodejsImportProtocol": "error",
81
+ "useTemplate": "off",
82
+ "useBlockStatements": "error",
83
+ "noParameterAssign": "error",
84
+ "useConst": "error",
85
+ "useAsConstAssertion": "error",
86
+ "useDefaultParameterLast": "error",
87
+ "useEnumInitializers": "error",
88
+ "useSelfClosingElements": "error",
89
+ "useSingleVarDeclarator": "error",
90
+ "noUnusedTemplateLiteral": "error",
91
+ "useNumberNamespace": "error",
92
+ "noInferrableTypes": "error",
93
+ "noUselessElse": "error",
94
+ "useImportType": {
95
+ "level": "on",
96
+ "options": {
97
+ "style": "separatedType"
98
+ }
99
+ },
100
+ "noRestrictedImports": {
101
+ "level": "error",
102
+ "options": {
103
+ "paths": {
104
+ "node:module": "Don't use `node:module`. Did you mean to import `wrap` from our `@openrouter-monorepo/type-utils/result-monad` package?",
105
+ "crypto": "Use `node:crypto` instead of `crypto` to follow the Node.js import protocol."
106
+ }
107
+ }
108
+ }
109
+ },
110
+ "correctness": {
111
+ "noUnusedImports": "error",
112
+ "useExhaustiveDependencies": "off",
113
+ "noUnknownFunction": "off",
114
+ "noChildrenProp": "off",
115
+ "noInnerDeclarations": "error",
116
+ "useParseIntRadix": "error"
117
+ },
118
+ "suspicious": {
119
+ "noExplicitAny": "warn",
120
+ "noArrayIndexKey": "off",
121
+ "noAssignInExpressions": "error",
122
+ "noAsyncPromiseExecutor": "off",
123
+ "noFallthroughSwitchClause": "error",
124
+ "noConsole": "error",
125
+ "noDoubleEquals": {
126
+ "level": "error",
127
+ "options": {
128
+ "ignoreNull": false
129
+ }
130
+ },
131
+ "noExtraNonNullAssertion": "error",
132
+ "noUnknownAtRules": "off"
133
+ },
134
+ "performance": {
135
+ "recommended": true,
136
+ "noAccumulatingSpread": "error"
137
+ },
138
+ "security": {
139
+ "recommended": true
140
+ }
141
+ },
142
+ "includes": [
143
+ "**",
144
+ "!**/*.test.ts.snap"
145
+ ]
146
+ },
147
+ "javascript": {
148
+ "formatter": {
149
+ "expand": "always",
150
+ "lineWidth": 100,
151
+ "arrowParentheses": "always",
152
+ "jsxQuoteStyle": "single",
153
+ "attributePosition": "multiline",
154
+ "quoteProperties": "asNeeded",
155
+ "trailingCommas": "all",
156
+ "semicolons": "always",
157
+ "bracketSpacing": true,
158
+ "bracketSameLine": false,
159
+ "quoteStyle": "single",
160
+ "enabled": true
161
+ }
162
+ },
163
+ "css": {
164
+ "parser": {
165
+ "tailwindDirectives": true
166
+ },
167
+ "formatter": {
168
+ "quoteStyle": "single"
169
+ }
170
+ }
171
+ }
@@ -1,8 +1,8 @@
1
- import { OpenRouterCore } from "../core.js";
2
- import { RequestOptions } from "../lib/sdks.js";
3
- import { ResponseWrapper } from "../lib/response-wrapper.js";
4
- import * as models from "../models/index.js";
5
- import { EnhancedTool, MaxToolRounds } from "../lib/tool-types.js";
1
+ import type { OpenRouterCore } from '../core.js';
2
+ import type { RequestOptions } from '../lib/sdks.js';
3
+ import type { Tool, MaxToolRounds } from '../lib/tool-types.js';
4
+ import type * as models from '../models/index.js';
5
+ import { ResponseWrapper } from '../lib/response-wrapper.js';
6
6
  /**
7
7
  * Input type that accepts both chat-style messages and responses-style input
8
8
  */
@@ -10,7 +10,7 @@ export type CallModelInput = models.OpenResponsesInput | models.Message[];
10
10
  /**
11
11
  * Tool type that accepts chat-style, responses-style, or enhanced tools
12
12
  */
13
- export type CallModelTools = EnhancedTool[] | models.ToolDefinitionJson[] | models.OpenResponsesRequest["tools"];
13
+ export type CallModelTools = Tool[] | models.ToolDefinitionJson[] | models.OpenResponsesRequest['tools'];
14
14
  /**
15
15
  * Get a response with multiple consumption patterns
16
16
  *
@@ -79,7 +79,7 @@ export type CallModelTools = EnhancedTool[] | models.ToolDefinitionJson[] | mode
79
79
  * }
80
80
  * ```
81
81
  */
82
- export declare function callModel(client: OpenRouterCore, request: Omit<models.OpenResponsesRequest, "stream" | "tools" | "input"> & {
82
+ export declare function callModel(client: OpenRouterCore, request: Omit<models.OpenResponsesRequest, 'stream' | 'tools' | 'input'> & {
83
83
  input?: CallModelInput;
84
84
  tools?: CallModelTools;
85
85
  maxToolRounds?: MaxToolRounds;
@@ -1,13 +1,15 @@
1
- import { ResponseWrapper } from "../lib/response-wrapper.js";
2
- import { convertEnhancedToolsToAPIFormat } from "../lib/tool-executor.js";
1
+ import { ResponseWrapper } from '../lib/response-wrapper.js';
2
+ import { convertToolsToAPIFormat } from '../lib/tool-executor.js';
3
3
  /**
4
4
  * Check if input is chat-style messages (Message[])
5
5
  */
6
6
  function isChatStyleMessages(input) {
7
- if (!Array.isArray(input))
7
+ if (!Array.isArray(input)) {
8
8
  return false;
9
- if (input.length === 0)
9
+ }
10
+ if (input.length === 0) {
10
11
  return false;
12
+ }
11
13
  const first = input[0];
12
14
  // Chat-style messages have role but no 'type' field at top level
13
15
  // Responses-style items have 'type' field (like 'message', 'function_call', etc.)
@@ -17,22 +19,30 @@ function isChatStyleMessages(input) {
17
19
  * Check if tools are chat-style (ToolDefinitionJson[])
18
20
  */
19
21
  function isChatStyleTools(tools) {
20
- if (!Array.isArray(tools))
22
+ if (!Array.isArray(tools)) {
21
23
  return false;
22
- if (tools.length === 0)
24
+ }
25
+ if (tools.length === 0) {
23
26
  return false;
27
+ }
24
28
  const first = tools[0];
25
29
  // Chat-style tools have nested 'function' property with 'name' inside
26
30
  // Enhanced tools have 'function' with 'inputSchema'
27
31
  // Responses-style tools have 'name' at top level
28
- return first && 'function' in first && first.function && 'name' in first.function && !('inputSchema' in first.function);
32
+ const fn = first?.['function'];
33
+ return (first &&
34
+ 'function' in first &&
35
+ fn !== undefined &&
36
+ fn !== null &&
37
+ 'name' in fn &&
38
+ !('inputSchema' in fn));
29
39
  }
30
40
  /**
31
41
  * Convert chat-style tools to responses-style
32
42
  */
33
43
  function convertChatToResponsesTools(tools) {
34
44
  return tools.map((tool) => ({
35
- type: "function",
45
+ type: 'function',
36
46
  name: tool.function.name,
37
47
  description: tool.function.description ?? null,
38
48
  strict: tool.function.strict ?? null,
@@ -46,35 +56,35 @@ function convertChatToResponsesInput(messages) {
46
56
  return messages.map((msg) => {
47
57
  // Extract extra fields like cache_control
48
58
  const { role, content, ...extraFields } = msg;
49
- if (role === "tool") {
59
+ if (role === 'tool') {
50
60
  const toolMsg = msg;
51
61
  return {
52
- type: "function_call_output",
62
+ type: 'function_call_output',
53
63
  callId: toolMsg.toolCallId,
54
- output: typeof toolMsg.content === "string" ? toolMsg.content : JSON.stringify(toolMsg.content),
64
+ output: typeof toolMsg.content === 'string' ? toolMsg.content : JSON.stringify(toolMsg.content),
55
65
  ...extraFields,
56
66
  };
57
67
  }
58
68
  // Handle assistant messages with tool calls
59
- if (role === "assistant") {
69
+ if (role === 'assistant') {
60
70
  const assistantMsg = msg;
61
71
  // If it has tool calls, we need to convert them
62
72
  // For now, just convert the content part
63
73
  return {
64
- role: "assistant",
65
- content: typeof assistantMsg.content === "string"
74
+ role: 'assistant',
75
+ content: typeof assistantMsg.content === 'string'
66
76
  ? assistantMsg.content
67
77
  : assistantMsg.content === null
68
- ? ""
78
+ ? ''
69
79
  : JSON.stringify(assistantMsg.content),
70
80
  ...extraFields,
71
81
  };
72
82
  }
73
83
  // System, user, developer messages
74
- const convertedContent = typeof content === "string"
84
+ const convertedContent = typeof content === 'string'
75
85
  ? content
76
86
  : content === null || content === undefined
77
- ? ""
87
+ ? ''
78
88
  : JSON.stringify(content);
79
89
  return {
80
90
  role: role,
@@ -154,9 +164,7 @@ function convertChatToResponsesInput(messages) {
154
164
  export function callModel(client, request, options) {
155
165
  const { tools, maxToolRounds, input, ...restRequest } = request;
156
166
  // Convert chat-style messages to responses-style input if needed
157
- const convertedInput = input && isChatStyleMessages(input)
158
- ? convertChatToResponsesInput(input)
159
- : input;
167
+ const convertedInput = input && isChatStyleMessages(input) ? convertChatToResponsesInput(input) : input;
160
168
  const apiRequest = {
161
169
  ...restRequest,
162
170
  input: convertedInput,
@@ -166,14 +174,16 @@ export function callModel(client, request, options) {
166
174
  let isChatTools = false;
167
175
  if (tools && Array.isArray(tools) && tools.length > 0) {
168
176
  const firstTool = tools[0];
169
- isEnhancedTools = "function" in firstTool && firstTool.function && "inputSchema" in firstTool.function;
177
+ const fn = firstTool?.['function'];
178
+ isEnhancedTools =
179
+ 'function' in firstTool && fn !== undefined && fn !== null && 'inputSchema' in fn;
170
180
  isChatTools = !isEnhancedTools && isChatStyleTools(tools);
171
181
  }
172
182
  const enhancedTools = isEnhancedTools ? tools : undefined;
173
183
  // Convert tools to API format based on their type
174
184
  let apiTools;
175
185
  if (enhancedTools) {
176
- apiTools = convertEnhancedToolsToAPIFormat(enhancedTools);
186
+ apiTools = convertToolsToAPIFormat(enhancedTools);
177
187
  }
178
188
  else if (isChatTools) {
179
189
  apiTools = convertChatToResponsesTools(tools);
@@ -184,7 +194,9 @@ export function callModel(client, request, options) {
184
194
  // Build the request with converted tools
185
195
  const finalRequest = {
186
196
  ...apiRequest,
187
- ...(apiTools && { tools: apiTools }),
197
+ ...(apiTools && {
198
+ tools: apiTools,
199
+ }),
188
200
  };
189
201
  const wrapperOptions = {
190
202
  client,
@@ -1,6 +1,6 @@
1
- import z from "zod/v3";
2
- import { OpenRouterCore } from "../core.js";
3
- import { Result } from "../types/fp.js";
1
+ import type { OpenRouterCore } from '../core.js';
2
+ import type { Result } from '../types/fp.js';
3
+ import z from 'zod/v3';
4
4
  declare const CreateAuthorizationurlParamsSchema: z.ZodUnion<[z.ZodObject<{
5
5
  callbackUrl: z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>;
6
6
  limit: z.ZodOptional<z.ZodNumber>;
@@ -1,12 +1,18 @@
1
- import z from "zod/v3";
2
- import { serverURLFromOptions } from "../lib/config.js";
1
+ import z from 'zod/v3';
2
+ import { serverURLFromOptions } from '../lib/config.js';
3
3
  const CreateAuthorizationUrlBaseSchema = z.object({
4
- callbackUrl: z.union([z.string().url(), z.instanceof(URL)]),
4
+ callbackUrl: z.union([
5
+ z.string().url(),
6
+ z.instanceof(URL),
7
+ ]),
5
8
  limit: z.number().optional(),
6
9
  });
7
10
  const CreateAuthorizationurlParamsSchema = z.union([
8
11
  CreateAuthorizationUrlBaseSchema.extend({
9
- codeChallengeMethod: z.enum(["S256", "plain"]),
12
+ codeChallengeMethod: z.enum([
13
+ 'S256',
14
+ 'plain',
15
+ ]),
10
16
  codeChallenge: z.string(),
11
17
  }),
12
18
  CreateAuthorizationUrlBaseSchema,
@@ -23,22 +29,32 @@ const CreateAuthorizationurlParamsSchema = z.union([
23
29
  */
24
30
  export function oAuthCreateAuthorizationUrl(client, params) {
25
31
  const parsedParams = CreateAuthorizationurlParamsSchema.safeParse(params);
26
- if (!parsedParams.success)
27
- return { ok: false, error: parsedParams.error };
32
+ if (!parsedParams.success) {
33
+ return {
34
+ ok: false,
35
+ error: parsedParams.error,
36
+ };
37
+ }
28
38
  const baseURL = serverURLFromOptions(client._options);
29
39
  if (!baseURL) {
30
- return { ok: false, error: new Error("No server URL configured") };
40
+ return {
41
+ ok: false,
42
+ error: new Error('No server URL configured'),
43
+ };
31
44
  }
32
45
  // Clone the URL to avoid mutating the original
33
- const authURL = new URL("/auth", baseURL);
34
- authURL.searchParams.set("callback_url", parsedParams.data.callbackUrl.toString());
35
- if ("codeChallengeMethod" in parsedParams.data) {
36
- authURL.searchParams.set("code_challenge", parsedParams.data.codeChallenge);
37
- authURL.searchParams.set("code_challenge_method", parsedParams.data.codeChallengeMethod);
46
+ const authURL = new URL('/auth', baseURL);
47
+ authURL.searchParams.set('callback_url', parsedParams.data.callbackUrl.toString());
48
+ if ('codeChallengeMethod' in parsedParams.data) {
49
+ authURL.searchParams.set('code_challenge', parsedParams.data.codeChallenge);
50
+ authURL.searchParams.set('code_challenge_method', parsedParams.data.codeChallengeMethod);
38
51
  }
39
52
  if (parsedParams.data.limit !== undefined) {
40
- authURL.searchParams.set("limit", parsedParams.data.limit.toString());
53
+ authURL.searchParams.set('limit', parsedParams.data.limit.toString());
41
54
  }
42
- return { ok: true, value: authURL.toString() };
55
+ return {
56
+ ok: true,
57
+ value: authURL.toString(),
58
+ };
43
59
  }
44
60
  //# sourceMappingURL=oAuthCreateAuthorizationUrl.js.map
@@ -1,5 +1,5 @@
1
- import z from "zod/v3";
2
- import { Result } from "../types/fp.js";
1
+ import type { Result } from '../types/fp.js';
2
+ import z from 'zod/v3';
3
3
  declare const CreateSHA256CodeChallengeRequestSchema: z.ZodObject<{
4
4
  /**
5
5
  * If not provided, a random code verifier will be generated.
@@ -1,4 +1,4 @@
1
- import z from "zod/v3";
1
+ import z from 'zod/v3';
2
2
  const CreateSHA256CodeChallengeRequestSchema = z.object({
3
3
  /**
4
4
  * If not provided, a random code verifier will be generated.
@@ -7,23 +7,20 @@ const CreateSHA256CodeChallengeRequestSchema = z.object({
7
7
  */
8
8
  codeVerifier: z
9
9
  .string()
10
- .min(43, "Code verifier must be at least 43 characters")
11
- .max(128, "Code verifier must be at most 128 characters")
12
- .regex(/^[A-Za-z0-9\-._~]+$/, "Code verifier must only contain unreserved characters: [A-Za-z0-9-._~]")
10
+ .min(43, 'Code verifier must be at least 43 characters')
11
+ .max(128, 'Code verifier must be at most 128 characters')
12
+ .regex(/^[A-Za-z0-9\-._~]+$/, 'Code verifier must only contain unreserved characters: [A-Za-z0-9-._~]')
13
13
  .optional(),
14
14
  });
15
15
  /**
16
16
  * Convert a Uint8Array to base64url encoding (RFC 4648)
17
17
  */
18
18
  function arrayBufferToBase64Url(buffer) {
19
- let binary = "";
19
+ let binary = '';
20
20
  for (let i = 0; i < buffer.length; i++) {
21
21
  binary += String.fromCharCode(buffer[i]);
22
22
  }
23
- return btoa(binary)
24
- .replace(/\+/g, "-")
25
- .replace(/\//g, "_")
26
- .replace(/=+$/, "");
23
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
27
24
  }
28
25
  /**
29
26
  * Generate a cryptographically random code verifier per RFC 7636
@@ -48,13 +45,17 @@ function generateCodeVerifier() {
48
45
  */
49
46
  export async function oAuthCreateSHA256CodeChallenge(params = {}) {
50
47
  const parsedParams = CreateSHA256CodeChallengeRequestSchema.safeParse(params);
51
- if (!parsedParams.success)
52
- return { ok: false, error: parsedParams.error };
48
+ if (!parsedParams.success) {
49
+ return {
50
+ ok: false,
51
+ error: parsedParams.error,
52
+ };
53
+ }
53
54
  const { codeVerifier = generateCodeVerifier() } = parsedParams.data;
54
55
  // Generate SHA-256 hash
55
56
  const encoder = new TextEncoder();
56
57
  const data = encoder.encode(codeVerifier);
57
- const hash = await crypto.subtle.digest("SHA-256", data);
58
+ const hash = await crypto.subtle.digest('SHA-256', data);
58
59
  // Convert hash to base64url
59
60
  const hashArray = new Uint8Array(hash);
60
61
  const codeChallenge = arrayBufferToBase64Url(hashArray);
@@ -1,3 +1,3 @@
1
- import { Hooks } from "./types.js";
2
- export declare function initHooks(hooks: Hooks): void;
1
+ import type { Hooks } from './types.js';
2
+ export declare function initHooks(_hooks: Hooks): void;
3
3
  //# sourceMappingURL=registration.d.ts.map
@@ -3,8 +3,7 @@
3
3
  * Any hooks you wish to add should be registered in the initHooks function. Feel free to define them
4
4
  * in this file or in separate files in the hooks folder.
5
5
  */
6
- // @ts-expect-error remove this line when you add your first hook and hooks is used
7
- export function initHooks(hooks) {
6
+ export function initHooks(_hooks) {
8
7
  // Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
9
8
  // with an instance of a hook that implements that specific Hook interface
10
9
  // Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
@@ -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.27";
49
- readonly genVersion: "2.760.2";
50
- readonly userAgent: "speakeasy-sdk/typescript 0.1.27 2.760.2 1.0.0 @openrouter/sdk";
48
+ readonly sdkVersion: "0.2.6";
49
+ readonly genVersion: "2.768.0";
50
+ readonly userAgent: "speakeasy-sdk/typescript 0.2.6 2.768.0 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.27",
29
- genVersion: "2.760.2",
30
- userAgent: "speakeasy-sdk/typescript 0.1.27 2.760.2 1.0.0 @openrouter/sdk",
28
+ sdkVersion: "0.2.6",
29
+ genVersion: "2.768.0",
30
+ userAgent: "speakeasy-sdk/typescript 0.2.6 2.768.0 1.0.0 @openrouter/sdk",
31
31
  };
32
32
  //# sourceMappingURL=config.js.map
@@ -38,6 +38,7 @@ export declare function queryJoin(...args: (string | undefined)[]): string;
38
38
  type QueryEncoderOptions = {
39
39
  explode?: boolean;
40
40
  charEncoding?: "percent" | "none";
41
+ allowEmptyValue?: string[];
41
42
  };
42
43
  type QueryEncoder = (key: string, value: unknown, options?: QueryEncoderOptions) => string | undefined;
43
44
  type BulkQueryEncoder = (values: Record<string, unknown>, options?: QueryEncoderOptions) => string;
@@ -83,7 +83,9 @@ export function encodeLabel(key, value, options) {
83
83
  encValue = mapped?.join("").slice(1);
84
84
  }
85
85
  else {
86
- const k = options?.explode && isPlainObject(value) ? `${encodeString(pk)}=` : "";
86
+ const k = options?.explode && isPlainObject(value)
87
+ ? `${encodeString(pk)}=`
88
+ : "";
87
89
  encValue = `${k}${encodeValue(pv)}`;
88
90
  }
89
91
  out += encValue == null ? "" : `.${encValue}`;
@@ -325,7 +327,16 @@ export function queryEncoder(f) {
325
327
  explode: options?.explode ?? true,
326
328
  charEncoding: options?.charEncoding ?? "percent",
327
329
  };
330
+ const allowEmptySet = new Set(options?.allowEmptyValue ?? []);
328
331
  const encoded = Object.entries(values).map(([key, value]) => {
332
+ if (allowEmptySet.has(key)) {
333
+ if (value === undefined
334
+ || value === null
335
+ || value === ""
336
+ || (Array.isArray(value) && value.length === 0)) {
337
+ return `${encodeURIComponent(key)}=`;
338
+ }
339
+ }
329
340
  return f(key, value, opts);
330
341
  });
331
342
  return queryJoin(...encoded);
@@ -1,12 +1,12 @@
1
- import { OpenRouterCore } from "../core.js";
2
- import { RequestOptions } from "./sdks.js";
3
- import * as models from "../models/index.js";
4
- import { EnhancedTool, ParsedToolCall, MaxToolRounds, EnhancedResponseStreamEvent, ToolStreamEvent, ChatStreamEvent } from "./tool-types.js";
1
+ import type { OpenRouterCore } from '../core.js';
2
+ import type * as models from '../models/index.js';
3
+ import type { RequestOptions } from './sdks.js';
4
+ import type { ChatStreamEvent, EnhancedResponseStreamEvent, Tool, MaxToolRounds, ParsedToolCall, ToolStreamEvent } from './tool-types.js';
5
5
  export interface GetResponseOptions {
6
6
  request: models.OpenResponsesRequest;
7
7
  client: OpenRouterCore;
8
8
  options?: RequestOptions;
9
- tools?: EnhancedTool[];
9
+ tools?: Tool[];
10
10
  maxToolRounds?: MaxToolRounds;
11
11
  }
12
12
  /**