1import {
2 type AuthClientPresentationMetadata,
3 type DesktopSshEnvironmentBootstrap,
4 type DesktopSshEnvironmentTarget,
5 EnvironmentId,
6} from "@t3tools/contracts";
7import * as Context from "effect/Context";
8import type * as Effect from "effect/Effect";
9import type * as Option from "effect/Option";
10
11import type { ConnectionAttemptError } from "../connection/model.ts";
12
13export interface PreparedSshEnvironment {
14 readonly bootstrap: DesktopSshEnvironmentBootstrap;
15 readonly bearerToken: string;
16}
17
18export interface ProvisionedSshEnvironment extends PreparedSshEnvironment {
19 readonly environmentId: EnvironmentId;
20 readonly label: string;
21}
22
23/** Stable for one signed-in session, including same-account token refreshes. */
24export interface CloudSessionIdentity {
25 readonly accountId: string;
26}
27
28export class CloudSession extends Context.Service<
29 CloudSession,
30 {
31 readonly identity: Effect.Effect<Option.Option<CloudSessionIdentity>>;
32 readonly clerkToken: Effect.Effect<string, ConnectionAttemptError>;
33 }
34>()("@t3tools/client-runtime/platform/capabilities/CloudSession") {}
35
36export class RelayDeviceIdentity extends Context.Service<
37 RelayDeviceIdentity,
38 {
39 readonly deviceId: Effect.Effect<Option.Option<string>, ConnectionAttemptError>;
40 }
41>()("@t3tools/client-runtime/platform/capabilities/RelayDeviceIdentity") {}
42
43export class ClientPresentation extends Context.Service<
44 ClientPresentation,
45 {
46 readonly metadata: AuthClientPresentationMetadata;
47 }
48>()("@t3tools/client-runtime/platform/capabilities/ClientPresentation") {}
49
50export class PrimaryEnvironmentAuth extends Context.Service<
51 PrimaryEnvironmentAuth,
52 {
53 readonly bearerToken: Effect.Effect<Option.Option<string>, ConnectionAttemptError>;
54 }
55>()("@t3tools/client-runtime/platform/capabilities/PrimaryEnvironmentAuth") {}
56
57export class SshEnvironmentGateway extends Context.Service<
58 SshEnvironmentGateway,
59 {
60 /**
61 * Starts or reuses the remote server and pairs with it. With
62 * `expectedEnvironmentId`, a server that is a different machine fails
63 * before its one-time pairing credential is spent.
64 */
65 readonly provision: (
66 target: DesktopSshEnvironmentTarget,
67 expectedEnvironmentId?: EnvironmentId,
68 ) => Effect.Effect<ProvisionedSshEnvironment, ConnectionAttemptError>;
69 readonly prepare: (input: {
70 readonly connectionId: string;
71 readonly expectedEnvironmentId: EnvironmentId;
72 readonly target: DesktopSshEnvironmentTarget;
73 }) => Effect.Effect<PreparedSshEnvironment, ConnectionAttemptError>;
74 readonly disconnect: (
75 target: DesktopSshEnvironmentTarget,
76 ) => Effect.Effect<void, ConnectionAttemptError>;
77 }
78>()("@t3tools/client-runtime/platform/capabilities/SshEnvironmentGateway") {}
79
80export class HostedAuthAccess extends Context.Service<
81 HostedAuthAccess,
82 {
83 readonly headers: (
84 serverUrl: string,
85 ) => Effect.Effect<Record<string, string>, ConnectionAttemptError>;
86 }
87>()("@t3tools/client-runtime/platform/capabilities/HostedAuthAccess") {}