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

server.ts

97 lines3.3 KB

1import { Schema } from "effect";
2import { IsoDateTime, TrimmedNonEmptyString } from "./baseSchemas";
3import { KeybindingRule, ResolvedKeybindingsConfig } from "./keybindings";
4import { EditorId } from "./editor";
5import { ModelCapabilities } from "./model";
6import { ProviderKind } from "./orchestration";
7import { ServerSettings } from "./settings";
8​
9const KeybindingsMalformedConfigIssue = Schema.Struct({
10 kind: Schema.Literal("keybindings.malformed-config"),
11 message: TrimmedNonEmptyString,
12});
13​
14const KeybindingsInvalidEntryIssue = Schema.Struct({
15 kind: Schema.Literal("keybindings.invalid-entry"),
16 message: TrimmedNonEmptyString,
17 index: Schema.Number,
18});
19​
20export const ServerConfigIssue = Schema.Union([
21 KeybindingsMalformedConfigIssue,
22 KeybindingsInvalidEntryIssue,
23]);
24export type ServerConfigIssue = typeof ServerConfigIssue.Type;
25​
26const ServerConfigIssues = Schema.Array(ServerConfigIssue);
27​
28export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
29export type ServerProviderState = typeof ServerProviderState.Type;
30​
31export const ServerProviderAuthStatus = Schema.Literals([
32 "authenticated",
33 "unauthenticated",
34 "unknown",
35]);
36export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
37​
38export const ServerProviderAuth = Schema.Struct({
39 status: ServerProviderAuthStatus,
40 type: Schema.optional(TrimmedNonEmptyString),
41 label: Schema.optional(TrimmedNonEmptyString),
42});
43export type ServerProviderAuth = typeof ServerProviderAuth.Type;
44​
45export const ServerProviderModel = Schema.Struct({
46 slug: TrimmedNonEmptyString,
47 name: TrimmedNonEmptyString,
48 isCustom: Schema.Boolean,
49 capabilities: Schema.NullOr(ModelCapabilities),
50});
51export type ServerProviderModel = typeof ServerProviderModel.Type;
52​
53export const ServerProvider = Schema.Struct({
54 provider: ProviderKind,
55 enabled: Schema.Boolean,
56 installed: Schema.Boolean,
57 version: Schema.NullOr(TrimmedNonEmptyString),
58 status: ServerProviderState,
59 auth: ServerProviderAuth,
60 checkedAt: IsoDateTime,
61 message: Schema.optional(TrimmedNonEmptyString),
62 models: Schema.Array(ServerProviderModel),
63});
64export type ServerProvider = typeof ServerProvider.Type;
65​
66const ServerProviders = Schema.Array(ServerProvider);
67​
68export const ServerConfig = Schema.Struct({
69 cwd: TrimmedNonEmptyString,
70 keybindingsConfigPath: TrimmedNonEmptyString,
71 keybindings: ResolvedKeybindingsConfig,
72 issues: ServerConfigIssues,
73 providers: ServerProviders,
74 availableEditors: Schema.Array(EditorId),
75 settings: ServerSettings,
76});
77export type ServerConfig = typeof ServerConfig.Type;
78​
79export const ServerUpsertKeybindingInput = KeybindingRule;
80export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
81​
82export const ServerUpsertKeybindingResult = Schema.Struct({
83 keybindings: ResolvedKeybindingsConfig,
84 issues: ServerConfigIssues,
85});
86export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
87​
88export const ServerConfigUpdatedPayload = Schema.Struct({
89 issues: ServerConfigIssues,
90 settings: Schema.optional(ServerSettings),
91});
92export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
93​
94export const ServerProviderUpdatedPayload = Schema.Struct({
95 providers: ServerProviders,
96});
97export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;