@uncarved/jade 0.1.3 → 0.2.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/bin/jade.js +5 -27
- 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 +159 -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 +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -100
- 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 +73 -38
- 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 +19 -42
- package/{src/tools → plugins/fs}/grep.ts +1 -1
- package/plugins/fs/index.ts +34 -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 +79 -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 +198 -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 +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -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 +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +113 -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 +74 -99
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -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 +58 -26
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
- 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 +51 -33
- 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 +17 -42
- package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
- package/plugins-dist/fs/index.js +36 -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 +69 -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 +167 -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 +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -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 +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +586 -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 +115 -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 +76 -98
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -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 +50 -24
- 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 +155 -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/README.md +0 -204
- 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/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/plugins/core.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
// 内置插件里和界面有关的部分:/memory、/skills、/mcp、/checks、/compact 这些斜杠命令,
|
|
2
|
-
// 以及把一段系统提示词、一个"第几次回复"计数器挂到插件上的小工具。
|
|
3
|
-
// 命令用的是第三方插件同样的 PluginCommand 接口(ctx.ui 交互、ctx.note 告诉模型),停用插件时命令也一起消失。
|
|
4
|
-
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import type { HookSpec, SystemSegment, Trust } from "uncarved";
|
|
7
|
-
import type { Check, Checks } from "./checks.ts";
|
|
8
|
-
import type { Compactor } from "./compact.ts";
|
|
9
|
-
import type { JadePlugin, PluginCommand } from "./loader.ts";
|
|
10
|
-
import { MEMORY_SCOPES, type Memory, type MemoryScope } from "../memory.ts";
|
|
11
|
-
import { describeServer, type McpClient } from "../mcp.ts";
|
|
12
|
-
import type { Skill } from "../skills.ts";
|
|
13
|
-
import { display } from "../tools/fs.ts";
|
|
14
|
-
import { SEARCH_PROVIDERS } from "../tools/web.ts";
|
|
15
|
-
import { updateEnvFile } from "../config.ts";
|
|
16
|
-
import { clip } from "../ui/render.ts";
|
|
17
|
-
import { bold, dim, green, red, yellow } from "../ui/screen.ts";
|
|
18
|
-
|
|
19
|
-
/** 给插件加一个 context.build hook,把这些段落接在已有的系统提示词后面 */
|
|
20
|
-
export function withSystem<T extends JadePlugin>(plugin: T, parts: { text: string; trust: Trust }[]): T {
|
|
21
|
-
if (parts.length === 0) return plugin;
|
|
22
|
-
const segments: SystemSegment[] = parts.map(({ text, trust }) => ({ text, trust, stability: "stable", origin: { by: "plugin", id: plugin.id } }));
|
|
23
|
-
return addHook(plugin, { kind: "transform", point: "context.build", fn: (req) => ({ ...req, system: [...req.system, ...segments] }) });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** 每次请求模型前加一:工具据此判断两个调用是不是同一次回复里发出的 */
|
|
27
|
-
export function withCounter<T extends JadePlugin>(plugin: T, counter: { calls: number }): T {
|
|
28
|
-
return addHook(plugin, {
|
|
29
|
-
kind: "transform",
|
|
30
|
-
point: "model.before",
|
|
31
|
-
fn: () => {
|
|
32
|
-
counter.calls++;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function addHook<T extends JadePlugin>(plugin: T, hook: HookSpec): T {
|
|
38
|
-
const need = `${hook.kind}:${hook.point}`;
|
|
39
|
-
return { ...plugin, hooks: [...(plugin.hooks ?? []), hook], needs: [...new Set([...(plugin.needs ?? []), need])] };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ---------- /memory ----------
|
|
43
|
-
|
|
44
|
-
export function memoryCommand(memory: Memory): PluginCommand {
|
|
45
|
-
return {
|
|
46
|
-
name: "memory",
|
|
47
|
-
args: "[text]",
|
|
48
|
-
description: "see and remove what jade remembers across sessions, or remember text",
|
|
49
|
-
instant: true,
|
|
50
|
-
async run(args, { ui, note }) {
|
|
51
|
-
let text = args.trim();
|
|
52
|
-
if (!text) {
|
|
53
|
-
const entries = (await Promise.all(MEMORY_SCOPES.map(async (scope) => (await memory.list(scope)).map((t) => ({ scope, text: t }))))).flat();
|
|
54
|
-
if (!ui.interactive) return entries.length ? entries.map((e) => `${e.scope}: ${e.text}`).join("\n") : "jade does not remember anything yet";
|
|
55
|
-
const choice = await ui.select<{ scope: MemoryScope; text: string } | "add">(
|
|
56
|
-
entries.length ? "Memory: choose an entry to remove it, or add one" : "jade does not remember anything yet",
|
|
57
|
-
[{ label: "Add a memory…", value: "add" as const }, ...entries.map((e) => ({ label: e.text, value: e, hint: e.scope }))],
|
|
58
|
-
{ body: dim(`user (all projects): ${memory.files.user}\nproject: ${memory.files.project}`) },
|
|
59
|
-
);
|
|
60
|
-
if (!choice) return;
|
|
61
|
-
if (choice !== "add") {
|
|
62
|
-
const ok = await ui.select(
|
|
63
|
-
`Remove this ${choice.scope} memory?`,
|
|
64
|
-
[
|
|
65
|
-
{ label: "No", value: false },
|
|
66
|
-
{ label: "Yes, remove it", value: true },
|
|
67
|
-
],
|
|
68
|
-
{ body: choice.text },
|
|
69
|
-
);
|
|
70
|
-
if (!ok) return;
|
|
71
|
-
await memory.remove(choice.scope, choice.text);
|
|
72
|
-
note(`The user removed this ${choice.scope} memory, so stop following it: ${choice.text}`);
|
|
73
|
-
return green(`Removed from ${choice.scope} memory: ${choice.text}`);
|
|
74
|
-
}
|
|
75
|
-
text = (await ui.input("What should jade remember?", { placeholder: "e.g. Reply in Chinese; run tests with bun test" })) ?? "";
|
|
76
|
-
if (!text) return;
|
|
77
|
-
}
|
|
78
|
-
const scope = await ui.select<MemoryScope>("Remember it for", [
|
|
79
|
-
{ label: "All projects", value: "user", hint: "user memory" },
|
|
80
|
-
{ label: "This project only", value: "project", hint: "project memory" },
|
|
81
|
-
]);
|
|
82
|
-
if (!scope) return;
|
|
83
|
-
const added = await memory.add(scope, text);
|
|
84
|
-
if (added) note(`The user saved a ${scope} memory; follow it from now on: ${text}`);
|
|
85
|
-
return added ? green(`Saved to ${scope} memory.`) : dim(`The ${scope} memory already has this.`);
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ---------- /skills ----------
|
|
91
|
-
|
|
92
|
-
export function skillsCommand(skills: Skill[], opts: { cwd: string; home: string }): PluginCommand {
|
|
93
|
-
return {
|
|
94
|
-
name: "skills",
|
|
95
|
-
description: "skills the agent can use",
|
|
96
|
-
instant: true,
|
|
97
|
-
run() {
|
|
98
|
-
if (skills.length === 0) {
|
|
99
|
-
return dim(`(no skills) put them in ${display(opts.cwd, path.join(opts.home, "skills"))}/<name>/SKILL.md or .jade/skills/<name>/SKILL.md`);
|
|
100
|
-
}
|
|
101
|
-
return skills
|
|
102
|
-
.map((sk) => {
|
|
103
|
-
const from = sk.plugin ? `plugin ${sk.plugin}` : sk.layer;
|
|
104
|
-
return `${bold(sk.name)} ${dim(`${from} · ${display(opts.cwd, sk.dir)}`)}\n ${clip(sk.description.replace(/\s+/g, " "), 300)}`;
|
|
105
|
-
})
|
|
106
|
-
.join("\n");
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ---------- /mcp ----------
|
|
112
|
-
|
|
113
|
-
export function mcpCommand(clients: McpClient[], opts: { cwd: string; home: string }): PluginCommand {
|
|
114
|
-
return {
|
|
115
|
-
name: "mcp",
|
|
116
|
-
args: "[reconnect <name>]",
|
|
117
|
-
description: "MCP servers: status and tools",
|
|
118
|
-
instant: true,
|
|
119
|
-
async run(args) {
|
|
120
|
-
const words = args.trim().split(/\s+/).filter(Boolean);
|
|
121
|
-
if (words[0] === "reconnect") {
|
|
122
|
-
const c = clients.find((x) => x.name === words[1]);
|
|
123
|
-
if (!c) return red(`usage: /mcp reconnect <name>; servers: ${clients.map((x) => x.name).join(", ") || "(none)"}`);
|
|
124
|
-
await c.close();
|
|
125
|
-
try {
|
|
126
|
-
await c.connect();
|
|
127
|
-
return green(`${c.name} connected, ${c.tools.length} tools`);
|
|
128
|
-
} catch (err) {
|
|
129
|
-
return red(`${c.name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (clients.length === 0) {
|
|
133
|
-
return dim(`(no MCP servers) configure them in ${display(opts.cwd, path.join(opts.home, "mcp.json"))}, .mcp.json or .jade/mcp.json`);
|
|
134
|
-
}
|
|
135
|
-
const lines: string[] = [];
|
|
136
|
-
for (const c of clients) {
|
|
137
|
-
const state = c.status === "connected" ? green("connected") : c.status === "failed" ? red("failed") : yellow(c.status);
|
|
138
|
-
const info = c.serverInfo?.name ? ` · ${c.serverInfo.name}${c.serverInfo.version ? ` ${c.serverInfo.version}` : ""}` : "";
|
|
139
|
-
const from = c.entry.plugin ? `plugin ${c.entry.plugin}` : `${c.entry.layer} · ${display(opts.cwd, c.entry.file)}`;
|
|
140
|
-
lines.push(`${bold(c.name)} ${state} ${dim(`${from} · ${describeServer(c.entry.config)}${info}`)}`);
|
|
141
|
-
if (c.error) lines.push(red(` ${c.error}`));
|
|
142
|
-
if (c.tools.length) {
|
|
143
|
-
lines.push(` tools ${c.tools.map((t) => `${t.name}${t.annotations?.readOnlyHint ? dim(" (read)") : ""}`).join(", ")}`);
|
|
144
|
-
}
|
|
145
|
-
if (c.status === "failed" && c.stderr.length) lines.push(dim(c.stderr.map((l) => ` │ ${clip(l, 200)}`).join("\n")));
|
|
146
|
-
}
|
|
147
|
-
return lines.join("\n");
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** MCP 服务在初始化时给出的使用说明,放进系统提示词(来自外部,untrusted) */
|
|
153
|
-
export function mcpInstructions(clients: McpClient[]): { text: string; trust: Trust }[] {
|
|
154
|
-
return clients
|
|
155
|
-
.filter((c) => c.status === "connected" && c.instructions)
|
|
156
|
-
.map((c) => ({ text: `# Instructions from the MCP server "${c.name}" (about its mcp__${c.name}__* tools)\n\n${c.instructions}`, trust: "untrusted" as const }));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// ---------- /checks ----------
|
|
160
|
-
|
|
161
|
-
export interface ChecksCommandOptions {
|
|
162
|
-
cwd: string;
|
|
163
|
-
home: string;
|
|
164
|
-
/** 本会话改过的文件 */
|
|
165
|
-
changed(sessionId: string): Promise<string[]>;
|
|
166
|
-
/** 这条检查命令用户是否已经确认过 */
|
|
167
|
-
confirmed?(check: Check): Promise<boolean>;
|
|
168
|
-
/** 没有检查时的原因 */
|
|
169
|
-
unavailable?: string;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function checksCommand(checks: Checks | undefined, opts: ChecksCommandOptions): PluginCommand {
|
|
173
|
-
return {
|
|
174
|
-
name: "checks",
|
|
175
|
-
args: "[on|off]",
|
|
176
|
-
description: "checks jade runs after the agent edits files (type checker, linter)",
|
|
177
|
-
instant: true,
|
|
178
|
-
async run(args, { sessionId }) {
|
|
179
|
-
if (!checks) return dim(opts.unavailable ?? "Edit-time checks are not available.");
|
|
180
|
-
const arg = args.trim();
|
|
181
|
-
if (arg === "on" || arg === "off") {
|
|
182
|
-
checks.enabled = arg === "on";
|
|
183
|
-
if (arg === "on") checks.reset();
|
|
184
|
-
return `checks: ${arg}`;
|
|
185
|
-
}
|
|
186
|
-
if (arg) return red("usage: /checks [on|off]");
|
|
187
|
-
const files = await opts.changed(sessionId);
|
|
188
|
-
const found = await checks.resolve(files);
|
|
189
|
-
const lines = [`Edit-time checks are ${checks.enabled ? "on" : "off"} in this session.`];
|
|
190
|
-
if (found.length > 0) {
|
|
191
|
-
lines.push("For the files changed in this session:");
|
|
192
|
-
for (const c of found) {
|
|
193
|
-
const pending = opts.confirmed && !(await opts.confirmed(c)) ? ", not confirmed yet" : "";
|
|
194
|
-
lines.push(` ${bold(c.name)} ${dim(`in ${display(opts.cwd, c.cwd) || "."}${pending}`)}\n ${dim(c.command)}`);
|
|
195
|
-
}
|
|
196
|
-
} else lines.push(dim(files.length ? "No checks apply to the files changed in this session." : "No files changed in this session yet."));
|
|
197
|
-
lines.push(
|
|
198
|
-
dim(
|
|
199
|
-
"Detected per file: TypeScript (nearest tsconfig.json + the project's typescript), Python (ruff), Go (go vet).\n" +
|
|
200
|
-
`Add your own in .jade/checks.json or ${path.join(opts.home, "checks.json")}; JADE_CHECKS=off turns them off.`,
|
|
201
|
-
),
|
|
202
|
-
);
|
|
203
|
-
return lines.join("\n");
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// ---------- /compact ----------
|
|
209
|
-
|
|
210
|
-
export function compactCommand(compact: Compactor): PluginCommand {
|
|
211
|
-
return {
|
|
212
|
-
name: "compact",
|
|
213
|
-
description: "compact the history before the next request",
|
|
214
|
-
run() {
|
|
215
|
-
compact.request();
|
|
216
|
-
return dim("History will be compacted before the next request.");
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// ---------- /search ----------
|
|
222
|
-
|
|
223
|
-
/** /search:设置或去掉某个搜索服务的 API key(写进 $JADE_HOME/.env),用 session.reload 让当前会话立即用上 */
|
|
224
|
-
export function searchCommand(opts: { envFile: string; env?: Record<string, string | undefined> }): PluginCommand {
|
|
225
|
-
return {
|
|
226
|
-
name: "search",
|
|
227
|
-
description: "set up web search services (TinyFish, AnySearch, Tavily, Exa, Firecrawl, Jina)",
|
|
228
|
-
async run(_args, { ui, session }) {
|
|
229
|
-
if (!session) throw new Error("/search needs session control, which this host does not provide here");
|
|
230
|
-
const env = opts.env ?? process.env;
|
|
231
|
-
const on = SEARCH_PROVIDERS.filter((p) => env[p.env]);
|
|
232
|
-
const name = await ui.select(
|
|
233
|
-
on.length ? `Web search is on (${on.map((p) => p.name).join(", ")}; tried in order, the next one takes over on failure)` : "Web search is off",
|
|
234
|
-
SEARCH_PROVIDERS.map((p) => ({ label: `${p.name}${env[p.env] ? " ✓" : ""}`, value: p.name, hint: p.signup })),
|
|
235
|
-
);
|
|
236
|
-
const p = SEARCH_PROVIDERS.find((x) => x.name === name);
|
|
237
|
-
if (!p) return;
|
|
238
|
-
if (env[p.env]) {
|
|
239
|
-
const choice = await ui.select(p.name, [
|
|
240
|
-
{ label: "Change the API key…", value: "set" as const },
|
|
241
|
-
{ label: "Remove", value: "off" as const, hint: `removes ${p.env} from ${opts.envFile}` },
|
|
242
|
-
]);
|
|
243
|
-
if (!choice) return;
|
|
244
|
-
if (choice === "off") {
|
|
245
|
-
await updateEnvFile(opts.envFile, { [p.env]: undefined }, env);
|
|
246
|
-
await session.reload();
|
|
247
|
-
return dim(`${p.name} removed.${on.length > 1 ? "" : " Web search is off."}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
const key = (await ui.input(`${p.name} API key`, { mask: true }))?.trim();
|
|
251
|
-
if (!key) return;
|
|
252
|
-
await updateEnvFile(opts.envFile, { [p.env]: key }, env);
|
|
253
|
-
await session.reload();
|
|
254
|
-
return green(`Web search is on with ${p.name}: web_search uses it, and web_fetch falls back to it when a page cannot be fetched directly.`);
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
package/src/plugins/host.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
// 进程级的插件管理(PluginHost):发现、读清单、加载、注册模型服务、退出时结束进程外插件。
|
|
2
|
-
//
|
|
3
|
-
// 整个 jade 进程只有一个。进程级的东西(插件模块、进程外插件的进程、模型服务)只在这里创建、只在这里销毁;
|
|
4
|
-
// 会话级的插件实例由 createJade 每个会话创建一套。见 docs/design/jade-plugin-lifecycle.md 第 3.1 节。
|
|
5
|
-
|
|
6
|
-
import { UntrustedPlugin, type TrustStore } from "uncarved";
|
|
7
|
-
import { PROVIDER_KIND, registerProviders, SETTING_ENV, type ProviderSetting } from "../provider.ts";
|
|
8
|
-
import { discoverPlugins, loadPlugin, resolvePlugins, type ConfirmPlugin, type LoadedPlugin, type PluginBundle, type PluginLayer, type PluginProvider, type ResolvedPlugin } from "./loader.ts";
|
|
9
|
-
|
|
10
|
-
export interface PluginHostOptions {
|
|
11
|
-
/** $JADE_HOME */
|
|
12
|
-
home: string;
|
|
13
|
-
/** 仓库根目录和工作目录(都已解析符号链接) */
|
|
14
|
-
root: string;
|
|
15
|
-
cwd: string;
|
|
16
|
-
/** 停用的插件 id($JADE_HOME/plugins.json) */
|
|
17
|
-
disabled: ReadonlySet<string>;
|
|
18
|
-
trust: TrustStore;
|
|
19
|
-
/** 项目层插件新出现或内容变化时请用户确认 */
|
|
20
|
-
confirm: ConfirmPlugin;
|
|
21
|
-
/** 要告诉用户的事:skipped 没加载的插件,note 提示,warning 问题 */
|
|
22
|
-
report(kind: "skipped" | "note" | "warning", text: string): void;
|
|
23
|
-
/** 显示插件目录,默认原样 */
|
|
24
|
-
display?(dir: string): string;
|
|
25
|
-
/** 项目层插件没确认而跳过时,附在原因后面的话(例如非交互运行时教用户怎么确认) */
|
|
26
|
-
untrustedHint?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface PluginHost {
|
|
30
|
-
/** 读过清单、没停用的插件,还没执行代码。它们带的 skills、命令、MCP 配置从这里取,不用等加载 */
|
|
31
|
-
readonly plugins: readonly ResolvedPlugin[];
|
|
32
|
-
/** 插件带的某种内容的目录,标上是哪个插件、哪一层的 */
|
|
33
|
-
bundled(pick: (b: PluginBundle) => string[]): { plugin: string; dir: string; layer: PluginLayer }[];
|
|
34
|
-
/**
|
|
35
|
-
* 依次加载插件(项目层的先请用户确认),然后注册它们导出的模型服务。只调用一次;
|
|
36
|
-
* 加载失败的跳过并报告,返回加载成功的
|
|
37
|
-
*/
|
|
38
|
-
load(): Promise<LoadedPlugin[]>;
|
|
39
|
-
/** 加载成功的插件;load 完成之前是空的 */
|
|
40
|
-
readonly loaded: readonly LoadedPlugin[];
|
|
41
|
-
/** 结束进程外插件;之后它们退出不再报告。可以多次调用 */
|
|
42
|
-
close(): Promise<void>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** 发现插件并读清单(不执行代码);按 id 停用的、id 重复的在这里去掉 */
|
|
46
|
-
export async function openPluginHost(opts: PluginHostOptions): Promise<PluginHost> {
|
|
47
|
-
const show = opts.display ?? ((dir: string) => dir);
|
|
48
|
-
const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
|
|
49
|
-
const resolved = await resolvePlugins(await discoverPlugins({ home: opts.home, root: opts.root, cwd: opts.cwd }), opts.disabled);
|
|
50
|
-
const loaded: LoadedPlugin[] = [];
|
|
51
|
-
let loading: Promise<LoadedPlugin[]> | undefined;
|
|
52
|
-
let closing = false;
|
|
53
|
-
|
|
54
|
-
async function load(): Promise<LoadedPlugin[]> {
|
|
55
|
-
for (const { found, error } of resolved.broken) opts.report("skipped", `plugin ${show(found.dir)}: ${errorText(error)}`);
|
|
56
|
-
for (const w of resolved.warnings) opts.report("skipped", w);
|
|
57
|
-
for (const p of resolved.plugins) {
|
|
58
|
-
if (p.info.bundle.unsupported.length) opts.report("note", `plugin ${p.id}: jade does not support its ${p.info.bundle.unsupported.join(" and ")} yet; they are ignored`);
|
|
59
|
-
try {
|
|
60
|
-
loaded.push(
|
|
61
|
-
await loadPlugin(p, {
|
|
62
|
-
trust: opts.trust,
|
|
63
|
-
confirm: opts.confirm,
|
|
64
|
-
onExit: (plugin, { code, signal }) => {
|
|
65
|
-
if (!closing) opts.report("warning", `plugin ${plugin.id} exited (${signal ?? `code ${code}`}); its hooks fail until jade restarts. /plugins shows its stderr`);
|
|
66
|
-
},
|
|
67
|
-
}),
|
|
68
|
-
);
|
|
69
|
-
} catch (err) {
|
|
70
|
-
const hint = p.layer === "project" && err instanceof UntrustedPlugin && opts.untrustedHint ? ` ${opts.untrustedHint}` : "";
|
|
71
|
-
opts.report("skipped", `plugin ${show(p.dir)}: ${errorText(err)}${hint}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// 模型服务是插件模块导出的,不属于哪套插件实例:加载完注册一次,所有会话共用
|
|
75
|
-
const collected = collectProviders(loaded);
|
|
76
|
-
for (const w of [...collected.warnings, ...registerProviders(collected.providers)]) opts.report("warning", w);
|
|
77
|
-
return loaded;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
plugins: resolved.plugins,
|
|
82
|
-
bundled: (pick) => resolved.plugins.flatMap((p) => pick(p.info.bundle).map((dir) => ({ plugin: p.id, dir, layer: p.layer }))),
|
|
83
|
-
load: () => (loading ??= load()),
|
|
84
|
-
loaded,
|
|
85
|
-
async close() {
|
|
86
|
-
closing = true;
|
|
87
|
-
await Promise.all(loaded.map((p) => p.close?.().catch(() => {})));
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 插件模块导出的模型服务(LoadedPlugin.providers):检查后返回要注册的服务和要告诉用户的问题。
|
|
94
|
-
* 只认用户层插件:服务能看到全部对话和 API key。不用创建插件实例,所以宿主可以先注册服务、配置好模型,再创建插件
|
|
95
|
-
*/
|
|
96
|
-
export function collectProviders(sources: readonly LoadedPlugin[]): { providers: { plugin: string; def: PluginProvider }[]; warnings: string[] } {
|
|
97
|
-
const warnings: string[] = [];
|
|
98
|
-
const providers = sources.flatMap((source) => {
|
|
99
|
-
if (source.providers === undefined) return [];
|
|
100
|
-
const where = `plugin ${source.id} (${source.layer})`;
|
|
101
|
-
if (source.layer === "project") {
|
|
102
|
-
warnings.push(`${where}: providers are ignored: only user plugins can provide model services`);
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
if (!Array.isArray(source.providers)) {
|
|
106
|
-
warnings.push(`${where}: providers is ignored: it must be an array`);
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
return (source.providers as PluginProvider[]).flatMap((d) => {
|
|
110
|
-
const ok = d && typeof d.kind === "string" && PROVIDER_KIND.test(d.kind) && typeof d.model === "function" && typeof d.create === "function";
|
|
111
|
-
if (!ok) {
|
|
112
|
-
warnings.push(`${where}: provider ${JSON.stringify(d?.kind)} is ignored: it needs a kind of letters, digits, - and _, and model and create functions`);
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
// 不改插件导出的对象:用检查过的字段另做一个,方法绑定到原对象(插件的方法里可能用 this)
|
|
116
|
-
const def: PluginProvider = {
|
|
117
|
-
kind: d.kind,
|
|
118
|
-
model: d.model.bind(d),
|
|
119
|
-
create: d.create.bind(d),
|
|
120
|
-
...(typeof d.via === "function" ? { via: d.via.bind(d) } : {}),
|
|
121
|
-
...(typeof d.listModels === "function" ? { listModels: d.listModels.bind(d) } : {}),
|
|
122
|
-
...(d.settings !== undefined ? { settings: providerSettings(d.settings, `${where}: provider ${d.kind}`, warnings) } : {}),
|
|
123
|
-
};
|
|
124
|
-
return [{ plugin: source.id, def }];
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
return { providers, warnings };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** 插件服务的配置项:格式不对、用了 jade 自己的变量、重复、第二个 model 的跳过并警告 */
|
|
131
|
-
function providerSettings(raw: unknown, where: string, warnings: string[]): ProviderSetting[] {
|
|
132
|
-
if (!Array.isArray(raw)) {
|
|
133
|
-
warnings.push(`${where}: settings are ignored: they must be an array`);
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
const out: ProviderSetting[] = [];
|
|
137
|
-
for (const x of raw as Partial<ProviderSetting>[]) {
|
|
138
|
-
const env = x?.env;
|
|
139
|
-
if (typeof env !== "string" || !SETTING_ENV.test(env) || env.startsWith("JADE_") || typeof x.label !== "string") {
|
|
140
|
-
warnings.push(`${where}: setting ${JSON.stringify(env)} is ignored: it needs an env name of capital letters, digits and _ (not JADE_…) and a label`);
|
|
141
|
-
} else if (out.some((o) => o.env === env)) warnings.push(`${where}: setting ${env} is ignored: it is listed twice`);
|
|
142
|
-
else if (x.model && out.some((o) => o.model)) warnings.push(`${where}: setting ${env} is ignored: only one setting can be the model`);
|
|
143
|
-
else out.push(x as ProviderSetting);
|
|
144
|
-
}
|
|
145
|
-
return out;
|
|
146
|
-
}
|