@omnicross/core 0.1.5 → 0.1.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 (231) hide show
  1. package/dist/ApiConverter.cjs +2 -2
  2. package/dist/ApiConverter.js +1 -1
  3. package/dist/{CompletionService-DdWaAxq0.d.ts → CompletionService-C3BX0Ovy.d.ts} +4 -3
  4. package/dist/{CompletionService-D3a47vdU.d.cts → CompletionService-kNA17cfI.d.cts} +4 -3
  5. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +8 -6
  6. package/dist/auth/GeminiCodeAssistProjectResolver.js +6 -4
  7. package/dist/{chunk-3Z5BQZFM.cjs → chunk-235MXAGX.cjs} +3 -1
  8. package/dist/{chunk-HRRYG2AX.js → chunk-23S5OPIO.js} +10 -1
  9. package/dist/chunk-25GXJCEZ.cjs +40 -0
  10. package/dist/chunk-2E42SAW3.cjs +323 -0
  11. package/dist/chunk-2JYRIADS.js +40 -0
  12. package/dist/chunk-2Z4XM3H5.cjs +44 -0
  13. package/dist/{chunk-BODMAL6G.js → chunk-32O35CIF.js} +271 -91
  14. package/dist/chunk-3SCOLIPT.cjs +63 -0
  15. package/dist/{chunk-SYQF7OIR.js → chunk-3WD4HTR2.js} +2 -0
  16. package/dist/{chunk-CGKLE6IW.cjs → chunk-4BB343BI.cjs} +1489 -520
  17. package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
  18. package/dist/{chunk-5ZQBEOMD.js → chunk-5NJLQ6T6.js} +46 -12
  19. package/dist/chunk-5RSZYQJH.cjs +62 -0
  20. package/dist/chunk-6QQG7YG3.cjs +153 -0
  21. package/dist/{chunk-IFXJ2BG7.js → chunk-7C7DET6S.js} +51 -6
  22. package/dist/{chunk-IK3KE3AU.js → chunk-DE2SRBFZ.js} +1 -1
  23. package/dist/{chunk-FH2P4OCD.js → chunk-E3COOKUP.js} +1240 -271
  24. package/dist/{chunk-UHGVBFU3.js → chunk-EBLFCNPY.js} +38 -14
  25. package/dist/chunk-FU7EAR73.js +62 -0
  26. package/dist/chunk-FXR6N3SR.js +323 -0
  27. package/dist/{chunk-SUEGJ75D.cjs → chunk-GDIXXKF2.cjs} +46 -12
  28. package/dist/chunk-GFIZ6LQI.js +170 -0
  29. package/dist/chunk-GL6XM527.js +61 -0
  30. package/dist/chunk-HVBBDBS3.cjs +350 -0
  31. package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
  32. package/dist/chunk-J3QQ6JS5.cjs +170 -0
  33. package/dist/{chunk-JWVTXXPX.cjs → chunk-KBM2W6UY.cjs} +8 -4
  34. package/dist/chunk-LB6EBS6Y.js +69 -0
  35. package/dist/{chunk-IWQAX3CS.js → chunk-LVUCAWMK.js} +1 -1
  36. package/dist/chunk-MKF46GNZ.js +350 -0
  37. package/dist/{chunk-HYN75H6G.cjs → chunk-MUHWHQVM.cjs} +1 -1
  38. package/dist/chunk-MYYR3HZL.js +44 -0
  39. package/dist/{chunk-MFZ5437A.js → chunk-N5T4M4GU.js} +1 -1
  40. package/dist/{chunk-5ENKBSWO.js → chunk-N7OOJI5V.js} +88 -8
  41. package/dist/chunk-NKVZ6Z3Y.cjs +61 -0
  42. package/dist/chunk-OF3BECU2.cjs +69 -0
  43. package/dist/{chunk-SNYBEXLB.cjs → chunk-OJGQKHN5.cjs} +3 -1
  44. package/dist/{chunk-DDMRUL76.cjs → chunk-OKMJLEXX.cjs} +5 -5
  45. package/dist/chunk-OPRS4IQZ.js +153 -0
  46. package/dist/chunk-OTZC4TNH.cjs +79 -0
  47. package/dist/{chunk-3Q6Z6JTO.cjs → chunk-OVQBNVSV.cjs} +287 -107
  48. package/dist/{chunk-4XMYPW46.cjs → chunk-OXHNSZ53.cjs} +84 -44
  49. package/dist/{chunk-C6OV7GCC.js → chunk-PEGTIPB3.js} +52 -12
  50. package/dist/chunk-PO3XB56Z.js +79 -0
  51. package/dist/{chunk-D3TDKWRP.js → chunk-RJ5ZGNI3.js} +54 -5
  52. package/dist/{chunk-PG7PS2NN.cjs → chunk-RJUONLUQ.cjs} +59 -10
  53. package/dist/{chunk-BPKCU575.js → chunk-SOO562NM.js} +3 -1
  54. package/dist/{chunk-6QZGDLL4.js → chunk-TOVPMMHM.js} +5 -1
  55. package/dist/{chunk-K52THW2C.cjs → chunk-V4TXMEJS.cjs} +5 -5
  56. package/dist/{chunk-G2UTNSGU.js → chunk-WNKWAEUR.js} +7 -1
  57. package/dist/{chunk-UNWKG6EI.cjs → chunk-XPIOJQS2.cjs} +51 -6
  58. package/dist/chunk-XXFYLL7R.js +63 -0
  59. package/dist/{chunk-KFI44N2R.cjs → chunk-YNJNTCSQ.cjs} +10 -1
  60. package/dist/{chunk-VQY5W4YW.cjs → chunk-YWL7YZWS.cjs} +90 -10
  61. package/dist/completion/ApiKeyPoolService.cjs +12 -0
  62. package/dist/completion/ApiKeyPoolService.d.cts +6 -0
  63. package/dist/completion/ApiKeyPoolService.d.ts +6 -0
  64. package/dist/completion/ApiKeyPoolService.js +12 -0
  65. package/dist/completion/CompletionService.cjs +30 -24
  66. package/dist/completion/CompletionService.d.cts +3 -1
  67. package/dist/completion/CompletionService.d.ts +3 -1
  68. package/dist/completion/CompletionService.js +29 -23
  69. package/dist/completion.cjs +32 -26
  70. package/dist/completion.d.cts +3 -1
  71. package/dist/completion.d.ts +3 -1
  72. package/dist/completion.js +31 -25
  73. package/dist/index.cjs +56 -29
  74. package/dist/index.d.cts +8 -8
  75. package/dist/index.d.ts +8 -8
  76. package/dist/index.js +61 -34
  77. package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
  78. package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
  79. package/dist/outbound-api/auditCapture.cjs +2 -2
  80. package/dist/outbound-api/auditCapture.d.cts +3 -4
  81. package/dist/outbound-api/auditCapture.d.ts +3 -4
  82. package/dist/outbound-api/auditCapture.js +1 -1
  83. package/dist/outbound-api/quotaWarn.d.cts +1 -1
  84. package/dist/outbound-api/quotaWarn.d.ts +1 -1
  85. package/dist/outbound-api/routeResolver.cjs +2 -2
  86. package/dist/outbound-api/routeResolver.d.cts +5 -3
  87. package/dist/outbound-api/routeResolver.d.ts +5 -3
  88. package/dist/outbound-api/routeResolver.js +1 -1
  89. package/dist/outbound-api/subscriptionRegistryPort.d.cts +2 -0
  90. package/dist/outbound-api/subscriptionRegistryPort.d.ts +2 -0
  91. package/dist/outbound-api/types.d.cts +4 -2
  92. package/dist/outbound-api/types.d.ts +4 -2
  93. package/dist/outbound-api.cjs +52 -25
  94. package/dist/outbound-api.d.cts +131 -87
  95. package/dist/outbound-api.d.ts +131 -87
  96. package/dist/outbound-api.js +55 -28
  97. package/dist/pipeline/AccountAllowanceScheduling.cjs +15 -0
  98. package/dist/pipeline/AccountAllowanceScheduling.d.cts +91 -0
  99. package/dist/pipeline/AccountAllowanceScheduling.d.ts +91 -0
  100. package/dist/pipeline/AccountAllowanceScheduling.js +15 -0
  101. package/dist/pipeline/AccountAllowanceStore.cjs +20 -0
  102. package/dist/pipeline/AccountAllowanceStore.d.cts +77 -0
  103. package/dist/pipeline/AccountAllowanceStore.d.ts +77 -0
  104. package/dist/pipeline/AccountAllowanceStore.js +20 -0
  105. package/dist/pipeline/AccountRouteActivity.cjs +10 -0
  106. package/dist/pipeline/AccountRouteActivity.d.cts +61 -0
  107. package/dist/pipeline/AccountRouteActivity.d.ts +61 -0
  108. package/dist/pipeline/AccountRouteActivity.js +10 -0
  109. package/dist/pipeline/AuthSource.d.cts +11 -2
  110. package/dist/pipeline/AuthSource.d.ts +11 -2
  111. package/dist/pipeline/BoundAccountSelectionError.cjs +10 -0
  112. package/dist/pipeline/BoundAccountSelectionError.d.cts +28 -0
  113. package/dist/pipeline/BoundAccountSelectionError.d.ts +28 -0
  114. package/dist/pipeline/BoundAccountSelectionError.js +10 -0
  115. package/dist/pipeline/LlmConfigProviderAuth.d.cts +1 -0
  116. package/dist/pipeline/LlmConfigProviderAuth.d.ts +1 -0
  117. package/dist/pipeline/ServerOverloadCounter.cjs +16 -0
  118. package/dist/pipeline/ServerOverloadCounter.d.cts +77 -0
  119. package/dist/pipeline/ServerOverloadCounter.d.ts +77 -0
  120. package/dist/pipeline/ServerOverloadCounter.js +16 -0
  121. package/dist/pipeline/SubscriptionAccountHealth.cjs +6 -2
  122. package/dist/pipeline/SubscriptionAccountHealth.d.cts +65 -8
  123. package/dist/pipeline/SubscriptionAccountHealth.d.ts +65 -8
  124. package/dist/pipeline/SubscriptionAccountHealth.js +5 -1
  125. package/dist/pipeline/SubscriptionAuthSource.cjs +5 -2
  126. package/dist/pipeline/SubscriptionAuthSource.d.cts +1 -0
  127. package/dist/pipeline/SubscriptionAuthSource.d.ts +1 -0
  128. package/dist/pipeline/SubscriptionAuthSource.js +4 -1
  129. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +8 -3
  130. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +8 -3
  131. package/dist/pipeline/executeProviderCall.cjs +2 -2
  132. package/dist/pipeline/executeProviderCall.d.cts +8 -3
  133. package/dist/pipeline/executeProviderCall.d.ts +8 -3
  134. package/dist/pipeline/executeProviderCall.js +1 -1
  135. package/dist/pipeline/resolveProviderChain.d.cts +2 -3
  136. package/dist/pipeline/resolveProviderChain.d.ts +2 -3
  137. package/dist/pipeline/resolveSubscriptionChain.d.cts +1 -0
  138. package/dist/pipeline/resolveSubscriptionChain.d.ts +1 -0
  139. package/dist/pipeline/upstreamFetch.cjs +5 -3
  140. package/dist/pipeline/upstreamFetch.d.cts +35 -6
  141. package/dist/pipeline/upstreamFetch.d.ts +35 -6
  142. package/dist/pipeline/upstreamFetch.js +4 -2
  143. package/dist/pipeline/upstreamTrace.cjs +4 -2
  144. package/dist/pipeline/upstreamTrace.d.cts +22 -8
  145. package/dist/pipeline/upstreamTrace.d.ts +22 -8
  146. package/dist/pipeline/upstreamTrace.js +3 -1
  147. package/dist/ports/pricing-store.d.cts +4 -3
  148. package/dist/ports/pricing-store.d.ts +4 -3
  149. package/dist/ports.d.cts +4 -3
  150. package/dist/ports.d.ts +4 -3
  151. package/dist/provider-proxy/ProviderProxy.cjs +30 -24
  152. package/dist/provider-proxy/ProviderProxy.d.cts +2 -0
  153. package/dist/provider-proxy/ProviderProxy.d.ts +2 -0
  154. package/dist/provider-proxy/ProviderProxy.js +29 -23
  155. package/dist/provider-proxy/identity/codexCliHeaders.cjs +10 -0
  156. package/dist/provider-proxy/identity/codexCliHeaders.d.cts +45 -0
  157. package/dist/provider-proxy/identity/codexCliHeaders.d.ts +45 -0
  158. package/dist/provider-proxy/identity/codexCliHeaders.js +10 -0
  159. package/dist/provider-proxy/ingress/providerProxyShared.cjs +32 -24
  160. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +44 -5
  161. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +44 -5
  162. package/dist/provider-proxy/ingress/providerProxyShared.js +31 -23
  163. package/dist/provider-proxy/matchText.cjs +4 -2
  164. package/dist/provider-proxy/matchText.d.cts +39 -6
  165. package/dist/provider-proxy/matchText.d.ts +39 -6
  166. package/dist/provider-proxy/matchText.js +3 -1
  167. package/dist/provider-proxy/types.d.cts +35 -2
  168. package/dist/provider-proxy/types.d.ts +35 -2
  169. package/dist/provider-proxy.cjs +30 -24
  170. package/dist/provider-proxy.d.cts +2 -0
  171. package/dist/provider-proxy.d.ts +2 -0
  172. package/dist/provider-proxy.js +29 -23
  173. package/dist/{routeResolver-C4T7yClx.d.ts → routeResolver-BxOfunbm.d.ts} +1 -1
  174. package/dist/{routeResolver-CB3tvJKy.d.cts → routeResolver-D5OzD0iM.d.cts} +1 -1
  175. package/dist/transformer/TransformerChainExecutor.cjs +2 -2
  176. package/dist/transformer/TransformerChainExecutor.js +1 -1
  177. package/dist/transformer/transformers/AnthropicTransformer.cjs +3 -2
  178. package/dist/transformer/transformers/AnthropicTransformer.js +2 -1
  179. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
  180. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
  181. package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
  182. package/dist/transformer/transformers/GeminiTransformer.js +2 -2
  183. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -2
  184. package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +1 -1
  185. package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +1 -1
  186. package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -1
  187. package/dist/transformer/transformers/OpenAITransformer.cjs +6 -0
  188. package/dist/transformer/transformers/OpenAITransformer.d.cts +68 -0
  189. package/dist/transformer/transformers/OpenAITransformer.d.ts +68 -0
  190. package/dist/transformer/transformers/OpenAITransformer.js +6 -0
  191. package/dist/transformer/transformers.cjs +9 -14
  192. package/dist/transformer/transformers.d.cts +12 -48
  193. package/dist/transformer/transformers.d.ts +12 -48
  194. package/dist/transformer/transformers.js +11 -16
  195. package/dist/transformer/types.d.cts +17 -0
  196. package/dist/transformer/types.d.ts +17 -0
  197. package/dist/transformer.cjs +12 -12
  198. package/dist/transformer.d.cts +1 -2
  199. package/dist/transformer.d.ts +1 -2
  200. package/dist/transformer.js +12 -12
  201. package/dist/{types-lgPYQuZS.d.ts → types-CqZD77rS.d.ts} +173 -7
  202. package/dist/{types-B8Arpxn0.d.cts → types-gjJ5lJ5n.d.cts} +173 -7
  203. package/dist/usage/pricing-engine.cjs +2 -2
  204. package/dist/usage/pricing-engine.d.cts +29 -1
  205. package/dist/usage/pricing-engine.d.ts +29 -1
  206. package/dist/usage/pricing-engine.js +1 -1
  207. package/dist/usage/usage-recorder.cjs +2 -2
  208. package/dist/usage/usage-recorder.d.cts +5 -1
  209. package/dist/usage/usage-recorder.d.ts +5 -1
  210. package/dist/usage/usage-recorder.js +1 -1
  211. package/dist/usage.cjs +3 -3
  212. package/dist/usage.js +2 -2
  213. package/package.json +1 -1
  214. package/dist/chunk-7FEBOPJO.cjs +0 -50
  215. package/dist/chunk-DWKQZ2SK.cjs +0 -254
  216. package/dist/chunk-IAXWICZU.js +0 -69
  217. package/dist/chunk-IB3FDI4O.js +0 -50
  218. package/dist/chunk-OQWKZCXP.js +0 -242
  219. package/dist/chunk-QWBWGODS.cjs +0 -69
  220. package/dist/chunk-YMFAJFQT.cjs +0 -173
  221. package/dist/chunk-ZCIQ3L3R.cjs +0 -242
  222. package/dist/chunk-ZJZAOKI7.js +0 -254
  223. package/dist/chunk-ZLX3KGXX.js +0 -173
  224. package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +0 -6
  225. package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +0 -51
  226. package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +0 -51
  227. package/dist/transformer/transformers/OpenCodeGoTransformer.js +0 -6
  228. package/dist/transformer/transformers/ReasoningTransformer.cjs +0 -6
  229. package/dist/transformer/transformers/ReasoningTransformer.d.cts +0 -47
  230. package/dist/transformer/transformers/ReasoningTransformer.d.ts +0 -47
  231. package/dist/transformer/transformers/ReasoningTransformer.js +0 -6
@@ -1,242 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
-
3
- var _chunk7FEBOPJOcjs = require('./chunk-7FEBOPJO.cjs');
4
-
5
-
6
- var _chunkDWKQZ2SKcjs = require('./chunk-DWKQZ2SK.cjs');
7
-
8
-
9
- var _chunk4XMYPW46cjs = require('./chunk-4XMYPW46.cjs');
10
-
11
-
12
- var _chunkK52THW2Ccjs = require('./chunk-K52THW2C.cjs');
13
-
14
-
15
- var _chunk3Q6Z6JTOcjs = require('./chunk-3Q6Z6JTO.cjs');
16
-
17
-
18
- var _chunkDDMRUL76cjs = require('./chunk-DDMRUL76.cjs');
19
-
20
- // src/transformer/transformers/DeepseekTransformer.ts
21
- var DeepseekTransformer = (_class = class {constructor() { _class.prototype.__init.call(this); }
22
- static __initStatic() {this.TransformerName = "deepseek"}
23
- __init() {this.name = "deepseek"}
24
-
25
- /**
26
- * Transform request: limit max_tokens to 8192 for legacy models only
27
- * V4 models support up to 384K output tokens
28
- */
29
- async transformRequestIn(request, _provider, _context) {
30
- const isV4 = _optionalChain([request, 'access', _ => _.model, 'optionalAccess', _2 => _2.startsWith, 'call', _3 => _3("deepseek-v4")]);
31
- if (!isV4 && request.max_tokens && request.max_tokens > 8192) {
32
- _optionalChain([this, 'access', _4 => _4.logger, 'optionalAccess', _5 => _5.debug, 'call', _6 => _6("DeepSeek: Limiting max_tokens from %d to 8192", request.max_tokens)]);
33
- request.max_tokens = 8192;
34
- }
35
- const sanitizedMessages = (_nullishCoalesce(request.messages, () => ( []))).map((m) => {
36
- const out = { role: m.role };
37
- if (m.content !== void 0) out.content = m.content;
38
- if (m.tool_calls) out.tool_calls = m.tool_calls;
39
- if (m.tool_call_id) out.tool_call_id = m.tool_call_id;
40
- return out;
41
- });
42
- return { ...request, messages: sanitizedMessages };
43
- }
44
- /**
45
- * Transform response: convert reasoning_content to thinking blocks
46
- */
47
- async transformResponseOut(response, _context) {
48
- const contentType = _nullishCoalesce(response.headers.get("Content-Type"), () => ( ""));
49
- if (contentType.includes("application/json")) {
50
- return this.handleJsonResponse(response);
51
- } else if (contentType.includes("stream") || contentType.includes("text/event-stream")) {
52
- return this.handleStreamResponse(response);
53
- }
54
- return response;
55
- }
56
- /**
57
- * Handle JSON (non-streaming) response
58
- */
59
- async handleJsonResponse(response) {
60
- const jsonResponse = await response.json();
61
- if (_optionalChain([jsonResponse, 'access', _7 => _7.choices, 'optionalAccess', _8 => _8[0], 'optionalAccess', _9 => _9.message, 'optionalAccess', _10 => _10.reasoning_content])) {
62
- jsonResponse.choices[0].message.thinking = {
63
- content: jsonResponse.choices[0].message.reasoning_content
64
- };
65
- delete jsonResponse.choices[0].message.reasoning_content;
66
- }
67
- return new Response(JSON.stringify(jsonResponse), {
68
- status: response.status,
69
- statusText: response.statusText,
70
- headers: response.headers
71
- });
72
- }
73
- /**
74
- * Handle streaming response - convert reasoning_content to thinking blocks
75
- */
76
- async handleStreamResponse(response) {
77
- if (!response.body) {
78
- return response;
79
- }
80
- const decoder = new TextDecoder();
81
- const encoder = new TextEncoder();
82
- let reasoningContent = "";
83
- let isReasoningComplete = false;
84
- let buffer = "";
85
- const stream = new ReadableStream({
86
- start: async (controller) => {
87
- const reader = response.body.getReader();
88
- const processLine = (line) => {
89
- if (line.startsWith("data: ") && line.trim() !== "data: [DONE]") {
90
- try {
91
- const data = JSON.parse(line.slice(6));
92
- if (_optionalChain([data, 'access', _11 => _11.choices, 'optionalAccess', _12 => _12[0], 'optionalAccess', _13 => _13.delta, 'optionalAccess', _14 => _14.reasoning_content])) {
93
- reasoningContent += data.choices[0].delta.reasoning_content;
94
- const thinkingChunk = {
95
- ...data,
96
- choices: [
97
- {
98
- ...data.choices[0],
99
- delta: {
100
- ...data.choices[0].delta,
101
- thinking: {
102
- content: data.choices[0].delta.reasoning_content
103
- }
104
- }
105
- }
106
- ]
107
- };
108
- delete thinkingChunk.choices[0].delta.reasoning_content;
109
- const thinkingLine = `data: ${JSON.stringify(thinkingChunk)}
110
-
111
- `;
112
- controller.enqueue(encoder.encode(thinkingLine));
113
- return;
114
- }
115
- if (_optionalChain([data, 'access', _15 => _15.choices, 'optionalAccess', _16 => _16[0], 'optionalAccess', _17 => _17.delta, 'optionalAccess', _18 => _18.content]) && reasoningContent && !isReasoningComplete) {
116
- isReasoningComplete = true;
117
- const signature = Date.now().toString();
118
- const thinkingChunk = {
119
- ...data,
120
- choices: [
121
- {
122
- ...data.choices[0],
123
- delta: {
124
- ...data.choices[0].delta,
125
- content: null,
126
- thinking: {
127
- signature
128
- }
129
- }
130
- }
131
- ]
132
- };
133
- const thinkingLine = `data: ${JSON.stringify(thinkingChunk)}
134
-
135
- `;
136
- controller.enqueue(encoder.encode(thinkingLine));
137
- }
138
- if (_optionalChain([data, 'access', _19 => _19.choices, 'optionalAccess', _20 => _20[0], 'optionalAccess', _21 => _21.delta, 'optionalAccess', _22 => _22.reasoning_content])) {
139
- delete data.choices[0].delta.reasoning_content;
140
- }
141
- if (_optionalChain([data, 'access', _23 => _23.choices, 'optionalAccess', _24 => _24[0], 'optionalAccess', _25 => _25.delta]) && Object.keys(data.choices[0].delta).length > 0) {
142
- if (isReasoningComplete) {
143
- data.choices[0].index++;
144
- }
145
- const modifiedLine = `data: ${JSON.stringify(data)}
146
-
147
- `;
148
- controller.enqueue(encoder.encode(modifiedLine));
149
- }
150
- } catch (_e) {
151
- controller.enqueue(encoder.encode(line + "\n"));
152
- }
153
- } else {
154
- controller.enqueue(encoder.encode(line + "\n"));
155
- }
156
- };
157
- try {
158
- while (true) {
159
- const { done, value } = await reader.read();
160
- if (done) {
161
- if (buffer.trim()) {
162
- const lines2 = buffer.split("\n");
163
- for (const line of lines2) {
164
- if (line.trim()) {
165
- controller.enqueue(encoder.encode(line + "\n"));
166
- }
167
- }
168
- }
169
- break;
170
- }
171
- const chunk = decoder.decode(value, { stream: true });
172
- buffer += chunk;
173
- const lines = buffer.split("\n");
174
- buffer = lines.pop() || "";
175
- for (const line of lines) {
176
- if (!line.trim()) continue;
177
- try {
178
- processLine(line);
179
- } catch (error) {
180
- _optionalChain([this, 'access', _26 => _26.logger, 'optionalAccess', _27 => _27.error, 'call', _28 => _28("Error processing DeepSeek stream line:", error)]);
181
- controller.enqueue(encoder.encode(line + "\n"));
182
- }
183
- }
184
- }
185
- } catch (error) {
186
- _optionalChain([this, 'access', _29 => _29.logger, 'optionalAccess', _30 => _30.error, 'call', _31 => _31("DeepSeek stream error:", error)]);
187
- controller.error(error);
188
- } finally {
189
- try {
190
- reader.releaseLock();
191
- } catch (e) {
192
- _optionalChain([this, 'access', _32 => _32.logger, 'optionalAccess', _33 => _33.error, 'call', _34 => _34("Error releasing reader lock:", e)]);
193
- }
194
- controller.close();
195
- }
196
- }
197
- });
198
- return new Response(stream, {
199
- status: response.status,
200
- statusText: response.statusText,
201
- headers: new Headers({
202
- "Content-Type": "text/event-stream",
203
- "Cache-Control": "no-cache",
204
- Connection: "keep-alive"
205
- })
206
- });
207
- }
208
- }, _class.__initStatic(), _class);
209
-
210
- // src/transformer/transformers/index.ts
211
- var BuiltinTransformers = {
212
- DeepseekTransformer,
213
- ReasoningTransformer: _chunkDWKQZ2SKcjs.ReasoningTransformer,
214
- GeminiTransformer: _chunkK52THW2Ccjs.GeminiTransformer,
215
- GeminiCodeAssistTransformer: _chunkDDMRUL76cjs.GeminiCodeAssistTransformer,
216
- AnthropicTransformer: _chunk4XMYPW46cjs.AnthropicTransformer,
217
- OpenAIResponseTransformer: _chunk3Q6Z6JTOcjs.OpenAIResponseTransformer,
218
- OpenCodeGoTransformer: _chunk7FEBOPJOcjs.OpenCodeGoTransformer
219
- };
220
- function getBuiltinTransformers() {
221
- return BuiltinTransformers;
222
- }
223
- var BUILTIN_TRANSFORMER_NAMES = [
224
- "deepseek",
225
- "reasoning",
226
- "gemini",
227
- "gemini-code-assist",
228
- "anthropic",
229
- "openai-response",
230
- "opencodego"
231
- ];
232
- async function registerBuiltinTransformers(service) {
233
- await service.initialize(getBuiltinTransformers());
234
- }
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
- exports.DeepseekTransformer = DeepseekTransformer; exports.BuiltinTransformers = BuiltinTransformers; exports.getBuiltinTransformers = getBuiltinTransformers; exports.BUILTIN_TRANSFORMER_NAMES = BUILTIN_TRANSFORMER_NAMES; exports.registerBuiltinTransformers = registerBuiltinTransformers;
@@ -1,254 +0,0 @@
1
- // src/transformer/transformers/ReasoningTransformer.ts
2
- import {
3
- buildAnthropicThinking,
4
- buildQwenThinkingConfig,
5
- calculateThinkingBudget,
6
- getOpenAIReasoningEffort
7
- } from "@omnicross/contracts/thinking-config";
8
- var ReasoningTransformer = class {
9
- static TransformerName = "reasoning";
10
- name = "reasoning";
11
- logger;
12
- enabled;
13
- constructor(options) {
14
- this.enabled = options?.enable !== false;
15
- }
16
- /**
17
- * Transform request: convert reasoning config to thinking parameters
18
- * Uses model-specific budget calculation based on effort level
19
- */
20
- async transformRequestIn(request, provider, _context) {
21
- const extendedRequest = request;
22
- const modelId = request.model;
23
- if (!this.enabled) {
24
- extendedRequest.thinking = {
25
- type: "disabled",
26
- budget_tokens: -1
27
- };
28
- extendedRequest.enable_thinking = false;
29
- return extendedRequest;
30
- }
31
- if (request.reasoning) {
32
- const effortLevel = request.reasoning.effort || "none";
33
- const userMaxTokens = request.reasoning.max_tokens || request.max_tokens;
34
- const calculatedBudget = calculateThinkingBudget(modelId, effortLevel, userMaxTokens);
35
- const providerName = provider.name?.toLowerCase() || "";
36
- if (providerName === "anthropic" || providerName.includes("claude")) {
37
- const thinkingConfig = buildAnthropicThinking(modelId, effortLevel, userMaxTokens);
38
- if (thinkingConfig) {
39
- extendedRequest.thinking = thinkingConfig;
40
- } else {
41
- extendedRequest.thinking = {
42
- type: "disabled"
43
- };
44
- }
45
- } else if (providerName === "openai" || modelId.match(/^o[134]/i)) {
46
- const reasoningEffort = getOpenAIReasoningEffort(effortLevel);
47
- if (reasoningEffort) {
48
- extendedRequest.reasoning_effort = reasoningEffort;
49
- }
50
- extendedRequest.thinking = {
51
- type: effortLevel === "none" ? "disabled" : "enabled",
52
- budget_tokens: calculatedBudget
53
- };
54
- } else if (providerName === "deepseek" && modelId?.startsWith("deepseek-v4")) {
55
- extendedRequest.thinking = {
56
- type: effortLevel === "none" ? "disabled" : "enabled",
57
- budget_tokens: calculatedBudget
58
- };
59
- if (effortLevel !== "none") {
60
- extendedRequest.reasoning_effort = effortLevel === "high" ? "max" : "high";
61
- }
62
- } else if (providerName === "deepseek" || providerName === "qwen" || providerName === "alibaba") {
63
- const qwenConfig = buildQwenThinkingConfig(effortLevel, userMaxTokens);
64
- extendedRequest.enable_thinking = qwenConfig.enable_thinking;
65
- if (qwenConfig.thinking_budget) {
66
- extendedRequest.thinking_budget = qwenConfig.thinking_budget;
67
- }
68
- extendedRequest.thinking = {
69
- type: qwenConfig.enable_thinking ? "enabled" : "disabled",
70
- budget_tokens: calculatedBudget
71
- };
72
- } else {
73
- extendedRequest.thinking = {
74
- type: effortLevel === "none" ? "disabled" : "enabled",
75
- budget_tokens: calculatedBudget
76
- };
77
- extendedRequest.enable_thinking = effortLevel !== "none";
78
- }
79
- this.logger?.debug(`[ReasoningTransformer] Model: ${modelId}, Effort: ${effortLevel}, Budget: ${calculatedBudget}`);
80
- }
81
- return extendedRequest;
82
- }
83
- /**
84
- * Transform response: convert reasoning_content to thinking blocks
85
- */
86
- async transformResponseOut(response, _context) {
87
- if (!this.enabled) return response;
88
- const contentType = response.headers.get("Content-Type") ?? "";
89
- if (contentType.includes("application/json")) {
90
- return this.handleJsonResponse(response);
91
- } else if (contentType.includes("stream") || contentType.includes("text/event-stream")) {
92
- return this.handleStreamResponse(response);
93
- }
94
- return response;
95
- }
96
- /**
97
- * Handle JSON (non-streaming) response
98
- */
99
- async handleJsonResponse(response) {
100
- const jsonResponse = await response.json();
101
- if (jsonResponse.choices?.[0]?.message?.reasoning_content) {
102
- jsonResponse.thinking = {
103
- content: jsonResponse.choices[0].message.reasoning_content
104
- };
105
- delete jsonResponse.choices[0].message.reasoning_content;
106
- }
107
- return new Response(JSON.stringify(jsonResponse), {
108
- status: response.status,
109
- statusText: response.statusText,
110
- headers: response.headers
111
- });
112
- }
113
- /**
114
- * Handle streaming response - convert reasoning_content to thinking blocks
115
- */
116
- handleStreamResponse(response) {
117
- if (!response.body) {
118
- return response;
119
- }
120
- const decoder = new TextDecoder();
121
- const encoder = new TextEncoder();
122
- let reasoningContent = "";
123
- let isReasoningComplete = false;
124
- let buffer = "";
125
- const stream = new ReadableStream({
126
- start: async (controller) => {
127
- const reader = response.body.getReader();
128
- const processLine = (line) => {
129
- this.logger?.debug("Processing reasoning line:", line);
130
- if (line.startsWith("data: ") && line.trim() !== "data: [DONE]") {
131
- try {
132
- const data = JSON.parse(line.slice(6));
133
- if (data.choices?.[0]?.delta?.reasoning_content) {
134
- reasoningContent += data.choices[0].delta.reasoning_content;
135
- const thinkingChunk = {
136
- ...data,
137
- choices: [
138
- {
139
- ...data.choices[0],
140
- delta: {
141
- ...data.choices[0].delta,
142
- thinking: {
143
- content: data.choices[0].delta.reasoning_content
144
- }
145
- }
146
- }
147
- ]
148
- };
149
- delete thinkingChunk.choices[0].delta.reasoning_content;
150
- const thinkingLine = `data: ${JSON.stringify(thinkingChunk)}
151
-
152
- `;
153
- controller.enqueue(encoder.encode(thinkingLine));
154
- return;
155
- }
156
- if ((data.choices?.[0]?.delta?.content || data.choices?.[0]?.delta?.tool_calls) && reasoningContent && !isReasoningComplete) {
157
- isReasoningComplete = true;
158
- const signature = Date.now().toString();
159
- const thinkingChunk = {
160
- ...data,
161
- choices: [
162
- {
163
- ...data.choices[0],
164
- delta: {
165
- ...data.choices[0].delta,
166
- content: null,
167
- thinking: {
168
- signature
169
- }
170
- }
171
- }
172
- ]
173
- };
174
- delete thinkingChunk.choices[0].delta.reasoning_content;
175
- const thinkingLine = `data: ${JSON.stringify(thinkingChunk)}
176
-
177
- `;
178
- controller.enqueue(encoder.encode(thinkingLine));
179
- }
180
- if (data.choices?.[0]?.delta?.reasoning_content) {
181
- delete data.choices[0].delta.reasoning_content;
182
- }
183
- if (data.choices?.[0]?.delta && Object.keys(data.choices[0].delta).length > 0) {
184
- if (isReasoningComplete) {
185
- data.choices[0].index++;
186
- }
187
- const modifiedLine = `data: ${JSON.stringify(data)}
188
-
189
- `;
190
- controller.enqueue(encoder.encode(modifiedLine));
191
- }
192
- } catch (_e) {
193
- controller.enqueue(encoder.encode(line + "\n"));
194
- }
195
- } else {
196
- controller.enqueue(encoder.encode(line + "\n"));
197
- }
198
- };
199
- try {
200
- while (true) {
201
- const { done, value } = await reader.read();
202
- if (done) {
203
- if (buffer.trim()) {
204
- const lines2 = buffer.split("\n");
205
- for (const line of lines2) {
206
- if (line.trim()) {
207
- controller.enqueue(encoder.encode(line + "\n"));
208
- }
209
- }
210
- }
211
- break;
212
- }
213
- const chunk = decoder.decode(value, { stream: true });
214
- buffer += chunk;
215
- const lines = buffer.split("\n");
216
- buffer = lines.pop() || "";
217
- for (const line of lines) {
218
- if (!line.trim()) continue;
219
- try {
220
- processLine(line);
221
- } catch (error) {
222
- this.logger?.error("Error processing reasoning stream line:", error);
223
- controller.enqueue(encoder.encode(line + "\n"));
224
- }
225
- }
226
- }
227
- } catch (error) {
228
- this.logger?.error("Reasoning stream error:", error);
229
- controller.error(error);
230
- } finally {
231
- try {
232
- reader.releaseLock();
233
- } catch (e) {
234
- this.logger?.error("Error releasing reader lock:", e);
235
- }
236
- controller.close();
237
- }
238
- }
239
- });
240
- return new Response(stream, {
241
- status: response.status,
242
- statusText: response.statusText,
243
- headers: new Headers({
244
- "Content-Type": "text/event-stream",
245
- "Cache-Control": "no-cache",
246
- Connection: "keep-alive"
247
- })
248
- });
249
- }
250
- };
251
-
252
- export {
253
- ReasoningTransformer
254
- };
@@ -1,173 +0,0 @@
1
- // src/usage/pricing-engine.ts
2
- import { DEFAULT_LITELLM_PRICING_URL } from "@omnicross/contracts/pricing-types";
3
- var PricingEngine = class {
4
- constructor(store, logger, options = {}) {
5
- this.store = store;
6
- this.logger = logger;
7
- this.options = options;
8
- }
9
- store;
10
- logger;
11
- options;
12
- cache = /* @__PURE__ */ new Map();
13
- /**
14
- * Secondary index keyed by modelId alone. Used as a fallback when no exact
15
- * (providerId, modelId) match exists — usage may be recorded under a
16
- * runtime provider alias while pricing rows use the canonical provider id,
17
- * so matching by model name lets the price still resolve. First
18
- * non-wildcard entry per model wins.
19
- */
20
- cacheByModel = /* @__PURE__ */ new Map();
21
- cacheLoaded = false;
22
- // ===== Cache management =====
23
- /** Lazy-load and cache the full pricing table. */
24
- async ensureCache() {
25
- if (this.cacheLoaded) return;
26
- const rows = await this.store.getAll();
27
- this.cache = new Map(rows.map((r) => [keyOf(r.providerId, r.modelId), r]));
28
- this.cacheByModel = /* @__PURE__ */ new Map();
29
- for (const r of rows) {
30
- if (r.providerId === "*") continue;
31
- if (!this.cacheByModel.has(r.modelId)) this.cacheByModel.set(r.modelId, r);
32
- }
33
- this.cacheLoaded = true;
34
- }
35
- /** Force a cache refresh — call after any write. */
36
- async invalidateCache() {
37
- this.cacheLoaded = false;
38
- await this.ensureCache();
39
- }
40
- // ===== Read API =====
41
- async getAll() {
42
- await this.ensureCache();
43
- return Array.from(this.cache.values());
44
- }
45
- /**
46
- * Look up a price for (provider, model). Resolution order:
47
- * 1. exact (providerId, modelId)
48
- * 2. wildcard provider ('*', modelId)
49
- * 3. model name alone (any provider) — tolerates a runtime-alias vs
50
- * canonical provider-id mismatch for the same model.
51
- */
52
- async getEntry(providerId, modelId) {
53
- await this.ensureCache();
54
- return this.cache.get(keyOf(providerId, modelId)) ?? this.cache.get(keyOf("*", modelId)) ?? this.cacheByModel.get(modelId) ?? null;
55
- }
56
- // ===== Cost calculation =====
57
- /**
58
- * Compute the cost (and cache savings) for a single response.
59
- *
60
- * Cost formula (USD):
61
- * cost = (input * inputPrice
62
- * + output * outputPrice
63
- * + cacheRead * (cacheReadPrice ?? inputPrice)
64
- * + cacheWrite * (cacheWritePrice ?? inputPrice)
65
- * ) / 1e6
66
- *
67
- * Cache savings:
68
- * savings = cacheRead * (inputPrice - cacheReadPrice) / 1e6
69
- * — clamped at 0 if cacheReadPrice is null or ≥ inputPrice.
70
- */
71
- async calculateCost(providerId, modelId, usage) {
72
- const entry = await this.getEntry(providerId, modelId);
73
- if (!entry) {
74
- return { costUsd: 0, costSavedByCacheUsd: 0 };
75
- }
76
- const ip = entry.inputPricePer1m;
77
- const op = entry.outputPricePer1m;
78
- const crp = entry.cacheReadPricePer1m ?? ip;
79
- const cwp = entry.cacheWritePricePer1m ?? ip;
80
- const costUsd = (usage.inputTokens * ip + usage.outputTokens * op + usage.cacheReadTokens * crp + usage.cacheCreationTokens * cwp) / 1e6;
81
- const savingsRate = entry.cacheReadPricePer1m == null ? 0 : Math.max(0, ip - crp);
82
- const costSavedByCacheUsd = usage.cacheReadTokens * savingsRate / 1e6;
83
- return { costUsd, costSavedByCacheUsd };
84
- }
85
- // ===== Manual upsert (used by inline editors) =====
86
- async upsertManual(input) {
87
- const updated = await this.store.upsert(
88
- input,
89
- /* asUserEdit */
90
- true
91
- );
92
- this.cache.set(keyOf(updated.providerId, updated.modelId), updated);
93
- if (updated.providerId !== "*") this.cacheByModel.set(updated.modelId, updated);
94
- return updated;
95
- }
96
- // ===== Source refresh =====
97
- async fetchLatestFromSource() {
98
- const sourceUrl = this.options.sourceUrl ?? DEFAULT_LITELLM_PRICING_URL;
99
- const fetchImpl = this.options.fetchImpl ?? fetch;
100
- const fetchedAt = Date.now();
101
- let json;
102
- try {
103
- const res = await fetchImpl(sourceUrl);
104
- if (!res.ok) {
105
- throw new Error(`Pricing-source fetch failed with status ${res.status}`);
106
- }
107
- json = await res.json();
108
- } catch (e) {
109
- this.logger.warn("[PricingEngine] pricing-source fetch failed", {
110
- error: e instanceof Error ? e.message : String(e)
111
- });
112
- throw e;
113
- }
114
- const incoming = parseLitellmJson(json);
115
- const { applied, conflicts } = await this.store.bulkApplyFromSource(incoming);
116
- await this.invalidateCache();
117
- return {
118
- applied,
119
- conflicts: conflicts.map((c) => ({
120
- providerId: c.current.providerId,
121
- modelId: c.current.modelId,
122
- current: c.current,
123
- incoming: c.incoming
124
- })),
125
- fetchedAt,
126
- sourceUrl
127
- };
128
- }
129
- // ===== Conflict resolution =====
130
- async resolveConflicts(decisions, pendingIncoming) {
131
- const resolutions = [];
132
- for (const d of decisions) {
133
- const incoming = pendingIncoming.get(keyOf(d.providerId, d.modelId));
134
- if (!incoming) continue;
135
- resolutions.push({ incoming, action: d.action });
136
- }
137
- const result = await this.store.applyResolutions(resolutions);
138
- await this.invalidateCache();
139
- return result;
140
- }
141
- };
142
- var keyOf = (providerId, modelId) => `${providerId}::${modelId}`;
143
- var PROVIDER_ALIASES = {
144
- vertex_ai: "gemini",
145
- google: "gemini",
146
- bedrock: "anthropic",
147
- azure: "openai"
148
- };
149
- var parseLitellmJson = (json) => {
150
- const out = [];
151
- for (const [modelId, entry] of Object.entries(json)) {
152
- if (!entry || typeof entry !== "object") continue;
153
- if (entry.input_cost_per_token == null || entry.output_cost_per_token == null) {
154
- continue;
155
- }
156
- const rawProvider = entry.litellm_provider ?? "";
157
- const providerId = PROVIDER_ALIASES[rawProvider] ?? rawProvider;
158
- if (!providerId) continue;
159
- out.push({
160
- providerId,
161
- modelId,
162
- inputPricePer1m: entry.input_cost_per_token * 1e6,
163
- outputPricePer1m: entry.output_cost_per_token * 1e6,
164
- cacheReadPricePer1m: entry.cache_read_input_token_cost != null ? entry.cache_read_input_token_cost * 1e6 : null,
165
- cacheWritePricePer1m: entry.cache_creation_input_token_cost != null ? entry.cache_creation_input_token_cost * 1e6 : null
166
- });
167
- }
168
- return out;
169
- };
170
-
171
- export {
172
- PricingEngine
173
- };
@@ -1,6 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunk7FEBOPJOcjs = require('../../chunk-7FEBOPJO.cjs');
4
-
5
-
6
- exports.OpenCodeGoTransformer = _chunk7FEBOPJOcjs.OpenCodeGoTransformer;