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

main
ts 76 lines 3.02 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import * as Effect from "effect/Effect";
3 import { serveProbes } from "../../bindingHost.ts";
4
5 /**
6 * Git links need a connection whose GitHub App install is COMPLETE; a fresh
7 * connection stays PENDING_USER_OAUTH and link create fails with BadRequest
8 * ("connection must have installation_state COMPLETE"). Set
9 * `GCP_TEST_DEVELOPERCONNECT_GITHUB_TOKEN_SECRET` (OAuth token secret
10 * version) and `GCP_TEST_DEVELOPERCONNECT_GITHUB_INSTALLATION_ID` to run.
11 * The values are forwarded to the host's environment so the deployed
12 * runtime binds the same set.
13 */
14 const githubTokenSecret = process.env.GCP_TEST_DEVELOPERCONNECT_GITHUB_TOKEN_SECRET ?? "";
15 const githubInstallationId = process.env.GCP_TEST_DEVELOPERCONNECT_GITHUB_INSTALLATION_ID ?? "";
16 export const linkEnabled = !!githubTokenSecret && !!githubInstallationId;
17
18 const cloneUri =
19 process.env.GCP_DEVELOPERCONNECT_CLONE_URI ?? "https://github.com/octocat/Hello-World.git";
20
21 /** GitHub connection; declared only when {@link linkEnabled}. */
22 export const Github = GCP.DeveloperConnect.Connection("Github", {
23 githubConfig: {
24 githubApp: "DEVELOPER_CONNECT",
25 authorizerCredential: { oauthTokenSecretVersion: githubTokenSecret },
26 appInstallationId: githubInstallationId,
27 },
28 });
29
30 /** Repository link the bindings bind; declared only when {@link linkEnabled}. */
31 export const Source = Effect.gen(function* () {
32 const github = yield* Github;
33 return yield* GCP.DeveloperConnect.ConnectionsGitRepositoryLink("Source", {
34 connection: github.name,
35 cloneUri,
36 });
37 });
38
39 const linkProbes = Effect.gen(function* () {
40 const fetchReadToken = yield* GCP.DeveloperConnect.FetchReadToken(Source);
41 const fetchReadWriteToken = yield* GCP.DeveloperConnect.FetchReadWriteToken(Source);
42 const fetchGitRefs = yield* GCP.DeveloperConnect.FetchGitRefs(Source);
43 return {
44 fetchReadToken: fetchReadToken().pipe(Effect.map((read) => ({ hasToken: !!read.token }))),
45 fetchReadWriteToken: fetchReadWriteToken().pipe(
46 Effect.map((write) => ({ hasToken: !!write.token })),
47 ),
48 fetchGitRefs: fetchGitRefs({ refType: "BRANCH" }),
49 };
50 });
51
52 /**
53 * Effect-native Cloud Run service exercising every Developer Connect binding
54 * as its own runtime service account. Deployed from
55 * {@link ../Bindings.test.ts}.
56 */
57 export default class DeveloperConnectBindingsHost extends GCP.Function<DeveloperConnectBindingsHost>()(
58 "DeveloperConnectBindingsHost",
59 {
60 main: import.meta.url,
61 invokerIamDisabled: true,
62 env: {
63 GCP_TEST_DEVELOPERCONNECT_GITHUB_TOKEN_SECRET: githubTokenSecret,
64 GCP_TEST_DEVELOPERCONNECT_GITHUB_INSTALLATION_ID: githubInstallationId,
65 GCP_DEVELOPERCONNECT_CLONE_URI: cloneUri,
66 },
67 },
68 Effect.gen(function* () {
69 const link = linkEnabled ? yield* linkProbes : {};
70 return { fetch: serveProbes({ ...link }) };
71 }).pipe(
72 Effect.provide(GCP.DeveloperConnect.FetchReadTokenHttp),
73 Effect.provide(GCP.DeveloperConnect.FetchReadWriteTokenHttp),
74 Effect.provide(GCP.DeveloperConnect.FetchGitRefsHttp),
75 ),
76 ) {}