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.4 KB
Raw Blame
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: skill_context_generation.sql

package store

import (
	"context"

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

const acquireUnifiedSkillPolicyExclusiveLock = `-- name: AcquireUnifiedSkillPolicyExclusiveLock :exec
SELECT pg_advisory_xact_lock(hashtextextended('unified-agent-skill-policy',0))
`

func (q *Queries) AcquireUnifiedSkillPolicyExclusiveLock(ctx context.Context) error {
	_, err := q.db.Exec(ctx, acquireUnifiedSkillPolicyExclusiveLock)
	return err
}

const acquireUnifiedSkillPolicySharedLock = `-- name: AcquireUnifiedSkillPolicySharedLock :exec
SELECT pg_advisory_xact_lock_shared(hashtextextended('unified-agent-skill-policy',0))
`

func (q *Queries) AcquireUnifiedSkillPolicySharedLock(ctx context.Context) error {
	_, err := q.db.Exec(ctx, acquireUnifiedSkillPolicySharedLock)
	return err
}

const getAgentSkillPackageManifest = `-- name: GetAgentSkillPackageManifest :one
SELECT manifest.manifest_id,manifest.content_hash,manifest.package_state,
       skill.name,skill.owner_kind,skill.tenant_id,skill.access_scope,skill.owner_actor_id,
       manifest.state
FROM skill_manifests manifest
JOIN skills skill ON skill.skill_id=manifest.skill_id
WHERE manifest.manifest_id=$1
`

type GetAgentSkillPackageManifestRow struct {
	ManifestID   string      `json:"manifest_id"`
	ContentHash  []byte      `json:"content_hash"`
	PackageState string      `json:"package_state"`
	Name         string      `json:"name"`
	OwnerKind    string      `json:"owner_kind"`
	TenantID     pgtype.Text `json:"tenant_id"`
	AccessScope  string      `json:"access_scope"`
	OwnerActorID pgtype.Text `json:"owner_actor_id"`
	State        string      `json:"state"`
}

func (q *Queries) GetAgentSkillPackageManifest(ctx context.Context, manifestID string) (GetAgentSkillPackageManifestRow, error) {
	row := q.db.QueryRow(ctx, getAgentSkillPackageManifest, manifestID)
	var i GetAgentSkillPackageManifestRow
	err := row.Scan(
		&i.ManifestID,
		&i.ContentHash,
		&i.PackageState,
		&i.Name,
		&i.OwnerKind,
		&i.TenantID,
		&i.AccessScope,
		&i.OwnerActorID,
		&i.State,
	)
	return i, err
}

const getSkillAgentForShare = `-- name: GetSkillAgentForShare :one
SELECT actor_id,tenant_id,agent_management_id,agent_type
FROM agent_registrations
WHERE actor_id=$1::text
  AND tenant_id=$2::text
  AND status='active'
FOR SHARE
`

type GetSkillAgentForShareParams struct {
	AgentActorID string `json:"agent_actor_id"`
	TenantID     string `json:"tenant_id"`
}

type GetSkillAgentForShareRow struct {
	ActorID           string      `json:"actor_id"`
	TenantID          string      `json:"tenant_id"`
	AgentManagementID pgtype.Text `json:"agent_management_id"`
	AgentType         string      `json:"agent_type"`
}

func (q *Queries) GetSkillAgentForShare(ctx context.Context, arg GetSkillAgentForShareParams) (GetSkillAgentForShareRow, error) {
	row := q.db.QueryRow(ctx, getSkillAgentForShare, arg.AgentActorID, arg.TenantID)
	var i GetSkillAgentForShareRow
	err := row.Scan(
		&i.ActorID,
		&i.TenantID,
		&i.AgentManagementID,
		&i.AgentType,
	)
	return i, err
}

const listAgentSkillPackageFiles = `-- name: ListAgentSkillPackageFiles :many
SELECT file.path::text AS path,file.media_type::text AS media_type,file.size_bytes::bigint AS size_bytes,
       decode(file.sha256,'hex')::bytea AS sha256,file.object_key::text AS object_key
FROM skill_manifests manifest
CROSS JOIN LATERAL jsonb_to_recordset(manifest.files)
    AS file(path text,media_type text,size_bytes bigint,sha256 text,object_key text)
WHERE manifest.manifest_id=$1
ORDER BY file.path COLLATE "C"
`

type ListAgentSkillPackageFilesRow struct {
	Path      string `json:"path"`
	MediaType string `json:"media_type"`
	SizeBytes int64  `json:"size_bytes"`
	Sha256    []byte `json:"sha256"`
	ObjectKey string `json:"object_key"`
}

func (q *Queries) ListAgentSkillPackageFiles(ctx context.Context, manifestID string) ([]ListAgentSkillPackageFilesRow, error) {
	rows, err := q.db.Query(ctx, listAgentSkillPackageFiles, manifestID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAgentSkillPackageFilesRow{}
	for rows.Next() {
		var i ListAgentSkillPackageFilesRow
		if err := rows.Scan(
			&i.Path,
			&i.MediaType,
			&i.SizeBytes,
			&i.Sha256,
			&i.ObjectKey,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}