@hop-top/kit 0.5.0-alpha.0 → 0.5.0-alpha.10
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 +262 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-2JV3A7OP.js +1894 -0
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-72XZWQX7.js +504 -0
- package/dist/chunk-ABQSE7AI.js +513 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BLS2OBIQ.js +263 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-GGWJRWWA.js +309 -0
- package/dist/chunk-GHPJJV5L.js +613 -0
- package/dist/chunk-IXVQ62NZ.js +334 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-JZ22ZUFA.js +1131 -0
- package/dist/chunk-K7VCKJ27.js +814 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-MUIQVU6E.js +251 -0
- package/dist/chunk-NLMS7HGP.js +178 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-PSFYJGDG.js +1445 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QPUCXQXT.js +67 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T46YPHKN.js +669 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-WWUKGJB5.js +90 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YGYQUFGY.js +219 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-C5B5tnpA.d.ts +400 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +70 -885
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-DCe1boBz.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +184 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +137 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +18 -322
- package/dist/upgrade-p_zh3pvV.d.ts +102 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +236 -46
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +195 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +297 -0
- package/src/completion.test.ts +256 -145
- package/src/completion.ts +767 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +71 -0
- package/src/index.ts +46 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +222 -0
- package/src/mcp/bridge.ts +291 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/published-types.test.ts +133 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +410 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +142 -0
- package/src/tui/parity.ts +59 -13
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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; }
|
|
2
|
+
|
|
3
|
+
var _chunk4UE5TCMQjs = require('./chunk-4UE5TCMQ.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
7
|
+
|
|
8
|
+
// src/aim.ts
|
|
9
|
+
var aim_exports = {};
|
|
10
|
+
_chunkR5U7XKVJjs.__export.call(void 0, aim_exports, {
|
|
11
|
+
Cache: () => Cache,
|
|
12
|
+
ModelsDevSource: () => ModelsDevSource,
|
|
13
|
+
Registry: () => Registry,
|
|
14
|
+
normalize: () => normalize,
|
|
15
|
+
parseQuery: () => parseQuery
|
|
16
|
+
});
|
|
17
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
18
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
19
|
+
function normalize(m) {
|
|
20
|
+
const n = { ...m };
|
|
21
|
+
n.input = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _ => _.modalities, 'optionalAccess', _2 => _2.input]), () => ( n.input)), () => ( []));
|
|
22
|
+
n.output = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _3 => _3.modalities, 'optionalAccess', _4 => _4.output]), () => ( n.output)), () => ( []));
|
|
23
|
+
n.context = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _5 => _5.limit, 'optionalAccess', _6 => _6.context]), () => ( n.context)), () => ( 0));
|
|
24
|
+
n.maxOutput = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _7 => _7.limit, 'optionalAccess', _8 => _8.output]), () => ( n.maxOutput)), () => ( 0));
|
|
25
|
+
n.costInput = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _9 => _9.cost, 'optionalAccess', _10 => _10.input]), () => ( n.costInput)), () => ( 0));
|
|
26
|
+
n.costOutput = _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _11 => _11.cost, 'optionalAccess', _12 => _12.output]), () => ( n.costOutput)), () => ( 0));
|
|
27
|
+
n.tool_call = _nullishCoalesce(n.tool_call, () => ( false));
|
|
28
|
+
n.reasoning = _nullishCoalesce(n.reasoning, () => ( false));
|
|
29
|
+
n.open_weights = _nullishCoalesce(n.open_weights, () => ( false));
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
function validateProviders(raw) {
|
|
33
|
+
for (const [key, p] of Object.entries(raw)) {
|
|
34
|
+
if (key !== p.id)
|
|
35
|
+
throw new Error(`aim: map key "${key}" != provider.id "${p.id}"`);
|
|
36
|
+
for (const [id, m] of Object.entries(p.models)) {
|
|
37
|
+
const normalized = normalize(m);
|
|
38
|
+
if (!normalized.provider) normalized.provider = key;
|
|
39
|
+
p.models[id] = normalized;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return raw;
|
|
43
|
+
}
|
|
44
|
+
var ModelsDevSource = class {
|
|
45
|
+
constructor(opts) {
|
|
46
|
+
this.url = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _13 => _13.url]), () => ( "https://models.dev/api.json"));
|
|
47
|
+
this.timeout = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _14 => _14.timeout]), () => ( 3e4));
|
|
48
|
+
this.maxSize = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _15 => _15.maxSize]), () => ( 50 * 1024 * 1024));
|
|
49
|
+
}
|
|
50
|
+
doFetch(headers, signal) {
|
|
51
|
+
const ctrl = new AbortController();
|
|
52
|
+
const timer = setTimeout(() => ctrl.abort(), this.timeout);
|
|
53
|
+
if (signal) signal.addEventListener("abort", () => ctrl.abort(), { once: true });
|
|
54
|
+
return { ctrl, timer, promise: globalThis.fetch(this.url, {
|
|
55
|
+
headers,
|
|
56
|
+
signal: ctrl.signal
|
|
57
|
+
}) };
|
|
58
|
+
}
|
|
59
|
+
async readBody(resp) {
|
|
60
|
+
const text = await resp.text();
|
|
61
|
+
if (text.length > this.maxSize)
|
|
62
|
+
throw new Error(`aim: response exceeds max size (${this.maxSize} bytes)`);
|
|
63
|
+
return validateProviders(JSON.parse(text));
|
|
64
|
+
}
|
|
65
|
+
async fetch(signal) {
|
|
66
|
+
const { timer, promise } = this.doFetch({ Accept: "application/json" }, signal);
|
|
67
|
+
try {
|
|
68
|
+
const resp = await promise;
|
|
69
|
+
if (resp.status !== 200)
|
|
70
|
+
throw new Error(`aim: unexpected status ${resp.status} from ${this.url}`);
|
|
71
|
+
return this.readBody(resp);
|
|
72
|
+
} finally {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async fetchWithETag(etag, signal) {
|
|
77
|
+
const hdrs = { Accept: "application/json" };
|
|
78
|
+
if (etag) hdrs["If-None-Match"] = etag;
|
|
79
|
+
const { timer, promise } = this.doFetch(hdrs, signal);
|
|
80
|
+
try {
|
|
81
|
+
const resp = await promise;
|
|
82
|
+
if (resp.status === 304)
|
|
83
|
+
return { providers: null, etag, notModified: true };
|
|
84
|
+
if (resp.status !== 200)
|
|
85
|
+
throw new Error(`aim: unexpected status ${resp.status} from ${this.url}`);
|
|
86
|
+
const providers = await this.readBody(resp);
|
|
87
|
+
return {
|
|
88
|
+
providers,
|
|
89
|
+
notModified: false,
|
|
90
|
+
etag: _nullishCoalesce(resp.headers.get("etag"), () => ( ""))
|
|
91
|
+
};
|
|
92
|
+
} finally {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var DATA_FILE = "providers.json";
|
|
98
|
+
var ETAG_FILE = "etag";
|
|
99
|
+
var LOCK_FILE = ".lock";
|
|
100
|
+
var LOCK_STALE_MS = 3e4;
|
|
101
|
+
var LOCK_POLL_MS = 50;
|
|
102
|
+
var LOCK_TIMEOUT_MS = 1e4;
|
|
103
|
+
function acquireLock(dir) {
|
|
104
|
+
const lockPath = path.join(dir, LOCK_FILE);
|
|
105
|
+
const deadline = Date.now() + LOCK_TIMEOUT_MS;
|
|
106
|
+
while (true) {
|
|
107
|
+
try {
|
|
108
|
+
fs.writeFileSync(lockPath, String(process.pid), { flag: "wx" });
|
|
109
|
+
return;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
try {
|
|
112
|
+
const stat = fs.statSync(lockPath);
|
|
113
|
+
if (Date.now() - stat.mtimeMs > LOCK_STALE_MS) {
|
|
114
|
+
fs.unlinkSync(lockPath);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
} catch (e2) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (Date.now() >= deadline)
|
|
121
|
+
throw new Error("aim: lock acquisition timed out");
|
|
122
|
+
const until = Date.now() + LOCK_POLL_MS;
|
|
123
|
+
while (Date.now() < until) {
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function releaseLock(dir) {
|
|
129
|
+
try {
|
|
130
|
+
fs.unlinkSync(path.join(dir, LOCK_FILE));
|
|
131
|
+
} catch (e3) {
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
var Cache = class {
|
|
135
|
+
constructor(src, opts) {
|
|
136
|
+
this.src = src;
|
|
137
|
+
this.ttl = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _16 => _16.ttl]), () => ( 864e5));
|
|
138
|
+
this.dir = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _17 => _17.dir]), () => ( path.join(_chunk4UE5TCMQjs.cacheDir.call(void 0, ""), "hop/aim")));
|
|
139
|
+
}
|
|
140
|
+
async fetch(signal) {
|
|
141
|
+
const env = this.load();
|
|
142
|
+
if (env && Date.now() - new Date(env.fetched_at).getTime() < this.ttl)
|
|
143
|
+
return env.providers;
|
|
144
|
+
try {
|
|
145
|
+
return await this.refresh(signal);
|
|
146
|
+
} catch (e4) {
|
|
147
|
+
if (env) return env.providers;
|
|
148
|
+
throw new Error("aim: fetch failed and no cached data available");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async forceRefresh(signal) {
|
|
152
|
+
return this.refresh(signal);
|
|
153
|
+
}
|
|
154
|
+
async refresh(signal) {
|
|
155
|
+
fs.mkdirSync(this.dir, { recursive: true, mode: 493 });
|
|
156
|
+
acquireLock(this.dir);
|
|
157
|
+
try {
|
|
158
|
+
let providers;
|
|
159
|
+
const src = this.src;
|
|
160
|
+
if (typeof src.fetchWithETag === "function") {
|
|
161
|
+
const etag = this.readFile(ETAG_FILE);
|
|
162
|
+
const r = await src.fetchWithETag(etag, signal);
|
|
163
|
+
if (r.notModified) {
|
|
164
|
+
const env = this.load();
|
|
165
|
+
if (env) {
|
|
166
|
+
env.fetched_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
167
|
+
this.store(env);
|
|
168
|
+
return env.providers;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
providers = await _asyncNullishCoalesce(r.providers, async () => ( await src.fetch(signal)));
|
|
172
|
+
if (r.etag) this.writeFile(ETAG_FILE, r.etag);
|
|
173
|
+
} else {
|
|
174
|
+
providers = await src.fetch(signal);
|
|
175
|
+
}
|
|
176
|
+
this.store({ fetched_at: (/* @__PURE__ */ new Date()).toISOString(), providers });
|
|
177
|
+
return providers;
|
|
178
|
+
} finally {
|
|
179
|
+
releaseLock(this.dir);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
load() {
|
|
183
|
+
try {
|
|
184
|
+
const env = JSON.parse(
|
|
185
|
+
fs.readFileSync(path.join(this.dir, DATA_FILE), "utf-8")
|
|
186
|
+
);
|
|
187
|
+
for (const [key, p] of Object.entries(env.providers)) {
|
|
188
|
+
for (const [id, m] of Object.entries(p.models)) {
|
|
189
|
+
const n = normalize(m);
|
|
190
|
+
if (!n.provider) n.provider = key;
|
|
191
|
+
p.models[id] = n;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return env;
|
|
195
|
+
} catch (e5) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
store(env) {
|
|
200
|
+
const tmp = path.join(this.dir, DATA_FILE + ".tmp");
|
|
201
|
+
fs.writeFileSync(tmp, JSON.stringify(env), { mode: 420 });
|
|
202
|
+
fs.renameSync(tmp, path.join(this.dir, DATA_FILE));
|
|
203
|
+
}
|
|
204
|
+
readFile(name) {
|
|
205
|
+
try {
|
|
206
|
+
return fs.readFileSync(path.join(this.dir, name), "utf-8");
|
|
207
|
+
} catch (e6) {
|
|
208
|
+
return "";
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
writeFile(name, data) {
|
|
212
|
+
const tmp = path.join(this.dir, name + ".tmp");
|
|
213
|
+
try {
|
|
214
|
+
fs.writeFileSync(tmp, data, { mode: 420 });
|
|
215
|
+
fs.renameSync(tmp, path.join(this.dir, name));
|
|
216
|
+
} catch (e7) {
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
function parseQuery(q) {
|
|
221
|
+
const f = {};
|
|
222
|
+
const free = [];
|
|
223
|
+
for (let i = 0, n = q.length; i < n; ) {
|
|
224
|
+
if (q[i] === " " || q[i] === " ") {
|
|
225
|
+
i++;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
let val;
|
|
229
|
+
let quoted = false;
|
|
230
|
+
if (q[i] === '"') {
|
|
231
|
+
const j = q.indexOf('"', i + 1);
|
|
232
|
+
if (j < 0) throw new Error("unterminated quote");
|
|
233
|
+
val = q.slice(i + 1, j);
|
|
234
|
+
quoted = true;
|
|
235
|
+
i = j + 1;
|
|
236
|
+
} else {
|
|
237
|
+
let j = i;
|
|
238
|
+
while (j < n && q[j] !== " " && q[j] !== " ") j++;
|
|
239
|
+
val = q.slice(i, j);
|
|
240
|
+
i = j;
|
|
241
|
+
}
|
|
242
|
+
if (quoted) {
|
|
243
|
+
free.push(val);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const ci = val.indexOf(":");
|
|
247
|
+
if (ci < 0) {
|
|
248
|
+
free.push(val);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const key = val.slice(0, ci), v = val.slice(ci + 1);
|
|
252
|
+
if (key === "") throw new Error(`malformed tag "${val}": missing key`);
|
|
253
|
+
if (v === "") throw new Error(`empty value for tag "${key}"`);
|
|
254
|
+
switch (key) {
|
|
255
|
+
case "provider":
|
|
256
|
+
f.provider = csv(f.provider, v);
|
|
257
|
+
break;
|
|
258
|
+
case "family":
|
|
259
|
+
f.family = csv(f.family, v);
|
|
260
|
+
break;
|
|
261
|
+
case "in":
|
|
262
|
+
f.input = csv(f.input, v);
|
|
263
|
+
break;
|
|
264
|
+
case "out":
|
|
265
|
+
f.output = csv(f.output, v);
|
|
266
|
+
break;
|
|
267
|
+
case "toolcall":
|
|
268
|
+
case "reasoning":
|
|
269
|
+
case "openweights": {
|
|
270
|
+
const b = toBool(v, key);
|
|
271
|
+
if (key === "toolcall") f.toolCall = b;
|
|
272
|
+
else if (key === "reasoning") f.reasoning = b;
|
|
273
|
+
else f.openWeights = b;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
default:
|
|
277
|
+
throw new Error(`unknown tag "${key}"`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (free.length > 0) f.query = free.join(" ");
|
|
281
|
+
return f;
|
|
282
|
+
}
|
|
283
|
+
function toBool(v, tag) {
|
|
284
|
+
if (v === "true") return true;
|
|
285
|
+
if (v === "false") return false;
|
|
286
|
+
throw new Error(`invalid bool value "${v}" for tag "${tag}": must be true or false`);
|
|
287
|
+
}
|
|
288
|
+
function csv(a, b) {
|
|
289
|
+
return a ? a + "," + b : b;
|
|
290
|
+
}
|
|
291
|
+
var Registry = class {
|
|
292
|
+
constructor(opts) {
|
|
293
|
+
this.providers = null;
|
|
294
|
+
const sources = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _18 => _18.sources]), () => ( [new ModelsDevSource()]));
|
|
295
|
+
const merged = {
|
|
296
|
+
async fetch(signal) {
|
|
297
|
+
const r = {};
|
|
298
|
+
for (const s of sources) Object.assign(r, await s.fetch(signal));
|
|
299
|
+
return r;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
this.cache = new Cache(merged, { dir: _optionalChain([opts, 'optionalAccess', _19 => _19.cacheDir]), ttl: _optionalChain([opts, 'optionalAccess', _20 => _20.cacheTTL]) });
|
|
303
|
+
}
|
|
304
|
+
async ensure() {
|
|
305
|
+
if (this.providers) return;
|
|
306
|
+
try {
|
|
307
|
+
this.providers = await this.cache.fetch();
|
|
308
|
+
} catch (e8) {
|
|
309
|
+
this.providers = {};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async refresh() {
|
|
313
|
+
this.providers = await this.cache.forceRefresh();
|
|
314
|
+
}
|
|
315
|
+
async getProviders() {
|
|
316
|
+
await this.ensure();
|
|
317
|
+
return Object.values(this.providers).sort((a, b) => a.id.localeCompare(b.id));
|
|
318
|
+
}
|
|
319
|
+
async models(f) {
|
|
320
|
+
await this.ensure();
|
|
321
|
+
const out = [];
|
|
322
|
+
for (const p of Object.values(this.providers))
|
|
323
|
+
for (const m of Object.values(p.models))
|
|
324
|
+
if (matchesFilter(m, f)) out.push(m);
|
|
325
|
+
out.sort((a, b) => a.provider !== b.provider ? (_nullishCoalesce(a.provider, () => ( ""))).localeCompare(_nullishCoalesce(b.provider, () => ( ""))) : a.id.localeCompare(b.id));
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
async get(provider, model) {
|
|
329
|
+
await this.ensure();
|
|
330
|
+
return _optionalChain([this, 'access', _21 => _21.providers, 'access', _22 => _22[provider], 'optionalAccess', _23 => _23.models, 'access', _24 => _24[model]]);
|
|
331
|
+
}
|
|
332
|
+
async query(q) {
|
|
333
|
+
return this.models(parseQuery(q));
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
function csvMatch(filter, value) {
|
|
337
|
+
return filter.split(",").some((v) => v.trim() === value);
|
|
338
|
+
}
|
|
339
|
+
function matchesFilter(m, f) {
|
|
340
|
+
if (f.provider && !csvMatch(f.provider, m.provider)) return false;
|
|
341
|
+
if (f.family && !csvMatch(f.family, m.family)) return false;
|
|
342
|
+
if (f.input && !modSubset(f.input, m.input)) return false;
|
|
343
|
+
if (f.output && !modSubset(f.output, m.output)) return false;
|
|
344
|
+
if (f.toolCall !== void 0 && m.tool_call !== f.toolCall) return false;
|
|
345
|
+
if (f.reasoning !== void 0 && m.reasoning !== f.reasoning) return false;
|
|
346
|
+
if (f.openWeights !== void 0 && m.open_weights !== f.openWeights) return false;
|
|
347
|
+
if (f.query) {
|
|
348
|
+
const q = f.query.toLowerCase();
|
|
349
|
+
if (!m.id.toLowerCase().includes(q) && !m.name.toLowerCase().includes(q)) return false;
|
|
350
|
+
}
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
function modSubset(filter, mods) {
|
|
354
|
+
const set = new Set(mods.map((v) => v.toLowerCase().trim()));
|
|
355
|
+
for (const w of filter.split(",")) {
|
|
356
|
+
const t = w.toLowerCase().trim();
|
|
357
|
+
if (t && !set.has(t)) return false;
|
|
358
|
+
}
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
exports.normalize = normalize; exports.ModelsDevSource = ModelsDevSource; exports.Cache = Cache; exports.parseQuery = parseQuery; exports.Registry = Registry; exports.aim_exports = aim_exports;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// ../../contracts/parity/parity.json
|
|
2
|
+
var parity_default = {
|
|
3
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
4
|
+
$id: "https://hop.top/kit/go/console/tui/parity.json",
|
|
5
|
+
description: "Cross-language TUI parity constants. All language implementations MUST load values from here.",
|
|
6
|
+
status: {
|
|
7
|
+
description: "Prefix symbols for status lines. Mirrors Go's InfoType constants in tui/status.go.",
|
|
8
|
+
symbols: {
|
|
9
|
+
info: "\u2139",
|
|
10
|
+
success: "\u2713",
|
|
11
|
+
error: "\u25CF",
|
|
12
|
+
warn: "\u25B2"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
spinner: {
|
|
16
|
+
description: "Braille dot spinner frames and timing.",
|
|
17
|
+
frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"],
|
|
18
|
+
interval_ms: 80
|
|
19
|
+
},
|
|
20
|
+
anim: {
|
|
21
|
+
description: "Gradient character-scramble animation constants.",
|
|
22
|
+
runes: "0123456789abcdefABCDEF~!@#$%^&*()+=_",
|
|
23
|
+
interval_ms: 100,
|
|
24
|
+
default_width: 10
|
|
25
|
+
},
|
|
26
|
+
help: {
|
|
27
|
+
description: "Root --help layout contract. Fang is canonical; TS and Python mirror it.",
|
|
28
|
+
section_order: ["commands", "flags"],
|
|
29
|
+
sections: {
|
|
30
|
+
usage: { title: "USAGE" },
|
|
31
|
+
commands: { title: "COMMANDS" },
|
|
32
|
+
flags: { title: "FLAGS" },
|
|
33
|
+
"global flags": { title: "GLOBAL FLAGS" },
|
|
34
|
+
arguments: { title: "ARGUMENTS" },
|
|
35
|
+
aliases: { title: "ALIASES" },
|
|
36
|
+
examples: { title: "EXAMPLES" },
|
|
37
|
+
streams: { title: "STREAMS" }
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
verbosity: {
|
|
41
|
+
description: "Stackable -V flag maps count to log level. --quiet overrides to warn.",
|
|
42
|
+
flag: "-V",
|
|
43
|
+
levels: {
|
|
44
|
+
"0": "info",
|
|
45
|
+
"1": "debug",
|
|
46
|
+
"2": "trace"
|
|
47
|
+
},
|
|
48
|
+
quiet_override: "warn"
|
|
49
|
+
},
|
|
50
|
+
streams: {
|
|
51
|
+
description: "Per-command named output streams toggled via --stream flag.",
|
|
52
|
+
flag: "--stream",
|
|
53
|
+
label_format: "[{name}]",
|
|
54
|
+
output: "stderr"
|
|
55
|
+
},
|
|
56
|
+
extends: [
|
|
57
|
+
"scope-defaults.json",
|
|
58
|
+
"serve.json"
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/tui/parity.ts
|
|
63
|
+
var parity = parity_default;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
exports.parity = parity;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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; }
|
|
2
|
+
|
|
3
|
+
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
4
|
+
|
|
5
|
+
// src/config.ts
|
|
6
|
+
var config_exports = {};
|
|
7
|
+
_chunkR5U7XKVJjs.__export.call(void 0, config_exports, {
|
|
8
|
+
load: () => load2,
|
|
9
|
+
mergeLayers: () => mergeLayers
|
|
10
|
+
});
|
|
11
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
12
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
13
|
+
var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml);
|
|
14
|
+
function mergeLayers(layers, opts = {}) {
|
|
15
|
+
const policy = resolvePolicy(opts);
|
|
16
|
+
const out = {};
|
|
17
|
+
layers.forEach((layer, i) => {
|
|
18
|
+
if (!isPlainObject(layer)) return;
|
|
19
|
+
try {
|
|
20
|
+
checkBounds(layer);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
throw new Error(`config: layer ${i}: ${errMessage(err)}`);
|
|
23
|
+
}
|
|
24
|
+
mergeInto(out, layer, policy, 0, "");
|
|
25
|
+
});
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
function load2(dst, opts = {}) {
|
|
29
|
+
const policy = resolvePolicy(_nullishCoalesce(opts.merge, () => ( {})));
|
|
30
|
+
const paths = [
|
|
31
|
+
opts.systemConfigPath,
|
|
32
|
+
opts.userConfigPath,
|
|
33
|
+
opts.projectConfigPath
|
|
34
|
+
];
|
|
35
|
+
for (const p of paths) {
|
|
36
|
+
if (!p) continue;
|
|
37
|
+
mergeFile(dst, p, opts.parse, policy);
|
|
38
|
+
}
|
|
39
|
+
if (opts.envOverride) {
|
|
40
|
+
opts.envOverride(dst);
|
|
41
|
+
}
|
|
42
|
+
return dst;
|
|
43
|
+
}
|
|
44
|
+
function mergeFile(dst, filePath, parse, policy) {
|
|
45
|
+
let raw;
|
|
46
|
+
try {
|
|
47
|
+
raw = fs.readFileSync(filePath, "utf8");
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (isEnoent(err)) return;
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
let parsed;
|
|
53
|
+
try {
|
|
54
|
+
const parser = parserFor(parse, filePath);
|
|
55
|
+
parsed = parser ? parser(raw, filePath) : yaml.load(raw);
|
|
56
|
+
checkBounds(parsed);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
throw new Error(`config: failed to parse ${filePath}: ${errMessage(err)}`);
|
|
59
|
+
}
|
|
60
|
+
if (isPlainObject(parsed)) {
|
|
61
|
+
mergeInto(dst, parsed, policy, 0, "");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function parserFor(parse, filePath) {
|
|
65
|
+
if (parse === void 0) return void 0;
|
|
66
|
+
if (typeof parse === "function") return parse;
|
|
67
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
68
|
+
return Object.prototype.hasOwnProperty.call(parse, ext) ? parse[ext] : void 0;
|
|
69
|
+
}
|
|
70
|
+
function errMessage(err) {
|
|
71
|
+
return err instanceof Error ? err.message : String(err);
|
|
72
|
+
}
|
|
73
|
+
var ARRAY_POLICIES = ["replace", "concat", "union"];
|
|
74
|
+
function resolvePolicy(opts) {
|
|
75
|
+
const { nullPolicy = "clear", maxDepth = Infinity, arrayPolicy = "replace", arrayPolicyByPath } = opts;
|
|
76
|
+
if (nullPolicy !== "clear" && nullPolicy !== "keep-lower") {
|
|
77
|
+
throw new Error(`config: invalid nullPolicy ${JSON.stringify(nullPolicy)}`);
|
|
78
|
+
}
|
|
79
|
+
if (maxDepth !== Infinity && !(Number.isInteger(maxDepth) && maxDepth >= 0)) {
|
|
80
|
+
throw new Error(`config: invalid maxDepth ${String(maxDepth)}: want a non-negative integer or Infinity`);
|
|
81
|
+
}
|
|
82
|
+
if (!ARRAY_POLICIES.includes(arrayPolicy)) {
|
|
83
|
+
throw new Error(`config: invalid arrayPolicy ${JSON.stringify(arrayPolicy)}`);
|
|
84
|
+
}
|
|
85
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
86
|
+
const wildcards = [];
|
|
87
|
+
for (const [p, v] of Object.entries(_nullishCoalesce(arrayPolicyByPath, () => ( {})))) {
|
|
88
|
+
if (typeof v !== "function" && !ARRAY_POLICIES.includes(v)) {
|
|
89
|
+
throw new Error(`config: invalid arrayPolicyByPath[${JSON.stringify(p)}] ${JSON.stringify(v)}`);
|
|
90
|
+
}
|
|
91
|
+
const segs = p.split(".");
|
|
92
|
+
if (segs.includes("**")) {
|
|
93
|
+
throw new Error(`config: invalid arrayPolicyByPath[${JSON.stringify(p)}]: ** is not supported`);
|
|
94
|
+
}
|
|
95
|
+
byPath.set(p, v);
|
|
96
|
+
if (segs.includes("*")) wildcards.push({ pattern: p, segs, rule: v });
|
|
97
|
+
}
|
|
98
|
+
const stars = (segs) => segs.filter((x) => x === "*").length;
|
|
99
|
+
wildcards.sort(
|
|
100
|
+
(a, b) => stars(a.segs) - stars(b.segs) || (a.pattern < b.pattern ? -1 : a.pattern > b.pattern ? 1 : 0)
|
|
101
|
+
);
|
|
102
|
+
return { keepLower: nullPolicy === "keep-lower", maxDepth, array: arrayPolicy, byPath, wildcards };
|
|
103
|
+
}
|
|
104
|
+
var MAX_DEPTH = 100;
|
|
105
|
+
var ALIAS_MIN_ALIASES = 100;
|
|
106
|
+
var ALIAS_MIN_DECODED = 1e3;
|
|
107
|
+
var ALIAS_RATIO_LOW = 4e5;
|
|
108
|
+
var ALIAS_RATIO_HIGH = 4e6;
|
|
109
|
+
function allowedAliasRatio(decoded) {
|
|
110
|
+
if (decoded <= ALIAS_RATIO_LOW) return 0.99;
|
|
111
|
+
if (decoded >= ALIAS_RATIO_HIGH) return 0.1;
|
|
112
|
+
return 0.99 - 0.89 * ((decoded - ALIAS_RATIO_LOW) / (ALIAS_RATIO_HIGH - ALIAS_RATIO_LOW));
|
|
113
|
+
}
|
|
114
|
+
function checkBounds(root) {
|
|
115
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
116
|
+
const stack = [[root, 1, false]];
|
|
117
|
+
let decoded = 0;
|
|
118
|
+
let aliased = 0;
|
|
119
|
+
while (stack.length > 0) {
|
|
120
|
+
const [node, depth, inAlias] = stack.pop();
|
|
121
|
+
let alias = inAlias;
|
|
122
|
+
const container = Array.isArray(node) || isPlainObject(node);
|
|
123
|
+
if (container) {
|
|
124
|
+
if (seen.has(node)) {
|
|
125
|
+
decoded++;
|
|
126
|
+
alias = true;
|
|
127
|
+
} else {
|
|
128
|
+
seen.add(node);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
decoded++;
|
|
132
|
+
if (alias) aliased++;
|
|
133
|
+
if (aliased > ALIAS_MIN_ALIASES && decoded > ALIAS_MIN_DECODED && aliased / decoded > allowedAliasRatio(decoded)) {
|
|
134
|
+
throw new Error("document contains excessive aliasing");
|
|
135
|
+
}
|
|
136
|
+
if (!container) continue;
|
|
137
|
+
if (depth > MAX_DEPTH) {
|
|
138
|
+
throw new Error(`nesting exceeded maxDepth (${MAX_DEPTH})`);
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(node)) {
|
|
141
|
+
for (let i = node.length - 1; i >= 0; i--) stack.push([node[i], depth + 1, alias]);
|
|
142
|
+
} else {
|
|
143
|
+
const keys = Object.keys(node);
|
|
144
|
+
for (let i = keys.length - 1; i >= 0; i--) {
|
|
145
|
+
decoded++;
|
|
146
|
+
if (alias) aliased++;
|
|
147
|
+
stack.push([node[keys[i]], depth + 1, alias]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function mergeInto(dst, src, policy, depth, at) {
|
|
153
|
+
for (const key of Object.keys(src)) {
|
|
154
|
+
const next = src[key];
|
|
155
|
+
const has = Object.prototype.hasOwnProperty.call(dst, key);
|
|
156
|
+
const cur = has ? dst[key] : void 0;
|
|
157
|
+
if (next === null) {
|
|
158
|
+
if (policy.keepLower) continue;
|
|
159
|
+
if (has && cur !== null && cur !== void 0 && typeof cur !== "object") {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
setOwn(dst, key, null);
|
|
163
|
+
} else if (isPlainObject(next) && isPlainObject(cur) && depth < policy.maxDepth) {
|
|
164
|
+
mergeInto(cur, next, policy, depth + 1, at === "" ? key : `${at}.${key}`);
|
|
165
|
+
} else if (Array.isArray(next) && Array.isArray(cur)) {
|
|
166
|
+
setOwn(dst, key, mergeArrays(cur, next, policy, at === "" ? key : `${at}.${key}`));
|
|
167
|
+
} else {
|
|
168
|
+
setOwn(dst, key, copy(next));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function mergeArrays(lower, higher, policy, at) {
|
|
173
|
+
const rule = _nullishCoalesce(_nullishCoalesce(policy.byPath.get(at), () => ( matchWildcard(policy, at))), () => ( policy.array));
|
|
174
|
+
const items = copy(higher);
|
|
175
|
+
if (typeof rule === "function") return rule(lower, items, at);
|
|
176
|
+
switch (rule) {
|
|
177
|
+
case "concat":
|
|
178
|
+
return [...lower, ...items];
|
|
179
|
+
case "union": {
|
|
180
|
+
const out = [];
|
|
181
|
+
for (const item of [...lower, ...items]) {
|
|
182
|
+
if (!out.some((o) => deepEqual(o, item))) out.push(item);
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
default:
|
|
187
|
+
return items;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function matchWildcard(policy, at) {
|
|
191
|
+
if (policy.wildcards.length === 0) return void 0;
|
|
192
|
+
const segs = at.split(".");
|
|
193
|
+
const hit = policy.wildcards.find(
|
|
194
|
+
(w) => w.segs.length === segs.length && w.segs.every((x, i) => x === "*" || x === segs[i])
|
|
195
|
+
);
|
|
196
|
+
return _optionalChain([hit, 'optionalAccess', _ => _.rule]);
|
|
197
|
+
}
|
|
198
|
+
function deepEqual(a, b) {
|
|
199
|
+
if (a === b || a !== a && b !== b) return true;
|
|
200
|
+
if (Array.isArray(a)) {
|
|
201
|
+
return Array.isArray(b) && a.length === b.length && a.every((v, i) => deepEqual(v, b[i]));
|
|
202
|
+
}
|
|
203
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
204
|
+
const ka = Object.keys(a);
|
|
205
|
+
if (ka.length !== Object.keys(b).length) return false;
|
|
206
|
+
return ka.every((k) => Object.prototype.hasOwnProperty.call(b, k) && deepEqual(a[k], b[k]));
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
function setOwn(dst, key, value) {
|
|
211
|
+
Object.defineProperty(dst, key, {
|
|
212
|
+
value,
|
|
213
|
+
writable: true,
|
|
214
|
+
enumerable: true,
|
|
215
|
+
configurable: true
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function copy(v) {
|
|
219
|
+
if (Array.isArray(v)) return v.map(copy);
|
|
220
|
+
if (isPlainObject(v)) {
|
|
221
|
+
const out = {};
|
|
222
|
+
for (const k of Object.keys(v)) setOwn(out, k, copy(v[k]));
|
|
223
|
+
return out;
|
|
224
|
+
}
|
|
225
|
+
return v;
|
|
226
|
+
}
|
|
227
|
+
function isPlainObject(v) {
|
|
228
|
+
if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
|
|
229
|
+
const proto = Object.getPrototypeOf(v);
|
|
230
|
+
return proto === Object.prototype || proto === null;
|
|
231
|
+
}
|
|
232
|
+
function isEnoent(err) {
|
|
233
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
exports.mergeLayers = mergeLayers; exports.load = load2; exports.config_exports = config_exports;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
exports.__require = __require; exports.__export = __export;
|