Skip to content

Commit ba50b6a

Browse files
add localBindingsOnly option to getPlatformProxy to disable the remote aspect of remote bindings
1 parent 07efcac commit ba50b6a

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

.changeset/modern-foxes-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
add a `localBindingsOnly` option to `getPlatformProxy` to disable the remote aspect of remote bindings
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, expect, test } from "vitest";
2+
import { getPlatformProxy } from "wrangler";
3+
import type { Ai } from "@cloudflare/workers-types/experimental";
4+
5+
describe(
6+
"getPlatformProxy - remote bindings with localBindingsOnly",
7+
{ timeout: 50_000 },
8+
() => {
9+
test("getPlatformProxy works with remote bindings", async () => {
10+
const { env, dispose } = await getPlatformProxy<{
11+
AI: Ai;
12+
}>({
13+
configPath: "./wrangler.local-bindings-only.jsonc",
14+
localBindingsOnly: true,
15+
});
16+
17+
await expect(
18+
(async () => {
19+
await env.AI.run("@cf/meta/llama-3.1-8b-instruct-fp8", {
20+
messages: [],
21+
});
22+
})()
23+
).rejects.toThrowErrorMatchingInlineSnapshot(
24+
`[Error: Binding AI needs to be run remotely]`
25+
);
26+
27+
await dispose();
28+
});
29+
}
30+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "get-platform-proxy-remote-bindings-with-local-bindings-only-test",
3+
"compatibility_date": "2025-05-07",
4+
"ai": {
5+
"binding": "AI",
6+
"remote": true,
7+
},
8+
}

packages/wrangler/src/api/integrations/platform/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ export type GetPlatformProxyOptions = {
8585
* If `false` is specified no data is persisted on the filesystem.
8686
*/
8787
persist?: boolean | { path: string };
88+
/**
89+
* Wether only local bindings should be used. This effectively disables the remote aspect of remote bindings
90+
* (exactly as if their `remote` configuration was changed from `true` to `false`)
91+
*/
92+
localBindingsOnly?: boolean;
8893
};
8994

9095
/**
@@ -138,7 +143,7 @@ export async function getPlatformProxy<
138143
});
139144

140145
let remoteProxySession: RemoteProxySession | undefined = undefined;
141-
if (config.configPath) {
146+
if (config.configPath && !options.localBindingsOnly) {
142147
remoteProxySession = (
143148
(await maybeStartOrUpdateRemoteProxySession({
144149
path: config.configPath,

0 commit comments

Comments
 (0)