本次一并提交工作区此前累积的改动(均已验证),并接入工具并发调度所需的 声明项。 把「谁来反代谁」从内核硬编码变成插件可声明。设备网关(remotedevice) 这类**编译进内核、没有独立插件目录与 plugin.json** 的服务,静态扫描扫不到, 此前只能靠约定。新增 DeclareProxy 让它们能自己声明反代路由。 ParallelSafe 的**反向**声明项。判据优先级:Serial 胜出,显式声明不允许被 ParallelSafe 或任何默认值覆盖。 为什么需要它:ParallelSafe 零值 false 已表达「安全/串行」,插件无法区分 「我没想过」和「我确认过必须串行」。没有这个区分,工具作者只能靠命名约定 传递意图,那不是契约。 ParallelSafe 本身也补齐了注释,明确其零值语义(默认串行、保守)与理由 (新语义下并发会改变工具的行为前提,让存量插件意外并发比慢一点危险得多)。 配套 ScenePolicy 声明项的使用说明。 remotedevice/ 整目录(C 实现的设备网关,已由 Go 侧 DeclareProxy 路径取代)。 - sdk/knowledge.go:随场面策略配套调整 - docs/api/*、docs/assets/api-index.json、docs/llms.txt、mkdocs.yml: 由 tools/apidoc/build.sh 从源码重新生成(行号随 plugin.go 变动漂移)
4.9 KiB
配置(Settings)
声明插件自己的配置项,内核会把它渲染到 WebUI 的设置页,并为每个插件维护独立的配置表。
SettingsAPI
| 方法 | 说明 |
|---|---|
DataDir |
DataDir returns the plugin-specific data directory (guaranteed to exist): |
Defs |
Defs returns config definitions matching the prefix. |
Dump |
Dump returns all config values. |
Get |
Get reads the plugin's own config value (config_ table). |
GetCore |
GetCore reads the core config table. |
GetPlugin |
GetPlugin reads another plugin's config table. |
List |
List returns all keys matching the given prefix. |
ListCore |
ListCore lists core config keys matching the prefix. |
ListPlugin |
ListPlugin lists another plugin's config keys matching the prefix. |
Plugins |
Plugins returns a list of all plugin config namespaces. |
RegisterDef |
RegisterDef registers a config definition for UI display. |
Set |
Set writes a config value to the plugin's own config table. |
SetCore |
SetCore writes to the core config table. |
SetPlugin |
SetPlugin writes to another plugin's config table. |
SettingsAPI.DataDir
DataDir() string
DataDir returns the plugin-specific data directory (guaranteed to exist): /plugin_data/<plugin_name>. Plugins should persist any runtime files (generated images, caches, downloads) here.
settings.go:25
SettingsAPI.Defs
Defs(prefix string) []*ConfigDef
Defs returns config definitions matching the prefix.
settings.go:40
SettingsAPI.Dump
Dump() map[string]interface{}
Dump returns all config values.
settings.go:43
SettingsAPI.Get
Get(key string) (interface{}, error)
Get reads the plugin's own config value (config_ table).
settings.go:5
SettingsAPI.GetCore
GetCore(key string) (interface{}, error)
GetCore reads the core config table.
settings.go:14
SettingsAPI.GetPlugin
GetPlugin(plugin, key string) (interface{}, error)
GetPlugin reads another plugin's config table.
settings.go:28
SettingsAPI.List
List(prefix string) ([]string, error)
List returns all keys matching the given prefix.
settings.go:11
SettingsAPI.ListCore
ListCore(prefix string) ([]string, error)
ListCore lists core config keys matching the prefix.
settings.go:20
SettingsAPI.ListPlugin
ListPlugin(plugin, prefix string) ([]string, error)
ListPlugin lists another plugin's config keys matching the prefix.
settings.go:34
SettingsAPI.Plugins
Plugins() []string
Plugins returns a list of all plugin config namespaces.
settings.go:46
SettingsAPI.RegisterDef
RegisterDef(def ConfigDef)
RegisterDef registers a config definition for UI display.
settings.go:37
SettingsAPI.Set
Set(key string, value interface{}) error
Set writes a config value to the plugin's own config table.
settings.go:8
SettingsAPI.SetCore
SetCore(key string, value interface{}) error
SetCore writes to the core config table.
settings.go:17
SettingsAPI.SetPlugin
SetPlugin(plugin, key string, value interface{}) error
SetPlugin writes to another plugin's config table.
settings.go:31
ConfigDef
type ConfigDef struct { Key string `json:"key"` Default interface{} `json:"default,omitempty"` Type string `json:"type"` DisplayName string …
ConfigDef describes a configuration field for the WebUI.
settings.go:50
PluginSDK.Settings
func (s *PluginSDK) Settings() SettingsAPI
Settings returns the settings API for reading/writing plugin configuration. sett 在 New 时一次性写入且无 setter,故不需要加锁。
示例插件里的真实用法
| 插件 | 位置 | 代码 |
|---|---|---|
a2a |
example/a2a/plugin.go:68 |
s.Settings().RegisterDef(sdk.ConfigDef{ |
acp |
example/acp/plugin.go:63 |
s.Settings().RegisterDef(sdk.ConfigDef{ |
ai_image |
example/ai_image/plugin.go:114 |
s.Settings().RegisterDef(sdk.ConfigDef{ |
bili |
example/bili/plugin.go:29 |
s.Settings().RegisterDef(sdk.ConfigDef{ |
plugin.go:505