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

main
ts 44 lines 1.64 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda/Function";
2 /**
3 * The pack hasher as an AWS Lambda (DESIGN §22.11): an Effect-native
4 * Function that answers {@link HashEvent}s — the same scan the Worker runs
5 * inline, on a core several times faster and, above all, on as many cores
6 * as there are chunks in flight. Declare it in the same stack as the Git
7 * Worker (the stack needs both provider sets) and hand it to
8 * {@link HasherLambda}.
9 *
10 * **Example:** A Git host that hashes pushes on Lambda
11 * ```typescript
12 * import * as Git from "@alchemy.run/git";
13 * import * as GitHasher from "@alchemy.run/git/Hasher";
14 *
15 * const GitLive = Git.ApiLive.pipe(
16 * Layer.provide(Git.ApiHandlersLive),
17 * Layer.provide(Authentication.layer),
18 * Layer.provide(Git.ReposDurableObject),
19 * Layer.provide(Git.RegistryDurableObject),
20 * Layer.provide(GitHasher.HasherLambda(GitHasher.HasherFunction)),
21 * Layer.provide(AWS.Lambda.InvokeFunctionHttp),
22 * Layer.provide(Git.BlobStoreR2(GitObjects)),
23 * );
24 * ```
25 */
26 import * as Duration from "effect/Duration";
27 import * as Effect from "effect/Effect";
28 import { handleHashEvent, isHashEvent } from "./LambdaEvent.ts";
29
30 export default class HasherFunction extends Lambda.Function<HasherFunction>()(
31 "GitHasher",
32 {
33 main: import.meta.url,
34 // CPU scales with memory on Lambda; 3 GB is the fastest single-thread
35 // tier and a chunk needs well under that.
36 memorySize: 3008,
37 timeout: Duration.seconds(60),
38 },
39 Effect.gen(function* () {
40 const fn = yield* Lambda.Function;
41 yield* fn.listen((event: unknown) => (isHashEvent(event) ? handleHashEvent(event) : undefined));
42 return {};
43 }),
44 ) {}