Files
inkreach-agent/packages/plugin-template/main.mjs
T

60 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 主进程侧:Agent 能力(pi 工具/命令/事件)+ 设置声明 + 内联 UI。
// 日志规范见 docs/plugins/06-self-diagnosis.md:激活时 info 一条能力清单,一切 catch 记 error。
import { definePlugin } from '@aso/plugin-sdk'
export default definePlugin((api) => {
const log = api.log
log.info('activated', { manifest: api.manifest.version })
// ---- 设置(用户可配置;值为宿主持久化) ----
api.ui.registerSettings({
items: [
{ type: 'string', key: 'greeting', label: '问候语', default: 'Hello', placeholder: 'Hello' },
{ type: 'boolean', key: 'verbose', label: '详细日志', default: false }
]
})
let values = api.ui.getSettingValues()
api.ui.onSettingsChange((next) => {
values = next
log.info('settings changed', { greeting: next.greeting })
})
api.ui.onSettingsAction((key) => {
log.info('settings action', { key })
})
// ---- Agent 工具示例 ----
api.pi.registerTool({
name: 'my_plugin_ping',
description: '返回问候语(示例工具:把这段换成真正的能力)',
parameters: {},
async execute() {
log.debug('ping called', { verbose: values.verbose })
return { output: `${values.greeting ?? 'Hello'} from my-plugin` }
}
})
// ---- 状态胶囊示范:顶栏紧凑状态条,点击展开详情弹层(数据驱动,宿主统一渲染) ----
api.ui.setStatusItem('summary', {
text: '示例 1/2',
tone: 'accent',
detail: {
sections: [
{
rows: [
{ label: '示例任务', detail: '把这段换成真正的状态数据', trailing: '进行中', tone: 'accent' },
{ label: '打开面板', openView: { view: api.manifest.id } }
]
}
]
}
})
// ---- 面板/视图组件在 renderer.mjs(JSX 构建见 README);无 UI 需求可整段去掉 ----
log.info('ready', { hasRenderer: true })
return () => {
log.info('disposed')
}
})