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.

3.1 KB
Raw Blame
import type { Message } from "@/i18n/messages";
import { useT } from "@/i18n/use-translation";

import type {
  RuntimeActivityContentBlock,
  RuntimeActivityEntry,
  RuntimeActivityPresentation,
} from "./runtime-presentation-events";
import { runtimeStatusMessages as m } from "./runtime-status.messages";

const outcomeLabels: Record<
  NonNullable<RuntimeActivityPresentation["outcome"]>,
  Message<string>
> = {
  canceled: m.outcomeCanceled,
  declined: m.outcomeDeclined,
  failed: m.outcomeFailed,
  succeeded: m.outcomeSucceeded,
};

/**
 * One step's details: the tool the Runtime called, how it ended once it has,
 * and the public blocks the Computer published for it.
 */
export function RuntimeActivityEntries({
  entries,
  outcome,
  title,
  tool,
}: {
  entries: readonly RuntimeActivityEntry[];
  outcome?: RuntimeActivityPresentation["outcome"];
  title: string;
  tool: string;
}) {
  const t = useT();
  return (
    <div
      aria-label={t(m.stepDetails, { title })}
      className="mt-1.5 space-y-1.5"
    >
      <dl className="grid grid-cols-[auto_minmax(0,1fr)] gap-x-2 gap-y-0.5 text-[12px] leading-4">
        <dt className="text-app-subtle">{t(m.tool)}</dt>
        <dd className="break-all font-mono text-app-body">{tool}</dd>
        {outcome ? (
          <>
            <dt className="text-app-subtle">{t(m.outcome)}</dt>
            <dd
              className={
                outcome === "failed" ? "text-app-danger" : "text-app-body"
              }
            >
              {t(outcomeLabels[outcome])}
            </dd>
          </>
        ) : null}
      </dl>
      {entries.map((entry, index) =>
        entry.type === "content" ? (
          <RuntimeActivityContentBlockView
            block={entry.block}
            key={JSON.stringify([
              entry.type,
              entry.block.format,
              entry.block.label,
              index,
            ])}
          />
        ) : (
          <div
            className="flex min-w-0 items-start gap-1.5 text-[12px] leading-4 text-app-muted"
            key={JSON.stringify([entry.type, entry.detail, index])}
          >
            <span
              aria-hidden="true"
              className="mt-[0.45rem] size-1 shrink-0 rounded-full bg-app-border-strong"
            />
            <span className="min-w-0 break-words">{entry.detail}</span>
          </div>
        ),
      )}
    </div>
  );
}

function RuntimeActivityContentBlockView({
  block,
}: {
  block: RuntimeActivityContentBlock;
}) {
  return (
    <div>
      {block.label ? (
        <p className="mb-0.5 text-[10px] font-medium uppercase text-app-subtle">
          {block.label}
        </p>
      ) : null}
      {block.format === "text" ? (
        <p className="whitespace-pre-wrap break-words text-[12px] leading-4 text-app-muted">
          {block.content}
        </p>
      ) : (
        <pre className="workspace-scrollbar max-w-full overflow-x-auto whitespace-pre-wrap break-words rounded-sm border border-app-border bg-app-surface-soft px-2 py-1.5 text-[12px] leading-4 text-app-body">
          <code>{block.content}</code>
        </pre>
      )}
    </div>
  );
}