1import * as Schema from "effect/Schema";
2import { EnvironmentId, ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
3
4export const ManagedWorkspaceStatus = Schema.Struct({ projectId: Schema.NullOr(ProjectId) });
5export const ManagedWorkspaceCreated = Schema.Struct({
6 workspacePath: TrimmedNonEmptyString,
7 projectId: ProjectId,
8 threadId: ThreadId,
9 environmentId: EnvironmentId,
10});
11export type ManagedWorkspaceCreated = typeof ManagedWorkspaceCreated.Type;
12
13export const ManagedWorkspaceArchiveInput = Schema.Struct({ workspacePath: TrimmedNonEmptyString });
14export const ManagedWorkspaceArchived = Schema.Struct({
15 archivedThreadIds: Schema.Array(ThreadId),
16});
17export type ManagedWorkspaceArchived = typeof ManagedWorkspaceArchived.Type;
18
19export class ManagedWorkspaceError extends Schema.TaggedError<ManagedWorkspaceError>()(
20 "ManagedWorkspaceError",
21 {
22 reason: Schema.Literals(["unavailable", "create", "reply", "workspace", "archive"]),
23 cause: Schema.optional(Schema.Defect()),
24 },
25) {
26 override get message(): string {
27 switch (this.reason) {
28 case "workspace":
29 return "Workspace cleanup is paused. Check the managed workspace on this host.";
30 case "archive":
31 return "Workspace archival is paused. Check its linked pull requests and retry.";
32 case "unavailable":
33 return "Workspace creation is unavailable. Install ws, configure the source for my work, and add that source to T3 Code on this host.";
34 case "create":
35 return "Workspace creation stopped. Run ws new on this host for details.";
36 case "reply":
37 return "The workspace tool returned an unreadable reply. Update ws on this host before trying again.";
38 }
39 }
40}