@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, 04:45 UTC

main
ts 53 lines 1.47 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as Layer from "effect/Layer";
3 import { Worker, WorkerEnvironment } from "../Workers/Worker.ts";
4 import type { Dataset as AnalyticsEngineDatasetLike } from "./Dataset.ts";
5 import {
6 DatasetError,
7 type DatasetClient,
8 type RuntimeAnalyticsEngineDataset,
9 WriteDataset,
10 } from "./WriteDataset.ts";
11
12 export const WriteDatasetBinding = Layer.effect(
13 WriteDataset,
14 Effect.gen(function* () {
15 const env = yield* WorkerEnvironment;
16 const host = yield* Worker;
17
18 return Effect.fn(function* (dataset: AnalyticsEngineDatasetLike) {
19 if (!globalThis.__ALCHEMY_RUNTIME__) {
20 yield* host.bind(dataset.name, {
21 bindings: [
22 {
23 type: "analytics_engine",
24 name: dataset.name,
25 dataset: dataset.dataset,
26 },
27 ],
28 });
29 }
30
31 const raw = Effect.sync(
32 () => (env as Record<string, RuntimeAnalyticsEngineDataset>)[dataset.name]!,
33 );
34
35 return {
36 raw,
37 writeDataPoint: (dataPoint) =>
38 raw.pipe(
39 Effect.flatMap((raw) =>
40 Effect.try({
41 try: () => raw.writeDataPoint(dataPoint),
42 catch: (error: any) =>
43 new DatasetError({
44 message: error?.message ?? "Unknown error",
45 cause: error,
46 }),
47 }),
48 ),
49 ),
50 } satisfies DatasetClient;
51 });
52 }),
53 );