1import * as Cloudflare from "alchemy/Cloudflare";
2import * as Effect from "effect/Effect";
3import * as HttpServerResponse from "effect/http/HttpServerResponse";
4import Agent from "./Agent.ts";
5
6// A second Worker that binds the same `Agent` Durable Object as `Api`. Each
7// `yield* Agent` runs the DO's outer init, which calls
8// `Cloudflare.Container(Sandbox)` and pushes a binding onto the Sandbox
9// ContainerApplication carrying the Agent namespace. With two Workers binding
10// the same DO, the Sandbox ends up with two bindings that share a single
11// `namespaceId` — the regression case for the dedupe fix in this PR.
12export class SecondaryApi extends Cloudflare.Worker<SecondaryApi, {}>()(
13 "SecondaryApi",
14) {}
15
16export default SecondaryApi.make(
17 {
18 main: import.meta.url,
19 observability: { enabled: true },
20 },
21 Effect.gen(function* () {
22 const agents = yield* Agent;
23
24 return {
25 fetch: Effect.gen(function* () {
26 const body = yield* agents
27 .getByName("sandbox-test")
28 .hello()
29 .pipe(Effect.orDie);
30 return HttpServerResponse.text(body);
31 }),
32 };
33 }),
34);