# Collaboration stream

What a run's agents really say to each other in one container: every message names its sender and recipient, handoffs and questions for you are tagged, files open where they stand, details unfold, and a composer answers or names an agent with @.

Live variants: https://design.arcadia.is/components/collaboration-stream

```tsx
import { CollaborationStream } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import { Facts, CollaborationStream } from "@arcadia/ui";

function Thread() {
  const agents: StreamAgent[] = [
    { id: "orch", name: "Lead", model: "Max 4" },
    { id: "research", name: "Researcher", model: "Fast 4" },
    { id: "scout", name: "Scout", model: "Base 4" },
  ];
  const seed: StreamMessage[] = [
    { id: "m1", from: "orch", to: "research", kind: "spawn", text: "", at: "14:00" },
    { id: "m2", from: "you", to: "orch", kind: "ask", text: "Launch the new pricing page by Friday.", at: "14:02" },
    { id: "m3", from: "orch", to: "research", kind: "handoff", text: "Write the launch copy, then hand the page to Scout.", at: "14:03" },
    {
      id: "m4", from: "research", to: "you", kind: "reply", at: "14:06", replyTo: "m2",
      text: "The draft is ready. It keeps the first headline and adds the new plan names.",
      attachments: [{
        label: "launch-copy.md", kind: "document", meta: "4.2 KB, edited 2 minutes ago",
        preview: "Pricing that scales with the work.\nStart with one seat, add the team when the work does.",
      }],
      details: <Facts items={[{ label: "Owner", value: "Researcher" }, { label: "Words", value: "412" }, { label: "Hands off", value: "Scout" }]} />,
    },
    {
      id: "m4b", from: "scout", to: "all", kind: "share", at: "14:07",
      text: "The comparison table stacks on mobile. The billing toggle and FAQ both work with the keyboard.",
    },
    { id: "m5", from: "research", to: "you", kind: "question", at: "14:08", text: "Which headline should the page open with?" },
    { id: "m6", from: "you", to: "research", kind: "reply", at: "14:09", replyTo: "m5", text: "The second one. It names the work." },
    {
      id: "m7", from: "orch", to: "scout", kind: "handoff", at: "14:10", text: "Take the page from here.",
      attachments: [{ label: "page-preview.png", kind: "image", meta: "1440 wide, above the fold" }],
      details: <Facts items={[{ label: "Route", value: "/pricing" }, { label: "Ready", value: "Copy and plans" }]} />,
    },
    { id: "m8", from: "scout", to: "you", kind: "handoff", at: "14:11", text: "", redacted: true, redactedLabel: "Hidden by permissions" },
    { id: "m9", from: "orch", to: "you", kind: "reply", text: "The draft is with Scout for a final check.", at: "14:12" },
  ];
  const [messages, setMessages] = useState<StreamMessage[]>(seed);
  return (
    <div {...sx(null, CollaborationStreamStyles.thread)}>
      <CollaborationStream
        title="Launch review"
        task="Review the pricing page"
        appearance="quiet"
        live
        agents={agents}
        messages={messages}
        onSend={({ text, to, replyTo }) => {
          setMessages((list) => [...list, {
            id: "sent-" + (list.length + 1), from: "you", to: to[0] ?? "all", kind: replyTo === undefined ? "ask" : "reply", text, at: "now",
            ...(replyTo === undefined ? {} : { replyTo }),
          }]);
        }}
      />
    </div>
  );
}
```

## Accessibility

Tab reaches the filters as one stop, and they wrap onto more lines where the stream is narrow. ArrowLeft and ArrowRight move between them, Home and End to either end, and the selected tab names the thread for a reader. Each entry is one stop: ArrowUp and ArrowDown move between entries, Home and End to the first and last, Enter or Space toggles its details, and Escape closes a preview, then clears the reply.

The thread is a log. While the stream is live, additions are announced politely, and every entry's label names its sender, its recipient, its kind, its time and any withholding. A redacted entry never announces its body.

The composer's field is a combobox: @ opens the agent list, the arrow keys move through it, Enter or Tab inserts the name, and Escape or a press outside closes it. Enter sends and Shift+Enter starts a new line. The send control is disabled while the field holds only spaces, and while a send is on its way.

## API reference

### CollaborationStream

- `agents` (`readonly StreamAgent[]`, required): Every agent of the run, in tab order. A message names one by its id.
- `messages` (`readonly StreamMessage[]`, required): The thread, in the order it was sent. A spawn is drawn as its quiet lifecycle line.
- `task` (`string`): What the run is about: a quiet line under the title, and part of the log's label.
- `live` (`boolean`, default `false`): The run is still going: a Live mark, and the log announces what arrives.
- `focusAgent` (`string | null`): The agent whose tab is on, or null for All. Left out, the stream keeps its own.
- `onFocusAgentChange` (`(id: string | null) => void`): A tab was picked: the agent's id, or null for All.
- `onSend` (`(payload: { text: string; to: string[]; replyTo?: string }) => boolean | void | Promise<boolean | void>`): Shows the composer and sends with it: the text, who it is for, and the message it answers. Answered `false`, or with a promise that answers `false` or rejects, the draft and the reply stay put for another try.
- `placeholder` (`string`, default `"Message the agents, @ to name one"`): The composer's placeholder.
- `logos` (`Record<string, ReactNode>`): Names that get a product's logo in a message's text, by exact name.
- `maxHeight` (`number`, default `520`): How tall the thread grows before it scrolls. With a composer it is its fixed height.
- `title` (`string`, default `"Agent chat"`): The stream's title, and the log's name for a reader.
- `appearance` (`"default" | "quiet"`, default `"default"`): The container's surface. `quiet`: the app ground lifted a hair, held by an inset hairline alone, for a run that should not read as a raised card.
- `rootStyle` (`RootStyle<CollaborationStreamKnobs>`): Typed StyleX override: where the surface sits and its knobs.

Rest props go to `<div>` props.
