Skip to content

feat: make shared chat links agent-friendly - #213

Merged
yongkangc merged 2 commits into
cfal:mainfrom
0xSolarPunk:feat/agent-friendly-share
Jun 24, 2026
Merged

feat: make shared chat links agent-friendly#213
yongkangc merged 2 commits into
cfal:mainfrom
0xSolarPunk:feat/agent-friendly-share

Conversation

@0xSolarPunk

Copy link
Copy Markdown
Contributor

Problem

A shared chat link (/shared/:token) served only the SvelteKit SPA shell — the transcript loaded client-side via a follow-up /api/v1/shared fetch. Agents and crawlers that do not execute JavaScript (most HTTP fetchers, link unfurlers, LLM web-fetch tools) saw an empty shell with a generic <title>Garcon</title> and no conversation content. The agent-readable plain-text endpoint (/shared/llm/:token) existed but was undiscoverable from the human URL.

Solution

Serve /shared/:token from a dynamic handler that enriches the SPA shell server-side: Open Graph/Twitter metadata, a discoverable <link rel="alternate"> to the plain-text transcript, and a no-JS transcript fallback embedded in the HTML. An inline script removes the fallback the instant JS runs, so browser users get the normal hydrated app while JS-less agents read the full transcript straight from the markup. All snapshot content is HTML-escaped.

Changes

  • Add server/chats/share-page.ts with pure render helpers (injectSharedChatContext, renderStandaloneSharedHtml) that inject share metadata and the escaped transcript fallback (reusing renderSharedChatText).
  • Move /shared/:token from the static route map to a dynamic handler in server/routes/shares.ts; unknown tokens fall through to the SPA shell with no transcript leak.
  • Export loadStaticText from server/routes/static.ts to read the SPA shell; remove the static /shared/:token route.
  • Add route tests covering metadata/transcript presence, HTML-escaping (XSS safety), and not-found handling.

Expected Impact

A shared link is now both human-friendly and agent-scrapable: fetching /shared/:token returns the full conversation in the HTML with no JS engine or second request needed, and link unfurls show the chat title/snippet. Note: branded AI crawler user-agents (GPTBot, ClaudeBot) are still blocked by Cloudflare bot protection at the edge; allowing them through for /shared/* is a separate infra change.

0xSolarPunk and others added 2 commits June 23, 2026 07:08
Serve /shared/:token with server-rendered share metadata and a no-JS
transcript fallback so a shared link is both human-friendly and readable
by agents/crawlers that do not execute JavaScript.
@yongkangc
yongkangc enabled auto-merge (squash) June 24, 2026 02:49
@yongkangc
yongkangc merged commit ef2da42 into cfal:main Jun 24, 2026
4 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