Skip to content

Commit f59c2b7

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
feat(docs): Ask AI, MCP server and personalized samples
Mono-RevId: bf2393424c8ba2c4f82f57202ba45dd3e89b91da
1 parent 82a1b55 commit f59c2b7

93 files changed

Lines changed: 6365 additions & 78 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/docs.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- "apps/docs/**"
5656
5757
# Builds the docs site (apps/docs) and runs its checks: every internal link and #anchor
58-
# resolves, and every published docs URL and redirect still answers.
58+
# resolves, every published docs URL and redirect still answers, and the MCP endpoint works.
5959
check:
6060
name: check
6161
needs: changes
@@ -106,7 +106,7 @@ jobs:
106106
env:
107107
NEXT_TELEMETRY_DISABLED: "1"
108108

109-
- name: 🔗 Check links and URLs
109+
- name: 🔗 Check links, URLs and MCP
110110
run: pnpm --filter docs-site check
111111
env:
112112
NEXT_TELEMETRY_DISABLED: "1"

‎.github/workflows/publish-docs.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ jobs:
190190
if: steps.config.outputs.enabled == 'true'
191191
run: pnpm dlx "$VERCEL_CLI" pull --yes --environment=production --token="$VERCEL_TOKEN"
192192

193-
# The build stops if a production setting (analytics) is missing.
193+
# The build stops if a production setting (Ask AI, its limits, analytics) is missing.
194194
- name: 🏗️ Build
195195
if: steps.config.outputs.enabled == 'true'
196196
env:
@@ -204,7 +204,7 @@ jobs:
204204
url=$(pnpm dlx "$VERCEL_CLI" deploy --prebuilt --prod --skip-domain --token="$VERCEL_TOKEN")
205205
echo "url=$url" >> "$GITHUB_OUTPUT"
206206
207-
- name: 🔗 Check URLs and headers on the deployment
207+
- name: 🔗 Check URLs, MCP and headers on the deployment
208208
if: steps.config.outputs.enabled == 'true'
209209
working-directory: apps/docs
210210
env:
@@ -213,6 +213,7 @@ jobs:
213213
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
214214
run: |
215215
node scripts/check-urls.mjs "$URL/docs" --live
216+
node scripts/check-mcp.mjs "$URL/docs"
216217
node scripts/check-headers.mjs "$URL/docs"
217218
218219
- name: ✅ Promote to production

‎apps/docs/.env.example‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
# Copy to .env.local. Every setting is optional locally: without any of them you get the docs with
2-
# search and no analytics. The table in README.md, "Settings", says what each one does and which a
3-
# production build requires.
1+
# Copy to .env.local. Every setting is optional locally: without any of them you get the
2+
# anonymous docs with search, no Ask AI and no analytics. The table in README.md, "Settings",
3+
# says what each one does and which a production build requires.
4+
5+
# Ask AI. Unset: no Ask AI button and /api/ask answers 404.
6+
# ANTHROPIC_API_KEY=
7+
# Default: claude-sonnet-5-5
8+
# ASK_AI_MODEL=
9+
# Default: 25000000 (output tokens count 5 times)
10+
# ASK_AI_DAILY_TOKENS=
11+
# Ask AI rate limits and daily cap. Unset: unlimited locally, 503 on a deployment.
12+
# REDIS_URL=redis://localhost:6379
13+
# Shared with the proxy in front of the site, which sends it with the reader's IP. Unset: limits
14+
# key on the connecting address.
15+
# DOCS_WORKER_SECRET=
416

517
# Analytics. Unset: no events.
618
# NEXT_PUBLIC_POSTHOG_KEY=
719
# Default: https://eu.i.posthog.com
820
# NEXT_PUBLIC_POSTHOG_HOST=
921

10-
# The dashboard the Dashboard link opens. Default: https://cloud.trigger.dev
22+
# Signed-in docs. Unset: everyone sees the anonymous docs. The dashboard must list this site's
23+
# origin in its DOCS_ORIGINS (e.g. http://localhost:43000).
24+
# NEXT_PUBLIC_DOCS_PERSONALIZATION=1
25+
# Default: https://cloud.trigger.dev
1126
# NEXT_PUBLIC_DASHBOARD_URL=http://localhost:3030
1227

1328
# Another server for the API playground (a local or staging API).
@@ -18,5 +33,5 @@
1833
# DOCS_TWOSLASH=
1934
# DOCS_BUILD_CPUS=
2035

21-
# Checks against a preview behind Vercel Authentication (check-urls, check-headers).
36+
# Checks against a preview behind Vercel Authentication (check-urls, check-mcp, check-headers).
2237
# VERCEL_AUTOMATION_BYPASS_SECRET=

‎apps/docs/README.md‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Next.js + Fumadocs app that renders `trigger.dev/docs` at `/docs`. Writers o
66
pnpm --filter docs-site dev # http://localhost:43000/docs
77
pnpm --filter docs-site build:sdk # once, and after SDK type changes: type hovers and <SdkType> read these
88
pnpm --filter docs-site build
9-
pnpm --filter docs-site check # after a build: links, URL contract, headers
9+
pnpm --filter docs-site check # after a build: links, URL contract, MCP
1010
pnpm --filter docs-site check --links # links and anchors only, no build
1111
```
1212

@@ -17,18 +17,19 @@ pnpm --filter docs-site check --links # links and anchors only, no build
1717
## SDK types in the docs
1818

1919
- Type hovers: on production builds, every `ts`/`tsx` block that imports from `@trigger.dev/*` is analysed with the built SDK types (`lib/twoslash.ts`). Readers see hovers on imported names and documented options, never compiler errors, and type errors don't fail the build (about two thirds of samples have some, almost all from being excerpts); a block that can't be analysed renders as plain highlighted code. Results are cached in `.next/cache/twoslash/<types hash>`. `DOCS_TWOSLASH=1` turns hovers on in `dev`, `DOCS_TWOSLASH=0` turns them off; add `no-twoslash` to a fence's meta to skip one block. A block that calls SDK names (`task(`, `logger.info`, `chat.agent`) without importing them gets a hidden import line above a `// ---cut---`, inferred from the packages' exports, so it gets hovers too. Under `CI` the build fails if the SDK types aren't built.
20-
- `<SdkType name="TaskOptions" />` renders the properties of a type exported from `lib/sdk-types/index.ts`, with types, defaults and JSDoc from the SDK source. Add a line there to document another type. The tables are generated by `scripts/build-search-index.mjs` into `.generated/sdk-types.js`, and the same rows become a markdown table in the page's `.md` and `llms-full.txt`.
20+
- `<SdkType name="TaskOptions" />` renders the properties of a type exported from `lib/sdk-types/index.ts`, with types, defaults and JSDoc from the SDK source. Add a line there to document another type. The tables are generated by `scripts/build-search-index.mjs` into `.generated/sdk-types.js`, and the same rows become a markdown table in the page's `.md`, `llms-full.txt`, MCP and Ask AI.
2121

2222
## What `check` covers
2323

2424
- `lib/slug.test.ts`: heading ids match the previous docs site, so existing `#anchor` links keep working.
2525
- `scripts/check-links.mjs`: every internal link and `#anchor` in the MDX resolves to a page (or a `docs.json` redirect) and a heading.
2626
- `scripts/check-urls.mjs <base>`: every URL in `scripts/live-sitemap.txt` (a snapshot of the published sitemap; `--refresh` re-fetches it), every `docs.json` redirect, and the URLs CLIs and agents depend on answer 200 on `<base>`. `--live` also checks every page in production's sitemap today (the release gate uses it, so a page first published on the new site keeps its URL).
27-
- `scripts/check-headers.mjs <base>`: pages can only be framed by the docs, and responses carry `nosniff` and the referrer policy.
27+
- `scripts/check-mcp.mjs <base>`: `/mcp` answers the docs search request published CLIs send, and `get_page_trigger_dev` returns a page with its snippets inlined.
28+
- `scripts/check-headers.mjs <base>`: pages can only be framed by the docs, `/embed/*` pages only by the dashboards, and responses carry `nosniff` and the referrer policy.
2829

29-
`check-urls.mjs` and `check-headers.mjs` also run against any deployment: `node scripts/check-urls.mjs https://<preview>/docs`.
30+
`check-urls.mjs`, `check-mcp.mjs` and `check-headers.mjs` also run against any deployment: `node scripts/check-urls.mjs https://<preview>/docs`.
3031

31-
`pnpm --filter docs-site test` runs the unit tests.
32+
`pnpm --filter docs-site test` runs the unit tests, including `lib/api-access-spec.test.ts`, which fails when an OpenAPI operation's `x-trigger-access` doesn't match its webapp route. `node scripts/api-access.mjs` rewrites those values from the routes.
3233

3334
## Build-time data
3435

@@ -37,23 +38,37 @@ pnpm --filter docs-site check --links # links and anchors only, no build
3738
## For agents
3839

3940
- Every page's `.md` starts with frontmatter: `title`, `description`, `url`, `last_updated`, `section`, `group` and `related` (previous, next and sibling pages from the sidebar).
41+
- "Copy prompt" (`components/copy-prompt.tsx`) shows on guides and on pages with `<Steps>`: it copies the page's markdown as instructions for an AI coding assistant.
42+
- WebMCP (`lib/webmcp.ts`, registered by `components/webmcp.tsx`): where the browser has the API, the page registers `search_docs` and `read_page` for agents running in the browser.
43+
44+
## Content-gap report
45+
46+
`node scripts/content-gaps.mjs` reads the last 7 days of `docs_search`, `docs_search_result_clicked`, `docs_ask_ai_answered` and `docs_ask_ai_feedback` events from PostHog and prints the questions the docs didn't answer (no search results, no click, no citations, thumbs down), grouped by topic. It needs `POSTHOG_PERSONAL_API_KEY`, `POSTHOG_PROJECT_ID` and `POSTHOG_HOST`. `--linear` (with `LINEAR_API_KEY`, `LINEAR_TEAM_ID`, `LINEAR_PROJECT_ID`) files one issue per new topic with at least `--min` readers (default 2), skipping topics already filed. `--fixture scripts/fixtures/content-gaps.json` runs without keys.
47+
48+
Exit codes: 0 report printed, 1 an API failed, 2 keys missing, 3 no docs events at all in the window (usually a missing or wrong analytics key on the site, not a quiet week). A query that hits its row limit prints a "Truncated" warning.
4049

4150
## Deployment
4251

43-
Built and deployed from GitHub Actions only (the host's Git integration is off in `vercel.json`): `.github/workflows/publish-docs.yml` deploys every new `docs-live` commit (docs-only commits on merge, everything else with a `docs-release-*` tag) and checks it with `check-urls` and `check-headers` before it takes the production domain. A production build stops if any setting marked "production" below is unset. Preview deployments send `X-Robots-Tag: noindex` (`next.config.mjs`).
52+
Built and deployed from GitHub Actions only (the host's Git integration is off in `vercel.json`): `.github/workflows/publish-docs.yml` deploys every new `docs-live` commit (docs-only commits on merge, everything else with a `docs-release-*` tag) and checks it with `check-urls`, `check-mcp` and `check-headers` before it takes the production domain. A production build stops if any setting marked "production" below is unset. Preview deployments send `X-Robots-Tag: noindex` (`next.config.mjs`).
4453

4554
## Settings
4655

4756
`.env.example` lists them with their defaults; copy it to `.env.local`.
4857

4958
| Name | Read at | Production | Without it |
5059
| --- | --- | --- | --- |
51-
| `NEXT_PUBLIC_POSTHOG_KEY` | build | required | No analytics events. |
60+
| `ANTHROPIC_API_KEY` | build and runtime | required | No Ask AI button, and `/api/ask` answers 404. |
61+
| `ASK_AI_MODEL` | runtime | optional | Ask AI uses its default model. |
62+
| `ASK_AI_DAILY_TOKENS` | runtime | optional | Ask AI closes for the day after 25M tokens (output tokens count 5 times), about $50 a day at Sonnet-class prices. Set it when the model or the spend you want changes; `0` keeps Ask AI closed. |
63+
| `REDIS_URL` | runtime | required | Ask AI's rate limits and daily cap. Locally, Ask runs unlimited; on a deployment, Ask answers 503. |
64+
| `DOCS_WORKER_SECRET` | runtime | required | The shared secret the proxy in front of the site sends with the reader's IP. Without it, Ask AI limits key on the connecting address, so readers behind the proxy share one limit. |
65+
| `NEXT_PUBLIC_POSTHOG_KEY` | build | required | No analytics events, so the content-gap report has nothing to read. |
5266
| `NEXT_PUBLIC_POSTHOG_HOST` | build | optional | Events go to PostHog's EU host. |
53-
| `NEXT_PUBLIC_DASHBOARD_URL` | build | optional | The Dashboard link goes to `https://cloud.trigger.dev`, which is right for production. |
67+
| `NEXT_PUBLIC_DASHBOARD_URL` | build | optional | Sign-in links and personalization use `https://cloud.trigger.dev`, which is right for production. |
68+
| `NEXT_PUBLIC_DOCS_PERSONALIZATION` | build | required | Every reader sees the anonymous docs: no project in code samples, no docs keys. |
5469
| `DOCS_API_SERVER_URL` | build and runtime | optional | The API playground offers only the servers in the OpenAPI spec. Set it to add another (a local or staging API). |
5570
| `DOCS_TWOSLASH`, `DOCS_BUILD_CPUS` | build | optional | See "Dev server" and "SDK types in the docs". |
5671
| `DOCS_DEV_ORIGINS` | dev | optional | `next dev` answers only on localhost. Comma-separated hosts to allow another (a tailnet name, say). |
57-
| `VERCEL_AUTOMATION_BYPASS_SECRET` | check scripts | optional | `check-urls` and `check-headers` can't get past Vercel Authentication on a preview. |
72+
| `VERCEL_AUTOMATION_BYPASS_SECRET` | check scripts | optional | `check-urls`, `check-mcp` and `check-headers` can't get past Vercel Authentication on a preview. |
5873

59-
Browser events for monitoring: `docs_not_found` (a 404, with `path` and `referrer`).
74+
Logs are one JSON object per line. The `event` field: `ask` (an answer: sources, tool counts, latency, token usage, `siteCount`; never the question), `ask.error` (the model call failed; the reader still gets HTTP 200 with an error in the stream), `ask.limited` (a 429, with `limit`: `minute`, `day` or `site`), `ask.ratelimit_error` (the limiter failed, so Ask answered 503), `ask.redis_error` (Redis connection errors, at most one a minute), `ask.timeout` and `ask.aborted` (an answer cut off at 50 s, or stopped by the reader; both still count toward the daily budget), `ask.tool_error` (a search or page read the model asked for failed), `ask.spend_error` (the token count couldn't be added to the daily budget), `mcp.error` (an exception inside an MCP call). Browser events for monitoring: `docs_reader_error` (personalization failed for a signed-in reader; `status` 0 means blocked or unreachable) and `docs_not_found` (a 404, with `path` and `referrer`).

‎apps/docs/app/(docs)/[...slug]/page.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
ViewOptionsPopover,
99
} from "fumadocs-ui/layouts/notebook/page";
1010
import { TrackPageActions } from "@/components/analytics";
11+
import { CopyPromptButton } from "@/components/copy-prompt";
12+
import { pageSection } from "@/lib/agent-markdown";
13+
import { isPromptPage } from "@/lib/copy-prompt";
1114
import { PageFeedback } from "@/components/feedback";
1215
import { PageBody } from "@/components/page-body";
1316
import { PageFreshness } from "@/components/page-freshness";
@@ -26,6 +29,7 @@ export default async function Page({ params }: Props) {
2629
// fumadocs prefixes the /docs basePath itself.
2730
const markdownUrl = `${page.url}.md`;
2831
const api = await pageApi(page);
32+
const promptable = !api && isPromptPage(pageSection(page), await page.data.getText("processed"));
2933

3034
return (
3135
<DocsPage toc={toc} full={page.data.full || page.data.mode === "wide" || !!api}>
@@ -45,6 +49,13 @@ export default async function Page({ params }: Props) {
4549
<div className="flex shrink-0 flex-row items-center gap-2 sm:pt-1.5">
4650
<TrackPageActions path={page.url}>
4751
<MarkdownCopyButton markdownUrl={markdownUrl} />
52+
{promptable && (
53+
<CopyPromptButton
54+
path={page.url}
55+
title={page.data.title}
56+
mdUrl={`${docsUrl}${page.url}.md`}
57+
/>
58+
)}
4859
<ViewOptionsPopover
4960
markdownUrl={markdownUrl}
5061
pageUrl={`${docsUrl}${page.url}`}

‎apps/docs/app/(docs)/layout.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { ReactNode } from "react";
22
import { DocsLayout } from "fumadocs-ui/layouts/notebook";
33
import { LayoutDashboard } from "lucide-react";
4+
import { AskAIButton, AskAIPanel, PhoneSearchAndAsk } from "@/components/ask-ai";
45
import { HeaderTabs } from "@/components/header-tabs";
56
import { Logo } from "@/components/logo";
6-
import { dashboardLink } from "@/lib/dashboard-link";
7+
import { ReaderMenu } from "@/components/reader-menu";
8+
import { askEnabled } from "@/lib/ask-config";
9+
import { dashboardLink, personalizationEnabled } from "@/lib/dashboard-link";
710
import { pageTree, sectionTabs as tabs } from "@/lib/nav";
811
import { githubUrl } from "@/lib/source";
912

@@ -15,6 +18,11 @@ export default function Layout({ children }: { children: ReactNode }) {
1518
tabs={tabs}
1619
// Pages are static and CDN-cached: fetch one on click instead of every sidebar link in view.
1720
sidebar={{ prefetch: false }}
21+
searchToggle={
22+
askEnabled()
23+
? { components: { sm: <PhoneSearchAndAsk hideIfDisabled className="p-2" /> } }
24+
: undefined
25+
}
1826
nav={{
1927
mode: "top",
2028
title: (
@@ -28,6 +36,7 @@ export default function Layout({ children }: { children: ReactNode }) {
2836
}}
2937
githubUrl={githubUrl}
3038
links={[
39+
...(askEnabled() ? [{ type: "custom" as const, children: <AskAIButton /> }] : []),
3140
{
3241
type: "button",
3342
text: "Dashboard",
@@ -36,9 +45,11 @@ export default function Layout({ children }: { children: ReactNode }) {
3645
external: true,
3746
secondary: true,
3847
},
48+
...(personalizationEnabled ? [{ type: "custom" as const, children: <ReaderMenu /> }] : []),
3949
]}
4050
>
4151
{children}
52+
{askEnabled() && <AskAIPanel />}
4253
</DocsLayout>
4354
);
4455
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { siteDescription, skillDescription, skillUrl } from "@/lib/agent-surface";
2+
import { docsUrl, siteUrl } from "@/lib/source";
3+
4+
export const dynamic = "force-static";
5+
6+
// A2A agent card, same fields as the one served before.
7+
export function GET() {
8+
const url = `${docsUrl}/`;
9+
return Response.json({
10+
name: "Trigger.dev",
11+
description: siteDescription,
12+
url,
13+
version: "1.0.0",
14+
protocolVersion: "0.3",
15+
preferredTransport: "HTTP+JSON",
16+
supportedInterfaces: [{ url, protocolBinding: "HTTP+JSON", protocolVersion: "0.3" }],
17+
provider: { url, organization: "Trigger.dev" },
18+
documentationUrl: url,
19+
capabilities: { streaming: false, pushNotifications: false },
20+
defaultInputModes: ["text/plain"],
21+
defaultOutputModes: ["text/plain"],
22+
skills: [
23+
{
24+
id: "trigger",
25+
name: "trigger",
26+
description: skillDescription,
27+
tags: [],
28+
url: `${siteUrl}${skillUrl}`,
29+
},
30+
],
31+
});
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { skillDescription, skillDigest, skillUrl } from "@/lib/agent-surface";
2+
3+
export const dynamic = "force-static";
4+
5+
export function GET() {
6+
return Response.json({
7+
$schema: "https://schemas.agentskills.io/discovery/0.2.0/schema.json",
8+
skills: [
9+
{
10+
name: "trigger",
11+
type: "skill-md",
12+
description: skillDescription,
13+
url: skillUrl,
14+
digest: skillDigest,
15+
},
16+
],
17+
});
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { docsUrl, siteUrl } from "@/lib/source";
2+
3+
export const dynamic = "force-static";
4+
5+
// RFC 9727 API catalog: the REST API, its OpenAPI description and its docs.
6+
export function GET() {
7+
return Response.json(
8+
{
9+
linkset: [
10+
{
11+
anchor: `${siteUrl}/api`,
12+
"service-desc": [{ href: `${docsUrl}/v3-openapi.yaml`, type: "application/yaml" }],
13+
"service-doc": [{ href: `${docsUrl}/management/overview`, type: "text/html" }],
14+
},
15+
],
16+
},
17+
{ headers: { "Content-Type": "application/linkset+json" } }
18+
);
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { mcpUrl } from "@/lib/agent-surface";
2+
import { mcpTools } from "@/lib/mcp";
3+
4+
export const dynamic = "force-static";
5+
6+
export function GET() {
7+
const name = "Trigger.dev Docs MCP";
8+
return Response.json({
9+
name,
10+
description: "Search and read the Trigger.dev documentation",
11+
version: "1.0.0",
12+
serverInfo: { name, version: "1.0.0" },
13+
url: mcpUrl,
14+
transport: "http",
15+
capabilities: { tools: true, resources: false },
16+
authentication: "none",
17+
tools: mcpTools.map(({ name, description, inputSchema, title, annotations }) => ({
18+
name,
19+
description,
20+
inputSchema,
21+
annotations: { title, destructiveHint: false, ...annotations },
22+
})),
23+
});
24+
}

0 commit comments

Comments
 (0)