Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions apps/desktop/src/app/DesktopObservability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ export function makeComponentLogger(component: string): DesktopComponentLogger {
};
}

const readPersistedOtlpTracesUrl: Effect.Effect<
Option.Option<string>,
never,
FileSystem.FileSystem | DesktopEnvironment.DesktopEnvironment
> = Effect.gen(function* () {
const readPersistedOtlpTracesUrl = Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const raw = yield* fileSystem.readFileString(environment.serverSettingsPath).pipe(Effect.option);
Expand Down
6 changes: 1 addition & 5 deletions apps/desktop/src/backend/DesktopBackendConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ const { logWarning: logBackendConfigurationWarning } = DesktopObservability.make
"desktop-backend-configuration",
);

const readPersistedBackendObservabilitySettings: Effect.Effect<
BackendObservabilitySettings,
never,
FileSystem.FileSystem | DesktopEnvironment.DesktopEnvironment
> = Effect.gen(function* () {
const readPersistedBackendObservabilitySettings = Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const exists = yield* fileSystem
Expand Down
6 changes: 1 addition & 5 deletions apps/desktop/src/shell/DesktopShellEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,7 @@ const readLoginShellEnvironment = (
timeout: LOGIN_SHELL_TIMEOUT,
}).pipe(Effect.map((output) => extractEnvironment(output, names)));

const readLaunchctlPath: Effect.Effect<
Option.Option<string>,
never,
ChildProcessSpawner.ChildProcessSpawner
> = runCommandOutput({
const readLaunchctlPath = runCommandOutput({
command: "/bin/launchctl",
args: ["getenv", "PATH"],
timeout: LAUNCHCTL_TIMEOUT,
Expand Down
12 changes: 2 additions & 10 deletions apps/desktop/src/window/DesktopApplicationMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ const dispatchMenuAction = Effect.fn("desktop.menu.dispatchMenuAction")(function
yield* desktopWindow.dispatchMenuAction(action);
});

const checkForUpdatesFromMenu: Effect.Effect<
void,
never,
DesktopUpdates.DesktopUpdates | ElectronDialog.ElectronDialog
> = Effect.gen(function* () {
const checkForUpdatesFromMenu = Effect.gen(function* () {
const updates = yield* DesktopUpdates.DesktopUpdates;
const electronDialog = yield* ElectronDialog.ElectronDialog;
const result = yield* updates.check("menu");
Expand All @@ -65,11 +61,7 @@ const checkForUpdatesFromMenu: Effect.Effect<
}
}).pipe(Effect.withSpan("desktop.menu.checkForUpdates"));

const handleCheckForUpdatesMenuClick: Effect.Effect<
void,
DesktopWindow.DesktopWindowError,
DesktopUpdates.DesktopUpdates | ElectronDialog.ElectronDialog | DesktopWindow.DesktopWindow
> = Effect.gen(function* () {
const handleCheckForUpdatesMenuClick = Effect.gen(function* () {
const updates = yield* DesktopUpdates.DesktopUpdates;
const electronDialog = yield* ElectronDialog.ElectronDialog;
const disabledReason = yield* updates.disabledReason;
Expand Down
18 changes: 7 additions & 11 deletions apps/mobile/src/connection/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ import { Atom } from "effect/unstable/reactivity";
import { runtimeContextLayer } from "../lib/runtime";
import { connectionPlatformLayer } from "./platform";

const providedConnectionPlatformLayer: Layer.Layer<
Layer.Success<typeof connectionPlatformLayer>,
Layer.Error<typeof connectionPlatformLayer>
> = connectionPlatformLayer.pipe(Layer.provide(runtimeContextLayer));
const providedConnectionPlatformLayer = connectionPlatformLayer.pipe(
Layer.provide(runtimeContextLayer),
);

type ConnectionLayerSource =
| typeof Connection.layer
| typeof runtimeContextLayer
| typeof providedConnectionPlatformLayer;
| typeof connectionPlatformLayer;

export const connectionLayer: Layer.Layer<
Layer.Success<ConnectionLayerSource>,
Layer.Error<ConnectionLayerSource>
> = Connection.layer.pipe(
const connectionLayer = Connection.layer.pipe(
Layer.provideMerge(Layer.mergeAll(runtimeContextLayer, providedConnectionPlatformLayer)),
);

export const connectionAtomRuntime: Atom.AtomRuntime<
Layer.Success<typeof connectionLayer>,
Layer.Error<typeof connectionLayer>
Layer.Success<ConnectionLayerSource>,
Layer.Error<ConnectionLayerSource>
> = Atom.runtime(connectionLayer);
13 changes: 5 additions & 8 deletions apps/mobile/src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ type RuntimeLayerSource =
| typeof httpClientLayer
| typeof tracingLayer;

export const runtimeLayer: Layer.Layer<
Layer.Success<RuntimeLayerSource>,
Layer.Error<RuntimeLayerSource>
> = Layer.merge(
const runtimeLayer = Layer.merge(
managedRelayClientLayer(configuredRelayUrl()),
Socket.layerWebSocketConstructorGlobal,
).pipe(
Expand All @@ -35,11 +32,11 @@ export const runtimeLayer: Layer.Layer<
);

export const runtime: ManagedRuntime.ManagedRuntime<
Layer.Success<typeof runtimeLayer>,
Layer.Error<typeof runtimeLayer>
Layer.Success<RuntimeLayerSource>,
Layer.Error<RuntimeLayerSource>
> = ManagedRuntime.make(runtimeLayer);

export const runtimeContextLayer: Layer.Layer<
Layer.Success<typeof runtimeLayer>,
Layer.Error<typeof runtimeLayer>
Layer.Success<RuntimeLayerSource>,
Layer.Error<RuntimeLayerSource>
> = Layer.effectContext(runtime.contextEffect);
2 changes: 1 addition & 1 deletion apps/mobile/src/state/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { createRelayEnvironmentDiscoveryAtoms } from "@t3tools/client-runtime/st

import { connectionAtomRuntime } from "../connection/runtime";

export const relayEnvironmentDiscovery: ReturnType<typeof createRelayEnvironmentDiscoveryAtoms> =
export const relayEnvironmentDiscovery =
createRelayEnvironmentDiscoveryAtoms(connectionAtomRuntime);
6 changes: 1 addition & 5 deletions apps/server/src/mcp/McpSessionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ const make = Effect.acquireRelease(
}),
);

export const layer: Layer.Layer<
McpSessionRegistry,
never,
Crypto.Crypto | ServerEnvironment.ServerEnvironment | HttpServer.HttpServer
> = Layer.effect(McpSessionRegistry, make);
export const layer = Layer.effect(McpSessionRegistry, make);

export const issueActiveMcpCredential = (
request: McpCredentialRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ export const deriveProviderInstanceConfigMap = (
* configs, so the only way the watcher could fail is a settings stream
* tear-down, which logs and exits cleanly.
*/
const SettingsWatcherLive: Layer.Layer<
never,
never,
ProviderInstanceRegistryMutator | ServerSettingsService
> = Layer.effectDiscard(
const SettingsWatcherLive = Layer.effectDiscard(
Effect.gen(function* () {
const mutator = yield* ProviderInstanceRegistryMutator;
const serverSettings = yield* ServerSettingsService;
Expand Down
71 changes: 34 additions & 37 deletions apps/web/src/cloud/dpop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,40 @@ export function writeStoredBrowserDpopKey(
);
}

export const generateBrowserDpopKey: Effect.Effect<BrowserDpopKey, BrowserDpopError> = Effect.gen(
function* () {
const generated = yield* Effect.tryPromise({
try: () =>
crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, [
"sign",
"verify",
]) as Promise<CryptoKeyPair>,
catch: (cause) => dpopError("Could not generate DPoP proof key.", cause),
});
const privateJwk = yield* Effect.tryPromise({
try: () => crypto.subtle.exportKey("jwk", generated.privateKey),
catch: (cause) => dpopError("Could not export DPoP private key.", cause),
});
const publicJwk = yield* Effect.tryPromise({
try: () => crypto.subtle.exportKey("jwk", generated.publicKey),
catch: (cause) => dpopError("Could not export DPoP public key.", cause),
}).pipe(
Effect.flatMap((jwk) => decodeDpopPublicJwk(jwk)),
Effect.mapError((cause) =>
cause instanceof BrowserDpopError
? cause
: dpopError("Generated DPoP public key is invalid.", cause),
),
);
const privateKey = yield* Effect.tryPromise({
try: () =>
importJWK(privateJwk as JWK, "ES256", { extractable: false }) as Promise<CryptoKey>,
catch: (cause) => dpopError("Could not import DPoP private key.", cause),
});
return {
privateKey,
publicJwk,
thumbprint: computeDpopJwkThumbprint(publicJwk),
};
},
);
export const generateBrowserDpopKey = Effect.gen(function* () {
const generated = yield* Effect.tryPromise({
try: () =>
crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, [
"sign",
"verify",
]) as Promise<CryptoKeyPair>,
catch: (cause) => dpopError("Could not generate DPoP proof key.", cause),
});
const privateJwk = yield* Effect.tryPromise({
try: () => crypto.subtle.exportKey("jwk", generated.privateKey),
catch: (cause) => dpopError("Could not export DPoP private key.", cause),
});
const publicJwk = yield* Effect.tryPromise({
try: () => crypto.subtle.exportKey("jwk", generated.publicKey),
catch: (cause) => dpopError("Could not export DPoP public key.", cause),
}).pipe(
Effect.flatMap((jwk) => decodeDpopPublicJwk(jwk)),
Effect.mapError((cause) =>
cause instanceof BrowserDpopError
? cause
: dpopError("Generated DPoP public key is invalid.", cause),
),
);
const privateKey = yield* Effect.tryPromise({
try: () => importJWK(privateJwk as JWK, "ES256", { extractable: false }) as Promise<CryptoKey>,
catch: (cause) => dpopError("Could not import DPoP private key.", cause),
});
return {
privateKey,
publicJwk,
thumbprint: computeDpopJwkThumbprint(publicJwk),
};
});

export function createBrowserDpopProof(input: {
readonly method: string;
Expand Down
18 changes: 7 additions & 11 deletions apps/web/src/connection/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ import { Atom } from "effect/unstable/reactivity";
import { runtimeContextLayer } from "../lib/runtime";
import { connectionPlatformLayer } from "./platform";

const providedConnectionPlatformLayer: Layer.Layer<
Layer.Success<typeof connectionPlatformLayer>,
Layer.Error<typeof connectionPlatformLayer>
> = connectionPlatformLayer.pipe(Layer.provide(runtimeContextLayer));
const providedConnectionPlatformLayer = connectionPlatformLayer.pipe(
Layer.provide(runtimeContextLayer),
);

type ConnectionLayerSource =
| typeof Connection.layer
| typeof runtimeContextLayer
| typeof providedConnectionPlatformLayer;
| typeof connectionPlatformLayer;

export const connectionLayer: Layer.Layer<
Layer.Success<ConnectionLayerSource>,
Layer.Error<ConnectionLayerSource>
> = Connection.layer.pipe(
const connectionLayer = Connection.layer.pipe(
Layer.provideMerge(Layer.mergeAll(runtimeContextLayer, providedConnectionPlatformLayer)),
);

export const connectionAtomRuntime: Atom.AtomRuntime<
Layer.Success<typeof connectionLayer>,
Layer.Error<typeof connectionLayer>
Layer.Success<ConnectionLayerSource>,
Layer.Error<ConnectionLayerSource>
> = Atom.runtime(connectionLayer);
13 changes: 5 additions & 8 deletions apps/web/src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export function __setPrimaryHttpRunnerForTests(runner?: PrimaryHttpEffectRunner)
primaryHttpRunner = runner ?? livePrimaryHttpRunner;
}

export const runtimeLayer: Layer.Layer<
Layer.Success<RuntimeLayerSource>,
Layer.Error<RuntimeLayerSource>
> = Layer.mergeAll(
const runtimeLayer = Layer.mergeAll(
httpClientLayer,
browserCryptoLayer,
Socket.layerWebSocketConstructorGlobal,
Expand All @@ -68,11 +65,11 @@ export const runtimeLayer: Layer.Layer<
);

export const runtime: ManagedRuntime.ManagedRuntime<
Layer.Success<typeof runtimeLayer>,
Layer.Error<typeof runtimeLayer>
Layer.Success<RuntimeLayerSource>,
Layer.Error<RuntimeLayerSource>
> = ManagedRuntime.make(runtimeLayer);

export const runtimeContextLayer: Layer.Layer<
Layer.Success<typeof runtimeLayer>,
Layer.Error<typeof runtimeLayer>
Layer.Success<RuntimeLayerSource>,
Layer.Error<RuntimeLayerSource>
> = Layer.effectContext(runtime.contextEffect);
9 changes: 2 additions & 7 deletions packages/client-runtime/src/rpc/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ORCHESTRATION_WS_METHODS, type ServerConfig, WS_METHODS } from "@t3tools/contracts";
import { ORCHESTRATION_WS_METHODS, WS_METHODS } from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import type * as Duration from "effect/Duration";
Expand All @@ -9,7 +9,6 @@ import * as Stream from "effect/Stream";
import * as SubscriptionRef from "effect/SubscriptionRef";
import { RpcClientError } from "effect/unstable/rpc";

import type { ConnectionAttemptError } from "../connection/model.ts";
import { EnvironmentSupervisor } from "../connection/supervisor.ts";
import type { WsRpcProtocolClient } from "../rpc/protocol.ts";

Expand Down Expand Up @@ -237,11 +236,7 @@ export function subscribe<TTag extends EnvironmentSubscriptionRpcTag>(
);
}

export const config: Effect.Effect<
ServerConfig,
EnvironmentRpcUnavailableError | ConnectionAttemptError,
EnvironmentSupervisor
> = Effect.gen(function* () {
export const config = Effect.gen(function* () {
const session = yield* currentSession();
return yield* session.initialConfig;
}).pipe(Effect.withSpan("EnvironmentRpc.config"));
6 changes: 1 addition & 5 deletions packages/tailscale/src/tailscale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ export const parseTailscaleStatus = (
}),
);

export const readTailscaleStatus: Effect.Effect<
TailscaleStatus,
TailscaleCommandError | TailscaleStatusParseError,
ChildProcessSpawner.ChildProcessSpawner
> = Effect.gen(function* () {
export const readTailscaleStatus = Effect.gen(function* () {
const args = ["status", "--json"];
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const hostPlatform = yield* HostProcessPlatform;
Expand Down
Loading