chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// ArtifactFileSource authorizes persisted files independently of sandbox paths.
|
||||
// Implementations must restrict references to the bound conversation's outputs.
|
||||
type ArtifactFileSource interface {
|
||||
Read(context.Context, string) ([]byte, error)
|
||||
}
|
||||
|
||||
// WithArtifacts adds authorized persisted outputs without granting sandbox access.
|
||||
func (t *ReadFileTool) WithArtifacts(source ArtifactFileSource) *ReadFileTool {
|
||||
t.artifacts = source
|
||||
t.updateDescription()
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ReadFileTool) readArtifact(ctx context.Context, input ReadFileInput) *types.ToolResult {
|
||||
if t.artifacts == nil {
|
||||
return &types.ToolResult{Success: false, Error: "generated file access is unavailable in this conversation"}
|
||||
}
|
||||
if input.Offset < 0 || input.LineOffset < 0 || input.Limit < 0 || input.MaxBytes < 0 {
|
||||
return &types.ToolResult{Success: false, Error: "read offsets and limits must be non-negative"}
|
||||
}
|
||||
if strings.TrimSpace(input.Query) != "" && input.LineOffset != 0 {
|
||||
return &types.ToolResult{Success: false, Error: "line_offset cannot be combined with query"}
|
||||
}
|
||||
data, err := t.artifacts.Read(ctx, input.Path)
|
||||
if err != nil {
|
||||
return &types.ToolResult{Success: false, Error: err.Error()}
|
||||
}
|
||||
return renderFilePage(ctx, input, data, resolveSessionID(ctx), input.Path, types.ResourceScheme)
|
||||
}
|
||||
Reference in new issue
Block a user