@gitlab/gitlab-ai-provider 3.4.0 → 3.4.1

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
+ ## <small>3.4.1 (2026-02-06)</small>
6
+
7
+ - Merge branch 'vg/token_refresh_fix' into 'main' ([8c1f2c4](https://gitlab.com/gitlab-org/editor-extensions/gitlab-ai-provider/commit/8c1f2c4))
8
+ - fix: detect context overflow errors before token refresh ([ce272cd](https://gitlab.com/gitlab-org/editor-extensions/gitlab-ai-provider/commit/ce272cd))
9
+
5
10
  ## 3.4.0 (2026-02-02)
6
11
 
7
12
  - Merge branch 'feat/ai-gateway-headers' into 'main' ([f2d4c79](https://gitlab.com/gitlab-org/editor-extensions/gitlab-ai-provider/commit/f2d4c79))
package/dist/index.d.mts CHANGED
@@ -65,6 +65,11 @@ declare class GitLabAnthropicLanguageModel implements LanguageModelV2 {
65
65
  * Check if an error is a token-related authentication error that can be retried
66
66
  */
67
67
  private isTokenError;
68
+ /**
69
+ * Check if an error is a context overflow error (prompt too long)
70
+ * These should NOT trigger token refresh and should be reported to the user.
71
+ */
72
+ private isContextOverflowError;
68
73
  /**
69
74
  * Convert AI SDK tools to Anthropic tool format
70
75
  */
@@ -265,6 +270,11 @@ declare class GitLabOpenAILanguageModel implements LanguageModelV2 {
265
270
  get provider(): string;
266
271
  private getOpenAIClient;
267
272
  private isTokenError;
273
+ /**
274
+ * Check if an error is a context overflow error (prompt too long)
275
+ * These should NOT trigger token refresh and should be reported to the user.
276
+ */
277
+ private isContextOverflowError;
268
278
  private convertTools;
269
279
  private convertToolChoice;
270
280
  private convertPrompt;
@@ -342,6 +352,11 @@ declare class GitLabError extends Error {
342
352
  isRateLimitError(): boolean;
343
353
  isForbiddenError(): boolean;
344
354
  isServerError(): boolean;
355
+ /**
356
+ * Check if this error is a context overflow error (prompt too long).
357
+ * These errors occur when the conversation exceeds the model's token limit.
358
+ */
359
+ isContextOverflowError(): boolean;
345
360
  }
346
361
 
347
362
  declare const gitlabOAuthTokenResponseSchema: z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -65,6 +65,11 @@ declare class GitLabAnthropicLanguageModel implements LanguageModelV2 {
65
65
  * Check if an error is a token-related authentication error that can be retried
66
66
  */
67
67
  private isTokenError;
68
+ /**
69
+ * Check if an error is a context overflow error (prompt too long)
70
+ * These should NOT trigger token refresh and should be reported to the user.
71
+ */
72
+ private isContextOverflowError;
68
73
  /**
69
74
  * Convert AI SDK tools to Anthropic tool format
70
75
  */
@@ -265,6 +270,11 @@ declare class GitLabOpenAILanguageModel implements LanguageModelV2 {
265
270
  get provider(): string;
266
271
  private getOpenAIClient;
267
272
  private isTokenError;
273
+ /**
274
+ * Check if an error is a context overflow error (prompt too long)
275
+ * These should NOT trigger token refresh and should be reported to the user.
276
+ */
277
+ private isContextOverflowError;
268
278
  private convertTools;
269
279
  private convertToolChoice;
270
280
  private convertPrompt;
@@ -342,6 +352,11 @@ declare class GitLabError extends Error {
342
352
  isRateLimitError(): boolean;
343
353
  isForbiddenError(): boolean;
344
354
  isServerError(): boolean;
355
+ /**
356
+ * Check if this error is a context overflow error (prompt too long).
357
+ * These errors occur when the conversation exceeds the model's token limit.
358
+ */
359
+ isContextOverflowError(): boolean;
345
360
  }
346
361
 
347
362
  declare const gitlabOAuthTokenResponseSchema: z.ZodObject<{
package/dist/index.js CHANGED
@@ -96,6 +96,17 @@ var GitLabError = class _GitLabError extends Error {
96
96
  isServerError() {
97
97
  return this.statusCode !== void 0 && this.statusCode >= 500;
98
98
  }
99
+ /**
100
+ * Check if this error is a context overflow error (prompt too long).
101
+ * These errors occur when the conversation exceeds the model's token limit.
102
+ */
103
+ isContextOverflowError() {
104
+ if (this.statusCode !== 400) {
105
+ return false;
106
+ }
107
+ const message = this.message?.toLowerCase() || "";
108
+ return message.includes("context overflow") || message.includes("prompt is too long") || message.includes("prompt too long") || message.includes("tokens") && message.includes("maximum");
109
+ }
99
110
  };
100
111
 
101
112
  // src/gitlab-direct-access.ts
@@ -266,6 +277,21 @@ var GitLabAnthropicLanguageModel = class {
266
277
  }
267
278
  return false;
268
279
  }
280
+ /**
281
+ * Check if an error is a context overflow error (prompt too long)
282
+ * These should NOT trigger token refresh and should be reported to the user.
283
+ */
284
+ isContextOverflowError(error) {
285
+ if (error instanceof import_sdk.default.APIError) {
286
+ if (error.status === 400) {
287
+ const message = error.message?.toLowerCase() || "";
288
+ if (message.includes("prompt is too long") || message.includes("prompt too long") || message.includes("tokens") && message.includes("maximum")) {
289
+ return true;
290
+ }
291
+ }
292
+ }
293
+ return false;
294
+ }
269
295
  /**
270
296
  * Convert AI SDK tools to Anthropic tool format
271
297
  */
@@ -443,6 +469,14 @@ var GitLabAnthropicLanguageModel = class {
443
469
  warnings: []
444
470
  };
445
471
  } catch (error) {
472
+ if (this.isContextOverflowError(error)) {
473
+ const apiError = error;
474
+ throw new GitLabError({
475
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
476
+ statusCode: 400,
477
+ cause: error
478
+ });
479
+ }
446
480
  if (!isRetry && this.isTokenError(error)) {
447
481
  this.directAccessClient.invalidateToken();
448
482
  return this.doGenerateWithRetry(options, true);
@@ -450,6 +484,7 @@ var GitLabAnthropicLanguageModel = class {
450
484
  if (error instanceof import_sdk.default.APIError) {
451
485
  throw new GitLabError({
452
486
  message: `Anthropic API error: ${error.message}`,
487
+ statusCode: error.status,
453
488
  cause: error
454
489
  });
455
490
  }
@@ -630,6 +665,19 @@ var GitLabAnthropicLanguageModel = class {
630
665
  });
631
666
  }
632
667
  }
668
+ if (self.isContextOverflowError(error)) {
669
+ const apiError = error;
670
+ controller.enqueue({
671
+ type: "error",
672
+ error: new GitLabError({
673
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
674
+ statusCode: 400,
675
+ cause: error
676
+ })
677
+ });
678
+ controller.close();
679
+ return;
680
+ }
633
681
  if (!isRetry && self.isTokenError(error)) {
634
682
  self.directAccessClient.invalidateToken();
635
683
  controller.enqueue({
@@ -647,6 +695,7 @@ var GitLabAnthropicLanguageModel = class {
647
695
  type: "error",
648
696
  error: new GitLabError({
649
697
  message: `Anthropic API error: ${error.message}`,
698
+ statusCode: error.status,
650
699
  cause: error
651
700
  })
652
701
  });
@@ -771,6 +820,21 @@ var GitLabOpenAILanguageModel = class {
771
820
  }
772
821
  return false;
773
822
  }
823
+ /**
824
+ * Check if an error is a context overflow error (prompt too long)
825
+ * These should NOT trigger token refresh and should be reported to the user.
826
+ */
827
+ isContextOverflowError(error) {
828
+ if (error instanceof import_openai.default.APIError) {
829
+ if (error.status === 400) {
830
+ const message = error.message?.toLowerCase() || "";
831
+ if (message.includes("prompt is too long") || message.includes("prompt too long") || message.includes("tokens") && message.includes("maximum")) {
832
+ return true;
833
+ }
834
+ }
835
+ }
836
+ return false;
837
+ }
774
838
  convertTools(tools) {
775
839
  if (!tools || tools.length === 0) {
776
840
  return void 0;
@@ -1051,6 +1115,14 @@ var GitLabOpenAILanguageModel = class {
1051
1115
  warnings: []
1052
1116
  };
1053
1117
  } catch (error) {
1118
+ if (this.isContextOverflowError(error)) {
1119
+ const apiError = error;
1120
+ throw new GitLabError({
1121
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1122
+ statusCode: 400,
1123
+ cause: error
1124
+ });
1125
+ }
1054
1126
  if (!isRetry && this.isTokenError(error)) {
1055
1127
  this.directAccessClient.invalidateToken();
1056
1128
  return this.doGenerateWithChatApi(options, true);
@@ -1058,6 +1130,7 @@ var GitLabOpenAILanguageModel = class {
1058
1130
  if (error instanceof import_openai.default.APIError) {
1059
1131
  throw new GitLabError({
1060
1132
  message: `OpenAI API error: ${error.message}`,
1133
+ statusCode: error.status,
1061
1134
  cause: error
1062
1135
  });
1063
1136
  }
@@ -1113,6 +1186,14 @@ var GitLabOpenAILanguageModel = class {
1113
1186
  warnings: []
1114
1187
  };
1115
1188
  } catch (error) {
1189
+ if (this.isContextOverflowError(error)) {
1190
+ const apiError = error;
1191
+ throw new GitLabError({
1192
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1193
+ statusCode: 400,
1194
+ cause: error
1195
+ });
1196
+ }
1116
1197
  if (!isRetry && this.isTokenError(error)) {
1117
1198
  this.directAccessClient.invalidateToken();
1118
1199
  return this.doGenerateWithResponsesApi(options, true);
@@ -1120,6 +1201,7 @@ var GitLabOpenAILanguageModel = class {
1120
1201
  if (error instanceof import_openai.default.APIError) {
1121
1202
  throw new GitLabError({
1122
1203
  message: `OpenAI API error: ${error.message}`,
1204
+ statusCode: error.status,
1123
1205
  cause: error
1124
1206
  });
1125
1207
  }
@@ -1238,6 +1320,19 @@ var GitLabOpenAILanguageModel = class {
1238
1320
  controller.enqueue({ type: "finish", finishReason, usage });
1239
1321
  controller.close();
1240
1322
  } catch (error) {
1323
+ if (self.isContextOverflowError(error)) {
1324
+ const apiError = error;
1325
+ controller.enqueue({
1326
+ type: "error",
1327
+ error: new GitLabError({
1328
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1329
+ statusCode: 400,
1330
+ cause: error
1331
+ })
1332
+ });
1333
+ controller.close();
1334
+ return;
1335
+ }
1241
1336
  if (!isRetry && self.isTokenError(error)) {
1242
1337
  self.directAccessClient.invalidateToken();
1243
1338
  controller.enqueue({
@@ -1252,6 +1347,7 @@ var GitLabOpenAILanguageModel = class {
1252
1347
  type: "error",
1253
1348
  error: new GitLabError({
1254
1349
  message: `OpenAI API error: ${error.message}`,
1350
+ statusCode: error.status,
1255
1351
  cause: error
1256
1352
  })
1257
1353
  });
@@ -1378,6 +1474,19 @@ var GitLabOpenAILanguageModel = class {
1378
1474
  controller.enqueue({ type: "finish", finishReason, usage });
1379
1475
  controller.close();
1380
1476
  } catch (error) {
1477
+ if (self.isContextOverflowError(error)) {
1478
+ const apiError = error;
1479
+ controller.enqueue({
1480
+ type: "error",
1481
+ error: new GitLabError({
1482
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1483
+ statusCode: 400,
1484
+ cause: error
1485
+ })
1486
+ });
1487
+ controller.close();
1488
+ return;
1489
+ }
1381
1490
  if (!isRetry && self.isTokenError(error)) {
1382
1491
  self.directAccessClient.invalidateToken();
1383
1492
  controller.enqueue({
@@ -1392,6 +1501,7 @@ var GitLabOpenAILanguageModel = class {
1392
1501
  type: "error",
1393
1502
  error: new GitLabError({
1394
1503
  message: `OpenAI API error: ${error.message}`,
1504
+ statusCode: error.status,
1395
1505
  cause: error
1396
1506
  })
1397
1507
  });
@@ -1569,7 +1679,7 @@ var GitLabOAuthManager = class {
1569
1679
  };
1570
1680
 
1571
1681
  // src/version.ts
1572
- var VERSION = true ? "3.3.1" : "0.0.0-dev";
1682
+ var VERSION = true ? "3.4.0" : "0.0.0-dev";
1573
1683
 
1574
1684
  // src/gitlab-provider.ts
1575
1685
  var fs = __toESM(require("fs"));