@cjhyy/code-shell 0.1.5 → 0.1.7
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 +30 -0
- package/dist/anthropic-UBSB5AQH.js +1 -0
- package/dist/arena/index.js +1 -104
- package/dist/arena-OW55ZCHT.js +3 -0
- package/dist/bwrap-PVZMLHZR.js +2 -0
- package/dist/chunk-2NS3JMNK.js +1 -0
- package/dist/chunk-3QP5BQ3L.js +1 -0
- package/dist/chunk-B7K2OWKC.js +2 -0
- package/dist/chunk-EWWK56K6.js +2 -0
- package/dist/chunk-FU7AHZNN.js +1 -0
- package/dist/chunk-HIJ2XXGX.js +1 -0
- package/dist/chunk-KCXSARAA.js +1 -0
- package/dist/chunk-NFH3UQ3E.js +2 -0
- package/dist/chunk-NMBYBGC7.js +250 -0
- package/dist/chunk-NVAZJ5XS.js +2 -0
- package/dist/chunk-O5HFCH2U.js +1 -0
- package/dist/chunk-P6JSTIFM.js +1 -0
- package/dist/chunk-PGANL6F2.js +3 -0
- package/dist/chunk-Q4O2HGWS.js +251 -0
- package/dist/chunk-QTWU7UNA.js +5 -0
- package/dist/chunk-RP26WO4R.js +1 -0
- package/dist/chunk-SNFAPSLA.js +1 -0
- package/dist/chunk-T222K6IV.js +18 -0
- package/dist/chunk-TKJA6W36.js +3 -0
- package/dist/chunk-UDPUTFQT.js +2 -0
- package/dist/chunk-W47Z7MGS.js +33 -0
- package/dist/chunk-WI6FSWGU.js +1 -0
- package/dist/chunk-WOP6MJKW.js +1 -0
- package/dist/chunk-XDOWC7EG.js +4 -0
- package/dist/chunk-Y2NS6HPO.js +641 -0
- package/dist/cli/main.js +303 -22037
- package/dist/cli/updater.d.ts +8 -0
- package/dist/client-base-6ZZJJYDY.js +1 -0
- package/dist/compaction-ECVQVOCT.js +1 -0
- package/dist/devtools-SGDUOOM4.js +1 -0
- package/dist/engine/engine.d.ts +15 -0
- package/dist/export-md-U72T7NW7.js +22 -0
- package/dist/file-history-7FQFEQOL.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -347
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/manager-C3TDN6MS.js +1 -0
- package/dist/mcp-manager-OP4XYV53.js +1 -0
- package/dist/memory-BNI4WEWL.js +1 -0
- package/dist/model-cache-HEDXI7UJ.js +1 -0
- package/dist/model-fetcher-BJ64META.js +1 -0
- package/dist/off-7SDVMMXW.js +1 -0
- package/dist/openai-KEWQ54TM.js +1 -0
- package/dist/openrouter-models-AM6M52D6.js +1 -0
- package/dist/openrouter-sync-5JNBL3Z6.js +1 -0
- package/dist/product/index.js +1 -21
- package/dist/run/index.js +1 -48
- package/dist/seatbelt-WBYROQT6.js +37 -0
- package/dist/session/session-manager.d.ts +2 -0
- package/dist/session-manager-AGWS5SMJ.js +1 -0
- package/dist/settings/schema.d.ts +72 -6
- package/dist/tool-summary-5UE62VU4.js +2 -0
- package/dist/tool-system/builtin/bash.d.ts +7 -1
- package/dist/tool-system/context.d.ts +7 -0
- package/dist/tool-system/investigation-guard.d.ts +9 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/index.d.ts +71 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/types.d.ts +4 -0
- package/dist/ui/components/SessionPicker.d.ts +2 -0
- package/dist/ui/components/SpinnerWithVerb.d.ts +2 -2
- package/dist/ui/components/StatusLine.d.ts +2 -2
- package/dist/updater-OCNU2K2Z.js +1 -0
- package/package.json +8 -10
- package/skills-builtin/codeshell-help.md +135 -0
- package/dist/anthropic-IBTI4WL2.cjs +0 -10
- package/dist/anthropic-PRZZKHEZ.js +0 -10
- package/dist/arena/index.cjs +0 -104
- package/dist/arena-KBQOPLFV.cjs +0 -261
- package/dist/arena-O2L4TN6A.js +0 -261
- package/dist/chunk-2EP3CLEN.js +0 -44
- package/dist/chunk-2YW4FPFG.cjs +0 -101
- package/dist/chunk-3OA5G4TM.js +0 -47
- package/dist/chunk-52LGZKT3.cjs +0 -47
- package/dist/chunk-55XGPMAP.cjs +0 -146
- package/dist/chunk-5ECBT4YA.js +0 -450
- package/dist/chunk-6QVAYW7C.cjs +0 -438
- package/dist/chunk-6S4BJ65N.js +0 -113
- package/dist/chunk-76HYEPDM.js +0 -307
- package/dist/chunk-76W334S4.js +0 -54
- package/dist/chunk-7EG3V4JY.cjs +0 -113
- package/dist/chunk-7JVTYEEC.js +0 -340
- package/dist/chunk-7K6SDRRF.js +0 -9047
- package/dist/chunk-7Y6S3OCX.js +0 -438
- package/dist/chunk-A5LCRPDP.cjs +0 -54
- package/dist/chunk-BSW22MPA.js +0 -146
- package/dist/chunk-BUU5PZK2.cjs +0 -9048
- package/dist/chunk-BWTOS5BH.cjs +0 -5128
- package/dist/chunk-BXCY2FSE.js +0 -203
- package/dist/chunk-C5YQBIRK.js +0 -5128
- package/dist/chunk-HEKQCI7B.cjs +0 -224
- package/dist/chunk-HS2MFNUC.cjs +0 -44
- package/dist/chunk-IK4EWJBP.cjs +0 -203
- package/dist/chunk-JMR33QVF.cjs +0 -169
- package/dist/chunk-KOVYSDHZ.cjs +0 -340
- package/dist/chunk-KS3RYAYL.cjs +0 -45
- package/dist/chunk-MD32R22I.js +0 -50
- package/dist/chunk-MY5XHADU.cjs +0 -216
- package/dist/chunk-NUNC3VFB.cjs +0 -307
- package/dist/chunk-QRM7IF2S.cjs +0 -4711
- package/dist/chunk-R47ROHGL.cjs +0 -298
- package/dist/chunk-RMYKO74M.js +0 -1252
- package/dist/chunk-SFXHZSRF.js +0 -101
- package/dist/chunk-SIHHIQLO.js +0 -224
- package/dist/chunk-SNT563K3.cjs +0 -107
- package/dist/chunk-T6VYG46N.js +0 -105
- package/dist/chunk-TUY2T5KP.cjs +0 -105
- package/dist/chunk-VIAGTYYW.js +0 -169
- package/dist/chunk-VYL4EFRC.cjs +0 -1252
- package/dist/chunk-W22P377T.js +0 -299
- package/dist/chunk-WASS5YWB.js +0 -215
- package/dist/chunk-XDIQWQJ4.js +0 -4711
- package/dist/chunk-YIQBXAYU.cjs +0 -264
- package/dist/chunk-YJ77GQK5.js +0 -107
- package/dist/chunk-YUI524OE.cjs +0 -450
- package/dist/chunk-ZBPSQCPU.js +0 -264
- package/dist/cli/main.cjs +0 -22133
- package/dist/client-base-HTF236ZD.cjs +0 -9
- package/dist/client-base-QKRKCOWB.js +0 -9
- package/dist/compaction-6VU2T643.js +0 -33
- package/dist/compaction-OKUNTCA7.cjs +0 -33
- package/dist/devtools-T2NIZBJK.cjs +0 -6
- package/dist/devtools-YXWHOVKR.js +0 -6
- package/dist/export-md-RXDW6F5W.cjs +0 -135
- package/dist/export-md-XXKZANW5.js +0 -135
- package/dist/file-history-KYPE3ECT.cjs +0 -7
- package/dist/file-history-LF4F7X26.js +0 -7
- package/dist/index.cjs +0 -347
- package/dist/manager-C2IUXKRC.js +0 -7
- package/dist/manager-YYKWYTRM.cjs +0 -7
- package/dist/mcp-manager-QMKWPBZ4.js +0 -8
- package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
- package/dist/memory-5LWZ6FI2.cjs +0 -9
- package/dist/memory-VIJLBAMQ.js +0 -9
- package/dist/model-cache-5KIYL5SL.js +0 -13
- package/dist/model-cache-OED3IM4R.cjs +0 -13
- package/dist/model-fetcher-HKGICACL.js +0 -8
- package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
- package/dist/openai-JR2WEKOF.js +0 -10
- package/dist/openai-YBTOET4O.cjs +0 -10
- package/dist/openrouter-models-OU4GRZQY.cjs +0 -15
- package/dist/openrouter-models-TGKDKY52.js +0 -15
- package/dist/openrouter-sync-BBHUM3R6.cjs +0 -11
- package/dist/openrouter-sync-UXUSJCIR.js +0 -11
- package/dist/product/index.cjs +0 -21
- package/dist/run/index.cjs +0 -48
- package/dist/session-manager-Q22BBMD3.js +0 -8
- package/dist/session-manager-XODQVL3C.cjs +0 -8
- package/dist/tool-summary-63DPIS7G.cjs +0 -31
- package/dist/tool-summary-NP5CDBKG.js +0 -31
- package/dist/updater-QW473OF4.cjs +0 -17
- package/dist/updater-VFUAHCVY.js +0 -17
package/dist/chunk-2YW4FPFG.cjs
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
4
|
-
|
|
5
|
-
// src/exceptions.ts
|
|
6
|
-
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
7
|
-
var FrameworkError = class extends Error {
|
|
8
|
-
constructor(message, details) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.details = details;
|
|
11
|
-
this.name = "FrameworkError";
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var LLMError = class extends FrameworkError {
|
|
15
|
-
constructor(message, provider, details) {
|
|
16
|
-
super(message, details);
|
|
17
|
-
this.provider = provider;
|
|
18
|
-
this.name = "LLMError";
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var LLMRateLimitError = class extends LLMError {
|
|
22
|
-
constructor(provider, retryAfter) {
|
|
23
|
-
super(`Rate limit exceeded for ${provider}`, provider, { retryAfter });
|
|
24
|
-
this.retryAfter = retryAfter;
|
|
25
|
-
this.name = "LLMRateLimitError";
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var ContextLimitError = class extends LLMError {
|
|
29
|
-
constructor(provider) {
|
|
30
|
-
super("Context limit exceeded", provider);
|
|
31
|
-
this.name = "ContextLimitError";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var ToolError = class extends FrameworkError {
|
|
35
|
-
constructor(message, toolName, details) {
|
|
36
|
-
super(message, details);
|
|
37
|
-
this.toolName = toolName;
|
|
38
|
-
this.name = "ToolError";
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var ToolNotFoundError = class extends ToolError {
|
|
42
|
-
constructor(toolName) {
|
|
43
|
-
super(`Tool not found: ${toolName}`, toolName);
|
|
44
|
-
this.name = "ToolNotFoundError";
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var ToolExecutionError = class extends ToolError {
|
|
48
|
-
constructor(toolName, cause) {
|
|
49
|
-
super(`Tool execution failed: ${toolName} - ${cause}`, toolName, { cause });
|
|
50
|
-
this.name = "ToolExecutionError";
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var ToolTimeoutError = class extends ToolError {
|
|
54
|
-
constructor(toolName, timeoutMs) {
|
|
55
|
-
super(`Tool timed out after ${timeoutMs}ms: ${toolName}`, toolName, { timeoutMs });
|
|
56
|
-
this.timeoutMs = timeoutMs;
|
|
57
|
-
this.name = "ToolTimeoutError";
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var PermissionDeniedError = class extends FrameworkError {
|
|
61
|
-
constructor(toolName, reason) {
|
|
62
|
-
super(`Permission denied for tool: ${toolName}${reason ? ` - ${reason}` : ""}`, {
|
|
63
|
-
toolName,
|
|
64
|
-
reason
|
|
65
|
-
});
|
|
66
|
-
this.name = "PermissionDeniedError";
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
var SessionError = class extends FrameworkError {
|
|
70
|
-
constructor(message, details) {
|
|
71
|
-
super(message, details);
|
|
72
|
-
this.name = "SessionError";
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var TranscriptError = class extends FrameworkError {
|
|
76
|
-
constructor(message, details) {
|
|
77
|
-
super(message, details);
|
|
78
|
-
this.name = "TranscriptError";
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
var ConfigError = class extends FrameworkError {
|
|
82
|
-
constructor(message, details) {
|
|
83
|
-
super(message, details);
|
|
84
|
-
this.name = "ConfigError";
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
exports.FrameworkError = FrameworkError; exports.LLMError = LLMError; exports.LLMRateLimitError = LLMRateLimitError; exports.ContextLimitError = ContextLimitError; exports.ToolError = ToolError; exports.ToolNotFoundError = ToolNotFoundError; exports.ToolExecutionError = ToolExecutionError; exports.ToolTimeoutError = ToolTimeoutError; exports.PermissionDeniedError = PermissionDeniedError; exports.SessionError = SessionError; exports.TranscriptError = TranscriptError; exports.ConfigError = ConfigError;
|
package/dist/chunk-3OA5G4TM.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init_esm_shims
|
|
3
|
-
} from "./chunk-MD32R22I.js";
|
|
4
|
-
|
|
5
|
-
// src/llm/model-cache.ts
|
|
6
|
-
init_esm_shims();
|
|
7
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
8
|
-
import { homedir } from "os";
|
|
9
|
-
import { join } from "path";
|
|
10
|
-
var TTL_MS = 7 * 24 * 3600 * 1e3;
|
|
11
|
-
function readCache(cacheDir, providerKey) {
|
|
12
|
-
const path = join(cacheDir, `${providerKey}.json`);
|
|
13
|
-
if (!existsSync(path)) return void 0;
|
|
14
|
-
try {
|
|
15
|
-
const raw = readFileSync(path, "utf-8");
|
|
16
|
-
const parsed = JSON.parse(raw);
|
|
17
|
-
if (!parsed || !Array.isArray(parsed.models)) return void 0;
|
|
18
|
-
return parsed;
|
|
19
|
-
} catch {
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function writeCache(cacheDir, providerKey, models) {
|
|
24
|
-
if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true });
|
|
25
|
-
const payload = {
|
|
26
|
-
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27
|
-
providerKey,
|
|
28
|
-
models
|
|
29
|
-
};
|
|
30
|
-
writeFileSync(join(cacheDir, `${providerKey}.json`), JSON.stringify(payload, null, 2), "utf-8");
|
|
31
|
-
return payload;
|
|
32
|
-
}
|
|
33
|
-
function isStale(file, now = Date.now()) {
|
|
34
|
-
const ts = Date.parse(file.fetchedAt);
|
|
35
|
-
if (!Number.isFinite(ts)) return true;
|
|
36
|
-
return now - ts > TTL_MS;
|
|
37
|
-
}
|
|
38
|
-
function defaultCacheDir() {
|
|
39
|
-
return join(homedir(), ".code-shell", "cache", "models");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
readCache,
|
|
44
|
-
writeCache,
|
|
45
|
-
isStale,
|
|
46
|
-
defaultCacheDir
|
|
47
|
-
};
|
package/dist/chunk-52LGZKT3.cjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
4
|
-
|
|
5
|
-
// src/llm/model-cache.ts
|
|
6
|
-
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
7
|
-
var _fs = require('fs');
|
|
8
|
-
var _os = require('os');
|
|
9
|
-
var _path = require('path');
|
|
10
|
-
var TTL_MS = 7 * 24 * 3600 * 1e3;
|
|
11
|
-
function readCache(cacheDir, providerKey) {
|
|
12
|
-
const path = _path.join.call(void 0, cacheDir, `${providerKey}.json`);
|
|
13
|
-
if (!_fs.existsSync.call(void 0, path)) return void 0;
|
|
14
|
-
try {
|
|
15
|
-
const raw = _fs.readFileSync.call(void 0, path, "utf-8");
|
|
16
|
-
const parsed = JSON.parse(raw);
|
|
17
|
-
if (!parsed || !Array.isArray(parsed.models)) return void 0;
|
|
18
|
-
return parsed;
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function writeCache(cacheDir, providerKey, models) {
|
|
24
|
-
if (!_fs.existsSync.call(void 0, cacheDir)) _fs.mkdirSync.call(void 0, cacheDir, { recursive: true });
|
|
25
|
-
const payload = {
|
|
26
|
-
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27
|
-
providerKey,
|
|
28
|
-
models
|
|
29
|
-
};
|
|
30
|
-
_fs.writeFileSync.call(void 0, _path.join.call(void 0, cacheDir, `${providerKey}.json`), JSON.stringify(payload, null, 2), "utf-8");
|
|
31
|
-
return payload;
|
|
32
|
-
}
|
|
33
|
-
function isStale(file, now = Date.now()) {
|
|
34
|
-
const ts = Date.parse(file.fetchedAt);
|
|
35
|
-
if (!Number.isFinite(ts)) return true;
|
|
36
|
-
return now - ts > TTL_MS;
|
|
37
|
-
}
|
|
38
|
-
function defaultCacheDir() {
|
|
39
|
-
return _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "cache", "models");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
exports.readCache = readCache; exports.writeCache = writeCache; exports.isStale = isStale; exports.defaultCacheDir = defaultCacheDir;
|
package/dist/chunk-55XGPMAP.cjs
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
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; } var _class;
|
|
2
|
-
|
|
3
|
-
var _chunk52LGZKT3cjs = require('./chunk-52LGZKT3.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
7
|
-
|
|
8
|
-
// src/llm/model-pool.ts
|
|
9
|
-
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
10
|
-
var BUILTIN_CONTEXT_WINDOWS = [
|
|
11
|
-
// DeepSeek V4 family — 1M context (api-docs.deepseek.com)
|
|
12
|
-
[/^deepseek-v4(?:-|$)/i, 1e6],
|
|
13
|
-
[/(?:^|\/)deepseek-v4(?:-|$)/i, 1e6]
|
|
14
|
-
];
|
|
15
|
-
function lookupBuiltinContextWindow(model) {
|
|
16
|
-
for (const [re, tokens] of BUILTIN_CONTEXT_WINDOWS) {
|
|
17
|
-
if (re.test(model)) return tokens;
|
|
18
|
-
}
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
|
-
var ModelPool = (_class = class {
|
|
22
|
-
__init() {this.models = /* @__PURE__ */ new Map()}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 = _chunk52LGZKT3cjs.readCache.call(void 0, this.cacheDir, entry.providerKey);
|
|
43
|
-
if (!file) continue;
|
|
44
|
-
const match = file.models.find((m) => m.id === entry.model);
|
|
45
|
-
if (_optionalChain([match, 'optionalAccess', _ => _.contextLength])) {
|
|
46
|
-
this.models.set(key, { ...entry, maxContextTokens: match.contextLength });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Build a pool from an array of model entries.
|
|
52
|
-
* The first entry (or the one matching `defaultKey`) becomes active.
|
|
53
|
-
*/
|
|
54
|
-
constructor(entries, defaultKey) {;_class.prototype.__init.call(this);
|
|
55
|
-
if (entries) {
|
|
56
|
-
for (const e of entries) {
|
|
57
|
-
this.models.set(e.key, this.withBuiltinDefaults(e));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (defaultKey && this.models.has(defaultKey)) {
|
|
61
|
-
this.activeKey = defaultKey;
|
|
62
|
-
} else if (_optionalChain([entries, 'optionalAccess', _2 => _2.length])) {
|
|
63
|
-
this.activeKey = entries[0].key;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** Register a model at runtime. */
|
|
67
|
-
register(entry) {
|
|
68
|
-
this.models.set(entry.key, this.withBuiltinDefaults(entry));
|
|
69
|
-
if (!this.activeKey) {
|
|
70
|
-
this.activeKey = entry.key;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/** Fill in known defaults (e.g. context window for DeepSeek V4) when the entry doesn't specify them. */
|
|
74
|
-
withBuiltinDefaults(entry) {
|
|
75
|
-
if (entry.maxContextTokens != null) return entry;
|
|
76
|
-
const builtin = lookupBuiltinContextWindow(entry.model);
|
|
77
|
-
if (builtin == null) return entry;
|
|
78
|
-
return { ...entry, maxContextTokens: builtin };
|
|
79
|
-
}
|
|
80
|
-
/** Switch the active model. Throws if key not found. */
|
|
81
|
-
switch(key) {
|
|
82
|
-
const entry = this.models.get(key);
|
|
83
|
-
if (!entry) {
|
|
84
|
-
const available = [...this.models.keys()].join(", ");
|
|
85
|
-
throw new Error(`Model "${key}" not found. Available: ${available}`);
|
|
86
|
-
}
|
|
87
|
-
this.activeKey = key;
|
|
88
|
-
return entry;
|
|
89
|
-
}
|
|
90
|
-
/** Get a model by key. No key = active model. Returns undefined if not found. */
|
|
91
|
-
get(key) {
|
|
92
|
-
if (key) return this.models.get(key);
|
|
93
|
-
if (this.activeKey) return this.models.get(this.activeKey);
|
|
94
|
-
return void 0;
|
|
95
|
-
}
|
|
96
|
-
/** Get the active model key. */
|
|
97
|
-
getActiveKey() {
|
|
98
|
-
return this.activeKey;
|
|
99
|
-
}
|
|
100
|
-
/** List all registered models. */
|
|
101
|
-
list() {
|
|
102
|
-
return [...this.models.values()];
|
|
103
|
-
}
|
|
104
|
-
/** Number of registered models. */
|
|
105
|
-
get size() {
|
|
106
|
-
return this.models.size;
|
|
107
|
-
}
|
|
108
|
-
/** Check if a key exists. */
|
|
109
|
-
has(key) {
|
|
110
|
-
return this.models.has(key);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Build an LLMConfig for a given model entry, merging with a base config
|
|
114
|
-
* (inherits apiKey, baseUrl, etc. from the base if not set on the entry).
|
|
115
|
-
*/
|
|
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
|
-
};
|
|
123
|
-
return {
|
|
124
|
-
provider: entry.provider || kindToClientProvider(_optionalChain([fromCat, 'optionalAccess', _3 => _3.kind])) || "openai",
|
|
125
|
-
model: entry.model,
|
|
126
|
-
apiKey: _nullishCoalesce(_nullishCoalesce(entry.apiKey, () => ( _optionalChain([fromCat, 'optionalAccess', _4 => _4.apiKey]))), () => ( _optionalChain([base, 'optionalAccess', _5 => _5.apiKey]))),
|
|
127
|
-
baseUrl: _nullishCoalesce(_nullishCoalesce(entry.baseUrl, () => ( _optionalChain([fromCat, 'optionalAccess', _6 => _6.baseUrl]))), () => ( _optionalChain([base, 'optionalAccess', _7 => _7.baseUrl]))),
|
|
128
|
-
temperature: _nullishCoalesce(_optionalChain([base, 'optionalAccess', _8 => _8.temperature]), () => ( 0.3)),
|
|
129
|
-
maxTokens: _nullishCoalesce(_nullishCoalesce(entry.maxOutputTokens, () => ( _optionalChain([base, 'optionalAccess', _9 => _9.maxTokens]))), () => ( 8192)),
|
|
130
|
-
enableStreaming: _nullishCoalesce(_optionalChain([base, 'optionalAccess', _10 => _10.enableStreaming]), () => ( true))
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Build an LLMConfig for the active model (or a specific key),
|
|
135
|
-
* merging with a base config.
|
|
136
|
-
*/
|
|
137
|
-
resolveLLMConfig(key, base) {
|
|
138
|
-
const entry = this.get(key);
|
|
139
|
-
if (!entry) return void 0;
|
|
140
|
-
return this.toLLMConfig(entry, base);
|
|
141
|
-
}
|
|
142
|
-
}, _class);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
exports.ModelPool = ModelPool;
|