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

server.ts

77 lines2.6 KB

1import { Schema } from "effect";
2import { IsoDateTime, TrimmedNonEmptyString } from "./baseSchemas";
3import { KeybindingRule, ResolvedKeybindingsConfig } from "./keybindings";
4import { EditorId } from "./editor";
5import { ProviderKind } from "./orchestration";
6​
7const KeybindingsMalformedConfigIssue = Schema.Struct({
8 kind: Schema.Literal("keybindings.malformed-config"),
9 message: TrimmedNonEmptyString,
10});
11​
12const KeybindingsInvalidEntryIssue = Schema.Struct({
13 kind: Schema.Literal("keybindings.invalid-entry"),
14 message: TrimmedNonEmptyString,
15 index: Schema.Number,
16});
17​
18export const ServerConfigIssue = Schema.Union([
19 KeybindingsMalformedConfigIssue,
20 KeybindingsInvalidEntryIssue,
21]);
22export type ServerConfigIssue = typeof ServerConfigIssue.Type;
23​
24const ServerConfigIssues = Schema.Array(ServerConfigIssue);
25​
26export const ServerProviderStatusState = Schema.Literals(["ready", "warning", "error"]);
27export type ServerProviderStatusState = typeof ServerProviderStatusState.Type;
28​
29export const ServerProviderAuthStatus = Schema.Literals([
30 "authenticated",
31 "unauthenticated",
32 "unknown",
33]);
34export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
35​
36const DiscoveredModel = Schema.Struct({
37 slug: TrimmedNonEmptyString,
38 name: TrimmedNonEmptyString,
39});
40​
41export const ServerProviderStatus = Schema.Struct({
42 provider: ProviderKind,
43 status: ServerProviderStatusState,
44 available: Schema.Boolean,
45 authStatus: ServerProviderAuthStatus,
46 checkedAt: IsoDateTime,
47 message: Schema.optional(TrimmedNonEmptyString),
48 discoveredModels: Schema.optional(Schema.Array(DiscoveredModel)),
49});
50export type ServerProviderStatus = typeof ServerProviderStatus.Type;
51​
52const ServerProviderStatuses = Schema.Array(ServerProviderStatus);
53​
54export const ServerConfig = Schema.Struct({
55 cwd: TrimmedNonEmptyString,
56 keybindingsConfigPath: TrimmedNonEmptyString,
57 keybindings: ResolvedKeybindingsConfig,
58 issues: ServerConfigIssues,
59 providers: ServerProviderStatuses,
60 availableEditors: Schema.Array(EditorId),
61});
62export type ServerConfig = typeof ServerConfig.Type;
63​
64export const ServerUpsertKeybindingInput = KeybindingRule;
65export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
66​
67export const ServerUpsertKeybindingResult = Schema.Struct({
68 keybindings: ResolvedKeybindingsConfig,
69 issues: ServerConfigIssues,
70});
71export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
72​
73export const ServerConfigUpdatedPayload = Schema.Struct({
74 issues: ServerConfigIssues,
75 providers: ServerProviderStatuses,
76});
77export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;