Skip to content

feat(chat): add the reads Chat was missing, one registry file per area - #1800

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-16-reads
Oct 30, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w1-16-reads

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat Wave 1, W1-16: the reads Chat was missing (CHAT-20 tool spec), one registry file per area, all behind CHAT_AGENTIC.

Tools (all read, minRole: analyst, mcpTool: null; labels in en.json chatTools):

  • registry/prompts.ts: get_fanouts, list_ai_answers, get_prompt_insights
  • registry/visibility.ts: get_overview_summary
  • registry/action-center.ts: get_action_center_kpis, get_onboarding_progress
  • registry/ai-traffic.ts: get_gsc_summary, get_ga_summary
  • registry/account.ts (no brand): list_members, list_connections, get_chat_policy, get_plan_facts
  • tools.ts takes them through one areas.ts import.

Data (lib/mcp/*-reads.ts): each tool calls one function.

  • Access: brand reads check brandInOrg, then run the page's own loader as the service role (withDbClient(supabaseAdmin)). This is the product-visibility / prompt-locations pattern.
  • Clients: for that, kpis.ts, traffic.ts, fanout.ts and getting-started.ts use dbClient(). Outside a scope it is the session client, so the pages behave the same.
  • Platforms by plan: filtered at row level (allowedScrapers). getQueryFanout takes an optional platforms.
  • data_as_of on every read:
    • GSC: Google's last reported day, source_lag "2–3 days".
    • GA: ga_ai_traffic_stats' last day, lag "1 day".
  • Privacy:
    • list_members gives email to Admins only.
    • list_connections reads only the person's own API keys (user_id), and no hashes, last4, Composio ids or CMS credentials.
    • get_plan_facts whitelists counts: no AI budget dollars.
    • get_chat_policy routes to Settings › Roles & access.

Review round (f630a2f):

  • list_connections own keys only.
  • GSC reads use gscLatestDays like the page (≤ 7 days), and data_as_of is the last reported day.
  • connected needs integration_connections.status = 'connected' and a property.
  • list_ai_answers reads 50, filters by plan, then cuts.
  • get_fanouts counts only plan engines.
  • get_prompt_insights adds truncated.

Related issue

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

Type of change

  • feat — New feature

How to test

  1. cd web && yarn vitest run src/lib/chat src/lib/mcp: registry and MCP parity, and chat-reads.test.ts. That test covers org check, own keys only, plan filtering, the GSC window and connection status.
  2. With CHAT_AGENTIC on, ask Chat "how did my fan-out change this week" or "who is in my workspace". The answers name their data_as_of.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: lint, typecheck and tests pass (src/lib/chat, src/lib/mcp, the four action files: 55 files, 671 tests, after merging main)
  • Tests added
  • No 'use client' file added (the production build's client graph is unchanged)

🤖 Generated with Claude Code

cihan-gyk and others added 3 commits October 29, 2026 20:38
Chat Wave 1 W1-16 (CHAT-20 §9): twelve READ rows, each with its label,
its brand (brandOf) and `data_as_of` in what it returns (§15a), listed in
tools.ts with the rest:

- prompts: get_fanouts (Query Fan-outs, the plan's engines only),
  list_ai_answers (a prompt's newest answers, shortened, the plan's
  platforms only), get_prompt_insights (estimated AI volume, by intent,
  the most demanded prompts).
- visibility: get_overview_summary (the visibility summary with when
  tracking last ran and runs next).
- action_center: get_action_center_kpis (the KPIs page's snapshots),
  get_onboarding_progress (Getting started's steps).
- ai_traffic: get_gsc_summary and get_ga_summary (clicks and sessions
  against the period before, or "not connected", with Google's lag).
- account: list_members (e-mails for Admins only), list_connections
  (Google per brand, CMS sites, AI provider keys set or not, API key
  names and last use: never a key or credential), get_chat_policy,
  get_plan_facts (counts and the plan card, never an AI budget in
  dollars).

The brand reads run the pages' own loaders with the service role once
brandInOrg passed (as product visibility and prompt locations do): the
KPIs, traffic, fan-out and Getting started loaders now take their client
from dbClient(), which on the pages is still the member's own. The RPCs
they call don't read auth.uid() (ai_traffic_page_citations lets the
service role through). None has an MCP tool yet (mcpTool null).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ounts to what the plan and Google show

Review of W1-16:

- list_connections read every member's API keys with the service role,
  so anyone saw an Admin's key names and last use. It now reads the
  person's own, as Settings › API Keys and its RLS do (your_api_keys).
- get_gsc_summary reads Google's latest reported days for a range of a
  week or less, as the page does (gscLatestDays), and its data_as_of is
  the last day Search Console reported; get_ga_summary's is Analytics'.
- A Google source is connected when the workspace's connection is on
  (integration_connections) and the brand has its property picked, as
  AI Referral Traffic reads it.
- list_ai_answers reads up to 50, keeps the plan's platforms, then the
  number asked for, so a page isn't short.
- get_fanouts reads the plan's platforms from the rows up (getQueryFanout
  takes an optional platforms filter; the page passes none), so its
  totals, times searched and data_as_of are theirs.
- get_prompt_insights says when the volume read stopped at 500 prompts
  (truncated).
- get_chat_policy's page is Settings › Roles & access.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Approving as is (8647b34). It merges clean on main (a8121a6) and adds no migration.

What I checked, tool by tool

  • Organization and brand.
    • Every brand read checks brandInOrg (or getVisibilitySummaryFor / getPromptVolumesFor, which do the same) before anything runs as the service role.
    • I followed every loader asService runs, down to the queries: getKpiSnapshots (and the visibility, insights, share-of-voice and traffic reads it calls), getTrackingWindow, getGettingStarted, getQueryFanout, getTrafficGoogleTotals, getPromptResults. Each query and RPC filters by the brand id, or by ids taken from the brand's own rows.
    • list_ai_answers with another brand's prompt id returns nothing: the answers are filtered by brand.
    • The workspace reads filter by organization_id. list_connections reads only the person's own API keys.
  • dbClient() in the four action files. Outside a scope it is the session client, so the pages behave the same. The only withDbClient scopes are Chat's and MCP's, after the brand check.
  • Read/write and role. All twelve are read, minRole: analyst, mcpTool: null, and none writes. What they show matches what Settings shows every role. E-mails are stricter than Settings › Team: Admins only.
  • Plan gates. get_prompt_insights has prompt_volumes, like get_prompt_volumes. Fan-outs and AI answers keep the plan's platforms from the rows up. None of the pages behind the others gates by plan (KPIs, Getting started, Search Console, Analytics).
  • No dollars. get_plan_facts whitelists counts and sends the plan card (list prices only), never the AI budget.
  • Bounds. 50 sub-queries, up to 10 answers of 1,500 characters, the top 25 prompts, a 90-day window. The engine's own result budget sits on top.
  • Outside text. None of the twelve is in the engine's TRUSTED_READS, so each marks the run, and a change after it asks first. That's right for AI answers, fan-out sub-queries, prompt texts, member names and CMS site names.
  • Embeds and imports.
    • The new code has no embeds.
    • No client file imports the new modules (the Capabilities view imports a type only).
    • plan-row.test.ts passes.

Not blocking

  1. TRUSTED_READS. Some of these return only the workspace's own numbers and settings: get_overview_summary (the trusted visibility summary plus run times), get_action_center_kpis, get_onboarding_progress, get_gsc_summary, get_ga_summary, get_plan_facts and get_chat_policy. They could join the list in a follow-up, so that reading them doesn't make a later change ask in Full auto.
  2. The demo brand in list_connections. Its google and cms rows include the demo brand, also once it's hidden. list_brands leaves a hidden demo brand out (is_demo.eq.false,demo_hidden_at.is.null), and these reads could do the same.
  3. asService. It now exists twice (mcp/product-visibility.ts and mcp/chat-facts.ts). product-visibility could import the new one.
  4. list_ai_answers dates. date_from and date_to take any string. z.iso.datetime() would turn a bad date into a schema error the model can correct, instead of a failed read.

Tests (on the PR head, which is main plus this PR):

  • src/lib/chat and src/lib/mcp: 55 files, 653 tests pass.
  • The guards, subscription-guard-coverage, the demo tests and the four action files' tests: 23 files, 121 tests pass.
  • plan-row.test.ts passes.
  • tsc passes. eslint shows no errors on the changed files, and prettier --check passes on them.

@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 and keeps both sides of #1807's conflict in the tool registry, its test and en.json (the area reads and the navigation read).

@gkhngyk
gkhngyk merged commit beb1633 into ansvisor:main Oct 30, 2026
8 of 9 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