This commit is contained in:
2026-06-09 21:19:30 +08:00
parent 8b41ff9360
commit 0484e79978
66 changed files with 4043 additions and 533 deletions
+42 -31
View File
@@ -24,22 +24,23 @@ func (q *Queries) CountAgentKindUsage(ctx context.Context, agentKindID pgtype.UU
const createAgentKind = `-- name: CreateAgentKind :one
INSERT INTO acp_agent_kinds (
id, name, display_name, description, binary_path, args, encrypted_env, enabled, created_by
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
id, name, display_name, description, binary_path, args, encrypted_env, enabled, created_by, tool_allowlist
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING id, name, display_name, description, binary_path, args, encrypted_env,
enabled, created_by, created_at, updated_at
enabled, created_by, created_at, updated_at, tool_allowlist
`
type CreateAgentKindParams struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
BinaryPath string `json:"binary_path"`
Args []string `json:"args"`
EncryptedEnv []byte `json:"encrypted_env"`
Enabled bool `json:"enabled"`
CreatedBy pgtype.UUID `json:"created_by"`
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
BinaryPath string `json:"binary_path"`
Args []string `json:"args"`
EncryptedEnv []byte `json:"encrypted_env"`
Enabled bool `json:"enabled"`
CreatedBy pgtype.UUID `json:"created_by"`
ToolAllowlist []string `json:"tool_allowlist"`
}
func (q *Queries) CreateAgentKind(ctx context.Context, arg CreateAgentKindParams) (AcpAgentKind, error) {
@@ -53,6 +54,7 @@ func (q *Queries) CreateAgentKind(ctx context.Context, arg CreateAgentKindParams
arg.EncryptedEnv,
arg.Enabled,
arg.CreatedBy,
arg.ToolAllowlist,
)
var i AcpAgentKind
err := row.Scan(
@@ -67,6 +69,7 @@ func (q *Queries) CreateAgentKind(ctx context.Context, arg CreateAgentKindParams
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
&i.ToolAllowlist,
)
return i, err
}
@@ -82,7 +85,7 @@ func (q *Queries) DeleteAgentKind(ctx context.Context, id pgtype.UUID) error {
const getAgentKindByID = `-- name: GetAgentKindByID :one
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
enabled, created_by, created_at, updated_at
enabled, created_by, created_at, updated_at, tool_allowlist
FROM acp_agent_kinds
WHERE id = $1
`
@@ -102,13 +105,14 @@ func (q *Queries) GetAgentKindByID(ctx context.Context, id pgtype.UUID) (AcpAgen
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
&i.ToolAllowlist,
)
return i, err
}
const getAgentKindByName = `-- name: GetAgentKindByName :one
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
enabled, created_by, created_at, updated_at
enabled, created_by, created_at, updated_at, tool_allowlist
FROM acp_agent_kinds
WHERE name = $1
`
@@ -128,13 +132,14 @@ func (q *Queries) GetAgentKindByName(ctx context.Context, name string) (AcpAgent
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
&i.ToolAllowlist,
)
return i, err
}
const listAgentKinds = `-- name: ListAgentKinds :many
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
enabled, created_by, created_at, updated_at
enabled, created_by, created_at, updated_at, tool_allowlist
FROM acp_agent_kinds
ORDER BY created_at DESC
`
@@ -160,6 +165,7 @@ func (q *Queries) ListAgentKinds(ctx context.Context) ([]AcpAgentKind, error) {
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
&i.ToolAllowlist,
); err != nil {
return nil, err
}
@@ -173,7 +179,7 @@ func (q *Queries) ListAgentKinds(ctx context.Context) ([]AcpAgentKind, error) {
const listEnabledAgentKinds = `-- name: ListEnabledAgentKinds :many
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
enabled, created_by, created_at, updated_at
enabled, created_by, created_at, updated_at, tool_allowlist
FROM acp_agent_kinds
WHERE enabled = TRUE
ORDER BY name ASC
@@ -200,6 +206,7 @@ func (q *Queries) ListEnabledAgentKinds(ctx context.Context) ([]AcpAgentKind, er
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
&i.ToolAllowlist,
); err != nil {
return nil, err
}
@@ -213,26 +220,28 @@ func (q *Queries) ListEnabledAgentKinds(ctx context.Context) ([]AcpAgentKind, er
const updateAgentKind = `-- name: UpdateAgentKind :one
UPDATE acp_agent_kinds
SET display_name = $2,
description = $3,
binary_path = $4,
args = $5,
encrypted_env = $6,
enabled = $7,
updated_at = now()
SET display_name = $2,
description = $3,
binary_path = $4,
args = $5,
encrypted_env = $6,
enabled = $7,
tool_allowlist = $8,
updated_at = now()
WHERE id = $1
RETURNING id, name, display_name, description, binary_path, args, encrypted_env,
enabled, created_by, created_at, updated_at
enabled, created_by, created_at, updated_at, tool_allowlist
`
type UpdateAgentKindParams struct {
ID pgtype.UUID `json:"id"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
BinaryPath string `json:"binary_path"`
Args []string `json:"args"`
EncryptedEnv []byte `json:"encrypted_env"`
Enabled bool `json:"enabled"`
ID pgtype.UUID `json:"id"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
BinaryPath string `json:"binary_path"`
Args []string `json:"args"`
EncryptedEnv []byte `json:"encrypted_env"`
Enabled bool `json:"enabled"`
ToolAllowlist []string `json:"tool_allowlist"`
}
func (q *Queries) UpdateAgentKind(ctx context.Context, arg UpdateAgentKindParams) (AcpAgentKind, error) {
@@ -244,6 +253,7 @@ func (q *Queries) UpdateAgentKind(ctx context.Context, arg UpdateAgentKindParams
arg.Args,
arg.EncryptedEnv,
arg.Enabled,
arg.ToolAllowlist,
)
var i AcpAgentKind
err := row.Scan(
@@ -258,6 +268,7 @@ func (q *Queries) UpdateAgentKind(ctx context.Context, arg UpdateAgentKindParams
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
&i.ToolAllowlist,
)
return i, err
}
+27 -11
View File
@@ -11,17 +11,18 @@ import (
)
type AcpAgentKind struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
BinaryPath string `json:"binary_path"`
Args []string `json:"args"`
EncryptedEnv []byte `json:"encrypted_env"`
Enabled bool `json:"enabled"`
CreatedBy pgtype.UUID `json:"created_by"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
BinaryPath string `json:"binary_path"`
Args []string `json:"args"`
EncryptedEnv []byte `json:"encrypted_env"`
Enabled bool `json:"enabled"`
CreatedBy pgtype.UUID `json:"created_by"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ToolAllowlist []string `json:"tool_allowlist"`
}
type AcpEvent struct {
@@ -36,6 +37,20 @@ type AcpEvent struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type AcpPermissionRequest struct {
ID pgtype.UUID `json:"id"`
SessionID pgtype.UUID `json:"session_id"`
AgentRequestID string `json:"agent_request_id"`
ToolName string `json:"tool_name"`
ToolCall []byte `json:"tool_call"`
Options []byte `json:"options"`
Status string `json:"status"`
ChosenOptionID *string `json:"chosen_option_id"`
DecidedBy pgtype.UUID `json:"decided_by"`
DecidedAt pgtype.Timestamptz `json:"decided_at"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type AcpSession struct {
ID pgtype.UUID `json:"id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
@@ -269,6 +284,7 @@ type User struct {
IsAdmin bool `json:"is_admin"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Enabled bool `json:"enabled"`
}
type UserSession struct {
+237
View File
@@ -0,0 +1,237 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: permissions.sql
package acpsqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const decidePermissionRequest = `-- name: DecidePermissionRequest :one
UPDATE acp_permission_requests
SET status = $2, chosen_option_id = $3, decided_by = $4, decided_at = now()
WHERE id = $1 AND status = 'pending'
RETURNING id, session_id, agent_request_id, tool_name, tool_call, options, status,
chosen_option_id, decided_by, decided_at, created_at
`
type DecidePermissionRequestParams struct {
ID pgtype.UUID `json:"id"`
Status string `json:"status"`
ChosenOptionID *string `json:"chosen_option_id"`
DecidedBy pgtype.UUID `json:"decided_by"`
}
func (q *Queries) DecidePermissionRequest(ctx context.Context, arg DecidePermissionRequestParams) (AcpPermissionRequest, error) {
row := q.db.QueryRow(ctx, decidePermissionRequest,
arg.ID,
arg.Status,
arg.ChosenOptionID,
arg.DecidedBy,
)
var i AcpPermissionRequest
err := row.Scan(
&i.ID,
&i.SessionID,
&i.AgentRequestID,
&i.ToolName,
&i.ToolCall,
&i.Options,
&i.Status,
&i.ChosenOptionID,
&i.DecidedBy,
&i.DecidedAt,
&i.CreatedAt,
)
return i, err
}
const expirePendingPermissionRequestsBySession = `-- name: ExpirePendingPermissionRequestsBySession :execrows
UPDATE acp_permission_requests
SET status = 'expired', decided_at = now()
WHERE session_id = $1 AND status = 'pending'
`
func (q *Queries) ExpirePendingPermissionRequestsBySession(ctx context.Context, sessionID pgtype.UUID) (int64, error) {
result, err := q.db.Exec(ctx, expirePendingPermissionRequestsBySession, sessionID)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const expireStalePermissionRequests = `-- name: ExpireStalePermissionRequests :execrows
UPDATE acp_permission_requests
SET status = 'expired', decided_at = now()
WHERE status = 'pending' AND created_at < $1
`
func (q *Queries) ExpireStalePermissionRequests(ctx context.Context, createdAt pgtype.Timestamptz) (int64, error) {
result, err := q.db.Exec(ctx, expireStalePermissionRequests, createdAt)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getPermissionRequestByID = `-- name: GetPermissionRequestByID :one
SELECT id, session_id, agent_request_id, tool_name, tool_call, options, status,
chosen_option_id, decided_by, decided_at, created_at
FROM acp_permission_requests
WHERE id = $1
`
func (q *Queries) GetPermissionRequestByID(ctx context.Context, id pgtype.UUID) (AcpPermissionRequest, error) {
row := q.db.QueryRow(ctx, getPermissionRequestByID, id)
var i AcpPermissionRequest
err := row.Scan(
&i.ID,
&i.SessionID,
&i.AgentRequestID,
&i.ToolName,
&i.ToolCall,
&i.Options,
&i.Status,
&i.ChosenOptionID,
&i.DecidedBy,
&i.DecidedAt,
&i.CreatedAt,
)
return i, err
}
const insertPermissionRequest = `-- name: InsertPermissionRequest :one
INSERT INTO acp_permission_requests (
id, session_id, agent_request_id, tool_name, tool_call, options, status, chosen_option_id, decided_by, decided_at
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING id, session_id, agent_request_id, tool_name, tool_call, options, status,
chosen_option_id, decided_by, decided_at, created_at
`
type InsertPermissionRequestParams struct {
ID pgtype.UUID `json:"id"`
SessionID pgtype.UUID `json:"session_id"`
AgentRequestID string `json:"agent_request_id"`
ToolName string `json:"tool_name"`
ToolCall []byte `json:"tool_call"`
Options []byte `json:"options"`
Status string `json:"status"`
ChosenOptionID *string `json:"chosen_option_id"`
DecidedBy pgtype.UUID `json:"decided_by"`
DecidedAt pgtype.Timestamptz `json:"decided_at"`
}
func (q *Queries) InsertPermissionRequest(ctx context.Context, arg InsertPermissionRequestParams) (AcpPermissionRequest, error) {
row := q.db.QueryRow(ctx, insertPermissionRequest,
arg.ID,
arg.SessionID,
arg.AgentRequestID,
arg.ToolName,
arg.ToolCall,
arg.Options,
arg.Status,
arg.ChosenOptionID,
arg.DecidedBy,
arg.DecidedAt,
)
var i AcpPermissionRequest
err := row.Scan(
&i.ID,
&i.SessionID,
&i.AgentRequestID,
&i.ToolName,
&i.ToolCall,
&i.Options,
&i.Status,
&i.ChosenOptionID,
&i.DecidedBy,
&i.DecidedAt,
&i.CreatedAt,
)
return i, err
}
const listPendingPermissionRequestsBySession = `-- name: ListPendingPermissionRequestsBySession :many
SELECT id, session_id, agent_request_id, tool_name, tool_call, options, status,
chosen_option_id, decided_by, decided_at, created_at
FROM acp_permission_requests
WHERE session_id = $1 AND status = 'pending'
ORDER BY created_at ASC
`
func (q *Queries) ListPendingPermissionRequestsBySession(ctx context.Context, sessionID pgtype.UUID) ([]AcpPermissionRequest, error) {
rows, err := q.db.Query(ctx, listPendingPermissionRequestsBySession, sessionID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AcpPermissionRequest
for rows.Next() {
var i AcpPermissionRequest
if err := rows.Scan(
&i.ID,
&i.SessionID,
&i.AgentRequestID,
&i.ToolName,
&i.ToolCall,
&i.Options,
&i.Status,
&i.ChosenOptionID,
&i.DecidedBy,
&i.DecidedAt,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listPendingPermissionRequestsByUser = `-- name: ListPendingPermissionRequestsByUser :many
SELECT p.id, p.session_id, p.agent_request_id, p.tool_name, p.tool_call, p.options, p.status,
p.chosen_option_id, p.decided_by, p.decided_at, p.created_at
FROM acp_permission_requests p
JOIN acp_sessions s ON s.id = p.session_id
WHERE s.user_id = $1 AND p.status = 'pending'
ORDER BY p.created_at ASC
`
func (q *Queries) ListPendingPermissionRequestsByUser(ctx context.Context, userID pgtype.UUID) ([]AcpPermissionRequest, error) {
rows, err := q.db.Query(ctx, listPendingPermissionRequestsByUser, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AcpPermissionRequest
for rows.Next() {
var i AcpPermissionRequest
if err := rows.Scan(
&i.ID,
&i.SessionID,
&i.AgentRequestID,
&i.ToolName,
&i.ToolCall,
&i.Options,
&i.Status,
&i.ChosenOptionID,
&i.DecidedBy,
&i.DecidedAt,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}