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, 03:37 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | import { AcpRegistryUrlAuthAction } from "./acpRegistry.ts"; |
| 4 | import { |
| 5 | type EnvironmentMachineKind, |
| 6 | ExecutionEnvironmentDescriptor, |
| 7 | ServerSelfUpdateMethod, |
| 8 | } from "./environment.ts"; |
| 9 | import { AuthClientPresentationMetadata, ServerAuthDescriptor } from "./auth.ts"; |
| 10 | import { |
| 11 | ForwardCompatibleArray, |
| 12 | IsoDateTime, |
| 13 | NonNegativeInt, |
| 14 | PositiveInt, |
| 15 | ProjectId, |
| 16 | ThreadId, |
| 17 | TrimmedNonEmptyString, |
| 18 | } from "./baseSchemas.ts"; |
| 19 | import { |
| 20 | KeybindingCommand, |
| 21 | KeybindingValue, |
| 22 | KeybindingWhen, |
| 23 | ResolvedKeybindingsConfig, |
| 24 | } from "./keybindings.ts"; |
| 25 | import { EditorId, FileManagerRevealKind, RemoteOpenTarget } from "./editor.ts"; |
| 26 | import { ManagedPolicySummary } from "./managedPolicy.ts"; |
| 27 | import { ModelCapabilities, ProviderOptionDescriptor } from "./model.ts"; |
| 28 | import { RuntimeMode } from "./providerPolicy.ts"; |
| 29 | import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts"; |
| 30 | import { ServerProviderUsageLimits, UsageLimitSourceSnapshots } from "./providerUsageLimits.ts"; |
| 31 | import { ServerSettings } from "./settings.ts"; |
| 32 | import { DesktopUpdateChannelSchema } from "./ipc.ts"; |
| 33 | |
| 34 | const KeybindingsMalformedConfigIssue = Schema.Struct({ |
| 35 | kind: Schema.Literal("keybindings.malformed-config"), |
| 36 | message: TrimmedNonEmptyString, |
| 37 | }); |
| 38 | |
| 39 | const KeybindingsInvalidEntryIssue = Schema.Struct({ |
| 40 | kind: Schema.Literal("keybindings.invalid-entry"), |
| 41 | message: TrimmedNonEmptyString, |
| 42 | index: Schema.Number, |
| 43 | }); |
| 44 | |
| 45 | export const ServerConfigIssue = Schema.Union([ |
| 46 | KeybindingsMalformedConfigIssue, |
| 47 | KeybindingsInvalidEntryIssue, |
| 48 | ]); |
| 49 | export type ServerConfigIssue = typeof ServerConfigIssue.Type; |
| 50 | |
| 51 | const ServerConfigIssues = ForwardCompatibleArray(ServerConfigIssue); |
| 52 | |
| 53 | export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]); |
| 54 | export type ServerProviderState = typeof ServerProviderState.Type; |
| 55 | |
| 56 | export const ServerProviderAuthStatus = Schema.Literals([ |
| 57 | "authenticated", |
| 58 | "unauthenticated", |
| 59 | "unknown", |
| 60 | ]); |
| 61 | export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type; |
| 62 | |
| 63 | export const ServerProviderAuth = Schema.Struct({ |
| 64 | status: ServerProviderAuthStatus, |
| 65 | type: Schema.optional(TrimmedNonEmptyString), |
| 66 | label: Schema.optional(TrimmedNonEmptyString), |
| 67 | email: Schema.optional(TrimmedNonEmptyString), |
| 68 | action: Schema.optional(AcpRegistryUrlAuthAction), |
| 69 | canLogout: Schema.optional(Schema.Boolean), |
| 70 | subscriptionSharing: Schema.optional(Schema.Boolean), |
| 71 | profileId: Schema.optional(TrimmedNonEmptyString), |
| 72 | workspaceId: Schema.optional(TrimmedNonEmptyString), |
| 73 | /** Origin of the custom endpoint the instance sends its requests to. */ |
| 74 | endpoint: Schema.optional(TrimmedNonEmptyString), |
| 75 | }); |
| 76 | export type ServerProviderAuth = typeof ServerProviderAuth.Type; |
| 77 | |
| 78 | export const ServerProviderModel = Schema.Struct({ |
| 79 | slug: TrimmedNonEmptyString, |
| 80 | name: TrimmedNonEmptyString, |
| 81 | shortName: Schema.optional(TrimmedNonEmptyString), |
| 82 | subProvider: Schema.optional(TrimmedNonEmptyString), |
| 83 | aliases: Schema.optional(Schema.Array(TrimmedNonEmptyString)), |
| 84 | badge: Schema.optional(Schema.Literal("new")), |
| 85 | isCustom: Schema.Boolean, |
| 86 | isDefault: Schema.optional(Schema.Boolean), |
| 87 | isLegacy: Schema.optional(Schema.Boolean), |
| 88 | // False when the provider can run this model in sessions but not for |
| 89 | // application text generation. Absent means supported. |
| 90 | supportsTextGeneration: Schema.optional(Schema.Boolean), |
| 91 | capabilities: Schema.NullOr(ModelCapabilities), |
| 92 | }); |
| 93 | export type ServerProviderModel = typeof ServerProviderModel.Type; |
| 94 | |
| 95 | /** A backend a provider's models run on, such as one of fx's. */ |
| 96 | export const ServerProviderSubProvider = Schema.Struct({ |
| 97 | name: TrimmedNonEmptyString, |
| 98 | /** Why none of its models can run now, such as a signed-out backend. */ |
| 99 | unavailableReason: Schema.optional(TrimmedNonEmptyString), |
| 100 | }); |
| 101 | export type ServerProviderSubProvider = typeof ServerProviderSubProvider.Type; |
| 102 | |
| 103 | export const ServerProviderUpdateRequiredModel = Schema.Struct({ |
| 104 | slug: TrimmedNonEmptyString, |
| 105 | name: TrimmedNonEmptyString, |
| 106 | badge: Schema.optional(Schema.Literal("new")), |
| 107 | minVersion: TrimmedNonEmptyString, |
| 108 | }); |
| 109 | export type ServerProviderUpdateRequiredModel = typeof ServerProviderUpdateRequiredModel.Type; |
| 110 | |
| 111 | export const ServerProviderSlashCommandInput = Schema.Struct({ |
| 112 | hint: TrimmedNonEmptyString, |
| 113 | }); |
| 114 | export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type; |
| 115 | |
| 116 | export const ServerProviderSlashCommand = Schema.Struct({ |
| 117 | name: TrimmedNonEmptyString, |
| 118 | description: Schema.optional(TrimmedNonEmptyString), |
| 119 | input: Schema.optional(ServerProviderSlashCommandInput), |
| 120 | }); |
| 121 | export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type; |
| 122 | |
| 123 | export const ServerProviderSkill = Schema.Struct({ |
| 124 | name: TrimmedNonEmptyString, |
| 125 | description: Schema.optional(TrimmedNonEmptyString), |
| 126 | path: TrimmedNonEmptyString, |
| 127 | scope: Schema.optional(TrimmedNonEmptyString), |
| 128 | enabled: Schema.Boolean, |
| 129 | displayName: Schema.optional(TrimmedNonEmptyString), |
| 130 | shortDescription: Schema.optional(TrimmedNonEmptyString), |
| 131 | /** Claude disable-model-invocation: only users can invoke; composers must offer a slash command. */ |
| 132 | userInvocationOnly: Schema.optional(Schema.Boolean), |
| 133 | /** Claude user-invocable:false: only agents can invoke; composers must hide the slash command. */ |
| 134 | userInvocable: Schema.optional(Schema.Boolean), |
| 135 | }); |
| 136 | export type ServerProviderSkill = typeof ServerProviderSkill.Type; |
| 137 | |
| 138 | export const ServerProviderWorkspaceSnapshot = Schema.Struct({ |
| 139 | cwd: TrimmedNonEmptyString, |
| 140 | checkedAt: IsoDateTime, |
| 141 | slashCommands: Schema.Array(ServerProviderSlashCommand), |
| 142 | slashCommandsPending: Schema.optional(Schema.Boolean), |
| 143 | skills: Schema.Array(ServerProviderSkill), |
| 144 | optionDescriptors: Schema.optional(Schema.Array(ProviderOptionDescriptor)), |
| 145 | // Absent means the provider's machine `models`, which keeps most snapshots small. |
| 146 | models: Schema.optional(Schema.Array(ServerProviderModel)), |
| 147 | modelsPending: Schema.optional(Schema.Boolean), |
| 148 | }); |
| 149 | export type ServerProviderWorkspaceSnapshot = typeof ServerProviderWorkspaceSnapshot.Type; |
| 150 | |
| 151 | export const PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS = 5 * 60_000; |
| 152 | |
| 153 | export function isProviderWorkspaceSnapshotCurrent( |
| 154 | snapshot: Pick<ServerProviderWorkspaceSnapshot, "checkedAt">, |
| 155 | nowMs: number, |
| 156 | ): boolean { |
| 157 | return nowMs - Date.parse(snapshot.checkedAt) < PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS; |
| 158 | } |
| 159 | |
| 160 | /** A pending snapshot keeps what it found before and is rescanned before its TTL. */ |
| 161 | export function isProviderWorkspaceSnapshotPending( |
| 162 | snapshot: Pick<ServerProviderWorkspaceSnapshot, "slashCommandsPending" | "modelsPending">, |
| 163 | ): boolean { |
| 164 | return snapshot.slashCommandsPending === true || snapshot.modelsPending === true; |
| 165 | } |
| 166 | |
| 167 | /** Unavailable snapshots must set installed and enabled false. */ |
| 168 | export const ServerProviderAvailability = Schema.Literals(["available", "unavailable"]); |
| 169 | export type ServerProviderAvailability = typeof ServerProviderAvailability.Type; |
| 170 | |
| 171 | export const ServerProviderContinuation = Schema.Struct({ |
| 172 | groupKey: TrimmedNonEmptyString, |
| 173 | }); |
| 174 | export type ServerProviderContinuation = typeof ServerProviderContinuation.Type; |
| 175 | |
| 176 | export const ServerProviderCompatibilityStatus = Schema.Literals([ |
| 177 | "unknown", |
| 178 | "supported", |
| 179 | "graceful", |
| 180 | "unsupported", |
| 181 | "broken", |
| 182 | ]); |
| 183 | export const ServerProviderCompatibilityAdvisory = Schema.Struct({ |
| 184 | status: ServerProviderCompatibilityStatus, |
| 185 | latestVersionStatus: Schema.optionalKey(ServerProviderCompatibilityStatus), |
| 186 | message: Schema.NullOr(TrimmedNonEmptyString), |
| 187 | recommendedVersion: Schema.NullOr(TrimmedNonEmptyString), |
| 188 | recommendedRange: Schema.NullOr(TrimmedNonEmptyString), |
| 189 | }); |
| 190 | export type ServerProviderCompatibilityAdvisory = typeof ServerProviderCompatibilityAdvisory.Type; |
| 191 | |
| 192 | export const ServerProviderVersionAdvisoryStatus = Schema.Literals([ |
| 193 | "unknown", |
| 194 | "current", |
| 195 | "behind_latest", |
| 196 | ]); |
| 197 | export type ServerProviderVersionAdvisoryStatus = typeof ServerProviderVersionAdvisoryStatus.Type; |
| 198 | |
| 199 | export const ServerProviderVersionAdvisory = Schema.Struct({ |
| 200 | status: ServerProviderVersionAdvisoryStatus, |
| 201 | currentVersion: Schema.NullOr(TrimmedNonEmptyString), |
| 202 | latestVersion: Schema.NullOr(TrimmedNonEmptyString), |
| 203 | updateCommand: Schema.NullOr(TrimmedNonEmptyString), |
| 204 | canUpdate: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), |
| 205 | canInstallVersion: Schema.optionalKey(Schema.Boolean), |
| 206 | checkedAt: Schema.NullOr(IsoDateTime), |
| 207 | message: Schema.NullOr(TrimmedNonEmptyString), |
| 208 | }); |
| 209 | export type ServerProviderVersionAdvisory = typeof ServerProviderVersionAdvisory.Type; |
| 210 | |
| 211 | export const ServerProviderUpdateStatus = Schema.Literals([ |
| 212 | "idle", |
| 213 | "queued", |
| 214 | "running", |
| 215 | "succeeded", |
| 216 | "failed", |
| 217 | "unchanged", |
| 218 | ]); |
| 219 | export type ServerProviderUpdateStatus = typeof ServerProviderUpdateStatus.Type; |
| 220 | |
| 221 | export const ServerProviderUpdateState = Schema.Struct({ |
| 222 | status: ServerProviderUpdateStatus, |
| 223 | startedAt: Schema.NullOr(IsoDateTime), |
| 224 | finishedAt: Schema.NullOr(IsoDateTime), |
| 225 | message: Schema.NullOr(TrimmedNonEmptyString), |
| 226 | output: Schema.NullOr(Schema.String.check(Schema.isMaxLength(10_000))), |
| 227 | }); |
| 228 | export type ServerProviderUpdateState = typeof ServerProviderUpdateState.Type; |
| 229 | |
| 230 | export const ServerProvider = Schema.Struct({ |
| 231 | // Only instanceId is stable enough for provider routing. |
| 232 | instanceId: ProviderInstanceId, |
| 233 | driver: ProviderDriverKind, |
| 234 | displayName: Schema.optional(TrimmedNonEmptyString), |
| 235 | accentColor: Schema.optional(TrimmedNonEmptyString), |
| 236 | // Validate driver-supplied remote icons against the driver's trusted origin. |
| 237 | iconUrl: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))), |
| 238 | badgeLabel: Schema.optional(TrimmedNonEmptyString), |
| 239 | continuation: Schema.optional(ServerProviderContinuation), |
| 240 | showInteractionModeToggle: Schema.optional(Schema.Boolean), |
| 241 | reportsContextWindow: Schema.optional(Schema.Boolean), |
| 242 | supportedRuntimeModes: Schema.optional(ForwardCompatibleArray(RuntimeMode)), |
| 243 | supportsConversationRollback: Schema.optional(Schema.Boolean), |
| 244 | supportsTextGeneration: Schema.optional(Schema.Boolean), |
| 245 | setup: Schema.optional( |
| 246 | Schema.Struct({ |
| 247 | canAuthenticate: Schema.Boolean, |
| 248 | canInstall: Schema.Boolean, |
| 249 | documentationUrl: Schema.optionalKey(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))), |
| 250 | }), |
| 251 | ), |
| 252 | nativeSessions: Schema.optional( |
| 253 | Schema.Struct({ |
| 254 | canList: Schema.Boolean, |
| 255 | canLoad: Schema.Boolean, |
| 256 | canResume: Schema.Boolean, |
| 257 | canDelete: Schema.optional(Schema.Boolean), |
| 258 | }), |
| 259 | ), |
| 260 | configurableProviders: Schema.optional(Schema.Boolean), |
| 261 | runtimePaths: Schema.optionalKey( |
| 262 | Schema.Struct({ |
| 263 | homePath: TrimmedNonEmptyString, |
| 264 | shadowHomePath: Schema.NullOr(TrimmedNonEmptyString), |
| 265 | }), |
| 266 | ), |
| 267 | enabled: Schema.Boolean, |
| 268 | installed: Schema.Boolean, |
| 269 | version: Schema.NullOr(TrimmedNonEmptyString), |
| 270 | // Version reported by the installed CLI for a local provider with a separate |
| 271 | // server. Null means unknown; absence keeps legacy snapshots on `version`. |
| 272 | installedVersion: Schema.optionalKey(Schema.NullOr(TrimmedNonEmptyString)), |
| 273 | status: ServerProviderState, |
| 274 | auth: ServerProviderAuth, |
| 275 | checkedAt: IsoDateTime, |
| 276 | message: Schema.optional(TrimmedNonEmptyString), |
| 277 | availability: Schema.optional(ServerProviderAvailability), |
| 278 | unavailableReason: Schema.optional(TrimmedNonEmptyString), |
| 279 | models: Schema.Array(ServerProviderModel), |
| 280 | // Pickers group `models` under these, in order, by `subProvider`. |
| 281 | subProviders: Schema.optional(Schema.Array(ServerProviderSubProvider)), |
| 282 | // Set for the one failed check that follows a ready one: pickers keep offering `models`. |
| 283 | modelsRetained: Schema.optionalKey(Schema.Boolean), |
| 284 | // Kept apart from `models` so clients that predate it never offer them. |
| 285 | updateRequiredModels: Schema.optionalKey(Schema.Array(ServerProviderUpdateRequiredModel)), |
| 286 | slashCommands: Schema.Array(ServerProviderSlashCommand).pipe( |
| 287 | Schema.withDecodingDefault(Effect.succeed([])), |
| 288 | ), |
| 289 | skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))), |
| 290 | workspaceSnapshots: Schema.optionalKey(Schema.Array(ServerProviderWorkspaceSnapshot)), |
| 291 | /** |
| 292 | * Set when the server rescanned a workspace after a session start and its skills or commands |
| 293 | * changed. Clients holding fetched workspace snapshots for this provider fetch them again. |
| 294 | */ |
| 295 | workspaceRescannedAt: Schema.optionalKey(IsoDateTime), |
| 296 | usageLimits: Schema.optional(ServerProviderUsageLimits), |
| 297 | versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory), |
| 298 | compatibilityAdvisory: Schema.optionalKey(ServerProviderCompatibilityAdvisory), |
| 299 | updateState: Schema.optionalKey(ServerProviderUpdateState), |
| 300 | /** |
| 301 | * Stands for the machine slash commands and skills, which are then left out. Sent to clients |
| 302 | * that ask for catalog digests; they load both lists with their next cwd snapshot. |
| 303 | */ |
| 304 | catalogDigest: Schema.optionalKey(TrimmedNonEmptyString), |
| 305 | /** Set by the client, never sent: the `catalogDigest` its slash commands and skills belong to. */ |
| 306 | loadedCatalogDigest: Schema.optionalKey(TrimmedNonEmptyString), |
| 307 | }); |
| 308 | export type ServerProvider = typeof ServerProvider.Type; |
| 309 | |
| 310 | /** A provider without the lists that equal the ones its reader already holds. */ |
| 311 | export const ServerProviderDelta = ServerProvider.mapFields((fields) => ({ |
| 312 | ...fields, |
| 313 | models: Schema.optionalKey(fields.models), |
| 314 | // Declared again without the decoding default, which would read as a change to an empty list. |
| 315 | slashCommands: Schema.optionalKey(Schema.Array(ServerProviderSlashCommand)), |
| 316 | skills: Schema.optionalKey(Schema.Array(ServerProviderSkill)), |
| 317 | })); |
| 318 | export type ServerProviderDelta = typeof ServerProviderDelta.Type; |
| 319 | |
| 320 | const sameJson = (left: unknown, right: unknown) => |
| 321 | left === right || JSON.stringify(left) === JSON.stringify(right); |
| 322 | |
| 323 | /** Leaves each provider's models, slash commands, and skills out when `previous` has the same. */ |
| 324 | export function serverProviderDeltas( |
| 325 | previous: ReadonlyArray<ServerProvider>, |
| 326 | next: ReadonlyArray<ServerProvider>, |
| 327 | ): ServerProviderDelta[] { |
| 328 | const held = new Map(previous.map((provider) => [provider.instanceId, provider])); |
| 329 | return next.map((provider) => { |
| 330 | const base = held.get(provider.instanceId); |
| 331 | if (base === undefined) return provider; |
| 332 | const { models, slashCommands, skills, ...rest } = provider; |
| 333 | return { |
| 334 | ...rest, |
| 335 | ...(sameJson(base.models, models) ? {} : { models }), |
| 336 | ...(sameJson(base.slashCommands, slashCommands) ? {} : { slashCommands }), |
| 337 | ...(sameJson(base.skills, skills) ? {} : { skills }), |
| 338 | }; |
| 339 | }); |
| 340 | } |
| 341 | |
| 342 | /** Rebuilds the provider list `serverProviderDeltas` was made from. */ |
| 343 | export function applyServerProviderDeltas( |
| 344 | previous: ReadonlyArray<ServerProvider>, |
| 345 | deltas: ReadonlyArray<ServerProviderDelta>, |
| 346 | ): ServerProvider[] { |
| 347 | const held = new Map(previous.map((provider) => [provider.instanceId, provider])); |
| 348 | return deltas.flatMap((delta) => { |
| 349 | const base = held.get(delta.instanceId); |
| 350 | const models = delta.models ?? base?.models; |
| 351 | const slashCommands = delta.slashCommands ?? base?.slashCommands; |
| 352 | const skills = delta.skills ?? base?.skills; |
| 353 | // A list this reader never held cannot be rebuilt; drop the provider like an unreadable one. |
| 354 | return models && slashCommands && skills ? [{ ...delta, models, slashCommands, skills }] : []; |
| 355 | }); |
| 356 | } |
| 357 | |
| 358 | export const ServerProviders = ForwardCompatibleArray(ServerProvider); |
| 359 | export type ServerProviders = typeof ServerProviders.Type; |
| 360 | |
| 361 | export const isProviderAvailable = (snapshot: ServerProvider): boolean => |
| 362 | snapshot.availability !== "unavailable"; |
| 363 | |
| 364 | /** Legacy producers omit this field and support text generation. */ |
| 365 | export const isProviderTextGenerationCapable = (snapshot: ServerProvider): boolean => |
| 366 | snapshot.supportsTextGeneration !== false; |
| 367 | |
| 368 | export const OtlpEndpointSource = Schema.Literals(["environment", "bootstrap", "settings"]); |
| 369 | export type OtlpEndpointSource = typeof OtlpEndpointSource.Type; |
| 370 | |
| 371 | export const ServerObservability = Schema.Struct({ |
| 372 | logsDirectoryPath: TrimmedNonEmptyString, |
| 373 | localTracingEnabled: Schema.Boolean, |
| 374 | otlpTracesUrl: Schema.optional(TrimmedNonEmptyString), |
| 375 | otlpTracesSource: Schema.optional(OtlpEndpointSource), |
| 376 | otlpTracesVariable: Schema.optional(TrimmedNonEmptyString), |
| 377 | otlpTracesEnabled: Schema.Boolean, |
| 378 | otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString), |
| 379 | otlpMetricsSource: Schema.optional(OtlpEndpointSource), |
| 380 | otlpMetricsVariable: Schema.optional(TrimmedNonEmptyString), |
| 381 | otlpMetricsEnabled: Schema.Boolean, |
| 382 | otlpLogsUrl: Schema.optional(TrimmedNonEmptyString), |
| 383 | otlpLogsSource: Schema.optional(OtlpEndpointSource), |
| 384 | otlpLogsVariable: Schema.optional(TrimmedNonEmptyString), |
| 385 | otlpLogsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), |
| 386 | }); |
| 387 | export type ServerObservability = typeof ServerObservability.Type; |
| 388 | |
| 389 | export const OtlpSignal = Schema.Literals(["traces", "metrics", "logs"]); |
| 390 | export type OtlpSignal = typeof OtlpSignal.Type; |
| 391 | |
| 392 | export const OtlpEndpointCheckInput = Schema.Struct({ |
| 393 | signal: OtlpSignal, |
| 394 | url: TrimmedNonEmptyString.check(Schema.isPattern(/^https?:\/\/./i)), |
| 395 | }); |
| 396 | export type OtlpEndpointCheckInput = typeof OtlpEndpointCheckInput.Type; |
| 397 | |
| 398 | export const OtlpEndpointCheckResult = Schema.Union([ |
| 399 | Schema.TaggedStruct("Accepted", { latencyMs: Schema.Number }), |
| 400 | Schema.TaggedStruct("Rejected", { status: Schema.Number }), |
| 401 | Schema.TaggedStruct("Unreachable", { timedOut: Schema.Boolean }), |
| 402 | ]); |
| 403 | export type OtlpEndpointCheckResult = typeof OtlpEndpointCheckResult.Type; |
| 404 | |
| 405 | /** The client tells the server what it is, so the triage context can name it. */ |
| 406 | export const ServerPrepareTriageInput = Schema.Struct({ |
| 407 | client: AuthClientPresentationMetadata, |
| 408 | }); |
| 409 | export type ServerPrepareTriageInput = typeof ServerPrepareTriageInput.Type; |
| 410 | |
| 411 | export const ServerPrepareTriageResult = Schema.Struct({ |
| 412 | /** Composer text that links the session's prompt file. */ |
| 413 | prompt: Schema.String, |
| 414 | }); |
| 415 | export type ServerPrepareTriageResult = typeof ServerPrepareTriageResult.Type; |
| 416 | |
| 417 | /** |
| 418 | * The prompt file links as a chip in the user's message; clients spot a triage |
| 419 | * draft by it. |
| 420 | */ |
| 421 | export const TRIAGE_PROMPT_FILE_NAME = "triage-playbook.md"; |
| 422 | |
| 423 | export class ServerPrepareTriageError extends Schema.TaggedError<ServerPrepareTriageError>()( |
| 424 | "ServerPrepareTriageError", |
| 425 | { cause: Schema.optional(Schema.Defect()) }, |
| 426 | ) { |
| 427 | override get message(): string { |
| 428 | return "Could not write the triage session files."; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | export const ServerTraceDiagnosticsErrorKind = Schema.Literals([ |
| 433 | "trace-file-not-found", |
| 434 | "trace-file-read-failed", |
| 435 | ]); |
| 436 | export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type; |
| 437 | |
| 438 | export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({ |
| 439 | name: TrimmedNonEmptyString, |
| 440 | count: NonNegativeInt, |
| 441 | failureCount: NonNegativeInt, |
| 442 | totalDurationMs: Schema.Number, |
| 443 | averageDurationMs: Schema.Number, |
| 444 | maxDurationMs: Schema.Number, |
| 445 | }); |
| 446 | export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type; |
| 447 | |
| 448 | export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({ |
| 449 | name: TrimmedNonEmptyString, |
| 450 | cause: TrimmedNonEmptyString, |
| 451 | count: NonNegativeInt, |
| 452 | lastSeenAt: Schema.DateTimeUtc, |
| 453 | traceId: TrimmedNonEmptyString, |
| 454 | spanId: TrimmedNonEmptyString, |
| 455 | }); |
| 456 | export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type; |
| 457 | |
| 458 | export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({ |
| 459 | name: TrimmedNonEmptyString, |
| 460 | cause: TrimmedNonEmptyString, |
| 461 | durationMs: Schema.Number, |
| 462 | endedAt: Schema.DateTimeUtc, |
| 463 | traceId: TrimmedNonEmptyString, |
| 464 | spanId: TrimmedNonEmptyString, |
| 465 | }); |
| 466 | export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type; |
| 467 | |
| 468 | export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({ |
| 469 | name: TrimmedNonEmptyString, |
| 470 | durationMs: Schema.Number, |
| 471 | endedAt: Schema.DateTimeUtc, |
| 472 | traceId: TrimmedNonEmptyString, |
| 473 | spanId: TrimmedNonEmptyString, |
| 474 | }); |
| 475 | export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type; |
| 476 | |
| 477 | export const ServerTraceDiagnosticsLogEvent = Schema.Struct({ |
| 478 | spanName: TrimmedNonEmptyString, |
| 479 | level: TrimmedNonEmptyString, |
| 480 | message: TrimmedNonEmptyString, |
| 481 | seenAt: Schema.DateTimeUtc, |
| 482 | traceId: TrimmedNonEmptyString, |
| 483 | spanId: TrimmedNonEmptyString, |
| 484 | }); |
| 485 | export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type; |
| 486 | |
| 487 | export const ServerTraceDiagnosticsResult = Schema.Struct({ |
| 488 | traceFilePath: TrimmedNonEmptyString, |
| 489 | scannedFilePaths: Schema.Array(TrimmedNonEmptyString), |
| 490 | readAt: Schema.DateTimeUtc, |
| 491 | recordCount: NonNegativeInt, |
| 492 | parseErrorCount: NonNegativeInt, |
| 493 | firstSpanAt: Schema.Option(Schema.DateTimeUtc), |
| 494 | lastSpanAt: Schema.Option(Schema.DateTimeUtc), |
| 495 | failureCount: NonNegativeInt, |
| 496 | interruptionCount: NonNegativeInt, |
| 497 | slowSpanThresholdMs: NonNegativeInt, |
| 498 | slowSpanCount: NonNegativeInt, |
| 499 | logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt), |
| 500 | topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary), |
| 501 | slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence), |
| 502 | commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary), |
| 503 | latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure), |
| 504 | latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent), |
| 505 | partialFailure: Schema.Option(Schema.Boolean), |
| 506 | error: Schema.Option( |
| 507 | Schema.Struct({ |
| 508 | kind: ServerTraceDiagnosticsErrorKind, |
| 509 | message: TrimmedNonEmptyString, |
| 510 | }), |
| 511 | ), |
| 512 | }); |
| 513 | export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type; |
| 514 | |
| 515 | export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]); |
| 516 | export type ServerProcessSignal = typeof ServerProcessSignal.Type; |
| 517 | |
| 518 | export const ServerProcessDiagnosticsEntry = Schema.Struct({ |
| 519 | pid: PositiveInt, |
| 520 | startTimeMs: NonNegativeInt, |
| 521 | ppid: NonNegativeInt, |
| 522 | pgid: Schema.Option(Schema.Int), |
| 523 | status: TrimmedNonEmptyString, |
| 524 | cpuPercent: Schema.Number, |
| 525 | rssBytes: NonNegativeInt, |
| 526 | elapsed: TrimmedNonEmptyString, |
| 527 | command: TrimmedNonEmptyString, |
| 528 | depth: NonNegativeInt, |
| 529 | childPids: Schema.Array(PositiveInt), |
| 530 | }); |
| 531 | export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type; |
| 532 | |
| 533 | export const ServerProcessDiagnosticsResult = Schema.Struct({ |
| 534 | serverPid: PositiveInt, |
| 535 | readAt: Schema.DateTimeUtc, |
| 536 | processCount: NonNegativeInt, |
| 537 | totalRssBytes: NonNegativeInt, |
| 538 | totalCpuPercent: Schema.Number, |
| 539 | processes: Schema.Array(ServerProcessDiagnosticsEntry), |
| 540 | error: Schema.Option( |
| 541 | Schema.Struct({ |
| 542 | message: TrimmedNonEmptyString, |
| 543 | }), |
| 544 | ), |
| 545 | }); |
| 546 | export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type; |
| 547 | |
| 548 | export const ServerProcessResourceHistoryInput = Schema.Struct({ |
| 549 | windowMs: NonNegativeInt, |
| 550 | bucketMs: NonNegativeInt, |
| 551 | }); |
| 552 | export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type; |
| 553 | |
| 554 | export const ServerProcessResourceHistoryBucket = Schema.Struct({ |
| 555 | startedAt: Schema.DateTimeUtc, |
| 556 | endedAt: Schema.DateTimeUtc, |
| 557 | avgCpuPercent: Schema.Number, |
| 558 | maxCpuPercent: Schema.Number, |
| 559 | maxRssBytes: NonNegativeInt, |
| 560 | maxProcessCount: NonNegativeInt, |
| 561 | }); |
| 562 | export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type; |
| 563 | |
| 564 | export const ServerProcessResourceHistorySummary = Schema.Struct({ |
| 565 | processKey: TrimmedNonEmptyString, |
| 566 | pid: PositiveInt, |
| 567 | ppid: NonNegativeInt, |
| 568 | command: TrimmedNonEmptyString, |
| 569 | depth: NonNegativeInt, |
| 570 | isServerRoot: Schema.Boolean, |
| 571 | firstSeenAt: Schema.DateTimeUtc, |
| 572 | lastSeenAt: Schema.DateTimeUtc, |
| 573 | currentCpuPercent: Schema.Number, |
| 574 | avgCpuPercent: Schema.Number, |
| 575 | maxCpuPercent: Schema.Number, |
| 576 | cpuSecondsApprox: Schema.Number, |
| 577 | currentRssBytes: NonNegativeInt, |
| 578 | maxRssBytes: NonNegativeInt, |
| 579 | sampleCount: NonNegativeInt, |
| 580 | }); |
| 581 | export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type; |
| 582 | |
| 583 | export const ServerProcessResourceHistoryFailureTag = Schema.Literals([ |
| 584 | "ProcessDiagnosticsQueryTimeoutError", |
| 585 | "ProcessDiagnosticsQueryFailedError", |
| 586 | "ProcessDiagnosticsServerProcessSignalError", |
| 587 | "ProcessDiagnosticsNotDescendantError", |
| 588 | "ProcessDiagnosticsSignalFailedError", |
| 589 | ]); |
| 590 | export type ServerProcessResourceHistoryFailureTag = |
| 591 | typeof ServerProcessResourceHistoryFailureTag.Type; |
| 592 | |
| 593 | export const ServerProcessResourceHistoryResult = Schema.Struct({ |
| 594 | readAt: Schema.DateTimeUtc, |
| 595 | windowMs: NonNegativeInt, |
| 596 | bucketMs: NonNegativeInt, |
| 597 | sampleIntervalMs: NonNegativeInt, |
| 598 | retainedSampleCount: NonNegativeInt, |
| 599 | totalCpuSecondsApprox: Schema.Number, |
| 600 | buckets: Schema.Array(ServerProcessResourceHistoryBucket), |
| 601 | topProcesses: Schema.Array(ServerProcessResourceHistorySummary), |
| 602 | error: Schema.Option( |
| 603 | Schema.Struct({ |
| 604 | failureTag: ServerProcessResourceHistoryFailureTag, |
| 605 | message: TrimmedNonEmptyString, |
| 606 | }), |
| 607 | ), |
| 608 | }); |
| 609 | export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type; |
| 610 | |
| 611 | export const ServerSignalProcessInput = Schema.Struct({ |
| 612 | pid: PositiveInt, |
| 613 | startTimeMs: NonNegativeInt, |
| 614 | signal: ServerProcessSignal, |
| 615 | }); |
| 616 | export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type; |
| 617 | |
| 618 | export const ServerSignalProcessResult = Schema.Struct({ |
| 619 | pid: PositiveInt, |
| 620 | signal: ServerProcessSignal, |
| 621 | signaled: Schema.Boolean, |
| 622 | message: Schema.Option(TrimmedNonEmptyString), |
| 623 | }); |
| 624 | export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type; |
| 625 | |
| 626 | export const EnvironmentThemeColor = Schema.String.check( |
| 627 | Schema.isPattern(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/), |
| 628 | ); |
| 629 | export type EnvironmentThemeColor = typeof EnvironmentThemeColor.Type; |
| 630 | |
| 631 | /** Reserve appearance keywords so published themes cannot replace stock preferences. */ |
| 632 | export const EnvironmentThemeId = Schema.String.check( |
| 633 | Schema.isPattern(/^(?!(?:system|light|dark)$)[a-z0-9](?:[a-z0-9-]{0,47})$/), |
| 634 | ); |
| 635 | export type EnvironmentThemeId = typeof EnvironmentThemeId.Type; |
| 636 | |
| 637 | const EnvironmentThemeColors = Schema.Record( |
| 638 | Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9]{0,63}$/)), |
| 639 | TrimmedNonEmptyString.check(Schema.isMaxLength(64)), |
| 640 | ); |
| 641 | |
| 642 | export const THEME_CSS_MAX_LENGTH = 100_000; |
| 643 | |
| 644 | const environmentThemeFields = { |
| 645 | version: Schema.optional(Schema.Literal(1)), |
| 646 | name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)), |
| 647 | appearance: Schema.Literals(["light", "dark"]), |
| 648 | /** Derive the palette from canvas/accent, then overlay colors; without them, colors is the palette. */ |
| 649 | canvas: Schema.optional(EnvironmentThemeColor), |
| 650 | accent: Schema.optional(EnvironmentThemeColor), |
| 651 | colors: Schema.optional(EnvironmentThemeColors), |
| 652 | variants: Schema.optional( |
| 653 | Schema.Struct({ |
| 654 | light: Schema.optional(EnvironmentThemeColors), |
| 655 | dark: Schema.optional(EnvironmentThemeColors), |
| 656 | }), |
| 657 | ), |
| 658 | /** Custom styles for web and desktop clients. */ |
| 659 | css: Schema.optional(Schema.String.check(Schema.isMaxLength(THEME_CSS_MAX_LENGTH))), |
| 660 | }; |
| 661 | |
| 662 | export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields); |
| 663 | export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type; |
| 664 | |
| 665 | export const EnvironmentTheme = Schema.Struct({ |
| 666 | id: EnvironmentThemeId, |
| 667 | ...environmentThemeFields, |
| 668 | /** Revision of the image file published beside the theme; absent without one. */ |
| 669 | background: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(64))), |
| 670 | }); |
| 671 | export type EnvironmentTheme = typeof EnvironmentTheme.Type; |
| 672 | |
| 673 | export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean { |
| 674 | return ( |
| 675 | (file.canvas !== undefined && file.accent !== undefined) || |
| 676 | (file.colors !== undefined && Object.keys(file.colors).length > 0) |
| 677 | ); |
| 678 | } |
| 679 | |
| 680 | /** tailnet means this machine's Tailscale interface; other private addresses are lan. */ |
| 681 | export const ServerDirectEndpointKind = Schema.Literals(["lan", "tailnet"]); |
| 682 | export type ServerDirectEndpointKind = typeof ServerDirectEndpointKind.Type; |
| 683 | |
| 684 | export const ServerDirectEndpoint = Schema.Struct({ |
| 685 | kind: ServerDirectEndpointKind, |
| 686 | httpBaseUrl: TrimmedNonEmptyString, |
| 687 | }); |
| 688 | export type ServerDirectEndpoint = typeof ServerDirectEndpoint.Type; |
| 689 | |
| 690 | /** |
| 691 | * A stretch where the server's event loop could not run, so it answered |
| 692 | * nothing and clients may have dropped the connection. |
| 693 | */ |
| 694 | export const ServerEventLoopStall = Schema.Struct({ |
| 695 | detectedAt: IsoDateTime, |
| 696 | durationMs: NonNegativeInt, |
| 697 | /** One-minute load average when the stall was seen. Absent on Windows, which has none. */ |
| 698 | loadAverage: Schema.optionalKey(Schema.Number), |
| 699 | cpuCount: PositiveInt, |
| 700 | }); |
| 701 | export type ServerEventLoopStall = typeof ServerEventLoopStall.Type; |
| 702 | |
| 703 | export const ServerConfig = Schema.Struct({ |
| 704 | environment: ExecutionEnvironmentDescriptor, |
| 705 | auth: ServerAuthDescriptor, |
| 706 | cwd: TrimmedNonEmptyString, |
| 707 | /** The machine's own name, which file URIs from its shells may carry. Older servers omit it. */ |
| 708 | hostname: Schema.optionalKey(Schema.String), |
| 709 | keybindingsConfigPath: TrimmedNonEmptyString, |
| 710 | keybindings: ResolvedKeybindingsConfig, |
| 711 | issues: ServerConfigIssues, |
| 712 | providers: ServerProviders, |
| 713 | availableEditors: ForwardCompatibleArray(EditorId), |
| 714 | remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)), |
| 715 | /** Hints only; verify each address answers as this environment. */ |
| 716 | directEndpoints: Schema.optionalKey(ForwardCompatibleArray(ServerDirectEndpoint)), |
| 717 | observability: ServerObservability, |
| 718 | settings: ServerSettings, |
| 719 | /** Present when an administrator's policy file manages this environment. */ |
| 720 | managedPolicy: Schema.optionalKey(ManagedPolicySummary), |
| 721 | shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean), |
| 722 | /** |
| 723 | * The shell can leave idle subagent children out of snapshots (`omitIdleSubagents`), and |
| 724 | * `getThreadFamily` and `getWorktreeThreadIds` serve the rows it leaves out. |
| 725 | */ |
| 726 | shellThreadFamilies: Schema.optionalKey(Schema.Boolean), |
| 727 | threadLinkMetadata: Schema.optionalKey(Schema.Boolean), |
| 728 | /** |
| 729 | * The shell can leave older settled threads out of snapshots (`omitOlderSettled`), and |
| 730 | * `getOlderSettledThreads` serves them. Only servers that also advertise `shellThreadFamilies`. |
| 731 | */ |
| 732 | shellOlderSettled: Schema.optionalKey(Schema.Boolean), |
| 733 | shellRevealInFileManager: Schema.optionalKey(Schema.Boolean), |
| 734 | shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind), |
| 735 | threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean), |
| 736 | /** Send window fields only when advertised. */ |
| 737 | threadSnapshotPagination: Schema.optionalKey(Schema.Boolean), |
| 738 | threadFind: Schema.optionalKey(Schema.Boolean), |
| 739 | threadFindProgressive: Schema.optionalKey(Schema.Boolean), |
| 740 | /** Settings patches may carry `secretProviders`; older servers drop the key without an error. */ |
| 741 | secretProviderSettings: Schema.optionalKey(Schema.Boolean), |
| 742 | /** Secret settings may point at a secret provider; older servers drop the reference. */ |
| 743 | secretReferences: Schema.optionalKey(Schema.Boolean), |
| 744 | /** A secret request card may be answered with a secret provider reference. */ |
| 745 | secretRequestReferences: Schema.optionalKey(Schema.Boolean), |
| 746 | scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString), |
| 747 | newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString), |
| 748 | /** |
| 749 | * The latest stall long enough to notice, sent only for a few minutes after |
| 750 | * it. A client that reconnects reads it to say why the host stopped |
| 751 | * answering. Clients do not cache it, since it describes the host at connect. |
| 752 | */ |
| 753 | lastEventLoopStall: Schema.optionalKey(ServerEventLoopStall), |
| 754 | /** |
| 755 | * The host's clock when it built the config, so clients can count live |
| 756 | * elapsed times against host timestamps despite clock skew. Only a |
| 757 | * subscription's first snapshot is fresh; later snapshots may repeat it. |
| 758 | */ |
| 759 | serverTime: Schema.optionalKey(IsoDateTime), |
| 760 | /** |
| 761 | * Never sent in a config snapshot: the theme stream emits the current set |
| 762 | * before any change, so a snapshot carrying it too would hand every |
| 763 | * subscriber the same array twice per connect. |
| 764 | */ |
| 765 | environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)), |
| 766 | /** Stream-only and opt-in; the source stream emits the current set on subscribe. */ |
| 767 | usageLimitSources: Schema.optional(UsageLimitSourceSnapshots), |
| 768 | }); |
| 769 | export type ServerConfig = typeof ServerConfig.Type; |
| 770 | |
| 771 | export function resolveEnvironmentMachineKind( |
| 772 | config: { |
| 773 | readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">; |
| 774 | readonly settings?: Pick<ServerSettings, "environmentIcon">; |
| 775 | } | null, |
| 776 | ): EnvironmentMachineKind { |
| 777 | return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server"; |
| 778 | } |
| 779 | |
| 780 | const ServerUpsertKeybindingReplaceTarget = Schema.Struct({ |
| 781 | key: KeybindingValue, |
| 782 | command: KeybindingCommand, |
| 783 | when: Schema.optional(KeybindingWhen), |
| 784 | }); |
| 785 | |
| 786 | export const ServerUpsertKeybindingInput = Schema.Struct({ |
| 787 | key: KeybindingValue, |
| 788 | command: KeybindingCommand, |
| 789 | when: Schema.optional(KeybindingWhen), |
| 790 | replace: Schema.optional(ServerUpsertKeybindingReplaceTarget), |
| 791 | }); |
| 792 | export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type; |
| 793 | |
| 794 | export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget; |
| 795 | export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type; |
| 796 | |
| 797 | export const ServerUpsertKeybindingResult = Schema.Struct({ |
| 798 | keybindings: ResolvedKeybindingsConfig, |
| 799 | issues: ServerConfigIssues, |
| 800 | }); |
| 801 | export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type; |
| 802 | |
| 803 | export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult; |
| 804 | export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type; |
| 805 | |
| 806 | export const ServerConfigUpdatedPayload = Schema.Struct({ |
| 807 | issues: ServerConfigIssues, |
| 808 | providers: ServerProviders, |
| 809 | settings: Schema.optional(ServerSettings), |
| 810 | }); |
| 811 | export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type; |
| 812 | |
| 813 | export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({ |
| 814 | keybindings: ResolvedKeybindingsConfig, |
| 815 | issues: ServerConfigIssues, |
| 816 | }); |
| 817 | export type ServerConfigKeybindingsUpdatedPayload = |
| 818 | typeof ServerConfigKeybindingsUpdatedPayload.Type; |
| 819 | |
| 820 | export const ServerConfigProviderStatusesPayload = Schema.Struct({ |
| 821 | providers: ServerProviders, |
| 822 | }); |
| 823 | export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type; |
| 824 | |
| 825 | export const ServerConfigProviderStatusDeltasPayload = Schema.Struct({ |
| 826 | /** Every provider in order, as `serverProviderDeltas` from the list this client last received. */ |
| 827 | providers: ForwardCompatibleArray(ServerProviderDelta), |
| 828 | }); |
| 829 | export type ServerConfigProviderStatusDeltasPayload = |
| 830 | typeof ServerConfigProviderStatusDeltasPayload.Type; |
| 831 | |
| 832 | export const ServerConfigSettingsUpdatedPayload = Schema.Struct({ |
| 833 | settings: ServerSettings, |
| 834 | }); |
| 835 | export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type; |
| 836 | |
| 837 | export const ServerConfigStreamSnapshotEvent = Schema.Struct({ |
| 838 | version: Schema.Literal(1), |
| 839 | type: Schema.Literal("snapshot"), |
| 840 | config: ServerConfig, |
| 841 | }); |
| 842 | export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type; |
| 843 | |
| 844 | export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({ |
| 845 | version: Schema.Literal(1), |
| 846 | type: Schema.Literal("keybindingsUpdated"), |
| 847 | payload: ServerConfigKeybindingsUpdatedPayload, |
| 848 | }); |
| 849 | export type ServerConfigStreamKeybindingsUpdatedEvent = |
| 850 | typeof ServerConfigStreamKeybindingsUpdatedEvent.Type; |
| 851 | |
| 852 | export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({ |
| 853 | version: Schema.Literal(1), |
| 854 | type: Schema.Literal("providerStatuses"), |
| 855 | payload: ServerConfigProviderStatusesPayload, |
| 856 | }); |
| 857 | export type ServerConfigStreamProviderStatusesEvent = |
| 858 | typeof ServerConfigStreamProviderStatusesEvent.Type; |
| 859 | |
| 860 | export const ServerConfigStreamProviderStatusDeltasEvent = Schema.Struct({ |
| 861 | version: Schema.Literal(1), |
| 862 | type: Schema.Literal("providerStatusDeltas"), |
| 863 | payload: ServerConfigProviderStatusDeltasPayload, |
| 864 | }); |
| 865 | export type ServerConfigStreamProviderStatusDeltasEvent = |
| 866 | typeof ServerConfigStreamProviderStatusDeltasEvent.Type; |
| 867 | |
| 868 | export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({ |
| 869 | version: Schema.Literal(1), |
| 870 | type: Schema.Literal("settingsUpdated"), |
| 871 | payload: ServerConfigSettingsUpdatedPayload, |
| 872 | }); |
| 873 | export type ServerConfigStreamSettingsUpdatedEvent = |
| 874 | typeof ServerConfigStreamSettingsUpdatedEvent.Type; |
| 875 | |
| 876 | export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({ |
| 877 | themes: Schema.Array(EnvironmentTheme), |
| 878 | }); |
| 879 | export type ServerConfigEnvironmentThemesUpdatedPayload = |
| 880 | typeof ServerConfigEnvironmentThemesUpdatedPayload.Type; |
| 881 | |
| 882 | export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({ |
| 883 | version: Schema.Literal(1), |
| 884 | type: Schema.Literal("environmentThemesUpdated"), |
| 885 | payload: ServerConfigEnvironmentThemesUpdatedPayload, |
| 886 | }); |
| 887 | export type ServerConfigStreamEnvironmentThemesUpdatedEvent = |
| 888 | typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type; |
| 889 | |
| 890 | export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({ |
| 891 | sources: UsageLimitSourceSnapshots, |
| 892 | }); |
| 893 | export type ServerConfigUsageLimitSourcesUpdatedPayload = |
| 894 | typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type; |
| 895 | |
| 896 | export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({ |
| 897 | version: Schema.Literal(1), |
| 898 | type: Schema.Literal("usageLimitSourcesUpdated"), |
| 899 | payload: ServerConfigUsageLimitSourcesUpdatedPayload, |
| 900 | }); |
| 901 | export type ServerConfigStreamUsageLimitSourcesUpdatedEvent = |
| 902 | typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type; |
| 903 | |
| 904 | export const ServerConfigStreamEvent = Schema.Union([ |
| 905 | ServerConfigStreamSnapshotEvent, |
| 906 | ServerConfigStreamKeybindingsUpdatedEvent, |
| 907 | ServerConfigStreamProviderStatusesEvent, |
| 908 | ServerConfigStreamProviderStatusDeltasEvent, |
| 909 | ServerConfigStreamSettingsUpdatedEvent, |
| 910 | ServerConfigStreamEnvironmentThemesUpdatedEvent, |
| 911 | ServerConfigStreamUsageLimitSourcesUpdatedEvent, |
| 912 | ]); |
| 913 | export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type; |
| 914 | |
| 915 | export const ServerSelfUpdateOutcome = Schema.Struct({ |
| 916 | id: TrimmedNonEmptyString, |
| 917 | fromVersion: TrimmedNonEmptyString, |
| 918 | targetVersion: TrimmedNonEmptyString, |
| 919 | status: Schema.Literals(["committed", "rolled-back", "failed"]), |
| 920 | reason: Schema.optionalKey(TrimmedNonEmptyString), |
| 921 | }); |
| 922 | export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type; |
| 923 | |
| 924 | export const ServerLifecycleReadyPayload = Schema.Struct({ |
| 925 | at: IsoDateTime, |
| 926 | environment: ExecutionEnvironmentDescriptor, |
| 927 | updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome), |
| 928 | }); |
| 929 | export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type; |
| 930 | |
| 931 | export const ServerLifecycleWelcomePayload = Schema.Struct({ |
| 932 | environment: ExecutionEnvironmentDescriptor, |
| 933 | cwd: TrimmedNonEmptyString, |
| 934 | projectName: TrimmedNonEmptyString, |
| 935 | bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])), |
| 936 | bootstrapProjectId: Schema.optional(ProjectId), |
| 937 | bootstrapThreadId: Schema.optional(ThreadId), |
| 938 | bootstrapProjectCreated: Schema.optional(Schema.Boolean), |
| 939 | bootstrapThreadCreated: Schema.optional(Schema.Boolean), |
| 940 | }); |
| 941 | export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type; |
| 942 | |
| 943 | export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({ |
| 944 | status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]), |
| 945 | totalThreadCount: NonNegativeInt, |
| 946 | }); |
| 947 | export type ServerLifecycleLegacyThreadMigrationPayload = |
| 948 | typeof ServerLifecycleLegacyThreadMigrationPayload.Type; |
| 949 | |
| 950 | export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({ |
| 951 | version: Schema.Literal(1), |
| 952 | sequence: NonNegativeInt, |
| 953 | type: Schema.Literal("welcome"), |
| 954 | payload: ServerLifecycleWelcomePayload, |
| 955 | }); |
| 956 | export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type; |
| 957 | |
| 958 | export const ServerLifecycleStreamReadyEvent = Schema.Struct({ |
| 959 | version: Schema.Literal(1), |
| 960 | sequence: NonNegativeInt, |
| 961 | type: Schema.Literal("ready"), |
| 962 | payload: ServerLifecycleReadyPayload, |
| 963 | }); |
| 964 | export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type; |
| 965 | |
| 966 | export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({ |
| 967 | version: Schema.Literal(1), |
| 968 | sequence: NonNegativeInt, |
| 969 | type: Schema.Literal("legacyThreadMigration"), |
| 970 | payload: ServerLifecycleLegacyThreadMigrationPayload, |
| 971 | }); |
| 972 | export type ServerLifecycleStreamLegacyThreadMigrationEvent = |
| 973 | typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type; |
| 974 | |
| 975 | export const ServerLifecycleStreamEvent = Schema.Union([ |
| 976 | ServerLifecycleStreamWelcomeEvent, |
| 977 | ServerLifecycleStreamReadyEvent, |
| 978 | ServerLifecycleStreamLegacyThreadMigrationEvent, |
| 979 | ]); |
| 980 | export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type; |
| 981 | |
| 982 | export const ServerProviderUpdatedPayload = Schema.Struct({ |
| 983 | providers: ServerProviders, |
| 984 | }); |
| 985 | export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type; |
| 986 | |
| 987 | export const ServerProviderUpdateInput = Schema.Struct({ |
| 988 | provider: ProviderDriverKind, |
| 989 | targetVersion: Schema.optionalKey(TrimmedNonEmptyString), |
| 990 | instanceId: Schema.optionalKey(ProviderInstanceId), |
| 991 | }); |
| 992 | export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type; |
| 993 | |
| 994 | export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()( |
| 995 | "ServerProviderUpdateError", |
| 996 | { |
| 997 | provider: ProviderDriverKind, |
| 998 | reason: TrimmedNonEmptyString, |
| 999 | cause: Schema.optional(Schema.Defect()), |
| 1000 | }, |
| 1001 | ) { |
| 1002 | override get message(): string { |
| 1003 | return `Provider update failed for ${this.provider}: ${this.reason}`; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | export const ServerNpmReleaseInput = Schema.Struct({ |
| 1008 | spec: Schema.String.check( |
| 1009 | Schema.isMaxLength(64), |
| 1010 | Schema.isPattern(/^(?:latest|nightly|\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/), |
| 1011 | ), |
| 1012 | }); |
| 1013 | export type ServerNpmReleaseInput = typeof ServerNpmReleaseInput.Type; |
| 1014 | |
| 1015 | export const ServerNpmRelease = Schema.Struct({ |
| 1016 | version: Schema.String, |
| 1017 | databaseMigration: Schema.optionalKey(Schema.Int), |
| 1018 | }); |
| 1019 | export type ServerNpmRelease = typeof ServerNpmRelease.Type; |
| 1020 | |
| 1021 | export class ServerNpmReleaseError extends Schema.TaggedError<ServerNpmReleaseError>()( |
| 1022 | "ServerNpmReleaseError", |
| 1023 | { reason: Schema.String }, |
| 1024 | ) { |
| 1025 | override get message(): string { |
| 1026 | return `Could not check the configured npm registry: ${this.reason}`; |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | export const ServerSelfUpdateInput = Schema.Struct({ |
| 1031 | /** Exact npm version, never a dist-tag, so server and client agree on the request. */ |
| 1032 | targetVersion: TrimmedNonEmptyString, |
| 1033 | /** Desktop-managed hosts move their app to this update track first. Sent only for a track switch. */ |
| 1034 | channel: Schema.optionalKey(DesktopUpdateChannelSchema), |
| 1035 | /** The target release's highest migration; the host refuses to leave Nightly without it. */ |
| 1036 | targetDatabaseMigration: Schema.optionalKey(Schema.Int), |
| 1037 | stageOnly: Schema.optionalKey(Schema.Boolean), |
| 1038 | }); |
| 1039 | export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type; |
| 1040 | |
| 1041 | export const ServerSelfUpdateResult = Schema.Struct({ |
| 1042 | targetVersion: TrimmedNonEmptyString, |
| 1043 | method: ServerSelfUpdateMethod, |
| 1044 | updateId: Schema.optionalKey(TrimmedNonEmptyString), |
| 1045 | desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString), |
| 1046 | }); |
| 1047 | export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type; |
| 1048 | |
| 1049 | export const DesktopUpdateCommitInput = Schema.Struct({ |
| 1050 | requestId: TrimmedNonEmptyString, |
| 1051 | }); |
| 1052 | export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type; |
| 1053 | |
| 1054 | export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]); |
| 1055 | export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type; |
| 1056 | |
| 1057 | export const ServerSelfUpdateProgressEvent = Schema.Union([ |
| 1058 | Schema.Struct({ |
| 1059 | type: Schema.Literal("progress"), |
| 1060 | stage: ServerSelfUpdateProgressStage, |
| 1061 | }), |
| 1062 | Schema.Struct({ |
| 1063 | type: Schema.Literal("complete"), |
| 1064 | result: ServerSelfUpdateResult, |
| 1065 | }), |
| 1066 | ]); |
| 1067 | export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type; |
| 1068 | |
| 1069 | export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()( |
| 1070 | "ServerSelfUpdateError", |
| 1071 | { |
| 1072 | reason: TrimmedNonEmptyString, |
| 1073 | /** Set when the host's desktop app refused only because its build and saved tracks differ. */ |
| 1074 | trackMismatch: Schema.optionalKey( |
| 1075 | Schema.Struct({ |
| 1076 | buildChannel: DesktopUpdateChannelSchema, |
| 1077 | savedChannel: DesktopUpdateChannelSchema, |
| 1078 | }), |
| 1079 | ), |
| 1080 | cause: Schema.optional(Schema.Defect()), |
| 1081 | }, |
| 1082 | ) { |
| 1083 | override get message(): string { |
| 1084 | return `Server update failed: ${this.reason}`; |
| 1085 | } |
| 1086 | } |