@openrouter/sdk 0.3.1 → 0.3.7

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 (296) hide show
  1. package/esm/core.js +1 -0
  2. package/esm/funcs/analyticsGetUserActivity.js +1 -0
  3. package/esm/funcs/apiKeysCreate.js +1 -0
  4. package/esm/funcs/apiKeysDelete.js +1 -0
  5. package/esm/funcs/apiKeysGet.js +1 -0
  6. package/esm/funcs/apiKeysGetCurrentKeyMetadata.js +1 -0
  7. package/esm/funcs/apiKeysList.js +1 -0
  8. package/esm/funcs/apiKeysUpdate.js +1 -0
  9. package/esm/funcs/betaResponsesSend.js +1 -0
  10. package/esm/funcs/call-model.d.ts +33 -0
  11. package/esm/funcs/call-model.js +155 -0
  12. package/esm/funcs/chatSend.js +1 -0
  13. package/esm/funcs/completionsGenerate.js +1 -0
  14. package/esm/funcs/creditsCreateCoinbaseCharge.js +1 -0
  15. package/esm/funcs/creditsGetCredits.js +1 -0
  16. package/esm/funcs/embeddingsGenerate.js +1 -0
  17. package/esm/funcs/embeddingsListModels.js +1 -0
  18. package/esm/funcs/endpointsList.js +1 -0
  19. package/esm/funcs/endpointsListZdrEndpoints.js +1 -0
  20. package/esm/funcs/generationsGetGeneration.js +1 -0
  21. package/esm/funcs/modelsCount.js +1 -0
  22. package/esm/funcs/modelsList.js +1 -0
  23. package/esm/funcs/modelsListForUser.js +1 -0
  24. package/esm/funcs/oAuthCreateAuthCode.js +1 -0
  25. package/esm/funcs/oAuthExchangeAuthCodeForAPIKey.js +1 -0
  26. package/esm/funcs/parametersGetParameters.js +1 -0
  27. package/esm/funcs/providersList.js +1 -0
  28. package/esm/hooks/hooks.js +1 -0
  29. package/esm/hooks/index.js +1 -0
  30. package/esm/hooks/types.js +1 -0
  31. package/esm/index.d.ts +3 -0
  32. package/esm/index.js +4 -0
  33. package/esm/lib/anthropic-compat.d.ts +46 -0
  34. package/esm/lib/anthropic-compat.js +204 -0
  35. package/esm/lib/anthropic-compat.test.d.ts +2 -0
  36. package/esm/lib/anthropic-compat.test.js +479 -0
  37. package/esm/lib/base64.js +1 -0
  38. package/esm/lib/chat-compat.d.ts +46 -0
  39. package/esm/lib/chat-compat.js +108 -0
  40. package/esm/lib/chat-compat.test.d.ts +2 -0
  41. package/esm/lib/chat-compat.test.js +282 -0
  42. package/esm/lib/config.d.ts +3 -3
  43. package/esm/lib/config.js +4 -3
  44. package/esm/lib/dlv.js +1 -0
  45. package/esm/lib/encodings.js +1 -0
  46. package/esm/lib/env.js +1 -0
  47. package/esm/lib/event-streams.js +2 -1
  48. package/esm/lib/files.js +1 -0
  49. package/esm/lib/http.js +1 -0
  50. package/esm/lib/is-plain-object.js +1 -0
  51. package/esm/lib/logger.js +1 -0
  52. package/esm/lib/matchers.js +1 -0
  53. package/esm/lib/{response-wrapper.d.ts → model-result.d.ts} +19 -26
  54. package/esm/lib/{response-wrapper.js → model-result.js} +93 -83
  55. package/esm/lib/primitives.js +1 -0
  56. package/esm/lib/retries.js +1 -0
  57. package/esm/lib/schemas.js +1 -0
  58. package/esm/lib/sdks.js +1 -0
  59. package/esm/lib/security.js +1 -0
  60. package/esm/lib/stream-transformers.d.ts +27 -1
  61. package/esm/lib/stream-transformers.js +319 -1
  62. package/esm/lib/tool-types.d.ts +3 -3
  63. package/esm/lib/url.js +1 -0
  64. package/esm/models/activityitem.js +1 -0
  65. package/esm/models/assistantmessage.js +1 -0
  66. package/esm/models/badgatewayresponseerrordata.js +1 -0
  67. package/esm/models/badrequestresponseerrordata.js +1 -0
  68. package/esm/models/chatcompletionfinishreason.js +1 -0
  69. package/esm/models/chaterror.js +1 -0
  70. package/esm/models/chatgenerationparams.js +1 -0
  71. package/esm/models/chatgenerationtokenusage.js +1 -0
  72. package/esm/models/chatmessagecontentitem.js +1 -0
  73. package/esm/models/chatmessagecontentitemaudio.js +1 -0
  74. package/esm/models/chatmessagecontentitemcachecontrol.js +1 -0
  75. package/esm/models/chatmessagecontentitemimage.js +1 -0
  76. package/esm/models/chatmessagecontentitemtext.js +1 -0
  77. package/esm/models/chatmessagecontentitemvideo.js +1 -0
  78. package/esm/models/chatmessagetokenlogprob.js +1 -0
  79. package/esm/models/chatmessagetokenlogprobs.js +1 -0
  80. package/esm/models/chatmessagetoolcall.js +1 -0
  81. package/esm/models/chatresponse.js +1 -0
  82. package/esm/models/chatresponsechoice.js +1 -0
  83. package/esm/models/chatstreamingchoice.js +1 -0
  84. package/esm/models/chatstreamingmessagechunk.js +1 -0
  85. package/esm/models/chatstreamingmessagetoolcall.js +1 -0
  86. package/esm/models/chatstreamingresponsechunk.js +1 -0
  87. package/esm/models/chatstreamoptions.js +1 -0
  88. package/esm/models/claude-message.d.ts +218 -0
  89. package/esm/models/claude-message.js +6 -0
  90. package/esm/models/completionchoice.js +1 -0
  91. package/esm/models/completioncreateparams.js +1 -0
  92. package/esm/models/completionlogprobs.js +1 -0
  93. package/esm/models/completionresponse.js +1 -0
  94. package/esm/models/completionusage.js +1 -0
  95. package/esm/models/createchargerequest.js +1 -0
  96. package/esm/models/datacollection.js +1 -0
  97. package/esm/models/defaultparameters.js +1 -0
  98. package/esm/models/edgenetworktimeoutresponseerrordata.js +1 -0
  99. package/esm/models/endpointstatus.js +1 -0
  100. package/esm/models/errors/badgatewayresponseerror.js +1 -0
  101. package/esm/models/errors/badrequestresponseerror.js +1 -0
  102. package/esm/models/errors/chaterror.js +1 -0
  103. package/esm/models/errors/edgenetworktimeoutresponseerror.js +1 -0
  104. package/esm/models/errors/forbiddenresponseerror.js +1 -0
  105. package/esm/models/errors/httpclienterrors.js +1 -0
  106. package/esm/models/errors/index.js +1 -0
  107. package/esm/models/errors/internalserverresponseerror.js +1 -0
  108. package/esm/models/errors/notfoundresponseerror.js +1 -0
  109. package/esm/models/errors/openrouterdefaulterror.js +1 -0
  110. package/esm/models/errors/openroutererror.js +1 -0
  111. package/esm/models/errors/payloadtoolargeresponseerror.js +1 -0
  112. package/esm/models/errors/paymentrequiredresponseerror.js +1 -0
  113. package/esm/models/errors/provideroverloadedresponseerror.js +1 -0
  114. package/esm/models/errors/requesttimeoutresponseerror.js +1 -0
  115. package/esm/models/errors/responsevalidationerror.js +1 -0
  116. package/esm/models/errors/sdkvalidationerror.js +1 -0
  117. package/esm/models/errors/serviceunavailableresponseerror.js +1 -0
  118. package/esm/models/errors/toomanyrequestsresponseerror.js +1 -0
  119. package/esm/models/errors/unauthorizedresponseerror.js +1 -0
  120. package/esm/models/errors/unprocessableentityresponseerror.js +1 -0
  121. package/esm/models/filecitation.js +1 -0
  122. package/esm/models/filepath.js +1 -0
  123. package/esm/models/forbiddenresponseerrordata.js +1 -0
  124. package/esm/models/imagegenerationstatus.js +1 -0
  125. package/esm/models/index.d.ts +1 -0
  126. package/esm/models/index.js +2 -0
  127. package/esm/models/inputmodality.js +1 -0
  128. package/esm/models/instructtype.js +1 -0
  129. package/esm/models/internalserverresponseerrordata.js +1 -0
  130. package/esm/models/jsonschemaconfig.js +1 -0
  131. package/esm/models/listendpointsresponse.js +1 -0
  132. package/esm/models/message.js +1 -0
  133. package/esm/models/model.js +1 -0
  134. package/esm/models/modelarchitecture.js +1 -0
  135. package/esm/models/modelgroup.js +1 -0
  136. package/esm/models/modelscountresponse.js +1 -0
  137. package/esm/models/modelslistresponse.js +1 -0
  138. package/esm/models/namedtoolchoice.js +1 -0
  139. package/esm/models/notfoundresponseerrordata.js +1 -0
  140. package/esm/models/openairesponsesannotation.js +1 -0
  141. package/esm/models/openairesponsesincludable.js +1 -0
  142. package/esm/models/openairesponsesincompletedetails.js +1 -0
  143. package/esm/models/openairesponsesinputunion.js +1 -0
  144. package/esm/models/openairesponsesprompt.js +1 -0
  145. package/esm/models/openairesponsesreasoningconfig.js +1 -0
  146. package/esm/models/openairesponsesreasoningeffort.js +1 -0
  147. package/esm/models/openairesponsesrefusalcontent.js +1 -0
  148. package/esm/models/openairesponsesresponsestatus.js +1 -0
  149. package/esm/models/openairesponsesservicetier.js +1 -0
  150. package/esm/models/openairesponsestoolchoiceunion.js +1 -0
  151. package/esm/models/openairesponsestruncation.js +1 -0
  152. package/esm/models/openresponseseasyinputmessage.js +1 -0
  153. package/esm/models/openresponseserrorevent.js +1 -0
  154. package/esm/models/openresponsesfunctioncalloutput.js +1 -0
  155. package/esm/models/openresponsesfunctiontoolcall.js +1 -0
  156. package/esm/models/openresponsesimagegencallcompleted.js +1 -0
  157. package/esm/models/openresponsesimagegencallgenerating.js +1 -0
  158. package/esm/models/openresponsesimagegencallinprogress.js +1 -0
  159. package/esm/models/openresponsesimagegencallpartialimage.js +1 -0
  160. package/esm/models/openresponsesinput.js +1 -0
  161. package/esm/models/openresponsesinputmessageitem.js +1 -0
  162. package/esm/models/openresponseslogprobs.js +1 -0
  163. package/esm/models/openresponsesnonstreamingresponse.js +1 -0
  164. package/esm/models/openresponsesreasoning.js +1 -0
  165. package/esm/models/openresponsesreasoningconfig.js +1 -0
  166. package/esm/models/openresponsesreasoningdeltaevent.js +1 -0
  167. package/esm/models/openresponsesreasoningdoneevent.js +1 -0
  168. package/esm/models/openresponsesreasoningsummarypartaddedevent.js +1 -0
  169. package/esm/models/openresponsesreasoningsummarytextdeltaevent.js +1 -0
  170. package/esm/models/openresponsesreasoningsummarytextdoneevent.js +1 -0
  171. package/esm/models/openresponsesrequest.js +1 -0
  172. package/esm/models/openresponsesresponsetext.js +1 -0
  173. package/esm/models/openresponsesstreamevent.js +1 -0
  174. package/esm/models/openresponsestoplogprobs.js +1 -0
  175. package/esm/models/openresponsesusage.js +1 -0
  176. package/esm/models/openresponseswebsearch20250826tool.js +1 -0
  177. package/esm/models/openresponseswebsearchpreview20250311tool.js +1 -0
  178. package/esm/models/openresponseswebsearchpreviewtool.js +1 -0
  179. package/esm/models/openresponseswebsearchtool.js +1 -0
  180. package/esm/models/operations/createauthkeyscode.js +1 -0
  181. package/esm/models/operations/createcoinbasecharge.js +1 -0
  182. package/esm/models/operations/createembeddings.js +1 -0
  183. package/esm/models/operations/createkeys.js +1 -0
  184. package/esm/models/operations/createresponses.js +1 -0
  185. package/esm/models/operations/deletekeys.js +1 -0
  186. package/esm/models/operations/exchangeauthcodeforapikey.js +1 -0
  187. package/esm/models/operations/getcredits.js +1 -0
  188. package/esm/models/operations/getcurrentkey.js +1 -0
  189. package/esm/models/operations/getgeneration.js +1 -0
  190. package/esm/models/operations/getkey.js +1 -0
  191. package/esm/models/operations/getmodels.js +1 -0
  192. package/esm/models/operations/getparameters.js +1 -0
  193. package/esm/models/operations/getuseractivity.js +1 -0
  194. package/esm/models/operations/index.js +1 -0
  195. package/esm/models/operations/list.js +1 -0
  196. package/esm/models/operations/listendpoints.js +1 -0
  197. package/esm/models/operations/listendpointszdr.js +1 -0
  198. package/esm/models/operations/listmodelsuser.js +1 -0
  199. package/esm/models/operations/listproviders.js +1 -0
  200. package/esm/models/operations/sendchatcompletionrequest.js +1 -0
  201. package/esm/models/operations/updatekeys.js +1 -0
  202. package/esm/models/outputitemimagegenerationcall.d.ts +1 -1
  203. package/esm/models/outputitemimagegenerationcall.js +1 -0
  204. package/esm/models/outputmessage.js +1 -0
  205. package/esm/models/outputmodality.js +1 -0
  206. package/esm/models/parameter.js +1 -0
  207. package/esm/models/payloadtoolargeresponseerrordata.js +1 -0
  208. package/esm/models/paymentrequiredresponseerrordata.js +1 -0
  209. package/esm/models/pdfparserengine.js +1 -0
  210. package/esm/models/pdfparseroptions.js +1 -0
  211. package/esm/models/perrequestlimits.js +1 -0
  212. package/esm/models/providername.js +1 -0
  213. package/esm/models/provideroverloadedresponseerrordata.js +1 -0
  214. package/esm/models/providerpreferences.js +1 -0
  215. package/esm/models/providersort.js +1 -0
  216. package/esm/models/providersortconfig.js +1 -0
  217. package/esm/models/providersortunion.js +1 -0
  218. package/esm/models/publicendpoint.js +1 -0
  219. package/esm/models/publicpricing.js +1 -0
  220. package/esm/models/quantization.js +1 -0
  221. package/esm/models/reasoningsummarytext.js +1 -0
  222. package/esm/models/reasoningsummaryverbosity.js +1 -0
  223. package/esm/models/reasoningtextcontent.js +1 -0
  224. package/esm/models/requesttimeoutresponseerrordata.js +1 -0
  225. package/esm/models/responseformatjsonschema.js +1 -0
  226. package/esm/models/responseformattextconfig.js +1 -0
  227. package/esm/models/responseformattextgrammar.js +1 -0
  228. package/esm/models/responseinputaudio.js +1 -0
  229. package/esm/models/responseinputfile.js +1 -0
  230. package/esm/models/responseinputimage.js +1 -0
  231. package/esm/models/responseinputtext.js +1 -0
  232. package/esm/models/responseoutputtext.js +1 -0
  233. package/esm/models/responseserrorfield.js +1 -0
  234. package/esm/models/responsesformatjsonobject.js +1 -0
  235. package/esm/models/responsesformattext.js +1 -0
  236. package/esm/models/responsesformattextjsonschemaconfig.js +1 -0
  237. package/esm/models/responsesimagegenerationcall.js +1 -0
  238. package/esm/models/responsesoutputitem.js +1 -0
  239. package/esm/models/responsesoutputitemfilesearchcall.js +1 -0
  240. package/esm/models/responsesoutputitemfunctioncall.js +1 -0
  241. package/esm/models/responsesoutputitemreasoning.js +1 -0
  242. package/esm/models/responsesoutputmessage.js +1 -0
  243. package/esm/models/responsessearchcontextsize.js +1 -0
  244. package/esm/models/responseswebsearchcalloutput.js +1 -0
  245. package/esm/models/responseswebsearchuserlocation.js +1 -0
  246. package/esm/models/responsetextconfig.js +1 -0
  247. package/esm/models/schema0.js +1 -0
  248. package/esm/models/schema3.js +1 -0
  249. package/esm/models/security.js +1 -0
  250. package/esm/models/serviceunavailableresponseerrordata.js +1 -0
  251. package/esm/models/systemmessage.js +1 -0
  252. package/esm/models/toolcallstatus.js +1 -0
  253. package/esm/models/tooldefinitionjson.js +1 -0
  254. package/esm/models/toolresponsemessage.js +1 -0
  255. package/esm/models/toomanyrequestsresponseerrordata.js +1 -0
  256. package/esm/models/topproviderinfo.js +1 -0
  257. package/esm/models/unauthorizedresponseerrordata.js +1 -0
  258. package/esm/models/unprocessableentityresponseerrordata.js +1 -0
  259. package/esm/models/urlcitation.js +1 -0
  260. package/esm/models/usermessage.js +1 -0
  261. package/esm/models/websearchengine.js +1 -0
  262. package/esm/models/websearchpreviewtooluserlocation.js +1 -0
  263. package/esm/models/websearchstatus.js +1 -0
  264. package/esm/sdk/analytics.js +1 -0
  265. package/esm/sdk/apikeys.js +1 -0
  266. package/esm/sdk/beta.js +1 -0
  267. package/esm/sdk/chat.js +1 -0
  268. package/esm/sdk/completions.js +1 -0
  269. package/esm/sdk/credits.js +1 -0
  270. package/esm/sdk/embeddings.js +1 -0
  271. package/esm/sdk/endpoints.js +1 -0
  272. package/esm/sdk/generations.js +1 -0
  273. package/esm/sdk/index.js +1 -0
  274. package/esm/sdk/models.js +1 -0
  275. package/esm/sdk/oauth.js +1 -0
  276. package/esm/sdk/parameters.js +1 -0
  277. package/esm/sdk/providers.js +1 -0
  278. package/esm/sdk/responses.js +1 -0
  279. package/esm/sdk/sdk.d.ts +3 -3
  280. package/esm/sdk/sdk.js +2 -1
  281. package/esm/types/async.js +1 -0
  282. package/esm/types/blobs.js +1 -0
  283. package/esm/types/constdatetime.js +1 -0
  284. package/esm/types/discriminatedUnion.js +1 -0
  285. package/esm/types/enums.js +1 -0
  286. package/esm/types/fp.js +1 -0
  287. package/esm/types/index.js +1 -0
  288. package/esm/types/operations.js +1 -0
  289. package/esm/types/rfcdate.js +1 -0
  290. package/esm/types/streams.js +1 -0
  291. package/esm/types/unrecognized.js +1 -0
  292. package/jsr.json +1 -1
  293. package/package.json +1 -1
  294. package/tsconfig.json +1 -1
  295. package/esm/funcs/callModel.d.ts +0 -87
  296. package/esm/funcs/callModel.js +0 -215
@@ -40,6 +40,66 @@ export async function* extractToolDeltas(stream) {
40
40
  }
41
41
  }
42
42
  }
43
+ /**
44
+ * Build incremental message updates from responses stream events
45
+ * Returns ResponsesOutputMessage (assistant/responses format)
46
+ */
47
+ export async function* buildResponsesMessageStream(stream) {
48
+ const consumer = stream.createConsumer();
49
+ // Track the accumulated text and message info
50
+ let currentText = '';
51
+ let currentId = '';
52
+ let hasStarted = false;
53
+ for await (const event of consumer) {
54
+ if (!('type' in event)) {
55
+ continue;
56
+ }
57
+ switch (event.type) {
58
+ case 'response.output_item.added': {
59
+ const itemEvent = event;
60
+ if (itemEvent.item && 'type' in itemEvent.item && itemEvent.item.type === 'message') {
61
+ hasStarted = true;
62
+ currentText = '';
63
+ const msgItem = itemEvent.item;
64
+ currentId = msgItem.id;
65
+ }
66
+ break;
67
+ }
68
+ case 'response.output_text.delta': {
69
+ const deltaEvent = event;
70
+ if (hasStarted && deltaEvent.delta) {
71
+ currentText += deltaEvent.delta;
72
+ // Yield updated message in ResponsesOutputMessage format
73
+ yield {
74
+ id: currentId,
75
+ type: 'message',
76
+ role: 'assistant',
77
+ status: 'in_progress',
78
+ content: [
79
+ {
80
+ type: 'output_text',
81
+ text: currentText,
82
+ annotations: [],
83
+ },
84
+ ],
85
+ };
86
+ }
87
+ break;
88
+ }
89
+ case 'response.output_item.done': {
90
+ const itemDoneEvent = event;
91
+ if (itemDoneEvent.item &&
92
+ 'type' in itemDoneEvent.item &&
93
+ itemDoneEvent.item.type === 'message') {
94
+ // Yield final complete message in ResponsesOutputMessage format
95
+ const outputMessage = itemDoneEvent.item;
96
+ yield outputMessage;
97
+ }
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ }
43
103
  /**
44
104
  * Build incremental message updates from responses stream events
45
105
  * Returns AssistantMessage (chat format) instead of ResponsesOutputMessage
@@ -129,7 +189,7 @@ function convertToAssistantMessage(outputMessage) {
129
189
  };
130
190
  }
131
191
  /**
132
- * Extract the first message from a completed response
192
+ * Extract the first message from a completed response (chat format)
133
193
  */
134
194
  export function extractMessageFromResponse(response) {
135
195
  const messageItem = response.output.find((item) => 'type' in item && item.type === 'message');
@@ -138,6 +198,16 @@ export function extractMessageFromResponse(response) {
138
198
  }
139
199
  return convertToAssistantMessage(messageItem);
140
200
  }
201
+ /**
202
+ * Extract the first message from a completed response (responses format)
203
+ */
204
+ export function extractResponsesMessageFromResponse(response) {
205
+ const messageItem = response.output.find((item) => 'type' in item && item.type === 'message');
206
+ if (!messageItem) {
207
+ throw new Error('No message found in response output');
208
+ }
209
+ return messageItem;
210
+ }
141
211
  /**
142
212
  * Extract text from a response, either from outputText or by concatenating message content
143
213
  */
@@ -279,4 +349,252 @@ export async function* buildToolCallStream(stream) {
279
349
  export function responseHasToolCalls(response) {
280
350
  return response.output.some((item) => 'type' in item && item.type === 'function_call');
281
351
  }
352
+ /**
353
+ * Convert OpenRouter annotations to Claude citations
354
+ */
355
+ function mapAnnotationsToCitations(annotations) {
356
+ if (!annotations || annotations.length === 0) {
357
+ return undefined;
358
+ }
359
+ const citations = [];
360
+ for (const annotation of annotations) {
361
+ if (!('type' in annotation)) {
362
+ continue;
363
+ }
364
+ switch (annotation.type) {
365
+ case 'file_citation': {
366
+ const fileCite = annotation;
367
+ citations.push({
368
+ type: 'char_location',
369
+ cited_text: '',
370
+ document_index: fileCite.index,
371
+ document_title: fileCite.filename,
372
+ file_id: fileCite.fileId,
373
+ start_char_index: 0,
374
+ end_char_index: 0,
375
+ });
376
+ break;
377
+ }
378
+ case 'url_citation': {
379
+ const urlCite = annotation;
380
+ citations.push({
381
+ type: 'web_search_result_location',
382
+ cited_text: '',
383
+ title: urlCite.title,
384
+ url: urlCite.url,
385
+ encrypted_index: '',
386
+ });
387
+ break;
388
+ }
389
+ case 'file_path': {
390
+ const pathCite = annotation;
391
+ citations.push({
392
+ type: 'char_location',
393
+ cited_text: '',
394
+ document_index: pathCite.index,
395
+ document_title: '',
396
+ file_id: pathCite.fileId,
397
+ start_char_index: 0,
398
+ end_char_index: 0,
399
+ });
400
+ break;
401
+ }
402
+ default: {
403
+ const _exhaustiveCheck = annotation;
404
+ throw new Error(`Unhandled annotation type: ${_exhaustiveCheck.type}`);
405
+ }
406
+ }
407
+ }
408
+ return citations.length > 0 ? citations : undefined;
409
+ }
410
+ /**
411
+ * Map OpenResponses status to Claude stop reason
412
+ */
413
+ function mapStopReason(response) {
414
+ // Check if any tool calls exist in the response
415
+ const hasToolCalls = response.output.some((item) => 'type' in item && item.type === 'function_call');
416
+ if (hasToolCalls) {
417
+ return 'tool_use';
418
+ }
419
+ // Check the response status
420
+ if (response.status === 'completed') {
421
+ return 'end_turn';
422
+ }
423
+ if (response.status === 'incomplete') {
424
+ // Check incomplete reason if available
425
+ const incompleteReason = response.incompleteDetails?.reason;
426
+ if (incompleteReason === 'max_output_tokens') {
427
+ return 'max_tokens';
428
+ }
429
+ return 'end_turn';
430
+ }
431
+ return 'end_turn';
432
+ }
433
+ /**
434
+ * Convert OpenResponsesNonStreamingResponse to ClaudeMessage format
435
+ * Compatible with the Anthropic SDK BetaMessage type
436
+ */
437
+ export function convertToClaudeMessage(response) {
438
+ const content = [];
439
+ const unsupportedContent = [];
440
+ for (const item of response.output) {
441
+ if (!('type' in item)) {
442
+ continue;
443
+ }
444
+ switch (item.type) {
445
+ case 'message': {
446
+ const msgItem = item;
447
+ for (const part of msgItem.content) {
448
+ if (!('type' in part)) {
449
+ continue;
450
+ }
451
+ if (part.type === 'output_text') {
452
+ const textPart = part;
453
+ const citations = mapAnnotationsToCitations(textPart.annotations);
454
+ content.push({
455
+ type: 'text',
456
+ text: textPart.text,
457
+ ...(citations && { citations }),
458
+ });
459
+ }
460
+ else if (part.type === 'refusal') {
461
+ const refusalPart = part;
462
+ unsupportedContent.push({
463
+ original_type: 'refusal',
464
+ data: { refusal: refusalPart.refusal },
465
+ reason: 'Claude does not have a native refusal content type',
466
+ });
467
+ }
468
+ }
469
+ break;
470
+ }
471
+ case 'function_call': {
472
+ const fnCall = item;
473
+ let parsedInput = {};
474
+ try {
475
+ parsedInput = JSON.parse(fnCall.arguments);
476
+ }
477
+ catch {
478
+ parsedInput = {};
479
+ }
480
+ content.push({
481
+ type: 'tool_use',
482
+ id: fnCall.callId,
483
+ name: fnCall.name,
484
+ input: parsedInput,
485
+ });
486
+ break;
487
+ }
488
+ case 'reasoning': {
489
+ const reasoningItem = item;
490
+ if (reasoningItem.summary && reasoningItem.summary.length > 0) {
491
+ for (const summaryItem of reasoningItem.summary) {
492
+ if (summaryItem.type === 'summary_text' && summaryItem.text) {
493
+ content.push({
494
+ type: 'thinking',
495
+ thinking: summaryItem.text,
496
+ signature: '',
497
+ });
498
+ }
499
+ }
500
+ }
501
+ if (reasoningItem.encryptedContent) {
502
+ unsupportedContent.push({
503
+ original_type: 'reasoning_encrypted',
504
+ data: {
505
+ id: reasoningItem.id,
506
+ encrypted_content: reasoningItem.encryptedContent,
507
+ },
508
+ reason: 'Encrypted reasoning content preserved for round-trip',
509
+ });
510
+ }
511
+ break;
512
+ }
513
+ case 'web_search_call': {
514
+ const webSearchItem = item;
515
+ content.push({
516
+ type: 'server_tool_use',
517
+ id: webSearchItem.id,
518
+ name: 'web_search',
519
+ input: { status: webSearchItem.status },
520
+ });
521
+ break;
522
+ }
523
+ case 'file_search_call': {
524
+ const fileSearchItem = item;
525
+ content.push({
526
+ type: 'tool_use',
527
+ id: fileSearchItem.id,
528
+ name: 'file_search',
529
+ input: {
530
+ queries: fileSearchItem.queries,
531
+ status: fileSearchItem.status,
532
+ },
533
+ });
534
+ break;
535
+ }
536
+ case 'image_generation_call': {
537
+ const imageGenItem = item;
538
+ unsupportedContent.push({
539
+ original_type: 'image_generation_call',
540
+ data: {
541
+ id: imageGenItem.id,
542
+ result: imageGenItem.result,
543
+ status: imageGenItem.status,
544
+ },
545
+ reason: 'Claude does not support image outputs in assistant messages',
546
+ });
547
+ break;
548
+ }
549
+ default: {
550
+ const _exhaustiveCheck = item;
551
+ throw new Error(`Unhandled output item type: ${_exhaustiveCheck.type}`);
552
+ }
553
+ }
554
+ }
555
+ return {
556
+ id: response.id,
557
+ type: 'message',
558
+ role: 'assistant',
559
+ model: response.model ?? 'unknown',
560
+ content,
561
+ stop_reason: mapStopReason(response),
562
+ stop_sequence: null,
563
+ usage: {
564
+ input_tokens: response.usage?.inputTokens ?? 0,
565
+ output_tokens: response.usage?.outputTokens ?? 0,
566
+ cache_creation_input_tokens: response.usage?.inputTokensDetails?.cachedTokens ?? 0,
567
+ cache_read_input_tokens: 0,
568
+ },
569
+ ...(unsupportedContent.length > 0 && { unsupported_content: unsupportedContent }),
570
+ };
571
+ }
572
+ /**
573
+ * Extract unsupported content by original type
574
+ */
575
+ export function extractUnsupportedContent(message, originalType) {
576
+ if (!message.unsupported_content) {
577
+ return [];
578
+ }
579
+ return message.unsupported_content.filter(item => item.original_type === originalType);
580
+ }
581
+ /**
582
+ * Check if message has any unsupported content
583
+ */
584
+ export function hasUnsupportedContent(message) {
585
+ return !!(message.unsupported_content && message.unsupported_content.length > 0);
586
+ }
587
+ /**
588
+ * Get summary of unsupported content types
589
+ */
590
+ export function getUnsupportedContentSummary(message) {
591
+ if (!message.unsupported_content) {
592
+ return {};
593
+ }
594
+ const summary = {};
595
+ for (const item of message.unsupported_content) {
596
+ summary[item.original_type] = (summary[item.original_type] || 0) + 1;
597
+ }
598
+ return summary;
599
+ }
282
600
  //# sourceMappingURL=stream-transformers.js.map
@@ -1,7 +1,7 @@
1
1
  import type { ZodObject, ZodRawShape, ZodType, z } from 'zod/v4';
2
2
  import type * as models from '../models/index.js';
3
3
  import type { OpenResponsesStreamEvent } from '../models/index.js';
4
- import type { ResponseWrapper } from './response-wrapper.js';
4
+ import type { ModelResult } from './model-result.js';
5
5
  /**
6
6
  * Tool type enum for enhanced tools
7
7
  */
@@ -129,8 +129,8 @@ export type MaxToolRounds = number | ((context: TurnContext) => boolean);
129
129
  * Result of executeTools operation
130
130
  */
131
131
  export interface ExecuteToolsResult {
132
- finalResponse: ResponseWrapper;
133
- allResponses: ResponseWrapper[];
132
+ finalResponse: ModelResult;
133
+ allResponses: ModelResult[];
134
134
  toolResults: Map<string, {
135
135
  result: unknown;
136
136
  preliminaryResults?: unknown[];
package/esm/lib/url.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: b0057e24ed76
3
4
  */
4
5
  const hasOwn = Object.prototype.hasOwnProperty;
5
6
  export function pathToFunc(pathPattern, options) {
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: ee2d86453873
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 2147a953e992
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: de317517c298
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 42d173ee6203
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 6b06a4d1562d
3
4
  */
4
5
  import * as openEnums from "../types/enums.js";
5
6
  export const ChatCompletionFinishReason = {
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: b107ec938dc1
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: f98a2a558f3f
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 1d57b0d238b8
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: bb7f6b29b93f
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 49b1cafcb338
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: b5c18e04e19c
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 3989cdc41817
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 27089860fd98
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 5a81301cb4a7
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: eed686a58eb1
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 2dbd9fc61ed8
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: b294b44052da
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 76c3703fa3d5
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 7db13c3cc866
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 15346f0b1bc4
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 339ee7e4b920
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 74ba154581ba
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { safeParse } from "../lib/schemas.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 00bf2ea52439
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 83ba1c3db4bb
3
4
  */
4
5
  import * as z from "zod/v4";
5
6
  import { remap as remap$ } from "../lib/primitives.js";