Changeset 0.17.1 (#76)

This commit is contained in:
2026-02-28 01:40:31 +00:00
parent c9141a6896
commit 856dc9b0ac
64 changed files with 8037 additions and 1657 deletions

View File

@@ -46,17 +46,17 @@ func GetActiveLeaf(channelID, userID string) (*string, error) {
var leafID *string
// Try cursor first
err := database.DB.QueryRow(`
err := database.DB.QueryRow(database.Q(`
SELECT active_leaf_id FROM channel_cursors
WHERE channel_id = $1 AND user_id = $2
`, channelID, userID).Scan(&leafID)
`), channelID, userID).Scan(&leafID)
if err == nil && leafID != nil {
// Verify the leaf still exists and isn't deleted
var exists bool
database.DB.QueryRow(`
database.DB.QueryRow(database.Q(`
SELECT EXISTS(SELECT 1 FROM messages WHERE id = $1 AND deleted_at IS NULL)
`, *leafID).Scan(&exists)
`), *leafID).Scan(&exists)
if exists {
return leafID, nil
}
@@ -64,11 +64,11 @@ func GetActiveLeaf(channelID, userID string) (*string, error) {
// Fallback: latest live message in channel
var fallbackID string
err = database.DB.QueryRow(`
err = database.DB.QueryRow(database.Q(`
SELECT id FROM messages
WHERE channel_id = $1 AND deleted_at IS NULL
ORDER BY created_at DESC LIMIT 1
`, channelID).Scan(&fallbackID)
`), channelID).Scan(&fallbackID)
if err == sql.ErrNoRows {
return nil, nil // empty channel
}
@@ -96,7 +96,7 @@ func GetActivePath(channelID, userID string) ([]PathMessage, error) {
// GetPathToLeaf walks from a specific leaf up to root, returning root-first.
func GetPathToLeaf(channelID, leafID string) ([]PathMessage, error) {
rows, err := database.DB.Query(`
rows, err := database.DB.Query(database.Q(`
WITH RECURSIVE path AS (
-- Anchor: start at the leaf
SELECT id, parent_id, role, content, model, tokens_used, tool_calls, metadata,
@@ -119,7 +119,7 @@ func GetPathToLeaf(channelID, leafID string) ([]PathMessage, error) {
participant_type, participant_id, sibling_index, created_at
FROM path
ORDER BY depth DESC
`, leafID, channelID)
`), leafID, channelID)
if err != nil {
return nil, fmt.Errorf("GetPathToLeaf: %w", err)
}