@bastani/pi-ai 0.9.74 → 0.9.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +3 -1
  3. package/dist/api/anthropic-messages.d.ts.map +1 -1
  4. package/dist/api/anthropic-messages.js +21 -7
  5. package/dist/api/anthropic-messages.js.map +1 -1
  6. package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  7. package/dist/api/bedrock-converse-stream.js +4 -2
  8. package/dist/api/bedrock-converse-stream.js.map +1 -1
  9. package/dist/api/constrained-sampling.d.ts +0 -2
  10. package/dist/api/constrained-sampling.d.ts.map +1 -1
  11. package/dist/api/constrained-sampling.js +0 -13
  12. package/dist/api/constrained-sampling.js.map +1 -1
  13. package/dist/api/openai-completions.d.ts.map +1 -1
  14. package/dist/api/openai-completions.js +9 -5
  15. package/dist/api/openai-completions.js.map +1 -1
  16. package/dist/api/openai-images-options.d.ts +18 -5
  17. package/dist/api/openai-images-options.d.ts.map +1 -1
  18. package/dist/api/openai-images-options.js +9 -3
  19. package/dist/api/openai-images-options.js.map +1 -1
  20. package/dist/api/openai-images.d.ts.map +1 -1
  21. package/dist/api/openai-images.js +121 -19
  22. package/dist/api/openai-images.js.map +1 -1
  23. package/dist/api/openai-responses.d.ts.map +1 -1
  24. package/dist/api/openai-responses.js +10 -3
  25. package/dist/api/openai-responses.js.map +1 -1
  26. package/dist/api/strict-tool-limits.d.ts +13 -0
  27. package/dist/api/strict-tool-limits.d.ts.map +1 -0
  28. package/dist/api/strict-tool-limits.js +50 -0
  29. package/dist/api/strict-tool-limits.js.map +1 -0
  30. package/dist/auth/types.d.ts +7 -0
  31. package/dist/auth/types.d.ts.map +1 -1
  32. package/dist/auth/types.js.map +1 -1
  33. package/dist/cache-warming.d.ts +53 -0
  34. package/dist/cache-warming.d.ts.map +1 -0
  35. package/dist/cache-warming.js +82 -0
  36. package/dist/cache-warming.js.map +1 -0
  37. package/dist/image-generation-error.d.ts +10 -3
  38. package/dist/image-generation-error.d.ts.map +1 -1
  39. package/dist/image-generation-error.js +3 -2
  40. package/dist/image-generation-error.js.map +1 -1
  41. package/dist/index.d.ts +3 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +3 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/models.d.ts +15 -6
  46. package/dist/models.d.ts.map +1 -1
  47. package/dist/models.js +22 -7
  48. package/dist/models.js.map +1 -1
  49. package/dist/providers/data/.manifest.json +1 -1
  50. package/dist/providers/data/amazon-bedrock.json +1 -1
  51. package/dist/providers/data/anthropic.json +1 -1
  52. package/dist/providers/data/azure.json +1 -1
  53. package/dist/providers/data/google.json +1 -1
  54. package/dist/providers/data/meta.json +1 -1
  55. package/dist/providers/data/opencode-go.json +1 -1
  56. package/dist/providers/data/opencode.json +1 -1
  57. package/dist/providers/data/openrouter.json +1 -1
  58. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  59. package/dist/providers/github-copilot-errors.d.ts +17 -5
  60. package/dist/providers/github-copilot-errors.d.ts.map +1 -1
  61. package/dist/providers/github-copilot-errors.js +55 -11
  62. package/dist/providers/github-copilot-errors.js.map +1 -1
  63. package/dist/providers/github-copilot-stream-attempt.d.ts +27 -0
  64. package/dist/providers/github-copilot-stream-attempt.d.ts.map +1 -0
  65. package/dist/providers/github-copilot-stream-attempt.js +45 -0
  66. package/dist/providers/github-copilot-stream-attempt.js.map +1 -0
  67. package/dist/providers/github-copilot.d.ts +10 -2
  68. package/dist/providers/github-copilot.d.ts.map +1 -1
  69. package/dist/providers/github-copilot.js +62 -36
  70. package/dist/providers/github-copilot.js.map +1 -1
  71. package/dist/types.d.ts +2 -0
  72. package/dist/types.d.ts.map +1 -1
  73. package/dist/types.js.map +1 -1
  74. package/dist/utils/stream-deadline.d.ts +6 -2
  75. package/dist/utils/stream-deadline.d.ts.map +1 -1
  76. package/dist/utils/stream-deadline.js +12 -3
  77. package/dist/utils/stream-deadline.js.map +1 -1
  78. package/dist/utils/version.d.ts +1 -1
  79. package/dist/utils/version.js +1 -1
  80. package/dist/utils/version.js.map +1 -1
  81. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  import type { AssistantMessage } from "../types.ts";
2
+ import type { GitHubCopilotStreamSnapshot } from "./github-copilot-stream-attempt.ts";
2
3
  /** Stable codes of every GitHub Copilot request failure. Public API: never renamed or reused. */
3
4
  export type GitHubCopilotErrorCode = "model-unavailable" | "rate-limited" | "quota-exhausted" | "content-filtered" | "prompt-too-large" | "invalid-request" | "authentication-failed" | "service-unavailable" | "stream-ended-early" | "empty-response" | "unrecognized-response";
4
5
  declare const MODEL_UNAVAILABLE_REASONS: readonly ["integration", "not-supported", "wrong-api", "no-endpoint", "not-found"];
@@ -11,7 +12,7 @@ export type GitHubCopilotInvalidRequestReason = (typeof INVALID_REQUEST_REASONS)
11
12
  /** What Atomic could not interpret. */
12
13
  export type GitHubCopilotUnrecognizedReason = (typeof UNRECOGNIZED_REASONS)[number];
13
14
  export type GitHubCopilotErrorName = "GitHubCopilotError" | "GitHubCopilotModelUnavailableError" | "GitHubCopilotRateLimitError" | "GitHubCopilotQuotaExhaustedError" | "GitHubCopilotContentFilterError" | "GitHubCopilotPromptTooLargeError" | "GitHubCopilotInvalidRequestError" | "GitHubCopilotAuthenticationError" | "GitHubCopilotServiceUnavailableError" | "GitHubCopilotStreamEndedEarlyError" | "GitHubCopilotEmptyResponseError" | "GitHubCopilotUnrecognizedResponseError";
14
- export type GitHubCopilotErrorFieldValue = string | number | null;
15
+ export type GitHubCopilotErrorFieldValue = string | number | boolean | null;
15
16
  export type GitHubCopilotErrorFields = Readonly<Record<string, GitHubCopilotErrorFieldValue>>;
16
17
  /** The request a failure belongs to, and what the provider reported about it. No prompt text, tokens or bodies. */
17
18
  export interface GitHubCopilotErrorContext {
@@ -48,6 +49,8 @@ export declare const GITHUB_COPILOT_ERROR_DIAGNOSTIC = "github_copilot_error";
48
49
  interface GitHubCopilotErrorOptions {
49
50
  readonly hint?: string;
50
51
  readonly cause?: unknown;
52
+ /** What the failure observed, as one sentence without its final period; it follows the code in the message. */
53
+ readonly circumstances?: string;
51
54
  }
52
55
  /** Base of every GitHub Copilot request failure. Catch this to handle the whole family. */
53
56
  export declare class GitHubCopilotError extends Error {
@@ -141,13 +144,22 @@ export declare class GitHubCopilotServiceUnavailableError extends GitHubCopilotE
141
144
  readonly cause?: unknown;
142
145
  });
143
146
  }
144
- /** The response stream stopped before its finish reason or terminal event. Retryable. */
147
+ /**
148
+ * The response stream stopped before its finish reason or terminal event. Retryable. `durationMs` is how long the attempt
149
+ * ran before it ended and `startedContent` whether any provider stream event had arrived; both are undefined when the
150
+ * error was built without them. The provider's `x-request-id` is `requestId`.
151
+ */
145
152
  export declare class GitHubCopilotStreamEndedEarlyError extends GitHubCopilotError {
146
153
  readonly name: "GitHubCopilotStreamEndedEarlyError";
147
154
  readonly code: "stream-ended-early";
155
+ readonly durationMs: number | undefined;
156
+ readonly startedContent: boolean | undefined;
148
157
  constructor(context: GitHubCopilotErrorContext, options?: {
149
158
  readonly cause?: unknown;
159
+ readonly durationMs?: number;
160
+ readonly startedContent?: boolean;
150
161
  });
162
+ fields(): GitHubCopilotErrorFields;
151
163
  }
152
164
  /** The model finished with no text and no tool call, as Copilot's Gemini models sometimes do. Retryable. */
153
165
  export declare class GitHubCopilotEmptyResponseError extends GitHubCopilotError {
@@ -213,8 +225,8 @@ export declare function getGitHubCopilotError(message: {
213
225
  export interface GitHubCopilotFailureContext {
214
226
  readonly modelId: string;
215
227
  readonly api: string;
216
- /** True once Copilot answered with HTTP success and the response stream started. */
217
- readonly streamStarted: boolean;
228
+ /** What the request observed once Copilot answered with HTTP success; undefined when no response arrived. */
229
+ readonly stream?: GitHubCopilotStreamSnapshot;
218
230
  /** The provider's raw finish or stop reason, when the stream reported one. */
219
231
  readonly finishReason?: string;
220
232
  }
@@ -233,7 +245,7 @@ export declare function classifyGitHubCopilotFailure(error: unknown, failure: Gi
233
245
  * Type a failed Copilot assistant message at the provider boundary: classify `error` and record it on `output`,
234
246
  * keeping the provider's text after the typed message. A cancelled message is left alone.
235
247
  */
236
- export declare function recordGitHubCopilotFailure(output: AssistantMessage, error: unknown, streamStarted: boolean): void;
248
+ export declare function recordGitHubCopilotFailure(output: AssistantMessage, error: unknown, stream: GitHubCopilotStreamSnapshot | undefined): void;
237
249
  /**
238
250
  * The typed failure for a completed Copilot turn that has no text and no tool call, as Copilot's Gemini models
239
251
  * sometimes return; undefined for any other turn. A length stop is left to the caller's length handling.
@@ -1 +1 @@
1
- {"version":3,"file":"github-copilot-errors.d.ts","sourceRoot":"","sources":["../../src/providers/github-copilot-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,aAAa,CAAC;AAIhE,iGAAiG;AACjG,MAAM,MAAM,sBAAsB,GAC/B,mBAAmB,GACnB,cAAc,GACd,iBAAiB,GACjB,kBAAkB,GAClB,kBAAkB,GAClB,iBAAiB,GACjB,uBAAuB,GACvB,qBAAqB,GACrB,oBAAoB,GACpB,gBAAgB,GAChB,uBAAuB,CAAC;AAE3B,QAAA,MAAM,yBAAyB,YAAI,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,CAAU,CAAC;AACrH,QAAA,MAAM,uBAAuB,YAAI,kBAAkB,EAAE,gBAAgB,EAAE,UAAU,CAAU,CAAC;AAC5F,QAAA,MAAM,oBAAoB,YAAI,gBAAgB,EAAE,qBAAqB,EAAE,gBAAgB,CAAU,CAAC;AAElG,8CAA8C;AAC9C,MAAM,MAAM,mCAAmC,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7F,kDAAkD;AAClD,MAAM,MAAM,iCAAiC,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzF,uCAAuC;AACvC,MAAM,MAAM,+BAA+B,GAAG,CAAC,OAAO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gB,EACxB,KAAK,EAAE,kBAAkB,EACzB,YAAY,CAAC,EAAE,MAAM,GACnB,IAAI,CAcN;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,EAAE;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,GACrD,kBAAkB,GAAG,SAAS,CAUhC;AAkMD,kDAAkD;AAClD,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,6GAA6G;IAC7G,QAAQ,CAAC,MAAM,CAAC,EAAE,2BAA2B,CAAC;IAC9C,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B;AAYD;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,2BAA2B,GAClC,kBAAkB,GAAG,SAAS,CAsChC;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,2BAA2B,GAAG,SAAS,GAC7C,IAAI,CASN;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,gBAAgB,GAAG,+BAA+B,GAAG,SAAS,CAQhH"}
@@ -50,7 +50,7 @@ const HINTS = {
50
50
  "invalid-request": "Check the model's thinking level and any models.json overrides for this model.",
51
51
  "authentication-failed": "Run /login to sign in to GitHub Copilot again, or check COPILOT_GITHUB_TOKEN.",
52
52
  "service-unavailable": "Retry later; Atomic retries the request when retries are enabled.",
53
- "stream-ended-early": "Retry the request; Atomic retries it when retries are enabled.",
53
+ "stream-ended-early": "If the stream keeps ending early, split the work into smaller steps, lower the thinking effort, or add a fallback model with the fallbackModels setting.",
54
54
  "empty-response": "Retry the request; Atomic retries it when retries are enabled.",
55
55
  "unrecognized-response": "Retry the request, and report it if it keeps happening.",
56
56
  };
@@ -64,8 +64,8 @@ const INVALID_REQUEST_HINTS = {
64
64
  "reasoning-effort": "Pick a thinking level this model lists.",
65
65
  "integration-id": "Remove the Copilot-Integration-Id header override from models.json.",
66
66
  };
67
- function failureMessage(code, modelId, hint) {
68
- return `${WHAT_FAILED[code]}: ${modelId} (${code}). ${hint}`;
67
+ function failureMessage(code, modelId, hint, circumstances) {
68
+ return `${WHAT_FAILED[code]}: ${modelId} (${code}). ${circumstances === undefined ? "" : `${circumstances}. `}${hint}`;
69
69
  }
70
70
  /** Base of every GitHub Copilot request failure. Catch this to handle the whole family. */
71
71
  export class GitHubCopilotError extends Error {
@@ -81,7 +81,7 @@ export class GitHubCopilotError extends Error {
81
81
  detail;
82
82
  constructor(code, context, options) {
83
83
  const hint = options?.hint ?? HINTS[code];
84
- super(failureMessage(code, context.modelId, hint), options?.cause === undefined ? undefined : { cause: options.cause });
84
+ super(failureMessage(code, context.modelId, hint, options?.circumstances), options?.cause === undefined ? undefined : { cause: options.cause });
85
85
  this.code = code;
86
86
  this.retryable = RETRYABLE_CODES.has(code);
87
87
  this.hint = hint;
@@ -182,11 +182,38 @@ export class GitHubCopilotServiceUnavailableError extends GitHubCopilotError {
182
182
  super("service-unavailable", context, options);
183
183
  }
184
184
  }
185
- /** The response stream stopped before its finish reason or terminal event. Retryable. */
185
+ /** What a stream that ended early observed, as the sentence that follows its code in the message. */
186
+ function streamEndedEarlyCircumstances(requestId, durationMs, startedContent) {
187
+ const facts = [
188
+ ...(durationMs === undefined ? [] : [`Attempt ran ${(durationMs / 1000).toFixed(1)} s`]),
189
+ ...(startedContent === undefined ? [] : [startedContent ? "response started" : "no response events arrived"]),
190
+ ...(requestId === undefined ? [] : [`request ID ${requestId}`]),
191
+ ];
192
+ return facts.length === 0 ? undefined : facts.join(", ");
193
+ }
194
+ /**
195
+ * The response stream stopped before its finish reason or terminal event. Retryable. `durationMs` is how long the attempt
196
+ * ran before it ended and `startedContent` whether any provider stream event had arrived; both are undefined when the
197
+ * error was built without them. The provider's `x-request-id` is `requestId`.
198
+ */
186
199
  export class GitHubCopilotStreamEndedEarlyError extends GitHubCopilotError {
187
200
  name = "GitHubCopilotStreamEndedEarlyError";
201
+ durationMs;
202
+ startedContent;
188
203
  constructor(context, options) {
189
- super("stream-ended-early", context, options);
204
+ super("stream-ended-early", context, {
205
+ cause: options?.cause,
206
+ circumstances: streamEndedEarlyCircumstances(context.requestId, options?.durationMs, options?.startedContent),
207
+ });
208
+ this.durationMs = options?.durationMs;
209
+ this.startedContent = options?.startedContent;
210
+ }
211
+ fields() {
212
+ return {
213
+ ...super.fields(),
214
+ durationMs: this.durationMs ?? null,
215
+ startedContent: this.startedContent ?? null,
216
+ };
190
217
  }
191
218
  }
192
219
  /** The model finished with no text and no tool call, as Copilot's Gemini models sometimes do. Retryable. */
@@ -362,6 +389,10 @@ function numberField(fields, key) {
362
389
  const value = fields[key];
363
390
  return typeof value === "number" ? value : undefined;
364
391
  }
392
+ function booleanField(fields, key) {
393
+ const value = fields[key];
394
+ return typeof value === "boolean" ? value : undefined;
395
+ }
365
396
  function contextFromFields(fields) {
366
397
  return {
367
398
  modelId: stringField(fields, "modelId") ?? "",
@@ -385,6 +416,13 @@ function isSerializedCause(value, depth = 0) {
385
416
  (value.code === undefined || typeof value.code === "string") &&
386
417
  isSerializedCause(value.cause, depth + 1));
387
418
  }
419
+ /** The fields that hold a boolean; every other field holds a string, a number or null. */
420
+ const BOOLEAN_FIELD_KEYS = new Set(["startedContent"]);
421
+ function isSerializedFieldValue(key, field) {
422
+ if (field === null || typeof field === "string" || typeof field === "number")
423
+ return true;
424
+ return typeof field === "boolean" && BOOLEAN_FIELD_KEYS.has(key);
425
+ }
388
426
  function isSerializedError(value) {
389
427
  if (!isJsonRecord(value) || !isJsonRecord(value.fields))
390
428
  return false;
@@ -393,7 +431,7 @@ function isSerializedError(value) {
393
431
  typeof value.message === "string" &&
394
432
  typeof value.hint === "string" &&
395
433
  typeof value.retryable === "boolean" &&
396
- Object.values(value.fields).every((field) => field === null || typeof field === "string" || typeof field === "number") &&
434
+ Object.entries(value.fields).every(([key, field]) => isSerializedFieldValue(key, field)) &&
397
435
  isSerializedCause(value.cause));
398
436
  }
399
437
  /** A serialized reason: one of `allowed`, or `fallback` when the field is absent. Undefined when it is anything else. */
@@ -442,7 +480,11 @@ export function deserializeGitHubCopilotError(value) {
442
480
  case "GitHubCopilotServiceUnavailableError":
443
481
  return new GitHubCopilotServiceUnavailableError(context, { cause });
444
482
  case "GitHubCopilotStreamEndedEarlyError":
445
- return new GitHubCopilotStreamEndedEarlyError(context, { cause });
483
+ return new GitHubCopilotStreamEndedEarlyError(context, {
484
+ cause,
485
+ durationMs: numberField(fields, "durationMs"),
486
+ startedContent: booleanField(fields, "startedContent"),
487
+ });
446
488
  case "GitHubCopilotEmptyResponseError":
447
489
  return new GitHubCopilotEmptyResponseError(context, { cause });
448
490
  case "GitHubCopilotUnrecognizedResponseError": {
@@ -688,19 +730,21 @@ export function classifyGitHubCopilotFailure(error, failure) {
688
730
  if (providerError instanceof SyntaxError || providerError.error !== undefined) {
689
731
  return new GitHubCopilotUnrecognizedResponseError("malformed-body", context, { cause: providerError });
690
732
  }
691
- return failure.streamStarted ? new GitHubCopilotStreamEndedEarlyError(context, { cause: providerError }) : undefined;
733
+ if (failure.stream === undefined)
734
+ return undefined;
735
+ return new GitHubCopilotStreamEndedEarlyError({ ...context, requestId: context.requestId ?? failure.stream.requestId }, { cause: providerError, durationMs: failure.stream.durationMs, startedContent: failure.stream.startedContent });
692
736
  }
693
737
  /**
694
738
  * Type a failed Copilot assistant message at the provider boundary: classify `error` and record it on `output`,
695
739
  * keeping the provider's text after the typed message. A cancelled message is left alone.
696
740
  */
697
- export function recordGitHubCopilotFailure(output, error, streamStarted) {
741
+ export function recordGitHubCopilotFailure(output, error, stream) {
698
742
  if (output.stopReason !== "error")
699
743
  return;
700
744
  const typed = classifyGitHubCopilotFailure(error, {
701
745
  modelId: output.model,
702
746
  api: output.api,
703
- streamStarted,
747
+ stream,
704
748
  finishReason: output.rawStopReason,
705
749
  });
706
750
  if (typed !== undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"github-copilot-errors.js","sourceRoot":"","sources":["../../src/providers/github-copilot-errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAC5G,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAgBlE,MAAM,yBAAyB,GAAG,CAAC,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,CAAU,CAAC;AACrH,MAAM,uBAAuB,GAAG,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,UAAU,CAAU,CAAC;AAC5F,MAAM,oBAAoB,GAAG,CAAC,gBAAgB,EAAE,qBAAqB,EAAE,gBAAgB,CAAU,CAAC;AA6DlG,0GAA0G;AAC1G,MAAM,CAAC,MAAM,+BAA+B,GAAG,sBAAsB,CAAC;AAEtE,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,mFAAmF;AACnF,MAAM,0BAA0B,GAAyB,IAAI,GAAG,CAAyB;IACxF,mBAAmB;IACnB,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,iBAAiB;IACjB,uBAAuB;IACvB,qBAAqB;IACrB,oBAAoB;IACpB,gBAAgB;IAChB,uBAAuB;CACvB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAwC,IAAI,GAAG,CAAyB;IAC5F,cAAc;IACd,qBAAqB;IACrB,oBAAoB;IACpB,gBAAgB;IAChB,uBAAuB;CACvB,CAAC,CAAC;AAEH,MAAM,WAAW,GAAqD;IACrE,mBAAmB,EAAE,kCAAkC;IACvD,cAAc,EAAE,mCAAmC;IACnD,iBAAiB,EAAE,gCAAgC;IACnD,kBAAkB,EAAE,mDAAmD;IACvE,kBAAkB,EAA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,SAAS;QAAE,wBAAwB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;AACvF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAwB;IAClE,IAAI,MAAM,CAAC,QAAQ,KAAK,gBAAgB,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,MAAM,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,EAAE,CAAC;QAC/G,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CACnC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAC/F,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,+BAA+B,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;AAC/G,CAAC","sourcesContent":["import type { AssistantMessage, JsonObject } from \"../types.ts\";\nimport { type AssistantMessageDiagnostic, appendAssistantMessageDiagnostic } from \"../utils/diagnostics.ts\";\nimport { getProviderRetryAfterMs } from \"../utils/retry-hints.ts\";\n\n/** Stable codes of every GitHub Copilot request failure. Public API: never renamed or reused. */\nexport type GitHubCopilotErrorCode =\n\t| \"model-unavailable\"\n\t| \"rate-limited\"\n\t| \"quota-exhausted\"\n\t| \"content-filtered\"\n\t| \"prompt-too-large\"\n\t| \"invalid-request\"\n\t| \"authentication-failed\"\n\t| \"service-unavailable\"\n\t| \"stream-ended-early\"\n\t| \"empty-response\"\n\t| \"unrecognized-response\";\n\nconst MODEL_UNAVAILABLE_REASONS = [\"integration\", \"not-supported\", \"wrong-api\", \"no-endpoint\", \"not-found\"] as const;\nconst INVALID_REQUEST_REASONS = [\"reasoning-effort\", \"integration-id\", \"rejected\"] as const;\nconst UNRECOGNIZED_REASONS = [\"unknown-status\", \"unknown-error-event\", \"malformed-body\"] as const;\n\n/** Why Copilot refused to serve the model. */\nexport type GitHubCopilotModelUnavailableReason = (typeof MODEL_UNAVAILABLE_REASONS)[number];\n\n/** Which part of the request Copilot rejected. */\nexport type GitHubCopilotInvalidRequestReason = (typeof INVALID_REQUEST_REASONS)[number];\n\n/** What Atomic could not interpret. */\nexport type GitHubCopilotUnrecognizedReason = (typeof UNRECOGNIZED_REASONS)[number];\n\nexport type GitHubCopilotErrorName =\n\t| \"GitHubCopilotError\"\n\t| \"GitHubCopilotModelUnavailableError\"\n\t| \"GitHubCopilotRateLimitError\"\n\t| \"GitHubCopilotQuotaExhaustedError\"\n\t| \"GitHubCopilotContentFilterError\"\n\t| \"GitHubCopilotPromptTooLargeError\"\n\t| \"GitHubCopilotInvalidRequestError\"\n\t| \"GitHubCopilotAuthenticationError\"\n\t| \"GitHubCopilotServiceUnavailableError\"\n\t| \"GitHubCopilotStreamEndedEarlyError\"\n\t| \"GitHubCopilotEmptyResponseError\"\n\t| \"GitHubCopilotUnrecognizedResponseError\";\n\nexport type GitHubCopilotErrorFieldValue = string | number | null;\nexport type GitHubCopilotErrorFields = Readonly<Record<string, GitHubCopilotErrorFieldValue>>;\n\n/** The request a failure belongs to, and what the provider reported about it. No prompt text, tokens or bodies. */\nexport interface GitHubCopilotErrorContext {\n\treadonly modelId: string;\n\treadonly api: string;\n\t/** HTTP status, when the failure was an HTTP response. */\n\treadonly status?: number;\n\t/** The provider's own error code, such as `model_not_supported`. */\n\treadonly providerCode?: string;\n\t/** The provider's `x-request-id`, for support requests. */\n\treadonly requestId?: string;\n\t/** The provider's short error text, truncated. */\n\treadonly detail?: string;\n}\n\n/** A cause in wire form, bounded in depth. */\nexport interface SerializedGitHubCopilotErrorCause {\n\treadonly name: string;\n\treadonly message: string;\n\treadonly code?: string;\n\treadonly cause?: SerializedGitHubCopilotErrorCause;\n}\n\n/** Wire form of a GitHub Copilot error, as an assistant message's diagnostics carry it across processes. */\nexport interface SerializedGitHubCopilotError {\n\treadonly name: string;\n\treadonly code: GitHubCopilotErrorCode;\n\treadonly message: string;\n\treadonly hint: string;\n\treadonly retryable: boolean;\n\treadonly fields: GitHubCopilotErrorFields;\n\treadonly cause?: SerializedGitHubCopilotErrorCause;\n}\n\n/** `AssistantMessageDiagnostic.type` of the diagnostic that carries a serialized GitHub Copilot error. */\nexport const GITHUB_COPILOT_ERROR_DIAGNOSTIC = \"github_copilot_error\";\n\nconst MAX_CAUSE_DEPTH = 8;\nconst MAX_DETAIL_CHARS = 300;\n\n/** Every code, as a set that relayed values of any type can be checked against. */\nconst GITHUB_COPILOT_ERROR_CODES: ReadonlySet<unknown> = new Set<GitHubCopilotErrorCode>([\n\t\"model-unavailable\",\n\t\"rate-limited\",\n\t\"quota-exhausted\",\n\t\"content-filtered\",\n\t\"prompt-too-large\",\n\t\"invalid-request\",\n\t\"authentication-failed\",\n\t\"service-unavailable\",\n\t\"stream-ended-early\",\n\t\"empty-response\",\n\t\"unrecognized-response\",\n]);\n\nconst RETRYABLE_CODES: ReadonlySet<GitHubCopilotErrorCode> = new Set<GitHubCopilotErrorCode>([\n\t\"rate-limited\",\n\t\"service-unavailable\",\n\t\"stream-ended-early\",\n\t\"empty-response\",\n\t\"unrecognized-response\",\n]);\n\nconst WHAT_FAILED: Readonly<Record<GitHubCopilotErrorCode, string>> = {\n\t\"model-unavailable\": \"GitHub Copilot model unavailable\",\n\t\"rate-limited\": \"GitHub Copilot rate limit reached\",\n\t\"quota-exhausted\": \"GitHub Copilot quota exhausted\",\n\t\"content-filtered\": \"GitHub Copilot content filter blocked the request\",\n\t\"prompt-too-large\": \"GitHub Copilot prompt too large\",\n\t\"invalid-request\": \"GitHub Copilot rejected the request\",\n\t\"authentication-failed\": \"GitHub Copilot authentication failed\",\n\t\"service-unavailable\": \"GitHub Copilot service unavailable\",\n\t\"stream-ended-early\": \"GitHub Copilot response stream ended early\",\n\t\"empty-response\": \"GitHub Copilot returned an empty response\",\n\t\"unrecognized-response\": \"GitHub Copilot returned an unrecognized response\",\n};\n\nconst HINTS: Readonly<Record<GitHubCopilotErrorCode, string>> = {\n\t\"model-unavailable\": \"Pick another model, or run /login to refresh the models this account can use.\",\n\t\"rate-limited\": \"Wait for the rate limit to reset; Atomic retries the request when retries are enabled.\",\n\t\"quota-exhausted\": \"Pick another model, or wait until the Copilot plan's quota resets.\",\n\t\"content-filtered\":\n\t\t\"Rephrase the request or pick another model; retry.fallbackOnContentFilter decides whether a fallback model is tried.\",\n\t\"prompt-too-large\": \"Run /compact or start a new session to shrink the conversation.\",\n\t\"invalid-request\": \"Check the model's thinking level and any models.json overrides for this model.\",\n\t\"authentication-failed\": \"Run /login to sign in to GitHub Copilot again, or check COPILOT_GITHUB_TOKEN.\",\n\t\"service-unavailable\": \"Retry later; Atomic retries the request when retries are enabled.\",\n\t\"stream-ended-early\": \"Retry the request; Atomic retries it when retries are enabled.\",\n\t\"empty-response\": \"Retry the request; Atomic retries it when retries are enabled.\",\n\t\"unrecognized-response\": \"Retry the request, and report it if it keeps happening.\",\n};\n\n/** Hints for the reasons that need more than their code's hint. */\nconst MODEL_UNAVAILABLE_HINTS: Readonly<Partial<Record<GitHubCopilotModelUnavailableReason, string>>> = {\n\tintegration:\n\t\t\"Copilot does not offer this model to Atomic's integration. Pick another model, or run /login to refresh the model list.\",\n\t\"wrong-api\": \"Run /login to refresh the model list so Atomic calls the API Copilot serves this model on.\",\n\t\"no-endpoint\": \"Copilot has no endpoint for this model under this account's settings. Pick another model.\",\n};\n\nconst INVALID_REQUEST_HINTS: Readonly<Partial<Record<GitHubCopilotInvalidRequestReason, string>>> = {\n\t\"reasoning-effort\": \"Pick a thinking level this model lists.\",\n\t\"integration-id\": \"Remove the Copilot-Integration-Id header override from models.json.\",\n};\n\nfunction failureMessage(code: GitHubCopilotErrorCode, modelId: string, hint: string): string {\n\treturn `${WHAT_FAILED[code]}: ${modelId} (${code}). ${hint}`;\n}\n\ninterface GitHubCopilotErrorOptions {\n\treadonly hint?: string;\n\treadonly cause?: unknown;\n}\n\n/** Base of every GitHub Copilot request failure. Catch this to handle the whole family. */\nexport class GitHubCopilotError extends Error {\n\toverride readonly name: string = \"GitHubCopilotError\";\n\treadonly code: GitHubCopilotErrorCode;\n\treadonly retryable: boolean;\n\treadonly hint: string;\n\treadonly modelId: string;\n\treadonly api: string;\n\treadonly status: number | undefined;\n\treadonly providerCode: string | undefined;\n\treadonly requestId: string | undefined;\n\treadonly detail: string | undefined;\n\n\tconstructor(code: GitHubCopilotErrorCode, context: GitHubCopilotErrorContext, options?: GitHubCopilotErrorOptions) {\n\t\tconst hint = options?.hint ?? HINTS[code];\n\t\tsuper(\n\t\t\tfailureMessage(code, context.modelId, hint),\n\t\t\toptions?.cause === undefined ? undefined : { cause: options.cause },\n\t\t);\n\t\tthis.code = code;\n\t\tthis.retryable = RETRYABLE_CODES.has(code);\n\t\tthis.hint = hint;\n\t\tthis.modelId = context.modelId;\n\t\tthis.api = context.api;\n\t\tthis.status = context.status;\n\t\tthis.providerCode = context.providerCode;\n\t\tthis.requestId = context.requestId;\n\t\tthis.detail = context.detail;\n\t}\n\n\t/** JSON-safe context fields; subclasses add their own. */\n\tfields(): GitHubCopilotErrorFields {\n\t\treturn {\n\t\t\tmodelId: this.modelId,\n\t\t\tapi: this.api,\n\t\t\tstatus: this.status ?? null,\n\t\t\tproviderCode: this.providerCode ?? null,\n\t\t\trequestId: this.requestId ?? null,\n\t\t\tdetail: this.detail ?? null,\n\t\t};\n\t}\n}\n\n/** Copilot will not serve this model to this account, integration or API. Not retryable; a fallback model may work. */\nexport class GitHubCopilotModelUnavailableError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotModelUnavailableError\" as const;\n\tdeclare readonly code: \"model-unavailable\";\n\treadonly reason: GitHubCopilotModelUnavailableReason;\n\n\tconstructor(\n\t\treason: GitHubCopilotModelUnavailableReason,\n\t\tcontext: GitHubCopilotErrorContext,\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"model-unavailable\", context, { hint: MODEL_UNAVAILABLE_HINTS[reason], cause: options?.cause });\n\t\tthis.reason = reason;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), reason: this.reason };\n\t}\n}\n\n/** Copilot throttled the request. Retryable after `retryAfterMs` when the server sent a delay. */\nexport class GitHubCopilotRateLimitError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotRateLimitError\" as const;\n\tdeclare readonly code: \"rate-limited\";\n\treadonly retryAfterMs: number | undefined;\n\n\tconstructor(context: GitHubCopilotErrorContext, retryAfterMs?: number, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"rate-limited\", context, options);\n\t\tthis.retryAfterMs = retryAfterMs;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), retryAfterMs: this.retryAfterMs ?? null };\n\t}\n}\n\n/** The plan's quota or billing allowance for the model is used up. Not retryable until it resets. */\nexport class GitHubCopilotQuotaExhaustedError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotQuotaExhaustedError\" as const;\n\tdeclare readonly code: \"quota-exhausted\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"quota-exhausted\", context, options);\n\t}\n}\n\n/** A content or safety filter blocked the request or the response. The same request is refused again. */\nexport class GitHubCopilotContentFilterError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotContentFilterError\" as const;\n\tdeclare readonly code: \"content-filtered\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"content-filtered\", context, options);\n\t}\n}\n\n/** The prompt exceeds the model's prompt-token limit. Compact the conversation instead of retrying. */\nexport class GitHubCopilotPromptTooLargeError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotPromptTooLargeError\" as const;\n\tdeclare readonly code: \"prompt-too-large\";\n\treadonly promptTokens: number | undefined;\n\treadonly limitTokens: number | undefined;\n\n\tconstructor(\n\t\tcontext: GitHubCopilotErrorContext,\n\t\ttokens?: { readonly promptTokens?: number; readonly limitTokens?: number },\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"prompt-too-large\", context, options);\n\t\tthis.promptTokens = tokens?.promptTokens;\n\t\tthis.limitTokens = tokens?.limitTokens;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), promptTokens: this.promptTokens ?? null, limitTokens: this.limitTokens ?? null };\n\t}\n}\n\n/** Copilot rejected the request's shape or settings. Sending it again fails the same way. */\nexport class GitHubCopilotInvalidRequestError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotInvalidRequestError\" as const;\n\tdeclare readonly code: \"invalid-request\";\n\treadonly reason: GitHubCopilotInvalidRequestReason;\n\n\tconstructor(\n\t\treason: GitHubCopilotInvalidRequestReason,\n\t\tcontext: GitHubCopilotErrorContext,\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"invalid-request\", context, { hint: INVALID_REQUEST_HINTS[reason], cause: options?.cause });\n\t\tthis.reason = reason;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), reason: this.reason };\n\t}\n}\n\n/** Copilot refused the credential. Sign in again; another provider's model may still work. */\nexport class GitHubCopilotAuthenticationError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotAuthenticationError\" as const;\n\tdeclare readonly code: \"authentication-failed\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"authentication-failed\", context, options);\n\t}\n}\n\n/** Copilot or the model behind it is down, overloaded or timed out. Retryable. */\nexport class GitHubCopilotServiceUnavailableError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotServiceUnavailableError\" as const;\n\tdeclare readonly code: \"service-unavailable\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"service-unavailable\", context, options);\n\t}\n}\n\n/** The response stream stopped before its finish reason or terminal event. Retryable. */\nexport class GitHubCopilotStreamEndedEarlyError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotStreamEndedEarlyError\" as const;\n\tdeclare readonly code: \"stream-ended-early\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"stream-ended-early\", context, options);\n\t}\n}\n\n/** The model finished with no text and no tool call, as Copilot's Gemini models sometimes do. Retryable. */\nexport class GitHubCopilotEmptyResponseError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotEmptyResponseError\" as const;\n\tdeclare readonly code: \"empty-response\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"empty-response\", context, options);\n\t}\n}\n\n/** Copilot answered with a status, error event or body Atomic does not recognize. Retryable a bounded number of times. */\nexport class GitHubCopilotUnrecognizedResponseError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotUnrecognizedResponseError\" as const;\n\tdeclare readonly code: \"unrecognized-response\";\n\treadonly reason: GitHubCopilotUnrecognizedReason;\n\n\tconstructor(\n\t\treason: GitHubCopilotUnrecognizedReason,\n\t\tcontext: GitHubCopilotErrorContext,\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"unrecognized-response\", context, options);\n\t\tthis.reason = reason;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), reason: this.reason };\n\t}\n}\n\nconst CODE_BY_NAME: Readonly<Record<Exclude<GitHubCopilotErrorName, \"GitHubCopilotError\">, GitHubCopilotErrorCode>> = {\n\tGitHubCopilotModelUnavailableError: \"model-unavailable\",\n\tGitHubCopilotRateLimitError: \"rate-limited\",\n\tGitHubCopilotQuotaExhaustedError: \"quota-exhausted\",\n\tGitHubCopilotContentFilterError: \"content-filtered\",\n\tGitHubCopilotPromptTooLargeError: \"prompt-too-large\",\n\tGitHubCopilotInvalidRequestError: \"invalid-request\",\n\tGitHubCopilotAuthenticationError: \"authentication-failed\",\n\tGitHubCopilotServiceUnavailableError: \"service-unavailable\",\n\tGitHubCopilotStreamEndedEarlyError: \"stream-ended-early\",\n\tGitHubCopilotEmptyResponseError: \"empty-response\",\n\tGitHubCopilotUnrecognizedResponseError: \"unrecognized-response\",\n};\n\ninterface StructuralError {\n\treadonly name?: unknown;\n\treadonly code?: unknown;\n\treadonly cause?: unknown;\n\treadonly diagnostics?: unknown;\n}\n\nfunction structural(value: unknown): StructuralError | undefined {\n\treturn typeof value === \"object\" && value !== null ? (value as StructuralError) : undefined;\n}\n\n/** A family member seen from another process or realm: its name and code, maybe its message. */\ninterface StructuralFamilyMember {\n\treadonly name: string;\n\treadonly code: GitHubCopilotErrorCode;\n\treadonly message?: unknown;\n}\n\n/** A family member relayed from another process or realm: an object with a family name and that name's code. */\nfunction isRelayedFamilyMember(value: unknown): value is StructuralFamilyMember {\n\tconst candidate = structural(value);\n\tif (typeof candidate?.name !== \"string\") return false;\n\tif (candidate.name === \"GitHubCopilotError\") return GITHUB_COPILOT_ERROR_CODES.has(candidate.code);\n\treturn CODE_BY_NAME[candidate.name as keyof typeof CODE_BY_NAME] === candidate.code;\n}\n\n/** Rebuild a relayed family member as its class; one that carries only its name and code gets that code's hint. */\nfunction rebuildRelayedFamilyMember(found: StructuralFamilyMember): GitHubCopilotError | undefined {\n\tconst deserialized = deserializeGitHubCopilotError(found);\n\tif (deserialized) return deserialized;\n\tif (\"fields\" in found || \"hint\" in found || \"retryable\" in found || \"cause\" in found) return undefined;\n\tif (Reflect.ownKeys(found).some((key) => key !== \"name\" && key !== \"code\" && key !== \"message\")) return undefined;\n\tif (\"message\" in found && typeof found.message !== \"string\") return undefined;\n\treturn deserializeGitHubCopilotError({\n\t\tname: found.name,\n\t\tcode: found.code,\n\t\tmessage: found.message ?? \"\",\n\t\thint: HINTS[found.code],\n\t\tretryable: RETRYABLE_CODES.has(found.code),\n\t\tfields: {},\n\t});\n}\n\n/**\n * The typed error at one link of a cause chain: the link itself, rebuilt when it was relayed from another process, or\n * the error its `diagnostics` carry when the link is a failed assistant message, as a workflow failure's cause is.\n */\nfunction typedErrorAt(link: unknown): GitHubCopilotError | undefined {\n\tif (link instanceof GitHubCopilotError) return link;\n\tif (isRelayedFamilyMember(link)) return rebuildRelayedFamilyMember(link);\n\treturn getGitHubCopilotError(structural(link));\n}\n\n/** The first typed error `matches` accepts, walking at most MAX_CAUSE_DEPTH links of the cause chain. */\nfunction findInCauseChain(\n\terror: unknown,\n\tmatches: (typed: GitHubCopilotError) => boolean,\n): GitHubCopilotError | undefined {\n\tlet current = error;\n\tfor (let depth = 0; depth < MAX_CAUSE_DEPTH; depth++) {\n\t\tconst typed = typedErrorAt(current);\n\t\tif (typed !== undefined && matches(typed)) return typed;\n\t\tcurrent = structural(current)?.cause;\n\t}\n\treturn undefined;\n}\n\n/**\n * A guard that answers whether the error, anything in its cause chain, or a failed assistant message in that chain holds\n * an error of this class. It returns a plain boolean, not a type predicate: the value passed in is usually the wrapper\n * or the message, not the error. Use `findGitHubCopilotError()` for the instance.\n */\nfunction guard(ctor: abstract new (...args: never[]) => GitHubCopilotError): (error: unknown) => boolean {\n\treturn (error) => findInCauseChain(error, (typed) => typed instanceof ctor) !== undefined;\n}\n\n/**\n * True when the error, anything in its cause chain, or a failed assistant message in that chain holds a GitHub Copilot\n * error. A plain boolean, not a type predicate: use `findGitHubCopilotError()` for the instance.\n */\nexport function isGitHubCopilotError(error: unknown): boolean {\n\treturn findGitHubCopilotError(error) !== undefined;\n}\n\n/**\n * First GitHub Copilot error in the cause chain, as an instance of its class: a link that is one, rebuilt when it was\n * relayed from another process, or the error a failed assistant message's diagnostics carry. The chain is walked to a\n * bounded depth, through JSON round-tripped links too.\n */\nexport function findGitHubCopilotError(error: unknown): GitHubCopilotError | undefined {\n\treturn findInCauseChain(error, () => true);\n}\n\n/** True when the first GitHub Copilot error in the cause chain says the same request may be sent again. */\nexport function isRetryableGitHubCopilotError(error: unknown): boolean {\n\treturn findGitHubCopilotError(error)?.retryable === true;\n}\n\nexport const isGitHubCopilotModelUnavailableError = guard(GitHubCopilotModelUnavailableError);\nexport const isGitHubCopilotRateLimitError = guard(GitHubCopilotRateLimitError);\nexport const isGitHubCopilotQuotaExhaustedError = guard(GitHubCopilotQuotaExhaustedError);\nexport const isGitHubCopilotContentFilterError = guard(GitHubCopilotContentFilterError);\nexport const isGitHubCopilotPromptTooLargeError = guard(GitHubCopilotPromptTooLargeError);\nexport const isGitHubCopilotInvalidRequestError = guard(GitHubCopilotInvalidRequestError);\nexport const isGitHubCopilotAuthenticationError = guard(GitHubCopilotAuthenticationError);\nexport const isGitHubCopilotServiceUnavailableError = guard(GitHubCopilotServiceUnavailableError);\nexport const isGitHubCopilotStreamEndedEarlyError = guard(GitHubCopilotStreamEndedEarlyError);\nexport const isGitHubCopilotEmptyResponseError = guard(GitHubCopilotEmptyResponseError);\nexport const isGitHubCopilotUnrecognizedResponseError = guard(GitHubCopilotUnrecognizedResponseError);\n\nfunction serializeCause(cause: unknown, depth: number): SerializedGitHubCopilotErrorCause | undefined {\n\tif (depth >= MAX_CAUSE_DEPTH || cause === undefined || cause === null) return undefined;\n\tconst candidate = structural(cause);\n\tconst nested = serializeCause(candidate?.cause, depth + 1);\n\treturn {\n\t\tname: typeof candidate?.name === \"string\" ? candidate.name : typeof cause,\n\t\tmessage: truncate(cause instanceof Error ? cause.message : String(cause)),\n\t\t...(typeof candidate?.code === \"string\" ? { code: candidate.code } : {}),\n\t\t...(nested === undefined ? {} : { cause: nested }),\n\t};\n}\n\n/** Wire form for crossing a process boundary; the cause chain is kept to a bounded depth. */\nexport function serializeGitHubCopilotError(error: GitHubCopilotError): SerializedGitHubCopilotError {\n\tconst cause = serializeCause(error.cause, 0);\n\treturn {\n\t\tname: error.name,\n\t\tcode: error.code,\n\t\tmessage: error.message,\n\t\thint: error.hint,\n\t\tretryable: error.retryable,\n\t\tfields: error.fields(),\n\t\t...(cause === undefined ? {} : { cause }),\n\t};\n}\n\nfunction rehydrateCause(cause: SerializedGitHubCopilotErrorCause | undefined): Error | undefined {\n\tif (cause === undefined) return undefined;\n\tconst family = isRelayedFamilyMember(cause)\n\t\t? rebuildRelayedFamilyMember({ name: cause.name, code: cause.code, message: cause.message })\n\t\t: undefined;\n\tconst error = family ?? new Error(cause.message);\n\tObject.defineProperties(error, {\n\t\tmessage: { value: cause.message },\n\t\tcause: { value: rehydrateCause(cause.cause), writable: true, configurable: true },\n\t});\n\tObject.defineProperty(error, \"name\", { value: cause.name });\n\tif (cause.code !== undefined) Object.defineProperty(error, \"code\", { value: cause.code, enumerable: true });\n\treturn error;\n}\n\nfunction stringField(fields: GitHubCopilotErrorFields, key: string): string | undefined {\n\tconst value = fields[key];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction numberField(fields: GitHubCopilotErrorFields, key: string): number | undefined {\n\tconst value = fields[key];\n\treturn typeof value === \"number\" ? value : undefined;\n}\n\nfunction contextFromFields(fields: GitHubCopilotErrorFields): GitHubCopilotErrorContext {\n\treturn {\n\t\tmodelId: stringField(fields, \"modelId\") ?? \"\",\n\t\tapi: stringField(fields, \"api\") ?? \"\",\n\t\tstatus: numberField(fields, \"status\"),\n\t\tproviderCode: stringField(fields, \"providerCode\"),\n\t\trequestId: stringField(fields, \"requestId\"),\n\t\tdetail: stringField(fields, \"detail\"),\n\t};\n}\n\nfunction isJsonRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isSerializedCause(value: unknown, depth = 0): value is SerializedGitHubCopilotErrorCause {\n\tif (value === undefined) return true;\n\tif (depth >= MAX_CAUSE_DEPTH || !isJsonRecord(value)) return false;\n\treturn (\n\t\ttypeof value.name === \"string\" &&\n\t\ttypeof value.message === \"string\" &&\n\t\t(value.code === undefined || typeof value.code === \"string\") &&\n\t\tisSerializedCause(value.cause, depth + 1)\n\t);\n}\n\nfunction isSerializedError(value: unknown): value is SerializedGitHubCopilotError {\n\tif (!isJsonRecord(value) || !isJsonRecord(value.fields)) return false;\n\treturn (\n\t\ttypeof value.name === \"string\" &&\n\t\tGITHUB_COPILOT_ERROR_CODES.has(value.code) &&\n\t\ttypeof value.message === \"string\" &&\n\t\ttypeof value.hint === \"string\" &&\n\t\ttypeof value.retryable === \"boolean\" &&\n\t\tObject.values(value.fields).every(\n\t\t\t(field) => field === null || typeof field === \"string\" || typeof field === \"number\",\n\t\t) &&\n\t\tisSerializedCause(value.cause)\n\t);\n}\n\n/** A serialized reason: one of `allowed`, or `fallback` when the field is absent. Undefined when it is anything else. */\nfunction reasonField<T extends string>(\n\tfields: GitHubCopilotErrorFields,\n\tallowed: readonly T[],\n\tfallback: T,\n): T | undefined {\n\tconst reason = fields.reason;\n\tif (reason === undefined || reason === null) return fallback;\n\treturn allowed.find((candidate) => candidate === reason);\n}\n\n/** Whether a serialized error's name, if it is a known class, goes with its code. */\nfunction agreesWithClass(serialized: SerializedGitHubCopilotError): boolean {\n\treturn (\n\t\t!Object.hasOwn(CODE_BY_NAME, serialized.name) ||\n\t\t(CODE_BY_NAME as Record<string, string>)[serialized.name] === serialized.code\n\t);\n}\n\n/**\n * Rebuild a serialized GitHub Copilot error as its own class. An unknown name becomes the family base with the\n * original name, code, message, hint and retryability kept. Returns undefined for anything that is not a serialized\n * GitHub Copilot error: a code this version does not know, a class name that does not go with its code, or a reason\n * that class does not have.\n */\nexport function deserializeGitHubCopilotError(value: unknown): GitHubCopilotError | undefined {\n\tif (!isSerializedError(value) || !agreesWithClass(value)) return undefined;\n\tconst cause = rehydrateCause(value.cause);\n\tconst fields = value.fields;\n\tconst context = contextFromFields(fields);\n\tswitch (value.name) {\n\t\tcase \"GitHubCopilotModelUnavailableError\": {\n\t\t\tconst reason = reasonField(fields, MODEL_UNAVAILABLE_REASONS, \"not-supported\");\n\t\t\treturn reason === undefined ? undefined : new GitHubCopilotModelUnavailableError(reason, context, { cause });\n\t\t}\n\t\tcase \"GitHubCopilotRateLimitError\":\n\t\t\treturn new GitHubCopilotRateLimitError(context, numberField(fields, \"retryAfterMs\"), { cause });\n\t\tcase \"GitHubCopilotQuotaExhaustedError\":\n\t\t\treturn new GitHubCopilotQuotaExhaustedError(context, { cause });\n\t\tcase \"GitHubCopilotContentFilterError\":\n\t\t\treturn new GitHubCopilotContentFilterError(context, { cause });\n\t\tcase \"GitHubCopilotPromptTooLargeError\":\n\t\t\treturn new GitHubCopilotPromptTooLargeError(\n\t\t\t\tcontext,\n\t\t\t\t{ promptTokens: numberField(fields, \"promptTokens\"), limitTokens: numberField(fields, \"limitTokens\") },\n\t\t\t\t{ cause },\n\t\t\t);\n\t\tcase \"GitHubCopilotInvalidRequestError\": {\n\t\t\tconst reason = reasonField(fields, INVALID_REQUEST_REASONS, \"rejected\");\n\t\t\treturn reason === undefined ? undefined : new GitHubCopilotInvalidRequestError(reason, context, { cause });\n\t\t}\n\t\tcase \"GitHubCopilotAuthenticationError\":\n\t\t\treturn new GitHubCopilotAuthenticationError(context, { cause });\n\t\tcase \"GitHubCopilotServiceUnavailableError\":\n\t\t\treturn new GitHubCopilotServiceUnavailableError(context, { cause });\n\t\tcase \"GitHubCopilotStreamEndedEarlyError\":\n\t\t\treturn new GitHubCopilotStreamEndedEarlyError(context, { cause });\n\t\tcase \"GitHubCopilotEmptyResponseError\":\n\t\t\treturn new GitHubCopilotEmptyResponseError(context, { cause });\n\t\tcase \"GitHubCopilotUnrecognizedResponseError\": {\n\t\t\tconst reason = reasonField(fields, UNRECOGNIZED_REASONS, \"malformed-body\");\n\t\t\treturn reason === undefined\n\t\t\t\t? undefined\n\t\t\t\t: new GitHubCopilotUnrecognizedResponseError(reason, context, { cause });\n\t\t}\n\t\tdefault: {\n\t\t\tconst base = new GitHubCopilotError(value.code, context, { hint: value.hint, cause });\n\t\t\tObject.defineProperties(base, {\n\t\t\t\tname: { value: value.name },\n\t\t\t\tmessage: { value: value.message },\n\t\t\t\tretryable: { value: value.retryable },\n\t\t\t});\n\t\t\treturn base;\n\t\t}\n\t}\n}\n\n/** Record `error` on a failed assistant message: its diagnostics carry the typed error across processes. */\nexport function recordGitHubCopilotError(\n\toutput: AssistantMessage,\n\terror: GitHubCopilotError,\n\tproviderText?: string,\n): void {\n\toutput.errorMessage =\n\t\tproviderText === undefined || providerText === error.message\n\t\t\t? error.message\n\t\t\t: `${error.message}\\n\\n${providerText}`;\n\tif (error instanceof GitHubCopilotRateLimitError && error.retryAfterMs !== undefined) {\n\t\toutput.retryAfterMs = error.retryAfterMs;\n\t}\n\tappendAssistantMessageDiagnostic(output, {\n\t\ttype: GITHUB_COPILOT_ERROR_DIAGNOSTIC,\n\t\ttimestamp: Date.now(),\n\t\terror: { name: error.name, message: error.message, code: error.code },\n\t\tdetails: JSON.parse(JSON.stringify(serializeGitHubCopilotError(error))) as JsonObject,\n\t});\n}\n\n/**\n * The GitHub Copilot error an assistant message's diagnostics carry, rebuilt as its class: the latest valid one.\n * Accepts a message read back from JSON, whose diagnostics are validated here.\n */\nexport function getGitHubCopilotError(\n\tmessage: { readonly diagnostics?: unknown } | undefined,\n): GitHubCopilotError | undefined {\n\tconst diagnostics = message?.diagnostics;\n\tif (!Array.isArray(diagnostics)) return undefined;\n\tfor (const entry of [...diagnostics].reverse()) {\n\t\tconst diagnostic = structural(entry) as Partial<AssistantMessageDiagnostic> | undefined;\n\t\tif (diagnostic?.type !== GITHUB_COPILOT_ERROR_DIAGNOSTIC) continue;\n\t\tconst error = deserializeGitHubCopilotError(diagnostic.details);\n\t\tif (error !== undefined) return error;\n\t}\n\treturn undefined;\n}\n\nfunction truncate(text: string): string {\n\treturn text.length <= MAX_DETAIL_CHARS ? text : `${text.slice(0, MAX_DETAIL_CHARS)}…`;\n}\n\nfunction nonEmptyString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" && value.trim().length > 0 ? value.trim() : undefined;\n}\n\ntype ProviderFailure = Error & {\n\tstatus?: unknown;\n\tcode?: unknown;\n\ttype?: unknown;\n\terror?: unknown;\n\trequestID?: unknown;\n\trequest_id?: unknown;\n\theaders?: unknown;\n};\n\n/**\n * The error that holds the provider's response. When the retry helper gave up on a server-requested delay above its\n * cap, it threw a wrapper that keeps only `status` and `retryAfterMs` and holds the original response error as its\n * `cause`: no code, body or headers of its own. The response is then that cause. Any other error is its own response.\n */\nfunction responseOf(error: ProviderFailure): ProviderFailure {\n\tconst origin = error.cause;\n\tconst wrapsResponse =\n\t\terror.code === undefined &&\n\t\terror.error === undefined &&\n\t\terror.headers === undefined &&\n\t\torigin instanceof Error &&\n\t\ttypeof (origin as ProviderFailure).status === \"number\";\n\treturn wrapsResponse ? (origin as ProviderFailure) : error;\n}\n\n/** The SDK's request ID, else Copilot's `x-request-id` header, which the Anthropic SDK does not read. */\nfunction requestIdOf(error: ProviderFailure): string | undefined {\n\tconst headers = error.headers;\n\tconst header = headers instanceof Headers ? headers.get(\"x-request-id\") : undefined;\n\treturn nonEmptyString(error.requestID) ?? nonEmptyString(error.request_id) ?? nonEmptyString(header);\n}\n\n/**\n * The provider's code: the SDK's `code`, then the parsed body's `error.code` or `code`. A Messages `error` event\n * arrives with no HTTP status and names its failure only by `type`, so that type is its code.\n */\nfunction providerCodeOf(error: ProviderFailure): string | undefined {\n\tconst body = structural(error.error) as { code?: unknown; error?: unknown } | undefined;\n\treturn (\n\t\tnonEmptyString(error.code) ??\n\t\tnonEmptyString((structural(body?.error) as { code?: unknown } | undefined)?.code) ??\n\t\tnonEmptyString(body?.code) ??\n\t\t(error.status === undefined && error.error !== undefined ? nonEmptyString(error.type) : undefined)\n\t);\n}\n\n/** The provider's error text: the parsed body's message, else the SDK message without its status prefix. */\nfunction providerDetailOf(error: ProviderFailure, status: number | undefined): string | undefined {\n\tconst body = structural(error.error) as { message?: unknown; error?: unknown } | undefined;\n\tconst bodyMessage =\n\t\tnonEmptyString((structural(body?.error) as { message?: unknown } | undefined)?.message) ??\n\t\tnonEmptyString(body?.message);\n\tif (bodyMessage !== undefined) return truncate(bodyMessage);\n\tif (typeof error.error === \"string\") {\n\t\tconst text = nonEmptyString(error.error);\n\t\treturn text === undefined ? undefined : truncate(text);\n\t}\n\tconst message =\n\t\tstatus !== undefined && error.message.startsWith(`${status} `)\n\t\t\t? error.message.slice(`${status} `.length)\n\t\t\t: error.message;\n\tconst text = nonEmptyString(message);\n\treturn text === undefined ? undefined : truncate(text);\n}\n\n/** Provider codes Copilot sends, observed live or documented publicly, and the failure each one means. */\nconst PROVIDER_CODE_FAILURES: Readonly<\n\tRecord<string, (context: GitHubCopilotErrorContext, error: ProviderFailure) => GitHubCopilotError>\n> = {\n\tmodel_not_available_for_integrator: (context, cause) =>\n\t\tnew GitHubCopilotModelUnavailableError(\"integration\", context, { cause }),\n\tmodel_not_supported: (context, cause) => new GitHubCopilotModelUnavailableError(\"not-supported\", context, { cause }),\n\tunsupported_api_for_model: (context, cause) =>\n\t\tnew GitHubCopilotModelUnavailableError(\"wrong-api\", context, { cause }),\n\tmodel_max_prompt_tokens_exceeded: (context, cause) => promptTooLarge(context, cause),\n\tcontext_length_exceeded: (context, cause) => promptTooLarge(context, cause),\n\tinvalid_reasoning_effort: (context, cause) =>\n\t\tnew GitHubCopilotInvalidRequestError(\"reasoning-effort\", context, { cause }),\n\tcontent_filter: (context, cause) => new GitHubCopilotContentFilterError(context, { cause }),\n\tcyber_policy: (context, cause) => new GitHubCopilotContentFilterError(context, { cause }),\n\trate_limit_exceeded: (context, cause) =>\n\t\tnew GitHubCopilotRateLimitError(context, getProviderRetryAfterMs(cause), { cause }),\n\tinsufficient_quota: (context, cause) => new GitHubCopilotQuotaExhaustedError(context, { cause }),\n\tquota_exceeded: (context, cause) => new GitHubCopilotQuotaExhaustedError(context, { cause }),\n\tserver_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n\tinvalid_request_error: (context, cause) =>\n\t\tbadRequestTextFailure(undefined, context, cause) ??\n\t\tnew GitHubCopilotInvalidRequestError(\"rejected\", context, { cause }),\n\tauthentication_error: (context, cause) => new GitHubCopilotAuthenticationError(context, { cause }),\n\tpermission_error: (context, cause) => new GitHubCopilotAuthenticationError(context, { cause }),\n\tbilling_error: (context, cause) => new GitHubCopilotQuotaExhaustedError(context, { cause }),\n\tnot_found_error: (context, cause) => new GitHubCopilotModelUnavailableError(\"not-found\", context, { cause }),\n\trequest_too_large: (context, cause) => promptTooLarge(context, cause),\n\trate_limit_error: (context, cause) =>\n\t\tnew GitHubCopilotRateLimitError(context, getProviderRetryAfterMs(cause), { cause }),\n\toverloaded_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n\tapi_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n\ttimeout_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n};\n\nconst PROMPT_TOKENS_PATTERN = /prompt token count of (\\d+) exceeds the limit of (\\d+)/i;\n\nfunction promptTooLarge(context: GitHubCopilotErrorContext, cause: ProviderFailure): GitHubCopilotPromptTooLargeError {\n\tconst match = context.detail?.match(PROMPT_TOKENS_PATTERN);\n\treturn new GitHubCopilotPromptTooLargeError(\n\t\tcontext,\n\t\tmatch ? { promptTokens: Number(match[1]), limitTokens: Number(match[2]) } : undefined,\n\t\t{ cause },\n\t);\n}\n\n/**\n * Plain-text 400 bodies Copilot sends without a JSON code, observed live. Each is matched in full at the boundary so\n * the rest of Atomic branches on the typed code instead of on this text.\n */\nfunction plainTextFailure(\n\tdetail: string | undefined,\n\tcontext: GitHubCopilotErrorContext,\n\tcause: ProviderFailure,\n): GitHubCopilotError | undefined {\n\tconst text = detail?.toLowerCase();\n\tif (text === \"no model endpoints available given user constraints\") {\n\t\treturn new GitHubCopilotModelUnavailableError(\"no-endpoint\", context, { cause });\n\t}\n\tif (text === \"bad request: unknown copilot-integration-id\") {\n\t\treturn new GitHubCopilotInvalidRequestError(\"integration-id\", context, { cause });\n\t}\n\treturn undefined;\n}\n\n/**\n * Copilot sends a used-up monthly quota as HTTP 429 with `x-ratelimit-exceeded: quota_exceeded` and the plain body\n * `quota exceeded` (seen in public reports), unlike a short rate limit.\n */\nfunction reportsExhaustedQuota(response: ProviderFailure): boolean {\n\tconst exceeded = response.headers instanceof Headers ? response.headers.get(\"x-ratelimit-exceeded\") : null;\n\treturn (\n\t\texceeded?.trim().toLowerCase() === \"quota_exceeded\" ||\n\t\tproviderDetailOf(response, 429)?.toLowerCase() === \"quota exceeded\"\n\t);\n}\n\n/**\n * A 400 whose code Atomic does not recognize: Copilot's own prompt-token overflow text means the prompt is too large,\n * whatever the code; without a code, the exact plain-text bodies Copilot sends are matched.\n */\nfunction badRequestTextFailure(\n\tproviderCode: string | undefined,\n\tcontext: GitHubCopilotErrorContext,\n\tcause: ProviderFailure,\n): GitHubCopilotError | undefined {\n\tif (context.detail?.match(PROMPT_TOKENS_PATTERN)) return promptTooLarge(context, cause);\n\treturn providerCode === undefined ? plainTextFailure(context.detail, context, cause) : undefined;\n}\n\nfunction statusFailure(\n\tstatus: number,\n\tcontext: GitHubCopilotErrorContext,\n\tcause: ProviderFailure,\n\treportsQuota: boolean,\n): GitHubCopilotError {\n\tswitch (status) {\n\t\tcase 401:\n\t\tcase 403:\n\t\t\treturn new GitHubCopilotAuthenticationError(context, { cause });\n\t\tcase 402:\n\t\t\treturn new GitHubCopilotQuotaExhaustedError(context, { cause });\n\t\tcase 404:\n\t\t\treturn new GitHubCopilotModelUnavailableError(\"not-found\", context, { cause });\n\t\tcase 408:\n\t\t\treturn new GitHubCopilotServiceUnavailableError(context, { cause });\n\t\tcase 413:\n\t\t\treturn promptTooLarge(context, cause);\n\t\tcase 429:\n\t\t\treturn reportsQuota\n\t\t\t\t? new GitHubCopilotQuotaExhaustedError(context, { cause })\n\t\t\t\t: new GitHubCopilotRateLimitError(context, getProviderRetryAfterMs(cause), { cause });\n\t}\n\tif (status >= 500 && status <= 599) return new GitHubCopilotServiceUnavailableError(context, { cause });\n\tif (status >= 400 && status <= 499) return new GitHubCopilotInvalidRequestError(\"rejected\", context, { cause });\n\treturn new GitHubCopilotUnrecognizedResponseError(\"unknown-status\", context, { cause });\n}\n\n/** Where a Copilot request was when it failed. */\nexport interface GitHubCopilotFailureContext {\n\treadonly modelId: string;\n\treadonly api: string;\n\t/** True once Copilot answered with HTTP success and the response stream started. */\n\treadonly streamStarted: boolean;\n\t/** The provider's raw finish or stop reason, when the stream reported one. */\n\treadonly finishReason?: string;\n}\n\n/**\n * The stop reasons each API reports when a content or safety filter ended the response. Responses also records a\n * plain `refusal` for a refusal delta that does not end the turn, so each API has its own set.\n */\nconst CONTENT_FILTER_STOPS: Readonly<Record<string, ReadonlySet<string | undefined>>> = {\n\t\"openai-completions\": new Set([\"content_filter\"]),\n\t\"openai-responses\": new Set([\"incomplete.content_filter\"]),\n\t\"anthropic-messages\": new Set([\"refusal\", \"sensitive\"]),\n};\n\n/**\n * Translate a failed Copilot request into its typed error, once, at the provider boundary.\n *\n * HTTP failures are classified by the provider's code first, then on a 400 by Copilot's prompt-token overflow text\n * and the exact plain-text bodies it sends without a code, then by status (a 429 that reports a used-up quota is\n * `quota-exhausted`). A failure after the stream started is a content-filter stop for its API, an in-stream error\n * event, a malformed body, or a stream that ended early. Returns undefined for a failure that never reached Copilot (a\n * connection error before any response), which keeps Atomic's generic network handling. Never call it for a\n * cancelled request: cancellation is not a failure.\n */\nexport function classifyGitHubCopilotFailure(\n\terror: unknown,\n\tfailure: GitHubCopilotFailureContext,\n): GitHubCopilotError | undefined {\n\tconst typed = findGitHubCopilotError(error);\n\tif (typed !== undefined) return typed;\n\tconst providerError: ProviderFailure =\n\t\terror instanceof Error ? (error as ProviderFailure) : new Error(String(error), { cause: error });\n\tconst response = responseOf(providerError);\n\tconst status = typeof providerError.status === \"number\" ? providerError.status : undefined;\n\tconst providerCode = providerCodeOf(response);\n\tconst context: GitHubCopilotErrorContext = {\n\t\tmodelId: failure.modelId,\n\t\tapi: failure.api,\n\t\tstatus,\n\t\tproviderCode,\n\t\trequestId: requestIdOf(response),\n\t\tdetail: providerDetailOf(response, typeof response.status === \"number\" ? response.status : undefined),\n\t};\n\tconst codeFailure = providerCode === undefined ? undefined : PROVIDER_CODE_FAILURES[providerCode.toLowerCase()];\n\tif (codeFailure !== undefined) return codeFailure(context, providerError);\n\tif (status !== undefined) {\n\t\treturn (\n\t\t\t(status === 400 ? badRequestTextFailure(providerCode, context, providerError) : undefined) ??\n\t\t\tstatusFailure(status, context, providerError, reportsExhaustedQuota(response))\n\t\t);\n\t}\n\tif (CONTENT_FILTER_STOPS[failure.api]?.has(failure.finishReason)) {\n\t\treturn new GitHubCopilotContentFilterError(context, { cause: providerError });\n\t}\n\tif (providerCode !== undefined) {\n\t\treturn new GitHubCopilotUnrecognizedResponseError(\"unknown-error-event\", context, { cause: providerError });\n\t}\n\tif (providerError instanceof SyntaxError || providerError.error !== undefined) {\n\t\treturn new GitHubCopilotUnrecognizedResponseError(\"malformed-body\", context, { cause: providerError });\n\t}\n\treturn failure.streamStarted ? new GitHubCopilotStreamEndedEarlyError(context, { cause: providerError }) : undefined;\n}\n\n/**\n * Type a failed Copilot assistant message at the provider boundary: classify `error` and record it on `output`,\n * keeping the provider's text after the typed message. A cancelled message is left alone.\n */\nexport function recordGitHubCopilotFailure(output: AssistantMessage, error: unknown, streamStarted: boolean): void {\n\tif (output.stopReason !== \"error\") return;\n\tconst typed = classifyGitHubCopilotFailure(error, {\n\t\tmodelId: output.model,\n\t\tapi: output.api,\n\t\tstreamStarted,\n\t\tfinishReason: output.rawStopReason,\n\t});\n\tif (typed !== undefined) recordGitHubCopilotError(output, typed, output.errorMessage);\n}\n\n/**\n * The typed failure for a completed Copilot turn that has no text and no tool call, as Copilot's Gemini models\n * sometimes return; undefined for any other turn. A length stop is left to the caller's length handling.\n */\nexport function githubCopilotEmptyResponse(output: AssistantMessage): GitHubCopilotEmptyResponseError | undefined {\n\tif (output.provider !== \"github-copilot\" || (output.stopReason !== \"stop\" && output.stopReason !== \"toolUse\")) {\n\t\treturn undefined;\n\t}\n\tconst answered = output.content.some(\n\t\t(block) => block.type === \"toolCall\" || (block.type === \"text\" && block.text.trim().length > 0),\n\t);\n\treturn answered ? undefined : new GitHubCopilotEmptyResponseError({ modelId: output.model, api: output.api });\n}\n"]}
1
+ {"version":3,"file":"github-copilot-errors.js","sourceRoot":"","sources":["../../src/providers/github-copilot-errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAC5G,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAiBlE,MAAM,yBAAyB,GAAG,CAAC,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,CAAU,CAAC;AACrH,MAAM,uBAAuB,GAAG,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,UAAU,CAAU,CAAC;AAC5F,MAAM,oBAAoB,GAAG,CAAC,gBAAgB,EAAE,qBAAqB,EAAE,gBAAgB,CAAU,CAAC;AA6DlG,0GAA0G;AAC1G,MAAM,CAAC,MAAM,+BAA+B,GAAG,sBAAsB,CAAC;AAEtE,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,mFAAmF;AACnF,MAAM,0BAA0B,GAAyB,IAAI,GAAG,CAAyB;IACxF,mBAAmB;IACnB,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,iBAAiB;IACjB,uBAAuB;IACvB,qBAAqB;IACrB,oBAAoB;IACpB,gBAAgB;IAChB,uBAAuB;CACvB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAwC,IAAI,GAAG,CAAyB;IAC5F,cAAc;IACd,qBAAqB;IACrB,oBAAoB;IACpB,gBAAgB;IAChB,uBAAuB;CACvB,CAAC,CAAC;AAEH,MAAM,WAAW,GA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,MAAM,CAAC,UAAU,KAAK,MAAM,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,EAAE,CAAC;QAC/G,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CACnC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAC/F,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,+BAA+B,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;AAC/G,CAAC","sourcesContent":["import type { AssistantMessage, JsonObject } from \"../types.ts\";\nimport { type AssistantMessageDiagnostic, appendAssistantMessageDiagnostic } from \"../utils/diagnostics.ts\";\nimport { getProviderRetryAfterMs } from \"../utils/retry-hints.ts\";\nimport type { GitHubCopilotStreamSnapshot } from \"./github-copilot-stream-attempt.ts\";\n\n/** Stable codes of every GitHub Copilot request failure. Public API: never renamed or reused. */\nexport type GitHubCopilotErrorCode =\n\t| \"model-unavailable\"\n\t| \"rate-limited\"\n\t| \"quota-exhausted\"\n\t| \"content-filtered\"\n\t| \"prompt-too-large\"\n\t| \"invalid-request\"\n\t| \"authentication-failed\"\n\t| \"service-unavailable\"\n\t| \"stream-ended-early\"\n\t| \"empty-response\"\n\t| \"unrecognized-response\";\n\nconst MODEL_UNAVAILABLE_REASONS = [\"integration\", \"not-supported\", \"wrong-api\", \"no-endpoint\", \"not-found\"] as const;\nconst INVALID_REQUEST_REASONS = [\"reasoning-effort\", \"integration-id\", \"rejected\"] as const;\nconst UNRECOGNIZED_REASONS = [\"unknown-status\", \"unknown-error-event\", \"malformed-body\"] as const;\n\n/** Why Copilot refused to serve the model. */\nexport type GitHubCopilotModelUnavailableReason = (typeof MODEL_UNAVAILABLE_REASONS)[number];\n\n/** Which part of the request Copilot rejected. */\nexport type GitHubCopilotInvalidRequestReason = (typeof INVALID_REQUEST_REASONS)[number];\n\n/** What Atomic could not interpret. */\nexport type GitHubCopilotUnrecognizedReason = (typeof UNRECOGNIZED_REASONS)[number];\n\nexport type GitHubCopilotErrorName =\n\t| \"GitHubCopilotError\"\n\t| \"GitHubCopilotModelUnavailableError\"\n\t| \"GitHubCopilotRateLimitError\"\n\t| \"GitHubCopilotQuotaExhaustedError\"\n\t| \"GitHubCopilotContentFilterError\"\n\t| \"GitHubCopilotPromptTooLargeError\"\n\t| \"GitHubCopilotInvalidRequestError\"\n\t| \"GitHubCopilotAuthenticationError\"\n\t| \"GitHubCopilotServiceUnavailableError\"\n\t| \"GitHubCopilotStreamEndedEarlyError\"\n\t| \"GitHubCopilotEmptyResponseError\"\n\t| \"GitHubCopilotUnrecognizedResponseError\";\n\nexport type GitHubCopilotErrorFieldValue = string | number | boolean | null;\nexport type GitHubCopilotErrorFields = Readonly<Record<string, GitHubCopilotErrorFieldValue>>;\n\n/** The request a failure belongs to, and what the provider reported about it. No prompt text, tokens or bodies. */\nexport interface GitHubCopilotErrorContext {\n\treadonly modelId: string;\n\treadonly api: string;\n\t/** HTTP status, when the failure was an HTTP response. */\n\treadonly status?: number;\n\t/** The provider's own error code, such as `model_not_supported`. */\n\treadonly providerCode?: string;\n\t/** The provider's `x-request-id`, for support requests. */\n\treadonly requestId?: string;\n\t/** The provider's short error text, truncated. */\n\treadonly detail?: string;\n}\n\n/** A cause in wire form, bounded in depth. */\nexport interface SerializedGitHubCopilotErrorCause {\n\treadonly name: string;\n\treadonly message: string;\n\treadonly code?: string;\n\treadonly cause?: SerializedGitHubCopilotErrorCause;\n}\n\n/** Wire form of a GitHub Copilot error, as an assistant message's diagnostics carry it across processes. */\nexport interface SerializedGitHubCopilotError {\n\treadonly name: string;\n\treadonly code: GitHubCopilotErrorCode;\n\treadonly message: string;\n\treadonly hint: string;\n\treadonly retryable: boolean;\n\treadonly fields: GitHubCopilotErrorFields;\n\treadonly cause?: SerializedGitHubCopilotErrorCause;\n}\n\n/** `AssistantMessageDiagnostic.type` of the diagnostic that carries a serialized GitHub Copilot error. */\nexport const GITHUB_COPILOT_ERROR_DIAGNOSTIC = \"github_copilot_error\";\n\nconst MAX_CAUSE_DEPTH = 8;\nconst MAX_DETAIL_CHARS = 300;\n\n/** Every code, as a set that relayed values of any type can be checked against. */\nconst GITHUB_COPILOT_ERROR_CODES: ReadonlySet<unknown> = new Set<GitHubCopilotErrorCode>([\n\t\"model-unavailable\",\n\t\"rate-limited\",\n\t\"quota-exhausted\",\n\t\"content-filtered\",\n\t\"prompt-too-large\",\n\t\"invalid-request\",\n\t\"authentication-failed\",\n\t\"service-unavailable\",\n\t\"stream-ended-early\",\n\t\"empty-response\",\n\t\"unrecognized-response\",\n]);\n\nconst RETRYABLE_CODES: ReadonlySet<GitHubCopilotErrorCode> = new Set<GitHubCopilotErrorCode>([\n\t\"rate-limited\",\n\t\"service-unavailable\",\n\t\"stream-ended-early\",\n\t\"empty-response\",\n\t\"unrecognized-response\",\n]);\n\nconst WHAT_FAILED: Readonly<Record<GitHubCopilotErrorCode, string>> = {\n\t\"model-unavailable\": \"GitHub Copilot model unavailable\",\n\t\"rate-limited\": \"GitHub Copilot rate limit reached\",\n\t\"quota-exhausted\": \"GitHub Copilot quota exhausted\",\n\t\"content-filtered\": \"GitHub Copilot content filter blocked the request\",\n\t\"prompt-too-large\": \"GitHub Copilot prompt too large\",\n\t\"invalid-request\": \"GitHub Copilot rejected the request\",\n\t\"authentication-failed\": \"GitHub Copilot authentication failed\",\n\t\"service-unavailable\": \"GitHub Copilot service unavailable\",\n\t\"stream-ended-early\": \"GitHub Copilot response stream ended early\",\n\t\"empty-response\": \"GitHub Copilot returned an empty response\",\n\t\"unrecognized-response\": \"GitHub Copilot returned an unrecognized response\",\n};\n\nconst HINTS: Readonly<Record<GitHubCopilotErrorCode, string>> = {\n\t\"model-unavailable\": \"Pick another model, or run /login to refresh the models this account can use.\",\n\t\"rate-limited\": \"Wait for the rate limit to reset; Atomic retries the request when retries are enabled.\",\n\t\"quota-exhausted\": \"Pick another model, or wait until the Copilot plan's quota resets.\",\n\t\"content-filtered\":\n\t\t\"Rephrase the request or pick another model; retry.fallbackOnContentFilter decides whether a fallback model is tried.\",\n\t\"prompt-too-large\": \"Run /compact or start a new session to shrink the conversation.\",\n\t\"invalid-request\": \"Check the model's thinking level and any models.json overrides for this model.\",\n\t\"authentication-failed\": \"Run /login to sign in to GitHub Copilot again, or check COPILOT_GITHUB_TOKEN.\",\n\t\"service-unavailable\": \"Retry later; Atomic retries the request when retries are enabled.\",\n\t\"stream-ended-early\":\n\t\t\"If the stream keeps ending early, split the work into smaller steps, lower the thinking effort, or add a fallback model with the fallbackModels setting.\",\n\t\"empty-response\": \"Retry the request; Atomic retries it when retries are enabled.\",\n\t\"unrecognized-response\": \"Retry the request, and report it if it keeps happening.\",\n};\n\n/** Hints for the reasons that need more than their code's hint. */\nconst MODEL_UNAVAILABLE_HINTS: Readonly<Partial<Record<GitHubCopilotModelUnavailableReason, string>>> = {\n\tintegration:\n\t\t\"Copilot does not offer this model to Atomic's integration. Pick another model, or run /login to refresh the model list.\",\n\t\"wrong-api\": \"Run /login to refresh the model list so Atomic calls the API Copilot serves this model on.\",\n\t\"no-endpoint\": \"Copilot has no endpoint for this model under this account's settings. Pick another model.\",\n};\n\nconst INVALID_REQUEST_HINTS: Readonly<Partial<Record<GitHubCopilotInvalidRequestReason, string>>> = {\n\t\"reasoning-effort\": \"Pick a thinking level this model lists.\",\n\t\"integration-id\": \"Remove the Copilot-Integration-Id header override from models.json.\",\n};\n\nfunction failureMessage(code: GitHubCopilotErrorCode, modelId: string, hint: string, circumstances?: string): string {\n\treturn `${WHAT_FAILED[code]}: ${modelId} (${code}). ${circumstances === undefined ? \"\" : `${circumstances}. `}${hint}`;\n}\n\ninterface GitHubCopilotErrorOptions {\n\treadonly hint?: string;\n\treadonly cause?: unknown;\n\t/** What the failure observed, as one sentence without its final period; it follows the code in the message. */\n\treadonly circumstances?: string;\n}\n\n/** Base of every GitHub Copilot request failure. Catch this to handle the whole family. */\nexport class GitHubCopilotError extends Error {\n\toverride readonly name: string = \"GitHubCopilotError\";\n\treadonly code: GitHubCopilotErrorCode;\n\treadonly retryable: boolean;\n\treadonly hint: string;\n\treadonly modelId: string;\n\treadonly api: string;\n\treadonly status: number | undefined;\n\treadonly providerCode: string | undefined;\n\treadonly requestId: string | undefined;\n\treadonly detail: string | undefined;\n\n\tconstructor(code: GitHubCopilotErrorCode, context: GitHubCopilotErrorContext, options?: GitHubCopilotErrorOptions) {\n\t\tconst hint = options?.hint ?? HINTS[code];\n\t\tsuper(\n\t\t\tfailureMessage(code, context.modelId, hint, options?.circumstances),\n\t\t\toptions?.cause === undefined ? undefined : { cause: options.cause },\n\t\t);\n\t\tthis.code = code;\n\t\tthis.retryable = RETRYABLE_CODES.has(code);\n\t\tthis.hint = hint;\n\t\tthis.modelId = context.modelId;\n\t\tthis.api = context.api;\n\t\tthis.status = context.status;\n\t\tthis.providerCode = context.providerCode;\n\t\tthis.requestId = context.requestId;\n\t\tthis.detail = context.detail;\n\t}\n\n\t/** JSON-safe context fields; subclasses add their own. */\n\tfields(): GitHubCopilotErrorFields {\n\t\treturn {\n\t\t\tmodelId: this.modelId,\n\t\t\tapi: this.api,\n\t\t\tstatus: this.status ?? null,\n\t\t\tproviderCode: this.providerCode ?? null,\n\t\t\trequestId: this.requestId ?? null,\n\t\t\tdetail: this.detail ?? null,\n\t\t};\n\t}\n}\n\n/** Copilot will not serve this model to this account, integration or API. Not retryable; a fallback model may work. */\nexport class GitHubCopilotModelUnavailableError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotModelUnavailableError\" as const;\n\tdeclare readonly code: \"model-unavailable\";\n\treadonly reason: GitHubCopilotModelUnavailableReason;\n\n\tconstructor(\n\t\treason: GitHubCopilotModelUnavailableReason,\n\t\tcontext: GitHubCopilotErrorContext,\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"model-unavailable\", context, { hint: MODEL_UNAVAILABLE_HINTS[reason], cause: options?.cause });\n\t\tthis.reason = reason;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), reason: this.reason };\n\t}\n}\n\n/** Copilot throttled the request. Retryable after `retryAfterMs` when the server sent a delay. */\nexport class GitHubCopilotRateLimitError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotRateLimitError\" as const;\n\tdeclare readonly code: \"rate-limited\";\n\treadonly retryAfterMs: number | undefined;\n\n\tconstructor(context: GitHubCopilotErrorContext, retryAfterMs?: number, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"rate-limited\", context, options);\n\t\tthis.retryAfterMs = retryAfterMs;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), retryAfterMs: this.retryAfterMs ?? null };\n\t}\n}\n\n/** The plan's quota or billing allowance for the model is used up. Not retryable until it resets. */\nexport class GitHubCopilotQuotaExhaustedError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotQuotaExhaustedError\" as const;\n\tdeclare readonly code: \"quota-exhausted\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"quota-exhausted\", context, options);\n\t}\n}\n\n/** A content or safety filter blocked the request or the response. The same request is refused again. */\nexport class GitHubCopilotContentFilterError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotContentFilterError\" as const;\n\tdeclare readonly code: \"content-filtered\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"content-filtered\", context, options);\n\t}\n}\n\n/** The prompt exceeds the model's prompt-token limit. Compact the conversation instead of retrying. */\nexport class GitHubCopilotPromptTooLargeError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotPromptTooLargeError\" as const;\n\tdeclare readonly code: \"prompt-too-large\";\n\treadonly promptTokens: number | undefined;\n\treadonly limitTokens: number | undefined;\n\n\tconstructor(\n\t\tcontext: GitHubCopilotErrorContext,\n\t\ttokens?: { readonly promptTokens?: number; readonly limitTokens?: number },\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"prompt-too-large\", context, options);\n\t\tthis.promptTokens = tokens?.promptTokens;\n\t\tthis.limitTokens = tokens?.limitTokens;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), promptTokens: this.promptTokens ?? null, limitTokens: this.limitTokens ?? null };\n\t}\n}\n\n/** Copilot rejected the request's shape or settings. Sending it again fails the same way. */\nexport class GitHubCopilotInvalidRequestError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotInvalidRequestError\" as const;\n\tdeclare readonly code: \"invalid-request\";\n\treadonly reason: GitHubCopilotInvalidRequestReason;\n\n\tconstructor(\n\t\treason: GitHubCopilotInvalidRequestReason,\n\t\tcontext: GitHubCopilotErrorContext,\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"invalid-request\", context, { hint: INVALID_REQUEST_HINTS[reason], cause: options?.cause });\n\t\tthis.reason = reason;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), reason: this.reason };\n\t}\n}\n\n/** Copilot refused the credential. Sign in again; another provider's model may still work. */\nexport class GitHubCopilotAuthenticationError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotAuthenticationError\" as const;\n\tdeclare readonly code: \"authentication-failed\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"authentication-failed\", context, options);\n\t}\n}\n\n/** Copilot or the model behind it is down, overloaded or timed out. Retryable. */\nexport class GitHubCopilotServiceUnavailableError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotServiceUnavailableError\" as const;\n\tdeclare readonly code: \"service-unavailable\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"service-unavailable\", context, options);\n\t}\n}\n\n/** What a stream that ended early observed, as the sentence that follows its code in the message. */\nfunction streamEndedEarlyCircumstances(\n\trequestId: string | undefined,\n\tdurationMs: number | undefined,\n\tstartedContent: boolean | undefined,\n): string | undefined {\n\tconst facts = [\n\t\t...(durationMs === undefined ? [] : [`Attempt ran ${(durationMs / 1000).toFixed(1)} s`]),\n\t\t...(startedContent === undefined ? [] : [startedContent ? \"response started\" : \"no response events arrived\"]),\n\t\t...(requestId === undefined ? [] : [`request ID ${requestId}`]),\n\t];\n\treturn facts.length === 0 ? undefined : facts.join(\", \");\n}\n\n/**\n * The response stream stopped before its finish reason or terminal event. Retryable. `durationMs` is how long the attempt\n * ran before it ended and `startedContent` whether any provider stream event had arrived; both are undefined when the\n * error was built without them. The provider's `x-request-id` is `requestId`.\n */\nexport class GitHubCopilotStreamEndedEarlyError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotStreamEndedEarlyError\" as const;\n\tdeclare readonly code: \"stream-ended-early\";\n\treadonly durationMs: number | undefined;\n\treadonly startedContent: boolean | undefined;\n\n\tconstructor(\n\t\tcontext: GitHubCopilotErrorContext,\n\t\toptions?: { readonly cause?: unknown; readonly durationMs?: number; readonly startedContent?: boolean },\n\t) {\n\t\tsuper(\"stream-ended-early\", context, {\n\t\t\tcause: options?.cause,\n\t\t\tcircumstances: streamEndedEarlyCircumstances(context.requestId, options?.durationMs, options?.startedContent),\n\t\t});\n\t\tthis.durationMs = options?.durationMs;\n\t\tthis.startedContent = options?.startedContent;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn {\n\t\t\t...super.fields(),\n\t\t\tdurationMs: this.durationMs ?? null,\n\t\t\tstartedContent: this.startedContent ?? null,\n\t\t};\n\t}\n}\n\n/** The model finished with no text and no tool call, as Copilot's Gemini models sometimes do. Retryable. */\nexport class GitHubCopilotEmptyResponseError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotEmptyResponseError\" as const;\n\tdeclare readonly code: \"empty-response\";\n\n\tconstructor(context: GitHubCopilotErrorContext, options?: { readonly cause?: unknown }) {\n\t\tsuper(\"empty-response\", context, options);\n\t}\n}\n\n/** Copilot answered with a status, error event or body Atomic does not recognize. Retryable a bounded number of times. */\nexport class GitHubCopilotUnrecognizedResponseError extends GitHubCopilotError {\n\toverride readonly name = \"GitHubCopilotUnrecognizedResponseError\" as const;\n\tdeclare readonly code: \"unrecognized-response\";\n\treadonly reason: GitHubCopilotUnrecognizedReason;\n\n\tconstructor(\n\t\treason: GitHubCopilotUnrecognizedReason,\n\t\tcontext: GitHubCopilotErrorContext,\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(\"unrecognized-response\", context, options);\n\t\tthis.reason = reason;\n\t}\n\n\toverride fields(): GitHubCopilotErrorFields {\n\t\treturn { ...super.fields(), reason: this.reason };\n\t}\n}\n\nconst CODE_BY_NAME: Readonly<Record<Exclude<GitHubCopilotErrorName, \"GitHubCopilotError\">, GitHubCopilotErrorCode>> = {\n\tGitHubCopilotModelUnavailableError: \"model-unavailable\",\n\tGitHubCopilotRateLimitError: \"rate-limited\",\n\tGitHubCopilotQuotaExhaustedError: \"quota-exhausted\",\n\tGitHubCopilotContentFilterError: \"content-filtered\",\n\tGitHubCopilotPromptTooLargeError: \"prompt-too-large\",\n\tGitHubCopilotInvalidRequestError: \"invalid-request\",\n\tGitHubCopilotAuthenticationError: \"authentication-failed\",\n\tGitHubCopilotServiceUnavailableError: \"service-unavailable\",\n\tGitHubCopilotStreamEndedEarlyError: \"stream-ended-early\",\n\tGitHubCopilotEmptyResponseError: \"empty-response\",\n\tGitHubCopilotUnrecognizedResponseError: \"unrecognized-response\",\n};\n\ninterface StructuralError {\n\treadonly name?: unknown;\n\treadonly code?: unknown;\n\treadonly cause?: unknown;\n\treadonly diagnostics?: unknown;\n}\n\nfunction structural(value: unknown): StructuralError | undefined {\n\treturn typeof value === \"object\" && value !== null ? (value as StructuralError) : undefined;\n}\n\n/** A family member seen from another process or realm: its name and code, maybe its message. */\ninterface StructuralFamilyMember {\n\treadonly name: string;\n\treadonly code: GitHubCopilotErrorCode;\n\treadonly message?: unknown;\n}\n\n/** A family member relayed from another process or realm: an object with a family name and that name's code. */\nfunction isRelayedFamilyMember(value: unknown): value is StructuralFamilyMember {\n\tconst candidate = structural(value);\n\tif (typeof candidate?.name !== \"string\") return false;\n\tif (candidate.name === \"GitHubCopilotError\") return GITHUB_COPILOT_ERROR_CODES.has(candidate.code);\n\treturn CODE_BY_NAME[candidate.name as keyof typeof CODE_BY_NAME] === candidate.code;\n}\n\n/** Rebuild a relayed family member as its class; one that carries only its name and code gets that code's hint. */\nfunction rebuildRelayedFamilyMember(found: StructuralFamilyMember): GitHubCopilotError | undefined {\n\tconst deserialized = deserializeGitHubCopilotError(found);\n\tif (deserialized) return deserialized;\n\tif (\"fields\" in found || \"hint\" in found || \"retryable\" in found || \"cause\" in found) return undefined;\n\tif (Reflect.ownKeys(found).some((key) => key !== \"name\" && key !== \"code\" && key !== \"message\")) return undefined;\n\tif (\"message\" in found && typeof found.message !== \"string\") return undefined;\n\treturn deserializeGitHubCopilotError({\n\t\tname: found.name,\n\t\tcode: found.code,\n\t\tmessage: found.message ?? \"\",\n\t\thint: HINTS[found.code],\n\t\tretryable: RETRYABLE_CODES.has(found.code),\n\t\tfields: {},\n\t});\n}\n\n/**\n * The typed error at one link of a cause chain: the link itself, rebuilt when it was relayed from another process, or\n * the error its `diagnostics` carry when the link is a failed assistant message, as a workflow failure's cause is.\n */\nfunction typedErrorAt(link: unknown): GitHubCopilotError | undefined {\n\tif (link instanceof GitHubCopilotError) return link;\n\tif (isRelayedFamilyMember(link)) return rebuildRelayedFamilyMember(link);\n\treturn getGitHubCopilotError(structural(link));\n}\n\n/** The first typed error `matches` accepts, walking at most MAX_CAUSE_DEPTH links of the cause chain. */\nfunction findInCauseChain(\n\terror: unknown,\n\tmatches: (typed: GitHubCopilotError) => boolean,\n): GitHubCopilotError | undefined {\n\tlet current = error;\n\tfor (let depth = 0; depth < MAX_CAUSE_DEPTH; depth++) {\n\t\tconst typed = typedErrorAt(current);\n\t\tif (typed !== undefined && matches(typed)) return typed;\n\t\tcurrent = structural(current)?.cause;\n\t}\n\treturn undefined;\n}\n\n/**\n * A guard that answers whether the error, anything in its cause chain, or a failed assistant message in that chain holds\n * an error of this class. It returns a plain boolean, not a type predicate: the value passed in is usually the wrapper\n * or the message, not the error. Use `findGitHubCopilotError()` for the instance.\n */\nfunction guard(ctor: abstract new (...args: never[]) => GitHubCopilotError): (error: unknown) => boolean {\n\treturn (error) => findInCauseChain(error, (typed) => typed instanceof ctor) !== undefined;\n}\n\n/**\n * True when the error, anything in its cause chain, or a failed assistant message in that chain holds a GitHub Copilot\n * error. A plain boolean, not a type predicate: use `findGitHubCopilotError()` for the instance.\n */\nexport function isGitHubCopilotError(error: unknown): boolean {\n\treturn findGitHubCopilotError(error) !== undefined;\n}\n\n/**\n * First GitHub Copilot error in the cause chain, as an instance of its class: a link that is one, rebuilt when it was\n * relayed from another process, or the error a failed assistant message's diagnostics carry. The chain is walked to a\n * bounded depth, through JSON round-tripped links too.\n */\nexport function findGitHubCopilotError(error: unknown): GitHubCopilotError | undefined {\n\treturn findInCauseChain(error, () => true);\n}\n\n/** True when the first GitHub Copilot error in the cause chain says the same request may be sent again. */\nexport function isRetryableGitHubCopilotError(error: unknown): boolean {\n\treturn findGitHubCopilotError(error)?.retryable === true;\n}\n\nexport const isGitHubCopilotModelUnavailableError = guard(GitHubCopilotModelUnavailableError);\nexport const isGitHubCopilotRateLimitError = guard(GitHubCopilotRateLimitError);\nexport const isGitHubCopilotQuotaExhaustedError = guard(GitHubCopilotQuotaExhaustedError);\nexport const isGitHubCopilotContentFilterError = guard(GitHubCopilotContentFilterError);\nexport const isGitHubCopilotPromptTooLargeError = guard(GitHubCopilotPromptTooLargeError);\nexport const isGitHubCopilotInvalidRequestError = guard(GitHubCopilotInvalidRequestError);\nexport const isGitHubCopilotAuthenticationError = guard(GitHubCopilotAuthenticationError);\nexport const isGitHubCopilotServiceUnavailableError = guard(GitHubCopilotServiceUnavailableError);\nexport const isGitHubCopilotStreamEndedEarlyError = guard(GitHubCopilotStreamEndedEarlyError);\nexport const isGitHubCopilotEmptyResponseError = guard(GitHubCopilotEmptyResponseError);\nexport const isGitHubCopilotUnrecognizedResponseError = guard(GitHubCopilotUnrecognizedResponseError);\n\nfunction serializeCause(cause: unknown, depth: number): SerializedGitHubCopilotErrorCause | undefined {\n\tif (depth >= MAX_CAUSE_DEPTH || cause === undefined || cause === null) return undefined;\n\tconst candidate = structural(cause);\n\tconst nested = serializeCause(candidate?.cause, depth + 1);\n\treturn {\n\t\tname: typeof candidate?.name === \"string\" ? candidate.name : typeof cause,\n\t\tmessage: truncate(cause instanceof Error ? cause.message : String(cause)),\n\t\t...(typeof candidate?.code === \"string\" ? { code: candidate.code } : {}),\n\t\t...(nested === undefined ? {} : { cause: nested }),\n\t};\n}\n\n/** Wire form for crossing a process boundary; the cause chain is kept to a bounded depth. */\nexport function serializeGitHubCopilotError(error: GitHubCopilotError): SerializedGitHubCopilotError {\n\tconst cause = serializeCause(error.cause, 0);\n\treturn {\n\t\tname: error.name,\n\t\tcode: error.code,\n\t\tmessage: error.message,\n\t\thint: error.hint,\n\t\tretryable: error.retryable,\n\t\tfields: error.fields(),\n\t\t...(cause === undefined ? {} : { cause }),\n\t};\n}\n\nfunction rehydrateCause(cause: SerializedGitHubCopilotErrorCause | undefined): Error | undefined {\n\tif (cause === undefined) return undefined;\n\tconst family = isRelayedFamilyMember(cause)\n\t\t? rebuildRelayedFamilyMember({ name: cause.name, code: cause.code, message: cause.message })\n\t\t: undefined;\n\tconst error = family ?? new Error(cause.message);\n\tObject.defineProperties(error, {\n\t\tmessage: { value: cause.message },\n\t\tcause: { value: rehydrateCause(cause.cause), writable: true, configurable: true },\n\t});\n\tObject.defineProperty(error, \"name\", { value: cause.name });\n\tif (cause.code !== undefined) Object.defineProperty(error, \"code\", { value: cause.code, enumerable: true });\n\treturn error;\n}\n\nfunction stringField(fields: GitHubCopilotErrorFields, key: string): string | undefined {\n\tconst value = fields[key];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction numberField(fields: GitHubCopilotErrorFields, key: string): number | undefined {\n\tconst value = fields[key];\n\treturn typeof value === \"number\" ? value : undefined;\n}\n\nfunction booleanField(fields: GitHubCopilotErrorFields, key: string): boolean | undefined {\n\tconst value = fields[key];\n\treturn typeof value === \"boolean\" ? value : undefined;\n}\n\nfunction contextFromFields(fields: GitHubCopilotErrorFields): GitHubCopilotErrorContext {\n\treturn {\n\t\tmodelId: stringField(fields, \"modelId\") ?? \"\",\n\t\tapi: stringField(fields, \"api\") ?? \"\",\n\t\tstatus: numberField(fields, \"status\"),\n\t\tproviderCode: stringField(fields, \"providerCode\"),\n\t\trequestId: stringField(fields, \"requestId\"),\n\t\tdetail: stringField(fields, \"detail\"),\n\t};\n}\n\nfunction isJsonRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isSerializedCause(value: unknown, depth = 0): value is SerializedGitHubCopilotErrorCause {\n\tif (value === undefined) return true;\n\tif (depth >= MAX_CAUSE_DEPTH || !isJsonRecord(value)) return false;\n\treturn (\n\t\ttypeof value.name === \"string\" &&\n\t\ttypeof value.message === \"string\" &&\n\t\t(value.code === undefined || typeof value.code === \"string\") &&\n\t\tisSerializedCause(value.cause, depth + 1)\n\t);\n}\n\n/** The fields that hold a boolean; every other field holds a string, a number or null. */\nconst BOOLEAN_FIELD_KEYS: ReadonlySet<string> = new Set([\"startedContent\"]);\n\nfunction isSerializedFieldValue(key: string, field: unknown): boolean {\n\tif (field === null || typeof field === \"string\" || typeof field === \"number\") return true;\n\treturn typeof field === \"boolean\" && BOOLEAN_FIELD_KEYS.has(key);\n}\n\nfunction isSerializedError(value: unknown): value is SerializedGitHubCopilotError {\n\tif (!isJsonRecord(value) || !isJsonRecord(value.fields)) return false;\n\treturn (\n\t\ttypeof value.name === \"string\" &&\n\t\tGITHUB_COPILOT_ERROR_CODES.has(value.code) &&\n\t\ttypeof value.message === \"string\" &&\n\t\ttypeof value.hint === \"string\" &&\n\t\ttypeof value.retryable === \"boolean\" &&\n\t\tObject.entries(value.fields).every(([key, field]) => isSerializedFieldValue(key, field)) &&\n\t\tisSerializedCause(value.cause)\n\t);\n}\n\n/** A serialized reason: one of `allowed`, or `fallback` when the field is absent. Undefined when it is anything else. */\nfunction reasonField<T extends string>(\n\tfields: GitHubCopilotErrorFields,\n\tallowed: readonly T[],\n\tfallback: T,\n): T | undefined {\n\tconst reason = fields.reason;\n\tif (reason === undefined || reason === null) return fallback;\n\treturn allowed.find((candidate) => candidate === reason);\n}\n\n/** Whether a serialized error's name, if it is a known class, goes with its code. */\nfunction agreesWithClass(serialized: SerializedGitHubCopilotError): boolean {\n\treturn (\n\t\t!Object.hasOwn(CODE_BY_NAME, serialized.name) ||\n\t\t(CODE_BY_NAME as Record<string, string>)[serialized.name] === serialized.code\n\t);\n}\n\n/**\n * Rebuild a serialized GitHub Copilot error as its own class. An unknown name becomes the family base with the\n * original name, code, message, hint and retryability kept. Returns undefined for anything that is not a serialized\n * GitHub Copilot error: a code this version does not know, a class name that does not go with its code, or a reason\n * that class does not have.\n */\nexport function deserializeGitHubCopilotError(value: unknown): GitHubCopilotError | undefined {\n\tif (!isSerializedError(value) || !agreesWithClass(value)) return undefined;\n\tconst cause = rehydrateCause(value.cause);\n\tconst fields = value.fields;\n\tconst context = contextFromFields(fields);\n\tswitch (value.name) {\n\t\tcase \"GitHubCopilotModelUnavailableError\": {\n\t\t\tconst reason = reasonField(fields, MODEL_UNAVAILABLE_REASONS, \"not-supported\");\n\t\t\treturn reason === undefined ? undefined : new GitHubCopilotModelUnavailableError(reason, context, { cause });\n\t\t}\n\t\tcase \"GitHubCopilotRateLimitError\":\n\t\t\treturn new GitHubCopilotRateLimitError(context, numberField(fields, \"retryAfterMs\"), { cause });\n\t\tcase \"GitHubCopilotQuotaExhaustedError\":\n\t\t\treturn new GitHubCopilotQuotaExhaustedError(context, { cause });\n\t\tcase \"GitHubCopilotContentFilterError\":\n\t\t\treturn new GitHubCopilotContentFilterError(context, { cause });\n\t\tcase \"GitHubCopilotPromptTooLargeError\":\n\t\t\treturn new GitHubCopilotPromptTooLargeError(\n\t\t\t\tcontext,\n\t\t\t\t{ promptTokens: numberField(fields, \"promptTokens\"), limitTokens: numberField(fields, \"limitTokens\") },\n\t\t\t\t{ cause },\n\t\t\t);\n\t\tcase \"GitHubCopilotInvalidRequestError\": {\n\t\t\tconst reason = reasonField(fields, INVALID_REQUEST_REASONS, \"rejected\");\n\t\t\treturn reason === undefined ? undefined : new GitHubCopilotInvalidRequestError(reason, context, { cause });\n\t\t}\n\t\tcase \"GitHubCopilotAuthenticationError\":\n\t\t\treturn new GitHubCopilotAuthenticationError(context, { cause });\n\t\tcase \"GitHubCopilotServiceUnavailableError\":\n\t\t\treturn new GitHubCopilotServiceUnavailableError(context, { cause });\n\t\tcase \"GitHubCopilotStreamEndedEarlyError\":\n\t\t\treturn new GitHubCopilotStreamEndedEarlyError(context, {\n\t\t\t\tcause,\n\t\t\t\tdurationMs: numberField(fields, \"durationMs\"),\n\t\t\t\tstartedContent: booleanField(fields, \"startedContent\"),\n\t\t\t});\n\t\tcase \"GitHubCopilotEmptyResponseError\":\n\t\t\treturn new GitHubCopilotEmptyResponseError(context, { cause });\n\t\tcase \"GitHubCopilotUnrecognizedResponseError\": {\n\t\t\tconst reason = reasonField(fields, UNRECOGNIZED_REASONS, \"malformed-body\");\n\t\t\treturn reason === undefined\n\t\t\t\t? undefined\n\t\t\t\t: new GitHubCopilotUnrecognizedResponseError(reason, context, { cause });\n\t\t}\n\t\tdefault: {\n\t\t\tconst base = new GitHubCopilotError(value.code, context, { hint: value.hint, cause });\n\t\t\tObject.defineProperties(base, {\n\t\t\t\tname: { value: value.name },\n\t\t\t\tmessage: { value: value.message },\n\t\t\t\tretryable: { value: value.retryable },\n\t\t\t});\n\t\t\treturn base;\n\t\t}\n\t}\n}\n\n/** Record `error` on a failed assistant message: its diagnostics carry the typed error across processes. */\nexport function recordGitHubCopilotError(\n\toutput: AssistantMessage,\n\terror: GitHubCopilotError,\n\tproviderText?: string,\n): void {\n\toutput.errorMessage =\n\t\tproviderText === undefined || providerText === error.message\n\t\t\t? error.message\n\t\t\t: `${error.message}\\n\\n${providerText}`;\n\tif (error instanceof GitHubCopilotRateLimitError && error.retryAfterMs !== undefined) {\n\t\toutput.retryAfterMs = error.retryAfterMs;\n\t}\n\tappendAssistantMessageDiagnostic(output, {\n\t\ttype: GITHUB_COPILOT_ERROR_DIAGNOSTIC,\n\t\ttimestamp: Date.now(),\n\t\terror: { name: error.name, message: error.message, code: error.code },\n\t\tdetails: JSON.parse(JSON.stringify(serializeGitHubCopilotError(error))) as JsonObject,\n\t});\n}\n\n/**\n * The GitHub Copilot error an assistant message's diagnostics carry, rebuilt as its class: the latest valid one.\n * Accepts a message read back from JSON, whose diagnostics are validated here.\n */\nexport function getGitHubCopilotError(\n\tmessage: { readonly diagnostics?: unknown } | undefined,\n): GitHubCopilotError | undefined {\n\tconst diagnostics = message?.diagnostics;\n\tif (!Array.isArray(diagnostics)) return undefined;\n\tfor (const entry of [...diagnostics].reverse()) {\n\t\tconst diagnostic = structural(entry) as Partial<AssistantMessageDiagnostic> | undefined;\n\t\tif (diagnostic?.type !== GITHUB_COPILOT_ERROR_DIAGNOSTIC) continue;\n\t\tconst error = deserializeGitHubCopilotError(diagnostic.details);\n\t\tif (error !== undefined) return error;\n\t}\n\treturn undefined;\n}\n\nfunction truncate(text: string): string {\n\treturn text.length <= MAX_DETAIL_CHARS ? text : `${text.slice(0, MAX_DETAIL_CHARS)}…`;\n}\n\nfunction nonEmptyString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" && value.trim().length > 0 ? value.trim() : undefined;\n}\n\ntype ProviderFailure = Error & {\n\tstatus?: unknown;\n\tcode?: unknown;\n\ttype?: unknown;\n\terror?: unknown;\n\trequestID?: unknown;\n\trequest_id?: unknown;\n\theaders?: unknown;\n};\n\n/**\n * The error that holds the provider's response. When the retry helper gave up on a server-requested delay above its\n * cap, it threw a wrapper that keeps only `status` and `retryAfterMs` and holds the original response error as its\n * `cause`: no code, body or headers of its own. The response is then that cause. Any other error is its own response.\n */\nfunction responseOf(error: ProviderFailure): ProviderFailure {\n\tconst origin = error.cause;\n\tconst wrapsResponse =\n\t\terror.code === undefined &&\n\t\terror.error === undefined &&\n\t\terror.headers === undefined &&\n\t\torigin instanceof Error &&\n\t\ttypeof (origin as ProviderFailure).status === \"number\";\n\treturn wrapsResponse ? (origin as ProviderFailure) : error;\n}\n\n/** The SDK's request ID, else Copilot's `x-request-id` header, which the Anthropic SDK does not read. */\nfunction requestIdOf(error: ProviderFailure): string | undefined {\n\tconst headers = error.headers;\n\tconst header = headers instanceof Headers ? headers.get(\"x-request-id\") : undefined;\n\treturn nonEmptyString(error.requestID) ?? nonEmptyString(error.request_id) ?? nonEmptyString(header);\n}\n\n/**\n * The provider's code: the SDK's `code`, then the parsed body's `error.code` or `code`. A Messages `error` event\n * arrives with no HTTP status and names its failure only by `type`, so that type is its code.\n */\nfunction providerCodeOf(error: ProviderFailure): string | undefined {\n\tconst body = structural(error.error) as { code?: unknown; error?: unknown } | undefined;\n\treturn (\n\t\tnonEmptyString(error.code) ??\n\t\tnonEmptyString((structural(body?.error) as { code?: unknown } | undefined)?.code) ??\n\t\tnonEmptyString(body?.code) ??\n\t\t(error.status === undefined && error.error !== undefined ? nonEmptyString(error.type) : undefined)\n\t);\n}\n\n/** The provider's error text: the parsed body's message, else the SDK message without its status prefix. */\nfunction providerDetailOf(error: ProviderFailure, status: number | undefined): string | undefined {\n\tconst body = structural(error.error) as { message?: unknown; error?: unknown } | undefined;\n\tconst bodyMessage =\n\t\tnonEmptyString((structural(body?.error) as { message?: unknown } | undefined)?.message) ??\n\t\tnonEmptyString(body?.message);\n\tif (bodyMessage !== undefined) return truncate(bodyMessage);\n\tif (typeof error.error === \"string\") {\n\t\tconst text = nonEmptyString(error.error);\n\t\treturn text === undefined ? undefined : truncate(text);\n\t}\n\tconst message =\n\t\tstatus !== undefined && error.message.startsWith(`${status} `)\n\t\t\t? error.message.slice(`${status} `.length)\n\t\t\t: error.message;\n\tconst text = nonEmptyString(message);\n\treturn text === undefined ? undefined : truncate(text);\n}\n\n/** Provider codes Copilot sends, observed live or documented publicly, and the failure each one means. */\nconst PROVIDER_CODE_FAILURES: Readonly<\n\tRecord<string, (context: GitHubCopilotErrorContext, error: ProviderFailure) => GitHubCopilotError>\n> = {\n\tmodel_not_available_for_integrator: (context, cause) =>\n\t\tnew GitHubCopilotModelUnavailableError(\"integration\", context, { cause }),\n\tmodel_not_supported: (context, cause) => new GitHubCopilotModelUnavailableError(\"not-supported\", context, { cause }),\n\tunsupported_api_for_model: (context, cause) =>\n\t\tnew GitHubCopilotModelUnavailableError(\"wrong-api\", context, { cause }),\n\tmodel_max_prompt_tokens_exceeded: (context, cause) => promptTooLarge(context, cause),\n\tcontext_length_exceeded: (context, cause) => promptTooLarge(context, cause),\n\tinvalid_reasoning_effort: (context, cause) =>\n\t\tnew GitHubCopilotInvalidRequestError(\"reasoning-effort\", context, { cause }),\n\tcontent_filter: (context, cause) => new GitHubCopilotContentFilterError(context, { cause }),\n\tcyber_policy: (context, cause) => new GitHubCopilotContentFilterError(context, { cause }),\n\trate_limit_exceeded: (context, cause) =>\n\t\tnew GitHubCopilotRateLimitError(context, getProviderRetryAfterMs(cause), { cause }),\n\tinsufficient_quota: (context, cause) => new GitHubCopilotQuotaExhaustedError(context, { cause }),\n\tquota_exceeded: (context, cause) => new GitHubCopilotQuotaExhaustedError(context, { cause }),\n\tserver_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n\tinvalid_request_error: (context, cause) =>\n\t\tbadRequestTextFailure(undefined, context, cause) ??\n\t\tnew GitHubCopilotInvalidRequestError(\"rejected\", context, { cause }),\n\tauthentication_error: (context, cause) => new GitHubCopilotAuthenticationError(context, { cause }),\n\tpermission_error: (context, cause) => new GitHubCopilotAuthenticationError(context, { cause }),\n\tbilling_error: (context, cause) => new GitHubCopilotQuotaExhaustedError(context, { cause }),\n\tnot_found_error: (context, cause) => new GitHubCopilotModelUnavailableError(\"not-found\", context, { cause }),\n\trequest_too_large: (context, cause) => promptTooLarge(context, cause),\n\trate_limit_error: (context, cause) =>\n\t\tnew GitHubCopilotRateLimitError(context, getProviderRetryAfterMs(cause), { cause }),\n\toverloaded_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n\tapi_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n\ttimeout_error: (context, cause) => new GitHubCopilotServiceUnavailableError(context, { cause }),\n};\n\nconst PROMPT_TOKENS_PATTERN = /prompt token count of (\\d+) exceeds the limit of (\\d+)/i;\n\nfunction promptTooLarge(context: GitHubCopilotErrorContext, cause: ProviderFailure): GitHubCopilotPromptTooLargeError {\n\tconst match = context.detail?.match(PROMPT_TOKENS_PATTERN);\n\treturn new GitHubCopilotPromptTooLargeError(\n\t\tcontext,\n\t\tmatch ? { promptTokens: Number(match[1]), limitTokens: Number(match[2]) } : undefined,\n\t\t{ cause },\n\t);\n}\n\n/**\n * Plain-text 400 bodies Copilot sends without a JSON code, observed live. Each is matched in full at the boundary so\n * the rest of Atomic branches on the typed code instead of on this text.\n */\nfunction plainTextFailure(\n\tdetail: string | undefined,\n\tcontext: GitHubCopilotErrorContext,\n\tcause: ProviderFailure,\n): GitHubCopilotError | undefined {\n\tconst text = detail?.toLowerCase();\n\tif (text === \"no model endpoints available given user constraints\") {\n\t\treturn new GitHubCopilotModelUnavailableError(\"no-endpoint\", context, { cause });\n\t}\n\tif (text === \"bad request: unknown copilot-integration-id\") {\n\t\treturn new GitHubCopilotInvalidRequestError(\"integration-id\", context, { cause });\n\t}\n\treturn undefined;\n}\n\n/**\n * Copilot sends a used-up monthly quota as HTTP 429 with `x-ratelimit-exceeded: quota_exceeded` and the plain body\n * `quota exceeded` (seen in public reports), unlike a short rate limit.\n */\nfunction reportsExhaustedQuota(response: ProviderFailure): boolean {\n\tconst exceeded = response.headers instanceof Headers ? response.headers.get(\"x-ratelimit-exceeded\") : null;\n\treturn (\n\t\texceeded?.trim().toLowerCase() === \"quota_exceeded\" ||\n\t\tproviderDetailOf(response, 429)?.toLowerCase() === \"quota exceeded\"\n\t);\n}\n\n/**\n * A 400 whose code Atomic does not recognize: Copilot's own prompt-token overflow text means the prompt is too large,\n * whatever the code; without a code, the exact plain-text bodies Copilot sends are matched.\n */\nfunction badRequestTextFailure(\n\tproviderCode: string | undefined,\n\tcontext: GitHubCopilotErrorContext,\n\tcause: ProviderFailure,\n): GitHubCopilotError | undefined {\n\tif (context.detail?.match(PROMPT_TOKENS_PATTERN)) return promptTooLarge(context, cause);\n\treturn providerCode === undefined ? plainTextFailure(context.detail, context, cause) : undefined;\n}\n\nfunction statusFailure(\n\tstatus: number,\n\tcontext: GitHubCopilotErrorContext,\n\tcause: ProviderFailure,\n\treportsQuota: boolean,\n): GitHubCopilotError {\n\tswitch (status) {\n\t\tcase 401:\n\t\tcase 403:\n\t\t\treturn new GitHubCopilotAuthenticationError(context, { cause });\n\t\tcase 402:\n\t\t\treturn new GitHubCopilotQuotaExhaustedError(context, { cause });\n\t\tcase 404:\n\t\t\treturn new GitHubCopilotModelUnavailableError(\"not-found\", context, { cause });\n\t\tcase 408:\n\t\t\treturn new GitHubCopilotServiceUnavailableError(context, { cause });\n\t\tcase 413:\n\t\t\treturn promptTooLarge(context, cause);\n\t\tcase 429:\n\t\t\treturn reportsQuota\n\t\t\t\t? new GitHubCopilotQuotaExhaustedError(context, { cause })\n\t\t\t\t: new GitHubCopilotRateLimitError(context, getProviderRetryAfterMs(cause), { cause });\n\t}\n\tif (status >= 500 && status <= 599) return new GitHubCopilotServiceUnavailableError(context, { cause });\n\tif (status >= 400 && status <= 499) return new GitHubCopilotInvalidRequestError(\"rejected\", context, { cause });\n\treturn new GitHubCopilotUnrecognizedResponseError(\"unknown-status\", context, { cause });\n}\n\n/** Where a Copilot request was when it failed. */\nexport interface GitHubCopilotFailureContext {\n\treadonly modelId: string;\n\treadonly api: string;\n\t/** What the request observed once Copilot answered with HTTP success; undefined when no response arrived. */\n\treadonly stream?: GitHubCopilotStreamSnapshot;\n\t/** The provider's raw finish or stop reason, when the stream reported one. */\n\treadonly finishReason?: string;\n}\n\n/**\n * The stop reasons each API reports when a content or safety filter ended the response. Responses also records a\n * plain `refusal` for a refusal delta that does not end the turn, so each API has its own set.\n */\nconst CONTENT_FILTER_STOPS: Readonly<Record<string, ReadonlySet<string | undefined>>> = {\n\t\"openai-completions\": new Set([\"content_filter\"]),\n\t\"openai-responses\": new Set([\"incomplete.content_filter\"]),\n\t\"anthropic-messages\": new Set([\"refusal\", \"sensitive\"]),\n};\n\n/**\n * Translate a failed Copilot request into its typed error, once, at the provider boundary.\n *\n * HTTP failures are classified by the provider's code first, then on a 400 by Copilot's prompt-token overflow text\n * and the exact plain-text bodies it sends without a code, then by status (a 429 that reports a used-up quota is\n * `quota-exhausted`). A failure after the stream started is a content-filter stop for its API, an in-stream error\n * event, a malformed body, or a stream that ended early. Returns undefined for a failure that never reached Copilot (a\n * connection error before any response), which keeps Atomic's generic network handling. Never call it for a\n * cancelled request: cancellation is not a failure.\n */\nexport function classifyGitHubCopilotFailure(\n\terror: unknown,\n\tfailure: GitHubCopilotFailureContext,\n): GitHubCopilotError | undefined {\n\tconst typed = findGitHubCopilotError(error);\n\tif (typed !== undefined) return typed;\n\tconst providerError: ProviderFailure =\n\t\terror instanceof Error ? (error as ProviderFailure) : new Error(String(error), { cause: error });\n\tconst response = responseOf(providerError);\n\tconst status = typeof providerError.status === \"number\" ? providerError.status : undefined;\n\tconst providerCode = providerCodeOf(response);\n\tconst context: GitHubCopilotErrorContext = {\n\t\tmodelId: failure.modelId,\n\t\tapi: failure.api,\n\t\tstatus,\n\t\tproviderCode,\n\t\trequestId: requestIdOf(response),\n\t\tdetail: providerDetailOf(response, typeof response.status === \"number\" ? response.status : undefined),\n\t};\n\tconst codeFailure = providerCode === undefined ? undefined : PROVIDER_CODE_FAILURES[providerCode.toLowerCase()];\n\tif (codeFailure !== undefined) return codeFailure(context, providerError);\n\tif (status !== undefined) {\n\t\treturn (\n\t\t\t(status === 400 ? badRequestTextFailure(providerCode, context, providerError) : undefined) ??\n\t\t\tstatusFailure(status, context, providerError, reportsExhaustedQuota(response))\n\t\t);\n\t}\n\tif (CONTENT_FILTER_STOPS[failure.api]?.has(failure.finishReason)) {\n\t\treturn new GitHubCopilotContentFilterError(context, { cause: providerError });\n\t}\n\tif (providerCode !== undefined) {\n\t\treturn new GitHubCopilotUnrecognizedResponseError(\"unknown-error-event\", context, { cause: providerError });\n\t}\n\tif (providerError instanceof SyntaxError || providerError.error !== undefined) {\n\t\treturn new GitHubCopilotUnrecognizedResponseError(\"malformed-body\", context, { cause: providerError });\n\t}\n\tif (failure.stream === undefined) return undefined;\n\treturn new GitHubCopilotStreamEndedEarlyError(\n\t\t{ ...context, requestId: context.requestId ?? failure.stream.requestId },\n\t\t{ cause: providerError, durationMs: failure.stream.durationMs, startedContent: failure.stream.startedContent },\n\t);\n}\n\n/**\n * Type a failed Copilot assistant message at the provider boundary: classify `error` and record it on `output`,\n * keeping the provider's text after the typed message. A cancelled message is left alone.\n */\nexport function recordGitHubCopilotFailure(\n\toutput: AssistantMessage,\n\terror: unknown,\n\tstream: GitHubCopilotStreamSnapshot | undefined,\n): void {\n\tif (output.stopReason !== \"error\") return;\n\tconst typed = classifyGitHubCopilotFailure(error, {\n\t\tmodelId: output.model,\n\t\tapi: output.api,\n\t\tstream,\n\t\tfinishReason: output.rawStopReason,\n\t});\n\tif (typed !== undefined) recordGitHubCopilotError(output, typed, output.errorMessage);\n}\n\n/**\n * The typed failure for a completed Copilot turn that has no text and no tool call, as Copilot's Gemini models\n * sometimes return; undefined for any other turn. A length stop is left to the caller's length handling.\n */\nexport function githubCopilotEmptyResponse(output: AssistantMessage): GitHubCopilotEmptyResponseError | undefined {\n\tif (output.provider !== \"github-copilot\" || (output.stopReason !== \"stop\" && output.stopReason !== \"toolUse\")) {\n\t\treturn undefined;\n\t}\n\tconst answered = output.content.some(\n\t\t(block) => block.type === \"toolCall\" || (block.type === \"text\" && block.text.trim().length > 0),\n\t);\n\treturn answered ? undefined : new GitHubCopilotEmptyResponseError({ modelId: output.model, api: output.api });\n}\n"]}