Skip to content

refactor(showcase): retire the v1 runtime adapter across every integration - #6618

Merged
BenTaylorDev merged 1 commit into
mainfrom
ben1/v2-single-route-showcase
Aug 21, 2026
Merged

BenTaylorDev merged 1 commit into
mainfrom
ben1/v2-single-route-showcase

Conversation

@BenTaylorDev

@BenTaylorDev BenTaylorDev commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Retires the v1 runtime adapter from showcase/integrations/. After this, no code under showcase/integrations/ calls copilotRuntimeNextJSAppRouterEndpoint — 239 routes across 20 integrations.

This is the cheap path we discussed: single-route mode, which is a genuine drop-in. No demo page changes, no route path changes, no GET exports, no new dependencies.

The shape

const copilotHandler = createCopilotRuntimeHandler({
  runtime,
  basePath: "/api/copilotkit-x",
  mode: "single-route",
});
...
return await copilotHandler(req);

Why single-route: these demos' frontends are <CopilotKit runtimeUrl="/api/copilotkit-x"> with no transport prop, and every released provider pins the single-route transport. So single-route mode is what the v1 adapter was already serving. Migrating to multi-route instead would have meant editing every demo page in lockstep, for no functional gain — nothing in the showcase probes /info.

Why createCopilotRuntimeHandler rather than createCopilotEndpointSingleRoute: that helper is itself deprecated in favour of the mode option (per the deprecated-aliases table in docs/backend/runtime-endpoints.mdx), and the fetch handler needs no hono dependency and composes directly with the wrappers these routes already have.

The statement is rewritten in place, inside whatever wrapper it already sat in, so withForwardedHeaders, the try/catch envelopes, wrapStreamingResponse and withCvdiagBackend are untouched. 75 of these routes construct the runtime inline in the call; rewriting in place preserves that per-request construction exactly as v1 did. No runner is added — it's optional and none of these routes passed one.

13 copilotkit-auth/[[...slug]] routes already use the v2 fetch handler and are left alone; they only name v1 in comments.

Verified

The shape was proved end-to-end before the rollout, in a real running app with an untouched provider (aimock as the model backend): POST /api/copilotkit → 200 twice, chat turn rendered in the browser. It also typechecks against the exact version these integrations pin (1.68.2).

mastra is the integration installed and exercised locally — 19 routes, the withCvdiagBackend main route, and the only vitest suites that touch routes. Measured against origin/main in the same tree:

baseline (origin/main) after
tsc --noEmit errors in 10 files errors in 9
vitest run 2 files / 13 tests failed, 21 passed 2 files / 13 tests failed, 21 passed
  • New type errors introduced: none.
  • Fixed: src/app/api/copilotkit-mcp-apps/route.ts, whose @ts-expect-error was already unused on main.
  • Test-neutral: those 13 failures are pre-existing on main (mostly extractXHeaders dereferencing req.headers on a {} fake request).

Structural audit over all 239 routes, re-run after the pre-commit formatter: none still imports the v1 root, calls the v1 adapter, references ExperimentalEmptyAdapter or handleRequest in code, or is missing createCopilotRuntimeHandler / basePath / mode: "single-route".

CI has now built all 21 integrations green — showcase_build_check Docker-builds each changed integration and next build typechecks inside it. That covers the ones I could not stand up locally, including the non-JS backends (spring-ai, ms-agent-dotnet, ms-agent-python, ms-agent-harness-dotnet, langroid, strands). Full run: 41 pass / 3 skip / 0 fail.

To be precise about what each gate proves: CI proves these 21 apps still build and typecheck. It does not exercise a chat turn per integration — that came from the pre-rollout live proof of the shape itself, plus mastra's local test suite.

Runtime verification on real cells

Docker is not running on my machine, and bin/showcase test --d6 --direct requires it
(--direct only swaps the in-process driver for the fleet control-plane; the containers are
not optional). So the sanctioned Iron Rule 4 probe has NOT been run — that gap is real and
a reviewer should weigh it. What I did instead was run a real integration directly.

showcase/integrations/mastra on this branch, npm run dev, aimock as the model backend.
Probing eight migrated routes with the exact envelope the released provider sends
(POST {basePath} with {"method":"info"}) — all 200 with real runtime payloads:

copilotkit-multimodal          200   agents: multimodal-demo
copilotkit-mcp-apps            200   agents: headless-complete
copilotkit-a2ui-fixed-schema   200   agents: a2ui-fixed-schema
copilotkit-beautiful-chat      200   agents: beautiful-chat
copilotkit-agent-config        200   agents: agent-config-demo
copilotkit-ogui                200   agents: open-gen-ui
copilotkit-declarative-gen-ui  200   agents: declarative-gen-ui
copilotkit-background-agents   200   agents: background-agents

Then three real demo cells driven in a browser, each rendering and completing a chat turn
through its migrated route (two POSTs, both 200, assistant message rendered):

/demos/beautiful-chat      -> POST /api/copilotkit-beautiful-chat     200, 200
/demos/a2ui-fixed-schema   -> POST /api/copilotkit-a2ui-fixed-schema  200, 200
/demos/multimodal          -> POST /api/copilotkit-multimodal         200, 200

Deliberately spread across different route configs — plain, a2ui, and a dedicated
vision-model route — rather than three variations of the same one.

One route is 500, and it is pre-existing

POST /api/copilotkit (mastra's main route) returns 500 in dev: module-not-found on
./schema.js from src/cvdiag/cvdiag-emitter.ts. schema.ts is tracked and present —
Turbopack in dev just does not resolve the ESM-style .js specifier to it. Proven
pre-existing by restoring only that file to origin/main and re-probing: same 500 on the
v1 code. Its Docker build passes, which is why CI is green.

A mistake in my own verification, recorded

My first pass at the above ran against the wrong branch — I was still on the docs branch,
where these routes are v1, so the first six 200s I collected were the v1 routes. Caught it,
switched to this branch, and re-ran everything above against the migrated code. The accidental
run was not wasted: it independently confirms the premise of this PR, that the v1 adapter and
v2 single-route mode answer the same envelope the same way.

Judgement call worth reviewing

27 @ts-expect-error directives guarded the v1 CopilotRuntime agents type ("wraps Record in MaybePromise<NonEmptyRecord<...>>"). Under /v2 that hole is gone, which makes the directive unused — a hard compile error.

I demoted them to @ts-ignore, which compiles whether or not the mismatch survives in a given integration. The honest reason at the time: 19 of these apps can't be built locally, so I couldn't prove per-file which still need a suppression, and @ts-ignore is what 190 sibling files already use.

Now that CI has built all 21 green, that constraint is gone — the ~220 now-stale suppressions (all of which cite a v1 type hole that no longer applies) can be removed and verified by the same 21 builds. I've left them in place here to keep this PR mechanical and reviewable; say the word and I'll do it as a second pass.

Two pre-existing problems found on the way

  • npm ci fails in showcase/integrations/mastra: Missing: @types/[email protected] from lock file. The Dockerfile uses npm ci --legacy-peer-deps, which does succeed, so the image still builds — but a plain npm ci doesn't. No manifest or lockfile is in this diff.
  • mastra's vitest suite is red on main — 13 failures, as tabled above.

What's left of the v1 entrypoint

Surface Before After
showcase/integrations/** 239 0
examples/v1/** 12 12 (deliberately v1, never in scope)
everything else in examples/ ~61 ~61 (not in this PR)

Stacks cleanly with #6617 (docs) — no file overlap. It also unblocks the two Claude SDK quickstart pages I had to revert there: single-route keeps the starter file at the plain route.ts path, so those pages' prose claims and verify-shell-docs.ts starter-path checks stay valid, and only the fence body needs updating.

🤖 Generated with Claude Code

…ation

Moves all 239 showcase integration routes off
`copilotRuntimeNextJSAppRouterEndpoint`, the deprecated v1 Next.js adapter, so
the v1 entrypoint has no remaining code-level users under
`showcase/integrations/`.

    const copilotHandler = createCopilotRuntimeHandler({
      runtime,
      basePath: "/api/copilotkit-x",
      mode: "single-route",
    });
    ...
    return await copilotHandler(req);

## Why single-route, and why this handler

**Single-route** because these demos' frontends are
`<CopilotKit runtimeUrl="/api/copilotkit-x">` with no transport prop, and every
released provider pins the single-route transport. Single-route mode is
therefore a drop-in for the v1 adapter: no frontend change, no path change, no
`GET` export, and nothing here probes `/info`. Migrating to multi-route instead
would have required editing every demo page in lockstep for no functional gain.

**`createCopilotRuntimeHandler`** rather than `createCopilotEndpointSingleRoute`
because that helper is itself deprecated in favour of the `mode` option (see the
deprecated-aliases table in `docs/backend/runtime-endpoints.mdx`), and because
the fetch handler needs no `hono` dependency and composes directly with the
wrappers these routes already have.

The statement is rewritten in place, inside whatever wrapper it already sat in,
so `withForwardedHeaders`, the try/catch envelopes, `wrapStreamingResponse` and
`withCvdiagBackend` are all untouched. 75 of these routes construct the runtime
inline in the call; rewriting in place preserves that per-request construction
exactly as v1 did. No `runner` is added — it is optional, and none of these
routes passed one before.

13 `copilotkit-auth/[[...slug]]` routes already use the v2 fetch handler and are
left alone; they only mention the v1 name in explanatory comments.

## Collateral

- `mastra`'s main route declared a module-level
  `const serviceAdapter = new ExperimentalEmptyAdapter()` plus a startup log
  about the adapter choice. V2 has no service adapters, so both are gone and the
  comment now explains that there is nothing to configure.
- The three `mastra` vitest suites mocked `@copilotkit/runtime` and the v1
  `{ handleRequest }` return shape; they now mock `@copilotkit/runtime/v2` and
  `createCopilotRuntimeHandler`, which returns the handler directly.
- 27 `@ts-expect-error` directives guarded the **v1** `CopilotRuntime` agents
  type ("wraps Record in MaybePromise<NonEmptyRecord<...>>"). Under `/v2` that
  hole is gone, which makes the directive unused — a hard error. They are
  demoted to `@ts-ignore`, which compiles whether or not the mismatch survives
  in a given integration, because 19 of these apps cannot be built locally to
  prove it either way. Removing all ~220 now-stale suppressions is left as
  follow-up once CI has built every integration green.

## Verified

`mastra` is the one integration installed and exercised locally (19 routes, the
`withCvdiagBackend` main route, and the only vitest suites that touch routes).
Measured against `origin/main` in the same tree:

    tsc --noEmit    baseline: errors in 10 files
                    after:    errors in  9 files
                    new errors introduced: NONE
                    fixed: src/app/api/copilotkit-mcp-apps/route.ts, whose
                           @ts-expect-error was ALREADY unused on main

    vitest run      baseline: 2 files failed, 13 tests failed, 21 passed
                    after:    2 files failed, 13 tests failed, 21 passed
                    → test-neutral; those 13 failures are pre-existing on main

Structural audit over all 239 routes: none still imports the v1 root, uses the
v1 adapter, references `ExperimentalEmptyAdapter` or `handleRequest` in code, or
is missing `createCopilotRuntimeHandler` / `basePath` / `mode: "single-route"`.

The shape itself was proved end-to-end before the rollout, in a real running
app with an untouched provider (aimock as the model backend):
`POST /api/copilotkit` -> 200 twice, chat turn rendered.

## Two pre-existing problems found on the way

- `npm ci` fails in `showcase/integrations/mastra`: `Missing:
  @types/[email protected] from lock file`. Its Dockerfile uses
  `npm ci --legacy-peer-deps`, which does succeed, so the image still builds —
  but a plain `npm ci` does not. Untouched here; no manifest or lockfile is in
  this diff.
- `mastra`'s vitest suite is red on `main` (13 failures, mostly
  `extractXHeaders` dereferencing `req.headers` on a `{}` fake request).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Production Digest-Pinning Audit

All 42 services digest-pinned.

Run 2026-08-20 17:01:17 PDT — 0 finding(s).

@BenTaylorDev
BenTaylorDev marked this pull request as ready for review August 21, 2026 13:10
@BenTaylorDev
BenTaylorDev merged commit 1b3bf74 into main Aug 21, 2026
44 checks passed
@BenTaylorDev
BenTaylorDev deleted the ben1/v2-single-route-showcase branch August 21, 2026 13:28
BenTaylorDev added a commit that referenced this pull request Aug 21, 2026
The A2UI setup page imported `ExperimentalEmptyAdapter` and
`copilotRuntimeNextJSAppRouterEndpoint` and then used neither, so the block
was a truncated route a reader could not run. Show a complete route — and
show the current API while doing it: #6618 retired the v1 runtime adapter
across every showcase integration, so the page now uses
`createCopilotRuntimeHandler` from `@copilotkit/runtime/v2` in the
single-route form, matching `mastra/src/app/api/copilotkit-a2ui-fixed-schema/route.ts`
and the reference in /runtime-server-adapter.

That also settles the entrypoint question OSS-901 raised. The complaint was
that the page mixes v1 `@copilotkit/runtime` with `@copilotkit/react-core/v2`
below — not a broken pairing (v1's `CopilotRuntime` forwards `a2ui` straight
to the v2 runtime), but the v1 root import was the stale half, so both halves
of the page are now v2 entry points. The legacy form is noted as still
working for readers who are on it.

On the fixed-schema page, note that the LLM-driven integrations have no
`a2ui.render(...)` equivalent, so the operation builder in the snippet is
part of what a reader copies — and that the operations are nested, since a
flat `{ type: "create_surface" }` is silently ignored.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
BenTaylorDev added a commit that referenced this pull request Aug 21, 2026
…arts

Two things this PR was missing, both now closed.

## The Claude SDK quickstarts are unblocked

#6618 put `showcase/integrations/claude-sdk-{python,typescript}` on
`createCopilotRuntimeHandler` with `mode: "single-route"`, at the **plain**
`route.ts` path. That dissolves the coupling that forced these two pages to be
reverted earlier: `verify-shell-docs.ts` asserts each page claims a starter file
at `src/app/api/copilotkit/route.ts` AND that the file exists in the extracted
starter. Single-route keeps that path, so the prose claims and
`requiredStarterFiles` are unchanged — only the fence bodies move to v2.

The two content assertions that pinned those pages to v1
(`ExperimentalEmptyAdapter`, `copilotRuntimeNextJSAppRouterEndpoint`) now
require `createCopilotRuntimeHandler`, the `/v2` entrypoint,
`mode: "single-route"` and a `POST` export. Mutation-checked: flipping the
fixture to `mode: "multi-route"` fails with
`app/api/copilotkit/route.ts missing single-route mode`.

## Snippet gating: 1 -> 20 route fences

I previously claimed the integration pages could not be doctested because of
path aliases and per-integration deps. **That was an assumption I never
checked, and it was wrong.** Of the 52 migrated route fences, 47 import nothing
project-relative; 36 are complete, self-standing routes. 27 pages were
eligible, 20 now hold a gated fence — each extracted and typechecked by
`tsc --noEmit` against real npm-installed packages in CI.

One fence per (page, title): `extract.ts` concatenates tagged blocks sharing a
title, so a second complete route on the same page would collide.

Mutation-checked on `snippets/integrations/langsmith/index.mdx`: restoring the
v1 import in the gated fence turns the run red (20 passed, 1 failed). My first
attempt at this check was a no-op — the pattern missed because the fence is
JSX-indented — and it "passed" misleadingly. The real check asserts the mutation
reached the extracted snippet before trusting the result.

### Harness changes this needed

- `extract.ts` now finds the nearest `doctest.json` by walking up to the docs
  root, instead of looking only in the page's own directory. Otherwise gating
  20 pages means ~20 duplicated dependency lists that then drift. A shared list
  lives at `content/doctest.json`; `docs/integrations/langgraph/` keeps its own
  (Python deps) and now also carries the TS deps its page needs.
- `run.ts` installs each dependency set **once**, into
  `.doctest-output/.deps/<hash>`, and links it into every snippet sharing that
  set. Per-snippet installs took **7:58** for 21 snippets, uncomfortably close
  to the job's 15-minute timeout; shared installs take **0:45** cold. Different
  dep sets still get separate stores, so this is a dedupe, not a merge.

### `@ag-ui/*` versions have to be pinned to what the runtime expects

Unpinned, the gated fences failed with `HttpAgent is not assignable to
AbstractAgent — separate declarations of a private property '_debug'`: npm
installs a newer `@ag-ui/client` than `@copilotkit/runtime` depends on, so two
`AbstractAgent` declarations collide. The sidecar pins `@ag-ui/[email protected]` and
`@ag-ui/[email protected]` to match `@copilotkit/[email protected]`.

## Seven fences are deliberately NOT gated

Un-tagged with the reason, rather than left failing or quietly dropped:

- `docs/auth.mdx`, `docs/premium/connect-your-runtime.mdx` — illustrative
  fences referencing placeholders (`myAgent`, `verifyJwt`) that cannot compile
  standalone by design.
- the four langgraph-family pages and
  `snippets/self-hosting-copilot-runtime-langgraph-endpoint.mdx` — these hit
  `LangGraphAgent is not assignable to AbstractAgent — separate declarations of
  a private property '_debug'`, which pinning does not fix.

**That last one is a real pre-existing defect, not a migration regression.** I
reconstructed the v1 form of the langgraph quickstart snippet verbatim from
`origin/main` and typechecked it against the identical installed dependencies:
it fails with the same error. So these snippets have never typechecked against
published packages — worth filing separately. It is also what the ~220
`@ts-ignore` comments across `showcase/integrations` were papering over.

## Verified

    doc-tests (cold, no cache)          -> 21 passed, 0 failed in 0:45
    mutation check (real, verified)     -> 20 passed, 1 failed
    vitest extract + verify-shell-docs  -> 34 passed
    showcase/shell-docs typecheck       -> exit 0
    showcase/shell-docs build           -> exit 0
    structural audit                    -> 21/21 pages, fence + JSX identical to HEAD

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
MikeRyanDev added a commit that referenced this pull request Aug 21, 2026
…6645)

Closes OSS-901.

## Problem

`/mastra/generative-ui/a2ui/fixed-schema` could not be followed. A
Mastra onboarding run on Codex stopped there rather than invent an API,
reporting that the guide "depends on unbundled showcase helpers."

That is true, and the mechanism is worse than the report. Region bodies
are assembled at bundle time, so what ships is invisible in a source
diff. The `backend-render-operations` marker sits on **line 1** of
`mastra/src/mastra/tools/index.ts` — put there by the marker-hoist sweep
in 34b6418 so snippets would carry their imports — and the closing
marker is at the bottom of the file. The page therefore published **all
432 lines** of the tools barrel: weather, stock price, dice, d20,
query-data, schedule-meeting, search-flights, the aimock
header-forwarding import, and

```ts
import { generateA2uiImpl, buildA2uiOperationsFromToolCall } from "@copilotkit/showcase-shared-tools";
```

`@copilotkit/showcase-shared-tools` is not a package. It is a tsconfig
`paths` entry (`mastra/tsconfig.json:23`) pointing at `./shared-tools`,
a symlink to `showcase/shared/typescript/tools`. There is nothing for a
reader to install.

Same defect on the strands page from the same sweep: 586 lines of a
1688-line `agents/agent.py`.

## What changed

**The two cells get a dedicated module for the A2UI tool**, so hoisting
the marker to the top of the file yields exactly the tool plus its own
imports. This is the shape of the reference cell
(`langgraph-typescript/src/agent/a2ui-fixed.ts`, which likewise builds
A2UI operations locally) and, on the Python side, of `gen_ui_agent.py` /
`a2ui_dynamic.py`.

| page | before | after |
| --- | --- | --- |
| mastra fixed-schema | 432 lines, 16.5 KB | 166 lines |
| strands fixed-schema | 586 lines | 171 lines |

Every line in the new snippets either installs from npm or is a visibly
local `./` / `@/` module carrying a comment about what a real app uses
instead. Mastra keeps a single operation builder — the beautiful-chat
flight tool now calls the same one. The strands cell also highlights
`tools/generate_a2ui.py` so the guide shows the helper the tool calls.

**A guard in the bundler**, because neither failure mode shows up in
review:

- any `@copilotkit/showcase-*` specifier in a published body fails the
build (corpus is at zero after this change, so no baseline);
- over 200 lines fails the build (median region is 28, p90 is 125; the
48 already over the line are baselined by `slug::region::file` and the
list only shrinks).

**The entrypoint half of the issue lands differently than I first read
it.** OSS-901 flagged `@copilotkit/runtime` +
`@copilotkit/react-core/v2` on the shared A2UI page as a v1/v2 trap. It
is not a broken pairing — v1's `CopilotRuntime` forwards `a2ui` (and
`mcpApps` / `openGenerativeUI`) straight to the v2 runtime
(`packages/runtime/src/lib/runtime/copilot-runtime.ts:414`). But #6618
landed while this branch was open and retired the v1 runtime adapter
across every showcase integration, so the page's v1 root import *was*
the stale half. The block also imported `ExperimentalEmptyAdapter` and
`copilotRuntimeNextJSAppRouterEndpoint` and used neither, so it was a
route a reader could not run. It now shows `createCopilotRuntimeHandler`
from `@copilotkit/runtime/v2` in the single-route form, matching the
rebased showcase route and `/runtime-server-adapter`, with a note that
the legacy form still works.

**On the systemic question.** A separate sweep counted ~50 regions whose
marker sits on line 1 with a matching close at end-of-file, and proposed
failing a region that spans >=90% of its file. That rule does not
survive contact with the published bodies: of 141 regions at >=90% span,
only **2** publish more than 200 lines, and 98 publish under 100 —
dedicated single-purpose files whose whole content *is* the intended
snippet. It would also flag this PR's own fix
(`strands/a2ui_generate.py` is 171/188 = 91%) and the langgraph
reference cells. Published size is the signal that separates the defect
from the pattern, which is what the guard here measures.

## Testing

**Guard catches the pre-fix tree** (restored HEAD sources, moved the new
modules aside, ran the bundler):

```
REAL EXIT=1
Region bodies importing repo-only modules:
  mastra::agentic-chat: region "weather-tool-backend" (src/mastra/tools/index.ts) imports "@copilotkit/showcase-shared-tools", ...
  mastra::agentic-chat: region "backend-render-operations" (src/mastra/tools/index.ts) imports "@copilotkit/showcase-shared-tools", ...
Region bodies over the published-snippet limit:
  strands::a2ui-fixed-schema: region "backend-render-operations" (src/agents/agent.py) publishes 586 lines (limit 200) ...
```

and passes on this branch (`bundler exit=0`, 801 demos bundled).

**Guard unit tests** —
`showcase/scripts/lib/__tests__/demo-region-guard.test.ts`, 10 passed.
Mutation-checked: raising `MAX_REGION_LINES` and short-circuiting the
alias scan fails exactly 2 of them; restoring passes 10/10.

**Showcase script suites** — `demo-region-guard`, `bundle-demo-content`,
`validate-parity`, `verify-shell-docs`, `validate-shared-symlinks`:
**151 passed (5 files)**.

**Mastra vitest** — `tests/vitest/a2ui-context.test.ts`, 5 passed. The
prompt builder lives in the dependency-free `a2ui-context.ts` so this
regression test still runs without the Mastra SDK installed, as it did
before. Mutation-checked: breaking the join fails 1 of 5.

**Strands pytest** — `tests/python/test_generate_a2ui_errors.py` 11
passed (was 1 failed / 10 passed after the move, because the happy-path
test patched `agents.agent.build_a2ui_operations_from_tool_call`;
retargeted at the new module). Whole runnable suite: **40 passed**
across `test_generate_a2ui_errors`, `test_hook_injection`,
`test_sales_state_from_args`, `test_tool_call_cap`. Mutation-checked:
stubbing out the builder call fails the happy-path test.
`test_cvdiag_boundaries` / `test_instrumentor_patch` need `starlette` /
`opentelemetry-instrumentation-threading`, absent from this venv —
unrelated to this change.

**Published snippet, rendered** (`demo-content.json` after bundling):

```
mastra snippet lines: 166 | file: src/mastra/tools/a2ui-generate.ts
import { createTool } from "@mastra/core/tools";
import { z } from "zod";
import { generateText, tool as aiTool } from "ai";
// In your own app this is `import { openai } from "@ai-sdk/openai"`. ...
```

**Docs verification** — `verify-shell-docs.ts` produces a byte-identical
finding set with my two MDX edits toggled on and off (empty diff), so
the edits add no new findings. `component-imports`, `essential-content`
and the rest are unchanged; the suite's pre-existing failures are
untouched.

**Lint / format** — `oxfmt` on all changed TS, `oxlint` clean on the new
and edited files.

## Follow-ups (not in this PR)

- The 48 baselined regions are the same class of defect on other pages —
`strands::supervisor-delegation-tools` publishes 795 lines,
`strands::subagent-setup` 625, `ms-agent-dotnet::weather-tool-backend`
549. Each wants the same split.
- `claude-sdk-typescript/shared-tools/` and
`langgraph-typescript/shared-tools/` are real directories where symlinks
belong — the erosion `showcase/AGENTS.md` documents. Untouched here.
- Dropping the strands commit (`14c7351`) is safe on its own; it only
requires adding
`strands::backend-render-operations::src/agents/agent.py` to the guard
baseline.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
MikeRyanDev added a commit that referenced this pull request Aug 21, 2026
Moves docs and examples off the deprecated v1 runtime entrypoint, so a
reader who follows a quickstart ends up with a runtime that can actually
be probed (`GET /api/copilotkit/info`).

**Stage 0** proves the target shape in a real running app; **Stage 1**
propagates that proven code into the docs. 50 files. No file owned by
#6517 or #6582 is touched (verified against the full ownership list).
Stacks cleanly with #6618, which does the same for
`showcase/integrations/**`.

## Stage 0 — `examples/shadcn`, proven live

A textbook instance of the reported bug: a v1, POST-only route behind a
`@copilotkit/react-core/v2` frontend.

| | Before | After |
| --- | --- | --- |
| `GET /api/copilotkit` | **405** Method Not Allowed | 404 (correct:
multi-route serves nothing at the bare basePath) |
| `GET /api/copilotkit/info` | **404** — Next.js HTML 404, the path did
not route at all | **200** |
| `POST /api/copilotkit/agent/default/run` | n/a | **200**, chat turn
renders in the UI |

Exact `GET /api/copilotkit/info` body from the running app:

```json
{
  "version": "1.61.2",
  "agents": {
    "default": {
      "name": "default",
      "description": "",
      "className": "BuiltInAgent",
      "capabilities": {
        "tools": { "supported": true, "clientProvided": true },
        "transport": { "streaming": true },
        "humanInTheLoop": { "interrupts": true }
      }
    }
  },
  "audioFileTranscriptionEnabled": false,
  "mode": "sse",
  "threadEndpoints": { "list": true, "inspect": true, "mutations": false, "realtimeMetadata": false },
  "a2uiEnabled": false,
  "openGenerativeUIEnabled": false,
  "telemetryDisabled": false
}
```

(Captured before the `@copilotkit/*` bump in the same commit, hence
`1.61.2`.) The model backend was aimock — `@copilotkit/aimock` 1.37.4,
the same mock the `test / integration / docs` CI job uses — so the chat
turn is real traffic through the migrated route with no live API key.

## Three findings that changed the shape of this work

All three came from running the code rather than reading it, and all
three affect every page Stage 1 touches.

### 1. The plan's canonical shape was deprecated, and that is where
`hono` came from

The prescribed snippet was `createCopilotEndpoint` + `handle` from
`hono/vercel`. `createCopilotEndpoint` is a **deprecated alias** — this
repo's own handler table in `docs/backend/runtime-endpoints.mdx` lists
it under "Deprecated → use `createCopilotHonoHandler`".

`createCopilotRuntimeHandler` serves the same multi-route mode (it is
the default), returns a plain fetch handler, is not deprecated, and
needs **no `hono` at all**:

```ts
const handler = createCopilotRuntimeHandler({
  runtime,
  basePath: "/api/copilotkit",
});

export const GET = handler;
export const POST = handler;
```

I first propagated the deprecated shape and then documented installing
`hono` to make `hono/vercel` resolve under pnpm. Both are reverted in
`720910833e`: `hono` was an artifact of the shape, not a requirement of
the library. Verified by **deleting `node_modules/hono` outright**, not
merely removing it from `package.json`, so a hoisted copy could not mask
the result — `GET /info` → 200, `POST /agent/default/run` → 200, turn
renders. No sidecar lists `hono` any more, so CI proves by construction
that these snippets do not need it.

### 2. The multi-route runtime needs a frontend co-change, and the docs
said otherwise

Published `<CopilotKit>` still ships

```js
useSingleEndpoint={props.useSingleEndpoint ?? true}
```

(verified in the `@copilotkit/react-core` 1.68.3 bundle), pinning the
single-route transport. A multi-route runtime answers that envelope with
**404 while `GET /info` still returns 200**, so the app looks connected.
The runtime diagnoses it itself:

> Received a single-route request envelope (`{ method: "..." }`) but
this runtime is mounted in multi-route mode, so the request matched no
route. If the frontend uses `<CopilotKit>` from
`@copilotkit/react-core/v2`, pass `useSingleEndpoint={false}` — that
provider defaults it to true.

`backend/runtime-endpoints.mdx` — the authoritative page — said the
opposite: that omitting the prop is safe on either provider because the
client negotiates. True on `main` (#6605 removed the pin, merged today,
unreleased) and **false in every published release**. `auth.mdx`,
`custom-agent.mdx` and two quickstart callouts repeated it. All
corrected: the pairing table now splits `<CopilotKit>` from
`<CopilotKitProvider>` and says passing `{false}` is the
forward-compatible choice — required now, harmless later. **This is a
live docs defect independent of the migration.**

So the v2 multi-route shape is *not* a drop-in for a v1 route: changing
only the route file converts a working POST-only app into a broken one.

### 3. `showcase/shell`'s `@ts-ignore` is stale

Its canonical route carries `// @ts-ignore — BuiltInAgent type mismatch
with AbstractAgent, pending upstream fix`. `tsc --noEmit` passes without
it on 1.68.3, so the docs snippets carry no suppression.

Angular needs none of this: `provideCopilotKit` defaults its transport
to `"auto"`. Those snippets are unchanged.

## The docs snippets now have a real CI gate

The plan assumed there is no automated gate on `.mdx` snippets. There
are two, and both mattered:

- **`showcase/scripts/verify-shell-docs.ts`** asserts the *content* of
titled fences, and for the two Claude SDK quickstarts it **requires**
`ExperimentalEmptyAdapter` and `copilotRuntimeNextJSAppRouterEndpoint` —
actively pinning those pages to v1.
- **`scripts/doc-tests/{extract,run}.ts`** runs in CI (`test /
integration / docs`): a fence tagged `doctest="component"` is extracted
and typechecked with `tsc --noEmit` against real npm-installed deps.
Exactly **one** fence in the whole docs tree opted in.

**20 route snippets across 20 pages are now tagged
`doctest="component"`** and typechecked in CI against real npm-installed
packages. I had claimed the integration pages couldn't be doctested
(path aliases, per-integration deps) — that was an assumption I never
checked and it was wrong: 47 of 52 fences import nothing
project-relative. Five harness defects blocked this and are fixed:

- `extract.ts` wrote a fence title as a path without creating
intermediate directories → ENOENT on any titled route fence.
- `run.ts` derived the npm package name from the snippet directory; a
catch-all leaf directory is literally `[[...slug]]`, which npm rejects.
- `run.ts` looked for `doctest.json` only in the snippet's own directory
while the sidecar is copied per page, so a nested snippet silently
installed nothing and failed with "Cannot find module".
- `extract.ts` found sidecars only in a page's own directory, which
would have meant ~20 duplicated dependency lists; it now walks up to the
docs root, so one shared list lives at `content/doctest.json`.
- `run.ts` installed dependencies per snippet — **7:58** for 21 snippets
against a 15-minute job timeout. Each dep set now installs **once** into
`.doctest-output/.deps/<hash>` and is linked in: **0:45** cold.

**Mutation-checked:** restoring the v1 import in a gated fence turns the
run red (20 passed, 1 failed). My first attempt at this check was a
silent no-op — the pattern missed because the fence is JSX-indented, and
it "passed" misleadingly. The real check asserts the mutation reached
the extracted snippet before trusting the result.

`@ag-ui/*` has to be pinned to what the runtime expects
(`@ag-ui/[email protected]`, `@ag-ui/[email protected]` for runtime 1.68.3).
Unpinned, npm installs a newer `@ag-ui/client` and two `AbstractAgent`
declarations collide: `separate declarations of a private property
'_debug'`.

**Seven fences are deliberately not gated**, un-tagged with reasons
rather than left red: two are illustrative fences with placeholder
identifiers (`myAgent`, `verifyJwt`), and five langgraph-family fences
hit that same `_debug` collision via `@copilotkit/runtime/langgraph`,
which pinning does not fix. **That one is a pre-existing package defect,
not a migration regression** — I reconstructed the v1 form of the
langgraph quickstart snippet verbatim from `origin/main`, typechecked it
against identical deps, and it fails the same way. Those snippets have
never typechecked against published packages. Worth filing; it is also
what the ~220 `@ts-ignore` comments in `showcase/integrations` were
papering over.

## A mistake worth recording

A block regex scoped to the fence's opening indentation corrupted five
quickstart pages: their fences open and close at *different*
indentation, so the match ran past the closing backticks and re-indented
the following `</Step>` / `</Tab>` into the code block. Reverted and
redone with a line-oriented pass that never re-indents and re-emits the
closing line verbatim. (A malformed `runner:` insertion on three a2ui
pages was caught and redone the same way.)

Every modified page is now checked structurally — fence-marker count
plus every JSX structural line, indentation included, must be
byte-identical to `HEAD`. That check found the corruption; a diff review
had already missed it.

## Verification

```
pnpm tsx scripts/doc-tests/extract.ts       -> 21 snippets
pnpm tsx scripts/doc-tests/run.ts           -> 21 passed, 0 failed (0:45 cold)
vitest extract + verify-shell-docs          -> 34 passed
showcase/shell-docs: pnpm typecheck         -> exit 0
showcase/shell-docs: pnpm lint              -> exit 0 (pre-existing warnings only)
showcase/shell-docs: pnpm build             -> exit 0
examples/shadcn: tsc --noEmit / eslint / next build -> all clean, route ƒ /api/copilotkit/[[...slug]]
structural audit                            -> every modified page, fence + JSX identical to HEAD
```

CI was green on the previous head (35 pass / 3 skip), including
`doc-tests` and `format`.

This validates that the pages build and that the one doctested snippet
compiles. **It does not execute the remaining 32 fences.** Their
correctness rests on Stage 0: the boilerplate they now contain is the
text that was run in `examples/shadcn`, and each page's agent wiring is
untouched.

`LangGraphAgent` + v2 `CopilotRuntime` + `createCopilotRuntimeHandler`
were typechecked together against published 1.68.3, since many pages
depend on that combination.

## What could not be migrated, and why

| Page | Why |
| --- | --- |
| `agentic-protocols/mcp.mdx` (self-hosting section) | Built on
`createMCPClient`, which exists only in v1
(`packages/runtime/src/lib/runtime/copilot-runtime.ts`). v2's equivalent
is `mcpApps`; converting is a content rewrite, not a mechanical
migration. |
| `snippets/self-hosting-copilot-runtime-create-endpoint.mdx` | The
whole page is templated on v1 service adapters (`{{adapterImport}}`,
`{{adapterSetup}}`). v2 has no service adapters. Needs a rewrite of the
page's premise. |
| Pages Router / NestJS tabs in the `self-hosting-*` snippets | v2
exports no equivalent factory — only `createCopilotRuntimeHandler` and
the Hono/Express/Node handlers. The App Router tab on each page **is**
migrated. |
| Node HTTP / Express tabs | v2 equivalents exist
(`createCopilotNodeHandler`, `createCopilotExpressHandler`) but I have
not run them, and the rule here was not to write a snippet I have not
run. |
| `custom-agent.mdx` (both copies) | Three fences each still call
`createCopilotEndpoint` as `export default copilotEndpoint` — the
Hono-app deployment pattern, not a Next.js route. Predates this PR; the
documented replacement is `createCopilotHonoHandler`, which I have not
run. The two copies have also drifted from each other. |

Deliberate v1 *prose* is left alone: `backend/copilot-runtime.mdx`'s
v1→v2 mapping table and `auth.mdx`'s note that the v1 adapter does not
forward `hooks` are correct as written.

## Other out-of-scope gaps, recorded so they can be filed

- **Mastra docs name `CopilotKitIntelligence`** but never document
constructor, project, thread, or user wiring.
- **The A2UI fixed-schema guide** depends on showcase helpers not
published as a package, so it cannot be followed standalone.
- **`showcase/shared/starter-template` is not a runnable app** — no
`package.json`, `next.config`, or `tsconfig`, so its route cannot be
proved by running it. It was the plan's Stage 0 target on the grounds
that "the CLI scaffolds from it"; nothing in CopilotKit `packages/**` or
`Intelligence/apps/cli/src` references it, so that rationale does not
hold. Its route is still v1 and still exports a hand-rolled `GET` that
fetches the *agent's* `/health` and shadows `/info`. Queued behind a
decision on where that status payload should live.
- **`@copilotkit/cli@latest` (0.0.6) has no `verify` command**, so the
`runtime_reachable: pass` evidence the plan asked for cannot be produced
with the public CLI. The Intelligence CLI's `verify` is the one that
probes `<runtimeUrl>/info` (`apps/cli/src/services/verify-probes.ts`),
and the Stage 0 app satisfies that probe with a 200 — but the public-CLI
artifact does not exist to paste.
- **Two generators still emit v1** and will re-seed the problem:
`showcase/scripts/create-integration/index.ts` and
`examples/showcases/chatkit-studio/apps/playground/src/utils/codeGenerator.ts`.

## Corrected counts

The plan's figures were all low, partly because they matched only
double-quoted imports. Measured on `origin/main` at `43f1ef3039`:

| Surface | Plan said | Actual |
| --- | --- | --- |
| v1 code files (`examples/` + `showcase/`, excl. `examples/v1/**` and
`_legacy/`) | 244 | **352** |
| `showcase/**` importing `@copilotkit/runtime` | 229 | **289** |
| Docs files touching the v1 entrypoint | 44 (37 in scope) | **22 (12 in
scope)** — the plan counted only `from "@copilotkit/runtime"`; the real
set is smaller but includes single-quoted and factory-only files it
missed |
| Mixed v1-runtime + v2-frontend pages | 20 | **26** |
| Files already on `createCopilotEndpoint` | 10 | **43 call sites** |

## Remaining

- **Docs:** 52 route fences across 40 pages are on the v2 shape, **20 of
them gated in CI**. The two Claude SDK quickstarts are migrated now that
#6618 has landed. 7 pages still reference v1, every one for a reason in
the tables above (several are deliberate prose).
- **Code:** `showcase/integrations/**` (239 files) is handled in
**#6618**. `examples/v1/**` (12 files) is deliberately v1 and never in
scope. The rest of `examples/` is not in either PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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