| author | |
| committer | |
| log | 477b4f9d0ec7e7a48cb74357ea00ecf7bddfc62f |
| tree | 9ab54bd81a91cda272bd193f8a0ae5e1aaee94f7 |
| parent | d5d88270f0d9cdc9797a650ed6ccace28cb1dc39 |
- 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 wiring4 files changed, 7 insertions(+), 3 deletions(-)
apps/server/src/index.ts-2| ... | @@ -9,12 +9,10 @@ import { Command } from "effect/unstable/cli"; | ... | @@ -9,12 +9,10 @@ import { Command } from "effect/unstable/cli"; |
| 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), |
apps/server/src/main.test.ts+2| ... | @@ -5,6 +5,7 @@ import * as ConfigProvider from "effect/ConfigProvider"; | ... | @@ -5,6 +5,7 @@ import * as ConfigProvider from "effect/ConfigProvider"; |
| 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( | ... | @@ -52,6 +53,7 @@ const testLayer = Layer.mergeAll( |
| 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 |
apps/server/src/main.ts+2| ... | @@ -23,6 +23,7 @@ import { makeServerProviderLayer, makeServerRuntimeServicesLayer } from "./serve | ... | @@ -23,6 +23,7 @@ import { makeServerProviderLayer, makeServerRuntimeServicesLayer } from "./serve |
| 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) => | ... | @@ -197,6 +198,7 @@ const LayerLive = (input: CliInput) => |
| 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 |
apps/server/src/telemetry/Identify.ts+3-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -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* () { | ... | @@ -39,8 +40,9 @@ const getCodexAccountId = Effect.gen(function* () { |
| 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* () { |