Repository navigation
feat(chat): read a brand's connections once, for agents, Chat and the Connections page (W4-24) - #2012
Conversation
… Connections page (W4-24) One read of a brand's connection rows (connection-rows.ts) that the agents' checks, Chat's list_connections and the new GET /api/chat/connections all use, and connections.ts building each tool's record for a brand: status, account, who connected it and when, access, what uses it, the agents that would stop on Disconnect, up to two Suggested, and the tools coming soon. Per brand, behind CHAT_AGENTIC. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
One fix needed.
Search Console and Analytics stay "connected" after the Google sign-in is gone. stateOf (web/src/lib/chat/connections.ts:243-254) decides the status from brands.gsc_property / ga_property_id alone, and readSignIns drops every row that isn't connected. DELETE /api/integrations/:provider deletes the integration_connections row but leaves the brand's property set. So after an Admin disconnects Google in Settings, or while the sign-in is pending/error, the Connections page, the menu and list_connections all still say Connected. Before this PR, list_connections returned each provider's sign-in status, so Chat could tell; that list is gone now.
Fix: property set and sign-in connected → connected; property set but no connected sign-in → failing; no property → not_connected. Do the same in connectedKinds, and add a test for a property with no sign-in.
Small: the description says no ids go in the answer, but account for Analytics is the raw ga_property_id. It isn't a secret, so just adjust the wording.
Search Console and Analytics were read as connected from the brand's picked property alone. Disconnecting Google in Settings deletes the workspace's sign-in but keeps the brand's property, so the Connections page, the chat menu and list_connections went on saying Connected. A property now counts as connected only while its Google sign-in is connected; with the property set and no connected sign-in it shows as failing. connectedKinds takes the sign-ins too, so Suggested and the agents' "would stop" list agree with the status. Called without sign-ins (the agent-run check) it reads as before. The comments no longer claim a record carries no id: Analytics' account is its property id.
Summary
One read of a brand's connections for Chat, behind
CHAT_AGENTIC(Chat Wave 4, W4-24; agentic plan §6). Until now the agents' connection checks and Chat'slist_connectionsread the same tables in two ways; now they share one read, and the Connections menu row and page (W4-25, the next PR) will use it too. Connections stay per brand, as the code and the Brand-level access decision have them (owner decision 15).lib/chat/connection-rows.ts: the one read of a brand's rows (properties, CMS sites, workflow webhooks, catalog sources), for one or many brands.readBrandConnections(agents) now reads through it; what it decides doesn't change.lib/chat/connections.ts: every tool as a record for a brand: status (connected, sign-in failed, not connected, Soon), the account as the person named it, who connected it and when, access (read-only, read + write drafts, sends pages), what uses it (skills and the brand's agents the person can see), the agents that would stop on Disconnect (only when no other tool of its kind is connected), and up to two Suggested (what the brand's agents lack, then Search Console, then Analytics).GET /api/chat/connections?brand=: a brand the person reaches only (RLS read first), withcanConnectfor Admins. No id, key or token in the answer.list_connectionsreads the same records per brand the person may use: connected tools with account and access, failed sign-ins, what could be connected, and the tools coming soon, plus the AI provider keys and the person's own API keys as before.No screen in this PR. Connect still happens in Settings › Integrations.
Related issue
None. Chat waves plan, Wave 4 (W4-24).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd web && yarn vitest run src/lib/chat/connections.test.ts src/lib/chat/agent-connections.test.ts src/lib/mcp/chat-reads.test.ts src/app/api/chat/connections/route.test.ts src/lib/chat/agent-driver.test.ts src/lib/chat/agents.test.ts src/lib/chat/agent-runs.test.ts src/lib/chat/registry/tools.test.tsGET /api/chat/connections?brand={brand id}lists the brand's tools; a brand of another workspace answers 404.No migration. No new environment variable (Merchant Center's offer is read as before, through
CRON_SECRET).Checklist
yarn lintpassesyarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)CI passed on this branch (a643bff), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41479883313): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code