Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions packages/miniflare/src/plugins/agent-memory/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import {
getUserBindingServiceName,
buildRemoteProxyProps,
ProxyNodeBinding,
remoteProxyClientWorker,
} from "../shared";
Expand All @@ -20,6 +20,7 @@ export const AgentMemoryOptionsSchema = z.object({
export const AGENT_MEMORY_PLUGIN_NAME = "agent-memory";

const AGENT_MEMORY_SCOPE = "agent-memory";
const AGENT_MEMORY_REMOTE_SERVICE_NAME = `${AGENT_MEMORY_SCOPE}:remote`;

export const AGENT_MEMORY_PLUGIN: Plugin<typeof AgentMemoryOptionsSchema> = {
options: AgentMemoryOptionsSchema,
Expand All @@ -32,10 +33,10 @@ export const AGENT_MEMORY_PLUGIN: Plugin<typeof AgentMemoryOptionsSchema> = {
return Object.entries(options.agentMemory).map(([bindingName, entry]) => ({
name: bindingName,
service: {
name: getUserBindingServiceName(
AGENT_MEMORY_SCOPE,
bindingName,
entry.remoteProxyConnectionString
name: AGENT_MEMORY_REMOTE_SERVICE_NAME,
props: buildRemoteProxyProps(
entry.remoteProxyConnectionString,
bindingName
),
},
}));
Expand All @@ -53,20 +54,15 @@ export const AGENT_MEMORY_PLUGIN: Plugin<typeof AgentMemoryOptionsSchema> = {
);
},
async getServices({ options }) {
if (!options.agentMemory) {
if (!options.agentMemory || Object.keys(options.agentMemory).length === 0) {
return [];
}

return Object.entries(options.agentMemory).map(([bindingName, entry]) => ({
name: getUserBindingServiceName(
AGENT_MEMORY_SCOPE,
bindingName,
entry.remoteProxyConnectionString
),
worker: remoteProxyClientWorker(
entry.remoteProxyConnectionString,
bindingName
),
}));
return [
{
name: AGENT_MEMORY_REMOTE_SERVICE_NAME,
worker: remoteProxyClientWorker(),
},
];
},
};
74 changes: 18 additions & 56 deletions packages/miniflare/src/plugins/ai-search/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import {
getUserBindingServiceName,
buildRemoteProxyProps,
ProxyNodeBinding,
remoteProxyClientWorker,
} from "../shared";
Expand All @@ -21,45 +21,29 @@ export const AISearchOptionsSchema = z.object({

export const AI_SEARCH_PLUGIN_NAME = "ai-search";

// Distinct scopes for service name generation to avoid collisions
// between namespace and instance bindings with the same binding name.
const AI_SEARCH_NS_SCOPE = "ai-search-ns";
const AI_SEARCH_INST_SCOPE = "ai-search-inst";
// One shared remote-proxy service for all AI Search bindings (config via props).
const AI_SEARCH_REMOTE_SERVICE_NAME = `${AI_SEARCH_PLUGIN_NAME}:remote`;

export const AI_SEARCH_PLUGIN: Plugin<typeof AISearchOptionsSchema> = {
options: AISearchOptionsSchema,
bindingTypeDescription: "AI Search",
async getBindings(options) {
const bindings: {
name: string;
service: { name: string };
service: { name: string; props?: { json: string } };
}[] = [];

for (const [bindingName, entry] of Object.entries(
options.aiSearchNamespaces ?? {}
)) {
for (const [bindingName, entry] of [
...Object.entries(options.aiSearchNamespaces ?? {}),
...Object.entries(options.aiSearchInstances ?? {}),
]) {
bindings.push({
name: bindingName,
service: {
name: getUserBindingServiceName(
AI_SEARCH_NS_SCOPE,
bindingName,
entry.remoteProxyConnectionString
),
},
});
}

for (const [bindingName, entry] of Object.entries(
options.aiSearchInstances ?? {}
)) {
bindings.push({
name: bindingName,
service: {
name: getUserBindingServiceName(
AI_SEARCH_INST_SCOPE,
bindingName,
entry.remoteProxyConnectionString
name: AI_SEARCH_REMOTE_SERVICE_NAME,
props: buildRemoteProxyProps(
entry.remoteProxyConnectionString,
bindingName
),
},
});
Expand All @@ -85,35 +69,13 @@ export const AI_SEARCH_PLUGIN: Plugin<typeof AISearchOptionsSchema> = {
worker: ReturnType<typeof remoteProxyClientWorker>;
}[] = [];

for (const [bindingName, entry] of Object.entries(
options.aiSearchNamespaces ?? {}
)) {
services.push({
name: getUserBindingServiceName(
AI_SEARCH_NS_SCOPE,
bindingName,
entry.remoteProxyConnectionString
),
worker: remoteProxyClientWorker(
entry.remoteProxyConnectionString,
bindingName
),
});
}

for (const [bindingName, entry] of Object.entries(
options.aiSearchInstances ?? {}
)) {
const hasAny =
Object.keys(options.aiSearchNamespaces ?? {}).length > 0 ||
Object.keys(options.aiSearchInstances ?? {}).length > 0;
if (hasAny) {
services.push({
name: getUserBindingServiceName(
AI_SEARCH_INST_SCOPE,
bindingName,
entry.remoteProxyConnectionString
),
worker: remoteProxyClientWorker(
entry.remoteProxyConnectionString,
bindingName
),
name: AI_SEARCH_REMOTE_SERVICE_NAME,
worker: remoteProxyClientWorker(),
});
}

Expand Down
22 changes: 8 additions & 14 deletions packages/miniflare/src/plugins/ai/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import {
getUserBindingServiceName,
buildRemoteProxyProps,
ProxyNodeBinding,
remoteProxyClientWorker,
} from "../shared";
Expand All @@ -18,6 +18,7 @@ export const AIOptionsSchema = z.object({
});

export const AI_PLUGIN_NAME = "ai";
const AI_REMOTE_SERVICE_NAME = `${AI_PLUGIN_NAME}:remote`;

export const AI_PLUGIN: Plugin<typeof AIOptionsSchema> = {
options: AIOptionsSchema,
Expand All @@ -36,10 +37,10 @@ export const AI_PLUGIN: Plugin<typeof AIOptionsSchema> = {
{
name: "fetcher",
service: {
name: getUserBindingServiceName(
AI_PLUGIN_NAME,
options.ai.binding,
options.ai.remoteProxyConnectionString
name: AI_REMOTE_SERVICE_NAME,
props: buildRemoteProxyProps(
options.ai.remoteProxyConnectionString,
options.ai.binding
),
},
},
Expand All @@ -63,15 +64,8 @@ export const AI_PLUGIN: Plugin<typeof AIOptionsSchema> = {

return [
{
name: getUserBindingServiceName(
AI_PLUGIN_NAME,
options.ai.binding,
options.ai.remoteProxyConnectionString
),
worker: remoteProxyClientWorker(
options.ai.remoteProxyConnectionString,
options.ai.binding
),
name: AI_REMOTE_SERVICE_NAME,
worker: remoteProxyClientWorker(),
},
];
},
Expand Down
30 changes: 13 additions & 17 deletions packages/miniflare/src/plugins/artifacts/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import {
getUserBindingServiceName,
buildRemoteProxyProps,
ProxyNodeBinding,
remoteProxyClientWorker,
} from "../shared";
Expand All @@ -18,6 +18,9 @@ export const ArtifactsOptionsSchema = z.object({
});

export const ARTIFACTS_PLUGIN_NAME = "artifacts";
// One shared remote-proxy service for every artifacts binding; per-binding
// config travels via props.
const ARTIFACTS_REMOTE_SERVICE_NAME = `${ARTIFACTS_PLUGIN_NAME}:remote`;

export const ARTIFACTS_PLUGIN: Plugin<typeof ArtifactsOptionsSchema> = {
options: ArtifactsOptionsSchema,
Expand All @@ -30,11 +33,8 @@ export const ARTIFACTS_PLUGIN: Plugin<typeof ArtifactsOptionsSchema> = {
return Object.entries(options.artifacts).map(([name, config]) => ({
name,
service: {
name: getUserBindingServiceName(
ARTIFACTS_PLUGIN_NAME,
name,
config.remoteProxyConnectionString
),
name: ARTIFACTS_REMOTE_SERVICE_NAME,
props: buildRemoteProxyProps(config.remoteProxyConnectionString, name),
},
}));
},
Expand All @@ -50,19 +50,15 @@ export const ARTIFACTS_PLUGIN: Plugin<typeof ArtifactsOptionsSchema> = {
);
},
async getServices({ options }) {
if (!options.artifacts) {
if (!options.artifacts || Object.keys(options.artifacts).length === 0) {
return [];
}

return Object.entries(options.artifacts).map(
([name, { remoteProxyConnectionString }]) => ({
name: getUserBindingServiceName(
ARTIFACTS_PLUGIN_NAME,
name,
remoteProxyConnectionString
),
worker: remoteProxyClientWorker(remoteProxyConnectionString, name),
})
);
return [
{
name: ARTIFACTS_REMOTE_SERVICE_NAME,
worker: remoteProxyClientWorker(),
},
];
},
};
90 changes: 51 additions & 39 deletions packages/miniflare/src/plugins/browser-rendering/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import BROWSER_RENDERING_WORKER from "worker:browser-rendering/binding";
import { z } from "zod";
import { kVoid } from "../../runtime";
import {
buildRemoteProxyProps,
getUserBindingServiceName,
ProxyNodeBinding,
remoteProxyClientWorker,
Expand All @@ -40,6 +41,7 @@ export const BrowserRenderingOptionsSchema = z.object({
});

export const BROWSER_RENDERING_PLUGIN_NAME = "browser-rendering";
const BROWSER_RENDERING_REMOTE_SERVICE_NAME = `${BROWSER_RENDERING_PLUGIN_NAME}:remote`;

export const BROWSER_RENDERING_PLUGIN: Plugin<
typeof BrowserRenderingOptionsSchema
Expand All @@ -54,13 +56,20 @@ export const BROWSER_RENDERING_PLUGIN: Plugin<
return [
{
name: options.browserRendering.binding,
service: {
name: getUserBindingServiceName(
BROWSER_RENDERING_PLUGIN_NAME,
"service",
options.browserRendering.remoteProxyConnectionString
),
},
service: options.browserRendering.remoteProxyConnectionString
? {
name: BROWSER_RENDERING_REMOTE_SERVICE_NAME,
props: buildRemoteProxyProps(
options.browserRendering.remoteProxyConnectionString,
options.browserRendering.binding
),
}
: {
name: getUserBindingServiceName(
BROWSER_RENDERING_PLUGIN_NAME,
"service"
),
},
},
];
},
Expand All @@ -77,44 +86,47 @@ export const BROWSER_RENDERING_PLUGIN: Plugin<
return [];
}

if (options.browserRendering.remoteProxyConnectionString) {
return [
{
name: BROWSER_RENDERING_REMOTE_SERVICE_NAME,
worker: remoteProxyClientWorker(),
},
];
}

return [
{
name: getUserBindingServiceName(
BROWSER_RENDERING_PLUGIN_NAME,
"service",
options.browserRendering.remoteProxyConnectionString
"service"
),
worker: options.browserRendering.remoteProxyConnectionString
? remoteProxyClientWorker(
options.browserRendering.remoteProxyConnectionString,
options.browserRendering.binding
)
: {
compatibilityDate: "2025-05-01",
compatibilityFlags: ["nodejs_compat"],
modules: [
{
name: "index.worker.js",
esModule: BROWSER_RENDERING_WORKER(),
},
],
bindings: [
WORKER_BINDING_SERVICE_LOOPBACK,
{
name: "BrowserSession",
durableObjectNamespace: {
className: "BrowserSession",
},
},
],
durableObjectNamespaces: [
{
className: "BrowserSession",
uniqueKey: "miniflare-BrowserSession",
},
],
durableObjectStorage: { inMemory: kVoid },
worker: {
compatibilityDate: "2025-05-01",
compatibilityFlags: ["nodejs_compat"],
modules: [
{
name: "index.worker.js",
esModule: BROWSER_RENDERING_WORKER(),
},
],
bindings: [
WORKER_BINDING_SERVICE_LOOPBACK,
{
name: "BrowserSession",
durableObjectNamespace: {
className: "BrowserSession",
},
},
],
durableObjectNamespaces: [
{
className: "BrowserSession",
uniqueKey: "miniflare-BrowserSession",
},
],
durableObjectStorage: { inMemory: kVoid },
},
},
];
},
Expand Down
Loading
Loading