Files
multica/server/pkg/db/generated/skill.sql.go
Bohan Jiang d0ac67dea2 fix(skills): drop SKILL.md content from list endpoints (#2180)
* fix(skills): drop SKILL.md content from list endpoints (#2174)

`GET /api/skills` and `GET /api/agents/{id}/skills` were SELECT *'ing the
skill row and shipping the full SKILL.md `content` blob to every caller.
SKILL.md bodies routinely run 50–200KB each, so a workspace with 30–40
skills returned multi-megabyte JSON arrays — past the CLI's 15s timeout
on high-latency links and locking out non-US users entirely.

Add `ListSkillSummariesByWorkspace` / `ListAgentSkillSummaries` sqlc
queries that omit `content`, plus a dedicated `SkillSummaryResponse`
wire shape so the contract is explicit (versus stuffing
`Content: ""` back into the existing struct). Detail endpoints
(`GET /api/skills/{id}`, agent CRUD return values) keep returning the
full body.

`AgentResponse.skills` and the matching TS `Agent.skills` now use
`SkillSummary[]` — frontend list/columns code already only read
id/name/description/config.origin, so the type narrowing matches actual
usage and prevents new code from accidentally depending on a content
field that won't be there.

Co-authored-by: multica-agent <github@multica.ai>

* fix(agents): narrow embedded skills to AgentSkillSummary; gofmt agent.go

GPT-Boy review of #2180: the previous commit typed AgentResponse.Skills as
[]SkillSummaryResponse, but the agent list batch query
(ListAgentSkillsByWorkspace) only joins agent_id/id/name/description, so
the wider type left workspace_id/config/created_at/updated_at as zero
values. Define a dedicated AgentSkillSummary {id,name,description} that
matches what the batch query actually returns and what the frontend
actually reads (`agent.skills.map(s => s.name|s.id)`); the standalone
GET /api/agents/{id}/skills endpoint keeps SkillSummaryResponse for
callers that need the source/origin info.

Switch GetAgent's per-agent skills load from ListAgentSkills (full Skill
rows including content) back to ListAgentSkillSummaries to avoid reading
SKILL.md bodies just to discard them.

Re-run gofmt on agent.go to fix the field-tag alignment that drifted when
Skills changed type.

Co-authored-by: multica-agent <github@multica.ai>

* docs(types): correct SkillSummary JSDoc — Agent.skills is AgentSkillSummary[]

GPT-Boy spotted on review: comment said SkillSummary was "embedded in
Agent.skills", but that field is now AgentSkillSummary[]. Re-point the
reader at the right type to avoid future confusion.

Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: multica-agent <github@multica.ai>
2026-05-07 01:36:29 +08:00

511 lines
13 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: skill.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const addAgentSkill = `-- name: AddAgentSkill :exec
INSERT INTO agent_skill (agent_id, skill_id)
VALUES ($1, $2)
ON CONFLICT DO NOTHING
`
type AddAgentSkillParams struct {
AgentID pgtype.UUID `json:"agent_id"`
SkillID pgtype.UUID `json:"skill_id"`
}
func (q *Queries) AddAgentSkill(ctx context.Context, arg AddAgentSkillParams) error {
_, err := q.db.Exec(ctx, addAgentSkill, arg.AgentID, arg.SkillID)
return err
}
const createSkill = `-- name: CreateSkill :one
INSERT INTO skill (workspace_id, name, description, content, config, created_by)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, workspace_id, name, description, content, config, created_by, created_at, updated_at
`
type CreateSkillParams struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
Name string `json:"name"`
Description string `json:"description"`
Content string `json:"content"`
Config []byte `json:"config"`
CreatedBy pgtype.UUID `json:"created_by"`
}
func (q *Queries) CreateSkill(ctx context.Context, arg CreateSkillParams) (Skill, error) {
row := q.db.QueryRow(ctx, createSkill,
arg.WorkspaceID,
arg.Name,
arg.Description,
arg.Content,
arg.Config,
arg.CreatedBy,
)
var i Skill
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Content,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteSkill = `-- name: DeleteSkill :exec
DELETE FROM skill WHERE id = $1
`
func (q *Queries) DeleteSkill(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteSkill, id)
return err
}
const deleteSkillFile = `-- name: DeleteSkillFile :exec
DELETE FROM skill_file WHERE id = $1
`
func (q *Queries) DeleteSkillFile(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteSkillFile, id)
return err
}
const deleteSkillFilesBySkill = `-- name: DeleteSkillFilesBySkill :exec
DELETE FROM skill_file WHERE skill_id = $1
`
func (q *Queries) DeleteSkillFilesBySkill(ctx context.Context, skillID pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteSkillFilesBySkill, skillID)
return err
}
const getSkill = `-- name: GetSkill :one
SELECT id, workspace_id, name, description, content, config, created_by, created_at, updated_at FROM skill
WHERE id = $1
`
func (q *Queries) GetSkill(ctx context.Context, id pgtype.UUID) (Skill, error) {
row := q.db.QueryRow(ctx, getSkill, id)
var i Skill
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Content,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getSkillFile = `-- name: GetSkillFile :one
SELECT id, skill_id, path, content, created_at, updated_at FROM skill_file
WHERE id = $1
`
func (q *Queries) GetSkillFile(ctx context.Context, id pgtype.UUID) (SkillFile, error) {
row := q.db.QueryRow(ctx, getSkillFile, id)
var i SkillFile
err := row.Scan(
&i.ID,
&i.SkillID,
&i.Path,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getSkillInWorkspace = `-- name: GetSkillInWorkspace :one
SELECT id, workspace_id, name, description, content, config, created_by, created_at, updated_at FROM skill
WHERE id = $1 AND workspace_id = $2
`
type GetSkillInWorkspaceParams struct {
ID pgtype.UUID `json:"id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
}
func (q *Queries) GetSkillInWorkspace(ctx context.Context, arg GetSkillInWorkspaceParams) (Skill, error) {
row := q.db.QueryRow(ctx, getSkillInWorkspace, arg.ID, arg.WorkspaceID)
var i Skill
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Content,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listAgentSkillSummaries = `-- name: ListAgentSkillSummaries :many
SELECT s.id, s.workspace_id, s.name, s.description, s.config, s.created_by, s.created_at, s.updated_at
FROM skill s
JOIN agent_skill ask ON ask.skill_id = s.id
WHERE ask.agent_id = $1
ORDER BY s.name ASC
`
type ListAgentSkillSummariesRow struct {
ID pgtype.UUID `json:"id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
Name string `json:"name"`
Description string `json:"description"`
Config []byte `json:"config"`
CreatedBy pgtype.UUID `json:"created_by"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
// Summary variant for the agent skills list endpoint — omits `content` for
// the same reason as ListSkillSummariesByWorkspace.
func (q *Queries) ListAgentSkillSummaries(ctx context.Context, agentID pgtype.UUID) ([]ListAgentSkillSummariesRow, error) {
rows, err := q.db.Query(ctx, listAgentSkillSummaries, agentID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListAgentSkillSummariesRow{}
for rows.Next() {
var i ListAgentSkillSummariesRow
if err := rows.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listAgentSkills = `-- name: ListAgentSkills :many
SELECT s.id, s.workspace_id, s.name, s.description, s.content, s.config, s.created_by, s.created_at, s.updated_at FROM skill s
JOIN agent_skill ask ON ask.skill_id = s.id
WHERE ask.agent_id = $1
ORDER BY s.name ASC
`
// Agent-Skill junction
func (q *Queries) ListAgentSkills(ctx context.Context, agentID pgtype.UUID) ([]Skill, error) {
rows, err := q.db.Query(ctx, listAgentSkills, agentID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Skill{}
for rows.Next() {
var i Skill
if err := rows.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Content,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listAgentSkillsByWorkspace = `-- name: ListAgentSkillsByWorkspace :many
SELECT ask.agent_id, s.id, s.name, s.description
FROM agent_skill ask
JOIN skill s ON s.id = ask.skill_id
WHERE s.workspace_id = $1
ORDER BY s.name ASC
`
type ListAgentSkillsByWorkspaceRow struct {
AgentID pgtype.UUID `json:"agent_id"`
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
func (q *Queries) ListAgentSkillsByWorkspace(ctx context.Context, workspaceID pgtype.UUID) ([]ListAgentSkillsByWorkspaceRow, error) {
rows, err := q.db.Query(ctx, listAgentSkillsByWorkspace, workspaceID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListAgentSkillsByWorkspaceRow{}
for rows.Next() {
var i ListAgentSkillsByWorkspaceRow
if err := rows.Scan(
&i.AgentID,
&i.ID,
&i.Name,
&i.Description,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSkillFiles = `-- name: ListSkillFiles :many
SELECT id, skill_id, path, content, created_at, updated_at FROM skill_file
WHERE skill_id = $1
ORDER BY path ASC
`
// Skill File CRUD
func (q *Queries) ListSkillFiles(ctx context.Context, skillID pgtype.UUID) ([]SkillFile, error) {
rows, err := q.db.Query(ctx, listSkillFiles, skillID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SkillFile{}
for rows.Next() {
var i SkillFile
if err := rows.Scan(
&i.ID,
&i.SkillID,
&i.Path,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSkillSummariesByWorkspace = `-- name: ListSkillSummariesByWorkspace :many
SELECT id, workspace_id, name, description, config, created_by, created_at, updated_at
FROM skill
WHERE workspace_id = $1
ORDER BY name ASC
`
type ListSkillSummariesByWorkspaceRow struct {
ID pgtype.UUID `json:"id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
Name string `json:"name"`
Description string `json:"description"`
Config []byte `json:"config"`
CreatedBy pgtype.UUID `json:"created_by"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
// Same as ListSkillsByWorkspace but omits the SKILL.md `content` column. Used
// by list endpoints (CLI table, web list page) where the body is never read;
// shipping it everywhere blew up payload size on workspaces with many skills
// and caused 15s CLI timeouts from high-latency regions (GH multica-ai/multica#2174).
func (q *Queries) ListSkillSummariesByWorkspace(ctx context.Context, workspaceID pgtype.UUID) ([]ListSkillSummariesByWorkspaceRow, error) {
rows, err := q.db.Query(ctx, listSkillSummariesByWorkspace, workspaceID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListSkillSummariesByWorkspaceRow{}
for rows.Next() {
var i ListSkillSummariesByWorkspaceRow
if err := rows.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSkillsByWorkspace = `-- name: ListSkillsByWorkspace :many
SELECT id, workspace_id, name, description, content, config, created_by, created_at, updated_at FROM skill
WHERE workspace_id = $1
ORDER BY name ASC
`
// Skill CRUD
func (q *Queries) ListSkillsByWorkspace(ctx context.Context, workspaceID pgtype.UUID) ([]Skill, error) {
rows, err := q.db.Query(ctx, listSkillsByWorkspace, workspaceID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Skill{}
for rows.Next() {
var i Skill
if err := rows.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Content,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const removeAgentSkill = `-- name: RemoveAgentSkill :exec
DELETE FROM agent_skill
WHERE agent_id = $1 AND skill_id = $2
`
type RemoveAgentSkillParams struct {
AgentID pgtype.UUID `json:"agent_id"`
SkillID pgtype.UUID `json:"skill_id"`
}
func (q *Queries) RemoveAgentSkill(ctx context.Context, arg RemoveAgentSkillParams) error {
_, err := q.db.Exec(ctx, removeAgentSkill, arg.AgentID, arg.SkillID)
return err
}
const removeAllAgentSkills = `-- name: RemoveAllAgentSkills :exec
DELETE FROM agent_skill WHERE agent_id = $1
`
func (q *Queries) RemoveAllAgentSkills(ctx context.Context, agentID pgtype.UUID) error {
_, err := q.db.Exec(ctx, removeAllAgentSkills, agentID)
return err
}
const updateSkill = `-- name: UpdateSkill :one
UPDATE skill SET
name = COALESCE($2, name),
description = COALESCE($3, description),
content = COALESCE($4, content),
config = COALESCE($5, config),
updated_at = now()
WHERE id = $1
RETURNING id, workspace_id, name, description, content, config, created_by, created_at, updated_at
`
type UpdateSkillParams struct {
ID pgtype.UUID `json:"id"`
Name pgtype.Text `json:"name"`
Description pgtype.Text `json:"description"`
Content pgtype.Text `json:"content"`
Config []byte `json:"config"`
}
func (q *Queries) UpdateSkill(ctx context.Context, arg UpdateSkillParams) (Skill, error) {
row := q.db.QueryRow(ctx, updateSkill,
arg.ID,
arg.Name,
arg.Description,
arg.Content,
arg.Config,
)
var i Skill
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.Name,
&i.Description,
&i.Content,
&i.Config,
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertSkillFile = `-- name: UpsertSkillFile :one
INSERT INTO skill_file (skill_id, path, content)
VALUES ($1, $2, $3)
ON CONFLICT (skill_id, path) DO UPDATE SET
content = EXCLUDED.content,
updated_at = now()
RETURNING id, skill_id, path, content, created_at, updated_at
`
type UpsertSkillFileParams struct {
SkillID pgtype.UUID `json:"skill_id"`
Path string `json:"path"`
Content string `json:"content"`
}
func (q *Queries) UpsertSkillFile(ctx context.Context, arg UpsertSkillFileParams) (SkillFile, error) {
row := q.db.QueryRow(ctx, upsertSkillFile, arg.SkillID, arg.Path, arg.Content)
var i SkillFile
err := row.Scan(
&i.ID,
&i.SkillID,
&i.Path,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}