@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 46 lines 1.52 KB
Raw
1 import type { ServerSettings, ServerSettingsError } from "@t3tools/contracts";
2 import * as Effect from "effect/Effect";
3 import * as Equal from "effect/Equal";
4 import * as Stream from "effect/Stream";
5
6 import * as ProviderHost from "./ProviderHost.ts";
7
8 export interface ProviderSnapshotSettings<Settings> {
9 readonly provider: Settings;
10 readonly enableProviderUpdateChecks: boolean;
11 }
12
13 function makeProviderSnapshotSettings<Settings>(
14 provider: Settings,
15 settings: ServerSettings,
16 ): ProviderSnapshotSettings<Settings> {
17 return {
18 provider,
19 enableProviderUpdateChecks: settings.enableProviderUpdateChecks,
20 };
21 }
22
23 export function haveProviderSnapshotSettingsChanged<Settings>(
24 previous: ProviderSnapshotSettings<Settings>,
25 next: ProviderSnapshotSettings<Settings>,
26 ): boolean {
27 return !Equal.equals(previous, next);
28 }
29
30 export const makeProviderSnapshotSettingsSource = Effect.fn(
31 "snapshotSettings.makeProviderSnapshotSettingsSource",
32 )(function* <Settings>(provider: Settings): Effect.fn.Return<
33 {
34 readonly getSettings: Effect.Effect<ProviderSnapshotSettings<Settings>, ServerSettingsError>;
35 readonly streamSettings: Stream.Stream<ProviderSnapshotSettings<Settings>>;
36 },
37 never,
38 ProviderHost.ProviderHost
39 > {
40 const { settings } = yield* ProviderHost.ProviderHost;
41 const mapSettings = (current: ServerSettings) => makeProviderSnapshotSettings(provider, current);
42 return {
43 getSettings: settings.get.pipe(Effect.map(mapSettings)),
44 streamSettings: settings.changes.pipe(Stream.map(mapSettings)),
45 };
46 });