You've already forked agentic-coding-workflow
ACP / MCP
This commit is contained in:
+92
-30
@@ -28,6 +28,11 @@ type Repository interface {
|
||||
DeleteAgentKind(ctx context.Context, id uuid.UUID) error
|
||||
CountAgentKindUsage(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
|
||||
// AgentKind 配置文件(内容为密文,加解密在 service / supervisor 层)
|
||||
ListConfigFiles(ctx context.Context, kindID uuid.UUID) ([]*ConfigFile, error)
|
||||
UpsertConfigFile(ctx context.Context, f *ConfigFile) (*ConfigFile, error)
|
||||
DeleteConfigFile(ctx context.Context, kindID uuid.UUID, relPath string) (bool, error)
|
||||
|
||||
// Session
|
||||
InsertSession(ctx context.Context, s *Session) (*Session, error)
|
||||
GetSessionByID(ctx context.Context, id uuid.UUID) (*Session, error)
|
||||
@@ -142,16 +147,18 @@ func pgxNoRowsToErrNotFound(err error, code errs.Code, msg string) error {
|
||||
|
||||
func (r *pgRepo) CreateAgentKind(ctx context.Context, k *AgentKind) (*AgentKind, error) {
|
||||
row, err := r.q.CreateAgentKind(ctx, acpsqlc.CreateAgentKindParams{
|
||||
ID: toPgUUID(k.ID),
|
||||
Name: k.Name,
|
||||
DisplayName: k.DisplayName,
|
||||
Description: k.Description,
|
||||
BinaryPath: k.BinaryPath,
|
||||
Args: k.Args,
|
||||
EncryptedEnv: k.EncryptedEnv,
|
||||
Enabled: k.Enabled,
|
||||
CreatedBy: toPgUUID(k.CreatedBy),
|
||||
ToolAllowlist: normalizeStrSlice(k.ToolAllowlist),
|
||||
ID: toPgUUID(k.ID),
|
||||
Name: k.Name,
|
||||
DisplayName: k.DisplayName,
|
||||
Description: k.Description,
|
||||
BinaryPath: k.BinaryPath,
|
||||
Args: k.Args,
|
||||
EncryptedEnv: k.EncryptedEnv,
|
||||
Enabled: k.Enabled,
|
||||
CreatedBy: toPgUUID(k.CreatedBy),
|
||||
ToolAllowlist: normalizeStrSlice(k.ToolAllowlist),
|
||||
ClientType: string(k.ClientType),
|
||||
EncryptedMcpServers: k.EncryptedMCPServers,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "create agent kind")
|
||||
@@ -201,14 +208,16 @@ func (r *pgRepo) ListEnabledAgentKinds(ctx context.Context) ([]*AgentKind, error
|
||||
|
||||
func (r *pgRepo) UpdateAgentKind(ctx context.Context, k *AgentKind) (*AgentKind, error) {
|
||||
row, err := r.q.UpdateAgentKind(ctx, acpsqlc.UpdateAgentKindParams{
|
||||
ID: toPgUUID(k.ID),
|
||||
DisplayName: k.DisplayName,
|
||||
Description: k.Description,
|
||||
BinaryPath: k.BinaryPath,
|
||||
Args: k.Args,
|
||||
EncryptedEnv: k.EncryptedEnv,
|
||||
Enabled: k.Enabled,
|
||||
ToolAllowlist: normalizeStrSlice(k.ToolAllowlist),
|
||||
ID: toPgUUID(k.ID),
|
||||
DisplayName: k.DisplayName,
|
||||
Description: k.Description,
|
||||
BinaryPath: k.BinaryPath,
|
||||
Args: k.Args,
|
||||
EncryptedEnv: k.EncryptedEnv,
|
||||
Enabled: k.Enabled,
|
||||
ToolAllowlist: normalizeStrSlice(k.ToolAllowlist),
|
||||
ClientType: string(k.ClientType),
|
||||
EncryptedMcpServers: k.EncryptedMCPServers,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, pgxNoRowsToErrNotFound(err, errs.CodeAcpAgentKindNotFound, "agent kind not found")
|
||||
@@ -234,22 +243,75 @@ func (r *pgRepo) CountAgentKindUsage(ctx context.Context, id uuid.UUID) (int64,
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// ===== AgentKind 配置文件 =====
|
||||
|
||||
func (r *pgRepo) ListConfigFiles(ctx context.Context, kindID uuid.UUID) ([]*ConfigFile, error) {
|
||||
rows, err := r.q.ListAgentKindConfigFiles(ctx, toPgUUID(kindID))
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "list agent kind config files")
|
||||
}
|
||||
out := make([]*ConfigFile, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, rowToConfigFile(row))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) UpsertConfigFile(ctx context.Context, f *ConfigFile) (*ConfigFile, error) {
|
||||
row, err := r.q.UpsertAgentKindConfigFile(ctx, acpsqlc.UpsertAgentKindConfigFileParams{
|
||||
ID: toPgUUID(f.ID),
|
||||
AgentKindID: toPgUUID(f.AgentKindID),
|
||||
RelPath: f.RelPath,
|
||||
EncryptedContent: f.EncryptedContent,
|
||||
UpdatedBy: toPgUUID(f.UpdatedBy),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "upsert agent kind config file")
|
||||
}
|
||||
return rowToConfigFile(row), nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) DeleteConfigFile(ctx context.Context, kindID uuid.UUID, relPath string) (bool, error) {
|
||||
n, err := r.q.DeleteAgentKindConfigFile(ctx, acpsqlc.DeleteAgentKindConfigFileParams{
|
||||
AgentKindID: toPgUUID(kindID),
|
||||
RelPath: relPath,
|
||||
})
|
||||
if err != nil {
|
||||
return false, errs.Wrap(err, errs.CodeInternal, "delete agent kind config file")
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
// ===== row → domain converters =====
|
||||
|
||||
func rowToAgentKind(row acpsqlc.AcpAgentKind) *AgentKind {
|
||||
return &AgentKind{
|
||||
ID: fromPgUUID(row.ID),
|
||||
Name: row.Name,
|
||||
DisplayName: row.DisplayName,
|
||||
Description: row.Description,
|
||||
BinaryPath: row.BinaryPath,
|
||||
Args: row.Args,
|
||||
EncryptedEnv: row.EncryptedEnv,
|
||||
Enabled: row.Enabled,
|
||||
ToolAllowlist: row.ToolAllowlist,
|
||||
CreatedBy: fromPgUUID(row.CreatedBy),
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
ID: fromPgUUID(row.ID),
|
||||
Name: row.Name,
|
||||
DisplayName: row.DisplayName,
|
||||
Description: row.Description,
|
||||
BinaryPath: row.BinaryPath,
|
||||
Args: row.Args,
|
||||
EncryptedEnv: row.EncryptedEnv,
|
||||
Enabled: row.Enabled,
|
||||
ToolAllowlist: row.ToolAllowlist,
|
||||
ClientType: ClientType(row.ClientType),
|
||||
EncryptedMCPServers: row.EncryptedMcpServers,
|
||||
CreatedBy: fromPgUUID(row.CreatedBy),
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
}
|
||||
}
|
||||
|
||||
func rowToConfigFile(row acpsqlc.AcpAgentKindConfigFile) *ConfigFile {
|
||||
return &ConfigFile{
|
||||
ID: fromPgUUID(row.ID),
|
||||
AgentKindID: fromPgUUID(row.AgentKindID),
|
||||
RelPath: row.RelPath,
|
||||
EncryptedContent: row.EncryptedContent,
|
||||
UpdatedBy: fromPgUUID(row.UpdatedBy),
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user