Skip to content

fix(showcase): make the A2UI fixed-schema guide followable (OSS-901) - #6645

Merged
MikeRyanDev merged 5 commits into
mainfrom
ben1/oss-901-a2ui-fixed-schema-followable
Aug 21, 2026
Merged

MikeRyanDev merged 5 commits into
mainfrom
ben1/oss-901-a2ui-fixed-schema-followable

Conversation

@BenTaylorDev

@BenTaylorDev BenTaylorDev commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

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

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

@linear-code

linear-code Bot commented Aug 21, 2026

Copy link
Copy Markdown

OSS-901

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Production Digest-Pinning Audit

All 42 services digest-pinned.

Run 2026-08-21 06:51:42 PDT — 0 finding(s).

@BenTaylorDev
BenTaylorDev marked this pull request as ready for review August 21, 2026 13:40
BenTaylorDev and others added 4 commits August 21, 2026 08:42
`/mastra/generative-ui/a2ui/fixed-schema` published the entire 432-line
tools barrel, because the `backend-render-operations` marker sits at the
top of the file (the marker-hoist sweep in 34b6418 put it there so the
snippet would carry its imports). The published body therefore included
every unrelated tool plus
`import { ... } from "@copilotkit/showcase-shared-tools"` — a tsconfig
path alias to a symlink in this repo, not a package a reader can install.
A Mastra onboarding run stopped there rather than invent an API (OSS-901).

Move `generateA2uiTool` into its own module and mark the region there, so
hoisting to the top of the file yields exactly the tool plus its own
imports — the same shape as the reference cell,
`langgraph-typescript/src/agent/a2ui-fixed.ts`, which likewise builds the
A2UI operations locally instead of importing the showcase's shared tools.
The published snippet goes from 432 lines to 166, and everything in it
either installs from npm or is a visibly local `./` / `@/` module with a
comment saying what a real app would use instead.

`buildA2uiOperations` and `systemPromptFrom` replace the two shared-tools
helpers so mastra keeps a single operation builder: the beautiful-chat
flight tool now calls the same one. The prompt builder lands in the
dependency-free `a2ui-context.ts` so its regression test keeps running
without the Mastra SDK installed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Same defect as the mastra cell, same page: the `backend-render-operations`
marker is hoisted to the top of `agents/agent.py`, so
`/aws-strands/generative-ui/a2ui/fixed-schema` published 586 lines of a
1688-line module — the messages-snapshot wrapper, the weather/dice/query
tools, everything — instead of the A2UI tool the step is about.

Move `generate_a2ui` and its `_A2uiError` shape into
`agents/a2ui_generate.py`, which is what `gen_ui_agent.py` /
`a2ui_dynamic.py` already do for their own surfaces ("this module lives in
its own file so the surface area is reviewable in isolation"). `agent.py`
imports the tool back for the shared agent's tool list, so the wiring and
the tool id are unchanged; the published snippet is now 171 lines with its
own imports. `tools/generate_a2ui.py` joins the cell's highlighted files so
the guide also shows the helper the tool calls.

The error-handling suite patched `agents.agent.build_a2ui_operations_from_tool_call`,
which now lives on the new module — retargeted, and it still imports the
tool via `agents.agent` so the re-export stays covered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Region bodies are assembled at bundle time, so neither failure mode in the
two preceding commits is visible in review — the source diff looks fine
while the docs page renders a 400-line slab or an uninstallable import.
Two checks over every region the bundler is about to publish:

- Any `@copilotkit/showcase-*` specifier fails the build. These resolve
  only through a tsconfig path alias to a symlink in this repo, so they
  cannot appear in a snippet a reader is meant to copy. The corpus is at
  zero once OSS-901 is fixed, so there is no baseline.
- Over 200 lines fails the build. The median region is 28 lines and p90 is
  125, so 200 catches a marker sitting above unrelated code without
  arguing about genuinely long single-purpose files (the 344-line
  declarative-gen-ui renderers.tsx is the point of that page). The 48
  regions already over the line are baselined by
  `slug::region::file` and the list only shrinks.

Both are reported together for the whole run, so one build lists every
unfollowable snippet instead of only the first.

Verified against the pre-fix tree: the guard exits 1 and names both the
mastra `@copilotkit/showcase-shared-tools` bodies and the 586-line strands
region.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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
BenTaylorDev force-pushed the ben1/oss-901-a2ui-fixed-schema-followable branch from 13bed7d to a43bd7c Compare August 21, 2026 13:50
Reapplies the formatter fix the CI auto-format job pushed (13bed7d),
which a rebase force-push dropped.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@MikeRyanDev
MikeRyanDev merged commit 36d9f16 into main Aug 21, 2026
31 checks passed
@MikeRyanDev
MikeRyanDev deleted the ben1/oss-901-a2ui-fixed-schema-followable branch August 21, 2026 17:44
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