@vetta-org/plugin-sdk 0.3.7 → 0.3.10
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/dist/bottom-panel.d.ts +83 -0
- package/dist/bottom-panel.d.ts.map +1 -0
- package/dist/bottom-panel.js +23 -0
- package/dist/bottom-panel.js.map +1 -0
- package/dist/file-explorer.d.ts +30 -0
- package/dist/file-explorer.d.ts.map +1 -1
- package/dist/file-explorer.js.map +1 -1
- package/dist/fs.d.ts +17 -1
- package/dist/fs.d.ts.map +1 -1
- package/dist/fs.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/manifest-schema.d.ts +2 -2
- package/dist/manifest-schema.d.ts.map +1 -1
- package/dist/official.d.ts +62 -12
- package/dist/official.d.ts.map +1 -1
- package/dist/official.js.map +1 -1
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +2 -0
- package/dist/permissions.js.map +1 -1
- package/dist/ui.d.ts +43 -3
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js.map +1 -1
- package/docs/README.md +1 -0
- package/docs/conversation-and-agent.md +14 -1
- package/docs/file-explorer.md +54 -3
- package/docs/manifest.md +1 -1
- package/docs/message-cards.md +5 -1
- package/docs/permissions.md +3 -1
- package/docs/styling-and-pitfalls.md +1 -0
- package/docs/ui-slots.md +98 -2
- package/package.json +1 -1
package/docs/file-explorer.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
| --- | --- |
|
|
11
11
|
| `ui.file-explorer.context-menu` | 注册文件或目录右键菜单动作 |
|
|
12
12
|
| `ui.file-explorer.toolbar` | 注册文件列表顶部工具栏动作 |
|
|
13
|
-
| `ui.file-explorer.decorations` |
|
|
13
|
+
| `ui.file-explorer.decorations` | 注册状态装饰和可选文件图标主题 |
|
|
14
14
|
| `workspace.read` | 查询根目录/选中项、定位、刷新和订阅事件 |
|
|
15
15
|
|
|
16
16
|
上述 API 缺权限时会抛 `Plugin permission denied: <permission>`。它们不会隐式授予 `fs.read` 或 `fs.write`。
|
|
@@ -35,6 +35,8 @@ ctx.fileExplorer.registerContextMenuAction({
|
|
|
35
35
|
});
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
省略菜单项的 `icon` 时,宿主使用 `plugin.json#icon`;传入 React 节点可只覆盖这一项。
|
|
39
|
+
|
|
38
40
|
`when` 支持:
|
|
39
41
|
|
|
40
42
|
- `resourceType`: `file` 或 `directory`
|
|
@@ -56,10 +58,16 @@ ctx.fileExplorer.registerToolbarAction({
|
|
|
56
58
|
});
|
|
57
59
|
```
|
|
58
60
|
|
|
61
|
+
省略工具栏动作的 `icon` 时同样继承插件图标;传入 React 节点可只覆盖这一项。
|
|
62
|
+
|
|
59
63
|
工具栏动作只在文件列表存在活动工作区时显示。`selection` 是当前文件列表选中项的只读快照。
|
|
60
64
|
|
|
61
65
|
## 文件装饰
|
|
62
66
|
|
|
67
|
+
文件装饰不是插件入口:它不会从 `plugin.json#icon` 自动继承。它适合表达 Git、诊断、同步等
|
|
68
|
+
会动态变化的状态;图标主题则负责文件类型与文件夹外观。两者独立解析,所以用户选择图标主题后,
|
|
69
|
+
状态徽标、颜色和提示仍会保留。
|
|
70
|
+
|
|
63
71
|
```tsx
|
|
64
72
|
ctx.fileExplorer.registerDecorationProvider({
|
|
65
73
|
id: "git-status",
|
|
@@ -71,18 +79,61 @@ ctx.fileExplorer.registerDecorationProvider({
|
|
|
71
79
|
return {
|
|
72
80
|
badge: status,
|
|
73
81
|
tooltip: `%explorer.gitStatus.${status}%`,
|
|
82
|
+
color: status === "M" ? "warning" : "success",
|
|
83
|
+
propagate: true,
|
|
74
84
|
};
|
|
75
85
|
},
|
|
86
|
+
onDidChangeDecorations(listener) {
|
|
87
|
+
return gitStatusStore.subscribe((entries) => listener(entries));
|
|
88
|
+
},
|
|
76
89
|
});
|
|
77
90
|
```
|
|
78
91
|
|
|
79
|
-
`provideDecoration`
|
|
92
|
+
`provideDecoration` 在文件树渲染时同步调用,必须快速且无副作用。网络、命令和文件读取应提前完成并缓存在插件内。状态变化时用 `onDidChangeDecorations` 通知宿主重新计算,不需要为改一个徽标刷新文件系统;事件也可以携带尚未展开的后代条目,让父目录提前显示聚合状态。传 `undefined` 表示全部失效。多个提供者命中时,宿主采用 `priority` 最高且返回非空结果的提供者。
|
|
80
93
|
|
|
81
94
|
装饰可返回:
|
|
82
95
|
|
|
83
|
-
- `icon`:
|
|
96
|
+
- `icon`: 兼容旧插件的单条目图标覆盖;新插件优先注册图标主题
|
|
84
97
|
- `badge`: 文件名后的紧凑状态文本,建议一到两个字符
|
|
85
98
|
- `tooltip`: 文件行提示信息
|
|
99
|
+
- `color`: `foreground`、`muted`、`accent`、`success`、`warning` 或 `error` 语义色
|
|
100
|
+
- `faded`: 降低文件名透明度
|
|
101
|
+
- `strikethrough`: 给文件名加删除线
|
|
102
|
+
- `propagate`: 将该状态聚合到当前工作区内的父目录
|
|
103
|
+
|
|
104
|
+
插件不能注入任意 CSS,也不能改变行高、字体、缩进、排序或交互区域;这些仍由宿主控制,以保证主题、可访问性和虚拟列表稳定。
|
|
105
|
+
|
|
106
|
+
## 文件图标主题
|
|
107
|
+
|
|
108
|
+
图标主题采用类似 VS Code 的声明式关联,但图标值仍是共享 React 运行时中的节点。主题可以为默认文件/文件夹、精确文件名、扩展名、文件夹名和展开状态设置图标,并为浅色、深色和高对比模式提供覆盖。用户在文件列表的显示设置中显式选择主题;插件停用后宿主回退到内置图标,重新启用时会恢复用户原来的选择。
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
ctx.fileExplorer.registerIconTheme({
|
|
112
|
+
id: "product-icons",
|
|
113
|
+
label: "Product Icons",
|
|
114
|
+
iconDefinitions: {
|
|
115
|
+
file: <FileIcon />,
|
|
116
|
+
folder: <FolderIcon />,
|
|
117
|
+
folderOpen: <FolderOpenIcon />,
|
|
118
|
+
typescript: <TypeScriptIcon />,
|
|
119
|
+
config: <ConfigIcon />,
|
|
120
|
+
},
|
|
121
|
+
file: "file",
|
|
122
|
+
folder: "folder",
|
|
123
|
+
folderExpanded: "folderOpen",
|
|
124
|
+
fileNames: {
|
|
125
|
+
"package.json": "config",
|
|
126
|
+
},
|
|
127
|
+
fileExtensions: {
|
|
128
|
+
ts: "typescript",
|
|
129
|
+
"d.ts": "typescript",
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
关联优先级为精确文件名、最长复合扩展名(如 `d.ts`)、普通扩展名、默认文件图标;文件夹按精确名称后回退默认图标。名称匹配不区分大小写。所有引用必须指向同一主题的 `iconDefinitions`,无效输入会在注册边界直接报错。
|
|
135
|
+
|
|
136
|
+
状态装饰事件、语义样式和 `registerIconTheme` 要求插件声明 `pluginApiVersion: ^2.7.0`,旧的 `icon` / `badge` / `tooltip` provider 保持兼容。
|
|
86
137
|
|
|
87
138
|
## 工作区、选择与定位
|
|
88
139
|
|
package/docs/manifest.md
CHANGED
|
@@ -70,7 +70,7 @@ Schema 只描述 `plugin.json` 数据本身;Plugin API 版本是否兼容、
|
|
|
70
70
|
| `browser` | 使用 `browser.*` 权限时必填 | `{ allowedHosts: string[] }` | 浏览器顶层导航的最大 host 授权;session 只能收窄,见 [browser.md](./browser.md)。 |
|
|
71
71
|
| `description` | ❌ | string | 简介。可用 `%key%`。 |
|
|
72
72
|
| `author` | ❌ | string | 作者。 |
|
|
73
|
-
| `icon` | ❌ | string |
|
|
73
|
+
| `icon` | ❌ | string | 能力页/插件列表展示的图标,也是所有带图标的宿主入口未单独声明时的默认图标,包括[工作区视图、Activity Tab、输入动作与新会话上下文](./ui-slots.md)、[消息卡片](./message-cards.md)及[文件操作](./file-explorer.md)。任一入口都可声明自己的 `icon` 覆盖它。支持 Iconify 名(如 `solar:widget-add-bold`)、`http(s)://` 外链,或包内相对路径(如 `assets/icon.png`)。 |
|
|
74
74
|
| `defaultLocale` | ❌ | string | i18n 缺译回退 locale,默认 `"zh"`。见 [i18n](#i18n)。 |
|
|
75
75
|
| `guidingWords` | ❌ | string[] | 新会话引导词,见 [下文](#guidingwords引导词)。条目可用 `%key%`。 |
|
|
76
76
|
| `agent` | ❌ | object | Agent 侧贡献(prompt / skill / **MCP** / toolPolicy),见 [Agent 清单](#agent-agent-侧贡献)。 |
|
package/docs/message-cards.md
CHANGED
|
@@ -60,7 +60,7 @@ interface PluginCardRendererContribution {
|
|
|
60
60
|
type: string; // 与描述符 type 完全一致
|
|
61
61
|
component: ComponentType<PluginCardProps>;
|
|
62
62
|
title?: string; // 默认 tab 标签
|
|
63
|
-
icon?: ReactNode; // 默认 tab
|
|
63
|
+
icon?: ReactNode; // 默认 tab 图标;省略时用插件自己的图标
|
|
64
64
|
pendingFor?: (toolCall: PluginPendingToolCall) => CardDescriptor | null;
|
|
65
65
|
}
|
|
66
66
|
```
|
|
@@ -79,6 +79,10 @@ ctx.ui.registerCardRenderer({
|
|
|
79
79
|
});
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
`plugin.json#icon` 是 renderer 的缺省 tab 图标;注册时传入 `icon` 可为这一类卡片设置专用图标,
|
|
83
|
+
单个 `CardDescriptor.icon` 又可覆盖 renderer 默认值。描述符跨 agent → 宿主边界传递,因此该字段使用
|
|
84
|
+
Iconify 名或 `icon-[…]` 字符串,而不是 React 节点。
|
|
85
|
+
|
|
82
86
|
## 生成中骨架 pendingFor
|
|
83
87
|
|
|
84
88
|
`details.cards` 只在工具**完成后**才有。为了让「生成中」也占一张卡片/一个 tab,宿主对每个 **pending 的** tool_call 调用每个渲染器的 `pendingFor(toolCall)`:
|
package/docs/permissions.md
CHANGED
|
@@ -24,7 +24,7 @@ ctx.permissions.require("fs.read"); // 缺则抛 Plugin permission denied: fs.r
|
|
|
24
24
|
|
|
25
25
|
不同注册点对「声明了但未授权」的处理不同:
|
|
26
26
|
|
|
27
|
-
- **抛错(require)**:`registerInputAction`、`registerCardRenderer`、`registerToolCallSlot`、`registerTurnCard`、`registerShortcutScope`、`openActivityTab`、`setActivityTabVisible`、`setPromptAttachment`、`fileExplorer.*`、`agent.registerContinuationProvider`、`agent.registerSystemPromptProvider`、`conversation.*`、`fs.*`、`network.*`、`storage.*`、`media.*`、`ai.*`、`command.run`。缺权限直接抛 `Plugin permission denied: <permission>`,中断该次调用。
|
|
27
|
+
- **抛错(require)**:`registerInputAction`、`registerCardRenderer`、`registerToolCallSlot`、`registerTurnCard`、`registerShortcutScope`、`openActivityTab`、`setActivityTabVisible`、`setPromptAttachment`、`fileExplorer.*`、`useBottomPanel().openTerminal`、`agent.registerContinuationProvider`、`agent.registerSystemPromptProvider`、`conversation.*`、`fs.*`、`network.*`、`storage.*`、`media.*`、`ai.*`、`command.run`。缺权限直接抛 `Plugin permission denied: <permission>`,中断该次调用。
|
|
28
28
|
- **跳过 + 警告(warn+noop)**:`registerGlobalSlot`、`registerFilePreview`、`registerActivityTab`、`registerNewSessionContext`、`agent.registerTool`、`agent.registerHook`、`appActions.register`。缺权限时静默跳过该贡献并打 `console.warn`,**不影响**插件其它已授权能力。
|
|
29
29
|
|
|
30
30
|
> 设计上一个缺失权限不应拖垮插件的其它能力——`activate()` 里建议把可选能力的注册各自独立,避免一处 throw 掉整段。
|
|
@@ -37,6 +37,8 @@ ctx.permissions.require("fs.read"); // 缺则抛 Plugin permission denied: fs.r
|
|
|
37
37
|
| `ui.slot.workspace-view` | `ctx.ui.registerWorkspaceView()` / `openWorkspaceView()` / `setWorkspaceViewBadge()` | [ui-slots](./ui-slots.md#工作区视图-registerworkspaceview) |
|
|
38
38
|
| `ui.slot.file-preview` | `ctx.ui.registerFilePreview()` | [ui-slots](./ui-slots.md#文件预览-registerfilepreview) |
|
|
39
39
|
| `ui.slot.activity-tab` | `registerActivityTab` / `openActivityTab` / `setActivityTabVisible` | [ui-slots](./ui-slots.md#活动面板-tab-registeractivitytab) |
|
|
40
|
+
| `ui.slot.bottom-panel` | `registerBottomPanel` | [ui-slots](./ui-slots.md#会话底部面板-registerbottompanel) |
|
|
41
|
+
| `terminal.run` | 底部面板里的 `useBottomPanel().openTerminal()`(开终端并替用户敲命令) | [ui-slots](./ui-slots.md#替用户开终端跑命令-openterminal) |
|
|
40
42
|
| `ui.slot.input-action` | `registerInputAction` / `setPromptAttachment` | [ui-slots](./ui-slots.md#输入栏动作-registerinputaction) |
|
|
41
43
|
| `ui.slot.new-session-context` | `ctx.ui.registerNewSessionContext()` | [ui-slots](./ui-slots.md#新会话上下文区-registernewsessioncontext) |
|
|
42
44
|
| `conversation.draft.read` | 新会话上下文区的 `context.draft`(未授予恒为空串) | 同上 |
|
|
@@ -72,6 +72,7 @@ Agent 写插件时可以按普通 React 项目使用 `className` 或 CSS;不
|
|
|
72
72
|
| --- | --- |
|
|
73
73
|
| **`registerFilePreview`** | 内容铺满预览区;所有 UI 留在预览壳内 |
|
|
74
74
|
| **`registerActivityTab`** | 内容铺满 Tab 面板;所有 UI 留在面板内 |
|
|
75
|
+
| **`registerBottomPanel`** | 内容铺满自己的分格;关闭确认交给宿主,不要自己画对话框 |
|
|
75
76
|
| **`registerInputAction` 面板内容**(若有) | 同面板约束 |
|
|
76
77
|
| **`registerGlobalSlot`** | **例外**:这是全局浮层扩展点,可相对视口布局 |
|
|
77
78
|
| **`ctx.ui.notify`** | **例外**:全局 Toast,由宿主渲染,不要自己造右上角固定条 |
|
package/docs/ui-slots.md
CHANGED
|
@@ -358,7 +358,7 @@ pdfjs.getDocument({ url: file.getUrl() });
|
|
|
358
358
|
interface PluginActivityTabContribution {
|
|
359
359
|
id: string;
|
|
360
360
|
label: string; // 可用 %catalogKey%(见 i18n)
|
|
361
|
-
icon?: ReactNode;
|
|
361
|
+
icon?: ReactNode; // 省略时用插件自己的图标
|
|
362
362
|
component: ComponentType; // 零 props
|
|
363
363
|
scope_use?: readonly ConversationScenario[]; // fail-closed
|
|
364
364
|
initiallyVisible?: boolean; // 缺省 true:注册即上栏;false = 出现条件由插件自己驱动
|
|
@@ -437,6 +437,102 @@ ctx.ui.registerInputAction({
|
|
|
437
437
|
|
|
438
438
|
上栏记录按 cwd 持久化,所以**只需在条件变化时调用**;用户之后用减号手动隐藏的结果不会被重复调用覆盖。当前没有活动会话时是 no-op(无处记录),插件应在会话就绪后重新判定。异步判定要注意丢弃过期结果:写入落在**调用时**的活动会话上,探测期间切走了就别再写。
|
|
439
439
|
|
|
440
|
+
## 会话底部面板 registerBottomPanel
|
|
441
|
+
|
|
442
|
+
向会话页底部面板注册一个可打开的组件。
|
|
443
|
+
|
|
444
|
+
**和活动面板 Tab 怎么选**:活动面板在右侧、一个贡献只有一个实例,适合「看某个东西的当前状态」;底部面板横跨会话页下沿、可上下左右分屏、**同一个贡献可以开多个实例**,适合终端、日志跟随这类长驻的工作面。
|
|
445
|
+
|
|
446
|
+
- 权限:`ui.slot.bottom-panel`(注册 **warn+noop**)
|
|
447
|
+
- **`scope_use` fail-closed**(必写,否则任何场景都不出现)
|
|
448
|
+
- **注册只入池**,不直接渲染:用户从面板的「+」菜单开出实例。`order` 决定菜单里的位置(缺省 100,宿主把下限钳到 10,内置终端永远在前)
|
|
449
|
+
- **多实例**:缺省不限,`maxInstances: 1` 表示单例(开过一个之后菜单项禁用)
|
|
450
|
+
- **布局与结构按会话持久化**(分屏、比例、面板高度、哪些 tab 开着)。进程与组件状态不跨应用重启保活
|
|
451
|
+
- **折叠不卸载**:面板收起时组件仍然挂着,只是 `active` 变成 `false`;此时它的名字和状态点会以药丸的形式排在输入框下方。昂贵的轮询和动画应在 `active === false` 时主动暂停
|
|
452
|
+
- **布局边界(面板内)**:与 file-preview / activity-tab 相同——UI 留在自己的分格矩形内,禁止 viewport 级 `fixed` / 超高 z-index / portal 到 `document.body`。**关闭确认由宿主弹**,插件不要自己画对话框。见 [styling-and-pitfalls.md → 面板类 slot 布局边界](./styling-and-pitfalls.md#面板类-slot-布局边界禁止-viewport-级浮层)
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
interface PluginBottomPanelContribution {
|
|
456
|
+
id: string;
|
|
457
|
+
label: string; // 「+」菜单里的名字,也是新实例的初始名;可用 %catalogKey%
|
|
458
|
+
icon?: ReactNode; // 省略时用插件自己的图标
|
|
459
|
+
component: ComponentType; // 零 props
|
|
460
|
+
scope_use?: readonly ConversationScenario[]; // fail-closed
|
|
461
|
+
order?: number; // 缺省 100
|
|
462
|
+
maxInstances?: number; // 缺省不限
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
```tsx
|
|
467
|
+
ctx.ui.registerBottomPanel({
|
|
468
|
+
id: "logs",
|
|
469
|
+
label: "%panel.logs%",
|
|
470
|
+
component: LogsPanel,
|
|
471
|
+
scope_use: ["project", "conversation"],
|
|
472
|
+
});
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### useBottomPanel
|
|
476
|
+
|
|
477
|
+
组件零 props,实例身份与控制面用 `useBottomPanel()` 取。**名字、图标、状态点都是命令式设置的**,不是「每帧返回 meta」——同一个贡献可以有多个实例,每帧 hook 拿不到实例身份。
|
|
478
|
+
|
|
479
|
+
```tsx
|
|
480
|
+
import { useBottomPanel } from "@vetta-org/plugin-sdk";
|
|
481
|
+
|
|
482
|
+
function LogsPanel() {
|
|
483
|
+
const { instanceId, cwd, active, setMeta, setCloseGuard } = useBottomPanel();
|
|
484
|
+
|
|
485
|
+
// 名字与状态点随运行情况变:空闲是灰点,活动是脉冲绿点。
|
|
486
|
+
useEffect(() => {
|
|
487
|
+
setMeta({ label: `logs — ${basename(cwd ?? "")}`, status: running ? "active" : "idle" });
|
|
488
|
+
}, [cwd, running, setMeta]);
|
|
489
|
+
|
|
490
|
+
// 有东西在跑时先让宿主问一句;空闲时把守卫撤掉,免得每次关都弹窗。
|
|
491
|
+
useEffect(() => {
|
|
492
|
+
setCloseGuard(
|
|
493
|
+
running
|
|
494
|
+
? async () => ({ title: "还在跟随日志", message: "关闭会断开跟随。", destructive: true })
|
|
495
|
+
: null,
|
|
496
|
+
);
|
|
497
|
+
}, [running, setCloseGuard]);
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
`setCloseGuard` 的裁决:`true` 直接关、`false` 取消、返回文案则请宿主弹一次确认。允许 async(真实判断常常要问后端)。**3 秒内给不出裁决按「需要确认」处理**,不会静默关掉——丢东西的方向必须是保守的。`reason` 为 `session-switch` / `app-quit` 时仍会调用守卫(给你收尾的机会),但返回值被忽略:退出流程上挂一个能阻塞的对话框会把用户卡住。
|
|
502
|
+
|
|
503
|
+
### 替用户开终端跑命令 openTerminal
|
|
504
|
+
|
|
505
|
+
脚本运行器、任务面板这类插件要让命令跑在真终端里时,不要自己用 `command.spawn` 拼一个输出视图:`useBottomPanel().openTerminal()` 让宿主在**本实例所在的格子**里开一个内置终端,把命令敲进用户的交互式 shell。终端的输入、颜色、进度条重绘、分屏、关闭前确认都由宿主负责,本地项目和 `ssh://` 远程项目都能用。
|
|
506
|
+
|
|
507
|
+
- 权限:`terminal.run`(缺权限**抛错** `Plugin permission denied: terminal.run`),并且面板本身要有 `ui.slot.bottom-panel`
|
|
508
|
+
- 需要 Plugin API `^2.8.0`
|
|
509
|
+
- 返回新终端的 `instanceId`;`revealInstance(instanceId)` 把它切回前台,终端已被用户关掉时返回 `false`,据此决定复用还是新开
|
|
510
|
+
- 命令只在终端**第一次**启动时敲一次。用户重开会话时宿主会恢复终端的布局和上次输出,但起的是新 shell,**不会**再敲一遍命令
|
|
511
|
+
- 命令跑完 shell 还在,用户可以接着按上箭头重跑或自己继续敲
|
|
512
|
+
|
|
513
|
+
```ts
|
|
514
|
+
interface PluginBottomPanelTerminalRequest {
|
|
515
|
+
command: string; // 单行,不能含换行或其他控制字符,最长 4096 字符
|
|
516
|
+
cwd?: string; // 面板 cwd 本身或它下面的目录;省略即面板 cwd
|
|
517
|
+
label?: string; // 终端 tab 的名字;省略按目录名显示
|
|
518
|
+
}
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
```tsx
|
|
522
|
+
function ScriptsPanel() {
|
|
523
|
+
const { cwd, openTerminal, revealInstance } = useBottomPanel();
|
|
524
|
+
const running = useRef(new Map<string, string>()); // 脚本 → 终端 instanceId
|
|
525
|
+
|
|
526
|
+
const run = (script: { key: string; dir: string; command: string }) => {
|
|
527
|
+
const existing = running.current.get(script.key);
|
|
528
|
+
if (existing && revealInstance(existing)) return; // 还开着就切过去,不重复启动 dev server
|
|
529
|
+
running.current.set(script.key, openTerminal({ command: script.command, cwd: script.dir, label: script.key }));
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
以下情况 `openTerminal` 抛错:缺 `terminal.run`;`cwd` 越出面板 `cwd`(或本地、远程混用、不是同一台主机);命令为空、跨行或含控制字符;当前是本地会话而这台机器上没有终端支持。
|
|
535
|
+
|
|
440
536
|
## 输入栏动作 registerInputAction
|
|
441
537
|
|
|
442
538
|
在 AI 输入栏下方加一个**开关型动作按钮**(toggle)。激活时,宿主在每次发送前调用 `decoratePrompt()`,把元数据和插件隐藏指令合并进外发 prompt。
|
|
@@ -448,7 +544,7 @@ ctx.ui.registerInputAction({
|
|
|
448
544
|
interface PluginInputActionContribution {
|
|
449
545
|
id: string;
|
|
450
546
|
label: string;
|
|
451
|
-
icon?: ReactNode;
|
|
547
|
+
icon?: ReactNode; // 省略时用插件自己的图标
|
|
452
548
|
defaultActive?: boolean;
|
|
453
549
|
requiresActiveTool?: string; // 仅当该 agent 工具在本会话激活时显示
|
|
454
550
|
scope_use?: readonly ConversationScenario[];
|