@omnicross/core 0.1.1 → 0.1.3

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 (259) hide show
  1. package/dist/ApiConverter.cjs +3 -778
  2. package/dist/ApiConverter.js +12 -751
  3. package/dist/{CompletionService-DtOF_War.d.cts → CompletionService-D3a47vdU.d.cts} +2 -1
  4. package/dist/{CompletionService-7fCmKAP3.d.ts → CompletionService-DdWaAxq0.d.ts} +2 -1
  5. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +32 -60
  6. package/dist/auth/GeminiCodeAssistProjectResolver.js +11 -10
  7. package/dist/builtin-web-fetch-77JZUZGM.cjs +100 -0
  8. package/dist/builtin-web-fetch-IGLBX2XY.js +100 -0
  9. package/dist/chunk-2DCNB7DF.cjs +514 -0
  10. package/dist/chunk-2FMI2B6V.cjs +6196 -0
  11. package/dist/chunk-3OPYJG76.cjs +266 -0
  12. package/dist/chunk-3QOSDDNI.cjs +130 -0
  13. package/dist/chunk-46RLHI7D.js +0 -0
  14. package/dist/chunk-46ZIFWYG.cjs +277 -0
  15. package/dist/chunk-4DECIFU7.js +6196 -0
  16. package/dist/chunk-4IH4EL7M.cjs +9 -0
  17. package/dist/chunk-4VAVYUZS.cjs +991 -0
  18. package/dist/chunk-5ENKBSWO.js +311 -0
  19. package/dist/chunk-5ERIZW3D.js +44 -0
  20. package/dist/chunk-5HTVET6E.js +514 -0
  21. package/dist/chunk-5ZQBEOMD.js +764 -0
  22. package/dist/chunk-6RPZADX3.cjs +92 -0
  23. package/dist/chunk-7VU7V2E4.js +0 -0
  24. package/dist/chunk-7YN22L2H.cjs +87 -0
  25. package/dist/chunk-A2YMUCBT.cjs +105 -0
  26. package/dist/chunk-AEOZIDEB.cjs +32 -0
  27. package/dist/chunk-AQ5TNQB7.js +13 -0
  28. package/dist/chunk-AVYJ4YBN.js +58 -0
  29. package/dist/chunk-BO4RFWBR.js +89 -0
  30. package/dist/chunk-C72S6TTV.cjs +49 -0
  31. package/dist/chunk-C7PSERMH.js +87 -0
  32. package/dist/chunk-CDHS2QDC.js +179 -0
  33. package/dist/chunk-CWM2ZDU5.js +130 -0
  34. package/dist/chunk-CZHZGRU7.js +383 -0
  35. package/dist/chunk-DK4A7DLE.js +266 -0
  36. package/dist/chunk-DQ5VAYZ6.cjs +42 -0
  37. package/dist/chunk-DRWHTIIZ.js +13 -0
  38. package/dist/chunk-DWKQZ2SK.cjs +254 -0
  39. package/dist/chunk-EYZYXJTJ.cjs +1 -0
  40. package/dist/chunk-FFALUUZZ.cjs +235 -0
  41. package/dist/chunk-FMOBD2OQ.js +39 -0
  42. package/dist/chunk-FTQ7IQUC.js +991 -0
  43. package/dist/chunk-FZ46M34D.cjs +1 -0
  44. package/dist/chunk-G2UTNSGU.js +277 -0
  45. package/dist/chunk-GBHYAGX3.cjs +26 -0
  46. package/dist/chunk-GMMT7RVN.cjs +39 -0
  47. package/dist/chunk-H5JUT3KV.js +105 -0
  48. package/dist/chunk-HQP3K7PU.cjs +431 -0
  49. package/dist/chunk-HUZZZ3JL.js +32 -0
  50. package/dist/chunk-IAXWICZU.js +69 -0
  51. package/dist/chunk-JMJBSACD.cjs +147 -0
  52. package/dist/chunk-JO5NLTLY.js +46 -0
  53. package/dist/chunk-JWC6APFQ.js +23 -0
  54. package/dist/chunk-KUU2RNG6.cjs +46 -0
  55. package/dist/chunk-L74VDN4A.cjs +32 -0
  56. package/dist/chunk-MQNDWYPN.js +235 -0
  57. package/dist/chunk-MZNPGW5Q.js +26 -0
  58. package/dist/chunk-N5QFKSDO.js +56 -0
  59. package/dist/chunk-NYUNU75A.cjs +44 -0
  60. package/dist/chunk-NZYN7C3P.cjs +179 -0
  61. package/dist/chunk-Q27JY5RG.cjs +126 -0
  62. package/dist/chunk-QBZJ7P2T.cjs +13 -0
  63. package/dist/chunk-QWBWGODS.cjs +69 -0
  64. package/dist/chunk-QXD4MV2X.cjs +23 -0
  65. package/dist/chunk-R3HK6R4B.cjs +13 -0
  66. package/dist/chunk-RPII3E6Z.cjs +145 -0
  67. package/dist/chunk-RSJ3TWJQ.cjs +186 -0
  68. package/dist/chunk-S4WBV25P.js +913 -0
  69. package/dist/chunk-S6JGLF3G.cjs +89 -0
  70. package/dist/chunk-SUEGJ75D.cjs +764 -0
  71. package/dist/chunk-SVNDB62D.cjs +58 -0
  72. package/dist/chunk-SVXC36MU.cjs +383 -0
  73. package/dist/chunk-TKJMZBAH.js +32 -0
  74. package/dist/chunk-UBWEBKRC.js +42 -0
  75. package/dist/chunk-UNEFIWXI.cjs +32 -0
  76. package/dist/chunk-VQY5W4YW.cjs +311 -0
  77. package/dist/chunk-VVEHS2LI.js +431 -0
  78. package/dist/chunk-WNY4WMRF.js +32 -0
  79. package/dist/chunk-XEKD23J5.js +9 -0
  80. package/dist/chunk-XTEI64OU.js +145 -0
  81. package/dist/chunk-XX6NQJMA.js +92 -0
  82. package/dist/chunk-Y6OM7EV7.cjs +56 -0
  83. package/dist/chunk-Y7FO65VT.js +147 -0
  84. package/dist/chunk-YGXJGRFI.cjs +913 -0
  85. package/dist/chunk-YMFAJFQT.cjs +173 -0
  86. package/dist/chunk-Z7LUNECE.js +49 -0
  87. package/dist/chunk-Z7Y2NPHY.js +186 -0
  88. package/dist/chunk-ZJZAOKI7.js +254 -0
  89. package/dist/chunk-ZLX3KGXX.js +173 -0
  90. package/dist/chunk-ZY6KU6P3.js +126 -0
  91. package/dist/completion/ApiKeyPoolService.cjs +23 -48
  92. package/dist/completion/ApiKeyPoolService.d.cts +150 -2
  93. package/dist/completion/ApiKeyPoolService.d.ts +150 -2
  94. package/dist/completion/BuiltinToolExecutor.cjs +9 -324
  95. package/dist/completion/BuiltinToolExecutor.js +6 -290
  96. package/dist/completion/CompletionService.cjs +45 -3487
  97. package/dist/completion/CompletionService.d.cts +3 -2
  98. package/dist/completion/CompletionService.d.ts +3 -2
  99. package/dist/completion/CompletionService.js +41 -3457
  100. package/dist/completion/NativeSearchInjector.cjs +8 -192
  101. package/dist/completion/NativeSearchInjector.js +7 -162
  102. package/dist/completion/ProviderSearchInjector.cjs +12 -39
  103. package/dist/completion/native-search-types.cjs +13 -66
  104. package/dist/completion/native-search-types.js +7 -31
  105. package/dist/completion/openrouter-headers.cjs +12 -71
  106. package/dist/completion/openrouter-headers.d.cts +9 -12
  107. package/dist/completion/openrouter-headers.d.ts +9 -12
  108. package/dist/completion/openrouter-headers.js +7 -36
  109. package/dist/completion/openrouter-models.cjs +11 -67
  110. package/dist/completion/openrouter-models.js +5 -34
  111. package/dist/completion/types.cjs +1 -18
  112. package/dist/completion/url-builder.cjs +24 -138
  113. package/dist/completion/url-builder.js +12 -92
  114. package/dist/completion.cjs +62 -3989
  115. package/dist/completion.d.cts +3 -2
  116. package/dist/completion.d.ts +3 -2
  117. package/dist/completion.js +70 -3953
  118. package/dist/index.cjs +319 -10429
  119. package/dist/index.d.cts +49 -12
  120. package/dist/index.d.ts +49 -12
  121. package/dist/index.js +248 -10269
  122. package/dist/logger-4GvQNzhE.d.cts +22 -0
  123. package/dist/logger-4GvQNzhE.d.ts +22 -0
  124. package/dist/outbound-api/routeResolver.cjs +10 -217
  125. package/dist/outbound-api/routeResolver.d.cts +10 -3
  126. package/dist/outbound-api/routeResolver.d.ts +10 -3
  127. package/dist/outbound-api/routeResolver.js +9 -187
  128. package/dist/outbound-api/subscriptionRegistryPort.cjs +7 -37
  129. package/dist/outbound-api/subscriptionRegistryPort.d.cts +2 -1
  130. package/dist/outbound-api/subscriptionRegistryPort.d.ts +2 -1
  131. package/dist/outbound-api/subscriptionRegistryPort.js +4 -8
  132. package/dist/outbound-api/types.cjs +5 -17
  133. package/dist/outbound-api/types.d.cts +12 -144
  134. package/dist/outbound-api/types.d.ts +12 -144
  135. package/dist/outbound-api/types.js +6 -0
  136. package/dist/outbound-api.cjs +197 -5265
  137. package/dist/outbound-api.d.cts +787 -25
  138. package/dist/outbound-api.d.ts +787 -25
  139. package/dist/outbound-api.js +173 -5195
  140. package/dist/pipeline/AuthSource.cjs +1 -18
  141. package/dist/pipeline/AuthSource.d.cts +23 -1
  142. package/dist/pipeline/AuthSource.d.ts +23 -1
  143. package/dist/pipeline/LlmConfigProviderAuth.cjs +5 -166
  144. package/dist/pipeline/LlmConfigProviderAuth.d.cts +2 -1
  145. package/dist/pipeline/LlmConfigProviderAuth.d.ts +2 -1
  146. package/dist/pipeline/LlmConfigProviderAuth.js +5 -139
  147. package/dist/pipeline/SubscriptionAccountHealth.cjs +22 -0
  148. package/dist/pipeline/SubscriptionAccountHealth.d.cts +235 -0
  149. package/dist/pipeline/SubscriptionAccountHealth.d.ts +235 -0
  150. package/dist/pipeline/SubscriptionAccountHealth.js +22 -0
  151. package/dist/pipeline/SubscriptionAuthSource.cjs +6 -128
  152. package/dist/pipeline/SubscriptionAuthSource.d.cts +3 -2
  153. package/dist/pipeline/SubscriptionAuthSource.d.ts +3 -2
  154. package/dist/pipeline/SubscriptionAuthSource.js +5 -99
  155. package/dist/pipeline/SubscriptionAuthStrategy.cjs +1 -18
  156. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +24 -1
  157. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +24 -1
  158. package/dist/pipeline/auditSink.cjs +14 -0
  159. package/dist/pipeline/auditSink.d.cts +48 -0
  160. package/dist/pipeline/auditSink.d.ts +48 -0
  161. package/dist/pipeline/auditSink.js +14 -0
  162. package/dist/pipeline/billingEmit.cjs +14 -0
  163. package/dist/pipeline/billingEmit.d.cts +49 -0
  164. package/dist/pipeline/billingEmit.d.ts +49 -0
  165. package/dist/pipeline/billingEmit.js +14 -0
  166. package/dist/pipeline/executeProviderCall.cjs +5 -69
  167. package/dist/pipeline/executeProviderCall.js +3 -42
  168. package/dist/pipeline/resolveProviderChain.cjs +5 -46
  169. package/dist/pipeline/resolveProviderChain.js +3 -19
  170. package/dist/pipeline/resolveSubscriptionChain.cjs +5 -67
  171. package/dist/pipeline/resolveSubscriptionChain.js +3 -40
  172. package/dist/ports/gemini-code-assist-resolver.cjs +7 -37
  173. package/dist/ports/gemini-code-assist-resolver.js +4 -8
  174. package/dist/ports/pricing-store.cjs +1 -0
  175. package/dist/ports/pricing-store.d.cts +50 -0
  176. package/dist/ports/pricing-store.d.ts +50 -0
  177. package/dist/ports/pricing-store.js +0 -0
  178. package/dist/ports/provider-config-source.cjs +1 -18
  179. package/dist/ports/usage-event-store.cjs +1 -0
  180. package/dist/ports/usage-event-store.d.cts +54 -0
  181. package/dist/ports/usage-event-store.d.ts +54 -0
  182. package/dist/ports/usage-event-store.js +0 -0
  183. package/dist/ports/web-search-backend.cjs +1 -18
  184. package/dist/ports.cjs +1 -18
  185. package/dist/ports.d.cts +13 -2
  186. package/dist/ports.d.ts +13 -2
  187. package/dist/provider-proxy/ProviderProxy.cjs +47 -4643
  188. package/dist/provider-proxy/ProviderProxy.d.cts +2 -1
  189. package/dist/provider-proxy/ProviderProxy.d.ts +2 -1
  190. package/dist/provider-proxy/ProviderProxy.js +42 -4613
  191. package/dist/provider-proxy/identity/SubscriptionIdentityStore.cjs +15 -0
  192. package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.cts +121 -0
  193. package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.ts +121 -0
  194. package/dist/provider-proxy/identity/SubscriptionIdentityStore.js +15 -0
  195. package/dist/provider-proxy/identity/fingerprintHeaders.cjs +20 -0
  196. package/dist/provider-proxy/identity/fingerprintHeaders.d.cts +89 -0
  197. package/dist/provider-proxy/identity/fingerprintHeaders.d.ts +89 -0
  198. package/dist/provider-proxy/identity/fingerprintHeaders.js +20 -0
  199. package/dist/provider-proxy/ingress/providerProxyShared.cjs +42 -2941
  200. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +13 -3
  201. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +13 -3
  202. package/dist/provider-proxy/ingress/providerProxyShared.js +48 -2914
  203. package/dist/provider-proxy/matchText.cjs +13 -72
  204. package/dist/provider-proxy/matchText.d.cts +14 -1
  205. package/dist/provider-proxy/matchText.d.ts +14 -1
  206. package/dist/provider-proxy/matchText.js +8 -39
  207. package/dist/provider-proxy/types.cjs +1 -18
  208. package/dist/provider-proxy/types.d.cts +25 -1
  209. package/dist/provider-proxy/types.d.ts +25 -1
  210. package/dist/provider-proxy.cjs +42 -4655
  211. package/dist/provider-proxy.d.cts +2 -1
  212. package/dist/provider-proxy.d.ts +2 -1
  213. package/dist/provider-proxy.js +46 -4628
  214. package/dist/{routeResolver-HE-ZO0fO.d.ts → routeResolver-B1NglTfe.d.ts} +36 -10
  215. package/dist/{routeResolver-BrbK6ja9.d.cts → routeResolver-CbG5uBgm.d.cts} +36 -10
  216. package/dist/serializeError.cjs +5 -81
  217. package/dist/serializeError.js +3 -54
  218. package/dist/sse-parser.cjs +7 -455
  219. package/dist/sse-parser.js +4 -426
  220. package/dist/transformer/TransformerChainExecutor.cjs +4 -318
  221. package/dist/transformer/TransformerChainExecutor.js +4 -291
  222. package/dist/transformer/TransformerService.cjs +5 -289
  223. package/dist/transformer/TransformerService.js +3 -262
  224. package/dist/transformer/anthropicBetaInject.cjs +7 -50
  225. package/dist/transformer/anthropicBetaInject.js +4 -21
  226. package/dist/transformer/transformers/AnthropicTransformer.cjs +3 -1014
  227. package/dist/transformer/transformers/AnthropicTransformer.js +3 -987
  228. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +4 -1106
  229. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +7 -1079
  230. package/dist/transformer/transformers/GeminiTransformer.cjs +4 -1010
  231. package/dist/transformer/transformers/GeminiTransformer.js +4 -983
  232. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -535
  233. package/dist/transformer/transformers/OpenAIResponseTransformer.js +3 -510
  234. package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +5 -72
  235. package/dist/transformer/transformers/OpenCodeGoTransformer.js +3 -45
  236. package/dist/transformer/transformers/ReasoningTransformer.cjs +3 -270
  237. package/dist/transformer/transformers/ReasoningTransformer.js +2 -249
  238. package/dist/transformer/transformers.cjs +10 -3177
  239. package/dist/transformer/transformers.js +23 -3158
  240. package/dist/transformer/types.cjs +1 -18
  241. package/dist/transformer.cjs +13 -3726
  242. package/dist/transformer.js +17 -3706
  243. package/dist/types-6OUY_xfA.d.ts +830 -0
  244. package/dist/types-aBFFXoBz.d.cts +830 -0
  245. package/dist/usage/pricing-engine.cjs +6 -0
  246. package/dist/usage/pricing-engine.d.cts +83 -0
  247. package/dist/usage/pricing-engine.d.ts +83 -0
  248. package/dist/usage/pricing-engine.js +6 -0
  249. package/dist/usage/usage-recorder.cjs +6 -0
  250. package/dist/usage/usage-recorder.d.cts +91 -0
  251. package/dist/usage/usage-recorder.d.ts +91 -0
  252. package/dist/usage/usage-recorder.js +6 -0
  253. package/dist/usage.cjs +11 -0
  254. package/dist/usage.d.cts +8 -0
  255. package/dist/usage.d.ts +8 -0
  256. package/dist/usage.js +11 -0
  257. package/package.json +4 -2
  258. package/dist/ApiKeyPoolService-BmMkau07.d.cts +0 -170
  259. package/dist/ApiKeyPoolService-BmMkau07.d.ts +0 -170
@@ -1,799 +1,24 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/ApiConverter.ts
21
- var ApiConverter_exports = {};
22
- __export(ApiConverter_exports, {
23
- convertAnthropicRequestToOpenAI: () => convertAnthropicRequestToOpenAI,
24
- convertAnthropicStreamToOpenAI: () => convertAnthropicStreamToOpenAI,
25
- convertAnthropicToOpenAI: () => convertAnthropicToOpenAI,
26
- convertAnthropicToOpenAIWithThinking: () => convertAnthropicToOpenAIWithThinking,
27
- convertOpenAIResponseToAnthropic: () => convertOpenAIResponseToAnthropic,
28
- convertOpenAIStreamToAnthropic: () => convertOpenAIStreamToAnthropic,
29
- convertOpenAIToAnthropic: () => convertOpenAIToAnthropic,
30
- convertOpenAIToAnthropicWithThinking: () => convertOpenAIToAnthropicWithThinking,
31
- hasImageContent: () => hasImageContent,
32
- hasThinkingEnabled: () => hasThinkingEnabled
33
- });
34
- module.exports = __toCommonJS(ApiConverter_exports);
35
3
 
36
- // src/api-converter/shared.ts
37
- function convertOpenAITool(tool) {
38
- return {
39
- name: tool.function.name,
40
- description: tool.function.description,
41
- input_schema: tool.function.parameters
42
- };
43
- }
44
- function mapAnthropicStopReason(stopReason) {
45
- switch (stopReason) {
46
- case "end_turn":
47
- return "stop";
48
- case "max_tokens":
49
- return "length";
50
- case "tool_use":
51
- return "tool_calls";
52
- case "stop_sequence":
53
- return "stop";
54
- default:
55
- return "stop";
56
- }
57
- }
58
- function mapOpenAIFinishReason(finishReason) {
59
- switch (finishReason) {
60
- case "stop":
61
- return "end_turn";
62
- case "length":
63
- return "max_tokens";
64
- case "tool_calls":
65
- return "tool_use";
66
- case "content_filter":
67
- return "end_turn";
68
- default:
69
- return "end_turn";
70
- }
71
- }
72
- function hasImageContent(request) {
73
- const messages = request.messages;
74
- for (const msg of messages) {
75
- if (Array.isArray(msg.content)) {
76
- for (const part of msg.content) {
77
- if ("type" in part && part.type === "image_url") {
78
- return true;
79
- }
80
- if ("type" in part && part.type === "image") {
81
- return true;
82
- }
83
- }
84
- }
85
- }
86
- return false;
87
- }
88
- function hasThinkingEnabled(request) {
89
- if ("thinking" in request && request.thinking?.type === "enabled") {
90
- return true;
91
- }
92
- if ("reasoning" in request) {
93
- return true;
94
- }
95
- return false;
96
- }
97
4
 
98
- // src/api-converter/anthropic-to-openai.ts
99
- function convertAnthropicToOpenAI(response) {
100
- const content = [];
101
- const toolCalls = [];
102
- let reasoningContent = "";
103
- for (const block of response.content) {
104
- if (block.type === "text") {
105
- content.push(block.text);
106
- } else if (block.type === "tool_use") {
107
- toolCalls.push({
108
- id: block.id,
109
- type: "function",
110
- function: {
111
- name: block.name,
112
- arguments: JSON.stringify(block.input)
113
- }
114
- });
115
- } else if (block.type === "thinking") {
116
- reasoningContent += block.thinking;
117
- }
118
- }
119
- const finishReason = mapAnthropicStopReason(response.stop_reason);
120
- const result = {
121
- id: response.id,
122
- object: "chat.completion",
123
- created: Math.floor(Date.now() / 1e3),
124
- model: response.model,
125
- choices: [
126
- {
127
- index: 0,
128
- message: {
129
- role: "assistant",
130
- content: content.join("\n") || null,
131
- ...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
132
- },
133
- finish_reason: finishReason
134
- }
135
- ],
136
- usage: {
137
- prompt_tokens: response.usage.input_tokens,
138
- completion_tokens: response.usage.output_tokens,
139
- total_tokens: response.usage.input_tokens + response.usage.output_tokens
140
- }
141
- };
142
- if (reasoningContent) {
143
- result.reasoning_content = reasoningContent;
144
- }
145
- return result;
146
- }
147
- function convertAnthropicRequestToOpenAI(request) {
148
- const messages = [];
149
- if (request.system) {
150
- if (typeof request.system === "string") {
151
- messages.push({ role: "system", content: request.system });
152
- } else if (Array.isArray(request.system)) {
153
- const systemText = request.system.filter((s) => s.type === "text").map((s) => s.text).join("\n");
154
- messages.push({ role: "system", content: systemText });
155
- }
156
- }
157
- for (const msg of request.messages) {
158
- if (typeof msg.content === "string") {
159
- messages.push({
160
- role: msg.role,
161
- content: msg.content
162
- });
163
- } else if (Array.isArray(msg.content)) {
164
- const openaiContent = [];
165
- const toolCalls = [];
166
- let toolResultId;
167
- let toolResultContent;
168
- for (const part of msg.content) {
169
- if (part.type === "text") {
170
- openaiContent.push({ type: "text", text: part.text });
171
- } else if (part.type === "image") {
172
- if (part.source.type === "base64") {
173
- openaiContent.push({
174
- type: "image_url",
175
- image_url: {
176
- url: `data:${part.source.media_type};base64,${part.source.data}`
177
- }
178
- });
179
- } else if (part.source.url) {
180
- openaiContent.push({
181
- type: "image_url",
182
- image_url: { url: part.source.url }
183
- });
184
- }
185
- } else if (part.type === "tool_use") {
186
- toolCalls.push({
187
- id: part.id,
188
- type: "function",
189
- function: {
190
- name: part.name,
191
- arguments: JSON.stringify(part.input)
192
- }
193
- });
194
- } else if (part.type === "tool_result") {
195
- toolResultId = part.tool_use_id;
196
- toolResultContent = typeof part.content === "string" ? part.content : JSON.stringify(part.content);
197
- }
198
- }
199
- if (toolResultId && toolResultContent !== void 0) {
200
- messages.push({
201
- role: "tool",
202
- tool_call_id: toolResultId,
203
- content: toolResultContent
204
- });
205
- } else if (toolCalls.length > 0) {
206
- messages.push({
207
- role: "assistant",
208
- content: openaiContent.length > 0 ? openaiContent.map((c) => c.type === "text" ? c.text : "").join("\n") : null,
209
- tool_calls: toolCalls
210
- });
211
- } else {
212
- messages.push({
213
- role: msg.role,
214
- content: openaiContent.length > 0 ? openaiContent : null
215
- });
216
- }
217
- }
218
- }
219
- const result = {
220
- model: request.model,
221
- messages,
222
- max_tokens: request.max_tokens,
223
- stream: request.stream
224
- };
225
- if (request.tools && request.tools.length > 0) {
226
- result.tools = request.tools.map((tool) => ({
227
- type: "function",
228
- function: {
229
- name: tool.name,
230
- description: tool.description,
231
- parameters: tool.input_schema
232
- }
233
- }));
234
- if (request.tool_choice) {
235
- if (request.tool_choice.type === "auto") {
236
- result.tool_choice = "auto";
237
- } else if (request.tool_choice.type === "any") {
238
- result.tool_choice = "required";
239
- } else if (request.tool_choice.type === "tool") {
240
- result.tool_choice = {
241
- type: "function",
242
- function: { name: request.tool_choice.name }
243
- };
244
- }
245
- }
246
- }
247
- return result;
248
- }
249
- function convertAnthropicToOpenAIWithThinking(response) {
250
- const baseResult = convertAnthropicToOpenAI(response);
251
- const thinkingBlocks = response.content.filter(
252
- (block) => block.type === "thinking"
253
- );
254
- if (thinkingBlocks.length > 0) {
255
- baseResult.reasoning_content = thinkingBlocks.map((block) => "thinking" in block ? block.thinking : "").join("\n");
256
- }
257
- return baseResult;
258
- }
259
- async function* convertAnthropicStreamToOpenAI(anthropicStream) {
260
- let messageId = "";
261
- let model = "unknown";
262
- const toolCalls = /* @__PURE__ */ new Map();
263
- for await (const line of anthropicStream) {
264
- if (!line.startsWith("data:")) continue;
265
- const data = line.slice(5).trim();
266
- try {
267
- const event = JSON.parse(data);
268
- switch (event.type) {
269
- case "message_start":
270
- messageId = event.message?.id || `chatcmpl-${Date.now()}`;
271
- model = event.message?.model || model;
272
- break;
273
- case "content_block_delta":
274
- if (event.delta?.type === "text_delta") {
275
- yield `data: ${JSON.stringify({
276
- id: messageId,
277
- object: "chat.completion.chunk",
278
- created: Math.floor(Date.now() / 1e3),
279
- model,
280
- choices: [{
281
- index: 0,
282
- delta: { content: event.delta.text },
283
- finish_reason: null
284
- }]
285
- })}
286
5
 
287
- `;
288
- } else if (event.delta?.type === "thinking_delta") {
289
- yield `data: ${JSON.stringify({
290
- id: messageId,
291
- object: "chat.completion.chunk",
292
- created: Math.floor(Date.now() / 1e3),
293
- model,
294
- choices: [{
295
- index: 0,
296
- delta: { reasoning_content: event.delta.thinking },
297
- finish_reason: null
298
- }]
299
- })}
300
6
 
301
- `;
302
- } else if (event.delta?.type === "input_json_delta") {
303
- const toolIndex = event.index || 0;
304
- const tc = toolCalls.get(toolIndex);
305
- if (tc) {
306
- yield `data: ${JSON.stringify({
307
- id: messageId,
308
- object: "chat.completion.chunk",
309
- created: Math.floor(Date.now() / 1e3),
310
- model,
311
- choices: [{
312
- index: 0,
313
- delta: {
314
- tool_calls: [{
315
- index: toolIndex,
316
- function: { arguments: event.delta.partial_json }
317
- }]
318
- },
319
- finish_reason: null
320
- }]
321
- })}
322
7
 
323
- `;
324
- }
325
- }
326
- break;
327
- case "content_block_start":
328
- if (event.content_block?.type === "tool_use") {
329
- const toolIndex = event.index || 0;
330
- toolCalls.set(toolIndex, {
331
- id: event.content_block.id,
332
- name: event.content_block.name,
333
- arguments: ""
334
- });
335
- yield `data: ${JSON.stringify({
336
- id: messageId,
337
- object: "chat.completion.chunk",
338
- created: Math.floor(Date.now() / 1e3),
339
- model,
340
- choices: [{
341
- index: 0,
342
- delta: {
343
- tool_calls: [{
344
- index: toolIndex,
345
- id: event.content_block.id,
346
- type: "function",
347
- function: { name: event.content_block.name, arguments: "" }
348
- }]
349
- },
350
- finish_reason: null
351
- }]
352
- })}
353
8
 
354
- `;
355
- }
356
- break;
357
- case "message_delta":
358
- if (event.delta?.stop_reason) {
359
- const finishReason = mapAnthropicStopReason(event.delta.stop_reason);
360
- yield `data: ${JSON.stringify({
361
- id: messageId,
362
- object: "chat.completion.chunk",
363
- created: Math.floor(Date.now() / 1e3),
364
- model,
365
- choices: [{
366
- index: 0,
367
- delta: {},
368
- finish_reason: finishReason
369
- }],
370
- usage: event.usage ? {
371
- prompt_tokens: event.usage.input_tokens || 0,
372
- completion_tokens: event.usage.output_tokens || 0,
373
- total_tokens: (event.usage.input_tokens || 0) + (event.usage.output_tokens || 0)
374
- } : void 0
375
- })}
376
9
 
377
- `;
378
- }
379
- break;
380
- case "message_stop":
381
- yield "data: [DONE]\n\n";
382
- break;
383
- }
384
- } catch {
385
- }
386
- }
387
- }
388
10
 
389
- // src/api-converter/openai-to-anthropic.ts
390
- function convertOpenAIToAnthropic(request, config) {
391
- const messages = [];
392
- let system;
393
- for (const msg of request.messages) {
394
- if (msg.role === "system") {
395
- if (typeof msg.content === "string") {
396
- system = msg.content;
397
- } else if (Array.isArray(msg.content)) {
398
- system = msg.content.filter((p) => p.type === "text").map((p) => ({ type: "text", text: p.text || "" }));
399
- }
400
- continue;
401
- }
402
- if (msg.role === "tool" && msg.tool_call_id) {
403
- const toolResult = {
404
- type: "tool_result",
405
- tool_use_id: msg.tool_call_id,
406
- content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
407
- };
408
- const lastMsg = messages[messages.length - 1];
409
- if (lastMsg && lastMsg.role === "user" && Array.isArray(lastMsg.content)) {
410
- lastMsg.content.push(toolResult);
411
- } else {
412
- messages.push({ role: "user", content: [toolResult] });
413
- }
414
- continue;
415
- }
416
- if (msg.role === "assistant" && msg.tool_calls && msg.tool_calls.length > 0) {
417
- const content = [];
418
- if (msg.content) {
419
- if (typeof msg.content === "string") {
420
- content.push({ type: "text", text: msg.content });
421
- } else if (Array.isArray(msg.content)) {
422
- for (const part of msg.content) {
423
- if (part.type === "text" && part.text) {
424
- content.push({ type: "text", text: part.text });
425
- }
426
- }
427
- }
428
- }
429
- for (const tc of msg.tool_calls) {
430
- content.push({
431
- type: "tool_use",
432
- id: tc.id,
433
- name: tc.function.name,
434
- input: JSON.parse(tc.function.arguments || "{}")
435
- });
436
- }
437
- messages.push({ role: "assistant", content });
438
- continue;
439
- }
440
- if (msg.role === "user" || msg.role === "assistant") {
441
- const content = convertOpenAIMessageContent(msg);
442
- messages.push({ role: msg.role, content });
443
- }
444
- }
445
- let model = request.model;
446
- if (config.modelMapping && config.modelMapping[model]) {
447
- model = config.modelMapping[model];
448
- } else if (!model.startsWith("claude")) {
449
- model = config.defaultModel;
450
- }
451
- const result = {
452
- model,
453
- // Anthropic requires max_tokens; use high default (16384) if not explicitly set
454
- // This prevents output truncation for long responses
455
- max_tokens: request.max_tokens || 16384,
456
- messages,
457
- stream: request.stream
458
- };
459
- if (system) {
460
- result.system = system;
461
- }
462
- if (request.tools && request.tools.length > 0) {
463
- result.tools = request.tools.map(convertOpenAITool);
464
- if (request.tool_choice) {
465
- if (request.tool_choice === "auto") {
466
- result.tool_choice = { type: "auto" };
467
- } else if (request.tool_choice === "required") {
468
- result.tool_choice = { type: "any" };
469
- } else if (typeof request.tool_choice === "object") {
470
- result.tool_choice = {
471
- type: "tool",
472
- name: request.tool_choice.function.name
473
- };
474
- }
475
- }
476
- }
477
- return result;
478
- }
479
- function convertOpenAIMessageContent(msg) {
480
- if (typeof msg.content === "string") {
481
- return msg.content;
482
- }
483
- if (!msg.content || !Array.isArray(msg.content)) {
484
- return "";
485
- }
486
- const parts = [];
487
- for (const part of msg.content) {
488
- if (part.type === "text" && part.text) {
489
- parts.push({ type: "text", text: part.text });
490
- } else if (part.type === "image_url" && part.image_url) {
491
- const url = part.image_url.url;
492
- if (url.startsWith("data:")) {
493
- const match = url.match(/^data:([^;]+);base64,(.+)$/);
494
- if (match) {
495
- parts.push({
496
- type: "image",
497
- source: {
498
- type: "base64",
499
- media_type: match[1],
500
- data: match[2]
501
- }
502
- });
503
- }
504
- } else {
505
- parts.push({
506
- type: "image",
507
- source: { type: "url", url }
508
- });
509
- }
510
- }
511
- }
512
- return parts.length > 0 ? parts : "";
513
- }
514
- function convertOpenAIResponseToAnthropic(response) {
515
- const content = [];
516
- const choice = response.choices[0];
517
- if (choice.message.content) {
518
- content.push({ type: "text", text: choice.message.content });
519
- }
520
- if (choice.message.tool_calls) {
521
- for (const tc of choice.message.tool_calls) {
522
- content.push({
523
- type: "tool_use",
524
- id: tc.id,
525
- name: tc.function.name,
526
- input: JSON.parse(tc.function.arguments || "{}")
527
- });
528
- }
529
- }
530
- if (response.reasoning_content) {
531
- content.unshift({
532
- type: "thinking",
533
- thinking: response.reasoning_content
534
- });
535
- }
536
- return {
537
- id: response.id,
538
- type: "message",
539
- role: "assistant",
540
- model: response.model,
541
- content,
542
- stop_reason: mapOpenAIFinishReason(choice.finish_reason),
543
- usage: {
544
- input_tokens: response.usage.prompt_tokens,
545
- output_tokens: response.usage.completion_tokens
546
- }
547
- };
548
- }
549
- function convertOpenAIToAnthropicWithThinking(request, config) {
550
- const baseResult = convertOpenAIToAnthropic(request, config);
551
- if (config.enableThinking) {
552
- baseResult.thinking = {
553
- type: "enabled",
554
- budget_tokens: config.thinkingBudget || 1e4
555
- };
556
- }
557
- return baseResult;
558
- }
559
- async function* convertOpenAIStreamToAnthropic(openaiStream) {
560
- const messageId = `msg_${Date.now()}`;
561
- let hasStarted = false;
562
- let hasTextContentStarted = false;
563
- let hasThinkingContentStarted = false;
564
- let contentIndex = 0;
565
- let model = "unknown";
566
- const toolCalls = /* @__PURE__ */ new Map();
567
- for await (const line of openaiStream) {
568
- if (!line.startsWith("data:")) continue;
569
- const data = line.slice(5).trim();
570
- if (data === "[DONE]") {
571
- if (hasTextContentStarted) {
572
- yield `event: content_block_stop
573
- data: ${JSON.stringify({
574
- type: "content_block_stop",
575
- index: contentIndex
576
- })}
577
11
 
578
- `;
579
- contentIndex++;
580
- hasTextContentStarted = false;
581
- }
582
- if (hasThinkingContentStarted) {
583
- yield `event: content_block_stop
584
- data: ${JSON.stringify({
585
- type: "content_block_stop",
586
- index: contentIndex
587
- })}
12
+ var _chunkSUEGJ75Dcjs = require('./chunk-SUEGJ75D.cjs');
588
13
 
589
- `;
590
- contentIndex++;
591
- hasThinkingContentStarted = false;
592
- }
593
- for (const [, tc] of toolCalls) {
594
- yield `event: content_block_stop
595
- data: ${JSON.stringify({
596
- type: "content_block_stop",
597
- index: tc.contentIndex
598
- })}
599
14
 
600
- `;
601
- }
602
- yield `event: message_delta
603
- data: ${JSON.stringify({
604
- type: "message_delta",
605
- delta: { stop_reason: "end_turn", stop_sequence: null },
606
- usage: { input_tokens: 0, output_tokens: 0 }
607
- })}
608
15
 
609
- `;
610
- yield `event: message_stop
611
- data: ${JSON.stringify({ type: "message_stop" })}
612
16
 
613
- `;
614
- break;
615
- }
616
- try {
617
- const chunk = JSON.parse(data);
618
- model = chunk.model || model;
619
- if (!hasStarted) {
620
- hasStarted = true;
621
- yield `event: message_start
622
- data: ${JSON.stringify({
623
- type: "message_start",
624
- message: {
625
- id: messageId,
626
- type: "message",
627
- role: "assistant",
628
- content: [],
629
- model,
630
- stop_reason: null,
631
- stop_sequence: null,
632
- usage: { input_tokens: 0, output_tokens: 0 }
633
- }
634
- })}
635
17
 
636
- `;
637
- }
638
- const choice = chunk.choices?.[0];
639
- if (!choice) continue;
640
- if (choice.delta?.content) {
641
- if (!hasTextContentStarted) {
642
- hasTextContentStarted = true;
643
- yield `event: content_block_start
644
- data: ${JSON.stringify({
645
- type: "content_block_start",
646
- index: contentIndex,
647
- content_block: { type: "text", text: "" }
648
- })}
649
18
 
650
- `;
651
- }
652
- yield `event: content_block_delta
653
- data: ${JSON.stringify({
654
- type: "content_block_delta",
655
- index: contentIndex,
656
- delta: { type: "text_delta", text: choice.delta.content }
657
- })}
658
19
 
659
- `;
660
- }
661
- if (choice.delta?.reasoning_content) {
662
- if (hasTextContentStarted) {
663
- yield `event: content_block_stop
664
- data: ${JSON.stringify({
665
- type: "content_block_stop",
666
- index: contentIndex
667
- })}
668
20
 
669
- `;
670
- contentIndex++;
671
- hasTextContentStarted = false;
672
- }
673
- if (!hasThinkingContentStarted) {
674
- hasThinkingContentStarted = true;
675
- yield `event: content_block_start
676
- data: ${JSON.stringify({
677
- type: "content_block_start",
678
- index: contentIndex,
679
- content_block: { type: "thinking", thinking: "" }
680
- })}
681
21
 
682
- `;
683
- }
684
- yield `event: content_block_delta
685
- data: ${JSON.stringify({
686
- type: "content_block_delta",
687
- index: contentIndex,
688
- delta: { type: "thinking_delta", thinking: choice.delta.reasoning_content }
689
- })}
690
22
 
691
- `;
692
- }
693
- if (choice.delta?.tool_calls) {
694
- if (hasTextContentStarted) {
695
- yield `event: content_block_stop
696
- data: ${JSON.stringify({
697
- type: "content_block_stop",
698
- index: contentIndex
699
- })}
700
23
 
701
- `;
702
- contentIndex++;
703
- hasTextContentStarted = false;
704
- }
705
- for (const toolCall of choice.delta.tool_calls) {
706
- const toolIndex = toolCall.index ?? 0;
707
- if (!toolCalls.has(toolIndex)) {
708
- const toolContentIndex = contentIndex++;
709
- const toolId = toolCall.id || `call_${Date.now()}_${toolIndex}`;
710
- const toolName = toolCall.function?.name || `tool_${toolIndex}`;
711
- toolCalls.set(toolIndex, { id: toolId, name: toolName, contentIndex: toolContentIndex });
712
- yield `event: content_block_start
713
- data: ${JSON.stringify({
714
- type: "content_block_start",
715
- index: toolContentIndex,
716
- content_block: { type: "tool_use", id: toolId, name: toolName, input: {} }
717
- })}
718
-
719
- `;
720
- }
721
- if (toolCall.function?.arguments) {
722
- const tc = toolCalls.get(toolIndex);
723
- yield `event: content_block_delta
724
- data: ${JSON.stringify({
725
- type: "content_block_delta",
726
- index: tc.contentIndex,
727
- delta: { type: "input_json_delta", partial_json: toolCall.function.arguments }
728
- })}
729
-
730
- `;
731
- }
732
- }
733
- }
734
- if (choice.finish_reason) {
735
- if (hasTextContentStarted) {
736
- yield `event: content_block_stop
737
- data: ${JSON.stringify({
738
- type: "content_block_stop",
739
- index: contentIndex
740
- })}
741
-
742
- `;
743
- contentIndex++;
744
- hasTextContentStarted = false;
745
- }
746
- if (hasThinkingContentStarted) {
747
- yield `event: content_block_stop
748
- data: ${JSON.stringify({
749
- type: "content_block_stop",
750
- index: contentIndex
751
- })}
752
-
753
- `;
754
- contentIndex++;
755
- hasThinkingContentStarted = false;
756
- }
757
- for (const [, tc] of toolCalls) {
758
- yield `event: content_block_stop
759
- data: ${JSON.stringify({
760
- type: "content_block_stop",
761
- index: tc.contentIndex
762
- })}
763
-
764
- `;
765
- }
766
- const stopReason = mapOpenAIFinishReason(choice.finish_reason);
767
- yield `event: message_delta
768
- data: ${JSON.stringify({
769
- type: "message_delta",
770
- delta: { stop_reason: stopReason, stop_sequence: null },
771
- usage: {
772
- input_tokens: chunk.usage?.prompt_tokens || 0,
773
- output_tokens: chunk.usage?.completion_tokens || 0
774
- }
775
- })}
776
-
777
- `;
778
- yield `event: message_stop
779
- data: ${JSON.stringify({ type: "message_stop" })}
780
-
781
- `;
782
- }
783
- } catch {
784
- }
785
- }
786
- }
787
- // Annotate the CommonJS export names for ESM import in node:
788
- 0 && (module.exports = {
789
- convertAnthropicRequestToOpenAI,
790
- convertAnthropicStreamToOpenAI,
791
- convertAnthropicToOpenAI,
792
- convertAnthropicToOpenAIWithThinking,
793
- convertOpenAIResponseToAnthropic,
794
- convertOpenAIStreamToAnthropic,
795
- convertOpenAIToAnthropic,
796
- convertOpenAIToAnthropicWithThinking,
797
- hasImageContent,
798
- hasThinkingEnabled
799
- });
24
+ exports.convertAnthropicRequestToOpenAI = _chunkSUEGJ75Dcjs.convertAnthropicRequestToOpenAI; exports.convertAnthropicStreamToOpenAI = _chunkSUEGJ75Dcjs.convertAnthropicStreamToOpenAI; exports.convertAnthropicToOpenAI = _chunkSUEGJ75Dcjs.convertAnthropicToOpenAI; exports.convertAnthropicToOpenAIWithThinking = _chunkSUEGJ75Dcjs.convertAnthropicToOpenAIWithThinking; exports.convertOpenAIResponseToAnthropic = _chunkSUEGJ75Dcjs.convertOpenAIResponseToAnthropic; exports.convertOpenAIStreamToAnthropic = _chunkSUEGJ75Dcjs.convertOpenAIStreamToAnthropic; exports.convertOpenAIToAnthropic = _chunkSUEGJ75Dcjs.convertOpenAIToAnthropic; exports.convertOpenAIToAnthropicWithThinking = _chunkSUEGJ75Dcjs.convertOpenAIToAnthropicWithThinking; exports.hasImageContent = _chunkSUEGJ75Dcjs.hasImageContent; exports.hasThinkingEnabled = _chunkSUEGJ75Dcjs.hasThinkingEnabled;