feat(ECR-023): AICoreConfig KnowledgeSource 只读并 Closed
运营可观测知识源目录(knowledge_sources + admin /ai),不含 Chunk/Embedding。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -60,3 +60,59 @@ func (r *AdminRepo) GetSystemPrompt(ctx context.Context, id uuid.UUID) (*SystemP
|
||||
}
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
// KnowledgeSourceRow is AICoreConfig KnowledgeSource catalog row.
|
||||
type KnowledgeSourceRow struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
SourceKind string `json:"source_kind"`
|
||||
Version int `json:"version"`
|
||||
Active bool `json:"active"`
|
||||
System bool `json:"system"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ListKnowledgeSources returns knowledge source catalog.
|
||||
func (r *AdminRepo) ListKnowledgeSources(ctx context.Context) ([]KnowledgeSourceRow, error) {
|
||||
rows, err := r.Pool.Query(ctx, `
|
||||
SELECT id, code, title, description, source_kind, version, active, system, updated_at
|
||||
FROM knowledge_sources
|
||||
ORDER BY active DESC, code ASC`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []KnowledgeSourceRow
|
||||
for rows.Next() {
|
||||
var k KnowledgeSourceRow
|
||||
if err := rows.Scan(
|
||||
&k.ID, &k.Code, &k.Title, &k.Description, &k.SourceKind,
|
||||
&k.Version, &k.Active, &k.System, &k.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, k)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// GetKnowledgeSource loads one source by id.
|
||||
func (r *AdminRepo) GetKnowledgeSource(ctx context.Context, id uuid.UUID) (*KnowledgeSourceRow, error) {
|
||||
var k KnowledgeSourceRow
|
||||
err := r.Pool.QueryRow(ctx, `
|
||||
SELECT id, code, title, description, source_kind, version, active, system, updated_at
|
||||
FROM knowledge_sources WHERE id=$1`, id,
|
||||
).Scan(
|
||||
&k.ID, &k.Code, &k.Title, &k.Description, &k.SourceKind,
|
||||
&k.Version, &k.Active, &k.System, &k.UpdatedAt,
|
||||
)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, err
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &k, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user