@openrouter/sdk 0.9.11 → 0.10.2

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 (274) hide show
  1. package/FUNCTIONS.md +2 -1
  2. package/_speakeasy/.github/action-inputs-config.json +4 -0
  3. package/esm/funcs/analyticsGetUserActivity.js +2 -1
  4. package/esm/funcs/apiKeysCreate.js +2 -1
  5. package/esm/funcs/apiKeysDelete.js +2 -1
  6. package/esm/funcs/apiKeysGet.js +2 -1
  7. package/esm/funcs/apiKeysGetCurrentKeyMetadata.js +2 -1
  8. package/esm/funcs/apiKeysList.js +2 -1
  9. package/esm/funcs/apiKeysUpdate.js +2 -1
  10. package/esm/funcs/betaResponsesSend.js +2 -1
  11. package/esm/funcs/call-model.d.ts +19 -70
  12. package/esm/funcs/call-model.js +29 -71
  13. package/esm/funcs/chatSend.js +2 -1
  14. package/esm/funcs/creditsCreateCoinbaseCharge.js +2 -1
  15. package/esm/funcs/creditsGetCredits.js +2 -1
  16. package/esm/funcs/embeddingsGenerate.js +2 -1
  17. package/esm/funcs/embeddingsListModels.js +2 -1
  18. package/esm/funcs/endpointsList.js +2 -1
  19. package/esm/funcs/endpointsListZdrEndpoints.js +2 -1
  20. package/esm/funcs/generationsGetGeneration.js +2 -1
  21. package/esm/funcs/guardrailsBulkAssignKeys.js +2 -1
  22. package/esm/funcs/guardrailsBulkAssignMembers.js +2 -1
  23. package/esm/funcs/guardrailsBulkUnassignKeys.js +2 -1
  24. package/esm/funcs/guardrailsBulkUnassignMembers.js +2 -1
  25. package/esm/funcs/guardrailsCreate.js +2 -1
  26. package/esm/funcs/guardrailsDelete.js +2 -1
  27. package/esm/funcs/guardrailsGet.js +2 -1
  28. package/esm/funcs/guardrailsList.js +2 -1
  29. package/esm/funcs/guardrailsListGuardrailKeyAssignments.js +2 -1
  30. package/esm/funcs/guardrailsListGuardrailMemberAssignments.js +2 -1
  31. package/esm/funcs/guardrailsListKeyAssignments.js +2 -1
  32. package/esm/funcs/guardrailsListMemberAssignments.js +2 -1
  33. package/esm/funcs/guardrailsUpdate.js +2 -1
  34. package/esm/funcs/modelsCount.d.ts +1 -1
  35. package/esm/funcs/modelsCount.js +9 -4
  36. package/esm/funcs/modelsList.js +3 -1
  37. package/esm/funcs/modelsListForUser.js +2 -1
  38. package/esm/funcs/oAuthCreateAuthCode.d.ts +1 -1
  39. package/esm/funcs/oAuthCreateAuthCode.js +4 -3
  40. package/esm/funcs/oAuthExchangeAuthCodeForAPIKey.js +2 -1
  41. package/esm/funcs/providersList.js +2 -1
  42. package/esm/index.d.ts +22 -23
  43. package/esm/index.js +20 -17
  44. package/esm/lib/anthropic-compat.d.ts +2 -1
  45. package/esm/lib/anthropic-compat.js +1 -2
  46. package/esm/lib/async-params.d.ts +19 -5
  47. package/esm/lib/async-params.js +5 -1
  48. package/esm/lib/chat-compat.d.ts +1 -1
  49. package/esm/lib/chat-compat.js +1 -2
  50. package/esm/lib/claude-type-guards.d.ts +2 -2
  51. package/esm/lib/config.d.ts +8 -10
  52. package/esm/lib/config.js +2 -2
  53. package/esm/lib/conversation-state.d.ts +1 -1
  54. package/esm/lib/conversation-state.js +35 -32
  55. package/esm/lib/env.d.ts +6 -2
  56. package/esm/lib/env.js +7 -3
  57. package/esm/lib/model-result.d.ts +73 -17
  58. package/esm/lib/model-result.js +329 -125
  59. package/esm/lib/sdks.d.ts +1 -1
  60. package/esm/lib/sdks.js +8 -28
  61. package/esm/lib/stream-transformers.d.ts +5 -4
  62. package/esm/lib/stream-transformers.js +24 -29
  63. package/esm/lib/stream-type-guards.js +8 -32
  64. package/esm/lib/tool-context.d.ts +68 -0
  65. package/esm/lib/tool-context.js +175 -0
  66. package/esm/lib/tool-executor.d.ts +9 -5
  67. package/esm/lib/tool-executor.js +26 -16
  68. package/esm/lib/tool-orchestrator.d.ts +2 -2
  69. package/esm/lib/tool-types.d.ts +101 -14
  70. package/esm/lib/tool-types.js +17 -0
  71. package/esm/lib/tool.d.ts +49 -60
  72. package/esm/lib/tool.js +15 -19
  73. package/esm/lib/turn-context.d.ts +1 -1
  74. package/esm/models/assistantmessage.d.ts +6 -0
  75. package/esm/models/assistantmessage.js +3 -0
  76. package/esm/models/chatcompletionaudiooutput.d.ts +38 -0
  77. package/esm/models/chatcompletionaudiooutput.js +36 -0
  78. package/esm/models/chatgenerationparams.d.ts +75 -6
  79. package/esm/models/chatgenerationparams.js +42 -0
  80. package/esm/models/chatmessagecontentitem.d.ts +3 -2
  81. package/esm/models/chatmessagecontentitem.js +3 -0
  82. package/esm/models/chatmessagecontentitemcachecontrol.d.ts +5 -5
  83. package/esm/models/chatmessagecontentitemcachecontrol.js +5 -7
  84. package/esm/models/chatmessagecontentitemfile.d.ts +57 -0
  85. package/esm/models/chatmessagecontentitemfile.js +59 -0
  86. package/esm/models/chatmessagetokenlogprobs.d.ts +1 -1
  87. package/esm/models/chatmessagetokenlogprobs.js +2 -1
  88. package/esm/models/chatresponse.d.ts +1 -1
  89. package/esm/models/chatresponse.js +1 -1
  90. package/esm/models/chatstreamingmessagechunk.d.ts +2 -0
  91. package/esm/models/chatstreamingmessagechunk.js +2 -0
  92. package/esm/models/chatstreamingresponsechunk.d.ts +1 -1
  93. package/esm/models/chatstreamingresponsechunk.js +1 -1
  94. package/esm/models/compoundfilter.d.ts +36 -0
  95. package/esm/models/compoundfilter.js +32 -0
  96. package/esm/models/conflictresponseerrordata.d.ts +17 -0
  97. package/esm/models/conflictresponseerrordata.js +16 -0
  98. package/esm/models/contextcompressionengine.d.ts +15 -0
  99. package/esm/models/contextcompressionengine.js +14 -0
  100. package/esm/models/datetimeservertool.d.ts +30 -0
  101. package/esm/models/datetimeservertool.js +22 -0
  102. package/esm/models/defaultparameters.d.ts +3 -0
  103. package/esm/models/defaultparameters.js +6 -0
  104. package/esm/models/errors/conflictresponseerror.d.ts +33 -0
  105. package/esm/models/errors/conflictresponseerror.js +42 -0
  106. package/esm/models/errors/index.d.ts +1 -0
  107. package/esm/models/errors/index.js +1 -0
  108. package/esm/models/index.d.ts +23 -4
  109. package/esm/models/index.js +23 -4
  110. package/esm/models/openairesponsesinputunion.d.ts +32 -1
  111. package/esm/models/openairesponsesinputunion.js +53 -1
  112. package/esm/models/openresponsesapplypatchtool.d.ts +20 -0
  113. package/esm/models/openresponsesapplypatchtool.js +21 -0
  114. package/esm/models/openresponsescodeinterpretertool.d.ts +68 -0
  115. package/esm/models/openresponsescodeinterpretertool.js +85 -0
  116. package/esm/models/openresponsescomputertool.d.ts +39 -0
  117. package/esm/models/openresponsescomputertool.js +50 -0
  118. package/esm/models/openresponsescustomtool.d.ts +75 -0
  119. package/esm/models/openresponsescustomtool.js +95 -0
  120. package/esm/models/openresponseseasyinputmessage.d.ts +30 -4
  121. package/esm/models/openresponseseasyinputmessage.js +28 -2
  122. package/esm/models/openresponsesfilesearchtool.d.ts +111 -0
  123. package/esm/models/openresponsesfilesearchtool.js +180 -0
  124. package/esm/models/openresponsesfunctioncalloutput.d.ts +46 -7
  125. package/esm/models/openresponsesfunctioncalloutput.js +56 -4
  126. package/esm/models/openresponsesfunctionshelltool.d.ts +20 -0
  127. package/esm/models/openresponsesfunctionshelltool.js +21 -0
  128. package/esm/models/openresponsesimagegenerationtool.d.ts +125 -0
  129. package/esm/models/openresponsesimagegenerationtool.js +153 -0
  130. package/esm/models/openresponsesinputmessageitem.d.ts +2 -2
  131. package/esm/models/openresponsesinputmessageitem.js +2 -2
  132. package/esm/models/openresponsesinputunion.d.ts +207 -0
  133. package/esm/models/openresponsesinputunion.js +225 -0
  134. package/esm/models/openresponseslocalshelltool.d.ts +20 -0
  135. package/esm/models/openresponseslocalshelltool.js +21 -0
  136. package/esm/models/openresponsesmcptool.d.ts +128 -0
  137. package/esm/models/openresponsesmcptool.js +173 -0
  138. package/esm/models/openresponsesnonstreamingresponse.d.ts +11 -2
  139. package/esm/models/openresponsesnonstreamingresponse.js +27 -0
  140. package/esm/models/openresponsesrequest.d.ts +53 -11
  141. package/esm/models/openresponsesrequest.js +51 -2
  142. package/esm/models/openresponsesstreamevent.d.ts +52 -4
  143. package/esm/models/openresponsesstreamevent.js +54 -3
  144. package/esm/models/openresponseswebsearch20250826tool.d.ts +29 -0
  145. package/esm/models/openresponseswebsearch20250826tool.js +23 -0
  146. package/esm/models/openresponseswebsearchcallcompleted.d.ts +16 -0
  147. package/esm/models/openresponseswebsearchcallcompleted.js +24 -0
  148. package/esm/models/openresponseswebsearchcallinprogress.d.ts +16 -0
  149. package/esm/models/openresponseswebsearchcallinprogress.js +24 -0
  150. package/esm/models/openresponseswebsearchcallsearching.d.ts +16 -0
  151. package/esm/models/openresponseswebsearchcallsearching.js +24 -0
  152. package/esm/models/openresponseswebsearchpreview20250311tool.d.ts +44 -0
  153. package/esm/models/openresponseswebsearchpreview20250311tool.js +51 -0
  154. package/esm/models/openresponseswebsearchpreviewtool.d.ts +44 -0
  155. package/esm/models/openresponseswebsearchpreviewtool.js +47 -0
  156. package/esm/models/openresponseswebsearchtool.d.ts +29 -0
  157. package/esm/models/openresponseswebsearchtool.js +23 -0
  158. package/esm/models/operations/bulkassignkeystoguardrail.d.ts +16 -3
  159. package/esm/models/operations/bulkassignkeystoguardrail.js +2 -2
  160. package/esm/models/operations/bulkassignmemberstoguardrail.d.ts +16 -3
  161. package/esm/models/operations/bulkassignmemberstoguardrail.js +2 -2
  162. package/esm/models/operations/bulkunassignkeysfromguardrail.d.ts +16 -3
  163. package/esm/models/operations/bulkunassignkeysfromguardrail.js +2 -2
  164. package/esm/models/operations/bulkunassignmembersfromguardrail.d.ts +16 -3
  165. package/esm/models/operations/bulkunassignmembersfromguardrail.js +2 -2
  166. package/esm/models/operations/createauthkeyscode.d.ts +16 -3
  167. package/esm/models/operations/createauthkeyscode.js +2 -2
  168. package/esm/models/operations/createcoinbasecharge.d.ts +16 -3
  169. package/esm/models/operations/createcoinbasecharge.js +2 -2
  170. package/esm/models/operations/createembeddings.d.ts +16 -3
  171. package/esm/models/operations/createembeddings.js +2 -2
  172. package/esm/models/operations/createguardrail.d.ts +25 -3
  173. package/esm/models/operations/createguardrail.js +6 -2
  174. package/esm/models/operations/createkeys.d.ts +16 -3
  175. package/esm/models/operations/createkeys.js +2 -2
  176. package/esm/models/operations/createresponses.d.ts +16 -3
  177. package/esm/models/operations/createresponses.js +2 -2
  178. package/esm/models/operations/deleteguardrail.d.ts +16 -3
  179. package/esm/models/operations/deleteguardrail.js +2 -2
  180. package/esm/models/operations/deletekeys.d.ts +16 -3
  181. package/esm/models/operations/deletekeys.js +2 -2
  182. package/esm/models/operations/exchangeauthcodeforapikey.d.ts +16 -3
  183. package/esm/models/operations/exchangeauthcodeforapikey.js +2 -2
  184. package/esm/models/operations/getcredits.d.ts +16 -3
  185. package/esm/models/operations/getcredits.js +2 -2
  186. package/esm/models/operations/getcurrentkey.d.ts +16 -3
  187. package/esm/models/operations/getcurrentkey.js +2 -2
  188. package/esm/models/operations/getgeneration.d.ts +25 -3
  189. package/esm/models/operations/getgeneration.js +7 -2
  190. package/esm/models/operations/getguardrail.d.ts +20 -3
  191. package/esm/models/operations/getguardrail.js +4 -2
  192. package/esm/models/operations/getkey.d.ts +16 -3
  193. package/esm/models/operations/getkey.js +2 -2
  194. package/esm/models/operations/getmodels.d.ts +21 -3
  195. package/esm/models/operations/getmodels.js +4 -2
  196. package/esm/models/operations/getuseractivity.d.ts +16 -3
  197. package/esm/models/operations/getuseractivity.js +2 -2
  198. package/esm/models/operations/list.d.ts +16 -3
  199. package/esm/models/operations/list.js +2 -2
  200. package/esm/models/operations/listembeddingsmodels.d.ts +16 -3
  201. package/esm/models/operations/listembeddingsmodels.js +2 -2
  202. package/esm/models/operations/listendpoints.d.ts +16 -3
  203. package/esm/models/operations/listendpoints.js +2 -2
  204. package/esm/models/operations/listendpointszdr.d.ts +16 -3
  205. package/esm/models/operations/listendpointszdr.js +2 -2
  206. package/esm/models/operations/listguardrailkeyassignments.d.ts +16 -3
  207. package/esm/models/operations/listguardrailkeyassignments.js +2 -2
  208. package/esm/models/operations/listguardrailmemberassignments.d.ts +16 -3
  209. package/esm/models/operations/listguardrailmemberassignments.js +2 -2
  210. package/esm/models/operations/listguardrails.d.ts +20 -3
  211. package/esm/models/operations/listguardrails.js +4 -2
  212. package/esm/models/operations/listkeyassignments.d.ts +16 -3
  213. package/esm/models/operations/listkeyassignments.js +2 -2
  214. package/esm/models/operations/listmemberassignments.d.ts +16 -3
  215. package/esm/models/operations/listmemberassignments.js +2 -2
  216. package/esm/models/operations/listmodelscount.d.ts +21 -3
  217. package/esm/models/operations/listmodelscount.js +4 -2
  218. package/esm/models/operations/listmodelsuser.d.ts +16 -3
  219. package/esm/models/operations/listmodelsuser.js +2 -2
  220. package/esm/models/operations/listproviders.d.ts +16 -3
  221. package/esm/models/operations/listproviders.js +2 -2
  222. package/esm/models/operations/sendchatcompletionrequest.d.ts +16 -3
  223. package/esm/models/operations/sendchatcompletionrequest.js +2 -2
  224. package/esm/models/operations/updateguardrail.d.ts +25 -3
  225. package/esm/models/operations/updateguardrail.js +6 -2
  226. package/esm/models/operations/updatekeys.d.ts +16 -3
  227. package/esm/models/operations/updatekeys.js +2 -2
  228. package/esm/models/outputmessage.d.ts +23 -0
  229. package/esm/models/outputmessage.js +24 -0
  230. package/esm/models/outputmodality.d.ts +1 -0
  231. package/esm/models/outputmodality.js +1 -0
  232. package/esm/models/providername.d.ts +1 -0
  233. package/esm/models/providername.js +1 -0
  234. package/esm/models/providerpreferences.d.ts +4 -0
  235. package/esm/models/providerpreferences.js +4 -0
  236. package/esm/models/providersort.d.ts +1 -0
  237. package/esm/models/providersort.js +1 -0
  238. package/esm/models/providersortconfig.d.ts +1 -0
  239. package/esm/models/providersortconfig.js +1 -0
  240. package/esm/models/responseoutputtext.d.ts +8 -8
  241. package/esm/models/responseoutputtext.js +10 -9
  242. package/esm/models/responsesoutputitem.d.ts +2 -13
  243. package/esm/models/responsesoutputitem.js +8 -6
  244. package/esm/models/responsesoutputitemreasoning.d.ts +2 -31
  245. package/esm/models/responsesoutputitemreasoning.js +2 -44
  246. package/esm/models/responsesoutputmessage.d.ts +24 -32
  247. package/esm/models/responsesoutputmessage.js +26 -47
  248. package/esm/models/responsesservertooloutput.d.ts +42 -0
  249. package/esm/models/responsesservertooloutput.js +44 -0
  250. package/esm/models/responseswebsearchcalloutput.d.ts +90 -5
  251. package/esm/models/responseswebsearchcalloutput.js +113 -5
  252. package/esm/models/responseswebsearchservertool.d.ts +35 -0
  253. package/esm/models/responseswebsearchservertool.js +28 -0
  254. package/esm/models/tooldefinitionjson.d.ts +38 -20
  255. package/esm/models/tooldefinitionjson.js +22 -11
  256. package/esm/models/websearchengine.d.ts +2 -0
  257. package/esm/models/websearchengine.js +2 -0
  258. package/esm/models/websearchservertool.d.ts +116 -0
  259. package/esm/models/websearchservertool.js +77 -0
  260. package/esm/models/websearchshorthand.d.ts +215 -0
  261. package/esm/models/websearchshorthand.js +138 -0
  262. package/esm/sdk/sdk.d.ts +4 -1
  263. package/esm/sdk/sdk.js +0 -1
  264. package/esm/types/index.d.ts +0 -2
  265. package/esm/types/index.js +0 -1
  266. package/jsr.json +1 -1
  267. package/package.json +11 -6
  268. package/turbo.json +10 -0
  269. package/esm/models/openresponsesinput.d.ts +0 -28
  270. package/esm/models/openresponsesinput.js +0 -54
  271. package/esm/models/openresponseslogprobs.d.ts +0 -16
  272. package/esm/models/openresponseslogprobs.js +0 -22
  273. package/esm/models/openresponsestoplogprobs.d.ts +0 -14
  274. package/esm/models/openresponsestoplogprobs.js +0 -15
package/esm/lib/sdks.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SDKHooks } from "../hooks/hooks.js";
2
- import type { HookContext } from "../hooks/types.js";
2
+ import { HookContext } from "../hooks/types.js";
3
3
  import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from "../models/errors/httpclienterrors.js";
4
4
  import { Result } from "../types/fp.js";
5
5
  import { SDKOptions } from "./config.js";
package/esm/lib/sdks.js CHANGED
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
14
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
15
  };
16
- var _ClientSDK_instances, _ClientSDK_httpClient, _ClientSDK_hooks, _ClientSDK_logger, _ClientSDK_registerHook;
16
+ var _ClientSDK_httpClient, _ClientSDK_hooks, _ClientSDK_logger;
17
17
  import { SDKHooks } from "../hooks/hooks.js";
18
18
  import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js";
19
19
  import { ERR, OK } from "../types/fp.js";
@@ -33,22 +33,18 @@ const isBrowserLike = webWorkerLike
33
33
  || (typeof window === "object" && typeof window.document !== "undefined");
34
34
  export class ClientSDK {
35
35
  constructor(options = {}) {
36
- _ClientSDK_instances.add(this);
37
36
  _ClientSDK_httpClient.set(this, void 0);
38
37
  _ClientSDK_hooks.set(this, void 0);
39
38
  _ClientSDK_logger.set(this, void 0);
40
- // Reuse existing SDKHooks if passed (for sub-SDKs)
41
- if (options.hooks instanceof SDKHooks) {
42
- __classPrivateFieldSet(this, _ClientSDK_hooks, options.hooks, "f");
39
+ const opt = options;
40
+ if (typeof opt === "object"
41
+ && opt != null
42
+ && "hooks" in opt
43
+ && opt.hooks instanceof SDKHooks) {
44
+ __classPrivateFieldSet(this, _ClientSDK_hooks, opt.hooks, "f");
43
45
  }
44
46
  else {
45
47
  __classPrivateFieldSet(this, _ClientSDK_hooks, new SDKHooks(), "f");
46
- if (options.hooks) {
47
- const hooksArray = Array.isArray(options.hooks) ? options.hooks : [options.hooks];
48
- for (const hook of hooksArray) {
49
- __classPrivateFieldGet(this, _ClientSDK_instances, "m", _ClientSDK_registerHook).call(this, hook);
50
- }
51
- }
52
48
  }
53
49
  const defaultHttpClient = new HTTPClient();
54
50
  options.httpClient = options.httpClient || defaultHttpClient;
@@ -189,23 +185,7 @@ export class ClientSDK {
189
185
  });
190
186
  }
191
187
  }
192
- _ClientSDK_httpClient = new WeakMap(), _ClientSDK_hooks = new WeakMap(), _ClientSDK_logger = new WeakMap(), _ClientSDK_instances = new WeakSet(), _ClientSDK_registerHook = function _ClientSDK_registerHook(hook) {
193
- if ("sdkInit" in hook) {
194
- __classPrivateFieldGet(this, _ClientSDK_hooks, "f").registerSDKInitHook(hook);
195
- }
196
- if ("beforeCreateRequest" in hook) {
197
- __classPrivateFieldGet(this, _ClientSDK_hooks, "f").registerBeforeCreateRequestHook(hook);
198
- }
199
- if ("beforeRequest" in hook) {
200
- __classPrivateFieldGet(this, _ClientSDK_hooks, "f").registerBeforeRequestHook(hook);
201
- }
202
- if ("afterSuccess" in hook) {
203
- __classPrivateFieldGet(this, _ClientSDK_hooks, "f").registerAfterSuccessHook(hook);
204
- }
205
- if ("afterError" in hook) {
206
- __classPrivateFieldGet(this, _ClientSDK_hooks, "f").registerAfterErrorHook(hook);
207
- }
208
- };
188
+ _ClientSDK_httpClient = new WeakMap(), _ClientSDK_hooks = new WeakMap(), _ClientSDK_logger = new WeakMap();
209
189
  const jsonLikeContentTypeRE = /(application|text)\/.*?\+*json.*/;
210
190
  const jsonlLikeContentTypeRE = /(application|text)\/(.*?\+*\bjsonl\b.*|.*?\+*\bx-ndjson\b.*)/;
211
191
  async function logRequest(logger, req) {
@@ -1,4 +1,5 @@
1
1
  import type * as models from '../models/index.js';
2
+ import type { ClaudeMessage, UnsupportedContent } from '../models/claude-message.js';
2
3
  import type { ReusableReadableStream } from './reusable-stream.js';
3
4
  import type { ParsedToolCall, Tool } from './tool-types.js';
4
5
  /**
@@ -69,17 +70,17 @@ export declare function responseHasToolCalls(response: models.OpenResponsesNonSt
69
70
  * Convert OpenResponsesNonStreamingResponse to ClaudeMessage format
70
71
  * Compatible with the Anthropic SDK BetaMessage type
71
72
  */
72
- export declare function convertToClaudeMessage(response: models.OpenResponsesNonStreamingResponse): models.ClaudeMessage;
73
+ export declare function convertToClaudeMessage(response: models.OpenResponsesNonStreamingResponse): ClaudeMessage;
73
74
  /**
74
75
  * Extract unsupported content by original type
75
76
  */
76
- export declare function extractUnsupportedContent(message: models.ClaudeMessage, originalType: string): models.UnsupportedContent[];
77
+ export declare function extractUnsupportedContent(message: ClaudeMessage, originalType: string): UnsupportedContent[];
77
78
  /**
78
79
  * Check if message has any unsupported content
79
80
  */
80
- export declare function hasUnsupportedContent(message: models.ClaudeMessage): boolean;
81
+ export declare function hasUnsupportedContent(message: ClaudeMessage): boolean;
81
82
  /**
82
83
  * Get summary of unsupported content types
83
84
  */
84
- export declare function getUnsupportedContentSummary(message: models.ClaudeMessage): Record<string, number>;
85
+ export declare function getUnsupportedContentSummary(message: ClaudeMessage): Record<string, number>;
85
86
  //# sourceMappingURL=stream-transformers.d.ts.map
@@ -440,7 +440,8 @@ export function extractToolCallsFromResponse(response) {
440
440
  for (const item of response.output) {
441
441
  if (isFunctionCallItem(item)) {
442
442
  try {
443
- const parsedArguments = JSON.parse(item.arguments);
443
+ const trimmedArgs = item.arguments.trim();
444
+ const parsedArguments = trimmedArgs ? JSON.parse(trimmedArgs) : {};
444
445
  toolCalls.push({
445
446
  id: item.callId,
446
447
  name: item.name,
@@ -475,7 +476,9 @@ export async function* buildToolCallStream(stream) {
475
476
  switch (event.type) {
476
477
  case 'response.output_item.added': {
477
478
  if (isOutputItemAddedEvent(event) && event.item && isFunctionCallItem(event.item)) {
478
- toolCallsInProgress.set(event.item.callId, {
479
+ // Use item.id if available (matches itemId in delta events), fall back to callId
480
+ const itemKey = event.item.id ?? event.item.callId;
481
+ toolCallsInProgress.set(itemKey, {
479
482
  id: event.item.callId,
480
483
  name: event.item.name,
481
484
  argumentsAccumulated: '',
@@ -496,9 +499,10 @@ export async function* buildToolCallStream(stream) {
496
499
  if (isFunctionCallArgumentsDoneEvent(event)) {
497
500
  const toolCall = toolCallsInProgress.get(event.itemId);
498
501
  if (toolCall) {
499
- // Parse complete arguments
502
+ // Parse complete arguments (empty string → empty object for no-param tools)
500
503
  try {
501
- const parsedArguments = JSON.parse(event.arguments);
504
+ const trimmedArgs = event.arguments.trim();
505
+ const parsedArguments = trimmedArgs ? JSON.parse(trimmedArgs) : {};
502
506
  yield {
503
507
  id: toolCall.id,
504
508
  name: event.name,
@@ -522,10 +526,13 @@ export async function* buildToolCallStream(stream) {
522
526
  }
523
527
  case 'response.output_item.done': {
524
528
  if (isOutputItemDoneEvent(event) && event.item && isFunctionCallItem(event.item)) {
529
+ // Use item.id if available (matches itemId in delta events), fall back to callId
530
+ const itemKey = event.item.id ?? event.item.callId;
525
531
  // Yield final tool call if we haven't already
526
- if (toolCallsInProgress.has(event.item.callId)) {
532
+ if (toolCallsInProgress.has(itemKey)) {
527
533
  try {
528
- const parsedArguments = JSON.parse(event.item.arguments);
534
+ const trimmedArgs = event.item.arguments.trim();
535
+ const parsedArguments = trimmedArgs ? JSON.parse(trimmedArgs) : {};
529
536
  yield {
530
537
  id: event.item.callId,
531
538
  name: event.item.name,
@@ -539,7 +546,7 @@ export async function* buildToolCallStream(stream) {
539
546
  arguments: event.item.arguments,
540
547
  };
541
548
  }
542
- toolCallsInProgress.delete(event.item.callId);
549
+ toolCallsInProgress.delete(itemKey);
543
550
  }
544
551
  }
545
552
  break;
@@ -606,14 +613,9 @@ function mapAnnotationsToCitations(annotations) {
606
613
  }
607
614
  break;
608
615
  }
609
- default: {
610
- // Exhaustiveness check - TypeScript will error if we don't handle all annotation types
611
- const exhaustiveCheck = annotation;
612
- // Cast to unknown for runtime debugging if type system bypassed
613
- // This should never execute - throw with JSON of the unhandled value
614
- throw new Error(`Unhandled annotation type. This indicates a new annotation type was added. ` +
615
- `Annotation: ${JSON.stringify(exhaustiveCheck)}`);
616
- }
616
+ default:
617
+ // Unknown annotation types are skipped for forward compatibility.
618
+ break;
617
619
  }
618
620
  }
619
621
  return citations.length > 0 ? citations : undefined;
@@ -698,11 +700,7 @@ export function convertToClaudeMessage(response) {
698
700
  });
699
701
  }
700
702
  else {
701
- // Exhaustiveness check - TypeScript will error if we don't handle all part types
702
- const exhaustiveCheck = part;
703
- // This should never execute - new content type was added
704
- throw new Error(`Unhandled message content type. This indicates a new content type was added. ` +
705
- `Part: ${JSON.stringify(exhaustiveCheck)}`);
703
+ // Unknown content types are skipped for forward compatibility.
706
704
  }
707
705
  }
708
706
  }
@@ -712,7 +710,8 @@ export function convertToClaudeMessage(response) {
712
710
  if (isFunctionCallItem(item)) {
713
711
  let parsedInput;
714
712
  try {
715
- parsedInput = JSON.parse(item.arguments);
713
+ const trimmedArgs = item.arguments.trim();
714
+ parsedInput = trimmedArgs ? JSON.parse(trimmedArgs) : {};
716
715
  }
717
716
  catch (error) {
718
717
  console.warn(`Failed to parse tool call arguments for ${item.name}:`, error instanceof Error ? error.message : String(error), `\nArguments: ${item.arguments.substring(0, 100)}${item.arguments.length > 100 ? '...' : ''}`);
@@ -797,14 +796,10 @@ export function convertToClaudeMessage(response) {
797
796
  }
798
797
  break;
799
798
  }
800
- default: {
801
- // Exhaustiveness check - if a new output type is added, TypeScript will error here
802
- const exhaustiveCheck = item;
803
- // This line should never execute - it means a new type was added to the union
804
- // Throw an error instead of silently continuing to ensure we catch new types
805
- throw new Error(`Unhandled output item type. This indicates a new output type was added to the API. ` +
806
- `Item: ${JSON.stringify(exhaustiveCheck)}`);
807
- }
799
+ default:
800
+ // Unknown output types (e.g. new server tools) are skipped during Claude format
801
+ // conversion they round-trip natively via the Responses API input union.
802
+ break;
808
803
  }
809
804
  }
810
805
  return {
@@ -32,34 +32,19 @@ export function isFunctionCallArgumentsDoneEvent(event) {
32
32
  }
33
33
  // Output item type guards
34
34
  export function isOutputMessage(item) {
35
- return (typeof item === 'object' &&
36
- item !== null &&
37
- 'type' in item &&
38
- item.type === 'message');
35
+ return typeof item === 'object' && item !== null && 'type' in item && item.type === 'message';
39
36
  }
40
37
  export function isFunctionCallItem(item) {
41
- return (typeof item === 'object' &&
42
- item !== null &&
43
- 'type' in item &&
44
- item.type === 'function_call');
38
+ return (typeof item === 'object' && item !== null && 'type' in item && item.type === 'function_call');
45
39
  }
46
40
  export function isReasoningOutputItem(item) {
47
- return (typeof item === 'object' &&
48
- item !== null &&
49
- 'type' in item &&
50
- item.type === 'reasoning');
41
+ return typeof item === 'object' && item !== null && 'type' in item && item.type === 'reasoning';
51
42
  }
52
43
  export function isWebSearchCallOutputItem(item) {
53
- return (typeof item === 'object' &&
54
- item !== null &&
55
- 'type' in item &&
56
- item.type === 'web_search_call');
44
+ return (typeof item === 'object' && item !== null && 'type' in item && item.type === 'web_search_call');
57
45
  }
58
46
  export function isFileSearchCallOutputItem(item) {
59
- return (typeof item === 'object' &&
60
- item !== null &&
61
- 'type' in item &&
62
- item.type === 'file_search_call');
47
+ return (typeof item === 'object' && item !== null && 'type' in item && item.type === 'file_search_call');
63
48
  }
64
49
  export function isImageGenerationCallOutputItem(item) {
65
50
  return (typeof item === 'object' &&
@@ -69,16 +54,10 @@ export function isImageGenerationCallOutputItem(item) {
69
54
  }
70
55
  // Content part type guards
71
56
  export function isOutputTextPart(part) {
72
- return (typeof part === 'object' &&
73
- part !== null &&
74
- 'type' in part &&
75
- part.type === 'output_text');
57
+ return typeof part === 'object' && part !== null && 'type' in part && part.type === 'output_text';
76
58
  }
77
59
  export function isRefusalPart(part) {
78
- return (typeof part === 'object' &&
79
- part !== null &&
80
- 'type' in part &&
81
- part.type === 'refusal');
60
+ return typeof part === 'object' && part !== null && 'type' in part && part.type === 'refusal';
82
61
  }
83
62
  // Annotation type guards for Claude conversion
84
63
  export function isFileCitationAnnotation(annotation) {
@@ -101,9 +80,6 @@ export function isFilePathAnnotation(annotation) {
101
80
  }
102
81
  // Helper to check if output has a type property
103
82
  export function hasTypeProperty(item) {
104
- return (typeof item === 'object' &&
105
- item !== null &&
106
- 'type' in item &&
107
- typeof item.type === 'string');
83
+ return (typeof item === 'object' && item !== null && 'type' in item && typeof item.type === 'string');
108
84
  }
109
85
  //# sourceMappingURL=stream-type-guards.js.map
@@ -0,0 +1,68 @@
1
+ import type { $ZodObject, $ZodShape } from 'zod/v4/core';
2
+ import type { ToolExecuteContext, TurnContext } from './tool-types.js';
3
+ /**
4
+ * Listener function called when context values change
5
+ * Receives a shallow copy of the full context store
6
+ */
7
+ type ContextChangeListener = (snapshot: Record<string, Record<string, unknown>>) => void;
8
+ /**
9
+ * Context input can be a static value, a sync function, or an async function
10
+ */
11
+ export type ContextInput<T extends Record<string, Record<string, unknown>>> = T | ((turn: TurnContext) => T) | ((turn: TurnContext) => Promise<T>);
12
+ /**
13
+ * Mutable context store shared across all tool executions within a callModel invocation.
14
+ * Stores context keyed by tool name: `{ get_weather: { apiKey: '...' }, db_query: { dbUrl: '...' } }`.
15
+ * Notifies listeners on changes.
16
+ */
17
+ export declare class ToolContextStore {
18
+ private store;
19
+ private listeners;
20
+ constructor(initialValues?: Record<string, Record<string, unknown>>);
21
+ /** Subscribe to context changes. Returns an unsubscribe function. */
22
+ subscribe(listener: ContextChangeListener): () => void;
23
+ /** Get a deep-shallow copy of the full context (all tools) */
24
+ getSnapshot(): Record<string, Record<string, unknown>>;
25
+ /** Get a shallow copy of context for a specific tool */
26
+ getToolContext(toolName: string): Record<string, unknown>;
27
+ /** Set context for a specific tool and notify listeners */
28
+ setToolContext(toolName: string, values: Record<string, unknown>): void;
29
+ /** Merge partial values into a specific tool's context and notify listeners */
30
+ mergeToolContext(toolName: string, partial: Record<string, unknown>): void;
31
+ private notifyListeners;
32
+ }
33
+ /**
34
+ * Build a flat ToolExecuteContext for a specific tool.
35
+ * Returns a merged object with TurnContext fields, a `local` getter
36
+ * (reads from the store on each access), `shared` getter, and mutation methods.
37
+ *
38
+ * The `local` and `shared` getters are live — calling `setContext()` or
39
+ * `setSharedContext()` and then reading the property reflects updated values immediately.
40
+ *
41
+ * @param turnContext - The current turn context
42
+ * @param store - The shared context store (keyed by tool name)
43
+ * @param toolName - The tool's name
44
+ * @param schema - The tool's contextSchema (for validation)
45
+ * @param sharedSchema - The shared contextSchema (for validation)
46
+ * @returns A flat ToolExecuteContext
47
+ */
48
+ export declare function buildToolExecuteContext<TName extends string, TContext extends Record<string, unknown>, TShared extends Record<string, unknown> = Record<string, unknown>>(turnContext: TurnContext, store: ToolContextStore | undefined, toolName: TName, schema: $ZodObject<$ZodShape> | undefined, sharedSchema?: $ZodObject<$ZodShape> | undefined): ToolExecuteContext<TName, TContext, TShared>;
49
+ /**
50
+ * Resolve a context input (static value, sync function, or async function) to a plain object.
51
+ *
52
+ * @param contextInput - The context value or function from callModel
53
+ * @param turnContext - The current turn context for function resolution
54
+ * @returns The resolved context object (keyed by tool name)
55
+ */
56
+ export declare function resolveContext<T extends Record<string, Record<string, unknown>>>(contextInput: ContextInput<T> | undefined, turnContext: TurnContext): Promise<T>;
57
+ /**
58
+ * Extract and validate context values for a specific tool from the context store.
59
+ * Returns a shallow copy so the caller cannot mutate the store directly.
60
+ *
61
+ * @param store - The shared context store (keyed by tool name)
62
+ * @param toolName - The tool's name
63
+ * @param schema - The tool's contextSchema
64
+ * @returns A shallow copy of the validated context values for this tool
65
+ */
66
+ export declare function extractToolContext(store: ToolContextStore, toolName: string, schema: $ZodObject<$ZodShape> | undefined): Record<string, unknown>;
67
+ export {};
68
+ //# sourceMappingURL=tool-context.d.ts.map
@@ -0,0 +1,175 @@
1
+ import * as z4 from 'zod/v4';
2
+ import { SHARED_CONTEXT_KEY } from './tool-types.js';
3
+ //#endregion
4
+ //#region ToolContextStore
5
+ /**
6
+ * Mutable context store shared across all tool executions within a callModel invocation.
7
+ * Stores context keyed by tool name: `{ get_weather: { apiKey: '...' }, db_query: { dbUrl: '...' } }`.
8
+ * Notifies listeners on changes.
9
+ */
10
+ export class ToolContextStore {
11
+ constructor(initialValues = {}) {
12
+ this.listeners = new Set();
13
+ this.store = {};
14
+ for (const [key, value] of Object.entries(initialValues)) {
15
+ this.store[key] = { ...value };
16
+ }
17
+ }
18
+ /** Subscribe to context changes. Returns an unsubscribe function. */
19
+ subscribe(listener) {
20
+ this.listeners.add(listener);
21
+ return () => {
22
+ this.listeners.delete(listener);
23
+ };
24
+ }
25
+ /** Get a deep-shallow copy of the full context (all tools) */
26
+ getSnapshot() {
27
+ const snapshot = {};
28
+ for (const [key, value] of Object.entries(this.store)) {
29
+ snapshot[key] = { ...value };
30
+ }
31
+ return snapshot;
32
+ }
33
+ /** Get a shallow copy of context for a specific tool */
34
+ getToolContext(toolName) {
35
+ const data = this.store[toolName];
36
+ if (!data) {
37
+ return {};
38
+ }
39
+ return { ...data };
40
+ }
41
+ /** Set context for a specific tool and notify listeners */
42
+ setToolContext(toolName, values) {
43
+ this.store[toolName] = { ...values };
44
+ this.notifyListeners();
45
+ }
46
+ /** Merge partial values into a specific tool's context and notify listeners */
47
+ mergeToolContext(toolName, partial) {
48
+ const existing = this.store[toolName] ?? {};
49
+ this.store[toolName] = { ...existing, ...partial };
50
+ this.notifyListeners();
51
+ }
52
+ notifyListeners() {
53
+ const snapshot = {};
54
+ for (const [key, value] of Object.entries(this.store)) {
55
+ snapshot[key] = { ...value };
56
+ }
57
+ for (const listener of this.listeners) {
58
+ listener(snapshot);
59
+ }
60
+ }
61
+ }
62
+ //#endregion
63
+ //#region buildToolExecuteContext
64
+ /**
65
+ * Validate a partial update against a schema's shape, filtering to known keys
66
+ * and validating each key individually. Returns the filtered partial.
67
+ */
68
+ function validatePartialAgainstSchema(partial, schema) {
69
+ const schemaKeys = Object.keys(schema._zod.def.shape);
70
+ const filteredPartial = {};
71
+ for (const [key, value] of Object.entries(partial)) {
72
+ if (schemaKeys.includes(key)) {
73
+ filteredPartial[key] = value;
74
+ }
75
+ }
76
+ const shape = schema._zod.def.shape;
77
+ for (const [key, value] of Object.entries(filteredPartial)) {
78
+ const keySchema = shape[key];
79
+ if (keySchema) {
80
+ z4.parse(keySchema, value);
81
+ }
82
+ }
83
+ return filteredPartial;
84
+ }
85
+ /**
86
+ * Build a flat ToolExecuteContext for a specific tool.
87
+ * Returns a merged object with TurnContext fields, a `local` getter
88
+ * (reads from the store on each access), `shared` getter, and mutation methods.
89
+ *
90
+ * The `local` and `shared` getters are live — calling `setContext()` or
91
+ * `setSharedContext()` and then reading the property reflects updated values immediately.
92
+ *
93
+ * @param turnContext - The current turn context
94
+ * @param store - The shared context store (keyed by tool name)
95
+ * @param toolName - The tool's name
96
+ * @param schema - The tool's contextSchema (for validation)
97
+ * @param sharedSchema - The shared contextSchema (for validation)
98
+ * @returns A flat ToolExecuteContext
99
+ */
100
+ export function buildToolExecuteContext(turnContext, store, toolName, schema, sharedSchema) {
101
+ // Validate initial context eagerly (throws on bad data)
102
+ if (store && schema) {
103
+ extractToolContext(store, toolName, schema);
104
+ }
105
+ if (store && sharedSchema) {
106
+ extractToolContext(store, SHARED_CONTEXT_KEY, sharedSchema);
107
+ }
108
+ const ctx = {
109
+ ...turnContext,
110
+ get local() {
111
+ const data = store ? store.getToolContext(toolName) : {};
112
+ return Object.freeze(data);
113
+ },
114
+ setContext(partial) {
115
+ if (!store || !schema) {
116
+ return;
117
+ }
118
+ const filteredPartial = validatePartialAgainstSchema(partial, schema);
119
+ store.mergeToolContext(toolName, filteredPartial);
120
+ },
121
+ get shared() {
122
+ const data = store ? store.getToolContext(SHARED_CONTEXT_KEY) : {};
123
+ return Object.freeze(data);
124
+ },
125
+ setSharedContext(partial) {
126
+ if (!store || !sharedSchema) {
127
+ return;
128
+ }
129
+ const filteredPartial = validatePartialAgainstSchema(partial, sharedSchema);
130
+ store.mergeToolContext(SHARED_CONTEXT_KEY, filteredPartial);
131
+ },
132
+ };
133
+ return ctx;
134
+ }
135
+ //#endregion
136
+ //#region resolveContext
137
+ /**
138
+ * Resolve a context input (static value, sync function, or async function) to a plain object.
139
+ *
140
+ * @param contextInput - The context value or function from callModel
141
+ * @param turnContext - The current turn context for function resolution
142
+ * @returns The resolved context object (keyed by tool name)
143
+ */
144
+ export async function resolveContext(contextInput, turnContext) {
145
+ if (contextInput === undefined) {
146
+ return {};
147
+ }
148
+ if (typeof contextInput === 'function') {
149
+ return Promise.resolve(contextInput(turnContext));
150
+ }
151
+ return contextInput;
152
+ }
153
+ //#endregion
154
+ //#region extractToolContext
155
+ /**
156
+ * Extract and validate context values for a specific tool from the context store.
157
+ * Returns a shallow copy so the caller cannot mutate the store directly.
158
+ *
159
+ * @param store - The shared context store (keyed by tool name)
160
+ * @param toolName - The tool's name
161
+ * @param schema - The tool's contextSchema
162
+ * @returns A shallow copy of the validated context values for this tool
163
+ */
164
+ export function extractToolContext(store, toolName, schema) {
165
+ if (!schema) {
166
+ return {};
167
+ }
168
+ const toolData = store.getToolContext(toolName);
169
+ // Validate the extracted values against the schema
170
+ z4.parse(schema, toolData);
171
+ // getToolContext already returns a shallow copy
172
+ return toolData;
173
+ }
174
+ //#endregion
175
+ //# sourceMappingURL=tool-context.js.map
@@ -1,6 +1,8 @@
1
1
  import type { $ZodType } from 'zod/v4/core';
2
- import type { APITool, Tool, ParsedToolCall, ToolExecutionResult, TurnContext } from './tool-types.js';
2
+ import type { $ZodObject, $ZodShape } from 'zod/v4/core';
3
+ import type { APITool, ParsedToolCall, Tool, ToolExecutionResult, TurnContext } from './tool-types.js';
3
4
  import * as z4 from 'zod/v4';
5
+ import { type ToolContextStore } from './tool-context.js';
4
6
  export declare const ZodError: z4.z.core.$constructor<z4.ZodError<unknown>, z4.z.core.$ZodIssue[]>;
5
7
  /**
6
8
  * Recursively remove keys prefixed with ~ from an object.
@@ -36,25 +38,27 @@ export declare function validateToolInput<T>(schema: $ZodType<T>, args: unknown)
36
38
  */
37
39
  export declare function validateToolOutput<T>(schema: $ZodType<T>, result: unknown): T;
38
40
  /**
39
- * Parse tool call arguments from JSON string
41
+ * Parse tool call arguments from JSON string.
42
+ * Treats empty/whitespace-only strings as an empty object — some providers
43
+ * return `arguments: ""` for tools that take no parameters.
40
44
  */
41
45
  export declare function parseToolCallArguments(argumentsString: string): unknown;
42
46
  /**
43
47
  * Execute a regular (non-generator) tool
44
48
  */
45
- export declare function executeRegularTool(tool: Tool, toolCall: ParsedToolCall<Tool>, context: TurnContext): Promise<ToolExecutionResult<Tool>>;
49
+ export declare function executeRegularTool(tool: Tool, toolCall: ParsedToolCall<Tool>, context: TurnContext, contextStore?: ToolContextStore, sharedSchema?: $ZodObject<$ZodShape>): Promise<ToolExecutionResult<Tool>>;
46
50
  /**
47
51
  * Execute a generator tool and collect preliminary and final results
48
52
  * - Intermediate yields are validated against eventSchema (preliminary events)
49
53
  * - Last yield is validated against outputSchema (final result sent to model)
50
54
  * - Generator must emit at least one value
51
55
  */
52
- export declare function executeGeneratorTool(tool: Tool, toolCall: ParsedToolCall<Tool>, context: TurnContext, onPreliminaryResult?: (toolCallId: string, result: unknown) => void): Promise<ToolExecutionResult<Tool>>;
56
+ export declare function executeGeneratorTool(tool: Tool, toolCall: ParsedToolCall<Tool>, context: TurnContext, onPreliminaryResult?: (toolCallId: string, result: unknown) => void, contextStore?: ToolContextStore, sharedSchema?: $ZodObject<$ZodShape>): Promise<ToolExecutionResult<Tool>>;
53
57
  /**
54
58
  * Execute a tool call
55
59
  * Automatically detects if it's a regular or generator tool
56
60
  */
57
- export declare function executeTool(tool: Tool, toolCall: ParsedToolCall<Tool>, context: TurnContext, onPreliminaryResult?: (toolCallId: string, result: unknown) => void): Promise<ToolExecutionResult<Tool>>;
61
+ export declare function executeTool(tool: Tool, toolCall: ParsedToolCall<Tool>, context: TurnContext, onPreliminaryResult?: (toolCallId: string, result: unknown) => void, contextStore?: ToolContextStore, sharedSchema?: $ZodObject<$ZodShape>): Promise<ToolExecutionResult<Tool>>;
58
62
  /**
59
63
  * Find a tool by name in the tools array
60
64
  */