Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import type { CheckpointServiceError } from "../checkpointing/Errors.ts";
4
5/**
6 * ProviderAdapterValidationError - Invalid adapter API input.
7 */
8export class ProviderAdapterValidationError extends Schema.TaggedError<ProviderAdapterValidationError>()(
9 "ProviderAdapterValidationError",
10 {
11 provider: Schema.String,
12 operation: Schema.String,
13 issue: Schema.String,
14 cause: Schema.optional(Schema.Defect()),
15 },
16) {
17 override get message(): string {
18 return `Provider adapter validation failed (${this.provider}) in ${this.operation}: ${this.issue}`;
19 }
20}
21
22/**
23 * ProviderAdapterSessionNotFoundError - Adapter-owned session id is unknown.
24 */
25export class ProviderAdapterSessionNotFoundError extends Schema.TaggedError<ProviderAdapterSessionNotFoundError>()(
26 "ProviderAdapterSessionNotFoundError",
27 {
28 provider: Schema.String,
29 threadId: Schema.String,
30 cause: Schema.optional(Schema.Defect()),
31 },
32) {
33 override get message(): string {
34 return `Unknown ${this.provider} adapter thread: ${this.threadId}`;
35 }
36}
37
38/**
39 * ProviderAdapterSessionClosedError - Adapter session exists but is closed.
40 */
41export class ProviderAdapterSessionClosedError extends Schema.TaggedError<ProviderAdapterSessionClosedError>()(
42 "ProviderAdapterSessionClosedError",
43 {
44 provider: Schema.String,
45 threadId: Schema.String,
46 cause: Schema.optional(Schema.Defect()),
47 },
48) {
49 override get message(): string {
50 return `${this.provider} adapter thread is closed: ${this.threadId}`;
51 }
52}
53
54/**
55 * ProviderAdapterRequestError - Provider protocol request failed or timed out.
56 */
57export class ProviderAdapterRequestError extends Schema.TaggedError<ProviderAdapterRequestError>()(
58 "ProviderAdapterRequestError",
59 {
60 provider: Schema.String,
61 method: Schema.String,
62 detail: Schema.String,
63 cause: Schema.optional(Schema.Defect()),
64 },
65) {
66 override get message(): string {
67 return `Provider adapter request failed (${this.provider}) for ${this.method}: ${this.detail}`;
68 }
69}
70
71/**
72 * ProviderAdapterProcessError - Provider process lifecycle failure.
73 */
74export class ProviderAdapterProcessError extends Schema.TaggedError<ProviderAdapterProcessError>()(
75 "ProviderAdapterProcessError",
76 {
77 provider: Schema.String,
78 threadId: Schema.String,
79 detail: Schema.String,
80 cause: Schema.optional(Schema.Defect()),
81 },
82) {
83 override get message(): string {
84 return `Provider adapter process error (${this.provider}) for thread ${this.threadId}: ${this.detail}`;
85 }
86}
87
88/**
89 * ProviderWorkspaceMissingError - The session's working directory no longer
90 * exists on disk, so no provider process can start in it.
91 */
92export class ProviderWorkspaceMissingError extends Schema.TaggedError<ProviderWorkspaceMissingError>()(
93 "ProviderWorkspaceMissingError",
94 {
95 threadId: Schema.String,
96 cwd: Schema.String,
97 },
98) {
99 override get message(): string {
100 return `This thread's workspace folder no longer exists or is not a directory: ${this.cwd}. Restore the folder at this path before retrying.`;
101 }
102}
103
104/**
105 * ProviderValidationError - Invalid provider API input.
106 */
107export class ProviderValidationError extends Schema.TaggedError<ProviderValidationError>()(
108 "ProviderValidationError",
109 {
110 operation: Schema.String,
111 issue: Schema.String,
112 cause: Schema.optional(Schema.Defect()),
113 },
114) {
115 override get message(): string {
116 return `Provider validation failed in ${this.operation}: ${this.issue}`;
117 }
118}
119
120/**
121 * ProviderUnsupportedError - Requested provider is not implemented.
122 */
123export class ProviderUnsupportedError extends Schema.TaggedError<ProviderUnsupportedError>()(
124 "ProviderUnsupportedError",
125 {
126 provider: Schema.String,
127 cause: Schema.optional(Schema.Defect()),
128 },
129) {
130 override get message(): string {
131 return `Provider '${this.provider}' is not implemented`;
132 }
133}
134
135/**
136 * ProviderInstanceNotFoundError - Lookup against the instance registry failed.
137 *
138 * Distinct from `ProviderUnsupportedError`: the driver is registered, but no
139 * instance with the requested id has been bootstrapped — typically because
140 * the persisted instance id refers to an instance the user removed from
141 * settings, or because routing is asked for an instance before the registry
142 * has finished its first reload.
143 */
144export class ProviderInstanceNotFoundError extends Schema.TaggedError<ProviderInstanceNotFoundError>()(
145 "ProviderInstanceNotFoundError",
146 {
147 instanceId: Schema.String,
148 cause: Schema.optional(Schema.Defect()),
149 },
150) {
151 override get message(): string {
152 return `No provider instance bound to id '${this.instanceId}'`;
153 }
154}
155
156/**
157 * ProviderDriverError - A driver `create` call failed before producing an
158 * instance. Surfaced to the registry, which marks the offending entry as
159 * an "unavailable" shadow snapshot rather than crashing the server.
160 */
161export class ProviderDriverError extends Schema.TaggedError<ProviderDriverError>()(
162 "ProviderDriverError",
163 {
164 driver: Schema.String,
165 instanceId: Schema.String,
166 detail: Schema.String,
167 cause: Schema.optional(Schema.Defect()),
168 },
169) {
170 override get message(): string {
171 return `Provider driver '${this.driver}' failed to create instance '${this.instanceId}': ${this.detail}`;
172 }
173}
174
175/**
176 * ProviderSessionNotFoundError - Provider-facing session not found.
177 */
178export class ProviderSessionNotFoundError extends Schema.TaggedError<ProviderSessionNotFoundError>()(
179 "ProviderSessionNotFoundError",
180 {
181 threadId: Schema.String,
182 cause: Schema.optional(Schema.Defect()),
183 },
184) {
185 override get message(): string {
186 return `Unknown provider thread: ${this.threadId}`;
187 }
188}
189
190/**
191 * ProviderSessionDirectoryPersistenceError - Session directory persistence failure.
192 */
193export class ProviderSessionDirectoryPersistenceError extends Schema.TaggedError<ProviderSessionDirectoryPersistenceError>()(
194 "ProviderSessionDirectoryPersistenceError",
195 {
196 operation: Schema.String,
197 detail: Schema.String,
198 cause: Schema.optional(Schema.Defect()),
199 },
200) {
201 override get message(): string {
202 return `Provider session directory persistence error in ${this.operation}: ${this.detail}`;
203 }
204}
205
206export type ProviderAdapterError =
207 | ProviderAdapterValidationError
208 | ProviderAdapterSessionNotFoundError
209 | ProviderAdapterSessionClosedError
210 | ProviderAdapterRequestError
211 | ProviderAdapterProcessError;
212
213export type ProviderServiceError =
214 | ProviderValidationError
215 | ProviderUnsupportedError
216 | ProviderWorkspaceMissingError
217 | ProviderInstanceNotFoundError
218 | ProviderSessionNotFoundError
219 | ProviderSessionDirectoryPersistenceError
220 | ProviderAdapterError
221 | CheckpointServiceError;