bug: AG-UI delta patches fail with "a.applyPatch is not a function" (@ag-ui/client 0.0.52)
Summary
With @ag-ui/[email protected], every AG-UI delta patch the Next.js runtime tries to apply fails with:
Failed to apply activity patch for 'call_…-activity': a.applyPatch is not a function
It is logged once per ACTIVITY_DELTA event, so a single interactive answer produced several hundred identical warnings in my run.
PR #99 mentions the same message as a side observation and offers to open an issue; I could not find one, so this tracks it.
Reproduction
Node's ESM loader cannot see applyPatch in [email protected] (CommonJS), which @ag-ui/[email protected]'s .mjs build namespace-imports:
cd node_modules/.pnpm/@[email protected]/node_modules/@ag-ui/client
node --input-type=module -e "
import * as a from 'fast-json-patch';
console.log(typeof a.applyPatch, typeof a.default?.applyPatch);"
# -> undefined function
The shipped code is import*as a from"fast-json-patch" followed by a.applyPatch(...). @copilotkit/runtime is listed in serverExternalPackages, so it runs under native Node ESM and hits this.
Impact (what I did and did not observe)
- The error is caught and logged; chat answers and generated widgets still rendered in my end-to-end run, so I have not observed user-visible breakage.
- The server-side copy of messages/state does not receive the patches, and the log is flooded, which makes real problems harder to spot.
Fix
@ag-ui/[email protected] is the first release that uses a default import (import a from "fast-json-patch"). @copilotkit/[email protected] pins @ag-ui/client to exactly 0.0.52, so a pnpm override aligns @ag-ui/client, core, encoder and proto on 0.0.53 (it also removes a duplicate 0.0.48 copy). PR to follow. The durable fix is for CopilotKit to bump its pin; I can open an issue there too.
Verification
After the override, a live chat (real OpenAI + OpenRouter calls) produced 0 applyPatch warnings in the Next.js log and 0 in the browser console. Before: several hundred. pnpm test, pnpm lint (no errors) and pnpm build pass; pnpm install --frozen-lockfile is clean.