Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

6.1 KB
Raw Blame
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: task_runtime_presentation.sql

package store

import (
	"context"

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

const getAgentRuntimeTaskParticipantRoom = `-- name: GetAgentRuntimeTaskParticipantRoom :one
SELECT link.room_id
FROM work_items item
JOIN task_execution_generations generation
  ON generation.task_id=item.id AND generation.tenant_id=item.tenant_id
 AND generation.generation=item.task_execution_generation
 AND generation.terminal_at IS NULL
JOIN task_execution_participants participant
  ON participant.task_id=item.id AND participant.tenant_id=item.tenant_id
 AND participant.generation=generation.generation
 AND participant.actor_id=$1::text
 AND participant.agent_management_id=$2::text
JOIN agent_registrations registration
  ON registration.actor_id=participant.actor_id
 AND registration.agent_management_id=participant.agent_management_id
 AND registration.tenant_id=item.tenant_id AND registration.status='active'
JOIN work_item_room_links link
  ON link.work_item_id=item.id AND link.tenant_id=item.tenant_id AND link.link_type='work'
JOIN rooms room ON room.id=link.room_id AND room.tenant_id=item.tenant_id
 AND room.deleted_at IS NULL AND room.deletion_started_at IS NULL
WHERE item.id=$3::text AND item.tenant_id=$4::text
  AND item.kind='task' AND item.archived_at IS NULL
`

type GetAgentRuntimeTaskParticipantRoomParams struct {
	AgentActorID      string `json:"agent_actor_id"`
	AgentManagementID string `json:"agent_management_id"`
	TaskID            string `json:"task_id"`
	TenantID          string `json:"tenant_id"`
}

func (q *Queries) GetAgentRuntimeTaskParticipantRoom(ctx context.Context, arg GetAgentRuntimeTaskParticipantRoomParams) (string, error) {
	row := q.db.QueryRow(ctx, getAgentRuntimeTaskParticipantRoom,
		arg.AgentActorID,
		arg.AgentManagementID,
		arg.TaskID,
		arg.TenantID,
	)
	var room_id string
	err := row.Scan(&room_id)
	return room_id, err
}

const getTaskRuntimePresentationRoomForAccount = `-- name: GetTaskRuntimePresentationRoomForAccount :one
SELECT room.id
FROM work_item_room_links link
JOIN rooms room ON room.id=link.room_id AND room.tenant_id=link.tenant_id
 AND room.deleted_at IS NULL AND room.deletion_started_at IS NULL
JOIN actors caller ON caller.tenant_id=room.tenant_id
 AND caller.account_id=$1::text AND caller.kind='human'
JOIN active_room_members membership
  ON membership.room_id=room.id AND membership.actor_id=caller.id
WHERE link.work_item_id=$2::text AND link.link_type='work'
  AND room_actor_participating(room.id,caller.id)
`

type GetTaskRuntimePresentationRoomForAccountParams struct {
	AccountID string `json:"account_id"`
	TaskID    string `json:"task_id"`
}

func (q *Queries) GetTaskRuntimePresentationRoomForAccount(ctx context.Context, arg GetTaskRuntimePresentationRoomForAccountParams) (string, error) {
	row := q.db.QueryRow(ctx, getTaskRuntimePresentationRoomForAccount, arg.AccountID, arg.TaskID)
	var id string
	err := row.Scan(&id)
	return id, err
}

const listTaskRuntimePresentationRuns = `-- name: ListTaskRuntimePresentationRuns :many
SELECT run.run_id,run.status,run.status_room_id::text AS room_id,run.created_at,run.updated_at,
       context.agent_actor_id,actor.kind AS agent_kind,actor.display_name AS agent_display_name,
       coalesce((SELECT max(event.event_ordinal) FROM agent_runtime_status_events event
                 WHERE event.local_run_id=run.run_id),0)::bigint AS event_ordinal,
       COALESCE(CASE WHEN run.status='canceled' THEN left(run.terminal->>'reason',1000) END,'')::text AS stop_reason,
       agent_local_run_replied(run.run_id)::boolean AS replied
FROM agent_local_runs run
JOIN agent_execution_contexts context ON context.context_key=run.context_key
JOIN actors actor ON actor.id=context.agent_actor_id AND actor.tenant_id=context.tenant_id
WHERE context.task_id=$1::text
  AND context.tenant_id=$2::text
  AND run.status_room_id=$3::text
  AND (NOT $4::boolean OR run.status IN ('queued','running'))
  AND ($5::timestamptz IS NULL
    OR (run.created_at,run.run_id)<($5::timestamptz,$6::text))
ORDER BY run.created_at DESC,run.run_id DESC
LIMIT $7::integer
`

type ListTaskRuntimePresentationRunsParams struct {
	TaskID          string             `json:"task_id"`
	TenantID        string             `json:"tenant_id"`
	RoomID          string             `json:"room_id"`
	ActiveOnly      bool               `json:"active_only"`
	BeforeCreatedAt pgtype.Timestamptz `json:"before_created_at"`
	BeforeRunID     string             `json:"before_run_id"`
	ResultLimit     pgtype.Int4        `json:"result_limit"`
}

type ListTaskRuntimePresentationRunsRow struct {
	RunID            string             `json:"run_id"`
	Status           string             `json:"status"`
	RoomID           string             `json:"room_id"`
	CreatedAt        pgtype.Timestamptz `json:"created_at"`
	UpdatedAt        pgtype.Timestamptz `json:"updated_at"`
	AgentActorID     string             `json:"agent_actor_id"`
	AgentKind        string             `json:"agent_kind"`
	AgentDisplayName string             `json:"agent_display_name"`
	EventOrdinal     int64              `json:"event_ordinal"`
	StopReason       string             `json:"stop_reason"`
	Replied          bool               `json:"replied"`
}

func (q *Queries) ListTaskRuntimePresentationRuns(ctx context.Context, arg ListTaskRuntimePresentationRunsParams) ([]ListTaskRuntimePresentationRunsRow, error) {
	rows, err := q.db.Query(ctx, listTaskRuntimePresentationRuns,
		arg.TaskID,
		arg.TenantID,
		arg.RoomID,
		arg.ActiveOnly,
		arg.BeforeCreatedAt,
		arg.BeforeRunID,
		arg.ResultLimit,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListTaskRuntimePresentationRunsRow{}
	for rows.Next() {
		var i ListTaskRuntimePresentationRunsRow
		if err := rows.Scan(
			&i.RunID,
			&i.Status,
			&i.RoomID,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.AgentActorID,
			&i.AgentKind,
			&i.AgentDisplayName,
			&i.EventOrdinal,
			&i.StopReason,
			&i.Replied,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}