@uncarved/jade 0.1.3 → 0.2.1
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 +161 -150
- package/bin/jade.js +14 -25
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -30
- package/dist/index.js +11 -30
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +160 -1362
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +2 -0
- package/dist/update.js +6 -3
- package/dist/update.js.map +1 -1
- package/package.json +10 -8
- package/plugins/approval/index.ts +311 -0
- package/plugins/approval/plugin.json +22 -0
- package/{src/plugins → plugins/approval}/policy.ts +45 -104
- package/{src/plugins → plugins/approval}/review.ts +62 -16
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +48 -38
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +80 -39
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +2 -2
- package/{src/tools → plugins/fs}/fs.ts +89 -46
- package/{src/tools → plugins/fs}/grep.ts +36 -8
- package/plugins/fs/index.ts +37 -0
- package/plugins/fs/plugin.json +7 -0
- package/{src/ui → plugins/fs}/renderers.ts +25 -70
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +99 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +213 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +16 -119
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +160 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +111 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +258 -0
- package/plugins/prompts/results.ts +63 -0
- package/plugins/prompts/sys.ts +84 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +31 -20
- package/{src → plugins/shell}/sys.ts +2 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +168 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +343 -0
- package/plugins/todo/index.ts +93 -0
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +619 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +153 -0
- package/plugins/tui/plugin.json +10 -0
- package/{src/ui → plugins/tui}/render.ts +8 -2
- package/{src/ui → plugins/tui}/screen.ts +8 -3
- package/{src/ui → plugins/tui}/transcript.ts +79 -100
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
- package/plugins/tui/vendor.ts +16 -0
- package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
- package/plugins/undo/index.ts +143 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/{src/tools → plugins/web}/web.ts +64 -31
- package/plugins-dist/approval/index.js +287 -0
- package/plugins-dist/approval/plugin.json +28 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
- package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +58 -34
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
- package/{dist/tools → plugins-dist/fs}/fs.js +82 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
- package/plugins-dist/fs/index.js +39 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +87 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +181 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +18 -81
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +172 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +85 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +231 -0
- package/plugins-dist/prompts/results.js +60 -0
- package/plugins-dist/prompts/sys.js +58 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
- package/{dist → plugins-dist/shell}/sys.js +2 -43
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +152 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +284 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +609 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
- package/plugins-dist/tui/mentions.js +153 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/{dist/ui → plugins-dist/tui}/render.js +7 -3
- package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
- package/{dist/ui → plugins-dist/tui}/transcript.js +79 -99
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
- package/plugins-dist/tui/vendor.js +13822 -0
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
- package/plugins-dist/undo/index.js +143 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/{dist/tools → plugins-dist/web}/web.js +56 -29
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -30
- package/src/install.ts +355 -0
- package/src/main.ts +156 -1387
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -262
- package/LICENSE +0 -21
- package/dist/commands.d.ts +0 -50
- package/dist/commands.js +0 -126
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -141
- package/dist/distro.js +0 -462
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -294
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -25
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -71
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -47
- package/dist/plugins/core.js +0 -229
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/host.d.ts +0 -52
- package/dist/plugins/host.js +0 -115
- package/dist/plugins/host.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -410
- package/dist/plugins/loader.js +0 -407
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -98
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -43
- package/dist/plugins/prompts.js +0 -284
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -16
- package/dist/plugins/repeats.js +0 -151
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -18
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/plugins/sessions.d.ts +0 -7
- package/dist/plugins/sessions.js +0 -110
- package/dist/plugins/sessions.js.map +0 -1
- package/dist/provider.d.ts +0 -165
- package/dist/provider.js.map +0 -1
- package/dist/session-lifecycle.d.ts +0 -61
- package/dist/session-lifecycle.js +0 -167
- package/dist/session-lifecycle.js.map +0 -1
- package/dist/session-scope.d.ts +0 -53
- package/dist/session-scope.js +0 -116
- package/dist/session-scope.js.map +0 -1
- package/dist/sessions.d.ts +0 -28
- package/dist/sessions.js +0 -73
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -51
- package/dist/sys.js.map +0 -1
- package/dist/tools/ask.d.ts +0 -11
- package/dist/tools/ask.js +0 -62
- package/dist/tools/ask.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -39
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -39
- package/dist/tools/task.js +0 -117
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -53
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -447
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -41
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -22
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -14
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/renderers.d.ts +0 -8
- package/dist/ui/renderers.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -118
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -46
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -47
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -144
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -577
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -278
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -34
- package/src/plugins/core.ts +0 -257
- package/src/plugins/host.ts +0 -146
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -742
- package/src/plugins/prompts.ts +0 -327
- package/src/plugins/repeats.ts +0 -157
- package/src/plugins/sessions.ts +0 -109
- package/src/session-lifecycle.ts +0 -194
- package/src/session-scope.ts +0 -135
- package/src/sessions.ts +0 -78
- package/src/tools/ask.ts +0 -72
- package/src/tools/task.ts +0 -149
- package/src/tools/todo.ts +0 -67
- package/src/ui/configure.ts +0 -471
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
- /package/{src/ui → plugins/tui}/markdown.ts +0 -0
package/src/tools/todo.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// todo_write 工具:模型维护本轮任务的清单。每次调用给出完整清单,替换之前的。
|
|
2
|
-
//
|
|
3
|
-
// 清单本身就是工具调用的参数,已经在日志里,不另外保存:宿主从 tool.decided 读取并显示,
|
|
4
|
-
// 压缩插件把被压缩部分里最后一份清单写进摘要。
|
|
5
|
-
|
|
6
|
-
import type { Message, Tool } from "uncarved";
|
|
7
|
-
|
|
8
|
-
export type TodoStatus = "pending" | "in_progress" | "completed";
|
|
9
|
-
|
|
10
|
-
export interface Todo {
|
|
11
|
-
content: string;
|
|
12
|
-
status: TodoStatus;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const MARK: Record<TodoStatus, string> = { pending: "[ ]", in_progress: "[~]", completed: "[x]" };
|
|
16
|
-
|
|
17
|
-
export function renderTodos(todos: Todo[]): string {
|
|
18
|
-
return todos.length ? todos.map((t) => `${MARK[t.status]} ${t.content}`).join("\n") : "(empty)";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function todoTool(): Tool {
|
|
22
|
-
return {
|
|
23
|
-
name: "todo_write",
|
|
24
|
-
description:
|
|
25
|
-
"Maintain a task list for multi-step work. Each call replaces the whole list. " +
|
|
26
|
-
"Use it when a task has three or more steps: write the plan, mark one item in_progress while working on it, " +
|
|
27
|
-
"and mark items completed as soon as they are done. Skip it for simple tasks.",
|
|
28
|
-
inputSchema: {
|
|
29
|
-
type: "object",
|
|
30
|
-
properties: {
|
|
31
|
-
todos: {
|
|
32
|
-
type: "array",
|
|
33
|
-
items: {
|
|
34
|
-
type: "object",
|
|
35
|
-
properties: {
|
|
36
|
-
content: { type: "string" },
|
|
37
|
-
status: { type: "string", enum: ["pending", "in_progress", "completed"] },
|
|
38
|
-
},
|
|
39
|
-
required: ["content", "status"],
|
|
40
|
-
additionalProperties: false,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
required: ["todos"],
|
|
45
|
-
additionalProperties: false,
|
|
46
|
-
},
|
|
47
|
-
// 不碰文件和进程
|
|
48
|
-
effect: "read",
|
|
49
|
-
concurrency: "exclusive",
|
|
50
|
-
idempotent: true,
|
|
51
|
-
async execute(input) {
|
|
52
|
-
const { todos } = input as { todos: Todo[] };
|
|
53
|
-
const active = todos.filter((t) => t.status === "in_progress").length;
|
|
54
|
-
const note = active > 1 ? "\nNote: keep only one item in_progress at a time." : "";
|
|
55
|
-
return { content: `Todo list updated:\n${renderTodos(todos)}${note}` };
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** messages 里最后一次 todo_write 的清单 */
|
|
61
|
-
export function latestTodos(messages: Message[]): Todo[] | undefined {
|
|
62
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
63
|
-
const use = messages[i]!.content.findLast((b) => b.kind === "tool_use" && b.name === "todo_write");
|
|
64
|
-
if (use?.kind === "tool_use") return (use.input as { todos?: Todo[] }).todos;
|
|
65
|
-
}
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
package/src/ui/configure.ts
DELETED
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
// /model:选服务、填地址和密钥、选模型、改输出上限、思考力度和上下文窗口。配置写进 $JADE_HOME/.env。
|
|
2
|
-
// 配置过的服务和模型都记在 $JADE_HOME/models.json 里:同一个服务(类型、地址、密钥都相同)下的模型放在一起,
|
|
3
|
-
// 每个模型带自己的设置。/model 可以直接切回去,换了服务或地址之前的也不会丢。
|
|
4
|
-
|
|
5
|
-
import { hasProvider, parseTokens, readSavedServices, updateEnvFile, writeSavedServices, type SavedModel, type SavedService } from "../config.ts";
|
|
6
|
-
import { EFFORTS, isBuiltinKind, listModels, pluginProvider, pluginProviders, providerInfo, providerKind, rpmFromEnv, visionFromEnv, type ProviderKind } from "../provider.ts";
|
|
7
|
-
import { shortPath } from "./render.ts";
|
|
8
|
-
import { dim, green, red, type Screen } from "./screen.ts";
|
|
9
|
-
|
|
10
|
-
export interface ConfigureOptions {
|
|
11
|
-
screen: Screen;
|
|
12
|
-
envFile: string;
|
|
13
|
-
/** 保存过的服务和模型($JADE_HOME/models.json) */
|
|
14
|
-
modelsFile: string;
|
|
15
|
-
/** 按新的环境变量换上 provider、更新上下文窗口;配置不完整时抛出 */
|
|
16
|
-
apply(): Promise<void>;
|
|
17
|
-
/** 当前的上下文窗口(显示用) */
|
|
18
|
-
contextWindow(): number;
|
|
19
|
-
/** 配置成功后更新状态栏 */
|
|
20
|
-
onApplied(): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface Configure {
|
|
24
|
-
/** 选服务、填地址和密钥、选模型;返回是否配置成功 */
|
|
25
|
-
provider(): Promise<boolean>;
|
|
26
|
-
/** /model [name] */
|
|
27
|
-
model(arg: string | undefined): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const PROVIDERS: Array<{ kind: ProviderKind; label: string; hint: string }> = [
|
|
31
|
-
{ kind: "openai-compat", label: "OpenAI-compatible service", hint: "any /chat/completions endpoint" },
|
|
32
|
-
{ kind: "openai", label: "OpenAI", hint: "Responses API" },
|
|
33
|
-
{ kind: "anthropic", label: "Anthropic", hint: "Claude" },
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const MODEL_KEY: Record<ProviderKind, string> = { "openai-compat": "OPENAI_COMPAT_MODEL", openai: "OPENAI_MODEL", anthropic: "ANTHROPIC_MODEL" };
|
|
37
|
-
const KEY_KEY: Record<ProviderKind, string> = { "openai-compat": "OPENAI_COMPAT_API_KEY", openai: "OPENAI_API_KEY", anthropic: "ANTHROPIC_API_KEY" };
|
|
38
|
-
const URL_KEY: Record<ProviderKind, string> = { "openai-compat": "OPENAI_COMPAT_BASE_URL", openai: "OPENAI_BASE_URL", anthropic: "ANTHROPIC_BASE_URL" };
|
|
39
|
-
|
|
40
|
-
/** 每个模型自己的设置:切换模型时一起换掉 */
|
|
41
|
-
const MODEL_SETTINGS = ["JADE_MAX_TOKENS", "JADE_EFFORT", "JADE_CONTEXT_WINDOW", "JADE_RPM", "JADE_VISION"];
|
|
42
|
-
|
|
43
|
-
/** JADE_VISION 设成了什么;没设或写错时 undefined */
|
|
44
|
-
function visionSetting(): boolean | undefined {
|
|
45
|
-
if (!process.env.JADE_VISION?.trim()) return undefined;
|
|
46
|
-
try {
|
|
47
|
-
return visionFromEnv({ JADE_VISION: process.env.JADE_VISION });
|
|
48
|
-
} catch {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function visionHint(kind: string): string {
|
|
54
|
-
const v = visionSetting();
|
|
55
|
-
return v === undefined ? `${isBuiltinKind(kind) && kind !== "openai-compat" ? "yes" : "no"} (default)` : v ? "yes" : "no";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** 插件服务声明的配置项(见 ProviderDef.settings) */
|
|
59
|
-
const settingsOf = (kind: string) => pluginProvider(kind)?.def.settings ?? [];
|
|
60
|
-
|
|
61
|
-
/** 一个服务包含的变量(不含模型名);插件服务是它声明的配置项 */
|
|
62
|
-
const serviceKeys = (kind: string) =>
|
|
63
|
-
isBuiltinKind(kind)
|
|
64
|
-
? ["JADE_PROVIDER", URL_KEY[kind], KEY_KEY[kind], ...(kind === "openai-compat" ? ["OPENAI_COMPAT_EXTRA_BODY"] : [])]
|
|
65
|
-
: ["JADE_PROVIDER", ...settingsOf(kind).filter((x) => !x.model).map((x) => x.env)];
|
|
66
|
-
|
|
67
|
-
/** 保存模型名的变量;插件服务没有声明模型名时 undefined */
|
|
68
|
-
const modelKey = (kind: string): string | undefined => (isBuiltinKind(kind) ? MODEL_KEY[kind] : settingsOf(kind).find((x) => x.model)?.env);
|
|
69
|
-
|
|
70
|
-
type Env = Record<string, string | undefined>;
|
|
71
|
-
|
|
72
|
-
const pick = (env: Env, keys: string[]) => {
|
|
73
|
-
const out: Record<string, string> = {};
|
|
74
|
-
for (const k of keys) if (env[k] !== undefined) out[k] = env[k]!;
|
|
75
|
-
return out;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 服务的类型、地址和密钥都相同的算同一个;插件服务是类型和它声明的配置项(模型名除外)都相同。
|
|
80
|
-
* 配置无效、插件服务的插件没有加载时返回 undefined
|
|
81
|
-
*/
|
|
82
|
-
function serviceId(env: Env): string | undefined {
|
|
83
|
-
try {
|
|
84
|
-
const i = providerInfo(env);
|
|
85
|
-
if (!isBuiltinKind(i.kind)) return pluginProvider(i.kind) ? [i.kind, ...serviceKeys(i.kind).slice(1).map((k) => env[k] ?? "")].join("|") : undefined;
|
|
86
|
-
return `${i.kind}|${i.baseURL ?? ""}|${env[KEY_KEY[i.kind]] ?? ""}`;
|
|
87
|
-
} catch {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** 选择列表里服务的说明:类型和地址的主机名 */
|
|
93
|
-
function describeService(s: SavedService): string {
|
|
94
|
-
const i = providerInfo(s.env);
|
|
95
|
-
let host = i.baseURL ?? "";
|
|
96
|
-
try {
|
|
97
|
-
host = new URL(host).host;
|
|
98
|
-
} catch {}
|
|
99
|
-
return [i.kind, host].filter(Boolean).join(" · ");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** 输入的 token 数:空表示不设;写错时报告并返回 false */
|
|
103
|
-
function tokensInput(screen: Screen, name: string, text: string): boolean {
|
|
104
|
-
if (!text) return true;
|
|
105
|
-
try {
|
|
106
|
-
parseTokens(name, text);
|
|
107
|
-
return true;
|
|
108
|
-
} catch (err) {
|
|
109
|
-
screen.log(red(errorText(err)));
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** 选择列表里一组模型的说明:前几个名字 */
|
|
115
|
-
function modelNames(models: SavedModel[]): string {
|
|
116
|
-
const names = models.slice(0, 3).map((m) => m.name).join(", ");
|
|
117
|
-
return models.length > 3 ? `${names} +${models.length - 3}` : names;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** 主菜单里设置那一项的简要说明,例如 "64K out · 1M ctx · images" */
|
|
121
|
-
function settingsSummary(kind: string, contextWindow: number): string {
|
|
122
|
-
const env = process.env;
|
|
123
|
-
const images = visionSetting() ?? (isBuiltinKind(kind) && kind !== "openai-compat");
|
|
124
|
-
return [
|
|
125
|
-
env.JADE_MAX_TOKENS && `${env.JADE_MAX_TOKENS} out`,
|
|
126
|
-
env.JADE_EFFORT && `${env.JADE_EFFORT} effort`,
|
|
127
|
-
`${env.JADE_CONTEXT_WINDOW ?? contextWindow} ctx`,
|
|
128
|
-
env.JADE_RPM && `${env.JADE_RPM}/min`,
|
|
129
|
-
images ? "images" : "no images",
|
|
130
|
-
]
|
|
131
|
-
.filter(Boolean)
|
|
132
|
-
.join(" · ");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
|
|
136
|
-
|
|
137
|
-
export function configurator(opts: ConfigureOptions): Configure {
|
|
138
|
-
const { screen, envFile, modelsFile } = opts;
|
|
139
|
-
|
|
140
|
-
/** 保存过的、有效的服务,最近用过的在前 */
|
|
141
|
-
const savedServices = async () => (await readSavedServices(modelsFile)).filter((s) => serviceId(s.env) !== undefined);
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 把当前的服务和模型记下来,都放到最前面。
|
|
145
|
-
* replacing:换了密钥的那个服务原来的 id,它下面的模型归到新的密钥下
|
|
146
|
-
*/
|
|
147
|
-
async function remember(replacing?: string) {
|
|
148
|
-
if (!hasProvider()) return;
|
|
149
|
-
const id = serviceId(process.env);
|
|
150
|
-
const model = providerInfo().model;
|
|
151
|
-
if (!id || !model) return;
|
|
152
|
-
const kind = providerKind();
|
|
153
|
-
// 写回时保留现在认不出的服务(例如提供它的插件这次没加载),不然它和它的密钥就丢了
|
|
154
|
-
const all = await readSavedServices(modelsFile);
|
|
155
|
-
const old = all.filter((s) => {
|
|
156
|
-
const sid = serviceId(s.env);
|
|
157
|
-
return sid !== undefined && (sid === id || (replacing !== undefined && sid === replacing));
|
|
158
|
-
});
|
|
159
|
-
const models = old.flatMap((s) => s.models).filter((m, i, list) => m.name !== model && list.findIndex((x) => x.name === m.name) === i);
|
|
160
|
-
const service: SavedService = {
|
|
161
|
-
env: { ...pick(process.env, serviceKeys(kind)), JADE_PROVIDER: kind },
|
|
162
|
-
models: [{ name: model, settings: pick(process.env, MODEL_SETTINGS) }, ...models],
|
|
163
|
-
};
|
|
164
|
-
await writeSavedServices(modelsFile, [service, ...all.filter((s) => !old.includes(s))]);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** 保存配置并换上新的 provider;失败时报告原因,旧的 provider 继续用 */
|
|
168
|
-
async function applyConfig(updates: Record<string, string | undefined>, replacing?: string): Promise<boolean> {
|
|
169
|
-
await updateEnvFile(envFile, updates);
|
|
170
|
-
try {
|
|
171
|
-
await opts.apply();
|
|
172
|
-
} catch (err) {
|
|
173
|
-
screen.log(red(`Saved to ${shortPath(envFile)}, but the configuration is incomplete: ${errorText(err)}`));
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
const info = providerInfo();
|
|
177
|
-
opts.onApplied();
|
|
178
|
-
await remember(replacing).catch((err) => screen.log(red(`Could not save the model list to ${shortPath(modelsFile)}: ${errorText(err)}`)));
|
|
179
|
-
screen.log(green(`Model: ${info.model} (${info.kind}${info.baseURL ? `, ${info.baseURL}` : ""}). Saved to ${shortPath(envFile)}.`));
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** 换成保存过的服务 s 上的模型 m:服务的变量和模型的设置写进 .env,模型没设的设置删掉 */
|
|
184
|
-
function useSaved(s: SavedService, m: SavedModel): Promise<boolean> {
|
|
185
|
-
const kind = providerKind(s.env);
|
|
186
|
-
const updates: Record<string, string | undefined> = {};
|
|
187
|
-
for (const k of serviceKeys(kind)) updates[k] = s.env[k];
|
|
188
|
-
for (const k of MODEL_SETTINGS) updates[k] = m.settings[k];
|
|
189
|
-
updates.JADE_PROVIDER = kind;
|
|
190
|
-
const mk = modelKey(kind);
|
|
191
|
-
if (mk) updates[mk] = m.name;
|
|
192
|
-
return applyConfig(updates);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* 在当前的服务上换成 model:用过的带上它自己的设置;新的模型沿用输出上限和思考力度,
|
|
197
|
-
* 上下文窗口不沿用(不同模型差别很大),按模型名推断
|
|
198
|
-
*/
|
|
199
|
-
async function switchModel(model: string): Promise<boolean> {
|
|
200
|
-
const id = serviceId(process.env);
|
|
201
|
-
const service = (await savedServices()).find((s) => serviceId(s.env) === id);
|
|
202
|
-
const saved = service?.models.find((m) => m.name === model);
|
|
203
|
-
if (service && saved) return useSaved(service, saved);
|
|
204
|
-
const kind = providerKind();
|
|
205
|
-
const mk = modelKey(kind);
|
|
206
|
-
if (!mk) {
|
|
207
|
-
screen.log(red(`${kind} is provided by plugin ${pluginProvider(kind)?.plugin ?? "(not loaded)"}, which does not declare a model setting; set the model in ${shortPath(envFile)}.`));
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
return applyConfig({ [mk]: model, JADE_CONTEXT_WINDOW: undefined });
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** 选模型:服务能列出模型时从列表里选,否则手动输入 */
|
|
214
|
-
async function chooseModel(env: Env, current: string | undefined, saved: string[] = []): Promise<string | undefined> {
|
|
215
|
-
const models = await listModels(env);
|
|
216
|
-
if (models.length > 0) {
|
|
217
|
-
const OTHER = "\0other";
|
|
218
|
-
const picked = await screen.select(
|
|
219
|
-
"Choose a model",
|
|
220
|
-
[
|
|
221
|
-
...models.map((m) => ({ label: m, value: m, hint: m === current ? "current" : saved.includes(m) ? "saved" : undefined })),
|
|
222
|
-
{ label: "Enter a name…", value: OTHER },
|
|
223
|
-
],
|
|
224
|
-
);
|
|
225
|
-
if (picked !== OTHER) return picked;
|
|
226
|
-
}
|
|
227
|
-
return (await screen.input("Model name", { initial: current })) || undefined;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
async function configureProvider(): Promise<boolean> {
|
|
231
|
-
const current = hasProvider() ? providerInfo() : undefined;
|
|
232
|
-
const currentId = hasProvider() ? serviceId(process.env) : undefined;
|
|
233
|
-
const kind = await screen.select<string>("Which service should jade use?", [
|
|
234
|
-
...PROVIDERS.map((p) => ({ label: p.label, value: p.kind, hint: p.kind === current?.kind ? `${p.hint} · current` : p.hint })),
|
|
235
|
-
...pluginProviders().map((p) => ({ label: p.def.kind, value: p.def.kind, hint: `plugin ${p.plugin}${p.def.kind === current?.kind ? " · current" : ""}` })),
|
|
236
|
-
]);
|
|
237
|
-
if (!kind) return false;
|
|
238
|
-
if (!isBuiltinKind(kind)) return configurePlugin(kind);
|
|
239
|
-
const same = kind === current?.kind;
|
|
240
|
-
|
|
241
|
-
let baseURL: string | undefined = process.env[URL_KEY[kind]];
|
|
242
|
-
if (kind !== "anthropic") {
|
|
243
|
-
const fallback = kind === "openai" ? "https://api.openai.com/v1" : "";
|
|
244
|
-
const answer = await screen.input("Base URL", { initial: baseURL ?? fallback, placeholder: "https://example.com/v1" });
|
|
245
|
-
if (answer === undefined) return false;
|
|
246
|
-
if (kind === "openai-compat" && !answer) {
|
|
247
|
-
screen.log(red("A base URL is required."));
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
baseURL = answer || undefined;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// 已知的密钥:当前服务的,或者保存过的同一个地址的服务的(最近用过的那个)
|
|
254
|
-
const sameAddress = (env: Env) => {
|
|
255
|
-
const i = providerInfo(env);
|
|
256
|
-
return i.kind === kind && (i.baseURL ?? "") === (providerInfo({ JADE_PROVIDER: kind, [URL_KEY[kind]]: baseURL }).baseURL ?? "");
|
|
257
|
-
};
|
|
258
|
-
const services = await savedServices();
|
|
259
|
-
const known = current && sameAddress(process.env) ? process.env[KEY_KEY[kind]] : services.find((s) => sameAddress(s.env))?.env[KEY_KEY[kind]];
|
|
260
|
-
const answer = await screen.input("API key", {
|
|
261
|
-
mask: true,
|
|
262
|
-
placeholder: known ? "leave empty to keep the saved key" : kind === "openai-compat" ? "leave empty if the service needs none" : "",
|
|
263
|
-
});
|
|
264
|
-
if (answer === undefined) return false;
|
|
265
|
-
const key = answer || known;
|
|
266
|
-
|
|
267
|
-
const serviceEnv: Env = { JADE_PROVIDER: kind, [URL_KEY[kind]]: baseURL, [KEY_KEY[kind]]: key };
|
|
268
|
-
if (kind === "openai-compat") {
|
|
269
|
-
// 额外的请求参数跟着服务走:同一个服务保留,换了服务用保存过的那份
|
|
270
|
-
const saved = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
|
|
271
|
-
serviceEnv.OPENAI_COMPAT_EXTRA_BODY = saved ? saved.env.OPENAI_COMPAT_EXTRA_BODY : sameAddress(process.env) ? process.env.OPENAI_COMPAT_EXTRA_BODY : undefined;
|
|
272
|
-
}
|
|
273
|
-
const target = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
|
|
274
|
-
const model = await chooseModel({ ...process.env, ...serviceEnv }, same ? current?.model : undefined, target?.models.map((m) => m.name));
|
|
275
|
-
if (!model) return false;
|
|
276
|
-
|
|
277
|
-
// 用过的模型带上它自己的设置
|
|
278
|
-
const saved = target?.models.find((m) => m.name === model);
|
|
279
|
-
if (target && saved) return useSaved({ ...target, env: { ...target.env, ...pick(serviceEnv, serviceKeys(kind)) } }, saved);
|
|
280
|
-
|
|
281
|
-
const updates: Record<string, string | undefined> = { ...serviceEnv, [MODEL_KEY[kind]]: model, JADE_CONTEXT_WINDOW: undefined };
|
|
282
|
-
// 思考力度的取值每种服务不同
|
|
283
|
-
if (!same) updates.JADE_EFFORT = undefined;
|
|
284
|
-
// 其他服务常常默认只给 4096 个输出 token,带思考的模型很容易用完
|
|
285
|
-
if (kind !== "anthropic" && !process.env.JADE_MAX_TOKENS) {
|
|
286
|
-
const max = await screen.input("Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", { initial: "32K" });
|
|
287
|
-
if (max === undefined || !tokensInput(screen, "Output limit", max)) return false;
|
|
288
|
-
if (max) updates.JADE_MAX_TOKENS = max;
|
|
289
|
-
}
|
|
290
|
-
// 同一个地址只换了密钥:原来的服务下的模型归到新的密钥下
|
|
291
|
-
const rekeyed = same && currentId !== undefined && sameAddress(process.env) && key !== process.env[KEY_KEY[kind]];
|
|
292
|
-
return applyConfig(updates, rekeyed ? currentId : undefined);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/** 插件提供的服务:依次询问它声明的配置项,再选模型(声明了模型名时) */
|
|
296
|
-
async function configurePlugin(kind: string): Promise<boolean> {
|
|
297
|
-
const settings = settingsOf(kind);
|
|
298
|
-
const same = providerKind() === kind && hasProvider();
|
|
299
|
-
const services = await savedServices();
|
|
300
|
-
/** 已知的值:当前用的就是这个服务时取当前的,否则取最近保存过的这个服务的 */
|
|
301
|
-
const known = (k: string) => (same ? process.env[k] : services.find((s) => providerKind(s.env) === kind)?.env[k]);
|
|
302
|
-
const env: Env = { JADE_PROVIDER: kind };
|
|
303
|
-
for (const x of settings.filter((s) => !s.model)) {
|
|
304
|
-
const old = known(x.env);
|
|
305
|
-
const answer = await screen.input(x.label, {
|
|
306
|
-
mask: x.secret,
|
|
307
|
-
initial: x.secret ? undefined : old,
|
|
308
|
-
placeholder: x.secret && old ? "leave empty to keep the saved value" : x.placeholder,
|
|
309
|
-
});
|
|
310
|
-
if (answer === undefined) return false;
|
|
311
|
-
// 密钥留空表示沿用,其他的留空表示不设
|
|
312
|
-
const value = answer.trim() || (x.secret ? old : undefined);
|
|
313
|
-
if (x.required && !value) {
|
|
314
|
-
screen.log(red(`${x.label} is required.`));
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
env[x.env] = value;
|
|
318
|
-
}
|
|
319
|
-
const updates: Record<string, string | undefined> = { ...env, JADE_CONTEXT_WINDOW: undefined };
|
|
320
|
-
// 思考力度的取值每种服务不同
|
|
321
|
-
if (!same) updates.JADE_EFFORT = undefined;
|
|
322
|
-
const mk = modelKey(kind);
|
|
323
|
-
if (mk) {
|
|
324
|
-
const target = services.find((s) => serviceId(s.env) === serviceId(env));
|
|
325
|
-
const model = await chooseModel({ ...process.env, ...env }, same ? process.env[mk] : undefined, target?.models.map((m) => m.name));
|
|
326
|
-
if (!model) return false;
|
|
327
|
-
const saved = target?.models.find((m) => m.name === model);
|
|
328
|
-
if (target && saved) return useSaved({ ...target, env: { ...target.env, ...pick(env, serviceKeys(kind)) } }, saved);
|
|
329
|
-
updates[mk] = model;
|
|
330
|
-
}
|
|
331
|
-
return applyConfig(updates);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
async function configureModel(arg: string | undefined) {
|
|
335
|
-
const info = providerInfo();
|
|
336
|
-
// 之前只有 .env 时配置的模型也记下来,之后换了不会丢
|
|
337
|
-
await remember().catch(() => {});
|
|
338
|
-
const currentId = serviceId(process.env);
|
|
339
|
-
const services = await savedServices();
|
|
340
|
-
/** 保存过的、不是当前的模型,按服务分组:当前服务的在前 */
|
|
341
|
-
const others = [...services.filter((s) => serviceId(s.env) === currentId), ...services.filter((s) => serviceId(s.env) !== currentId)].flatMap((s) =>
|
|
342
|
-
s.models.filter((m) => !(serviceId(s.env) === currentId && m.name === info.model)).map((m) => ({ service: s, model: m })),
|
|
343
|
-
);
|
|
344
|
-
if (arg) {
|
|
345
|
-
// 保存过的模型按名字切换(当前服务的优先),否则换当前服务的模型
|
|
346
|
-
const saved = others.find((o) => o.model.name === arg);
|
|
347
|
-
return void (await (saved ? useSaved(saved.service, saved.model) : switchModel(arg)));
|
|
348
|
-
}
|
|
349
|
-
// 主菜单只管切换:保存过的模型全部直接列出(当前的在最前,然后是同一服务的),选中就换;
|
|
350
|
-
// 添加模型、当前模型的设置、删除各占一项,细节进子菜单再看。模型多于 10 个时可以打字筛选
|
|
351
|
-
const here = describeService({ env: process.env as Record<string, string>, models: [] });
|
|
352
|
-
const multi = services.length > 1;
|
|
353
|
-
const action = await screen.select<string>("Switch model", [
|
|
354
|
-
{ label: info.model, value: "current", hint: multi ? `current · ${here}` : "current" },
|
|
355
|
-
...others.map((o, i) => ({ label: o.model.name, value: `saved:${i}`, hint: multi ? describeService(o.service) : undefined })),
|
|
356
|
-
{ label: "Add a model…", value: "add", hint: "from this service or another one" },
|
|
357
|
-
{ label: `Settings for ${info.model}…`, value: "settings", hint: settingsSummary(info.kind, opts.contextWindow()) },
|
|
358
|
-
...(others.length ? [{ label: "Remove a saved model…", value: "forget" }] : []),
|
|
359
|
-
]);
|
|
360
|
-
if (action?.startsWith("saved:")) {
|
|
361
|
-
const o = others[Number(action.slice(6))]!;
|
|
362
|
-
await useSaved(o.service, o.model);
|
|
363
|
-
} else if (action === "add") {
|
|
364
|
-
const where = await screen.select<string>("Add a model from", [
|
|
365
|
-
{ label: "This service", value: "model", hint: here },
|
|
366
|
-
{ label: "Another service…", value: "provider", hint: "or change this one's base URL / API key" },
|
|
367
|
-
]);
|
|
368
|
-
if (where === "model") {
|
|
369
|
-
const saved = services.find((s) => serviceId(s.env) === currentId)?.models.map((m) => m.name);
|
|
370
|
-
const model = await chooseModel(process.env, info.model, saved);
|
|
371
|
-
if (model && model !== info.model) await switchModel(model);
|
|
372
|
-
} else if (where === "provider") await configureProvider();
|
|
373
|
-
} else if (action === "settings") await configureSettings();
|
|
374
|
-
else if (action === "forget") {
|
|
375
|
-
const owners = services.filter((s) => others.some((o) => o.service === s));
|
|
376
|
-
const gone = await pickSaved(owners, "Remove a model from which service?", (s, m) => !(serviceId(s.env) === currentId && m.name === info.model));
|
|
377
|
-
if (!gone) return;
|
|
378
|
-
const id = serviceId(gone.service.env);
|
|
379
|
-
// 服务下没有模型了就连服务(和它的密钥)一起删掉;认不出的服务原样保留
|
|
380
|
-
const rest = (await readSavedServices(modelsFile))
|
|
381
|
-
.map((s) => (serviceId(s.env) === id ? { ...s, models: s.models.filter((m) => m.name !== gone.model.name) } : s))
|
|
382
|
-
.filter((s) => s.models.length > 0);
|
|
383
|
-
await writeSavedServices(modelsFile, rest);
|
|
384
|
-
screen.log(dim(`Removed ${gone.model.name} (${describeService(gone.service)}).`));
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/** 当前模型自己的设置(切换模型时跟着换):输出上限、思考力度、上下文窗口、限速、能不能看图 */
|
|
389
|
-
async function configureSettings() {
|
|
390
|
-
const info = providerInfo();
|
|
391
|
-
const efforts = isBuiltinKind(info.kind) ? EFFORTS[info.kind] : undefined;
|
|
392
|
-
const action = await screen.select<string>(`Settings for ${info.model}`, [
|
|
393
|
-
{ label: "Output limit per reply", value: "max", hint: process.env.JADE_MAX_TOKENS ? `${process.env.JADE_MAX_TOKENS} tokens` : "service default" },
|
|
394
|
-
...(efforts
|
|
395
|
-
? [{ label: "Reasoning effort", value: "effort", hint: process.env.JADE_EFFORT ?? (info.kind === "anthropic" ? "high (default)" : "service default") }]
|
|
396
|
-
: []),
|
|
397
|
-
{ label: "Context window", value: "window", hint: `${opts.contextWindow()} tokens${process.env.JADE_CONTEXT_WINDOW ? "" : " (default)"}` },
|
|
398
|
-
{ label: "Requests per minute", value: "rpm", hint: process.env.JADE_RPM ? `${process.env.JADE_RPM}/min` : "no limit (slows down after being rate limited)" },
|
|
399
|
-
{ label: "Can see images", value: "vision", hint: visionHint(info.kind) },
|
|
400
|
-
]);
|
|
401
|
-
if (action === "max") {
|
|
402
|
-
const max = await screen.input("Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", { initial: process.env.JADE_MAX_TOKENS ?? "32K" });
|
|
403
|
-
if (max !== undefined && tokensInput(screen, "Output limit", max)) await applyConfig({ JADE_MAX_TOKENS: max || undefined });
|
|
404
|
-
} else if (action === "effort" && efforts) {
|
|
405
|
-
const DEFAULT = "\0default";
|
|
406
|
-
const effort = await screen.select("Reasoning effort", [
|
|
407
|
-
...efforts.map((e) => ({ label: e, value: e, hint: e === process.env.JADE_EFFORT ? "current" : undefined })),
|
|
408
|
-
{ label: "Default", value: DEFAULT, hint: info.kind === "anthropic" ? "high" : "service default" },
|
|
409
|
-
]);
|
|
410
|
-
if (effort !== undefined) await applyConfig({ JADE_EFFORT: effort === DEFAULT ? undefined : effort });
|
|
411
|
-
} else if (action === "rpm") {
|
|
412
|
-
const n = await screen.input("Requests per minute, e.g. 20 for most free models (empty for no limit)", { initial: process.env.JADE_RPM ?? "" });
|
|
413
|
-
if (n === undefined) return;
|
|
414
|
-
try {
|
|
415
|
-
rpmFromEnv({ JADE_RPM: n });
|
|
416
|
-
} catch (err) {
|
|
417
|
-
return screen.log(red(errorText(err)));
|
|
418
|
-
}
|
|
419
|
-
await applyConfig({ JADE_RPM: n.trim() || undefined });
|
|
420
|
-
} else if (action === "vision") {
|
|
421
|
-
const DEFAULT = "\0default";
|
|
422
|
-
const current = visionSetting();
|
|
423
|
-
const choice = await screen.select("Can this model see images (screenshots, image files)?", [
|
|
424
|
-
{ label: "Yes", value: "on", hint: current === true ? "current" : "the screenshot tool becomes available" },
|
|
425
|
-
{ label: "No", value: "off", hint: current === false ? "current" : "images are replaced with a note" },
|
|
426
|
-
{
|
|
427
|
-
label: "Default",
|
|
428
|
-
value: DEFAULT,
|
|
429
|
-
hint: info.kind === "openai-compat" ? "no for compatible services" : isBuiltinKind(info.kind) ? "yes" : "no for plugin services",
|
|
430
|
-
},
|
|
431
|
-
]);
|
|
432
|
-
if (choice === undefined) return;
|
|
433
|
-
// 换了 provider 立即生效:图片发不发、截图工具给不给模型都在每次请求时按它判断,不用重启
|
|
434
|
-
if (await applyConfig({ JADE_VISION: choice === DEFAULT ? undefined : choice })) {
|
|
435
|
-
screen.log(dim(visionFromEnv() ? "Images and screenshots will be sent to the model." : "Images will be replaced with a note; the screenshot tool is hidden."));
|
|
436
|
-
}
|
|
437
|
-
} else if (action === "window") {
|
|
438
|
-
const n = await screen.input("Context window in tokens, e.g. 128000, 512K, 1M (empty to infer it from the model name, or 128K if unknown)", {
|
|
439
|
-
initial: process.env.JADE_CONTEXT_WINDOW ?? "",
|
|
440
|
-
});
|
|
441
|
-
if (n !== undefined && tokensInput(screen, "Context window", n)) await applyConfig({ JADE_CONTEXT_WINDOW: n || undefined });
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* 从几个服务里选一个保存过的模型:只有一个服务时直接列它的模型,否则先选服务。
|
|
447
|
-
* keep 过滤可选的模型;取消时返回 undefined
|
|
448
|
-
*/
|
|
449
|
-
async function pickSaved(
|
|
450
|
-
from: SavedService[],
|
|
451
|
-
title: string,
|
|
452
|
-
keep: (s: SavedService, m: SavedModel) => boolean = () => true,
|
|
453
|
-
): Promise<{ service: SavedService; model: SavedModel } | undefined> {
|
|
454
|
-
const groups = from.map((s) => ({ service: s, models: s.models.filter((m) => keep(s, m)) })).filter((g) => g.models.length > 0);
|
|
455
|
-
const group =
|
|
456
|
-
groups.length === 1
|
|
457
|
-
? groups[0]
|
|
458
|
-
: await screen.select(
|
|
459
|
-
title,
|
|
460
|
-
groups.map((g) => ({ label: describeService(g.service), value: g, hint: modelNames(g.models) })),
|
|
461
|
-
);
|
|
462
|
-
if (!group) return undefined;
|
|
463
|
-
const model = await screen.select(
|
|
464
|
-
`Model (${describeService(group.service)})`,
|
|
465
|
-
group.models.map((m) => ({ label: m.name, value: m })),
|
|
466
|
-
);
|
|
467
|
-
return model && { service: group.service, model };
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return { provider: configureProvider, model: configureModel };
|
|
471
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|