Skip to content

feat(chat): add the composer, with modes, Stop and steer (W1-10) - #1826

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-10-composer
Oct 30, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-10-composer

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat Wave 1, behind CHAT_AGENTIC. Stacked on #1812 (W1-DB). The diff against main includes the PRs below it until they merge. The product owner saw it in the /dashboard/chat/preview page and approved it.

W1-10: the composer (components/chat/composer/), a copy of the approved mockup's composer, in theme tokens.

  • Variants: home (2 rows), dock and panel; up to 240px tall.
  • Modes: Ask me first · Auto, ask before changes · Full auto, with the mockup's toasts. Full auto is locked with Needs Growth unless the plan allows it (fullAutoOpen from plan-facts).
  • Send / Stop:
    • Enter sends and Shift+Enter adds a line; Enter doesn't send during IME composition or on touch screens.
    • Esc and ■ stop a run.
  • Steer (decision: stop and send). While a run goes on, the placeholder reads "Steer while I work: “only blog pages”…". Typing shows "Enter stops this run and sends your message", and Enter calls onSteer. The page stops the run (POST /api/chat/runs/{id}/stop), then sends the new message.
  • Read-only (analyst, agency partner): no modes. Read-only · Analyst links to What Chat can do, and the hint reads "@ data · read-only".
  • Model label: "Auto · Haiku reads, Sonnet writes".
  • Data actions: every control carries the mockup's data-action name.

The components aren't wired into /dashboard/chat yet; the shell PRs (W1-01…05) wire them in. No migration, no new dependency.

Related issue

Part of Chat (CHAT-02, Wave 1).

Type of change

  • feat — New feature

How to test

yarn vitest run src/components/chat/composer covers the keys (IME, touch, Esc), the modes and the Full auto lock, steer, and the read-only view. Then open /dashboard/chat/preview › Composer.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: eslint/prettier, typecheck and the related tests pass (run one at a time on an 8 GB machine; build left to CI)
  • Tests added
  • Help article: written when the composer is wired into the Chat page (the shell PR adds help/chat)

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 30, 2026 01:12
…iles, Help and add-on packs

Chat's Wave 1 tables in one PR (one DB PR per wave), behind CHAT_AGENTIC:
nothing reads or writes them while the flag is off. Tables, types and the
demo's coverage only; the code that uses them comes in the Wave 1 PRs.

- 00407: chat_conversations gets shared_at (Share with team: every member
  of the workspace reads it), last_read_at (unread results), deleted_at
  (Delete with Undo; deleted chats are hidden from every member) and a
  title search column; chat_messages gets context_json (what a person's
  message was scoped to) and a text search column. 'simple' text search,
  so a chat in any language is found. The author policy now leaves deleted
  chats out, and a shared policy reads shared ones.
- 00408: chat_user_prefs gets the rest of Settings › General and the
  one-time notices: rail_open, panel_size, default_mode, answer_language,
  notify_via, show_thought, panel_on_pages, focus_prompted_at,
  usage_notice_period, legacy_imported_at.
- 00409: chat_uploads and the private bucket chat-uploads: 10 MB a file,
  the composer's 11 types, 5 a message (a trigger backs the server's
  check), kept 90 days.
- 00410: chat_tool_cache (a chat's read results by tool and scope, server
  only) and each step's and model call's measure: latency, cache hit,
  truncation, result tokens on chat_run_steps (never granted to members),
  prompt cache read/write tokens and latency on the ledger.
- 00411: chat_files (filed deliverables and saved answers, the
  workspace's, kept a year, searchable by title, summary and tags),
  chat_file_task_links, chat_storage_usage kept by a trigger, and the
  private bucket chat-files.
- 00412: help_answer_cache and help_gaps (server only, no workspace or
  person ids).
- 00413: add_on_products seeded with the owner's packs (AI credits $10,
  $50, $250, $1,000 at half their price in budget, 12 months; storage
  +25/+100/+250 GB at $5/$15/$29 a month; $50 and +25 GB Most picked),
  add_on_purchases (Admins read), ai_credit_grants and storage_grants
  (server only), and prompt_improve_usage.grant_id.

Members only ever read; every write is the server's. Tool names, tool
results and dollars stay server only. web/src/types/supabase.ts carries
the new tables and columns; schema.test.ts checks the policies, the
server-only tables, the limits and the seeded packs from the SQL;
steps.test.ts keeps the step measure out of the member columns. The demo
coverage skips chat_files and chat_tool_cache (a person's own Chat work).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and a read-only view

Chat Wave 1, W1-10 (CHAT-02, agentic update). A copy of the mockup's
composer (compHTML), as components to be wired into the Chat pages by the
shell (W1-01).

- ChatComposer: the box, a toolbar with the run mode and Send, and the line
  under it. Variants: home (2 rows), dock and panel (1 row). The box grows
  to 240px, then scrolls.
- Enter sends, Shift+Enter adds a line. Enter during an input method's
  composition or on a touch screen is the box's own (composerKeyAction).
  Send is off for an empty box.
- While a run answers, Send is Stop, and Esc stops too. The box steers:
  "Steer while I work…". Enter stops the run, its done steps kept, and
  sends the text as the next message (onSteer; decided 2026-10-30). The
  line under reads "Enter stops this run and sends your message". A page
  without steering keeps the text until the run ends.
- ModeSwitch: Ask me first · Auto, ask before changes · Full auto, each pick
  with the mockup's toast. Full auto below Growth is locked: "Needs Growth",
  and it can't be picked.
- Analysts and Agency partners read only: no mode switch, a "Read-only ·
  Analyst" link to Your access, and "@ data · read-only" under the box.
- The model button reads "Auto · Haiku reads, Sonnet writes". Slots for
  the + / @ tools (W1-12) and the usage meter (W1-23).
- The Chat pieces preview gets a Composer section: home, a dock with a
  pretend run, and an Analyst's panel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 30, 2026
gkhngyk
gkhngyk previously approved these changes Oct 30, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with follow-ups.

Reviewed this PR's own commit only (c8921ac, on top of #1812 af43140): the composer (components/chat/composer/), its strings, and the Composer section of /dashboard/chat/preview. No migration, no route, no new dependency, and nothing outside the preview page renders it yet.

What I checked

  • Flag off: the only place the composer shows is /dashboard/chat/preview, which still answers 404 unless CHAT_AGENTIC is on for the workspace (checked on the server per request). With the flag off nothing changes.
  • Modes are a UI choice; the server decides. The composer only passes the picked mode to the page. On main, POST /api/chat/runs takes mode from a fixed list, and the precedence check turns Full auto into a card when the plan doesn't allow it (full_auto_locked) or when the Admin has turned Full auto off for non-Admins (full_auto_off). The Analyst / Agency partner view hides the switch, and their writes are refused on the server whatever mode is sent. So a hand-made request can't get more than the UI offers.
  • Stop and steer only call the page's handlers here. The routes they will use (/api/chat/runs/{id}/stop, /api/chat/runs) already check that the run is the person's own in their own workspace, and they only move a run from a status it is really in. A repeated Stop answers ok for a run that has already ended, so a double click does no harm.
  • Double submit: sending blocks a second Enter or click while a send or a steer is in flight. A refused send (false or an error) puts the text back. Tested.
  • Keys: Enter sends, Shift+Enter adds a line, and Enter does nothing during IME composition (isComposing / 229) or on a coarse pointer. Esc stops only while a run answers. Enter on an empty box adds no line. composerKeyAction is pure and covered.
  • Plan lock: the locked Full auto has aria-disabled, a "Needs Growth" tag and a title, and a click on it does nothing. Tested.
  • Copy: the strings are in en.json, and chatAccess.roleNames covers every TeamRole, so the read-only label never falls back to a key.
  • Merges clean on current main (merge-base is main's tip, a8121a6). It needs #1812 merged first.

Tests

  • src/components/chat/composer (11), chat/preview/page.test.tsx (8), src/lib/guards/plan-row.test.ts: pass.
  • Web tsc --noEmit: clean. eslint and prettier on the touched files and en.json: clean.
  • I didn't run next build. Everything added is a client component that imports only client-safe modules, and plan-row passes.

Follow-ups (none block)

  1. Message length. The server takes up to 20,000 characters and answers a longer message with a generic "failed". Setting maxLength on the textarea, or a short "too long" line, from a shared constant would stop a long paste from failing without saying why.
  2. Mode switch keyboard. role="radiogroup"/role="radio" leads screen readers to expect arrow keys between the options with one tab stop. Right now each mode is its own tab stop and the arrows do nothing. Either add arrow keys with a roving tabIndex, or drop the radio roles and use aria-pressed buttons.
  3. Esc in the side panel. Esc calls preventDefault() but doesn't stop the event from spreading. When the panel variant goes into a sheet or dialog, check that Esc during a run stops the run and doesn't also close the panel.
  4. Announcing the run state. The line under the box changes ("Answering · Esc to stop", "Enter stops this run…") without being read aloud. A polite aria-live on that line would tell screen-reader users.
  5. Touch with a keyboard. (pointer: coarse) is true on a tablet with a hardware keyboard, so Enter never sends there. This is fine if it's what the mockup intends. Otherwise, check (any-pointer: fine) too.
  6. Minor: with running set and no onStop, the Stop button shows but does nothing. Hiding it, or making onStop required when running is set, would avoid a dead button.

For the stacked PRs (#1827, #1828, #1835)

  • fullAutoOpen should match what the server will do. In #1835, chatComposerSetup opens it from the plan alone. A Manager in a workspace where the Admin turned Full auto off for members would see it open, and the server would then ask anyway. Passing plan.fullAuto && (role === 'admin' || settings.fullAutoForMembers) keeps the two in step.
  • A read-only workspace (lapsed plan): POST /api/chat/runs answers 402. #1835 opens the upgrade dialog on that, which works. Passing disabled (or a read-only line) from the plan facts would say so before the person types.
  • Steer in #1835 awaits stop() and then sends, whatever Stop answered. A run driven by another server instance takes a couple of seconds to see the Stop, so the new message can land in the queue behind it. That's acceptable, but worth a test in that PR.

gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 30, 2026
…ew fixes) into take-1840

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/chat/_chat-page-access.ts
#	web/src/components/chat/chat-thread-view.tsx

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging in order with the other approved Chat PRs. This head merges current main; where they overlapped, both sides are kept. Its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build. Chat stays behind CHAT_AGENTIC.

@gkhngyk
gkhngyk merged commit 318801c into ansvisor:main Oct 30, 2026
7 of 9 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants