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

main
ts 58 lines 1.89 KB
Raw
1 import * as Grafana from "@alchemy.run/aws/Grafana";
2 import * as Lambda from "@alchemy.run/aws/Lambda";
3 import * as Duration from "effect/Duration";
4 import * as Effect from "effect/Effect";
5 import { HttpServerRequest } from "effect/http/HttpServerRequest";
6 import * as HttpServerResponse from "effect/http/HttpServerResponse";
7 import path from "pathe";
8
9 const main = path.resolve(import.meta.dirname, "handler.ts");
10
11 export class GrafanaTestFunction extends Lambda.Function<Lambda.Function>()(
12 "GrafanaTestFunction",
13 ) {}
14
15 /**
16 * Ungated fixture: binds the account-level `ListVersions` capability, which
17 * needs no live workspace — proving the BindingHttp scaffold (init + IAM
18 * grant + runtime call) end-to-end at low cost. The workspace-scoped
19 * bindings are exercised by the gated fixture in `workspace-handler.ts`.
20 */
21 export default GrafanaTestFunction.make(
22 {
23 main,
24 functionUrl: true,
25 timeout: Duration.seconds(30),
26 },
27 Effect.gen(function* () {
28 const listVersions = yield* Grafana.ListVersions();
29
30 const bound = { listVersions };
31
32 return {
33 fetch: Effect.gen(function* () {
34 const request = yield* HttpServerRequest;
35 const url = new URL(request.originalUrl);
36 const pathname = url.pathname;
37
38 if (request.method === "GET" && pathname === "/bindings") {
39 return yield* HttpServerResponse.json({
40 bound: Object.keys(bound),
41 });
42 }
43
44 if (request.method === "GET" && pathname === "/versions") {
45 const { grafanaVersions } = yield* listVersions();
46 return yield* HttpServerResponse.json({
47 versions: grafanaVersions ?? [],
48 });
49 }
50
51 return yield* HttpServerResponse.json(
52 { error: "Not found", method: request.method, pathname },
53 { status: 404 },
54 );
55 }).pipe(Effect.orDie),
56 };
57 }).pipe(Effect.provide(Grafana.ListVersionsHttp)),
58 );