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

main
ts 38 lines 1.22 KB
Raw
1 import * as cloudrun from "@distilled.cloud/gcp/run_v2";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as GCPBindings from "../GCPBindings.ts";
5 import { grantFor } from "../HttpBinding.ts";
6 import type { Job } from "./Job.ts";
7 import { RunJob, type RunJobRequest } from "./RunJob.ts";
8
9 /**
10 * HTTP implementation of {@link RunJob}.
11 *
12 * @layer
13 * @provides GCP.Run.RunJob
14 */
15 export const RunJobHttp = Layer.effect(
16 RunJob,
17 Effect.gen(function* () {
18 const bind = yield* GCPBindings.Bind;
19 const run = yield* GCPBindings.withCredentials(cloudrun.runProjectsLocationsJobs);
20 return Effect.fn(function* <T extends Job>(job: T) {
21 const name = yield* job.name;
22 if (!globalThis.__ALCHEMY_RUNTIME__) {
23 yield* bind`GCP.Run.RunJob(${job})`({
24 iam: [
25 // runWithOverrides: RunJobRequest accepts `body.overrides`.
26 grantFor({ role: "roles/run.jobsExecutorWithOverrides", on: "run.job" }, job.name),
27 ],
28 });
29 }
30 return Effect.fn(`GCP.Run.RunJob(${job.LogicalId})`)(function* (request?: RunJobRequest) {
31 return yield* run({
32 ...request,
33 name: yield* name,
34 });
35 });
36 });
37 }),
38 );