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.TaggedErrorClass<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.TaggedErrorClass<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.TaggedErrorClass<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.TaggedErrorClass<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.TaggedErrorClass<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 * ProviderValidationError - Invalid provider API input.
90 */
91export class ProviderValidationError extends Schema.TaggedErrorClass<ProviderValidationError>()(
92 "ProviderValidationError",
93 {
94 operation: Schema.String,
95 issue: Schema.String,
96 cause: Schema.optional(Schema.Defect()),
97 },
98) {
99 override get message(): string {
100 return `Provider validation failed in ${this.operation}: ${this.issue}`;
101 }
102}
103
104/**
105 * ProviderUnsupportedError - Requested provider is not implemented.
106 */
107export class ProviderUnsupportedError extends Schema.TaggedErrorClass<ProviderUnsupportedError>()(
108 "ProviderUnsupportedError",
109 {
110 provider: Schema.String,
111 cause: Schema.optional(Schema.Defect()),
112 },
113) {
114 override get message(): string {
115 return `Provider '${this.provider}' is not implemented`;
116 }
117}
118
119/**
120 * ProviderInstanceNotFoundError - Lookup against the instance registry failed.
121 *
122 * Distinct from `ProviderUnsupportedError`: the driver is registered, but no
123 * instance with the requested id has been bootstrapped — typically because
124 * the persisted instance id refers to an instance the user removed from
125 * settings, or because routing is asked for an instance before the registry
126 * has finished its first reload.
127 */
128export class ProviderInstanceNotFoundError extends Schema.TaggedErrorClass<ProviderInstanceNotFoundError>()(
129 "ProviderInstanceNotFoundError",
130 {
131 instanceId: Schema.String,
132 cause: Schema.optional(Schema.Defect()),
133 },
134) {
135 override get message(): string {
136 return `No provider instance bound to id '${this.instanceId}'`;
137 }
138}
139
140/**
141 * ProviderDriverError - A driver `create` call failed before producing an
142 * instance. Surfaced to the registry, which marks the offending entry as
143 * an "unavailable" shadow snapshot rather than crashing the server.
144 */
145export class ProviderDriverError extends Schema.TaggedErrorClass<ProviderDriverError>()(
146 "ProviderDriverError",
147 {
148 driver: Schema.String,
149 instanceId: Schema.String,
150 detail: Schema.String,
151 cause: Schema.optional(Schema.Defect()),
152 },
153) {
154 override get message(): string {
155 return `Provider driver '${this.driver}' failed to create instance '${this.instanceId}': ${this.detail}`;
156 }
157}
158
159/**
160 * ProviderSessionNotFoundError - Provider-facing session not found.
161 */
162export class ProviderSessionNotFoundError extends Schema.TaggedErrorClass<ProviderSessionNotFoundError>()(
163 "ProviderSessionNotFoundError",
164 {
165 threadId: Schema.String,
166 cause: Schema.optional(Schema.Defect()),
167 },
168) {
169 override get message(): string {
170 return `Unknown provider thread: ${this.threadId}`;
171 }
172}
173
174/**
175 * ProviderSessionDirectoryPersistenceError - Session directory persistence failure.
176 */
177export class ProviderSessionDirectoryPersistenceError extends Schema.TaggedErrorClass<ProviderSessionDirectoryPersistenceError>()(
178 "ProviderSessionDirectoryPersistenceError",
179 {
180 operation: Schema.String,
181 detail: Schema.String,
182 cause: Schema.optional(Schema.Defect()),
183 },
184) {
185 override get message(): string {
186 return `Provider session directory persistence error in ${this.operation}: ${this.detail}`;
187 }
188}
189
190export type ProviderAdapterError =
191 | ProviderAdapterValidationError
192 | ProviderAdapterSessionNotFoundError
193 | ProviderAdapterSessionClosedError
194 | ProviderAdapterRequestError
195 | ProviderAdapterProcessError;
196
197export type ProviderServiceError =
198 | ProviderValidationError
199 | ProviderUnsupportedError
200 | ProviderInstanceNotFoundError
201 | ProviderSessionNotFoundError
202 | ProviderSessionDirectoryPersistenceError
203 | ProviderAdapterError
204 | CheckpointServiceError;