Skip to content

Build the Music app

Build the app Sessions ships for session music — a playlist picker on the staff session page and a playlist row on the buyer’s session sheet — from an empty folder, one file at a time. The finished files on this page are the real ones.

Framework@sessions/apps/preactTargets2TimeAbout 45 minutes

What you’ll build

Music is one app with one extension, playlist, that renders in two places. Each place is a target, and each target gets its own module: one for staff, which can write, and one for buyers, which can only read. Both read the same live query.

business.session.details.block
On a session’s page in Sessions, staff switch on Spotify, Apple Music or YouTube, paste a playlist link, save it, and preview the playlist.
public.session.detail-list.row
On the session sheet a buyer sees, the playlist is one more row among the price, time and location — only when the session has one.

Before you begin

Two things to have ready.

A Sessions account that is staff on a business, so you can install your app there and open its sessions. A test business is the right place to try things out.

Node.js 22.18 or later, git access to the Sessions repository (the package is installed from it), and an editor that understands TypeScript. You don’t need a bundler: the sessions command bundles your code for you.

Create the project

A Sessions app is an ordinary npm package with one development dependency.

Make a folder and add a package.json. @sessions/apps is the only Sessions package you need: the extension API and its types, the Preact and React components, and the sessions command. It is installed from a git tag of the Sessions repository. Preact sits beside it because Music is written as Preact components.

tsconfig.json is only for type-checking in your editor: Preact JSX, imports that name a .ts file, and allowArbitraryExtensions so TypeScript reads the types the CLI writes beside your .graphql files. .gitignore keeps those generated files, and the build output, out of git.

Files in this step
  • package.jsonNewThe one Sessions dependency, @sessions/apps, plus Preact, and scripts for the sessions commands.
  • tsconfig.jsonNewType-checking only: Preact JSX, .ts extensions in imports, and the generated .graphql.d.ts files.
  • .gitignoreNewKeeps installed packages, the build output and the generated types out of git.
package.json
{
  "name": "music",
  "private": true,
  "type": "module",
  "scripts": {
    "types": "sessions types",
    "build": "sessions build",
    "push": "sessions push",
    "publish:app": "sessions publish"
  },
  "devDependencies": {
    "@sessions/apps": "github:SessionsCode/Sessions#sessions-apps/v0.1.0",
    "preact": "^10.29.2"
  }
}
terminal
mkdir music && cd music
# write package.json, tsconfig.json and .gitignore, then:
npm install
In the Sessions repository, apps/music points its package.json and tsconfig.json at the workspace instead. Every other file on this page is the real Music app, byte for byte.
What you should see

npm install finishes, and npx sessions --help lists the commands.

Describe the app

One file at the root says what the app is.

sessions.app.json names the app. The handle is global across Sessions — it is how a business finds your app to install it — and the name and description are what the business sees in its Apps settings. extensions says where the extensions are: every folder under extensions/. The icon comes later.

Files in this step
  • sessions.app.jsonNewThe app: its global handle, its name and description, and where its extensions are.
sessions.app.json
{
  "handle": "sessions-music",
  "name": "Music",
  "description": "A playlist for every session, for your staff and the people who book.",
  "extensions": ["extensions/*"]
}
sessions-music belongs to Sessions, so pick a handle of your own, like yourname-music. The first push creates the app under that handle, and it is yours from then on.

Add the extension

An extension is one feature of your app. Music has one: the playlist.

Create extensions/playlist/ with a sessions.extension.json. It names the extension and lists its targets — for now just one, business.session.details.block, the block on the staff session page — with the module that renders each.

The module’s default export comes from extension(target, render). Passing the target gives the render function that target’s exact API, and @sessions/apps/preact renders what it returns. Text is a Sessions component: the extension describes it, and Sessions draws it in its own style.

Files in this step
  • extensions/playlist/sessions.extension.jsonNewThe extension, and one target with the module that renders it.
  • extensions/playlist/business.tsxNewThe staff target’s module. For now it renders one line.
extensions/playlist/sessions.extension.json
{
  "handle": "playlist",
  "name": "Playlist",
  "description": "Share a playlist with your customers.",
  "targets": [
    {
      "target": "business.session.details.block",
      "module": "./business.tsx"
    }
  ]
}

Put it on a session

Sign in, push and install. Once this works, every later step is an edit and a push.

npx sessions login opens Sessions in your browser to authorize the command line on this computer, and keeps the token it gets there. npx sessions build bundles each target into .sessions/build/, and npx sessions push --publish uploads a new version of the extension and makes it live.

terminal
npx sessions login
npx sessions build
npx sessions push --publish

In Sessions, open the business’s Settings, then Apps. Choose Install app, enter your app’s handle, and install it. Then open any of the business’s sessions.

What you should see

A card headed Playlist, from your app, with your line of text in it. The terminal reads like this:

terminal
$ npx sessions login
• Opening https://go.sessions.website/build/cli/authorize?…
• Waiting for you to authorize the CLI in your browser…
✔ Signed in as you@example.com.

$ npx sessions build

Built 1 extension
  – playlist · business.session.details.block → .sessions/build/playlist/business.session.details.block.js (16,564 bytes)

$ npx sessions push --publish
• Creating app yourname-music…

Pushed and published
  – playlist → version 1 (published)
From here on, after each step, run npx sessions push --publish again and reload the session page. Every push is a new version, and publishing picks the one businesses run.

Ask for data

A live query says what the module needs to know. Sessions runs it for you.

A live query is a GraphQL query you ship with a target. Sessions stores it, runs it before your module renders, and runs it again whenever the data changes — after every save, for one. The module never fetches anything.

SessionPlaylistQuery.graphql runs against the extension API. Its session is the session the block sits beside; metadata(name:) reads one stored value by its reverse-DNS name — one alias per service, so the result says which service has a playlist — and playlist is the playlist Sessions resolves from them, with its name. Point the target at the file with query in sessions.extension.json.

services.ts is plain TypeScript with nothing from Sessions in it: the three services, where each stores its playlist, how to read a pasted link, and how to embed it. Both targets share it.

In the module, useQuery returns the query’s result and renders again when it changes. Each service is a Disclosure row in a DisclosureGroup, with its logo in the media slot — greyed out with muted until it is connected.

Files in this step
  • extensions/playlist/SessionPlaylistQuery.graphqlNewThe live query: the stored playlist id for each service, and the resolved playlist.
  • extensions/playlist/services.tsNewThe three services: metadata names, link parsing and embeds. Nothing from Sessions.
  • extensions/playlist/sessions.extension.jsonChangedThe target now names its live query.
  • extensions/playlist/business.tsxChangedReads the live query and lists each service as a disclosure row.
extensions/playlist/SessionPlaylistQuery.graphql
# The live query both targets read. Sessions stores it with the extension,
# runs it for the session each target renders beside, and runs it again when
# the data changes — after every `api.mutate`, for one.
#
# Music is Sessions' own `default` app, so it keeps the reverse-DNS names
# Sessions itself reads (`website.sessions.*`). A private app would use its
# own `app.<handle>.*` names instead.
query SessionPlaylist {
  session {
    id
    spotify: metadata(name: "website.sessions.spotify.playlist.id") {
      value
    }
    appleMusic: metadata(name: "website.sessions.apple-music.playlist.id") {
      value
    }
    youtube: metadata(name: "website.sessions.youtube.playlist.id") {
      value
    }
    # The connected playlist, resolved: which service, its public URL, and
    # its name as the service reports it (null when the lookup fails).
    playlist {
      service
      url
      name
    }
  }
}
SessionPlaylistQueryData comes from SessionPlaylistQuery.graphql.d.ts, which sessions build writes beside the query (so does sessions types, in the next step). You never write the result’s type by hand.
What you should see

The card lists Spotify, Apple Music and YouTube, each Not connected.

Write the mutations

Staff targets can write. Each mutation is a .graphql file, typed by the CLI.

The playlist is stored on the session as metadata. SetPlaylistMutation.graphql stores one value with setMetadata; DeletePlaylistMutation.graphql removes one with deleteMetadata. Both take the session as owner and the metadata name as a variable, so one pair serves all three services.

Run npx sessions types. It validates every .graphql file against the extension API — a typo stops it with the file, line and column — and writes a .graphql.d.ts beside each, so importing a mutation gives you a typed document: api.mutate checks its variables and types its result.

Files in this step
  • extensions/playlist/SetPlaylistMutation.graphqlNewStores one metadata value on the session.
  • extensions/playlist/DeletePlaylistMutation.graphqlNewRemoves one metadata value from the session.
extensions/playlist/SetPlaylistMutation.graphql
mutation SetPlaylist($owner: EntityRef!, $name: String!, $value: String!) {
  setMetadata(owner: $owner, name: $name, value: $value) {
    value
    errors {
      field
      message
    }
  }
}
terminal
npx sessions types
A private app can only write metadata under its own handle, app.yourname-music.…. Music is a default app, so it writes Sessions’ own names, website.sessions.…, the ones session.playlist reads. In your copy, change each metadataName in services.ts, and the names in the query, to app.<your handle>.spotify.playlist.id and so on.
What you should see

The terminal lists three typed documents, and .graphql.d.ts files appear beside them.

terminal
$ npx sessions types

Typed 3 documents
  – SessionPlaylist query → extensions/playlist/SessionPlaylistQuery.graphql.d.ts
  – SetPlaylist mutation → extensions/playlist/SetPlaylistMutation.graphql.d.ts
  – DeletePlaylist mutation → extensions/playlist/DeletePlaylistMutation.graphql.d.ts

Keep state in a model

One object holds everything the picker knows and does. Components just read it.

PlaylistModel.ts is a class made once per extension with useModel((api: MusicApi) => new PlaylistModel(api)) — the pattern Sessions’ own pages use. MusicApi is the target’s API with the live query’s type, so the model is typed end to end.

Its state lives in signals: what’s typed in each field, which service is open, the playlist being previewed, and whether a save is running. Getters read them, so a component that reads model.draft(…) or model.isSaving renders again when they change. What’s saved is never copied — #saved is a computed over api.query, so it is always the live query’s.

save, select and deselect run the mutations with api.mutate. A failure comes back as a result, not an exception, so #mutate reads both kinds of error and shows one in a toast. After a mutation, Sessions re-runs the live query and every row updates on its own.

business.tsx draws one Disclosure per service: a Switch in the accessory slot turns it on or off, a Form with a TextField takes the link (a submit button appears in the field once the link changes), and an Embed previews the playlist below.

Files in this step
  • extensions/playlist/PlaylistModel.tsNewEverything the picker knows and does, in signals, with the mutations.
  • extensions/playlist/business.tsxChangedDraws the picker from the model: a switch, a link field and a preview per service.
extensions/playlist/PlaylistModel.ts
import {
  batch,
  computed,
  signal,
  type Api,
  type Signal,
} from '@sessions/apps/preact';

import deletePlaylist from './DeletePlaylistMutation.graphql';
import setPlaylist from './SetPlaylistMutation.graphql';
import type {SessionPlaylistQueryData} from './SessionPlaylistQuery.graphql';
import {
  SERVICES,
  samePlaylist,
  type Service,
  type ServiceKey,
} from './services.ts';

export type MusicApi = Api<
  'business.session.details.block',
  SessionPlaylistQueryData
>;

/**
 * Everything the staff picker knows and does, made once per render from the
 * extension's API (see `useModel` in `business.tsx`). State lives in
 * signals; components read the getters while rendering and re-render when
 * they change. The saved playlist is never copied: it is read from the live
 * query, which Sessions re-runs after every mutation.
 */
export class PlaylistModel {
  readonly #api: MusicApi;
  readonly #drafts: Record<ServiceKey, Signal<string>> = {
    spotify: signal(''),
    appleMusic: signal(''),
    youtube: signal(''),
  };
  readonly #expanded = signal<ServiceKey | null>(null);
  readonly #previewId = signal<string | null>(null);
  readonly #running = signal(0);

  /** The id saved for each service, from the live query. */
  readonly #saved = computed(() => {
    const session = this.#api.query.value.session;
    return {
      spotify: session?.spotify?.value ?? null,
      appleMusic: session?.appleMusic?.value ?? null,
      youtube: session?.youtube?.value ?? null,
    } satisfies Record<ServiceKey, string | null>;
  });

  constructor(api: MusicApi) {
    this.#api = api;
    const saved = this.#saved.peek();
    const connected = SERVICES.find((service) => saved[service.key]);
    batch(() => {
      for (const service of SERVICES) {
        const id = saved[service.key];
        this.#drafts[service.key].value = id ? service.playlistUrl(id) : '';
      }
      this.#expanded.value = connected?.key ?? null;
      this.#previewId.value = connected ? saved[connected.key] : null;
    });
  }

  // #region Reading

  saved(key: ServiceKey): string | null {
    return this.#saved.value[key];
  }

  /**
   * The saved playlist's name as its service reports it, from the live
   * query's resolved `session.playlist`; null until it is saved, or when the
   * service does not say (a private playlist, a failed lookup).
   */
  savedName(key: ServiceKey): string | null {
    const playlist = this.#api.query.value.session?.playlist;
    return playlist?.service === key ? (playlist.name ?? null) : null;
  }

  /** The service with a saved playlist; the picker keeps at most one. */
  get connected(): ServiceKey | null {
    return SERVICES.find((service) => this.saved(service.key))?.key ?? null;
  }

  draft(key: ServiceKey): string {
    return this.#drafts[key].value;
  }

  hasChanged(key: ServiceKey): boolean {
    const service = SERVICES.find((entry) => entry.key === key)!;
    return !samePlaylist(service, this.draft(key), this.saved(key) ?? '');
  }

  get expanded(): ServiceKey | null {
    return this.#expanded.value;
  }

  /** The playlist being previewed in the open service's embed. */
  get previewId(): string | null {
    return this.#previewId.value;
  }

  get isSaving(): boolean {
    return this.#running.value > 0;
  }

  // #endregion

  // #region Editing

  setDraft(key: ServiceKey, value: string) {
    this.#drafts[key].value = value;
  }

  setExpanded(key: ServiceKey | null) {
    this.#expanded.value = key;
  }

  /** Preview whatever the field holds, once the person leaves it. */
  previewDraft(service: Service) {
    const id = service.parseId(this.draft(service.key));
    this.#previewId.value = id || null;
  }

  // #endregion

  // #region Saving

  /** Saves the field's playlist, or removes it when the field is empty. */
  async save(service: Service) {
    const id = service.parseId(this.draft(service.key));
    if (id) {
      // The field keeps showing a link people recognise — the playlist's
      // own page — while the session stores just the id.
      batch(() => {
        this.#drafts[service.key].value = service.playlistUrl(id);
        this.#previewId.value = id;
      });
      await this.#mutate(() =>
        this.#api.mutate(setPlaylist, {
          variables: {
            owner: this.#owner,
            name: service.metadataName,
            value: id,
          },
        }),
      );
    } else {
      this.#previewId.value = null;
      await this.#remove(service);
    }
  }

  /** Switching a service on turns the connected one off. */
  async select(service: Service) {
    const connected = this.connected;
    if (connected != null && connected !== service.key) {
      const previous = SERVICES.find((entry) => entry.key === connected)!;
      this.#clear(previous.key);
      await this.#remove(previous);
    }
    this.#expanded.value = service.key;
  }

  async deselect(service: Service) {
    this.#clear(service.key);
    await this.#remove(service);
    this.#expanded.value = null;
  }

  #clear(key: ServiceKey) {
    batch(() => {
      this.#drafts[key].value = '';
      this.#previewId.value = null;
    });
  }

  #remove(service: Service) {
    return this.#mutate(() =>
      this.#api.mutate(deletePlaylist, {
        variables: {owner: this.#owner, name: service.metadataName},
      }),
    );
  }

  get #owner() {
    return {id: this.#api.session.id};
  }

  /**
   * Runs one mutation, keeping `isSaving` up while it does, and says so in a
   * toast when it fails — a failed save resolves like any other.
   */
  async #mutate(
    run: () => Promise<{
      data?: unknown;
      errors?: readonly {readonly message: string}[];
    }>,
  ) {
    this.#running.value += 1;
    try {
      const result = await run();
      const payload = Object.values(
        (result.data ?? {}) as Record<
          string,
          {errors?: readonly {message: string}[]} | null
        >,
      )[0];
      const message =
        result.errors?.[0]?.message ?? payload?.errors?.[0]?.message;
      if (message) this.#api.ui.toast(message, {tone: 'critical'});
    } finally {
      this.#running.value -= 1;
    }
  }

  // #endregion
}
What you should see

Switch on Spotify, paste a playlist link and press Save: the row says Connected, its logo gains colour, and the playlist appears below. Switching on YouTube disconnects Spotify.

Speak the viewer’s language

Sessions comes in English, French and Spanish. Your extension can too.

Add translations/en.json, fr.json and es.json to the extension. Each holds the same keys; nested objects read as dot paths, and {{service}} is a placeholder. sessions push sends them with the version.

useTranslate() returns translate, which looks a key up in the viewer’s language — falling back to English, then to the key — and renders the component again when the viewer switches language. The module reads translate('status.connected') where it used to say Connected. This is the finished staff module.

Files in this step
  • extensions/playlist/translations/en.jsonNewEvery word the extension shows, in English — the fallback.
  • extensions/playlist/translations/fr.jsonNewThe same keys, in another language.
  • extensions/playlist/translations/es.jsonNewThe same keys, in another language.
  • extensions/playlist/business.tsxChangedEvery word now comes from translate. This is the finished module.
extensions/playlist/translations/en.json
{
  "status": {
    "connected": "Connected",
    "connectedTo": "Connected · {{name}}",
    "notConnected": "Not connected",
    "pasteToConnect": "Paste a link to connect"
  },
  "link": {
    "label": "Playlist URL or ID",
    "placeholder": "Paste a {{service}} playlist link…"
  },
  "save": "Save",
  "saving": "Saving…",
  "playlist": "Playlist"
}
What you should see

Switch Sessions to Français: the rows change to French straight away, with no reload.

Show it to buyers

A second target, with its own module, in the session sheet buyers see.

Add public.session.detail-list.row to sessions.extension.json with its own module, public.tsx, and the same query. Each module is bundled on its own, so buyers never download the staff picker.

A *.row target has no card: what it renders joins the sheet’s own list of facts. DetailRow is drawn exactly like the price and location rows around it — the playlist’s name, the service under it, the logo in the icon slot, and an href that opens the playlist.

A buyer target’s API has no mutate — the viewer may not even be signed in — so TypeScript won’t let you call it. When the session has no playlist the module renders nothing, and the list is unchanged.

Files in this step
  • extensions/playlist/public.tsxNewpublic.session.detail-list.row: one read-only row with the playlist, for buyers.
  • extensions/playlist/sessions.extension.jsonChangedBoth targets, a module each, sharing one live query.
extensions/playlist/public.tsx
import {
  extension,
  useQuery,
  useTranslate,
  DetailRow,
  Image,
} from '@sessions/apps/preact';

import type {SessionPlaylistQueryData} from './SessionPlaylistQuery.graphql';
import {serviceFor} from './services.ts';

/**
 * The buyer side: one row in the session sheet's details — the playlist's
 * name, the service under it, and a link out. Renders nothing (so the row
 * isn't there) when the session has no playlist.
 */
export default extension('public.session.detail-list.row', () => (
  <PlaylistRow />
));

function PlaylistRow() {
  const {session} = useQuery<SessionPlaylistQueryData>();
  const translate = useTranslate();
  const playlist = session?.playlist;
  const service = playlist ? serviceFor(playlist.service) : null;
  if (playlist == null || service == null) return null;

  return (
    <DetailRow href={playlist.url} subtitle={service.name}>
      <Image slot="icon" src={service.logoUrl} alt="" />
      {playlist.name ?? translate('playlist')}
    </DetailRow>
  );
}
What you should see

On the business’s public page, open the session you gave a playlist: its sheet lists the playlist under the location, and tapping it opens the playlist.

Give it an icon

The icon heads your cards and your app’s page in a business’s settings.

Add a square image — Music’s is a 512×512 PNG, drawn from an SVG kept beside it — and name it with icon in sessions.app.json. Draw it edge to edge; Sessions rounds the corners.

The Music app icon

`assets/icon.png`, as Sessions draws it. Binary files aren’t shown as code.

Files in this step
  • assets/icon.pngNewThe app icon: square, 512×512. Uploaded on push.
  • sessions.app.jsonChangedThe app, now with its icon.
sessions.app.json
{
  "handle": "sessions-music",
  "name": "Music",
  "description": "A playlist for every session, for your staff and the people who book.",
  "icon": "./assets/icon.png",
  "extensions": ["extensions/*"]
}

sessions push uploads the icon whenever the file changes, and remembers what it uploaded in .sessions/state.json, so an unchanged icon costs nothing.

Push the finished app

Build and push once more.

sessions build now makes two bundles, one per target. Push and publish: the icon goes up, and both targets render for every business that has the app installed.

terminal
npx sessions build
npx sessions push --publish
What you should see

The build lists both targets, and the push uploads the icon. The staff card is headed by your icon, “Playlist” and “From Music”.

terminal
$ npx sessions build

Built 1 extension
  – playlist · business.session.details.block → .sessions/build/playlist/business.session.details.block.js (28,227 bytes)
  – playlist · public.session.detail-list.row → .sessions/build/playlist/public.session.detail-list.row.js (25,179 bytes)

$ npx sessions push --publish
• Uploading the icon (icon.png)…

Pushed and published
  – playlist → version 7 (published)
The business stays in charge. The card’s “…” menu opens your app’s page in its settings; from there, or from the menu, an admin can hide the extension or uninstall the app.

The whole app

Every file you wrote, and the job each one does. Apart from package.json, tsconfig.json and .gitignore, these are the real Music files.

  • music/Your app: an ordinary npm package.
  • package.jsonThe one Sessions dependency, @sessions/apps, plus Preact, and scripts for the sessions commands.
  • tsconfig.jsonType-checking only: Preact JSX, .ts extensions in imports, and the generated .graphql.d.ts files.
  • .gitignoreKeeps installed packages, the build output and the generated types out of git.
  • sessions.app.jsonThe app, now with its icon.
  • assets/Files the app uses that aren’t code.
  • icon.pngThe app icon: square, 512×512. Uploaded on push.
  • icon.svgThe icon’s source, kept to redraw the PNG. Not uploaded.
  • extensions/One folder per extension.
  • playlist/The playlist extension: its config, its GraphQL, its model, a module per target, and its translations.
  • sessions.extension.jsonBoth targets, a module each, sharing one live query.
  • SessionPlaylistQuery.graphqlThe live query: the stored playlist id for each service, and the resolved playlist.
  • SetPlaylistMutation.graphqlStores one metadata value on the session.
  • DeletePlaylistMutation.graphqlRemoves one metadata value from the session.
  • *.graphql.d.tsWritten by sessions types beside each .graphql file. Not committed.
  • services.tsThe three services: metadata names, link parsing and embeds. Nothing from Sessions.
  • PlaylistModel.tsEverything the picker knows and does, in signals, with the mutations.
  • business.tsxbusiness.session.details.block: the staff picker, drawn from the model.
  • public.tsxpublic.session.detail-list.row: one read-only row with the playlist, for buyers.
  • translations/One file per language.
  • en.jsonEvery word the extension shows, in English — the fallback.
  • fr.jsonThe same keys, in another language.
  • es.jsonThe same keys, in another language.
  • .sessions/build/Made by sessions build: one bundle per target. Not committed.
extensions/playlist/business.tsx
import {
  extension,
  useModel,
  useTranslate,
  Button,
  Disclosure,
  DisclosureGroup,
  Embed,
  Form,
  Image,
  Stack,
  Switch,
  TextField,
} from '@sessions/apps/preact';

import {PlaylistModel, type MusicApi} from './PlaylistModel.ts';
import {SERVICES, type Service} from './services.ts';

/**
 * The staff side: one row per service, each with a switch. Turning a service
 * on opens it to paste a playlist link, saves it on the session, and previews
 * the playlist below; only one service is connected at a time.
 */
export default extension('business.session.details.block', () => (
  <MusicPicker />
));

function MusicPicker() {
  // One model for the extension, made once from its API.
  const model = useModel((api: MusicApi) => new PlaylistModel(api));

  return (
    <DisclosureGroup>
      {SERVICES.map((service) => (
        <ServiceDisclosure key={service.key} model={model} service={service} />
      ))}
    </DisclosureGroup>
  );
}

function ServiceDisclosure({
  model,
  service,
}: {
  model: PlaylistModel;
  service: Service;
}) {
  const translate = useTranslate();
  const connected = model.saved(service.key) != null;
  const name = connected ? model.savedName(service.key) : null;
  const open = model.expanded === service.key;
  const previewId = open ? model.previewId : null;

  return (
    <Disclosure
      title={service.name}
      subtitle={
        name != null
          ? translate('status.connectedTo', {name})
          : connected
            ? translate('status.connected')
            : // Open but not saved yet: the switch reads on, so say what's
              // left to do rather than "Not connected" beside it.
              translate(open ? 'status.pasteToConnect' : 'status.notConnected')
      }
      open={open}
      onToggle={() => {
        if (open) model.setExpanded(null);
        else void model.select(service);
      }}
    >
      <Image
        slot="media"
        src={service.logoUrl}
        alt={service.name}
        muted={!connected}
      />
      <Switch
        slot="accessory"
        checked={connected || open}
        onChange={(checked) => {
          if (checked) void model.select(service);
          else void model.deselect(service);
        }}
      />
      <Stack gap="base">
        <Form onSubmit={() => model.save(service)}>
          <TextField
            label={translate('link.label')}
            labelVisibility="hidden"
            placeholder={translate('link.placeholder', {service: service.name})}
            value={model.draft(service.key)}
            selectOnPaste
            onInput={(value) => model.setDraft(service.key, value)}
            onBlur={() => model.previewDraft(service)}
          >
            {model.hasChanged(service.key) ? (
              <Button
                slot="accessory"
                type="submit"
                size="small"
                disabled={model.isSaving}
              >
                {translate(model.isSaving ? 'saving' : 'save')}
              </Button>
            ) : null}
          </TextField>
        </Form>
        <Embed
          src={previewId ? service.embedUrl(previewId) : undefined}
          height={String(service.embedHeight)}
          title={service.name}
        />
      </Stack>
    </Disclosure>
  );
}

What happens when it renders

How the files you wrote become a card on a session page and a row on its sheet, and where each part is covered in depth.

  1. The CLI types and bundles each targetYour code

    sessions build validates every .graphql file, writes its types, and bundles each target’s module on its own, with everything it imports — mutations included.

    extensions/playlist/business.tsxextensions/playlist/public.tsxextensions/playlist/SetPlaylistMutation.graphqlCLI
  2. Push stores a versionYour code

    sessions push uploads each bundle, its live query and the translations as a new, unchangeable version of the extension, and the icon if it changed. Publishing decides which version businesses run.

    sessions.app.jsonextensions/playlist/sessions.extension.jsonextensions/playlist/translations/CLI
  3. Sessions runs the live querySessions

    When someone opens a session, Sessions finds the extensions for that target — default apps, then installed ones, minus any the business hid — and runs each one’s live query against the extension API, as that viewer.

    extensions/playlist/SessionPlaylistQuery.graphqlAPI
  4. A sandboxed worker runs your moduleSessions

    The module loads in a Web Worker with a remote DOM, with the query’s result and its translations. It never touches the page and never sees a cookie or a token: api is its only way out.

  5. sessions-* elements render as Sessions UISessions

    What the module renders reaches the page as a tree of sessions-* elements, and Sessions draws each one as its own component — in a card for a block, among the sheet’s rows for a row.

  6. api.mutate runs against the extension APIYour code

    A staff target’s mutation goes through Sessions as the signed-in staff member, attributed to your extension, and can only write your app’s own metadata names.

    extensions/playlist/PlaylistModel.tsAPI
  7. The live query runs againSessions

    Once the mutation settles, Sessions runs the live query again and sends the result into the worker; the model’s computed values follow, and the components render.

Next steps

Everything the Music app used, in full.