Files
Agent-System-Backend/pkg/extension/host.go
T
weichen 727f3702d0
ci / vet-and-test (pull_request) Successful in 46s
Expose builtin document parsing through the host handle
Why: downstream parsers are unreachable via extension.Host and the base lacked xlsx/pptx parsers; MS1 needs Excel and PPT ingest (EXT-5 request, documents proposal 2026-10-06-ext-5-host-parse-document).

Evidence: local GOWORK=off go test ./... all 29 packages pass incl. new ooxml_test (hand-built parts), ooxml_python_test (openpyxl/python-pptx round-trip), inproc owner-scope and limit tests, xlsx upload e2e; go vet clean; recorded as SELF on the Dev task card, PR CI to confirm.

Impact: Host gains ParseDocument (pure compute; errors only on ctx cancel or >100MiB input); builtin:xlsx (sheet order via workbook.xml rels, rich-text shared strings, formula cache, 1900/1904 dates, sparse cells) and builtin:pptx (sldIdLst order, titles, group shapes, AlternateContent Choice, tables, notes) added with 200k-cell/64MiB-part caps; legacy doc/xls/ppt get an actionable hint; ParsersDescription gains xlsx/pptx and the missing text ext; surface snapshot now records exported interface methods; docx part reads share the 64MiB cap.

Refs: documents 2026-10-06-ext-5-host-parse-document.md; EXT-1 host.go precedent.
2026-10-06 14:59:38 +00:00

62 lines
2.8 KiB
Go
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.
package extension
import (
"context"
core "agent-system-core"
)
// Request 是进程内命令处理器收到的一次分发请求(cmdbus.Request 的子集)。
type Request struct {
ID string
Params map[string]any
Entrance string // button | card | slash | chat | api(归一)
Actor string
Owner string
ConversationID string
}
// Handler 是下游注册的进程内命令处理器:每次分发由基座构造 owner 作用域的
// Host 句柄传入,处理器经句柄访问基座能力,不得自行越权持有 owner 凭证。
type Handler func(ctx context.Context, h Host, req Request) (any, error)
// Host 是基座在分发时构造的 owner 作用域宿主句柄(EXT-1 最小集 + EXT-5 解析)。
// 所有能力的可见范围都以本次分发的 Owner 为准;artifacts 只读
// (写入属完整集,另行评估)。实现由基座 internal 提供。
type Host interface {
// PluginID 返回注册处理器的插件标识(形如 rdm)。
PluginID() string
// Owner 返回本次分发的作用域 owner。
Owner() string
// KVPut/KVGet 插件 KV(按 pluginID+owner 隔离)。
KVPut(key, value string) error
KVGet(key string) (value string, ok bool, err error)
// Audit 写一条 owner 名下的审计事件。
Audit(action, target, evidence string) error
// Complete 经基座 LLM 路由补全(owner 的模型配置生效)。
Complete(ctx context.Context, prompt string) (string, error)
// KnowledgeSearch 混合检索(owner 可见范围)。
KnowledgeSearch(ctx context.Context, projectID core.ID, text string, topK int) ([]core.RetrievalHit, error)
// KnowledgeWrite 写知识分块;embed=true 时同步建向量(失败降级纯全文)。
// docs 各项的 Owner 由基座强制改写为本次 owner;Source 为空补 "plugin:<PluginID>"。
KnowledgeWrite(ctx context.Context, docs []core.KnowledgeDoc, embed bool) error
// TaskCreate/TaskUpdate 后台任务台账(进度/状态记账,执行体由下游自跑)。
TaskCreate(kind, title, conversationID string) (taskID string, err error)
TaskUpdate(taskID, status string, progress int, errText string) error
// ArtifactGet/ArtifactContent 工件只读(R1-3 ingest 读原件)。
ArtifactGet(artifactID string) (core.Artifact, error)
ArtifactContent(artifactID string) ([]byte, error)
// ParseDocument 用基座内置解析器把文档字节解析为 ParsedDocument(EXT-5)。
// 纯计算,不读写 owner 数据——要解析工件原件先经 ArtifactContent 取字节,
// owner 作用域由它保证。按扩展名分派;不可解析返回带 Warnings 的文档
//(显式失败),只有 ctx 取消与输入超过 100MiB 两种情况返回 error。
ParseDocument(ctx context.Context, filename, mime string, content []byte) (core.ParsedDocument, error)
}