Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix workers ai binding for cf vite plugin #8273

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

penalosa
Copy link
Contributor

Continuation of #8016 (unfortunately I can't push to that branch)


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • Wrangler E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because:

justinvdm and others added 15 commits February 3, 2025 17:56
 ## Context
Hi there o/

At RedwoodJS, we're trying out @cloudflare/vite-plugin alongside Workers AI, but we've run into an issue where the two don't seem to work together.

This is mainly to highlight the issue (its easier to explain with code). Feel free to use or disregard the solution as needed.

 ## Problem

When using `@cloudflare/vite-plugin` for a worker with an `[ai]` binding in the `worker.toml`, we end up getting this error:

```
workerd/server/workerd-api.c++:753: error: wrapped binding module can't be resolved (internal modules only); moduleName = miniflare-internal:wrapped:__WRANGLER_EXTERNAL_AI_WORKER
```

This seems to be because the miniflare options include the wrapped bindings mapping to an internal AI worker script, but the corresponding worker options for this worker are not included in the miniflare options.

 ## Solution

* In `wrangler`: Include `externalWorkers` in the results of [`unstable_getMiniflareWorkerOptions`](https://github.com/cloudflare/workers-sdk/blob/a7163b3a21f56c9bd839e34c9d5f31c3099a585a/packages/wrangler/src/api/integrations/platform/index.ts#L273) - it contains the worker options for the AI worker
* In `@cloudflare/vite-plugin-cloudflare`: For the bindings in `wrappedBindings`, if their corresponding scripts are in `externalWorkers`, add these worker options to the miniflare options
@penalosa penalosa requested review from a team as code owners February 26, 2025 17:07
Copy link

changeset-bot bot commented Feb 26, 2025

⚠️ No Changeset found

Latest commit: de85d3c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@penalosa penalosa added the e2e Run wrangler e2e tests on a PR label Feb 26, 2025
Copy link
Contributor

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-wrangler-8273

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/8273/npm-package-wrangler-8273

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-wrangler-8273 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-workers-bindings-extension-8273 -O ./cloudflare-workers-bindings-extension.0.0.0-v6811eaf35.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v6811eaf35.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-create-cloudflare-8273 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-kv-asset-handler-8273

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-miniflare-8273

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-pages-shared-8273

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-unenv-preset-8273

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-vite-plugin-8273

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-vitest-pool-workers-8273

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-workers-editor-shared-8273

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-workers-shared-8273

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13549418185/npm-package-cloudflare-workflows-shared-8273

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20250214.1
workerd 1.20250214.0 1.20250214.0
workerd --version 1.20250214.0 2025-02-14

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@justinvdm
Copy link

justinvdm commented Feb 26, 2025

@penalosa thank you so much for continuing this in #8273! 🙇 I think I'll close this PR then, but let me know if I can help :)

edit: I commented on wrong PR, sorry for the noise 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run wrangler e2e tests on a PR
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

2 participants