nexus-agents 4.14.3 → 4.15.0
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/dist/{child-mcp-config-APH7KTWD.js → child-mcp-config-HW5K2JVC.js} +2 -2
- package/dist/{chunk-FZ7ACQTB.js → chunk-2LJDOJ2V.js} +45 -12
- package/dist/chunk-2LJDOJ2V.js.map +1 -0
- package/dist/{chunk-FLX3LARU.js → chunk-32ZZ4GBB.js} +2 -2
- package/dist/{chunk-BRPWBUSX.js → chunk-33QUGCOZ.js} +42 -20
- package/dist/chunk-33QUGCOZ.js.map +1 -0
- package/dist/{chunk-CBFZSAUL.js → chunk-5JDI34FB.js} +4 -4
- package/dist/{chunk-XMD26PDY.js → chunk-6LUR7LMM.js} +5 -5
- package/dist/{chunk-VJJMHVLJ.js → chunk-747LKXD4.js} +7 -7
- package/dist/{chunk-5DT2LK7C.js → chunk-74BJOUWL.js} +6 -6
- package/dist/{chunk-HHHB3R7L.js → chunk-BK2BNOPS.js} +2 -2
- package/dist/{chunk-JUZRCQJI.js → chunk-GKGPTBTG.js} +8 -8
- package/dist/{chunk-7RRQSUX4.js → chunk-GR2VJFBO.js} +3 -3
- package/dist/{chunk-5WDKJA6B.js → chunk-JC4QH4WC.js} +2 -2
- package/dist/{chunk-FEC3PFSO.js → chunk-KBSRNMIM.js} +2 -2
- package/dist/{chunk-QE3FY3DG.js → chunk-KTMBBIFH.js} +8 -8
- package/dist/{chunk-3FRBJFOX.js → chunk-LOMQMLJH.js} +2 -2
- package/dist/{chunk-75J5CYUV.js → chunk-MHRAJ6GM.js} +3 -3
- package/dist/{chunk-YYDGGULW.js → chunk-N5O3XVNG.js} +35 -35
- package/dist/{chunk-VP7KIRQQ.js → chunk-O2WHBWK5.js} +4 -4
- package/dist/{chunk-WWPXJKN4.js → chunk-PEISXF34.js} +3 -3
- package/dist/{chunk-XLZ734N3.js → chunk-QHWMR6OT.js} +3 -3
- package/dist/{chunk-YL27XZ6T.js → chunk-RBQ3UYWT.js} +5 -5
- package/dist/{chunk-6DPOX5GU.js → chunk-T3645YDF.js} +2 -2
- package/dist/{chunk-7K4UQJD3.js → chunk-UHSAME2X.js} +2 -2
- package/dist/{chunk-BI6L5HAS.js → chunk-UTADCOFU.js} +2 -2
- package/dist/{chunk-WJA3TLFH.js → chunk-VPOVLDT6.js} +2 -2
- package/dist/{chunk-BV4L3SWR.js → chunk-VR76FPIN.js} +7 -7
- package/dist/{chunk-TCKP3H54.js → chunk-VVR2JO2I.js} +2 -2
- package/dist/{chunk-UCVDEZGK.js → chunk-W2EOSNAN.js} +2 -2
- package/dist/{chunk-JGQ3YQP5.js → chunk-XHUVJJHC.js} +4 -4
- package/dist/{chunk-7PCOAMGG.js → chunk-XULO32DU.js} +2 -2
- package/dist/{chunk-25ZTN5RI.js → chunk-YADJHL2U.js} +2 -2
- package/dist/{chunk-CD24GOBY.js → chunk-YMCIDGNP.js} +2 -2
- package/dist/{chunk-MVLURKBG.js → chunk-ZGMPNBYH.js} +2 -2
- package/dist/{cli-circuit-breaker-KMEJKQHZ.js → cli-circuit-breaker-SYBXPR6Q.js} +3 -3
- package/dist/cli.js +40 -40
- package/dist/{composite-router-RGDD4TNU.js → composite-router-P2ZFPWEQ.js} +2 -2
- package/dist/{consensus-vote-Z5PEK4MM.js → consensus-vote-BGJUZRZJ.js} +16 -16
- package/dist/{context-retriever-4AQ3X4BA.js → context-retriever-XLRKR2FE.js} +8 -8
- package/dist/{doctor-deep-6WIHSJVD.js → doctor-deep-TBTCDJP5.js} +3 -3
- package/dist/{doctor-live-KBPUGB2N.js → doctor-live-NANGVE6E.js} +9 -9
- package/dist/{expert-bridge-FXGOGERJ.js → expert-bridge-TY74K2FE.js} +4 -4
- package/dist/{factory-3C6ZJRL5.js → factory-26MTUNKV.js} +9 -9
- package/dist/{factory-QT45XC23.js → factory-MZCGPGEN.js} +5 -5
- package/dist/{improvement-review-EV7EKX2P.js → improvement-review-XMZIAREG.js} +5 -5
- package/dist/index.js +30 -30
- package/dist/{init-opencode-6U27FCUS.js → init-opencode-4IKJR7KI.js} +6 -6
- package/dist/issue-triage-LTO7DCEH.js +17 -0
- package/dist/{pr-reviewer-helpers-ZXSBKVAA.js → pr-reviewer-helpers-6PQ5N665.js} +4 -4
- package/dist/{registry-command-QXMKIBJK.js → registry-command-43DUBO6N.js} +2 -2
- package/dist/{repo-security-plan-3KJC6D43.js → repo-security-plan-5TQRW56I.js} +3 -3
- package/dist/{research-helpers-synthesize-UEHRTCC5.js → research-helpers-synthesize-XTVNZIQ7.js} +4 -4
- package/dist/{routing-memory-BQO6PUXU.js → routing-memory-FB5G6AGG.js} +2 -2
- package/dist/{session-memory-7XFRHFGO.js → session-memory-BBSBVXGZ.js} +3 -3
- package/dist/{setup-config-5WO4DBWX.js → setup-config-7O2J7HIU.js} +3 -3
- package/dist/{setup-custom-api-OSRXX3Z7.js → setup-custom-api-S5HGF5KY.js} +4 -4
- package/dist/setup-data-dir-ORCVLI3F.js +28 -0
- package/dist/{tool-memory-YRVKVPJA.js → tool-memory-LUE6HXAS.js} +5 -5
- package/dist/{unified-registry-NZUP46HN.js → unified-registry-FW2GDVXD.js} +10 -10
- package/dist/{weather-report-WQKQQGOM.js → weather-report-RABZEX2Z.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-BRPWBUSX.js.map +0 -1
- package/dist/chunk-FZ7ACQTB.js.map +0 -1
- package/dist/issue-triage-JSEBZBJ2.js +0 -17
- package/dist/setup-data-dir-K2XK7ZRA.js +0 -28
- /package/dist/{child-mcp-config-APH7KTWD.js.map → child-mcp-config-HW5K2JVC.js.map} +0 -0
- /package/dist/{chunk-FLX3LARU.js.map → chunk-32ZZ4GBB.js.map} +0 -0
- /package/dist/{chunk-CBFZSAUL.js.map → chunk-5JDI34FB.js.map} +0 -0
- /package/dist/{chunk-XMD26PDY.js.map → chunk-6LUR7LMM.js.map} +0 -0
- /package/dist/{chunk-VJJMHVLJ.js.map → chunk-747LKXD4.js.map} +0 -0
- /package/dist/{chunk-5DT2LK7C.js.map → chunk-74BJOUWL.js.map} +0 -0
- /package/dist/{chunk-HHHB3R7L.js.map → chunk-BK2BNOPS.js.map} +0 -0
- /package/dist/{chunk-JUZRCQJI.js.map → chunk-GKGPTBTG.js.map} +0 -0
- /package/dist/{chunk-7RRQSUX4.js.map → chunk-GR2VJFBO.js.map} +0 -0
- /package/dist/{chunk-5WDKJA6B.js.map → chunk-JC4QH4WC.js.map} +0 -0
- /package/dist/{chunk-FEC3PFSO.js.map → chunk-KBSRNMIM.js.map} +0 -0
- /package/dist/{chunk-QE3FY3DG.js.map → chunk-KTMBBIFH.js.map} +0 -0
- /package/dist/{chunk-3FRBJFOX.js.map → chunk-LOMQMLJH.js.map} +0 -0
- /package/dist/{chunk-75J5CYUV.js.map → chunk-MHRAJ6GM.js.map} +0 -0
- /package/dist/{chunk-YYDGGULW.js.map → chunk-N5O3XVNG.js.map} +0 -0
- /package/dist/{chunk-VP7KIRQQ.js.map → chunk-O2WHBWK5.js.map} +0 -0
- /package/dist/{chunk-WWPXJKN4.js.map → chunk-PEISXF34.js.map} +0 -0
- /package/dist/{chunk-XLZ734N3.js.map → chunk-QHWMR6OT.js.map} +0 -0
- /package/dist/{chunk-YL27XZ6T.js.map → chunk-RBQ3UYWT.js.map} +0 -0
- /package/dist/{chunk-6DPOX5GU.js.map → chunk-T3645YDF.js.map} +0 -0
- /package/dist/{chunk-7K4UQJD3.js.map → chunk-UHSAME2X.js.map} +0 -0
- /package/dist/{chunk-BI6L5HAS.js.map → chunk-UTADCOFU.js.map} +0 -0
- /package/dist/{chunk-WJA3TLFH.js.map → chunk-VPOVLDT6.js.map} +0 -0
- /package/dist/{chunk-BV4L3SWR.js.map → chunk-VR76FPIN.js.map} +0 -0
- /package/dist/{chunk-TCKP3H54.js.map → chunk-VVR2JO2I.js.map} +0 -0
- /package/dist/{chunk-UCVDEZGK.js.map → chunk-W2EOSNAN.js.map} +0 -0
- /package/dist/{chunk-JGQ3YQP5.js.map → chunk-XHUVJJHC.js.map} +0 -0
- /package/dist/{chunk-7PCOAMGG.js.map → chunk-XULO32DU.js.map} +0 -0
- /package/dist/{chunk-25ZTN5RI.js.map → chunk-YADJHL2U.js.map} +0 -0
- /package/dist/{chunk-CD24GOBY.js.map → chunk-YMCIDGNP.js.map} +0 -0
- /package/dist/{chunk-MVLURKBG.js.map → chunk-ZGMPNBYH.js.map} +0 -0
- /package/dist/{cli-circuit-breaker-KMEJKQHZ.js.map → cli-circuit-breaker-SYBXPR6Q.js.map} +0 -0
- /package/dist/{composite-router-RGDD4TNU.js.map → composite-router-P2ZFPWEQ.js.map} +0 -0
- /package/dist/{consensus-vote-Z5PEK4MM.js.map → consensus-vote-BGJUZRZJ.js.map} +0 -0
- /package/dist/{context-retriever-4AQ3X4BA.js.map → context-retriever-XLRKR2FE.js.map} +0 -0
- /package/dist/{doctor-deep-6WIHSJVD.js.map → doctor-deep-TBTCDJP5.js.map} +0 -0
- /package/dist/{doctor-live-KBPUGB2N.js.map → doctor-live-NANGVE6E.js.map} +0 -0
- /package/dist/{expert-bridge-FXGOGERJ.js.map → expert-bridge-TY74K2FE.js.map} +0 -0
- /package/dist/{factory-3C6ZJRL5.js.map → factory-26MTUNKV.js.map} +0 -0
- /package/dist/{factory-QT45XC23.js.map → factory-MZCGPGEN.js.map} +0 -0
- /package/dist/{improvement-review-EV7EKX2P.js.map → improvement-review-XMZIAREG.js.map} +0 -0
- /package/dist/{init-opencode-6U27FCUS.js.map → init-opencode-4IKJR7KI.js.map} +0 -0
- /package/dist/{issue-triage-JSEBZBJ2.js.map → issue-triage-LTO7DCEH.js.map} +0 -0
- /package/dist/{pr-reviewer-helpers-ZXSBKVAA.js.map → pr-reviewer-helpers-6PQ5N665.js.map} +0 -0
- /package/dist/{registry-command-QXMKIBJK.js.map → registry-command-43DUBO6N.js.map} +0 -0
- /package/dist/{repo-security-plan-3KJC6D43.js.map → repo-security-plan-5TQRW56I.js.map} +0 -0
- /package/dist/{research-helpers-synthesize-UEHRTCC5.js.map → research-helpers-synthesize-XTVNZIQ7.js.map} +0 -0
- /package/dist/{routing-memory-BQO6PUXU.js.map → routing-memory-FB5G6AGG.js.map} +0 -0
- /package/dist/{session-memory-7XFRHFGO.js.map → session-memory-BBSBVXGZ.js.map} +0 -0
- /package/dist/{setup-config-5WO4DBWX.js.map → setup-config-7O2J7HIU.js.map} +0 -0
- /package/dist/{setup-custom-api-OSRXX3Z7.js.map → setup-custom-api-S5HGF5KY.js.map} +0 -0
- /package/dist/{setup-data-dir-K2XK7ZRA.js.map → setup-data-dir-ORCVLI3F.js.map} +0 -0
- /package/dist/{tool-memory-YRVKVPJA.js.map → tool-memory-LUE6HXAS.js.map} +0 -0
- /package/dist/{unified-registry-NZUP46HN.js.map → unified-registry-FW2GDVXD.js.map} +0 -0
- /package/dist/{weather-report-WQKQQGOM.js.map → weather-report-RABZEX2Z.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-RQV5ZUXT.js";
|
|
4
4
|
import {
|
|
5
5
|
createLogger
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-33QUGCOZ.js";
|
|
7
7
|
import "./chunk-HHLCAWAV.js";
|
|
8
8
|
import "./chunk-NBMWONHE.js";
|
|
9
9
|
import "./chunk-ZPWHCABL.js";
|
|
@@ -62,4 +62,4 @@ export {
|
|
|
62
62
|
generateMcpConfig,
|
|
63
63
|
getDefaultAllowedTools
|
|
64
64
|
};
|
|
65
|
-
//# sourceMappingURL=child-mcp-config-
|
|
65
|
+
//# sourceMappingURL=child-mcp-config-HW5K2JVC.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
createLogger,
|
|
4
4
|
err,
|
|
5
5
|
ok
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-33QUGCOZ.js";
|
|
7
7
|
|
|
8
8
|
// src/adapters/sdk/types.ts
|
|
9
9
|
var PROVIDER_ENV_KEYS = {
|
|
@@ -147,14 +147,35 @@ var IPV4_RULES = [
|
|
|
147
147
|
reason: "link_local",
|
|
148
148
|
label: "IPv4 link-local (169.254/16 \u2014 AWS IMDS)"
|
|
149
149
|
},
|
|
150
|
-
{ match: (a) => a === 0, reason: "reserved", label: "IPv4 reserved (0/8)" }
|
|
150
|
+
{ match: (a) => a === 0, reason: "reserved", label: "IPv4 reserved (0/8)" },
|
|
151
|
+
{
|
|
152
|
+
match: (a, b) => a === 100 && b >= 64 && b <= 127,
|
|
153
|
+
reason: "private_range",
|
|
154
|
+
label: "IPv4 shared address space (100.64/10 \u2014 CGNAT, Alibaba metadata)"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
match: (a, b, c) => a === 192 && b === 0 && c === 0,
|
|
158
|
+
reason: "reserved",
|
|
159
|
+
label: "IPv4 IETF protocol assignments (192.0.0/24 \u2014 legacy Oracle metadata)"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
match: (a, b) => a === 198 && (b === 18 || b === 19),
|
|
163
|
+
reason: "reserved",
|
|
164
|
+
label: "IPv4 benchmarking (198.18/15)"
|
|
165
|
+
},
|
|
166
|
+
{ match: (a) => a >= 224 && a <= 239, reason: "reserved", label: "IPv4 multicast (224/4)" },
|
|
167
|
+
{
|
|
168
|
+
match: (a) => a >= 240,
|
|
169
|
+
reason: "reserved",
|
|
170
|
+
label: "IPv4 reserved (240/4, includes 255.255.255.255 broadcast)"
|
|
171
|
+
}
|
|
151
172
|
];
|
|
152
173
|
function classifyIPv4(ip) {
|
|
153
174
|
const parts = ip.split(".").map((p) => Number.parseInt(p, 10));
|
|
154
175
|
if (parts.length !== 4 || parts.some((n) => Number.isNaN(n))) return null;
|
|
155
|
-
const [a, b] = parts;
|
|
176
|
+
const [a, b, c] = parts;
|
|
156
177
|
for (const rule of IPV4_RULES) {
|
|
157
|
-
if (rule.match(a, b)) {
|
|
178
|
+
if (rule.match(a, b, c)) {
|
|
158
179
|
return { reason: rule.reason, message: `${rule.label} (${ip})` };
|
|
159
180
|
}
|
|
160
181
|
}
|
|
@@ -182,6 +203,7 @@ function toHextets(ip) {
|
|
|
182
203
|
return out.some((n) => Number.isNaN(n) || n < 0 || n > 65535) ? null : out;
|
|
183
204
|
}
|
|
184
205
|
function embeddedIPv4(g) {
|
|
206
|
+
if (g[0] === 8194) return hextetPairToDotted(g[1] ?? 0, g[2] ?? 0);
|
|
185
207
|
const top = g.slice(0, 6);
|
|
186
208
|
const prefixes = [
|
|
187
209
|
[0, 0, 0, 0, 0, 65535],
|
|
@@ -198,19 +220,30 @@ function embeddedIPv4(g) {
|
|
|
198
220
|
const g6 = g[6] ?? 0;
|
|
199
221
|
const g7 = g[7] ?? 0;
|
|
200
222
|
if (top.every((v) => v === 0) && g6 === 0 && g7 <= 1) return null;
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
return hextetPairToDotted(g6, g7);
|
|
224
|
+
}
|
|
225
|
+
function hextetPairToDotted(hi, lo) {
|
|
226
|
+
return [hi >> 8 & 255, hi & 255, lo >> 8 & 255, lo & 255].join(".");
|
|
227
|
+
}
|
|
228
|
+
function classifyIPv6Prefix(first, ip) {
|
|
229
|
+
if (first >= 64512 && first <= 65023) {
|
|
230
|
+
return { reason: "private_range", message: `IPv6 unique-local (${ip}, fc00::/7)` };
|
|
231
|
+
}
|
|
232
|
+
if (first >= 65152 && first <= 65215) {
|
|
233
|
+
return { reason: "link_local", message: `IPv6 link-local (${ip}, fe80::/10)` };
|
|
234
|
+
}
|
|
235
|
+
if (first >= 65216 && first <= 65279) {
|
|
236
|
+
return { reason: "private_range", message: `IPv6 site-local (${ip}, fec0::/10)` };
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
203
239
|
}
|
|
204
240
|
function classifyIPv6(ip) {
|
|
205
241
|
const lower = ip.toLowerCase();
|
|
206
242
|
if (lower === "::1") return { reason: "loopback", message: `IPv6 loopback (${ip})` };
|
|
207
|
-
if (lower.startsWith("fe80:"))
|
|
208
|
-
return { reason: "link_local", message: `IPv6 link-local (${ip})` };
|
|
209
|
-
if (/^fc|^fd/.test(lower)) {
|
|
210
|
-
return { reason: "private_range", message: `IPv6 unique-local (${ip}, fc00::/7)` };
|
|
211
|
-
}
|
|
212
243
|
const groups = toHextets(lower);
|
|
213
244
|
if (groups === null) return null;
|
|
245
|
+
const prefixDetail = classifyIPv6Prefix(groups[0] ?? 0, ip);
|
|
246
|
+
if (prefixDetail !== null) return prefixDetail;
|
|
214
247
|
if (groups.every((n) => n === 0)) {
|
|
215
248
|
return { reason: "reserved", message: `IPv6 unspecified (${ip}) \u2014 routes to localhost` };
|
|
216
249
|
}
|
|
@@ -227,4 +260,4 @@ export {
|
|
|
227
260
|
validateCustomApiBaseUrl,
|
|
228
261
|
assertCustomApiHostResolvesPublic
|
|
229
262
|
};
|
|
230
|
-
//# sourceMappingURL=chunk-
|
|
263
|
+
//# sourceMappingURL=chunk-2LJDOJ2V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/sdk/types.ts","../src/adapters/sdk/custom-api-validation.ts"],"sourcesContent":["/**\n * nexus-agents/adapters/sdk - Shared Types\n *\n * Type definitions for AI SDK adapter layer.\n *\n * @module adapters/sdk/types\n * (Source: Issue #1123 — AI SDK provider layer)\n */\n\n/**\n * Supported AI SDK provider identifiers.\n *\n * `custom-openai` is for OpenAI-compatible gateways (multi-vendor proxies,\n * self-hosted LLM servers, corporate model gateways) — uses the same\n * @ai-sdk/openai package but with a configurable `baseURL`.\n */\nexport type SdkProviderId = 'anthropic' | 'openai' | 'google' | 'custom-openai';\n\n/**\n * Configuration for creating an AI SDK adapter.\n */\nexport interface SdkAdapterConfig {\n /** Provider identifier */\n providerId: SdkProviderId;\n /** Model to use (e.g., 'claude-sonnet-4-6', 'gpt-4o') */\n modelId: string;\n /** API key (falls back to environment variable) */\n apiKey?: string;\n /**\n * Base URL for OpenAI-compatible gateways. Required when\n * `providerId === 'custom-openai'`, ignored otherwise. Falls back to\n * the `NEXUS_CUSTOM_API_BASE_URL` environment variable.\n */\n baseUrl?: string;\n /** Request timeout in milliseconds */\n timeout?: number;\n /** Maximum retries on transient failures */\n maxRetries?: number;\n}\n\n/**\n * Maps provider IDs to their environment variable names.\n */\nexport const PROVIDER_ENV_KEYS: Record<SdkProviderId, string> = {\n anthropic: 'ANTHROPIC_API_KEY',\n openai: 'OPENAI_API_KEY',\n google: 'GOOGLE_AI_API_KEY',\n 'custom-openai': 'NEXUS_CUSTOM_API_KEY',\n};\n\n/**\n * Environment variable name for the custom gateway base URL.\n * Keep in sync with `SdkAdapterConfig.baseUrl`.\n */\nexport const CUSTOM_API_BASE_URL_ENV = 'NEXUS_CUSTOM_API_BASE_URL';\n\n/**\n * Escape hatch: set to `1`/`true` to allow the custom gateway base URL to\n * resolve to a loopback or RFC 1918 private address. Default is DENY —\n * SSRF defense. Only disable this when you know the gateway runs on a\n * trusted internal host and you accept the risk.\n */\nexport const CUSTOM_API_ALLOW_PRIVATE_ENV = 'NEXUS_CUSTOM_API_ALLOW_PRIVATE';\n","/**\n * Validation for the `custom-openai` SDK adapter's gateway URL.\n *\n * The base URL is user-provided, so without validation the adapter becomes\n * an SSRF vector: a malicious prompt that reshaped env vars, or a typo in\n * the config, could point nexus-agents at `http://169.254.169.254/` (AWS\n * metadata) or `http://localhost:5432/` (internal services). This module\n * rejects such URLs unless the user explicitly opts in via\n * `NEXUS_CUSTOM_API_ALLOW_PRIVATE=1`.\n *\n * Called out in the #2119 consensus vote by the Security Engineer role.\n *\n * @module adapters/sdk/custom-api-validation\n */\n\nimport { isIPv4, isIPv6 } from 'node:net';\nimport { lookup as dnsLookup } from 'node:dns/promises';\nimport { ConfigError, ok, err, createLogger, type Result } from '../../core/index.js';\nimport { CUSTOM_API_ALLOW_PRIVATE_ENV } from './types.js';\n\nconst logger = createLogger({ module: 'custom-api-validation' });\n\n/**\n * Why a given URL was rejected. Machine-readable so error messages can\n * distinguish root causes in downstream tooling.\n */\nexport type BaseUrlRejectionReason =\n | 'empty'\n | 'not_a_url'\n | 'not_http_https'\n | 'loopback'\n | 'link_local'\n | 'private_range'\n | 'reserved';\n\ninterface RejectionDetail {\n readonly reason: BaseUrlRejectionReason;\n readonly message: string;\n}\n\n/**\n * Validates a user-provided custom-gateway base URL. Returns the URL as an\n * `ok` Result if it passes, or a `ConfigError` with a machine-readable\n * reason if it fails.\n *\n * Pass `{ allowPrivate: true }` (or set the env var) to bypass the SSRF\n * checks — use this only when the gateway is on a trusted internal host\n * and you accept the risk.\n */\nexport function validateCustomApiBaseUrl(\n raw: string | undefined,\n opts: { readonly allowPrivate?: boolean } = {}\n): Result<URL, ConfigError> {\n if (raw === undefined || raw.trim() === '') {\n return err(\n new ConfigError(\n 'Custom API base URL is required but missing. Set NEXUS_CUSTOM_API_BASE_URL or pass `baseUrl` in config.'\n )\n );\n }\n\n let url: URL;\n try {\n url = new URL(raw);\n } catch {\n return err(new ConfigError(`Custom API base URL is not a valid URL: ${raw}`));\n }\n\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n return err(\n new ConfigError(`Custom API base URL must use http or https, got \"${url.protocol}\" in ${raw}`)\n );\n }\n\n const allowPrivate = opts.allowPrivate === true || resolveAllowPrivateFromEnv();\n if (!allowPrivate) {\n const rejection = classifyPrivateHost(url.hostname);\n if (rejection !== null) {\n return err(\n new ConfigError(\n `Custom API base URL rejected (SSRF guard, reason=\"${rejection.reason}\"): ${rejection.message}. ` +\n `Set ${CUSTOM_API_ALLOW_PRIVATE_ENV}=1 to bypass if the gateway runs on a trusted internal host.`\n )\n );\n }\n }\n\n return ok(url);\n}\n\nfunction resolveAllowPrivateFromEnv(): boolean {\n // Deliberately strict (case-sensitive, not parseBoolEnv): this disables an\n // SSRF guard, so we don't want extra case variants (e.g. `TRUE`) to loosen\n // the control. Fail-closed on anything but exact `1`/`true` (#3297).\n const v = process.env[CUSTOM_API_ALLOW_PRIVATE_ENV];\n return v === '1' || v === 'true';\n}\n\n/**\n * Returns a rejection reason if the hostname resolves (by string form) to\n * a loopback, link-local, or RFC 1918 private address; `null` otherwise.\n *\n * Note: this is a string-level check. It does NOT perform DNS resolution,\n * so a public DNS name that secretly resolves to a private IP will pass.\n * For that level of defense, callers should additionally run\n * {@link assertCustomApiHostResolvesPublic}, which performs a DNS lookup\n * and classifies each resolved address with the same range tables below.\n */\nfunction classifyPrivateHost(hostname: string): RejectionDetail | null {\n const normalized = normalizeHost(hostname);\n\n // Literal IP addresses — classify directly against the range tables.\n const literal = classifyIpAddress(normalized);\n if (literal !== 'not_an_ip') {\n return literal;\n }\n\n // Hostname literals that resolve to loopback without needing DNS\n if (\n normalized === 'localhost' ||\n normalized.endsWith('.localhost') ||\n normalized.endsWith('.local') // mDNS\n ) {\n return {\n reason: 'loopback',\n message: `hostname \"${hostname}\" resolves to loopback/mDNS`,\n };\n }\n\n return null;\n}\n\n/**\n * Strips IPv6 bracket wrapping (URL.hostname yields \"[::1]\") and lowercases,\n * giving the bare form the `node:net` checks expect. Shared by the sync and\n * async guards so the normalization rule lives in one place.\n */\nfunction normalizeHost(hostname: string): string {\n const stripped =\n hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;\n return stripped.toLowerCase();\n}\n\n/**\n * Classifies a single (already normalized, bracket-stripped) address string.\n * Returns:\n * - a {@link RejectionDetail} if it is a private/loopback/link-local/reserved IP,\n * - `null` if it is a public IP literal (safe),\n * - the sentinel `'not_an_ip'` if the string is not an IP literal at all.\n *\n * This is the shared per-address classifier reused by both the sync\n * string-level guard ({@link classifyPrivateHost}) and the async\n * DNS-resolve-time guard ({@link assertCustomApiHostResolvesPublic}), so the\n * IPv4/IPv6 range tables live in exactly one place.\n */\nfunction classifyIpAddress(normalized: string): RejectionDetail | null | 'not_an_ip' {\n if (isIPv4(normalized)) {\n return classifyIPv4(normalized);\n }\n if (isIPv6(normalized)) {\n return classifyIPv6(normalized);\n }\n return 'not_an_ip';\n}\n\n/** Verdict for a host that is already an IP literal — no DNS required. */\nfunction classifyLiteral(hostname: string, normalized: string): Result<void, ConfigError> {\n const literal = classifyIpAddress(normalized);\n if (literal === null || literal === 'not_an_ip') return ok(undefined);\n return err(\n new ConfigError(\n `Custom API host '${hostname}' is a ${literal.reason} address: ${literal.message}`\n )\n );\n}\n\n/**\n * DNS-resolve-time SSRF guard for the custom-openai gateway.\n *\n * The sync {@link validateCustomApiBaseUrl} only inspects the hostname as a\n * string, so a PUBLIC DNS name that resolves to a PRIVATE/loopback/link-local\n * IP (e.g. an attacker-controlled `gateway.evil.test` pointing at\n * `169.254.169.254`) slips past it. This function closes that gap: it resolves\n * the hostname and runs the EXISTING IP classification against every returned\n * address, failing closed if ANY of them is private.\n *\n * Behaviour:\n * - `allowPrivate` (opt or env) → bypass, returns `ok` (matches the sync guard).\n * - hostname is already an IP literal → no DNS needed; the sync guard already\n * classified literals at construction, so return `ok`.\n * - otherwise `dns.lookup(hostname, { all: true })` and classify each address.\n * If ANY resolves private → `err(ConfigError)`.\n * - on a `dns.lookup` THROW (transient/NXDOMAIN/network error) → log debug and\n * return `ok`. Failing closed here is too aggressive: it would break legit\n * gateways on a flaky resolver, and this is additive defense-in-depth layered\n * on top of the sync string guard that already ran at construction. We only\n * REJECT on a SUCCESSFUL resolution to a private address.\n *\n * Residual risk (TOCTOU): this is RESOLVE-time, not socket-connect-time. A name\n * that passes here could rebind to a private IP before the actual connect\n * (DNS rebinding). A full fix needs a custom `fetch` `lookup` hook validating\n * the peer address at the socket layer — out of scope for this LOW\n * defense-in-depth pass (#3426).\n */\nexport async function assertCustomApiHostResolvesPublic(\n hostname: string,\n opts: { readonly allowPrivate?: boolean } = {}\n): Promise<Result<void, ConfigError>> {\n const allowPrivate = opts.allowPrivate === true || resolveAllowPrivateFromEnv();\n if (allowPrivate) {\n return ok(undefined);\n }\n\n const normalized = normalizeHost(hostname);\n\n // A literal needs no DNS, but it is still classified HERE rather than\n // assumed handled elsewhere. This used to return ok for any literal on the\n // grounds that the sync guard had classified it at construction — but\n // `discoverModels` calls only this guard, never the sync one, so on that\n // path each deferred to the other and neither ran. `http://169.254.169.254/`\n // reached IMDS, from a base URL that can come from a file rather than from\n // operator intent.\n if (isIPv4(normalized) || isIPv6(normalized)) {\n return classifyLiteral(hostname, normalized);\n }\n\n // Only `address` is read; the resolver's `family` is intentionally NOT\n // trusted — `classifyIpAddress` re-derives v4/v6 from the address string, so\n // a mislabeled family in the lookup result cannot let a private IP slip past.\n let addresses: ReadonlyArray<{ readonly address: string }>;\n try {\n addresses = await dnsLookup(hostname, { all: true });\n } catch (error) {\n // Fail OPEN: transient/NXDOMAIN/network errors must not break legit\n // gateways. The sync string guard already ran; this is additive only.\n logger.debug('custom-api SSRF resolve check: DNS lookup failed, skipping (fail-open)', {\n hostname,\n error: error instanceof Error ? error.message : String(error),\n });\n return ok(undefined);\n }\n\n const rejection = firstPrivateAddress(addresses);\n if (rejection !== null) {\n return err(\n new ConfigError(\n `Custom API base URL rejected (SSRF resolve guard, reason=\"${rejection.reason}\"): ` +\n `hostname \"${hostname}\" resolved to ${rejection.message}. ` +\n `Set ${CUSTOM_API_ALLOW_PRIVATE_ENV}=1 to bypass if the gateway runs on a trusted internal host.`\n )\n );\n }\n\n return ok(undefined);\n}\n\n/**\n * Returns the {@link RejectionDetail} for the first resolved address that\n * classifies as private/loopback/link-local/reserved, or `null` if every\n * address is public. Fail-closed: any single private hit trips the guard.\n */\nfunction firstPrivateAddress(\n addresses: ReadonlyArray<{ readonly address: string }>\n): RejectionDetail | null {\n for (const { address } of addresses) {\n const rejection = classifyIpAddress(address.toLowerCase());\n if (rejection !== null && rejection !== 'not_an_ip') {\n return rejection;\n }\n }\n return null;\n}\n\n/**\n * IPv4 ranges the SSRF guard rejects, in order of specificity.\n *\n * \"Not RFC1918\" is not the same as \"public\". The blocks below RFC1918 are\n * here because each is reachable from a host and serves something: 100.64/10\n * carries Alibaba Cloud's metadata endpoint, 192.0.0/24 carries a legacy\n * Oracle Cloud one, and multicast/reserved/broadcast reach the local segment\n * rather than the internet (second pass over #4884).\n */\nconst IPV4_RULES: ReadonlyArray<{\n readonly match: (a: number, b: number, c: number) => boolean;\n readonly reason: BaseUrlRejectionReason;\n readonly label: string;\n}> = [\n { match: (a) => a === 127, reason: 'loopback', label: 'IPv4 loopback' },\n { match: (a) => a === 10, reason: 'private_range', label: 'IPv4 private (10/8)' },\n {\n match: (a, b) => a === 172 && b >= 16 && b <= 31,\n reason: 'private_range',\n label: 'IPv4 private (172.16/12)',\n },\n {\n match: (a, b) => a === 192 && b === 168,\n reason: 'private_range',\n label: 'IPv4 private (192.168/16)',\n },\n {\n match: (a, b) => a === 169 && b === 254,\n reason: 'link_local',\n label: 'IPv4 link-local (169.254/16 — AWS IMDS)',\n },\n { match: (a) => a === 0, reason: 'reserved', label: 'IPv4 reserved (0/8)' },\n {\n match: (a, b) => a === 100 && b >= 64 && b <= 127,\n reason: 'private_range',\n label: 'IPv4 shared address space (100.64/10 — CGNAT, Alibaba metadata)',\n },\n {\n match: (a, b, c) => a === 192 && b === 0 && c === 0,\n reason: 'reserved',\n label: 'IPv4 IETF protocol assignments (192.0.0/24 — legacy Oracle metadata)',\n },\n {\n match: (a, b) => a === 198 && (b === 18 || b === 19),\n reason: 'reserved',\n label: 'IPv4 benchmarking (198.18/15)',\n },\n { match: (a) => a >= 224 && a <= 239, reason: 'reserved', label: 'IPv4 multicast (224/4)' },\n {\n match: (a) => a >= 240,\n reason: 'reserved',\n label: 'IPv4 reserved (240/4, includes 255.255.255.255 broadcast)',\n },\n];\n\nfunction classifyIPv4(ip: string): RejectionDetail | null {\n const parts = ip.split('.').map((p) => Number.parseInt(p, 10));\n if (parts.length !== 4 || parts.some((n) => Number.isNaN(n))) return null;\n const [a, b, c] = parts as [number, number, number, number];\n for (const rule of IPV4_RULES) {\n if (rule.match(a, b, c)) {\n return { reason: rule.reason, message: `${rule.label} (${ip})` };\n }\n }\n return null;\n}\n\n/**\n * Expand an IPv6 literal to its eight 16-bit groups, or null if unparseable.\n *\n * A trailing dotted quad (`::ffff:1.2.3.4`) is folded into two groups first,\n * so callers see one representation regardless of spelling.\n */\nfunction foldTrailingQuad(s: string): string | null {\n const dotted = /(?:^|:)((?:\\d{1,3}\\.){3}\\d{1,3})$/.exec(s);\n if (dotted?.[1] === undefined) return s;\n const q = dotted[1].split('.').map((n) => Number.parseInt(n, 10));\n if (q.length !== 4 || q.some((n) => Number.isNaN(n) || n < 0 || n > 255)) return null;\n const hi = (((q[0] ?? 0) << 8) | (q[1] ?? 0)).toString(16);\n const lo = (((q[2] ?? 0) << 8) | (q[3] ?? 0)).toString(16);\n return `${s.slice(0, s.length - dotted[1].length)}${hi}:${lo}`;\n}\n\nfunction toHextets(ip: string): number[] | null {\n const s = foldTrailingQuad(ip.toLowerCase());\n if (s === null) return null;\n const halves = s.split('::');\n if (halves.length > 2) return null;\n const head = halves[0] === '' || halves[0] === undefined ? [] : halves[0].split(':');\n const tail = halves[1] === '' || halves[1] === undefined ? [] : halves[1].split(':');\n const groups =\n halves.length === 1\n ? head\n : [...head, ...Array<string>(8 - head.length - tail.length).fill('0'), ...tail];\n if (groups.length !== 8) return null;\n const out = groups.map((g) => Number.parseInt(g === '' ? '0' : g, 16));\n return out.some((n) => Number.isNaN(n) || n < 0 || n > 0xffff) ? null : out;\n}\n\n/**\n * The IPv4 address embedded in an IPv6 literal, in dotted form, or null.\n *\n * Covers every prefix that carries a routable IPv4 payload: IPv4-mapped\n * (`::ffff:0:0/96`), IPv4-translated (`::ffff:0:0:0/96`), the NAT64\n * well-known prefix (`64:ff9b::/96`), 6to4 (`2002::/16`), and the deprecated\n * IPv4-compatible form (`::a.b.c.d`). Each is the same destination under a\n * different spelling, and the IPv4 rules must apply to all of them.\n */\nfunction embeddedIPv4(g: readonly number[]): string | null {\n // 6to4 is the odd one out: the payload sits in hextets 1-2, not 6-7, so it\n // cannot share the trailing-quad extraction below.\n if (g[0] === 0x2002) return hextetPairToDotted(g[1] ?? 0, g[2] ?? 0);\n const top = g.slice(0, 6);\n const prefixes: ReadonlyArray<readonly number[]> = [\n [0, 0, 0, 0, 0, 0xffff], // ::ffff:0:0/96 — IPv4-mapped\n [0, 0, 0, 0, 0xffff, 0], // ::ffff:0:0:0/96 — IPv4-translated\n [0x64, 0xff9b, 0, 0, 0, 0], // 64:ff9b::/96 — NAT64 well-known\n [0, 0, 0, 0, 0, 0], // ::a.b.c.d — deprecated IPv4-compatible\n ];\n const matched = prefixes.some((p) => p.every((v, i) => top[i] === v));\n if (!matched) return null;\n const g6 = g[6] ?? 0;\n const g7 = g[7] ?? 0;\n // `::` and `::1` are their own addresses, not embedded IPv4.\n if (top.every((v) => v === 0) && g6 === 0 && g7 <= 1) return null;\n return hextetPairToDotted(g6, g7);\n}\n\n/** The dotted IPv4 address carried by two consecutive 16-bit hextets. */\nfunction hextetPairToDotted(hi: number, lo: number): string {\n return [(hi >> 8) & 255, hi & 255, (lo >> 8) & 255, lo & 255].join('.');\n}\n\n/**\n * Classify an IPv6 address by its first hextet, or null if it is not in a\n * non-global prefix.\n *\n * Numeric rather than a string prefix test. The previous `startsWith('fe80:')`\n * covered 1/64th of fe80::/10 — `febf::1` is equally link-local and was\n * allowed — and site-local fec0::/10 had no check at all (second pass over #4884).\n */\nfunction classifyIPv6Prefix(first: number, ip: string): RejectionDetail | null {\n if (first >= 0xfc00 && first <= 0xfdff) {\n return { reason: 'private_range', message: `IPv6 unique-local (${ip}, fc00::/7)` };\n }\n if (first >= 0xfe80 && first <= 0xfebf) {\n return { reason: 'link_local', message: `IPv6 link-local (${ip}, fe80::/10)` };\n }\n if (first >= 0xfec0 && first <= 0xfeff) {\n return { reason: 'private_range', message: `IPv6 site-local (${ip}, fec0::/10)` };\n }\n return null;\n}\n\nfunction classifyIPv6(ip: string): RejectionDetail | null {\n const lower = ip.toLowerCase();\n if (lower === '::1') return { reason: 'loopback', message: `IPv6 loopback (${ip})` };\n\n const groups = toHextets(lower);\n if (groups === null) return null;\n\n const prefixDetail = classifyIPv6Prefix(groups[0] ?? 0, ip);\n if (prefixDetail !== null) return prefixDetail;\n\n if (groups.every((n) => n === 0)) {\n return { reason: 'reserved', message: `IPv6 unspecified (${ip}) — routes to localhost` };\n }\n\n // An IPv4 address written in IPv6 form is still that IPv4 address, and\n // `isIPv6` is true for it so it never reached the IPv4 rules — IMDS,\n // loopback and RFC1918 were all reachable this way. Note the URL parser\n // normalises the dotted spelling to hex, so the hex form is the one that\n // actually arrives.\n const v4 = embeddedIPv4(groups);\n if (v4 === null) return null;\n const detail = classifyIPv4(v4);\n return detail === null\n ? null\n : { reason: detail.reason, message: `${detail.message} via IPv6 (${ip})` };\n}\n"],"mappings":";;;;;;;;AA2CO,IAAM,oBAAmD;AAAA,EAC9D,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,iBAAiB;AACnB;AAMO,IAAM,0BAA0B;AAQhC,IAAM,+BAA+B;;;AC/C5C,SAAS,QAAQ,cAAc;AAC/B,SAAS,UAAU,iBAAiB;AAIpC,IAAM,SAAS,aAAa,EAAE,QAAQ,wBAAwB,CAAC;AA6BxD,SAAS,yBACd,KACA,OAA4C,CAAC,GACnB;AAC1B,MAAI,QAAQ,UAAa,IAAI,KAAK,MAAM,IAAI;AAC1C,WAAO;AAAA,MACL,IAAI;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AACJ,MAAI;AACF,UAAM,IAAI,IAAI,GAAG;AAAA,EACnB,QAAQ;AACN,WAAO,IAAI,IAAI,YAAY,2CAA2C,GAAG,EAAE,CAAC;AAAA,EAC9E;AAEA,MAAI,IAAI,aAAa,WAAW,IAAI,aAAa,UAAU;AACzD,WAAO;AAAA,MACL,IAAI,YAAY,oDAAoD,IAAI,QAAQ,QAAQ,GAAG,EAAE;AAAA,IAC/F;AAAA,EACF;AAEA,QAAM,eAAe,KAAK,iBAAiB,QAAQ,2BAA2B;AAC9E,MAAI,CAAC,cAAc;AACjB,UAAM,YAAY,oBAAoB,IAAI,QAAQ;AAClD,QAAI,cAA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AAQ;AACtC,WAAO,EAAE,QAAQ,cAAc,SAAS,oBAAoB,EAAE,eAAe;AAAA,EAC/E;AACA,MAAI,SAAS,SAAU,SAAS,OAAQ;AACtC,WAAO,EAAE,QAAQ,iBAAiB,SAAS,oBAAoB,EAAE,eAAe;AAAA,EAClF;AACA,SAAO;AACT;AAEA,SAAS,aAAa,IAAoC;AACxD,QAAM,QAAQ,GAAG,YAAY;AAC7B,MAAI,UAAU,MAAO,QAAO,EAAE,QAAQ,YAAY,SAAS,kBAAkB,EAAE,IAAI;AAEnF,QAAM,SAAS,UAAU,KAAK;AAC9B,MAAI,WAAW,KAAM,QAAO;AAE5B,QAAM,eAAe,mBAAmB,OAAO,CAAC,KAAK,GAAG,EAAE;AAC1D,MAAI,iBAAiB,KAAM,QAAO;AAElC,MAAI,OAAO,MAAM,CAAC,MAAM,MAAM,CAAC,GAAG;AAChC,WAAO,EAAE,QAAQ,YAAY,SAAS,qBAAqB,EAAE,+BAA0B;AAAA,EACzF;AAOA,QAAM,KAAK,aAAa,MAAM;AAC9B,MAAI,OAAO,KAAM,QAAO;AACxB,QAAM,SAAS,aAAa,EAAE;AAC9B,SAAO,WAAW,OACd,OACA,EAAE,QAAQ,OAAO,QAAQ,SAAS,GAAG,OAAO,OAAO,cAAc,EAAE,IAAI;AAC7E;","names":[]}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
CACHE_TIMEOUTS,
|
|
3
3
|
createLogger,
|
|
4
4
|
getTimeProvider
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-33QUGCOZ.js";
|
|
6
6
|
|
|
7
7
|
// src/security/trust-types.ts
|
|
8
8
|
import { z } from "zod";
|
|
@@ -560,4 +560,4 @@ export {
|
|
|
560
560
|
resolveReputationGatingMode,
|
|
561
561
|
gateWithReputation
|
|
562
562
|
};
|
|
563
|
-
//# sourceMappingURL=chunk-
|
|
563
|
+
//# sourceMappingURL=chunk-32ZZ4GBB.js.map
|
|
@@ -2623,7 +2623,7 @@ function setDefaultRegistry(registry) {
|
|
|
2623
2623
|
}
|
|
2624
2624
|
async function reloadDefaultRegistry() {
|
|
2625
2625
|
globalRegistry = buildDefaultRegistry();
|
|
2626
|
-
const { resetGlobalRegistry } = await import("./unified-registry-
|
|
2626
|
+
const { resetGlobalRegistry } = await import("./unified-registry-FW2GDVXD.js");
|
|
2627
2627
|
resetGlobalRegistry();
|
|
2628
2628
|
return globalRegistry;
|
|
2629
2629
|
}
|
|
@@ -10571,6 +10571,31 @@ var CompositeRoutingError = class extends Error {
|
|
|
10571
10571
|
}
|
|
10572
10572
|
};
|
|
10573
10573
|
|
|
10574
|
+
// src/cli-adapters/composite-router-budget-feature.ts
|
|
10575
|
+
function toBudgetConstraint(raw) {
|
|
10576
|
+
const constraint = {};
|
|
10577
|
+
if (raw?.maxTokens !== void 0) {
|
|
10578
|
+
constraint.maxTokens = raw.maxTokens;
|
|
10579
|
+
}
|
|
10580
|
+
if (raw?.maxCostUsd !== void 0) {
|
|
10581
|
+
constraint.maxCostUsd = raw.maxCostUsd;
|
|
10582
|
+
}
|
|
10583
|
+
if (raw?.maxLatencyMs !== void 0) {
|
|
10584
|
+
constraint.maxLatencyMs = raw.maxLatencyMs;
|
|
10585
|
+
}
|
|
10586
|
+
return constraint;
|
|
10587
|
+
}
|
|
10588
|
+
function budgetUtilizationOf(estimatedCostUsd, maxCostUsd) {
|
|
10589
|
+
if (maxCostUsd === void 0 || maxCostUsd <= 0) return void 0;
|
|
10590
|
+
return Math.min(1, estimatedCostUsd / maxCostUsd);
|
|
10591
|
+
}
|
|
10592
|
+
function budgetUtilizationForTask(task, budgetRouter, rawConstraints) {
|
|
10593
|
+
if (budgetRouter === void 0) return void 0;
|
|
10594
|
+
const constraint = toBudgetConstraint(rawConstraints);
|
|
10595
|
+
const result = budgetRouter.checkBudget(task, constraint);
|
|
10596
|
+
return budgetUtilizationOf(result.estimatedCostUsd, constraint.maxCostUsd);
|
|
10597
|
+
}
|
|
10598
|
+
|
|
10574
10599
|
// src/cli-adapters/composite-router-helpers.ts
|
|
10575
10600
|
function adjustProfileForTask(profile, taskProfile) {
|
|
10576
10601
|
if (taskProfile.taskType === "architecture" || taskProfile.reasoningComplexity > 7) {
|
|
@@ -10630,26 +10655,13 @@ function cliTaskToTask(cliTask) {
|
|
|
10630
10655
|
context: {}
|
|
10631
10656
|
};
|
|
10632
10657
|
}
|
|
10633
|
-
function toBudgetConstraint(raw) {
|
|
10634
|
-
const constraint = {};
|
|
10635
|
-
if (raw?.maxTokens !== void 0) {
|
|
10636
|
-
constraint.maxTokens = raw.maxTokens;
|
|
10637
|
-
}
|
|
10638
|
-
if (raw?.maxCostUsd !== void 0) {
|
|
10639
|
-
constraint.maxCostUsd = raw.maxCostUsd;
|
|
10640
|
-
}
|
|
10641
|
-
if (raw?.maxLatencyMs !== void 0) {
|
|
10642
|
-
constraint.maxLatencyMs = raw.maxLatencyMs;
|
|
10643
|
-
}
|
|
10644
|
-
return constraint;
|
|
10645
|
-
}
|
|
10646
10658
|
function applyBudgetFilter(task, candidates, budgetRouter, config) {
|
|
10647
10659
|
if (budgetRouter === void 0) return { eligible: candidates, withinBudget: true };
|
|
10648
10660
|
const constraint = toBudgetConstraint(config.budgetConstraints);
|
|
10649
10661
|
const result = budgetRouter.checkBudget(task, constraint);
|
|
10650
10662
|
if (!result.withinBudget) return { eligible: [], withinBudget: false };
|
|
10651
|
-
const
|
|
10652
|
-
const utilization =
|
|
10663
|
+
const share = budgetUtilizationOf(result.estimatedCostUsd, constraint.maxCostUsd);
|
|
10664
|
+
const utilization = share === void 0 ? {} : { budgetUtilization: share };
|
|
10653
10665
|
if (config.billingMode !== "api")
|
|
10654
10666
|
return { eligible: candidates, withinBudget: true, ...utilization };
|
|
10655
10667
|
return {
|
|
@@ -14686,7 +14698,15 @@ function recordBanditOutcome(cliName, task, reward, deps) {
|
|
|
14686
14698
|
}
|
|
14687
14699
|
const internalTask = cliTaskToTask(task);
|
|
14688
14700
|
const analysis = sharedAnalyzer3.analyze(internalTask);
|
|
14689
|
-
const
|
|
14701
|
+
const budgetUtilization = budgetUtilizationForTask(
|
|
14702
|
+
task,
|
|
14703
|
+
deps.budgetRouter,
|
|
14704
|
+
deps.budgetConstraints
|
|
14705
|
+
);
|
|
14706
|
+
const context = taskAnalysisResultToBanditContext(
|
|
14707
|
+
analysis,
|
|
14708
|
+
budgetUtilization === void 0 ? {} : { budgetUtilization }
|
|
14709
|
+
);
|
|
14690
14710
|
deps.linucbBandit.update(armIndex, context, reward);
|
|
14691
14711
|
deps.logger.debug("Recorded outcome", { cliName, reward });
|
|
14692
14712
|
}
|
|
@@ -15079,7 +15099,7 @@ var CompositeRouter = class _CompositeRouter {
|
|
|
15079
15099
|
*/
|
|
15080
15100
|
async consultUnifiedContext(task) {
|
|
15081
15101
|
try {
|
|
15082
|
-
const { getContextForTask, inferTaskCategory } = await import("./context-retriever-
|
|
15102
|
+
const { getContextForTask, inferTaskCategory } = await import("./context-retriever-XLRKR2FE.js");
|
|
15083
15103
|
const ctx = await getContextForTask({
|
|
15084
15104
|
task: task.content,
|
|
15085
15105
|
category: inferTaskCategory(task.content),
|
|
@@ -15466,7 +15486,9 @@ var CompositeRouter = class _CompositeRouter {
|
|
|
15466
15486
|
linucbBandit: this.linucbBandit,
|
|
15467
15487
|
preferenceRouter: this.preferenceRouter,
|
|
15468
15488
|
zeroRouter: this.zeroRouter,
|
|
15469
|
-
lastRoutedTask: this.lastRoutedTask
|
|
15489
|
+
lastRoutedTask: this.lastRoutedTask,
|
|
15490
|
+
budgetRouter: this.budgetRouter,
|
|
15491
|
+
budgetConstraints: this.config.budgetConstraints
|
|
15470
15492
|
};
|
|
15471
15493
|
}
|
|
15472
15494
|
getZeroRouter() {
|
|
@@ -16670,4 +16692,4 @@ export {
|
|
|
16670
16692
|
AgentCapability,
|
|
16671
16693
|
OrchestratorError
|
|
16672
16694
|
};
|
|
16673
|
-
//# sourceMappingURL=chunk-
|
|
16695
|
+
//# sourceMappingURL=chunk-33QUGCOZ.js.map
|