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.

2.9 KB
Raw Blame
import type {
  TeamHubAgentTemplate,
  TeamHubAgentTemplatePublishInput,
  TeamHubTenantAgent,
} from "@/features/teamhub/teamhub-types";
import { type Translate, translate } from "@/i18n/language";

import type { AgentAvatarKey } from "../members/agent-avatar";

import { agentTemplateMessages as m } from "./agent-templates.messages";

/**
 * The portable part of an Agent: identity text, instructions, and the Skill
 * and Connector selections. Runtime provider, model, reasoning effort, and
 * Local Computer stay with the Agent because they describe where it runs, not
 * what it is.
 */
export function agentTemplateFromAgent(
  agent: TeamHubTenantAgent,
  avatarKey?: AgentAvatarKey,
  connectorKeys: readonly string[] = [],
): TeamHubAgentTemplatePublishInput {
  const avatar = avatarKey ?? agent.avatar_key;
  return {
    source_agent_actor_id: agent.actor.id,
    name: agent.actor.display_name.trim(),
    description: agent.description,
    instructions: agent.instructions,
    ...(avatar ? { avatar_key: avatar } : {}),
    // Managed platform defaults are attached by TeamHub to every new Agent, so
    // carrying them would duplicate them rather than reproduce this Agent.
    skill_bindings: agent.skill_bindings.flatMap((binding) =>
      binding.is_default
        ? []
        : [
            {
              manifest_version: binding.manifest_version,
              name: binding.name,
              skill_id: binding.skill_id,
            },
          ],
    ),
    // Only the App key travels. The publisher's connection, account and
    // credentials stay with them; whoever uses the template authorizes their
    // own accounts after the Agent exists.
    connector_bindings: [...new Set(connectorKeys)],
  };
}

export type TemplateResourceCounts = Pick<
  TeamHubAgentTemplate,
  "connector_bindings" | "skill_bindings"
> &
  Partial<Pick<TeamHubAgentTemplate, "routines">>;

/**
 * One label per resource kind the template carries, so a card can show which
 * kinds it has rather than one string that has to be read apart. Kinds the
 * template does not carry are left out entirely.
 */
export function templateResourceChips(
  template: TemplateResourceCounts,
  t: Translate = translate,
) {
  const skills = template.skill_bindings.length;
  const routines = template.routines?.length ?? 0;
  const connectors = template.connector_bindings?.length ?? 0;
  return [
    skills ? t(m.skillCount, { count: skills }) : "",
    routines ? t(m.routineCount, { count: routines }) : "",
    connectors ? t(m.connectorCount, { count: connectors }) : "",
  ].filter((part) => part !== "");
}

/** Single-line summary, for places that have room for only one string. */
export function templateResourceSummary(
  template: TemplateResourceCounts,
  t: Translate = translate,
) {
  const parts = templateResourceChips(template, t);
  return parts.length ? parts.join(" · ") : t(m.instructionsOnly);
}