@binblink/wasmnest-plugin-sdk-desktop 0.0.0-stage → 0.0.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 +287 -2
- package/README_en.md +284 -0
- package/bin/cli.js +602 -0
- package/bin/manifest-gen.js +454 -0
- package/bin/manifest-validate.js +432 -0
- package/bin/permission-vocabulary.json +5 -0
- package/bin/plugin-watch.js +331 -0
- package/bin/wasm-hash.js +124 -0
- package/dev-shell/README.md +121 -0
- package/dev-shell/index.html +12 -0
- package/dev-shell/package.json +28 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/components/LogPanel.vue +90 -0
- package/dev-shell/src/loader.ts +109 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales.ts +50 -0
- package/dev-shell/src/main.ts +46 -0
- package/dev-shell/src/mock/agent-hub-commands.ts +1065 -0
- package/dev-shell/src/mock/agent-hub.ts +42 -0
- package/dev-shell/src/mock/app-env.ts +102 -0
- package/dev-shell/src/mock/commands.ts +54 -0
- package/dev-shell/src/mock/domain-context.ts +46 -0
- package/dev-shell/src/mock/events.ts +16 -0
- package/dev-shell/src/mock/file-transfer.ts +512 -0
- package/dev-shell/src/mock/tauri-ipc.ts +109 -0
- package/dev-shell/src/registry.ts +90 -0
- package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
- package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
- package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
- package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
- package/dev-shell/src/shell/mount/appSession.ts +45 -0
- package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
- package/dev-shell/src/shell/types.ts +132 -0
- package/dev-shell/src/styles/dev.css +27 -0
- package/dev-shell/src/styles/shell.css +546 -0
- package/dev-shell/src/styles/style.css +1132 -0
- package/dev-shell/src/theme.ts +140 -0
- package/dev-shell/src/vite-env.d.ts +24 -0
- package/dev-shell/tailwind.config.js +98 -0
- package/dev-shell/vite.config.ts +174 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +170 -0
- package/dist/types.d.ts +585 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +25 -0
- package/dist/vite-plugin.js +80 -0
- package/package.json +89 -3
- package/src/config.ts +49 -0
- package/src/global-dialog.ts +169 -0
- package/src/index.ts +80 -0
- package/src/runtime.ts +54 -0
- package/src/types.ts +630 -0
- package/src/ui/MarkdownEditor.vue +520 -0
- package/src/ui/PluginGlobalDialog.vue +401 -0
- package/src/ui/Select.d.ts +36 -0
- package/src/ui/Select.vue +220 -0
- package/src/ui/TerminalInputRail.vue +184 -0
- package/src/ui/apply-select-position.ts +65 -0
- package/src/ui/markdown-editor-syntax.ts +234 -0
- package/src/ui/markdown-editor.d.ts +36 -0
- package/src/ui/plugin-global-dialog.d.ts +12 -0
- package/src/ui/select-position.ts +79 -0
- package/src/ui/terminal-input-rail.d.ts +30 -0
- package/src/ui/zoom-compensation.d.ts +9 -0
- package/src/ui/zoom-compensation.ts +52 -0
- package/src/vite-plugin.ts +124 -0
- package/template/README.md +39 -0
- package/template/package.json +23 -0
- package/template/plugin.json +14 -0
- package/template/rust/Cargo.toml +21 -0
- package/template/rust/src/lib.rs +39 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
- package/tools/componentize/Cargo.lock +270 -0
- package/tools/componentize/Cargo.toml +15 -0
- package/tools/componentize/src/main.rs +94 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Hub 插件领域 mock(dev-shell 专用,纯通用接线)
|
|
3
|
+
*
|
|
4
|
+
* 浏览器中 Rust WASM 后端不可用,app 经 `env.appInvoke` 发的命令只能由前端
|
|
5
|
+
* mock 顶上。本模块注册 agent-hub 五个领域(探测/安装/Skills/供应商/使用统计)
|
|
6
|
+
* 的命令 handler 骨架(经 `DomainContext` 落到全局命令表),并模拟事件回流
|
|
7
|
+
* (`plugin:agent-hub:*` 全量状态推送,经 Tauri 事件垫片送达 app 的 listen),
|
|
8
|
+
* 使插件在 dev-shell 中展示「有数据」的完整形态:
|
|
9
|
+
* - 探测:detect 逐 CLI 延时推进 detecting → 终态(种子为终态目标)
|
|
10
|
+
* - 安装:run 剧本逐行回显输出、测速/检查更新延时出结果、换源改写 npmrc 状态
|
|
11
|
+
* - Skills:扫描动画、编辑保存(hash 重算 → 分发转 stale)、分发/GitHub 安装/本地导入
|
|
12
|
+
* - 供应商:预设 CRUD、反向导入(种子发现条目)、应用(claude 桥接冲突演示)
|
|
13
|
+
* - 使用统计:扫描 syncing → ok、看板聚合、会话分页、日志详情读取
|
|
14
|
+
*
|
|
15
|
+
* 本模块不包含任何具体业务 mock 数据:全部演示种子由插件工程持有(入口导出
|
|
16
|
+
* devMock:detection / install / skills / providers / usage 五个子域),
|
|
17
|
+
* 注入时按 pluginId 经 getDevMock 取种子驱动命令返回值与事件;未导出对应
|
|
18
|
+
* 子域的插件不受影响(各子域命令不注册)。
|
|
19
|
+
*
|
|
20
|
+
* 2026-10-25:命令实现(种子派生状态 / 安装模拟 / 五域 handler)拆至
|
|
21
|
+
* agent-hub-commands.ts,本文件只做种子查找门面。
|
|
22
|
+
*/
|
|
23
|
+
import { getDevMock } from '../registry'
|
|
24
|
+
import type { DomainContext } from './domain-context'
|
|
25
|
+
import { registerAgentHubMockImpl, type AgentHubSeed } from './agent-hub-commands'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 注册 agent-hub 领域命令 mock(loader 在 activate 前调用)
|
|
29
|
+
*
|
|
30
|
+
* 仅注册种子中存在的子域命令;返回 Disposable 供插件 deactivate 清理定时器
|
|
31
|
+
*/
|
|
32
|
+
export function registerAgentHubMock(context: DomainContext, pluginId: string): {
|
|
33
|
+
dispose(): void
|
|
34
|
+
} {
|
|
35
|
+
// SAFETY: dev-shell 刻意不收录插件包类型(SDK 不依赖插件),种子形状按
|
|
36
|
+
// 插件 devMockTypes.ts 的领域接口本地镜像后 cast——运行期种子字段是这些
|
|
37
|
+
// 接口的超集(额外字段经索引签名透传),cast 只收窄不丢字段
|
|
38
|
+
const seed = getDevMock(pluginId) as unknown as AgentHubSeed | undefined
|
|
39
|
+
if (!seed) return { dispose() {} }
|
|
40
|
+
|
|
41
|
+
return registerAgentHubMockImpl(context, seed)
|
|
42
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock 挂载环境(桌面端 dev-shell)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 构造 `AppMountEnv`(与宿主 `useAppMount.ts` 同形):宿主在真机上注入真命令通道
|
|
5
|
+
* 与真令牌,dev-shell 注入浏览器实现——
|
|
6
|
+
*
|
|
7
|
+
* - `invoke`(宿主面命令):少数几个有浏览器语义(`get_app_settings` 读终端字号、
|
|
8
|
+
* `report_frontend_log` 收前端日志);其余显性失败(Rust 侧不在浏览器)。
|
|
9
|
+
* - `appInvoke`(插件面命令):转交领域 mock 表(`mock/commands.ts`)。
|
|
10
|
+
* - 存储:localStorage 持久化(键前缀 `wasmnest-dev-shell:<appId>:`)。
|
|
11
|
+
* - 事件出口:`navigate` / `route` 转交 dev-shell 壳(前者无宿主路由可跳,只记日志;
|
|
12
|
+
* 后者喂 `appSession` 的页面记忆)。
|
|
13
|
+
*/
|
|
14
|
+
import type { AppMountEnv } from '../shell/types'
|
|
15
|
+
import { dispatchCommand } from './commands'
|
|
16
|
+
import { pushLog } from '../registry'
|
|
17
|
+
|
|
18
|
+
/** 存储键前缀(与旧 dev-shell 一致,切换形态不换键:旧的本地数据不丢) */
|
|
19
|
+
function storageKey(appId: string, key: string): string {
|
|
20
|
+
return `wasmnest-dev-shell:${appId}:${key}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MockEnvOptions {
|
|
24
|
+
/** 应用 id */
|
|
25
|
+
appId: string
|
|
26
|
+
/** 宿主语言(zh-CN / en) */
|
|
27
|
+
locale: string
|
|
28
|
+
/** 宿主主题(light / dark / system) */
|
|
29
|
+
theme: string
|
|
30
|
+
/** 应用初始路由(应用内存路由的落地路径) */
|
|
31
|
+
initialRoute: string
|
|
32
|
+
/** 事件出口转发(壳侧消费) */
|
|
33
|
+
onEvent?: (type: string, payload: unknown) => void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 宿主面命令 mock(Rust 侧不在浏览器,只有有浏览器语义的少数几个) */
|
|
37
|
+
async function invokeHostCommand(
|
|
38
|
+
appId: string,
|
|
39
|
+
command: string,
|
|
40
|
+
args?: Record<string, unknown>,
|
|
41
|
+
): Promise<unknown> {
|
|
42
|
+
switch (command) {
|
|
43
|
+
case 'get_app_settings':
|
|
44
|
+
// 终端窗口初值计算读这两个字段(见 app 侧 predictTerminalSize)
|
|
45
|
+
return { ui: { terminal_font_size: 14, terminal_letter_spacing: 0 } }
|
|
46
|
+
case 'report_frontend_log':
|
|
47
|
+
// 前端日志上报:浏览器里没有上报通道,落到 dev-shell 日志面板即可
|
|
48
|
+
pushLog('debug', appId, `前端日志上报(mock):${JSON.stringify(args?.logs ?? [])}`)
|
|
49
|
+
return undefined
|
|
50
|
+
default:
|
|
51
|
+
pushLog(
|
|
52
|
+
'warn',
|
|
53
|
+
appId,
|
|
54
|
+
`宿主命令 "${command}" 在浏览器不可用(Rust 侧不在 dev-shell 运行),需到真机验证`,
|
|
55
|
+
)
|
|
56
|
+
throw new Error(
|
|
57
|
+
`[dev-shell] 宿主命令 "${command}" 在浏览器不可用,请到真机验证该路径`,
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 构造 mock 挂载环境 */
|
|
63
|
+
export function createMockEnv(options: MockEnvOptions): AppMountEnv {
|
|
64
|
+
const { appId, locale, theme, initialRoute } = options
|
|
65
|
+
return {
|
|
66
|
+
appId,
|
|
67
|
+
mountContract: '1',
|
|
68
|
+
invoke: (command, args) => invokeHostCommand(appId, command, args) as Promise<never>,
|
|
69
|
+
appInvoke: (command, ...args) =>
|
|
70
|
+
dispatchCommand(appId, command, args) as Promise<never>,
|
|
71
|
+
async appStorageGet<T = unknown>(key: string): Promise<T | undefined> {
|
|
72
|
+
try {
|
|
73
|
+
const raw = localStorage.getItem(storageKey(appId, key))
|
|
74
|
+
return raw === null ? undefined : (JSON.parse(raw) as T)
|
|
75
|
+
} catch {
|
|
76
|
+
return undefined
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async appStorageSet(key: string, value: unknown): Promise<void> {
|
|
80
|
+
try {
|
|
81
|
+
localStorage.setItem(storageKey(appId, key), JSON.stringify(value))
|
|
82
|
+
} catch {
|
|
83
|
+
pushLog('warn', appId, `storage.set("${key}") 失败(localStorage 不可用)`)
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
async appStorageDelete(key: string): Promise<void> {
|
|
87
|
+
localStorage.removeItem(storageKey(appId, key))
|
|
88
|
+
},
|
|
89
|
+
locale,
|
|
90
|
+
theme,
|
|
91
|
+
platform: 'desktop',
|
|
92
|
+
initialRoute,
|
|
93
|
+
onEvent: (type, payload) => {
|
|
94
|
+
if (type === 'navigate') {
|
|
95
|
+
// dev-shell 没有宿主路由表可跳(只有一个挂载槽),只记日志说明去向
|
|
96
|
+
pushLog('info', appId, `应用请求宿主导航:${String(payload)}(dev-shell 无宿主路由,忽略)`)
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
options.onEvent?.(type, payload)
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 命令 mock 表(桌面端 dev-shell)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 浏览器里没有 Rust WASM 后端,app 经 `AppMountEnv.appInvoke` 发的插件面命令
|
|
5
|
+
* 必须由前端 mock 顶上,否则 app 首屏就是空态 / 报错——而 dev-shell 的意义正是
|
|
6
|
+
* 「不跑真后端也能调 UI」。
|
|
7
|
+
*
|
|
8
|
+
* 领域 mock(file-transfer / agent-hub)在这里注册命令 handler,种子数据来自
|
|
9
|
+
* app 自己导出的 `devMock`(各 app 持有自己的演示数据,dev-shell 不写死业务内容)。
|
|
10
|
+
*
|
|
11
|
+
* 未注册的命令**显性失败**(reject + warn 日志),不静默返回 undefined:静默
|
|
12
|
+
* undefined 会让 app 以为「后端返回了空」,开发者看不出是哪条命令缺 mock。
|
|
13
|
+
*/
|
|
14
|
+
import { pushLog } from '../registry'
|
|
15
|
+
|
|
16
|
+
/** 命令 handler(参数与 app 侧 `commands.execute(id, ...args)` 一致) */
|
|
17
|
+
export type CommandHandler = (...args: any[]) => unknown
|
|
18
|
+
|
|
19
|
+
const handlers = new Map<string, CommandHandler>()
|
|
20
|
+
|
|
21
|
+
/** 注册命令 mock(重复注册覆盖前者——切 app 时同域 mock 会重新注册) */
|
|
22
|
+
export function registerCommand(id: string, handler: CommandHandler): void {
|
|
23
|
+
handlers.set(id, handler)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 注销一批命令(切 app / 卸载时调用,避免上一 app 的 handler 残留) */
|
|
27
|
+
export function unregisterCommands(ids: Iterable<string>): void {
|
|
28
|
+
for (const id of ids) handlers.delete(id)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 已注册的命令 id(排障用:日志面板可列当前 mock 面) */
|
|
32
|
+
export function registeredCommandIds(): string[] {
|
|
33
|
+
return [...handlers.keys()].sort()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 分发一条插件面命令
|
|
38
|
+
*
|
|
39
|
+
* @throws 未注册的命令 → reject(错误文案点明「浏览器无 WASM 后端」)
|
|
40
|
+
*/
|
|
41
|
+
export async function dispatchCommand(appId: string, id: string, args: unknown[]): Promise<unknown> {
|
|
42
|
+
const handler = handlers.get(id)
|
|
43
|
+
if (!handler) {
|
|
44
|
+
pushLog(
|
|
45
|
+
'warn',
|
|
46
|
+
appId,
|
|
47
|
+
`命令 "${id}" 未注册 mock —— Rust WASM 后端不在浏览器运行;该路径需到真机验证`,
|
|
48
|
+
)
|
|
49
|
+
throw new Error(
|
|
50
|
+
`[dev-shell] 命令 "${id}" 未注册 mock:浏览器无 Rust WASM 后端,请到真机验证该路径`,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
return handler(...args)
|
|
54
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 领域 mock 的接线适配器(dev-shell 内部用)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 领域 mock(file-transfer / agent-hub)此前把命令 handler 注册进 app 的
|
|
5
|
+
* `PluginContext`。挂载包形态下 **app 自己持 context**(宿主注入 env,app 在
|
|
6
|
+
* `entry.ts` 里造 context),dev-shell 触不到它——但领域 mock 仍需要两条通道:
|
|
7
|
+
*
|
|
8
|
+
* - `commands.register(id, handler)` → 全局命令 mock 表;app 经
|
|
9
|
+
* `env.appInvoke(id, …)` 打到这张表(`mock/commands.ts`)。
|
|
10
|
+
* - `events.emit(event, payload)` → Tauri 事件垫片;app 经 `listen()` 收到
|
|
11
|
+
* (`mock/tauri-ipc.ts`),与真机同一条通道。
|
|
12
|
+
*
|
|
13
|
+
* 因此领域 mock 只拿到这个**两通道最小接线对象**,不再拿整个 PluginContext:
|
|
14
|
+
* 领域 mock 触不到 app 的 i18n / storage / terminal / 权限等面——那些面在
|
|
15
|
+
* 挂载包形态下由 app 自行持有或经 env 注入,不该由 dev-shell 插手。
|
|
16
|
+
*/
|
|
17
|
+
import { registerCommand } from './commands'
|
|
18
|
+
import { emitTauriEvent } from './tauri-ipc'
|
|
19
|
+
|
|
20
|
+
/** 领域 mock 用的最小接线面 */
|
|
21
|
+
export interface DomainContext {
|
|
22
|
+
commands: {
|
|
23
|
+
register(id: string, handler: (...args: any[]) => any): { dispose(): void }
|
|
24
|
+
}
|
|
25
|
+
events: {
|
|
26
|
+
emit(event: string, ...args: unknown[]): void
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 造一个领域 mock 接线对象 */
|
|
31
|
+
export function createDomainContext(): DomainContext {
|
|
32
|
+
return {
|
|
33
|
+
commands: {
|
|
34
|
+
register(id: string, handler: (...args: any[]) => any) {
|
|
35
|
+
registerCommand(id, handler)
|
|
36
|
+
return { dispose() {} }
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
events: {
|
|
40
|
+
emit(event: string, ...args: unknown[]): void {
|
|
41
|
+
// 真机上 Rust 侧一次 emit 带一个载荷;这里逐个派发(多载荷时顺序保持)
|
|
42
|
+
for (const payload of args) emitTauriEvent(event, payload)
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dev-shell 事件出口(薄封装)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 领域 mock 推的事件必须走 **app 真正在听的那条通道**——app 的 `context.events.on`
|
|
5
|
+
* 内部调 `@tauri-apps/api/event` 的 `listen()`(Tauri 事件通道),app 自带的
|
|
6
|
+
* 内存总线在 app 包内部、dev-shell 触不到。
|
|
7
|
+
*
|
|
8
|
+
* 因此这里只做一件事:把 dev-shell 侧的事件派发到 Tauri 事件垫片
|
|
9
|
+
* (`mock/tauri-ipc.ts`),app 侧 `listen()` 的回调随即收到。
|
|
10
|
+
*/
|
|
11
|
+
import { emitTauriEvent } from './tauri-ipc'
|
|
12
|
+
|
|
13
|
+
/** 派发一个事件(载荷与真机 Rust 侧 emit 同形:单载荷) */
|
|
14
|
+
export function emitDevEvent(event: string, payload: unknown): void {
|
|
15
|
+
emitTauriEvent(event, payload)
|
|
16
|
+
}
|