The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { Worker, WorkerEnvironment } from "../Workers/Worker.ts"; |
| 4 | import { type Namespace as ArtifactsLike } from "./Namespace.ts"; |
| 5 | import { makeArtifactsNamespaceClient } from "./NamespaceBinding.ts"; |
| 6 | import { ReadNamespace, ReadWriteNamespace, WriteNamespace } from "./ReadWriteNamespace.ts"; |
| 7 | |
| 8 | const makeBinding = <Self>(tag: Self) => |
| 9 | Layer.effect( |
| 10 | tag as any, |
| 11 | Effect.gen(function* () { |
| 12 | const env = yield* WorkerEnvironment; |
| 13 | const host = yield* Worker; |
| 14 | return Effect.fn(function* (namespace: ArtifactsLike) { |
| 15 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 16 | yield* host.bind(namespace.name, { |
| 17 | bindings: [ |
| 18 | { |
| 19 | type: "artifacts", |
| 20 | name: namespace.name, |
| 21 | namespace: namespace.namespace, |
| 22 | } as any, |
| 23 | ], |
| 24 | }); |
| 25 | } |
| 26 | return makeArtifactsNamespaceClient(env, namespace); |
| 27 | }); |
| 28 | }), |
| 29 | ) as Layer.Layer<Self, never, Worker | WorkerEnvironment>; |
| 30 | |
| 31 | /** Read-only Artifacts binding (`get`/`list`/`raw`; repos expose history and file reads). */ |
| 32 | export const ReadNamespaceBinding = makeBinding(ReadNamespace); |
| 33 | /** Write Artifacts binding (`create`/`delete`/`import`). */ |
| 34 | export const WriteNamespaceBinding = makeBinding(WriteNamespace); |
| 35 | /** Full read + write Artifacts binding. */ |
| 36 | export const ReadWriteNamespaceBinding = makeBinding(ReadWriteNamespace); |