mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-04 00:03:59 +00:00
refactor: centralize ABI metadata into internal/meta/meta.go
- internal/meta/meta.go: add ABIVersion, ABIVersionMin, 45 dispatch
method IDs, SDKCompatibleVersion (single source of truth)
- internal/plugin/cabi/types.go: re-export from meta.go
- internal/plugin/cabi/loader.go: reject plugin when version > ABIVersion;
pass ABIVersion in Start instead of hardcoded 1
- loader.{go,c}: comments reference meta.go as canonical
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
// Package meta 收集 HomeAgent 内核的全部元数据。
|
// Package meta 收集 HomeAgent 内核的全部元数据。
|
||||||
// 版本号通过 `go build -ldflags` 注入,默认值为 dev 版本。
|
// 版本号通过 `go build -ldflags` 注入,默认值为 dev 版本。
|
||||||
|
// 此文件是 ABI 版本号与 dispatch method ID 的唯一数据源。
|
||||||
|
// SDK 仓的 meta/meta.go 应与此保持同步。
|
||||||
package meta
|
package meta
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -15,9 +17,70 @@ var (
|
|||||||
|
|
||||||
// KernelName 是内核名称。
|
// KernelName 是内核名称。
|
||||||
KernelName = "HomeAgent"
|
KernelName = "HomeAgent"
|
||||||
|
|
||||||
|
// SDKCompatibleVersion 是此内核兼容的最低 SDK 版本(semver)。
|
||||||
|
SDKCompatibleVersion = "0.8.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FullVersion 返回完整的版本字符串。
|
// FullVersion 返回完整的版本字符串。
|
||||||
func FullVersion() string {
|
func FullVersion() string {
|
||||||
return KernelName + " v" + Version + " (" + Commit + ")"
|
return KernelName + " v" + Version + " (" + Commit + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- ABI 版本(C ABI 协议版本,插件与内核通信用) ----
|
||||||
|
|
||||||
|
const (
|
||||||
|
ABIVersion = 1
|
||||||
|
ABIVersionMin = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
// ---- Dispatch Method IDs ----
|
||||||
|
// 核心→插件:这些 ID 通过 CoreAPI.dispatch 传递,标识 SDK 调用。
|
||||||
|
// 插件端的 C enum 定义在 plugindev 的 C ABI header 模板中。
|
||||||
|
const (
|
||||||
|
CoreRegisterTool = 1
|
||||||
|
CoreRegisterStage = 2
|
||||||
|
CoreRegisterOutputCh = 3
|
||||||
|
CoreRegisterPluginAPI = 4
|
||||||
|
CoreInjectText = 5
|
||||||
|
CoreInjectInterruptText = 6
|
||||||
|
CoreInjectTextNoMemory = 7
|
||||||
|
CoreSetAutoRestart = 8
|
||||||
|
CoreMemoryRecall = 9
|
||||||
|
CoreMemoryCommit = 10
|
||||||
|
CoreMemoryIntrospect = 11
|
||||||
|
CoreMemoryMerge = 12
|
||||||
|
CoreMemoryPurge = 13
|
||||||
|
CoreDocQuery = 14
|
||||||
|
CoreKnowledgeSearch = 15
|
||||||
|
CoreSettingsGet = 16
|
||||||
|
CoreSettingsSet = 17
|
||||||
|
CoreSettingsRegisterDef = 18
|
||||||
|
CoreLLMListSources = 19
|
||||||
|
CoreLLMSetSource = 20
|
||||||
|
CoreSocialGetPerson = 21
|
||||||
|
CoreSocialGetNetwork = 22
|
||||||
|
CoreSubscribe = 23
|
||||||
|
CoreUnsubscribe = 24
|
||||||
|
CoreFreeString = 25
|
||||||
|
CoreSettingsGetCore = 26
|
||||||
|
CoreSettingsSetCore = 27
|
||||||
|
CoreSettingsListCore = 28
|
||||||
|
CoreSettingsGetPlugin = 29
|
||||||
|
CoreSettingsSetPlugin = 30
|
||||||
|
CoreSettingsListPlugin = 31
|
||||||
|
CoreDocInsert = 32
|
||||||
|
CoreDocRemove = 33
|
||||||
|
CoreDocStats = 34
|
||||||
|
CoreKnowledgeAdd = 35
|
||||||
|
CoreKnowledgeList = 36
|
||||||
|
CoreLLMCurrentSource = 37
|
||||||
|
CoreSocialGetTrait = 38
|
||||||
|
CoreSocialGetRelations = 39
|
||||||
|
CoreSocialListPersons = 40
|
||||||
|
CoreTextMemoryAppend = 41
|
||||||
|
CoreSettingsList = 42
|
||||||
|
CoreSettingsDefs = 43
|
||||||
|
CoreSettingsDump = 44
|
||||||
|
CoreSettingsPlugins = 45
|
||||||
|
)
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
// HOMEAGENT_ABI_VERSION 与 internal/meta/meta.go ABIVersion 同步。
|
||||||
|
// C ABI 通过 version/version_min 协商,旧插件不受影响。
|
||||||
#define HOMEAGENT_ABI_VERSION 1
|
#define HOMEAGENT_ABI_VERSION 1
|
||||||
|
|
||||||
// PluginAPI — provided by the plugin
|
// PluginAPI — provided by the plugin
|
||||||
|
|||||||
@ -6,6 +6,8 @@ package cabi
|
|||||||
#cgo LDFLAGS: -ldl
|
#cgo LDFLAGS: -ldl
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// HOMEAGENT_ABI_VERSION 是当前内核的 ABI 版本号,与 internal/meta/meta.go ABIVersion 保持同步。
|
||||||
|
// 旧插件使用低版本 ABI 不受影响——C ABI wrapper 通过 version/version_min 字段协商兼容。
|
||||||
#define HOMEAGENT_ABI_VERSION 1
|
#define HOMEAGENT_ABI_VERSION 1
|
||||||
|
|
||||||
// PluginAPI — provided by the plugin via plugin_init()
|
// PluginAPI — provided by the plugin via plugin_init()
|
||||||
@ -94,6 +96,10 @@ func Load(soPath, name string, config map[string]interface{}) (*Handle, error) {
|
|||||||
C.lib_close(lib)
|
C.lib_close(lib)
|
||||||
return nil, fmt.Errorf("plugin %s: invalid PluginAPI (version=%d)", name, int(api.version))
|
return nil, fmt.Errorf("plugin %s: invalid PluginAPI (version=%d)", name, int(api.version))
|
||||||
}
|
}
|
||||||
|
if int(api.version) > ABIVersion {
|
||||||
|
C.lib_close(lib)
|
||||||
|
return nil, fmt.Errorf("plugin %s: ABI version %d > core %d, requires newer HomeAgent core", name, int(api.version), ABIVersion)
|
||||||
|
}
|
||||||
|
|
||||||
id := atomic.AddInt32(&nextID, 1)
|
id := atomic.AddInt32(&nextID, 1)
|
||||||
ps := &pluginState{id: id, name: name, api: api}
|
ps := &pluginState{id: id, name: name, api: api}
|
||||||
@ -146,7 +152,7 @@ func (h *Handle) FreeCoreAPI() {
|
|||||||
// Start calls the plugin's Start with a CoreAPI pointer.
|
// Start calls the plugin's Start with a CoreAPI pointer.
|
||||||
func (h *Handle) Start(corePtr unsafe.Pointer) error {
|
func (h *Handle) Start(corePtr unsafe.Pointer) error {
|
||||||
var cErr *C.char
|
var cErr *C.char
|
||||||
if ret := int(C.call_start_plugin(h.api, corePtr, C.int(1), &cErr)); ret != 0 {
|
if ret := int(C.call_start_plugin(h.api, corePtr, C.int(ABIVersion), &cErr)); ret != 0 {
|
||||||
errMsg := ""
|
errMsg := ""
|
||||||
if cErr != nil { errMsg = C.GoString(cErr); C.api_free_string(h.api, cErr) }
|
if cErr != nil { errMsg = C.GoString(cErr); C.api_free_string(h.api, cErr) }
|
||||||
return fmt.Errorf("start_plugin: %s", errMsg)
|
return fmt.Errorf("start_plugin: %s", errMsg)
|
||||||
|
|||||||
@ -1,56 +1,58 @@
|
|||||||
package cabi
|
package cabi
|
||||||
|
|
||||||
// ABI version constants
|
import "gitcode.com/JianFeeeee/HomeAgent/internal/meta"
|
||||||
|
|
||||||
|
// ABI version constants — single source of truth is meta.go
|
||||||
const (
|
const (
|
||||||
ABIVersion = 1
|
ABIVersion = meta.ABIVersion
|
||||||
ABIVersionMin = 1
|
ABIVersionMin = meta.ABIVersionMin
|
||||||
)
|
)
|
||||||
|
|
||||||
// Dispatch method IDs (mirrors the plugin side constants)
|
// Dispatch method IDs — single source of truth is meta.go
|
||||||
const (
|
const (
|
||||||
CoreRegisterTool = 1
|
CoreRegisterTool = meta.CoreRegisterTool
|
||||||
CoreRegisterStage = 2
|
CoreRegisterStage = meta.CoreRegisterStage
|
||||||
CoreRegisterOutputCh = 3
|
CoreRegisterOutputCh = meta.CoreRegisterOutputCh
|
||||||
CoreRegisterPluginAPI = 4
|
CoreRegisterPluginAPI = meta.CoreRegisterPluginAPI
|
||||||
CoreInjectText = 5
|
CoreInjectText = meta.CoreInjectText
|
||||||
CoreInjectInterruptText = 6
|
CoreInjectInterruptText = meta.CoreInjectInterruptText
|
||||||
CoreInjectTextNoMemory = 7
|
CoreInjectTextNoMemory = meta.CoreInjectTextNoMemory
|
||||||
CoreSetAutoRestart = 8
|
CoreSetAutoRestart = meta.CoreSetAutoRestart
|
||||||
CoreMemoryRecall = 9
|
CoreMemoryRecall = meta.CoreMemoryRecall
|
||||||
CoreMemoryCommit = 10
|
CoreMemoryCommit = meta.CoreMemoryCommit
|
||||||
CoreMemoryIntrospect = 11
|
CoreMemoryIntrospect = meta.CoreMemoryIntrospect
|
||||||
CoreMemoryMerge = 12
|
CoreMemoryMerge = meta.CoreMemoryMerge
|
||||||
CoreMemoryPurge = 13
|
CoreMemoryPurge = meta.CoreMemoryPurge
|
||||||
CoreDocQuery = 14
|
CoreDocQuery = meta.CoreDocQuery
|
||||||
CoreKnowledgeSearch = 15
|
CoreKnowledgeSearch = meta.CoreKnowledgeSearch
|
||||||
CoreSettingsGet = 16
|
CoreSettingsGet = meta.CoreSettingsGet
|
||||||
CoreSettingsSet = 17
|
CoreSettingsSet = meta.CoreSettingsSet
|
||||||
CoreSettingsRegisterDef = 18
|
CoreSettingsRegisterDef = meta.CoreSettingsRegisterDef
|
||||||
CoreLLMListSources = 19
|
CoreLLMListSources = meta.CoreLLMListSources
|
||||||
CoreLLMSetSource = 20
|
CoreLLMSetSource = meta.CoreLLMSetSource
|
||||||
CoreSocialGetPerson = 21
|
CoreSocialGetPerson = meta.CoreSocialGetPerson
|
||||||
CoreSocialGetNetwork = 22
|
CoreSocialGetNetwork = meta.CoreSocialGetNetwork
|
||||||
CoreSubscribe = 23
|
CoreSubscribe = meta.CoreSubscribe
|
||||||
CoreUnsubscribe = 24
|
CoreUnsubscribe = meta.CoreUnsubscribe
|
||||||
CoreFreeString = 25
|
CoreFreeString = meta.CoreFreeString
|
||||||
CoreSettingsGetCore = 26
|
CoreSettingsGetCore = meta.CoreSettingsGetCore
|
||||||
CoreSettingsSetCore = 27
|
CoreSettingsSetCore = meta.CoreSettingsSetCore
|
||||||
CoreSettingsListCore = 28
|
CoreSettingsListCore = meta.CoreSettingsListCore
|
||||||
CoreSettingsGetPlugin = 29
|
CoreSettingsGetPlugin = meta.CoreSettingsGetPlugin
|
||||||
CoreSettingsSetPlugin = 30
|
CoreSettingsSetPlugin = meta.CoreSettingsSetPlugin
|
||||||
CoreSettingsListPlugin = 31
|
CoreSettingsListPlugin = meta.CoreSettingsListPlugin
|
||||||
CoreDocInsert = 32
|
CoreDocInsert = meta.CoreDocInsert
|
||||||
CoreDocRemove = 33
|
CoreDocRemove = meta.CoreDocRemove
|
||||||
CoreDocStats = 34
|
CoreDocStats = meta.CoreDocStats
|
||||||
CoreKnowledgeAdd = 35
|
CoreKnowledgeAdd = meta.CoreKnowledgeAdd
|
||||||
CoreKnowledgeList = 36
|
CoreKnowledgeList = meta.CoreKnowledgeList
|
||||||
CoreLLMCurrentSource = 37
|
CoreLLMCurrentSource = meta.CoreLLMCurrentSource
|
||||||
CoreSocialGetTrait = 38
|
CoreSocialGetTrait = meta.CoreSocialGetTrait
|
||||||
CoreSocialGetRelations = 39
|
CoreSocialGetRelations = meta.CoreSocialGetRelations
|
||||||
CoreSocialListPersons = 40
|
CoreSocialListPersons = meta.CoreSocialListPersons
|
||||||
CoreTextMemoryAppend = 41
|
CoreTextMemoryAppend = meta.CoreTextMemoryAppend
|
||||||
CoreSettingsList = 42
|
CoreSettingsList = meta.CoreSettingsList
|
||||||
CoreSettingsDefs = 43
|
CoreSettingsDefs = meta.CoreSettingsDefs
|
||||||
CoreSettingsDump = 44
|
CoreSettingsDump = meta.CoreSettingsDump
|
||||||
CoreSettingsPlugins = 45
|
CoreSettingsPlugins = meta.CoreSettingsPlugins
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user