Skip to content

feat(chat): show a Connect card when a tool's app isn't connected - #5563

Draft
mattboon wants to merge 2 commits into
veryfront:mainfrom
mattboon:mattboon/chat-connect-card
Draft

mattboon wants to merge 2 commits into
veryfront:mainfrom
mattboon:mattboon/chat-connect-card

Conversation

@mattboon

@mattboon mattboon commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of veryfront/veryfront-issue-inbox#4216 (Connect card in the local chat and the UI kit).

Problem

When a tool stops because its app isn't connected, the API answers with a structured result:

{ "error": "authentication_required", "integration": "salesforce",
  "connectUrl": "https://api.veryfront.com/oauth/connect/salesforce?project_reference=…",
  "message": "Authentication required for Salesforce." }

Studio renders that as a Connect card. The UI kit's ToolCall (used by <Chat> in every generated app and in the local chat) showed it as a raw JSON result, so the user saw a failed tool and had nothing to click.

Change

  • New IntegrationConnectCard in the UI kit, exported from veryfront/chat: it names the app and says Not connected (or Connection expired for reconnect_required). By default it shows the exact command that connects it: npx veryfront integration connect <app> --project <project from the connect URL>, with a copy button. Try again reruns the turn (the chat's onReload). A host that can run OAuth itself passes onConnect and gets a Connect button instead of the command.
  • ToolCall renders that card for a complete authentication_required / reconnect_required result, the same check the runtime uses (isIntegrationAuthenticationActionResult). This includes a sub-agent's tool inside an invoke_agent card. An incomplete result keeps the ordinary card. A custom variant or children still wins.
  • The card doesn't open connectUrl: in a browser it answers 401 without an API key. The --project value comes from that URL only when it's a plain id, and the app name only when it matches ^[a-z0-9][a-z0-9_-]*$, so nothing tool-supplied reaches the command unchecked.
  • API reference regenerated (deno task docs, Deno 2.9.7) and the veryfront/chat export list updated.

Not end to end yet: blocked by the API

In a local run (veryfront dev, connected to Cloud), the same call doesn't return authentication_required. It answers authorization-denied: "Run context is not authorized for this integration tool", because the run ID is bound for tool authorization. So the local chat can't show this card until veryfront/veryfront-issue-inbox#4486 is fixed in the API. Once it is, the card appears there with no further Code change.

Still open in #4216: a one-click Connect in the local chat. The dev server would need to create a one-time connect session with its own key, as npx veryfront integration connect does, and resume the run once connected. That's a follow-up after #4486.

Validation

  • deno task test:file src/react/components/chat/chat/components/tool-ui.test.tsx: 4 new tests (card with command and project; expired connection without a project; incomplete result keeps the ordinary card; Try again calls onReload). Three fail on main and pass here; the incomplete-result test is a guard.
  • deno task test:file src/react/components/chat/: 158 passed. deno task test:file src/chat/: passed after adding the export.
  • deno check src/chat/index.ts and the test file; deno fmt and deno lint on the changed files (Deno 2.9.7).

Before: the local chat on the Salesforce template, staging, Salesforce not connected (veryfront dev from this branch's base). The sub-agent says Completed and the reply only says access was denied:

before

After: Storybook › Chat/Components/ToolCall › Not connected, rendering the API's real authentication_required result:

after

Test hardening (9c359f650)

A coverage audit found two defects in tool-ui.tsx and fixed them.

  • Accessors no longer run: the card read message and error from the tool result with plain property access. A tool result with a getter on message ran it and showed its value as the app name, which breaks the existing "renders hostile tool values" rule. All four fields are now read with readToolResultOwnDataProperty.
  • Try again uses the message's own reload: it always called the chat's onReload and ignored a reload passed to Message.Root. It now uses the same handler as that message's Regenerate action and falls back to the chat's onReload.
  • New integration-connect-card.test.tsx (10 tests):
    • the command with and without --project;
    • app name from the message, a title-cased fallback, and an overlong name ignored;
    • "Connection expired" on reconnect;
    • a host onConnect button labelled Connect or Reconnect;
    • Try again as a native keyboard-reachable button, and the copy control named "Copy code";
    • ref and className forwarding;
    • escaped tool text.
  • 10 more cases in tool-ui.test.tsx:
    • a message reload wins over the chat reload, and there's no Try again without a reload;
    • integration and project ids that aren't plain ids fall back safely;
    • blank, non-string, wrong-error and array results keep the ordinary card;
    • accessors never run;
    • variant and children overrides still win;
    • a sub-agent's not-connected tool shows the card inside the child-agent card.
  • Red/green:
    • On this PR's earlier head, the accessor and reload tests fail.
    • With tool-ui.tsx reverted to main, 9 tests fail.
    • With the id filters removed, both guard tests fail.
    • On the final head, deno task test:file src/react/components/chat/ src/chat/ gives 259 passed, 0 failed.
  • Checks: lint:chat-composability, ban-chat-antipatterns.ts (no ceiling raised), audit-client-bundle.ts, storybook:check and docs:api-reference:check pass. The full pre-push gate passed on Deno 2.9.7. The first attempt failed one unrelated timing test, ssr-module-loader/loader.test.ts, under parallel load; it passes 3/3 alone and on the retry.

… the message's reload

The Connect card read `message` and `error` from the tool result with a plain
property access, so an accessor-backed `message` ran and its value named the app.
Read them as own data properties, as `isIntegrationAuthenticationActionResult`
already does for `integration` and `connectUrl`.

Try again now runs the message's reload override first, the same handler as the
message's Regenerate action, and falls back to the chat's `onReload`.

Tests: the card's states (command, host Connect and Reconnect, Try again, name
fallback, overlong name, ref and className, escaped text), unsafe integration ids
and project references, malformed results, variant and children overrides, and a
sub-agent's tool inside the child-agent card.

This branch has not been deployed

No deployments
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.

1 participant