@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 45 lines 1.55 KB
Raw
1 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
2 import * as resourcemanager from "@distilled.cloud/gcp/cloudresourcemanager_v3";
3 import * as Effect from "effect/Effect";
4 import { MinimumLogLevel } from "effect/References";
5
6 export const logLevel = Effect.provideService(
7 MinimumLogLevel,
8 process.env.DEBUG ? "Debug" : "Info",
9 );
10
11 export const currentProject = GcpEnvironment.current.pipe(Effect.map((env) => env.project));
12
13 // Access policies live on the organization and need Access Context Manager
14 // admin there; the testing credentials get Forbidden "The caller does not have
15 // permission". Set GOOGLE_ORGANIZATION_ID when the credentials administer the
16 // org to run the lifecycles.
17 export const runLifecycle = !!process.env.GOOGLE_ORGANIZATION_ID;
18
19 export const runProbe = !runLifecycle;
20
21 export const lastSegment = (value: string) => {
22 const trimmed = value.replace(/\/+$/, "");
23 const parts = trimmed.split("/");
24 return parts[parts.length - 1] || trimmed;
25 };
26
27 export const projectContext = () =>
28 currentProject.pipe(
29 Effect.flatMap((project) => resourcemanager.getProjects({ name: `projects/${project}` })),
30 Effect.map((resource) => {
31 const parent = resource.parent ?? "";
32 return {
33 projectNumber: lastSegment(resource.name ?? ""),
34 parent,
35 organization: parent.startsWith("organizations/") ? parent : undefined,
36 };
37 }),
38 Effect.catchTag("NotFound", () =>
39 Effect.succeed({
40 projectNumber: "",
41 parent: "",
42 organization: undefined as string | undefined,
43 }),
44 ),
45 );