The best way to control Claude Code, Codex and more from any computer or phone

main
ts 31 lines 1.21 KB
Raw
1 import * as crypto from "node:crypto";
2 import type * as Bundle from "alchemy/Bundle/Bundle";
3 import * as Effect from "effect/Effect";
4 import * as Stream from "effect/Stream";
5 import type { SourceProvider } from "../Source.ts";
6 import { bundleSource } from "./shared.ts";
7
8 /**
9 * Source provider for `props.script` workers: the raw module source is
10 * uploaded as a single ESM module (`main.js`), bypassing bundling
11 * entirely. The bundle hash is `sha256(script)` — identical to the
12 * pre-SourceProvider `hashScript` slot, so persisted state diffs cleanly
13 * across the refactor.
14 */
15 export const makeInlineScriptSource = (script: string): SourceProvider => {
16 const bundle = Effect.sync(() => crypto.createHash("sha256").update(script).digest("hex")).pipe(
17 Effect.map((hash): Bundle.BundleOutput => ({
18 files: [{ path: "main.js", content: script, hash }],
19 hash,
20 })),
21 );
22 return bundleSource({
23 build: () => bundle,
24 // Local dev: a single-element stream — script changes arrive as new
25 // props, which restart the instance via `structuralSignature`.
26 watch: () =>
27 bundle.pipe(
28 Effect.map((output) => Stream.make({ _tag: "Success", output } as Bundle.BundleWatchEvent)),
29 ),
30 });
31 };