@uncarved/jade 0.2.0 → 0.3.0
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/README.md +277 -0
- package/assets/logo.svg +1 -0
- package/bin/jade.js +15 -0
- package/dist/api.d.ts +5 -250
- package/dist/api.js +5 -7
- package/dist/api.js.map +1 -1
- package/dist/fetch.d.ts +8 -0
- package/dist/fetch.js +19 -17
- package/dist/fetch.js.map +1 -1
- package/dist/host.d.ts +12 -1
- package/dist/host.js +49 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +28 -5
- package/dist/main.js.map +1 -1
- package/dist/remote.js +4 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +2 -0
- package/dist/session.js +133 -13
- package/dist/session.js.map +1 -1
- package/dist/source.d.ts +2 -10
- package/dist/source.js.map +1 -1
- package/dist/update.d.ts +8 -20
- package/dist/update.js +12 -1
- package/dist/update.js.map +1 -1
- package/package.json +6 -4
- package/plugins/approval/index.ts +246 -84
- package/plugins/approval/plugin.json +5 -1
- package/plugins/approval/policy.ts +27 -6
- package/plugins/approval/review.ts +1 -1
- package/plugins/ask/index.ts +2 -2
- package/plugins/budget/index.ts +1 -1
- package/plugins/checks/checks.ts +3 -2
- package/plugins/checks/index.ts +2 -5
- package/plugins/commands/index.ts +2 -44
- package/plugins/compact/compact.ts +15 -4
- package/plugins/compact/index.ts +13 -16
- package/plugins/continue/index.ts +1 -1
- package/plugins/cost/index.ts +143 -0
- package/plugins/cost/plugin.json +13 -0
- package/plugins/custom-commands/index.ts +85 -0
- package/plugins/custom-commands/plugin.json +8 -0
- package/plugins/editor/index.ts +88 -0
- package/plugins/editor/plugin.json +17 -0
- package/plugins/fs/fs.ts +110 -17
- package/plugins/fs/grep.ts +41 -11
- package/plugins/fs/index.ts +9 -7
- package/plugins/fs/renderers.ts +1 -1
- package/plugins/hooks/index.ts +152 -0
- package/plugins/hooks/plugin.json +14 -0
- package/plugins/keys/index.ts +2 -18
- package/plugins/mcp/index.ts +40 -12
- package/plugins/mcp/install.ts +139 -0
- package/plugins/mcp/mcp.ts +2 -1
- package/plugins/mcp/plugin.json +1 -1
- package/plugins/mcp/project.ts +37 -1
- package/plugins/memory/index.ts +4 -9
- package/plugins/memory/plugin.json +1 -1
- package/plugins/mentions/index.ts +33 -13
- package/plugins/models/configure.ts +258 -150
- package/plugins/models/context.ts +2 -2
- package/plugins/models/index.ts +50 -42
- package/plugins/models/plugin.json +1 -1
- package/plugins/models/provider.ts +22 -4
- package/plugins/models/saved.ts +8 -4
- package/plugins/modes/index.ts +2 -17
- package/plugins/plugins/index.ts +2 -2
- package/plugins/print/index.ts +60 -12
- package/plugins/print/plugin.json +1 -0
- package/plugins/prompts/index.ts +50 -14
- package/plugins/{memory → prompts}/notes.ts +21 -9
- package/plugins/prompts/plugin.json +8 -2
- package/plugins/prompts/prompts.ts +14 -8
- package/plugins/prompts/results.ts +63 -0
- package/plugins/prompts/sys.ts +16 -4
- package/plugins/renderers/index.ts +2 -43
- package/plugins/repeats/index.ts +1 -1
- package/plugins/schedule/index.ts +2 -2
- package/plugins/scratch/index.ts +2 -3
- package/plugins/screenshot/index.ts +26 -13
- package/plugins/screenshot/plugin.json +1 -1
- package/plugins/sessions/index.ts +2 -17
- package/plugins/shell/index.ts +56 -6
- package/plugins/shell/plugin.json +3 -1
- package/plugins/shell/renderers.ts +1 -1
- package/plugins/shell/service.ts +2 -13
- package/plugins/shell/shell.ts +31 -16
- package/plugins/skills/index.ts +172 -37
- package/plugins/skills/install.ts +212 -0
- package/plugins/skills/plugin.json +3 -2
- package/plugins/skills/project.ts +38 -1
- package/plugins/skills/skills.ts +28 -9
- package/plugins/steer/index.ts +142 -0
- package/plugins/steer/plugin.json +8 -0
- package/plugins/suggest/index.ts +16 -11
- package/plugins/suggest/plugin.json +1 -1
- package/plugins/task/index.ts +8 -16
- package/plugins/task/plugin.json +9 -2
- package/plugins/task/subagent.ts +119 -15
- package/plugins/todo/index.ts +4 -4
- package/plugins/tui/editor.ts +10 -2
- package/plugins/tui/frontend.ts +130 -25
- package/plugins/tui/index.ts +3 -8
- package/plugins/tui/markdown.ts +51 -6
- package/plugins/tui/mascot.ts +505 -0
- package/plugins/tui/mentions.ts +48 -8
- package/plugins/tui/plugin.json +2 -2
- package/plugins/tui/screen.ts +6 -0
- package/plugins/tui/transcript.ts +22 -3
- package/plugins/tui/tui.ts +323 -95
- package/plugins/tui/vendor.ts +16 -0
- package/plugins/undo/checkpoint.ts +26 -2
- package/plugins/undo/index.ts +86 -24
- package/plugins/undo/plugin.json +8 -2
- package/plugins/undo/snapshot.ts +129 -0
- package/plugins/update/index.ts +11 -15
- package/plugins/update/plugin.json +2 -1
- package/plugins/web/index.ts +2 -5
- package/plugins/web/renderers.ts +1 -1
- package/plugins/web/web.ts +6 -5
- package/plugins-dist/approval/index.js +232 -50
- package/plugins-dist/approval/plugin.json +5 -1
- package/plugins-dist/approval/policy.js +27 -5
- package/plugins-dist/ask/index.js +1 -1
- package/plugins-dist/budget/index.js +1 -1
- package/plugins-dist/checks/checks.js +2 -1
- package/plugins-dist/checks/index.js +1 -1
- package/plugins-dist/commands/index.js +1 -1
- package/plugins-dist/compact/compact.js +13 -2
- package/plugins-dist/compact/index.js +12 -8
- package/plugins-dist/continue/index.js +1 -1
- package/plugins-dist/cost/index.js +135 -0
- package/plugins-dist/cost/plugin.json +16 -0
- package/plugins-dist/custom-commands/index.js +86 -0
- package/plugins-dist/custom-commands/plugin.json +12 -0
- package/plugins-dist/editor/index.js +89 -0
- package/plugins-dist/editor/plugin.json +21 -0
- package/plugins-dist/fs/fs.js +106 -17
- package/plugins-dist/fs/grep.js +40 -12
- package/plugins-dist/fs/index.js +8 -5
- package/plugins-dist/hooks/index.js +145 -0
- package/plugins-dist/hooks/plugin.json +19 -0
- package/plugins-dist/keys/index.js +1 -1
- package/plugins-dist/mcp/index.js +41 -9
- package/plugins-dist/mcp/install.js +160 -0
- package/plugins-dist/mcp/mcp.js +2 -1
- package/plugins-dist/mcp/plugin.json +2 -1
- package/plugins-dist/mcp/project.js +42 -1
- package/plugins-dist/memory/index.js +3 -5
- package/plugins-dist/memory/plugin.json +1 -1
- package/plugins-dist/mentions/index.js +29 -11
- package/plugins-dist/models/configure.js +252 -151
- package/plugins-dist/models/context.js +2 -2
- package/plugins-dist/models/index.js +53 -16
- package/plugins-dist/models/plugin.json +1 -1
- package/plugins-dist/models/provider.js +4 -2
- package/plugins-dist/models/saved.js +9 -4
- package/plugins-dist/modes/index.js +1 -1
- package/plugins-dist/plugins/index.js +1 -1
- package/plugins-dist/print/index.js +62 -9
- package/plugins-dist/print/plugin.json +3 -0
- package/plugins-dist/prompts/index.js +49 -2
- package/plugins-dist/{memory → prompts}/notes.js +10 -7
- package/plugins-dist/prompts/plugin.json +8 -2
- package/plugins-dist/prompts/prompts.js +13 -8
- package/plugins-dist/prompts/results.js +60 -0
- package/plugins-dist/prompts/sys.js +15 -3
- package/plugins-dist/renderers/index.js +1 -1
- package/plugins-dist/repeats/index.js +1 -1
- package/plugins-dist/schedule/index.js +1 -1
- package/plugins-dist/scratch/index.js +1 -1
- package/plugins-dist/screenshot/index.js +25 -11
- package/plugins-dist/screenshot/plugin.json +1 -1
- package/plugins-dist/sessions/index.js +1 -1
- package/plugins-dist/shell/index.js +55 -3
- package/plugins-dist/shell/plugin.json +3 -1
- package/plugins-dist/shell/shell.js +26 -8
- package/plugins-dist/skills/index.js +184 -35
- package/plugins-dist/skills/install.js +178 -0
- package/plugins-dist/skills/plugin.json +6 -2
- package/plugins-dist/skills/project.js +43 -1
- package/plugins-dist/skills/skills.js +27 -10
- package/plugins-dist/steer/index.js +135 -0
- package/plugins-dist/steer/plugin.json +12 -0
- package/plugins-dist/suggest/index.js +15 -9
- package/plugins-dist/suggest/plugin.json +1 -1
- package/plugins-dist/task/index.js +7 -4
- package/plugins-dist/task/plugin.json +10 -2
- package/plugins-dist/task/subagent.js +106 -15
- package/plugins-dist/todo/index.js +3 -3
- package/plugins-dist/tui/editor.js +7 -2
- package/plugins-dist/tui/frontend.js +135 -18
- package/plugins-dist/tui/index.js +2 -1
- package/plugins-dist/tui/markdown.js +48 -6
- package/plugins-dist/tui/mascot.js +439 -0
- package/plugins-dist/tui/mentions.js +44 -6
- package/plugins-dist/tui/plugin.json +3 -2
- package/plugins-dist/tui/screen.js +2 -0
- package/plugins-dist/tui/transcript.js +19 -2
- package/plugins-dist/tui/tui.js +303 -83
- package/plugins-dist/tui/vendor.js +13822 -0
- package/plugins-dist/undo/checkpoint.js +28 -1
- package/plugins-dist/undo/index.js +92 -22
- package/plugins-dist/undo/plugin.json +10 -3
- package/plugins-dist/undo/snapshot.js +111 -0
- package/plugins-dist/update/index.js +9 -10
- package/plugins-dist/update/plugin.json +4 -1
- package/plugins-dist/web/index.js +1 -1
- package/plugins-dist/web/web.js +6 -5
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +8 -0
- package/src/api.ts +7 -262
- package/src/fetch.ts +18 -16
- package/src/host.ts +49 -1
- package/src/index.ts +1 -1
- package/src/main.ts +25 -6
- package/src/remote.ts +2 -0
- package/src/session.ts +134 -15
- package/src/source.ts +2 -11
- package/src/update.ts +16 -10
- package/plugins/undo/notes.ts +0 -43
- package/plugins-dist/undo/notes.js +0 -36
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
8
8
|
import { hasProvider, parseTokens } from "./config.ts";
|
|
9
9
|
import { contextWindow } from "./context.ts";
|
|
10
|
-
import { EFFORTS, isBuiltinKind, KEY_KEY, listModels, MODEL_KEY, providerInfo, providerKind, rpmFromEnv, URL_KEY, visionFromEnv, type ProviderKind } from "./provider.ts";
|
|
10
|
+
import { EFFORTS, isBuiltinKind, jsonObject, KEY_KEY, listModels, MODEL_KEY, providerInfo, providerKind, rpmFromEnv, URL_KEY, visionFromEnv, type ProviderKind } from "./provider.ts";
|
|
11
11
|
import { MODEL_SETTINGS, readSavedServices, updateEnvFile, writeSavedServices, type Env, type SavedModel, type SavedService } from "./saved.ts";
|
|
12
|
-
import type { UI } from "
|
|
12
|
+
import type { UI } from "@uncarved/jade-api";
|
|
13
13
|
|
|
14
14
|
export interface ConfigureOptions {
|
|
15
15
|
envFile: string;
|
|
@@ -56,7 +56,7 @@ function visionHint(env: Env, kind: string): string {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** 一个服务包含的变量(不含模型名) */
|
|
59
|
-
const serviceKeys = (kind: ProviderKind) => ["JADE_PROVIDER", URL_KEY[kind], KEY_KEY[kind]
|
|
59
|
+
const serviceKeys = (kind: ProviderKind) => ["JADE_PROVIDER", URL_KEY[kind], KEY_KEY[kind]];
|
|
60
60
|
|
|
61
61
|
const pick = (env: Env, keys: string[]) => {
|
|
62
62
|
const out: Record<string, string> = {};
|
|
@@ -64,6 +64,13 @@ const pick = (env: Env, keys: string[]) => {
|
|
|
64
64
|
return out;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
/** keys 里明确清掉(设成默认)的那些:空字符串表示"不设",写进 models.json 时删掉;env 里没提到的不算 */
|
|
68
|
+
const blank = (env: Env, keys: string[]) => {
|
|
69
|
+
const out: Record<string, string> = {};
|
|
70
|
+
for (const k of keys) if (k in env && env[k] === undefined) out[k] = "";
|
|
71
|
+
return out;
|
|
72
|
+
};
|
|
73
|
+
|
|
67
74
|
/** 服务的类型、地址和密钥都相同的算同一个;配置无效时返回 undefined */
|
|
68
75
|
function serviceId(env: Env): string | undefined {
|
|
69
76
|
try {
|
|
@@ -85,28 +92,35 @@ function describeService(service: SavedService): string {
|
|
|
85
92
|
return [i.kind, host].filter(Boolean).join(" · ");
|
|
86
93
|
}
|
|
87
94
|
|
|
88
|
-
/**
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
/** 保存过的、不是当前的模型,按服务分组:当前服务的在前 */
|
|
96
|
+
function otherModels(services: SavedService[], currentId: string | undefined, currentModel: string): { service: SavedService; model: SavedModel }[] {
|
|
97
|
+
return [...services.filter((s) => serviceId(s.env) === currentId), ...services.filter((s) => serviceId(s.env) !== currentId)].flatMap((s) =>
|
|
98
|
+
s.models.filter((m) => !(serviceId(s.env) === currentId && m.name === currentModel)).map((m) => ({ service: s, model: m })),
|
|
99
|
+
);
|
|
92
100
|
}
|
|
93
101
|
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
/** Claude 不设输出上限时用的值:和 @uncarved/provider-anthropic 里的默认值一致(不从那里导入:加载它的 SDK 要一百多毫秒) */
|
|
103
|
+
const ANTHROPIC_DEFAULT_MAX_TOKENS = 64000;
|
|
104
|
+
|
|
105
|
+
/** 选项说明里放不下的长文本截短 */
|
|
106
|
+
const shorten = (text: string, max = 40) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
|
|
107
|
+
|
|
108
|
+
const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
|
|
109
|
+
|
|
110
|
+
/** 模型设置那一项的简要说明,例如 "64K out · 1M ctx · images";settings 是这个模型自己的设置变量 */
|
|
111
|
+
function settingsSummary(settings: Env, kind: string, window: number): string {
|
|
112
|
+
const images = visionSetting({ JADE_VISION: settings.JADE_VISION }) ?? (isBuiltinKind(kind) && kind !== "openai-compat");
|
|
97
113
|
return [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
`${
|
|
101
|
-
|
|
114
|
+
settings.JADE_MAX_TOKENS && `${settings.JADE_MAX_TOKENS} out`,
|
|
115
|
+
settings.JADE_EFFORT && `${settings.JADE_EFFORT} effort`,
|
|
116
|
+
`${settings.JADE_CONTEXT_WINDOW ?? window} ctx`,
|
|
117
|
+
settings.JADE_RPM && `${settings.JADE_RPM}/min`,
|
|
102
118
|
images ? "images" : "no images",
|
|
103
119
|
]
|
|
104
120
|
.filter(Boolean)
|
|
105
121
|
.join(" · ");
|
|
106
122
|
}
|
|
107
123
|
|
|
108
|
-
const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
|
|
109
|
-
|
|
110
124
|
export function configurator(opts: ConfigureOptions): Configure {
|
|
111
125
|
const { ui, envFile, modelsFile } = opts;
|
|
112
126
|
const report = (text: string) => opts.report(text);
|
|
@@ -186,7 +200,7 @@ export function configurator(opts: ConfigureOptions): Configure {
|
|
|
186
200
|
}
|
|
187
201
|
|
|
188
202
|
/**
|
|
189
|
-
* 在当前的服务上换成 model
|
|
203
|
+
* 在当前的服务上换成 model:用过的带上它自己的设置;新的模型沿用输出上限、思考力度和额外请求参数,
|
|
190
204
|
* 上下文窗口不沿用(不同模型差别很大),按模型名推断
|
|
191
205
|
*/
|
|
192
206
|
async function switchModel(model: string): Promise<boolean> {
|
|
@@ -203,18 +217,20 @@ export function configurator(opts: ConfigureOptions): Configure {
|
|
|
203
217
|
return applyConfig({ [MODEL_KEY[kind]]: model, JADE_CONTEXT_WINDOW: undefined });
|
|
204
218
|
}
|
|
205
219
|
|
|
206
|
-
/**
|
|
220
|
+
/** 选模型:服务能列出模型时从列表里选,否则手动输入。选 Back 和取消一样返回 undefined */
|
|
207
221
|
async function chooseModel(env: Env, current: string | undefined, saved: string[] = []): Promise<string | undefined> {
|
|
208
222
|
const models = await listModels(env, opts.fetch);
|
|
223
|
+
const BACK = "\0back";
|
|
209
224
|
if (models.length > 0) {
|
|
210
225
|
const OTHER = "\0other";
|
|
211
226
|
const picked = await ui.select(
|
|
212
227
|
{
|
|
213
228
|
title: "Choose a model",
|
|
214
|
-
options: [...models.map((m) => ({ label: m, value: m, ...(m === current ? { hint: "current" } : saved.includes(m) ? { hint: "saved" } : {}) })), { label: "Enter a name…", value: OTHER }],
|
|
229
|
+
options: [...models.map((m) => ({ label: m, value: m, ...(m === current ? { hint: "current" } : saved.includes(m) ? { hint: "saved" } : {}) })), { label: "Enter a name…", value: OTHER }, { label: "Back", value: BACK }],
|
|
215
230
|
},
|
|
216
231
|
opts.signal,
|
|
217
232
|
);
|
|
233
|
+
if (picked === BACK) return undefined;
|
|
218
234
|
if (picked !== OTHER) return picked;
|
|
219
235
|
}
|
|
220
236
|
return (await ui.input({ title: "Model name", ...(current ? { initial: current } : {}) }, opts.signal)) || undefined;
|
|
@@ -266,11 +282,6 @@ export function configurator(opts: ConfigureOptions): Configure {
|
|
|
266
282
|
const key = answer || known;
|
|
267
283
|
|
|
268
284
|
const serviceEnv: Env = { JADE_PROVIDER: kind, [URL_KEY[kind]]: baseURL, [KEY_KEY[kind]]: key };
|
|
269
|
-
if (kind === "openai-compat") {
|
|
270
|
-
// 额外的请求参数跟着服务走:同一个服务保留,换了服务用保存过的那份
|
|
271
|
-
const saved = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
|
|
272
|
-
serviceEnv.OPENAI_COMPAT_EXTRA_BODY = saved ? saved.env.OPENAI_COMPAT_EXTRA_BODY : sameAddress(env) ? env.OPENAI_COMPAT_EXTRA_BODY : undefined;
|
|
273
|
-
}
|
|
274
285
|
const target = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
|
|
275
286
|
const model = await chooseModel({ ...env, ...serviceEnv }, same ? current?.model : undefined, target?.models.map((m) => m.name));
|
|
276
287
|
if (!model) return false;
|
|
@@ -280,174 +291,271 @@ export function configurator(opts: ConfigureOptions): Configure {
|
|
|
280
291
|
if (target && saved) return useSaved({ ...target, env: { ...target.env, ...pick(serviceEnv, serviceKeys(kind)) } }, saved);
|
|
281
292
|
|
|
282
293
|
const updates: Env = { ...serviceEnv, [MODEL_KEY[kind]]: model, JADE_CONTEXT_WINDOW: undefined };
|
|
283
|
-
//
|
|
284
|
-
|
|
294
|
+
// 换了服务的新模型从新服务的默认值开始:思考力度、额外请求参数各服务写法不同,限速、输出上限、
|
|
295
|
+
// 能不能看图也是跟着服务和模型走的,沿用当前的容易错(例如免费服务的限速带到付费服务上)。
|
|
296
|
+
// 同一个服务(只换了密钥)照旧沿用
|
|
297
|
+
const sameService = same && sameAddress(env);
|
|
298
|
+
if (!sameService) for (const k of MODEL_SETTINGS) updates[k] = undefined;
|
|
285
299
|
// 其他服务常常默认只给 4096 个输出 token,带思考的模型很容易用完
|
|
286
|
-
if (kind !== "anthropic" && !env.JADE_MAX_TOKENS) {
|
|
300
|
+
if (kind !== "anthropic" && !(sameService && env.JADE_MAX_TOKENS)) {
|
|
287
301
|
const max = await ui.input({ title: "Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", initial: "32K" }, opts.signal);
|
|
288
302
|
if (max === undefined || !tokensInput("Output limit", max)) return false;
|
|
289
303
|
if (max) updates.JADE_MAX_TOKENS = max;
|
|
290
304
|
}
|
|
291
305
|
// 同一个地址只换了密钥:原来的服务下的模型归到新的密钥下
|
|
292
|
-
const rekeyed =
|
|
306
|
+
const rekeyed = sameService && currentId !== undefined && key !== env[KEY_KEY[kind]];
|
|
293
307
|
return applyConfig(updates, rekeyed ? currentId : undefined);
|
|
294
308
|
}
|
|
295
309
|
|
|
296
|
-
/**
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const max = await ui.input({ title: "Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", initial: env.JADE_MAX_TOKENS ?? "32K" }, opts.signal);
|
|
316
|
-
if (max !== undefined && tokensInput("Output limit", max)) await applyConfig({ JADE_MAX_TOKENS: max || undefined });
|
|
317
|
-
} else if (action === "effort" && efforts) {
|
|
318
|
-
const DEFAULT = "\0default";
|
|
319
|
-
const effort = await ui.select(
|
|
320
|
-
{
|
|
321
|
-
title: "Reasoning effort",
|
|
322
|
-
options: [...efforts.map((e) => ({ label: e, value: e, ...(e === env.JADE_EFFORT ? { hint: "current" } : {}) })), { label: "Default", value: DEFAULT, hint: info.kind === "anthropic" ? "high" : "service default" }],
|
|
323
|
-
},
|
|
324
|
-
opts.signal,
|
|
325
|
-
);
|
|
326
|
-
if (effort !== undefined) await applyConfig({ JADE_EFFORT: effort === DEFAULT ? undefined : effort });
|
|
327
|
-
} else if (action === "rpm") {
|
|
328
|
-
const n = await ui.input({ title: "Requests per minute, e.g. 20 for most free models (empty for no limit)", initial: env.JADE_RPM ?? "" }, opts.signal);
|
|
329
|
-
if (n === undefined) return;
|
|
330
|
-
try {
|
|
331
|
-
rpmFromEnv({ JADE_RPM: n });
|
|
332
|
-
} catch (err) {
|
|
333
|
-
return report(errorText(err));
|
|
334
|
-
}
|
|
335
|
-
await applyConfig({ JADE_RPM: n.trim() || undefined });
|
|
336
|
-
} else if (action === "vision") {
|
|
337
|
-
const DEFAULT = "\0default";
|
|
338
|
-
const current = visionSetting(env);
|
|
339
|
-
const choice = await ui.select(
|
|
310
|
+
/** 要配置设置的模型:title 和 kind 是显示和按服务取值用的,read 读这个模型现在的设置变量,update 写回改动 */
|
|
311
|
+
interface SettingsTarget {
|
|
312
|
+
title: string;
|
|
313
|
+
kind: string;
|
|
314
|
+
model: string;
|
|
315
|
+
read(): Promise<Env>;
|
|
316
|
+
update(settings: Env): Promise<boolean>;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 某个模型的设置(输出上限、思考力度、上下文窗口、限速、能不能看图,openai-compat 还有额外请求参数)。
|
|
321
|
+
* 改完一项回到这个菜单接着改(重新读一遍,显示的是改过的值);Back 或 Esc 才离开
|
|
322
|
+
*/
|
|
323
|
+
async function configureSettings(target: SettingsTarget) {
|
|
324
|
+
const { title, kind, model } = target;
|
|
325
|
+
const efforts = isBuiltinKind(kind) ? EFFORTS[kind] : undefined;
|
|
326
|
+
while (true) {
|
|
327
|
+
const env = await target.read();
|
|
328
|
+
const action = await ui.select(
|
|
340
329
|
{
|
|
341
|
-
title:
|
|
330
|
+
title: `Settings for ${title}`,
|
|
342
331
|
options: [
|
|
343
|
-
{ label: "
|
|
344
|
-
{ label: "
|
|
345
|
-
{ label: "
|
|
332
|
+
{ label: "Output limit per reply", value: "max", hint: env.JADE_MAX_TOKENS ? `${env.JADE_MAX_TOKENS} tokens` : kind === "anthropic" ? `${ANTHROPIC_DEFAULT_MAX_TOKENS} tokens (default)` : "service default" },
|
|
333
|
+
...(efforts ? [{ label: "Reasoning effort", value: "effort", hint: env.JADE_EFFORT ?? (kind === "anthropic" ? "high (default)" : "service default") }] : []),
|
|
334
|
+
{ label: "Context window", value: "window", hint: `${contextWindow(model, env)} tokens${env.JADE_CONTEXT_WINDOW ? "" : " (default)"}` },
|
|
335
|
+
{ label: "Requests per minute", value: "rpm", hint: env.JADE_RPM ? `${env.JADE_RPM}/min` : "no limit (slows down after being rate limited)" },
|
|
336
|
+
{ label: "Can see images", value: "vision", hint: visionHint(env, kind) },
|
|
337
|
+
...(kind === "openai-compat" ? [{ label: "Extra request body", value: "extra", hint: env.OPENAI_COMPAT_EXTRA_BODY ? shorten(env.OPENAI_COMPAT_EXTRA_BODY) : "none" }] : []),
|
|
338
|
+
{ label: "Back", value: "back" },
|
|
346
339
|
],
|
|
347
340
|
},
|
|
348
341
|
opts.signal,
|
|
349
342
|
);
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
|
|
343
|
+
if (action === undefined || action === "back") return;
|
|
344
|
+
// 每一项里按 Esc 或者输入有误:什么都不改,回到这个菜单
|
|
345
|
+
if (action === "max") {
|
|
346
|
+
const max = await ui.input({ title: "Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", initial: env.JADE_MAX_TOKENS ?? "32K" }, opts.signal);
|
|
347
|
+
if (max !== undefined && tokensInput("Output limit", max)) await target.update({ JADE_MAX_TOKENS: max || undefined });
|
|
348
|
+
} else if (action === "effort" && efforts) {
|
|
349
|
+
const DEFAULT = "\0default";
|
|
350
|
+
const effort = await ui.select(
|
|
351
|
+
{
|
|
352
|
+
title: "Reasoning effort",
|
|
353
|
+
options: [...efforts.map((e) => ({ label: e, value: e, ...(e === env.JADE_EFFORT ? { hint: "current" } : {}) })), { label: "Default", value: DEFAULT, hint: kind === "anthropic" ? "high" : "service default" }],
|
|
354
|
+
},
|
|
355
|
+
opts.signal,
|
|
356
|
+
);
|
|
357
|
+
if (effort !== undefined) await target.update({ JADE_EFFORT: effort === DEFAULT ? undefined : effort });
|
|
358
|
+
} else if (action === "rpm") {
|
|
359
|
+
const n = await ui.input({ title: "Requests per minute, e.g. 20 for most free models (empty for no limit)", initial: env.JADE_RPM ?? "" }, opts.signal);
|
|
360
|
+
if (n === undefined) continue;
|
|
361
|
+
try {
|
|
362
|
+
rpmFromEnv({ JADE_RPM: n });
|
|
363
|
+
} catch (err) {
|
|
364
|
+
report(errorText(err));
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
await target.update({ JADE_RPM: n.trim() || undefined });
|
|
368
|
+
} else if (action === "vision") {
|
|
369
|
+
const DEFAULT = "\0default";
|
|
370
|
+
const current = visionSetting(env);
|
|
371
|
+
const choice = await ui.select(
|
|
372
|
+
{
|
|
373
|
+
title: "Can this model see images (screenshots, image files)?",
|
|
374
|
+
options: [
|
|
375
|
+
{ label: "Yes", value: "on", hint: current === true ? "current" : "images are sent to the model" },
|
|
376
|
+
{ label: "No", value: "off", hint: current === false ? "current" : "images are replaced with a note" },
|
|
377
|
+
{ label: "Default", value: DEFAULT, hint: isBuiltinKind(kind) && kind !== "openai-compat" ? "yes" : "no" },
|
|
378
|
+
],
|
|
379
|
+
},
|
|
380
|
+
opts.signal,
|
|
381
|
+
);
|
|
382
|
+
if (choice === undefined) continue;
|
|
383
|
+
if (await target.update({ JADE_VISION: choice === DEFAULT ? undefined : choice })) {
|
|
384
|
+
const on = choice === DEFAULT ? isBuiltinKind(kind) && kind !== "openai-compat" : choice === "on";
|
|
385
|
+
report(on ? "Images will be sent to the model." : "Images will be replaced with a note.");
|
|
386
|
+
}
|
|
387
|
+
} else if (action === "window") {
|
|
388
|
+
const n = await ui.input({ title: "Context window in tokens, e.g. 128000, 512K, 1M (empty to infer it from the model name, or 256K if unknown)", initial: env.JADE_CONTEXT_WINDOW ?? "" }, opts.signal);
|
|
389
|
+
if (n !== undefined && tokensInput("Context window", n)) await target.update({ JADE_CONTEXT_WINDOW: n || undefined });
|
|
390
|
+
} else if (action === "extra" && kind === "openai-compat") {
|
|
391
|
+
const text = await ui.input(
|
|
392
|
+
{ title: 'JSON merged into every request for this model, e.g. {"enable_thinking":true} (empty for none)', initial: env.OPENAI_COMPAT_EXTRA_BODY ?? "" },
|
|
393
|
+
opts.signal,
|
|
394
|
+
);
|
|
395
|
+
if (text === undefined) continue;
|
|
396
|
+
if (text.trim()) {
|
|
397
|
+
try {
|
|
398
|
+
jsonObject("Extra request body", text);
|
|
399
|
+
} catch (err) {
|
|
400
|
+
report(errorText(err));
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
await target.update({ OPENAI_COMPAT_EXTRA_BODY: text.trim() || undefined });
|
|
353
405
|
}
|
|
354
|
-
} else if (action === "window") {
|
|
355
|
-
const n = await ui.input({ title: "Context window in tokens, e.g. 128000, 512K, 1M (empty to infer it from the model name, or 128K if unknown)", initial: env.JADE_CONTEXT_WINDOW ?? "" }, opts.signal);
|
|
356
|
-
if (n !== undefined && tokensInput("Context window", n)) await applyConfig({ JADE_CONTEXT_WINDOW: n || undefined });
|
|
357
406
|
}
|
|
358
407
|
}
|
|
359
408
|
|
|
409
|
+
/** 把模型的设置写进 models.json 里那一个模型;.env 不变(当前用的还是原来的模型)。改回默认值的设置从 settings 里删掉 */
|
|
410
|
+
async function writeSavedModel(service: SavedService, model: SavedModel, settings: Env): Promise<boolean> {
|
|
411
|
+
const id = serviceId(service.env);
|
|
412
|
+
const all = await readSavedServices(modelsFile);
|
|
413
|
+
const mine = id === undefined ? undefined : all.find((s) => serviceId(s.env) === id);
|
|
414
|
+
if (!mine) {
|
|
415
|
+
report(`Not saved: ${describeService(service)} is no longer in ${modelsFile}.`);
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
const mineIndex = all.indexOf(mine);
|
|
419
|
+
const modelIndex = mine.models.findIndex((m) => m.name === model.name);
|
|
420
|
+
// 在文件里现在的设置上改:菜单打开之后 models.json 可能被别的会话改过
|
|
421
|
+
const merged: Env = { ...(mine.models[modelIndex]?.settings ?? model.settings), ...pick(settings, MODEL_SETTINGS), ...blank(settings, MODEL_SETTINGS) };
|
|
422
|
+
const next: SavedModel = { name: model.name, settings: Object.fromEntries(Object.entries(merged).filter(([, v]) => v !== undefined && v !== "")) as Record<string, string> };
|
|
423
|
+
const models = modelIndex === -1 ? [next, ...mine.models] : [...mine.models.slice(0, modelIndex), next, ...mine.models.slice(modelIndex + 1)];
|
|
424
|
+
await writeSavedServices(modelsFile, [...all.slice(0, mineIndex), { ...mine, models }, ...all.slice(mineIndex + 1)]);
|
|
425
|
+
report(`Settings for ${model.name} (${describeService(mine)}) saved to ${modelsFile}.`);
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** 把保存过的模型从 models.json 里删掉;服务下没有模型了就连服务(和它的密钥)一起删掉 */
|
|
430
|
+
async function forgetModel(service: SavedService, model: SavedModel): Promise<void> {
|
|
431
|
+
const id = serviceId(service.env);
|
|
432
|
+
if (!id) return;
|
|
433
|
+
const rest = (await readSavedServices(modelsFile))
|
|
434
|
+
.map((s) => (serviceId(s.env) === id ? { ...s, models: s.models.filter((m) => m.name !== model.name) } : s))
|
|
435
|
+
.filter((s) => s.models.length > 0);
|
|
436
|
+
await writeSavedServices(modelsFile, rest);
|
|
437
|
+
report(`Removed ${model.name} (${describeService(service)}).`);
|
|
438
|
+
}
|
|
439
|
+
|
|
360
440
|
/**
|
|
361
|
-
*
|
|
362
|
-
*
|
|
441
|
+
* 选中主菜单里一个模型后:切换、配置它(不用先切到它)、把它删掉或返回主菜单。
|
|
442
|
+
* 当前的模型只能配置(切换没意义;删掉了下次进 /model 又会被记回来)。从设置里出来回到这个菜单;
|
|
443
|
+
* 切换、删除、Back 或 Esc 回到主菜单
|
|
363
444
|
*/
|
|
364
|
-
async function
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
445
|
+
async function pickModelAction(o: { service: SavedService; model: SavedModel }, isCurrent: boolean): Promise<void> {
|
|
446
|
+
const kind = providerKind(o.service.env);
|
|
447
|
+
// 当前的模型改 .env 就好——applyConfig 里的 remember 会把改完的 .env 写回 models.json;
|
|
448
|
+
// 其他保存过的模型只改 models.json 里的那一个
|
|
449
|
+
const read = isCurrent ? async () => pick(opts.env(), MODEL_SETTINGS) : () => savedSettings(o.service, o.model);
|
|
450
|
+
while (true) {
|
|
451
|
+
const settings = await read();
|
|
452
|
+
const action = await ui.select(
|
|
453
|
+
{
|
|
454
|
+
title: o.model.name,
|
|
455
|
+
options: [
|
|
456
|
+
...(isCurrent
|
|
457
|
+
? []
|
|
458
|
+
: [{ label: "Switch to it", value: "switch", hint: serviceId(o.service.env) === serviceId(opts.env()) ? "this service" : describeService(o.service) }]),
|
|
459
|
+
{ label: "Settings…", value: "settings", hint: settingsSummary(settings, kind, contextWindow(o.model.name, settings)) },
|
|
460
|
+
...(isCurrent ? [] : [{ label: "Remove", value: "forget" }]),
|
|
461
|
+
{ label: "Back", value: "back" },
|
|
462
|
+
],
|
|
463
|
+
},
|
|
370
464
|
opts.signal,
|
|
371
465
|
);
|
|
372
|
-
if (
|
|
373
|
-
|
|
466
|
+
if (action === "settings") {
|
|
467
|
+
await configureSettings({
|
|
468
|
+
title: o.model.name,
|
|
469
|
+
kind,
|
|
470
|
+
model: o.model.name,
|
|
471
|
+
read,
|
|
472
|
+
update: (updates) => (isCurrent ? applyConfig(updates) : writeSavedModel(o.service, o.model, updates)),
|
|
473
|
+
});
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
// 用刚读到的设置切换:在这个菜单里改过的也带上
|
|
477
|
+
if (action === "switch") await useSaved(o.service, { ...o.model, settings });
|
|
478
|
+
else if (action === "forget") await forgetModel(o.service, o.model);
|
|
479
|
+
return;
|
|
374
480
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
return model && { service: group.service, model };
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** 保存过的模型在 models.json 里现在的设置;找不到时用 fallback 那份 */
|
|
484
|
+
async function savedSettings(service: SavedService, fallback: SavedModel): Promise<Record<string, string>> {
|
|
485
|
+
const id = serviceId(service.env);
|
|
486
|
+
const mine = id === undefined ? undefined : (await readSavedServices(modelsFile)).find((s) => serviceId(s.env) === id);
|
|
487
|
+
return mine?.models.find((m) => m.name === fallback.name)?.settings ?? fallback.settings;
|
|
383
488
|
}
|
|
384
489
|
|
|
385
490
|
async function configureModel(arg: string | undefined) {
|
|
386
491
|
const env = opts.env();
|
|
387
492
|
// 还没有配置模型:没有"当前的服务"可以换模型,先选服务
|
|
388
493
|
if (!hasProvider(env)) return void (await configureProvider());
|
|
389
|
-
const info = providerInfo(env);
|
|
390
494
|
// 之前只有 .env 时配置的模型也记下来,之后换了不会丢
|
|
391
495
|
await remember().catch(() => {});
|
|
392
|
-
const currentId = serviceId(env);
|
|
393
|
-
const services = await savedServices();
|
|
394
|
-
/** 保存过的、不是当前的模型,按服务分组:当前服务的在前 */
|
|
395
|
-
const others = [...services.filter((s) => serviceId(s.env) === currentId), ...services.filter((s) => serviceId(s.env) !== currentId)].flatMap((s) =>
|
|
396
|
-
s.models.filter((m) => !(serviceId(s.env) === currentId && m.name === info.model)).map((m) => ({ service: s, model: m })),
|
|
397
|
-
);
|
|
398
496
|
if (arg) {
|
|
399
497
|
// 保存过的模型按名字切换(当前服务的优先),否则换当前服务的模型
|
|
400
|
-
const saved =
|
|
498
|
+
const saved = otherModels(await savedServices(), serviceId(env), providerInfo(env).model).find((o) => o.model.name === arg);
|
|
401
499
|
return void (await (saved ? useSaved(saved.service, saved.model) : switchModel(arg)));
|
|
402
500
|
}
|
|
403
|
-
//
|
|
404
|
-
//
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
},
|
|
418
|
-
opts.signal,
|
|
419
|
-
);
|
|
420
|
-
if (action?.startsWith("saved:")) {
|
|
421
|
-
const o = others[Number(action.slice(6))]!;
|
|
422
|
-
await useSaved(o.service, o.model);
|
|
423
|
-
} else if (action === "add") {
|
|
424
|
-
const where = await ui.select(
|
|
501
|
+
// 主菜单循环:保存过的模型全部直接列出(当前的在最前,然后是同一服务的),选中出一个子菜单
|
|
502
|
+
// (切换 / 设置 / 删除 / 返回);配置某个模型、把它删掉都不用先切到它,做完回到主菜单再选。
|
|
503
|
+
// 每一轮都重读当前配置:切换、配置之后模型和它的设置可能都变了
|
|
504
|
+
while (true) {
|
|
505
|
+
const env = opts.env();
|
|
506
|
+
const id = serviceId(env);
|
|
507
|
+
const kind = providerKind(env);
|
|
508
|
+
const kindKnown = isBuiltinKind(kind);
|
|
509
|
+
const info = providerInfo(env);
|
|
510
|
+
const here = describeService({ env: kindKnown ? pick(env, serviceKeys(kind as ProviderKind)) : {}, models: [] });
|
|
511
|
+
const services = await savedServices();
|
|
512
|
+
const multi = services.length > 1;
|
|
513
|
+
const others = otherModels(services, id, info.model);
|
|
514
|
+
const action = await ui.select(
|
|
425
515
|
{
|
|
426
|
-
title: "
|
|
516
|
+
title: "Switch model",
|
|
427
517
|
options: [
|
|
428
|
-
{
|
|
429
|
-
|
|
518
|
+
{
|
|
519
|
+
label: info.model,
|
|
520
|
+
value: "current",
|
|
521
|
+
hint: `${multi ? `${here} · ` : ""}current · ${settingsSummary(env, info.kind, contextWindow(info.model, env))}`,
|
|
522
|
+
},
|
|
523
|
+
...others.map((o, i) => ({
|
|
524
|
+
label: o.model.name,
|
|
525
|
+
value: `saved:${i}`,
|
|
526
|
+
hint: `${multi ? `${describeService(o.service)} · ` : ""}${settingsSummary(o.model.settings, providerKind(o.service.env), contextWindow(o.model.name, o.model.settings))}`,
|
|
527
|
+
})),
|
|
528
|
+
{ label: "Add a model…", value: "add", hint: "from this service or another one" },
|
|
430
529
|
],
|
|
431
530
|
},
|
|
432
531
|
opts.signal,
|
|
433
532
|
);
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
} else if (
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
533
|
+
if (action === undefined) return; // Esc:整个 /model 结束
|
|
534
|
+
if (action === "current") {
|
|
535
|
+
const service = { env: kindKnown ? { ...pick(env, serviceKeys(kind as ProviderKind)), JADE_PROVIDER: kind } : { JADE_PROVIDER: kind }, models: [] };
|
|
536
|
+
await pickModelAction({ service, model: { name: info.model, settings: pick(env, MODEL_SETTINGS) } }, true);
|
|
537
|
+
} else if (action.startsWith("saved:")) {
|
|
538
|
+
const o = others[Number(action.slice(6))];
|
|
539
|
+
if (o) await pickModelAction(o, false);
|
|
540
|
+
} else if (action === "add") {
|
|
541
|
+
const where = await ui.select(
|
|
542
|
+
{
|
|
543
|
+
title: "Add a model from",
|
|
544
|
+
options: [
|
|
545
|
+
{ label: "This service", value: "model", hint: here },
|
|
546
|
+
{ label: "Another service…", value: "provider", hint: "or change this one's base URL / API key" },
|
|
547
|
+
{ label: "Back", value: "back" },
|
|
548
|
+
],
|
|
549
|
+
},
|
|
550
|
+
opts.signal,
|
|
551
|
+
);
|
|
552
|
+
// 做完、Back、Esc 或没填完,都回到主菜单
|
|
553
|
+
if (where === "model") {
|
|
554
|
+
const saved = services.find((s) => serviceId(s.env) === id)?.models.map((m) => m.name);
|
|
555
|
+
const model = await chooseModel(env, info.model, saved);
|
|
556
|
+
if (model && model !== info.model) await switchModel(model);
|
|
557
|
+
} else if (where === "provider") await configureProvider();
|
|
558
|
+
}
|
|
451
559
|
}
|
|
452
560
|
}
|
|
453
561
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// 模型的上下文窗口(最大输入 token 数)。前端显示上下文用量,以后的 jade/compact 据此决定什么时候压缩。
|
|
2
2
|
//
|
|
3
|
-
// 窗口优先取 JADE_CONTEXT_WINDOW;不设时按模型名在一张小表里找(只收录确定的、取偏小的值),找不到用
|
|
3
|
+
// 窗口优先取 JADE_CONTEXT_WINDOW;不设时按模型名在一张小表里找(只收录确定的、取偏小的值),找不到用 256000。
|
|
4
4
|
|
|
5
5
|
import { parseTokens } from "./config.ts";
|
|
6
6
|
|
|
7
7
|
type Env = Record<string, string | undefined>;
|
|
8
8
|
|
|
9
9
|
/** 认不出模型时的窗口 */
|
|
10
|
-
export const DEFAULT_CONTEXT_WINDOW =
|
|
10
|
+
export const DEFAULT_CONTEXT_WINDOW = 256_000;
|
|
11
11
|
|
|
12
12
|
/** 模型名(不区分大小写,可以带 "anthropic/" 这类前缀)→ 窗口;按顺序取第一个匹配的 */
|
|
13
13
|
const KNOWN_WINDOWS: [RegExp, number][] = [
|