@cjhyy/code-shell 0.1.0-alpha.3 → 0.1.5
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 +77 -0
- package/dist/anthropic-IBTI4WL2.cjs +10 -0
- package/dist/anthropic-PRZZKHEZ.js +10 -0
- package/dist/arena/index.cjs +7 -6
- package/dist/arena/index.js +6 -5
- package/dist/arena/model-presets.d.ts +10 -1
- package/dist/{arena-HHDYYVHJ.cjs → arena-KBQOPLFV.cjs} +25 -23
- package/dist/{arena-ENHBHB2W.js → arena-O2L4TN6A.js} +9 -7
- package/dist/{chunk-SW3L7HIM.js → chunk-2EP3CLEN.js} +2 -2
- package/dist/{chunk-EL2RL5DG.cjs → chunk-2YW4FPFG.cjs} +2 -2
- package/dist/chunk-3OA5G4TM.js +47 -0
- package/dist/chunk-52LGZKT3.cjs +47 -0
- package/dist/{chunk-KOGV6PDQ.cjs → chunk-55XGPMAP.cjs} +44 -9
- package/dist/chunk-5ECBT4YA.js +450 -0
- package/dist/{chunk-YD7XTI7T.cjs → chunk-6QVAYW7C.cjs} +116 -28
- package/dist/{chunk-SCDKLTN3.js → chunk-6S4BJ65N.js} +5 -4
- package/dist/{chunk-ZLPJJZUW.js → chunk-76HYEPDM.js} +2 -2
- package/dist/{chunk-TDXBHD24.js → chunk-76W334S4.js} +2 -2
- package/dist/{chunk-GZBD6QRS.cjs → chunk-7EG3V4JY.cjs} +13 -12
- package/dist/{chunk-LMEKCQX4.js → chunk-7JVTYEEC.js} +6 -6
- package/dist/{chunk-ID6EJUHP.js → chunk-7K6SDRRF.js} +1262 -212
- package/dist/{chunk-5C5HIOML.js → chunk-7Y6S3OCX.js} +109 -21
- package/dist/{chunk-VIPLU4RY.cjs → chunk-A5LCRPDP.cjs} +4 -4
- package/dist/{chunk-F5BS3GUC.js → chunk-BSW22MPA.js} +39 -4
- package/dist/{chunk-VWFET3MG.cjs → chunk-BUU5PZK2.cjs} +1474 -423
- package/dist/{chunk-HOXQLX5R.cjs → chunk-BWTOS5BH.cjs} +444 -103
- package/dist/{chunk-ZRVPCXI7.js → chunk-BXCY2FSE.js} +2 -1
- package/dist/{chunk-Y7TSCDF6.js → chunk-C5YQBIRK.js} +347 -6
- package/dist/{chunk-C7C7ZZY4.cjs → chunk-HEKQCI7B.cjs} +10 -10
- package/dist/{chunk-JHXNOB5G.cjs → chunk-HS2MFNUC.cjs} +6 -6
- package/dist/{chunk-JHNCK7JP.cjs → chunk-IK4EWJBP.cjs} +4 -3
- package/dist/{chunk-M2QI5X3X.cjs → chunk-JMR33QVF.cjs} +2 -2
- package/dist/{chunk-YAFCN7ZW.cjs → chunk-KOVYSDHZ.cjs} +15 -15
- package/dist/{chunk-IJSHQGMP.cjs → chunk-KS3RYAYL.cjs} +4 -4
- package/dist/{chunk-DI7RDLOS.js → chunk-MD32R22I.js} +7 -4
- package/dist/chunk-MY5XHADU.cjs +216 -0
- package/dist/{chunk-OP57WUWQ.cjs → chunk-NUNC3VFB.cjs} +6 -6
- package/dist/{chunk-BF4LXLQV.cjs → chunk-QRM7IF2S.cjs} +133 -175
- package/dist/chunk-R47ROHGL.cjs +298 -0
- package/dist/{chunk-OUC2DFA7.js → chunk-RMYKO74M.js} +3 -3
- package/dist/{chunk-FUOKLKR2.js → chunk-SFXHZSRF.js} +1 -1
- package/dist/{chunk-2EUAE7AY.js → chunk-SIHHIQLO.js} +2 -2
- package/dist/{chunk-3CAZIWUA.cjs → chunk-SNT563K3.cjs} +9 -9
- package/dist/{chunk-SK62UVS6.js → chunk-T6VYG46N.js} +1 -1
- package/dist/{chunk-3QR52LL5.cjs → chunk-TUY2T5KP.cjs} +2 -2
- package/dist/{chunk-I57ZD5IQ.js → chunk-VIAGTYYW.js} +1 -1
- package/dist/{chunk-X2DNIMPC.cjs → chunk-VYL4EFRC.cjs} +32 -32
- package/dist/chunk-W22P377T.js +299 -0
- package/dist/chunk-WASS5YWB.js +215 -0
- package/dist/{chunk-FPFTIKEJ.js → chunk-XDIQWQJ4.js} +132 -174
- package/dist/{chunk-BUJ5KYCI.cjs → chunk-YIQBXAYU.cjs} +13 -13
- package/dist/{chunk-REFCCVDM.js → chunk-YJ77GQK5.js} +2 -2
- package/dist/chunk-YUI524OE.cjs +450 -0
- package/dist/{chunk-M2SVOKC6.js → chunk-ZBPSQCPU.js} +6 -6
- package/dist/cli/commands/builtin/export-md.d.ts +19 -0
- package/dist/cli/commands/builtin/init/detect.d.ts +25 -0
- package/dist/cli/commands/builtin/init/index.d.ts +19 -0
- package/dist/cli/main.cjs +2343 -1447
- package/dist/cli/main.js +2476 -1580
- package/dist/cli/migrate-models.d.ts +45 -0
- package/dist/cli/onboarding.d.ts +110 -5
- package/dist/cli/updater.d.ts +51 -4
- package/dist/client-base-HTF236ZD.cjs +9 -0
- package/dist/client-base-QKRKCOWB.js +9 -0
- package/dist/{compaction-YNWCEF7B.js → compaction-6VU2T643.js} +4 -2
- package/dist/compaction-OKUNTCA7.cjs +33 -0
- package/dist/context/compaction.d.ts +35 -3
- package/dist/context/manager.d.ts +40 -3
- package/dist/context/tool-result-storage.d.ts +96 -0
- package/dist/devtools-T2NIZBJK.cjs +6 -0
- package/dist/{devtools-IRQQPIRY.js → devtools-YXWHOVKR.js} +1 -1
- package/dist/engine/engine.d.ts +40 -0
- package/dist/engine/turn-loop.d.ts +6 -0
- package/dist/export-md-RXDW6F5W.cjs +135 -0
- package/dist/export-md-XXKZANW5.js +135 -0
- package/dist/file-history-KYPE3ECT.cjs +7 -0
- package/dist/file-history-LF4F7X26.js +7 -0
- package/dist/index.cjs +42 -22
- package/dist/index.d.ts +5 -2
- package/dist/index.js +40 -20
- package/dist/llm/client-base.d.ts +1 -1
- package/dist/llm/model-cache.d.ts +21 -0
- package/dist/llm/model-fetcher.d.ts +29 -0
- package/dist/llm/model-pool.d.ts +13 -0
- package/dist/llm/provider-catalog.d.ts +30 -0
- package/dist/llm/provider-kinds.d.ts +21 -0
- package/dist/llm/types.d.ts +8 -0
- package/dist/logging/session-recorder.d.ts +77 -0
- package/dist/manager-C2IUXKRC.js +7 -0
- package/dist/manager-YYKWYTRM.cjs +7 -0
- package/dist/mcp-manager-QMKWPBZ4.js +8 -0
- package/dist/mcp-manager-Z3OKI74O.cjs +8 -0
- package/dist/memory-5LWZ6FI2.cjs +9 -0
- package/dist/{memory-EPFDBPII.js → memory-VIJLBAMQ.js} +2 -2
- package/dist/model-cache-5KIYL5SL.js +13 -0
- package/dist/model-cache-OED3IM4R.cjs +13 -0
- package/dist/model-fetcher-HKGICACL.js +8 -0
- package/dist/model-fetcher-UR6WJOQP.cjs +8 -0
- package/dist/openai-JR2WEKOF.js +10 -0
- package/dist/openai-YBTOET4O.cjs +10 -0
- package/dist/openrouter-models-OU4GRZQY.cjs +15 -0
- package/dist/{openrouter-models-2FM3H4SQ.js → openrouter-models-TGKDKY52.js} +2 -2
- package/dist/openrouter-sync-BBHUM3R6.cjs +11 -0
- package/dist/{openrouter-sync-SO3AWEAM.js → openrouter-sync-UXUSJCIR.js} +3 -3
- package/dist/product/index.cjs +17 -15
- package/dist/product/index.js +16 -14
- package/dist/protocol/server.d.ts +3 -1
- package/dist/protocol/types.d.ts +36 -2
- package/dist/run/index.cjs +17 -15
- package/dist/run/index.js +16 -14
- package/dist/services/index.d.ts +0 -1
- package/dist/session-manager-Q22BBMD3.js +8 -0
- package/dist/session-manager-XODQVL3C.cjs +8 -0
- package/dist/settings/schema.d.ts +267 -42
- package/dist/{tool-summary-RYNR4DDB.cjs → tool-summary-63DPIS7G.cjs} +4 -4
- package/dist/{tool-summary-2RUFL5QK.js → tool-summary-NP5CDBKG.js} +2 -2
- package/dist/tool-system/builtin/ask-user.d.ts +9 -1
- package/dist/tool-system/context.d.ts +31 -2
- package/dist/tool-system/executor.d.ts +4 -0
- package/dist/tool-system/investigation-guard.d.ts +37 -0
- package/dist/types.d.ts +13 -2
- package/dist/ui/components/AskUserPrompt.d.ts +8 -1
- package/dist/ui/components/DiffLine.d.ts +33 -0
- package/dist/ui/components/ModelManager.d.ts +34 -1
- package/dist/ui/components/OnboardingPrompt.d.ts +10 -1
- package/dist/ui/components/ProviderModelFlow.d.ts +58 -0
- package/dist/ui/components/UpdateBanner.d.ts +1 -0
- package/dist/updater-QW473OF4.cjs +17 -0
- package/dist/updater-VFUAHCVY.js +17 -0
- package/dist/utils/semver.d.ts +1 -0
- package/dist/utils/task-sanitizer.d.ts +6 -0
- package/package.json +1 -1
- package/dist/anthropic-P5VETAFI.cjs +0 -10
- package/dist/anthropic-W2GU3D76.js +0 -10
- package/dist/chunk-75E4BBFC.js +0 -224
- package/dist/chunk-FV2ARONZ.cjs +0 -224
- package/dist/client-base-TOVE25FA.js +0 -9
- package/dist/client-base-VDDIADAC.cjs +0 -9
- package/dist/compaction-D3KV2NWY.cjs +0 -31
- package/dist/devtools-WTC3NFNE.cjs +0 -6
- package/dist/file-history-HZWO2WQ5.js +0 -7
- package/dist/file-history-UQQILIY7.cjs +0 -7
- package/dist/manager-FWLOVEEK.cjs +0 -7
- package/dist/manager-GEXJLOIS.js +0 -7
- package/dist/mcp-manager-37GQLFGX.js +0 -8
- package/dist/mcp-manager-U77NEXBY.cjs +0 -8
- package/dist/memory-ADGOWADP.cjs +0 -9
- package/dist/openai-RXU5URYI.js +0 -10
- package/dist/openai-SQW4H2K4.cjs +0 -10
- package/dist/openrouter-models-PLCWZZYE.cjs +0 -15
- package/dist/openrouter-sync-K2WK3A2A.cjs +0 -11
- package/dist/services/compact.d.ts +0 -56
- package/dist/session-manager-HRSKENKB.cjs +0 -8
- package/dist/session-manager-NEKFEHF3.js +0 -8
- package/dist/updater-J7L7R6BY.cjs +0 -185
- package/dist/updater-LDBNYCAO.js +0 -185
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
__esm,
|
|
3
3
|
__export,
|
|
4
4
|
init_esm_shims
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MD32R22I.js";
|
|
6
6
|
|
|
7
7
|
// src/context/token-counter.ts
|
|
8
8
|
function estimateStringTokens(text) {
|
|
@@ -70,6 +70,7 @@ var init_token_counter = __esm({
|
|
|
70
70
|
// src/context/compaction.ts
|
|
71
71
|
var compaction_exports = {};
|
|
72
72
|
__export(compaction_exports, {
|
|
73
|
+
COMPACTABLE_TOOL_NAMES: () => COMPACTABLE_TOOL_NAMES,
|
|
73
74
|
adjustIndexToPreserveAPIInvariants: () => adjustIndexToPreserveAPIInvariants,
|
|
74
75
|
applySummaryCompaction: () => applySummaryCompaction,
|
|
75
76
|
applyToolResultBudget: () => applyToolResultBudget,
|
|
@@ -143,35 +144,108 @@ function windowCompact(messages, keepLastN) {
|
|
|
143
144
|
if (startIndex <= 1) return messages;
|
|
144
145
|
return [messages[0], ...messages.slice(startIndex)];
|
|
145
146
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
const
|
|
147
|
+
function buildToolUseIdToNameMap(messages) {
|
|
148
|
+
const map = /* @__PURE__ */ new Map();
|
|
149
|
+
for (const msg of messages) {
|
|
150
|
+
if (!Array.isArray(msg.content)) continue;
|
|
151
|
+
for (const block of msg.content) {
|
|
152
|
+
if (block.type === "tool_use" && block.id && block.name) {
|
|
153
|
+
map.set(block.id, block.name);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return map;
|
|
158
|
+
}
|
|
159
|
+
function summarizeToolCallArgs(toolName, input) {
|
|
160
|
+
if (!input || typeof input !== "object") return "";
|
|
161
|
+
const pick = (keys) => {
|
|
162
|
+
const parts = [];
|
|
163
|
+
for (const key of keys) {
|
|
164
|
+
const v = input[key];
|
|
165
|
+
if (typeof v === "string" && v.length > 0) {
|
|
166
|
+
parts.push(`${key}=${v.length > 80 ? v.slice(0, 77) + "..." : v}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return parts.join(" ");
|
|
170
|
+
};
|
|
171
|
+
switch (toolName) {
|
|
172
|
+
case "Read":
|
|
173
|
+
case "Write":
|
|
174
|
+
case "Edit":
|
|
175
|
+
case "NotebookEdit":
|
|
176
|
+
return pick(["file_path", "path", "notebook_path"]);
|
|
177
|
+
case "Glob":
|
|
178
|
+
case "Grep":
|
|
179
|
+
return pick(["pattern", "path", "glob"]);
|
|
180
|
+
case "Bash":
|
|
181
|
+
case "PowerShell":
|
|
182
|
+
case "REPL":
|
|
183
|
+
return pick(["command"]);
|
|
184
|
+
case "WebFetch":
|
|
185
|
+
case "WebSearch":
|
|
186
|
+
return pick(["url", "query"]);
|
|
187
|
+
default: {
|
|
188
|
+
const json = JSON.stringify(input);
|
|
189
|
+
return json.length > 100 ? json.slice(0, 97) + "..." : json;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function microcompact(messages, options = {}) {
|
|
194
|
+
const keepRecentN = options.keepRecentN ?? 5;
|
|
195
|
+
const compactable = options.compactableTools ?? COMPACTABLE_TOOL_NAMES;
|
|
196
|
+
const idToName = buildToolUseIdToNameMap(messages);
|
|
197
|
+
const idToInput = /* @__PURE__ */ new Map();
|
|
198
|
+
for (const msg of messages) {
|
|
199
|
+
if (!Array.isArray(msg.content)) continue;
|
|
200
|
+
for (const block of msg.content) {
|
|
201
|
+
if (block.type === "tool_use" && block.id) {
|
|
202
|
+
idToInput.set(block.id, block.input);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let compactableRoundCount = 0;
|
|
207
|
+
const indicesToTouch = [];
|
|
149
208
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
150
209
|
const msg = messages[i];
|
|
151
|
-
if (Array.isArray(msg.content))
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
210
|
+
if (!Array.isArray(msg.content)) continue;
|
|
211
|
+
const hasEligible = msg.content.some(
|
|
212
|
+
(b) => b.type === "tool_result" && b.tool_use_id != null && compactable.has(idToName.get(b.tool_use_id) ?? "") && typeof b.content === "string" && !b.content.startsWith("[Old tool result cleared")
|
|
213
|
+
);
|
|
214
|
+
if (!hasEligible) continue;
|
|
215
|
+
compactableRoundCount++;
|
|
216
|
+
if (compactableRoundCount > keepRecentN) {
|
|
217
|
+
indicesToTouch.push(i);
|
|
159
218
|
}
|
|
160
219
|
}
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
220
|
+
if (indicesToTouch.length === 0) return messages;
|
|
221
|
+
const touchSet = new Set(indicesToTouch);
|
|
222
|
+
const clearedToolNames = /* @__PURE__ */ new Set();
|
|
223
|
+
let clearedBlocks = 0;
|
|
224
|
+
const result = messages.map((msg, i) => {
|
|
225
|
+
if (!touchSet.has(i) || !Array.isArray(msg.content)) return msg;
|
|
165
226
|
return {
|
|
166
227
|
...msg,
|
|
167
228
|
content: msg.content.map((block) => {
|
|
168
|
-
if (block.type
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return block;
|
|
229
|
+
if (block.type !== "tool_result" || !block.tool_use_id) return block;
|
|
230
|
+
const toolName = idToName.get(block.tool_use_id);
|
|
231
|
+
if (!toolName || !compactable.has(toolName)) return block;
|
|
232
|
+
if (typeof block.content !== "string") return block;
|
|
233
|
+
if (block.content.startsWith("[Old tool result cleared")) return block;
|
|
234
|
+
const argsSummary = summarizeToolCallArgs(toolName, idToInput.get(block.tool_use_id));
|
|
235
|
+
const fingerprint = argsSummary ? `[Old tool result cleared \u2014 ${toolName} ${argsSummary}]` : `[Old tool result cleared \u2014 ${toolName}]`;
|
|
236
|
+
clearedToolNames.add(toolName);
|
|
237
|
+
clearedBlocks++;
|
|
238
|
+
return { ...block, content: fingerprint };
|
|
172
239
|
})
|
|
173
240
|
};
|
|
174
241
|
});
|
|
242
|
+
if (clearedBlocks > 0) {
|
|
243
|
+
options.onClear?.({
|
|
244
|
+
clearedRounds: indicesToTouch.length,
|
|
245
|
+
toolNames: [...clearedToolNames].sort()
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
175
249
|
}
|
|
176
250
|
function applyToolResultBudget(messages, maxTotalChars = 1e5) {
|
|
177
251
|
return messages.map((msg) => {
|
|
@@ -200,9 +274,10 @@ function applyToolResultBudget(messages, maxTotalChars = 1e5) {
|
|
|
200
274
|
const newContent = msg.content.map((block, i) => {
|
|
201
275
|
if (!toTruncate.has(i)) return block;
|
|
202
276
|
const preview = typeof block.content === "string" ? block.content.slice(0, 500) : "";
|
|
277
|
+
const sizeKb = (block.content.length / 1e3).toFixed(0);
|
|
203
278
|
return {
|
|
204
279
|
...block,
|
|
205
|
-
content: `Output too large (${
|
|
280
|
+
content: `Output too large (${sizeKb}KB) \u2014 truncated to fit the per-message budget. Re-run the originating tool if you need the full output.
|
|
206
281
|
|
|
207
282
|
Preview (first 500 chars):
|
|
208
283
|
${preview}`
|
|
@@ -325,10 +400,22 @@ function extractReferencedFilePaths(messages) {
|
|
|
325
400
|
}
|
|
326
401
|
return [...paths];
|
|
327
402
|
}
|
|
403
|
+
var COMPACTABLE_TOOL_NAMES;
|
|
328
404
|
var init_compaction = __esm({
|
|
329
405
|
"src/context/compaction.ts"() {
|
|
330
406
|
init_esm_shims();
|
|
331
407
|
init_token_counter();
|
|
408
|
+
COMPACTABLE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
409
|
+
"Read",
|
|
410
|
+
"Glob",
|
|
411
|
+
"Grep",
|
|
412
|
+
"Bash",
|
|
413
|
+
"PowerShell",
|
|
414
|
+
"NotebookEdit",
|
|
415
|
+
"WebFetch",
|
|
416
|
+
"WebSearch",
|
|
417
|
+
"REPL"
|
|
418
|
+
]);
|
|
332
419
|
}
|
|
333
420
|
});
|
|
334
421
|
|
|
@@ -337,6 +424,7 @@ export {
|
|
|
337
424
|
adjustIndexToPreserveAPIInvariants,
|
|
338
425
|
snipCompact,
|
|
339
426
|
windowCompact,
|
|
427
|
+
COMPACTABLE_TOOL_NAMES,
|
|
340
428
|
microcompact,
|
|
341
429
|
applyToolResultBudget,
|
|
342
430
|
truncateToolResult,
|
|
@@ -1,12 +1,12 @@
|
|
|
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
|
|
3
|
+
var _chunkQRM7IF2Scjs = require('./chunk-QRM7IF2S.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
7
7
|
|
|
8
8
|
// src/data/openrouter-sync.ts
|
|
9
|
-
|
|
9
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
10
10
|
var ENDPOINT = "https://openrouter.ai/api/v1/models";
|
|
11
11
|
function priceToPerMillion(raw) {
|
|
12
12
|
if (!raw) return 0;
|
|
@@ -37,7 +37,7 @@ async function syncOpenRouterCatalog(timeoutMs = 15e3) {
|
|
|
37
37
|
const payload = await res.json();
|
|
38
38
|
const raw = _nullishCoalesce(payload.data, () => ( []));
|
|
39
39
|
const models = raw.map(slim).sort((a, b) => b.created - a.created);
|
|
40
|
-
|
|
40
|
+
_chunkQRM7IF2Scjs.setOpenRouterSnapshot.call(void 0, {
|
|
41
41
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42
42
|
source: ENDPOINT,
|
|
43
43
|
count: models.length,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readCache
|
|
3
|
+
} from "./chunk-3OA5G4TM.js";
|
|
1
4
|
import {
|
|
2
5
|
init_esm_shims
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MD32R22I.js";
|
|
4
7
|
|
|
5
8
|
// src/llm/model-pool.ts
|
|
6
9
|
init_esm_shims();
|
|
@@ -18,6 +21,32 @@ function lookupBuiltinContextWindow(model) {
|
|
|
18
21
|
var ModelPool = class {
|
|
19
22
|
models = /* @__PURE__ */ new Map();
|
|
20
23
|
activeKey;
|
|
24
|
+
providerCatalog;
|
|
25
|
+
cacheDir;
|
|
26
|
+
setProviderCatalog(cat) {
|
|
27
|
+
this.providerCatalog = cat;
|
|
28
|
+
}
|
|
29
|
+
setCacheDir(dir) {
|
|
30
|
+
this.cacheDir = dir;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* For each entry in the pool that lacks an explicit maxContextTokens
|
|
34
|
+
* but has a providerKey, look up the contextLength from the cached
|
|
35
|
+
* model list and patch it in.
|
|
36
|
+
*/
|
|
37
|
+
reloadCachedContextWindows() {
|
|
38
|
+
if (!this.cacheDir) return;
|
|
39
|
+
for (const [key, entry] of this.models) {
|
|
40
|
+
if (entry.maxContextTokens != null) continue;
|
|
41
|
+
if (!entry.providerKey) continue;
|
|
42
|
+
const file = readCache(this.cacheDir, entry.providerKey);
|
|
43
|
+
if (!file) continue;
|
|
44
|
+
const match = file.models.find((m) => m.id === entry.model);
|
|
45
|
+
if (match?.contextLength) {
|
|
46
|
+
this.models.set(key, { ...entry, maxContextTokens: match.contextLength });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
21
50
|
/**
|
|
22
51
|
* Build a pool from an array of model entries.
|
|
23
52
|
* The first entry (or the one matching `defaultKey`) becomes active.
|
|
@@ -85,11 +114,17 @@ var ModelPool = class {
|
|
|
85
114
|
* (inherits apiKey, baseUrl, etc. from the base if not set on the entry).
|
|
86
115
|
*/
|
|
87
116
|
toLLMConfig(entry, base) {
|
|
117
|
+
const fromCat = entry.providerKey && this.providerCatalog ? this.providerCatalog.get(entry.providerKey) : void 0;
|
|
118
|
+
const kindToClientProvider = (kind) => {
|
|
119
|
+
if (!kind) return "openai";
|
|
120
|
+
if (kind === "anthropic") return "anthropic";
|
|
121
|
+
return "openai";
|
|
122
|
+
};
|
|
88
123
|
return {
|
|
89
|
-
provider: entry.provider,
|
|
124
|
+
provider: entry.provider || kindToClientProvider(fromCat?.kind) || "openai",
|
|
90
125
|
model: entry.model,
|
|
91
|
-
apiKey: entry.apiKey ?? base?.apiKey,
|
|
92
|
-
baseUrl: entry.baseUrl ?? base?.baseUrl,
|
|
126
|
+
apiKey: entry.apiKey ?? fromCat?.apiKey ?? base?.apiKey,
|
|
127
|
+
baseUrl: entry.baseUrl ?? fromCat?.baseUrl ?? base?.baseUrl,
|
|
93
128
|
temperature: base?.temperature ?? 0.3,
|
|
94
129
|
maxTokens: entry.maxOutputTokens ?? base?.maxTokens ?? 8192,
|
|
95
130
|
enableStreaming: base?.enableStreaming ?? true
|