@syncshio/kano-plugin-sdk 0.0.0-stage → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +265 -2
- package/dist/api/contributions.d.ts +140 -0
- package/dist/api/launch-tools.d.ts +136 -0
- package/dist/api/types.d.ts +178 -0
- package/dist/contracts/app-context.d.ts +32 -0
- package/dist/contracts/app-lifecycle.d.ts +119 -0
- package/dist/contracts/app-plugin.d.ts +72 -0
- package/dist/contracts/drop.d.ts +35 -0
- package/dist/contracts/install-recipe.d.ts +140 -0
- package/dist/contracts/launch-pipeline.d.ts +272 -0
- package/dist/contracts/launch.d.ts +137 -0
- package/dist/contracts/model-market.d.ts +112 -0
- package/dist/contracts/models.d.ts +119 -0
- package/dist/contracts/params.d.ts +150 -0
- package/dist/contracts/providers.d.ts +344 -0
- package/dist/contracts/session.d.ts +64 -0
- package/dist/helpers/define-plugin.d.ts +2 -0
- package/dist/helpers/params.d.ts +14 -0
- package/dist/host.d.ts +626 -0
- package/dist/host.js +94 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +629 -0
- package/dist/manifest/plugin-manifest.d.ts +33 -0
- package/dist/manifest/validate.d.ts +12 -0
- package/dist/versions.d.ts +12 -0
- package/package.json +40 -4
- package/src/schemas/plugin-manifest.schema.json +262 -0
package/README.md
CHANGED
|
@@ -1,3 +1,266 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Kano Plugin SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 桌面宿主控件与操作(2.4)
|
|
4
|
+
|
|
5
|
+
插件页面可从 `@syncshio/kano-plugin-sdk/host` 导入 `PageHeader`、`KanoIcon`、`SegmentedControl`、`Drawer` 等共享组件,以及路径、参数和诊断的纯函数。将 `vue` 和 `@syncshio/kano-plugin-sdk/host` 声明为构建 external。应用启停、重启和导航使用 `api.apps`,页签和通知使用 `api.ui`。文件读写、HTTP 请求与启动检查分别由 `api.fs`、`api.http` 和 `api.launch` 提供,并按清单权限或应用归属校验。
|
|
6
|
+
|
|
7
|
+
校订日期:2026-11-23。独立的 Kano 插件 SDK,当前版本 **4.0.0**。包含类型契约、`definePlugin()`、插件清单 schema/验证和宿主版本约束检查;源码不引用 Kano 前端、Electron 或 Go 实现。
|
|
8
|
+
|
|
9
|
+
3.1 新增可最大化的宿主 Dialog、一次性启动选项、节点导入报告及更新前回调。插件通过 `api.fs.mediaFileUrl` 显示当前执行端的图片或视频,通过 `readPngMetadata` 读取 PNG 文本块,在 SSH 工作区通过 `downloadToLocal` 打开本机保存对话框。清单分别声明同名的 `fs.*` 方法权限。使用这些接口的插件应声明 `engines.pluginSdk: "^4.0.0"`。
|
|
10
|
+
|
|
11
|
+
当前支持可配置原生入口:`entry: { type: 'binary', path: { param: 'executable' } }`。关联参数使用 `type: 'path', pathKind: 'file'` 选择文件,可通过 `fileFilters: [{ name: 'GGUF', extensions: ['gguf'] }]` 声明筛选;路径控件默认仍选择目录。入口相对路径从应用目录解析,宿主统一检查文件存在性。
|
|
12
|
+
|
|
13
|
+
版本管理契约使用 `kind: 'git' | 'binary' | 'npm'`。Git provider必须显式声明 `kind: 'git'`。原生软件声明 `BinaryVersionProvider`,npm 软件声明 `NpmVersionProvider`,由宿主提供相应的版本查询与安装页面;配置页按能力显示。
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type { BinaryVersionProvider } from '@syncshio/kano-plugin-sdk'
|
|
17
|
+
|
|
18
|
+
const versionProvider: BinaryVersionProvider = {
|
|
19
|
+
kind: 'binary',
|
|
20
|
+
executableParam: 'executable',
|
|
21
|
+
defaultExecutable: 'server.exe',
|
|
22
|
+
source: { type: 'github', repository: 'owner/project' },
|
|
23
|
+
variants: [
|
|
24
|
+
{
|
|
25
|
+
id: 'cpu',
|
|
26
|
+
label: 'CPU',
|
|
27
|
+
os: 'windows',
|
|
28
|
+
arch: 'amd64',
|
|
29
|
+
executable: 'server.exe',
|
|
30
|
+
archives: [{ name: 'project-{version}-windows-x64.zip', format: 'zip' }]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`archives` 支持多包合并、`zip` / `tar.gz`、`stripComponents`,必须匹配发行附件名称和 SHA-256 digest。宿主在新目录中安装,成功校验文件后原子保存启动路径和 `binaryVersions`;配置保存失败可重试,不覆盖其他启动参数。详细行为见工作区[二进制版本管理](../docs/design/kano-binary-version-management.md)。
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npm ci
|
|
40
|
+
npm run build
|
|
41
|
+
npm run typecheck
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
构建输出 `dist/index.js`(可直接导入的 ESM)与类型声明。Vue 是用于 UI 组件类型的 peer dependency;SDK 不创建 Vue 应用、RPC 连接或全局宿主状态。
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { definePlugin } from '@syncshio/kano-plugin-sdk'
|
|
48
|
+
|
|
49
|
+
export default definePlugin({
|
|
50
|
+
id: 'my-plugin',
|
|
51
|
+
activate(api) {
|
|
52
|
+
const timer = setInterval(() => api.logger.debug('tick'), 1000)
|
|
53
|
+
api.onDispose(() => clearInterval(timer))
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
插件根目录包含 `package.json`、`plugin.json` 和一个可引用相对 chunk、样式、图片或字体的 ESM 入口。清单声明 `manifestVersion: 2`、`engines.kano` 和 `engines.pluginSdk: "^4.0.0"`。将模块依赖打包到分发归档中;Vue 与 SDK 的 host 子路径由客户端提供。
|
|
59
|
+
|
|
60
|
+
清单可直接导入 `@syncshio/kano-plugin-sdk/schemas/plugin-manifest.schema.json`;编程校验使用 `validateRuntimePluginManifest` 和 `validatePluginEngineCompatibility(manifest.engines, { kano, pluginSdk })`。版本范围支持常用 `^`、`~`、比较符、`x` / `*` 和 `||`;市场发布版本为 `major.minor.patch` 稳定版本。
|
|
61
|
+
|
|
62
|
+
资源在 `activate` 中创建,并通过 `onDispose` 或 `deactivate` 释放。顶层模块只声明逻辑;不得启动任务或创建需要清理的资源。宿主会清理通过 SDK 获取的 RPC、session、插件事件等订阅;异步创建的 Vue watcher、定时器和其他自有资源由作者登记。插件与宿主共享 renderer 执行环境,SDK 权限声明不构成恶意代码沙箱。
|
|
63
|
+
|
|
64
|
+
启动策略的 `resolveSelection`、`compile`、`preflight` 与 `executeCheckAction` 最后一个参数为 `PluginApi`。命令、拖入处理、应用操作、导入探测、扩展和模型操作也接收贡献方的 API。将回调收到的 API 传给需要访问资源的模块。
|
|
65
|
+
|
|
66
|
+
启动参数通过 `LaunchProvider.params` 声明。宿主统一解析默认值、校验字段与跨字段规则,再生成 CLI 和环境变量;表单复用同一套值与校验。选择项可以直接声明输出,多值参数可引用其他字段,不需要编写 argv 拼接函数:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import type { LaunchProvider } from '@syncshio/kano-plugin-sdk'
|
|
70
|
+
|
|
71
|
+
const launchProvider: LaunchProvider = {
|
|
72
|
+
entry: { type: 'python', script: 'main.py' },
|
|
73
|
+
params: [
|
|
74
|
+
{
|
|
75
|
+
id: 'cache',
|
|
76
|
+
label: '缓存',
|
|
77
|
+
type: 'select',
|
|
78
|
+
default: 'ram',
|
|
79
|
+
options: [
|
|
80
|
+
{ value: 'off', label: '禁用', cli: '--cache-none' },
|
|
81
|
+
{
|
|
82
|
+
value: 'ram',
|
|
83
|
+
label: 'RAM',
|
|
84
|
+
cli: { arg: '--cache-ram', format: 'values', values: [{ param: 'reserve' }] }
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'reserve',
|
|
90
|
+
label: '预留内存',
|
|
91
|
+
type: 'number',
|
|
92
|
+
default: 0,
|
|
93
|
+
min: 0,
|
|
94
|
+
showWhen: { param: 'cache', equals: 'ram' }
|
|
95
|
+
},
|
|
96
|
+
{ id: 'extra', label: '额外参数', type: 'text', default: '' }
|
|
97
|
+
],
|
|
98
|
+
extraArgs: { param: 'extra', target: 'argv' }
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`CliArgument` 支持 `flag`、`value`、`equals`、`values`、`repeat`,并可配置反向开关、列表分隔、路径解析与可选引用。可选数值用 `optional: true` 和空字符串默认值,显式 `0` 会保留;整数校验使用 `integer: true`,`step` 仅控制输入步长。`rules` 声明跨字段问题及其关联字段,条件为真时报告错误或警告。
|
|
103
|
+
|
|
104
|
+
动态默认函数通过 `ctx.getParam()` 读取其他参数;每个上下文只计算一次,循环引用会报错。`resolveParams` 用于生成引擎等领域规则对有效值的覆盖,不修改保存值;`bindings` 返回结构化 CLI 输出和环境变量。额外参数统一通过 `extraArgs` 转入 argv 或 `{ env: 'COMMANDLINE_ARGS' }`;声明中涉及的 CLI 标志自动归属 Kano,回调与绑定产生的标志用 `ownedArgs` 补充。
|
|
105
|
+
|
|
106
|
+
SDK 提供纯函数 `evaluateParamCondition`、`validateParamValue`、`validateParamRules`、`getManagedCliFlags` 和 `isParamSet`。完整编译流程及边界见工作区[参数编译框架](../docs/design/kano-parameter-compiler.md)。
|
|
107
|
+
|
|
108
|
+
工作区开发采用相邻 `kano/` 与 `kano-plugin-sdk/`,前端通过 `file:../kano-plugin-sdk` 依赖本项目。npm 包名为 `@syncshio/kano-plugin-sdk`。已有第三方插件迁移时,更新包依赖、源码 import 和构建配置中的 external;使用 `/host` 组件的插件需要重新构建并发布,以便新客户端解析宿主模块。
|
|
109
|
+
|
|
110
|
+
从 Kano 工作区统一发布:在 `kano/.env.publish` 填 `NPM_TOKEN`,执行 `npm run release:prepare -- --only sdk` 预演,或 `npm run release:publish -- --only sdk` 正式发布。也可在本独立仓库按标准 npm 流程构建和发布。
|
|
111
|
+
|
|
112
|
+
完整分发设计及插件签名步骤见 Kano 工作区的[插件包与市场](../docs/design/kano-plugin-packages-and-market.md)。npm 发布脚本不负责创建或推送 GitHub 远程仓库。
|
|
113
|
+
|
|
114
|
+
## Python 与原生应用能力
|
|
115
|
+
|
|
116
|
+
Python 启动入口默认检查可选的根 `requirements.txt`。`LaunchProvider.dependencies` 支持静态文件/目录声明、读取已捕获 `LaunchFacts` 的函数或 `false`;宿主在编译后解析,Go 离线检测、需要时使用内置 uv 安装。环境路径由客户端配置或安装结果提供,SDK 不拥有基础 Python 和 venv 文件。
|
|
117
|
+
|
|
118
|
+
原生入口未声明 Python 能力时不显示 Python 管理。Git provider 必须显式声明 `kind: 'git'`;binary provider 使用独立发行包安装和切换,不查询 Git。插件自定义页面、模型市场等能力不要求绑定 Python 应用。
|
|
119
|
+
|
|
120
|
+
工作区内进一步阅读[文档索引](../docs/README.md)和[Hello Plugin](../kano/examples/plugins/hello-plugin/README.md)。这些相邻链接供完整工作区使用;本 SDK 的构建和发布不依赖相邻文档或宿主源码。
|
|
121
|
+
|
|
122
|
+
## Node 与 WebUI 就绪(2.1)
|
|
123
|
+
|
|
124
|
+
Node 入口支持 `entry: { type: "node", script, executable: { param: "nodePath" } }`。省略 executable 时读取 `LaunchFacts.app.configuredNodePath`;宿主不再隐式寻找全局 Node。`LaunchFacts.runtime.node` 提供已探测的 path、version 和 environment,Node PATH 在预检前加入冻结执行快照。
|
|
125
|
+
|
|
126
|
+
`WebViewConfig.getReadyUrlFromLog(content, params)` 可从应用明确的就绪日志返回 HTTP(S) 地址。声明此回调后由插件负责就绪识别,宿主不做匿名 HTTP 探测;适合通过启动令牌登录的应用。回调不要把文档链接或任意日志 URL 当作就绪信号。详见工作区 [Node 环境与 dsh](../docs/design/kano-node-environments.md)。
|
|
127
|
+
|
|
128
|
+
## npm 版本管理(2.2)
|
|
129
|
+
|
|
130
|
+
声明 `versionProvider: { kind: 'npm', packageName: '@scope/app', registry?: 'https://registry.npmjs.org' }`,宿主提供版本查询、标签与 Node engines 展示、升级、降级和重装。`registry` 默认使用官方包源,页面优先使用应用安装记录中的源。
|
|
131
|
+
|
|
132
|
+
安装使用应用所选 Node 及其附带 npm,版本必须明确。npm 原位更新应用依赖,失败可能留下部分修改;宿主只在校验成功后登记。详见工作区 [npm 版本管理](../docs/design/kano-npm-version-management.md)。
|
|
133
|
+
|
|
134
|
+
## 拖入行为(2.3)
|
|
135
|
+
|
|
136
|
+
使用 `api.drops.register({ id, label, scope, accept, matches?, handle })` 注册拖入行为,并声明 `engines.pluginSdk: '^4.0.0'`。`scope: 'app'` 仅在当前插件的应用工作区生效,`'window'` 接受宿主全局拖入。`accept.extensions` 使用带点的扩展名,`mimeTypes` 使用精确 MIME;`handle` 接收 `DropPayload`,文件为本机浏览器 File,可返回 `DropPreview` 让宿主展示 Vue 组件。
|
|
137
|
+
|
|
138
|
+
应用处理器优先;同级多个匹配项让用户选择,不重复处理。返回的订阅可主动 `dispose()`,插件停用时自动清理。WebUI、iframe、输入区域、局部已消费的拖放和宿主内部拖动保留原行为。需要自行管理拖放的宿主 DOM 区域可设置 `data-kano-drop="native"`。完整契约及 ComfyUI 示例见工作区[拖入事件与工作流](../docs/design/kano-drop-workflows.md)。
|
|
139
|
+
|
|
140
|
+
## 插件贡献与生命周期
|
|
141
|
+
|
|
142
|
+
`definePlugin` 接受顶层 `modelMarkets`、`recipes`、`commands`、`slots`、`launchParticipants` 和 `drops`。应用专属页签与操作声明在 `app.tabs` 和 `app.actions`。宿主先注册静态贡献,再调用 `activate(api)`。插件停用、激活失败或切换工作区时,宿主释放该插件注册的资源。
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { definePlugin } from '@syncshio/kano-plugin-sdk'
|
|
146
|
+
import Gallery from './Gallery.vue'
|
|
147
|
+
|
|
148
|
+
export default definePlugin({
|
|
149
|
+
id: 'my-plugin',
|
|
150
|
+
app: {
|
|
151
|
+
tabs: [{ id: 'gallery', label: '图库', icon: 'i-lucide-image', component: Gallery }],
|
|
152
|
+
python: { minVersion: '3.10' },
|
|
153
|
+
async discoverImport(path, api) {
|
|
154
|
+
const file = api.launch.resolvePath(path, 'models.yaml')
|
|
155
|
+
return (await api.fs.exists(file)) ? { initialParams: { modelConfig: file } } : null
|
|
156
|
+
},
|
|
157
|
+
onInstalled({ app, mode, api }) {
|
|
158
|
+
api.logger.info(app.name, mode)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
示例需在清单声明 `permissions.rpc: ["fs.exists"]`。页签组件接收 `app` 与所属插件的 `api`。页签默认仅在所属应用显示,跨应用使用 `filter.pluginIds` 或 `filter.appIds` 指定目标,再用 `visibleWhen(app)` 判断当前状态。默认保留页面实例,可用 `keepAlive: false` 在离开时卸载。动态贡献使用 `api.ui.registerTab(tab)`。
|
|
165
|
+
|
|
166
|
+
`api.ui.switchTab(id)` 在当前应用内切换,`api.apps.openTab(appId, id)` 打开指定应用的页签。宿主内置页签使用 `settings`、`webview` 等完整 ID。插件可用局部 ID 打开自己贡献的页签,在其他插件的工作区中同样有效。使用 `插件ID:局部ID` 可以精确指定插件页签,包括与宿主页签同名的情况。
|
|
167
|
+
|
|
168
|
+
- 应用在 `app.python` 声明版本范围和可选解释器候选路径,在 `launchProvider.dependencies` 声明依赖文件与目录。
|
|
169
|
+
- 导入目录时,`app.identifiers` 声明带权重的目录特征。`app.detect(path, api)` 可用激活插件的 `PluginApi` 探测变体,返回 `true` 额外计一分,也可单独使插件入选。文件操作使用清单中声明的 RPC 权限。
|
|
170
|
+
- `app.discoverImport(path, api)` 可返回名称、运行时路径、启动参数和环境变量,导入向导将结果用作初值。`app.onInstalled` 在登记或保存成功后收到 `install`、`apply` 或 `import` 模式。
|
|
171
|
+
- 静态 `recipes` 或动态 `api.market.registerRecipe(recipe)` 使用 SDK 的 `InstallRecipe`,由 `kind` 决定市场栏目,贡献随插件停用移除。
|
|
172
|
+
- `api.services.provide<T>(id, implementation)` 发布服务。`consume<T>(id)` 取得一个实现,`list<T>(id)` 取得所有实现。`watch<T>(id, onChange)` 在订阅时和提供方变化后将当前列表传给 onChange。订阅 token 支持提前释放。
|
|
173
|
+
- `kano:llm-endpoints` 服务以提供方的插件 ID 作为 `providerId`。`list()` 公开端点 ID、名称、状态、OpenAI 兼容接口地址和密钥要求。端点 ID 在提供方内唯一。消费者在用户选择受保护的端点后,从该实现调用可选的 `getApiKey(endpointId)` 取得凭据,公开端点可省略此方法。
|
|
174
|
+
- `api.tasks.run({ title, cancellable: true }, async (task, signal) => ...)` 将异步操作加入后台任务。执行器可调用 `task.update({ detail, progress, subtitle })` 更新进度,应将 `signal` 传给进行中的操作以响应取消。返回值与错误通过 `run` 的 Promise 交付。
|
|
175
|
+
|
|
176
|
+
第三方插件可直接导入 SDK 的 `InferenceEndpoint` 和 `InferenceEndpointsService`。例如,在打开模型选择器时读取当前运行的端点:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
import type {
|
|
180
|
+
InferenceEndpoint,
|
|
181
|
+
InferenceEndpointsService,
|
|
182
|
+
PluginApi
|
|
183
|
+
} from '@syncshio/kano-plugin-sdk'
|
|
184
|
+
|
|
185
|
+
function runningEndpoints(api: PluginApi): InferenceEndpoint[] {
|
|
186
|
+
const services = api.services.list<InferenceEndpointsService>('kano:llm-endpoints')
|
|
187
|
+
return services.flatMap((service) =>
|
|
188
|
+
service.list().filter((endpoint) => endpoint.status === 'running')
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## 动态接口
|
|
194
|
+
|
|
195
|
+
- `api.apps.start/stop/restart(appId)` 执行应用操作。`api.ui.openDirectory/openFile` 选择当前执行服务器上的路径,`api.ui.toast.success(message)` 显示操作反馈。
|
|
196
|
+
- `await api.ui.confirm('继续安装?')` 打开宿主确认框。也可传入 `{ message, title?, confirmText?, cancelText?, type? }`,其中 `type` 可选 `info`、`warning` 或 `danger`。用户确认时返回 `true`,取消或请求所属的应用、插件、工作区被释放时返回 `false`。
|
|
197
|
+
- 模型市场的搜索、详情与下载解析通过 `context.api` 访问贡献插件的 API。附带平台凭据的请求使用 `context.http`,遵循该市场在清单中声明的来源范围。
|
|
198
|
+
- `api.models.list(appId)` 读取模型库,`api.models.openMarket(search, appId?, categoryId?)` 打开市场。`api.extensions.toggle(appId, id, enabled)` 切换扩展,`api.extensions.installBatch(appId, packages, onProgress?)` 为所属应用安装扩展。
|
|
199
|
+
- `api.downloads.enqueue({ url, directory, filename?, appId? })` 将文件加入下载队列并返回任务 ID。`api.downloads.list()` 读取任务快照,`api.downloads.observe(onChange)` 在订阅时和列表变化后交付快照。在 Vue 作用域中调用 `downloads.observe` 或 `services.watch`,组件卸载时会自动释放订阅。在组件外注册时,订阅随其 API 所属的应用、插件或工作区释放,也可以调用 token 的 `dispose()` 提前结束。
|
|
200
|
+
- `api.apps.list()` 返回本插件的完整只读应用实例。传入其他插件 ID 时,每个实例仅公开 `id`、`name`、`pluginId`、`status`、`webUrl`、`icon` 和 `color`。公开的 HTTP(S) 地址只保留源和路径。`getParams`、`setParam` 和 `getRuntime` 使用所属应用 ID,在激活回调中也可用。
|
|
201
|
+
- `api.launch.registerParticipant` 注册有序启动钩子,涵盖事实采集、编译、环境准备、预检、提交前处理、日志和就绪。拦截其他插件或全局应用需声明 `permissions.launchPipeline`。启动事件携带本次 `runId` 和递增 `seq`。
|
|
202
|
+
- `api.commands.register`、`api.apps.registerAction` 和 `api.ui.registerSlot` 分别贡献命令、应用动作及概览或工作区面板组件。贡献随停用撤销。
|
|
203
|
+
- 清单的 `settings` 声明 JSON 参数定义。使用 `api.settings.get/getAll/set/onChange` 获取默认值、读取或保存设置、订阅变更。已安装插件的设置可在市场操作栏打开。
|
|
204
|
+
|
|
205
|
+
例如,一个插件可为自己的实例提供启动日志、概览面板和参数操作。清单中的设置片段如下。字段支持布尔、文本、数字、端口、选择与路径等表单类型,可填写静态 `default`、`options` 和适用的范围约束。
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"settings": [{ "id": "logLaunch", "label": "记录启动", "type": "boolean", "default": false }]
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
清单直接授予访问这些设置键的权限。普通 `api.storage` 另行声明 `permissions.storage`。市场设置对话框一次保存所有已编辑且可见的字段,成功后 `onChange` 接收整份设置快照。下面的注册写在插件的 `activate(api)` 里,`StatusPanel` 是插件自己的 Vue 组件,其 props 接收 `app` 和操作所属插件的 `api`。
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
const owner = api.meta.getPluginId()
|
|
217
|
+
api.launch.registerParticipant({
|
|
218
|
+
id: 'record-launch',
|
|
219
|
+
filter: { pluginIds: [owner] },
|
|
220
|
+
async beforeSpawn(ctx) {
|
|
221
|
+
if (await api.settings.get<boolean>('logLaunch')) ctx.log(owner, '正在提交进程')
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
api.commands.register({
|
|
225
|
+
id: 'show-count',
|
|
226
|
+
label: '显示应用数量',
|
|
227
|
+
icon: 'i-lucide-list',
|
|
228
|
+
run: () => api.ui.toast.info(`共有 ${api.apps.list().length} 个应用`)
|
|
229
|
+
})
|
|
230
|
+
api.apps.registerAction({
|
|
231
|
+
id: 'show-status',
|
|
232
|
+
label: '查看运行状态',
|
|
233
|
+
icon: 'i-lucide-activity',
|
|
234
|
+
placements: ['quick-action', 'context-menu'],
|
|
235
|
+
run: (app, api) => api.ui.toast.info(api.apps.getRuntime(app.id).status)
|
|
236
|
+
})
|
|
237
|
+
api.ui.registerSlot({
|
|
238
|
+
id: 'status',
|
|
239
|
+
slot: 'app:overview:sections',
|
|
240
|
+
component: StatusPanel,
|
|
241
|
+
visibleWhen: ({ app }) => app?.pluginId === owner
|
|
242
|
+
})
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
`app:overview:header-actions` 提供概览页头动作,`app:overview:sections` 提供概览区块,`workbench:panel` 提供工作区面板。宿主为应用内插槽传入绑定当前应用的 API,因此可调用 `api.ui.switchTab()`。全局插槽取得插件的根 API。插件注册的 `id` 归属当前插件,返回的 token 可提前 `dispose()`。插件入口可直接写 `import('./panels/status.mjs')` 或 `new URL('./icons/status.svg', import.meta.url)`。将相对文件放入分发包,Electron 按当前工作区和版本解析。
|
|
246
|
+
|
|
247
|
+
### 应用动作与独立页面
|
|
248
|
+
|
|
249
|
+
`app.actions` 默认显示在本插件应用的概览快速操作区。`placements` 可包含 `quick-action`、`context-menu` 和 `header`。跨插件动作通过 `filter(app)` 选择目标。跳转使用 `kind: 'tab' | 'folder' | 'url'` 和 `target`,自定义动作用 `run(app, api)`。文件夹目标相对于应用目录,清单的 `permissions.shell` 需含 `showItemInFolder`。网址目标需含 `openExternal`。
|
|
250
|
+
|
|
251
|
+
独立页面接收根 `api` prop。使用 `entry: 'tools'` 将页面放在主页的「工具」区,使用 `entry: 'sidebar'` 在应用侧边栏提供一级入口。两种页面都可通过命令面板搜索。也可调用 `api.ui.registerPage(page)` 动态注册,调用 `await api.ui.openPage('library')` 打开本插件注册的页面。页面 ID 禁用 `/` 和 `:`。插件停用后页面卸载,导航入口随之移除。
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
export default definePlugin({
|
|
255
|
+
id: 'prompt-library',
|
|
256
|
+
pages: [
|
|
257
|
+
{
|
|
258
|
+
id: 'library',
|
|
259
|
+
label: '提示词库',
|
|
260
|
+
icon: 'i-lucide-book-open',
|
|
261
|
+
component: PromptLibrary,
|
|
262
|
+
entry: 'tools'
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
})
|
|
266
|
+
```
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { Component } from 'vue';
|
|
2
|
+
import type { AppInstance, AppStatus, PublicAppInstance } from '../contracts/app-context';
|
|
3
|
+
import type { PluginLaunchTools } from './launch-tools';
|
|
4
|
+
import type { PluginLaunchParticipant } from '../contracts/launch-pipeline';
|
|
5
|
+
import type { LaunchSessionState } from '../contracts/session';
|
|
6
|
+
import type { PluginApi, PluginSubscriptionToken } from './types';
|
|
7
|
+
export interface PluginWorkspaceTab {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
icon: string;
|
|
11
|
+
order?: number;
|
|
12
|
+
component: Component;
|
|
13
|
+
keepAlive?: boolean;
|
|
14
|
+
/** Defaults to workspaces owned by the contributing plugin. */
|
|
15
|
+
filter?: {
|
|
16
|
+
pluginIds?: string[];
|
|
17
|
+
appIds?: string[];
|
|
18
|
+
};
|
|
19
|
+
visibleWhen?(app: AppInstance | PublicAppInstance): boolean;
|
|
20
|
+
}
|
|
21
|
+
/** A configured OpenAI-compatible endpoint on the active execution server. */
|
|
22
|
+
export interface InferenceEndpoint {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
status: AppStatus;
|
|
26
|
+
baseURL: string;
|
|
27
|
+
requiresApiKey: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** The public contract of the 'kano:llm-endpoints' service. */
|
|
30
|
+
export interface InferenceEndpointsService {
|
|
31
|
+
/** Stable owning plugin ID. Endpoint IDs are local to this provider. */
|
|
32
|
+
readonly providerId: string;
|
|
33
|
+
list(): readonly InferenceEndpoint[];
|
|
34
|
+
getApiKey?(endpointId: string): string | undefined | Promise<string | undefined>;
|
|
35
|
+
}
|
|
36
|
+
/** Model directories explicitly offered to other plugins on this execution server. */
|
|
37
|
+
export interface SharedModelDirectoriesService {
|
|
38
|
+
list(): readonly {
|
|
39
|
+
appId: string;
|
|
40
|
+
name: string;
|
|
41
|
+
path: string;
|
|
42
|
+
layout: 'sd-webui' | 'comfyui';
|
|
43
|
+
}[];
|
|
44
|
+
}
|
|
45
|
+
export interface PluginServicesApi {
|
|
46
|
+
/** Calls onChange immediately, then whenever the providers for this ID change. */
|
|
47
|
+
watch<T extends object>(serviceId: string, onChange: (services: readonly T[]) => void): PluginSubscriptionToken;
|
|
48
|
+
provide<T extends object>(serviceId: string, implementation: T): PluginSubscriptionToken;
|
|
49
|
+
consume<T extends object>(serviceId: string): T | undefined;
|
|
50
|
+
list<T extends object>(serviceId: string): readonly T[];
|
|
51
|
+
}
|
|
52
|
+
export interface PluginTaskHandle {
|
|
53
|
+
update(patch: {
|
|
54
|
+
detail?: string;
|
|
55
|
+
progress?: number;
|
|
56
|
+
subtitle?: string;
|
|
57
|
+
}): void;
|
|
58
|
+
}
|
|
59
|
+
export interface PluginTasksApi {
|
|
60
|
+
run<T>(options: {
|
|
61
|
+
title: string;
|
|
62
|
+
subtitle?: string;
|
|
63
|
+
icon?: string;
|
|
64
|
+
cancellable?: boolean;
|
|
65
|
+
}, executor: (task: PluginTaskHandle, signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
66
|
+
}
|
|
67
|
+
export interface PluginCommand {
|
|
68
|
+
id: string;
|
|
69
|
+
label: string;
|
|
70
|
+
icon: string;
|
|
71
|
+
keywords?: string[];
|
|
72
|
+
shortcut?: string;
|
|
73
|
+
run(api: PluginApi): void | Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
export interface PluginPage {
|
|
76
|
+
id: string;
|
|
77
|
+
label: string;
|
|
78
|
+
icon: string;
|
|
79
|
+
entry: 'sidebar' | 'tools';
|
|
80
|
+
component: Component;
|
|
81
|
+
}
|
|
82
|
+
export type AppActionPlacement = 'context-menu' | 'quick-action' | 'header';
|
|
83
|
+
export type PluginAppAction = {
|
|
84
|
+
id: string;
|
|
85
|
+
label: string;
|
|
86
|
+
icon: string;
|
|
87
|
+
description?: string;
|
|
88
|
+
order?: number;
|
|
89
|
+
/** Defaults to the overview's quick actions. */
|
|
90
|
+
placements?: readonly AppActionPlacement[];
|
|
91
|
+
/** Defaults to applications owned by the contributor. */
|
|
92
|
+
filter?(app: AppInstance | PublicAppInstance): boolean;
|
|
93
|
+
} & ({
|
|
94
|
+
kind: 'tab' | 'folder' | 'url';
|
|
95
|
+
target: string;
|
|
96
|
+
run?: never;
|
|
97
|
+
} | {
|
|
98
|
+
kind?: never;
|
|
99
|
+
target?: never;
|
|
100
|
+
run(app: AppInstance | PublicAppInstance, api: PluginApi): void | Promise<void>;
|
|
101
|
+
});
|
|
102
|
+
export type PluginUiSlotId = 'titlebar:status' | 'app:models:settings' | 'app:maintenance' | 'app:overview:header-actions' | 'app:overview:sections' | 'workbench:panel';
|
|
103
|
+
export interface PluginUiSlot {
|
|
104
|
+
id: string;
|
|
105
|
+
slot: PluginUiSlotId;
|
|
106
|
+
label?: string;
|
|
107
|
+
icon?: string;
|
|
108
|
+
order?: number;
|
|
109
|
+
component: Component;
|
|
110
|
+
visibleWhen?(context: {
|
|
111
|
+
app?: AppInstance | PublicAppInstance;
|
|
112
|
+
}): boolean;
|
|
113
|
+
}
|
|
114
|
+
export interface PluginSettingsApi {
|
|
115
|
+
get<T = unknown>(key: string): Promise<T>;
|
|
116
|
+
getAll(): Promise<Record<string, unknown>>;
|
|
117
|
+
set(key: string, value: unknown): Promise<void>;
|
|
118
|
+
onChange(handler: (settings: Record<string, unknown>) => void): PluginSubscriptionToken;
|
|
119
|
+
}
|
|
120
|
+
export interface PluginContributionApi {
|
|
121
|
+
commands: {
|
|
122
|
+
register(command: PluginCommand): PluginSubscriptionToken;
|
|
123
|
+
};
|
|
124
|
+
launch: PluginLaunchTools & {
|
|
125
|
+
registerParticipant(participant: PluginLaunchParticipant): PluginSubscriptionToken;
|
|
126
|
+
};
|
|
127
|
+
apps: {
|
|
128
|
+
start(appId: string): Promise<void>;
|
|
129
|
+
stop(appId: string): Promise<void>;
|
|
130
|
+
restart(appId: string): Promise<void>;
|
|
131
|
+
openTab(appId: string, target: string): Promise<void>;
|
|
132
|
+
list(): readonly AppInstance[];
|
|
133
|
+
list(pluginId: string): readonly PublicAppInstance[];
|
|
134
|
+
getParams(appId: string): Record<string, unknown>;
|
|
135
|
+
setParam(appId: string, key: string, value: unknown): Promise<void>;
|
|
136
|
+
getRuntime(appId: string): LaunchSessionState;
|
|
137
|
+
registerAction(action: PluginAppAction): PluginSubscriptionToken;
|
|
138
|
+
};
|
|
139
|
+
settings: PluginSettingsApi;
|
|
140
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { AppContext } from '../contracts/app-context';
|
|
2
|
+
import type { LaunchRuleContext } from '../contracts/launch';
|
|
3
|
+
import type { LaunchFacts, LaunchRuntimeFacts, LaunchCompilationResult, LaunchCheckResult, LaunchSelection, LaunchResolvedBackendCandidate } from '../contracts/launch-pipeline';
|
|
4
|
+
import type { LaunchProvider, ExtensionConfig, ExtensionInfo, ExtensionToggleResult, ExtensionMarketItem } from '../contracts/providers';
|
|
5
|
+
interface FsEntry {
|
|
6
|
+
name: string;
|
|
7
|
+
is_dir: boolean;
|
|
8
|
+
size: number;
|
|
9
|
+
mod_time?: string;
|
|
10
|
+
}
|
|
11
|
+
interface FsStat {
|
|
12
|
+
size: number;
|
|
13
|
+
is_dir: boolean;
|
|
14
|
+
mod_time: string;
|
|
15
|
+
}
|
|
16
|
+
interface HttpResponse {
|
|
17
|
+
status_code: number;
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
body: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PythonProbeResult {
|
|
22
|
+
probe: string;
|
|
23
|
+
success: boolean;
|
|
24
|
+
details?: Record<string, unknown>;
|
|
25
|
+
stdout?: string;
|
|
26
|
+
stderr?: string;
|
|
27
|
+
error?: string;
|
|
28
|
+
duration_ms: number;
|
|
29
|
+
}
|
|
30
|
+
interface FsTextFile {
|
|
31
|
+
content: string;
|
|
32
|
+
version: string;
|
|
33
|
+
}
|
|
34
|
+
interface RequestOptions {
|
|
35
|
+
headers?: Record<string, string>;
|
|
36
|
+
timeout?: number;
|
|
37
|
+
no_redirect?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface HttpStreamOptions {
|
|
40
|
+
url: string;
|
|
41
|
+
method?: 'GET' | 'POST';
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
body?: string;
|
|
44
|
+
/** Overall deadline in seconds, including inference. Defaults to ten minutes. */
|
|
45
|
+
timeout?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface ExtensionBatchResult {
|
|
48
|
+
installed: ExtensionInfo[];
|
|
49
|
+
failures: Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
error: string;
|
|
52
|
+
}>;
|
|
53
|
+
dependenciesError?: string;
|
|
54
|
+
}
|
|
55
|
+
interface LaunchParamBuildResult {
|
|
56
|
+
args: string[];
|
|
57
|
+
env: Record<string, string>;
|
|
58
|
+
warnings: string[];
|
|
59
|
+
}
|
|
60
|
+
interface LaunchProviderCompileState {
|
|
61
|
+
ctx: LaunchRuleContext;
|
|
62
|
+
build: LaunchParamBuildResult;
|
|
63
|
+
}
|
|
64
|
+
export interface LaunchHelpers {
|
|
65
|
+
resolvePath(base: string, path: string): string;
|
|
66
|
+
isWindowsPlatform(platform?: string): boolean;
|
|
67
|
+
selectLaunchCapability(facts: Pick<LaunchFacts, 'capabilities' | 'selection'>, selection?: LaunchSelection): LaunchResolvedBackendCandidate | undefined;
|
|
68
|
+
parseShellArgs(input: string): {
|
|
69
|
+
args: string[];
|
|
70
|
+
error?: string;
|
|
71
|
+
};
|
|
72
|
+
getRuntimePackageVersion(runtime: LaunchRuntimeFacts, ...names: string[]): string | undefined;
|
|
73
|
+
getPythonProbeDetails(probe?: PythonProbeResult): Record<string, unknown> | undefined;
|
|
74
|
+
buildLocalWebviewUrl(options: {
|
|
75
|
+
host?: unknown;
|
|
76
|
+
port?: unknown;
|
|
77
|
+
defaultHost?: string;
|
|
78
|
+
defaultPort: number;
|
|
79
|
+
}): string;
|
|
80
|
+
createLaunchCheck(id: string, stage: LaunchCheckResult['stage'], passed: boolean, severity: LaunchCheckResult['severity'], message: string, suggestion?: string, actions?: LaunchCheckResult['actions']): LaunchCheckResult;
|
|
81
|
+
}
|
|
82
|
+
export interface PluginFsApi {
|
|
83
|
+
mediaFileUrl(path: string, modified?: string): string;
|
|
84
|
+
readPngMetadata(path: string, modified?: string, signal?: AbortSignal): Promise<Record<string, string>>;
|
|
85
|
+
downloadToLocal(path: string): Promise<string | null>;
|
|
86
|
+
trash(path: string): Promise<void>;
|
|
87
|
+
createFile(path: string): Promise<void>;
|
|
88
|
+
readTextFile(path: string): Promise<FsTextFile>;
|
|
89
|
+
saveTextFile(path: string, content: string, expectedVersion: string): Promise<FsTextFile>;
|
|
90
|
+
listDir(path: string): Promise<FsEntry[]>;
|
|
91
|
+
exists(path: string): Promise<boolean>;
|
|
92
|
+
isDir(path: string): Promise<boolean>;
|
|
93
|
+
stat(path: string): Promise<FsStat>;
|
|
94
|
+
removeOldBinary(appId: string, path: string, executable: string, current: string): Promise<void>;
|
|
95
|
+
removeDir(path: string): Promise<void>;
|
|
96
|
+
removeFile(path: string): Promise<void>;
|
|
97
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
98
|
+
mkdir(path: string): Promise<void>;
|
|
99
|
+
readFile(path: string): Promise<string>;
|
|
100
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
101
|
+
fileContains(path: string, pattern: string, useRegex?: boolean): Promise<boolean>;
|
|
102
|
+
}
|
|
103
|
+
export interface PluginHttpApi {
|
|
104
|
+
get(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
105
|
+
postJson(url: string, body: unknown, options?: RequestOptions): Promise<HttpResponse>;
|
|
106
|
+
getJson<T = unknown>(url: string): Promise<T>;
|
|
107
|
+
stream(options: HttpStreamOptions, onData: (data: string) => void, signal?: AbortSignal): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
export interface PluginLaunchTools extends LaunchHelpers {
|
|
110
|
+
compileLaunchProvider(facts: LaunchFacts, provider: LaunchProvider, customize?: (state: LaunchProviderCompileState) => LaunchParamBuildResult | Promise<LaunchParamBuildResult>): Promise<LaunchCompilationResult>;
|
|
111
|
+
runRuntimeProbe(facts: LaunchFacts, probe: string, options?: {
|
|
112
|
+
refresh?: boolean;
|
|
113
|
+
timeoutMs?: number;
|
|
114
|
+
}): Promise<PythonProbeResult | undefined>;
|
|
115
|
+
checkDuplicateExtensions(facts: LaunchFacts, relativeDir?: string): Promise<LaunchCheckResult[]>;
|
|
116
|
+
checkVCRuntime(id?: string): Promise<LaunchCheckResult[]>;
|
|
117
|
+
checkHttpPort(port: number, id?: string, host?: string, paramId?: string, protocol?: 'http' | 'https'): Promise<LaunchCheckResult[]>;
|
|
118
|
+
checkPaths(requirements: Array<{
|
|
119
|
+
id: string;
|
|
120
|
+
paths: string[];
|
|
121
|
+
stage?: LaunchCheckResult['stage'];
|
|
122
|
+
successMessage: string;
|
|
123
|
+
failureMessage: string;
|
|
124
|
+
suggestion?: string;
|
|
125
|
+
actions?: LaunchCheckResult['actions'];
|
|
126
|
+
}>): Promise<LaunchCheckResult[]>;
|
|
127
|
+
}
|
|
128
|
+
export interface PluginExtensionsApi {
|
|
129
|
+
toggle(appId: string, extensionId: string, enabled: boolean): Promise<void>;
|
|
130
|
+
defaultScan(ctx: AppContext, config: ExtensionConfig, options?: {
|
|
131
|
+
strict?: boolean;
|
|
132
|
+
}): Promise<ExtensionInfo[]>;
|
|
133
|
+
defaultToggle(ctx: AppContext, config: ExtensionConfig, extensionId: string, enabled: boolean): Promise<ExtensionToggleResult>;
|
|
134
|
+
installBatch(appId: string, packages: ExtensionMarketItem[], onProgress?: (text: string) => void): Promise<ExtensionBatchResult>;
|
|
135
|
+
}
|
|
136
|
+
export {};
|