Skip to content

feat(chat): read a brand's connections once, for agents, Chat and the Connections page (W4-24) - #2012

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-connections-reader
Nov 3, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-connections-reader

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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's list_connections read 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).
    • Live tools: Google Search Console, Google Analytics, Webflow, WordPress, Framer, Wix, workflow webhook, Google Merchant Center (only where this server offers it, or once a brand has it), WooCommerce, product feed or file.
    • Soon (nothing to click, as Agent Center's Soon cards): Bing Webmaster Tools, Contentful, Sanity, Shopify, HubSpot, Salesforce, Pipedrive, Stripe, Google Sheets, Looker Studio, Slack, Microsoft Teams, Zapier.
  • GET /api/chat/connections?brand=: a brand the person reaches only (RLS read first), with canConnect for Admins. No id, key or token in the answer.
  • list_connections reads 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. 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.ts
  2. With Chat on, signed in as the demo admin: GET /api/chat/connections?brand={brand id} lists the brand's tools; a brand of another workspace answers 404.
  3. In Chat, ask "What do we have connected?": the step reads Integrations and the answer lists each brand's tools from the same data.

No migration. No new environment variable (Merchant Center's offer is read as before, through CRON_SECRET).

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (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 and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

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

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.

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

LGTM

@gkhngyk
gkhngyk merged commit 286cf32 into ansvisor:main Nov 3, 2026
5 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Nov 3, 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