feat(cloudflare): make AI binding a first-class Component #6328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Summary
This PR adds the
Aicomponent for Cloudflare Workers making it a first-class Component alongside existing ones like Bucket and Worker.The main driver for this change is that currently, to use AI Bindings you have to manually update the bindings in the transform:
Which, I mean - works; But doesn't look great and has to be duplicated in every worker configuration and more importantly doesn't allow you to access it from
Resourceand you have to manually ensure it's present onENVinstead.Changes
Aicomponent (platform/src/components/cloudflare/ai.ts)platform/src/components/cloudflare/binding.ts): Add AiBinding type definitionexamples/cloudflare-hono/)Usage
Then access via
Resource.aiin the worker script:Notes
I updated the hono example to add this, which necessitated the update to the latest
worker-typespackage (4.20260114.0). I'm not 100% sure if this is something that needs to be updated someplace else to ensure that SST installs the appropriate version - so let me know if there's something that I need to update for that.I also wasn't sure if there was any tests I needed to update, so apologies if that's missing as well.