Skip to content

fix(app): align @ag-ui packages on 0.0.53 so delta patches apply - #150

Open
tbrandenburg wants to merge 1 commit into
CopilotKit:mainfrom
tbrandenburg:fix/146-ag-ui-client-patch
Open

tbrandenburg wants to merge 1 commit into
CopilotKit:mainfrom
tbrandenburg:fix/146-ag-ui-client-patch

Conversation

@tbrandenburg

Copy link
Copy Markdown

Summary

Aligns @ag-ui/client, core, encoder and proto on 0.0.53 via pnpm overrides so the Next.js runtime can apply AG-UI delta patches again.

Fixes #146

Root cause

@ag-ui/client@0.0.52 does import * as a from "fast-json-patch" and calls a.applyPatch(...). fast-json-patch@3.1.1 is CommonJS, and Node's ESM loader cannot detect applyPatch among its exports, so under native Node ESM (the externalized @copilotkit/runtime) it is undefined:

$ node --input-type=module -e "import * as a from 'fast-json-patch'; console.log(typeof a.applyPatch, typeof a.default?.applyPatch)"
undefined function

@ag-ui/client@0.0.53 is the first release using a default import (bisected 0.0.52 -> 0.0.59 and 1.0.x; all later versions keep it).

Changes

  • package.json: overrides for the four @ag-ui packages at 0.0.53 (@copilotkit/runtime@1.55.2-next.1 pins them to exactly 0.0.52).
  • pnpm-lock.yaml: regenerated; one version of each package remains, and the duplicate 0.0.48 copy is gone.

Testing

  • Before (live chat, real OpenAI + OpenRouter calls): several hundred Failed to apply activity patch ... a.applyPatch is not a function lines in the Next.js log for one answer.
  • After: 0 in the Next.js log and 0 in the browser console, with the generated chart still rendering and streaming.
  • pnpm install --frozen-lockfile is clean; pnpm --filter @repo/app test 164 passed; pnpm build and pnpm lint (no errors) pass.

Notes for reviewers

@ag-ui/client 0.0.52 namespace-imports fast-json-patch, a CommonJS package whose applyPatch Node's ESM loader cannot detect, so every ACTIVITY_DELTA/STATE_DELTA patch in the externalized CopilotKit runtime failed with 'a.applyPatch is not a function'. 0.0.53 is the first release using a default import. The overrides also collapse the duplicate 0.0.48 copy.

Fixes CopilotKit#146
@tbrandenburg

Copy link
Copy Markdown
Author

Extra "before" evidence on an unmodified upstream main base (the branch for #152, which does not include this override): one live chat producing a single bar chart logged 1458 Failed to apply activity patch ... a.applyPatch is not a function lines in the Next.js dev log. With this override applied, the same flow logged 0.

This branch has not been deployed

No deployments
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.

bug: AG-UI delta patches fail with "a.applyPatch is not a function" (@ag-ui/client 0.0.52)

1 participant