@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 42 lines 1.45 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import * as Effect from "effect/Effect";
3 import * as HttpServerResponse from "effect/http/HttpServerResponse";
4 import { DataBucket, Tweets } from "./bound-resources.ts";
5
6 /**
7 * Effect-native Cloud Run Service that binds Pub/Sub and Storage.
8 * Deployed from {@link ../Service.test.ts}.
9 */
10 export default class BoundService extends GCP.Function<BoundService>()(
11 "BoundService",
12 {
13 main: import.meta.url,
14 location: "us-central1",
15 invokerIamDisabled: true,
16 },
17 Effect.gen(function* () {
18 const tweets = yield* Tweets;
19 const bucket = yield* DataBucket;
20 const publish = yield* GCP.PubSub.Publish(tweets);
21 const putObject = yield* GCP.Storage.PutObject(bucket);
22 const getObject = yield* GCP.Storage.GetObject(bucket);
23
24 return {
25 fetch: Effect.gen(function* () {
26 const { messageIds } = yield* publish({
27 body: { messages: [{ data: btoa("hello") }] },
28 }).pipe(Effect.orDie);
29 yield* putObject({ name: "probe.txt", body: "stored" }).pipe(Effect.orDie);
30 const { body } = yield* getObject({ object: "probe.txt" }).pipe(Effect.orDie);
31 return yield* HttpServerResponse.json({
32 published: (messageIds?.length ?? 0) > 0,
33 read: new TextDecoder().decode(body),
34 });
35 }),
36 };
37 }).pipe(
38 Effect.provide(GCP.PubSub.PublishHttp),
39 Effect.provide(GCP.Storage.PutObjectHttp),
40 Effect.provide(GCP.Storage.GetObjectHttp),
41 ),
42 ) {}