Skip to content

feat(chat): open pages from Chat with a route registry and a rule-based router - #1807

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

gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-28-routes

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat Wave 1, W1-28: opening pages from Chat (CHAT-19 §2, §6), behind CHAT_AGENTIC.

  • Route registry (lib/chat/routes.ts):
    • Source: built from the live menu (config/dashboard.ts dashboardNav) and SETTINGS_SECTIONS, with the sidebar's names (nav.*, settings.*), plus Action Center Signals / KPIs / History, Competitors and Brands.
    • Per route: its plan feature, synonyms, and the filters its URL keeps:
      • insights range / model;
      • citations preset / platform;
      • prompts range;
      • competitors preset.
    • Self-hosted: Settings sections are filtered with hasSettingsSection.
  • routeRequest: a rule-based router that runs before the model, with no AI usage.
    • What it reads: a verb (open / show / take me to / go to …), a page (name, "section name" or synonym; the longest match wins), platform names, and ranges (today, last 7/30/90 days, this week/month, all time).
    • When it returns null: a question, an unsupported filter, leftover words, or two equally long matches to different pages ("open insights", "open plan"). The model handles those.
  • open_page:
    • Registry: registry/navigation.ts; area navigation, C0, read.
    • openPageFor: reads only the organization row. It returns { locked, needs } without the plan feature, and drops a platform the plan doesn't read.
    • Platforms: the field is a z.enum of the 8 answer engines.
  • components/chat/navigation-card.tsx: the page ("Prompts › Tracked Prompts"), filter chips, "Filters set for you…", Go to page. "Navigation only · no AI usage" shows only for rule-routed turns (ruleRouted). The card isn't wired into the shell yet; that comes with Wave 1's shell work.

Review round (42391e4)

  • Server code read a value from a client module.
    • routes.ts read ALL_DATE_PRESETS from 'use client' date-range-filter.tsx. On the server that export is a client reference, so /api/chat/runs would 500.
    • The presets now live in the plain module config/date-presets.ts, which date-range-filter re-exports; traffic-range.ts moved to it too.
    • plan-row.test.ts (fix(settings): keep the server Supabase client out of Roles & access, so the web build passes #1796) gets the reverse check: no shared module in src/lib or src/config reads a value from a client component. It caught this exact import before the fix.
  • Translated names: extra pages' names come from en.json via createTranslator.
  • Feature gate: Competitors requires competitor_tracking.
  • Ties: equally long matches to different routes return null.
  • Imports: ORG_PLAN_COLUMNS comes from plan-row.
  • New tests: ties, open-redirect inputs (//evil.com, https://evil.com, javascript:, ../login), the router with the plan lock, the platform enum, self-hosted Settings.

Related issue

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

Type of change

  • feat — New feature

How to test

  1. cd web && yarn vitest run src/lib/chat src/components/chat src/lib/guards src/config:
    • routes 13
    • navigation 6
    • navigation-card 2
    • traffic-range 9
    • registry / tools / MCP parity
  2. yarn build passes (73/73 static pages). Its TypeScript step needed NODE_OPTIONS=--max-old-space-size=4096 on an 8 GB machine.

Merging with #1800 (W1-16): additive conflicts in registry/tools.ts, tools.test.ts and en.json chatTools. Keep both sides.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: lint, typecheck, build and the related tests pass (676/677: plan-row.test.ts's import walk took 8.7 s under load against the 5 s default; it passes alone in 2 s)
  • Tests added

🤖 Generated with Claude Code

cihan-gyk and others added 3 commits October 29, 2026 20:48
…l, with a navigation card

Chat Wave 1 W1-28 (CHAT-19 §2, §6; CHAT-20 §9 row 1):

- Route registry (lib/chat/routes.ts): every page Chat can open, made
  from the live sidebar (config/dashboard.ts, its items and their
  submenus) and Settings' sections, named as the sidebar and Settings
  name them, with the plan feature each needs, other words people use for
  it, and the filters its address keeps (range and platform where the
  page reads them). Chat's own page isn't one.
- Rules-based router (routeRequest): a plain "open / show / take me to /
  go to {page} [for {platform}] [{range}]" gives the page and its filters
  with no model and no AI usage: "Open Visibility for Perplexity, last 30
  days" is /dashboard/insights?range=30d&model=perplexity-web. It answers
  only when it understood every word: a question, a filter the page
  doesn't keep ("drafts under Quality 60") or anything left over goes to
  the model.
- open_page (registry row, area navigation, C0): for what the model
  routes; only pages the plan opens (a locked one names the plan that
  has it) and the plan's platforms as a filter; it reads the plan and
  nothing else.
- Navigation card (components/chat/navigation-card.tsx): the page, its
  filters by name, "Filters set for you. This chat stays open in the side
  panel.", "Navigation only · no AI usage" and Go to page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…en_page

Review fixes for the route registry and open_page.

- routes.ts read ALL_DATE_PRESETS from the date range control, a 'use
  client' module. On the server, a client module's exports are client
  references, not values, so every Chat turn (engine → registry → open_page
  → routes) would fail. The presets now live in config/date-presets.ts, and
  the control re-exports them. traffic-range.ts reads them there too.
- plan-row.test.ts gains the other direction of its import walk: a shared
  module (src/lib, src/config) reads no value from a 'use client' file.
- open_page's platform is one of the tracked platform ids (z.enum), and the
  pages' platform filter takes only those. A wrong slug no longer opens an
  empty page on plans without allowedScrapers.
- The registry lists only the Settings sections this install shows: a
  self-hosted one has no Billing or AI Providers.
- Competitors needs competitor_tracking.
- The Action Center tabs' and Brands' names come from en.json.
- Two pages matched by phrases of the same length ("open plan": Content ›
  Plan or Billing, "open insights") are the model's to ask about.
- The navigation card says "no AI usage" only when the rules-based router
  answered (ruleRouted).
- ORG_PLAN_COLUMNS comes from guards/plan-row.
- Tests: ties, //evil.com and javascript: addresses, the router with a
  plan lock, the platform enum, and self-hosted Settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Insights' model filter holds the answers' model slugs, not platform ids,
so model=chatgpt-web opened an empty page. Insights keeps only its range;
a platform request for it goes to the model.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
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 19b2d17 (one commit on this branch). FILTERS.insights set the platform id as ?model=, but Insights' model filter takes the answers' model slugs (prompt_results.model_used, e.g. gpt-5-…), so "open visibility for ChatGPT" opened an empty Insights page. Insights now keeps only its range: the router hands "Open Visibility for Perplexity…" to the model, and open_page leaves the platform out of filters. The platform tests now use Citations, whose platform param does take the scraper id, and the two new cases fail without the commit. A real Insights platform filter (platform id → that family's slugs) could come later.

Checked, fine

  • Only in-app links: routeById matches exact registry ids, hrefWithFilters sets only allow-listed values, and the card uses the i18n Link.
  • openPageFor reads only the caller's organization plan columns. Plan-locked routes come back locked with needs, platforms outside the plan are dropped and reported, and self-hosted drops Billing and AI Providers.
  • Reached only through the engine behind CHAT_AGENTIC, no MCP tool. It's a read with no brand data, so the read-only gate and demo guard aren't needed.
  • plan-row.test.ts (with its new reverse check) and next build pass. Chat, MCP, guards, config and filter tests: 707 pass. tsc, eslint and prettier are clean.

Non-blocking

  • menu-access is listed for every role, while Settings shows it only to admins and the managers they allow. Shopping's requiresBrandPref isn't considered either.
  • When routeRequest is wired in, route it through openPageFor, since the router alone does no plan check.
  • The tool open_page shares its name with the open_page step kind in #1833–#1835 (external pages). Worth keeping them apart in labels.

Merge: clean on main, no migrations. Additive conflicts with #1800 and #1819–#1822 in registry/tools.ts, tools.test.ts and en.json chatTools: keep both sides.

Competitors is back on the sidebar (ansvisor#1809), so the registry would list it twice: from the sidebar and from the pages Chat adds.

@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.

Still good with 97658d7, one more commit for #1809. #1809 puts Competitors back on the sidebar, and this PR lists it as an extra page the sidebar doesn't have, so with both merged the registry lists it twice and routes.test.ts › points every route at a page of the app, once fails. The commit skips an extra page whose address the sidebar already has, so it works in either merge order. routes-sidebar.test.ts fails without it. On main with #1809 and this branch: 92 files, 1,008 tests pass, plus plan-row.test.ts and tsc.

@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 PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.

@gkhngyk
gkhngyk merged commit b51b0bd into ansvisor:main Oct 30, 2026
4 of 5 checks passed
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