Files
wehub-resource-sync f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

106 lines
2.6 KiB
Go

package duckdb
import (
"context"
"database/sql"
"fmt"
"go.kenn.io/agentsview/internal/db"
)
func (s *Store) StarSession(sessionID string) (bool, error) {
return false, db.ErrReadOnly
}
func (s *Store) UnstarSession(sessionID string) error {
return db.ErrReadOnly
}
func (s *Store) ListStarredSessionIDs(ctx context.Context) ([]string, error) {
rows, err := s.queryContext(ctx, `
SELECT session_id FROM starred_sessions
ORDER BY created_at DESC, session_id DESC`)
if err != nil {
return nil, err
}
defer rows.Close()
var ids []string
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
return nil, err
}
ids = append(ids, id)
}
return ids, rows.Err()
}
func (s *Store) BulkStarSessions(sessionIDs []string) error {
return db.ErrReadOnly
}
func (s *Store) PinMessage(sessionID string, messageID int64, note *string) (int64, error) {
return 0, db.ErrReadOnly
}
func (s *Store) UnpinMessage(sessionID string, messageID int64) error {
return db.ErrReadOnly
}
func (s *Store) ListPinnedMessages(
ctx context.Context, sessionID string, project string,
) ([]db.PinnedMessage, error) {
var rows *sql.Rows
var err error
if sessionID != "" {
rows, err = s.queryContext(ctx, `
SELECT id, session_id, message_id, ordinal, note, created_at
FROM pinned_messages
WHERE session_id = ?
ORDER BY created_at DESC, id DESC`,
sessionID,
)
} else {
query := `
SELECT p.id, p.session_id, p.message_id, p.ordinal,
p.note, p.created_at, m.content, m.role,
s.project, s.agent, COALESCE(s.display_name, s.session_name), s.first_message
FROM pinned_messages p
JOIN sessions s ON p.session_id = s.id AND s.deleted_at IS NULL
LEFT JOIN messages m ON p.session_id = m.session_id
AND p.message_id = m.id`
args := []any{}
if project != "" {
query += " WHERE s.project = ?"
args = append(args, project)
}
query += " ORDER BY p.created_at DESC, p.id DESC LIMIT 500"
rows, err = s.queryContext(ctx, query, args...)
}
if err != nil {
return nil, fmt.Errorf("listing duckdb pinned messages: %w", err)
}
defer rows.Close()
var pins []db.PinnedMessage
withContent := sessionID == ""
for rows.Next() {
var p db.PinnedMessage
var created any
if withContent {
err = rows.Scan(&p.ID, &p.SessionID, &p.MessageID, &p.Ordinal,
&p.Note, &created, &p.Content, &p.Role,
&p.SessionProject, &p.SessionAgent,
&p.SessionDisplayName, &p.SessionFirstMessage)
} else {
err = rows.Scan(&p.ID, &p.SessionID, &p.MessageID,
&p.Ordinal, &p.Note, &created)
}
if err != nil {
return nil, err
}
p.CreatedAt = formatDBTime(created)
pins = append(pins, p)
}
return pins, rows.Err()
}