@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 95 lines 3.43 KB
Raw
1 import {
2 type AuthClientPresentationMetadata,
3 type DesktopSshEnvironmentBootstrap,
4 type DesktopSshEnvironmentTarget,
5 EnvironmentId,
6 } from "@t3tools/contracts";
7 import * as Context from "effect/Context";
8 import * as Effect from "effect/Effect";
9 import type * as Option from "effect/Option";
10
11 import type { ConnectionAttemptError } from "../connection/model.ts";
12
13 export interface PreparedSshEnvironment {
14 readonly bootstrap: DesktopSshEnvironmentBootstrap;
15 readonly bearerToken: string;
16 }
17
18 export 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. */
24 export interface CloudSessionIdentity {
25 readonly accountId: string;
26 }
27
28 export 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
36 export 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
43 /**
44 * A random id this client keeps across launches. Environments it connects to
45 * record its hash, so two environments opened from one device share an owner
46 * in analytics even when nobody is signed in.
47 */
48 export class AnalyticsDevice extends Context.Reference<{
49 readonly id: Effect.Effect<Option.Option<string>>;
50 }>("@t3tools/client-runtime/platform/capabilities/AnalyticsDevice", {
51 defaultValue: () => ({ id: Effect.succeedNone }),
52 }) {}
53
54 export class ClientPresentation extends Context.Service<
55 ClientPresentation,
56 {
57 readonly metadata: AuthClientPresentationMetadata;
58 }
59 >()("@t3tools/client-runtime/platform/capabilities/ClientPresentation") {}
60
61 export class PrimaryEnvironmentAuth extends Context.Service<
62 PrimaryEnvironmentAuth,
63 {
64 readonly bearerToken: Effect.Effect<Option.Option<string>, ConnectionAttemptError>;
65 }
66 >()("@t3tools/client-runtime/platform/capabilities/PrimaryEnvironmentAuth") {}
67
68 export class SshEnvironmentGateway extends Context.Service<
69 SshEnvironmentGateway,
70 {
71 /**
72 * With `expectedEnvironmentId`, a server that is a different machine fails
73 * before its one-time pairing credential is spent.
74 */
75 readonly provision: (
76 target: DesktopSshEnvironmentTarget,
77 expectedEnvironmentId?: EnvironmentId,
78 ) => Effect.Effect<ProvisionedSshEnvironment, ConnectionAttemptError>;
79 /**
80 * Starts or reuses the remote server for a saved connection. Returns
81 * `bearerToken`, the token this client saved from an earlier pairing, while
82 * the host still accepts it with the standard scopes, and pairs again only
83 * when it does not, so a reconnect adds no session on the host.
84 */
85 readonly prepare: (input: {
86 readonly connectionId: string;
87 readonly expectedEnvironmentId: EnvironmentId;
88 readonly target: DesktopSshEnvironmentTarget;
89 readonly bearerToken?: string;
90 }) => Effect.Effect<PreparedSshEnvironment, ConnectionAttemptError>;
91 readonly disconnect: (
92 target: DesktopSshEnvironmentTarget,
93 ) => Effect.Effect<void, ConnectionAttemptError>;
94 }
95 >()("@t3tools/client-runtime/platform/capabilities/SshEnvironmentGateway") {}