@omnicross/core 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) 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 +6 -5
  6. package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -3
  7. package/dist/{chunk-HRRYG2AX.js → chunk-23S5OPIO.js} +10 -1
  8. package/dist/chunk-25GXJCEZ.cjs +40 -0
  9. package/dist/chunk-2JYRIADS.js +40 -0
  10. package/dist/{chunk-4XMYPW46.cjs → chunk-4VLRHHFE.cjs} +75 -33
  11. package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
  12. package/dist/{chunk-C6OV7GCC.js → chunk-6CL5HTPQ.js} +44 -2
  13. package/dist/chunk-6QQG7YG3.cjs +153 -0
  14. package/dist/{chunk-3Q6Z6JTO.cjs → chunk-6VUQPOV3.cjs} +277 -86
  15. package/dist/chunk-7AK7B36B.cjs +44 -0
  16. package/dist/{chunk-5ZQBEOMD.js → chunk-AT7B7SOZ.js} +25 -2
  17. package/dist/{chunk-IK3KE3AU.js → chunk-DE2SRBFZ.js} +1 -1
  18. package/dist/chunk-DLXZEZWO.cjs +285 -0
  19. package/dist/{chunk-UHGVBFU3.js → chunk-EBLFCNPY.js} +38 -14
  20. package/dist/chunk-EJLH6NFT.cjs +166 -0
  21. package/dist/chunk-HVBBDBS3.cjs +350 -0
  22. package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
  23. package/dist/{chunk-JWVTXXPX.cjs → chunk-KBM2W6UY.cjs} +8 -4
  24. package/dist/{chunk-PG7PS2NN.cjs → chunk-KCVJWJST.cjs} +14 -2
  25. package/dist/chunk-LB6EBS6Y.js +69 -0
  26. package/dist/{chunk-IWQAX3CS.js → chunk-LVUCAWMK.js} +1 -1
  27. package/dist/chunk-MKF46GNZ.js +350 -0
  28. package/dist/{chunk-HYN75H6G.cjs → chunk-MUHWHQVM.cjs} +1 -1
  29. package/dist/{chunk-MFZ5437A.js → chunk-N5T4M4GU.js} +1 -1
  30. package/dist/{chunk-BODMAL6G.js → chunk-OEWZUX4G.js} +262 -71
  31. package/dist/chunk-OF3BECU2.cjs +69 -0
  32. package/dist/{chunk-DDMRUL76.cjs → chunk-OKMJLEXX.cjs} +5 -5
  33. package/dist/chunk-OPRS4IQZ.js +153 -0
  34. package/dist/{chunk-D3TDKWRP.js → chunk-SIZQQD6T.js} +14 -2
  35. package/dist/{chunk-CGKLE6IW.cjs → chunk-SQYVORNP.cjs} +1219 -510
  36. package/dist/{chunk-6QZGDLL4.js → chunk-TOVPMMHM.js} +5 -1
  37. package/dist/{chunk-FH2P4OCD.js → chunk-UDCC7EMR.js} +976 -267
  38. package/dist/{chunk-ZLX3KGXX.js → chunk-UX7VWA46.js} +135 -23
  39. package/dist/{chunk-K52THW2C.cjs → chunk-V4TXMEJS.cjs} +5 -5
  40. package/dist/chunk-VRFBB5DB.js +44 -0
  41. package/dist/chunk-WB6PH56J.js +166 -0
  42. package/dist/{chunk-G2UTNSGU.js → chunk-WNKWAEUR.js} +7 -1
  43. package/dist/{chunk-SUEGJ75D.cjs → chunk-WYTEQ4Q5.cjs} +25 -2
  44. package/dist/{chunk-5ENKBSWO.js → chunk-YJVHCHQX.js} +42 -6
  45. package/dist/{chunk-VQY5W4YW.cjs → chunk-YK57NMIF.cjs} +44 -8
  46. package/dist/{chunk-KFI44N2R.cjs → chunk-YNJNTCSQ.cjs} +10 -1
  47. package/dist/completion/ApiKeyPoolService.cjs +12 -0
  48. package/dist/completion/ApiKeyPoolService.d.cts +6 -0
  49. package/dist/completion/ApiKeyPoolService.d.ts +6 -0
  50. package/dist/completion/ApiKeyPoolService.js +12 -0
  51. package/dist/completion/CompletionService.cjs +25 -23
  52. package/dist/completion/CompletionService.d.cts +2 -1
  53. package/dist/completion/CompletionService.d.ts +2 -1
  54. package/dist/completion/CompletionService.js +24 -22
  55. package/dist/completion.cjs +25 -23
  56. package/dist/completion.d.cts +2 -1
  57. package/dist/completion.d.ts +2 -1
  58. package/dist/completion.js +24 -22
  59. package/dist/index.cjs +49 -26
  60. package/dist/index.d.cts +8 -8
  61. package/dist/index.d.ts +8 -8
  62. package/dist/index.js +52 -29
  63. package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
  64. package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
  65. package/dist/outbound-api/quotaWarn.d.cts +1 -1
  66. package/dist/outbound-api/quotaWarn.d.ts +1 -1
  67. package/dist/outbound-api/routeResolver.cjs +2 -2
  68. package/dist/outbound-api/routeResolver.d.cts +4 -3
  69. package/dist/outbound-api/routeResolver.d.ts +4 -3
  70. package/dist/outbound-api/routeResolver.js +1 -1
  71. package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
  72. package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
  73. package/dist/outbound-api/types.d.cts +3 -2
  74. package/dist/outbound-api/types.d.ts +3 -2
  75. package/dist/outbound-api.cjs +47 -24
  76. package/dist/outbound-api.d.cts +127 -85
  77. package/dist/outbound-api.d.ts +127 -85
  78. package/dist/outbound-api.js +50 -27
  79. package/dist/pipeline/AccountAllowanceScheduling.cjs +15 -0
  80. package/dist/pipeline/AccountAllowanceScheduling.d.cts +90 -0
  81. package/dist/pipeline/AccountAllowanceScheduling.d.ts +90 -0
  82. package/dist/pipeline/AccountAllowanceScheduling.js +15 -0
  83. package/dist/pipeline/AccountAllowanceStore.cjs +20 -0
  84. package/dist/pipeline/AccountAllowanceStore.d.cts +77 -0
  85. package/dist/pipeline/AccountAllowanceStore.d.ts +77 -0
  86. package/dist/pipeline/AccountAllowanceStore.js +20 -0
  87. package/dist/pipeline/AuthSource.d.cts +11 -2
  88. package/dist/pipeline/AuthSource.d.ts +11 -2
  89. package/dist/pipeline/BoundAccountSelectionError.cjs +10 -0
  90. package/dist/pipeline/BoundAccountSelectionError.d.cts +28 -0
  91. package/dist/pipeline/BoundAccountSelectionError.d.ts +28 -0
  92. package/dist/pipeline/BoundAccountSelectionError.js +10 -0
  93. package/dist/pipeline/LlmConfigProviderAuth.d.cts +1 -0
  94. package/dist/pipeline/LlmConfigProviderAuth.d.ts +1 -0
  95. package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
  96. package/dist/pipeline/SubscriptionAccountHealth.d.cts +34 -6
  97. package/dist/pipeline/SubscriptionAccountHealth.d.ts +34 -6
  98. package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
  99. package/dist/pipeline/SubscriptionAuthSource.cjs +5 -2
  100. package/dist/pipeline/SubscriptionAuthSource.d.cts +1 -0
  101. package/dist/pipeline/SubscriptionAuthSource.d.ts +1 -0
  102. package/dist/pipeline/SubscriptionAuthSource.js +4 -1
  103. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +8 -3
  104. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +8 -3
  105. package/dist/pipeline/executeProviderCall.cjs +2 -2
  106. package/dist/pipeline/executeProviderCall.d.cts +8 -3
  107. package/dist/pipeline/executeProviderCall.d.ts +8 -3
  108. package/dist/pipeline/executeProviderCall.js +1 -1
  109. package/dist/pipeline/resolveProviderChain.d.cts +2 -3
  110. package/dist/pipeline/resolveProviderChain.d.ts +2 -3
  111. package/dist/pipeline/resolveSubscriptionChain.d.cts +1 -0
  112. package/dist/pipeline/resolveSubscriptionChain.d.ts +1 -0
  113. package/dist/pipeline/upstreamFetch.cjs +3 -2
  114. package/dist/pipeline/upstreamFetch.js +2 -1
  115. package/dist/ports/pricing-store.d.cts +4 -3
  116. package/dist/ports/pricing-store.d.ts +4 -3
  117. package/dist/ports.d.cts +4 -3
  118. package/dist/ports.d.ts +4 -3
  119. package/dist/provider-proxy/ProviderProxy.cjs +25 -23
  120. package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
  121. package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
  122. package/dist/provider-proxy/ProviderProxy.js +24 -22
  123. package/dist/provider-proxy/ingress/providerProxyShared.cjs +27 -23
  124. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +34 -5
  125. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +34 -5
  126. package/dist/provider-proxy/ingress/providerProxyShared.js +26 -22
  127. package/dist/provider-proxy/matchText.cjs +4 -2
  128. package/dist/provider-proxy/matchText.d.cts +41 -6
  129. package/dist/provider-proxy/matchText.d.ts +41 -6
  130. package/dist/provider-proxy/matchText.js +3 -1
  131. package/dist/provider-proxy/types.d.cts +30 -2
  132. package/dist/provider-proxy/types.d.ts +30 -2
  133. package/dist/provider-proxy.cjs +25 -23
  134. package/dist/provider-proxy.d.cts +1 -0
  135. package/dist/provider-proxy.d.ts +1 -0
  136. package/dist/provider-proxy.js +24 -22
  137. package/dist/{routeResolver-C4T7yClx.d.ts → routeResolver-CHTv_Bs5.d.ts} +1 -1
  138. package/dist/{routeResolver-CB3tvJKy.d.cts → routeResolver-kepxnfcC.d.cts} +1 -1
  139. package/dist/transformer/TransformerChainExecutor.cjs +2 -2
  140. package/dist/transformer/TransformerChainExecutor.js +1 -1
  141. package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
  142. package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
  143. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
  144. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
  145. package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
  146. package/dist/transformer/transformers/GeminiTransformer.js +2 -2
  147. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
  148. package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +1 -1
  149. package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +1 -1
  150. package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
  151. package/dist/transformer/transformers/OpenAITransformer.cjs +6 -0
  152. package/dist/transformer/transformers/OpenAITransformer.d.cts +68 -0
  153. package/dist/transformer/transformers/OpenAITransformer.d.ts +68 -0
  154. package/dist/transformer/transformers/OpenAITransformer.js +6 -0
  155. package/dist/transformer/transformers.cjs +8 -14
  156. package/dist/transformer/transformers.d.cts +12 -48
  157. package/dist/transformer/transformers.d.ts +12 -48
  158. package/dist/transformer/transformers.js +12 -18
  159. package/dist/transformer/types.d.cts +17 -0
  160. package/dist/transformer/types.d.ts +17 -0
  161. package/dist/transformer.cjs +10 -11
  162. package/dist/transformer.d.cts +1 -2
  163. package/dist/transformer.d.ts +1 -2
  164. package/dist/transformer.js +9 -10
  165. package/dist/{types-B8Arpxn0.d.cts → types-H3wGZSOo.d.cts} +134 -7
  166. package/dist/{types-lgPYQuZS.d.ts → types-hsoKrVQS.d.ts} +134 -7
  167. package/dist/usage/pricing-engine.cjs +2 -2
  168. package/dist/usage/pricing-engine.d.cts +9 -1
  169. package/dist/usage/pricing-engine.d.ts +9 -1
  170. package/dist/usage/pricing-engine.js +1 -1
  171. package/dist/usage.cjs +2 -2
  172. package/dist/usage.js +1 -1
  173. package/package.json +1 -1
  174. package/dist/chunk-7FEBOPJO.cjs +0 -50
  175. package/dist/chunk-DWKQZ2SK.cjs +0 -254
  176. package/dist/chunk-IAXWICZU.js +0 -69
  177. package/dist/chunk-IB3FDI4O.js +0 -50
  178. package/dist/chunk-OQWKZCXP.js +0 -242
  179. package/dist/chunk-QWBWGODS.cjs +0 -69
  180. package/dist/chunk-YMFAJFQT.cjs +0 -173
  181. package/dist/chunk-ZCIQ3L3R.cjs +0 -242
  182. package/dist/chunk-ZJZAOKI7.js +0 -254
  183. package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +0 -6
  184. package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +0 -51
  185. package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +0 -51
  186. package/dist/transformer/transformers/OpenCodeGoTransformer.js +0 -6
  187. package/dist/transformer/transformers/ReasoningTransformer.cjs +0 -6
  188. package/dist/transformer/transformers/ReasoningTransformer.d.cts +0 -47
  189. package/dist/transformer/transformers/ReasoningTransformer.d.ts +0 -47
  190. package/dist/transformer/transformers/ReasoningTransformer.js +0 -6
@@ -1,69 +0,0 @@
1
- // src/provider-proxy/matchText.ts
2
- var MATCH_TEXT_PER_MESSAGE_CAP = 8192;
3
- var MATCH_TEXT_RECENT_MESSAGES = 6;
4
- function flattenMatchText(value) {
5
- if (typeof value === "string") return value;
6
- if (Array.isArray(value)) {
7
- const parts = [];
8
- for (const item of value) {
9
- const text = flattenMatchText(item);
10
- if (text) parts.push(text);
11
- }
12
- return parts.join("\n");
13
- }
14
- if (value && typeof value === "object") {
15
- const obj = value;
16
- if (obj.type === "tool_result" && obj.content !== void 0) {
17
- return flattenMatchText(obj.content);
18
- }
19
- if (typeof obj.text === "string") return obj.text;
20
- }
21
- return "";
22
- }
23
- function collectMatchText(anthropicBody) {
24
- const messages = Array.isArray(anthropicBody.messages) ? anthropicBody.messages : [];
25
- const slices = [];
26
- const sys = flattenMatchText(anthropicBody.system).trim();
27
- if (sys) slices.push(sys.slice(0, MATCH_TEXT_PER_MESSAGE_CAP));
28
- const recent = [];
29
- for (let i = messages.length - 1; i >= 0 && recent.length < MATCH_TEXT_RECENT_MESSAGES; i--) {
30
- const message = messages[i];
31
- if (!message || typeof message !== "object") continue;
32
- const role = message.role;
33
- if (role !== "user" && role !== "system") continue;
34
- const text = flattenMatchText(message.content).trim();
35
- if (text) recent.push(text.slice(0, MATCH_TEXT_PER_MESSAGE_CAP));
36
- }
37
- for (let i = recent.length - 1; i >= 0; i--) slices.push(recent[i]);
38
- return slices;
39
- }
40
- function deriveSubscriptionSessionKey(anthropicBody) {
41
- const system = flattenMatchText(anthropicBody.system).trim().slice(0, MATCH_TEXT_PER_MESSAGE_CAP);
42
- const messages = Array.isArray(anthropicBody.messages) ? anthropicBody.messages : [];
43
- let firstUser = "";
44
- for (const message of messages) {
45
- if (message && typeof message === "object" && message.role === "user") {
46
- firstUser = flattenMatchText(message.content).trim().slice(0, MATCH_TEXT_PER_MESSAGE_CAP);
47
- break;
48
- }
49
- }
50
- const anchor = `${system}\0${firstUser}`;
51
- if (!system && !firstUser) return void 0;
52
- return fnv1a(anchor);
53
- }
54
- function fnv1a(str) {
55
- let h = 2166136261;
56
- for (let i = 0; i < str.length; i++) {
57
- h ^= str.charCodeAt(i);
58
- h = Math.imul(h, 16777619);
59
- }
60
- return (h >>> 0).toString(16).padStart(8, "0");
61
- }
62
-
63
- export {
64
- MATCH_TEXT_PER_MESSAGE_CAP,
65
- MATCH_TEXT_RECENT_MESSAGES,
66
- flattenMatchText,
67
- collectMatchText,
68
- deriveSubscriptionSessionKey
69
- };
@@ -1,50 +0,0 @@
1
- // src/transformer/transformers/OpenCodeGoTransformer.ts
2
- var OpenCodeGoTransformer = class {
3
- static TransformerName = "opencodego";
4
- name = "opencodego";
5
- endPoint = "/v1/chat/completions";
6
- logger;
7
- async auth(request, _provider, _context) {
8
- return { body: request, config: { headers: {} } };
9
- }
10
- /**
11
- * Unified → OpenAI Chat Completions.
12
- * Unified IS chat completions shape; this is mostly stripping `meta` and
13
- * normalizing string-content single-block messages.
14
- */
15
- async transformRequestIn(request, _provider, _context) {
16
- const messages = request.messages.map((m) => {
17
- const content = m.content;
18
- const normalizedContent = Array.isArray(content) && content.length === 1 && content[0]?.type === "text" ? content[0].text : content;
19
- const out2 = { role: m.role, content: normalizedContent };
20
- if (m.tool_calls) out2.tool_calls = m.tool_calls;
21
- if (m.tool_call_id) out2.tool_call_id = m.tool_call_id;
22
- return out2;
23
- });
24
- const out = {
25
- model: request.model,
26
- messages,
27
- stream: request.stream
28
- };
29
- if (request.temperature !== void 0) out.temperature = request.temperature;
30
- if (request.max_tokens !== void 0) out.max_tokens = request.max_tokens;
31
- if (request.tools && request.tools.length > 0) out.tools = request.tools;
32
- if (request.tool_choice !== void 0) out.tool_choice = request.tool_choice;
33
- if (request.reasoning?.effort && request.reasoning.effort !== "none") {
34
- out.reasoning_effort = request.reasoning.effort;
35
- }
36
- return out;
37
- }
38
- /**
39
- * OpenAI Chat Completions response → Unified.
40
- * The upstream's response shape already matches Unified — pass through.
41
- * The endpoint AnthropicTransformer re-encodes to Anthropic for the SDK.
42
- */
43
- async transformResponseOut(response, _context) {
44
- return response;
45
- }
46
- };
47
-
48
- export {
49
- OpenCodeGoTransformer
50
- };
@@ -1,242 +0,0 @@
1
- import {
2
- OpenCodeGoTransformer
3
- } from "./chunk-IB3FDI4O.js";
4
- import {
5
- ReasoningTransformer
6
- } from "./chunk-ZJZAOKI7.js";
7
- import {
8
- AnthropicTransformer
9
- } from "./chunk-C6OV7GCC.js";
10
- import {
11
- GeminiTransformer
12
- } from "./chunk-IWQAX3CS.js";
13
- import {
14
- OpenAIResponseTransformer
15
- } from "./chunk-BODMAL6G.js";
16
- import {
17
- GeminiCodeAssistTransformer
18
- } from "./chunk-MFZ5437A.js";
19
-
20
- // src/transformer/transformers/DeepseekTransformer.ts
21
- var DeepseekTransformer = class {
22
- static TransformerName = "deepseek";
23
- name = "deepseek";
24
- logger;
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 = request.model?.startsWith("deepseek-v4");
31
- if (!isV4 && request.max_tokens && request.max_tokens > 8192) {
32
- this.logger?.debug("DeepSeek: Limiting max_tokens from %d to 8192", request.max_tokens);
33
- request.max_tokens = 8192;
34
- }
35
- const sanitizedMessages = (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 = 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 (jsonResponse.choices?.[0]?.message?.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 (data.choices?.[0]?.delta?.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 (data.choices?.[0]?.delta?.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 (data.choices?.[0]?.delta?.reasoning_content) {
139
- delete data.choices[0].delta.reasoning_content;
140
- }
141
- if (data.choices?.[0]?.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
- this.logger?.error("Error processing DeepSeek stream line:", error);
181
- controller.enqueue(encoder.encode(line + "\n"));
182
- }
183
- }
184
- }
185
- } catch (error) {
186
- this.logger?.error("DeepSeek stream error:", error);
187
- controller.error(error);
188
- } finally {
189
- try {
190
- reader.releaseLock();
191
- } catch (e) {
192
- this.logger?.error("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
- };
209
-
210
- // src/transformer/transformers/index.ts
211
- var BuiltinTransformers = {
212
- DeepseekTransformer,
213
- ReasoningTransformer,
214
- GeminiTransformer,
215
- GeminiCodeAssistTransformer,
216
- AnthropicTransformer,
217
- OpenAIResponseTransformer,
218
- 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
- export {
237
- DeepseekTransformer,
238
- BuiltinTransformers,
239
- getBuiltinTransformers,
240
- BUILTIN_TRANSFORMER_NAMES,
241
- registerBuiltinTransformers
242
- };
@@ -1,69 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/provider-proxy/matchText.ts
2
- var MATCH_TEXT_PER_MESSAGE_CAP = 8192;
3
- var MATCH_TEXT_RECENT_MESSAGES = 6;
4
- function flattenMatchText(value) {
5
- if (typeof value === "string") return value;
6
- if (Array.isArray(value)) {
7
- const parts = [];
8
- for (const item of value) {
9
- const text = flattenMatchText(item);
10
- if (text) parts.push(text);
11
- }
12
- return parts.join("\n");
13
- }
14
- if (value && typeof value === "object") {
15
- const obj = value;
16
- if (obj.type === "tool_result" && obj.content !== void 0) {
17
- return flattenMatchText(obj.content);
18
- }
19
- if (typeof obj.text === "string") return obj.text;
20
- }
21
- return "";
22
- }
23
- function collectMatchText(anthropicBody) {
24
- const messages = Array.isArray(anthropicBody.messages) ? anthropicBody.messages : [];
25
- const slices = [];
26
- const sys = flattenMatchText(anthropicBody.system).trim();
27
- if (sys) slices.push(sys.slice(0, MATCH_TEXT_PER_MESSAGE_CAP));
28
- const recent = [];
29
- for (let i = messages.length - 1; i >= 0 && recent.length < MATCH_TEXT_RECENT_MESSAGES; i--) {
30
- const message = messages[i];
31
- if (!message || typeof message !== "object") continue;
32
- const role = message.role;
33
- if (role !== "user" && role !== "system") continue;
34
- const text = flattenMatchText(message.content).trim();
35
- if (text) recent.push(text.slice(0, MATCH_TEXT_PER_MESSAGE_CAP));
36
- }
37
- for (let i = recent.length - 1; i >= 0; i--) slices.push(recent[i]);
38
- return slices;
39
- }
40
- function deriveSubscriptionSessionKey(anthropicBody) {
41
- const system = flattenMatchText(anthropicBody.system).trim().slice(0, MATCH_TEXT_PER_MESSAGE_CAP);
42
- const messages = Array.isArray(anthropicBody.messages) ? anthropicBody.messages : [];
43
- let firstUser = "";
44
- for (const message of messages) {
45
- if (message && typeof message === "object" && message.role === "user") {
46
- firstUser = flattenMatchText(message.content).trim().slice(0, MATCH_TEXT_PER_MESSAGE_CAP);
47
- break;
48
- }
49
- }
50
- const anchor = `${system}\0${firstUser}`;
51
- if (!system && !firstUser) return void 0;
52
- return fnv1a(anchor);
53
- }
54
- function fnv1a(str) {
55
- let h = 2166136261;
56
- for (let i = 0; i < str.length; i++) {
57
- h ^= str.charCodeAt(i);
58
- h = Math.imul(h, 16777619);
59
- }
60
- return (h >>> 0).toString(16).padStart(8, "0");
61
- }
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
- exports.MATCH_TEXT_PER_MESSAGE_CAP = MATCH_TEXT_PER_MESSAGE_CAP; exports.MATCH_TEXT_RECENT_MESSAGES = MATCH_TEXT_RECENT_MESSAGES; exports.flattenMatchText = flattenMatchText; exports.collectMatchText = collectMatchText; exports.deriveSubscriptionSessionKey = deriveSubscriptionSessionKey;
@@ -1,173 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;// src/usage/pricing-engine.ts
2
- var _pricingtypes = require('@omnicross/contracts/pricing-types');
3
- var PricingEngine = (_class = class {
4
- constructor(store, logger, options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
5
- this.store = store;
6
- this.logger = logger;
7
- this.options = options;
8
- }
9
-
10
-
11
-
12
- __init() {this.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
- __init2() {this.cacheByModel = /* @__PURE__ */ new Map()}
21
- __init3() {this.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 _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(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 = _nullishCoalesce(entry.cacheReadPricePer1m, () => ( ip));
79
- const cwp = _nullishCoalesce(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 = _nullishCoalesce(this.options.sourceUrl, () => ( _pricingtypes.DEFAULT_LITELLM_PRICING_URL));
99
- const fetchImpl = _nullishCoalesce(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
- }, _class);
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 = _nullishCoalesce(entry.litellm_provider, () => ( ""));
157
- const providerId = _nullishCoalesce(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
-
172
-
173
- exports.PricingEngine = PricingEngine;