Skip to content

Comments

fix(ai-chat): wrap onRequest in constructor to guarantee /get-messages works#953

Open
mattzcarey wants to merge 5 commits intomainfrom
fix/ai-chat-get-messages-wrapper
Open

fix(ai-chat): wrap onRequest in constructor to guarantee /get-messages works#953
mattzcarey wants to merge 5 commits intomainfrom
fix/ai-chat-get-messages-wrapper

Conversation

@mattzcarey
Copy link
Contributor

@mattzcarey mattzcarey commented Feb 20, 2026

Summary

Move /get-messages handling from the prototype override to a constructor wrapper. This ensures the endpoint works even if users override onRequest without calling super.onRequest().

Why this is needed

When users override onRequest in their AIChatAgent subclass without calling super.onRequest(), the /get-messages endpoint doesn't work, causing messages to not persist on page reload.

Changes

  • Add constructor wrapper for onRequest that handles /get-messages before delegating to user code
  • Remove the now-redundant override onRequest() method

Note to reviewer

Pretty sure this isnt a breaking change.

  • Users calling super.onRequest(): Same behavior
  • Users NOT calling super.onRequest(): Was broken (404), now fixed
  • Users not overriding: Same behavior

Test plan

  • All 195 existing ai-chat tests pass

…s works

Move /get-messages handling from the prototype override to a constructor
wrapper. This ensures the endpoint works even if users override onRequest
without calling super.onRequest().

Not a breaking change - fixes broken code without affecting working code.
@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

🦋 Changeset detected

Latest commit: 7e5a940

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/ai-chat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@953
npm i https://pkg.pr.new/cloudflare/agents/@cloudflare/ai-chat@953
npm i https://pkg.pr.new/cloudflare/agents/@cloudflare/codemode@953
npm i https://pkg.pr.new/cloudflare/agents/hono-agents@953

commit: 7e5a940

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.

1 participant