@omnicross/core 0.1.3 → 0.1.4
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.
- package/LICENSE +21 -21
- package/NOTICE +57 -57
- package/README.md +15 -15
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +4 -4
- package/dist/auth/GeminiCodeAssistProjectResolver.js +3 -3
- package/dist/chunk-3QFXFCHG.js +33 -0
- package/dist/chunk-4YINUUKQ.cjs +33 -0
- package/dist/chunk-7Y47UCF2.js +142 -0
- package/dist/chunk-APYG5QD7.cjs +50 -0
- package/dist/{chunk-CWM2ZDU5.js → chunk-BPKCU575.js} +3 -10
- package/dist/{chunk-2FMI2B6V.cjs → chunk-DKPXN34V.cjs} +222 -448
- package/dist/chunk-E3UCVHLP.cjs +142 -0
- package/dist/chunk-FCR77GYM.cjs +33 -0
- package/dist/{chunk-N5QFKSDO.js → chunk-HRRYG2AX.js} +2 -1
- package/dist/{chunk-KUU2RNG6.cjs → chunk-HYN75H6G.cjs} +3 -0
- package/dist/{chunk-JO5NLTLY.js → chunk-IK3KE3AU.js} +3 -0
- package/dist/chunk-K5NM7VAH.js +33 -0
- package/dist/{chunk-Y6OM7EV7.cjs → chunk-KFI44N2R.cjs} +2 -1
- package/dist/{chunk-S6JGLF3G.cjs → chunk-OCEUVQHW.cjs} +27 -4
- package/dist/chunk-OE6TDIWW.js +22 -0
- package/dist/chunk-OZFM4X3S.js +18 -0
- package/dist/{chunk-4DECIFU7.js → chunk-QYTT6GE3.js} +62 -288
- package/dist/{chunk-FFALUUZZ.cjs → chunk-RGTR7CIO.cjs} +5 -5
- package/dist/{chunk-3QOSDDNI.cjs → chunk-SNYBEXLB.cjs} +6 -13
- package/dist/{chunk-2DCNB7DF.cjs → chunk-SU2GCLAC.cjs} +30 -10
- package/dist/{chunk-5HTVET6E.js → chunk-TIER4SUC.js} +24 -4
- package/dist/{chunk-CZHZGRU7.js → chunk-UHGVBFU3.js} +2 -0
- package/dist/chunk-UIBD2YY5.cjs +22 -0
- package/dist/{chunk-SVXC36MU.cjs → chunk-VACWOIRE.cjs} +2 -0
- package/dist/{chunk-MQNDWYPN.js → chunk-VPBAUQ2M.js} +4 -4
- package/dist/chunk-WLYIIEAF.js +50 -0
- package/dist/{chunk-BO4RFWBR.js → chunk-XK5CIRMQ.js} +24 -1
- package/dist/chunk-XSVNC2UD.cjs +18 -0
- package/dist/completion/CompletionService.cjs +22 -16
- package/dist/completion/CompletionService.js +21 -15
- package/dist/completion.cjs +24 -18
- package/dist/completion.js +23 -17
- package/dist/index.cjs +33 -24
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +42 -33
- package/dist/keyPolicy-Cp0FntZl.d.cts +90 -0
- package/dist/keyPolicy-Cp0FntZl.d.ts +90 -0
- package/dist/outbound-api/auditCapture.cjs +9 -0
- package/dist/outbound-api/auditCapture.d.cts +52 -0
- package/dist/outbound-api/auditCapture.d.ts +52 -0
- package/dist/outbound-api/auditCapture.js +9 -0
- package/dist/outbound-api/auditRedact.cjs +8 -0
- package/dist/outbound-api/auditRedact.d.cts +30 -0
- package/dist/outbound-api/auditRedact.d.ts +30 -0
- package/dist/outbound-api/auditRedact.js +8 -0
- package/dist/outbound-api/billingCapture.cjs +8 -0
- package/dist/outbound-api/billingCapture.d.cts +61 -0
- package/dist/outbound-api/billingCapture.d.ts +61 -0
- package/dist/outbound-api/billingCapture.js +8 -0
- package/dist/outbound-api/quotaWarn.cjs +12 -0
- package/dist/outbound-api/quotaWarn.d.cts +43 -0
- package/dist/outbound-api/quotaWarn.d.ts +43 -0
- package/dist/outbound-api/quotaWarn.js +12 -0
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.d.cts +3 -2
- package/dist/outbound-api/routeResolver.d.ts +3 -2
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/types.d.cts +2 -1
- package/dist/outbound-api/types.d.ts +2 -1
- package/dist/outbound-api.cjs +29 -20
- package/dist/outbound-api.d.cts +9 -140
- package/dist/outbound-api.d.ts +9 -140
- package/dist/outbound-api.js +28 -19
- package/dist/pipeline/AuthSource.d.cts +6 -0
- package/dist/pipeline/AuthSource.d.ts +6 -0
- package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
- package/dist/pipeline/SubscriptionAuthSource.js +1 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +6 -0
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +6 -0
- package/dist/pipeline/auditUsageStash.cjs +10 -0
- package/dist/pipeline/auditUsageStash.d.cts +37 -0
- package/dist/pipeline/auditUsageStash.d.ts +37 -0
- package/dist/pipeline/auditUsageStash.js +10 -0
- package/dist/pipeline/executeProviderCall.cjs +2 -2
- package/dist/pipeline/executeProviderCall.js +1 -1
- package/dist/pipeline/upstreamFetch.cjs +14 -0
- package/dist/pipeline/upstreamFetch.d.cts +83 -0
- package/dist/pipeline/upstreamFetch.d.ts +83 -0
- package/dist/pipeline/upstreamFetch.js +14 -0
- package/dist/pipeline/webhookEmit.cjs +10 -0
- package/dist/pipeline/webhookEmit.d.cts +36 -0
- package/dist/pipeline/webhookEmit.d.ts +36 -0
- package/dist/pipeline/webhookEmit.js +10 -0
- package/dist/ports.d.cts +2 -1
- package/dist/ports.d.ts +2 -1
- package/dist/provider-proxy/ProviderProxy.cjs +22 -16
- package/dist/provider-proxy/ProviderProxy.js +21 -15
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +22 -16
- package/dist/provider-proxy/ingress/providerProxyShared.js +21 -15
- package/dist/provider-proxy/types.d.cts +7 -0
- package/dist/provider-proxy/types.d.ts +7 -0
- package/dist/provider-proxy.cjs +22 -16
- package/dist/provider-proxy.js +21 -15
- package/dist/{routeResolver-B1NglTfe.d.ts → routeResolver-C4T7yClx.d.ts} +1 -1
- package/dist/{routeResolver-CbG5uBgm.d.cts → routeResolver-CB3tvJKy.d.cts} +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
- package/dist/transformer/transformers.cjs +6 -6
- package/dist/transformer/transformers.js +5 -5
- package/dist/transformer.cjs +7 -7
- package/dist/transformer.js +6 -6
- package/dist/{types-aBFFXoBz.d.cts → types-B8Arpxn0.d.cts} +14 -90
- package/dist/{types-6OUY_xfA.d.ts → types-lgPYQuZS.d.ts} +14 -90
- package/dist/usage/usage-recorder.cjs +3 -2
- package/dist/usage/usage-recorder.js +2 -1
- package/dist/usage.cjs +3 -2
- package/dist/usage.js +2 -1
- package/package.json +64 -64
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Sayo
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sayo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
@omnicross/core — THIRD-PARTY NOTICES
|
|
2
|
-
======================================
|
|
3
|
-
|
|
4
|
-
This package contains code adapted from, and depends on, the following
|
|
5
|
-
third-party works. Their respective licenses apply to those portions.
|
|
6
|
-
|
|
7
|
-
--------------------------------------------------------------------------------
|
|
8
|
-
1. musistudio/llms (MIT License)
|
|
9
|
-
--------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
The transformer subsystem (`src/transformer/`) — the unified-IR request/response
|
|
12
|
-
transformer chain (`TransformerService`, `TransformerChainExecutor`, and the
|
|
13
|
-
built-in transformers) — is adapted from the `musistudio/llms` project, the
|
|
14
|
-
upstream of the transformer intermediate representation.
|
|
15
|
-
|
|
16
|
-
Copyright (c) 2025 musistudio
|
|
17
|
-
https://github.com/musistudio/llms
|
|
18
|
-
|
|
19
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
-
in the Software without restriction, including without limitation the rights
|
|
22
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
-
furnished to do so, subject to the following conditions:
|
|
25
|
-
|
|
26
|
-
The above copyright notice and this permission notice shall be included in
|
|
27
|
-
all copies or substantial portions of the Software.
|
|
28
|
-
|
|
29
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
-
SOFTWARE.
|
|
36
|
-
|
|
37
|
-
--------------------------------------------------------------------------------
|
|
38
|
-
2. @mozilla/readability (Apache License 2.0)
|
|
39
|
-
--------------------------------------------------------------------------------
|
|
40
|
-
|
|
41
|
-
The built-in web-fetch tool (`src/completion/builtin-web-fetch.ts`) uses
|
|
42
|
-
`@mozilla/readability` to extract readable article content from fetched HTML.
|
|
43
|
-
|
|
44
|
-
Copyright Mozilla Foundation and contributors
|
|
45
|
-
https://github.com/mozilla/readability
|
|
46
|
-
|
|
47
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
48
|
-
use this file except in compliance with the License. You may obtain a copy of
|
|
49
|
-
the License at
|
|
50
|
-
|
|
51
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
52
|
-
|
|
53
|
-
Unless required by applicable law or agreed to in writing, software
|
|
54
|
-
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
55
|
-
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
56
|
-
License for the specific language governing permissions and limitations under
|
|
57
|
-
the License.
|
|
1
|
+
@omnicross/core — THIRD-PARTY NOTICES
|
|
2
|
+
======================================
|
|
3
|
+
|
|
4
|
+
This package contains code adapted from, and depends on, the following
|
|
5
|
+
third-party works. Their respective licenses apply to those portions.
|
|
6
|
+
|
|
7
|
+
--------------------------------------------------------------------------------
|
|
8
|
+
1. musistudio/llms (MIT License)
|
|
9
|
+
--------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
The transformer subsystem (`src/transformer/`) — the unified-IR request/response
|
|
12
|
+
transformer chain (`TransformerService`, `TransformerChainExecutor`, and the
|
|
13
|
+
built-in transformers) — is adapted from the `musistudio/llms` project, the
|
|
14
|
+
upstream of the transformer intermediate representation.
|
|
15
|
+
|
|
16
|
+
Copyright (c) 2025 musistudio
|
|
17
|
+
https://github.com/musistudio/llms
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
in the Software without restriction, including without limitation the rights
|
|
22
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
furnished to do so, subject to the following conditions:
|
|
25
|
+
|
|
26
|
+
The above copyright notice and this permission notice shall be included in
|
|
27
|
+
all copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
SOFTWARE.
|
|
36
|
+
|
|
37
|
+
--------------------------------------------------------------------------------
|
|
38
|
+
2. @mozilla/readability (Apache License 2.0)
|
|
39
|
+
--------------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
The built-in web-fetch tool (`src/completion/builtin-web-fetch.ts`) uses
|
|
42
|
+
`@mozilla/readability` to extract readable article content from fetched HTML.
|
|
43
|
+
|
|
44
|
+
Copyright Mozilla Foundation and contributors
|
|
45
|
+
https://github.com/mozilla/readability
|
|
46
|
+
|
|
47
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
48
|
+
use this file except in compliance with the License. You may obtain a copy of
|
|
49
|
+
the License at
|
|
50
|
+
|
|
51
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
52
|
+
|
|
53
|
+
Unless required by applicable law or agreed to in writing, software
|
|
54
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
55
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
56
|
+
License for the specific language governing permissions and limitations under
|
|
57
|
+
the License.
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# @omnicross/core
|
|
2
|
-
|
|
3
|
-
The omnicross LLM serving core — provider dispatch, the completion pipeline, the transformer chain, the outbound API server, and the resident provider proxy. Embed it in any Node project, or run it via [`@omnicross/daemon`](https://www.npmjs.com/package/@omnicross/daemon).
|
|
4
|
-
|
|
5
|
-
Part of the [omnicross](https://github.com/Dumoedss/omnicross) monorepo — see the root README for the full overview.
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @omnicross/core @omnicross/contracts
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## License
|
|
12
|
-
|
|
13
|
-
[MIT](LICENSE)
|
|
14
|
-
|
|
15
|
-
This package adapts third-party work under its own license — see the `NOTICE` file.
|
|
1
|
+
# @omnicross/core
|
|
2
|
+
|
|
3
|
+
The omnicross LLM serving core — provider dispatch, the completion pipeline, the transformer chain, the outbound API server, and the resident provider proxy. Embed it in any Node project, or run it via [`@omnicross/daemon`](https://www.npmjs.com/package/@omnicross/daemon).
|
|
4
|
+
|
|
5
|
+
Part of the [omnicross](https://github.com/Dumoedss/omnicross) monorepo — see the root README for the full overview.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @omnicross/core @omnicross/contracts
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## License
|
|
12
|
+
|
|
13
|
+
[MIT](LICENSE)
|
|
14
|
+
|
|
15
|
+
This package adapts third-party work under its own license — see the `NOTICE` file.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
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
2
|
|
|
3
|
-
var _chunkS6JGLF3Gcjs = require('../chunk-S6JGLF3G.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
3
|
|
|
7
4
|
var _chunkRSJ3TWJQcjs = require('../chunk-RSJ3TWJQ.cjs');
|
|
8
5
|
require('../chunk-YGXJGRFI.cjs');
|
|
9
6
|
|
|
7
|
+
|
|
8
|
+
var _chunkOCEUVQHWcjs = require('../chunk-OCEUVQHW.cjs');
|
|
9
|
+
|
|
10
10
|
// src/auth/GeminiCodeAssistProjectResolver.ts
|
|
11
11
|
var FREE_TIER_ID = "free-tier";
|
|
12
12
|
var LEGACY_TIER_ID = "legacy-tier";
|
|
@@ -25,7 +25,7 @@ var GeminiCodeAssistHandshakeError = class extends Error {
|
|
|
25
25
|
var GeminiCodeAssistProjectResolver = (_class = class {
|
|
26
26
|
// upstream-proxy: the Code Assist handshake is upstream egress → honor the
|
|
27
27
|
// gemini proxy by default (still injectable for tests).
|
|
28
|
-
constructor(fetchImpl = (url, init) =>
|
|
28
|
+
constructor(fetchImpl = (url, init) => _chunkOCEUVQHWcjs.fetchUpstream.call(void 0, url, init, { providerId: "gemini" })) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
29
29
|
this.fetchImpl = fetchImpl;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fetchUpstream
|
|
3
|
-
} from "../chunk-BO4RFWBR.js";
|
|
4
1
|
import {
|
|
5
2
|
resolveCodeAssistApiVersion,
|
|
6
3
|
resolveCodeAssistEndpoint
|
|
7
4
|
} from "../chunk-Z7Y2NPHY.js";
|
|
8
5
|
import "../chunk-S4WBV25P.js";
|
|
6
|
+
import {
|
|
7
|
+
fetchUpstream
|
|
8
|
+
} from "../chunk-XK5CIRMQ.js";
|
|
9
9
|
|
|
10
10
|
// src/auth/GeminiCodeAssistProjectResolver.ts
|
|
11
11
|
var FREE_TIER_ID = "free-tier";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/outbound-api/quotaWarn.ts
|
|
2
|
+
var WEBHOOK_QUOTA_WARN_RATIO = 0.8;
|
|
3
|
+
function computeQuotaWarnings(limits, spend, ratio = WEBHOOK_QUOTA_WARN_RATIO) {
|
|
4
|
+
const out = [];
|
|
5
|
+
const consider = (scope, limit, spent, windowStart) => {
|
|
6
|
+
if (limit == null || limit <= 0) return;
|
|
7
|
+
if (spent >= limit) return;
|
|
8
|
+
if (spent >= ratio * limit) out.push({ scope, limitUsd: limit, spentUsd: spent, windowStart });
|
|
9
|
+
};
|
|
10
|
+
consider("daily", limits.dailyUsd, spend.dailyUsd, spend.dailyWindowStart);
|
|
11
|
+
consider("weekly", limits.weeklyUsd, spend.weeklyUsd, spend.weeklyWindowStart);
|
|
12
|
+
consider("total", limits.totalUsd, spend.totalUsd, 0);
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
var WARN_GUARD_MAX = 1e4;
|
|
16
|
+
var warned = /* @__PURE__ */ new Set();
|
|
17
|
+
function markQuotaWarnedOnce(keyId, scope, windowStart) {
|
|
18
|
+
const key = `${keyId}\0${scope}\0${windowStart}`;
|
|
19
|
+
if (warned.has(key)) return false;
|
|
20
|
+
if (warned.size >= WARN_GUARD_MAX) warned.clear();
|
|
21
|
+
warned.add(key);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function __resetQuotaWarnGuardForTests() {
|
|
25
|
+
warned.clear();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
WEBHOOK_QUOTA_WARN_RATIO,
|
|
30
|
+
computeQuotaWarnings,
|
|
31
|
+
markQuotaWarnedOnce,
|
|
32
|
+
__resetQuotaWarnGuardForTests
|
|
33
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/outbound-api/quotaWarn.ts
|
|
2
|
+
var WEBHOOK_QUOTA_WARN_RATIO = 0.8;
|
|
3
|
+
function computeQuotaWarnings(limits, spend, ratio = WEBHOOK_QUOTA_WARN_RATIO) {
|
|
4
|
+
const out = [];
|
|
5
|
+
const consider = (scope, limit, spent, windowStart) => {
|
|
6
|
+
if (limit == null || limit <= 0) return;
|
|
7
|
+
if (spent >= limit) return;
|
|
8
|
+
if (spent >= ratio * limit) out.push({ scope, limitUsd: limit, spentUsd: spent, windowStart });
|
|
9
|
+
};
|
|
10
|
+
consider("daily", limits.dailyUsd, spend.dailyUsd, spend.dailyWindowStart);
|
|
11
|
+
consider("weekly", limits.weeklyUsd, spend.weeklyUsd, spend.weeklyWindowStart);
|
|
12
|
+
consider("total", limits.totalUsd, spend.totalUsd, 0);
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
var WARN_GUARD_MAX = 1e4;
|
|
16
|
+
var warned = /* @__PURE__ */ new Set();
|
|
17
|
+
function markQuotaWarnedOnce(keyId, scope, windowStart) {
|
|
18
|
+
const key = `${keyId}\0${scope}\0${windowStart}`;
|
|
19
|
+
if (warned.has(key)) return false;
|
|
20
|
+
if (warned.size >= WARN_GUARD_MAX) warned.clear();
|
|
21
|
+
warned.add(key);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function __resetQuotaWarnGuardForTests() {
|
|
25
|
+
warned.clear();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
exports.WEBHOOK_QUOTA_WARN_RATIO = WEBHOOK_QUOTA_WARN_RATIO; exports.computeQuotaWarnings = computeQuotaWarnings; exports.markQuotaWarnedOnce = markQuotaWarnedOnce; exports.__resetQuotaWarnGuardForTests = __resetQuotaWarnGuardForTests;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
redactAuditText
|
|
3
|
+
} from "./chunk-K5NM7VAH.js";
|
|
4
|
+
import {
|
|
5
|
+
getAuditCaptureConfig,
|
|
6
|
+
recordAudit
|
|
7
|
+
} from "./chunk-WNY4WMRF.js";
|
|
8
|
+
import {
|
|
9
|
+
readAuditUsage
|
|
10
|
+
} from "./chunk-OZFM4X3S.js";
|
|
11
|
+
|
|
12
|
+
// src/outbound-api/auditCapture.ts
|
|
13
|
+
import { randomUUID } from "crypto";
|
|
14
|
+
function isStreamingContentType(res) {
|
|
15
|
+
const ct = res.getHeader("content-type");
|
|
16
|
+
const value = Array.isArray(ct) ? ct.join(";") : String(ct ?? "");
|
|
17
|
+
return value.toLowerCase().includes("text/event-stream");
|
|
18
|
+
}
|
|
19
|
+
function resolveClientIp(req, trustForwardedFor) {
|
|
20
|
+
if (trustForwardedFor) {
|
|
21
|
+
const xff = req.headers["x-forwarded-for"];
|
|
22
|
+
const raw = Array.isArray(xff) ? xff[0] : xff;
|
|
23
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
24
|
+
const first = raw.split(",")[0]?.trim();
|
|
25
|
+
if (first) return first;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return req.socket?.remoteAddress ?? void 0;
|
|
29
|
+
}
|
|
30
|
+
function truncateToBytes(text, maxBytes) {
|
|
31
|
+
const buf = Buffer.from(text, "utf8");
|
|
32
|
+
if (buf.length <= maxBytes) return text;
|
|
33
|
+
return buf.subarray(0, maxBytes).toString("utf8");
|
|
34
|
+
}
|
|
35
|
+
function beginAuditCapture(req, res, now) {
|
|
36
|
+
const config = getAuditCaptureConfig();
|
|
37
|
+
if (!config) return null;
|
|
38
|
+
let rawRequestBody;
|
|
39
|
+
const responseChunks = [];
|
|
40
|
+
let responseBytes = 0;
|
|
41
|
+
let streamDetected = false;
|
|
42
|
+
let finished = false;
|
|
43
|
+
const ctx = {
|
|
44
|
+
setRequestBody(raw) {
|
|
45
|
+
if (config.captureBodies) rawRequestBody = raw;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (config.captureBodies) {
|
|
49
|
+
installResponseCapture(res, config.maxBodyBytes, {
|
|
50
|
+
push(chunk) {
|
|
51
|
+
responseBytes += chunk.length;
|
|
52
|
+
responseChunks.push(chunk);
|
|
53
|
+
},
|
|
54
|
+
get bytes() {
|
|
55
|
+
return responseBytes;
|
|
56
|
+
},
|
|
57
|
+
markStream() {
|
|
58
|
+
streamDetected = true;
|
|
59
|
+
},
|
|
60
|
+
get isStream() {
|
|
61
|
+
return streamDetected;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const finalize = () => {
|
|
66
|
+
if (finished) return;
|
|
67
|
+
finished = true;
|
|
68
|
+
try {
|
|
69
|
+
const record = {
|
|
70
|
+
id: randomUUID(),
|
|
71
|
+
ts: now,
|
|
72
|
+
method: req.method ?? "",
|
|
73
|
+
path: (req.url ?? "").split("?")[0] ?? "",
|
|
74
|
+
status: res.statusCode,
|
|
75
|
+
latencyMs: Math.max(0, Date.now() - now)
|
|
76
|
+
};
|
|
77
|
+
if (ctx.keyId != null) record.keyId = ctx.keyId;
|
|
78
|
+
const ip = resolveClientIp(req, config.trustForwardedFor);
|
|
79
|
+
if (ip) record.ip = ip;
|
|
80
|
+
const ua = req.headers["user-agent"];
|
|
81
|
+
if (typeof ua === "string" && ua) record.ua = ua;
|
|
82
|
+
if (ctx.model) record.model = ctx.model;
|
|
83
|
+
if (ctx.provider) record.provider = ctx.provider;
|
|
84
|
+
const usage = readAuditUsage(res);
|
|
85
|
+
if (usage) {
|
|
86
|
+
if (typeof usage.inputTokens === "number") record.inputTokens = usage.inputTokens;
|
|
87
|
+
if (typeof usage.outputTokens === "number") record.outputTokens = usage.outputTokens;
|
|
88
|
+
if (typeof usage.costUsd === "number") record.costUsd = usage.costUsd;
|
|
89
|
+
if (!record.model && usage.model) record.model = usage.model;
|
|
90
|
+
if (!record.provider && usage.provider) record.provider = usage.provider;
|
|
91
|
+
}
|
|
92
|
+
if (ctx.error) record.error = redactAuditText(ctx.error);
|
|
93
|
+
if (config.captureBodies) {
|
|
94
|
+
if (rawRequestBody != null && rawRequestBody.length > 0) {
|
|
95
|
+
record.requestBody = redactAuditText(truncateToBytes(rawRequestBody, config.maxBodyBytes));
|
|
96
|
+
}
|
|
97
|
+
if (!streamDetected && responseChunks.length > 0) {
|
|
98
|
+
const body = Buffer.concat(responseChunks).toString("utf8");
|
|
99
|
+
record.responseBody = redactAuditText(body);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
recordAudit(record);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
res.once("close", finalize);
|
|
107
|
+
return ctx;
|
|
108
|
+
}
|
|
109
|
+
function installResponseCapture(res, maxBodyBytes, sink) {
|
|
110
|
+
let contentTypeChecked = false;
|
|
111
|
+
const capture = (chunk) => {
|
|
112
|
+
if (sink.isStream) return;
|
|
113
|
+
if (!contentTypeChecked) {
|
|
114
|
+
contentTypeChecked = true;
|
|
115
|
+
if (isStreamingContentType(res)) {
|
|
116
|
+
sink.markStream();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (sink.bytes >= maxBodyBytes) return;
|
|
121
|
+
let buf = null;
|
|
122
|
+
if (Buffer.isBuffer(chunk)) buf = chunk;
|
|
123
|
+
else if (typeof chunk === "string") buf = Buffer.from(chunk, "utf8");
|
|
124
|
+
if (!buf || buf.length === 0) return;
|
|
125
|
+
const remaining = maxBodyBytes - sink.bytes;
|
|
126
|
+
sink.push(buf.length > remaining ? buf.subarray(0, remaining) : buf);
|
|
127
|
+
};
|
|
128
|
+
const originalWrite = res.write.bind(res);
|
|
129
|
+
const originalEnd = res.end.bind(res);
|
|
130
|
+
res.write = ((chunk, ...args) => {
|
|
131
|
+
if (chunk != null) capture(chunk);
|
|
132
|
+
return originalWrite(chunk, ...args);
|
|
133
|
+
});
|
|
134
|
+
res.end = ((chunk, ...args) => {
|
|
135
|
+
if (chunk != null && typeof chunk !== "function") capture(chunk);
|
|
136
|
+
return originalEnd(chunk, ...args);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
beginAuditCapture
|
|
142
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkL74VDN4Acjs = require('./chunk-L74VDN4A.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkXSVNC2UDcjs = require('./chunk-XSVNC2UD.cjs');
|
|
8
|
+
|
|
9
|
+
// src/outbound-api/billingCapture.ts
|
|
10
|
+
var _crypto = require('crypto');
|
|
11
|
+
var defaultDefer = (fn) => {
|
|
12
|
+
setTimeout(fn, 0);
|
|
13
|
+
};
|
|
14
|
+
function beginBillingCapture(_req, res, now, defer = defaultDefer) {
|
|
15
|
+
if (!_chunkL74VDN4Acjs.getBillingCaptureConfig.call(void 0, )) return null;
|
|
16
|
+
const ctx = {};
|
|
17
|
+
let finished = false;
|
|
18
|
+
const finalize = () => {
|
|
19
|
+
if (finished) return;
|
|
20
|
+
finished = true;
|
|
21
|
+
const status = res.statusCode;
|
|
22
|
+
defer(() => {
|
|
23
|
+
try {
|
|
24
|
+
const usage = _chunkXSVNC2UDcjs.readAuditUsage.call(void 0, res);
|
|
25
|
+
if (!usage) return;
|
|
26
|
+
const event = {
|
|
27
|
+
id: _crypto.randomUUID.call(void 0, ),
|
|
28
|
+
ts: now,
|
|
29
|
+
model: _nullishCoalesce(_nullishCoalesce(ctx.model, () => ( usage.model)), () => ( "")),
|
|
30
|
+
authMode: _nullishCoalesce(ctx.authMode, () => ( "byo")),
|
|
31
|
+
inputTokens: _nullishCoalesce(usage.inputTokens, () => ( 0)),
|
|
32
|
+
outputTokens: _nullishCoalesce(usage.outputTokens, () => ( 0)),
|
|
33
|
+
costUsd: _nullishCoalesce(usage.costUsd, () => ( 0)),
|
|
34
|
+
status
|
|
35
|
+
};
|
|
36
|
+
if (ctx.keyId != null) event.keyId = ctx.keyId;
|
|
37
|
+
const provider = _nullishCoalesce(ctx.provider, () => ( usage.provider));
|
|
38
|
+
if (provider) event.provider = provider;
|
|
39
|
+
_chunkL74VDN4Acjs.publishBillingEvent.call(void 0, event);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
res.once("close", finalize);
|
|
45
|
+
return ctx;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
exports.beginBillingCapture = beginBillingCapture;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const existing = stash.get(key);
|
|
5
|
-
stash.set(key, existing ? { ...existing, ...detail } : { ...detail });
|
|
6
|
-
}
|
|
7
|
-
function readAuditUsage(key) {
|
|
8
|
-
return stash.get(key);
|
|
9
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
stashAuditUsage
|
|
3
|
+
} from "./chunk-OZFM4X3S.js";
|
|
10
4
|
|
|
11
5
|
// src/usage/usage-recorder.ts
|
|
12
6
|
var UsageRecorder = class {
|
|
@@ -125,6 +119,5 @@ var safeStringify = (value) => {
|
|
|
125
119
|
};
|
|
126
120
|
|
|
127
121
|
export {
|
|
128
|
-
readAuditUsage,
|
|
129
122
|
UsageRecorder
|
|
130
123
|
};
|