feat: 动态插件系统 M0-M3(两层能力模型 + pi 原生契约 + Obsidian 式 SDK)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 浏览器插件(内置,组件级:UI 仍由宿主树 BrowserPanel 承载,面板 tab 见 App.tsx)。
|
||||
* 主进程侧:browserTools 经 pi.registerTool 注册(原生路径,提示词注入/审批拦截
|
||||
* 与 pi 生态一致),并示范内联 UI——受管浏览器打开时推状态胶囊。
|
||||
*/
|
||||
import { getBrowserController } from '../../browser/browser-controller'
|
||||
import { browserTools } from '../../tools/browser-tools'
|
||||
import type { BuiltinPlugin } from './index'
|
||||
|
||||
export const browserPlugin: BuiltinPlugin = {
|
||||
manifest: {
|
||||
id: 'browser',
|
||||
name: '浏览器',
|
||||
version: '0.1.0',
|
||||
minContract: '0.1.0',
|
||||
panel: true,
|
||||
order: 10,
|
||||
description: '受管浏览器(CDP 驱动,Agent 可操作,右侧面板查看)'
|
||||
},
|
||||
main: (api) => {
|
||||
for (const tool of browserTools) {
|
||||
api.pi.registerTool(tool)
|
||||
}
|
||||
|
||||
const pushStatus = (): void => {
|
||||
const state = getBrowserController().getState()
|
||||
if (!state.open || state.tabs.length === 0) {
|
||||
api.ui.removeStatusItem('tabs')
|
||||
return
|
||||
}
|
||||
const active = state.tabs.find((t) => t.tabId === state.activeTabId)
|
||||
const title = active?.title?.trim()
|
||||
api.ui.setStatusItem('tabs', {
|
||||
text: `浏览器 ${state.tabs.length} 页${title ? ` · ${title.slice(0, 12)}` : ''}`,
|
||||
tone: 'default'
|
||||
})
|
||||
}
|
||||
|
||||
const off = getBrowserController().onState(pushStatus)
|
||||
pushStatus()
|
||||
return () => {
|
||||
off()
|
||||
api.ui.removeStatusItem('tabs')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 内置插件注册表(编译进宿主 bundle 的"特权实现"):
|
||||
* - main:第一方工厂(不走动态 import;pi ExtensionAPI 语义与外置一致)
|
||||
* - component:渲染层组件 key(plugins/builtin-components.ts 里登记的宿主树组件;
|
||||
* 外置插件没有这项能力,遮蔽组件级内置需 manifest.replacesNative 声明)
|
||||
* 浏览器面板(M3)在此登记。
|
||||
*/
|
||||
import type { HarnessPluginFactory, PluginManifest } from '@aso/plugin-sdk'
|
||||
import { browserPlugin } from './browser'
|
||||
|
||||
export interface BuiltinPlugin {
|
||||
manifest: PluginManifest
|
||||
/** 主进程工厂(注册 pi 工具/事件、内联 UI) */
|
||||
main?: HarnessPluginFactory
|
||||
/** 渲染层宿主树组件 key(renderer/src/plugins/builtin-components.ts) */
|
||||
component?: string
|
||||
}
|
||||
|
||||
export const BUILTIN_PLUGINS: BuiltinPlugin[] = [browserPlugin]
|
||||
Reference in New Issue
Block a user