# Records list

Three to eight records of one type, each with one line of detail and a value or status. Each row opens the record in your app; a footer link leads to the rest.

{/* Generated by scripts/build-ui-catalog.mjs from src/ui-catalog/. Do not edit. */}

Three to eight records of one type, each with one line of detail and a value or status. Each row opens the record in your app; a footer link leads to the rest.

## When to use it

**Use it when:** The answer is a short list of records of one type (open tickets, deals closing soon, recent orders): 3–8 rows, each with a title, one line of detail and a value or status. Rows open the record in your app.

**Use something else when:** One record (entity card). The user needs to compare several columns or sort (paginated table). The user must pick one to go on (picker).

## What the agent receives

| The template calls | The agent gets | When |
| --- | --- | --- |
| `displayed()` | `FUNCTION_TOOL_DISPLAYED` | As soon as the card shows. The agent goes on. Opening a row is your app's job. |

## States

Besides its data, the template draws these as itself, with `mountState()`. Pick one on the preview with **State**.

| State | When it shows |
| --- | --- |
| Loading | While the list loads again in place, for example after Try again or a refresh. While execute runs, the SDK shows its own loader. |
| Empty | execute found no records. The card says so and the agent explains why. |
| Error | execute returned the failure as data, so the agent can explain it. Try again loads the rows in place. |

```ts
mountState({ root, head, title: "…", state: { kind: "error", text: "…", retry } });
```

The hosted action and the in-page handler below show each case. The state types are `LoadingState`, `EmptyState` and `ErrorState` in fs-kit.

## Data

### RecordsListData

| Field | Type | Notes |
| --- | --- | --- |
| `title` | `string` |  |
| `subtitle` (optional) | `string` |  |
| `icon` (optional) | `IconName` |  |
| `records` | `ListRecord[]` | 3–8 rows. More are cut. |
| `total` (optional) | `number` | How many there are in all. When it's more than the rows shown, the footer links to the rest. |
| `noun` (optional) | `string` | What the rows are, plural, for "Show all 12 deals". Default: "records". |
| `allHref` (optional) | `string` | Where "Show all" goes. Without it, the link calls actions.showAll (when given). |
| `avatarShape` (optional) | `"square" \| "circle"` | "square" (default) for companies and things, "circle" for people. |
| `footnote` (optional) | `string` | Short note on the left of the footer, e.g. "Sorted by close date". |
| `emptyText` (optional) | `string` | Shown instead of rows when records is empty. |

### ListRecord

| Field | Type | Notes |
| --- | --- | --- |
| `id` | `string` | Your record's id: actions.open gets the record back. |
| `title` | `string` |  |
| `meta` (optional) | `string` | The one line under the title, e.g. "Acme Logistics · closes Nov 28". |
| `avatar` (optional) | `string` | Name for the leading avatar's initials (a person or a company). Default: the title. |
| `avatarUrl` (optional) | `string` | Logo or photo for the leading avatar. Falls back to initials. |
| `icon` (optional) | `IconName` | A leading icon instead of an avatar. |
| `value` (optional) | `string \| number` | Trailing value. A number is formatted with format. |
| `format` (optional) | `NumberFormat` |  |
| `status` (optional) | `ListStatus` |  |
| `href` (optional) | `string` | Opens the record in your app. Without it, the row calls actions.open (when given). |

### ListStatus

| Field | Type | Notes |
| --- | --- | --- |
| `label` | `string` |  |
| `tone` (optional) | `ListTone` | neutral (default), info, success, warning, error. |

### RecordsListActions

| Field | Type | Notes |
| --- | --- | --- |
| `open()` (optional) | `(record: ListRecord) => void` | A row without href was clicked. Open the record in your app. |
| `showAll()` (optional) | `() => void` | "Show all" was clicked and there's no allHref. |

## Install

Copy the template and the shared kit into your code: `agent/ui/` in an agent repo, or anywhere in your app. The template imports only `./fs-kit.js`. Then wire it up from the hosted action or the in-page handler.

- Hosted action: [TypeScript](/ui-catalog/files/ts/usage/records-list.hosted.ts), [JavaScript](/ui-catalog/files/js/usage/records-list.hosted.js)
- In-page handler: [TypeScript](/ui-catalog/files/ts/usage/records-list.component.ts), [JavaScript](/ui-catalog/files/js/usage/records-list.component.js)
- records-list: [TypeScript](/ui-catalog/files/ts/records-list.ts), [JavaScript](/ui-catalog/files/js/records-list.js)
- fs-kit: [TypeScript](/ui-catalog/files/ts/fs-kit.ts), [JavaScript](/ui-catalog/files/js/fs-kit.js)

The hosted action needs an agent repo with one folder per action (`agent/actions/<action_key>/index.ts`). If your repo keeps its actions in `agent/actions/index.ts`, use the in-page handler: it runs the same template in your app.

All templates in machine-readable form: [/ui-catalog/catalog.json](/ui-catalog/catalog.json).

## Code

### Hosted action

```ts title="agent/actions/list_closing_deals/index.ts"
// agent/actions/list_closing_deals/index.ts: a hosted action.
// Copy the template (records-list.ts) and fs-kit.ts into agent/ui/.

type Result = RecordsListData | { error: string };

const STAGES: Record<string, ListRecord["status"]> = {
  commit: { label: "Commit", tone: "success" },
  negotiation: { label: "Negotiation", tone: "info" },
  proposal: { label: "Proposal" },
};

export async function execute(args: { month?: string; limit?: number }, ctx: ActionContext): Promise<Result> {
  const res = await ctx.fetch(`/api/deals?closing=${args.month ?? "this-month"}&owner=me&sort=closeDate&limit=${args.limit ?? 5}`);
  // A failure goes back as data: the agent explains it, and the card shows it.
  if (!res.ok) return { error: `Your deals didn't load (${res.status}). Nothing changed.` };
  const { deals, total } = await res.json();
  // Return every value the card shows: the agent reads this, not the card.
  return {
    title: "Deals closing this month",
    icon: "briefcase",
    records: deals.map((d: any): ListRecord => ({
      id: d.id,
      title: d.name,
      avatar: d.company.name,
      avatarUrl: d.company.logoUrl,
      meta: `${d.company.name} · closes ${new Date(d.closeDate).toLocaleDateString("en-US", { month: "short", day: "numeric" })}`,
      value: d.amount,
      format: { style: "currency" },
      status: d.atRisk ? { label: "At risk", tone: "error" } : STAGES[d.stage],
      href: `/deals/${d.id}`,
    })),
    total,
    noun: "deals",
    allHref: "/deals?closing=this-month&owner=me",
    footnote: "Sorted by close date",
  };
}

// Read-only in every case: the card reports displayed(result), so the agent reads the data and goes on.
export function render(result: Result, ctx: RenderContext) {
  const { root, head } = ctx.card;
  if ("error" in result) {
    mountState({ root, head, title: "Deals closing this month", icon: "briefcase", state: { kind: "error", title: "Couldn't load your deals", text: result.error } });
  } else if (result.records.length === 0) {
    mountState({ root, head, title: result.title, icon: "briefcase", state: { kind: "empty", icon: "calendar", title: "No deals close this month", text: "Deals show up here once their close date is this month." } });
  } else {
    mount({ root, head, data: result, api: { displayed: () => ctx.card.displayed(result) } });
    return;
  }
  ctx.card.displayed(result); // the agent reads what it shows, or the error to explain
}
```

```js title="agent/actions/list_closing_deals/index.js"
// agent/actions/list_closing_deals/index.js: a hosted action.
// Copy the template (records-list.ts) and fs-kit.ts into agent/ui/.

const STAGES = {
  commit: { label: "Commit", tone: "success" },
  negotiation: { label: "Negotiation", tone: "info" },
  proposal: { label: "Proposal" },
};

export async function execute(args, ctx) {
  const res = await ctx.fetch(`/api/deals?closing=${args.month ?? "this-month"}&owner=me&sort=closeDate&limit=${args.limit ?? 5}`);
  // A failure goes back as data: the agent explains it, and the card shows it.
  if (!res.ok) return { error: `Your deals didn't load (${res.status}). Nothing changed.` };
  const { deals, total } = await res.json();
  // Return every value the card shows: the agent reads this, not the card.
  return {
    title: "Deals closing this month",
    icon: "briefcase",
    records: deals.map((d) => ({
      id: d.id,
      title: d.name,
      avatar: d.company.name,
      avatarUrl: d.company.logoUrl,
      meta: `${d.company.name} · closes ${new Date(d.closeDate).toLocaleDateString("en-US", { month: "short", day: "numeric" })}`,
      value: d.amount,
      format: { style: "currency" },
      status: d.atRisk ? { label: "At risk", tone: "error" } : STAGES[d.stage],
      href: `/deals/${d.id}`,
    })),
    total,
    noun: "deals",
    allHref: "/deals?closing=this-month&owner=me",
    footnote: "Sorted by close date",
  };
}

// Read-only in every case: the card reports displayed(result), so the agent reads the data and goes on.
export function render(result, ctx) {
  const { root, head } = ctx.card;
  if ("error" in result) {
    mountState({ root, head, title: "Deals closing this month", icon: "briefcase", state: { kind: "error", title: "Couldn't load your deals", text: result.error } });
  } else if (result.records.length === 0) {
    mountState({ root, head, title: result.title, icon: "briefcase", state: { kind: "empty", icon: "calendar", title: "No deals close this month", text: "Deals show up here once their close date is this month." } });
  } else {
    mount({ root, head, data: result, api: { displayed: () => ctx.card.displayed(result) } });
    return;
  }
  ctx.card.displayed(result); // the agent reads what it shows, or the error to explain
}
```

### In-page handler

```ts title="in-page handler.ts"
// An in-page action handler: the template runs in your page.

type Result = RecordsListData | { error: string };
const TITLE = "Deals closing this month";

foldspace("when", "ready", () => {
  foldspace.agent({ /* …common setup… */ }).addActionHandlers({
    list_closing_deals: {
      // Return every row the card shows: the agent reads this, not the card.
      // A failure goes back as data too, so the agent can explain it.
      execute: async ({ month }: { month?: string }): Promise<Result> =>
        loadClosingDeals(month).catch(() => ({ error: "Your deals didn't load. Nothing changed." })),

      // Read-only: declares readyState only. The agent goes on as soon as the card reports it's shown.
      renderComponent: ({ data, host, header, readyState }: ComponentContext<Result>) => {
        // Once: on desktop a second readyState (after Retry) would start a new agent turn.
        const shown = once(readyState);
        const show = (result: Result): void => {
          if ("error" in result) {
            mountState({
              root: host, head: header, title: TITLE, icon: "briefcase",
              state: {
                kind: "error", title: "Couldn't load your deals", text: result.error,
                // Retry in the card: bone rows while it loads, then the list (or the error again).
                retry: async () => {
                  mountState({ root: host, head: header, title: TITLE, icon: "briefcase", state: { kind: "loading", label: "Loading deals…" } });
                  show(await loadClosingDeals().catch(() => ({ error: "Still not loading. Try again in a minute." })));
                },
              },
            });
          } else if (result.records.length === 0) {
            mountState({ root: host, head: header, title: TITLE, icon: "briefcase", state: { kind: "empty", icon: "calendar", title: "No deals close this month" } });
          } else {
            return void mount({
              root: host, head: header, data: result, api: { displayed: () => shown(result) },
              // Rows without href come here: open them with your router, no page reload.
              actions: {
                open: (deal) => router.push(`/deals/${deal.id}`),
                showAll: () => router.push("/deals?closing=this-month&owner=me"),
              },
            });
          }
          shown(result);
        };
        show(data);
      },
    },
  });
});
```

```js title="in-page handler.js"
// An in-page action handler: the template runs in your page.

const TITLE = "Deals closing this month";

foldspace("when", "ready", () => {
  foldspace.agent({ /* …common setup… */ }).addActionHandlers({
    list_closing_deals: {
      // Return every row the card shows: the agent reads this, not the card.
      // A failure goes back as data too, so the agent can explain it.
      execute: async ({ month }) =>
        loadClosingDeals(month).catch(() => ({ error: "Your deals didn't load. Nothing changed." })),

      // Read-only: declares readyState only. The agent goes on as soon as the card reports it's shown.
      renderComponent: ({ data, host, header, readyState }) => {
        // Once: on desktop a second readyState (after Retry) would start a new agent turn.
        const shown = once(readyState);
        const show = (result) => {
          if ("error" in result) {
            mountState({
              root: host, head: header, title: TITLE, icon: "briefcase",
              state: {
                kind: "error", title: "Couldn't load your deals", text: result.error,
                // Retry in the card: bone rows while it loads, then the list (or the error again).
                retry: async () => {
                  mountState({ root: host, head: header, title: TITLE, icon: "briefcase", state: { kind: "loading", label: "Loading deals…" } });
                  show(await loadClosingDeals().catch(() => ({ error: "Still not loading. Try again in a minute." })));
                },
              },
            });
          } else if (result.records.length === 0) {
            mountState({ root: host, head: header, title: TITLE, icon: "briefcase", state: { kind: "empty", icon: "calendar", title: "No deals close this month" } });
          } else {
            return void mount({
              root: host, head: header, data: result, api: { displayed: () => shown(result) },
              // Rows without href come here: open them with your router, no page reload.
              actions: {
                open: (deal) => router.push(`/deals/${deal.id}`),
                showAll: () => router.push("/deals?closing=this-month&owner=me"),
              },
            });
          }
          shown(result);
        };
        show(data);
      },
    },
  });
});
```

### records-list

```ts title="agent/ui/records-list.ts"
// Template: records-list. A read-only chat card with 3–8 records of one type, each row opening the record in your app.

export const meta = {
  id: "records-list",
  title: "Records list",
  surface: "card",
  kind: "read-only",
  mobile: "same",
  whenToUse: "The answer is a short list of records of one type (open tickets, deals closing soon, recent orders): 3–8 rows, each with a title, one line of detail and a value or status. Rows open the record in your app.",
  whenNotToUse: "One record (entity card). The user needs to compare several columns or sort (paginated table). The user must pick one to go on (picker).",
};

const CSS = `
.fsk-rl { container-type: inline-size; }
.fsk-rl .fsk-head > div { flex: 1; min-width: 0; }
.fsk-rl .fsk-rl-list { margin: -4px -8px 0; padding: 0; list-style: none; }
.fsk-rl .fsk-rl-list > li { position: relative; animation: fsk-in .3s var(--k-ease) both; }
/* Hairlines between rows, inset past the avatar; they hide next to a hovered row. */
.fsk-rl .fsk-rl-list > li + li::before {
  content: ""; position: absolute; top: 0; left: 54px; right: 8px; height: 1px; background: var(--k-divider); transition: opacity .15s;
}
.fsk-rl .fsk-rl-list > li:hover::before, .fsk-rl .fsk-rl-list > li:hover + li::before,
.fsk-rl .fsk-rl-list > li:focus-within::before, .fsk-rl .fsk-rl-list > li:focus-within + li::before { opacity: 0; }
.fsk-rl .fsk-rl-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: 10px;
  width: 100%; min-height: 44px; margin: 0; padding: 9px 8px; border: 0; border-radius: var(--k-r-md);
  background: none; color: inherit; font: inherit; text-align: left; text-decoration: none;
}
.fsk-rl .fsk-rl-row--open { grid-template-columns: auto minmax(0, 1fr) auto 14px; cursor: pointer; transition: background .15s; }
.fsk-rl .fsk-rl-row--open:hover { background: var(--k-hover); }
.fsk-rl .fsk-rl-row--open:focus-visible { outline: 2px solid var(--k-primary); outline-offset: -2px; }
.fsk-rl .fsk-rl-av {
  display: grid; place-items: center; width: 36px; height: 36px; overflow: hidden;
  border-radius: var(--k-r-md); font-size: .79em; font-weight: 650; letter-spacing: .02em; line-height: 1;
  color: color-mix(in srgb, var(--k-primary) 78%, var(--k-text));
  background: linear-gradient(145deg, color-mix(in srgb, var(--k-primary) 18%, var(--k-paper)), color-mix(in srgb, var(--k-primary) 7%, var(--k-paper)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--k-primary) 14%, transparent);
}
.fsk-rl[data-avatar="circle"] .fsk-rl-av { border-radius: 50%; }
.fsk-rl .fsk-rl-row .fsk-chip { width: 36px; height: 36px; }
.fsk-rl .fsk-rl-av img { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--k-paper); }
.fsk-rl .fsk-rl-main { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.fsk-rl .fsk-rl-title, .fsk-rl .fsk-rl-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsk-rl .fsk-rl-title { font-weight: 550; }
.fsk-rl .fsk-rl-meta { font-size: .86em; color: var(--k-text-2); }
.fsk-rl .fsk-rl-trail { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.fsk-rl .fsk-rl-value { font-weight: 600; white-space: nowrap; }
.fsk-rl .fsk-rl-chev { color: var(--k-text-2); opacity: .55; transition: transform .2s var(--k-ease), opacity .15s; }
.fsk-rl .fsk-rl-row--open:hover .fsk-rl-chev, .fsk-rl .fsk-rl-row--open:focus-visible .fsk-rl-chev { opacity: 1; transform: translateX(2px); }

.fsk-rl .fsk-rl-pill {
  --t: var(--k-text-2);
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 7px;
  border-radius: calc(var(--k-r) * 100); font-size: .76em; font-weight: 600; line-height: 1.6; white-space: nowrap;
  color: color-mix(in srgb, var(--t) 65%, var(--k-text));
  background: color-mix(in srgb, var(--t) 12%, var(--k-paper));
}
.fsk-rl .fsk-rl-pill::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--t); }
.fsk-rl .fsk-tone--info { --t: var(--k-primary); }
.fsk-rl .fsk-tone--success { --t: var(--k-success); }
.fsk-rl .fsk-tone--warning { --t: var(--k-warning); }
.fsk-rl .fsk-tone--error { --t: var(--k-error); }

.fsk-rl .fsk-rl-empty { margin: 0; padding: 14px 0 4px; text-align: center; color: var(--k-text-2); }
.fsk-rl .fsk-rl-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--k-divider); font-size: .86em; color: var(--k-text-2);
}
.fsk-rl .fsk-rl-foot .fsk-btn--link { margin-right: -4px; font-size: 1.08em; }
.fsk-rl .fsk-rl-foot .fsk-btn--link:focus-visible { outline: 2px solid var(--k-primary); outline-offset: 2px; }

/* Narrow card: smaller avatars, the hairline follows. */
@container (max-width: 280px) {
  .fsk-rl .fsk-rl-av, .fsk-rl .fsk-rl-row .fsk-chip { width: 30px; height: 30px; }
  .fsk-rl .fsk-rl-list > li + li::before { left: 48px; }
  .fsk-rl .fsk-rl-footnote { display: none; }
  .fsk-rl .fsk-rl-foot { justify-content: flex-end; }
}
.fsk-rl[data-surface="mobile"] .fsk-rl-row { min-height: 56px; }
.fsk-rl[data-surface="mobile"] .fsk-rl-chev { opacity: 1; }
.fsk-rl[data-surface="mobile"] .fsk-rl-foot .fsk-btn--link { min-height: 44px; }

/* Loading: bone rows on the same grid and hairlines as the real rows. */
.fsk-rl .fsk-rl-sk-main { gap: 7px; }
.fsk-rl .fsk-rl-sk-trail { gap: 6px; }
.fsk-rl .fsk-rl-sk-pill { border-radius: calc(var(--k-r) * 100); }
.fsk-rl[data-avatar="circle"] .fsk-rl-sk-av { border-radius: 50%; }
.fsk-rl .fsk-rl-sk-foot { min-height: 28px; }
@container (max-width: 280px) { .fsk-rl .fsk-rl-list { --fsk-rl-sk-av: 30px; } .fsk-rl .fsk-rl-sk-note { display: none; } .fsk-rl .fsk-rl-sk-foot { justify-content: flex-end; } }
`;

export type ListTone = "neutral" | "info" | "success" | "warning" | "error";

export interface ListStatus {
  label: string;
  /** neutral (default), info, success, warning, error. */
  tone?: ListTone;
}

export interface ListRecord {
  /** Your record's id: actions.open gets the record back. */
  id: string;
  title: string;
  /** The one line under the title, e.g. "Acme Logistics · closes Nov 28". */
  meta?: string;
  /** Name for the leading avatar's initials (a person or a company). Default: the title. */
  avatar?: string;
  /** Logo or photo for the leading avatar. Falls back to initials. */
  avatarUrl?: string;
  /** A leading icon instead of an avatar. */
  icon?: IconName;
  /** Trailing value. A number is formatted with format. */
  value?: string | number;
  format?: NumberFormat;
  status?: ListStatus;
  /** Opens the record in your app. Without it, the row calls actions.open (when given). */
  href?: string;
}

export interface RecordsListData {
  title: string;
  subtitle?: string;
  icon?: IconName;
  /** 3–8 rows. More are cut. */
  records: ListRecord[];
  /** How many there are in all. When it's more than the rows shown, the footer links to the rest. */
  total?: number;
  /** What the rows are, plural, for "Show all 12 deals". Default: "records". */
  noun?: string;
  /** Where "Show all" goes. Without it, the link calls actions.showAll (when given). */
  allHref?: string;
  /** "square" (default) for companies and things, "circle" for people. */
  avatarShape?: "square" | "circle";
  /** Short note on the left of the footer, e.g. "Sorted by close date". */
  footnote?: string;
  /** Shown instead of rows when records is empty. */
  emptyText?: string;
}

export interface RecordsListActions {
  /** A row without href was clicked. Open the record in your app. */
  open?(record: ListRecord): void;
  /** "Show all" was clicked and there's no allHref. */
  showAll?(): void;
}

export interface RecordsListProps {
  root: HTMLElement;
  head: StyleHost;
  data: RecordsListData;
  api?: CardApi;
  actions?: RecordsListActions;
  /** "mobile": taller rows and a 44px footer link. Otherwise the same card. */
  surface?: "desktop" | "mobile";
}

const initials = (name: string): string =>
  name.split(/[\s&·:,-]+/).filter(Boolean).slice(0, 2).map((w) => [...w][0].toUpperCase()).join("") || "?";

function lead(r: ListRecord): HTMLElement {
  if (r.icon && !r.avatarUrl) return h("span", { class: "fsk-chip", "aria-hidden": "true" }, icon(r.icon, 18));
  const name = r.avatar ?? r.title;
  const box = h("span", { class: "fsk-rl-av", "aria-hidden": "true" }, initials(name));
  if (r.avatarUrl) {
    const img = h<HTMLImageElement>("img", { src: r.avatarUrl, alt: "", decoding: "async", loading: "lazy", onerror: () => { img.remove(); box.textContent = initials(name); } });
    box.replaceChildren(img);
  }
  return box;
}

/** Read-only: draws the rows and reports "displayed", so the agent doesn't wait. Rows open records in your app. */
export function mount({ root, head, data, api, actions, surface = "desktop" }: RecordsListProps): Cleanup {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-rl", CSS);

  const records = data.records.slice(0, 8);
  const total = Math.max(data.total ?? records.length, records.length);
  const more = total > records.length && (data.allHref || actions?.showAll);
  const noun = data.noun ?? "records";

  const row = (r: ListRecord, i: number): HTMLElement => {
    const opens = !!(r.href || actions?.open);
    const value = r.value == null ? null : typeof r.value === "number" ? formatValue(r.value, r.format) : r.value;
    const kids = [
      lead(r),
      h("span", { class: "fsk-rl-main" },
        h("span", { class: "fsk-rl-title" }, r.title),
        r.meta && h("span", { class: "fsk-rl-meta" }, r.meta)),
      (value != null || r.status) ? h("span", { class: "fsk-rl-trail" },
        value != null && h("span", { class: "fsk-rl-value fsk-num" }, value),
        r.status && h("span", { class: `fsk-rl-pill fsk-tone--${r.status.tone ?? "neutral"}` }, r.status.label)) : h("span", {}),
      opens && h("span", { class: "fsk-rl-chev" }, icon("chevron", 14)),
    ];
    const cls = `fsk-rl-row${opens ? " fsk-rl-row--open" : ""}`;
    const el = r.href
      ? h("a", { class: cls, href: r.href, target: "_top" }, kids)
      : actions?.open
        ? h("button", { class: cls, type: "button", onclick: () => actions.open?.(r) }, kids)
        : h("div", { class: cls }, kids);
    return h("li", { style: { animationDelay: `${60 + i * 40}ms` } }, el);
  };

  const showAll = (): HTMLElement => {
    const kids = [`Show all ${formatValue(total)} ${noun}`, icon("arrowRight", 14)];
    return data.allHref
      ? h("a", { class: "fsk-btn fsk-btn--link", href: data.allHref, target: "_top" }, kids)
      : h("button", { class: "fsk-btn fsk-btn--link", type: "button", onclick: () => actions?.showAll?.() }, kids);
  };

  const card = h("section", { class: "fsk fsk-card fsk-rl", "data-surface": surface, "data-avatar": data.avatarShape ?? "square", "aria-label": data.title },
    h("header", { class: "fsk-head" },
      h("span", { class: "fsk-chip" }, icon(data.icon ?? "list", 18)),
      h("div", {}, h("h3", { class: "fsk-title" }, data.title), data.subtitle && h("p", { class: "fsk-sub" }, data.subtitle))),
    records.length
      ? h("ul", { class: "fsk-rl-list" }, records.map(row))
      : h("p", { class: "fsk-rl-empty" }, data.emptyText ?? `No ${noun} to show.`),
    (more || data.footnote) && h("footer", { class: "fsk-rl-foot" },
      h("span", { class: "fsk-rl-footnote fsk-num" }, data.footnote ?? (more ? `${records.length} of ${formatValue(total)}` : "")),
      more && showAll()));

  root.replaceChildren(card);
  api?.displayed?.(); // read-only: shown, the agent doesn't wait
  return () => root.replaceChildren();
}

/** The states this card draws besides its data. */
export const states: StateKind[] = ["loading", "empty", "error"];

export interface RecordsListStateProps extends StateProps {
  /** The header icon, as in the data. Default: list. */
  icon?: IconName;
  /** The avatar bones' shape while loading, as in the data. Default: square. */
  avatarShape?: "square" | "circle";
  /** How many bone rows while loading. Default 5. */
  rows?: number;
}

const SK_TITLE = [58, 44, 52, 38, 48, 56, 42, 50];
const SK_META = [72, 60, 80, 54, 66, 76, 58, 70];

/** Bone rows in the list's shape: avatar, title and detail line, value and status, then the footer. */
function skeleton(count: number): HTMLElement[] {
  return [
    h("ul", { class: "fsk-rl-list" }, Array.from({ length: count }, (_, i) => h("li", {},
      h("div", { class: "fsk-rl-row" },
        bone("var(--fsk-rl-sk-av, 36px)", "var(--fsk-rl-sk-av, 36px)", { cls: "fsk-bone--box fsk-rl-sk-av", i }),
        h("span", { class: "fsk-rl-main fsk-rl-sk-main" }, bone(`${SK_TITLE[i % 8]}%`, "11px", { i }), bone(`${SK_META[i % 8]}%`, "9px", { i })),
        h("span", { class: "fsk-rl-trail fsk-rl-sk-trail" }, bone("56px", "11px", { i }), bone("64px", "16px", { cls: "fsk-rl-sk-pill", i })))))),
    h("div", { class: "fsk-rl-foot fsk-rl-sk-foot" }, bone("112px", "9px", { cls: "fsk-rl-sk-note", i: count }), bone("104px", "11px", { i: count })),
  ];
}

/** Loading (bone rows), empty or error, drawn as this card. Read-only: report displayed() yourself if the agent shouldn't wait. */
export function mountState({ root, head, state, title, subtitle, surface = "desktop", icon: ic = "list", avatarShape = "square", rows = 5 }: RecordsListStateProps): Cleanup {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-rl", CSS);
  const card = stateCard({ state, cls: "fsk-rl", icon: ic, title, subtitle, surface, skeleton: () => skeleton(Math.max(1, Math.min(8, rows))) });
  card.el.setAttribute("data-avatar", avatarShape);
  root.replaceChildren(card.el);
  return () => { card.dispose(); root.replaceChildren(); };
}

export const fixtures: Record<string, RecordsListData> = {
  default: {
    title: "Deals closing this month",
    subtitle: "Your pipeline · November",
    icon: "briefcase",
    records: [
      { id: "deal_812", title: "Fleet expansion", avatar: "Acme Logistics", meta: "Acme Logistics · closes Nov 28", value: 48000, format: { style: "currency" }, status: { label: "Commit", tone: "success" } },
      { id: "deal_794", title: "2027 renewal", avatar: "Northwind Health", meta: "Northwind Health · closes Nov 29", value: 126500, format: { style: "currency" }, status: { label: "Negotiation", tone: "info" } },
      { id: "deal_801", title: "EU rollout", avatar: "Globex Retail", meta: "Globex Retail · no reply in 9 days", value: 72000, format: { style: "currency" }, status: { label: "At risk", tone: "error" } },
      { id: "deal_820", title: "Analytics add-on", avatar: "Initech", meta: "Initech · closes Nov 30", value: 18400, format: { style: "currency" }, status: { label: "Proposal" } },
      { id: "deal_787", title: "Platform upgrade", avatar: "Umbrella Labs", meta: "Umbrella Labs · closes Nov 30", value: 33900, format: { style: "currency" }, status: { label: "Negotiation", tone: "info" } },
    ],
    total: 12,
    noun: "deals",
    footnote: "Sorted by close date",
  },
  tickets: {
    title: "Your open tickets",
    subtitle: "Oldest first",
    icon: "inbox",
    avatarShape: "circle",
    records: [
      { id: "T-4821", title: "Export to CSV times out on large reports", avatar: "Sam Patel", meta: "#4821 · Acme Logistics · 2 h ago", status: { label: "Urgent", tone: "error" } },
      { id: "T-4817", title: "SSO sign-in loops back to the login page", avatar: "Lee Kim", meta: "#4817 · Northwind Health · 5 h ago", status: { label: "High", tone: "warning" } },
      { id: "T-4809", title: "Invoice PDF shows the old VAT number", avatar: "Ana Silva", meta: "#4809 · Globex Retail · yesterday", status: { label: "Waiting on customer" } },
    ],
    total: 3,
    noun: "tickets",
  },
};
```

```js title="agent/ui/records-list.js"
// Template: records-list. A read-only chat card with 3–8 records of one type, each row opening the record in your app.

export const meta = {
  id: "records-list",
  title: "Records list",
  surface: "card",
  kind: "read-only",
  mobile: "same",
  whenToUse: "The answer is a short list of records of one type (open tickets, deals closing soon, recent orders): 3–8 rows, each with a title, one line of detail and a value or status. Rows open the record in your app.",
  whenNotToUse: "One record (entity card). The user needs to compare several columns or sort (paginated table). The user must pick one to go on (picker).",
};

const CSS = `
.fsk-rl { container-type: inline-size; }
.fsk-rl .fsk-head > div { flex: 1; min-width: 0; }
.fsk-rl .fsk-rl-list { margin: -4px -8px 0; padding: 0; list-style: none; }
.fsk-rl .fsk-rl-list > li { position: relative; animation: fsk-in .3s var(--k-ease) both; }
/* Hairlines between rows, inset past the avatar; they hide next to a hovered row. */
.fsk-rl .fsk-rl-list > li + li::before {
  content: ""; position: absolute; top: 0; left: 54px; right: 8px; height: 1px; background: var(--k-divider); transition: opacity .15s;
}
.fsk-rl .fsk-rl-list > li:hover::before, .fsk-rl .fsk-rl-list > li:hover + li::before,
.fsk-rl .fsk-rl-list > li:focus-within::before, .fsk-rl .fsk-rl-list > li:focus-within + li::before { opacity: 0; }
.fsk-rl .fsk-rl-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: 10px;
  width: 100%; min-height: 44px; margin: 0; padding: 9px 8px; border: 0; border-radius: var(--k-r-md);
  background: none; color: inherit; font: inherit; text-align: left; text-decoration: none;
}
.fsk-rl .fsk-rl-row--open { grid-template-columns: auto minmax(0, 1fr) auto 14px; cursor: pointer; transition: background .15s; }
.fsk-rl .fsk-rl-row--open:hover { background: var(--k-hover); }
.fsk-rl .fsk-rl-row--open:focus-visible { outline: 2px solid var(--k-primary); outline-offset: -2px; }
.fsk-rl .fsk-rl-av {
  display: grid; place-items: center; width: 36px; height: 36px; overflow: hidden;
  border-radius: var(--k-r-md); font-size: .79em; font-weight: 650; letter-spacing: .02em; line-height: 1;
  color: color-mix(in srgb, var(--k-primary) 78%, var(--k-text));
  background: linear-gradient(145deg, color-mix(in srgb, var(--k-primary) 18%, var(--k-paper)), color-mix(in srgb, var(--k-primary) 7%, var(--k-paper)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--k-primary) 14%, transparent);
}
.fsk-rl[data-avatar="circle"] .fsk-rl-av { border-radius: 50%; }
.fsk-rl .fsk-rl-row .fsk-chip { width: 36px; height: 36px; }
.fsk-rl .fsk-rl-av img { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--k-paper); }
.fsk-rl .fsk-rl-main { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.fsk-rl .fsk-rl-title, .fsk-rl .fsk-rl-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsk-rl .fsk-rl-title { font-weight: 550; }
.fsk-rl .fsk-rl-meta { font-size: .86em; color: var(--k-text-2); }
.fsk-rl .fsk-rl-trail { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.fsk-rl .fsk-rl-value { font-weight: 600; white-space: nowrap; }
.fsk-rl .fsk-rl-chev { color: var(--k-text-2); opacity: .55; transition: transform .2s var(--k-ease), opacity .15s; }
.fsk-rl .fsk-rl-row--open:hover .fsk-rl-chev, .fsk-rl .fsk-rl-row--open:focus-visible .fsk-rl-chev { opacity: 1; transform: translateX(2px); }

.fsk-rl .fsk-rl-pill {
  --t: var(--k-text-2);
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 7px;
  border-radius: calc(var(--k-r) * 100); font-size: .76em; font-weight: 600; line-height: 1.6; white-space: nowrap;
  color: color-mix(in srgb, var(--t) 65%, var(--k-text));
  background: color-mix(in srgb, var(--t) 12%, var(--k-paper));
}
.fsk-rl .fsk-rl-pill::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--t); }
.fsk-rl .fsk-tone--info { --t: var(--k-primary); }
.fsk-rl .fsk-tone--success { --t: var(--k-success); }
.fsk-rl .fsk-tone--warning { --t: var(--k-warning); }
.fsk-rl .fsk-tone--error { --t: var(--k-error); }

.fsk-rl .fsk-rl-empty { margin: 0; padding: 14px 0 4px; text-align: center; color: var(--k-text-2); }
.fsk-rl .fsk-rl-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--k-divider); font-size: .86em; color: var(--k-text-2);
}
.fsk-rl .fsk-rl-foot .fsk-btn--link { margin-right: -4px; font-size: 1.08em; }
.fsk-rl .fsk-rl-foot .fsk-btn--link:focus-visible { outline: 2px solid var(--k-primary); outline-offset: 2px; }

/* Narrow card: smaller avatars, the hairline follows. */
@container (max-width: 280px) {
  .fsk-rl .fsk-rl-av, .fsk-rl .fsk-rl-row .fsk-chip { width: 30px; height: 30px; }
  .fsk-rl .fsk-rl-list > li + li::before { left: 48px; }
  .fsk-rl .fsk-rl-footnote { display: none; }
  .fsk-rl .fsk-rl-foot { justify-content: flex-end; }
}
.fsk-rl[data-surface="mobile"] .fsk-rl-row { min-height: 56px; }
.fsk-rl[data-surface="mobile"] .fsk-rl-chev { opacity: 1; }
.fsk-rl[data-surface="mobile"] .fsk-rl-foot .fsk-btn--link { min-height: 44px; }

/* Loading: bone rows on the same grid and hairlines as the real rows. */
.fsk-rl .fsk-rl-sk-main { gap: 7px; }
.fsk-rl .fsk-rl-sk-trail { gap: 6px; }
.fsk-rl .fsk-rl-sk-pill { border-radius: calc(var(--k-r) * 100); }
.fsk-rl[data-avatar="circle"] .fsk-rl-sk-av { border-radius: 50%; }
.fsk-rl .fsk-rl-sk-foot { min-height: 28px; }
@container (max-width: 280px) { .fsk-rl .fsk-rl-list { --fsk-rl-sk-av: 30px; } .fsk-rl .fsk-rl-sk-note { display: none; } .fsk-rl .fsk-rl-sk-foot { justify-content: flex-end; } }
`;

const initials = (name) =>
  name.split(/[\s&·:,-]+/).filter(Boolean).slice(0, 2).map((w) => [...w][0].toUpperCase()).join("") || "?";

function lead(r) {
  if (r.icon && !r.avatarUrl) return h("span", { class: "fsk-chip", "aria-hidden": "true" }, icon(r.icon, 18));
  const name = r.avatar ?? r.title;
  const box = h("span", { class: "fsk-rl-av", "aria-hidden": "true" }, initials(name));
  if (r.avatarUrl) {
    const img = h("img", { src: r.avatarUrl, alt: "", decoding: "async", loading: "lazy", onerror: () => { img.remove(); box.textContent = initials(name); } });
    box.replaceChildren(img);
  }
  return box;
}

/** Read-only: draws the rows and reports "displayed", so the agent doesn't wait. Rows open records in your app. */
export function mount({ root, head, data, api, actions, surface = "desktop" }) {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-rl", CSS);

  const records = data.records.slice(0, 8);
  const total = Math.max(data.total ?? records.length, records.length);
  const more = total > records.length && (data.allHref || actions?.showAll);
  const noun = data.noun ?? "records";

  const row = (r, i) => {
    const opens = !!(r.href || actions?.open);
    const value = r.value == null ? null : typeof r.value === "number" ? formatValue(r.value, r.format) : r.value;
    const kids = [
      lead(r),
      h("span", { class: "fsk-rl-main" },
        h("span", { class: "fsk-rl-title" }, r.title),
        r.meta && h("span", { class: "fsk-rl-meta" }, r.meta)),
      (value != null || r.status) ? h("span", { class: "fsk-rl-trail" },
        value != null && h("span", { class: "fsk-rl-value fsk-num" }, value),
        r.status && h("span", { class: `fsk-rl-pill fsk-tone--${r.status.tone ?? "neutral"}` }, r.status.label)) : h("span", {}),
      opens && h("span", { class: "fsk-rl-chev" }, icon("chevron", 14)),
    ];
    const cls = `fsk-rl-row${opens ? " fsk-rl-row--open" : ""}`;
    const el = r.href
      ? h("a", { class: cls, href: r.href, target: "_top" }, kids)
      : actions?.open
        ? h("button", { class: cls, type: "button", onclick: () => actions.open?.(r) }, kids)
        : h("div", { class: cls }, kids);
    return h("li", { style: { animationDelay: `${60 + i * 40}ms` } }, el);
  };

  const showAll = () => {
    const kids = [`Show all ${formatValue(total)} ${noun}`, icon("arrowRight", 14)];
    return data.allHref
      ? h("a", { class: "fsk-btn fsk-btn--link", href: data.allHref, target: "_top" }, kids)
      : h("button", { class: "fsk-btn fsk-btn--link", type: "button", onclick: () => actions?.showAll?.() }, kids);
  };

  const card = h("section", { class: "fsk fsk-card fsk-rl", "data-surface": surface, "data-avatar": data.avatarShape ?? "square", "aria-label": data.title },
    h("header", { class: "fsk-head" },
      h("span", { class: "fsk-chip" }, icon(data.icon ?? "list", 18)),
      h("div", {}, h("h3", { class: "fsk-title" }, data.title), data.subtitle && h("p", { class: "fsk-sub" }, data.subtitle))),
    records.length
      ? h("ul", { class: "fsk-rl-list" }, records.map(row))
      : h("p", { class: "fsk-rl-empty" }, data.emptyText ?? `No ${noun} to show.`),
    (more || data.footnote) && h("footer", { class: "fsk-rl-foot" },
      h("span", { class: "fsk-rl-footnote fsk-num" }, data.footnote ?? (more ? `${records.length} of ${formatValue(total)}` : "")),
      more && showAll()));

  root.replaceChildren(card);
  api?.displayed?.(); // read-only: shown, the agent doesn't wait
  return () => root.replaceChildren();
}

/** The states this card draws besides its data. */
export const states = ["loading", "empty", "error"];

const SK_TITLE = [58, 44, 52, 38, 48, 56, 42, 50];
const SK_META = [72, 60, 80, 54, 66, 76, 58, 70];

/** Bone rows in the list's shape: avatar, title and detail line, value and status, then the footer. */
function skeleton(count) {
  return [
    h("ul", { class: "fsk-rl-list" }, Array.from({ length: count }, (_, i) => h("li", {},
      h("div", { class: "fsk-rl-row" },
        bone("var(--fsk-rl-sk-av, 36px)", "var(--fsk-rl-sk-av, 36px)", { cls: "fsk-bone--box fsk-rl-sk-av", i }),
        h("span", { class: "fsk-rl-main fsk-rl-sk-main" }, bone(`${SK_TITLE[i % 8]}%`, "11px", { i }), bone(`${SK_META[i % 8]}%`, "9px", { i })),
        h("span", { class: "fsk-rl-trail fsk-rl-sk-trail" }, bone("56px", "11px", { i }), bone("64px", "16px", { cls: "fsk-rl-sk-pill", i })))))),
    h("div", { class: "fsk-rl-foot fsk-rl-sk-foot" }, bone("112px", "9px", { cls: "fsk-rl-sk-note", i: count }), bone("104px", "11px", { i: count })),
  ];
}

/** Loading (bone rows), empty or error, drawn as this card. Read-only: report displayed() yourself if the agent shouldn't wait. */
export function mountState({ root, head, state, title, subtitle, surface = "desktop", icon: ic = "list", avatarShape = "square", rows = 5 }) {
  ensureStyles(head, "fsk-base", BASE_CSS);
  ensureStyles(head, "fsk-rl", CSS);
  const card = stateCard({ state, cls: "fsk-rl", icon: ic, title, subtitle, surface, skeleton: () => skeleton(Math.max(1, Math.min(8, rows))) });
  card.el.setAttribute("data-avatar", avatarShape);
  root.replaceChildren(card.el);
  return () => { card.dispose(); root.replaceChildren(); };
}

export const fixtures = {
  default: {
    title: "Deals closing this month",
    subtitle: "Your pipeline · November",
    icon: "briefcase",
    records: [
      { id: "deal_812", title: "Fleet expansion", avatar: "Acme Logistics", meta: "Acme Logistics · closes Nov 28", value: 48000, format: { style: "currency" }, status: { label: "Commit", tone: "success" } },
      { id: "deal_794", title: "2027 renewal", avatar: "Northwind Health", meta: "Northwind Health · closes Nov 29", value: 126500, format: { style: "currency" }, status: { label: "Negotiation", tone: "info" } },
      { id: "deal_801", title: "EU rollout", avatar: "Globex Retail", meta: "Globex Retail · no reply in 9 days", value: 72000, format: { style: "currency" }, status: { label: "At risk", tone: "error" } },
      { id: "deal_820", title: "Analytics add-on", avatar: "Initech", meta: "Initech · closes Nov 30", value: 18400, format: { style: "currency" }, status: { label: "Proposal" } },
      { id: "deal_787", title: "Platform upgrade", avatar: "Umbrella Labs", meta: "Umbrella Labs · closes Nov 30", value: 33900, format: { style: "currency" }, status: { label: "Negotiation", tone: "info" } },
    ],
    total: 12,
    noun: "deals",
    footnote: "Sorted by close date",
  },
  tickets: {
    title: "Your open tickets",
    subtitle: "Oldest first",
    icon: "inbox",
    avatarShape: "circle",
    records: [
      { id: "T-4821", title: "Export to CSV times out on large reports", avatar: "Sam Patel", meta: "#4821 · Acme Logistics · 2 h ago", status: { label: "Urgent", tone: "error" } },
      { id: "T-4817", title: "SSO sign-in loops back to the login page", avatar: "Lee Kim", meta: "#4817 · Northwind Health · 5 h ago", status: { label: "High", tone: "warning" } },
      { id: "T-4809", title: "Invoice PDF shows the old VAT number", avatar: "Ana Silva", meta: "#4809 · Globex Retail · yesterday", status: { label: "Waiting on customer" } },
    ],
    total: 3,
    noun: "tickets",
  },
};
```

### fs-kit (shared by every template)

TypeScript: /ui-catalog/files/ts/fs-kit.ts, JavaScript: /ui-catalog/files/js/fs-kit.js
