- move `AnalyticsServiceLayerLive` from CLI runtime setup into `main` server layer - persist telemetry `anonymous-id` under configured `stateDir` instead of home directory - add `FetchHttpClient.layer` to `main.test.ts` test layer wiring
Unified · Split
| @@ -9,12 +9,10 @@ import { Command } from "effect/unstable/cli"; · 8 unmodified lines | |||
| 9 | import { version } from "../package.json" with { type: "json" }; | 9 | import { version } from "../package.json" with { type: "json" }; |
| 10 | import { ServerLive } from "./wsServer"; | 10 | import { ServerLive } from "./wsServer"; |
| 11 | import { NetService } from "@t3tools/shared/Net"; | 11 | import { NetService } from "@t3tools/shared/Net"; |
| 12 | import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService"; | ||
| 13 | import { FetchHttpClient } from "effect/unstable/http"; | 12 | import { FetchHttpClient } from "effect/unstable/http"; |
| 14 | 13 | ||
| 15 | const RuntimeLayer = Layer.empty.pipe( | 14 | const RuntimeLayer = Layer.empty.pipe( |
| 16 | Layer.provideMerge(CliConfig.layer), | 15 | Layer.provideMerge(CliConfig.layer), |
| 17 | Layer.provideMerge(AnalyticsServiceLayerLive), | ||
| 18 | Layer.provideMerge(ServerLive), | 16 | Layer.provideMerge(ServerLive), |
| 19 | Layer.provideMerge(OpenLive), | 17 | Layer.provideMerge(OpenLive), |
| 20 | Layer.provideMerge(NetService.layer), | 18 | Layer.provideMerge(NetService.layer), |
| @@ -5,6 +5,7 @@ import * as ConfigProvider from "effect/ConfigProvider"; · 4 unmodified lines | |||
| 5 | import * as Effect from "effect/Effect"; | 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Layer from "effect/Layer"; | 6 | import * as Layer from "effect/Layer"; |
| 7 | import * as Command from "effect/unstable/cli/Command"; | 7 | import * as Command from "effect/unstable/cli/Command"; |
| 8 | import { FetchHttpClient } from "effect/unstable/http"; | ||
| 8 | import { beforeEach } from "vitest"; | 9 | import { beforeEach } from "vitest"; |
| 9 | import { NetService } from "@t3tools/shared/Net"; | 10 | import { NetService } from "@t3tools/shared/Net"; |
| 10 | 11 | ||
| @@ -52,6 +53,7 @@ const testLayer = Layer.mergeAll( · 41 unmodified lines | |||
| 52 | record: () => Effect.void, | 53 | record: () => Effect.void, |
| 53 | flush: Effect.void, | 54 | flush: Effect.void, |
| 54 | }), | 55 | }), |
| 56 | FetchHttpClient.layer, | ||
| 55 | NodeServices.layer, | 57 | NodeServices.layer, |
| 56 | ); | 58 | ); |
| 57 | 59 | ||
| @@ -23,6 +23,7 @@ import { makeServerProviderLayer, makeServerRuntimeServicesLayer } from "./serve · 22 unmodified lines | |||
| 23 | import { ProviderHealthLive } from "./provider/Layers/ProviderHealth"; | 23 | import { ProviderHealthLive } from "./provider/Layers/ProviderHealth"; |
| 24 | import { Server } from "./wsServer"; | 24 | import { Server } from "./wsServer"; |
| 25 | import { ServerLoggerLive } from "./serverLogger"; | 25 | import { ServerLoggerLive } from "./serverLogger"; |
| 26 | import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService"; | ||
| 26 | 27 | ||
| 27 | export class StartupError extends Data.TaggedError("StartupError")<{ | 28 | export class StartupError extends Data.TaggedError("StartupError")<{ |
| 28 | readonly message: string; | 29 | readonly message: string; |
| @@ -197,6 +198,7 @@ const LayerLive = (input: CliInput) => · 168 unmodified lines | |||
| 197 | Layer.provideMerge(ProviderHealthLive), | 198 | Layer.provideMerge(ProviderHealthLive), |
| 198 | Layer.provideMerge(SqlitePersistence.layerConfig), | 199 | Layer.provideMerge(SqlitePersistence.layerConfig), |
| 199 | Layer.provideMerge(ServerLoggerLive), | 200 | Layer.provideMerge(ServerLoggerLive), |
| 201 | Layer.provideMerge(AnalyticsServiceLayerLive), | ||
| 200 | Layer.provideMerge(ServerConfigLive(input)), | 202 | Layer.provideMerge(ServerConfigLive(input)), |
| 201 | ); | 203 | ); |
| 202 | 204 | ||
| @@ -1,6 +1,7 @@ | |||
| 1 | import { Effect, FileSystem, Path, Random, Schema } from "effect"; | 1 | import { Effect, FileSystem, Path, Random, Schema } from "effect"; |
| 2 | import * as Crypto from "node:crypto"; | 2 | import * as Crypto from "node:crypto"; |
| 3 | import { homedir } from "node:os"; | 3 | import { homedir } from "node:os"; |
| 4 | import { ServerConfig } from "../config"; | ||
| 4 | 5 | ||
| 5 | const CodexAuthJsonSchema = Schema.Struct({ | 6 | const CodexAuthJsonSchema = Schema.Struct({ |
| 6 | tokens: Schema.Struct({ | 7 | tokens: Schema.Struct({ |
| @@ -39,8 +40,9 @@ const getCodexAccountId = Effect.gen(function* () { · 32 unmodified lines | |||
| 39 | const upsertAnonymousId = Effect.gen(function* () { | 40 | const upsertAnonymousId = Effect.gen(function* () { |
| 40 | const fileSystem = yield* FileSystem.FileSystem; | 41 | const fileSystem = yield* FileSystem.FileSystem; |
| 41 | const path = yield* Path.Path; | 42 | const path = yield* Path.Path; |
| 43 | const serverConfig = yield* ServerConfig; | ||
| 42 | 44 | ||
| 43 | const anonymousIdPath = path.join(homedir(), ".t3", "telemetry", "anonymous-id"); | 45 | const anonymousIdPath = path.join(serverConfig.stateDir, "anonymous-id"); |
| 44 | const anonymousId = yield* fileSystem.readFileString(anonymousIdPath).pipe( | 46 | const anonymousId = yield* fileSystem.readFileString(anonymousIdPath).pipe( |
| 45 | Effect.catch(() => | 47 | Effect.catch(() => |
| 46 | Effect.gen(function* () { | 48 | Effect.gen(function* () { |