@hop-top/kit 0.5.0-alpha.12 → 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.
Files changed (125) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +5 -5
  3. package/dist/bus-D2bAOPYz.d.ts +55 -0
  4. package/dist/bus.d.ts +1 -0
  5. package/dist/bus.js +13 -0
  6. package/dist/chunk-74E6RNOI.js +82 -0
  7. package/dist/chunk-B7XTFDBB.js +17 -0
  8. package/dist/chunk-CAONBSPO.js +497 -0
  9. package/dist/chunk-F7RSL4N4.js +88 -0
  10. package/dist/chunk-I6XDPSXQ.js +75 -0
  11. package/dist/chunk-IDM6YZXN.js +204 -0
  12. package/dist/{chunk-BXJ2J27B.js → chunk-IGKBRNEW.js} +10 -10
  13. package/dist/{chunk-VWGP4NVJ.js → chunk-MDVGMOZO.js} +45 -39
  14. package/dist/{chunk-4FMALWYB.js → chunk-MEF7W3MG.js} +45 -45
  15. package/dist/{chunk-VGOA5Y7S.js → chunk-Q547MHNB.js} +11 -11
  16. package/dist/{chunk-K7E34Q3A.js → chunk-TUU2BY5I.js} +136 -47
  17. package/dist/chunk-VKQCOVKI.js +880 -0
  18. package/dist/cli.js +3 -3
  19. package/dist/index-BqZ7WGQf.d.ts +731 -0
  20. package/dist/index.d.ts +8 -5
  21. package/dist/index.js +32 -18
  22. package/dist/{llm-DYuR7_uX.d.ts → llm-BazFKc_2.d.ts} +95 -9
  23. package/dist/{llm-anthropic-Cd_I2xXB.d.ts → llm-anthropic-BcAitoDV.d.ts} +1 -1
  24. package/dist/llm-anthropic.d.ts +2 -2
  25. package/dist/llm-anthropic.js +4 -4
  26. package/dist/{llm-openai-DyFrucmV.d.ts → llm-openai-CSDvuRH6.d.ts} +1 -1
  27. package/dist/llm-openai.d.ts +2 -2
  28. package/dist/llm-openai.js +4 -4
  29. package/dist/llm.d.ts +1 -1
  30. package/dist/llm.js +8 -2
  31. package/dist/{routellm-B0nv59mH.d.ts → routellm-B9UrONPr.d.ts} +1 -1
  32. package/dist/routellm.d.ts +2 -2
  33. package/dist/routellm.js +5 -5
  34. package/dist/upgrade/drivers/configfile.d.ts +45 -0
  35. package/dist/upgrade/drivers/configfile.js +78 -0
  36. package/dist/upgrade/drivers/fsdir.d.ts +61 -0
  37. package/dist/upgrade/drivers/fsdir.js +170 -0
  38. package/dist/upgrade/drivers/postgres.d.ts +121 -0
  39. package/dist/upgrade/drivers/postgres.js +195 -0
  40. package/dist/upgrade/drivers/sqlite.d.ts +101 -0
  41. package/dist/upgrade/drivers/sqlite.js +241 -0
  42. package/dist/upgrade/index.d.ts +2 -0
  43. package/dist/upgrade/index.js +73 -0
  44. package/dist/uri-IJ_AoY3d.d.ts +144 -0
  45. package/dist/uri.d.ts +1 -0
  46. package/dist/uri.js +37 -0
  47. package/dist/version-DEJ3pbiO.d.ts +10 -0
  48. package/dist/wizard-Bf_qHc31.d.ts +159 -0
  49. package/dist/wizard.d.ts +1 -0
  50. package/dist/wizard.js +39 -0
  51. package/package.json +76 -17
  52. package/skills/hop-top-kit-ts/.claude-plugin/plugin.json +19 -0
  53. package/skills/hop-top-kit-ts/SKILL.md +117 -0
  54. package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.expected +2 -0
  55. package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.ts +20 -0
  56. package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.expected +13 -0
  57. package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.ts +26 -0
  58. package/skills/hop-top-kit-ts/gym.json +5 -0
  59. package/skills/hop-top-kit-ts/references/ai-and-agents.md +45 -0
  60. package/skills/hop-top-kit-ts/references/cli-and-console.md +63 -0
  61. package/skills/hop-top-kit-ts/references/coverage.md +56 -0
  62. package/skills/hop-top-kit-ts/references/guardrails-and-trust.md +60 -0
  63. package/skills/hop-top-kit-ts/references/other-ports.md +31 -0
  64. package/skills/hop-top-kit-ts/references/serving-and-transports.md +49 -0
  65. package/skills/hop-top-kit-ts/scripts/detect-port.sh +168 -0
  66. package/src/index.test.ts +48 -2
  67. package/src/index.ts +6 -1
  68. package/src/llm-anthropic.conformance.test.ts +7 -0
  69. package/src/llm-boundkey.test.ts +260 -0
  70. package/src/llm-choice-hermetic.test.ts +1 -1
  71. package/src/llm-config.test.ts +2 -4
  72. package/src/llm-config.ts +5 -1
  73. package/src/llm-endpoint.ts +25 -5
  74. package/src/llm-keys.ts +47 -15
  75. package/src/llm-openai.test.ts +10 -4
  76. package/src/llm-openai.ts +7 -1
  77. package/src/llm-spec.test.ts +347 -0
  78. package/src/llm-spec.ts +80 -0
  79. package/src/llm-uri.ts +96 -12
  80. package/src/llm.test.ts +2 -2
  81. package/src/llm.ts +10 -0
  82. package/src/published-types.test.ts +8 -0
  83. package/src/serve.stopped-order.test.ts +156 -0
  84. package/src/upgrade/README.md +42 -0
  85. package/src/upgrade/backup.ts +174 -0
  86. package/src/upgrade/conformance.test.ts +310 -0
  87. package/src/upgrade/document.ts +229 -0
  88. package/src/upgrade/driver.ts +66 -0
  89. package/src/upgrade/drivers/README.md +47 -0
  90. package/src/upgrade/drivers/configfile.test.ts +112 -0
  91. package/src/upgrade/drivers/configfile.ts +107 -0
  92. package/src/upgrade/drivers/fsdir.test.ts +188 -0
  93. package/src/upgrade/drivers/fsdir.ts +216 -0
  94. package/src/upgrade/drivers/isolation.test.ts +18 -0
  95. package/src/upgrade/drivers/postgres.integration.test.ts +395 -0
  96. package/src/upgrade/drivers/postgres.test.ts +272 -0
  97. package/src/upgrade/drivers/postgres.ts +284 -0
  98. package/src/upgrade/drivers/sqlite.integration.test.ts +492 -0
  99. package/src/upgrade/drivers/sqlite.ts +300 -0
  100. package/src/upgrade/drivers/version.ts +21 -0
  101. package/src/upgrade/errors.ts +117 -0
  102. package/src/upgrade/events.ts +117 -0
  103. package/src/{upgrade.test.ts → upgrade/index.test.ts} +1 -1
  104. package/src/{upgrade.ts → upgrade/index.ts} +20 -0
  105. package/src/upgrade/migration.ts +89 -0
  106. package/src/upgrade/migrator.test.ts +391 -0
  107. package/src/upgrade/migrator.ts +527 -0
  108. package/src/upgrade/options.ts +59 -0
  109. package/src/upgrade/semver.ts +90 -0
  110. package/test/llm/conformance-helpers.ts +3 -0
  111. package/test/skill-snippets.test.ts +60 -0
  112. package/test/upgrade/conformance-migrator.ts +439 -0
  113. package/test/upgrade/conformance-support.ts +44 -0
  114. package/test/upgrade/driver-support.ts +44 -0
  115. package/test/upgrade/pg-container.ts +64 -0
  116. package/test/upgrade/pg-race-worker.ts +48 -0
  117. package/test/upgrade/race-helper.ts +36 -0
  118. package/test/upgrade/sqlite-support.ts +41 -0
  119. package/test/upgrade/testdata/go-fsdir-mydata.tar.gz +0 -0
  120. package/vitest.config.ts +26 -0
  121. package/dist/chunk-X4E5QGEB.js +0 -171
  122. package/dist/upgrade-BJ2z6Oqf.d.ts +0 -156
  123. package/dist/upgrade.d.ts +0 -1
  124. package/dist/upgrade.js +0 -9
  125. package/dist/{chunk-MFVUENZR.js → chunk-KV7FYEAF.js} +2 -2
@@ -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 trusted = [..._nullishCoalesce(_optionalChain([declarations, 'access', _2 => _2.get, 'call', _3 => _3(scheme), 'optionalAccess', _4 => _4.endpoints]), () => ( [])), ...extra];
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', _5 => _5(readLLMFile(), scheme), 'optionalAccess', _6 => _6.baseURL]);
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 uri = { scheme, model };
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 k = eq < 0 ? pair : pair.slice(0, eq);
819
- const v = eq < 0 ? "" : pair.slice(eq + 1);
820
- if (k === "") continue;
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', _7 => _7.params, 'optionalAccess', _8 => _8["api_key"]]);
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', _9 => _9(u.scheme), 'optionalAccess', _10 => _10.key]);
864
- let names = known ? [..._nullishCoalesce(_optionalChain([decl, 'optionalAccess', _11 => _11.envVars]), () => ( [envKeyName(u.scheme)]))] : [];
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', _13 => _13.params, 'optionalAccess', _14 => _14["base_url"]]);
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', _15 => _15.params, 'optionalAccess', _16 => _16["api_key"]]);
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) => p.split("=", 1)[0] !== name);
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 (e9) {
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', _17 => _17.params, 'optionalAccess', _18 => _18["api_key"]]);
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
- if (/[&?#]/.test(key.value)) {
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', _19 => _19.model]) || "" };
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', _20 => _20.baseURL]) || "";
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', _21 => _21.stopSequences, 'optionalAccess', _22 => _22.length]), () => ( 0))
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', _23 => _23.promptTokens]), () => ( 0)),
1013
- completion_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _24 => _24.completionTokens]), () => ( 0)),
1014
- cache_read_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _25 => _25.cacheReadTokens]), () => ( 0)),
1015
- cache_creation_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _26 => _26.cacheCreationTokens]), () => ( 0)),
1016
- total_tokens: _nullishCoalesce(_optionalChain([u, 'optionalAccess', _27 => _27.totalTokens]), () => ( 0))
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', _28 => _28.toolCalls, 'optionalAccess', _29 => _29.length]), () => ( 0))) > 0;
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', _30 => _30.parts, 'optionalAccess', _31 => _31.length]), () => ( 0))) > 0) {
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', _32 => _32.hermetic]) };
1321
+ const load2 = { hermetic: _optionalChain([opts, 'optionalAccess', _33 => _33.hermetic]) };
1236
1322
  const cfg = loadConfig(uri, load2);
1237
- const fallbackURIs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _33 => _33.fallback]), () => ( cfg.fallbacks));
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', _34 => _34.onError, 'optionalCall', _35 => _35(e)]);
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', _36 => _36.onFallback, 'optionalCall', _37 => _37(i, i + 1, e)]);
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', _38 => _38.onRequest, 'optionalCall', _39 => _39(request)]);
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', _40 => _40.onError, 'optionalCall', _41 => _41(e)]);
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', _42 => _42.onFallback, 'optionalCall', _43 => _43(i, i + 1, e)]);
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', _44 => _44.return, 'optionalCall', _45 => _45()]);
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', _46 => _46.outcome]) === "function" ? s.outcome() : void 0;
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', _47 => _47.onRequest, 'optionalCall', _48 => _48(request)]);
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', _49 => _49.onResponse, 'optionalCall', _50 => _50(resp, Date.now() - start)]);
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', _51 => _51.onRequest, 'optionalCall', _52 => _52(request)]);
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', _53 => _53.onResponse, 'optionalCall', _54 => _54(
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
- 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.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.clearRegistry = clearRegistry; exports.createLLM = createLLM; exports.llm_exports = llm_exports;
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;