Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
2.0 KB
Raw Blame
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: conversation_root.sql

package db

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const listConversationRootOwners = `-- name: ListConversationRootOwners :many
SELECT DISTINCT ON (agent_id) agent_id, squad_id
FROM agent_task_queue t
WHERE t.issue_id = $1 AND t.agent_id IS NOT NULL
  AND (t.trigger_comment_id = $2 OR $2 = ANY(t.coalesced_comment_ids) OR EXISTS (
      SELECT 1 FROM task_supplement s
      WHERE s.task_id = t.id AND s.issue_id = t.issue_id
        AND s.comment_id = $2 AND s.status = 'delivered'
  ))
ORDER BY agent_id, (squad_id IS NOT NULL) DESC, created_at DESC, id DESC
`

type ListConversationRootOwnersParams struct {
	IssueID          pgtype.UUID `json:"issue_id"`
	TriggerCommentID pgtype.UUID `json:"trigger_comment_id"`
}

type ListConversationRootOwnersRow struct {
	AgentID pgtype.UUID `json:"agent_id"`
	SquadID pgtype.UUID `json:"squad_id"`
}

// Preserve the newest non-null squad per agent, including terminal tasks.
// A root folded into a queued task keeps its owner after the merge repoints
// trigger_comment_id at the newer comment and moves the root into
// coalesced_comment_ids (MUL-8416).
// A delivered supplement establishes ownership even when the root did not
// start a separate task. Pending or failed delivery does not establish it.
// Routing does not need execution context, results, or other issue threads.
func (q *Queries) ListConversationRootOwners(ctx context.Context, arg ListConversationRootOwnersParams) ([]ListConversationRootOwnersRow, error) {
	rows, err := q.db.Query(ctx, listConversationRootOwners, arg.IssueID, arg.TriggerCommentID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListConversationRootOwnersRow{}
	for rows.Next() {
		var i ListConversationRootOwnersRow
		if err := rows.Scan(&i.AgentID, &i.SquadID); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}