Skip to content

Commit 596b8a0

Browse files
authored
[miniflare/wrangler] Revert AI Search RPC workaround (#12691)
1 parent 8e738f8 commit 596b8a0

File tree

8 files changed

+8
-235
lines changed

8 files changed

+8
-235
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"miniflare": patch
3+
"wrangler": patch
4+
---
5+
6+
Remove temporary AI Search RPC workaround (no user-facing changes)

‎packages/miniflare/src/plugins/ai/index.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export const AI_PLUGIN: Plugin<typeof AIOptionsSchema> = {
7070
),
7171
worker: remoteProxyClientWorker(
7272
options.ai.remoteProxyConnectionString,
73-
options.ai.binding,
74-
"ai"
73+
options.ai.binding
7574
),
7675
},
7776
];

‎packages/miniflare/src/plugins/dispatch-namespace/index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export const DISPATCH_NAMESPACE_PLUGIN: Plugin<
9090
worker: remoteProxyClientWorker(
9191
config.remoteProxyConnectionString,
9292
name,
93-
undefined,
9493
SCRIPT_DISPATCH_NAMESPACE_PROXY
9594
),
9695
}));

‎packages/miniflare/src/plugins/shared/constants.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export function objectEntryWorker(
7676
export function remoteProxyClientWorker(
7777
remoteProxyConnectionString: RemoteProxyConnectionString | undefined,
7878
binding: string,
79-
bindingType?: string,
8079
script?: () => string
8180
) {
8281
return {
@@ -100,14 +99,6 @@ export function remoteProxyClientWorker(
10099
name: "binding",
101100
text: binding,
102101
},
103-
...(bindingType
104-
? [
105-
{
106-
name: "bindingType",
107-
text: bindingType,
108-
},
109-
]
110-
: []),
111102
],
112103
};
113104
}

‎packages/miniflare/src/workers/shared/remote-bindings-utils.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import { newWebSocketRpcSession } from "capnweb";
66
export type RemoteBindingEnv = {
77
remoteProxyConnectionString?: string;
88
binding: string;
9-
bindingType?: string;
109
};
1110

1211
/** Headers sent alongside proxy requests to provide additional context. */
1312
export type ProxyMetadata = {
14-
"MF-Binding-Type"?: string;
1513
"MF-Dispatch-Namespace-Options"?: string;
1614
};
1715

‎packages/miniflare/src/workers/shared/remote-proxy-client.worker.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ export default class Client extends WorkerEntrypoint<RemoteBindingEnv> {
1919
super(ctx, env);
2020

2121
const stub = env.remoteProxyConnectionString
22-
? makeRemoteProxyStub(
23-
env.remoteProxyConnectionString,
24-
env.binding,
25-
env.bindingType ? { "MF-Binding-Type": env.bindingType } : undefined
26-
)
22+
? makeRemoteProxyStub(env.remoteProxyConnectionString, env.binding)
2723
: undefined;
2824

2925
return new Proxy(this, {

‎packages/wrangler/src/__tests__/dev/proxy-server-ai-rpc.test.ts‎

Lines changed: 0 additions & 186 deletions
This file was deleted.

‎packages/wrangler/templates/remoteBindings/ProxyServerWorker.ts‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ import { EmailMessage } from "cloudflare:email";
33

44
interface Env extends Record<string, unknown> {}
55

6-
/**
7-
* List of RPC methods exposed by the raw AI binding that need proxying
8-
* through a plain-object wrapper. The raw AI binding (deployed with raw:true)
9-
* has a non-standard prototype that capnweb's typeForRpc() doesn't recognise,
10-
* causing "RPC stub points at a non-serializable type". By wrapping only the
11-
* allowed RPC methods in a plain object we give capnweb an Object.prototype
12-
* target it can navigate.
13-
*
14-
* Add new AI RPC method names here as they are introduced.
15-
*/
16-
const AI_RPC_METHODS = ["aiSearch"] as const;
17-
186
class BindingNotFoundError extends Error {
197
constructor(name?: string) {
208
super(`Binding ${name ? `"${name}"` : ""} not found`);
@@ -33,11 +21,6 @@ class BindingNotFoundError extends Error {
3321
* can't emulate that over an async boundary, we mock it locally and _actually_
3422
* perform the .get() remotely at the first appropriate async point. See
3523
* packages/miniflare/src/workers/dispatch-namespace/dispatch-namespace.worker.ts
36-
* - AI bindings (raw:true / minimal_mode) have a workerd-internal prototype
37-
* that capnweb's typeForRpc() classifies as "unsupported", causing
38-
* "RPC stub points at a non-serializable type". We wrap the binding in a
39-
* plain object that delegates only the allowed RPC methods (AI_RPC_METHODS)
40-
* so capnweb gets an Object.prototype target it can navigate.
4124
*
4225
* getExposedJSRPCBinding() and getExposedFetcher() perform the logic for figuring out
4326
* which binding is being accessed, dependending on the request. Note: Both have logic
@@ -77,19 +60,6 @@ function getExposedJSRPCBinding(request: Request, env: Env) {
7760
};
7861
}
7962

80-
if (url.searchParams.get("MF-Binding-Type") === "ai") {
81-
const wrapper: Record<string, (...args: unknown[]) => unknown> = {};
82-
for (const method of AI_RPC_METHODS) {
83-
if (typeof (targetBinding as any)[method] === "function") {
84-
wrapper[method] = (...args: unknown[]) =>
85-
(targetBinding as any)[method](...args);
86-
}
87-
}
88-
if (Object.keys(wrapper).length > 0) {
89-
return wrapper;
90-
}
91-
}
92-
9363
if (url.searchParams.has("MF-Dispatch-Namespace-Options")) {
9464
const { name, args, options } = JSON.parse(
9565
url.searchParams.get("MF-Dispatch-Namespace-Options")!

0 commit comments

Comments
 (0)