You've already forked agentic-coding-workflow
ACP / MCP
This commit is contained in:
+100
-13
@@ -47,21 +47,90 @@ const (
|
||||
RPCError RPCKind = "error"
|
||||
)
|
||||
|
||||
// ClientType 标识 agent CLI 的客户端类型,决定 spawn 时注入哪个配置目录
|
||||
// 重定向变量(CLAUDE_CONFIG_DIR / CODEX_HOME / GEMINI_CLI_HOME)以及前端
|
||||
// 渲染哪套配置表单。generic 仅注入 HOME。
|
||||
type ClientType string
|
||||
|
||||
const (
|
||||
ClientClaudeCode ClientType = "claude_code"
|
||||
ClientCodex ClientType = "codex"
|
||||
ClientGemini ClientType = "gemini"
|
||||
ClientGeneric ClientType = "generic"
|
||||
)
|
||||
|
||||
// Valid 判定 client_type 是否为已知枚举值。
|
||||
func (t ClientType) Valid() bool {
|
||||
switch t {
|
||||
case ClientClaudeCode, ClientCodex, ClientGemini, ClientGeneric:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ACW 自家 MCP 注入约定:session 创建时签发的 system token 与 MCP 公网地址
|
||||
// 经 extraEnv 注入子进程,同时在 session/new 握手时作为 http MCP server 下发。
|
||||
const (
|
||||
EnvMCPToken = "ACW_MCP_TOKEN"
|
||||
EnvMCPURL = "ACW_MCP_URL"
|
||||
// AcwMcpServerName 是自家 MCP 在 mcpServers 里的保留名,第三方条目不可占用。
|
||||
AcwMcpServerName = "acw"
|
||||
)
|
||||
|
||||
// McpServerType 是第三方 MCP server 的传输类型。stdio 是 ACP 基线(所有 agent
|
||||
// 必须支持);http / sse 需 agent 在 initialize 中声明 mcpCapabilities 才下发。
|
||||
type McpServerType string
|
||||
|
||||
const (
|
||||
McpStdio McpServerType = "stdio"
|
||||
McpHTTP McpServerType = "http"
|
||||
McpSSE McpServerType = "sse"
|
||||
)
|
||||
|
||||
// McpServerSpec 是 admin 在 AgentKind 上配置的一条 MCP server。session/new
|
||||
// 握手时转换为 ACP wire 格式随 mcpServers 下发。Env / Headers 可能含密钥,
|
||||
// 整个列表加密落库(encrypted_mcp_servers);明文仅返回给 admin 编辑。
|
||||
type McpServerSpec struct {
|
||||
Name string `json:"name"`
|
||||
Type McpServerType `json:"type"`
|
||||
Command string `json:"command,omitempty"` // stdio
|
||||
Args []string `json:"args,omitempty"` // stdio
|
||||
Env map[string]string `json:"env,omitempty"` // stdio
|
||||
URL string `json:"url,omitempty"` // http / sse
|
||||
Headers map[string]string `json:"headers,omitempty"` // http / sse
|
||||
}
|
||||
|
||||
// AgentKind 是 admin 注册的 agent 类型记录。EncryptedEnv 是 AES-GCM 密文,
|
||||
// 仅 supervisor spawn 时解密为 map 注入子进程。其他场景不解密、不出 API。
|
||||
// EncryptedMCPServers 同为密文,但明文经 API 返回给 admin 供编辑。
|
||||
type AgentKind struct {
|
||||
ID uuid.UUID
|
||||
Name string
|
||||
DisplayName string
|
||||
Description string
|
||||
BinaryPath string
|
||||
Args []string
|
||||
EncryptedEnv []byte
|
||||
Enabled bool
|
||||
ToolAllowlist []string // 命中的工具调用自动放行;含 "*" 表示放行全部可识别的工具(无法识别名称的调用仍走人工审批)
|
||||
CreatedBy uuid.UUID
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ID uuid.UUID
|
||||
Name string
|
||||
DisplayName string
|
||||
Description string
|
||||
BinaryPath string
|
||||
Args []string
|
||||
EncryptedEnv []byte
|
||||
Enabled bool
|
||||
ToolAllowlist []string // 命中的工具调用自动放行;含 "*" 表示放行全部可识别的工具(无法识别名称的调用仍走人工审批)
|
||||
ClientType ClientType
|
||||
EncryptedMCPServers []byte
|
||||
CreatedBy uuid.UUID
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// ConfigFile 是 AgentKind 维度的 agent CLI 配置文件(如 .claude/settings.json、
|
||||
// .codex/config.toml)。RelPath 相对受管 home 目录;EncryptedContent 是 AES-GCM
|
||||
// 密文(内容可能含 auth token),spawn 前解密物化到受管目录。
|
||||
type ConfigFile struct {
|
||||
ID uuid.UUID
|
||||
AgentKindID uuid.UUID
|
||||
RelPath string
|
||||
EncryptedContent []byte
|
||||
UpdatedBy uuid.UUID
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// Session 是一次 ACP 会话。AgentSessionID 是 agent 侧的 session 标识(来自
|
||||
@@ -114,6 +183,19 @@ type AgentKindService interface {
|
||||
Get(ctx context.Context, c Caller, id uuid.UUID) (*AgentKind, error)
|
||||
Update(ctx context.Context, c Caller, id uuid.UUID, in UpdateAgentKindInput) (*AgentKind, error)
|
||||
Delete(ctx context.Context, c Caller, id uuid.UUID) error
|
||||
|
||||
// 配置文件管理(admin only)。与 env 不同:内容明文返回给 admin 供编辑,
|
||||
// 存储层加密。content 是明文。
|
||||
ListConfigFiles(ctx context.Context, c Caller, kindID uuid.UUID) ([]*ConfigFileContent, error)
|
||||
UpsertConfigFile(ctx context.Context, c Caller, kindID uuid.UUID, relPath, content string) (*ConfigFileContent, error)
|
||||
DeleteConfigFile(ctx context.Context, c Caller, kindID uuid.UUID, relPath string) error
|
||||
}
|
||||
|
||||
// ConfigFileContent 是解密后的配置文件视图(service → handler)。
|
||||
type ConfigFileContent struct {
|
||||
RelPath string
|
||||
Content string
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// SessionService 暴露 Session 聚合根的应用服务方法。
|
||||
@@ -143,6 +225,7 @@ type CreateSessionInput struct {
|
||||
}
|
||||
|
||||
// CreateAgentKindInput 携带创建必需字段。Args / Env 可为 nil。
|
||||
// ClientType 为空时默认 generic。
|
||||
type CreateAgentKindInput struct {
|
||||
Name string
|
||||
DisplayName string
|
||||
@@ -152,6 +235,8 @@ type CreateAgentKindInput struct {
|
||||
Env map[string]string
|
||||
Enabled bool
|
||||
ToolAllowlist []string
|
||||
ClientType ClientType
|
||||
MCPServers []McpServerSpec
|
||||
}
|
||||
|
||||
// UpdateAgentKindInput 是 patch 输入。Name 不可改(创建后稳定,引用约束)。
|
||||
@@ -163,7 +248,9 @@ type UpdateAgentKindInput struct {
|
||||
Args []string // nil = 不改;非 nil = 替换
|
||||
Env map[string]string // nil = 不改;非 nil(含空)= 替换
|
||||
Enabled *bool
|
||||
ToolAllowlist []string // nil = 不改;非 nil(含空)= 替换
|
||||
ToolAllowlist []string // nil = 不改;非 nil(含空)= 替换
|
||||
ClientType *ClientType // nil = 不改
|
||||
MCPServers []McpServerSpec // nil = 不改;非 nil(含空)= 替换
|
||||
}
|
||||
|
||||
// PermissionStatus 是 acp_permission_requests.status 枚举。
|
||||
|
||||
Reference in New Issue
Block a user