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.
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: direct_room.sql
package store
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const directRoomPeerIsActive = `-- name: DirectRoomPeerIsActive :one
SELECT coalesce((
SELECT registration.status='active'
FROM rooms direct
JOIN agent_registrations registration
ON registration.actor_id=direct.direct_agent_actor_id
AND registration.tenant_id=direct.tenant_id
WHERE direct.id=$1::text
),true)::boolean
`
// An Agent syncing its configuration is still a live peer: its direct Room
// takes messages and cannot be deleted.
func (q *Queries) DirectRoomPeerIsActive(ctx context.Context, roomID string) (bool, error) {
row := q.db.QueryRow(ctx, directRoomPeerIsActive, roomID)
var column_1 bool
err := row.Scan(&column_1)
return column_1, err
}
const getCurrentDirectRoom = `-- name: GetCurrentDirectRoom :one
SELECT room.id
FROM rooms room
JOIN active_room_members member
ON member.room_id=room.id AND member.tenant_id=room.tenant_id AND member.actor_id=room.direct_agent_actor_id
WHERE room.tenant_id=$1::text
AND room.direct_human_actor_id=$2::text
AND room.direct_agent_actor_id=$3::text
AND room.deletion_started_at IS NULL
`
type GetCurrentDirectRoomParams struct {
TenantID string `json:"tenant_id"`
HumanActorID string `json:"human_actor_id"`
AgentActorID string `json:"agent_actor_id"`
}
// The pair's direct Room while it is not being deleted and the Agent is still
// in it. Lookups that only use a direct Room read it here; opening one goes
// through roomcreation.OpenOrCreateDirectRoom.
func (q *Queries) GetCurrentDirectRoom(ctx context.Context, arg GetCurrentDirectRoomParams) (string, error) {
row := q.db.QueryRow(ctx, getCurrentDirectRoom, arg.TenantID, arg.HumanActorID, arg.AgentActorID)
var id string
err := row.Scan(&id)
return id, err
}
const getDirectRoom = `-- name: GetDirectRoom :one
SELECT id AS room_id,tenant_id,
direct_human_actor_id::text AS human_actor_id,
direct_agent_actor_id::text AS agent_actor_id
FROM rooms
WHERE id=$1::text AND direct_agent_actor_id IS NOT NULL
`
type GetDirectRoomRow struct {
RoomID string `json:"room_id"`
TenantID string `json:"tenant_id"`
HumanActorID string `json:"human_actor_id"`
AgentActorID string `json:"agent_actor_id"`
}
func (q *Queries) GetDirectRoom(ctx context.Context, roomID string) (GetDirectRoomRow, error) {
row := q.db.QueryRow(ctx, getDirectRoom, roomID)
var i GetDirectRoomRow
err := row.Scan(
&i.RoomID,
&i.TenantID,
&i.HumanActorID,
&i.AgentActorID,
)
return i, err
}
const getDirectRoomByPair = `-- name: GetDirectRoomByPair :one
SELECT id,tenant_id,name,description,created_by_actor_id,
next_room_seq,created_at,updated_at,
deletion_started_at,deletion_started_by_actor_id,
deleted_at,deleted_by_actor_id,
direct_human_actor_id,direct_agent_actor_id,parent_room_id,root_message_id,
team_md_raw_markdown,team_md_collaborate_pattern,team_md_document,
team_md_revision,team_md_updated_at,team_md_updated_by_actor_id
FROM rooms
WHERE tenant_id=$1::text
AND direct_human_actor_id=$2::text
AND direct_agent_actor_id=$3::text
`
type GetDirectRoomByPairParams struct {
TenantID string `json:"tenant_id"`
HumanActorID string `json:"human_actor_id"`
AgentActorID string `json:"agent_actor_id"`
}
// The pair's Room, whether live, being deleted or deleted: at most one Room
// holds a pair.
func (q *Queries) GetDirectRoomByPair(ctx context.Context, arg GetDirectRoomByPairParams) (Room, error) {
row := q.db.QueryRow(ctx, getDirectRoomByPair, arg.TenantID, arg.HumanActorID, arg.AgentActorID)
var i Room
err := row.Scan(
&i.ID,
&i.TenantID,
&i.Name,
&i.Description,
&i.CreatedByActorID,
&i.NextRoomSeq,
&i.CreatedAt,
&i.UpdatedAt,
&i.DeletionStartedAt,
&i.DeletionStartedByActorID,
&i.DeletedAt,
&i.DeletedByActorID,
&i.DirectHumanActorID,
&i.DirectAgentActorID,
&i.ParentRoomID,
&i.RootMessageID,
&i.TeamMdRawMarkdown,
&i.TeamMdCollaboratePattern,
&i.TeamMdDocument,
&i.TeamMdRevision,
&i.TeamMdUpdatedAt,
&i.TeamMdUpdatedByActorID,
)
return i, err
}
const getDirectRoomPeerForAccount = `-- name: GetDirectRoomPeerForAccount :one
SELECT peer.id,peer.tenant_id,peer.kind,peer.display_name,
peer.account_id,peer.handle,peer.created_at,
(registration.status='active')::boolean AS active
FROM rooms direct
JOIN actors caller
ON caller.id=direct.direct_human_actor_id
AND caller.tenant_id=direct.tenant_id
AND caller.account_id=$1::text
AND caller.kind='human'
JOIN active_room_members caller_membership
ON caller_membership.room_id=direct.id AND caller_membership.actor_id=caller.id
JOIN actors peer
ON peer.id=direct.direct_agent_actor_id AND peer.tenant_id=direct.tenant_id
JOIN agent_registrations registration
ON registration.actor_id=peer.id AND registration.tenant_id=peer.tenant_id
WHERE direct.id=$2::text
`
type GetDirectRoomPeerForAccountParams struct {
AccountID string `json:"account_id"`
RoomID string `json:"room_id"`
}
type GetDirectRoomPeerForAccountRow struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
Kind string `json:"kind"`
DisplayName string `json:"display_name"`
AccountID pgtype.Text `json:"account_id"`
Handle pgtype.Text `json:"handle"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
Active bool `json:"active"`
}
func (q *Queries) GetDirectRoomPeerForAccount(ctx context.Context, arg GetDirectRoomPeerForAccountParams) (GetDirectRoomPeerForAccountRow, error) {
row := q.db.QueryRow(ctx, getDirectRoomPeerForAccount, arg.AccountID, arg.RoomID)
var i GetDirectRoomPeerForAccountRow
err := row.Scan(
&i.ID,
&i.TenantID,
&i.Kind,
&i.DisplayName,
&i.AccountID,
&i.Handle,
&i.CreatedAt,
&i.Active,
)
return i, err
}
const getVisibleActiveAgentForDirectRoom = `-- name: GetVisibleActiveAgentForDirectRoom :one
SELECT agent.id,agent.tenant_id,agent.kind,agent.display_name,
agent.account_id,agent.handle,agent.created_at,
registration.created_by_actor_id,registration.visibility_scope
FROM agent_registrations registration
JOIN actors agent
ON agent.id=registration.actor_id AND agent.tenant_id=registration.tenant_id
WHERE registration.tenant_id=$1::text
AND registration.actor_id=$2::text
AND registration.status='active'
AND agent.kind='agent'
AND (
registration.visibility_scope='workspace' OR
registration.created_by_actor_id=$3::text OR
EXISTS (
SELECT 1
FROM active_room_members human_membership
JOIN active_room_members agent_membership
ON agent_membership.room_id=human_membership.room_id
AND agent_membership.actor_id=registration.actor_id
WHERE human_membership.actor_id=$3::text
)
)
FOR SHARE OF registration
`
type GetVisibleActiveAgentForDirectRoomParams struct {
TenantID string `json:"tenant_id"`
AgentActorID string `json:"agent_actor_id"`
HumanActorID string `json:"human_actor_id"`
}
type GetVisibleActiveAgentForDirectRoomRow struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
Kind string `json:"kind"`
DisplayName string `json:"display_name"`
AccountID pgtype.Text `json:"account_id"`
Handle pgtype.Text `json:"handle"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
CreatedByActorID string `json:"created_by_actor_id"`
VisibilityScope string `json:"visibility_scope"`
}
func (q *Queries) GetVisibleActiveAgentForDirectRoom(ctx context.Context, arg GetVisibleActiveAgentForDirectRoomParams) (GetVisibleActiveAgentForDirectRoomRow, error) {
row := q.db.QueryRow(ctx, getVisibleActiveAgentForDirectRoom, arg.TenantID, arg.AgentActorID, arg.HumanActorID)
var i GetVisibleActiveAgentForDirectRoomRow
err := row.Scan(
&i.ID,
&i.TenantID,
&i.Kind,
&i.DisplayName,
&i.AccountID,
&i.Handle,
&i.CreatedAt,
&i.CreatedByActorID,
&i.VisibilityScope,
)
return i, err
}
const isDirectRoom = `-- name: IsDirectRoom :one
SELECT EXISTS(
SELECT 1 FROM rooms WHERE id=$1::text AND direct_agent_actor_id IS NOT NULL
)::boolean
`
func (q *Queries) IsDirectRoom(ctx context.Context, roomID string) (bool, error) {
row := q.db.QueryRow(ctx, isDirectRoom, roomID)
var column_1 bool
err := row.Scan(&column_1)
return column_1, err
}
const markDirectRoom = `-- name: MarkDirectRoom :one
UPDATE rooms
SET direct_human_actor_id=$1::text,
direct_agent_actor_id=$2::text
WHERE id=$3::text AND tenant_id=$4::text
RETURNING id
`
type MarkDirectRoomParams struct {
HumanActorID string `json:"human_actor_id"`
AgentActorID string `json:"agent_actor_id"`
RoomID string `json:"room_id"`
TenantID string `json:"tenant_id"`
}
func (q *Queries) MarkDirectRoom(ctx context.Context, arg MarkDirectRoomParams) (string, error) {
row := q.db.QueryRow(ctx, markDirectRoom,
arg.HumanActorID,
arg.AgentActorID,
arg.RoomID,
arg.TenantID,
)
var id string
err := row.Scan(&id)
return id, err
}
const releaseFinishedDirectRoomPair = `-- name: ReleaseFinishedDirectRoomPair :exec
UPDATE rooms
SET direct_human_actor_id=NULL,direct_agent_actor_id=NULL
WHERE tenant_id=$1::text
AND direct_human_actor_id=$2::text
AND direct_agent_actor_id=$3::text
AND deleted_at IS NOT NULL
`
type ReleaseFinishedDirectRoomPairParams struct {
TenantID string `json:"tenant_id"`
HumanActorID string `json:"human_actor_id"`
AgentActorID string `json:"agent_actor_id"`
}
// Reopening a pair whose Room finished deletion leaves that Room as history:
// it stops holding the pair before MarkDirectRoom gives it to the new Room. A
// live or deleting Room is never released.
func (q *Queries) ReleaseFinishedDirectRoomPair(ctx context.Context, arg ReleaseFinishedDirectRoomPairParams) error {
_, err := q.db.Exec(ctx, releaseFinishedDirectRoomPair, arg.TenantID, arg.HumanActorID, arg.AgentActorID)
return err
}