Skip to content

feat(chat): open Chat at /dashboard/chat and add its chats API (W1-01) - #1829

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-01-routes
Oct 30, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-01-routes

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. With the flag off, the old Agent page and its menu link stay as they are today. The product owner saw the Chat shell in a local preview (menu, Home, row menus) and approved it.

W1-01: /dashboard/chat and its chats API.

  • Redirect: /dashboard/agent and everything under it 301-redirect to /dashboard/chat when the flag is on for the workspace, keeping the query string. The redirect lives in the proxy, no-store, so turning the flag off stops it at once.
  • Menus: the sidebar and the mobile menu link Chat to /dashboard/chat when the flag is on.
  • API (none of them throw; failures are values, per fix(prompts): show suggestions' load failures plainly and retry once, instead of React #441 #1777):
    • GET / POST /api/chat/conversations: list, create an empty chat;
    • GET / DELETE …/{id}: read with messages, soft delete (stops a running agent first);
    • POST …/{id}/restore: Undo within 1 minute;
    • POST …/{id}/read: mark read.
  • Deleted chats: the engine and access-request reads filter deleted_at is null, as feat(chat): add the tables Chat's first wave needs (00407–00413) #1812 noted.
  • Missing chat: shows "This chat isn't available." + New chat. Opening a chat marks it read.
  • Help: a chat area and help/chat/chat.md.

No migration, no new dependency.

Related issue

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

Type of change

  • feat — New feature

How to test

With CHAT_AGENTIC=true, /dashboard/agent lands on /dashboard/chat. Tests: src/app/api/chat/conversations, proxy, layout.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: prettier/eslint, typecheck and the related tests pass (stack tip: 61 files / 731 tests; build left to CI)
  • Tests added
  • Help article updated (help/chat/chat.md, approved: false)

🤖 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]>
Behind CHAT_AGENTIC; with it off, the Agent page and its menu link stay as
they are today.

- /dashboard/agent and every path under it answer a 301 to the matching
  /dashboard/chat path, query kept, where the new Chat is on for the
  person's workspace (CHAT-01 item 2). Sent with no-store, so turning the
  flag off again takes effect at once. The sidebar and mobile menu link
  Chat straight to /dashboard/chat.
- The chats API (CHAT-01 §1-3, 7-8, 26): GET /api/chat/conversations lists
  the person's chats and the team's shared ones (or their archived ones),
  newest first, with each row's brand name, dot and live step in words, and
  the Chats / Archived counts; POST starts an empty chat; GET .../{id} opens
  one with its messages and steps; DELETE stops a running agent, then hides
  the chat for everyone; .../restore is the Undo (one minute); .../read
  marks its result read for the author. Refusals come back as values
  (ansvisor#1777), never thrown.
- A chat that isn't there, was deleted or isn't shared says "This chat isn't
  available." with New chat (item 26); opening one marks it read.
- The engine and access requests read chats with the service role, so they
  now leave deleted chats out too (ansvisor#1812 note).
- Help: a "chat" area and its first article (approved: false).

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
cihan-gyk and others added 2 commits October 30, 2026 09:21
…workspace

Creating an empty chat, deleting, restoring and marking your own chat read
start no cost; a chat's first message is a run, which the engine refuses
with 402. The read-only coverage test lists them with that reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A person reads only their own profile, so the author's name came back
empty on every teammate's shared chat. Read it on the server, within the
workspace; only the initials leave.
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 c449c79 (one commit on this branch). On production, profiles lets a person read only their own row, and itemsOf read the authors' names with the person's own client, so a teammate's initials never showed on a shared chat. The unit test passed only because it used one fake client for both reads. The commit reads the names with the service role, scoped with .in('id', ownerIds).eq('organization_id', actor.organizationId), and only the initials leave. The new test models own-row-only reads and fails without it. (#1832 carries the same fix; the stack merges it once.)

Checked, fine

  • Every route answers 404 before any read when CHAT_AGENTIC is off or the workspace isn't in CHAT_AGENTIC_ORGS. The proxy redirect does nothing with the flag off.
  • Every read and write is scoped to the person and their workspace. Delete and restore are for the author, or an Admin on a shared chat.
  • Path ids are UUIDs, limit is 1–200, the brand must belong to the workspace, and originPage is bounded.
  • The four write routes are listed in the read-only coverage test with reasons. No brand data is written for the demo brand, and no embeds are added.
  • 00407's policies, run in a rolled-back transaction: the author sees their private, shared and archived shared chats, and a teammate only the shared ones. Another workspace sees nothing, anonymous callers are refused, and members can't write the chats table directly.

Later: the list reads at most 4× runs per chat, so an old chat with an unread result can show as idle. On the demo brand with the flag on, /dashboard/agent now goes to Chat instead of the preview.

Note: this branch's web CI format:check fails on the long OPEN_ROUTES lines in subscription-guard-coverage.test.ts. #1831 wraps them.

Tests: conversations, the chats API route, proxy, legacy route, dashboard navigation, subscription-guard coverage, plan-row, engine and chat access requests: 99 pass. tsc is clean. No migration of its own; it needs #1812's.

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

# Conflicts:
#	web/src/components/chat/chat-shell.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 bbcfff9 into ansvisor:main Oct 30, 2026
3 of 5 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