运营可观测知识源目录(knowledge_sources + admin /ai),不含 Chunk/Embedding。 Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
|
)
|
|
|
|
var ErrSystemPromptNotFound = errString("system prompt not found")
|
|
var ErrKnowledgeSourceNotFound = errString("knowledge source not found")
|
|
|
|
// ListSystemPrompts returns SystemPrompt catalog.
|
|
func (s *Service) ListSystemPrompts(ctx context.Context) ([]repository.SystemPromptRow, error) {
|
|
items, err := s.Repo.ListSystemPrompts(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if items == nil {
|
|
items = []repository.SystemPromptRow{}
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
// GetSystemPrompt loads one prompt.
|
|
func (s *Service) GetSystemPrompt(ctx context.Context, id uuid.UUID) (*repository.SystemPromptRow, error) {
|
|
row, err := s.Repo.GetSystemPrompt(ctx, id)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
return nil, ErrSystemPromptNotFound
|
|
}
|
|
return row, err
|
|
}
|
|
|
|
// ListKnowledgeSources returns KnowledgeSource catalog.
|
|
func (s *Service) ListKnowledgeSources(ctx context.Context) ([]repository.KnowledgeSourceRow, error) {
|
|
items, err := s.Repo.ListKnowledgeSources(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if items == nil {
|
|
items = []repository.KnowledgeSourceRow{}
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
// GetKnowledgeSource loads one source.
|
|
func (s *Service) GetKnowledgeSource(ctx context.Context, id uuid.UUID) (*repository.KnowledgeSourceRow, error) {
|
|
row, err := s.Repo.GetKnowledgeSource(ctx, id)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
return nil, ErrKnowledgeSourceNotFound
|
|
}
|
|
return row, err
|
|
}
|