@hop-top/kit 0.5.0-alpha.13 → 0.5.0-alpha.14
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 +22 -0
- package/dist/{chunk-BXJ2J27B.js → chunk-IGKBRNEW.js} +10 -10
- package/dist/{chunk-VWGP4NVJ.js → chunk-MDVGMOZO.js} +45 -39
- package/dist/{chunk-4FMALWYB.js → chunk-MEF7W3MG.js} +45 -45
- package/dist/{chunk-VGOA5Y7S.js → chunk-Q547MHNB.js} +11 -11
- package/dist/{chunk-K7E34Q3A.js → chunk-TUU2BY5I.js} +136 -47
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/{llm-DYuR7_uX.d.ts → llm-BazFKc_2.d.ts} +95 -9
- package/dist/{llm-anthropic-Cd_I2xXB.d.ts → llm-anthropic-BcAitoDV.d.ts} +1 -1
- package/dist/llm-anthropic.d.ts +2 -2
- package/dist/llm-anthropic.js +4 -4
- package/dist/{llm-openai-DyFrucmV.d.ts → llm-openai-CSDvuRH6.d.ts} +1 -1
- package/dist/llm-openai.d.ts +2 -2
- package/dist/llm-openai.js +4 -4
- package/dist/llm.d.ts +1 -1
- package/dist/llm.js +8 -2
- package/dist/{routellm-B0nv59mH.d.ts → routellm-B9UrONPr.d.ts} +1 -1
- package/dist/routellm.d.ts +2 -2
- package/dist/routellm.js +5 -5
- package/package.json +5 -5
- package/skills/hop-top-kit-ts/.claude-plugin/plugin.json +1 -1
- package/skills/hop-top-kit-ts/SKILL.md +2 -2
- package/skills/hop-top-kit-ts/references/other-ports.md +1 -1
- package/src/llm-anthropic.conformance.test.ts +7 -0
- package/src/llm-boundkey.test.ts +260 -0
- package/src/llm-choice-hermetic.test.ts +1 -1
- package/src/llm-config.test.ts +2 -4
- package/src/llm-config.ts +5 -1
- package/src/llm-endpoint.ts +25 -5
- package/src/llm-keys.ts +47 -15
- package/src/llm-openai.test.ts +10 -4
- package/src/llm-openai.ts +7 -1
- package/src/llm-spec.test.ts +347 -0
- package/src/llm-spec.ts +80 -0
- package/src/llm-uri.ts +96 -12
- package/src/llm.test.ts +2 -2
- package/src/llm.ts +10 -0
- package/test/llm/conformance-helpers.ts +3 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkMDVGMOZOjs = require('./chunk-MDVGMOZO.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkTUU2BY5Ijs = require('./chunk-TUU2BY5I.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
@@ -37,7 +37,7 @@ function parseRouterConfig(extras, opts = {}) {
|
|
|
37
37
|
const raw = extras["routellm"];
|
|
38
38
|
if (raw !== void 0) {
|
|
39
39
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
40
|
-
throw new (0,
|
|
40
|
+
throw new (0, _chunkTUU2BY5Ijs.LLMError)(
|
|
41
41
|
`routellm: expected map, got ${typeof raw}`
|
|
42
42
|
);
|
|
43
43
|
}
|
|
@@ -150,7 +150,7 @@ function formatFloat(v) {
|
|
|
150
150
|
return `${sign}${digits.slice(0, point)}.${digits.slice(point)}`;
|
|
151
151
|
}
|
|
152
152
|
function parseModelField(model) {
|
|
153
|
-
if (!model) throw new (0,
|
|
153
|
+
if (!model) throw new (0, _chunkTUU2BY5Ijs.LLMError)(MODEL_REQUIRED);
|
|
154
154
|
const idx = model.lastIndexOf(":");
|
|
155
155
|
if (idx > 0 && idx < model.length - 1) {
|
|
156
156
|
const threshold = parseFiniteFloat(model.slice(idx + 1));
|
|
@@ -168,9 +168,9 @@ function parseModelField(model) {
|
|
|
168
168
|
var RouteLLMAdapter = class {
|
|
169
169
|
constructor(cfg) {
|
|
170
170
|
this.config = parseRouterConfig(cfg.provider.extras, { hermetic: cfg.hermetic });
|
|
171
|
-
|
|
171
|
+
_chunkTUU2BY5Ijs.toolNameModeOf.call(void 0, cfg.provider.params);
|
|
172
172
|
const model = cfg.provider.model || cfg.uri.model;
|
|
173
|
-
if (!model) throw new (0,
|
|
173
|
+
if (!model) throw new (0, _chunkTUU2BY5Ijs.LLMError)(`routellm: ${MODEL_REQUIRED}`);
|
|
174
174
|
const parsed = parseModelField(model);
|
|
175
175
|
this.routerName = parsed.routerName;
|
|
176
176
|
this.threshold = parsed.threshold;
|
|
@@ -178,19 +178,19 @@ var RouteLLMAdapter = class {
|
|
|
178
178
|
let serverModel = parsed.tier;
|
|
179
179
|
if (!parsed.isTier) {
|
|
180
180
|
if (this.threshold < 0 || this.threshold > 1) {
|
|
181
|
-
throw new (0,
|
|
181
|
+
throw new (0, _chunkTUU2BY5Ijs.LLMError)(
|
|
182
182
|
`routellm: threshold ${this.threshold.toFixed(4)} out of range [0, 1]`
|
|
183
183
|
);
|
|
184
184
|
}
|
|
185
185
|
serverModel = `router-${this.routerName}-${formatFloat(this.threshold)}`;
|
|
186
186
|
}
|
|
187
|
-
this.baseURL =
|
|
187
|
+
this.baseURL = _chunkMDVGMOZOjs.apiRootV1.call(void 0, cfg.provider.baseURL || this.config.baseUrl);
|
|
188
188
|
const params = {};
|
|
189
|
-
for (const k of [
|
|
189
|
+
for (const k of [_chunkTUU2BY5Ijs.TOOL_NAMES_PARAM, "max_body_bytes", "max_event_bytes"]) {
|
|
190
190
|
const v = _optionalChain([cfg, 'access', _4 => _4.provider, 'access', _5 => _5.params, 'optionalAccess', _6 => _6[k]]);
|
|
191
191
|
if (v !== void 0) params[k] = v;
|
|
192
192
|
}
|
|
193
|
-
this.inner = new (0,
|
|
193
|
+
this.inner = new (0, _chunkMDVGMOZOjs.OpenAIAdapter)(
|
|
194
194
|
{
|
|
195
195
|
uri: { scheme: "routellm", model },
|
|
196
196
|
provider: {
|
|
@@ -239,7 +239,7 @@ function routellmFactory(cfg) {
|
|
|
239
239
|
close: () => adapter.close()
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
|
|
242
|
+
_chunkTUU2BY5Ijs.register.call(void 0, "routellm", routellmFactory, {
|
|
243
243
|
key: { envVars: ["ROUTELLM_API_KEY"], optional: true }
|
|
244
244
|
});
|
|
245
245
|
|
|
@@ -50,13 +50,16 @@ _chunkR5U7XKVJjs.__export.call(void 0, llm_exports, {
|
|
|
50
50
|
isPublicAddress: () => isPublicAddress,
|
|
51
51
|
isValidToolName: () => isValidToolName,
|
|
52
52
|
loadConfig: () => loadConfig,
|
|
53
|
+
loadConfigSpec: () => loadConfigSpec,
|
|
53
54
|
parseURI: () => parseURI,
|
|
54
55
|
redactURI: () => redactURI,
|
|
55
56
|
register: () => register,
|
|
56
57
|
requestStartedPayload: () => requestStartedPayload,
|
|
57
58
|
resolve: () => resolve2,
|
|
59
|
+
resolveSpec: () => resolveSpec,
|
|
58
60
|
responseReceivedPayload: () => responseReceivedPayload,
|
|
59
61
|
sanitizeToolName: () => sanitizeToolName,
|
|
62
|
+
specURI: () => specURI,
|
|
60
63
|
toolNameModeOf: () => toolNameModeOf,
|
|
61
64
|
urlSource: () => urlSource,
|
|
62
65
|
usageCost: () => usageCost
|
|
@@ -768,9 +771,10 @@ function trustedOrigin(scheme, baseURL, extra, ambient) {
|
|
|
768
771
|
const e = parseEndpoint(baseURL);
|
|
769
772
|
if (!e) return false;
|
|
770
773
|
if (_chunkKVG7YCTSjs.isLoopback.call(void 0, e.host)) return true;
|
|
771
|
-
const
|
|
774
|
+
const decl = declarations.get(scheme);
|
|
775
|
+
const trusted = [..._optionalChain([decl, 'optionalAccess', _2 => _2.baseURL]) ? [decl.baseURL] : [], ..._nullishCoalesce(_optionalChain([decl, 'optionalAccess', _3 => _3.endpoints]), () => ( [])), ...extra];
|
|
772
776
|
if (ambient) {
|
|
773
|
-
const file = _optionalChain([providerBlock, 'call',
|
|
777
|
+
const file = _optionalChain([providerBlock, 'call', _4 => _4(readLLMFile(), scheme), 'optionalAccess', _5 => _5.baseURL]);
|
|
774
778
|
if (file) trusted.push(file);
|
|
775
779
|
const env = process.env["LLM_BASE_URL"];
|
|
776
780
|
if (env) trusted.push(env);
|
|
@@ -792,7 +796,7 @@ function parseURI(raw) {
|
|
|
792
796
|
let params;
|
|
793
797
|
const q = rest.indexOf("?");
|
|
794
798
|
if (q >= 0) {
|
|
795
|
-
params = parseQuery(rest.slice(q + 1));
|
|
799
|
+
params = parseQuery(rest.slice(q + 1), raw);
|
|
796
800
|
rest = rest.slice(0, q);
|
|
797
801
|
}
|
|
798
802
|
let host = "";
|
|
@@ -805,23 +809,62 @@ function parseURI(raw) {
|
|
|
805
809
|
model = rest.slice(slash + 1);
|
|
806
810
|
}
|
|
807
811
|
}
|
|
808
|
-
const
|
|
812
|
+
const decoded = percentDecode(model);
|
|
813
|
+
if (decoded === void 0) throw malformed(raw);
|
|
814
|
+
const uri = { scheme, model: decoded };
|
|
809
815
|
if (host !== "") uri.host = host;
|
|
810
816
|
if (params && Object.keys(params).length > 0) uri.params = params;
|
|
811
817
|
return uri;
|
|
812
818
|
}
|
|
813
|
-
function parseQuery(qs) {
|
|
819
|
+
function parseQuery(qs, raw) {
|
|
814
820
|
if (qs === "") return void 0;
|
|
815
821
|
const m = {};
|
|
816
822
|
for (const pair of qs.split("&")) {
|
|
817
823
|
const eq = pair.indexOf("=");
|
|
818
|
-
const
|
|
819
|
-
const
|
|
820
|
-
if (
|
|
824
|
+
const rk = eq < 0 ? pair : pair.slice(0, eq);
|
|
825
|
+
const rv = eq < 0 ? "" : pair.slice(eq + 1);
|
|
826
|
+
if (rk === "") continue;
|
|
827
|
+
const k = percentDecode(rk);
|
|
828
|
+
const v = percentDecode(rv);
|
|
829
|
+
if (k === void 0 || v === void 0) throw malformed(raw);
|
|
830
|
+
if (Object.prototype.hasOwnProperty.call(m, k) && (k === "base_url" || credentialParam(k))) {
|
|
831
|
+
throw new LLMError(`duplicate ${goQuote(k)} param in URI ${goQuote(redactURI(raw))}`);
|
|
832
|
+
}
|
|
821
833
|
Object.defineProperty(m, k, { value: v, enumerable: true, writable: true, configurable: true });
|
|
822
834
|
}
|
|
823
835
|
return m;
|
|
824
836
|
}
|
|
837
|
+
function malformed(raw) {
|
|
838
|
+
return new LLMError(`malformed percent-escape in URI ${goQuote(redactURI(raw))}`);
|
|
839
|
+
}
|
|
840
|
+
function percentDecode(s) {
|
|
841
|
+
if (!s.includes("%")) return s;
|
|
842
|
+
if (/%(?![0-9A-Fa-f]{2})/.test(s)) return void 0;
|
|
843
|
+
try {
|
|
844
|
+
return s.replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => decodeURIComponent(run));
|
|
845
|
+
} catch (e9) {
|
|
846
|
+
return void 0;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
var UNRESERVED = /[A-Za-z0-9\-._~]/;
|
|
850
|
+
var enc = new TextEncoder();
|
|
851
|
+
function escapeExcept(s, keep) {
|
|
852
|
+
let out = "";
|
|
853
|
+
for (const ch of s) {
|
|
854
|
+
if (UNRESERVED.test(ch) || ch.length === 1 && keep.includes(ch)) {
|
|
855
|
+
out += ch;
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
for (const b of enc.encode(ch)) out += `%${b.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
859
|
+
}
|
|
860
|
+
return out;
|
|
861
|
+
}
|
|
862
|
+
function escapeParam(s) {
|
|
863
|
+
return escapeExcept(s, ":/@");
|
|
864
|
+
}
|
|
865
|
+
function escapeModel(s) {
|
|
866
|
+
return escapeExcept(s, "/@");
|
|
867
|
+
}
|
|
825
868
|
function splitHostPort(hp) {
|
|
826
869
|
const i = hp.lastIndexOf(":");
|
|
827
870
|
if (i < 0) return void 0;
|
|
@@ -851,7 +894,7 @@ function envKeyName(scheme) {
|
|
|
851
894
|
return `${scheme.toUpperCase().replace(/[^A-Z0-9]/g, "_")}_API_KEY`;
|
|
852
895
|
}
|
|
853
896
|
function uriKey(u) {
|
|
854
|
-
const v = _optionalChain([u, 'access',
|
|
897
|
+
const v = _optionalChain([u, 'access', _6 => _6.params, 'optionalAccess', _7 => _7["api_key"]]);
|
|
855
898
|
return v !== void 0 && !blankKey(v) ? v : void 0;
|
|
856
899
|
}
|
|
857
900
|
function resolveKey(u, file) {
|
|
@@ -860,17 +903,21 @@ function resolveKey(u, file) {
|
|
|
860
903
|
const block = providerBlock(file, u.scheme);
|
|
861
904
|
if (block && !blankKey(block.apiKey)) return { value: block.apiKey, source: "config" };
|
|
862
905
|
const known = isRegistered(u.scheme);
|
|
863
|
-
const decl = _optionalChain([declarationOf, 'call',
|
|
864
|
-
let names = known ? [..._nullishCoalesce(_optionalChain([decl, 'optionalAccess',
|
|
906
|
+
const decl = _optionalChain([declarationOf, 'call', _8 => _8(u.scheme), 'optionalAccess', _9 => _9.key]);
|
|
907
|
+
let names = known ? [..._nullishCoalesce(_optionalChain([decl, 'optionalAccess', _10 => _10.envVars]), () => ( [envKeyName(u.scheme)]))] : [];
|
|
865
908
|
if (block && !blankKey(block.apiKeyEnv)) {
|
|
866
909
|
names = [block.apiKeyEnv, ...names.filter((n) => n !== block.apiKeyEnv)];
|
|
867
910
|
}
|
|
911
|
+
let required = known && _optionalChain([decl, 'optionalAccess', _11 => _11.optional]) !== true;
|
|
912
|
+
if (customEndpoint(u, block)) {
|
|
913
|
+
names = block && !blankKey(block.apiKeyEnv) ? [block.apiKeyEnv] : [];
|
|
914
|
+
required = false;
|
|
915
|
+
}
|
|
868
916
|
if (names.length === 0) return { value: "", source: "" };
|
|
869
917
|
for (const n of names) {
|
|
870
918
|
const v = process.env[n];
|
|
871
919
|
if (v !== void 0 && !blankKey(v)) return { value: v, source: "env" };
|
|
872
920
|
}
|
|
873
|
-
const required = known && _optionalChain([decl, 'optionalAccess', _12 => _12.optional]) !== true;
|
|
874
921
|
if (!required) return { value: "", source: "" };
|
|
875
922
|
const fb = process.env[FALLBACK_ENV_KEY];
|
|
876
923
|
if (fb !== void 0 && !blankKey(fb)) return { value: fb, source: "fallback" };
|
|
@@ -880,8 +927,18 @@ function resolveKey(u, file) {
|
|
|
880
927
|
missing: new MissingKeyError(u.scheme, u.model, [...names, FALLBACK_ENV_KEY])
|
|
881
928
|
};
|
|
882
929
|
}
|
|
930
|
+
function customEndpoint(u, block) {
|
|
931
|
+
const decl = declarationOf(u.scheme);
|
|
932
|
+
if (!_optionalChain([decl, 'optionalAccess', _12 => _12.keyBoundToDefault]) || !decl.baseURL) return false;
|
|
933
|
+
const cand = uriEndpoint(u) || process.env["LLM_BASE_URL"] || _optionalChain([block, 'optionalAccess', _13 => _13.baseURL]) || "";
|
|
934
|
+
if (cand === "") return false;
|
|
935
|
+
const c = parseEndpoint(cand);
|
|
936
|
+
if (!c) return true;
|
|
937
|
+
const d = parseEndpoint(decl.baseURL);
|
|
938
|
+
return !d || origin(c) !== origin(d);
|
|
939
|
+
}
|
|
883
940
|
function uriEndpoint(u) {
|
|
884
|
-
const b = _optionalChain([u, 'access',
|
|
941
|
+
const b = _optionalChain([u, 'access', _14 => _14.params, 'optionalAccess', _15 => _15["base_url"]]);
|
|
885
942
|
if (b) return b;
|
|
886
943
|
return u.host ? `http://${u.host}` : "";
|
|
887
944
|
}
|
|
@@ -895,7 +952,7 @@ function guardKeyEndpoint(u, key, source) {
|
|
|
895
952
|
}
|
|
896
953
|
}
|
|
897
954
|
function dropBlankURIKey(u) {
|
|
898
|
-
const v = _optionalChain([u, 'access',
|
|
955
|
+
const v = _optionalChain([u, 'access', _16 => _16.params, 'optionalAccess', _17 => _17["api_key"]]);
|
|
899
956
|
if (v === void 0 || !blankKey(v)) return;
|
|
900
957
|
delete u.params["api_key"];
|
|
901
958
|
if (Object.keys(u.params).length === 0) delete u.params;
|
|
@@ -905,17 +962,20 @@ function stripURIParam(raw, name) {
|
|
|
905
962
|
if (s < 0) return raw;
|
|
906
963
|
const q = raw.indexOf("?", s + 3);
|
|
907
964
|
if (q < 0) return raw;
|
|
908
|
-
const kept = raw.slice(q + 1).split("&").filter((p) =>
|
|
965
|
+
const kept = raw.slice(q + 1).split("&").filter((p) => {
|
|
966
|
+
const k = p.split("=", 1)[0];
|
|
967
|
+
return (_nullishCoalesce(percentDecode(k), () => ( k))) !== name;
|
|
968
|
+
});
|
|
909
969
|
return kept.length === 0 ? raw.slice(0, q) : `${raw.slice(0, q + 1)}${kept.join("&")}`;
|
|
910
970
|
}
|
|
911
971
|
function applyAPIKey(uri) {
|
|
912
972
|
let parsed;
|
|
913
973
|
try {
|
|
914
974
|
parsed = parseURI(uri);
|
|
915
|
-
} catch (
|
|
975
|
+
} catch (e10) {
|
|
916
976
|
throw new LLMError("llm: apply API key: provider URI must be scheme://model");
|
|
917
977
|
}
|
|
918
|
-
const named = _optionalChain([parsed, 'access',
|
|
978
|
+
const named = _optionalChain([parsed, 'access', _18 => _18.params, 'optionalAccess', _19 => _19["api_key"]]);
|
|
919
979
|
if (named !== void 0 && blankKey(named)) {
|
|
920
980
|
uri = stripURIParam(uri, "api_key");
|
|
921
981
|
dropBlankURIKey(parsed);
|
|
@@ -924,12 +984,7 @@ function applyAPIKey(uri) {
|
|
|
924
984
|
if (key.missing) throw key.missing;
|
|
925
985
|
guardKeyEndpoint(parsed, key.value, key.source);
|
|
926
986
|
if (key.source === "uri" || key.value === "") return uri;
|
|
927
|
-
|
|
928
|
-
throw new LLMError(
|
|
929
|
-
`llm: ${parsed.scheme} API key contains a character a provider URI cannot carry (& ? #)`
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
return `${uri}${uri.includes("?") ? "&" : "?"}api_key=${key.value}`;
|
|
987
|
+
return `${uri}${uri.includes("?") ? "&" : "?"}api_key=${escapeParam(key.value)}`;
|
|
933
988
|
}
|
|
934
989
|
|
|
935
990
|
// src/llm-config.ts
|
|
@@ -947,11 +1002,11 @@ function loadConfig(uriStr, opts = {}) {
|
|
|
947
1002
|
const block = providerBlock(file, uri.scheme);
|
|
948
1003
|
const key = resolveKey(uri, file);
|
|
949
1004
|
guardKeyEndpoint(uri, key.value, key.source);
|
|
950
|
-
const provider = { model: uri.model || _optionalChain([block, 'optionalAccess',
|
|
1005
|
+
const provider = { model: uri.model || _optionalChain([block, 'optionalAccess', _20 => _20.model]) || "" };
|
|
951
1006
|
if (uri.params) provider.params = { ...uri.params };
|
|
952
1007
|
if (block && Object.keys(block.extras).length > 0) provider.extras = block.extras;
|
|
953
1008
|
if (key.value !== "") provider.apiKey = key.value;
|
|
954
|
-
let base = process.env["LLM_BASE_URL"] || _optionalChain([block, 'optionalAccess',
|
|
1009
|
+
let base = process.env["LLM_BASE_URL"] || _optionalChain([block, 'optionalAccess', _21 => _21.baseURL]) || "";
|
|
955
1010
|
if (uri.host) base = `http://${uri.host}`;
|
|
956
1011
|
if (uri.params && "base_url" in uri.params) base = uri.params["base_url"];
|
|
957
1012
|
if (base !== "") provider.baseURL = base;
|
|
@@ -977,6 +1032,34 @@ function hermeticConfig(uriStr) {
|
|
|
977
1032
|
return { uri, provider, fallbacks: [], hermetic: true };
|
|
978
1033
|
}
|
|
979
1034
|
|
|
1035
|
+
// src/llm-spec.ts
|
|
1036
|
+
var SCHEME = /^[A-Za-z0-9\-._+]+$/;
|
|
1037
|
+
function specURI(s) {
|
|
1038
|
+
if (!s.scheme) throw new LLMError("llm: spec: empty scheme");
|
|
1039
|
+
if (!SCHEME.test(s.scheme)) {
|
|
1040
|
+
throw new LLMError(`llm: spec: invalid scheme ${goQuote(s.scheme)}`);
|
|
1041
|
+
}
|
|
1042
|
+
const names = Object.keys(_nullishCoalesce(s.params, () => ( {})));
|
|
1043
|
+
for (const k of names) {
|
|
1044
|
+
if (k === "") throw new LLMError("llm: spec: empty param name");
|
|
1045
|
+
if (k === "base_url") throw new LLMError("llm: spec: set base_url in baseURL, not params");
|
|
1046
|
+
if (k === "api_key") throw new LLMError("llm: spec: set api_key in apiKey, not params");
|
|
1047
|
+
}
|
|
1048
|
+
const q = [];
|
|
1049
|
+
const add = (k, v) => {
|
|
1050
|
+
q.push(`${escapeParam(k)}=${escapeParam(v)}`);
|
|
1051
|
+
};
|
|
1052
|
+
names.sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
|
|
1053
|
+
for (const k of names) add(k, s.params[k]);
|
|
1054
|
+
if (s.baseURL) add("base_url", s.baseURL);
|
|
1055
|
+
if (s.apiKey) add("api_key", s.apiKey);
|
|
1056
|
+
const uri = `${s.scheme}://${escapeModel(_nullishCoalesce(s.model, () => ( "")))}`;
|
|
1057
|
+
return q.length > 0 ? `${uri}?${q.join("&")}` : uri;
|
|
1058
|
+
}
|
|
1059
|
+
function loadConfigSpec(s, opts = {}) {
|
|
1060
|
+
return loadConfig(specURI(s), opts);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
980
1063
|
// src/llm-payload.ts
|
|
981
1064
|
function requestStartedPayload(op, req, tools) {
|
|
982
1065
|
const p = {
|
|
@@ -987,7 +1070,7 @@ function requestStartedPayload(op, req, tools) {
|
|
|
987
1070
|
max_tokens: _nullishCoalesce(req.maxTokens, () => ( 0)),
|
|
988
1071
|
has_temperature: req.temperature !== void 0,
|
|
989
1072
|
thinking: req.thinking !== void 0,
|
|
990
|
-
stop_sequences: _nullishCoalesce(_optionalChain([req, 'access',
|
|
1073
|
+
stop_sequences: _nullishCoalesce(_optionalChain([req, 'access', _22 => _22.stopSequences, 'optionalAccess', _23 => _23.length]), () => ( 0))
|
|
991
1074
|
};
|
|
992
1075
|
if (req.model) p.model = req.model;
|
|
993
1076
|
for (const m of req.messages) {
|
|
@@ -1009,11 +1092,11 @@ function responseReceivedPayload(op, resp, toolCalls, durationMs) {
|
|
|
1009
1092
|
const p = {
|
|
1010
1093
|
op,
|
|
1011
1094
|
usage: {
|
|
1012
|
-
prompt_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess',
|
|
1013
|
-
completion_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess',
|
|
1014
|
-
cache_read_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess',
|
|
1015
|
-
cache_creation_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess',
|
|
1016
|
-
total_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess',
|
|
1095
|
+
prompt_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _24 => _24.promptTokens]), () => ( 0)),
|
|
1096
|
+
completion_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _25 => _25.completionTokens]), () => ( 0)),
|
|
1097
|
+
cache_read_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _26 => _26.cacheReadTokens]), () => ( 0)),
|
|
1098
|
+
cache_creation_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _27 => _27.cacheCreationTokens]), () => ( 0)),
|
|
1099
|
+
total_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _28 => _28.totalTokens]), () => ( 0))
|
|
1017
1100
|
},
|
|
1018
1101
|
content_bytes: bytes(resp.content) + callBytes(toolCalls) + thinkingBytes(resp.thinking),
|
|
1019
1102
|
tool_calls: toolCalls.length,
|
|
@@ -1155,9 +1238,9 @@ function isConnectionError(code) {
|
|
|
1155
1238
|
return CONNECTION_CODES.has(code);
|
|
1156
1239
|
}
|
|
1157
1240
|
function checkToolLinkage(m) {
|
|
1158
|
-
const hasCalls = (_nullishCoalesce(_optionalChain([m, 'access',
|
|
1241
|
+
const hasCalls = (_nullishCoalesce(_optionalChain([m, 'access', _29 => _29.toolCalls, 'optionalAccess', _30 => _30.length]), () => ( 0))) > 0;
|
|
1159
1242
|
if (m.role === "tool") {
|
|
1160
|
-
if (hasCalls || (_nullishCoalesce(_optionalChain([m, 'access',
|
|
1243
|
+
if (hasCalls || (_nullishCoalesce(_optionalChain([m, 'access', _31 => _31.parts, 'optionalAccess', _32 => _32.length]), () => ( 0))) > 0) {
|
|
1161
1244
|
throw new LLMError(
|
|
1162
1245
|
`tool result "${_nullishCoalesce(m.toolCallId, () => ( ""))}" carries only content`
|
|
1163
1246
|
);
|
|
@@ -1227,14 +1310,17 @@ function resolve2(uriStr, opts = {}) {
|
|
|
1227
1310
|
}
|
|
1228
1311
|
return factory(cfg);
|
|
1229
1312
|
}
|
|
1313
|
+
function resolveSpec(s, opts = {}) {
|
|
1314
|
+
return resolve2(specURI(s), opts);
|
|
1315
|
+
}
|
|
1230
1316
|
function clearRegistry() {
|
|
1231
1317
|
registry.clear();
|
|
1232
1318
|
clearDeclarations();
|
|
1233
1319
|
}
|
|
1234
1320
|
function createLLM(uri, opts) {
|
|
1235
|
-
const load2 = { hermetic: _optionalChain([opts, 'optionalAccess',
|
|
1321
|
+
const load2 = { hermetic: _optionalChain([opts, 'optionalAccess', _33 => _33.hermetic]) };
|
|
1236
1322
|
const cfg = loadConfig(uri, load2);
|
|
1237
|
-
const fallbackURIs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
1323
|
+
const fallbackURIs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _34 => _34.fallback]), () => ( cfg.fallbacks));
|
|
1238
1324
|
const primary = resolve2(uri, load2);
|
|
1239
1325
|
const allURIs = [uri, ...fallbackURIs];
|
|
1240
1326
|
const resolvedProviders = /* @__PURE__ */ new Map();
|
|
@@ -1262,7 +1348,7 @@ function createLLM(uri, opts) {
|
|
|
1262
1348
|
} catch (err) {
|
|
1263
1349
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
1264
1350
|
errors.push(e);
|
|
1265
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1351
|
+
_optionalChain([opts, 'optionalAccess', _35 => _35.onError, 'optionalCall', _36 => _36(e)]);
|
|
1266
1352
|
const canContinue = isFallbackable(e) || e instanceof CapabilityNotSupportedError;
|
|
1267
1353
|
if (!canContinue || i === allURIs.length - 1) {
|
|
1268
1354
|
if (errors.length > 1) {
|
|
@@ -1270,7 +1356,7 @@ function createLLM(uri, opts) {
|
|
|
1270
1356
|
}
|
|
1271
1357
|
throw e;
|
|
1272
1358
|
}
|
|
1273
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1359
|
+
_optionalChain([opts, 'optionalAccess', _37 => _37.onFallback, 'optionalCall', _38 => _38(i, i + 1, e)]);
|
|
1274
1360
|
}
|
|
1275
1361
|
}
|
|
1276
1362
|
throw new FallbackExhaustedError(errors);
|
|
@@ -1280,7 +1366,7 @@ function createLLM(uri, opts) {
|
|
|
1280
1366
|
let source = null;
|
|
1281
1367
|
let initialized = false;
|
|
1282
1368
|
async function first() {
|
|
1283
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1369
|
+
_optionalChain([opts, 'optionalAccess', _39 => _39.onRequest, 'optionalCall', _40 => _40(request)]);
|
|
1284
1370
|
const errors = [];
|
|
1285
1371
|
for (let i = 0; i < allURIs.length; i++) {
|
|
1286
1372
|
try {
|
|
@@ -1300,13 +1386,13 @@ function createLLM(uri, opts) {
|
|
|
1300
1386
|
} catch (err) {
|
|
1301
1387
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
1302
1388
|
errors.push(e);
|
|
1303
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1389
|
+
_optionalChain([opts, 'optionalAccess', _41 => _41.onError, 'optionalCall', _42 => _42(e)]);
|
|
1304
1390
|
const canContinue = isFallbackable(e) || e instanceof CapabilityNotSupportedError;
|
|
1305
1391
|
if (!canContinue || i === allURIs.length - 1) {
|
|
1306
1392
|
if (errors.length > 1) throw new FallbackExhaustedError(errors);
|
|
1307
1393
|
throw e;
|
|
1308
1394
|
}
|
|
1309
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1395
|
+
_optionalChain([opts, 'optionalAccess', _43 => _43.onFallback, 'optionalCall', _44 => _44(i, i + 1, e)]);
|
|
1310
1396
|
}
|
|
1311
1397
|
}
|
|
1312
1398
|
throw new FallbackExhaustedError(errors);
|
|
@@ -1322,26 +1408,26 @@ function createLLM(uri, opts) {
|
|
|
1322
1408
|
return inner.next();
|
|
1323
1409
|
},
|
|
1324
1410
|
async return() {
|
|
1325
|
-
await _optionalChain([inner, 'optionalAccess',
|
|
1411
|
+
await _optionalChain([inner, 'optionalAccess', _45 => _45.return, 'optionalCall', _46 => _46()]);
|
|
1326
1412
|
return { value: void 0, done: true };
|
|
1327
1413
|
}
|
|
1328
1414
|
};
|
|
1329
1415
|
},
|
|
1330
1416
|
outcome() {
|
|
1331
1417
|
const s = source;
|
|
1332
|
-
return typeof _optionalChain([s, 'optionalAccess',
|
|
1418
|
+
return typeof _optionalChain([s, 'optionalAccess', _47 => _47.outcome]) === "function" ? s.outcome() : void 0;
|
|
1333
1419
|
}
|
|
1334
1420
|
};
|
|
1335
1421
|
}
|
|
1336
1422
|
return {
|
|
1337
1423
|
async complete(request) {
|
|
1338
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1424
|
+
_optionalChain([opts, 'optionalAccess', _48 => _48.onRequest, 'optionalCall', _49 => _49(request)]);
|
|
1339
1425
|
const start = Date.now();
|
|
1340
1426
|
const resp = await withFallback(
|
|
1341
1427
|
"complete",
|
|
1342
1428
|
(p) => p.complete(request)
|
|
1343
1429
|
);
|
|
1344
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1430
|
+
_optionalChain([opts, 'optionalAccess', _50 => _50.onResponse, 'optionalCall', _51 => _51(resp, Date.now() - start)]);
|
|
1345
1431
|
return resp;
|
|
1346
1432
|
},
|
|
1347
1433
|
stream(request) {
|
|
@@ -1355,13 +1441,13 @@ function createLLM(uri, opts) {
|
|
|
1355
1441
|
);
|
|
1356
1442
|
},
|
|
1357
1443
|
async callWithTools(request, tools) {
|
|
1358
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1444
|
+
_optionalChain([opts, 'optionalAccess', _52 => _52.onRequest, 'optionalCall', _53 => _53(request)]);
|
|
1359
1445
|
const start = Date.now();
|
|
1360
1446
|
const resp = await withFallback(
|
|
1361
1447
|
"callWithTools",
|
|
1362
1448
|
(p) => p.callWithTools(request, tools)
|
|
1363
1449
|
);
|
|
1364
|
-
_optionalChain([opts, 'optionalAccess',
|
|
1450
|
+
_optionalChain([opts, 'optionalAccess', _54 => _54.onResponse, 'optionalCall', _55 => _55(
|
|
1365
1451
|
{
|
|
1366
1452
|
content: resp.content,
|
|
1367
1453
|
role: "assistant",
|
|
@@ -1442,4 +1528,7 @@ function createLLM(uri, opts) {
|
|
|
1442
1528
|
|
|
1443
1529
|
|
|
1444
1530
|
|
|
1445
|
-
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
exports.LLMError = LLMError; exports.HTTPStatusError = HTTPStatusError; exports.APIError = APIError; exports.StreamTruncatedError = StreamTruncatedError; exports.ResponseTooLargeError = ResponseTooLargeError; exports.KeyEndpointError = KeyEndpointError; exports.MissingKeyError = MissingKeyError; exports.TOOL_NAMES_PARAM = TOOL_NAMES_PARAM; exports.ANTHROPIC_TOOL_NAMES = ANTHROPIC_TOOL_NAMES; exports.OPENAI_TOOL_NAMES = OPENAI_TOOL_NAMES; exports.GEMINI_TOOL_NAMES = GEMINI_TOOL_NAMES; exports.ToolNameError = ToolNameError; exports.toolNameModeOf = toolNameModeOf; exports.isValidToolName = isValidToolName; exports.sanitizeToolName = sanitizeToolName; exports.ToolNames = ToolNames; exports.DEFAULT_MAX_MEDIA_BYTES = DEFAULT_MAX_MEDIA_BYTES; exports.MediaURLRefusedError = MediaURLRefusedError; exports.MediaTooLargeError = MediaTooLargeError; exports.isPublicAddress = isPublicAddress; exports.redactURI = redactURI; exports.scrubSecrets = scrubSecrets; exports.checkKeyEndpoint = checkKeyEndpoint; exports.declarationOf = declarationOf; exports.credentialsTrusted = credentialsTrusted; exports.parseURI = parseURI; exports.applyAPIKey = applyAPIKey; exports.loadConfig = loadConfig; exports.specURI = specURI; exports.loadConfigSpec = loadConfigSpec; exports.requestStartedPayload = requestStartedPayload; exports.responseReceivedPayload = responseReceivedPayload; exports.checkToolChoice = checkToolChoice; exports.usageCost = usageCost; exports.ProviderNotFoundError = ProviderNotFoundError; exports.CapabilityNotSupportedError = CapabilityNotSupportedError; exports.AuthError = AuthError; exports.PermissionDeniedError = PermissionDeniedError; exports.RateLimitError = RateLimitError; exports.ModelError = ModelError; exports.FallbackExhaustedError = FallbackExhaustedError; exports.isFallbackable = isFallbackable; exports.checkToolLinkage = checkToolLinkage; exports.inlineSource = inlineSource; exports.urlSource = urlSource; exports.fileSource = fileSource; exports.register = register; exports.resolve = resolve2; exports.resolveSpec = resolveSpec; exports.clearRegistry = clearRegistry; exports.createLLM = createLLM; exports.llm_exports = llm_exports;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { a as aim } from './aim-DZHwwiIc.js';
|
|
2
2
|
export { a as alias } from './alias-D9_qFlyP.js';
|
|
3
|
-
export { l as anthropic } from './llm-anthropic-
|
|
3
|
+
export { l as anthropic } from './llm-anthropic-BcAitoDV.js';
|
|
4
4
|
export { a as api } from './api-DAexsu2H.js';
|
|
5
5
|
export { a as auth } from './auth-2-jfgiHn.js';
|
|
6
6
|
export { b as bus } from './bus-D2bAOPYz.js';
|
|
@@ -11,15 +11,15 @@ export { c as compliance } from './compliance-AxFf-uMy.js';
|
|
|
11
11
|
export { c as config } from './config-CaK60ByQ.js';
|
|
12
12
|
export { e as errcorrect } from './errcorrect-BcX1Ft0K.js';
|
|
13
13
|
export { i as id } from './index-D9zpUrpE.js';
|
|
14
|
-
export { l as llm } from './llm-
|
|
14
|
+
export { l as llm } from './llm-BazFKc_2.js';
|
|
15
15
|
export { l as log } from './log-CkaxMX3U.js';
|
|
16
16
|
export { i as mcp } from './index-BKJZClJx.js';
|
|
17
17
|
export { n as netpolicy } from './netpolicy-Brx5XZUB.js';
|
|
18
|
-
export { l as openai } from './llm-openai-
|
|
18
|
+
export { l as openai } from './llm-openai-CSDvuRH6.js';
|
|
19
19
|
export { o as output } from './output-CjZWmL8s.js';
|
|
20
20
|
export { p as progress } from './progress-CAzyxeWl.js';
|
|
21
21
|
export { p as provenance } from './provenance-SMFHm5gx.js';
|
|
22
|
-
export { r as routellm } from './routellm-
|
|
22
|
+
export { r as routellm } from './routellm-B9UrONPr.js';
|
|
23
23
|
export { r as rpc } from './rpc-D31Lg0Kc.js';
|
|
24
24
|
export { s as safety } from './safety-CUaYEjZc.js';
|
|
25
25
|
export { s as scope } from './scope-BrhYB4ij.js';
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var _chunkBDNNPRX6js = require('./chunk-BDNNPRX6.js');
|
|
|
39
39
|
var _chunk6SVOHNICjs = require('./chunk-6SVOHNIC.js');
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
var
|
|
42
|
+
var _chunkQ547MHNBjs = require('./chunk-Q547MHNB.js');
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
var _chunkWUOAQVOAjs = require('./chunk-WUOAQVOA.js');
|
|
@@ -60,14 +60,14 @@ var _chunkQQQYCWSCjs = require('./chunk-QQQYCWSC.js');
|
|
|
60
60
|
var _chunk3FIKGFKIjs = require('./chunk-3FIKGFKI.js');
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
var
|
|
63
|
+
var _chunkMEF7W3MGjs = require('./chunk-MEF7W3MG.js');
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
var
|
|
67
|
-
require('./chunk-
|
|
66
|
+
var _chunkMDVGMOZOjs = require('./chunk-MDVGMOZO.js');
|
|
67
|
+
require('./chunk-IGKBRNEW.js');
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
var
|
|
70
|
+
var _chunkTUU2BY5Ijs = require('./chunk-TUU2BY5I.js');
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
var _chunkIZ6Q4SE3js = require('./chunk-IZ6Q4SE3.js');
|
|
@@ -143,4 +143,4 @@ require('./chunk-R5U7XKVJ.js');
|
|
|
143
143
|
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
exports.aim = _chunkQJVSKKRQjs.aim_exports; exports.alias = _chunkML7D5DWYjs.alias_exports; exports.anthropic =
|
|
146
|
+
exports.aim = _chunkQJVSKKRQjs.aim_exports; exports.alias = _chunkML7D5DWYjs.alias_exports; exports.anthropic = _chunkMEF7W3MGjs.llm_anthropic_exports; exports.api = _chunkCSJWB6D3js.api_exports; exports.auth = _chunkUKZIAQA7js.auth_exports; exports.bus = _chunk74E6RNOIjs.bus_exports; exports.cli = _chunkKV7FYEAFjs.cli_exports; exports.completion = _chunk65VPWMPVjs.completion_exports; exports.completionValues = _chunkJKMQSAJPjs.completion_values_exports; exports.compliance = _chunkXJTRY453js.compliance_exports; exports.config = _chunkQQQYCWSCjs.config_exports; exports.errcorrect = _chunk3FIKGFKIjs.errcorrect_exports; exports.id = _chunkP3Y46PYFjs.id_exports; exports.llm = _chunkTUU2BY5Ijs.llm_exports; exports.log = _chunkIZ6Q4SE3js.log_exports; exports.mcp = _chunkIVQHLI56js.mcp_exports; exports.netpolicy = _chunkKVG7YCTSjs.netpolicy_exports; exports.openai = _chunkMDVGMOZOjs.llm_openai_exports; exports.output = _chunkGFRAYYRDjs.output_exports; exports.progress = _chunkBDNNPRX6js.progress_exports; exports.provenance = _chunk6SVOHNICjs.provenance_exports; exports.routellm = _chunkQ547MHNBjs.routellm_exports; exports.rpc = _chunkWUOAQVOAjs.rpc_exports; exports.safety = _chunk6HFAEZ52js.safety_exports; exports.scope = _chunkWBVO43HUjs.scope_exports; exports.serve = _chunkMQXYDYRDjs.serve_exports; exports.stream = _chunkBRNEKPWXjs.stream_exports; exports.telemetry = _chunkYOBAUCVNjs.telemetry_exports; exports.toolspec = _chunkEE4M2UOFjs.toolspec_exports; exports.tui = _chunkRYKLVOVKjs.tui_exports; exports.upgrade = _chunkVKQCOVKIjs.upgrade_exports; exports.uri = _chunkF7RSL4N4js.uri_exports; exports.wizard = _chunkCAONBSPOjs.wizard_exports; exports.xdg = _chunk4UE5TCMQjs.xdg_exports;
|