Open History to see the last commit
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 * With `expectedEnvironmentId`, a server that is a different machine fails
62 * before its one-time pairing credential is spent.
63 */
64 readonly provision: (
65 target: DesktopSshEnvironmentTarget,
66 expectedEnvironmentId?: EnvironmentId,
67 ) => Effect.Effect<ProvisionedSshEnvironment, ConnectionAttemptError>;
68 /**
69 * Starts or reuses the remote server for a saved connection. Returns
70 * `bearerToken`, the token this client saved from an earlier pairing, while
71 * the host still accepts it with the standard scopes, and pairs again only
72 * when it does not, so a reconnect adds no session on the host.
73 */
74 readonly prepare: (input: {
75 readonly connectionId: string;
76 readonly expectedEnvironmentId: EnvironmentId;
77 readonly target: DesktopSshEnvironmentTarget;
78 readonly bearerToken?: string;
79 }) => Effect.Effect<PreparedSshEnvironment, ConnectionAttemptError>;
80 readonly disconnect: (
81 target: DesktopSshEnvironmentTarget,
82 ) => Effect.Effect<void, ConnectionAttemptError>;
83 }
84>()("@t3tools/client-runtime/platform/capabilities/SshEnvironmentGateway") {}