Allow callable to be used as a function.#1698
Conversation
Add a decorator-free way to expose callable Agent methods by allowing `callable(fn, metadata)` on function-valued class fields while keeping the existing `@callable()` decorator path intact. Both forms share the same callable metadata, and the runtime now normalizes own callable fields before RPC dispatch and method introspection so they retain Agent context and appear in `getCallableMethods()`.
🦋 Changeset detectedLatest commit: b9a4576 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
There was a problem hiding this comment.
Context: ECMAScript decorators were moved from Stage 3 to Stage 2.7 in tc39/proposals@cd2396f.
At present, I don’t recommend using them, since we only use this syntax in a single place. The lack of tooling support and the confusing tsconfig setup mentioned in the docs are what prompted this PR.
I have a few ideas for making ECMAScript decorators generally available in the Vite ecosystem, but that will take a while because it depends on the standard TC39 process.
|
I love that this has backward compat. I need to check some stuff with making sure regular rpc works with this and I'll land it (it might not, I think that's the problem with instance props and why we went with decorators here) |
Code reviewFound 3 critical issues:
The current implementation uses agents/packages/agents/src/index.ts Lines 129 to 131 in b9a4576
The hybrid approach requires complex conditional types that could compromise type safety. The current implementation only supports the decorator pattern cleanly, and adding function wrapping creates type complexity that may lead to runtime errors. agents/packages/agents/src/index.ts Lines 123 to 135 in b9a4576
The agents/packages/agents/src/index.ts Lines 847 to 906 in b9a4576 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Decorators are problematic. They have been stuck in standardization limbo for 12 years, there are a lot of versions, and they have recently been bumped back on the path to standardization. Vite 8 does not currently support decorators, which means the
agentspackage has to add Babel to pre-process JS which slows down compilation quite a bit. With agents, the value of decorators as syntax sugar may not be so clear anymore.This PR changes
callableinto a hybrid decorator and function so you can instead define callback functions like this:If you are on board with merging this, I would like to follow it up with an option for the Vite plugin to skip the decorator plugin for faster compilation, and in the future we could choose to flip the default to disable decorators (+ codemod) and possibly even remove it.