Public: anyone can read this; the crew can change it.
Talk is one centred column the window scrolls, with a rounded composer, quiet bubbles, folded steps and a greeting where the eye is #16276
Check · Review · Land · Live done — Landed and live in production.
talk/look-1-one-column → main 1 commit
20 files
changed +629
−416
docs/design/areas/talk-build.md +2 −2
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | # Talk build (#11010) |
| 2 | 2 | |
| 3 | 3 | - `.talk-build`: the panel beside a building conversation: repository, preview, versions, Publish. |
| 4 | - `.talk-build-box`: the empty Talk's one box, "What do you want to build?", with its starters. | |
| 4 | - `.talk-build-box`: retired (#15734): the empty conversation's composer is the box, in build mode (`?build=1`). | |
| 5 | 5 | - `.talk-build-versions`: the numbered list of versions, newest first, the chosen one in bold. |
| 6 | - `.talk-build-starters`: the templates to start from, a plain link list under the box. | |
| 6 | - `.talk-build-starters`: retired (#15734): the templates are `.talk-suggest` chips under the greeting. | |
| 7 | 7 | - `.talk-build-files`: the files a chosen version changed. |
docs/design/areas/talk.md +37 −11
| @@ -2,28 +2,28 @@ | ||
| 2 | 2 | |
| 3 | 3 | `/talk` (#7652) is the person's one conversation with the forge: a log, a composer, and Do it and Not now for a held action. |
| 4 | 4 | |
| 5 | - `.talk` — the page's column: at most 760px, centred, `min-width: 0` so nothing pushes the page sideways at 375px. | |
| 5 | - `.talk` — the thread: one reading column, at most 46rem, centred, `min-width: 0` so nothing pushes the page sideways at 360px; the window scrolls it (#15734). | |
| 6 | 6 | - `.talk-log` — the ordered list of turns; its `data-last` is the last turn id the stream resumes from. |
| 7 | 7 | - `.talk-turn` — one turn; wraps anywhere, so a long word or URL never scrolls the page. |
| 8 | - `.talk-person` — the person's words: right-aligned, no box, pre-wrapped. | |
| 9 | - `.talk-agent` — the agent's reply, markdown, full width, no bubble. | |
| 8 | - `.talk-person` — the person's words: right-aligned, a quiet bubble (`--muted` surface, 18px radius), pre-wrapped; the time under it. | |
| 9 | - `.talk-agent` — the agent's reply, markdown, full width, no bubble; its time, cost and actions show only under the last block of a reply. | |
| 10 | 10 | - `.talk-tool` — what the agent did, one muted small line. |
| 11 | 11 | - `.talk-confirm` — a held action: the sentence, then Do it and Not now at 44px high. |
| 12 | - `.talk-compose` — the composer, sticky to the bottom of the viewport (padded for the phone's safe area), so it stays reachable; its textarea is 16px so iOS does not zoom. | |
| 12 | - `.talk-compose` — the composer, sticky to the bottom of the viewport above the keyboard (padded for the phone's safe area), faded into the page above it; on an empty conversation it sits under the greeting instead. | |
| 13 | 13 | - `.talk-status` — one polite line (sending, answering, an error); it always takes its line, so nothing shifts. |
| 14 | 14 | - `.talk-more` — the "Earlier" link above the log. |
| 15 | 15 | - `.talk-body` — the text of one turn, above its meta line. |
| 16 | 16 | - `.talk-plain` — a person's words, shown as typed (line breaks kept). |
| 17 | - `.talk-meta` — who said it and when, with the copy button. | |
| 18 | - `.talk-copy` — a quiet text button that copies a message or a code block. | |
| 19 | - `.talk-suggest` — the starter questions on an empty chat; each fills the composer. | |
| 17 | - `.talk-meta` — the time under a message (who said it is for a screen reader), with the copy button. | |
| 18 | - `.talk-copy` — a quiet icon button that copies a message or a code block; under a message it shows on hover and focus where there is a mouse, always on touch. | |
| 19 | - `.talk-suggest` — the starters on an empty chat, round chips; each fills the composer and sends. Build an app is one of them. | |
| 20 | 20 | - `.talk-crew` — the one line of the crew's live work (or "The crew is idle."), above the composer; a fixed one-line height that clips with an ellipsis, so it never shifts the page. |
| 21 | 21 | - `.talk-about` — the one line naming the subject (`?about=`), above the composer; no rule of its own: it is plain `small muted` text that wraps like any paragraph. |
| 22 | 22 | - `.talk-jump` — the one follow control, a round pill centred above the composer: Pause while a reply is written and followed, Resume once let go, Latest when above the end with nothing running; hidden otherwise. |
| 23 | 23 | - `.talk-dot` — the accent dot on that control when something new arrived below. |
| 24 | 24 | - `.talk-error` — the line under the composer saying why a message was not sent; shown only then, with the box marked invalid. |
| 25 | 25 | - `.talk-chats` — the conversations list above the chat (#8814): New, the person's conversations newest first, and the Archived filter link. |
| 26 | - `.talk-here` — the line naming the open conversation, with its Rename and Archive forms. | |
| 26 | - `.talk-here` — retired by `.talk-head` (#15734). | |
| 27 | 27 | - `.talk-steps` — the quiet steps line under a reply ("read 3 files, opened #12"). |
| 28 | 28 | - `.talk-links` — the links under a reply to what the turn opened or changed. |
| 29 | 29 | - `.talk-replaced` — a turn the person edited, regenerated or retried past: kept in the log, dimmer, labelled "replaced". |
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | - Attachments (#8820) — drawn in `src/web/pages/talk.ts` and `talk_client.ts` from the existing `.badge` (a file's name) and `.btn` (Remove, Attach); the only new classes are layout: |
| 35 | 35 | - `.talk-chips` — the row of chosen files above the box; hidden while empty. |
| 36 | 36 | - `.talk-files` — the line of file badges under a sent message; each links to the owner-only download. |
| 37 | - `.talk-attach` — the "Attach" file-picker label in the composer bar, a `.btn` that stays hidden until the script runs (the picker needs it). | |
| 37 | - Attach is an icon `.btn` in `.talk-tools` (`data-attach`), hidden until the script runs, which opens the hidden file input. | |
| 38 | 38 | |
| 39 | 39 | Under a reply, `.talk-cost` is one quiet line with the turn's dollars; above the log, `.talk-total` says what the conversation has cost in all and `.talk-context` says how full the context is and, from 80 %, suggests a new conversation. Both are `small muted` text, no new colour. |
| 40 | 40 | - `.talk-queued` — a message waiting for the running turn: the person's words, dimmed, its "Queued" line and Cancel under it. |
| @@ -45,7 +45,7 @@ Search (#8823) adds no component class: the form is a `.bar` with `.input` and ` | ||
| 45 | 45 | |
| 46 | 46 | #11009: the builder layout. The pane's tabs are the `.tabs` component and the phone's Chat / Preview switch is `.seg`, both links (`?pane=`) the server draws, so it works with the script off; the pane is parted from the chat by one hairline, no box. |
| 47 | 47 | |
| 48 | - `.talk-shell` — the grid holding the chats sidebar, the chat and the preview pane; one column on a phone, where `data-pane` (from `?pane=`) says which shows. | |
| 48 | - `.talk-shell` — retired: `.talk-page` is the grid (#15734). | |
| 49 | 49 | - `.talk-side` — the sidebar column wrapping `.talk-chats`. |
| 50 | 50 | - `.talk-tabs` — the phone-only Chat / Preview `.seg`. |
| 51 | 51 | - `.talk-pane` — the right pane: one head line (repository · pull or Production · Open on its own), `.tabs`, then the chosen panel; its left hairline is the only rule. |
| @@ -54,7 +54,7 @@ Search (#8823) adds no component class: the form is a `.bar` with `.input` and ` | ||
| 54 | 54 | |
| 55 | 55 | - `.talk-dictate`: the Dictate button in the compose bar (#13943). A `.btn` at the 44 px target, hidden until the script finds on-device speech recognition; while listening it is filled with the accent and reads "Stop dictating". |
| 56 | 56 | |
| 57 | On a phone the conversations nav is pinned under the topbar (#14943): New stays in view, and `.talk-list` folds the search and the list under a "Conversations" summary. | |
| 57 | On a phone the conversations list is its own view (`?chats=1`), reached from the chat icon at the start of `.talk-head` (#15734); it no longer folds. | |
| 58 | 58 | |
| 59 | 59 | #15813: the new shell. The conversations sit beside the thread from 900 px (56.25rem); below that the thread is alone and the list is one tap away. Nothing scrolls sideways from 360 to 2560 px; the thread's reading width is 72ch, centred. |
| 60 | 60 | |
| @@ -73,3 +73,29 @@ Talk's voice (`src/web/talk_parts.ts`, docs/features/talk.md, Shown results): th | ||
| 73 | 73 | - `.talk-card` — a shown result: the forge's card, set apart from the agent's words by a hairline on its start side; a wide card scrolls inside itself, never the page. |
| 74 | 74 | - `.talk-card-from` — the quiet line under a card: the call in plain words and "as of" its time. |
| 75 | 75 | - `.talk-card-missing` — "Result not found." where a handle names no card of this conversation (markup only). |
| 76 | ||
| 77 | ## #15734: one scroller, one column | |
| 78 | ||
| 79 | The window is the thread's one scroller; the list and a side pane are sticky columns beside it. | |
| 80 | ||
| 81 | - `.talk-page` — the grid: the thread alone on a phone, the list beside it from 56.25rem, and a third column from 80rem only while `data-split` (an app being built, or one running). | |
| 82 | - `.talk-work` — that third column: the build panel and the preview; below 80rem it is the Preview tab of `.talk-tabs`. | |
| 83 | - `.talk-head` — the thread's head, sticky under the top bar: the way to the list on a phone, `.talk-title`, `.talk-spend` (cost and context, from 56.25rem), the conversation menu (Rename, Download, Pin, Archive) and New on a phone. | |
| 84 | - `.talk-title` — the conversation's name, one line, ellipsized. | |
| 85 | - `.talk-spend` — the cost and context lines, small and muted, beside the title. | |
| 86 | - `.talk-rename` — the Rename form inside the conversation menu. | |
| 87 | - `.talk-new`, `.talk-find`, `.talk-archived` — the list's New conversation button, its search box, and the Archived link under the rows. | |
| 88 | - `.talk-hello` — an empty conversation's greeting, centred, with the starters; the composer follows it mid-screen. | |
| 89 | - `.talk-box` — the composer's one rounded container: `.talk-chips`, the borderless `.talk-input`, then `.talk-tools`; its focus ring is the neutral `--muted-fg`, red only when a send failed. | |
| 90 | - `.talk-input` — the textarea, 16px so iOS does not zoom, growing to 40dvh. | |
| 91 | - `.talk-tools` — the row inside the box: Attach and Dictate as icon buttons, the hint, then Steer, Stop and Send; it never wraps. | |
| 92 | - `.talk-send`, `.talk-stop` — the one round button at the end: Send (an arrow up), or Stop (a square) while an answer runs and the box is empty. | |
| 93 | - `.talk-steer` — the one secondary control, shown while an answer runs and words are typed: send them now. | |
| 94 | - `.talk-hint` — "Enter sends", only where there is a mouse. | |
| 95 | - `.talk-foot` — the line under the box: the status while it says something, else the crew line. | |
| 96 | - `.talk-fold` — one run of steps (the calls and thoughts between words) folded into one closed disclosure, one tab stop: one step by its words, more by their count. | |
| 97 | - `.talk-fold-list` — the steps inside it, on a hairline at the start edge. | |
| 98 | - `.talk-live` — the block being written; its running line shimmers (plain under reduced motion). | |
| 99 | - `.talk-code`, `.talk-code-head` — a code block in a reply under a quiet head naming its language, with Copy there, never over the code. | |
| 100 | ||
| 101 | Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet bubble, the reply as plain text, a rounded composer with one round send that becomes stop); Vercel's AI Elements (stick to bottom with a jump control, a step disclosure per reply, shimmer on the running step). |
docs/design/quiet-debt.json +1 −1
| @@ -617,7 +617,7 @@ | ||
| 617 | 617 | "caps": 4 |
| 618 | 618 | }, |
| 619 | 619 | "src/web/talk_build.ts": { |
| 620 | "bare-list": 3 | |
| 620 | "bare-list": 2 | |
| 621 | 621 | }, |
| 622 | 622 | "src/web/ui.ts": { |
| 623 | 623 | "bare-list": 1 |
docs/design/size-budget.json +2 −2
| @@ -68,8 +68,8 @@ | ||
| 68 | 68 | "css": 48384 |
| 69 | 69 | }, |
| 70 | 70 | "/talk": { |
| 71 | "js": 28928, | |
| 72 | "css": 50688 | |
| 71 | "js": 29952, | |
| 72 | "css": 51712 | |
| 73 | 73 | }, |
| 74 | 74 | "/:owner/:name/pulls/:number": { |
| 75 | 75 | "js": 32000, |
docs/features/talk-builder.md +2 −2
| @@ -4,13 +4,13 @@ row: Talk as a builder | ||
| 4 | 4 | --- |
| 5 | 5 | # Talk as a builder (#11009) |
| 6 | 6 | |
| 7 | `/talk` is two panes on a wide screen: the chat (with the chats sidebar), and on the right the live preview of the repository the chat is working on, with Code and Diff beside it. Preview, Code, Diff and, on a phone, Chat / Preview are plain links (`?pane=`) drawn by the server, so all of it works with the script off; with the script a tab swaps the pane in place, so a streaming reply and the composer's words are kept. | |
| 7 | `/talk` gives the live preview of the repository the chat is working on its own column on a wide screen (from 80rem), with Code and Diff beside it, only while there is something to show: an app the conversation builds, or something running. With nothing running there is no pane at all (#15734); below 80rem it is the Preview tab of a Chat / Preview switch. Preview, Code, Diff and, on a phone, Chat / Preview are plain links (`?pane=`) drawn by the server, so all of it works with the script off; with the script a tab swaps the pane in place, so a streaming reply and the composer's words are kept. | |
| 8 | 8 | |
| 9 | 9 | The terminal has the same: the Talk screen (`src/tui/screens/talk_chats.ts`) draws the same steps, names the repository in its header, and `p` flips to the pane's contents: the repository and its pull, the address of what runs (Preview), the pull's files page (Diff) and the files the chat touched (Code). Both read `src/actions/talk_workspace.ts`. A terminal cannot draw a web page, so it prints the preview's address instead of framing it. |
| 10 | 10 | |
| 11 | 11 | - **Which repository:** the last one a tool call in the conversation named (`src/core/talk_steps.ts` `repoOf`), shown only if you can read it. |
| 12 | 12 | - **Preview:** the newest open pull's preview environment, else production, framed from the app's own origin (the page lists that one origin in `frame-src`; `originOf` takes scheme, host and port only, so a URL with userinfo names none). It reloads when a turn ends, which is when a push has deployed. Code lists the files the chat touched; Diff links the pull's files page (not frameable). |
| 13 | - **Steps, not JSON:** each tool call is one line ("Read src/a.ts", "Edited src/a.ts (+12)", "Opened pull #12", "Merged pull #12 and deployed"), closed; its `key: value` details open on a tap. Raw JSON is never drawn. The line under a reply summarises ("Read 4 files, opened #12"). | |
| 13 | - **Steps, not JSON:** each run of tool calls between two pieces of the reply is one closed disclosure, one tab stop, named by its one step ("Read src/a.ts") or its count ("3 steps"); open, each call is one line ("Read src/a.ts", "Edited src/a.ts (+12)", "Opened pull #12", "Merged pull #12 and deployed"), closed in turn, its `key: value` details a tap deeper (`foldSteps` in `src/web/pages/talk.ts`; the script folds a streamed step into its run the same way). Raw JSON is never drawn. The line under a reply summarises ("Read 4 files, opened #12"). | |
| 14 | 14 | - **Stop and Steer** while a reply streams, and the context meter, are unchanged. |
| 15 | 15 | |
| 16 | 16 | Not yet: sidebar grouping by repository (a chat has no repo of its own), added/removed counts on edits (stored calls are cut short; only added lines are known), per-turn versions to go back to. |
docs/features/talk-layout.md +9 −10
| @@ -2,19 +2,18 @@ | ||
| 2 | 2 | topic: Tell the crew |
| 3 | 3 | row: Talk's layout at every screen size |
| 4 | 4 | --- |
| 5 | ||
| 5 | 6 | # Talk's layout at every screen size |
| 6 | 7 | |
| 7 | `/talk` is one shell in `src/web/pages/talk_client.ts` (`talkCss`) with three breakpoints, checked by `test/talk-layout.test.ts` in a real Chromium at 360, 820, 1280 and 2560 px, and for an empty conversation at 820 and 1280 (#15734). That test skips where no Chromium starts, so the numbers have not yet been seen; the forge's check is where they run. The terminal shows the same conversations in `src/tui/screens/talk_chats.ts`, with no shell around them. | |
| 8 | `/talk` is one grid in `src/web/pages/talk_client.ts` (`talkCss`), checked by `test/talk-layout.test.ts` in a real Chromium at 360, 768, 900, 1280 and 2560 px, and for an empty conversation at 390, 900 and 1280 (#15734). The window is the thread's one scroller at every size: nothing inside the thread scrolls on its own, so following a reply, the keyboard and the browser's own find all work on one surface. The terminal shows the same conversations in `src/tui/screens/talk_chats.ts`, with no grid around them. | |
| 8 | 9 | |
| 9 | - **Phone, under 56.25rem (900 px):** the chat alone, the composer pinned above the keyboard (`--kb`), Chats/Chat/Preview as tabs; Chats opens the list alone (`?chats=1`). | |
| 10 | - **Tablet, 56.25rem up:** chats beside the chat, each scrolling on its own. The page is one column of the build box (an empty conversation) and the shell; the shell takes the height left, so the composer is on screen with or without the box. | |
| 11 | - **Laptop, 80rem up:** chats, chat and preview side by side, no tabs. | |
| 12 | - **Wide, 120rem up:** the reading column stops at 56rem; the preview takes the room. | |
| 10 | - **Phone, under 56.25rem (900 px):** the thread alone, its head sticky under the top bar with the way to the list at its start, and the composer pinned above the keyboard (`--kb`, and `interactive-widget=resizes-content` where the browser honours it). The list is its own view (`?chats=1`). | |
| 11 | - **Tablet, 56.25rem up:** the list beside the thread, sticky, scrolling on its own; the thread is a centred reading column of at most 46rem. | |
| 12 | - **Laptop, 80rem up:** while the conversation builds an app, or something it worked on is running, a third column holds the build panel and the preview. With nothing to show there is no third column. Below 80rem that column is the Preview tab of a Chat / Preview switch. | |
| 13 | - **Empty conversation:** a greeting and the composer sit mid-screen, the starters as chips between them; Build an app turns the same composer into the one that makes an app (`?build=1`). | |
| 13 | 14 | |
| 14 | 15 | Prior art each choice borrows from: |
| 15 | - The folded chat list on a phone and the list-beside-thread on a tablet: iMessage, Slack. | |
| 16 | - A reading column that stops growing on a wide screen: Claude and ChatGPT, where the line length is the measure. | |
| 17 | - The composer that stays put while the log scrolls: every one of them; here it is sticky inside the column, not the page. | |
| 18 | - Preview beside the chat as a third column: Claude's artifacts pane; Linear's detail pane for a list-and-detail layout. | |
| 19 | 16 | |
| 20 | Later pulls in #15734 take the log's scroll behaviour (the log scrolls in its own column from 56.25rem up, so following a growing reply needs the column's scroll, not the window's), the keyboard shortcuts, and code blocks and attachments. | |
| 17 | - One centred reading column with the composer as a rounded box at its foot: Claude and ChatGPT. | |
| 18 | - The list beside the thread on a tablet, its own screen on a phone: iMessage, Slack. | |
| 19 | - The preview beside the chat only while there is an app: Claude's artifacts pane, v0's preview. |
docs/features/talk.md +4 −4
| @@ -40,7 +40,7 @@ The reply is drawn as it is written. The runner reports each piece of the block | ||
| 40 | 40 | |
| 41 | 41 | ## The crew's line |
| 42 | 42 | |
| 43 | `/talk` shows one line above the composer from the live runs only (`liveCrewRows` in `src/actions/crew_now.ts`, with `crewNow`'s visibility filters but none of its planner or review-wait reads, so the common request stays fast): "The crew is working: <who> on <what>" (with the count first when several, "(3)") while an agent run is live, else "The crew is idle." It is rendered with the page, never polled, and holds a fixed one-line height so nothing shifts. The terminal twin is `ssh <forge> talk /crew`, which prints the same line (`crewLine()` in `src/web/crew_now.ts`); signed out it says the crew is idle. | |
| 43 | `/talk` shows one line under the composer from the live runs only (`liveCrewRows` in `src/actions/crew_now.ts`, with `crewNow`'s visibility filters but none of its planner or review-wait reads, so the common request stays fast): "The crew is working: <who> on <what>" (with the count first when several, "(3)") while an agent run is live, else "The crew is idle." It is rendered with the page, never polled, and holds a fixed one-line height so nothing shifts. The terminal twin is `ssh <forge> talk /crew`, which prints the same line (`crewLine()` in `src/web/crew_now.ts`); signed out it says the crew is idle. | |
| 44 | 44 | |
| 45 | 45 | ## Naming the subject: `?about=` and `--about` |
| 46 | 46 | |
| @@ -102,7 +102,7 @@ Prior art read: Vercel AI Elements (Apache-2.0 React on shadcn; anatomy and beha | ||
| 102 | 102 | | Enter sends, Shift+Enter breaks a line, autosizing box | this pull | what every chat does | |
| 103 | 103 | | Draft kept on reload (localStorage, this device): per person and conversation, saved after a 300 ms pause and when the page is hidden or closed | this pull | cheap, local | |
| 104 | 104 | | Who and when under each message; copy a message; copy a code block | this pull | AI Elements `Message`, `CodeBlock` | |
| 105 | | Tool calls as closed cards | this pull | AI Elements `Tool` | | |
| 105 | | Tool calls folded into one closed disclosure per run of steps | have (#15734) | AI Elements `Tool`, `ChainOfThought` | | |
| 106 | 106 | | Starter questions on an empty chat (links to `/talk?q=`, so they work without the script) | this pull | AI Elements `Suggestion` | |
| 107 | 107 | | Stick to bottom, with Pause, Resume and Latest in one control | have (#15734) | AI Elements `Conversation` | |
| 108 | 108 | | Thinking as one closed line; a steps line under a reply ("read 3 files, opened #12"); links to each issue, pull, file or app the turn opened or changed | this pull | AI Elements `Reasoning`, `ChainOfThought` | |
| @@ -130,7 +130,7 @@ A reply is drawn by the README renderer and then, for Talk alone, by `linkTalk` | ||
| 130 | 130 | |
| 131 | 131 | An agent reply is Markdown, drawn on the server by the same renderer as a README: fenced code is highlighted, tables and links render, and everything else is escaped (a `<script>` in a reply shows as text). A table wider than the column scrolls inside it; the page does not. The reply sits in the column like a person's turn, with none of the README's padding or line measure. |
| 132 | 132 | |
| 133 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 6,700 B, the script under 23,600 B, and a page with a code reply under 40,000 B. | |
| 133 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 12,000 B, the script under 26,700 B, and a page with a code reply under 42,000 B. | |
| 134 | 134 | |
| 135 | 135 | ## Following |
| 136 | 136 | |
| @@ -156,7 +156,7 @@ Finds a conversation by a word in its title or in what was said, among the perso | ||
| 156 | 156 | |
| 157 | 157 | ## Build an app from one prompt (#11010) |
| 158 | 158 | |
| 159 | An empty `/talk` asks "What do you want to build?" with starters from the marked app templates (`/talk?template=owner/name` chooses one). Send makes the repository from the template (`newAppFromSentence`), starts a conversation in it, and sends the prompt; the agent is told with every message to work on the branch `talk-<conversation id>` and never on main (`buildLead`, `src/core/chat_build.ts`). | |
| 159 | An empty conversation offers Build an app among its starters (#15734); it opens the same composer as the one that makes an app (`/talk/<id>?build=1`), asking "What do you want to build?" with the marked app templates as chips (`&template=owner/name` chooses one, a second tap lets it go). Without the script it is the same page and a plain form posting to `POST /talk/build`. Send makes the repository from the template (`newAppFromSentence`), starts a conversation in it, and sends the prompt; the agent is told with every message to work on the branch `talk-<conversation id>` and never on main (`buildLead`, `src/core/chat_build.ts`). | |
| 160 | 160 | |
| 161 | 161 | - **Versions** are the branch's commits past main, numbered v1, v2 from the oldest (`src/actions/build.ts`); nothing about them is stored twice. The first one opens the branch's pull, which is what gives it a preview: it opens when a turn ends, or on Restore or Publish; a read never writes. `?v=N` shows that version's files changed; **Restore** makes a new version holding exactly its tree, history kept. |
| 162 | 162 | - **Publish** merges the pull to the default branch, which deploys production; the production URL then shows as a link. Only a person publishes. |
src/design/dictate.ts +2 −1
| @@ -39,7 +39,8 @@ export function dictateFindings(page: string, css: string): string[] { | ||
| 39 | 39 | const m = /<button\b([^>]*\bdata-dictate\b[^>]*)>([\s\S]*?)<\/button>/.exec(page); |
| 40 | 40 | if (!m) return ["the [data-dictate] button is gone from src/web/pages/talk.ts"]; |
| 41 | 41 | const [, attrs = "", inner = ""] = m; |
| 42 | const named = inner.replace(/<[^>]*>/g, "").trim() !== "" || /\baria-label="[^"]+"/.test(attrs); | |
| 42 | // An icon drawn by `${icon(…)}` is no name: only words or an aria-label are. | |
| 43 | const named = inner.replace(/<[^>]*>|\$\{[^}]*\}/g, "").trim() !== "" || /\baria-label="[^"]+"/.test(attrs); | |
| 43 | 44 | if (!named) out.push("the [data-dictate] button has no text and no aria-label: give it a name"); |
| 44 | 45 | if (!/\bclass="[^"]*\bbtn\b[^"]*"/.test(attrs)) out.push("the [data-dictate] button lost class `btn`, which gives it the 44px target"); |
| 45 | 46 | const all = rules(strip(css)); |
src/web/icons.ts +4
| @@ -83,6 +83,10 @@ const PATHS = { | ||
| 83 | 83 | up: `<path d="M14 9 9 4 4 9"/><path d="M20 20h-7a4 4 0 0 1-4-4V4"/>`, |
| 84 | 84 | arrowDown: `<path d="M12 5v14"/><path d="m19 12-7 7-7-7"/>`, |
| 85 | 85 | pause: `<rect x="14" y="4" width="4" height="16" rx="1"/><rect x="6" y="4" width="4" height="16" rx="1"/>`, |
| 86 | arrowUp: `<path d="m5 12 7-7 7 7"/><path d="M12 19V5"/>`, | |
| 87 | paperclip: `<path d="m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"/>`, | |
| 88 | mic: `<path d="M12 19v3"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><rect x="9" y="2" width="6" height="13" rx="3"/>`, | |
| 89 | more: `<circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/>`, | |
| 86 | 90 | history: `<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/>`, |
| 87 | 91 | activity: `<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>`, |
| 88 | 92 | sync: `<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M3 21v-5h5"/>`, |
src/web/pages/talk.ts +159 −128
| @@ -66,8 +66,9 @@ import { liveCrewRows } from "../../actions/crew_now.ts"; | ||
| 66 | 66 | import { crewLineHtml } from "../crew_now.ts"; |
| 67 | 67 | import { renderMarkdown } from "../markdown.ts"; |
| 68 | 68 | import { agentHtml, voiceCss, voiceOf, type Voice } from "../talk_parts.ts"; |
| 69 | import { badge, btn, icon, row, time } from "../ui.ts"; | |
| 70 | import { buildBox, buildCss, chosenTemplate, panelFor } from "../talk_build.ts"; | |
| 69 | import { badge, btn, icon, iconBtn, menu, row, time } from "../ui.ts"; | |
| 70 | import { buildCss, chosenTemplate, panelFor, templateChips } from "../talk_build.ts"; | |
| 71 | import type { User } from "../../core/users.ts"; | |
| 71 | 72 | import { chatBuildOf } from "../../core/chat_build.ts"; |
| 72 | 73 | import { runningStep, stepOf, repoOf, type Step } from "../../core/talk_steps.ts"; |
| 73 | 74 | import { VIEWS, talkPane, type View } from "./talk_preview.ts"; |
| @@ -172,17 +173,53 @@ const ranOut = (conversationId: string): Html => html`<p class="muted small">Not | ||
| 172 | 173 | const ranOutOf = (ctx: Ctx, userId: string, turns: readonly Turn[]): Set<string> => |
| 173 | 174 | pastTime(ctx.app.db, userId, turns.filter((t) => t.role === "confirm").map((t) => String(parse(t.text)?.["confirm"] ?? ""))); |
| 174 | 175 | |
| 175 | /** Who said it and when, with the copy button: the line under a message. */ | |
| 176 | const meta = (who: string, at: string): Html => | |
| 177 | html`<p class="talk-meta small muted">${who} · ${time(at)}</p>`; | |
| 176 | /** | |
| 177 | * Who said it and when, the quiet line under a message the copy button joins: the time is shown, | |
| 178 | * who said it is for a screen reader (the side and the bubble already say it). | |
| 179 | */ | |
| 180 | const meta = (who: string, at: string, replaced = false): Html => | |
| 181 | html`<p class="talk-meta small muted"><span class="sr-only">${who} · </span>${replaced ? "Replaced · " : null}${time(at)}</p>`; | |
| 178 | 182 | |
| 179 | /** A tool call or its outcome as a quiet line: closed, the name alone; open, the whole line. */ | |
| 180 | const toolCard = (id: string, says: string, name: string, at: string, set = ""): Html => | |
| 181 | html`<li class="talk-turn talk-tool${set}" id="${id}"><details><summary>${name.slice(0, 60)} <span class="talk-when">${time(at)}</span></summary><p>${says}</p></details></li>`; | |
| 183 | /** | |
| 184 | * A tool call or its outcome as a quiet line: closed, the name alone; open, the whole line. A call | |
| 185 | * the agent made (`step`) joins its reply's one steps disclosure. | |
| 186 | */ | |
| 187 | const toolCard = (id: string, says: string, name: string, at: string, set = "", step = false): Html => | |
| 188 | html`<li class="talk-turn talk-tool${set}" id="${id}"${step ? raw(" data-step") : null}><details><summary>${name.slice(0, 60)} <span class="talk-when">${time(at)}</span></summary><p>${says}</p></details></li>`; | |
| 182 | 189 | |
| 183 | 190 | /** A call as a readable step: its label closed, `key: value` lines open; never the JSON. */ |
| 184 | 191 | const stepCard = (id: string, step: Step, at: string, set = ""): Html => |
| 185 | html`<li class="talk-turn talk-tool talk-step${set}" id="${id}"><details><summary>${step.label} <span class="talk-when">${time(at)}</span></summary><p>${step.details.length === 0 ? "No details." : step.details.join("\n")}</p></details></li>`; | |
| 192 | html`<li class="talk-turn talk-tool talk-step${set}" id="${id}" data-step><details><summary>${step.label} <span class="talk-when">${time(at)}</span></summary><p>${step.details.length === 0 ? "No details." : step.details.join("\n")}</p></details></li>`; | |
| 193 | ||
| 194 | /** | |
| 195 | * How a run of steps is named on its closed disclosure: one step by its own words ("Read | |
| 196 | * src/a.ts"), more by their count. | |
| 197 | */ | |
| 198 | const stepsWord = (run: readonly Html[]): string => | |
| 199 | run.length === 1 ? (/<summary>([^<]*)</.exec(run[0]!.text)?.[1]?.trim() ?? "1 step") : `${run.length} steps`; | |
| 200 | ||
| 201 | /** | |
| 202 | * The log's turns with each run of steps (the calls and thoughts between two words) folded into one | |
| 203 | * closed disclosure, one tab stop: "3 steps". The stream's script folds a step that arrives later | |
| 204 | * into the run it joins the same way. | |
| 205 | */ | |
| 206 | export function foldSteps(turns: readonly Html[]): Html[] { | |
| 207 | const out: Html[] = []; | |
| 208 | let run: Html[] = []; | |
| 209 | const close = (): void => { | |
| 210 | if (run.length > 0) out.push(html`<li class="talk-fold" data-steps><details><summary class="small muted">${raw(stepsWord(run))}</summary><ol class="talk-fold-list">${run}</ol></details></li>`); | |
| 211 | run = []; | |
| 212 | }; | |
| 213 | for (const t of turns) { | |
| 214 | if (/^<li [^>]*\bdata-step\b/.test(t.text.trimStart())) run.push(t); | |
| 215 | else { | |
| 216 | close(); | |
| 217 | out.push(t); | |
| 218 | } | |
| 219 | } | |
| 220 | close(); | |
| 221 | return out; | |
| 222 | } | |
| 186 | 223 | |
| 187 | 224 | /** The quiet steps line and the links to what the turn opened or changed, under its reply. */ |
| 188 | 225 | const workHtml = (work: Work): Html => |
| @@ -190,7 +227,7 @@ const workHtml = (work: Work): Html => | ||
| 190 | 227 | |
| 191 | 228 | /** Ask again as a form, so it works without the script; the script only enhances it. */ |
| 192 | 229 | const againForm = (base: string, how: "regenerate" | "retry", label: string, words: string, turn?: string): Html => |
| 193 | html`<form method="post" action="${base}/again/${how}" data-again="${how}">${turn === undefined ? null : html`<input type="hidden" name="turn" value="${turn}">`}${btn(label, { icon: "sync", label: words })}</form>`; | |
| 230 | html`<form method="post" action="${base}/again/${how}" data-again="${how}">${turn === undefined ? null : html`<input type="hidden" name="turn" value="${turn}">`}${how === "retry" ? btn(label, { icon: "sync", label: words }) : iconBtn("sync", words, { variant: "ghost", extra: "talk-act" })}</form>`; | |
| 194 | 231 | |
| 195 | 232 | /** |
| 196 | 233 | * What the last exchange offers, by the turn it sits under: Edit under the |
| @@ -202,7 +239,7 @@ export function exchangeActs(db: Database, userId: string, conversationId: strin | ||
| 202 | 239 | if (running) return acts; |
| 203 | 240 | const { person, after } = lastExchange(db, userId, conversationId); |
| 204 | 241 | if (person === undefined) return acts; |
| 205 | acts.set(person.id, html`<a class="btn talk-act" href="${base}?edit=1#compose" data-act="edit" aria-label="Edit your last message">Edit</a>`); | |
| 242 | acts.set(person.id, html`<a class="btn btn-icon talk-act" data-variant="ghost" href="${base}?edit=1#compose" data-act="edit" aria-label="Edit your last message" title="Edit your last message">${icon("pencil")}</a>`); | |
| 206 | 243 | const last = after.at(-1); |
| 207 | 244 | if (last?.failed === true) acts.set(last.id, againForm(base, "retry", "Retry", "Retry the failed turn", last.id)); |
| 208 | 245 | else if (last?.role === "agent") acts.set(last.id, againForm(base, "regenerate", "Regenerate", "Regenerate the last reply")); |
| @@ -247,7 +284,7 @@ export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: Spend, | ||
| 247 | 284 | const id = `t-${turn.id}`; |
| 248 | 285 | const set = turn.replaced ? " talk-replaced" : ""; |
| 249 | 286 | const acts = act === undefined ? null : html`<div class="talk-acts">${act}</div>`; |
| 250 | const label = (who: string): Html => meta(turn.replaced ? `${who} · replaced` : who, turn.createdAt); | |
| 287 | const label = (who: string): Html => meta(who, turn.createdAt, turn.replaced === true); | |
| 251 | 288 | if (turn.role === "person") |
| 252 | 289 | return html`<li class="talk-turn talk-person${set}" id="${id}"> |
| 253 | 290 | <div class="talk-body talk-plain">${turn.text}</div> |
| @@ -284,7 +321,7 @@ export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: Spend, | ||
| 284 | 321 | </li>`; |
| 285 | 322 | } |
| 286 | 323 | if (thought !== undefined) |
| 287 | return html`<li class="talk-turn talk-tool talk-thinking${set}" id="${id}"><details><summary>Thinking <span class="talk-when">${time(turn.createdAt)}</span></summary><p>${thought}</p></details></li>`; | |
| 324 | return html`<li class="talk-turn talk-tool talk-thinking${set}" id="${id}" data-step><details><summary>Thinking <span class="talk-when">${time(turn.createdAt)}</span></summary><p>${thought}</p></details></li>`; | |
| 288 | 325 | // A tool turn: the confirm's outcome as JSON, or the call the agent made as text. |
| 289 | 326 | const receipt = data?.["done"] === true ? readReceipt(data["receipt"]) : undefined; |
| 290 | 327 | if (data !== undefined && receipt !== undefined && ("confirm" in data || "undid" in data)) |
| @@ -304,7 +341,7 @@ export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: Spend, | ||
| 304 | 341 | const step = stepOf(turn.text); |
| 305 | 342 | if (step !== undefined) return stepCard(id, step, turn.createdAt, set); |
| 306 | 343 | const call = turn.text.slice(0, 300); |
| 307 | return toolCard(id, call, call.split(/[\s(:{]/, 1)[0] ?? "tool", turn.createdAt, set); | |
| 344 | return toolCard(id, call, call.split(/[\s(:{]/, 1)[0] ?? "tool", turn.createdAt, set, true); | |
| 308 | 345 | } |
| 309 | 346 | |
| 310 | 347 | /** `N messages · last 5m ago`, or `no messages yet`: the one line under a conversation's name. */ |
| @@ -317,44 +354,30 @@ export function activityLine(a: { readonly messages: number; readonly lastAt: st | ||
| 317 | 354 | * The conversations list, then this one's name with Rename and Archive: each a plain form, so none |
| 318 | 355 | * needs the script. |
| 319 | 356 | */ |
| 320 | function chats(ctx: Ctx, conversation: Conversation, showArchived: boolean, typed: string, listOpen = false): Html { | |
| 357 | function chats(ctx: Ctx, conversation: Conversation, showArchived: boolean, typed: string): Html { | |
| 321 | 358 | const user = ctx.auth.user!; |
| 322 | 359 | const found = typed === "" ? undefined : findConversations(ctx.app.db, user.id, typed); |
| 323 | 360 | const shown = listConversations(ctx.app.db, user.id, { archived: showArchived }); |
| 324 | 361 | const activity = conversationActivity(ctx.app.db, user.id, shown.map((c) => c.id)); |
| 325 | 362 | const put = listConversations(ctx.app.db, user.id, { archived: !showArchived }).length; |
| 326 | 363 | return html`<nav class="talk-chats" aria-label="Conversations"> |
| 327 | <div class="bar"> | |
| 328 | <form method="post" action="${HERE}/new">${btn("New", { icon: "plus", label: "New conversation" })}</form> | |
| 329 | <span class="spacer"></span> | |
| 330 | ${showArchived | |
| 331 | ? html`<a class="small" href="${HERE}">Back to conversations</a>` | |
| 332 | : put > 0 | |
| 333 | ? html`<a class="small" href="${HERE}?archived=1">Archived (${put})</a>` | |
| 334 | : null} | |
| 335 | </div> | |
| 336 | <details class="talk-list"${typed !== "" || showArchived || listOpen ? html` open` : null}> | |
| 337 | <summary class="small">Conversations</summary> | |
| 338 | <form class="bar" method="get" action="${HERE}" role="search"> | |
| 339 | <input class="input" type="search" name="find" value="${typed}" maxlength="${FIND_CHARS}" aria-label="Search conversations" placeholder="Search conversations" /> | |
| 340 | ${btn("Search")} | |
| 341 | </form> | |
| 342 | ${found === undefined | |
| 343 | ? null | |
| 344 | : html`<ul class="list" aria-label="Search results"> | |
| 345 | ${found.length === 0 | |
| 346 | ? html`<li class="muted small">Nothing found for "${typed}".</li>` | |
| 347 | : found.map((f) => | |
| 348 | row({ | |
| 349 | href: `${urlOf(f.conversation)}${f.turnId === undefined ? "" : `?turn=${f.turnId}-${f.turnId}`}`, | |
| 350 | title: nameOf(f.conversation), | |
| 351 | meta: html`${f.snippet}`, | |
| 352 | ...(f.conversation.archivedAt === null ? {} : { trail: badge("archived") }), | |
| 353 | }), | |
| 354 | )} | |
| 355 | </ul>`} | |
| 356 | <ul class="list"> | |
| 357 | ${shown.length === 0 | |
| 364 | <form method="post" action="${HERE}/new">${btn("New conversation", { icon: "plus", variant: "outline", extra: "talk-new" })}</form> | |
| 365 | <form class="talk-find" method="get" action="${HERE}" role="search"> | |
| 366 | <input class="input" type="search" name="find" value="${typed}" maxlength="${FIND_CHARS}" aria-label="Search conversations" placeholder="Search" /> | |
| 367 | </form> | |
| 368 | <ul class="list talk-list"${found === undefined ? null : raw(' aria-label="Search results"')}> | |
| 369 | ${found !== undefined | |
| 370 | ? found.length === 0 | |
| 371 | ? html`<li class="muted small">Nothing found for "${typed}".</li>` | |
| 372 | : found.map((f) => | |
| 373 | row({ | |
| 374 | href: `${urlOf(f.conversation)}${f.turnId === undefined ? "" : `?turn=${f.turnId}-${f.turnId}`}`, | |
| 375 | title: nameOf(f.conversation), | |
| 376 | meta: html`${f.snippet}`, | |
| 377 | ...(f.conversation.archivedAt === null ? {} : { trail: badge("archived") }), | |
| 378 | }), | |
| 379 | ) | |
| 380 | : shown.length === 0 | |
| 358 | 381 | ? html`<li class="muted small">${showArchived ? "Nothing archived." : "No conversations yet."}</li>` |
| 359 | 382 | : shown.map((c, i) => |
| 360 | 383 | html`${i === 0 && c.pinnedAt !== null ? html`<li class="muted small" data-pinned-heading>Pinned</li>` : null}${row({ |
| @@ -362,49 +385,56 @@ function chats(ctx: Ctx, conversation: Conversation, showArchived: boolean, type | ||
| 362 | 385 | title: nameOf(c), |
| 363 | 386 | meta: activityLine(activity.get(c.id)), |
| 364 | 387 | current: c.id === conversation.id, |
| 365 | ...(c.archivedAt === null | |
| 366 | ? { | |
| 367 | after: html`<form method="post" action="${urlOf(c)}/pin"> | |
| 368 | <input type="hidden" name="pinned" value="${c.pinnedAt === null ? "1" : "0"}" /> | |
| 369 | <input type="hidden" name="back" value="list" /> | |
| 370 | ${btn(c.pinnedAt === null ? "Pin" : "Unpin", { size: "sm", variant: "outline" })} | |
| 371 | </form>`, | |
| 372 | } | |
| 373 | : {}), | |
| 374 | 388 | })}`, |
| 375 | 389 | )} |
| 376 | </ul> | |
| 377 | </details> | |
| 390 | </ul> | |
| 391 | ${showArchived | |
| 392 | ? html`<a class="small talk-archived" href="${HERE}">Back to conversations</a>` | |
| 393 | : put > 0 | |
| 394 | ? html`<a class="small talk-archived" href="${HERE}?archived=1">Archived (${put})</a>` | |
| 395 | : null} | |
| 378 | 396 | </nav>`; |
| 379 | 397 | } |
| 380 | 398 | |
| 381 | 399 | /** |
| 382 | * The open conversation's head: its name and its controls. The way back to the list on a phone | |
| 383 | * is the first of the tabs, so it is reachable from the preview too. | |
| 400 | * The open conversation's head: on a phone the way to the list, then its name, what it has cost, | |
| 401 | * and one menu for Rename, Download, Pin and Archive, each a plain form or link. | |
| 384 | 402 | */ |
| 385 | function hereBar(conversation: Conversation): Html { | |
| 403 | function hereBar(ctx: Ctx, conversation: Conversation, context: Context | undefined): Html { | |
| 386 | 404 | const archived = conversation.archivedAt !== null; |
| 387 | return html`<div class="talk-here bar"> | |
| 388 | <strong>${nameOf(conversation)}${archived ? " (archived)" : ""}</strong> | |
| 389 | <details> | |
| 390 | <summary class="small">Rename</summary> | |
| 391 | <form method="post" action="${urlOf(conversation)}/rename"> | |
| 392 | <input class="input" name="title" value="${conversation.title}" maxlength="${TITLE_MAX}" aria-label="Title" placeholder="Title" /> | |
| 393 | ${btn("Save")} | |
| 394 | </form> | |
| 395 | </details> | |
| 396 | <a class="btn" href="${urlOf(conversation)}.md" download>Download</a> | |
| 397 | ${archived | |
| 398 | ? null | |
| 399 | : html`<form method="post" action="${urlOf(conversation)}/pin"> | |
| 400 | <input type="hidden" name="pinned" value="${conversation.pinnedAt === null ? "1" : "0"}" /> | |
| 401 | ${btn(conversation.pinnedAt === null ? "Pin" : "Unpin")} | |
| 402 | </form>`} | |
| 403 | <form method="post" action="${urlOf(conversation)}/archive"> | |
| 404 | <input type="hidden" name="archived" value="${archived ? "0" : "1"}" /> | |
| 405 | ${btn(archived ? "Restore" : "Archive")} | |
| 406 | </form> | |
| 407 | </div>`; | |
| 405 | const item = (action: string, field: string, value: string, label: string, ic: "pin" | "history" | "trash"): Html => | |
| 406 | html`<form method="post" action="${urlOf(conversation)}/${action}"><input type="hidden" name="${field}" value="${value}" /><button class="menu-item" type="submit">${icon(ic)}<span class="grow">${label}</span></button></form>`; | |
| 407 | return html`<header class="talk-head"> | |
| 408 | <a class="btn btn-icon talk-back" data-variant="ghost" href="${urlOf(conversation)}?chats=1" aria-label="Conversations" title="Conversations">${icon("comment")}</a> | |
| 409 | <h2 class="talk-title">${nameOf(conversation)}${archived ? " (archived)" : ""}</h2> | |
| 410 | <div class="talk-spend small muted">${totalLine(conversationTotal(ctx.app.db, conversation.id))}${contextLine(context)}</div> | |
| 411 | ${menu({ | |
| 412 | trigger: icon("more"), | |
| 413 | label: "Conversation menu", | |
| 414 | triggerOptions: { variant: "ghost", extra: "btn-icon" }, | |
| 415 | items: [ | |
| 416 | html`<form class="talk-rename" method="post" action="${urlOf(conversation)}/rename"> | |
| 417 | <input class="input" name="title" value="${conversation.title}" maxlength="${TITLE_MAX}" aria-label="Title" placeholder="Title" /> | |
| 418 | ${btn("Rename", { size: "sm" })} | |
| 419 | </form>`, | |
| 420 | { label: "Download", href: `${urlOf(conversation)}.md`, icon: "download" }, | |
| 421 | ...(archived ? [] : [item("pin", "pinned", conversation.pinnedAt === null ? "1" : "0", conversation.pinnedAt === null ? "Pin" : "Unpin", "pin")]), | |
| 422 | item("archive", "archived", archived ? "0" : "1", archived ? "Restore" : "Archive", archived ? "history" : "trash"), | |
| 423 | ], | |
| 424 | })} | |
| 425 | <form method="post" action="${HERE}/new">${iconBtn("plus", "New conversation", { variant: "ghost" })}</form> | |
| 426 | </header>`; | |
| 427 | } | |
| 428 | ||
| 429 | /** An empty conversation: a greeting where the eye lands, and a few ways to start as chips. */ | |
| 430 | function hello(ctx: Ctx, user: User, here: string, buildMode: boolean, chosen: string | undefined): Html { | |
| 431 | return html`<li class="talk-hello"> | |
| 432 | <h2>${buildMode ? "What do you want to build?" : "What should we work on?"}</h2> | |
| 433 | <p class="muted">${buildMode ? "Say what it is for. You watch it appear beside the chat, and nothing is live until you publish." : "The forge acts as you, with your permissions, and asks before anything hard to undo."}</p> | |
| 434 | ${buildMode | |
| 435 | ? templateChips(ctx.app.db, user, here, chosen) | |
| 436 | : html`<div class="talk-suggest">${STARTER_PROMPTS.map((q) => html`<form method="post" action="${here}" data-starter><input type="hidden" name="text" value="${q}" />${btn(q, { size: "sm" })}</form>`)}<a class="btn" data-size="sm" href="${here}?build=1">${icon("rocket")} Build an app</a></div>`} | |
| 437 | </li>`; | |
| 408 | 438 | } |
| 409 | 439 | |
| 410 | 440 | async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | undefined, latest: boolean, edit: boolean): Promise<Response> { |
| @@ -437,11 +467,13 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 437 | 467 | const acts = !paged ? exchangeActs(ctx.app.db, user.id, conversation.id, running, here) : new Map<string, Html>(); |
| 438 | 468 | // Edit shows the composer holding the last message, posting to Edit instead of Send. |
| 439 | 469 | const editing = edit ? lastExchange(ctx.app.db, user.id, conversation.id).person : undefined; |
| 440 | // A conversation that builds an app shows its versions and preview; an empty one offers the one | |
| 441 | // box (#11010). | |
| 470 | // A conversation that builds an app shows its versions and preview; an empty one offers to start | |
| 471 | // one from its first message (#11010): `?build=1`, with `template=` to start from one. | |
| 442 | 472 | const building = chatBuildOf(ctx.app.db, conversation.id) !== undefined; |
| 443 | 473 | const panel = building ? await panelFor(ctx, conversation.id, here) : null; |
| 444 | const box = !building && !paged && turns.length === 0 ? buildBox(ctx.app.db, user, chosenTemplate(ctx.app.db, user, ctx.url.searchParams.get("template"))) : null; | |
| 474 | const empty = !building && !paged && turns.length === 0; | |
| 475 | const chosen = empty ? chosenTemplate(ctx.app.db, user, ctx.url.searchParams.get("template")) : undefined; | |
| 476 | const buildMode = empty && editing === undefined && (ctx.url.searchParams.get("build") === "1" || chosen !== undefined); | |
| 445 | 477 | const asked = ctx.url.searchParams.get("pane"); |
| 446 | 478 | const view: View | undefined = VIEWS.find((p) => p === asked); |
| 447 | 479 | const shown = view ?? "chat"; |
| @@ -453,56 +485,55 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 453 | 485 | // The forge paths the replies name, each read once for the page however often they repeat. |
| 454 | 486 | const look = talkLook(ctx.app.db, user, turns.filter((t) => t.role === "agent").map((t) => t.text), appLook(ctx.app, user)); |
| 455 | 487 | const pane = talkPane(ctx, user, cited, works, view); |
| 456 | const body = html`<div class="talk-page"><h1 class="sr-only">Talk</h1> | |
| 457 | ${box} | |
| 458 | <div class="talk-shell" data-shell data-pane="${shown}"${listing ? raw(" data-view=\"list\"") : null}> | |
| 459 | <div class="talk-side">${chats(ctx, conversation, showArchived, typed, listing)}</div> | |
| 460 | <nav class="seg talk-tabs" aria-label="Chats, chat or preview"><a class="talk-back" href="${urlOf(conversation)}?chats=1">Chats</a><a href="?pane=chat"${shown === "chat" ? raw(' aria-current="page"') : null}>Chat</a><a href="?pane=preview"${shown !== "chat" ? raw(' aria-current="page"') : null}>Preview</a></nav> | |
| 488 | // The side pane is there only when it has something to show: an app being built, or one running. | |
| 489 | const split = panel !== null || pane.live; | |
| 490 | const about = editing === undefined ? aboutLine(ctx) : null; | |
| 491 | const body = html`<div class="talk-page" data-shell data-pane="${shown}"${listing ? raw(" data-view=\"list\"") : null}${split ? raw(" data-split") : null}><h1 class="sr-only">Talk</h1> | |
| 492 | <div class="talk-side">${chats(ctx, conversation, showArchived, typed)}</div> | |
| 461 | 493 | <div class="talk" data-talk data-user="${user.id}" data-c="${conversation.id}" data-here="${here}" data-paged="${paged ? "1" : "0"}" data-running="${running && !paged ? "1" : "0"}"> |
| 462 | <div> | |
| 463 | ${hereBar(conversation)} | |
| 464 | ${totalLine(conversationTotal(ctx.app.db, conversation.id))} | |
| 465 | ${contextLine(context)} | |
| 466 | ${turns.length === DEFAULT_PAGE && turns[0] !== undefined | |
| 467 | ? html`<p class="talk-more small"><a href="${here}?before=${turns[0].id}">Earlier</a></p>` | |
| 468 | : null} | |
| 469 | ${!paged ? null : html`<p class="talk-more small"><a href="${here}">Latest</a></p>`} | |
| 470 | <ol class="talk-log" role="log" data-last="${last}" aria-label="Conversation with the forge"> | |
| 471 | ${turns.length === 0 | |
| 472 | ? html`<li class="muted talk-turn">Ask the forge anything, or tell it what to change. It acts as you, with your permissions, and asks before anything hard to undo. | |
| 473 | <div class="talk-suggest">${STARTER_PROMPTS.map((q) => html`<form method="post" action="${here}" data-starter><input type="hidden" name="text" value="${q}" />${btn(q)}</form>`)}</div></li>` | |
| 474 | : turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs, voice, look))} | |
| 475 | ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null} | |
| 476 | </ol> | |
| 477 | <div id="end"></div> | |
| 478 | </div> | |
| 494 | ${hereBar(ctx, conversation, context)} | |
| 495 | ${split ? html`<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat"${shown === "chat" ? raw(' aria-current="page"') : null}>Chat</a><a href="?pane=preview"${shown !== "chat" ? raw(' aria-current="page"') : null}>Preview</a></nav>` : null} | |
| 496 | ${turns.length === DEFAULT_PAGE && turns[0] !== undefined | |
| 497 | ? html`<p class="talk-more small"><a href="${here}?before=${turns[0].id}">Earlier</a></p>` | |
| 498 | : null} | |
| 499 | ${!paged ? null : html`<p class="talk-more small"><a href="${here}">Latest</a></p>`} | |
| 500 | <ol class="talk-log" role="log" data-last="${last}" aria-label="Conversation with the forge"> | |
| 501 | ${empty | |
| 502 | ? hello(ctx, user, here, buildMode, chosen) | |
| 503 | : foldSteps(turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs, voice, look)))} | |
| 504 | ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null} | |
| 505 | </ol> | |
| 506 | <div id="end"></div> | |
| 479 | 507 | <div class="talk-keys" data-keys role="region" aria-label="Keyboard shortcuts" hidden><dl>${TALK_KEYS.map((k) => html`<dt>${k.keys}</dt><dd>${k.does}</dd>`)}</dl></div> |
| 480 | ${aboutLine(ctx)} | |
| 481 | ${crewLineHtml(liveCrewRows(ctx, user))} | |
| 482 | <form class="talk-compose" id="compose" method="post" action="${editing === undefined ? here : `${here}/again/edit`}" ${editing === undefined ? null : html`data-edit`}> | |
| 508 | <form class="talk-compose" id="compose" method="post" action="${buildMode ? "/talk/build" : editing === undefined ? here : `${here}/again/edit`}" ${editing === undefined ? null : html`data-edit`}${buildMode ? raw(" data-build") : null}> | |
| 483 | 509 | ${conversation.archivedAt === null ? null : html`<p class="small muted" data-archived-note>Archived: sending here keeps it archived; Restore puts it back in the list.</p>`} |
| 484 | <p class="talk-status small muted" role="status">${running ? "The forge is answering…" : ""}</p> | |
| 485 | <div class="talk-chips" data-chips role="group" aria-label="Attached files"></div> | |
| 486 | ${editing === undefined && aboutText(ctx.app.db, ctx.url.searchParams.get("about"), ctx.auth.user) !== null ? html`<input type="hidden" name="about" value="${ctx.url.searchParams.get("about")}" />` : null} | |
| 487 | <textarea class="input" name="text" rows="1" maxlength="${WORDS_MAX}" required placeholder="Talk to the forge" aria-label="Talk to the forge" aria-keyshortcuts="/" aria-describedby="talk-error">${editing === undefined ? "" : editing.text}</textarea> | |
| 488 | <p class="talk-error small" id="talk-error" data-error hidden></p> | |
| 489 | <button type="button" class="btn talk-jump" data-jump hidden>${icon("pause")}${icon("arrowDown")}<span data-word></span><i class="talk-dot"></i></button> | |
| 490 | <div class="bar"> | |
| 491 | <span class="muted small" data-compose-hint></span> | |
| 492 | <button type="button" class="btn talk-dictate" data-dictate aria-pressed="false" hidden>Dictate</button> | |
| 493 | <label class="btn talk-attach" data-attach hidden>Attach<input type="file" multiple hidden data-pick /></label> | |
| 494 | <span class="spacer"></span> | |
| 495 | ${editing === undefined ? null : html`<a class="btn" href="${here}">Keep as it was</a>`} | |
| 496 | <button type="button" class="btn" data-stop hidden>Stop</button> | |
| 497 | <button type="button" class="btn" data-steer hidden title="Stop this answer and send now">Steer</button> | |
| 498 | ${btn(editing === undefined ? "Send" : "Resend", { variant: "primary" })} | |
| 510 | ${about} | |
| 511 | ${editing === undefined && about !== null ? html`<input type="hidden" name="about" value="${ctx.url.searchParams.get("about")}" />` : null} | |
| 512 | ${chosen === undefined ? null : html`<input type="hidden" name="template" value="${chosen}" />`} | |
| 513 | <div class="talk-box"> | |
| 514 | <div class="talk-chips" data-chips role="group" aria-label="Attached files"></div> | |
| 515 | <textarea class="talk-input" name="${buildMode ? "prompt" : "text"}" rows="1" maxlength="${WORDS_MAX}" required placeholder="${buildMode ? (chosen === undefined ? "A tip calculator for friends" : `What to make from ${chosen}`) : "Ask the forge, or tell it what to change"}" aria-label="${buildMode ? "What to build" : "Talk to the forge"}" aria-keyshortcuts="/" aria-describedby="talk-error">${editing === undefined ? "" : editing.text}</textarea> | |
| 516 | <div class="talk-tools"> | |
| 517 | ${buildMode ? null : html`<button type="button" class="btn btn-icon" data-variant="ghost" data-attach hidden aria-label="Attach files" title="Attach files">${icon("paperclip")}</button><input type="file" multiple hidden data-files /> | |
| 518 | <button type="button" class="btn btn-icon talk-dictate" data-variant="ghost" data-dictate aria-pressed="false" aria-label="Dictate" title="Dictate" hidden>${icon("mic")}</button>`} | |
| 519 | ${buildMode ? html`<a class="small" href="${here}">Talk instead</a>` : null} | |
| 520 | <span class="spacer"></span> | |
| 521 | <span class="muted small talk-hint" data-compose-hint></span> | |
| 522 | ${editing === undefined ? null : html`<a class="btn" data-size="sm" href="${here}">Keep as it was</a>`} | |
| 523 | <button type="button" class="btn talk-steer" data-size="sm" data-steer hidden title="Stop this answer and send now">Steer</button> | |
| 524 | <button type="button" class="btn btn-icon talk-stop" data-stop hidden aria-label="Stop the answer" title="Stop the answer">${icon("square")}</button> | |
| 525 | <button type="submit" class="btn btn-icon talk-send" data-variant="primary" aria-label="${buildMode ? "Build it" : editing === undefined ? "Send" : "Resend"}" title="${buildMode ? "Build it" : editing === undefined ? "Send" : "Resend"}">${icon("arrowUp")}</button> | |
| 526 | </div> | |
| 499 | 527 | </div> |
| 528 | <p class="talk-error small" id="talk-error" data-error hidden></p> | |
| 529 | <div class="talk-foot small muted"><p class="talk-status" role="status">${running ? "The forge is answering…" : ""}</p>${crewLineHtml(liveCrewRows(ctx, user))}</div> | |
| 530 | <button type="button" class="btn talk-jump" data-jump hidden>${icon("pause")}${icon("arrowDown")}<span data-word></span><i class="talk-dot"></i></button> | |
| 500 | 531 | </form> |
| 532 | <template id="talk-ico">${icon("copy")}${icon("check")}</template> | |
| 501 | 533 | </div> |
| 502 | ${pane.html} | |
| 503 | ${panel} | |
| 504 | </div></div>`; | |
| 505 | return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: (panel === null && box === null ? talkCss : talkCss + buildCss) + voiceCss, scriptJs: talkJs, description: "Talk to the forge.", wide: true, ...(pane.frame === undefined ? {} : { frameSrc: pane.frame }) }); | |
| 534 | ${split ? html`<div class="talk-work">${panel}${pane.html}</div>` : null} | |
| 535 | </div>`; | |
| 536 | return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: (panel === null ? talkCss : talkCss + buildCss) + voiceCss, scriptJs: talkJs, description: "Talk to the forge.", wide: true, keyboardResizes: true, ...(pane.frame === undefined || !split ? {} : { frameSrc: pane.frame }) }); | |
| 506 | 537 | } |
| 507 | 538 | |
| 508 | 539 | /** |
src/web/pages/talk_client.ts +198 −91
| @@ -29,101 +29,152 @@ | ||
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | 31 | export const talkCss = /* css */ ` |
| 32 | .talk { display: grid; grid-template-rows: auto 1fr auto; gap: .75rem; max-width: min(48rem, 100%); margin: 0 auto; min-width: 0; } | |
| 33 | .talk-shell, .talk-pane { display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; min-width: 0; align-content: start; } | |
| 34 | .talk-frame { width: 100%; height: calc(100dvh - 12rem); border: 0; } | |
| 35 | .talk > * { width: 100%; max-width: 72ch; margin-inline: auto; box-sizing: border-box; } | |
| 36 | .talk-chats .btn, .talk-list summary, .talk-back { min-height: 2.75rem; display: inline-flex; align-items: center; } | |
| 37 | .talk-list summary { cursor: pointer; } | |
| 38 | @media (max-width: 56.24rem) { | |
| 39 | [data-view="list"] :is(.talk, .talk-tabs, .talk-pane) { display: none; } | |
| 40 | .talk-shell:not([data-view="list"]) .talk-side { display: none; } | |
| 41 | [data-pane="chat"] .talk-pane { display: none; } | |
| 42 | [data-pane]:not([data-pane="chat"]) .talk { display: none; } | |
| 43 | } | |
| 32 | #main:has(> .talk-page) { padding-top: 0; padding-bottom: 0; } | |
| 33 | body:has(.talk-page) .foot { display: none; } | |
| 34 | .talk-page { display: grid; grid-template-columns: minmax(0, 1fr); } | |
| 35 | .talk { display: flex; flex-direction: column; width: 100%; max-width: 46rem; margin: 0 auto; min-width: 0; min-height: calc(100dvh - var(--topbar-h)); } | |
| 36 | .talk-side, .talk-work, [data-view="list"] :is(.talk, .talk-work) { display: none; } | |
| 37 | [data-view="list"] .talk-side { display: block; padding: 12px 0; } | |
| 38 | .talk-head { position: sticky; top: var(--topbar-h); z-index: 8; display: flex; align-items: center; gap: 4px; min-height: 3.5rem; background: var(--bg); } | |
| 39 | .talk-title { flex: 1; min-width: 0; margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } | |
| 40 | .talk-spend { display: none; gap: 12px; white-space: nowrap; } | |
| 41 | .talk-spend p { margin: 0; } | |
| 42 | .talk-head .btn-icon, .talk-head summary.btn { min-width: 2.75rem; min-height: 2.75rem; } | |
| 43 | .talk-rename { display: flex; gap: 8px; padding: 8px; } | |
| 44 | .talk-rename .input { min-width: 0; flex: 1; font-size: 16px; } | |
| 45 | .talk-tabs { align-self: center; margin-bottom: 8px; } | |
| 46 | .talk-tabs a { min-height: 2.75rem; display: inline-flex; align-items: center; } | |
| 47 | .talk-chats { display: grid; gap: 8px; } | |
| 48 | .talk-new { width: 100%; justify-content: flex-start; min-height: 2.75rem; } | |
| 49 | .talk-find .input { width: 100%; font-size: 16px; } | |
| 50 | .talk-chats .list { margin: 0; } | |
| 51 | .talk-chats .row { min-height: 2.75rem; border-radius: var(--radius-sm); } | |
| 52 | .talk-chats :is(.row-meta, .row-title) { overflow-wrap: anywhere; } | |
| 53 | .talk-chats .row-meta { font-variant-numeric: tabular-nums; } | |
| 54 | .talk-archived { padding: 8px; } | |
| 44 | 55 | @media (min-width: 56.25rem) { |
| 45 | .talk-page { display: flex; flex-direction: column; height: calc(100dvh - 7rem); } | |
| 46 | .talk-shell { grid-template-columns: 15rem minmax(0, 1fr); grid-template-areas: "side tabs" "side main"; grid-template-rows: auto minmax(0, 1fr); flex: 1; min-height: 0; } | |
| 47 | .talk-side { grid-area: side; padding-right: .75rem; } | |
| 48 | .talk-back { display: none; } | |
| 49 | .talk-tabs { grid-area: tabs; justify-self: start; } | |
| 50 | .talk, .talk-pane { grid-area: main; } | |
| 51 | .talk-side, .talk-pane, .talk { overflow-y: auto; max-height: 100%; min-height: 0; } | |
| 52 | [data-pane]:not([data-pane="chat"]) .talk, [data-pane="chat"] .talk-pane { display: none; } | |
| 56 | .talk-page { grid-template-columns: 16rem minmax(0, 1fr); } | |
| 57 | .talk-side, [data-view="list"] .talk-side { display: block; position: sticky; top: var(--topbar-h); height: calc(100dvh - var(--topbar-h)); overflow-y: auto; padding: 12px 16px 12px 0; border-inline-end: 1px solid var(--border); } | |
| 58 | [data-view="list"] .talk { display: flex; } | |
| 59 | .talk { padding-inline: 24px; } | |
| 60 | .talk-back, .talk-head > form { display: none; } | |
| 61 | .talk-spend { display: flex; } | |
| 62 | } | |
| 63 | @media (max-width: 79.99rem) { | |
| 64 | [data-split]:not([data-pane="chat"]) .talk-work { display: block; } | |
| 65 | [data-split]:not([data-pane="chat"]) .talk { min-height: 0; } | |
| 66 | [data-split]:not([data-pane="chat"]) .talk > :not(.talk-head, .talk-tabs) { display: none; } | |
| 53 | 67 | } |
| 54 | 68 | @media (min-width: 80rem) { |
| 55 | .talk-shell { grid-template-columns: 16rem minmax(0, 1fr) minmax(0, 1.2fr); grid-template-areas: "side main pane"; grid-template-rows: minmax(0, 1fr); } | |
| 56 | .talk-tabs { display: none; } | |
| 57 | .talk-pane { grid-area: pane; border-left: 1px solid var(--border); padding-left: .75rem; } | |
| 58 | [data-pane]:not([data-pane="chat"]) .talk, [data-pane="chat"] .talk-pane { display: grid; } | |
| 59 | .talk { max-width: none; margin: 0; } | |
| 69 | [data-split] { grid-template-columns: 16rem minmax(24rem, 1fr) minmax(0, 1.25fr); } | |
| 70 | [data-split] .talk-tabs { display: none; } | |
| 71 | [data-split] .talk-work { display: block; position: sticky; top: var(--topbar-h); height: calc(100dvh - var(--topbar-h)); overflow-y: auto; padding: 12px 0 12px 16px; border-inline-start: 1px solid var(--border); } | |
| 60 | 72 | } |
| 61 | @media (min-width: 120rem) { | |
| 62 | .talk-shell { grid-template-columns: 18rem minmax(0, 56rem) minmax(0, 1fr); width: 100%; max-width: 150rem; margin: 0 auto; } | |
| 63 | } | |
| 64 | .talk-crew { margin: .625rem 0; height: 1.5em; line-height: 1.5em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } | |
| 65 | .talk-log { list-style: none; margin: 0; padding: 0; display: grid; gap: .625rem; min-width: 0; align-content: start; min-height: 40dvh; } | |
| 73 | .talk-work { min-width: 0; } | |
| 74 | .talk-frame { width: 100%; height: calc(100dvh - 12rem); border: 0; border-radius: var(--radius); background: var(--card); } | |
| 75 | .talk-log { list-style: none; margin: 0; padding: 8px 0 24px; display: grid; gap: 24px; align-content: start; flex: 1; min-width: 0; font-size: 15px; line-height: 1.65; } | |
| 66 | 76 | .talk-turn { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; } |
| 67 | 77 | .talk-turn p { margin: 0 0 8px; } |
| 68 | 78 | .talk-turn p:last-child { margin-bottom: 0; } |
| 69 | 79 | .talk-turn pre { max-width: 100%; overflow-x: auto; } |
| 70 | 80 | .talk-body a { overflow-wrap: anywhere; } |
| 71 | .talk-body.prose { padding: 0; font-size: inherit; } | |
| 81 | .talk-body.prose { padding: 0; font-size: inherit; line-height: inherit; } | |
| 72 | 82 | .talk-body.prose > * { max-width: none; } |
| 73 | .talk-body.prose table { display: block; max-width: 100%; overflow-x: auto; } | |
| 74 | .talk-body.prose :is(p, ul, ol, pre, table, blockquote) { margin: 0 0 8px; } | |
| 83 | .talk-body.prose table { display: block; width: fit-content; max-width: 100%; overflow-x: auto; } | |
| 84 | .talk-body.prose :is(p, ul, ol, pre, table, blockquote) { margin: 0 0 12px; } | |
| 75 | 85 | .talk-body.prose > :last-child { margin-bottom: 0; } |
| 76 | .talk-person { justify-self: end; max-width: 85%; padding: 4px 0; white-space: pre-wrap; } | |
| 77 | .talk-agent { justify-self: start; max-width: 100%; padding: 4px 0; } | |
| 78 | .talk-tool { color: var(--muted); font-size: var(--fs-min); padding: 0 4px; } | |
| 79 | .talk-confirm { padding: 8px 0; } | |
| 86 | .talk-person, .talk-agent { display: flex; flex-wrap: wrap; align-items: center; gap: 0 4px; } | |
| 87 | .talk-person { justify-content: flex-end; } | |
| 88 | .talk-person::after { content: ""; flex-basis: 100%; order: 1; } | |
| 89 | .talk-person > :is(.talk-meta, .talk-acts) { order: 2; } | |
| 90 | .talk-person > .talk-body { max-width: min(85%, 36rem); padding: 8px 16px; border-radius: 18px; background: var(--muted); white-space: pre-wrap; } | |
| 91 | .talk-agent > .talk-body, .talk-person > .talk-body + .talk-files, .talk-agent > :is(.talk-steps, .talk-links) { flex: 1 0 100%; } | |
| 92 | .talk-agent > .talk-cost { order: 1; margin: 0 8px 0 0; font-size: 12.5px; } | |
| 93 | .talk-agent > .talk-acts { order: 2; } | |
| 94 | .talk-agent > .talk-body { max-width: 100%; } | |
| 95 | .talk-meta { display: flex; align-items: center; gap: 4px; margin: 0; font-size: 12.5px; } | |
| 96 | .talk-agent:not(:last-child):not(:has(+ .talk-person, + [data-queued])) > .talk-meta { display: none; } | |
| 97 | .talk-acts { display: flex; gap: 4px; margin-top: 4px; } | |
| 98 | .talk-act, .talk-copy { min-width: 2.75rem; min-height: 2.75rem; } | |
| 99 | .talk-copy { display: inline-flex; align-items: center; justify-content: center; padding: 0; background: none; border: 0; border-radius: var(--radius-sm); color: inherit; cursor: pointer; } | |
| 100 | .talk-copy:hover { background: var(--muted); color: var(--fg); } | |
| 101 | @media (hover: hover) and (pointer: fine) { | |
| 102 | .talk-turn > :is(.talk-meta, .talk-acts) :is(.talk-copy, .talk-act):not(:focus-visible) { opacity: 0; transition: opacity var(--dur-2) var(--ease); } | |
| 103 | .talk-turn:is(:hover, :focus-within) > :is(.talk-meta, .talk-acts) :is(.talk-copy, .talk-act) { opacity: 1; } | |
| 104 | .talk-act, .talk-copy { min-width: 2rem; min-height: 2rem; } | |
| 105 | } | |
| 106 | .talk-tool { color: var(--muted-fg); font-size: 13px; } | |
| 107 | .talk-tool summary { cursor: pointer; min-height: 2rem; display: flex; align-items: center; gap: 6px; } | |
| 108 | .talk-tool details p { margin: 0 0 8px; white-space: pre-wrap; } | |
| 109 | .talk-fold { margin-block: -8px; } | |
| 110 | [data-steps] + .talk-agent > .talk-steps { display: none; } | |
| 111 | .talk-fold > details > summary { cursor: pointer; min-height: 2.75rem; display: inline-flex; align-items: center; gap: 6px; color: var(--muted-fg); } | |
| 112 | .talk-fold > details > summary:hover { color: var(--fg); } | |
| 113 | .talk-fold-list { list-style: none; margin: 0 0 0 8px; padding: 0 0 0 12px; border-inline-start: 2px solid var(--border); display: grid; gap: 2px; } | |
| 114 | .talk-steps { margin: 4px 0 0; } | |
| 115 | .talk-live .talk-steps:last-child, .talk-status:not(:empty) { background: linear-gradient(90deg, var(--muted-fg) 40%, var(--fg) 50%, var(--muted-fg) 60%) 0 0 / 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: talk-shine 2s linear infinite; } | |
| 116 | @keyframes talk-shine { from { background-position: 100% 0; } to { background-position: 0 0; } } | |
| 117 | @media (prefers-reduced-motion: reduce) { .talk-live .talk-steps:last-child, .talk-status:not(:empty) { animation: none; color: var(--muted-fg); background: none; } } | |
| 118 | .talk-links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 2px 0 0; font-size: 13px; } | |
| 119 | .talk-confirm { padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); } | |
| 80 | 120 | .talk-confirm .bar { margin-top: 8px; gap: 8px; } |
| 81 | 121 | .talk-confirm .btn { min-height: 2.75rem; flex: 1 1 8rem; } |
| 82 | .talk-compose { position: sticky; bottom: var(--kb, 0px); background: var(--bg); padding: .5rem 0 max(.5rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); z-index: 8; } | |
| 83 | .talk-compose textarea { width: 100%; min-height: 44px; max-height: 40dvh; font-size: 16px; resize: none; overflow-y: auto; box-sizing: border-box; } | |
| 84 | .talk-compose .bar { margin-top: 6px; gap: 8px; align-items: center; flex-wrap: wrap; } | |
| 85 | .talk-status { min-height: 1.5em; margin: 0; } | |
| 86 | .talk-context, .talk-total, .talk-cost { margin: 0; } | |
| 87 | .talk-meta { margin: 4px 0 0; display: flex; gap: 6px; align-items: center; } | |
| 88 | .talk-copy { margin-left: auto; background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 6px 8px; min-height: 2rem; opacity: .7; } | |
| 89 | .talk-copy:hover { opacity: 1; text-decoration: underline; } | |
| 90 | .talk-plain { white-space: pre-wrap; } | |
| 91 | .talk-tool summary { cursor: pointer; padding: 6px 0; min-height: 1.5rem; } | |
| 92 | .talk-tool details p { margin: 0 0 8px; white-space: pre-wrap; } | |
| 93 | .talk-steps { margin: 4px 0 0; } | |
| 94 | .talk-links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 2px 0 0; } | |
| 95 | .talk-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; } | |
| 96 | .talk-jump { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 9; min-height: 2.75rem; border-radius: 999px; box-shadow: var(--shadow-2); gap: 6px; } | |
| 122 | .talk:has(.talk-hello) .talk-log { flex: 0; margin-top: auto; } | |
| 123 | .talk:has(.talk-hello) .talk-compose { position: static; margin-bottom: auto; padding-bottom: 32px; } | |
| 124 | .talk-hello { align-self: center; padding: 0; text-align: center; } | |
| 125 | .talk-hello h2 { margin: 0 0 8px; font-size: 20px; font-weight: 620; letter-spacing: -.02em; } | |
| 126 | .talk-hello p { max-width: 32rem; margin: 0 auto; } | |
| 127 | .talk-suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 24px; } | |
| 128 | /* A narrow phone keeps the greeting and the composer in the eye line whatever the fonts wrap to. */ | |
| 129 | @media (max-width: 30rem) { .talk-suggest { margin-top: 16px; } .talk:has(.talk-hello) .talk-compose { padding-bottom: 16px; } .talk:has(.talk-hello) { padding-bottom: 10vh; } } | |
| 130 | .talk-suggest .btn { min-height: 2.75rem; border-radius: 999px; } | |
| 131 | .talk-compose { position: sticky; bottom: var(--kb, 0px); z-index: 8; padding: 12px 0 max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 12px); } | |
| 132 | .talk-box { display: grid; border: 1px solid var(--border-strong); border-radius: 18px; background: var(--card); box-shadow: var(--shadow-1); transition: border-color var(--dur-2) var(--ease); } | |
| 133 | .talk-box:focus-within { border-color: var(--muted-fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted-fg) 22%, transparent); } | |
| 134 | .talk-box:has([aria-invalid="true"]) { border-color: var(--danger); } | |
| 135 | @media (prefers-reduced-motion: reduce) { .talk-box, .talk-turn :is(.talk-copy, .talk-act) { transition: none; } } | |
| 136 | .talk-input { width: 100%; min-height: 48px; max-height: 40dvh; padding: 12px 16px 4px; border: 0; background: none; color: inherit; font: inherit; font-size: 16px; line-height: 1.5; resize: none; overflow-y: auto; box-sizing: border-box; } | |
| 137 | .talk-input:focus-visible { outline-color: transparent; } | |
| 138 | @media (forced-colors: active) { .talk-box:focus-within { outline: 2px solid CanvasText; } } | |
| 139 | .talk-tools { display: flex; align-items: center; gap: 4px; padding: 4px 8px 8px; min-width: 0; } | |
| 140 | .talk-tools .btn-icon { min-width: 2.75rem; min-height: 2.75rem; border-radius: 999px; } | |
| 141 | .talk-send, .talk-stop { width: 2.75rem; } | |
| 142 | .talk-send[hidden], .talk-stop[hidden], .talk-steer[hidden], .talk-dictate[hidden], [data-attach][hidden], .talk-jump[hidden] { display: none; } | |
| 143 | .talk-steer { min-height: 2.75rem; border-radius: 999px; } | |
| 144 | .talk-hint { margin-inline-end: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; } | |
| 145 | @media (hover: none) { .talk-hint { display: none; } } | |
| 146 | .talk-dictate[aria-pressed="true"] { background: var(--accent); color: var(--bg); } | |
| 147 | .talk-foot { display: flex; gap: 12px; min-height: 1.5em; margin: 6px 4px 0; } | |
| 148 | .talk-foot p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } | |
| 149 | .talk-status:empty { display: none; } | |
| 150 | [data-answering] .talk-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } | |
| 151 | .talk-status:not(:empty) + .talk-crew { display: none; } | |
| 152 | .talk-crew { flex: 1; min-width: 0; } | |
| 153 | .talk-error { margin: 6px 4px 0; color: var(--danger); } | |
| 154 | .talk-error[hidden] { display: none; } | |
| 155 | .talk-jump { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); min-height: 2.75rem; border-radius: 999px; box-shadow: var(--shadow-2); gap: 6px; } | |
| 97 | 156 | .talk-jump[data-follow="pause"] .ico + .ico, .talk-jump:not([data-follow="pause"]) .ico:first-child, .talk-jump:not([data-new]) .talk-dot { display: none; } |
| 98 | 157 | .talk-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); } |
| 99 | .talk-error { margin: 4px 0 0; color: var(--danger); } | |
| 100 | .talk-error[hidden] { display: none; } | |
| 101 | .talk-jump[hidden], .talk-dictate[hidden] { display: none; } | |
| 102 | .talk-dictate[aria-pressed="true"] { background: var(--accent); color: var(--bg); } | |
| 103 | .talk-body pre { position: relative; } | |
| 104 | .talk-body pre .talk-copy { position: absolute; top: 2px; right: 2px; } | |
| 105 | .talk-chips, .talk-files { margin: 0 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; } | |
| 158 | .talk-code { margin: 0 0 12px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; } | |
| 159 | .talk-code-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 0 12px; border-bottom: 1px solid var(--border); background: var(--muted); color: var(--muted-fg); font-size: 12.5px; } | |
| 160 | ||
| 161 | .talk-body .talk-code pre { margin: 0; border: 0; border-radius: 0; } | |
| 162 | .talk-chips, .talk-files { margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; } | |
| 163 | .talk-chips { padding: 8px 8px 0; } | |
| 106 | 164 | .talk-chips:empty { display: none; } |
| 107 | .talk-files { justify-content: flex-end; } | |
| 108 | .talk-more { text-align: center; } | |
| 109 | .talk-chats, .talk-here { margin-bottom: 12px; } | |
| 110 | @supports selector(::details-content) { @media (min-width: 56.25rem) { .talk-list > summary { display: none; } .talk-list::details-content { content-visibility: visible; } } } | |
| 111 | .talk-chats :is(.row-meta, .row-title) { overflow-wrap: anywhere; } | |
| 112 | .talk-chats .row-meta { font-variant-numeric: tabular-nums; } | |
| 113 | .talk-turn:target { box-shadow: -2px 0 0 var(--muted); scroll-margin-top: 4rem; } | |
| 165 | .talk-more { text-align: center; margin: 8px 0 0; } | |
| 166 | .talk-turn:target { box-shadow: -2px 0 0 var(--muted-fg); scroll-margin-top: 8rem; } | |
| 114 | 167 | .talk-replaced { opacity: .55; } |
| 115 | 168 | .talk-failed form { margin-top: 6px; } |
| 116 | .talk-compose .btn, .talk-suggest .btn, .talk-failed .btn, .talk-act { min-height: 2.75rem; } | |
| 117 | .talk-keys { border-bottom: 1px solid var(--border); padding: 0 0 .75rem; } | |
| 169 | .talk-failed .btn { min-height: 2.75rem; } | |
| 170 | .talk-keys { border-top: 1px solid var(--border); padding: 12px 0; } | |
| 118 | 171 | .talk-keys[hidden] { display: none; } |
| 119 | .talk-keys dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; } | |
| 172 | .talk-keys dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; } | |
| 120 | 173 | .talk-keys dt { font-weight: 600; } |
| 121 | 174 | .talk-keys dd { margin: 0; } |
| 122 | 175 | .talk-queued { opacity: .7; } |
| 123 | .talk-acts { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; } | |
| 124 | .talk-agent .talk-acts { justify-content: flex-start; } | |
| 176 | .talk-queued .btn { min-height: 2.75rem; } | |
| 125 | 177 | `; |
| 126 | ||
| 127 | 178 | /** |
| 128 | 179 | * The desktop keys (#15816). The page draws its help list from this and the test reads it, so |
| 129 | 180 | * the words are written once. `id` names the binding in the script below. |
| @@ -140,7 +191,7 @@ export const TALK_KEYS: readonly { readonly id: string; readonly keys: string; r | ||
| 140 | 191 | ]; |
| 141 | 192 | |
| 142 | 193 | /** The send button: the bar's one button that is not Stop, Steer or Dictate. */ |
| 143 | export const sendSelector = ".bar button.btn:not([data-stop]):not([data-steer]):not([data-dictate])"; | |
| 194 | export const sendSelector = ".talk-send"; | |
| 144 | 195 | |
| 145 | 196 | /** |
| 146 | 197 | * Dictation (#13943): shown only where the browser can recognise speech on the device, since a |
| @@ -154,7 +205,7 @@ export const dictateJs = ` | ||
| 154 | 205 | mic.hidden = false; |
| 155 | 206 | let rec = null; |
| 156 | 207 | const words = { "not-allowed": "Microphone access is blocked.", "no-speech": "Heard nothing.", "language-not-supported": "This language can't be heard on this device." }; |
| 157 | const off = () => { rec = null; mic.setAttribute("aria-pressed", "false"); mic.textContent = "Dictate"; }; | |
| 208 | const off = () => { rec = null; mic.setAttribute("aria-pressed", "false"); mic.setAttribute("aria-label", "Dictate"); }; | |
| 158 | 209 | mic.onclick = () => { |
| 159 | 210 | if (rec) return rec.stop(); |
| 160 | 211 | rec = new Rec(); |
| @@ -166,7 +217,7 @@ export const dictateJs = ` | ||
| 166 | 217 | }; |
| 167 | 218 | rec.onerror = (e) => say(words[e.error] || "Dictation stopped."); |
| 168 | 219 | rec.onend = off; |
| 169 | try { rec.start(); mic.setAttribute("aria-pressed", "true"); mic.textContent = "Stop dictating"; } catch (_) { off(); say("Dictation could not start."); } | |
| 220 | try { rec.start(); mic.setAttribute("aria-pressed", "true"); mic.setAttribute("aria-label", "Stop dictating"); } catch (_) { off(); say("Dictation could not start."); } | |
| 170 | 221 | }; |
| 171 | 222 | } |
| 172 | 223 | `; |
| @@ -221,6 +272,14 @@ export const draftJs = ` | ||
| 221 | 272 | */ |
| 222 | 273 | export const liveJs = ` |
| 223 | 274 | const liveDrop = () => { const l = document.getElementById("live"); if (l) l.remove(); }; |
| 275 | const liveMorph = (el, nodes) => { | |
| 276 | let i = 0; | |
| 277 | while (i < nodes.length && el.childNodes[i] && el.childNodes[i].isEqualNode(nodes[i])) i++; | |
| 278 | const o = el.childNodes[i], n = nodes[i]; | |
| 279 | if (o && n && o.nodeName === "DIV" && n.nodeName === "DIV" && o.className === n.className) { liveMorph(o, [...n.childNodes]); i++; } | |
| 280 | while (el.childNodes.length > i) el.lastChild.remove(); | |
| 281 | el.append(...nodes.slice(i)); | |
| 282 | }; | |
| 224 | 283 | const liveOn = (src) => { |
| 225 | 284 | src.addEventListener("live", (e) => { |
| 226 | 285 | const f = JSON.parse(e.data); |
| @@ -231,8 +290,11 @@ export const liveJs = ` | ||
| 231 | 290 | l.setAttribute("aria-hidden", "true"); |
| 232 | 291 | log.insertBefore(l, log.querySelector("[data-queued]")); |
| 233 | 292 | } |
| 234 | l.innerHTML = f.html; | |
| 235 | if (f.tool || !f.html) l.append(Object.assign(document.createElement("p"), { className: "talk-steps small muted", textContent: f.tool || "Thinking…" })); | |
| 293 | const t = document.createElement("template"); | |
| 294 | t.innerHTML = f.html; | |
| 295 | const next = [...t.content.childNodes]; | |
| 296 | if (f.tool || !f.html) next.push(Object.assign(document.createElement("p"), { className: "talk-steps small muted", textContent: f.tool || "Thinking…" })); | |
| 297 | liveMorph(l, next); | |
| 236 | 298 | if (f.tool && status.textContent !== f.tool) say(f.tool); |
| 237 | 299 | }); |
| 238 | 300 | src.addEventListener("turn", () => queueMicrotask(() => { const l = document.getElementById("live"); if (l) log.insertBefore(l, log.querySelector("[data-queued]")); })); |
| @@ -359,6 +421,7 @@ if (root) { | ||
| 359 | 421 | const grow = () => { box.style.height = "auto"; box.style.height = Math.min(box.scrollHeight, window.innerHeight * 0.4) + "px"; }; |
| 360 | 422 | box.addEventListener("input", () => { |
| 361 | 423 | grow(); |
| 424 | paint(); | |
| 362 | 425 | if (!err.hidden) { err.hidden = true; box.removeAttribute("aria-invalid"); } |
| 363 | 426 | clearTimeout(draftTimer); |
| 364 | 427 | draftTimer = setTimeout(saveDraft, 300); |
| @@ -367,10 +430,13 @@ if (root) { | ||
| 367 | 430 | window.addEventListener("pagehide", saveDraft); |
| 368 | 431 | document.addEventListener("visibilitychange", () => { if (document.visibilityState === "hidden") saveDraft(); }); |
| 369 | 432 | grow(); |
| 433 | const icons = document.getElementById("talk-ico"); | |
| 434 | const ico = (n) => icons ? icons.content.children[n].cloneNode(true) : document.createTextNode(n ? "Copied" : "Copy"); | |
| 370 | 435 | const copyButton = (label) => { |
| 371 | const b = Object.assign(document.createElement("button"), { type: "button", className: "talk-copy", textContent: "Copy" }); | |
| 436 | const b = Object.assign(document.createElement("button"), { type: "button", className: "talk-copy", title: label }); | |
| 372 | 437 | b.setAttribute("data-copy", ""); |
| 373 | 438 | b.setAttribute("aria-label", label); |
| 439 | b.append(ico(0)); | |
| 374 | 440 | return b; |
| 375 | 441 | }; |
| 376 | 442 | root.addEventListener("click", async (e) => { |
| @@ -386,16 +452,44 @@ if (root) { | ||
| 386 | 452 | } |
| 387 | 453 | const c = e.target.closest("[data-copy]"); |
| 388 | 454 | if (!c) return; |
| 389 | const pre = c.closest("pre"); | |
| 390 | const src = pre ? pre.querySelector("code") : c.closest(".talk-turn").querySelector(".talk-body"); | |
| 391 | try { await navigator.clipboard.writeText(src.textContent); c.textContent = "Copied"; say("Copied."); } catch (_) { say("Copy is not allowed here."); } | |
| 392 | setTimeout(() => { c.textContent = "Copy"; }, 1500); | |
| 455 | const code = c.closest(".talk-code"); | |
| 456 | const src = code ? code.querySelector("pre code, pre") : c.closest(".talk-turn").querySelector(".talk-body"); | |
| 457 | try { await navigator.clipboard.writeText(src.textContent); c.replaceChildren(ico(1)); say("Copied."); } catch (_) { say("Copy is not allowed here."); } | |
| 458 | setTimeout(() => { c.replaceChildren(ico(0)); }, 1500); | |
| 393 | 459 | }); |
| 460 | // A turn from the stream lands before any queued message (the live block is put back after it); | |
| 461 | // a step joins the run of steps it follows, folded under one "3 steps". | |
| 462 | const place = (markup) => { | |
| 463 | const t = document.createElement("template"); | |
| 464 | t.innerHTML = markup.trim(); | |
| 465 | const li = t.content.firstElementChild; | |
| 466 | if (!li) return; | |
| 467 | const at = log.querySelector("#live, [data-queued]"); | |
| 468 | const put = (x) => (at ? at.before(x) : log.append(x)); | |
| 469 | if (!li.hasAttribute("data-step")) return put(li); | |
| 470 | const prev = at ? at.previousElementSibling : log.lastElementChild; | |
| 471 | let fold = prev && prev.hasAttribute("data-steps") ? prev : null; | |
| 472 | if (!fold) { | |
| 473 | fold = Object.assign(document.createElement("li"), { className: "talk-fold" }); | |
| 474 | fold.setAttribute("data-steps", ""); | |
| 475 | const d = document.createElement("details"); | |
| 476 | d.append(Object.assign(document.createElement("summary"), { className: "small muted" }), Object.assign(document.createElement("ol"), { className: "talk-fold-list" })); | |
| 477 | fold.append(d); | |
| 478 | put(fold); | |
| 479 | } | |
| 480 | fold.querySelector("ol").append(li); | |
| 481 | const n = fold.querySelector("ol").children.length; | |
| 482 | fold.querySelector("summary").textContent = n === 1 ? li.querySelector("summary").firstChild.textContent.trim() : n + " steps"; | |
| 483 | }; | |
| 394 | 484 | const decorate = (scope) => { |
| 395 | 485 | scope.querySelectorAll(".talk-body pre:not([data-c])").forEach((pre) => { |
| 396 | 486 | pre.dataset.c = "1"; |
| 397 | 487 | pre.tabIndex = 0; |
| 398 | pre.insertBefore(copyButton("Copy this code"), pre.firstChild); | |
| 488 | const wrap = Object.assign(document.createElement("div"), { className: "talk-code" }); | |
| 489 | const head = Object.assign(document.createElement("div"), { className: "talk-code-head" }); | |
| 490 | head.append(Object.assign(document.createElement("span"), { textContent: ((pre.querySelector("code") || pre).className.match(/language-([\\w+#-]+)/) || [])[1] || "" }), copyButton("Copy this code")); | |
| 491 | pre.replaceWith(wrap); | |
| 492 | wrap.append(head, pre); | |
| 399 | 493 | }); |
| 400 | 494 | scope.querySelectorAll(".talk-turn:not([data-m]) > .talk-meta").forEach((m) => { |
| 401 | 495 | m.parentNode.dataset.m = "1"; |
| @@ -426,10 +520,22 @@ if (root) { | ||
| 426 | 520 | const stopBtn = form.querySelector("[data-stop]"); |
| 427 | 521 | const steerBtn = form.querySelector("[data-steer]"); |
| 428 | 522 | let answering = false; |
| 523 | const sendWord = action.getAttribute("aria-label"); | |
| 524 | // One round button: Send, or Stop while an answer runs and the box is empty; words typed meanwhile | |
| 525 | // queue, and Steer appears beside it to send them now. Nothing in the row wraps or moves. | |
| 526 | const paint = () => { | |
| 527 | const typed = box.value.trim() !== ""; | |
| 528 | stopBtn.hidden = !answering || typed; | |
| 529 | steerBtn.hidden = !answering || !typed; | |
| 530 | action.hidden = answering && !typed; | |
| 531 | const w = answering ? "Queue: it sends after this answer" : sendWord; | |
| 532 | action.setAttribute("aria-label", w); | |
| 533 | action.title = w; | |
| 534 | }; | |
| 429 | 535 | const mode = (on) => { |
| 430 | 536 | answering = on; |
| 431 | action.textContent = on ? "Queue" : "Send"; | |
| 432 | stopBtn.hidden = steerBtn.hidden = !on; | |
| 537 | form.toggleAttribute("data-answering", on); | |
| 538 | paint(); | |
| 433 | 539 | // The composer just changed (Steer and Stop, a row that wraps): a follower stays at the end |
| 434 | 540 | // now, in this task, rather than for a frame until the size observer catches up. |
| 435 | 541 | if (stuck) toEnd(); |
| @@ -473,8 +579,7 @@ if (root) { | ||
| 473 | 579 | const turn = JSON.parse(e.data); |
| 474 | 580 | last = turn.id; |
| 475 | 581 | if (!document.getElementById("t-" + turn.id)) { |
| 476 | const q = log.querySelector("[data-queued]"); | |
| 477 | if (q) q.insertAdjacentHTML("beforebegin", turn.html); else log.insertAdjacentHTML("beforeend", turn.html); | |
| 582 | place(turn.html); | |
| 478 | 583 | decorate(log); |
| 479 | 584 | if (!stuck) say("New message"); |
| 480 | 585 | } |
| @@ -488,6 +593,7 @@ if (root) { | ||
| 488 | 593 | source.addEventListener("done", (e) => { |
| 489 | 594 | log.removeAttribute("aria-busy"); |
| 490 | 595 | mode(false); dropActs(); say("The forge replied."); source.close(); source = null; |
| 596 | setTimeout(() => { if (status.textContent === "The forge replied.") say(""); }, 4000); | |
| 491 | 597 | document.querySelectorAll("[data-frame]").forEach((f) => { f.src = f.src; }); |
| 492 | 598 | const o = JSON.parse(e.data), c = root.querySelector("[data-context]"), t = root.querySelector("[data-total]"); |
| 493 | 599 | for (const k of o.costs || []) { const li = document.getElementById(k.id); if (li && !li.querySelector(".talk-cost")) li.insertAdjacentHTML("beforeend", k.html); } |
| @@ -509,9 +615,9 @@ if (root) { | ||
| 509 | 615 | }; |
| 510 | 616 | }; |
| 511 | 617 | const chips = form.querySelector("[data-chips]"); |
| 512 | const picker = form.querySelector("[data-pick]"); | |
| 513 | const attachLabel = form.querySelector("[data-attach]"); | |
| 514 | attachLabel.hidden = false; | |
| 618 | const picker = form.querySelector("[data-files]"); | |
| 619 | const attach = form.querySelector("[data-attach]"); | |
| 620 | if (attach) { attach.hidden = false; attach.addEventListener("click", () => picker.click()); } | |
| 515 | 621 | const attached = []; |
| 516 | 622 | const drawChip = (f) => { |
| 517 | 623 | const li = Object.assign(document.createElement("span"), { className: "badge", textContent: f.name + " " }); |
| @@ -542,7 +648,7 @@ if (root) { | ||
| 542 | 648 | }; |
| 543 | 649 | ${dictateJs} |
| 544 | 650 | const take = (files) => { for (const f of files) upload(f); }; |
| 545 | picker.addEventListener("change", () => { take(picker.files); picker.value = ""; }); | |
| 651 | if (picker) picker.addEventListener("change", () => { take(picker.files); picker.value = ""; }); | |
| 546 | 652 | box.addEventListener("paste", (e) => { |
| 547 | 653 | const files = [...(e.clipboardData ? e.clipboardData.files : [])]; |
| 548 | 654 | if (files.length) { e.preventDefault(); take(files); } |
| @@ -554,6 +660,7 @@ ${dictateJs} | ||
| 554 | 660 | take(e.dataTransfer.files); |
| 555 | 661 | }); |
| 556 | 662 | const send = async (e) => { |
| 663 | if (form.hasAttribute("data-build")) return; | |
| 557 | 664 | e.preventDefault(); |
| 558 | 665 | const text = box.value.trim(); |
| 559 | 666 | if (!text) { if (attached.length) say("Add a few words about what you attached."); return; } |
src/web/pages/talk_preview.ts +4
| @@ -22,6 +22,8 @@ export interface Pane { | ||
| 22 | 22 | readonly html: Html; |
| 23 | 23 | /** The one origin the frame needs in `frame-src`, when there is something running to frame. */ |
| 24 | 24 | readonly frame: string | undefined; |
| 25 | /** Something is running to frame: the page gives the pane its room only then. */ | |
| 26 | readonly live: boolean; | |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | export const VIEWS = ["preview", "code", "diff"] as const; |
| @@ -30,6 +32,7 @@ export type View = (typeof VIEWS)[number]; | ||
| 30 | 32 | export function talkPane(ctx: Ctx, user: User, name: string | undefined, works: ReadonlyMap<string, Work>, view: View = "preview", apps?: Apps): Pane { |
| 31 | 33 | const empty = (words: Html): Pane => ({ |
| 32 | 34 | frame: undefined, |
| 35 | live: false, | |
| 33 | 36 | html: html`<aside class="talk-pane" aria-label="Preview">${words}</aside>`, |
| 34 | 37 | }); |
| 35 | 38 | if (name === undefined) return empty(emptyLine("talkRepos")); |
| @@ -52,6 +55,7 @@ export function talkPane(ctx: Ctx, user: User, name: string | undefined, works: | ||
| 52 | 55 | : html`<iframe class="talk-frame" data-frame src="${url}" title="Live preview of ${name}" referrerpolicy="no-referrer" sandbox="allow-scripts allow-same-origin allow-forms allow-popups"></iframe>`; |
| 53 | 56 | return { |
| 54 | 57 | frame: ws.origin, |
| 58 | live: url !== undefined, | |
| 55 | 59 | html: html`<aside class="talk-pane" aria-label="Preview of ${name}"> |
| 56 | 60 | <p class="small"><strong>${name}</strong> · ${pull === undefined ? "Production" : `Pull #${String(pull)}`}${url === undefined ? null : html` · <a href="${url}" target="_blank" rel="noopener">Open on its own</a>`}</p> |
| 57 | 61 | <nav class="tabs" aria-label="Preview, code or diff">${tab("preview", "Preview")}${tab("code", "Code")}${tab("diff", "Diff")}</nav> |
src/web/talk_build.ts +13 −22
| @@ -18,7 +18,7 @@ import { signInFirst, notFoundPage } from "./chrome.ts"; | ||
| 18 | 18 | import { readForm } from "./form.ts"; |
| 19 | 19 | import { html, type Html } from "./html.ts"; |
| 20 | 20 | import { flashTo, redirect } from "./layout.ts"; |
| 21 | import { btn, time } from "./ui.ts"; | |
| 21 | import { btn, icon, time } from "./ui.ts"; | |
| 22 | 22 | import type { User } from "../core/users.ts"; |
| 23 | 23 | |
| 24 | 24 | const TEMPLATE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}\/[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/; |
| @@ -31,24 +31,17 @@ export function chosenTemplate(db: Database, user: User, asked: string | null): | ||
| 31 | 31 | return asked !== null && TEMPLATE.test(asked) && offeredTemplates(db, user).includes(asked) ? asked : undefined; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | /** The empty Talk's one box: what to build, starters that choose a template, one Send. */ | |
| 35 | export function buildBox(db: Database, user: User, chosen: string | undefined): Html { | |
| 34 | /** | |
| 35 | * An empty Talk in build mode (`?build=1`): the marked templates to start from, as chips. The | |
| 36 | * composer itself is the box: it posts the words to `POST /talk/build`. A chosen chip is current; | |
| 37 | * choosing it again starts from nothing. | |
| 38 | */ | |
| 39 | export function templateChips(db: Database, user: User, here: string, chosen: string | undefined): Html { | |
| 36 | 40 | const starters = offeredTemplates(db, user).slice(0, STARTERS_MAX); |
| 37 | return html`<section class="talk-build-box" aria-labelledby="build-q"> | |
| 38 | <h2 id="build-q">What do you want to build?</h2> | |
| 39 | <form method="post" action="/talk/build"> | |
| 40 | ${chosen === undefined ? null : html`<input type="hidden" name="template" value="${chosen}" />`} | |
| 41 | <textarea class="input" name="prompt" rows="3" maxlength="${WORDS_MAX}" required aria-labelledby="build-q" placeholder="A tip calculator for friends"></textarea> | |
| 42 | <div class="bar"> | |
| 43 | ${chosen === undefined ? null : html`<span class="small muted">Starting from ${chosen}</span>`} | |
| 44 | <span class="spacer"></span> | |
| 45 | ${btn("Build it", { variant: "primary" })} | |
| 46 | </div> | |
| 47 | </form> | |
| 48 | ${starters.length === 0 | |
| 49 | ? null | |
| 50 | : html`<ul class="talk-build-starters small" aria-label="Start from">${starters.map((t) => html`<li><a href="/talk?template=${encodeURIComponent(t)}" ${t === chosen ? html`aria-current="true"` : null}>${t}</a></li>`)}</ul>`} | |
| 51 | </section>`; | |
| 41 | if (starters.length === 0) return html``; | |
| 42 | return html`<nav class="talk-suggest" aria-label="Start from a template">${starters.map( | |
| 43 | (t) => html`<a class="btn" data-size="sm" href="${here}?build=1${t === chosen ? "" : `&template=${encodeURIComponent(t)}`}"${t === chosen ? html` aria-current="true"` : null}>${t === chosen ? html`${icon("check")} ` : null}${t}</a>`, | |
| 44 | )}</nav>`; | |
| 52 | 45 | } |
| 53 | 46 | |
| 54 | 47 | /** What a diff changed, file by file; the lines themselves are one step deeper, on the pull. */ |
| @@ -152,9 +145,7 @@ export async function talkPublish(ctx: Ctx): Promise<Response> { | ||
| 152 | 145 | |
| 153 | 146 | /** Styles for the box and the panel; added to Talk's own only on a page that draws one. Spacing is the 4px scale. */ |
| 154 | 147 | export const buildCss = /* css */ ` |
| 155 | .talk-build-box, .talk-build { width: 100%; max-width: min(48rem, 100%); margin: 0 auto 16px; display: grid; gap: 8px; } | |
| 156 | .talk-build-box textarea { width: 100%; } | |
| 157 | .talk-build-starters, .talk-build-versions, .talk-build-files { margin: 0; padding-left: 24px; } | |
| 158 | .talk-build-starters { display: flex; flex-wrap: wrap; gap: 4px 16px; padding-left: 0; list-style: none; } | |
| 148 | .talk-build { width: 100%; display: grid; gap: 8px; } | |
| 149 | .talk-build-versions, .talk-build-files { margin: 0; padding-left: 24px; } | |
| 159 | 150 | .talk-build-versions [aria-current] { font-weight: 600; } |
| 160 | 151 | `; |
test/talk-build.test.ts +7 −3
| @@ -161,7 +161,7 @@ test("a build is its owner's alone, and every change is refused without sign-in | ||
| 161 | 161 | expect(cross.status).toBe(403); |
| 162 | 162 | }); |
| 163 | 163 | |
| 164 | test("the page: one box on an empty Talk, then the versions, Restore and Publish as plain forms", async () => { | |
| 164 | test("the page: Build an app on an empty Talk opens the composer to build, then the versions, Restore and Publish as plain forms", async () => { | |
| 165 | 165 | const { createSession } = await import("../src/core/sessions.ts"); |
| 166 | 166 | const cookie = `forge_session=${createSession(app.db, alice.id).token}`; |
| 167 | 167 | const get = (path: string) => fetch(`${servers.url}${path}`, { redirect: "manual", headers: { cookie } }); |
| @@ -172,8 +172,12 @@ test("the page: one box on an empty Talk, then the versions, Restore and Publish | ||
| 172 | 172 | expect(empty).toBe(404); |
| 173 | 173 | const fresh = await call("POST", "/api/v1/conversations", {}); |
| 174 | 174 | const home = await (await get(`/talk/${fresh.body["conversation"].id}`)).text(); |
| 175 | expect(home).toContain("What do you want to build?"); | |
| 176 | expect(home).toContain('action="/talk/build"'); | |
| 175 | expect(home).toContain(`href="/talk/${fresh.body["conversation"].id}?build=1"`); | |
| 176 | expect(home).not.toContain('action="/talk/build"'); | |
| 177 | const asked = await (await get(`/talk/${fresh.body["conversation"].id}?build=1`)).text(); | |
| 178 | expect(asked).toContain("What do you want to build?"); | |
| 179 | expect(asked).toMatch(/<form class="talk-compose" id="compose" method="post" action="\/talk\/build"[^>]* data-build>/); | |
| 180 | expect(asked).toContain('name="prompt"'); | |
| 177 | 181 | |
| 178 | 182 | const sent = await post("/talk/build", { prompt: "a recipe box" }); |
| 179 | 183 | expect(sent.status).toBe(303); |
test/talk-follow.test.ts +3 −3
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | * Following a reply on /talk (#15734), in a real Chromium at a phone width (the page scrolls) and a | |
| 3 | * laptop width (the talk column scrolls): the thread keeps its end in view while the reader is at | |
| 2 | * Following a reply on /talk (#15734), in a real Chromium at a phone and a laptop width, where | |
| 3 | * the window is the one scroller (the rule reads whichever element scrolls): the thread keeps its end in view while the reader is at | |
| 4 | 4 | * the true end of whichever element scrolls; a wheel up, PageUp or the Pause control lets go and |
| 5 | 5 | * then nothing moves; Resume, End and Send come back to the end. And the composer never paints as |
| 6 | 6 | * an error after a send: it is invalid only when a message could not be sent, with the reason |
| @@ -144,7 +144,7 @@ const drive = async (width: number, height: number) => | ||
| 144 | 144 | |
| 145 | 145 | for (const [width, height, scroller] of [ |
| 146 | 146 | [390, 844, "page"], |
| 147 | [1280, 800, "column"], | |
| 147 | [1280, 800, "page"], | |
| 148 | 148 | ] as const) { |
| 149 | 149 | test.skipIf(chromium === undefined)( |
| 150 | 150 | `at ${width} px the ${scroller} follows, pauses, lets go and comes back; a send never paints an error`, |
test/talk-layout.test.ts +28 −29
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | /** |
| 2 | * The Talk shell at three sizes (#15734), measured in a real Chromium: a phone (360 px) shows the | |
| 2 | * The Talk shell at every size (#15734), measured in a real Chromium: a phone (360 px) shows the | |
| 3 | 3 | * chat alone with its composer inside the screen; a tablet (900 px) puts the chats beside the chat; |
| 4 | * a laptop (1280 px) adds the preview as a third column; a wide monitor (2560 px) keeps the reading | |
| 5 | * column at a readable width. At every size the page does not scroll sideways and the composer is | |
| 6 | * on screen. Skipped, and says so, where no Chromium starts. | |
| 4 | * a laptop (1280 px) and a wide monitor (2560 px) centre a reading column beside them, with no | |
| 5 | * third column while nothing runs. At every size the page does not scroll sideways, the composer | |
| 6 | * is on screen and the window is the thread's one scroller; an empty conversation puts the | |
| 7 | * greeting and the composer mid-screen. Skipped, and says so, where no Chromium starts. | |
| 7 | 8 | */ |
| 8 | 9 | import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"; |
| 9 | 10 | import { mkdtemp, rm } from "node:fs/promises"; |
| @@ -26,7 +27,7 @@ const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | ||
| 26 | 27 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the Talk layout is not measured"); |
| 27 | 28 | |
| 28 | 29 | interface Box { left: number; right: number; top: number; bottom: number; width: number } |
| 29 | interface Seen { scrollWidth: number; vw: number; vh: number; side: Box | null; chat: Box | null; pane: Box | null; compose: Box | null; build: Box | null; tabs: boolean; back: Box | null; long: { boxScrolls: boolean; boxWidth: number; linkRight: number } | null } | |
| 30 | interface Seen { scrollWidth: number; vw: number; vh: number; side: Box | null; chat: Box | null; pane: Box | null; compose: Box | null; hello: Box | null; ownScroll: boolean; tabs: boolean; back: Box | null; long: { boxScrolls: boolean; boxWidth: number; linkRight: number } | null } | |
| 30 | 31 | |
| 31 | 32 | let dir: string; |
| 32 | 33 | let app: App; |
| @@ -72,7 +73,8 @@ const EXPRESSION = `(() => { | ||
| 72 | 73 | scrollWidth: document.documentElement.scrollWidth, |
| 73 | 74 | vw: document.documentElement.clientWidth, |
| 74 | 75 | vh: window.innerHeight, |
| 75 | side: box(".talk-chats"), chat: box(".talk-log"), pane: box(".talk-pane"), compose: box(".talk-compose"), build: box(".talk-build-box"), back: box(".talk-tabs .talk-back"), | |
| 76 | side: box(".talk-chats"), chat: box(".talk-log"), pane: box(".talk-work"), compose: box(".talk-compose"), hello: box(".talk-hello"), back: box(".talk-back"), | |
| 77 | ownScroll: [".talk", ".talk-log"].some((sel) => { const e = document.querySelector(sel); return !!e && /auto|scroll/.test(getComputedStyle(e).overflowY); }), | |
| 76 | 78 | tabs: !!tabs && getComputedStyle(tabs).display !== "none", |
| 77 | 79 | long: longLine(), |
| 78 | 80 | }); |
| @@ -100,12 +102,14 @@ const longFits = (s: Seen, width: number): void => { | ||
| 100 | 102 | expect(s.long!.linkRight).toBeLessThanOrEqual(width); |
| 101 | 103 | }; |
| 102 | 104 | |
| 105 | /** No sideways scroll, the composer on screen, and the window the thread's one scroller. */ | |
| 103 | 106 | const fits = (s: Seen, width: number): void => { |
| 104 | 107 | expect(s.vw).toBe(width); |
| 105 | 108 | expect(s.scrollWidth).toBeLessThanOrEqual(width); |
| 106 | 109 | expect(s.compose).not.toBeNull(); |
| 107 | 110 | expect(s.compose!.bottom).toBeLessThanOrEqual(s.vh + 1); |
| 108 | 111 | expect(s.compose!.top).toBeGreaterThanOrEqual(0); |
| 112 | expect(s.ownScroll).toBe(false); | |
| 109 | 113 | }; |
| 110 | 114 | |
| 111 | 115 | test.skipIf(chromium === undefined)("a phone shows the chat alone, the composer on screen, nothing scrolling sideways", async () => { |
| @@ -113,17 +117,14 @@ test.skipIf(chromium === undefined)("a phone shows the chat alone, the composer | ||
| 113 | 117 | fits(s, 360); |
| 114 | 118 | longFits(s, 360); |
| 115 | 119 | expect(s.chat).not.toBeNull(); |
| 120 | expect(s.side).toBeNull(); | |
| 116 | 121 | expect(s.pane).toBeNull(); |
| 117 | expect(s.tabs).toBe(true); | |
| 122 | expect(s.tabs).toBe(false); | |
| 118 | 123 | expect(s.chat!.width).toBeGreaterThan(300); |
| 119 | 124 | expect(s.back).not.toBeNull(); |
| 120 | 125 | }, 30_000); |
| 121 | 126 | |
| 122 | test.skipIf(chromium === undefined)("on a phone the preview keeps Chats one tap away, and ?chats=1 with ?pane=preview shows the list", async () => { | |
| 123 | const preview = await look(360, 740, token, "?pane=preview"); | |
| 124 | expect(preview.scrollWidth).toBeLessThanOrEqual(360); | |
| 125 | expect(preview.chat).toBeNull(); | |
| 126 | expect(preview.back).not.toBeNull(); | |
| 127 | test.skipIf(chromium === undefined)("on a phone ?chats=1 is the list alone, whatever ?pane= asks", async () => { | |
| 127 | 128 | const both = await look(360, 740, token, "?chats=1&pane=preview"); |
| 128 | 129 | expect(both.scrollWidth).toBeLessThanOrEqual(360); |
| 129 | 130 | expect(both.side).not.toBeNull(); |
| @@ -134,46 +135,44 @@ test.skipIf(chromium === undefined)("on a phone the preview keeps Chats one tap | ||
| 134 | 135 | test.skipIf(chromium === undefined)("at 768 px the chat has the width alone, no list squeezing it", async () => { |
| 135 | 136 | const s = await look(768, 1024); |
| 136 | 137 | fits(s, 768); |
| 137 | // The list is a screen of its own here, so nothing sits beside the chat; its width is the 72ch | |
| 138 | // measure (set by the font, so only a floor is asserted). | |
| 139 | 138 | expect(s.side).toBeNull(); |
| 140 | 139 | expect(s.chat!.width).toBeGreaterThan(480); |
| 141 | 140 | }, 30_000); |
| 142 | 141 | |
| 143 | test.skipIf(chromium === undefined)("a tablet puts the chats beside the chat, the preview a tab away", async () => { | |
| 142 | test.skipIf(chromium === undefined)("a tablet puts the chats beside the chat; with nothing running there is no third column and no tab for one", async () => { | |
| 144 | 143 | const s = await look(900, 1100); |
| 145 | 144 | fits(s, 900); |
| 146 | 145 | expect(s.side).not.toBeNull(); |
| 147 | expect(s.chat).not.toBeNull(); | |
| 148 | 146 | expect(s.side!.right).toBeLessThanOrEqual(s.chat!.left); |
| 149 | 147 | expect(s.pane).toBeNull(); |
| 150 | expect(s.tabs).toBe(true); | |
| 148 | expect(s.tabs).toBe(false); | |
| 151 | 149 | expect(s.back).toBeNull(); |
| 152 | 150 | }, 30_000); |
| 153 | 151 | |
| 154 | test.skipIf(chromium === undefined)("a laptop shows chats, chat and preview side by side without tabs", async () => { | |
| 152 | test.skipIf(chromium === undefined)("a laptop centres a reading column beside the chats, with no empty pane", async () => { | |
| 155 | 153 | const s = await look(1280, 800); |
| 156 | 154 | longFits(s, 1280); |
| 157 | 155 | fits(s, 1280); |
| 158 | 156 | expect(s.side!.right).toBeLessThanOrEqual(s.chat!.left); |
| 159 | expect(s.pane).not.toBeNull(); | |
| 160 | expect(s.chat!.right).toBeLessThanOrEqual(s.pane!.left); | |
| 161 | expect(s.tabs).toBe(false); | |
| 157 | expect(s.pane).toBeNull(); | |
| 158 | expect(s.chat!.width).toBeLessThanOrEqual(736 + 1); | |
| 159 | expect(Math.abs((s.chat!.left + s.chat!.right) / 2 - (s.side!.right + s.vw) / 2)).toBeLessThan(24); | |
| 162 | 160 | }, 30_000); |
| 163 | 161 | |
| 164 | test.skipIf(chromium === undefined)("a wide monitor keeps the reading column readable and the preview the room", async () => { | |
| 162 | test.skipIf(chromium === undefined)("a wide monitor keeps the reading column readable", async () => { | |
| 165 | 163 | const s = await look(2560, 1300); |
| 166 | 164 | fits(s, 2560); |
| 167 | expect(s.chat!.width).toBeLessThanOrEqual(896 + 1); | |
| 168 | expect(s.pane!.width).toBeGreaterThan(s.chat!.width); | |
| 169 | expect(s.tabs).toBe(false); | |
| 165 | expect(s.chat!.width).toBeLessThanOrEqual(736 + 1); | |
| 166 | expect(s.pane).toBeNull(); | |
| 170 | 167 | }, 30_000); |
| 171 | 168 | |
| 172 | for (const [w, h, name] of [[900, 1100, "a tablet"], [1280, 800, "a laptop"]] as const) { | |
| 173 | test.skipIf(chromium === undefined)(`a first visit, the conversation empty, keeps the composer on screen at ${name}`, async () => { | |
| 169 | for (const [w, h, name] of [[390, 844, "a phone"], [900, 1100, "a tablet"], [1280, 800, "a laptop"]] as const) { | |
| 170 | test.skipIf(chromium === undefined)(`a first visit, the conversation empty, puts the greeting and the composer where the eye is at ${name}`, async () => { | |
| 174 | 171 | const s = await look(w, h, emptyToken); |
| 175 | 172 | fits(s, w); |
| 176 | expect(s.build).not.toBeNull(); | |
| 177 | expect(s.build!.bottom).toBeLessThanOrEqual(s.compose!.top); | |
| 173 | expect(s.hello).not.toBeNull(); | |
| 174 | expect(s.hello!.bottom).toBeLessThanOrEqual(s.compose!.top); | |
| 175 | // Not pinned to the foot of an empty page: the composer sits under the greeting, mid-screen. | |
| 176 | expect(s.compose!.bottom).toBeLessThan(s.vh * 0.85); | |
| 178 | 177 | }, 30_000); |
| 179 | 178 | } |
test/talk-page.test.ts +125 −79
| @@ -87,39 +87,44 @@ afterAll(async () => { | ||
| 87 | 87 | }); |
| 88 | 88 | |
| 89 | 89 | describe("the page", () => { |
| 90 | test("the conversations are rows and no turn sits in a box (#9690)", async () => { | |
| 90 | test("the conversations are rows; a person's words sit on a quiet surface, the forge's reply is plain text (#9690)", async () => { | |
| 91 | 91 | say(alice, "person", "hi"); |
| 92 | 92 | const html = await (await get("/talk", alice)).text(); |
| 93 | 93 | expect(html).toContain('<h1 class="sr-only">Talk</h1>'); |
| 94 | 94 | expect(html).not.toContain('class="page-head"'); |
| 95 | 95 | const nav = html.slice(html.indexOf('<nav class="talk-chats"'), html.indexOf("</nav>")); |
| 96 | expect(nav).toContain('<ul class="list">'); | |
| 96 | expect(nav).toContain('<ul class="list talk-list">'); | |
| 97 | 97 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); |
| 98 | 98 | const rule = (sel: string) => talkCss.match(new RegExp(`(?:^|\\n)${sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\{([^}]*)\\}`))?.[1]; |
| 99 | expect(rule(".talk-person")).toBeDefined(); | |
| 100 | expect(rule(".talk-person")).not.toMatch(/border|background/); | |
| 101 | expect(rule(".talk-confirm")).toBeDefined(); | |
| 102 | expect(rule(".talk-confirm")).not.toMatch(/border|background/); | |
| 99 | expect(rule(".talk-person > .talk-body")).toMatch(/background: var\(--muted\)/); | |
| 100 | expect(talkCss).not.toMatch(/\.talk-agent[^{,]*\{[^}]*(border|background)/); | |
| 103 | 101 | expect(rule(".talk-queued")).toBeDefined(); |
| 104 | 102 | expect(rule(".talk-queued")).not.toContain("border-style"); |
| 105 | 103 | expect(talkCss).not.toMatch(/\.talk-tool details\s*\{[^}]*border/); |
| 106 | 104 | expect(talkCss).not.toMatch(/\.talk-chats ul\s*\{/); |
| 107 | 105 | }); |
| 108 | 106 | |
| 109 | test("the shell: list beside the thread from 900 px, Chats link back below, thread capped (#15813)", async () => { | |
| 107 | test("one column the page scrolls: the list beside it from 900 px, its own view below; no side pane with nothing to show (#15813)", async () => { | |
| 110 | 108 | say(alice, "person", "hi"); |
| 111 | 109 | const html = await (await get("/talk", alice)).text(); |
| 112 | 110 | expect(html).toContain('data-shell data-pane="chat">'); |
| 113 | 111 | expect(html).not.toContain(`data-pane="chat" data-view`); |
| 114 | expect(html).toMatch(/<nav class="seg talk-tabs"[^>]*><a class="talk-back" href="\/talk\/[^"?]+\?chats=1">Chats<\/a>/); | |
| 115 | expect(html.indexOf('class="talk-chats"')).toBeLessThan(html.indexOf('class="talk-here')); | |
| 112 | expect(html).not.toMatch(/data-shell[^>]*data-split/); | |
| 113 | expect(html).not.toContain('class="talk-work"'); | |
| 114 | expect(html).not.toContain(`class="seg talk-tabs"`); | |
| 115 | expect(html).toMatch(/<a class="btn btn-icon talk-back" data-variant="ghost" href="\/talk\/[^"?]+\?chats=1" aria-label="Conversations"/); | |
| 116 | expect(html.indexOf('class="talk-chats"')).toBeLessThan(html.indexOf('class="talk-head')); | |
| 116 | 117 | const listed = await (await get("/talk?chats=1", alice)).text(); |
| 117 | 118 | expect(listed).toContain(`data-pane="chat" data-view="list"`); |
| 118 | expect(listed).toMatch(/<details class="talk-list" open>/); | |
| 119 | 119 | expect(html).not.toContain("Back to conversations"); |
| 120 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); | |
| 121 | // The window is the thread's one scroller: nothing in the column scrolls on its own. | |
| 122 | expect(talkCss).not.toMatch(/\.talk(-log)? \{[^}]*overflow-y/); | |
| 123 | expect(talkCss).toMatch(/\.talk \{[^}]*max-width: 46rem/); | |
| 124 | expect(talkCss).toMatch(/\.talk-side, \[data-view="list"\] \.talk-side \{[^}]*position: sticky/); | |
| 120 | 125 | }); |
| 121 | 126 | |
| 122 | test("a phone opening /talk/<id> gets the thread view, a Chats link back, a pinned composer and 44 px targets (#15814)", async () => { | |
| 127 | test("a phone opening /talk/<id> gets the thread, a way to the list, a pinned composer and 44 px targets (#15814)", async () => { | |
| 123 | 128 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); |
| 124 | 129 | say(alice, "person", "hi"); |
| 125 | 130 | const first = await (await get("/talk", alice)).text(); |
| @@ -127,34 +132,25 @@ describe("the page", () => { | ||
| 127 | 132 | const html = await (await get(`/talk/${id}`, alice)).text(); |
| 128 | 133 | expect(html).toContain('data-shell data-pane="chat">'); |
| 129 | 134 | expect(html).toContain('class="talk-compose"'); |
| 130 | expect(html).toMatch(/<a class="talk-back" href="\/talk\/[^"?]+\?chats=1">Chats<\/a>/); | |
| 131 | const narrow = /@media \(max-width: 56\.24rem\) \{([^@]*)\n\}/.exec(talkCss)![1]!; | |
| 132 | expect(narrow).toContain(".talk-shell:not([data-view=\"list\"]) .talk-side { display: none; }"); | |
| 135 | expect(html).toMatch(/talk-back" data-variant="ghost" href="\/talk\/[^"?]+\?chats=1"/); | |
| 136 | expect(talkCss).toContain('.talk-side, .talk-work, [data-view="list"] :is(.talk, .talk-work) { display: none; }'); | |
| 133 | 137 | expect(talkCss).toMatch(/\.talk-compose \{[^}]*position: sticky; bottom: var\(--kb, 0px\)/); |
| 134 | expect(talkCss).toMatch(/\.talk-back[^{]*\{[^}]*min-height: 2\.75rem/); | |
| 135 | expect(talkCss).toMatch(/\.talk-compose \.btn[^{]*\{[^}]*min-height: 2\.75rem/); | |
| 136 | expect(talkCss).toMatch(/\.talk-compose textarea \{[^}]*min-height: 44px/); | |
| 138 | expect(talkCss).toMatch(/\.talk-head \.btn-icon[^{]*\{[^}]*min-height: 2\.75rem/); | |
| 139 | expect(talkCss).toMatch(/\.talk-tools \.btn-icon \{[^}]*min-height: 2\.75rem/); | |
| 140 | expect(talkCss).toMatch(/\.talk-input \{[^}]*min-height: 48px/); | |
| 137 | 141 | }); |
| 138 | 142 | |
| 139 | test("below 900 px the preview keeps a way to the list, and ?chats=1 with ?pane=preview shows the list (#15813)", async () => { | |
| 143 | test("?pane=preview with nothing running draws no pane; the list view wins over it (#15813)", async () => { | |
| 140 | 144 | say(alice, "person", "hi"); |
| 141 | const tabsOf = (h: string) => h.match(/<nav class="seg talk-tabs"[^>]*>[\s\S]*?<\/nav>/)?.[0] ?? ""; | |
| 142 | // From the preview, the Chats link is in the tabs, which stay shown while .talk is hidden. | |
| 143 | 145 | const preview = await (await get("/talk?pane=preview", alice)).text(); |
| 144 | 146 | expect(preview).toContain('data-shell data-pane="preview">'); |
| 145 | expect(tabsOf(preview)).toMatch(/<a class="talk-back" href="\/talk\/[^"?]+\?chats=1">Chats<\/a>/); | |
| 146 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); | |
| 147 | const phone = talkCss.slice(talkCss.indexOf("@media (max-width: 56.24rem)"), talkCss.indexOf("@media (min-width: 56.25rem)")); | |
| 148 | expect(phone).not.toMatch(/\[data-pane[^\]]*\][^{]*\.talk-tabs/); | |
| 149 | // Both asked: the list view wins. The side is shown (only hidden off the list view) and the | |
| 150 | // rules that hide .talk and .talk-pane leave .talk-side alone, so the shell is never blank. | |
| 147 | expect(preview).not.toContain(`class="seg talk-tabs"`); | |
| 151 | 148 | const both = await (await get("/talk?chats=1&pane=preview", alice)).text(); |
| 152 | 149 | expect(both).toContain('data-shell data-pane="preview" data-view="list">'); |
| 153 | 150 | expect(both).toMatch(/<div class="talk-side"><nav class="talk-chats"/); |
| 154 | expect(phone).toContain('.talk-shell:not([data-view="list"]) .talk-side { display: none; }'); | |
| 155 | for (const rule of phone.split("\n").filter((l) => l.includes("display: none"))) { | |
| 156 | if (rule.includes(".talk-side")) expect(rule).toContain(':not([data-view="list"])'); | |
| 157 | } | |
| 151 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); | |
| 152 | // With a pane, below 80rem it is a tab: the head and the tabs stay, the thread steps aside. | |
| 153 | expect(talkCss).toContain('[data-split]:not([data-pane="chat"]) .talk > :not(.talk-head, .talk-tabs) { display: none; }'); | |
| 158 | 154 | }); |
| 159 | 155 | |
| 160 | 156 | test("signed out goes to /signin and comes back", async () => { |
| @@ -183,7 +179,7 @@ describe("the page", () => { | ||
| 183 | 179 | say(alice, "person", "alice-only secret"); |
| 184 | 180 | const bobs = await (await get("/talk", bob)).text(); |
| 185 | 181 | expect(bobs).not.toContain("alice-only secret"); |
| 186 | expect(bobs).toContain("Ask the forge anything"); | |
| 182 | expect(bobs).toContain("What should we work on?"); | |
| 187 | 183 | }); |
| 188 | 184 | |
| 189 | 185 | test("a message with no agent running says so and is not kept", async () => { |
| @@ -209,8 +205,8 @@ describe("the page", () => { | ||
| 209 | 205 | say(carol.value, "tool", "list_issues {\"repo\":\"x\"}"); |
| 210 | 206 | const page = await (await get("/talk", carol.value)).text(); |
| 211 | 207 | expect(page).not.toContain("data-starter"); |
| 212 | expect(page).toContain("You · <time"); | |
| 213 | expect(page).toContain("Forge · <time"); | |
| 208 | expect(page).toContain('<span class="sr-only">You · </span><time'); | |
| 209 | expect(page).toContain('<span class="sr-only">Forge · </span><time'); | |
| 214 | 210 | expect(page).not.toContain("data-copy"); |
| 215 | 211 | expect(page).toContain('role="log"'); |
| 216 | 212 | expect(page).toMatch(/<details><summary>List issues /); |
| @@ -254,7 +250,8 @@ describe("the page", () => { | ||
| 254 | 250 | expect(out).toContain(url); |
| 255 | 251 | expect(talkCss).toContain(".talk-turn pre { max-width: 100%; overflow-x: auto; }"); |
| 256 | 252 | expect(talkCss).toContain(".talk-body a { overflow-wrap: anywhere; }"); |
| 257 | expect(talkJs).toContain('pre.insertBefore(copyButton("Copy this code")'); | |
| 253 | expect(talkJs).toContain('copyButton("Copy this code")'); | |
| 254 | expect(talkJs).toContain("wrap.append(head, pre)"); | |
| 258 | 255 | expect(talkJs).toContain("pre.tabIndex = 0"); |
| 259 | 256 | }); |
| 260 | 257 | |
| @@ -279,6 +276,17 @@ describe("the page", () => { | ||
| 279 | 276 | expect(part).toContain("</code></pre>"); |
| 280 | 277 | }); |
| 281 | 278 | |
| 279 | test("the server folds each run of steps into one closed disclosure, one tab stop for the run", async () => { | |
| 280 | const { foldSteps, turnHtml } = await import("../src/web/pages/talk.ts"); | |
| 281 | const turn = (id: string, role: string, text: string) => turnHtml({ id, role, text, createdAt: "2026-01-01T00:00:00Z" } as any, new Set()); | |
| 282 | const out = foldSteps([turn("1", "person", "why"), turn("2", "tool", 'read_file {"repo":"a/b","path":"x.ts"}'), turn("3", "tool", 'runs {"repo":"a/b"}'), turn("4", "agent", "Because."), turn("5", "tool", 'read_file {"repo":"a/b","path":"y.ts"}')]).map((h) => h.text).join(""); | |
| 283 | expect(out.match(/data-steps/g)?.length).toBe(2); | |
| 284 | expect(out).toContain('<summary class="small muted">2 steps</summary>'); | |
| 285 | expect(out).toContain('<summary class="small muted">Read y.ts</summary>'); | |
| 286 | expect(out.indexOf('id="t-2"')).toBeGreaterThan(out.indexOf("data-steps")); | |
| 287 | expect(out).not.toMatch(/<details open/); | |
| 288 | }); | |
| 289 | ||
| 282 | 290 | test("an agent turn carries no prose padding or measure into the column", async () => { |
| 283 | 291 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); |
| 284 | 292 | expect(talkCss).toContain(".talk-body.prose { padding: 0;"); |
| @@ -295,8 +303,10 @@ describe("the page", () => { | ||
| 295 | 303 | expect(page).toContain('aria-keyshortcuts="/"'); |
| 296 | 304 | expect(talkCss).toContain("bottom: var(--kb, 0px)"); |
| 297 | 305 | expect(talkCss).not.toContain("overflow-x: clip"); |
| 298 | expect(talkCss).toMatch(/\.talk-shell, \.talk-pane \{[^}]*grid-template-columns: minmax\(0, 1fr\)/); | |
| 299 | expect(talkCss).toMatch(/\.talk-compose \.bar \{[^}]*flex-wrap: wrap/); | |
| 306 | expect(talkCss).toMatch(/\.talk-page \{[^}]*grid-template-columns: minmax\(0, 1fr\)/); | |
| 307 | // The composer's row never wraps: what appears while an answer runs takes the send button's place. | |
| 308 | expect(talkCss).toMatch(/\.talk-tools \{[^}]*min-width: 0/); | |
| 309 | expect(talkCss).not.toMatch(/\.talk-tools \{[^}]*flex-wrap: wrap/); | |
| 300 | 310 | expect(talkJs).toContain("visualViewport"); |
| 301 | 311 | expect(talkJs).toContain('e.key === "/"'); |
| 302 | 312 | }); |
| @@ -316,9 +326,9 @@ describe("the page", () => { | ||
| 316 | 326 | expect(talkCss).toMatch(/\.talk \{[^}]*min-width: 0/); |
| 317 | 327 | expect(talkCss).toMatch(/\.talk-turn \{[^}]*overflow-wrap: anywhere/); |
| 318 | 328 | expect(talkCss).toMatch(/\.talk-turn pre \{[^}]*max-width: 100%; overflow-x: auto/); |
| 319 | expect(talkCss).toMatch(/\.talk-body\.prose table \{[^}]*display: block; max-width: 100%; overflow-x: auto/); | |
| 320 | expect(talkCss).toMatch(/\.talk-compose textarea \{[^}]*width: 100%[^}]*box-sizing: border-box/); | |
| 321 | expect(talkCss).toMatch(/\.talk-compose textarea \{[^}]*font-size: 16px/); | |
| 329 | expect(talkCss).toMatch(/\.talk-body\.prose table \{[^}]*display: block;[^}]*max-width: 100%; overflow-x: auto/); | |
| 330 | expect(talkCss).toMatch(/\.talk-input \{[^}]*width: 100%[^}]*box-sizing: border-box/); | |
| 331 | expect(talkCss).toMatch(/\.talk-input \{[^}]*font-size: 16px/); | |
| 322 | 332 | }); |
| 323 | 333 | |
| 324 | 334 | test("every action is a native control or link, reachable by Tab, and none takes itself out of the order", async () => { |
| @@ -371,29 +381,36 @@ describe("the page", () => { | ||
| 371 | 381 | |
| 372 | 382 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 373 | 383 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 374 | expect(Buffer.byteLength(talkCss)).toBeLessThan(6_700); | |
| 375 | expect(Buffer.byteLength(talkJs)).toBeLessThan(23_600); | |
| 384 | expect(Buffer.byteLength(talkCss)).toBeLessThan(12_000); | |
| 385 | expect(Buffer.byteLength(talkJs)).toBeLessThan(26_700); | |
| 376 | 386 | say(alice, "agent", "```ts\nlet x = 1;\n```"); |
| 377 | 387 | const page = await get("/talk", alice); |
| 378 | 388 | const size = (await page.arrayBuffer()).byteLength; |
| 379 | expect(size).toBeLessThan(40_000); | |
| 389 | expect(size).toBeLessThan(42_000); | |
| 380 | 390 | }); |
| 381 | 391 | |
| 382 | 392 | describe("the script, driven against a DOM", () => { |
| 383 | 393 | test("while a reply streams the composer stays open: Send queues, Steer and Stop appear, Escape stops, and it is Send again when the turn ends", async () => { |
| 384 | 394 | const t = await boot(); |
| 385 | const send = t.doc.querySelector('.bar button[type="submit"]'); | |
| 395 | const send = t.doc.querySelector('.talk-tools button[type="submit"]'); | |
| 386 | 396 | const stop = t.doc.querySelector("[data-stop]"); |
| 387 | expect(send.textContent).toBe("Send"); | |
| 397 | const steer = t.doc.querySelector("[data-steer]"); | |
| 398 | expect([send.hidden, send.getAttribute("aria-label")]).toEqual([false, "Send"]); | |
| 388 | 399 | expect(stop.hidden).toBe(true); |
| 389 | 400 | t.sources.at(-1)!.on["running"]!({ data: "{}" }); |
| 390 | expect(send.textContent).toBe("Queue"); | |
| 391 | expect(stop.hidden).toBe(false); | |
| 401 | // Running with an empty box: the one round button is Stop. | |
| 402 | expect([send.hidden, stop.hidden, steer.hidden]).toEqual([true, false, true]); | |
| 403 | // Words typed meanwhile queue, and Steer appears to send them now. | |
| 404 | t.box.value = "also this"; | |
| 405 | t.box.dispatchEvent(new t.window.Event("input")); | |
| 406 | expect([send.hidden, send.getAttribute("aria-label"), stop.hidden, steer.hidden]).toEqual([false, "Queue: it sends after this answer", true, false]); | |
| 407 | t.box.value = ""; | |
| 408 | t.box.dispatchEvent(new t.window.Event("input")); | |
| 392 | 409 | stop.dispatchEvent(new t.window.MouseEvent("click", { bubbles: true, cancelable: true })); |
| 393 | 410 | t.doc.dispatchEvent(new t.window.KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true })); |
| 394 | 411 | expect(t.urls).toEqual(["/api/v1/conversation/stop", "/api/v1/conversation/stop"]); |
| 395 | 412 | t.sources.at(-1)!.on["done"]!({ data: "{}" }); |
| 396 | expect(send.textContent).toBe("Send"); | |
| 413 | expect([send.hidden, send.getAttribute("aria-label")]).toEqual([false, "Send"]); | |
| 397 | 414 | expect(stop.hidden).toBe(true); |
| 398 | 415 | t.doc.dispatchEvent(new t.window.KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true })); |
| 399 | 416 | expect(t.urls).toHaveLength(2); |
| @@ -447,7 +464,7 @@ describe("the page", () => { | ||
| 447 | 464 | const doc = window.document as any; |
| 448 | 465 | doc.body.innerHTML = `<div class="talk" data-talk data-user="${user}" data-c="${conv}" data-paged="0" data-running="1"><div> |
| 449 | 466 | <ol class="talk-log" role="log" data-last=""><li class="talk-turn talk-agent" id="t-1"><div class="talk-body"><pre><code>let a = 1;</code></pre></div><p class="talk-meta">Forge · now</p></li></ol><div id="end"></div></div> |
| 450 | <form class="talk-compose"><p class="talk-status" role="status"></p><ul data-chips></ul><textarea name="text" required></textarea><p data-error hidden></p><button type="button" class="btn talk-jump" data-jump hidden><span data-word></span></button><div class="bar"><span data-compose-hint></span><label data-attach hidden><input type="file" data-pick /></label><button class="btn" type="button" data-stop hidden>Stop</button><button class="btn" type="button" data-steer hidden>Steer</button><button class="btn" type="submit">Send</button></div></form></div>`; | |
| 467 | <form class="talk-compose"><div class="talk-box"><div data-chips></div><textarea name="text" required></textarea><div class="talk-tools"><button type="button" data-attach hidden aria-label="Attach files"></button><input type="file" multiple hidden data-files /><span data-compose-hint></span><button class="btn" type="button" data-steer hidden>Steer</button><button class="btn" type="button" data-stop hidden aria-label="Stop the answer">Stop</button><button class="btn talk-send" type="submit" aria-label="Send">Send</button></div></div><p data-error hidden></p><p class="talk-status" role="status"></p><button type="button" class="btn talk-jump" data-jump hidden><span data-word></span></button></form></div>`; | |
| 451 | 468 | const how = { value: "started" }; |
| 452 | 469 | const cancel = { status: 200 }; |
| 453 | 470 | const page = { html: "" }; |
| @@ -753,18 +770,62 @@ describe("the page", () => { | ||
| 753 | 770 | |
| 754 | 771 | test("copy buttons are drawn by the script, code first in tab order, and copy the text", async () => { |
| 755 | 772 | const t = await boot(); |
| 756 | const pre = t.doc.querySelector("pre"); | |
| 757 | expect(pre.firstElementChild.getAttribute("data-copy")).toBe(""); | |
| 773 | // The code sits under a head naming its language, with Copy there and never over the code. | |
| 774 | const head = t.doc.querySelector(".talk-code > .talk-code-head"); | |
| 775 | expect(head.nextElementSibling.tagName).toBe("PRE"); | |
| 776 | const copy = head.querySelector("[data-copy]"); | |
| 777 | expect(copy.getAttribute("aria-label")).toBe("Copy this code"); | |
| 778 | expect(t.doc.querySelector("pre [data-copy]")).toBeNull(); | |
| 758 | 779 | expect(t.doc.querySelector(".talk-meta [data-copy]")).not.toBeNull(); |
| 759 | pre.firstElementChild.dispatchEvent(new t.window.MouseEvent("click", { bubbles: true })); | |
| 780 | copy.dispatchEvent(new t.window.MouseEvent("click", { bubbles: true })); | |
| 760 | 781 | await tick(); |
| 761 | 782 | expect(t.copied).toEqual(["let a = 1;"]); |
| 762 | 783 | }); |
| 763 | 784 | |
| 785 | test("a step that streams in joins the run before it under one closed disclosure: one step by its words, more by their count", async () => { | |
| 786 | const t = await boot(); | |
| 787 | const step = (id: string, label: string) => t.emit(id, `<li class="talk-turn talk-tool talk-step" id="t-${id}" data-step><details><summary>${label} <span class="talk-when">now</span></summary><p>x</p></details></li>`); | |
| 788 | step("2", "Read src/a.ts"); | |
| 789 | const fold = t.doc.querySelector("[data-steps]"); | |
| 790 | expect(fold.querySelector("summary").textContent).toBe("Read src/a.ts"); | |
| 791 | step("3", "Ran the checks"); | |
| 792 | expect(t.doc.querySelectorAll("[data-steps]").length).toBe(1); | |
| 793 | expect(fold.querySelector("summary").textContent).toBe("2 steps"); | |
| 794 | expect([...fold.querySelectorAll("ol > li")].map((li: any) => li.id)).toEqual(["t-2", "t-3"]); | |
| 795 | // Words between steps end the run: the next step opens a run of its own. | |
| 796 | t.emit("4", '<li class="talk-turn talk-agent" id="t-4"><div class="talk-body"><p>So.</p></div></li>'); | |
| 797 | step("5", "Opened pull #2"); | |
| 798 | expect(t.doc.querySelectorAll("[data-steps]").length).toBe(2); | |
| 799 | // A repeat is still drawn once. | |
| 800 | step("3", "Ran the checks"); | |
| 801 | expect(t.doc.querySelectorAll("#t-3").length).toBe(1); | |
| 802 | }); | |
| 803 | ||
| 804 | test("a growing live block keeps what it already drew, so a selection in it survives the next frame", async () => { | |
| 805 | const t = await boot(); | |
| 806 | const frame = (html: string) => t.sources.at(-1)!.on["live"]!({ data: JSON.stringify({ html, tool: "", thinking: false }) }); | |
| 807 | frame('<div class="talk-body prose"><p>First.</p><p>Sec</p></div>'); | |
| 808 | const first = t.doc.querySelector("#live p"); | |
| 809 | frame('<div class="talk-body prose"><p>First.</p><p>Second, longer.</p></div>'); | |
| 810 | expect(t.doc.querySelector("#live p")).toBe(first); | |
| 811 | expect(t.doc.getElementById("live").textContent).toBe("First.Second, longer."); | |
| 812 | }); | |
| 813 | ||
| 814 | test("in build mode the composer posts its own form to make the app: the script does not take it", async () => { | |
| 815 | const t = await boot(); | |
| 816 | const form = t.doc.querySelector("form.talk-compose"); | |
| 817 | form.setAttribute("data-build", ""); | |
| 818 | t.box.value = "a recipe box"; | |
| 819 | const e = new t.window.Event("submit", { bubbles: true, cancelable: true }); | |
| 820 | form.dispatchEvent(e); | |
| 821 | expect(e.defaultPrevented).toBe(false); | |
| 822 | expect(t.sent).toEqual([]); | |
| 823 | }); | |
| 824 | ||
| 764 | 825 | test("a code block in a streamed turn gets its Copy button too", async () => { |
| 765 | 826 | const t = await boot(); |
| 766 | 827 | t.emit("2", '<li class="talk-turn" id="t-2"><div class="talk-body"><pre><code>x</code></pre></div><p class="talk-meta">Forge</p></li>'); |
| 767 | expect(t.doc.querySelectorAll("#t-2 pre [data-copy]").length).toBe(1); | |
| 828 | expect(t.doc.querySelectorAll("#t-2 .talk-code-head [data-copy]").length).toBe(1); | |
| 768 | 829 | expect(t.doc.querySelectorAll("#t-2 .talk-meta [data-copy]").length).toBe(1); |
| 769 | 830 | }); |
| 770 | 831 | |
| @@ -882,15 +943,15 @@ describe("the page", () => { | ||
| 882 | 943 | test("a turn that arrives again is not drawn twice or replaced, so what is above it keeps its place", async () => { |
| 883 | 944 | const t = await boot(); |
| 884 | 945 | const first = t.doc.getElementById("t-1"); |
| 885 | const copy = first.querySelector("pre [data-copy]"); | |
| 946 | const copy = first.querySelector(".talk-code-head [data-copy]"); | |
| 886 | 947 | t.emit("2", '<li class="talk-turn" id="t-2"><div class="talk-body"><pre><code>x</code></pre></div><p class="talk-meta">Forge</p></li>'); |
| 887 | 948 | const second = t.doc.getElementById("t-2"); |
| 888 | 949 | t.emit("2", '<li class="talk-turn" id="t-2"><div class="talk-body"><p>changed</p></div></li>'); |
| 889 | 950 | expect(t.doc.querySelectorAll("#t-2").length).toBe(1); |
| 890 | 951 | expect(t.doc.getElementById("t-2")).toBe(second); |
| 891 | 952 | expect(t.doc.getElementById("t-1")).toBe(first); |
| 892 | expect(first.querySelector("pre [data-copy]")).toBe(copy); | |
| 893 | expect(t.doc.querySelectorAll("#t-2 pre [data-copy]").length).toBe(1); | |
| 953 | expect(first.querySelector(".talk-code-head [data-copy]")).toBe(copy); | |
| 954 | expect(t.doc.querySelectorAll("#t-2 .talk-code-head [data-copy]").length).toBe(1); | |
| 894 | 955 | }); |
| 895 | 956 | |
| 896 | 957 | test("a turn arriving while scrolled up does not scroll the page, and is announced once", async () => { |
| @@ -1565,35 +1626,20 @@ describe("narrow viewport controls (#14943)", () => { | ||
| 1565 | 1626 | const html = await (await get(path, alice)).text(); |
| 1566 | 1627 | return html.slice(html.indexOf('<nav class="talk-chats"'), html.indexOf("</nav>")); |
| 1567 | 1628 | }; |
| 1568 | const listTag = (nav: string) => nav.match(/<details class="talk-list"[^>]*>/)![0]; | |
| 1569 | 1629 | |
| 1570 | test("New sits outside the fold; the fold ships closed with no script", async () => { | |
| 1630 | test("New comes first, then the search, then the rows; a phone gets the list as its own view, not a fold", async () => { | |
| 1571 | 1631 | const nav = await sideNav("/talk"); |
| 1572 | const list = nav.indexOf('class="talk-list"'); | |
| 1632 | const list = nav.indexOf('class="list talk-list"'); | |
| 1573 | 1633 | expect(list).toBeGreaterThan(0); |
| 1574 | expect(nav.indexOf('action="/talk/new"')).toBeLessThan(list); | |
| 1575 | expect(listTag(nav)).not.toContain("open"); | |
| 1576 | }); | |
| 1577 | ||
| 1578 | test("the wide layout hides the summary only where ::details-content can show the list", async () => { | |
| 1634 | expect(nav.indexOf('action="/talk/new"')).toBeLessThan(nav.indexOf('role="search"')); | |
| 1635 | expect(nav.indexOf('role="search"')).toBeLessThan(list); | |
| 1636 | expect(nav).not.toContain("<details"); | |
| 1579 | 1637 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); |
| 1580 | const guard = talkCss.indexOf("@supports selector(::details-content) {"); | |
| 1581 | expect(guard).toBeGreaterThan(-1); | |
| 1582 | let depth = 0; | |
| 1583 | let end = guard; | |
| 1584 | for (let i = talkCss.indexOf("{", guard); i < talkCss.length; i++) { | |
| 1585 | if (talkCss[i] === "{") depth++; | |
| 1586 | else if (talkCss[i] === "}" && --depth === 0) { end = i; break; } | |
| 1587 | } | |
| 1588 | const inside = talkCss.slice(guard, end); | |
| 1589 | expect(inside).toContain(".talk-list > summary { display: none; }"); | |
| 1590 | expect(inside).toContain(".talk-list::details-content { content-visibility: visible; }"); | |
| 1591 | const outside = talkCss.slice(0, guard) + talkCss.slice(end); | |
| 1592 | expect(outside).not.toContain(".talk-list > summary { display: none; }"); | |
| 1638 | expect(talkCss).toContain('[data-view="list"] .talk-side { display: block;'); | |
| 1593 | 1639 | }); |
| 1594 | 1640 | |
| 1595 | test("the fold opens from the server only for a search or the archive", async () => { | |
| 1596 | expect(listTag(await sideNav("/talk?find=hello"))).toContain(" open"); | |
| 1597 | expect(listTag(await sideNav("/talk?archived=1"))).toContain(" open"); | |
| 1641 | test("a search or the archive shows its rows at once", async () => { | |
| 1642 | expect(await sideNav("/talk?find=hello")).toContain('aria-label="Search results"'); | |
| 1643 | expect(await sideNav("/talk?archived=1")).toContain("Back to conversations"); | |
| 1598 | 1644 | }); |
| 1599 | 1645 | }); |
test/talk-pin.test.ts +5 −4
| @@ -70,14 +70,15 @@ describe("pin", () => { | ||
| 70 | 70 | expect(plain).not.toContain("data-pinned-heading"); |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | test("each row carries its own Pin or Unpin form, and back=list returns to the list", async () => { | |
| 73 | test("the open conversation's menu carries Pin or Unpin, the rows stay plain, and back=list returns to the list", async () => { | |
| 74 | 74 | const a = mine(alice); |
| 75 | 75 | const b = mine(alice); |
| 76 | const page = async () => (await fetch(`${servers.url}/talk/${b.id}`, { headers: { cookie: cookie(alice) } })).text(); | |
| 77 | expect(await page()).toContain(`action="/talk/${a.id}/pin"`); | |
| 76 | const page = async (c: { id: string }) => (await fetch(`${servers.url}/talk/${c.id}`, { headers: { cookie: cookie(alice) } })).text(); | |
| 77 | expect(await page(a)).toContain(`action="/talk/${a.id}/pin"`); | |
| 78 | expect(await page(b)).not.toContain(`action="/talk/${a.id}/pin"`); | |
| 78 | 79 | const res = await post(`/talk/${a.id}/pin`, alice, { pinned: "1", back: "list" }); |
| 79 | 80 | expect(res.headers.get("location")).toBe("/talk"); |
| 80 | expect(await page()).toMatch(new RegExp(`action="/talk/${a.id}/pin">\\s*<input[^>]*value="0"`)); | |
| 81 | expect(await page(a)).toMatch(new RegExp(`action="/talk/${a.id}/pin"><input[^>]*value="0"`)); | |
| 81 | 82 | const other = await post(`/talk/${a.id}/pin`, alice, { pinned: "0", back: "https://evil.example" }); |
| 82 | 83 | expect(other.headers.get("location")).toBe(`/talk/${a.id}`); |
| 83 | 84 | }); |
test/talk-steps.test.ts +12 −13
| @@ -56,7 +56,7 @@ test("the repository is the last good one a call named", () => { | ||
| 56 | 56 | expect(repoOf([{ role: "person", text: "hi" }])).toBeUndefined(); |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | test("/talk is two panes, steps are escaped and closed", async () => { | |
| 59 | test("/talk draws steps escaped and closed, and no side pane while nothing runs", async () => { | |
| 60 | 60 | const c = openConversation(app.db, userId); |
| 61 | 61 | appendTurn(app.db, userId, c.id, { role: "person", text: "build it" }); |
| 62 | 62 | appendTurn(app.db, userId, c.id, { role: "tool", text: 'mcp__forge__read_file {"repo":"dana/none","path":"<b>x</b>.ts"}' }); |
| @@ -66,11 +66,11 @@ test("/talk is two panes, steps are escaped and closed", async () => { | ||
| 66 | 66 | const page = await res.text(); |
| 67 | 67 | expect(page).toContain("data-shell"); |
| 68 | 68 | expect(page).not.toContain("role=\"tab\""); |
| 69 | expect(page).toContain('href="?pane=preview"'); | |
| 69 | expect(page).not.toContain('class="talk-work"'); | |
| 70 | 70 | expect(page).toContain("Read <b>"); |
| 71 | 71 | expect(page).not.toContain("mcp__forge__read_file"); |
| 72 | 72 | expect(page).not.toMatch(/<details open/); |
| 73 | expect(page).toContain("Not a repository you can see"); | |
| 73 | expect(page).not.toContain("Not a repository you can see"); | |
| 74 | 74 | }); |
| 75 | 75 | |
| 76 | 76 | test("the phone's Chat and Preview are links the server draws: ?pane= picks which shows", async () => { |
| @@ -101,6 +101,7 @@ describe("a repository the person can read", () => { | ||
| 101 | 101 | expect(pane.html.text).toContain('<iframe class="talk-frame" data-frame src="https://lab--7--site.example.test/"'); |
| 102 | 102 | expect(pane.html.text).toContain("Pull #7"); |
| 103 | 103 | expect(pane.frame).toBe("https://lab--7--site.example.test"); |
| 104 | expect(pane.live).toBe(true); | |
| 104 | 105 | expect(frameSources({ frameSrc: pane.frame })).toContain("https://lab--7--site.example.test"); |
| 105 | 106 | expect(frameSources({ frameSrc: pane.frame })).not.toContain("site.example.test/"); |
| 106 | 107 | }); |
| @@ -113,6 +114,7 @@ describe("a repository the person can read", () => { | ||
| 113 | 114 | |
| 114 | 115 | test("nothing running draws no frame and no frame-src", () => { |
| 115 | 116 | const pane = talkPane(ctx, user, "erin/site", works, "preview", apps(undefined, {})); |
| 117 | expect(pane.live).toBe(false); | |
| 116 | 118 | expect(pane.html.text).not.toContain("<iframe"); |
| 117 | 119 | expect(pane.frame).toBeUndefined(); |
| 118 | 120 | }); |
| @@ -174,7 +176,7 @@ describe("through the real page", () => { | ||
| 174 | 176 | for (const q of ["", "?pane=preview", "?pane=code", "?pane=diff"]) { |
| 175 | 177 | const res = await fetch(`${servers.url}/talk${q}`, { headers: { cookie: strangerCookie } }); |
| 176 | 178 | const page = await res.text(); |
| 177 | expect(page).toContain("Not a repository you can see."); | |
| 179 | expect(page).not.toContain('class="talk-work"'); | |
| 178 | 180 | expect(page).not.toContain("<iframe"); |
| 179 | 181 | expect(page).not.toContain("fay/secret</strong>"); |
| 180 | 182 | expect(page).not.toContain('href="?pane=code"'); |
| @@ -182,15 +184,12 @@ describe("through the real page", () => { | ||
| 182 | 184 | } |
| 183 | 185 | }); |
| 184 | 186 | |
| 185 | test("Code and Diff on a readable repository are drawn by the server, the head said once", async () => { | |
| 187 | test("a readable repository with nothing running leaves the pane out whatever ?pane= asks; the pane's tabs are talkPane's (above)", async () => { | |
| 186 | 188 | const get = async (q: string) => (await fetch(`${servers.url}/talk${q}`, { headers: { cookie: ownCookie } })).text(); |
| 187 | const code = await get("?pane=code"); | |
| 188 | expect(code).toContain('<a href="?pane=code" aria-current="page">Code</a>'); | |
| 189 | expect(code).toMatch(/No files touched yet\.|src\/a\.ts/); | |
| 190 | expect(code.split("fay/open</strong>").length).toBe(2); | |
| 191 | const diff = await get("?pane=diff"); | |
| 192 | expect(diff).toContain('<a href="?pane=diff" aria-current="page">Diff</a>'); | |
| 193 | expect(diff).toContain("No open pull yet."); | |
| 194 | expect(await get("?pane=preview")).toContain("Nothing running yet."); | |
| 189 | for (const q of ["?pane=code", "?pane=diff", "?pane=preview"]) { | |
| 190 | const page = await get(q); | |
| 191 | expect(page).not.toContain('class="talk-work"'); | |
| 192 | expect(page).not.toContain("Nothing running yet."); | |
| 193 | } | |
| 195 | 194 | }); |
| 196 | 195 | }); |
test/talk-voice.test.ts +12 −11
| @@ -52,13 +52,13 @@ describe("talk dictation", () => { | ||
| 52 | 52 | t.mic.click(); |
| 53 | 53 | expect(Stub.last.processLocally).toBe(true); |
| 54 | 54 | expect(Stub.last.started).toBe(true); |
| 55 | expect(t.mic.textContent).toBe("Stop dictating"); | |
| 55 | expect(t.mic.getAttribute("aria-label")).toBe("Stop dictating"); | |
| 56 | 56 | expect(t.mic.getAttribute("aria-pressed")).toBe("true"); |
| 57 | 57 | t.box.value = "fix"; |
| 58 | 58 | Stub.last.onresult(result("the footer")); |
| 59 | 59 | expect(t.box.value).toBe("fix the footer"); |
| 60 | 60 | t.mic.click(); |
| 61 | expect(t.mic.textContent).toBe("Dictate"); | |
| 61 | expect(t.mic.getAttribute("aria-label")).toBe("Dictate"); | |
| 62 | 62 | expect(t.mic.getAttribute("aria-pressed")).toBe("false"); |
| 63 | 63 | expect(t.submitted()).toBe(0); |
| 64 | 64 | }); |
| @@ -73,18 +73,19 @@ describe("talk dictation", () => { | ||
| 73 | 73 | const t = setup(class extends Stub { override failStart = true; override start() { throw new Error("busy"); } }); |
| 74 | 74 | t.mic.click(); |
| 75 | 75 | expect(t.said).toEqual(["Dictation could not start."]); |
| 76 | expect(t.mic.textContent).toBe("Dictate"); | |
| 76 | expect(t.mic.getAttribute("aria-label")).toBe("Dictate"); | |
| 77 | 77 | }); |
| 78 | test("the send selector skips Dictate, so Queue never renames it", () => { | |
| 78 | test("the send selector finds the round Send button, never Dictate, so Queue never renames it", () => { | |
| 79 | 79 | const window = new Window(); |
| 80 | window.document.body.innerHTML = `<div class="bar"><button data-dictate class="btn">Dictate</button><button class="btn">Send</button><button data-stop class="btn">Stop</button></div>`; | |
| 81 | expect(window.document.querySelector(sendSelector)?.textContent).toBe("Send"); | |
| 80 | window.document.body.innerHTML = `<div class="talk-tools"><button data-dictate class="btn btn-icon talk-dictate" aria-label="Dictate"></button><button data-stop class="btn btn-icon talk-stop" aria-label="Stop the answer"></button><button type="submit" class="btn btn-icon talk-send" aria-label="Send"></button></div>`; | |
| 81 | expect(window.document.querySelector(sendSelector)?.getAttribute("aria-label")).toBe("Send"); | |
| 82 | 82 | }); |
| 83 | 83 | test("the page script embeds it, adds no request, and the hidden button stays hidden in CSS", () => { |
| 84 | 84 | expect(talkJs).toContain(dictateJs); |
| 85 | 85 | expect(dictateJs).not.toMatch(/fetch|XMLHttpRequest|sendBeacon|WebSocket|EventSource|MediaRecorder/); |
| 86 | expect(talkCss).toContain(".talk-dictate[hidden] { display: none; }"); | |
| 87 | expect(talkCss).toContain(".talk-compose .btn, .talk-suggest .btn, .talk-failed .btn, .talk-act { min-height: 2.75rem; }"); | |
| 86 | expect(talkCss).toMatch(/\.talk-dictate\[hidden\][^{]*\{ display: none; \}/); | |
| 87 | expect(talkCss).toMatch(/\[data-attach\]\[hidden\], \.talk-jump\[hidden\] \{ display: none; \}/); | |
| 88 | expect(talkCss).toContain(".talk-tools .btn-icon { min-width: 2.75rem; min-height: 2.75rem;"); | |
| 88 | 89 | expect(dictateJs.length).toBeLessThan(1400); |
| 89 | 90 | }); |
| 90 | 91 | }); |
| @@ -97,11 +98,11 @@ describe("design lint: the Dictate button is named and 44px (#14198)", () => { | ||
| 97 | 98 | expect(scanDictate(process.cwd())).toEqual([]); |
| 98 | 99 | }); |
| 99 | 100 | test("losing the name, the btn class, the 44px rule or adding a short height each fails", () => { |
| 100 | expect(dictateFindings(page.replace(">Dictate</button>", "></button>"), css).join()).toContain("no text"); | |
| 101 | expect(dictateFindings(page.replace('class="btn talk-dictate"', 'class="talk-dictate"'), css).join()).toContain("btn"); | |
| 101 | expect(dictateFindings(page.replace('aria-label="Dictate" title="Dictate" ', ""), css).join()).toContain("no text"); | |
| 102 | expect(dictateFindings(page.replace('class="btn btn-icon talk-dictate"', 'class="talk-dictate"'), css).join()).toContain("btn"); | |
| 102 | 103 | expect(dictateFindings(page, css.replace(".btn { min-height: 44px; }", ".btn { min-height: 40px; }")).join()).toContain("44px"); |
| 103 | 104 | expect(dictateFindings(page, css + ".talk-dictate { height: 30px; }").join()).toContain("30px"); |
| 104 | expect(dictateFindings(page.replace(">Dictate</button>", ' aria-label="Dictate"></button>'), css)).toEqual([]); | |
| 105 | expect(dictateFindings(page.replace('aria-label="Dictate" title="Dictate" ', 'aria-label="Dictate" '), css)).toEqual([]); | |
| 105 | 106 | }); |
| 106 | 107 | test("the 44px rule must sit in a coarse-pointer block", () => { |
| 107 | 108 | const fine = css.replace("@media (pointer: coarse) {\n .btn { min-height: 44px; }", "@media (pointer: fine) {\n .btn { min-height: 44px; }"); |
new above
offline