@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.
- package/CHANGELOG.md +51 -0
- package/README.md +5 -5
- package/dist/bus-D2bAOPYz.d.ts +55 -0
- package/dist/bus.d.ts +1 -0
- package/dist/bus.js +13 -0
- package/dist/chunk-74E6RNOI.js +82 -0
- package/dist/chunk-B7XTFDBB.js +17 -0
- package/dist/chunk-CAONBSPO.js +497 -0
- package/dist/chunk-F7RSL4N4.js +88 -0
- package/dist/chunk-I6XDPSXQ.js +75 -0
- package/dist/chunk-IDM6YZXN.js +204 -0
- package/dist/{chunk-BXJ2J27B.js → chunk-IGKBRNEW.js} +10 -10
- package/dist/{chunk-VWGP4NVJ.js → chunk-MDVGMOZO.js} +45 -39
- package/dist/{chunk-4FMALWYB.js → chunk-MEF7W3MG.js} +45 -45
- package/dist/{chunk-VGOA5Y7S.js → chunk-Q547MHNB.js} +11 -11
- package/dist/{chunk-K7E34Q3A.js → chunk-TUU2BY5I.js} +136 -47
- package/dist/chunk-VKQCOVKI.js +880 -0
- package/dist/cli.js +3 -3
- package/dist/index-BqZ7WGQf.d.ts +731 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +32 -18
- package/dist/{llm-DYuR7_uX.d.ts → llm-BazFKc_2.d.ts} +95 -9
- package/dist/{llm-anthropic-Cd_I2xXB.d.ts → llm-anthropic-BcAitoDV.d.ts} +1 -1
- package/dist/llm-anthropic.d.ts +2 -2
- package/dist/llm-anthropic.js +4 -4
- package/dist/{llm-openai-DyFrucmV.d.ts → llm-openai-CSDvuRH6.d.ts} +1 -1
- package/dist/llm-openai.d.ts +2 -2
- package/dist/llm-openai.js +4 -4
- package/dist/llm.d.ts +1 -1
- package/dist/llm.js +8 -2
- package/dist/{routellm-B0nv59mH.d.ts → routellm-B9UrONPr.d.ts} +1 -1
- package/dist/routellm.d.ts +2 -2
- package/dist/routellm.js +5 -5
- package/dist/upgrade/drivers/configfile.d.ts +45 -0
- package/dist/upgrade/drivers/configfile.js +78 -0
- package/dist/upgrade/drivers/fsdir.d.ts +61 -0
- package/dist/upgrade/drivers/fsdir.js +170 -0
- package/dist/upgrade/drivers/postgres.d.ts +121 -0
- package/dist/upgrade/drivers/postgres.js +195 -0
- package/dist/upgrade/drivers/sqlite.d.ts +101 -0
- package/dist/upgrade/drivers/sqlite.js +241 -0
- package/dist/upgrade/index.d.ts +2 -0
- package/dist/upgrade/index.js +73 -0
- package/dist/uri-IJ_AoY3d.d.ts +144 -0
- package/dist/uri.d.ts +1 -0
- package/dist/uri.js +37 -0
- package/dist/version-DEJ3pbiO.d.ts +10 -0
- package/dist/wizard-Bf_qHc31.d.ts +159 -0
- package/dist/wizard.d.ts +1 -0
- package/dist/wizard.js +39 -0
- package/package.json +76 -17
- package/skills/hop-top-kit-ts/.claude-plugin/plugin.json +19 -0
- package/skills/hop-top-kit-ts/SKILL.md +117 -0
- package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.expected +2 -0
- package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.ts +20 -0
- package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.expected +13 -0
- package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.ts +26 -0
- package/skills/hop-top-kit-ts/gym.json +5 -0
- package/skills/hop-top-kit-ts/references/ai-and-agents.md +45 -0
- package/skills/hop-top-kit-ts/references/cli-and-console.md +63 -0
- package/skills/hop-top-kit-ts/references/coverage.md +56 -0
- package/skills/hop-top-kit-ts/references/guardrails-and-trust.md +60 -0
- package/skills/hop-top-kit-ts/references/other-ports.md +31 -0
- package/skills/hop-top-kit-ts/references/serving-and-transports.md +49 -0
- package/skills/hop-top-kit-ts/scripts/detect-port.sh +168 -0
- package/src/index.test.ts +48 -2
- package/src/index.ts +6 -1
- package/src/llm-anthropic.conformance.test.ts +7 -0
- package/src/llm-boundkey.test.ts +260 -0
- package/src/llm-choice-hermetic.test.ts +1 -1
- package/src/llm-config.test.ts +2 -4
- package/src/llm-config.ts +5 -1
- package/src/llm-endpoint.ts +25 -5
- package/src/llm-keys.ts +47 -15
- package/src/llm-openai.test.ts +10 -4
- package/src/llm-openai.ts +7 -1
- package/src/llm-spec.test.ts +347 -0
- package/src/llm-spec.ts +80 -0
- package/src/llm-uri.ts +96 -12
- package/src/llm.test.ts +2 -2
- package/src/llm.ts +10 -0
- package/src/published-types.test.ts +8 -0
- package/src/serve.stopped-order.test.ts +156 -0
- package/src/upgrade/README.md +42 -0
- package/src/upgrade/backup.ts +174 -0
- package/src/upgrade/conformance.test.ts +310 -0
- package/src/upgrade/document.ts +229 -0
- package/src/upgrade/driver.ts +66 -0
- package/src/upgrade/drivers/README.md +47 -0
- package/src/upgrade/drivers/configfile.test.ts +112 -0
- package/src/upgrade/drivers/configfile.ts +107 -0
- package/src/upgrade/drivers/fsdir.test.ts +188 -0
- package/src/upgrade/drivers/fsdir.ts +216 -0
- package/src/upgrade/drivers/isolation.test.ts +18 -0
- package/src/upgrade/drivers/postgres.integration.test.ts +395 -0
- package/src/upgrade/drivers/postgres.test.ts +272 -0
- package/src/upgrade/drivers/postgres.ts +284 -0
- package/src/upgrade/drivers/sqlite.integration.test.ts +492 -0
- package/src/upgrade/drivers/sqlite.ts +300 -0
- package/src/upgrade/drivers/version.ts +21 -0
- package/src/upgrade/errors.ts +117 -0
- package/src/upgrade/events.ts +117 -0
- package/src/{upgrade.test.ts → upgrade/index.test.ts} +1 -1
- package/src/{upgrade.ts → upgrade/index.ts} +20 -0
- package/src/upgrade/migration.ts +89 -0
- package/src/upgrade/migrator.test.ts +391 -0
- package/src/upgrade/migrator.ts +527 -0
- package/src/upgrade/options.ts +59 -0
- package/src/upgrade/semver.ts +90 -0
- package/test/llm/conformance-helpers.ts +3 -0
- package/test/skill-snippets.test.ts +60 -0
- package/test/upgrade/conformance-migrator.ts +439 -0
- package/test/upgrade/conformance-support.ts +44 -0
- package/test/upgrade/driver-support.ts +44 -0
- package/test/upgrade/pg-container.ts +64 -0
- package/test/upgrade/pg-race-worker.ts +48 -0
- package/test/upgrade/race-helper.ts +36 -0
- package/test/upgrade/sqlite-support.ts +41 -0
- package/test/upgrade/testdata/go-fsdir-mydata.tar.gz +0 -0
- package/vitest.config.ts +26 -0
- package/dist/chunk-X4E5QGEB.js +0 -171
- package/dist/upgrade-BJ2z6Oqf.d.ts +0 -156
- package/dist/upgrade.d.ts +0 -1
- package/dist/upgrade.js +0 -9
- package/dist/{chunk-MFVUENZR.js → chunk-KV7FYEAF.js} +2 -2
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
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
|
|
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,
|
|
59
|
-
this.limits =
|
|
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 =
|
|
61
|
+
this.toolNames = _chunkTUU2BY5Ijs.toolNameModeOf.call(void 0, cfg.provider.params);
|
|
62
62
|
} catch (err) {
|
|
63
|
-
throw new (0,
|
|
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
|
-
|
|
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
|
-
|
|
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 &&
|
|
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
|
|
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
|
|
139
|
-
const text = await
|
|
140
|
-
throw
|
|
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,
|
|
145
|
+
throw new (0, _chunkTUU2BY5Ijs.LLMError)("anthropic: response is not valid JSON");
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
url() {
|
|
149
|
-
return
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
201
|
+
throw _chunkIGKBRNEWjs.scrubError.call(void 0, err, this.secrets);
|
|
202
202
|
}
|
|
203
|
-
throw new (0,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
372
|
-
if (!p.source) throw new (0,
|
|
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,
|
|
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
|
-
|
|
392
|
+
_chunkTUU2BY5Ijs.checkToolChoice.call(void 0, c, tools);
|
|
393
393
|
} catch (err) {
|
|
394
|
-
throw new (0,
|
|
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,
|
|
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,
|
|
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,
|
|
639
|
+
const api = new (0, _chunkTUU2BY5Ijs.APIError)(SCHEME, status, type, message);
|
|
640
640
|
switch (status) {
|
|
641
641
|
case 401:
|
|
642
|
-
return new (0,
|
|
642
|
+
return new (0, _chunkTUU2BY5Ijs.AuthError)(SCHEME, api);
|
|
643
643
|
case 403:
|
|
644
|
-
return new (0,
|
|
644
|
+
return new (0, _chunkTUU2BY5Ijs.PermissionDeniedError)(SCHEME, api);
|
|
645
645
|
case 429:
|
|
646
|
-
return new (0,
|
|
646
|
+
return new (0, _chunkTUU2BY5Ijs.RateLimitError)(SCHEME);
|
|
647
647
|
case 404:
|
|
648
|
-
return new (0,
|
|
648
|
+
return new (0, _chunkTUU2BY5Ijs.ModelError)(model, SCHEME);
|
|
649
649
|
}
|
|
650
|
-
if (status >= 500) return new (0,
|
|
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
|
-
|
|
663
|
+
_chunkTUU2BY5Ijs.register.call(void 0, SCHEME, anthropicFactory, { endpoints: [ANTHROPIC_DEFAULT_BASE_URL] });
|
|
664
664
|
|
|
665
665
|
|
|
666
666
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkMDVGMOZOjs = require('./chunk-MDVGMOZO.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkTUU2BY5Ijs = require('./chunk-TUU2BY5I.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
@@ -37,7 +37,7 @@ function parseRouterConfig(extras, opts = {}) {
|
|
|
37
37
|
const raw = extras["routellm"];
|
|
38
38
|
if (raw !== void 0) {
|
|
39
39
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
40
|
-
throw new (0,
|
|
40
|
+
throw new (0, _chunkTUU2BY5Ijs.LLMError)(
|
|
41
41
|
`routellm: expected map, got ${typeof raw}`
|
|
42
42
|
);
|
|
43
43
|
}
|
|
@@ -150,7 +150,7 @@ function formatFloat(v) {
|
|
|
150
150
|
return `${sign}${digits.slice(0, point)}.${digits.slice(point)}`;
|
|
151
151
|
}
|
|
152
152
|
function parseModelField(model) {
|
|
153
|
-
if (!model) throw new (0,
|
|
153
|
+
if (!model) throw new (0, _chunkTUU2BY5Ijs.LLMError)(MODEL_REQUIRED);
|
|
154
154
|
const idx = model.lastIndexOf(":");
|
|
155
155
|
if (idx > 0 && idx < model.length - 1) {
|
|
156
156
|
const threshold = parseFiniteFloat(model.slice(idx + 1));
|
|
@@ -168,9 +168,9 @@ function parseModelField(model) {
|
|
|
168
168
|
var RouteLLMAdapter = class {
|
|
169
169
|
constructor(cfg) {
|
|
170
170
|
this.config = parseRouterConfig(cfg.provider.extras, { hermetic: cfg.hermetic });
|
|
171
|
-
|
|
171
|
+
_chunkTUU2BY5Ijs.toolNameModeOf.call(void 0, cfg.provider.params);
|
|
172
172
|
const model = cfg.provider.model || cfg.uri.model;
|
|
173
|
-
if (!model) throw new (0,
|
|
173
|
+
if (!model) throw new (0, _chunkTUU2BY5Ijs.LLMError)(`routellm: ${MODEL_REQUIRED}`);
|
|
174
174
|
const parsed = parseModelField(model);
|
|
175
175
|
this.routerName = parsed.routerName;
|
|
176
176
|
this.threshold = parsed.threshold;
|
|
@@ -178,19 +178,19 @@ var RouteLLMAdapter = class {
|
|
|
178
178
|
let serverModel = parsed.tier;
|
|
179
179
|
if (!parsed.isTier) {
|
|
180
180
|
if (this.threshold < 0 || this.threshold > 1) {
|
|
181
|
-
throw new (0,
|
|
181
|
+
throw new (0, _chunkTUU2BY5Ijs.LLMError)(
|
|
182
182
|
`routellm: threshold ${this.threshold.toFixed(4)} out of range [0, 1]`
|
|
183
183
|
);
|
|
184
184
|
}
|
|
185
185
|
serverModel = `router-${this.routerName}-${formatFloat(this.threshold)}`;
|
|
186
186
|
}
|
|
187
|
-
this.baseURL =
|
|
187
|
+
this.baseURL = _chunkMDVGMOZOjs.apiRootV1.call(void 0, cfg.provider.baseURL || this.config.baseUrl);
|
|
188
188
|
const params = {};
|
|
189
|
-
for (const k of [
|
|
189
|
+
for (const k of [_chunkTUU2BY5Ijs.TOOL_NAMES_PARAM, "max_body_bytes", "max_event_bytes"]) {
|
|
190
190
|
const v = _optionalChain([cfg, 'access', _4 => _4.provider, 'access', _5 => _5.params, 'optionalAccess', _6 => _6[k]]);
|
|
191
191
|
if (v !== void 0) params[k] = v;
|
|
192
192
|
}
|
|
193
|
-
this.inner = new (0,
|
|
193
|
+
this.inner = new (0, _chunkMDVGMOZOjs.OpenAIAdapter)(
|
|
194
194
|
{
|
|
195
195
|
uri: { scheme: "routellm", model },
|
|
196
196
|
provider: {
|
|
@@ -239,7 +239,7 @@ function routellmFactory(cfg) {
|
|
|
239
239
|
close: () => adapter.close()
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
|
|
242
|
+
_chunkTUU2BY5Ijs.register.call(void 0, "routellm", routellmFactory, {
|
|
243
243
|
key: { envVars: ["ROUTELLM_API_KEY"], optional: true }
|
|
244
244
|
});
|
|
245
245
|
|