新增 system_prompts 目录、admin.ai_config.read 与 admin-h5「AI」页;本切片不改运行时 Prompt、禁写发布/UGC/真支付。 Co-authored-by: Cursor <cursoragent@cursor.com>
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
// SystemPromptRow is AICoreConfig SystemPrompt catalog row.
|
|
type SystemPromptRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Code string `json:"code"`
|
|
Title string `json:"title"`
|
|
Scene *string `json:"scene,omitempty"`
|
|
Body string `json:"body"`
|
|
Version int `json:"version"`
|
|
Active bool `json:"active"`
|
|
System bool `json:"system"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// ListSystemPrompts returns prompt catalog (body included for ops read).
|
|
func (r *AdminRepo) ListSystemPrompts(ctx context.Context) ([]SystemPromptRow, error) {
|
|
rows, err := r.Pool.Query(ctx, `
|
|
SELECT id, code, title, scene, body, version, active, system, updated_at
|
|
FROM system_prompts
|
|
ORDER BY active DESC, code ASC`)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var out []SystemPromptRow
|
|
for rows.Next() {
|
|
var p SystemPromptRow
|
|
if err := rows.Scan(
|
|
&p.ID, &p.Code, &p.Title, &p.Scene, &p.Body, &p.Version, &p.Active, &p.System, &p.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, p)
|
|
}
|
|
return out, rows.Err()
|
|
}
|
|
|
|
// GetSystemPrompt loads one prompt by id.
|
|
func (r *AdminRepo) GetSystemPrompt(ctx context.Context, id uuid.UUID) (*SystemPromptRow, error) {
|
|
var p SystemPromptRow
|
|
err := r.Pool.QueryRow(ctx, `
|
|
SELECT id, code, title, scene, body, version, active, system, updated_at
|
|
FROM system_prompts WHERE id=$1`, id,
|
|
).Scan(&p.ID, &p.Code, &p.Title, &p.Scene, &p.Body, &p.Version, &p.Active, &p.System, &p.UpdatedAt)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
return nil, err
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &p, nil
|
|
}
|