circle-ir-ai 4.36.0 → 4.37.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/CHANGELOG.md +27 -0
- package/dist/blast-radius/index.d.ts +15 -3
- package/dist/blast-radius/index.d.ts.map +1 -1
- package/dist/blast-radius/index.js +34 -5
- package/dist/blast-radius/index.js.map +1 -1
- package/dist/blast-radius/radius.d.ts +28 -4
- package/dist/blast-radius/radius.d.ts.map +1 -1
- package/dist/blast-radius/radius.js +58 -4
- package/dist/blast-radius/radius.js.map +1 -1
- package/dist/blast-radius/types.d.ts +27 -0
- package/dist/blast-radius/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/llm/ax-client.d.ts.map +1 -1
- package/dist/llm/ax-client.js +4 -0
- package/dist/llm/ax-client.js.map +1 -1
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +3 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/model-route-dispatcher.d.ts +64 -0
- package/dist/llm/model-route-dispatcher.d.ts.map +1 -0
- package/dist/llm/model-route-dispatcher.js +115 -0
- package/dist/llm/model-route-dispatcher.js.map +1 -0
- package/dist/llm/model-route.d.ts +33 -4
- package/dist/llm/model-route.d.ts.map +1 -1
- package/dist/llm/model-route.js +100 -12
- package/dist/llm/model-route.js.map +1 -1
- package/dist/llm/non-public-address.d.ts +37 -0
- package/dist/llm/non-public-address.d.ts.map +1 -0
- package/dist/llm/non-public-address.js +155 -0
- package/dist/llm/non-public-address.js.map +1 -0
- package/dist/mcp/tools/blast-radius.d.ts.map +1 -1
- package/dist/mcp/tools/blast-radius.js +13 -1
- package/dist/mcp/tools/blast-radius.js.map +1 -1
- package/dist/scope/product-paths.d.ts +16 -8
- package/dist/scope/product-paths.d.ts.map +1 -1
- package/dist/scope/product-paths.js +10 -10
- package/dist/scope/product-paths.js.map +1 -1
- package/dist/security-scan/scanner.d.ts +7 -0
- package/dist/security-scan/scanner.d.ts.map +1 -1
- package/dist/security-scan/scanner.js +54 -14
- package/dist/security-scan/scanner.js.map +1 -1
- package/dist/specifica/index.d.ts +3 -2
- package/dist/specifica/index.d.ts.map +1 -1
- package/dist/specifica/index.js +3 -1
- package/dist/specifica/index.js.map +1 -1
- package/dist/specifica/learned-tree.d.ts +8 -0
- package/dist/specifica/learned-tree.d.ts.map +1 -1
- package/dist/specifica/learned-tree.js.map +1 -1
- package/dist/specifica/level-design.d.ts +7 -0
- package/dist/specifica/level-design.d.ts.map +1 -1
- package/dist/specifica/level-design.js +11 -4
- package/dist/specifica/level-design.js.map +1 -1
- package/dist/specifica/modules.d.ts +31 -1
- package/dist/specifica/modules.d.ts.map +1 -1
- package/dist/specifica/modules.js +48 -0
- package/dist/specifica/modules.js.map +1 -1
- package/dist/specifica/spec-tree.d.ts +5 -2
- package/dist/specifica/spec-tree.d.ts.map +1 -1
- package/dist/specifica/spec-tree.js +75 -47
- package/dist/specifica/spec-tree.js.map +1 -1
- package/dist/specifica/tree-types.d.ts +40 -0
- package/dist/specifica/tree-types.d.ts.map +1 -1
- package/dist/specifica/tree-types.js +5 -0
- package/dist/specifica/tree-types.js.map +1 -1
- package/dist/specifica/tree-writer.d.ts +7 -2
- package/dist/specifica/tree-writer.d.ts.map +1 -1
- package/dist/specifica/tree-writer.js +10 -3
- package/dist/specifica/tree-writer.js.map +1 -1
- package/dist/trust/passes/ai-generated-fingerprint.d.ts +2 -1
- package/dist/trust/passes/ai-generated-fingerprint.d.ts.map +1 -1
- package/dist/trust/passes/ai-generated-fingerprint.js +1 -1
- package/dist/trust/passes/ai-generated-fingerprint.js.map +1 -1
- package/dist/trust/passes/code-complexity.d.ts +2 -1
- package/dist/trust/passes/code-complexity.d.ts.map +1 -1
- package/dist/trust/passes/code-complexity.js +1 -1
- package/dist/trust/passes/code-complexity.js.map +1 -1
- package/dist/trust/passes/cross-skill-interaction.d.ts +2 -1
- package/dist/trust/passes/cross-skill-interaction.d.ts.map +1 -1
- package/dist/trust/passes/cross-skill-interaction.js +1 -1
- package/dist/trust/passes/cross-skill-interaction.js.map +1 -1
- package/dist/trust/passes/data-exfiltration.d.ts +3 -2
- package/dist/trust/passes/data-exfiltration.d.ts.map +1 -1
- package/dist/trust/passes/data-exfiltration.js +3 -3
- package/dist/trust/passes/data-exfiltration.js.map +1 -1
- package/dist/trust/passes/deprecated-usage.d.ts +2 -1
- package/dist/trust/passes/deprecated-usage.d.ts.map +1 -1
- package/dist/trust/passes/deprecated-usage.js +1 -1
- package/dist/trust/passes/deprecated-usage.js.map +1 -1
- package/dist/trust/passes/deprecation-no-replacement.d.ts +2 -1
- package/dist/trust/passes/deprecation-no-replacement.d.ts.map +1 -1
- package/dist/trust/passes/deprecation-no-replacement.js +1 -1
- package/dist/trust/passes/deprecation-no-replacement.js.map +1 -1
- package/dist/trust/passes/doc-coverage.d.ts +2 -1
- package/dist/trust/passes/doc-coverage.d.ts.map +1 -1
- package/dist/trust/passes/doc-coverage.js +1 -1
- package/dist/trust/passes/doc-coverage.js.map +1 -1
- package/dist/trust/passes/inconsistent-error-handling.d.ts +2 -1
- package/dist/trust/passes/inconsistent-error-handling.d.ts.map +1 -1
- package/dist/trust/passes/inconsistent-error-handling.js +1 -1
- package/dist/trust/passes/inconsistent-error-handling.js.map +1 -1
- package/dist/trust/passes/inconsistent-naming.d.ts +2 -1
- package/dist/trust/passes/inconsistent-naming.d.ts.map +1 -1
- package/dist/trust/passes/inconsistent-naming.js +1 -1
- package/dist/trust/passes/inconsistent-naming.js.map +1 -1
- package/dist/trust/passes/inconsistent-param-order.d.ts +2 -1
- package/dist/trust/passes/inconsistent-param-order.d.ts.map +1 -1
- package/dist/trust/passes/inconsistent-param-order.js +1 -1
- package/dist/trust/passes/inconsistent-param-order.js.map +1 -1
- package/dist/trust/passes/missing-guard-dom.d.ts +2 -1
- package/dist/trust/passes/missing-guard-dom.d.ts.map +1 -1
- package/dist/trust/passes/missing-guard-dom.js +6 -6
- package/dist/trust/passes/missing-guard-dom.js.map +1 -1
- package/dist/trust/passes/performance-passes.d.ts +2 -1
- package/dist/trust/passes/performance-passes.d.ts.map +1 -1
- package/dist/trust/passes/performance-passes.js +1 -1
- package/dist/trust/passes/performance-passes.js.map +1 -1
- package/dist/trust/passes/prompt-injection.d.ts +2 -1
- package/dist/trust/passes/prompt-injection.d.ts.map +1 -1
- package/dist/trust/passes/prompt-injection.js +1 -1
- package/dist/trust/passes/prompt-injection.js.map +1 -1
- package/dist/trust/passes/throws-mismatch.d.ts +2 -1
- package/dist/trust/passes/throws-mismatch.d.ts.map +1 -1
- package/dist/trust/passes/throws-mismatch.js +1 -1
- package/dist/trust/passes/throws-mismatch.js.map +1 -1
- package/dist/trust/passes/tool-poisoning.d.ts +2 -1
- package/dist/trust/passes/tool-poisoning.d.ts.map +1 -1
- package/dist/trust/passes/tool-poisoning.js +3 -3
- package/dist/trust/passes/tool-poisoning.js.map +1 -1
- package/dist/trust/passes/unnecessary-object-hotspot.d.ts +2 -1
- package/dist/trust/passes/unnecessary-object-hotspot.d.ts.map +1 -1
- package/dist/trust/passes/unnecessary-object-hotspot.js +1 -1
- package/dist/trust/passes/unnecessary-object-hotspot.js.map +1 -1
- package/dist/utils/analyze-pool.d.ts +7 -6
- package/dist/utils/analyze-pool.d.ts.map +1 -1
- package/dist/utils/analyze-pool.js +77 -7
- package/dist/utils/analyze-pool.js.map +1 -1
- package/package.json +3 -2
package/dist/llm/index.js
CHANGED
|
@@ -23,6 +23,9 @@ export { llmErrorCounter, } from './llm-error-counter.js';
|
|
|
23
23
|
export { checkAndCountCall, resetLLMCallLimiter, withLLMCallScope, isInLLMCallScope, markSwarmStart, markSwarmEnd, clearSwarmFlagForTesting, getLLMCallStats, LLM_CONCURRENCY, LLM_MAX_CALLS_PER_SCAN, LLM_MAX_CALLS_PER_FILE, } from './call-limiter.js';
|
|
24
24
|
// Per-run model route (a host names the endpoint, key and model for one run)
|
|
25
25
|
export { withLLMRoute, isInLLMRoute, getLLMRouteFailure, getLLMRouteStats, llmRouteCacheTag, LLMRouteError, } from './model-route.js';
|
|
26
|
+
// Model route address check (#1073): which addresses a route may not reach,
|
|
27
|
+
// and the local-development switch that lifts it.
|
|
28
|
+
export { isNonPublicAddress, modelRouteAllowsPrivate, MODEL_ROUTE_ALLOW_PRIVATE_ENV, } from './non-public-address.js';
|
|
26
29
|
export { runWithTokenMeter, getContextTokenUsage, recordTokenUsage, } from './token-meter.js';
|
|
27
30
|
// Prompt Security (for robustness against prompt injection)
|
|
28
31
|
export { sanitizeCodeForPrompt, sanitizeListForPrompt, sanitizeObjectForPrompt, wrapUserCode, formatSystemPrompt, formatCodeBlock, getModelPromptConfig, detectModelFamily, isInputSafe, logInjectionAttempt, } from './prompt-security.js';
|
package/dist/llm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,GAGzB,MAAM,aAAa,CAAC;AAErB,uDAAuD;AACvD,OAAO,EACL,WAAW,EACX,cAAc;AACd,aAAa;AACb,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,4BAA4B,EAC5B,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;AAExB,uBAAuB;AACvB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,GAMX,MAAM,iBAAiB,CAAC;AAEzB,yBAAyB;AACzB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,GAO3B,MAAM,mBAAmB,CAAC;AAE3B,uDAAuD;AACvD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAKpB,MAAM,gBAAgB,CAAC;AAExB,sDAAsD;AACtD,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,2BAA2B,EAC3B,gCAAgC,EAChC,cAAc,GAIf,MAAM,uBAAuB,CAAC;AAE/B,qCAAqC;AACrC,OAAO,EACL,eAAe,GAEhB,MAAM,wBAAwB,CAAC;AAEhC,uCAAuC;AACvC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,6EAA6E;AAC7E,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,GAId,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAE1B,4DAA4D;AAC5D,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GAGpB,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,GAGzB,MAAM,aAAa,CAAC;AAErB,uDAAuD;AACvD,OAAO,EACL,WAAW,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C,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAE1B,4DAA4D;AAC5D,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GAGpB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection every model-route request goes through (#1073).
|
|
3
|
+
*
|
|
4
|
+
* The route's base URL can be an endpoint an organisation's admin typed, and
|
|
5
|
+
* a name that looks public can resolve (or rebind, after the gateway tested
|
|
6
|
+
* the key) to the engine host's own network. So the check runs on the
|
|
7
|
+
* address the engine actually connects to: an undici `Agent` whose
|
|
8
|
+
* `connect.lookup` resolves the name and refuses it when any address it
|
|
9
|
+
* resolves to is non-public (`isNonPublicAddress`: loopback, RFC 1918,
|
|
10
|
+
* link-local, CGNAT, ULA, unspecified, multicast, reserved, and the mapped /
|
|
11
|
+
* NAT64 forms of those). The refusal fails the connection before a byte is
|
|
12
|
+
* sent, with an error whose `code` is `ERR_MODEL_ROUTE_NON_PUBLIC_ADDRESS`.
|
|
13
|
+
* An IP-literal host is never looked up, so the route fetch checks a literal
|
|
14
|
+
* itself before it connects (`model-route.ts`).
|
|
15
|
+
*
|
|
16
|
+
* The dispatcher is handed to the built-in `fetch` (`init.dispatcher`). The
|
|
17
|
+
* built-in fetch is undici too, but of the version bundled with Node (6.x on
|
|
18
|
+
* Node 22, 7.x on Node 24, 8.x on Node 26), and Node 22's fetch speaks the
|
|
19
|
+
* older handler interface that an undici 8 `Agent` no longer accepts. The
|
|
20
|
+
* agent is therefore wrapped in undici's own `Dispatcher1Wrapper`, which takes
|
|
21
|
+
* both interfaces (and forces HTTP/1.1 for the older one). undici is loaded
|
|
22
|
+
* only when a routed call is made.
|
|
23
|
+
*
|
|
24
|
+
* `MODEL_ROUTE_ALLOW_PRIVATE=1` (local development only) lets the lookup
|
|
25
|
+
* return non-public addresses.
|
|
26
|
+
*/
|
|
27
|
+
import type { LookupFunction } from 'node:net';
|
|
28
|
+
import type { Dispatcher } from 'undici';
|
|
29
|
+
/** `code` of the error a refused connection fails with. */
|
|
30
|
+
export declare const NON_PUBLIC_ADDRESS_CODE = "ERR_MODEL_ROUTE_NON_PUBLIC_ADDRESS";
|
|
31
|
+
/**
|
|
32
|
+
* The model route's host is, or resolves to, a non-public address, so the
|
|
33
|
+
* engine does not connect to it. Key-free: names the host only, never the
|
|
34
|
+
* address, the URL path or the key.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ModelRouteAddressError extends Error {
|
|
37
|
+
readonly code = "ERR_MODEL_ROUTE_NON_PUBLIC_ADDRESS";
|
|
38
|
+
constructor(host: string);
|
|
39
|
+
}
|
|
40
|
+
/** True when `err`, or an error it wraps (`cause`, `errors`), is a refused non-public address. */
|
|
41
|
+
export declare function isNonPublicAddressRefusal(err: unknown, depth?: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Wrap a `dns.lookup`-shaped function so that a name resolving to any
|
|
44
|
+
* non-public address fails with `ModelRouteAddressError` (unless
|
|
45
|
+
* `MODEL_ROUTE_ALLOW_PRIVATE` is on, read on every lookup). Refuses the name
|
|
46
|
+
* when any of its addresses is non-public, not just the one picked: a name
|
|
47
|
+
* that mixes public and private records is not a model endpoint. Answers in
|
|
48
|
+
* whichever shape the caller asked for (`all: true` from `net.connect` with
|
|
49
|
+
* `autoSelectFamily`, or a single address).
|
|
50
|
+
*/
|
|
51
|
+
export declare function guardModelRouteLookup(base?: LookupFunction): LookupFunction;
|
|
52
|
+
export interface ModelRouteDispatcherOptions {
|
|
53
|
+
/** Base resolver (default `dns.lookup`); tests pass a fake. The guard wraps it. */
|
|
54
|
+
lookup?: LookupFunction;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A new dispatcher for model-route requests: an undici `Agent` with the
|
|
58
|
+
* guarded lookup, wrapped so any Node's built-in fetch can use it. Resolves
|
|
59
|
+
* once undici is loaded.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createModelRouteDispatcher(options?: ModelRouteDispatcherOptions): Promise<Dispatcher>;
|
|
62
|
+
/** The process's model-route dispatcher (one connection pool for every route), created on first use. */
|
|
63
|
+
export declare function modelRouteDispatcher(): Promise<Dispatcher>;
|
|
64
|
+
//# sourceMappingURL=model-route-dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-route-dispatcher.d.ts","sourceRoot":"","sources":["../../src/llm/model-route-dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,2DAA2D;AAC3D,eAAO,MAAM,uBAAuB,uCAAuC,CAAC;AAE5E;;;;GAIG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,wCAA2B;IACxC,YAAY,IAAI,EAAE,MAAM,EAGvB;CACF;AAED,kGAAkG;AAClG,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAM1E;AAID;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,GAAE,cAAwD,GAAG,cAAc,CA4BpH;AAED,MAAM,WAAW,2BAA2B;IAC1C,mFAAmF;IACnF,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,GAAE,2BAAgC,GAAG,OAAO,CAAC,UAAU,CAAC,CAI/G;AAID,wGAAwG;AACxG,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,UAAU,CAAC,CAU1D"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection every model-route request goes through (#1073).
|
|
3
|
+
*
|
|
4
|
+
* The route's base URL can be an endpoint an organisation's admin typed, and
|
|
5
|
+
* a name that looks public can resolve (or rebind, after the gateway tested
|
|
6
|
+
* the key) to the engine host's own network. So the check runs on the
|
|
7
|
+
* address the engine actually connects to: an undici `Agent` whose
|
|
8
|
+
* `connect.lookup` resolves the name and refuses it when any address it
|
|
9
|
+
* resolves to is non-public (`isNonPublicAddress`: loopback, RFC 1918,
|
|
10
|
+
* link-local, CGNAT, ULA, unspecified, multicast, reserved, and the mapped /
|
|
11
|
+
* NAT64 forms of those). The refusal fails the connection before a byte is
|
|
12
|
+
* sent, with an error whose `code` is `ERR_MODEL_ROUTE_NON_PUBLIC_ADDRESS`.
|
|
13
|
+
* An IP-literal host is never looked up, so the route fetch checks a literal
|
|
14
|
+
* itself before it connects (`model-route.ts`).
|
|
15
|
+
*
|
|
16
|
+
* The dispatcher is handed to the built-in `fetch` (`init.dispatcher`). The
|
|
17
|
+
* built-in fetch is undici too, but of the version bundled with Node (6.x on
|
|
18
|
+
* Node 22, 7.x on Node 24, 8.x on Node 26), and Node 22's fetch speaks the
|
|
19
|
+
* older handler interface that an undici 8 `Agent` no longer accepts. The
|
|
20
|
+
* agent is therefore wrapped in undici's own `Dispatcher1Wrapper`, which takes
|
|
21
|
+
* both interfaces (and forces HTTP/1.1 for the older one). undici is loaded
|
|
22
|
+
* only when a routed call is made.
|
|
23
|
+
*
|
|
24
|
+
* `MODEL_ROUTE_ALLOW_PRIVATE=1` (local development only) lets the lookup
|
|
25
|
+
* return non-public addresses.
|
|
26
|
+
*/
|
|
27
|
+
import dns from 'node:dns';
|
|
28
|
+
import { isNonPublicAddress, modelRouteAllowsPrivate } from './non-public-address.js';
|
|
29
|
+
/** `code` of the error a refused connection fails with. */
|
|
30
|
+
export const NON_PUBLIC_ADDRESS_CODE = 'ERR_MODEL_ROUTE_NON_PUBLIC_ADDRESS';
|
|
31
|
+
/**
|
|
32
|
+
* The model route's host is, or resolves to, a non-public address, so the
|
|
33
|
+
* engine does not connect to it. Key-free: names the host only, never the
|
|
34
|
+
* address, the URL path or the key.
|
|
35
|
+
*/
|
|
36
|
+
export class ModelRouteAddressError extends Error {
|
|
37
|
+
code = NON_PUBLIC_ADDRESS_CODE;
|
|
38
|
+
constructor(host) {
|
|
39
|
+
super(`The model route host ${host} is or resolves to a non-public address; the engine does not connect to it.`);
|
|
40
|
+
this.name = 'ModelRouteAddressError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** True when `err`, or an error it wraps (`cause`, `errors`), is a refused non-public address. */
|
|
44
|
+
export function isNonPublicAddressRefusal(err, depth = 0) {
|
|
45
|
+
if (!err || typeof err !== 'object' || depth > 4)
|
|
46
|
+
return false;
|
|
47
|
+
const e = err;
|
|
48
|
+
if (e.code === NON_PUBLIC_ADDRESS_CODE)
|
|
49
|
+
return true;
|
|
50
|
+
if (isNonPublicAddressRefusal(e.cause, depth + 1))
|
|
51
|
+
return true;
|
|
52
|
+
return Array.isArray(e.errors) && e.errors.some((x) => isNonPublicAddressRefusal(x, depth + 1));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Wrap a `dns.lookup`-shaped function so that a name resolving to any
|
|
56
|
+
* non-public address fails with `ModelRouteAddressError` (unless
|
|
57
|
+
* `MODEL_ROUTE_ALLOW_PRIVATE` is on, read on every lookup). Refuses the name
|
|
58
|
+
* when any of its addresses is non-public, not just the one picked: a name
|
|
59
|
+
* that mixes public and private records is not a model endpoint. Answers in
|
|
60
|
+
* whichever shape the caller asked for (`all: true` from `net.connect` with
|
|
61
|
+
* `autoSelectFamily`, or a single address).
|
|
62
|
+
*/
|
|
63
|
+
export function guardModelRouteLookup(base = dns.lookup) {
|
|
64
|
+
return (hostname, options, callback) => {
|
|
65
|
+
const opts = typeof options === 'object' && options !== null ? options : {};
|
|
66
|
+
const cb = typeof options === 'function' ? options : callback;
|
|
67
|
+
base(hostname, { ...opts, all: true }, (err, addresses, family) => {
|
|
68
|
+
if (err) {
|
|
69
|
+
cb(err, '');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const list = Array.isArray(addresses)
|
|
73
|
+
? addresses
|
|
74
|
+
: [{ address: addresses, family: family ?? (addresses.includes(':') ? 6 : 4) }];
|
|
75
|
+
if (list.length === 0) {
|
|
76
|
+
cb(Object.assign(new Error(`getaddrinfo ENOTFOUND ${hostname}`), { code: 'ENOTFOUND', hostname }), '');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!modelRouteAllowsPrivate() && list.some((a) => isNonPublicAddress(a.address))) {
|
|
80
|
+
cb(new ModelRouteAddressError(hostname), '');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (opts.all) {
|
|
84
|
+
cb(null, list);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const pick = (opts.family ? list.find((a) => a.family === opts.family) : undefined) ?? list[0];
|
|
88
|
+
cb(null, pick.address, pick.family);
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A new dispatcher for model-route requests: an undici `Agent` with the
|
|
94
|
+
* guarded lookup, wrapped so any Node's built-in fetch can use it. Resolves
|
|
95
|
+
* once undici is loaded.
|
|
96
|
+
*/
|
|
97
|
+
export async function createModelRouteDispatcher(options = {}) {
|
|
98
|
+
const { Agent, Dispatcher1Wrapper } = await import('undici');
|
|
99
|
+
const agent = new Agent({ connect: { lookup: guardModelRouteLookup(options.lookup) } });
|
|
100
|
+
return new Dispatcher1Wrapper(agent);
|
|
101
|
+
}
|
|
102
|
+
let shared;
|
|
103
|
+
/** The process's model-route dispatcher (one connection pool for every route), created on first use. */
|
|
104
|
+
export function modelRouteDispatcher() {
|
|
105
|
+
if (!shared) {
|
|
106
|
+
shared = createModelRouteDispatcher();
|
|
107
|
+
// A failed load is not cached: the next routed call tries again (and
|
|
108
|
+
// fails closed, as an unreachable route, until it loads).
|
|
109
|
+
shared.catch(() => {
|
|
110
|
+
shared = undefined;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return shared;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=model-route-dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-route-dispatcher.js","sourceRoot":"","sources":["../../src/llm/model-route-dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,GAAG,MAAM,UAAU,CAAC;AAG3B,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEtF,2DAA2D;AAC3D,MAAM,CAAC,MAAM,uBAAuB,GAAG,oCAAoC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,IAAI,GAAG,uBAAuB,CAAC;IACxC,YAAY,IAAY;QACtB,KAAK,CAAC,wBAAwB,IAAI,6EAA6E,CAAC,CAAC;QACjH,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,kGAAkG;AAClG,MAAM,UAAU,yBAAyB,CAAC,GAAY,EAAE,KAAK,GAAG,CAAC;IAC/D,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/D,MAAM,CAAC,GAAG,GAA4D,CAAC;IACvE,IAAI,CAAC,CAAC,IAAI,KAAK,uBAAuB;QAAE,OAAO,IAAI,CAAC;IACpD,IAAI,yBAAyB,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,C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AC;QACtC,qEAAqE;QACrE,0DAA0D;QAC1D,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,MAAM,GAAG,SAAS,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -18,7 +18,16 @@
|
|
|
18
18
|
* LLM passes fail open (a failed call falls back to static analysis), so a
|
|
19
19
|
* route failure does not throw out of the passes. The scope records it, and
|
|
20
20
|
* the host asks `getLLMRouteFailure()` when the run ends and fails the step.
|
|
21
|
+
*
|
|
22
|
+
* The route's endpoint may be one an organisation typed, so the engine's
|
|
23
|
+
* request never leaves it (#1073): a redirect is never followed (it fails the
|
|
24
|
+
* run, and no second request goes out), and every request connects through
|
|
25
|
+
* a dispatcher that refuses loopback, private, link-local and other
|
|
26
|
+
* non-public addresses, checked on the address actually connected
|
|
27
|
+
* (`model-route-dispatcher.ts`). `MODEL_ROUTE_ALLOW_PRIVATE=1` lifts the
|
|
28
|
+
* address check for local development only.
|
|
21
29
|
*/
|
|
30
|
+
import type { Dispatcher } from 'undici';
|
|
22
31
|
/** One run's model endpoint (OpenAI-compatible chat completions). */
|
|
23
32
|
export interface LLMRoute {
|
|
24
33
|
/** OpenAI-compatible base URL, e.g. `https://gateway.example/v1`. */
|
|
@@ -32,8 +41,12 @@ export interface LLMRoute {
|
|
|
32
41
|
* Why a routed run's model calls failed.
|
|
33
42
|
* - `auth`: the endpoint refused the key (HTTP 401 or 403).
|
|
34
43
|
* - `not_found`: the endpoint or the model does not exist (HTTP 404).
|
|
35
|
-
* - `http_error`: every call failed with another HTTP status
|
|
36
|
-
*
|
|
44
|
+
* - `http_error`: every call failed with another HTTP status, or the
|
|
45
|
+
* endpoint answered with a redirect (3xx; `status` is the redirect's). A
|
|
46
|
+
* redirect is never followed and fails the run at once.
|
|
47
|
+
* - `unreachable`: every call failed to connect, or the route's host is or
|
|
48
|
+
* resolves to a non-public address (loopback, private, link-local, CGNAT,
|
|
49
|
+
* ULA, …), which fails the run at once and is never connected to.
|
|
37
50
|
* - `timeout`: every call timed out.
|
|
38
51
|
* - `misrouted`: a model client built outside this run (or for another
|
|
39
52
|
* run) was used inside it. The call was refused before any request went
|
|
@@ -61,7 +74,10 @@ export interface LLMRouteState {
|
|
|
61
74
|
* one-way fingerprint of the key (never the key). See `llmRouteCacheTag`.
|
|
62
75
|
*/
|
|
63
76
|
readonly cacheTag: string;
|
|
64
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* First fatal failure (refused key, unknown model, misrouted client, a
|
|
79
|
+
* redirect, a non-public address). Later calls short-circuit.
|
|
80
|
+
*/
|
|
65
81
|
fatal?: LLMRouteFailure;
|
|
66
82
|
/** Last non-fatal failure, reported only if no call ever succeeded. */
|
|
67
83
|
lastFailure?: LLMRouteFailure;
|
|
@@ -122,14 +138,27 @@ export declare function getLLMRouteStats(): {
|
|
|
122
138
|
succeeded: number;
|
|
123
139
|
failed: number;
|
|
124
140
|
} | undefined;
|
|
141
|
+
/** Options for `makeRouteFetch`; tests only. */
|
|
142
|
+
export interface RouteFetchOptions {
|
|
143
|
+
/** Dispatcher for the route's requests (default: the shared, address-checking one). */
|
|
144
|
+
dispatcher?: Dispatcher;
|
|
145
|
+
}
|
|
125
146
|
/**
|
|
126
147
|
* @internal A `fetch` bound to one route record: refuses any URL outside the
|
|
127
148
|
* route, counts outcomes, records failures, short-circuits once the key was
|
|
128
149
|
* refused, and strips error bodies so a provider's echo of the key never
|
|
129
150
|
* reaches a log. Bound at client construction because the LLM queue runs
|
|
130
151
|
* calls outside the caller's async context.
|
|
152
|
+
*
|
|
153
|
+
* Every request goes out with `redirect: 'manual'` and the address-checking
|
|
154
|
+
* dispatcher (#1073). A 3xx answer is a fatal route failure (`http_error`,
|
|
155
|
+
* the redirect's status): nothing follows it, so neither the prompt nor the
|
|
156
|
+
* key reaches the `Location`. A host that is or resolves to a non-public
|
|
157
|
+
* address is a fatal `unreachable` failure, refused before it is connected
|
|
158
|
+
* to. `MODEL_ROUTE_ALLOW_PRIVATE=1` (local development only) allows such
|
|
159
|
+
* addresses.
|
|
131
160
|
*/
|
|
132
|
-
export declare function makeRouteFetch(state: LLMRouteState): typeof fetch;
|
|
161
|
+
export declare function makeRouteFetch(state: LLMRouteState, options?: RouteFetchOptions): typeof fetch;
|
|
133
162
|
/**
|
|
134
163
|
* @internal Snapshot the current route (or its absence) so a task run later
|
|
135
164
|
* in another async context — the shared LLM queue runs a task in whichever
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-route.d.ts","sourceRoot":"","sources":["../../src/llm/model-route.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"model-route.d.ts","sourceRoot":"","sources":["../../src/llm/model-route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAKzC,qEAAqE;AACrE,MAAM,WAAW,QAAQ;IACvB,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,WAAW,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,GAAG,WAAW,CAAC;AAEhH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4EAA4E;AAC5E,qBAAa,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QA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eAAe,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAGvD"}
|
package/dist/llm/model-route.js
CHANGED
|
@@ -18,10 +18,21 @@
|
|
|
18
18
|
* LLM passes fail open (a failed call falls back to static analysis), so a
|
|
19
19
|
* route failure does not throw out of the passes. The scope records it, and
|
|
20
20
|
* the host asks `getLLMRouteFailure()` when the run ends and fails the step.
|
|
21
|
+
*
|
|
22
|
+
* The route's endpoint may be one an organisation typed, so the engine's
|
|
23
|
+
* request never leaves it (#1073): a redirect is never followed (it fails the
|
|
24
|
+
* run, and no second request goes out), and every request connects through
|
|
25
|
+
* a dispatcher that refuses loopback, private, link-local and other
|
|
26
|
+
* non-public addresses, checked on the address actually connected
|
|
27
|
+
* (`model-route-dispatcher.ts`). `MODEL_ROUTE_ALLOW_PRIVATE=1` lifts the
|
|
28
|
+
* address check for local development only.
|
|
21
29
|
*/
|
|
22
30
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
23
31
|
import { createHash } from 'node:crypto';
|
|
32
|
+
import { isIP } from 'node:net';
|
|
24
33
|
import { withLLMCallScope } from './call-limiter.js';
|
|
34
|
+
import { isNonPublicAddressRefusal, ModelRouteAddressError, modelRouteDispatcher } from './model-route-dispatcher.js';
|
|
35
|
+
import { isNonPublicAddress, modelRouteAllowsPrivate } from './non-public-address.js';
|
|
25
36
|
/** Thrown for an unusable route (bad URL, empty key or model). Key-free. */
|
|
26
37
|
export class LLMRouteError extends Error {
|
|
27
38
|
constructor(message) {
|
|
@@ -174,13 +185,43 @@ function failure(state, kind, status) {
|
|
|
174
185
|
: `${at} could not be reached.`;
|
|
175
186
|
return { kind, ...(status !== undefined ? { status } : {}), message };
|
|
176
187
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
188
|
+
function redirectFailure(state, status) {
|
|
189
|
+
const http = status !== undefined ? ` (HTTP ${status})` : '';
|
|
190
|
+
return {
|
|
191
|
+
kind: 'http_error',
|
|
192
|
+
...(status !== undefined ? { status } : {}),
|
|
193
|
+
message: `The model route (${state.host}) answered with a redirect${http}; redirects are not followed.`,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function nonPublicFailure(state) {
|
|
197
|
+
return {
|
|
198
|
+
kind: 'unreachable',
|
|
199
|
+
message: `The model route (${state.host}) is or resolves to a non-public address (loopback, private, link-local or similar); the engine does not connect to it.`,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* A key-free error response carrying `f`'s message, with the endpoint's own
|
|
204
|
+
* status when there was an answer (else `f`'s, else 401). Statuses that
|
|
205
|
+
* cannot carry a body (304) get none.
|
|
206
|
+
*/
|
|
207
|
+
function keyFreeFailureResponse(f, res) {
|
|
208
|
+
const status = res?.status && res.status >= 200 && res.status <= 599 ? res.status : (f.status ?? 401);
|
|
209
|
+
const statusText = res?.status === status ? res.statusText : undefined;
|
|
210
|
+
const nullBody = status === 204 || status === 205 || status === 304;
|
|
211
|
+
return new Response(nullBody ? null : JSON.stringify({ error: { message: f.message } }), {
|
|
212
|
+
status,
|
|
213
|
+
...(statusText !== undefined ? { statusText } : {}),
|
|
181
214
|
headers: { 'Content-Type': 'application/json' },
|
|
182
215
|
});
|
|
183
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* The connection-class error a refused address fails with, the shape the
|
|
219
|
+
* built-in fetch gives (`TypeError('fetch failed')` with the cause), so the
|
|
220
|
+
* LLM client takes its usual connection-failure path (static fallback).
|
|
221
|
+
*/
|
|
222
|
+
function nonPublicConnectError(state) {
|
|
223
|
+
return new TypeError('fetch failed', { cause: new ModelRouteAddressError(state.host) });
|
|
224
|
+
}
|
|
184
225
|
function requestUrl(input) {
|
|
185
226
|
if (typeof input === 'string')
|
|
186
227
|
return input;
|
|
@@ -188,15 +229,40 @@ function requestUrl(input) {
|
|
|
188
229
|
return input.href;
|
|
189
230
|
return input.url;
|
|
190
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* True when the route's host is an IP literal in a non-public range. A
|
|
234
|
+
* literal is never looked up, so the dispatcher's lookup cannot see it; the
|
|
235
|
+
* route fetch checks it before connecting.
|
|
236
|
+
*/
|
|
237
|
+
function routeHostIsNonPublicLiteral(state) {
|
|
238
|
+
let hostname;
|
|
239
|
+
try {
|
|
240
|
+
hostname = new URL(state.route.baseUrl).hostname;
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
const bare = hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
246
|
+
return isIP(bare) !== 0 && isNonPublicAddress(bare);
|
|
247
|
+
}
|
|
191
248
|
/**
|
|
192
249
|
* @internal A `fetch` bound to one route record: refuses any URL outside the
|
|
193
250
|
* route, counts outcomes, records failures, short-circuits once the key was
|
|
194
251
|
* refused, and strips error bodies so a provider's echo of the key never
|
|
195
252
|
* reaches a log. Bound at client construction because the LLM queue runs
|
|
196
253
|
* calls outside the caller's async context.
|
|
254
|
+
*
|
|
255
|
+
* Every request goes out with `redirect: 'manual'` and the address-checking
|
|
256
|
+
* dispatcher (#1073). A 3xx answer is a fatal route failure (`http_error`,
|
|
257
|
+
* the redirect's status): nothing follows it, so neither the prompt nor the
|
|
258
|
+
* key reaches the `Location`. A host that is or resolves to a non-public
|
|
259
|
+
* address is a fatal `unreachable` failure, refused before it is connected
|
|
260
|
+
* to. `MODEL_ROUTE_ALLOW_PRIVATE=1` (local development only) allows such
|
|
261
|
+
* addresses.
|
|
197
262
|
*/
|
|
198
|
-
export function makeRouteFetch(state) {
|
|
263
|
+
export function makeRouteFetch(state, options = {}) {
|
|
199
264
|
const prefix = state.route.baseUrl + '/';
|
|
265
|
+
const literalNonPublic = routeHostIsNonPublicLiteral(state);
|
|
200
266
|
return async (input, init) => {
|
|
201
267
|
const url = requestUrl(input);
|
|
202
268
|
if (url !== state.route.baseUrl && !url.startsWith(prefix)) {
|
|
@@ -204,21 +270,43 @@ export function makeRouteFetch(state) {
|
|
|
204
270
|
}
|
|
205
271
|
if (state.fatal) {
|
|
206
272
|
state.failed++;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
273
|
+
if (state.fatal.kind === 'unreachable')
|
|
274
|
+
throw nonPublicConnectError(state);
|
|
275
|
+
return keyFreeFailureResponse(state.fatal);
|
|
276
|
+
}
|
|
277
|
+
if (literalNonPublic && !modelRouteAllowsPrivate()) {
|
|
278
|
+
state.failed++;
|
|
279
|
+
state.fatal = nonPublicFailure(state);
|
|
280
|
+
throw nonPublicConnectError(state);
|
|
211
281
|
}
|
|
212
282
|
let res;
|
|
213
283
|
try {
|
|
214
|
-
|
|
284
|
+
const dispatcher = options.dispatcher ?? (await modelRouteDispatcher());
|
|
285
|
+
// `dispatcher` is undici's extension to RequestInit, honoured by Node's fetch.
|
|
286
|
+
res = await globalThis.fetch(input, { ...init, redirect: 'manual', dispatcher });
|
|
215
287
|
}
|
|
216
288
|
catch (err) {
|
|
217
289
|
state.failed++;
|
|
290
|
+
if (isNonPublicAddressRefusal(err)) {
|
|
291
|
+
state.fatal ??= nonPublicFailure(state);
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
218
294
|
const aborted = err instanceof Error && err.name === 'AbortError';
|
|
219
295
|
state.lastFailure = failure(state, aborted ? 'timeout' : 'unreachable');
|
|
220
296
|
throw err;
|
|
221
297
|
}
|
|
298
|
+
if (res.type === 'opaqueredirect' || (res.status >= 300 && res.status < 400)) {
|
|
299
|
+
state.failed++;
|
|
300
|
+
state.fatal ??= redirectFailure(state, res.status >= 300 ? res.status : undefined);
|
|
301
|
+
// Do not read what the redirect carries; free the connection.
|
|
302
|
+
try {
|
|
303
|
+
await res.body?.cancel();
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
/* already closed */
|
|
307
|
+
}
|
|
308
|
+
return keyFreeFailureResponse(state.fatal, res);
|
|
309
|
+
}
|
|
222
310
|
if (res.ok) {
|
|
223
311
|
state.succeeded++;
|
|
224
312
|
return res;
|
|
@@ -226,11 +314,11 @@ export function makeRouteFetch(state) {
|
|
|
226
314
|
state.failed++;
|
|
227
315
|
if (res.status === 401 || res.status === 403) {
|
|
228
316
|
state.fatal ??= failure(state, 'auth', res.status);
|
|
229
|
-
return
|
|
317
|
+
return keyFreeFailureResponse(state.fatal, res);
|
|
230
318
|
}
|
|
231
319
|
if (res.status === 404) {
|
|
232
320
|
state.fatal ??= failure(state, 'not_found', res.status);
|
|
233
|
-
return
|
|
321
|
+
return keyFreeFailureResponse(state.fatal, res);
|
|
234
322
|
}
|
|
235
323
|
const f = failure(state, 'http_error', res.status);
|
|
236
324
|
state.lastFailure = f;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-route.js","sourceRoot":"","sources":["../../src/llm/model-route.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"model-route.js","sourceRoot":"","sources":["../../src/llm/model-route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACtH,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAsCtF,4EAA4E;AAC5E,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAsBD,MAAM,YAAY,GAAG,IAAI,iBAAiB,EAA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AAC,GAAG,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QACnD,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC;QACtB,0EAA0E;QAC1E,6CAA6C;QAC7C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACzC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACjC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACnC,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1F,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-public network addresses, for the model route (#1073).
|
|
3
|
+
*
|
|
4
|
+
* A model route's base URL can be an endpoint an organisation's admin typed.
|
|
5
|
+
* The engine must not let it reach the engine host's own network: loopback,
|
|
6
|
+
* private (RFC 1918), link-local (169.254/16, which holds cloud metadata, and
|
|
7
|
+
* fe80::/10), shared CGNAT space (100.64/10), unique-local IPv6 (fc00::/7),
|
|
8
|
+
* unspecified, multicast, reserved and documentation ranges, and the
|
|
9
|
+
* IPv4-mapped, IPv4-translated, IPv4-compatible, NAT64 and 6to4 forms of
|
|
10
|
+
* those. A NAT64 or mapped form of a public IPv4 address is public.
|
|
11
|
+
*
|
|
12
|
+
* `MODEL_ROUTE_ALLOW_PRIVATE=1` lifts the refusal, for local development only
|
|
13
|
+
* (a model server on the developer's own machine). Only the exact value `1`
|
|
14
|
+
* turns it on: this switch turns a safety check off, so `true`, `yes`, `on`,
|
|
15
|
+
* ` 1` or anything else leaves the check on. Off by default; never set it on
|
|
16
|
+
* a deployed engine.
|
|
17
|
+
*
|
|
18
|
+
* circle-pack keeps a byte-identical copy (`src/api/non-public-address.ts`)
|
|
19
|
+
* for its `model_route` check until it moves to the circle-ir-ai release that
|
|
20
|
+
* exports this file; a test there compares the two.
|
|
21
|
+
*/
|
|
22
|
+
/** The local-development switch: exactly `1` allows non-public route addresses; any other value does not. */
|
|
23
|
+
export declare const MODEL_ROUTE_ALLOW_PRIVATE_ENV = "MODEL_ROUTE_ALLOW_PRIVATE";
|
|
24
|
+
/**
|
|
25
|
+
* True only when `MODEL_ROUTE_ALLOW_PRIVATE` is exactly `1` (local development
|
|
26
|
+
* only). No trimming or case folding: a templated `true` must not quietly
|
|
27
|
+
* turn the guard off. Read on every call.
|
|
28
|
+
*/
|
|
29
|
+
export declare function modelRouteAllowsPrivate(env?: NodeJS.ProcessEnv): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* True when `address` (an IP literal, with or without `[]`) is not a public
|
|
32
|
+
* unicast address: the model route must not connect to it. Anything that is
|
|
33
|
+
* not a valid IP address, and any scoped address (`fe80::1%eth0`), counts as
|
|
34
|
+
* non-public, so a caller that cannot tell refuses.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isNonPublicAddress(address: string): boolean;
|
|
37
|
+
//# sourceMappingURL=non-public-address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-public-address.d.ts","sourceRoot":"","sources":["../../src/llm/non-public-address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,6GAA6G;AAC7G,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAEzE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAErF;AAmGD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAgB3D"}
|