-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy patherrors.ts
More file actions
220 lines (195 loc) · 6.1 KB
/
Copy patherrors.ts
File metadata and controls
220 lines (195 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import type { OutputErrorAcpPayload, OutputErrorCode, OutputErrorOrigin } from "./types.js";
type AcpxErrorOptions = ErrorOptions & {
outputCode?: OutputErrorCode;
detailCode?: string;
origin?: OutputErrorOrigin;
retryable?: boolean;
acp?: OutputErrorAcpPayload;
outputAlreadyEmitted?: boolean;
};
export class AcpxOperationalError extends Error {
readonly outputCode?: OutputErrorCode;
readonly detailCode?: string;
readonly origin?: OutputErrorOrigin;
readonly retryable?: boolean;
readonly acp?: OutputErrorAcpPayload;
readonly outputAlreadyEmitted?: boolean;
constructor(message: string, options?: AcpxErrorOptions) {
super(message, options);
this.name = new.target.name;
this.outputCode = options?.outputCode;
this.detailCode = options?.detailCode;
this.origin = options?.origin;
this.retryable = options?.retryable;
this.acp = options?.acp;
this.outputAlreadyEmitted = options?.outputAlreadyEmitted;
}
}
export class SessionNotFoundError extends AcpxOperationalError {
readonly sessionId: string;
constructor(sessionId: string) {
super(`Session not found: ${sessionId}`);
this.sessionId = sessionId;
}
}
export class SessionResolutionError extends AcpxOperationalError {}
export class AgentSpawnError extends AcpxOperationalError {
readonly agentCommand: string;
constructor(agentCommand: string, cause?: unknown) {
super(`Failed to spawn agent command: ${agentCommand}`, {
cause: cause instanceof Error ? cause : undefined,
});
this.agentCommand = agentCommand;
}
}
export class AgentStartupError extends AcpxOperationalError {
readonly agentCommand: string;
readonly exitCode: number | null;
readonly signal: NodeJS.Signals | null;
readonly stderrSummary?: string;
constructor(params: {
agentCommand: string;
exitCode: number | null;
signal: NodeJS.Signals | null;
stderrSummary?: string;
cause?: unknown;
}) {
const exitSummary = `exit=${params.exitCode ?? "null"}, signal=${params.signal ?? "null"}`;
const stderrSuffix =
typeof params.stderrSummary === "string" && params.stderrSummary.trim().length > 0
? `: ${params.stderrSummary.trim()}`
: "";
super(`ACP agent exited before initialize completed (${exitSummary})${stderrSuffix}`, {
cause: params.cause instanceof Error ? params.cause : undefined,
outputCode: "RUNTIME",
detailCode: "AGENT_STARTUP_FAILED",
origin: "acp",
});
this.agentCommand = params.agentCommand;
this.exitCode = params.exitCode;
this.signal = params.signal;
this.stderrSummary = params.stderrSummary?.trim() || undefined;
}
}
export class AgentDisconnectedError extends AcpxOperationalError {
readonly reason: string;
readonly exitCode: number | null;
readonly signal: NodeJS.Signals | null;
constructor(
reason: string,
exitCode: number | null,
signal: NodeJS.Signals | null,
options?: AcpxErrorOptions,
) {
super(
`ACP agent disconnected during request (${reason}, exit=${exitCode ?? "null"}, signal=${signal ?? "null"})`,
{
outputCode: "RUNTIME",
detailCode: "AGENT_DISCONNECTED",
origin: "acp",
...options,
},
);
this.reason = reason;
this.exitCode = exitCode;
this.signal = signal;
}
}
export class UnsupportedPromptContentError extends AcpxOperationalError {
constructor(message: string) {
super(message, {
outputCode: "USAGE",
detailCode: "UNSUPPORTED_PROMPT_CONTENT",
origin: "acp",
});
}
}
export class SessionResumeRequiredError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "RUNTIME",
detailCode: "SESSION_RESUME_REQUIRED",
origin: "acp",
retryable: true,
...options,
});
}
}
export class GeminiAcpStartupTimeoutError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "TIMEOUT",
detailCode: "GEMINI_ACP_STARTUP_TIMEOUT",
origin: "acp",
...options,
});
}
}
export class SessionModeReplayError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "RUNTIME",
detailCode: "SESSION_MODE_REPLAY_FAILED",
origin: "acp",
...options,
});
}
}
export class SessionModelReplayError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "RUNTIME",
detailCode: "SESSION_MODEL_REPLAY_FAILED",
origin: "acp",
...options,
});
}
}
export class SessionConfigOptionReplayError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "RUNTIME",
detailCode: "SESSION_CONFIG_OPTION_REPLAY_FAILED",
origin: "acp",
...options,
});
}
}
export class ClaudeAcpSessionCreateTimeoutError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "TIMEOUT",
detailCode: "CLAUDE_ACP_SESSION_CREATE_TIMEOUT",
origin: "acp",
...options,
});
}
}
export class CopilotAcpUnsupportedError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "RUNTIME",
detailCode: "COPILOT_ACP_UNSUPPORTED",
origin: "acp",
...options,
});
}
}
export class AuthPolicyError extends AcpxOperationalError {
constructor(message: string, options?: AcpxErrorOptions) {
super(message, {
outputCode: "RUNTIME",
detailCode: "AUTH_REQUIRED",
origin: "acp",
...options,
});
}
}
export class QueueConnectionError extends AcpxOperationalError {}
export class QueueProtocolError extends AcpxOperationalError {}
export class PermissionDeniedError extends AcpxOperationalError {}
export class PermissionPromptUnavailableError extends AcpxOperationalError {
constructor() {
super("Permission prompt unavailable in non-interactive mode");
}
}