@gitlab/gitlab-ai-provider 3.4.0 → 3.5.0

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/dist/index.mjs CHANGED
@@ -38,6 +38,17 @@ var GitLabError = class _GitLabError extends Error {
38
38
  isServerError() {
39
39
  return this.statusCode !== void 0 && this.statusCode >= 500;
40
40
  }
41
+ /**
42
+ * Check if this error is a context overflow error (prompt too long).
43
+ * These errors occur when the conversation exceeds the model's token limit.
44
+ */
45
+ isContextOverflowError() {
46
+ if (this.statusCode !== 400) {
47
+ return false;
48
+ }
49
+ const message = this.message?.toLowerCase() || "";
50
+ return message.includes("context overflow") || message.includes("prompt is too long") || message.includes("prompt too long") || message.includes("tokens") && message.includes("maximum");
51
+ }
41
52
  };
42
53
 
43
54
  // src/gitlab-direct-access.ts
@@ -208,6 +219,21 @@ var GitLabAnthropicLanguageModel = class {
208
219
  }
209
220
  return false;
210
221
  }
222
+ /**
223
+ * Check if an error is a context overflow error (prompt too long)
224
+ * These should NOT trigger token refresh and should be reported to the user.
225
+ */
226
+ isContextOverflowError(error) {
227
+ if (error instanceof Anthropic.APIError) {
228
+ if (error.status === 400) {
229
+ const message = error.message?.toLowerCase() || "";
230
+ if (message.includes("prompt is too long") || message.includes("prompt too long") || message.includes("tokens") && message.includes("maximum")) {
231
+ return true;
232
+ }
233
+ }
234
+ }
235
+ return false;
236
+ }
211
237
  /**
212
238
  * Convert AI SDK tools to Anthropic tool format
213
239
  */
@@ -385,6 +411,14 @@ var GitLabAnthropicLanguageModel = class {
385
411
  warnings: []
386
412
  };
387
413
  } catch (error) {
414
+ if (this.isContextOverflowError(error)) {
415
+ const apiError = error;
416
+ throw new GitLabError({
417
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
418
+ statusCode: 400,
419
+ cause: error
420
+ });
421
+ }
388
422
  if (!isRetry && this.isTokenError(error)) {
389
423
  this.directAccessClient.invalidateToken();
390
424
  return this.doGenerateWithRetry(options, true);
@@ -392,6 +426,7 @@ var GitLabAnthropicLanguageModel = class {
392
426
  if (error instanceof Anthropic.APIError) {
393
427
  throw new GitLabError({
394
428
  message: `Anthropic API error: ${error.message}`,
429
+ statusCode: error.status,
395
430
  cause: error
396
431
  });
397
432
  }
@@ -572,6 +607,19 @@ var GitLabAnthropicLanguageModel = class {
572
607
  });
573
608
  }
574
609
  }
610
+ if (self.isContextOverflowError(error)) {
611
+ const apiError = error;
612
+ controller.enqueue({
613
+ type: "error",
614
+ error: new GitLabError({
615
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
616
+ statusCode: 400,
617
+ cause: error
618
+ })
619
+ });
620
+ controller.close();
621
+ return;
622
+ }
575
623
  if (!isRetry && self.isTokenError(error)) {
576
624
  self.directAccessClient.invalidateToken();
577
625
  controller.enqueue({
@@ -589,6 +637,7 @@ var GitLabAnthropicLanguageModel = class {
589
637
  type: "error",
590
638
  error: new GitLabError({
591
639
  message: `Anthropic API error: ${error.message}`,
640
+ statusCode: error.status,
592
641
  cause: error
593
642
  })
594
643
  });
@@ -615,6 +664,7 @@ import OpenAI from "openai";
615
664
  // src/model-mappings.ts
616
665
  var MODEL_MAPPINGS = {
617
666
  // Anthropic models
667
+ "duo-chat-opus-4-6": { provider: "anthropic", model: "claude-opus-4-6" },
618
668
  "duo-chat-opus-4-5": { provider: "anthropic", model: "claude-opus-4-5-20251101" },
619
669
  "duo-chat-sonnet-4-5": { provider: "anthropic", model: "claude-sonnet-4-5-20250929" },
620
670
  "duo-chat-haiku-4-5": { provider: "anthropic", model: "claude-haiku-4-5-20251001" },
@@ -713,6 +763,21 @@ var GitLabOpenAILanguageModel = class {
713
763
  }
714
764
  return false;
715
765
  }
766
+ /**
767
+ * Check if an error is a context overflow error (prompt too long)
768
+ * These should NOT trigger token refresh and should be reported to the user.
769
+ */
770
+ isContextOverflowError(error) {
771
+ if (error instanceof OpenAI.APIError) {
772
+ if (error.status === 400) {
773
+ const message = error.message?.toLowerCase() || "";
774
+ if (message.includes("prompt is too long") || message.includes("prompt too long") || message.includes("tokens") && message.includes("maximum")) {
775
+ return true;
776
+ }
777
+ }
778
+ }
779
+ return false;
780
+ }
716
781
  convertTools(tools) {
717
782
  if (!tools || tools.length === 0) {
718
783
  return void 0;
@@ -993,6 +1058,14 @@ var GitLabOpenAILanguageModel = class {
993
1058
  warnings: []
994
1059
  };
995
1060
  } catch (error) {
1061
+ if (this.isContextOverflowError(error)) {
1062
+ const apiError = error;
1063
+ throw new GitLabError({
1064
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1065
+ statusCode: 400,
1066
+ cause: error
1067
+ });
1068
+ }
996
1069
  if (!isRetry && this.isTokenError(error)) {
997
1070
  this.directAccessClient.invalidateToken();
998
1071
  return this.doGenerateWithChatApi(options, true);
@@ -1000,6 +1073,7 @@ var GitLabOpenAILanguageModel = class {
1000
1073
  if (error instanceof OpenAI.APIError) {
1001
1074
  throw new GitLabError({
1002
1075
  message: `OpenAI API error: ${error.message}`,
1076
+ statusCode: error.status,
1003
1077
  cause: error
1004
1078
  });
1005
1079
  }
@@ -1055,6 +1129,14 @@ var GitLabOpenAILanguageModel = class {
1055
1129
  warnings: []
1056
1130
  };
1057
1131
  } catch (error) {
1132
+ if (this.isContextOverflowError(error)) {
1133
+ const apiError = error;
1134
+ throw new GitLabError({
1135
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1136
+ statusCode: 400,
1137
+ cause: error
1138
+ });
1139
+ }
1058
1140
  if (!isRetry && this.isTokenError(error)) {
1059
1141
  this.directAccessClient.invalidateToken();
1060
1142
  return this.doGenerateWithResponsesApi(options, true);
@@ -1062,6 +1144,7 @@ var GitLabOpenAILanguageModel = class {
1062
1144
  if (error instanceof OpenAI.APIError) {
1063
1145
  throw new GitLabError({
1064
1146
  message: `OpenAI API error: ${error.message}`,
1147
+ statusCode: error.status,
1065
1148
  cause: error
1066
1149
  });
1067
1150
  }
@@ -1180,6 +1263,19 @@ var GitLabOpenAILanguageModel = class {
1180
1263
  controller.enqueue({ type: "finish", finishReason, usage });
1181
1264
  controller.close();
1182
1265
  } catch (error) {
1266
+ if (self.isContextOverflowError(error)) {
1267
+ const apiError = error;
1268
+ controller.enqueue({
1269
+ type: "error",
1270
+ error: new GitLabError({
1271
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1272
+ statusCode: 400,
1273
+ cause: error
1274
+ })
1275
+ });
1276
+ controller.close();
1277
+ return;
1278
+ }
1183
1279
  if (!isRetry && self.isTokenError(error)) {
1184
1280
  self.directAccessClient.invalidateToken();
1185
1281
  controller.enqueue({
@@ -1194,6 +1290,7 @@ var GitLabOpenAILanguageModel = class {
1194
1290
  type: "error",
1195
1291
  error: new GitLabError({
1196
1292
  message: `OpenAI API error: ${error.message}`,
1293
+ statusCode: error.status,
1197
1294
  cause: error
1198
1295
  })
1199
1296
  });
@@ -1320,6 +1417,19 @@ var GitLabOpenAILanguageModel = class {
1320
1417
  controller.enqueue({ type: "finish", finishReason, usage });
1321
1418
  controller.close();
1322
1419
  } catch (error) {
1420
+ if (self.isContextOverflowError(error)) {
1421
+ const apiError = error;
1422
+ controller.enqueue({
1423
+ type: "error",
1424
+ error: new GitLabError({
1425
+ message: `Context overflow: ${apiError.message}. Please start a new session or use /compact to reduce context.`,
1426
+ statusCode: 400,
1427
+ cause: error
1428
+ })
1429
+ });
1430
+ controller.close();
1431
+ return;
1432
+ }
1323
1433
  if (!isRetry && self.isTokenError(error)) {
1324
1434
  self.directAccessClient.invalidateToken();
1325
1435
  controller.enqueue({
@@ -1334,6 +1444,7 @@ var GitLabOpenAILanguageModel = class {
1334
1444
  type: "error",
1335
1445
  error: new GitLabError({
1336
1446
  message: `OpenAI API error: ${error.message}`,
1447
+ statusCode: error.status,
1337
1448
  cause: error
1338
1449
  })
1339
1450
  });
@@ -1511,7 +1622,7 @@ var GitLabOAuthManager = class {
1511
1622
  };
1512
1623
 
1513
1624
  // src/version.ts
1514
- var VERSION = true ? "3.3.1" : "0.0.0-dev";
1625
+ var VERSION = true ? "3.4.1" : "0.0.0-dev";
1515
1626
 
1516
1627
  // src/gitlab-provider.ts
1517
1628
  import * as fs from "fs";