@omnicross/core 0.1.10 → 0.2.1

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 (204) hide show
  1. package/README.md +7 -0
  2. package/dist/{BuiltinToolExecutor-CS2WpXhM.d.cts → BuiltinToolExecutor-BHgH-EaZ.d.cts} +25 -2
  3. package/dist/{BuiltinToolExecutor-BluWyeob.d.ts → BuiltinToolExecutor-Bi1LmiTP.d.ts} +25 -2
  4. package/dist/{CompletionService-kNA17cfI.d.cts → CompletionService-BniP7j88.d.cts} +2 -2
  5. package/dist/{CompletionService-C3BX0Ovy.d.ts → CompletionService-BqrKPwfA.d.ts} +2 -2
  6. package/dist/{ProviderProxy-QdwNV6l1.d.cts → ProviderProxy-Bz_nkOwq.d.cts} +1 -1
  7. package/dist/{ProviderProxy--ROec6VI.d.ts → ProviderProxy-Ckr6oTrE.d.ts} +1 -1
  8. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -6
  9. package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -4
  10. package/dist/{chunk-NGYOO5TO.js → chunk-2C3TTBS7.js} +7 -7
  11. package/dist/{chunk-QUSEZNYS.cjs → chunk-32SRZFFP.cjs} +4 -1
  12. package/dist/chunk-4JOU54M5.js +200 -0
  13. package/dist/{chunk-2UTGX6FM.js → chunk-4VVCXVB7.js} +1 -1
  14. package/dist/{chunk-RJUONLUQ.cjs → chunk-4Z3ZLLC2.cjs} +14 -8
  15. package/dist/chunk-6DDYNS2B.cjs +384 -0
  16. package/dist/{chunk-GXEZ2R3E.js → chunk-6OKXH2TW.js} +18 -7
  17. package/dist/{chunk-YWL7YZWS.cjs → chunk-7LRTPNFL.cjs} +5 -0
  18. package/dist/{chunk-CCVRRJOX.js → chunk-7PIUVCKK.js} +9 -2
  19. package/dist/chunk-7RJI3NDI.cjs +236 -0
  20. package/dist/{chunk-IIRPUVPH.cjs → chunk-7ZHBN75N.cjs} +3 -1
  21. package/dist/chunk-D4WNI6BR.cjs +386 -0
  22. package/dist/chunk-DBBR6RHF.js +236 -0
  23. package/dist/chunk-E4QHVXV5.cjs +118 -0
  24. package/dist/{chunk-HKB656B4.js → chunk-EUZRH544.js} +55 -287
  25. package/dist/{chunk-WNKWAEUR.js → chunk-EYGBM2VC.js} +3 -1
  26. package/dist/{chunk-UWDW6PN3.cjs → chunk-FX325I5Q.cjs} +20 -9
  27. package/dist/chunk-G4CZIUIB.cjs +200 -0
  28. package/dist/chunk-HCOQQAZE.cjs +123 -0
  29. package/dist/chunk-HL2YSPL7.cjs +673 -0
  30. package/dist/{chunk-55FMGZ3L.js → chunk-HN74IGEO.js} +1 -1
  31. package/dist/{chunk-ZY6KU6P3.js → chunk-HOMUGKHR.js} +8 -5
  32. package/dist/{chunk-AOFWNWLT.cjs → chunk-IUL4VWNU.cjs} +22 -1
  33. package/dist/{chunk-5LNYGCIW.cjs → chunk-KIQ2HA2A.cjs} +5 -5
  34. package/dist/{chunk-MUHWHQVM.cjs → chunk-KQBLZMP6.cjs} +4 -3
  35. package/dist/chunk-LFEH7CEO.js +384 -0
  36. package/dist/chunk-LFPQ2OVH.js +386 -0
  37. package/dist/{chunk-FEBAQI5A.js → chunk-LKDAN4D7.js} +6363 -1350
  38. package/dist/chunk-LQYS2N47.js +3923 -0
  39. package/dist/{chunk-NZYN7C3P.cjs → chunk-MPXOKQJP.cjs} +53 -53
  40. package/dist/chunk-MZEGQSKQ.js +118 -0
  41. package/dist/chunk-N76KU6F5.js +123 -0
  42. package/dist/chunk-NLUOTJWB.js +673 -0
  43. package/dist/{chunk-CMVXX7ON.cjs → chunk-NOITAVHA.cjs} +114 -58
  44. package/dist/{chunk-Q27JY5RG.cjs → chunk-OIKREZVQ.cjs} +7 -4
  45. package/dist/{chunk-ZQQUD66M.cjs → chunk-POUTD5AM.cjs} +63 -295
  46. package/dist/{chunk-6D4W22P4.js → chunk-QIIAMBTM.js} +4 -1
  47. package/dist/{chunk-56QD3YW6.cjs → chunk-QWNUOR7F.cjs} +11 -4
  48. package/dist/{chunk-S3DYFEBE.js → chunk-R4VCO2CB.js} +10 -1
  49. package/dist/{chunk-4VZX5F4T.cjs → chunk-T6NWPIYZ.cjs} +5 -2
  50. package/dist/{chunk-EBLFCNPY.js → chunk-U47LQXPB.js} +5 -2
  51. package/dist/chunk-UPQIWJIE.cjs +3923 -0
  52. package/dist/{chunk-N7OOJI5V.js → chunk-V2UKUTJ3.js} +5 -0
  53. package/dist/{chunk-45FHEOKW.js → chunk-V53ZEFXC.js} +92 -36
  54. package/dist/{chunk-RJ5ZGNI3.js → chunk-VL5TUDTM.js} +8 -2
  55. package/dist/{chunk-TIT74RIL.cjs → chunk-VSYQ6XYN.cjs} +6837 -1824
  56. package/dist/{chunk-OC6DOOFX.cjs → chunk-VXRTQZF2.cjs} +5 -5
  57. package/dist/{chunk-RICPANBY.cjs → chunk-WX2E2G7H.cjs} +13 -4
  58. package/dist/{chunk-DE2SRBFZ.js → chunk-X335TJNS.js} +4 -3
  59. package/dist/{chunk-CDHS2QDC.js → chunk-Y4CRNHJO.js} +53 -53
  60. package/dist/{chunk-P7EM6BND.cjs → chunk-ZAPN7XA6.cjs} +10 -10
  61. package/dist/{chunk-N2EIM2XJ.js → chunk-ZLNHPUFA.js} +22 -1
  62. package/dist/completion/BuiltinToolExecutor.cjs +2 -2
  63. package/dist/completion/BuiltinToolExecutor.d.cts +3 -1
  64. package/dist/completion/BuiltinToolExecutor.d.ts +3 -1
  65. package/dist/completion/BuiltinToolExecutor.js +1 -1
  66. package/dist/completion/CompletionService.cjs +32 -28
  67. package/dist/completion/CompletionService.d.cts +7 -3
  68. package/dist/completion/CompletionService.d.ts +7 -3
  69. package/dist/completion/CompletionService.js +31 -27
  70. package/dist/completion.cjs +40 -36
  71. package/dist/completion.d.cts +7 -3
  72. package/dist/completion.d.ts +7 -3
  73. package/dist/completion.js +39 -35
  74. package/dist/egress-I46O_p5L.d.cts +126 -0
  75. package/dist/egress-I46O_p5L.d.ts +126 -0
  76. package/dist/frontends-Doz0RaWu.d.cts +97 -0
  77. package/dist/frontends-Doz0RaWu.d.ts +97 -0
  78. package/dist/image-generation.cjs +52 -0
  79. package/dist/image-generation.d.cts +96 -0
  80. package/dist/image-generation.d.ts +96 -0
  81. package/dist/image-generation.js +52 -0
  82. package/dist/index.cjs +142 -32
  83. package/dist/index.d.cts +16 -8
  84. package/dist/index.d.ts +16 -8
  85. package/dist/index.js +159 -49
  86. package/dist/openai-operation.cjs +18 -0
  87. package/dist/openai-operation.d.cts +22 -0
  88. package/dist/openai-operation.d.ts +22 -0
  89. package/dist/openai-operation.js +18 -0
  90. package/dist/outbound-api/auditCapture.cjs +3 -3
  91. package/dist/outbound-api/auditCapture.d.cts +13 -2
  92. package/dist/outbound-api/auditCapture.d.ts +13 -2
  93. package/dist/outbound-api/auditCapture.js +2 -2
  94. package/dist/outbound-api/auditRedact.cjs +2 -2
  95. package/dist/outbound-api/auditRedact.js +1 -1
  96. package/dist/outbound-api/routeResolver.cjs +2 -2
  97. package/dist/outbound-api/routeResolver.d.cts +11 -4
  98. package/dist/outbound-api/routeResolver.d.ts +11 -4
  99. package/dist/outbound-api/routeResolver.js +1 -1
  100. package/dist/outbound-api/subscriptionRegistryPort.d.cts +5 -1
  101. package/dist/outbound-api/subscriptionRegistryPort.d.ts +5 -1
  102. package/dist/outbound-api/types.d.cts +10 -3
  103. package/dist/outbound-api/types.d.ts +10 -3
  104. package/dist/outbound-api.cjs +65 -33
  105. package/dist/outbound-api.d.cts +205 -10
  106. package/dist/outbound-api.d.ts +205 -10
  107. package/dist/outbound-api.js +64 -32
  108. package/dist/pipeline/AccountAllowanceScheduling.d.cts +22 -15
  109. package/dist/pipeline/AccountAllowanceScheduling.d.ts +22 -15
  110. package/dist/pipeline/LlmConfigProviderAuth.cjs +3 -3
  111. package/dist/pipeline/LlmConfigProviderAuth.js +2 -2
  112. package/dist/pipeline/SubscriptionAccountHealth.cjs +2 -2
  113. package/dist/pipeline/SubscriptionAccountHealth.d.cts +7 -0
  114. package/dist/pipeline/SubscriptionAccountHealth.d.ts +7 -0
  115. package/dist/pipeline/SubscriptionAccountHealth.js +1 -1
  116. package/dist/pipeline/executeProviderCall.cjs +2 -2
  117. package/dist/pipeline/executeProviderCall.d.cts +11 -6
  118. package/dist/pipeline/executeProviderCall.d.ts +11 -6
  119. package/dist/pipeline/executeProviderCall.js +1 -1
  120. package/dist/pipeline/upstreamFetch.cjs +2 -2
  121. package/dist/pipeline/upstreamFetch.d.cts +5 -0
  122. package/dist/pipeline/upstreamFetch.d.ts +5 -0
  123. package/dist/pipeline/upstreamFetch.js +1 -1
  124. package/dist/ports.d.cts +10 -3
  125. package/dist/ports.d.ts +10 -3
  126. package/dist/provider-proxy/ProviderProxy.cjs +32 -28
  127. package/dist/provider-proxy/ProviderProxy.d.cts +6 -2
  128. package/dist/provider-proxy/ProviderProxy.d.ts +6 -2
  129. package/dist/provider-proxy/ProviderProxy.js +31 -27
  130. package/dist/provider-proxy/identity/codexCliHeaders.cjs +4 -2
  131. package/dist/provider-proxy/identity/codexCliHeaders.d.cts +26 -6
  132. package/dist/provider-proxy/identity/codexCliHeaders.d.ts +26 -6
  133. package/dist/provider-proxy/identity/codexCliHeaders.js +5 -3
  134. package/dist/provider-proxy/ingress/providerProxyShared.cjs +36 -28
  135. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +41 -9
  136. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +41 -9
  137. package/dist/provider-proxy/ingress/providerProxyShared.js +35 -27
  138. package/dist/provider-proxy/types.d.cts +17 -483
  139. package/dist/provider-proxy/types.d.ts +17 -483
  140. package/dist/provider-proxy.cjs +46 -28
  141. package/dist/provider-proxy.d.cts +34 -8
  142. package/dist/provider-proxy.d.ts +34 -8
  143. package/dist/provider-proxy.js +45 -27
  144. package/dist/proxy-UZTtjPZx.d.cts +18 -0
  145. package/dist/proxy-UZTtjPZx.d.ts +18 -0
  146. package/dist/{routeResolver-CVFE8KKe.d.cts → routeResolver-Da0yvkL1.d.cts} +4 -2
  147. package/dist/{routeResolver-C0mkkZaM.d.ts → routeResolver-STwMz_G4.d.ts} +4 -2
  148. package/dist/runtime-6QXNU526.cjs +8 -0
  149. package/dist/runtime-M5WXLD2R.js +8 -0
  150. package/dist/runtime-t8AZacFF.d.cts +233 -0
  151. package/dist/runtime-t8AZacFF.d.ts +233 -0
  152. package/dist/search/api.cjs +761 -0
  153. package/dist/search/api.d.cts +370 -0
  154. package/dist/search/api.d.ts +370 -0
  155. package/dist/search/api.js +761 -0
  156. package/dist/search/http.cjs +37 -0
  157. package/dist/search/http.d.cts +269 -0
  158. package/dist/search/http.d.ts +269 -0
  159. package/dist/search/http.js +37 -0
  160. package/dist/search.cjs +57 -0
  161. package/dist/search.d.cts +113 -0
  162. package/dist/search.d.ts +113 -0
  163. package/dist/search.js +57 -0
  164. package/dist/transformer/TransformerChainExecutor.cjs +2 -2
  165. package/dist/transformer/TransformerChainExecutor.d.cts +2 -2
  166. package/dist/transformer/TransformerChainExecutor.d.ts +2 -2
  167. package/dist/transformer/TransformerChainExecutor.js +1 -1
  168. package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.cjs +16 -0
  169. package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.d.cts +53 -0
  170. package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.d.ts +53 -0
  171. package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.js +16 -0
  172. package/dist/transformer/transformers/AnthropicTransformer.cjs +4 -3
  173. package/dist/transformer/transformers/AnthropicTransformer.js +3 -2
  174. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +4 -4
  175. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +3 -3
  176. package/dist/transformer/transformers/GeminiTransformer.cjs +4 -4
  177. package/dist/transformer/transformers/GeminiTransformer.js +3 -3
  178. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -3
  179. package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -2
  180. package/dist/transformer/transformers/OpenAITransformer.cjs +3 -3
  181. package/dist/transformer/transformers/OpenAITransformer.js +2 -2
  182. package/dist/transformer/transformers.cjs +11 -10
  183. package/dist/transformer/transformers.js +12 -11
  184. package/dist/transformer/types.d.cts +39 -4
  185. package/dist/transformer/types.d.ts +39 -4
  186. package/dist/transformer.cjs +14 -13
  187. package/dist/transformer.js +13 -12
  188. package/dist/types-BSIJdsyl.d.cts +1130 -0
  189. package/dist/types-Be-yt_6T.d.cts +196 -0
  190. package/dist/types-By9Tg6-I.d.ts +1130 -0
  191. package/dist/types-CbCZqLGg.d.cts +127 -0
  192. package/dist/types-CbCZqLGg.d.ts +127 -0
  193. package/dist/{types-C2MwkLah.d.cts → types-D-oHYusb.d.cts} +250 -21
  194. package/dist/types-Dm4_36V4.d.ts +196 -0
  195. package/dist/{types-BB8pxk_3.d.ts → types-Dvlpjn0d.d.ts} +250 -21
  196. package/dist/usage.cjs +2 -2
  197. package/dist/usage.d.cts +6 -1
  198. package/dist/usage.d.ts +6 -1
  199. package/dist/usage.js +1 -1
  200. package/package.json +71 -64
  201. package/dist/chunk-FCR77GYM.cjs +0 -33
  202. package/dist/chunk-K5NM7VAH.js +0 -33
  203. /package/dist/{chunk-XXFYLL7R.js → chunk-ECZ3ZE2C.js} +0 -0
  204. /package/dist/{chunk-3SCOLIPT.cjs → chunk-MXI2PWIC.cjs} +0 -0
@@ -0,0 +1,384 @@
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; }// src/transformer/transformers/AnthropicOpenAIToAnthropicStream.ts
2
+ var DEFAULT_ANTHROPIC_PING_HEARTBEAT_MS = 2e4;
3
+ var anthropicPingHeartbeatMs = DEFAULT_ANTHROPIC_PING_HEARTBEAT_MS;
4
+ function setAnthropicPingHeartbeatMs(ms) {
5
+ anthropicPingHeartbeatMs = typeof ms === "number" && Number.isFinite(ms) ? ms : DEFAULT_ANTHROPIC_PING_HEARTBEAT_MS;
6
+ }
7
+ function getAnthropicPingHeartbeatMs() {
8
+ return anthropicPingHeartbeatMs;
9
+ }
10
+ var stopReasonContentFilterCount = 0;
11
+ function __resetStopReasonContentFilterCountForTests() {
12
+ stopReasonContentFilterCount = exports.stopReasonContentFilterCount = 0;
13
+ }
14
+ function noteContentFilterRemap(logger) {
15
+ stopReasonContentFilterCount = exports.stopReasonContentFilterCount += 1;
16
+ console.warn(
17
+ `[AnthropicStream] upstream finish_reason=content_filter remapped to stop_reason=refusal (count ${stopReasonContentFilterCount})`
18
+ );
19
+ _optionalChain([logger, 'optionalAccess', _ => _.warn, 'optionalCall', _2 => _2("upstream finish_reason=content_filter remapped to stop_reason=refusal")]);
20
+ }
21
+ function sniffErrorType(error) {
22
+ let text;
23
+ try {
24
+ text = _nullishCoalesce(JSON.stringify(error), () => ( ""));
25
+ } catch (e2) {
26
+ text = String(error);
27
+ }
28
+ const lower = text.toLowerCase();
29
+ if (lower.includes("overload") || lower.includes("capacity") || lower.includes("server_error")) {
30
+ return "overloaded_error";
31
+ }
32
+ const e = error;
33
+ for (const raw of [_optionalChain([e, 'optionalAccess', _3 => _3.status]), _optionalChain([e, 'optionalAccess', _4 => _4.code])]) {
34
+ const n = typeof raw === "string" ? Number.parseInt(raw, 10) : raw;
35
+ if (typeof n === "number" && Number.isFinite(n) && n >= 500) return "overloaded_error";
36
+ }
37
+ return "api_error";
38
+ }
39
+ function convertOpenAIStreamToAnthropic(openaiStream, _context, logger) {
40
+ const decoder = new TextDecoder();
41
+ const encoder = new TextEncoder();
42
+ let hasStarted = false;
43
+ let hasTextContentStarted = false;
44
+ let isThinkingStarted = false;
45
+ let contentIndex = 0;
46
+ let currentContentBlockIndex = -1;
47
+ const toolCallIndexToContentBlockIndex = /* @__PURE__ */ new Map();
48
+ let reader = null;
49
+ return new ReadableStream({
50
+ start: async (controller) => {
51
+ reader = openaiStream.getReader();
52
+ let buffer = "";
53
+ const messageId = `msg_${Date.now()}`;
54
+ let model = "unknown";
55
+ let isClosed = false;
56
+ let stopReasonDelta = null;
57
+ const safeEnqueue = (data) => {
58
+ if (!isClosed) {
59
+ try {
60
+ controller.enqueue(encoder.encode(data));
61
+ } catch (_e) {
62
+ isClosed = true;
63
+ }
64
+ }
65
+ };
66
+ let pingTimer = null;
67
+ const clearPing = () => {
68
+ if (pingTimer !== null) {
69
+ clearTimeout(pingTimer);
70
+ pingTimer = null;
71
+ }
72
+ };
73
+ const armPing = () => {
74
+ clearPing();
75
+ const interval = getAnthropicPingHeartbeatMs();
76
+ if (!(interval > 0)) return;
77
+ pingTimer = setTimeout(() => {
78
+ pingTimer = null;
79
+ safeEnqueue(`event: ping
80
+ data: ${JSON.stringify({ type: "ping" })}
81
+
82
+ `);
83
+ armPing();
84
+ }, interval);
85
+ _optionalChain([pingTimer, 'access', _5 => _5.unref, 'optionalCall', _6 => _6()]);
86
+ };
87
+ const assignContentBlockIndex = () => {
88
+ return contentIndex++;
89
+ };
90
+ const safeClose = () => {
91
+ if (isClosed) return;
92
+ if (currentContentBlockIndex >= 0) {
93
+ safeEnqueue(`event: content_block_stop
94
+ data: ${JSON.stringify({
95
+ type: "content_block_stop",
96
+ index: currentContentBlockIndex
97
+ })}
98
+
99
+ `);
100
+ }
101
+ if (stopReasonDelta) {
102
+ safeEnqueue(`event: message_delta
103
+ data: ${JSON.stringify(stopReasonDelta)}
104
+
105
+ `);
106
+ } else {
107
+ safeEnqueue(`event: message_delta
108
+ data: ${JSON.stringify({
109
+ type: "message_delta",
110
+ delta: { stop_reason: "end_turn", stop_sequence: null },
111
+ usage: { input_tokens: 0, output_tokens: 0 }
112
+ })}
113
+
114
+ `);
115
+ }
116
+ safeEnqueue(`event: message_stop
117
+ data: ${JSON.stringify({ type: "message_stop" })}
118
+
119
+ `);
120
+ try {
121
+ controller.close();
122
+ } catch (_e) {
123
+ }
124
+ isClosed = true;
125
+ };
126
+ try {
127
+ armPing();
128
+ while (true) {
129
+ const { done, value } = await reader.read();
130
+ if (done) break;
131
+ buffer += decoder.decode(value, { stream: true });
132
+ const lines = buffer.split("\n");
133
+ buffer = lines.pop() || "";
134
+ for (const line of lines) {
135
+ if (isClosed) break;
136
+ if (!line.startsWith("data:")) continue;
137
+ const data = line.slice(5).trim();
138
+ if (data === "[DONE]") continue;
139
+ try {
140
+ const chunk = JSON.parse(data);
141
+ if (chunk.error) {
142
+ safeEnqueue(`event: error
143
+ data: ${JSON.stringify({
144
+ type: "error",
145
+ error: {
146
+ type: sniffErrorType(chunk.error),
147
+ message: JSON.stringify(chunk.error)
148
+ }
149
+ })}
150
+
151
+ `);
152
+ continue;
153
+ }
154
+ if (chunk.type === "response.failed" && _optionalChain([chunk, 'access', _7 => _7.response, 'optionalAccess', _8 => _8.error])) {
155
+ safeEnqueue(`event: error
156
+ data: ${JSON.stringify({
157
+ type: "error",
158
+ error: {
159
+ type: sniffErrorType(chunk.response.error),
160
+ message: JSON.stringify(chunk.response.error)
161
+ }
162
+ })}
163
+
164
+ `);
165
+ continue;
166
+ }
167
+ model = chunk.model || model;
168
+ if (!hasStarted) {
169
+ hasStarted = true;
170
+ const startUsage = chunk.usage ? {
171
+ input_tokens: (chunk.usage.prompt_tokens || 0) - (_optionalChain([chunk, 'access', _9 => _9.usage, 'access', _10 => _10.prompt_tokens_details, 'optionalAccess', _11 => _11.cached_tokens]) || 0),
172
+ output_tokens: chunk.usage.completion_tokens || 0
173
+ } : { input_tokens: 0, output_tokens: 0 };
174
+ safeEnqueue(`event: message_start
175
+ data: ${JSON.stringify({
176
+ type: "message_start",
177
+ message: {
178
+ id: messageId,
179
+ type: "message",
180
+ role: "assistant",
181
+ content: [],
182
+ model,
183
+ stop_reason: null,
184
+ stop_sequence: null,
185
+ usage: startUsage
186
+ }
187
+ })}
188
+
189
+ `);
190
+ }
191
+ const choice = _optionalChain([chunk, 'access', _12 => _12.choices, 'optionalAccess', _13 => _13[0]]);
192
+ if (!choice) continue;
193
+ if (chunk.usage) {
194
+ stopReasonDelta = {
195
+ type: "message_delta",
196
+ delta: { stop_reason: "end_turn", stop_sequence: null },
197
+ usage: {
198
+ input_tokens: (chunk.usage.prompt_tokens || 0) - (_optionalChain([chunk, 'access', _14 => _14.usage, 'access', _15 => _15.prompt_tokens_details, 'optionalAccess', _16 => _16.cached_tokens]) || 0),
199
+ output_tokens: chunk.usage.completion_tokens || 0,
200
+ cache_read_input_tokens: _optionalChain([chunk, 'access', _17 => _17.usage, 'access', _18 => _18.prompt_tokens_details, 'optionalAccess', _19 => _19.cached_tokens]) || 0
201
+ }
202
+ };
203
+ }
204
+ if (_optionalChain([choice, 'access', _20 => _20.delta, 'optionalAccess', _21 => _21.thinking])) {
205
+ if (!isThinkingStarted) {
206
+ const thinkingBlockIndex = assignContentBlockIndex();
207
+ safeEnqueue(`event: content_block_start
208
+ data: ${JSON.stringify({
209
+ type: "content_block_start",
210
+ index: thinkingBlockIndex,
211
+ content_block: { type: "thinking", thinking: "" }
212
+ })}
213
+
214
+ `);
215
+ currentContentBlockIndex = thinkingBlockIndex;
216
+ isThinkingStarted = true;
217
+ }
218
+ if (choice.delta.thinking.signature) {
219
+ safeEnqueue(`event: content_block_delta
220
+ data: ${JSON.stringify({
221
+ type: "content_block_delta",
222
+ index: currentContentBlockIndex,
223
+ delta: { type: "signature_delta", signature: choice.delta.thinking.signature }
224
+ })}
225
+
226
+ `);
227
+ safeEnqueue(`event: content_block_stop
228
+ data: ${JSON.stringify({
229
+ type: "content_block_stop",
230
+ index: currentContentBlockIndex
231
+ })}
232
+
233
+ `);
234
+ currentContentBlockIndex = -1;
235
+ } else if (choice.delta.thinking.content) {
236
+ safeEnqueue(`event: content_block_delta
237
+ data: ${JSON.stringify({
238
+ type: "content_block_delta",
239
+ index: currentContentBlockIndex,
240
+ delta: { type: "thinking_delta", thinking: choice.delta.thinking.content }
241
+ })}
242
+
243
+ `);
244
+ }
245
+ }
246
+ if (_optionalChain([choice, 'access', _22 => _22.delta, 'optionalAccess', _23 => _23.content])) {
247
+ if (!hasTextContentStarted) {
248
+ if (currentContentBlockIndex >= 0 && isThinkingStarted) {
249
+ safeEnqueue(`event: content_block_stop
250
+ data: ${JSON.stringify({
251
+ type: "content_block_stop",
252
+ index: currentContentBlockIndex
253
+ })}
254
+
255
+ `);
256
+ }
257
+ hasTextContentStarted = true;
258
+ const textBlockIndex = assignContentBlockIndex();
259
+ safeEnqueue(`event: content_block_start
260
+ data: ${JSON.stringify({
261
+ type: "content_block_start",
262
+ index: textBlockIndex,
263
+ content_block: { type: "text", text: "" }
264
+ })}
265
+
266
+ `);
267
+ currentContentBlockIndex = textBlockIndex;
268
+ }
269
+ safeEnqueue(`event: content_block_delta
270
+ data: ${JSON.stringify({
271
+ type: "content_block_delta",
272
+ index: currentContentBlockIndex,
273
+ delta: { type: "text_delta", text: choice.delta.content }
274
+ })}
275
+
276
+ `);
277
+ }
278
+ if (_optionalChain([choice, 'access', _24 => _24.delta, 'optionalAccess', _25 => _25.tool_calls])) {
279
+ for (const toolCall of choice.delta.tool_calls) {
280
+ const toolCallIndex = _nullishCoalesce(toolCall.index, () => ( 0));
281
+ if (!toolCallIndexToContentBlockIndex.has(toolCallIndex)) {
282
+ if (currentContentBlockIndex >= 0) {
283
+ safeEnqueue(`event: content_block_stop
284
+ data: ${JSON.stringify({
285
+ type: "content_block_stop",
286
+ index: currentContentBlockIndex
287
+ })}
288
+
289
+ `);
290
+ hasTextContentStarted = false;
291
+ }
292
+ const newBlockIndex = assignContentBlockIndex();
293
+ toolCallIndexToContentBlockIndex.set(toolCallIndex, newBlockIndex);
294
+ safeEnqueue(`event: content_block_start
295
+ data: ${JSON.stringify({
296
+ type: "content_block_start",
297
+ index: newBlockIndex,
298
+ content_block: {
299
+ type: "tool_use",
300
+ id: toolCall.id || `call_${Date.now()}_${toolCallIndex}`,
301
+ name: _optionalChain([toolCall, 'access', _26 => _26.function, 'optionalAccess', _27 => _27.name]) || `tool_${toolCallIndex}`,
302
+ input: {}
303
+ }
304
+ })}
305
+
306
+ `);
307
+ currentContentBlockIndex = newBlockIndex;
308
+ }
309
+ if (_optionalChain([toolCall, 'access', _28 => _28.function, 'optionalAccess', _29 => _29.arguments])) {
310
+ const blockIndex = toolCallIndexToContentBlockIndex.get(toolCallIndex);
311
+ if (blockIndex !== void 0) {
312
+ safeEnqueue(`event: content_block_delta
313
+ data: ${JSON.stringify({
314
+ type: "content_block_delta",
315
+ index: blockIndex,
316
+ delta: { type: "input_json_delta", partial_json: toolCall.function.arguments }
317
+ })}
318
+
319
+ `);
320
+ }
321
+ }
322
+ }
323
+ }
324
+ if (choice.finish_reason) {
325
+ if (choice.finish_reason === "content_filter") {
326
+ noteContentFilterRemap(logger);
327
+ }
328
+ const stopReasonMapping = {
329
+ stop: "end_turn",
330
+ length: "max_tokens",
331
+ tool_calls: "tool_use",
332
+ content_filter: "refusal",
333
+ refusal: "refusal",
334
+ pause_turn: "pause_turn"
335
+ };
336
+ stopReasonDelta = {
337
+ type: "message_delta",
338
+ delta: {
339
+ stop_reason: stopReasonMapping[choice.finish_reason] || "end_turn",
340
+ stop_sequence: null
341
+ },
342
+ usage: {
343
+ input_tokens: (_optionalChain([chunk, 'access', _30 => _30.usage, 'optionalAccess', _31 => _31.prompt_tokens]) || 0) - (_optionalChain([chunk, 'access', _32 => _32.usage, 'optionalAccess', _33 => _33.prompt_tokens_details, 'optionalAccess', _34 => _34.cached_tokens]) || 0),
344
+ output_tokens: _optionalChain([chunk, 'access', _35 => _35.usage, 'optionalAccess', _36 => _36.completion_tokens]) || 0,
345
+ cache_read_input_tokens: _optionalChain([chunk, 'access', _37 => _37.usage, 'optionalAccess', _38 => _38.prompt_tokens_details, 'optionalAccess', _39 => _39.cached_tokens]) || 0
346
+ }
347
+ };
348
+ }
349
+ } catch (e) {
350
+ _optionalChain([logger, 'optionalAccess', _40 => _40.error, 'call', _41 => _41("Error parsing stream chunk:", e)]);
351
+ }
352
+ }
353
+ armPing();
354
+ }
355
+ } catch (e) {
356
+ if (!isClosed) {
357
+ controller.error(e);
358
+ }
359
+ } finally {
360
+ clearPing();
361
+ safeClose();
362
+ reader.releaseLock();
363
+ }
364
+ },
365
+ // R6: client disconnect. Cancelling the upstream reader settles the pending
366
+ // read(), which unblocks the loop's `finally` → `clearPing` — the timer is
367
+ // cleared INDIRECTLY (pinned by the cancel-leak fake-timer test).
368
+ cancel: async () => {
369
+ try {
370
+ await _optionalChain([reader, 'optionalAccess', _42 => _42.cancel, 'call', _43 => _43()]);
371
+ } catch (_e) {
372
+ }
373
+ }
374
+ });
375
+ }
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+ exports.DEFAULT_ANTHROPIC_PING_HEARTBEAT_MS = DEFAULT_ANTHROPIC_PING_HEARTBEAT_MS; exports.setAnthropicPingHeartbeatMs = setAnthropicPingHeartbeatMs; exports.getAnthropicPingHeartbeatMs = getAnthropicPingHeartbeatMs; exports.stopReasonContentFilterCount = stopReasonContentFilterCount; exports.__resetStopReasonContentFilterCountForTests = __resetStopReasonContentFilterCountForTests; exports.convertOpenAIStreamToAnthropic = convertOpenAIStreamToAnthropic;
@@ -1,10 +1,10 @@
1
- import {
2
- redactAuditText
3
- } from "./chunk-K5NM7VAH.js";
4
1
  import {
5
2
  getAuditCaptureConfig,
6
3
  recordAudit
7
4
  } from "./chunk-WNY4WMRF.js";
5
+ import {
6
+ redactAuditText
7
+ } from "./chunk-N76KU6F5.js";
8
8
  import {
9
9
  readAuditUsage
10
10
  } from "./chunk-OZFM4X3S.js";
@@ -195,24 +195,35 @@ function resolveClientIp(req, trustForwardedFor) {
195
195
  }
196
196
  return req.socket?.remoteAddress ?? void 0;
197
197
  }
198
- function beginAuditCapture(req, res, now) {
198
+ function beginAuditCapture(req, res, now, options) {
199
199
  const config = getAuditCaptureConfig();
200
200
  if (!config) return null;
201
+ const captureBodies = config.captureBodies;
201
202
  let requestBody;
202
203
  const responseChunks = [];
203
204
  let responseBytes = 0;
204
205
  let responseTruncated = false;
206
+ let bodiesSuppressed = options?.suppressBodies === true;
205
207
  let finished = false;
206
208
  const ctx = {
207
209
  setRequestBody(raw) {
208
- if (config.captureBodies) {
210
+ if (captureBodies && !bodiesSuppressed) {
209
211
  requestBody = truncateToBytes(redactAuditText(raw), config.maxBodyBytes);
210
212
  }
213
+ },
214
+ suppressBodies() {
215
+ if (bodiesSuppressed) return;
216
+ bodiesSuppressed = true;
217
+ requestBody = void 0;
218
+ responseChunks.length = 0;
219
+ responseBytes = 0;
220
+ responseTruncated = false;
211
221
  }
212
222
  };
213
- if (config.captureBodies) {
223
+ if (captureBodies && !bodiesSuppressed) {
214
224
  installResponseCapture(res, {
215
225
  push(chunk) {
226
+ if (bodiesSuppressed) return;
216
227
  if (config.maxBodyBytes < 0) {
217
228
  responseChunks.push(chunk);
218
229
  responseBytes += chunk.length;
@@ -263,7 +274,7 @@ function beginAuditCapture(req, res, now) {
263
274
  }
264
275
  if (ctx.error) record.error = redactAuditText(ctx.error);
265
276
  if (ctx.sessionKey) record.sessionKey = ctx.sessionKey;
266
- if (config.captureBodies) {
277
+ if (captureBodies && !bodiesSuppressed) {
267
278
  if (requestBody != null && requestBody.length > 0) {
268
279
  record.requestBody = requestBody;
269
280
  }
@@ -104,6 +104,11 @@ var SubscriptionAccountHealth = (_class = class {
104
104
  const preExisting = this.records.get(key);
105
105
  const record = _nullishCoalesce(preExisting, () => ( {}));
106
106
  const status = input.status;
107
+ if (input.upstreamErrorType) {
108
+ console.info(
109
+ `[AccountHealth] upstream error type ${input.upstreamErrorType} (provider=${providerId} status=${String(status)})`
110
+ );
111
+ }
107
112
  const wasUnhealthyBefore = preExisting ? this.isUnhealthyAt(preExisting, now) : false;
108
113
  let anomalyState;
109
114
  let recovered = false;
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  extractReasoningIntent,
3
+ recordDroppedField,
3
4
  resolveReasoningPlan
4
- } from "./chunk-N2EIM2XJ.js";
5
+ } from "./chunk-ZLNHPUFA.js";
5
6
 
6
7
  // src/transformer/transformers/OpenAITransformer.ts
7
8
  var FOREIGN_MESSAGE_KEYS = ["cache_control", "thinking"];
8
- var FOREIGN_BODY_KEYS = ["meta", "reasoning", "thinking"];
9
+ var FOREIGN_BODY_KEYS = ["meta", "reasoning", "thinking", "top_k", "metadata_user_id", "_transformWarnings"];
9
10
  function normalizeContent(content) {
10
11
  if (!Array.isArray(content)) return content;
11
12
  const cleaned = content.map((block) => {
@@ -36,6 +37,12 @@ var OpenAITransformer = class {
36
37
  if (FOREIGN_BODY_KEYS.includes(key)) continue;
37
38
  out[key] = source[key];
38
39
  }
40
+ if (request.metadata_user_id !== void 0) {
41
+ out.user = request.metadata_user_id;
42
+ }
43
+ if (request.top_k !== void 0) {
44
+ recordDroppedField(request, "top_k", "openai-chat");
45
+ }
39
46
  if (Array.isArray(request.messages)) {
40
47
  out.messages = request.messages.map((message) => {
41
48
  const src = message;