@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.
Files changed (39) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/{chunk-BXJ2J27B.js → chunk-IGKBRNEW.js} +10 -10
  3. package/dist/{chunk-VWGP4NVJ.js → chunk-MDVGMOZO.js} +45 -39
  4. package/dist/{chunk-4FMALWYB.js → chunk-MEF7W3MG.js} +45 -45
  5. package/dist/{chunk-VGOA5Y7S.js → chunk-Q547MHNB.js} +11 -11
  6. package/dist/{chunk-K7E34Q3A.js → chunk-TUU2BY5I.js} +136 -47
  7. package/dist/index.d.ts +4 -4
  8. package/dist/index.js +6 -6
  9. package/dist/{llm-DYuR7_uX.d.ts → llm-BazFKc_2.d.ts} +95 -9
  10. package/dist/{llm-anthropic-Cd_I2xXB.d.ts → llm-anthropic-BcAitoDV.d.ts} +1 -1
  11. package/dist/llm-anthropic.d.ts +2 -2
  12. package/dist/llm-anthropic.js +4 -4
  13. package/dist/{llm-openai-DyFrucmV.d.ts → llm-openai-CSDvuRH6.d.ts} +1 -1
  14. package/dist/llm-openai.d.ts +2 -2
  15. package/dist/llm-openai.js +4 -4
  16. package/dist/llm.d.ts +1 -1
  17. package/dist/llm.js +8 -2
  18. package/dist/{routellm-B0nv59mH.d.ts → routellm-B9UrONPr.d.ts} +1 -1
  19. package/dist/routellm.d.ts +2 -2
  20. package/dist/routellm.js +5 -5
  21. package/package.json +5 -5
  22. package/skills/hop-top-kit-ts/.claude-plugin/plugin.json +1 -1
  23. package/skills/hop-top-kit-ts/SKILL.md +2 -2
  24. package/skills/hop-top-kit-ts/references/other-ports.md +1 -1
  25. package/src/llm-anthropic.conformance.test.ts +7 -0
  26. package/src/llm-boundkey.test.ts +260 -0
  27. package/src/llm-choice-hermetic.test.ts +1 -1
  28. package/src/llm-config.test.ts +2 -4
  29. package/src/llm-config.ts +5 -1
  30. package/src/llm-endpoint.ts +25 -5
  31. package/src/llm-keys.ts +47 -15
  32. package/src/llm-openai.test.ts +10 -4
  33. package/src/llm-openai.ts +7 -1
  34. package/src/llm-spec.test.ts +347 -0
  35. package/src/llm-spec.ts +80 -0
  36. package/src/llm-uri.ts +96 -12
  37. package/src/llm.test.ts +2 -2
  38. package/src/llm.ts +10 -0
  39. package/test/llm/conformance-helpers.ts +3 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,28 @@ All notable changes to `@hop-top/kit` are documented in this file.
4
4
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
5
5
  versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.5.0-alpha.14](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.13...kit-ts/v0.5.0-alpha.14) (2026-12-01)
8
+
9
+ The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.14. This release includes new features and bug fixes.
10
+
11
+
12
+ ### ⚠ BREAKING CHANGES
13
+
14
+ * **sdk/ts:** OPENAI_API_KEY and other openai-family hosted keys are no longer sent to a custom endpoint.
15
+ * **sdk/ts:** parseURI percent-decodes model and params and rejects repeated base_url/credential params; applyAPIKey escapes the key and accepts keys holding & ? #.
16
+
17
+ ### Features
18
+
19
+ * **sdk/py:** kv port on sqldb, cross-language kv gate ([795bf03](https://github.com/hop-top/poly-kit/commit/795bf03a0edb3db2d82140cd8f337a750a4faa5c))
20
+ * **sdk/ts:** decode provider URIs, add typed Spec ([e9d7092](https://github.com/hop-top/poly-kit/commit/e9d709259be9ac3c592f93aa96b1bb83e99dbaa2))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * **sdk/ts:** bind openai-family hosted key to default endpoint ([71b15a3](https://github.com/hop-top/poly-kit/commit/71b15a3305824d37e9b3b7583c8d23f2f1f5fdb7))
26
+
27
+ Full diff: [kit-ts/v0.5.0-alpha.13...kit-ts/v0.5.0-alpha.14](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.13...kit-ts/v0.5.0-alpha.14)
28
+
7
29
  ## [0.5.0-alpha.13](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.12...kit-ts/v0.5.0-alpha.13) (2026-11-28)
8
30
 
9
31
  The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.13. This release includes new features and bug fixes.
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkK7E34Q3Ajs = require('./chunk-K7E34Q3A.js');
6
+ var _chunkTUU2BY5Ijs = require('./chunk-TUU2BY5I.js');
7
7
 
8
8
  // src/llm-http.ts
9
9
  var DEFAULT_MAX_BODY_BYTES = 32 << 20;
@@ -21,7 +21,7 @@ function limitsFrom(provider, params) {
21
21
  const t = v.trim();
22
22
  const n = Number(t);
23
23
  if (!/^\d+$/.test(t) || !Number.isSafeInteger(n) || n <= 0) {
24
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${provider}: ${name} must be a positive byte count`);
24
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(`${provider}: ${name} must be a positive byte count`);
25
25
  }
26
26
  l[key] = n;
27
27
  }
@@ -48,7 +48,7 @@ async function post(opts, url, headers, body) {
48
48
  }
49
49
  if (resp.status >= 300 && resp.status < 400) {
50
50
  await _optionalChain([resp, 'access', _2 => _2.body, 'optionalAccess', _3 => _3.cancel, 'call', _4 => _4(), 'access', _5 => _5.catch, 'call', _6 => _6(() => void 0)]);
51
- throw new (0, _chunkK7E34Q3Ajs.HTTPStatusError)(resp.status, `${opts.provider}: redirect not followed`);
51
+ throw new (0, _chunkTUU2BY5Ijs.HTTPStatusError)(resp.status, `${opts.provider}: redirect not followed`);
52
52
  }
53
53
  if (resp.ok) return resp;
54
54
  const text = await readBody(resp, opts.limits.body, opts.provider).catch(
@@ -65,7 +65,7 @@ async function post(opts, url, headers, body) {
65
65
  status: resp.status,
66
66
  statusText: resp.statusText,
67
67
  headers: resp.headers,
68
- body: _chunkK7E34Q3Ajs.scrubSecrets.call(void 0, text, opts.secrets)
68
+ body: _chunkTUU2BY5Ijs.scrubSecrets.call(void 0, text, opts.secrets)
69
69
  }),
70
70
  opts.secrets
71
71
  );
@@ -114,14 +114,14 @@ function sleep(ms) {
114
114
  function networkError(provider, err) {
115
115
  const cause = err.cause;
116
116
  const detail = _nullishCoalesce(_nullishCoalesce(_optionalChain([cause, 'optionalAccess', _7 => _7.message]), () => ( _optionalChain([err, 'optionalAccess', _8 => _8.message]))), () => ( String(err)));
117
- const e = new (0, _chunkK7E34Q3Ajs.LLMError)(`${provider}: request failed: ${detail}`);
117
+ const e = new (0, _chunkTUU2BY5Ijs.LLMError)(`${provider}: request failed: ${detail}`);
118
118
  if (_optionalChain([cause, 'optionalAccess', _9 => _9.code])) e.code = cause.code;
119
119
  return e;
120
120
  }
121
121
  function scrubError(err, secrets) {
122
122
  if (!(err instanceof Error) || secrets.length === 0) return err;
123
- err.message = _chunkK7E34Q3Ajs.scrubSecrets.call(void 0, err.message, secrets);
124
- if (err.stack) err.stack = _chunkK7E34Q3Ajs.scrubSecrets.call(void 0, err.stack, secrets);
123
+ err.message = _chunkTUU2BY5Ijs.scrubSecrets.call(void 0, err.message, secrets);
124
+ if (err.stack) err.stack = _chunkTUU2BY5Ijs.scrubSecrets.call(void 0, err.stack, secrets);
125
125
  const cause = err.cause;
126
126
  if (cause instanceof Error && cause !== err) scrubError(cause, secrets);
127
127
  return err;
@@ -138,7 +138,7 @@ async function readBody(resp, max, provider) {
138
138
  read += value.byteLength;
139
139
  if (read > max) {
140
140
  await reader.cancel().catch(() => void 0);
141
- throw new (0, _chunkK7E34Q3Ajs.ResponseTooLargeError)(provider, "body", max);
141
+ throw new (0, _chunkTUU2BY5Ijs.ResponseTooLargeError)(provider, "body", max);
142
142
  }
143
143
  chunks.push(value);
144
144
  }
@@ -177,7 +177,7 @@ async function* sseEvents(resp, max, provider) {
177
177
  continue;
178
178
  }
179
179
  eventBytes += nonCR(line) + 1;
180
- if (eventBytes > max) throw new (0, _chunkK7E34Q3Ajs.ResponseTooLargeError)(provider, "event", max);
180
+ if (eventBytes > max) throw new (0, _chunkTUU2BY5Ijs.ResponseTooLargeError)(provider, "event", max);
181
181
  const text = decoder.decode(line);
182
182
  if (text.startsWith(":")) continue;
183
183
  const colon = text.indexOf(":");
@@ -188,7 +188,7 @@ async function* sseEvents(resp, max, provider) {
188
188
  else if (field === "data") data.push(v);
189
189
  }
190
190
  if (eventBytes + nonCR(buf) > max) {
191
- throw new (0, _chunkK7E34Q3Ajs.ResponseTooLargeError)(provider, "event", max);
191
+ throw new (0, _chunkTUU2BY5Ijs.ResponseTooLargeError)(provider, "event", max);
192
192
  }
193
193
  if (done) {
194
194
  finished = true;
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkBXJ2J27Bjs = require('./chunk-BXJ2J27B.js');
8
+ var _chunkIGKBRNEWjs = require('./chunk-IGKBRNEW.js');
9
9
 
10
10
 
11
11
 
@@ -23,7 +23,7 @@ var _chunkBXJ2J27Bjs = require('./chunk-BXJ2J27B.js');
23
23
 
24
24
 
25
25
 
26
- var _chunkK7E34Q3Ajs = require('./chunk-K7E34Q3A.js');
26
+ var _chunkTUU2BY5Ijs = require('./chunk-TUU2BY5I.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 = _chunkBXJ2J27Bjs.limitsFrom.call(void 0, this.label, cfg.provider.params);
68
+ this.limits = _chunkIGKBRNEWjs.limitsFrom.call(void 0, this.label, cfg.provider.params);
69
69
  try {
70
- this.toolNames = _chunkK7E34Q3Ajs.toolNameModeOf.call(void 0, cfg.provider.params);
70
+ this.toolNames = _chunkTUU2BY5Ijs.toolNameModeOf.call(void 0, cfg.provider.params);
71
71
  } catch (err) {
72
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: ${err.message}`);
72
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(
82
- `${this.label}: invalid base URL: ${JSON.stringify(_chunkK7E34Q3Ajs.redactURI.call(void 0, base))}`
81
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
82
+ `${this.label}: invalid base URL: ${JSON.stringify(_chunkTUU2BY5Ijs.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
- _chunkK7E34Q3Ajs.checkKeyEndpoint.call(void 0, this.scheme, key, base);
88
+ _chunkTUU2BY5Ijs.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 _chunkK7E34Q3Ajs.ToolNames.build(_chunkK7E34Q3Ajs.OPENAI_TOOL_NAMES, this.toolNames, tools);
134
+ return _chunkTUU2BY5Ijs.ToolNames.build(_chunkTUU2BY5Ijs.OPENAI_TOOL_NAMES, this.toolNames, tools);
135
135
  }
136
136
  url() {
137
- return _chunkBXJ2J27Bjs.joinURL.call(void 0, this.baseURL, "chat/completions");
137
+ return _chunkIGKBRNEWjs.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 _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);
149
+ const resp = await _chunkIGKBRNEWjs.post.call(void 0, this.transport(req), this.url(), this.headers, body);
150
+ const text = await _chunkIGKBRNEWjs.readBody.call(void 0, resp, this.limits.body, this.label).catch((e) => {
151
+ throw _chunkIGKBRNEWjs.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, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: response is not valid JSON`);
156
+ throw new (0, _chunkTUU2BY5Ijs.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 _chunkBXJ2J27Bjs.post.call(void 0, this.transport(req), this.url(), {
177
+ const resp = await _chunkIGKBRNEWjs.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 _chunkBXJ2J27Bjs.sseEvents.call(void 0, resp, this.limits.event, this.label)) {
183
+ for await (const ev of _chunkIGKBRNEWjs.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, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: stream event is not valid JSON`);
193
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.APIError)(
197
+ throw new (0, _chunkTUU2BY5Ijs.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 _chunkBXJ2J27Bjs.scrubError.call(void 0, err, this.secrets);
207
+ throw _chunkIGKBRNEWjs.scrubError.call(void 0, err, this.secrets);
208
208
  }
209
- if (!acc.finished()) throw new (0, _chunkK7E34Q3Ajs.StreamTruncatedError)(this.label);
209
+ if (!acc.finished()) throw new (0, _chunkTUU2BY5Ijs.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
- _chunkK7E34Q3Ajs.checkToolChoice.call(void 0, req.toolChoice, tools);
219
+ _chunkTUU2BY5Ijs.checkToolChoice.call(void 0, req.toolChoice, tools);
220
220
  } catch (err) {
221
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`${this.label}: ${err.message}`);
221
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(`${label}: tool result needs toolCallId`);
250
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(`${label}: tool result needs toolCallId`);
251
251
  }
252
- _chunkK7E34Q3Ajs.checkToolLinkage.call(void 0, m);
252
+ _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(`${label}: assistant tool calls do not support content parts`);
258
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(`${label}: tool call ${JSON.stringify(tc.name)} needs an id`);
264
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(
279
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(
294
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(`${label}: image part needs a MIME type or URL`);
312
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(`${label}: unsupported modality ${JSON.stringify(p.type)}`);
320
+ throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.LLMError)(`${label}: nil media source`);
324
+ if (!p.source) throw new (0, _chunkTUU2BY5Ijs.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, _chunkK7E34Q3Ajs.APIError)(scheme, r.status, _nullishCoalesce(e.type, () => ( "")), message);
474
+ const api = new (0, _chunkTUU2BY5Ijs.APIError)(scheme, r.status, _nullishCoalesce(e.type, () => ( "")), message);
475
475
  switch (r.status) {
476
476
  case 401:
477
- return new (0, _chunkK7E34Q3Ajs.AuthError)(scheme, api);
477
+ return new (0, _chunkTUU2BY5Ijs.AuthError)(scheme, api);
478
478
  case 403:
479
- return new (0, _chunkK7E34Q3Ajs.PermissionDeniedError)(scheme, api);
479
+ return new (0, _chunkTUU2BY5Ijs.PermissionDeniedError)(scheme, api);
480
480
  case 429:
481
- return new (0, _chunkK7E34Q3Ajs.RateLimitError)(scheme);
481
+ return new (0, _chunkTUU2BY5Ijs.RateLimitError)(scheme);
482
482
  case 404:
483
- return new (0, _chunkK7E34Q3Ajs.ModelError)(model, scheme);
483
+ return new (0, _chunkTUU2BY5Ijs.ModelError)(model, scheme);
484
484
  }
485
- if (r.status >= 500) return new (0, _chunkK7E34Q3Ajs.HTTPStatusError)(r.status, message);
485
+ if (r.status >= 500) return new (0, _chunkTUU2BY5Ijs.HTTPStatusError)(r.status, message);
486
486
  return api;
487
487
  }
488
488
  function openaiFactory(cfg) {
@@ -496,8 +496,14 @@ function openaiFactory(cfg) {
496
496
  };
497
497
  }
498
498
  for (const s of OPENAI_SCHEMES) {
499
- _chunkK7E34Q3Ajs.register.call(void 0, s, openaiFactory, {
500
- endpoints: [_nullishCoalesce(OPENAI_BASE_URLS[s], () => ( OPENAI_DEFAULT_BASE_URL))],
499
+ const base = _nullishCoalesce(OPENAI_BASE_URLS[s], () => ( OPENAI_DEFAULT_BASE_URL));
500
+ _chunkTUU2BY5Ijs.register.call(void 0, s, openaiFactory, {
501
+ endpoints: [base],
502
+ // The hosted key belongs to the hosted endpoint: a server named by
503
+ // another base URL (vLLM, llama.cpp, LiteLLM) gets only a key set
504
+ // for it.
505
+ baseURL: base,
506
+ keyBoundToDefault: true,
501
507
  // LM Studio's local server takes no key: none is resolved for it.
502
508
  ...s === "lmstudio" ? { key: { envVars: [], optional: true } } : {}
503
509
  });
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkBXJ2J27Bjs = require('./chunk-BXJ2J27B.js');
8
+ var _chunkIGKBRNEWjs = require('./chunk-IGKBRNEW.js');
9
9
 
10
10
 
11
11
 
@@ -23,7 +23,7 @@ var _chunkBXJ2J27Bjs = require('./chunk-BXJ2J27B.js');
23
23
 
24
24
 
25
25
 
26
- var _chunkK7E34Q3Ajs = require('./chunk-K7E34Q3A.js');
26
+ var _chunkTUU2BY5Ijs = require('./chunk-TUU2BY5I.js');
27
27
 
28
28
 
29
29
  var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
@@ -55,12 +55,12 @@ var EVENT_STATUS = {
55
55
  var AnthropicAdapter = class {
56
56
  constructor(cfg) {
57
57
  const key = _nullishCoalesce(cfg.provider.apiKey, () => ( ""));
58
- if (key.trim() === "") throw new (0, _chunkK7E34Q3Ajs.LLMError)("anthropic: API key required");
59
- this.limits = _chunkBXJ2J27Bjs.limitsFrom.call(void 0, SCHEME, cfg.provider.params);
58
+ if (key.trim() === "") throw new (0, _chunkTUU2BY5Ijs.LLMError)("anthropic: API key required");
59
+ this.limits = _chunkIGKBRNEWjs.limitsFrom.call(void 0, SCHEME, cfg.provider.params);
60
60
  try {
61
- this.toolNames = _chunkK7E34Q3Ajs.toolNameModeOf.call(void 0, cfg.provider.params);
61
+ this.toolNames = _chunkTUU2BY5Ijs.toolNameModeOf.call(void 0, cfg.provider.params);
62
62
  } catch (err) {
63
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`anthropic: ${err.message}`);
63
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(`anthropic: ${err.message}`);
64
64
  }
65
65
  const env = envReader(cfg);
66
66
  const envBase = env("ANTHROPIC_BASE_URL");
@@ -69,7 +69,7 @@ var AnthropicAdapter = class {
69
69
  const base = cfg.provider.baseURL || envBase || ANTHROPIC_DEFAULT_BASE_URL;
70
70
  this.baseURL = base;
71
71
  this.model = cfg.provider.model || _optionalChain([cfg, 'access', _ => _.uri, 'optionalAccess', _2 => _2.model]) || "";
72
- _chunkK7E34Q3Ajs.checkKeyEndpoint.call(void 0, SCHEME, key, base);
72
+ _chunkTUU2BY5Ijs.checkKeyEndpoint.call(void 0, SCHEME, key, base);
73
73
  this.headers = {
74
74
  "content-type": "application/json",
75
75
  accept: "application/json",
@@ -79,14 +79,14 @@ var AnthropicAdapter = class {
79
79
  const token = _nullishCoalesce(env("ANTHROPIC_AUTH_TOKEN"), () => ( ""));
80
80
  const extra = {};
81
81
  if (token.trim() !== "") {
82
- _chunkK7E34Q3Ajs.checkKeyEndpoint.call(void 0, SCHEME, token, base);
82
+ _chunkTUU2BY5Ijs.checkKeyEndpoint.call(void 0, SCHEME, token, base);
83
83
  extra["authorization"] = `Bearer ${token}`;
84
84
  }
85
85
  const ws = _nullishCoalesce(env("ANTHROPIC_WORKSPACE_ID"), () => ( ""));
86
86
  if (ws !== "") extra["anthropic-workspace-id"] = ws;
87
87
  const trusted = [ANTHROPIC_DEFAULT_BASE_URL];
88
88
  if (envBase) trusted.push(envBase);
89
- if (Object.keys(extra).length > 0 && _chunkK7E34Q3Ajs.credentialsTrusted.call(void 0, SCHEME, base, ...trusted)) {
89
+ if (Object.keys(extra).length > 0 && _chunkTUU2BY5Ijs.credentialsTrusted.call(void 0, SCHEME, base, ...trusted)) {
90
90
  Object.assign(this.headers, extra);
91
91
  }
92
92
  this.secrets = [key, token].filter((s) => s.trim() !== "");
@@ -122,7 +122,7 @@ var AnthropicAdapter = class {
122
122
  }
123
123
  // ── private ────────────────────────────────────────────────────
124
124
  toolNameMap(tools) {
125
- return _chunkK7E34Q3Ajs.ToolNames.build(_chunkK7E34Q3Ajs.ANTHROPIC_TOOL_NAMES, this.toolNames, tools);
125
+ return _chunkTUU2BY5Ijs.ToolNames.build(_chunkTUU2BY5Ijs.ANTHROPIC_TOOL_NAMES, this.toolNames, tools);
126
126
  }
127
127
  transport(req) {
128
128
  const model = req.model || this.model;
@@ -135,18 +135,18 @@ var AnthropicAdapter = class {
135
135
  }
136
136
  async send(body, req) {
137
137
  const opts = this.transport(req);
138
- const resp = await _chunkBXJ2J27Bjs.post.call(void 0, opts, this.url(), this.headers, body);
139
- const text = await _chunkBXJ2J27Bjs.readBody.call(void 0, resp, this.limits.body, SCHEME).catch((e) => {
140
- throw _chunkBXJ2J27Bjs.scrubError.call(void 0, e, this.secrets);
138
+ const resp = await _chunkIGKBRNEWjs.post.call(void 0, opts, this.url(), this.headers, body);
139
+ const text = await _chunkIGKBRNEWjs.readBody.call(void 0, resp, this.limits.body, SCHEME).catch((e) => {
140
+ throw _chunkIGKBRNEWjs.scrubError.call(void 0, e, this.secrets);
141
141
  });
142
142
  try {
143
143
  return JSON.parse(text);
144
144
  } catch (e2) {
145
- throw new (0, _chunkK7E34Q3Ajs.LLMError)("anthropic: response is not valid JSON");
145
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)("anthropic: response is not valid JSON");
146
146
  }
147
147
  }
148
148
  url() {
149
- return _chunkBXJ2J27Bjs.joinURL.call(void 0, this.baseURL, "v1/messages");
149
+ return _chunkIGKBRNEWjs.joinURL.call(void 0, this.baseURL, "v1/messages");
150
150
  }
151
151
  openStream(req, tools) {
152
152
  let outcome;
@@ -165,19 +165,19 @@ var AnthropicAdapter = class {
165
165
  setToolChoice(body, req.toolChoice, _nullishCoalesce(tools, () => ( [])), names);
166
166
  body["stream"] = true;
167
167
  const opts = this.transport(req);
168
- const resp = await _chunkBXJ2J27Bjs.post.call(void 0, opts, this.url(), {
168
+ const resp = await _chunkIGKBRNEWjs.post.call(void 0, opts, this.url(), {
169
169
  ...this.headers,
170
170
  accept: "text/event-stream"
171
171
  }, body);
172
172
  const acc = new Accumulator();
173
173
  const events = req.streamEvents ? new EventMapper(acc, names) : void 0;
174
174
  try {
175
- for await (const ev of _chunkBXJ2J27Bjs.sseEvents.call(void 0, resp, this.limits.event, SCHEME)) {
175
+ for await (const ev of _chunkIGKBRNEWjs.sseEvents.call(void 0, resp, this.limits.event, SCHEME)) {
176
176
  let evt;
177
177
  try {
178
178
  evt = JSON.parse(ev.data);
179
179
  } catch (e3) {
180
- throw new (0, _chunkK7E34Q3Ajs.LLMError)("anthropic: stream event is not valid JSON");
180
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)("anthropic: stream event is not valid JSON");
181
181
  }
182
182
  if (evt.type === "error") {
183
183
  throw streamError(evt.error, req.model || this.model);
@@ -198,9 +198,9 @@ var AnthropicAdapter = class {
198
198
  }
199
199
  }
200
200
  } catch (err) {
201
- throw _chunkBXJ2J27Bjs.scrubError.call(void 0, err, this.secrets);
201
+ throw _chunkIGKBRNEWjs.scrubError.call(void 0, err, this.secrets);
202
202
  }
203
- throw new (0, _chunkK7E34Q3Ajs.StreamTruncatedError)(SCHEME);
203
+ throw new (0, _chunkTUU2BY5Ijs.StreamTruncatedError)(SCHEME);
204
204
  }
205
205
  async buildBody(req, names) {
206
206
  const maxTokens = req.maxTokens !== void 0 && req.maxTokens > 0 ? req.maxTokens : DEFAULT_MAX_TOKENS;
@@ -214,12 +214,12 @@ var AnthropicAdapter = class {
214
214
  if (req.thinking) {
215
215
  const b = req.thinking.budgetTokens;
216
216
  if (b < MIN_THINKING_BUDGET) {
217
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
217
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
218
218
  `anthropic: thinking budget_tokens must be at least ${MIN_THINKING_BUDGET}, got ${b}`
219
219
  );
220
220
  }
221
221
  if (b >= maxTokens) {
222
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
222
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
223
223
  `anthropic: thinking budget_tokens (${b}) must be less than max_tokens (${maxTokens})`
224
224
  );
225
225
  }
@@ -237,7 +237,7 @@ function checkBaseURL(what, base) {
237
237
  try {
238
238
  new URL(base);
239
239
  } catch (e4) {
240
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`anthropic: invalid ${what}: ${JSON.stringify(_chunkK7E34Q3Ajs.redactURI.call(void 0, base))}`);
240
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(`anthropic: invalid ${what}: ${JSON.stringify(_chunkTUU2BY5Ijs.redactURI.call(void 0, base))}`);
241
241
  }
242
242
  }
243
243
  async function extractSystem(msgs, names) {
@@ -288,27 +288,27 @@ function systemBlocks(msgs) {
288
288
  }
289
289
  function checkLinkageRole(m) {
290
290
  if ((_nullishCoalesce(_optionalChain([m, 'access', _9 => _9.toolCalls, 'optionalAccess', _10 => _10.length]), () => ( 0))) > 0 && m.role !== "assistant") {
291
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
291
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
292
292
  `anthropic: ToolCalls are valid only on role assistant, got ${JSON.stringify(m.role)}`
293
293
  );
294
294
  }
295
295
  if ((_nullishCoalesce(_optionalChain([m, 'access', _11 => _11.thinking, 'optionalAccess', _12 => _12.length]), () => ( 0))) > 0 && m.role !== "assistant") {
296
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
296
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
297
297
  `anthropic: Thinking is valid only on role assistant, got ${JSON.stringify(m.role)}`
298
298
  );
299
299
  }
300
300
  if (m.toolCallId && m.role !== "tool") {
301
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
301
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
302
302
  `anthropic: ToolCallID is valid only on role tool, got ${JSON.stringify(m.role)}`
303
303
  );
304
304
  }
305
305
  }
306
306
  function toolResultBlock(m) {
307
307
  if (!m.toolCallId) {
308
- throw new (0, _chunkK7E34Q3Ajs.LLMError)("anthropic: tool result needs ToolCallID");
308
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)("anthropic: tool result needs ToolCallID");
309
309
  }
310
310
  if (_optionalChain([m, 'access', _13 => _13.parts, 'optionalAccess', _14 => _14.length])) {
311
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
311
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
312
312
  `anthropic: tool result ${JSON.stringify(m.toolCallId)} carries only Content`
313
313
  );
314
314
  }
@@ -319,7 +319,7 @@ function toolResultBlock(m) {
319
319
  function toolUseBlocks(calls, names) {
320
320
  return calls.map((tc) => {
321
321
  if (!tc.id) {
322
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`anthropic: tool call ${JSON.stringify(tc.name)} needs an ID`);
322
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(`anthropic: tool call ${JSON.stringify(tc.name)} needs an ID`);
323
323
  }
324
324
  return {
325
325
  type: "tool_use",
@@ -336,7 +336,7 @@ function inputOf(tc) {
336
336
  try {
337
337
  return JSON.parse(args);
338
338
  } catch (e5) {
339
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
339
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
340
340
  `anthropic: tool call ${JSON.stringify(tc.id)} arguments are not valid JSON`
341
341
  );
342
342
  }
@@ -351,7 +351,7 @@ function cacheParam(cc) {
351
351
  const ttl = _nullishCoalesce(cc.ttl, () => ( ""));
352
352
  if (ttl === "") return { type: "ephemeral" };
353
353
  if (ttl === "5m" || ttl === "1h") return { type: "ephemeral", ttl };
354
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
354
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
355
355
  `anthropic: cache_control ttl must be "5m" or "1h", got ${JSON.stringify(ttl)}`
356
356
  );
357
357
  }
@@ -368,8 +368,8 @@ async function mapParts(parts) {
368
368
  break;
369
369
  case "image": {
370
370
  const mime = p.mimeType || _optionalChain([p, 'access', _15 => _15.source, 'optionalAccess', _16 => _16.mimeType, 'call', _17 => _17()]) || "";
371
- if (!mime) throw new (0, _chunkK7E34Q3Ajs.LLMError)("anthropic: image part needs a MIME type");
372
- if (!p.source) throw new (0, _chunkK7E34Q3Ajs.LLMError)("anthropic: nil media source");
371
+ if (!mime) throw new (0, _chunkTUU2BY5Ijs.LLMError)("anthropic: image part needs a MIME type");
372
+ if (!p.source) throw new (0, _chunkTUU2BY5Ijs.LLMError)("anthropic: nil media source");
373
373
  const url = p.source.url();
374
374
  if (url) {
375
375
  out.push({ type: mime === "application/pdf" ? "document" : "image", source: { type: "url", url } });
@@ -382,16 +382,16 @@ async function mapParts(parts) {
382
382
  break;
383
383
  }
384
384
  default:
385
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`anthropic: unsupported modality ${JSON.stringify(p.type)}`);
385
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(`anthropic: unsupported modality ${JSON.stringify(p.type)}`);
386
386
  }
387
387
  }
388
388
  return out;
389
389
  }
390
390
  function setToolChoice(body, c, tools, names) {
391
391
  try {
392
- _chunkK7E34Q3Ajs.checkToolChoice.call(void 0, c, tools);
392
+ _chunkTUU2BY5Ijs.checkToolChoice.call(void 0, c, tools);
393
393
  } catch (err) {
394
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(`anthropic: ${err.message}`);
394
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(`anthropic: ${err.message}`);
395
395
  }
396
396
  if (!c) return;
397
397
  body["tool_choice"] = c.mode === "tool" ? { type: "tool", name: names.wire(_nullishCoalesce(c.name, () => ( ""))) } : { type: c.mode };
@@ -493,7 +493,7 @@ var Accumulator = class {
493
493
  }
494
494
  case "content_block_start": {
495
495
  if (evt.index !== this.content.length) {
496
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
496
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
497
497
  `anthropic: received event of type content_block_start for content block at index ${evt.index}, expected index ${this.content.length}`
498
498
  );
499
499
  }
@@ -505,7 +505,7 @@ var Accumulator = class {
505
505
  case "content_block_delta": {
506
506
  const i = _nullishCoalesce(evt.index, () => ( -1));
507
507
  if (i < 0 || i >= this.content.length) {
508
- throw new (0, _chunkK7E34Q3Ajs.LLMError)(
508
+ throw new (0, _chunkTUU2BY5Ijs.LLMError)(
509
509
  `anthropic: received event of type content_block_delta for content block at index ${i}, only ${this.content.length} blocks exist`
510
510
  );
511
511
  }
@@ -636,18 +636,18 @@ function streamError(e, model) {
636
636
  return classify(status, type, `anthropic: stream error: ${type}: ${_nullishCoalesce(_optionalChain([e, 'optionalAccess', _26 => _26.message]), () => ( ""))}`, model);
637
637
  }
638
638
  function classify(status, type, message, model) {
639
- const api = new (0, _chunkK7E34Q3Ajs.APIError)(SCHEME, status, type, message);
639
+ const api = new (0, _chunkTUU2BY5Ijs.APIError)(SCHEME, status, type, message);
640
640
  switch (status) {
641
641
  case 401:
642
- return new (0, _chunkK7E34Q3Ajs.AuthError)(SCHEME, api);
642
+ return new (0, _chunkTUU2BY5Ijs.AuthError)(SCHEME, api);
643
643
  case 403:
644
- return new (0, _chunkK7E34Q3Ajs.PermissionDeniedError)(SCHEME, api);
644
+ return new (0, _chunkTUU2BY5Ijs.PermissionDeniedError)(SCHEME, api);
645
645
  case 429:
646
- return new (0, _chunkK7E34Q3Ajs.RateLimitError)(SCHEME);
646
+ return new (0, _chunkTUU2BY5Ijs.RateLimitError)(SCHEME);
647
647
  case 404:
648
- return new (0, _chunkK7E34Q3Ajs.ModelError)(model, SCHEME);
648
+ return new (0, _chunkTUU2BY5Ijs.ModelError)(model, SCHEME);
649
649
  }
650
- if (status >= 500) return new (0, _chunkK7E34Q3Ajs.HTTPStatusError)(status, message);
650
+ if (status >= 500) return new (0, _chunkTUU2BY5Ijs.HTTPStatusError)(status, message);
651
651
  return api;
652
652
  }
653
653
  function anthropicFactory(cfg) {
@@ -660,7 +660,7 @@ function anthropicFactory(cfg) {
660
660
  close: () => a.close()
661
661
  };
662
662
  }
663
- _chunkK7E34Q3Ajs.register.call(void 0, SCHEME, anthropicFactory, { endpoints: [ANTHROPIC_DEFAULT_BASE_URL] });
663
+ _chunkTUU2BY5Ijs.register.call(void 0, SCHEME, anthropicFactory, { endpoints: [ANTHROPIC_DEFAULT_BASE_URL] });
664
664
 
665
665
 
666
666