@omnicross/core 0.1.6 → 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 (131) hide show
  1. package/dist/ApiConverter.cjs +2 -2
  2. package/dist/ApiConverter.js +1 -1
  3. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +4 -3
  4. package/dist/auth/GeminiCodeAssistProjectResolver.js +3 -2
  5. package/dist/{chunk-3Z5BQZFM.cjs → chunk-235MXAGX.cjs} +3 -1
  6. package/dist/{chunk-DLXZEZWO.cjs → chunk-2E42SAW3.cjs} +42 -4
  7. package/dist/{chunk-7AK7B36B.cjs → chunk-2Z4XM3H5.cjs} +6 -6
  8. package/dist/{chunk-OEWZUX4G.js → chunk-32O35CIF.js} +9 -20
  9. package/dist/chunk-3SCOLIPT.cjs +63 -0
  10. package/dist/{chunk-SYQF7OIR.js → chunk-3WD4HTR2.js} +2 -0
  11. package/dist/{chunk-SQYVORNP.cjs → chunk-4BB343BI.cjs} +527 -267
  12. package/dist/{chunk-AT7B7SOZ.js → chunk-5NJLQ6T6.js} +21 -10
  13. package/dist/chunk-5RSZYQJH.cjs +62 -0
  14. package/dist/{chunk-IFXJ2BG7.js → chunk-7C7DET6S.js} +51 -6
  15. package/dist/{chunk-UDCC7EMR.js → chunk-E3COOKUP.js} +307 -47
  16. package/dist/chunk-FU7EAR73.js +62 -0
  17. package/dist/{chunk-UX7VWA46.js → chunk-FXR6N3SR.js} +39 -1
  18. package/dist/{chunk-WYTEQ4Q5.cjs → chunk-GDIXXKF2.cjs} +21 -10
  19. package/dist/{chunk-WB6PH56J.js → chunk-GFIZ6LQI.js} +12 -8
  20. package/dist/chunk-GL6XM527.js +61 -0
  21. package/dist/{chunk-EJLH6NFT.cjs → chunk-J3QQ6JS5.cjs} +12 -8
  22. package/dist/{chunk-VRFBB5DB.js → chunk-MYYR3HZL.js} +4 -4
  23. package/dist/{chunk-YJVHCHQX.js → chunk-N7OOJI5V.js} +46 -2
  24. package/dist/chunk-NKVZ6Z3Y.cjs +61 -0
  25. package/dist/{chunk-SNYBEXLB.cjs → chunk-OJGQKHN5.cjs} +3 -1
  26. package/dist/chunk-OTZC4TNH.cjs +79 -0
  27. package/dist/{chunk-6VUQPOV3.cjs → chunk-OVQBNVSV.cjs} +10 -21
  28. package/dist/{chunk-4VLRHHFE.cjs → chunk-OXHNSZ53.cjs} +9 -11
  29. package/dist/{chunk-6CL5HTPQ.js → chunk-PEGTIPB3.js} +8 -10
  30. package/dist/chunk-PO3XB56Z.js +79 -0
  31. package/dist/{chunk-SIZQQD6T.js → chunk-RJ5ZGNI3.js} +42 -5
  32. package/dist/{chunk-KCVJWJST.cjs → chunk-RJUONLUQ.cjs} +47 -10
  33. package/dist/{chunk-BPKCU575.js → chunk-SOO562NM.js} +3 -1
  34. package/dist/{chunk-UNWKG6EI.cjs → chunk-XPIOJQS2.cjs} +51 -6
  35. package/dist/chunk-XXFYLL7R.js +63 -0
  36. package/dist/{chunk-YK57NMIF.cjs → chunk-YWL7YZWS.cjs} +47 -3
  37. package/dist/completion/CompletionService.cjs +23 -19
  38. package/dist/completion/CompletionService.d.cts +1 -0
  39. package/dist/completion/CompletionService.d.ts +1 -0
  40. package/dist/completion/CompletionService.js +22 -18
  41. package/dist/completion.cjs +23 -19
  42. package/dist/completion.d.cts +1 -0
  43. package/dist/completion.d.ts +1 -0
  44. package/dist/completion.js +22 -18
  45. package/dist/index.cjs +26 -22
  46. package/dist/index.d.cts +2 -2
  47. package/dist/index.d.ts +2 -2
  48. package/dist/index.js +26 -22
  49. package/dist/outbound-api/auditCapture.cjs +2 -2
  50. package/dist/outbound-api/auditCapture.d.cts +3 -4
  51. package/dist/outbound-api/auditCapture.d.ts +3 -4
  52. package/dist/outbound-api/auditCapture.js +1 -1
  53. package/dist/outbound-api/routeResolver.d.cts +3 -2
  54. package/dist/outbound-api/routeResolver.d.ts +3 -2
  55. package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
  56. package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
  57. package/dist/outbound-api/types.d.cts +2 -1
  58. package/dist/outbound-api/types.d.ts +2 -1
  59. package/dist/outbound-api.cjs +23 -19
  60. package/dist/outbound-api.d.cts +7 -5
  61. package/dist/outbound-api.d.ts +7 -5
  62. package/dist/outbound-api.js +22 -18
  63. package/dist/pipeline/AccountAllowanceScheduling.d.cts +2 -1
  64. package/dist/pipeline/AccountAllowanceScheduling.d.ts +2 -1
  65. package/dist/pipeline/AccountRouteActivity.cjs +10 -0
  66. package/dist/pipeline/AccountRouteActivity.d.cts +61 -0
  67. package/dist/pipeline/AccountRouteActivity.d.ts +61 -0
  68. package/dist/pipeline/AccountRouteActivity.js +10 -0
  69. package/dist/pipeline/ServerOverloadCounter.cjs +16 -0
  70. package/dist/pipeline/ServerOverloadCounter.d.cts +77 -0
  71. package/dist/pipeline/ServerOverloadCounter.d.ts +77 -0
  72. package/dist/pipeline/ServerOverloadCounter.js +16 -0
  73. package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
  74. package/dist/pipeline/SubscriptionAccountHealth.d.cts +32 -3
  75. package/dist/pipeline/SubscriptionAccountHealth.d.ts +32 -3
  76. package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
  77. package/dist/pipeline/upstreamFetch.cjs +4 -3
  78. package/dist/pipeline/upstreamFetch.d.cts +35 -6
  79. package/dist/pipeline/upstreamFetch.d.ts +35 -6
  80. package/dist/pipeline/upstreamFetch.js +3 -2
  81. package/dist/pipeline/upstreamTrace.cjs +4 -2
  82. package/dist/pipeline/upstreamTrace.d.cts +22 -8
  83. package/dist/pipeline/upstreamTrace.d.ts +22 -8
  84. package/dist/pipeline/upstreamTrace.js +3 -1
  85. package/dist/ports.d.cts +1 -1
  86. package/dist/ports.d.ts +1 -1
  87. package/dist/provider-proxy/ProviderProxy.cjs +23 -19
  88. package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
  89. package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
  90. package/dist/provider-proxy/ProviderProxy.js +22 -18
  91. package/dist/provider-proxy/identity/codexCliHeaders.cjs +10 -0
  92. package/dist/provider-proxy/identity/codexCliHeaders.d.cts +45 -0
  93. package/dist/provider-proxy/identity/codexCliHeaders.d.ts +45 -0
  94. package/dist/provider-proxy/identity/codexCliHeaders.js +10 -0
  95. package/dist/provider-proxy/ingress/providerProxyShared.cjs +23 -19
  96. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +11 -1
  97. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +11 -1
  98. package/dist/provider-proxy/ingress/providerProxyShared.js +22 -18
  99. package/dist/provider-proxy/matchText.cjs +2 -2
  100. package/dist/provider-proxy/matchText.d.cts +1 -3
  101. package/dist/provider-proxy/matchText.d.ts +1 -3
  102. package/dist/provider-proxy/matchText.js +1 -1
  103. package/dist/provider-proxy/types.d.cts +5 -0
  104. package/dist/provider-proxy/types.d.ts +5 -0
  105. package/dist/provider-proxy.cjs +23 -19
  106. package/dist/provider-proxy.d.cts +1 -0
  107. package/dist/provider-proxy.d.ts +1 -0
  108. package/dist/provider-proxy.js +22 -18
  109. package/dist/{routeResolver-CHTv_Bs5.d.ts → routeResolver-BxOfunbm.d.ts} +1 -1
  110. package/dist/{routeResolver-kepxnfcC.d.cts → routeResolver-D5OzD0iM.d.cts} +1 -1
  111. package/dist/transformer/transformers/AnthropicTransformer.cjs +3 -2
  112. package/dist/transformer/transformers/AnthropicTransformer.js +2 -1
  113. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -2
  114. package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -1
  115. package/dist/transformer/transformers.cjs +7 -6
  116. package/dist/transformer/transformers.js +6 -5
  117. package/dist/transformer.cjs +9 -8
  118. package/dist/transformer.js +8 -7
  119. package/dist/{types-hsoKrVQS.d.ts → types-CqZD77rS.d.ts} +39 -0
  120. package/dist/{types-H3wGZSOo.d.cts → types-gjJ5lJ5n.d.cts} +39 -0
  121. package/dist/usage/pricing-engine.cjs +2 -2
  122. package/dist/usage/pricing-engine.d.cts +20 -0
  123. package/dist/usage/pricing-engine.d.ts +20 -0
  124. package/dist/usage/pricing-engine.js +1 -1
  125. package/dist/usage/usage-recorder.cjs +2 -2
  126. package/dist/usage/usage-recorder.d.cts +5 -1
  127. package/dist/usage/usage-recorder.d.ts +5 -1
  128. package/dist/usage/usage-recorder.js +1 -1
  129. package/dist/usage.cjs +3 -3
  130. package/dist/usage.js +2 -2
  131. package/package.json +1 -1
@@ -81,6 +81,20 @@ function flattenToolResultContent(content) {
81
81
  }
82
82
 
83
83
  // src/api-converter/anthropic-to-openai.ts
84
+ function anthropicUsageToChatUsage(usage) {
85
+ const input = usage.input_tokens || 0;
86
+ const output = usage.output_tokens || 0;
87
+ const cacheRead = usage.cache_read_input_tokens || 0;
88
+ const cacheCreation = usage.cache_creation_input_tokens || 0;
89
+ const promptTokens = input + cacheRead + cacheCreation;
90
+ const out = {
91
+ prompt_tokens: promptTokens,
92
+ completion_tokens: output,
93
+ total_tokens: promptTokens + output
94
+ };
95
+ if (cacheRead > 0) out.prompt_tokens_details = { cached_tokens: cacheRead };
96
+ return out;
97
+ }
84
98
  function convertAnthropicToOpenAI(response) {
85
99
  const content = [];
86
100
  const toolCalls = [];
@@ -118,11 +132,7 @@ function convertAnthropicToOpenAI(response) {
118
132
  finish_reason: finishReason
119
133
  }
120
134
  ],
121
- usage: {
122
- prompt_tokens: response.usage.input_tokens,
123
- completion_tokens: response.usage.output_tokens,
124
- total_tokens: response.usage.input_tokens + response.usage.output_tokens
125
- }
135
+ usage: anthropicUsageToChatUsage(response.usage)
126
136
  };
127
137
  if (reasoningContent) {
128
138
  result.reasoning_content = reasoningContent;
@@ -352,11 +362,12 @@ async function* convertAnthropicStreamToOpenAI(anthropicStream) {
352
362
  delta: {},
353
363
  finish_reason: finishReason
354
364
  }],
355
- usage: event.usage ? {
356
- prompt_tokens: event.usage.input_tokens || 0,
357
- completion_tokens: event.usage.output_tokens || 0,
358
- total_tokens: (event.usage.input_tokens || 0) + (event.usage.output_tokens || 0)
359
- } : void 0
365
+ usage: event.usage ? anthropicUsageToChatUsage({
366
+ input_tokens: event.usage.input_tokens || 0,
367
+ output_tokens: event.usage.output_tokens || 0,
368
+ cache_read_input_tokens: event.usage.cache_read_input_tokens,
369
+ cache_creation_input_tokens: event.usage.cache_creation_input_tokens
370
+ }) : void 0
360
371
  })}
361
372
 
362
373
  `;
@@ -0,0 +1,62 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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/utils/usage-mapping.ts
2
+ function num(obj, key) {
3
+ const v = _optionalChain([obj, 'optionalAccess', _ => _[key]]);
4
+ return typeof v === "number" && Number.isFinite(v) ? v : 0;
5
+ }
6
+ function detailCachedTokens(obj, detailKey) {
7
+ const detail = _optionalChain([obj, 'optionalAccess', _2 => _2[detailKey]]);
8
+ return num(detail, "cached_tokens");
9
+ }
10
+ function anthropicUsageToChatUsage(usage) {
11
+ if (!usage) return void 0;
12
+ const input = num(usage, "input_tokens");
13
+ const output = num(usage, "output_tokens");
14
+ const cacheRead = num(usage, "cache_read_input_tokens");
15
+ const cacheCreation = num(usage, "cache_creation_input_tokens");
16
+ const promptTokens = input + cacheRead + cacheCreation;
17
+ const out = {
18
+ prompt_tokens: promptTokens,
19
+ completion_tokens: output,
20
+ total_tokens: promptTokens + output
21
+ };
22
+ if (cacheRead > 0) {
23
+ out.prompt_tokens_details = { cached_tokens: cacheRead };
24
+ }
25
+ return out;
26
+ }
27
+ function chatUsageToResponsesUsage(usage) {
28
+ if (!usage) return void 0;
29
+ const prompt = num(usage, "prompt_tokens");
30
+ const completion = num(usage, "completion_tokens");
31
+ const out = {
32
+ input_tokens: prompt,
33
+ output_tokens: completion,
34
+ total_tokens: num(usage, "total_tokens") || prompt + completion
35
+ };
36
+ const cacheRead = detailCachedTokens(usage, "prompt_tokens_details");
37
+ if (cacheRead > 0) {
38
+ out.input_tokens_details = { cached_tokens: cacheRead };
39
+ }
40
+ return out;
41
+ }
42
+ function responsesUsageToChatUsage(usage) {
43
+ if (!usage) return void 0;
44
+ const input = num(usage, "input_tokens");
45
+ const output = num(usage, "output_tokens");
46
+ const out = {
47
+ prompt_tokens: input,
48
+ completion_tokens: output,
49
+ total_tokens: num(usage, "total_tokens") || input + output
50
+ };
51
+ const cacheRead = detailCachedTokens(usage, "input_tokens_details");
52
+ if (cacheRead > 0) {
53
+ out.prompt_tokens_details = { cached_tokens: cacheRead };
54
+ }
55
+ return out;
56
+ }
57
+
58
+
59
+
60
+
61
+
62
+ exports.anthropicUsageToChatUsage = anthropicUsageToChatUsage; exports.chatUsageToResponsesUsage = chatUsageToResponsesUsage; exports.responsesUsageToChatUsage = responsesUsageToChatUsage;
@@ -11,6 +11,29 @@ import {
11
11
 
12
12
  // src/outbound-api/auditCapture.ts
13
13
  import { randomUUID } from "crypto";
14
+ function completeUtf8PrefixLength(buf) {
15
+ if (buf.length === 0) return 0;
16
+ let leadIndex = buf.length - 1;
17
+ while (leadIndex >= 0 && (buf[leadIndex] & 192) === 128) leadIndex -= 1;
18
+ if (leadIndex < 0) return 0;
19
+ const lead = buf[leadIndex];
20
+ let expectedLength = 1;
21
+ if ((lead & 224) === 192) expectedLength = 2;
22
+ else if ((lead & 240) === 224) expectedLength = 3;
23
+ else if ((lead & 248) === 240) expectedLength = 4;
24
+ return buf.length - leadIndex < expectedLength ? leadIndex : buf.length;
25
+ }
26
+ function truncateToBytes(text, maxBytes) {
27
+ if (maxBytes < 0) return text;
28
+ const buf = Buffer.from(text, "utf8");
29
+ if (buf.length <= maxBytes) return text;
30
+ const head = buf.subarray(0, maxBytes);
31
+ return head.subarray(0, completeUtf8PrefixLength(head)).toString("utf8");
32
+ }
33
+ function decodeCapturedBody(body, truncated) {
34
+ if (!truncated) return body.toString("utf8");
35
+ return body.subarray(0, completeUtf8PrefixLength(body)).toString("utf8");
36
+ }
14
37
  function resolveClientIp(req, trustForwardedFor) {
15
38
  if (trustForwardedFor) {
16
39
  const xff = req.headers["x-forwarded-for"];
@@ -25,18 +48,39 @@ function resolveClientIp(req, trustForwardedFor) {
25
48
  function beginAuditCapture(req, res, now) {
26
49
  const config = getAuditCaptureConfig();
27
50
  if (!config) return null;
28
- let rawRequestBody;
51
+ let requestBody;
29
52
  const responseChunks = [];
53
+ let responseBytes = 0;
54
+ let responseTruncated = false;
30
55
  let finished = false;
31
56
  const ctx = {
32
57
  setRequestBody(raw) {
33
- if (config.captureBodies) rawRequestBody = raw;
58
+ if (config.captureBodies) {
59
+ requestBody = truncateToBytes(redactAuditText(raw), config.maxBodyBytes);
60
+ }
34
61
  }
35
62
  };
36
63
  if (config.captureBodies) {
37
64
  installResponseCapture(res, {
38
65
  push(chunk) {
66
+ if (config.maxBodyBytes < 0) {
67
+ responseChunks.push(chunk);
68
+ responseBytes += chunk.length;
69
+ return;
70
+ }
71
+ const remaining = config.maxBodyBytes - responseBytes;
72
+ if (remaining <= 0) {
73
+ responseTruncated = true;
74
+ return;
75
+ }
76
+ if (chunk.length > remaining) {
77
+ responseChunks.push(chunk.subarray(0, remaining));
78
+ responseBytes += remaining;
79
+ responseTruncated = true;
80
+ return;
81
+ }
39
82
  responseChunks.push(chunk);
83
+ responseBytes += chunk.length;
40
84
  }
41
85
  });
42
86
  }
@@ -69,12 +113,13 @@ function beginAuditCapture(req, res, now) {
69
113
  }
70
114
  if (ctx.error) record.error = redactAuditText(ctx.error);
71
115
  if (config.captureBodies) {
72
- if (rawRequestBody != null && rawRequestBody.length > 0) {
73
- record.requestBody = redactAuditText(rawRequestBody);
116
+ if (requestBody != null && requestBody.length > 0) {
117
+ record.requestBody = requestBody;
74
118
  }
75
119
  if (responseChunks.length > 0) {
76
- const body = Buffer.concat(responseChunks).toString("utf8");
77
- record.responseBody = redactAuditText(body);
120
+ const captured = Buffer.concat(responseChunks, responseBytes);
121
+ const body = decodeCapturedBody(captured, responseTruncated);
122
+ record.responseBody = truncateToBytes(redactAuditText(body), config.maxBodyBytes);
78
123
  }
79
124
  }
80
125
  recordAudit(record);