Open History to see the last commit
1import { Effect, Schema } from "effect";
2import { ExecutionEnvironmentDescriptor } from "./environment.ts";
3import { ServerAuthDescriptor } from "./auth.ts";
4import {
5 IsoDateTime,
6 NonNegativeInt,
7 ProjectId,
8 ThreadId,
9 TrimmedNonEmptyString,
10} from "./baseSchemas.ts";
11import { KeybindingRule, ResolvedKeybindingsConfig } from "./keybindings.ts";
12import { EditorId } from "./editor.ts";
13import { ModelCapabilities } from "./model.ts";
14import { ProviderKind } from "./orchestration.ts";
15import { ServerSettings } from "./settings.ts";
16
17const KeybindingsMalformedConfigIssue = Schema.Struct({
18 kind: Schema.Literal("keybindings.malformed-config"),
19 message: TrimmedNonEmptyString,
20});
21
22const KeybindingsInvalidEntryIssue = Schema.Struct({
23 kind: Schema.Literal("keybindings.invalid-entry"),
24 message: TrimmedNonEmptyString,
25 index: Schema.Number,
26});
27
28export const ServerConfigIssue = Schema.Union([
29 KeybindingsMalformedConfigIssue,
30 KeybindingsInvalidEntryIssue,
31]);
32export type ServerConfigIssue = typeof ServerConfigIssue.Type;
33
34const ServerConfigIssues = Schema.Array(ServerConfigIssue);
35
36export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
37export type ServerProviderState = typeof ServerProviderState.Type;
38
39export const ServerProviderAuthStatus = Schema.Literals([
40 "authenticated",
41 "unauthenticated",
42 "unknown",
43]);
44export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
45
46export const ServerProviderAuth = Schema.Struct({
47 status: ServerProviderAuthStatus,
48 type: Schema.optional(TrimmedNonEmptyString),
49 label: Schema.optional(TrimmedNonEmptyString),
50});
51export type ServerProviderAuth = typeof ServerProviderAuth.Type;
52
53export const ServerProviderModel = Schema.Struct({
54 slug: TrimmedNonEmptyString,
55 name: TrimmedNonEmptyString,
56 shortName: Schema.optional(TrimmedNonEmptyString),
57 subProvider: Schema.optional(TrimmedNonEmptyString),
58 isCustom: Schema.Boolean,
59 capabilities: Schema.NullOr(ModelCapabilities),
60});
61export type ServerProviderModel = typeof ServerProviderModel.Type;
62
63export const ServerProviderSlashCommandInput = Schema.Struct({
64 hint: TrimmedNonEmptyString,
65});
66export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type;
67
68export const ServerProviderSlashCommand = Schema.Struct({
69 name: TrimmedNonEmptyString,
70 description: Schema.optional(TrimmedNonEmptyString),
71 input: Schema.optional(ServerProviderSlashCommandInput),
72});
73export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type;
74
75export const ServerProviderSkill = Schema.Struct({
76 name: TrimmedNonEmptyString,
77 description: Schema.optional(TrimmedNonEmptyString),
78 path: TrimmedNonEmptyString,
79 scope: Schema.optional(TrimmedNonEmptyString),
80 enabled: Schema.Boolean,
81 displayName: Schema.optional(TrimmedNonEmptyString),
82 shortDescription: Schema.optional(TrimmedNonEmptyString),
83});
84export type ServerProviderSkill = typeof ServerProviderSkill.Type;
85
86export const ServerProvider = Schema.Struct({
87 provider: ProviderKind,
88 displayName: Schema.optional(TrimmedNonEmptyString),
89 badgeLabel: Schema.optional(TrimmedNonEmptyString),
90 showInteractionModeToggle: Schema.optional(Schema.Boolean),
91 enabled: Schema.Boolean,
92 installed: Schema.Boolean,
93 version: Schema.NullOr(TrimmedNonEmptyString),
94 status: ServerProviderState,
95 auth: ServerProviderAuth,
96 checkedAt: IsoDateTime,
97 message: Schema.optional(TrimmedNonEmptyString),
98 models: Schema.Array(ServerProviderModel),
99 slashCommands: Schema.Array(ServerProviderSlashCommand).pipe(
100 Schema.withDecodingDefault(Effect.succeed([])),
101 ),
102 skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
103});
104export type ServerProvider = typeof ServerProvider.Type;
105
106export const ServerProviders = Schema.Array(ServerProvider);
107export type ServerProviders = typeof ServerProviders.Type;
108
109export const ServerObservability = Schema.Struct({
110 logsDirectoryPath: TrimmedNonEmptyString,
111 localTracingEnabled: Schema.Boolean,
112 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
113 otlpTracesEnabled: Schema.Boolean,
114 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
115 otlpMetricsEnabled: Schema.Boolean,
116});
117export type ServerObservability = typeof ServerObservability.Type;
118
119export const ServerConfig = Schema.Struct({
120 environment: ExecutionEnvironmentDescriptor,
121 auth: ServerAuthDescriptor,
122 cwd: TrimmedNonEmptyString,
123 keybindingsConfigPath: TrimmedNonEmptyString,
124 keybindings: ResolvedKeybindingsConfig,
125 issues: ServerConfigIssues,
126 providers: ServerProviders,
127 availableEditors: Schema.Array(EditorId),
128 observability: ServerObservability,
129 settings: ServerSettings,
130});
131export type ServerConfig = typeof ServerConfig.Type;
132
133export const ServerUpsertKeybindingInput = KeybindingRule;
134export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
135
136export const ServerUpsertKeybindingResult = Schema.Struct({
137 keybindings: ResolvedKeybindingsConfig,
138 issues: ServerConfigIssues,
139});
140export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
141
142export const ServerConfigUpdatedPayload = Schema.Struct({
143 issues: ServerConfigIssues,
144 providers: ServerProviders,
145 settings: Schema.optional(ServerSettings),
146});
147export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
148
149export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
150 issues: ServerConfigIssues,
151});
152export type ServerConfigKeybindingsUpdatedPayload =
153 typeof ServerConfigKeybindingsUpdatedPayload.Type;
154
155export const ServerConfigProviderStatusesPayload = Schema.Struct({
156 providers: ServerProviders,
157});
158export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
159
160export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
161 settings: ServerSettings,
162});
163export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
164
165export const ServerConfigStreamSnapshotEvent = Schema.Struct({
166 version: Schema.Literal(1),
167 type: Schema.Literal("snapshot"),
168 config: ServerConfig,
169});
170export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
171
172export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
173 version: Schema.Literal(1),
174 type: Schema.Literal("keybindingsUpdated"),
175 payload: ServerConfigKeybindingsUpdatedPayload,
176});
177export type ServerConfigStreamKeybindingsUpdatedEvent =
178 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
179
180export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
181 version: Schema.Literal(1),
182 type: Schema.Literal("providerStatuses"),
183 payload: ServerConfigProviderStatusesPayload,
184});
185export type ServerConfigStreamProviderStatusesEvent =
186 typeof ServerConfigStreamProviderStatusesEvent.Type;
187
188export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
189 version: Schema.Literal(1),
190 type: Schema.Literal("settingsUpdated"),
191 payload: ServerConfigSettingsUpdatedPayload,
192});
193export type ServerConfigStreamSettingsUpdatedEvent =
194 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
195
196export const ServerConfigStreamEvent = Schema.Union([
197 ServerConfigStreamSnapshotEvent,
198 ServerConfigStreamKeybindingsUpdatedEvent,
199 ServerConfigStreamProviderStatusesEvent,
200 ServerConfigStreamSettingsUpdatedEvent,
201]);
202export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
203
204export const ServerLifecycleReadyPayload = Schema.Struct({
205 at: IsoDateTime,
206 environment: ExecutionEnvironmentDescriptor,
207});
208export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
209
210export const ServerLifecycleWelcomePayload = Schema.Struct({
211 environment: ExecutionEnvironmentDescriptor,
212 cwd: TrimmedNonEmptyString,
213 projectName: TrimmedNonEmptyString,
214 bootstrapProjectId: Schema.optional(ProjectId),
215 bootstrapThreadId: Schema.optional(ThreadId),
216});
217export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
218
219export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
220 version: Schema.Literal(1),
221 sequence: NonNegativeInt,
222 type: Schema.Literal("welcome"),
223 payload: ServerLifecycleWelcomePayload,
224});
225export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
226
227export const ServerLifecycleStreamReadyEvent = Schema.Struct({
228 version: Schema.Literal(1),
229 sequence: NonNegativeInt,
230 type: Schema.Literal("ready"),
231 payload: ServerLifecycleReadyPayload,
232});
233export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
234
235export const ServerLifecycleStreamEvent = Schema.Union([
236 ServerLifecycleStreamWelcomeEvent,
237 ServerLifecycleStreamReadyEvent,
238]);
239export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
240
241export const ServerProviderUpdatedPayload = Schema.Struct({
242 providers: ServerProviders,
243});
244export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;