Why: Downstream repositories need a versioned public manifest for skills, MCP, knowledge, parsers, agents, channels, and pages without forking the base. Evidence: go test ./... passed after omitzero on empty scope and backend so the golden plugin_manifest stays stable. Impact: apiVersion 1.0 remains accepted. New provides fields are optional. Scope and backend are omitted when zero. Refs: docs/proposals/2026-10-01-plugin-contract-v2.md Co-authored-by: Cursor <cursoragent@cursor.com>
101 lines
3.1 KiB
Go
101 lines
3.1 KiB
Go
package core
|
|
|
|
// PluginAPIVersionExperimental 是插件契约 v2 的实验窗口。
|
|
// 1.0 清单继续有效;v2 只增加可选字段,不收紧 1.0 已有资产。
|
|
const PluginAPIVersionExperimental = "2.0-experimental"
|
|
|
|
// PluginAPIAccepted 报告宿主是否接受该 apiVersion。空值由宿主填成 PluginAPIVersion。
|
|
func PluginAPIAccepted(v string) bool {
|
|
switch v {
|
|
case PluginAPIVersion, PluginAPIVersionExperimental:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// PluginScope 限制插件对哪些租户/项目可见。两者都空 = 全部可见。
|
|
type PluginScope struct {
|
|
Tenants []string `json:"tenants,omitempty"`
|
|
Projects []string `json:"projects,omitempty"`
|
|
}
|
|
|
|
// Allows 判断 owner/project 是否落在作用域内。
|
|
func (s PluginScope) Allows(owner, project string) bool {
|
|
if len(s.Tenants) > 0 && !scopeContains(s.Tenants, owner) {
|
|
return false
|
|
}
|
|
if len(s.Projects) > 0 && !scopeContains(s.Projects, project) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func scopeContains(xs []string, v string) bool {
|
|
for _, x := range xs {
|
|
if x == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// PluginBackend 声明进程内或 sidecar 代码档。SchemaVersion 是插件自有数据的迁移版本。
|
|
type PluginBackend struct {
|
|
Mode string `json:"mode,omitempty"` // inproc | sidecar
|
|
Command string `json:"command,omitempty"`
|
|
Args []string `json:"args,omitempty"`
|
|
SchemaVersion int `json:"schemaVersion,omitempty"`
|
|
}
|
|
|
|
// PluginSkill 是 skills/<name>.md 的装载结果(SKILL.md 正文)。
|
|
type PluginSkill struct {
|
|
Name string `json:"name"`
|
|
Body string `json:"body"`
|
|
}
|
|
|
|
// PluginMCPServer 是 mcpServers/<name>.json,字段与 agent-native MCP ServerConfig 对齐。
|
|
type PluginMCPServer struct {
|
|
Name string `json:"name"`
|
|
Command string `json:"command,omitempty"`
|
|
Args []string `json:"args,omitempty"`
|
|
URL string `json:"url,omitempty"`
|
|
}
|
|
|
|
// PluginKnowledgeSet 是知识数据集声明(数据在插件侧,检索引擎在基座)。
|
|
type PluginKnowledgeSet struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description,omitempty"`
|
|
}
|
|
|
|
// PluginParserDecl 是解析器声明。实现可以是内置名或 sidecar 工具名。
|
|
type PluginParserDecl struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
MIME string `json:"mime,omitempty"`
|
|
Tool string `json:"tool,omitempty"`
|
|
}
|
|
|
|
// PluginAgentDecl 是画像/子代理声明。
|
|
type PluginAgentDecl struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Instructions string `json:"instructions,omitempty"`
|
|
Tools []string `json:"tools,omitempty"`
|
|
}
|
|
|
|
// PluginChannelDecl 是渠道适配器声明(飞书等由下游实现,基座只登记入口)。
|
|
type PluginChannelDecl struct {
|
|
ID string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
Title string `json:"title,omitempty"`
|
|
}
|
|
|
|
// PluginPageDecl 是前端 ESM 页面。Module 相对插件目录或绝对 URL。
|
|
type PluginPageDecl struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Module string `json:"module"`
|
|
}
|