91c9ee4b2d
广播逻辑重构: - AI 回复 (stream_start/response/stream_segments/multi_message/stream_end) 改用 broadcastToUser 发送给所有客户端 - 用户消息回显保持 broadcastToUserExcept 排除发送者 消息去重与角色修复: - CacheMessage(user) 移至回复生成后,避免本轮 LLM 调用出现重复用户消息 - action 角色消息在 DB 存储时映射为 assistant,DeepSeek 等模型不支持自定义角色 - stream_end defer 机制确保错误路径也会终止客户端思考指示器 OS 完整环境支持: - host 包重构为 HostBackend 接口 + Direct/WSL/Docker 三种后端 - 新增 os_exec/os_file/os_system 工具供 AI 在完整 Linux 环境中自由操作 其他: - 视觉模型注入 + 图片预处理后清空 Images 避免传给 Chat 模型 - 图片 URL 相对路径→绝对 URL 转换 - DevTools 链路追踪页面 + 重启修复 - 记忆搜索模糊匹配增强 - 后台思考定时调度支持 - 管理后台页面 (模型配置/用户管理等) - docs/api 更新广播机制说明 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
74 lines
2.4 KiB
Go
74 lines
2.4 KiB
Go
package host
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// HostBackend defines the interface for command execution and file system
|
|
// operations. Implementations include DirectBackend (host OS), WSLBackend
|
|
// (Windows Subsystem for Linux), and DockerBackend (container).
|
|
type HostBackend interface {
|
|
Exec(ctx context.Context, command, workDir string, timeout time.Duration) (*ExecResult, error)
|
|
ReadFile(path string, maxBytes int) (string, error)
|
|
WriteFile(path, content string, maxBytes int) error
|
|
ListDir(path string) ([]DirEntry, error)
|
|
SystemInfo() map[string]interface{}
|
|
DiskUsage(path string) (map[string]interface{}, error)
|
|
Name() string
|
|
}
|
|
|
|
// Manager provides controlled access to the host machine. It delegates
|
|
// to a HostBackend implementation which may be direct, WSL, or Docker.
|
|
type Manager struct {
|
|
backend HostBackend
|
|
}
|
|
|
|
// NewManager creates a new host Manager with the given backend.
|
|
func NewManager(backend HostBackend) *Manager {
|
|
return &Manager{backend: backend}
|
|
}
|
|
|
|
// SetAllowedDirs updates directory restrictions. Only effective for
|
|
// DirectBackend; WSL and Docker backends are no-ops.
|
|
func (m *Manager) SetAllowedDirs(dirs []string) {
|
|
if db, ok := m.backend.(*DirectBackend); ok {
|
|
db.SetAllowedDirs(dirs)
|
|
}
|
|
}
|
|
|
|
// Exec runs a command via the configured backend.
|
|
func (m *Manager) Exec(ctx context.Context, command, workDir string, timeout time.Duration) (*ExecResult, error) {
|
|
return m.backend.Exec(ctx, command, workDir, timeout)
|
|
}
|
|
|
|
// ReadFile reads a file via the configured backend.
|
|
func (m *Manager) ReadFile(path string, maxBytes int) (string, error) {
|
|
return m.backend.ReadFile(path, maxBytes)
|
|
}
|
|
|
|
// WriteFile writes a file via the configured backend.
|
|
func (m *Manager) WriteFile(path, content string, maxBytes int) error {
|
|
return m.backend.WriteFile(path, content, maxBytes)
|
|
}
|
|
|
|
// ListDir lists a directory via the configured backend.
|
|
func (m *Manager) ListDir(path string) ([]DirEntry, error) {
|
|
return m.backend.ListDir(path)
|
|
}
|
|
|
|
// SystemInfo returns system information from the configured backend.
|
|
func (m *Manager) SystemInfo() map[string]interface{} {
|
|
return m.backend.SystemInfo()
|
|
}
|
|
|
|
// DiskUsage returns disk usage info from the configured backend.
|
|
func (m *Manager) DiskUsage(path string) (map[string]interface{}, error) {
|
|
return m.backend.DiskUsage(path)
|
|
}
|
|
|
|
// BackendName returns the name of the active backend.
|
|
func (m *Manager) BackendName() string {
|
|
return m.backend.Name()
|
|
}
|