docs/plans/2026-06-28-migrate-ai-sdk-v7.md
Objective: Migrate Plate AI SDK usage to v7; done when repo AI SDK packages, registry/template outputs, and affected builds/typechecks pass.
Flow mode: one-shot execution
Goal plan: docs/plans/2026-06-28-migrate-ai-sdk-v7.md
Template: docs/plans/templates/major-task.md
Primary template: docs/plans/templates/major-task.md
Applied packs:
Major source:
Major lane:
@platejs/ai dev type surface, public AI docs, and any package/example usage found by source audit.Timed checkpoint:
Completion threshold:
ai, @ai-sdk/*, and AI Gateway usage touched by Plate registry/template sources compiles against v7.node .agents/skills/autogoal/scripts/check-complete.mjs docs/plans/2026-06-28-migrate-ai-sdk-v7.md
passes.Verification surface:
rg for from 'ai', from "@ai-sdk, @ai-sdk/, AI SDK, streamText, useChat, and gateway.../ai clone plus Context7 official docs for AI SDK v7 migration, structured output, and AI Gateway.pnpm check if feasible.Constraints:
Boundaries:
../ai local clone, Context7 official AI SDK docs, and PR #5045 branch context.Output budget strategy:
rg --files-with-matches, focused globs, and capped sed ranges before printing matches. Exclude node_modules, .next, .turbo, generated registry JSON, and large lockfiles except targeted dependency slices.Blocked condition:
Major state:
Current verdict:
ai@7 with matching AI SDK provider/react major lines across the app, @platejs/ai dev surface, registry install metadata, and playground template.Completion rule:
update_goal(status: complete) while any required checklist item
remains unchecked. If an item does not apply, check it and add N/A: <reason>.update_goal(status: complete) until every completion threshold
above is satisfied, final evidence is recorded, and
node .agents/skills/autogoal/scripts/check-complete.mjs docs/plans/2026-06-28-migrate-ai-sdk-v7.md
passes.Start Gates:
| Gate | Applies | Evidence |
|---|---|---|
| Timed checkpoint parsed | N/A | No duration requested. |
major-task loaded | yes | Read .agents/skills/major-task/SKILL.md. |
| Active goal checked or created | yes | get_goal returned none; create_goal created active AI SDK v7 migration goal. |
| Source of truth read before analysis | yes | User prompt read; repo instructions supplied in chat; Context7 docs and local SDK clone selected for version-sensitive API source. |
| Major lane selected | yes | Lane: framework/library migration. |
| Decision criteria stated | yes | Criteria recorded in Major source. |
| Existing repo patterns / prior decisions checked | yes | Audited apps/www, packages/ai, templates/plate-playground-template, registry metadata, and AI docs before editing. |
| Helper stack selected | yes | autogoal, major-task, task, changeset, registry-changelog, docs-creator, Context7. Autoreview waived by prior user instruction in this thread. |
| External research decision recorded | yes | Use local ../ai clone plus official Context7 docs because AI SDK v7 API is version-sensitive. |
| Implementation expectation recorded | yes | Code-changing execution expected. |
| Workspace authority selected | yes | /Users/zbeyens/git/plate; local SDK source in /Users/zbeyens/git/ai only for external API evidence. |
| Branch / PR expectation decided | yes | Continue codex/fix-pr-5045-template-sync; push to open PR #5045 head templates/release-sync-failure if verified. |
| Output budget strategy recorded | yes | Focused searches and capped reads recorded above. |
| Package/API pack selected | yes | Dependency/API migration touches public install/template surfaces. |
| Public surface or package boundary identified | yes | Registry install metadata, templates, public AI docs, and @platejs/ai dev type surface are affected. |
| Release artifact path selected | yes | Both .changeset/ai-sdk-v7-chat-types.md and a registry changelog entry are required. |
changeset skill loaded when .changeset is required | yes | Read .agents/skills/changeset/SKILL.md and .agents/rules/changeset.mdc; only create .changeset if packages changed with user-visible delta from main. |
| Barrel/export impact decision recorded | yes | N/A: no package exports, exported folder layout, or public barrel files changed. |
| Registry changelog pack selected | yes | Selected because registry dependency metadata may change copied install shape. |
| User-visible registry impact classified | yes | Copied AI registry items install AI SDK v7 and use Gateway through ai; user-visible registry delta. |
| Source entry path selected | yes | apps/www/src/registry/changelog/entries/2026-06-28-ai-sdk-v7.mdx. |
| Generator command selected | yes | node tooling/scripts/generate-ui-changelog-entries.mjs --write then --check with Corepack pnpm on PATH. |
| Docs pack selected | yes | Added because public AI docs reference AI SDK imports and install shape. |
docs-creator loaded | yes | Read .agents/skills/docs-creator/SKILL.md. |
| Docs lane selected | yes | Workflow / AI docs; supporting surface under major migration. |
| Target docs and nearest sibling docs read | yes | Read and edited ai.mdx, ai.cn.mdx, copilot.mdx, and copilot.cn.mdx. |
| Docs style doctrine read | yes | docs-creator read through verification checklist. |
| Documented source owner identified | yes | AI docs now mirror registry command/copilot route sources and playground template route usage. |
Work Checklist:
.changeset, registry changelog, or explicit no-artifact reason..changeset work loads changeset and follows its package/version/prose rules.registry-changelog pack instead of adding a package changeset.main. N/A: package and registry artifacts are required.apps/www/src/registry/changelog/entries/*.mdx or N/A reason is recorded..agents/skills/registry-changelog/SKILL.md./registry/changelog/*.json, index.json, and components.json are updated by the generator, not by hand.Completion Gates:
| Gate | Applies | Required action | Evidence |
|---|---|---|---|
| Named verification threshold | yes | Run the repo audit, artifact checks, and affected builds named in this plan | Passed affected install/typecheck/lint/build, registry generator, docs source build, source audit, and root pnpm check. |
| Current-state source audit | yes | Map current owner, boundaries, constraints, and affected surfaces | Audited AI SDK dependencies/imports in apps/www, packages/ai, templates/plate-playground-template, registry metadata, and AI docs. |
| Decision criteria closure | yes | Mark each criterion satisfied, narrowed, rejected, or blocked with evidence | Satisfied: dependency majors aligned, v7 APIs compile, template builds, docs source builds, registry metadata regenerated. |
| Options / tradeoffs / rejection record | yes | Record viable options, chosen recommendation, and why alternatives lose | Chose ai-owned Gateway imports and instructions/stateless stream helpers; rejected direct gateway dep and v6/v7 mixed runtime. |
| Review / pressure pass | N/A | Run selected reviewer/lens or record N/A with reason | Formal autoreview waived by prior user instruction: "cut the autoreview". Source audit and command proof replace it for this task. |
| Review findings closure | yes | Fix or explicitly reject accepted/actionable findings and record closure proof | Fixed install peer issue by keeping app on [email protected]; fixed changelog generator test count after root check failure. |
| External-source audit | yes | Cite official/local clone/external sources when used, or record N/A | Used Context7 official AI SDK v7 docs and local ../ai source for v7 stream/Gateway/react helper API evidence. |
| Implementation gates | yes | If code changed, close primary-template and touched-surface gates; otherwise N/A | Closed package/API, registry changelog, and docs gates. Browser gate recorded as tool-unavailable caveat. |
| Final handoff contract | yes | Record recommendation, evidence, caveats, residual risk, and next owner | Recorded below. |
| Final lint | yes | Run pnpm lint:fix or scoped equivalent when files changed | pnpm lint:fix passed. |
| Output budget discipline | yes | Verify no unbounded high-volume command output was streamed, or record the accidental output and recovery | One noisy generated-registry search was stopped and replaced with scoped rg excludes; later outputs were capped. |
| Timed checkpoint | N/A | If duration was requested, keep improving until elapsed, then finish the current loop cleanly; otherwise N/A | No timed checkpoint requested. |
| Goal plan complete | yes | Run node .agents/skills/autogoal/scripts/check-complete.mjs docs/plans/2026-06-28-migrate-ai-sdk-v7.md | Passed at 2026-06-28T11:54Z. |
| Public API / package boundary proof | yes | Source-audit public API, exports, and package boundary impact | @platejs/ai dev helper types compile against @ai-sdk/react@4; no public barrel/export layout changed. |
| Release artifact classification | yes | Record whether the change is published package behavior/API/types/config/runtime, registry-only, or no published user-visible delta | Both package type-surface and registry/template install shape changed. |
| Published package changeset | yes | If published package users see a delta, load changeset, add/update one .changeset/*.md per package, and prove no forbidden minor on @platejs/slate, @platejs/core, or platejs | Added .changeset/ai-sdk-v7-chat-types.md with patch bump for @platejs/ai; no forbidden packages touched. |
| Registry changelog | yes | If the change is registry-only under apps/www/src/registry/**, use the registry-changelog pack and do not add a package changeset | Added registry changelog entry because registry items changed; package changeset remains separate for @platejs/ai. |
| No release artifact | N/A | If no artifact is needed, record the exact reason: internal-only, docs-only, agent-only, test-only, or no user-visible delta from main | Release artifacts are required and present. |
| Package typecheck/build/test | yes | Run owning package checks or record N/A with reason | pnpm --filter www typecheck, pnpm --filter @platejs/ai typecheck, template bun run typecheck, template bun run build, and root pnpm check passed. |
| Barrel/export generation | N/A | Run pnpm brl when exports or exported file layout changed, otherwise N/A | No exports or exported file layout changed. |
| Registry impact classification | yes | Record user-visible registry delta or N/A reason | Registry AI items install and show AI SDK v7 runtime/provider metadata. |
| Registry changelog source | yes | Add/update apps/www/src/registry/changelog/entries/*.mdx or record N/A | Added apps/www/src/registry/changelog/entries/2026-06-28-ai-sdk-v7.mdx. |
| Registry changelog generation | yes | Run node tooling/scripts/generate-ui-changelog-entries.mjs --write when a source entry is required | Generator --write passed with Corepack pnpm on PATH. |
| Registry changelog check | yes | Run node tooling/scripts/generate-ui-changelog-entries.mjs --check | Generator --check passed. |
| Registry generator test | yes | If generator/schema/source layout changed, run bun test tooling/scripts/generate-ui-changelog-entries.test.mjs; otherwise N/A | Ran after expected count update; 16 tests passed. |
| Registry package release split | yes | Record .changeset, registry changelog, both, or N/A with reason | Both: .changeset for @platejs/ai type surface and registry changelog for registry/template install behavior. |
| Docs source-backed claim audit | yes | Verify docs claims against current source or record N/A | Docs imports/options/routes mirror v7 API and copied registry/template routes. |
| Docs links / routes / previews | yes | Verify leaf links, routes, anchors, and preview names or record N/A | No new external links or preview routes added; existing AI/copilot leaf pages build through source parser. |
| Docs MDX/content parser | yes | Run pnpm --filter www build:source for MDX/content changes, or record N/A | pnpm --filter www build:source passed. |
| Plugin page specifics | yes | For plugin pages, apply docs-creator kit/manual/API rules; otherwise N/A | AI plugin docs use current-state route/API snippets without migration voice. |
Phase / pass table:
| Phase | Status | Evidence | Next |
|---|---|---|---|
| Intake and source read | complete | created plan; loaded required skills; cloned ../ai; queried official docs | current-state map done |
| Current-state map | complete | dependency/import/docs/template audit found all owned AI SDK surfaces | options done |
| Options and recommendation | complete | chose full v7 alignment with ai-owned Gateway import and instructions API | implementation done |
| Review / pressure pass | complete | formal autoreview waived; source audit plus command proof used | verification done |
| Implementation or plan artifact | complete | package manifests, lockfiles, registry metadata, template routes, docs, changeset, and registry changelog updated | verification done |
| Verification | complete | affected checks plus root pnpm check passed | closeout done |
| Closeout | complete | this plan is ready for mechanical completion check, commit, push, and PR body update | final response next |
Findings:
npx @ai-sdk/codemod v7 as the v6 -> v7 migration entrypoint.streamText array output should use Output.array plus elementStream for complete validated array elements.ai directly or from @ai-sdk/gateway.[email protected], @ai-sdk/[email protected], @ai-sdk/[email protected], @ai-sdk/[email protected], @ai-sdk/[email protected].ai@6 / @ai-sdk/*@3 in apps/www, packages/ai devDeps, and templates/plate-playground-template.packages/ai, apps/www/src/registry/**, and templates/plate-playground-template/src/**.../ai/packages/ai/src/index.ts re-exports createGateway and gateway from ai, so copied route code can avoid a direct @ai-sdk/gateway import.Decisions and tradeoffs:
createGateway from ai for copied routes so ai owns the Gateway provider version line and the template does not need a separate direct @ai-sdk/gateway dependency.Implementation notes:
apps/www, packages/ai, and templates/plate-playground-template use ai@7 and matching @ai-sdk/*@4 package lines.createGateway from ai and stateless toUIMessageStream({ stream: result.stream, ... }).instructions; request handling still accepts the old system field as a fallback.Review fixes:
apps/www to [email protected] instead of forcing zod 4 into the app.tooling/scripts/generate-ui-changelog-entries.test.mjs expected current-entry count after adding the new registry changelog.Error attempts:
| Error / failed attempt | Count | Next different move | Resolution |
|---|---|---|---|
rg ... apps www packages templates content typo included generated public registry JSON and returned truncated noise | 1 | Use focused roots and explicit !apps/www/public/r/** / !apps/www/public/rd/** excludes | Recorded; subsequent searches are scoped. |
Verification evidence:
/Users/zbeyens/git/plate: pnpm install passed with Corepack pnpm after zod peer fix./Users/zbeyens/git/plate/templates/plate-playground-template: bun install --no-frozen-lockfile passed./Users/zbeyens/git/plate: pnpm --filter www typecheck passed./Users/zbeyens/git/plate: pnpm --filter @platejs/ai typecheck passed./Users/zbeyens/git/plate/templates/plate-playground-template: bun run lint, bun run typecheck, and bun run build passed./Users/zbeyens/git/plate: node tooling/scripts/generate-ui-changelog-entries.mjs --write and --check passed with Corepack pnpm on PATH./Users/zbeyens/git/plate: bun test tooling/scripts/generate-ui-changelog-entries.test.mjs passed./Users/zbeyens/git/plate: pnpm --filter www build:source passed for MDX/source generation./Users/zbeyens/git/plate: pnpm lint:fix passed./Users/zbeyens/git/plate: git diff --check passed./Users/zbeyens/git/plate: focused rg audit found no stale owned @ai-sdk/gateway, ai@6, @ai-sdk/react@3, provider v3, convertToCoreMessages, toDataStreamResponse, maxTokens, body.system, System Prompt, OPENAI_API_KEY, or old provider examples in touched app/template/docs/package surfaces./Users/zbeyens/git/plate: pnpm check passed after updating the registry changelog generator test. Existing lint warning remains in apps/www/src/components/ui/sidebar.tsx about toggleSidebar; unrelated to this diff./Users/zbeyens/git/plate: node .agents/skills/autogoal/scripts/check-complete.mjs docs/plans/2026-06-28-migrate-ai-sdk-v7.md passed.apps/www/packages changes, but tool discovery did not expose a usable Browser or browser-use tool in this session. The template Next build proved the affected API routes compile, and no interactive UI behavior was changed.Final handoff contract:
pnpm check passed.Timeline:
autogoal, major-task, task, changeset, and registry changelog instructions.../ai because repo policy requires local source before external docs are treated as enough.codex/fix-pr-5045-template-sync and open PR #5045 head templates/release-sync-failure.docs-creator and added docs-pack rows.pnpm check failure in the registry changelog generator test.www MDX generation passed.Reboot status:
| Question | Answer |
|---|---|
| Where am I? | Closeout after local verification. |
| Where am I going? | Mechanical autogoal check, then commit/push and PR #5045 body update. |
| What is the goal? | Migrate Plate AI SDK usage to v7 with registry/template/package proof. |
| What have I learned? | ai re-exports Gateway helpers in v7; copied route code can avoid direct @ai-sdk/gateway; docs and registry install metadata are part of the migration surface. |
| What have I done? | Migrated package lines, route APIs, docs, registry metadata/changelog, template source/lockfile, changeset, and tests; local checks passed. |
Open risks:
pnpm check and template build passed.system to instructions.