@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 35 lines 1.16 KB
Raw
1 import type { EnvironmentId as EnvironmentIdType } from "@t3tools/contracts";
2 import * as Effect from "effect/Effect";
3 import * as Stream from "effect/Stream";
4 import * as EnvironmentRegistry from "../connection/registry.ts";
5 import type * as EnvironmentSupervisor from "../connection/supervisor.ts";
6
7 export function runStreamInEnvironment<A, E, R>(
8 environmentId: EnvironmentIdType,
9 stream: Stream.Stream<A, E, R>,
10 ): Stream.Stream<
11 A,
12 E | EnvironmentRegistry.EnvironmentNotRegisteredError,
13 EnvironmentRegistry.EnvironmentRegistry | Exclude<R, EnvironmentSupervisor.EnvironmentSupervisor>
14 > {
15 return Stream.unwrap(
16 EnvironmentRegistry.EnvironmentRegistry.pipe(
17 Effect.map((registry) => registry.runStream(environmentId, stream)),
18 ),
19 );
20 }
21
22 export function followStreamInEnvironment<A, E, R>(
23 environmentId: EnvironmentIdType,
24 stream: Stream.Stream<A, E, R>,
25 ): Stream.Stream<
26 A,
27 E,
28 EnvironmentRegistry.EnvironmentRegistry | Exclude<R, EnvironmentSupervisor.EnvironmentSupervisor>
29 > {
30 return Stream.unwrap(
31 EnvironmentRegistry.EnvironmentRegistry.pipe(
32 Effect.map((registry) => registry.followStream(environmentId, stream)),
33 ),
34 );
35 }