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.

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

package store

import (
	"context"
)

const getAgentContextReadRoom = `-- name: GetAgentContextReadRoom :one
SELECT room.id AS room_id, collaboration_membership_room_id(room.id)::text AS membership_room_id,
 coalesce((SELECT max(event.room_seq) FROM room_events event
 WHERE event.room_id=collaboration_membership_room_id(room.id)
 AND event.event_type IN ('room.member.added','room.member.role_changed','room.member.removed')),0)::bigint AS membership_revision
FROM rooms room
WHERE room.id=agent_inbox_resource_room($1::text,$2::text)
 AND room.tenant_id=$1::text
 AND actor_can_read_inbox($1::text,$3::text,$2::text)
`

type GetAgentContextReadRoomParams struct {
	TenantID string `json:"tenant_id"`
	InboxID  string `json:"inbox_id"`
	ActorID  string `json:"actor_id"`
}

type GetAgentContextReadRoomRow struct {
	RoomID             string `json:"room_id"`
	MembershipRoomID   string `json:"membership_room_id"`
	MembershipRevision int64  `json:"membership_revision"`
}

func (q *Queries) GetAgentContextReadRoom(ctx context.Context, arg GetAgentContextReadRoomParams) (GetAgentContextReadRoomRow, error) {
	row := q.db.QueryRow(ctx, getAgentContextReadRoom, arg.TenantID, arg.InboxID, arg.ActorID)
	var i GetAgentContextReadRoomRow
	err := row.Scan(&i.RoomID, &i.MembershipRoomID, &i.MembershipRevision)
	return i, err
}

const listAgentContextReadRoomMembers = `-- name: ListAgentContextReadRoomMembers :many
WITH members AS (
 SELECT actor.id AS actor_id,actor.kind,actor.display_name
 FROM active_room_members member JOIN actors actor ON actor.id=member.actor_id AND actor.tenant_id=member.tenant_id
 WHERE member.tenant_id=$1::text AND member.room_id=$2::text
 UNION
 SELECT actor.id,actor.kind,actor.display_name FROM rooms thread
 JOIN messages root ON root.id=thread.root_message_id AND root.tenant_id=thread.tenant_id
 JOIN actors actor ON actor.id=root.author_actor_id AND actor.tenant_id=thread.tenant_id
 JOIN active_room_members parent_member ON parent_member.room_id=thread.parent_room_id AND parent_member.actor_id=actor.id AND parent_member.tenant_id=thread.tenant_id
 WHERE thread.id=$2::text AND thread.tenant_id=$1::text
 UNION
 SELECT actor.id,actor.kind,actor.display_name FROM thread_room_list_actors listed
 JOIN rooms thread ON thread.id=listed.thread_room_id AND thread.tenant_id=listed.tenant_id
 JOIN actors actor ON actor.id=listed.actor_id AND actor.tenant_id=listed.tenant_id
 JOIN active_room_members parent_member ON parent_member.room_id=thread.parent_room_id AND parent_member.actor_id=actor.id AND parent_member.tenant_id=thread.tenant_id
 WHERE thread.id=$2::text AND thread.tenant_id=$1::text
)
SELECT members.actor_id,members.kind,members.display_name,
 coalesce(registration.agent_type,'')::text AS agent_type,
 coalesce(registration.description,'')::text AS description
FROM members LEFT JOIN agent_registrations registration
 ON registration.actor_id=members.actor_id AND registration.tenant_id=$1::text AND members.kind='agent'
ORDER BY members.actor_id
`

type ListAgentContextReadRoomMembersParams struct {
	TenantID string `json:"tenant_id"`
	RoomID   string `json:"room_id"`
}

type ListAgentContextReadRoomMembersRow struct {
	ActorID     string `json:"actor_id"`
	Kind        string `json:"kind"`
	DisplayName string `json:"display_name"`
	AgentType   string `json:"agent_type"`
	Description string `json:"description"`
}

func (q *Queries) ListAgentContextReadRoomMembers(ctx context.Context, arg ListAgentContextReadRoomMembersParams) ([]ListAgentContextReadRoomMembersRow, error) {
	rows, err := q.db.Query(ctx, listAgentContextReadRoomMembers, arg.TenantID, arg.RoomID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAgentContextReadRoomMembersRow{}
	for rows.Next() {
		var i ListAgentContextReadRoomMembersRow
		if err := rows.Scan(
			&i.ActorID,
			&i.Kind,
			&i.DisplayName,
			&i.AgentType,
			&i.Description,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}