@hop-top/kit 0.5.0-alpha.10 → 0.5.0-alpha.12

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 (68) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +4 -4
  3. package/dist/alias.js +3 -3
  4. package/dist/{chunk-T46YPHKN.js → chunk-4FMALWYB.js} +45 -45
  5. package/dist/{chunk-JZ22ZUFA.js → chunk-65VPWMPV.js} +4 -1
  6. package/dist/{chunk-YGYQUFGY.js → chunk-BXJ2J27B.js} +10 -10
  7. package/dist/chunk-CXBZTONY.js +65 -0
  8. package/dist/{chunk-K7VCKJ27.js → chunk-EE4M2UOF.js} +8 -4
  9. package/dist/{chunk-72XZWQX7.js → chunk-GFRAYYRD.js} +475 -162
  10. package/dist/{chunk-2JV3A7OP.js → chunk-IVQHLI56.js} +6 -10
  11. package/dist/{chunk-NLMS7HGP.js → chunk-IZ6Q4SE3.js} +3 -3
  12. package/dist/chunk-MFVUENZR.js +1549 -0
  13. package/dist/{chunk-BLS2OBIQ.js → chunk-ML7D5DWY.js} +2 -2
  14. package/dist/chunk-P3Y46PYF.js +138 -0
  15. package/dist/{chunk-GGWJRWWA.js → chunk-RYKLVOVK.js} +7 -7
  16. package/dist/{chunk-QPUCXQXT.js → chunk-T6OZMPPV.js} +2 -1
  17. package/dist/{chunk-MUIQVU6E.js → chunk-VGOA5Y7S.js} +11 -11
  18. package/dist/{chunk-ABQSE7AI.js → chunk-VWGP4NVJ.js} +38 -38
  19. package/dist/chunk-X4E5QGEB.js +171 -0
  20. package/dist/cli-RSRk1M36.d.ts +707 -0
  21. package/dist/cli.d.ts +1 -1
  22. package/dist/cli.js +60 -5
  23. package/dist/completion.js +2 -2
  24. package/dist/id/index.d.ts +1 -1
  25. package/dist/id/index.js +4 -2
  26. package/dist/{index-DCe1boBz.d.ts → index-CGE5yLBj.d.ts} +1 -1
  27. package/dist/{index-VLDcI5NF.d.ts → index-D9zpUrpE.d.ts} +18 -6
  28. package/dist/index.d.ts +4 -4
  29. package/dist/index.js +23 -23
  30. package/dist/llm-anthropic.js +5 -5
  31. package/dist/llm-openai.js +5 -5
  32. package/dist/llm.js +3 -3
  33. package/dist/log.js +3 -3
  34. package/dist/mcp/index.js +3 -2
  35. package/dist/output.js +2 -4
  36. package/dist/routellm.js +6 -6
  37. package/dist/toolspec.js +4 -4
  38. package/dist/tui/index.d.ts +2 -2
  39. package/dist/tui/index.js +3 -3
  40. package/dist/{upgrade-p_zh3pvV.d.ts → upgrade-BJ2z6Oqf.d.ts} +58 -4
  41. package/dist/upgrade.d.ts +1 -1
  42. package/dist/upgrade.js +4 -2
  43. package/package.json +9 -9
  44. package/src/cli.root.conformance.test.ts +166 -0
  45. package/src/cli.ts +39 -0
  46. package/src/completion.conformance.test.ts +3 -2
  47. package/src/completion.test.ts +12 -0
  48. package/src/completion.ts +8 -3
  49. package/src/delegation.test.ts +299 -0
  50. package/src/delegation.ts +807 -0
  51. package/src/id/README.md +2 -2
  52. package/src/id/contract.test.ts +11 -8
  53. package/src/id/differential.test.ts +54 -0
  54. package/src/id/index.ts +123 -17
  55. package/src/mcp/bridge.test.ts +28 -0
  56. package/src/mcp/bridge.ts +5 -10
  57. package/src/plan.ts +89 -0
  58. package/src/policy.ts +472 -0
  59. package/src/sideeffect.ts +105 -0
  60. package/src/toolspec-manifest.ts +7 -2
  61. package/src/upgrade.test.ts +393 -1
  62. package/src/upgrade.ts +183 -25
  63. package/dist/chunk-GHPJJV5L.js +0 -613
  64. package/dist/chunk-IXVQ62NZ.js +0 -334
  65. package/dist/chunk-L23O2FFE.js +0 -51
  66. package/dist/chunk-WWUKGJB5.js +0 -90
  67. package/dist/cli-C5B5tnpA.d.ts +0 -400
  68. package/dist/{chunk-PSFYJGDG.js → chunk-K7E34Q3A.js} +2 -2
@@ -1,6 +1,6 @@
1
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
2
 
3
- var _chunkJZ22ZUFAjs = require('./chunk-JZ22ZUFA.js');
3
+ var _chunk65VPWMPVjs = require('./chunk-65VPWMPV.js');
4
4
 
5
5
 
6
6
  var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
@@ -222,7 +222,7 @@ function bridgeAliases(program, source, opts) {
222
222
  const proxyAll = hasBridgeOptions(opts);
223
223
  const realProxy = proxyAll && (opts.hidden === false || typeof opts.dispatch === "function");
224
224
  for (const [name, target] of Object.entries(all)) {
225
- if (!realProxy) _chunkJZ22ZUFAjs.registerRootAlias.call(void 0, program, name, target);
225
+ if (!realProxy) _chunk65VPWMPVjs.registerRootAlias.call(void 0, program, name, target);
226
226
  const parts = target.split(/\s+/);
227
227
  if (!proxyAll && parts.length === 1) {
228
228
  const targetCmd = findCommand(program, target);
@@ -0,0 +1,138 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
4
+
5
+ // src/id/index.ts
6
+ var id_exports = {};
7
+ _chunkR5U7XKVJjs.__export.call(void 0, id_exports, {
8
+ fromUUID: () => fromUUID,
9
+ newId: () => newId,
10
+ newTyped: () => newTyped,
11
+ parse: () => parse,
12
+ parseTyped: () => parseTyped,
13
+ typeIdSchema: () => typeIdSchema
14
+ });
15
+ var _zod = require('zod');
16
+ var ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
17
+ var DECODE = Object.fromEntries(
18
+ [...ALPHABET].map((c, i) => [c, i])
19
+ );
20
+ var PREFIX_RE = /^(?:[a-z](?:[a-z_]{0,61}[a-z])?)?$/;
21
+ function checkPrefix(prefix) {
22
+ if (!PREFIX_RE.test(prefix)) {
23
+ throw new Error(
24
+ `invalid typeid prefix '${prefix}': want up to 63 chars of [a-z_], starting and ending with a letter`
25
+ );
26
+ }
27
+ }
28
+ function encode(bytes) {
29
+ let n = 0n;
30
+ for (const b of bytes) n = n << 8n | BigInt(b);
31
+ let out = "";
32
+ for (let i = 0; i < 26; i++) {
33
+ out = ALPHABET[Number(n & 31n)] + out;
34
+ n >>= 5n;
35
+ }
36
+ return out;
37
+ }
38
+ function decode(suffix) {
39
+ if (suffix.length !== 26) {
40
+ throw new Error(`invalid typeid suffix '${suffix}': want 26 chars`);
41
+ }
42
+ if (suffix[0] > "7") {
43
+ throw new Error(`invalid typeid suffix '${suffix}': first char must be 0-7`);
44
+ }
45
+ let n = 0n;
46
+ for (const c of suffix) {
47
+ const v = DECODE[c];
48
+ if (v === void 0) {
49
+ throw new Error(
50
+ `invalid typeid suffix '${suffix}': '${c}' is not lowercase Crockford base32`
51
+ );
52
+ }
53
+ n = n << 5n | BigInt(v);
54
+ }
55
+ const bytes = new Uint8Array(16);
56
+ for (let i = 15; i >= 0; i--) {
57
+ bytes[i] = Number(n & 0xffn);
58
+ n >>= 8n;
59
+ }
60
+ return bytes;
61
+ }
62
+ function uuidString(bytes) {
63
+ const hex = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
64
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
65
+ }
66
+ function uuidBytes(uuid) {
67
+ const hex = uuid.replace(/-/g, "");
68
+ if (!/^[0-9a-fA-F]{32}$/.test(hex)) {
69
+ throw new Error(`invalid uuid '${uuid}'`);
70
+ }
71
+ const bytes = new Uint8Array(16);
72
+ for (let i = 0; i < 16; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
73
+ return bytes;
74
+ }
75
+ function uuidv7() {
76
+ const bytes = new Uint8Array(16);
77
+ globalThis.crypto.getRandomValues(bytes);
78
+ let ms = BigInt(Date.now());
79
+ for (let i = 5; i >= 0; i--) {
80
+ bytes[i] = Number(ms & 0xffn);
81
+ ms >>= 8n;
82
+ }
83
+ bytes[6] = bytes[6] & 15 | 112;
84
+ bytes[8] = bytes[8] & 63 | 128;
85
+ return bytes;
86
+ }
87
+ function format(prefix, bytes) {
88
+ const suffix = encode(bytes);
89
+ return prefix === "" ? suffix : `${prefix}_${suffix}`;
90
+ }
91
+ function fromUUID(prefix, uuid) {
92
+ checkPrefix(prefix);
93
+ return format(prefix, uuidBytes(uuid));
94
+ }
95
+ function newId(prefix) {
96
+ checkPrefix(prefix);
97
+ return format(prefix, uuidv7());
98
+ }
99
+ function parse(s) {
100
+ const sep = s.lastIndexOf("_");
101
+ const prefix = sep === -1 ? "" : s.slice(0, sep);
102
+ const suffix = sep === -1 ? s : s.slice(sep + 1);
103
+ if (sep !== -1 && prefix === "") {
104
+ throw new Error(`invalid typeid '${s}': empty prefix with a separator`);
105
+ }
106
+ checkPrefix(prefix);
107
+ return { prefix, uuid: uuidString(decode(suffix)) };
108
+ }
109
+ function newTyped(prefix) {
110
+ return newId(prefix);
111
+ }
112
+ function parseTyped(prefix, s) {
113
+ const parsed = parse(s);
114
+ if (parsed.prefix !== prefix) {
115
+ throw new Error(`typeid '${s}' has prefix '${parsed.prefix}', want '${prefix}'`);
116
+ }
117
+ return s;
118
+ }
119
+ var SUFFIX_RE = /^[0-7][0-9a-hjkmnp-tv-z]{25}$/;
120
+ function typeIdSchema(prefix) {
121
+ const pattern = new RegExp(
122
+ `^${escapeRegExp(prefix)}_${SUFFIX_RE.source.slice(1, -1)}$`
123
+ );
124
+ return _zod.z.string().regex(pattern, `invalid typeid for prefix '${prefix}'`);
125
+ }
126
+ function escapeRegExp(s) {
127
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
128
+ }
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+ exports.fromUUID = fromUUID; exports.newId = newId; exports.parse = parse; exports.newTyped = newTyped; exports.parseTyped = parseTyped; exports.typeIdSchema = typeIdSchema; exports.id_exports = id_exports;
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
2
 
3
- var _chunkQPUCXQXTjs = require('./chunk-QPUCXQXT.js');
3
+ var _chunkT6OZMPPVjs = require('./chunk-T6OZMPPV.js');
4
4
 
5
5
 
6
6
  var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
@@ -40,7 +40,7 @@ function hexToRgb(hex) {
40
40
  }
41
41
 
42
42
  // src/tui/status.ts
43
- var _symbols = _chunkQPUCXQXTjs.parity.status.symbols;
43
+ var _symbols = _chunkT6OZMPPVjs.parity.status.symbols;
44
44
  function status(theme, text, kind = "info") {
45
45
  const { symbol, color } = resolveKind(theme, kind);
46
46
  const indicator = colorize(color, symbol);
@@ -81,8 +81,8 @@ function renderPill(hex, text) {
81
81
  }
82
82
 
83
83
  // src/tui/spinner.ts
84
- var FRAMES = _chunkQPUCXQXTjs.parity.spinner.frames;
85
- var INTERVAL_MS = _chunkQPUCXQXTjs.parity.spinner.interval_ms;
84
+ var FRAMES = _chunkT6OZMPPVjs.parity.spinner.frames;
85
+ var INTERVAL_MS = _chunkT6OZMPPVjs.parity.spinner.interval_ms;
86
86
  function spinner(theme) {
87
87
  const [r, g, b] = hexToRgb2(theme.accent);
88
88
  const accentOpen = `\x1B[38;2;${r};${g};${b}m`;
@@ -195,9 +195,9 @@ function hexToRgb3(hex) {
195
195
  }
196
196
 
197
197
  // src/tui/anim.ts
198
- var ANIM_RUNES = _chunkQPUCXQXTjs.parity.anim.runes;
199
- var DEFAULT_WIDTH = _chunkQPUCXQXTjs.parity.anim.default_width;
200
- var INTERVAL_MS2 = _chunkQPUCXQXTjs.parity.anim.interval_ms;
198
+ var ANIM_RUNES = _chunkT6OZMPPVjs.parity.anim.runes;
199
+ var DEFAULT_WIDTH = _chunkT6OZMPPVjs.parity.anim.default_width;
200
+ var INTERVAL_MS2 = _chunkT6OZMPPVjs.parity.anim.interval_ms;
201
201
  function anim(theme, opts) {
202
202
  const width = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _2 => _2.width]), () => ( DEFAULT_WIDTH));
203
203
  let label = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _3 => _3.label]), () => ( ""));
@@ -55,7 +55,8 @@ var parity_default = {
55
55
  },
56
56
  extends: [
57
57
  "scope-defaults.json",
58
- "serve.json"
58
+ "serve.json",
59
+ "api.json"
59
60
  ]
60
61
  };
61
62
 
@@ -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 _chunkABQSE7AIjs = require('./chunk-ABQSE7AI.js');
4
+ var _chunkVWGP4NVJjs = require('./chunk-VWGP4NVJ.js');
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunkPSFYJGDGjs = require('./chunk-PSFYJGDG.js');
10
+ var _chunkK7E34Q3Ajs = require('./chunk-K7E34Q3A.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, _chunkPSFYJGDGjs.LLMError)(
40
+ throw new (0, _chunkK7E34Q3Ajs.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, _chunkPSFYJGDGjs.LLMError)(MODEL_REQUIRED);
153
+ if (!model) throw new (0, _chunkK7E34Q3Ajs.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
- _chunkPSFYJGDGjs.toolNameModeOf.call(void 0, cfg.provider.params);
171
+ _chunkK7E34Q3Ajs.toolNameModeOf.call(void 0, cfg.provider.params);
172
172
  const model = cfg.provider.model || cfg.uri.model;
173
- if (!model) throw new (0, _chunkPSFYJGDGjs.LLMError)(`routellm: ${MODEL_REQUIRED}`);
173
+ if (!model) throw new (0, _chunkK7E34Q3Ajs.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, _chunkPSFYJGDGjs.LLMError)(
181
+ throw new (0, _chunkK7E34Q3Ajs.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 = _chunkABQSE7AIjs.apiRootV1.call(void 0, cfg.provider.baseURL || this.config.baseUrl);
187
+ this.baseURL = _chunkVWGP4NVJjs.apiRootV1.call(void 0, cfg.provider.baseURL || this.config.baseUrl);
188
188
  const params = {};
189
- for (const k of [_chunkPSFYJGDGjs.TOOL_NAMES_PARAM, "max_body_bytes", "max_event_bytes"]) {
189
+ for (const k of [_chunkK7E34Q3Ajs.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, _chunkABQSE7AIjs.OpenAIAdapter)(
193
+ this.inner = new (0, _chunkVWGP4NVJjs.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
- _chunkPSFYJGDGjs.register.call(void 0, "routellm", routellmFactory, {
242
+ _chunkK7E34Q3Ajs.register.call(void 0, "routellm", routellmFactory, {
243
243
  key: { envVars: ["ROUTELLM_API_KEY"], optional: true }
244
244
  });
245
245
 
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkYGYQUFGYjs = require('./chunk-YGYQUFGY.js');
8
+ var _chunkBXJ2J27Bjs = require('./chunk-BXJ2J27B.js');
9
9
 
10
10
 
11
11
 
@@ -23,7 +23,7 @@ var _chunkYGYQUFGYjs = require('./chunk-YGYQUFGY.js');
23
23
 
24
24
 
25
25
 
26
- var _chunkPSFYJGDGjs = require('./chunk-PSFYJGDG.js');
26
+ var _chunkK7E34Q3Ajs = require('./chunk-K7E34Q3A.js');
27
27
 
28
28
 
29
29
  var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
@@ -65,11 +65,11 @@ var OpenAIAdapter = class {
65
65
  constructor(cfg, opts = {}) {
66
66
  this.scheme = _optionalChain([cfg, 'access', _2 => _2.uri, 'optionalAccess', _3 => _3.scheme]) || "openai";
67
67
  this.label = _nullishCoalesce(opts.label, () => ( this.scheme));
68
- this.limits = _chunkYGYQUFGYjs.limitsFrom.call(void 0, this.label, cfg.provider.params);
68
+ this.limits = _chunkBXJ2J27Bjs.limitsFrom.call(void 0, this.label, cfg.provider.params);
69
69
  try {
70
- this.toolNames = _chunkPSFYJGDGjs.toolNameModeOf.call(void 0, cfg.provider.params);
70
+ this.toolNames = _chunkK7E34Q3Ajs.toolNameModeOf.call(void 0, cfg.provider.params);
71
71
  } catch (err) {
72
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${this.label}: ${err.message}`);
72
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: ${err.message}`);
73
73
  }
74
74
  let base = cfg.provider.baseURL || OPENAI_BASE_URLS[this.scheme] || OPENAI_DEFAULT_BASE_URL;
75
75
  if (this.scheme === "lmstudio" || this.scheme === "openai" && isHostForm(cfg)) {
@@ -78,14 +78,14 @@ var OpenAIAdapter = class {
78
78
  try {
79
79
  new URL(base);
80
80
  } catch (e2) {
81
- throw new (0, _chunkPSFYJGDGjs.LLMError)(
82
- `${this.label}: invalid base URL: ${JSON.stringify(_chunkPSFYJGDGjs.redactURI.call(void 0, base))}`
81
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(
82
+ `${this.label}: invalid base URL: ${JSON.stringify(_chunkK7E34Q3Ajs.redactURI.call(void 0, base))}`
83
83
  );
84
84
  }
85
85
  this.baseURL = base;
86
86
  this.model = cfg.provider.model || _optionalChain([cfg, 'access', _4 => _4.uri, 'optionalAccess', _5 => _5.model]) || "";
87
87
  const key = _nullishCoalesce(cfg.provider.apiKey, () => ( ""));
88
- _chunkPSFYJGDGjs.checkKeyEndpoint.call(void 0, this.scheme, key, base);
88
+ _chunkK7E34Q3Ajs.checkKeyEndpoint.call(void 0, this.scheme, key, base);
89
89
  this.headers = {
90
90
  "content-type": "application/json",
91
91
  accept: "application/json"
@@ -131,10 +131,10 @@ var OpenAIAdapter = class {
131
131
  }
132
132
  // ── private ────────────────────────────────────────────────────
133
133
  toolNameMap(tools) {
134
- return _chunkPSFYJGDGjs.ToolNames.build(_chunkPSFYJGDGjs.OPENAI_TOOL_NAMES, this.toolNames, tools);
134
+ return _chunkK7E34Q3Ajs.ToolNames.build(_chunkK7E34Q3Ajs.OPENAI_TOOL_NAMES, this.toolNames, tools);
135
135
  }
136
136
  url() {
137
- return _chunkYGYQUFGYjs.joinURL.call(void 0, this.baseURL, "chat/completions");
137
+ return _chunkBXJ2J27Bjs.joinURL.call(void 0, this.baseURL, "chat/completions");
138
138
  }
139
139
  transport(req) {
140
140
  const model = req.model || this.model;
@@ -146,14 +146,14 @@ var OpenAIAdapter = class {
146
146
  };
147
147
  }
148
148
  async send(body, req) {
149
- const resp = await _chunkYGYQUFGYjs.post.call(void 0, this.transport(req), this.url(), this.headers, body);
150
- const text = await _chunkYGYQUFGYjs.readBody.call(void 0, resp, this.limits.body, this.label).catch((e) => {
151
- throw _chunkYGYQUFGYjs.scrubError.call(void 0, e, this.secrets);
149
+ const resp = await _chunkBXJ2J27Bjs.post.call(void 0, this.transport(req), this.url(), this.headers, body);
150
+ const text = await _chunkBXJ2J27Bjs.readBody.call(void 0, resp, this.limits.body, this.label).catch((e) => {
151
+ throw _chunkBXJ2J27Bjs.scrubError.call(void 0, e, this.secrets);
152
152
  });
153
153
  try {
154
154
  return JSON.parse(text);
155
155
  } catch (e3) {
156
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${this.label}: response is not valid JSON`);
156
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: response is not valid JSON`);
157
157
  }
158
158
  }
159
159
  openStream(req, tools) {
@@ -174,13 +174,13 @@ var OpenAIAdapter = class {
174
174
  if (req.streamEvents) {
175
175
  body["stream_options"] = { include_usage: true };
176
176
  }
177
- const resp = await _chunkYGYQUFGYjs.post.call(void 0, this.transport(req), this.url(), {
177
+ const resp = await _chunkBXJ2J27Bjs.post.call(void 0, this.transport(req), this.url(), {
178
178
  ...this.headers,
179
179
  accept: "text/event-stream"
180
180
  }, body);
181
181
  const acc = new Accumulator(names, req.streamEvents === true);
182
182
  try {
183
- for await (const ev of _chunkYGYQUFGYjs.sseEvents.call(void 0, resp, this.limits.event, this.label)) {
183
+ for await (const ev of _chunkBXJ2J27Bjs.sseEvents.call(void 0, resp, this.limits.event, this.label)) {
184
184
  if (ev.data === "[DONE]") {
185
185
  done(acc.outcome());
186
186
  yield { content: "", done: true };
@@ -190,11 +190,11 @@ var OpenAIAdapter = class {
190
190
  try {
191
191
  chunk = JSON.parse(ev.data);
192
192
  } catch (e4) {
193
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${this.label}: stream event is not valid JSON`);
193
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: stream event is not valid JSON`);
194
194
  }
195
195
  if (chunk.error) {
196
196
  const e = chunk.error;
197
- throw new (0, _chunkPSFYJGDGjs.APIError)(
197
+ throw new (0, _chunkK7E34Q3Ajs.APIError)(
198
198
  this.label,
199
199
  0,
200
200
  _nullishCoalesce(e.type, () => ( "")),
@@ -204,9 +204,9 @@ var OpenAIAdapter = class {
204
204
  yield* acc.add(chunk);
205
205
  }
206
206
  } catch (err) {
207
- throw _chunkYGYQUFGYjs.scrubError.call(void 0, err, this.secrets);
207
+ throw _chunkBXJ2J27Bjs.scrubError.call(void 0, err, this.secrets);
208
208
  }
209
- if (!acc.finished()) throw new (0, _chunkPSFYJGDGjs.StreamTruncatedError)(this.label);
209
+ if (!acc.finished()) throw new (0, _chunkK7E34Q3Ajs.StreamTruncatedError)(this.label);
210
210
  done(acc.outcome());
211
211
  yield { content: "", done: true };
212
212
  }
@@ -216,9 +216,9 @@ var OpenAIAdapter = class {
216
216
  */
217
217
  async buildBody(req, names, tools) {
218
218
  try {
219
- _chunkPSFYJGDGjs.checkToolChoice.call(void 0, req.toolChoice, tools);
219
+ _chunkK7E34Q3Ajs.checkToolChoice.call(void 0, req.toolChoice, tools);
220
220
  } catch (err) {
221
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${this.label}: ${err.message}`);
221
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: ${err.message}`);
222
222
  }
223
223
  const messages = [];
224
224
  for (const m of req.messages) {
@@ -247,21 +247,21 @@ function apiRootV1(base) {
247
247
  }
248
248
  async function mapMessage(m, names, label) {
249
249
  if (m.role === "tool" && !m.toolCallId) {
250
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${label}: tool result needs toolCallId`);
250
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${label}: tool result needs toolCallId`);
251
251
  }
252
- _chunkPSFYJGDGjs.checkToolLinkage.call(void 0, m);
252
+ _chunkK7E34Q3Ajs.checkToolLinkage.call(void 0, m);
253
253
  if (m.role === "tool") {
254
254
  return { role: "tool", content: m.content, tool_call_id: m.toolCallId };
255
255
  }
256
256
  if (_optionalChain([m, 'access', _31 => _31.toolCalls, 'optionalAccess', _32 => _32.length])) {
257
257
  if (_optionalChain([m, 'access', _33 => _33.parts, 'optionalAccess', _34 => _34.length])) {
258
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${label}: assistant tool calls do not support content parts`);
258
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${label}: assistant tool calls do not support content parts`);
259
259
  }
260
260
  const out = { role: "assistant" };
261
261
  if (m.content) out["content"] = m.content;
262
262
  out["tool_calls"] = m.toolCalls.map((tc) => {
263
263
  if (!tc.id) {
264
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${label}: tool call ${JSON.stringify(tc.name)} needs an id`);
264
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${label}: tool call ${JSON.stringify(tc.name)} needs an id`);
265
265
  }
266
266
  return {
267
267
  id: tc.id,
@@ -276,7 +276,7 @@ async function mapMessage(m, names, label) {
276
276
  }
277
277
  if (!_optionalChain([m, 'access', _35 => _35.parts, 'optionalAccess', _36 => _36.length])) return { role: m.role, content: m.content };
278
278
  if (m.role !== "" && m.role !== "user") {
279
- throw new (0, _chunkPSFYJGDGjs.LLMError)(
279
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(
280
280
  `${label}: message role ${JSON.stringify(m.role)} does not support content parts`
281
281
  );
282
282
  }
@@ -291,7 +291,7 @@ function encodeArguments(tc, label) {
291
291
  try {
292
292
  JSON.parse(args);
293
293
  } catch (e5) {
294
- throw new (0, _chunkPSFYJGDGjs.LLMError)(
294
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(
295
295
  `${label}: tool call ${JSON.stringify(tc.id)} arguments are not valid JSON`
296
296
  );
297
297
  }
@@ -309,7 +309,7 @@ async function mapPart(p, label) {
309
309
  const url = _optionalChain([p, 'access', _40 => _40.source, 'optionalAccess', _41 => _41.url, 'call', _42 => _42()]);
310
310
  if (url) return { type: "image_url", image_url: { url } };
311
311
  if (!mime) {
312
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${label}: image part needs a MIME type or URL`);
312
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${label}: image part needs a MIME type or URL`);
313
313
  }
314
314
  return {
315
315
  type: "image_url",
@@ -317,11 +317,11 @@ async function mapPart(p, label) {
317
317
  };
318
318
  }
319
319
  default:
320
- throw new (0, _chunkPSFYJGDGjs.LLMError)(`${label}: unsupported modality ${JSON.stringify(p.type)}`);
320
+ throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${label}: unsupported modality ${JSON.stringify(p.type)}`);
321
321
  }
322
322
  }
323
323
  async function readBase64(p, label) {
324
- if (!p.source) throw new (0, _chunkPSFYJGDGjs.LLMError)(`${label}: nil media source`);
324
+ if (!p.source) throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${label}: nil media source`);
325
325
  return Buffer.from(await p.source.read()).toString("base64");
326
326
  }
327
327
  function mapTools(defs) {
@@ -471,18 +471,18 @@ function mapErrorResponse(r, label, scheme, model) {
471
471
  }
472
472
  const detail = e.message !== void 0 ? `${_nullishCoalesce(e.type, () => ( "error"))}: ${e.message}` : r.body.slice(0, 2048);
473
473
  const message = `${label}: ${r.status} ${detail}`.trim();
474
- const api = new (0, _chunkPSFYJGDGjs.APIError)(scheme, r.status, _nullishCoalesce(e.type, () => ( "")), message);
474
+ const api = new (0, _chunkK7E34Q3Ajs.APIError)(scheme, r.status, _nullishCoalesce(e.type, () => ( "")), message);
475
475
  switch (r.status) {
476
476
  case 401:
477
- return new (0, _chunkPSFYJGDGjs.AuthError)(scheme, api);
477
+ return new (0, _chunkK7E34Q3Ajs.AuthError)(scheme, api);
478
478
  case 403:
479
- return new (0, _chunkPSFYJGDGjs.PermissionDeniedError)(scheme, api);
479
+ return new (0, _chunkK7E34Q3Ajs.PermissionDeniedError)(scheme, api);
480
480
  case 429:
481
- return new (0, _chunkPSFYJGDGjs.RateLimitError)(scheme);
481
+ return new (0, _chunkK7E34Q3Ajs.RateLimitError)(scheme);
482
482
  case 404:
483
- return new (0, _chunkPSFYJGDGjs.ModelError)(model, scheme);
483
+ return new (0, _chunkK7E34Q3Ajs.ModelError)(model, scheme);
484
484
  }
485
- if (r.status >= 500) return new (0, _chunkPSFYJGDGjs.HTTPStatusError)(r.status, message);
485
+ if (r.status >= 500) return new (0, _chunkK7E34Q3Ajs.HTTPStatusError)(r.status, message);
486
486
  return api;
487
487
  }
488
488
  function openaiFactory(cfg) {
@@ -496,7 +496,7 @@ function openaiFactory(cfg) {
496
496
  };
497
497
  }
498
498
  for (const s of OPENAI_SCHEMES) {
499
- _chunkPSFYJGDGjs.register.call(void 0, s, openaiFactory, {
499
+ _chunkK7E34Q3Ajs.register.call(void 0, s, openaiFactory, {
500
500
  endpoints: [_nullishCoalesce(OPENAI_BASE_URLS[s], () => ( OPENAI_DEFAULT_BASE_URL))],
501
501
  // LM Studio's local server takes no key: none is resolved for it.
502
502
  ...s === "lmstudio" ? { key: { envVars: [], optional: true } } : {}