Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

environment.ts

108 lines4.4 KB

1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3​
4import { EnvironmentId, ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
5​
6export const ExecutionEnvironmentPlatformOs = Schema.Literals([
7 "darwin",
8 "linux",
9 "windows",
10 "unknown",
11]);
12export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
13​
14export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
15export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
16​
17export const ExecutionEnvironmentPlatform = Schema.Struct({
18 os: ExecutionEnvironmentPlatformOs,
19 arch: ExecutionEnvironmentPlatformArch,
20});
21export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
22​
23/** How a server can replace itself with another version when asked over RPC:
24 "boot-service" rewrites the systemd user unit and restarts it; "respawn"
25 installs the target version and respawns the foreground process. */
26export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn"]);
27export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
28​
29/** What update path a client should offer for a server: one of the RPC
30 self-update methods above, or "desktop-managed" when the backend's
31 version belongs to the T3 Code desktop app supervising it — updating the
32 app on that machine is the only way to update the server. */
33export const ServerSelfUpdateCapability = Schema.Literals([
34 "boot-service",
35 "respawn",
36 "desktop-managed",
37]);
38export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
39​
40export const ExecutionEnvironmentCapabilities = Schema.Struct({
41 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
42 connectionProbe: Schema.optionalKey(Schema.Boolean),
43 /** Server understands thread.settle / thread.unsettle commands. Absent on
44 pre-settlement servers, so clients treat missing as unsupported and
45 never send the commands under version skew. */
46 threadSettlement: Schema.optionalKey(Schema.Boolean),
47 /** Server understands thread.snooze / thread.unsnooze commands. Same
48 version-skew contract as threadSettlement. */
49 threadSnooze: Schema.optionalKey(Schema.Boolean),
50 /** The update path clients should offer for this server. Absent on
51 servers that must be relaunched manually (dev checkouts, Windows
52 foreground runs, pre-update servers). */
53 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
54});
55export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
56​
57export const ExecutionEnvironmentDescriptor = Schema.Struct({
58 environmentId: EnvironmentId,
59 label: TrimmedNonEmptyString,
60 platform: ExecutionEnvironmentPlatform,
61 serverVersion: TrimmedNonEmptyString,
62 capabilities: ExecutionEnvironmentCapabilities,
63});
64export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
65​
66export const EnvironmentConnectionState = Schema.Literals([
67 "connecting",
68 "connected",
69 "disconnected",
70 "error",
71]);
72export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
73​
74export const RepositoryIdentityLocator = Schema.Struct({
75 source: Schema.Literal("git-remote"),
76 remoteName: TrimmedNonEmptyString,
77 remoteUrl: TrimmedNonEmptyString,
78});
79export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
80​
81export const RepositoryIdentity = Schema.Struct({
82 canonicalKey: TrimmedNonEmptyString,
83 locator: RepositoryIdentityLocator,
84 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
85 displayName: Schema.optionalKey(TrimmedNonEmptyString),
86 provider: Schema.optionalKey(TrimmedNonEmptyString),
87 owner: Schema.optionalKey(TrimmedNonEmptyString),
88 name: Schema.optionalKey(TrimmedNonEmptyString),
89});
90export type RepositoryIdentity = typeof RepositoryIdentity.Type;
91​
92export const ScopedProjectRef = Schema.Struct({
93 environmentId: EnvironmentId,
94 projectId: ProjectId,
95});
96export type ScopedProjectRef = typeof ScopedProjectRef.Type;
97​
98export const ScopedThreadRef = Schema.Struct({
99 environmentId: EnvironmentId,
100 threadId: ThreadId,
101});
102export type ScopedThreadRef = typeof ScopedThreadRef.Type;
103​
104export const ScopedThreadSessionRef = Schema.Struct({
105 environmentId: EnvironmentId,
106 threadId: ThreadId,
107});
108export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;