Repository navigation
feat(chat): add the reads Chat was missing, one registry file per area - #1800
Merged
Merged
Conversation
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]>
This was referenced Oct 29, 2026
gkhngyk
previously approved these changes
Oct 30, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
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(orgetVisibilitySummaryFor/getPromptVolumesFor, which do the same) before anything runs as the service role. - I followed every loader
asServiceruns, 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_answerswith another brand's prompt id returns nothing: the answers are filtered by brand.- The workspace reads filter by
organization_id.list_connectionsreads only the person's own API keys.
- Every brand read checks
dbClient()in the four action files. Outside a scope it is the session client, so the pages behave the same. The onlywithDbClientscopes 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_insightshasprompt_volumes, likeget_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_factswhitelists 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.tspasses.
Not blocking
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_factsandget_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.- The demo brand in
list_connections. Itsgoogleandcmsrows include the demo brand, also once it's hidden.list_brandsleaves a hidden demo brand out (is_demo.eq.false,demo_hidden_at.is.null), and these reads could do the same. asService. It now exists twice (mcp/product-visibility.tsandmcp/chat-facts.ts).product-visibilitycould import the new one.list_ai_answersdates.date_fromanddate_totake 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/chatandsrc/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.tspasses.tscpasses.eslintshows no errors on the changed files, andprettier --checkpasses on them.
This was referenced Oct 30, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inen.jsonchatTools):registry/prompts.ts:get_fanouts,list_ai_answers,get_prompt_insightsregistry/visibility.ts:get_overview_summaryregistry/action-center.ts:get_action_center_kpis,get_onboarding_progressregistry/ai-traffic.ts:get_gsc_summary,get_ga_summaryregistry/account.ts(no brand):list_members,list_connections,get_chat_policy,get_plan_factstools.tstakes them through oneareas.tsimport.Data (
lib/mcp/*-reads.ts): each tool calls one function.brandInOrg, then run the page's own loader as the service role (withDbClient(supabaseAdmin)). This is theproduct-visibility/prompt-locationspattern.kpis.ts,traffic.ts,fanout.tsandgetting-started.tsusedbClient(). Outside a scope it is the session client, so the pages behave the same.allowedScrapers).getQueryFanouttakes an optionalplatforms.data_as_ofon every read:source_lag"2–3 days".ga_ai_traffic_stats' last day, lag "1 day".list_membersgives email to Admins only.list_connectionsreads only the person's own API keys (user_id), and no hashes, last4, Composio ids or CMS credentials.get_plan_factswhitelists counts: no AI budget dollars.get_chat_policyroutes to Settings › Roles & access.Review round (f630a2f):
list_connectionsown keys only.gscLatestDayslike the page (≤ 7 days), anddata_as_ofis the last reported day.connectedneedsintegration_connections.status = 'connected'and a property.list_ai_answersreads 50, filters by plan, then cuts.get_fanoutscounts only plan engines.get_prompt_insightsaddstruncated.Related issue
Part of Chat (CHAT-20, Wave 1).
Type of change
feat— New featureHow to test
cd web && yarn vitest run src/lib/chat src/lib/mcp: registry and MCP parity, andchat-reads.test.ts. That test covers org check, own keys only, plan filtering, the GSC window and connection status.CHAT_AGENTICon, ask Chat "how did my fan-out change this week" or "who is in my workspace". The answers name theirdata_as_of.Checklist
src/lib/chat,src/lib/mcp, the four action files: 55 files, 671 tests, after merging main)'use client'file added (the production build's client graph is unchanged)🤖 Generated with Claude Code