gitlab-ai-provider 6.9.2 → 6.10.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
@@ -648,6 +648,9 @@ var GitLabDirectAccessClient = class {
648
648
  if (this.config.featureFlags && Object.keys(this.config.featureFlags).length > 0) {
649
649
  requestBody.feature_flags = this.config.featureFlags;
650
650
  }
651
+ if (this.config.ensureApiKey) {
652
+ await this.config.ensureApiKey();
653
+ }
651
654
  try {
652
655
  const response = await this.fetchFn(url, {
653
656
  method: "POST",
@@ -743,6 +746,7 @@ var GitLabAnthropicLanguageModel = class {
743
746
  this.directAccessClient = new GitLabDirectAccessClient({
744
747
  instanceUrl: config.instanceUrl,
745
748
  getHeaders: config.getHeaders,
749
+ ensureApiKey: config.ensureApiKey,
746
750
  refreshApiKey: config.refreshApiKey,
747
751
  fetch: config.fetch,
748
752
  featureFlags: config.featureFlags,
@@ -1378,6 +1382,7 @@ var MODEL_MAPPINGS = {
1378
1382
  "duo-chat-opus-4-8": { provider: "anthropic", model: "claude-opus-4-8" },
1379
1383
  "duo-chat-opus-4-7": { provider: "anthropic", model: "claude-opus-4-7" },
1380
1384
  "duo-chat-opus-4-6": { provider: "anthropic", model: "claude-opus-4-6" },
1385
+ "duo-chat-sonnet-5": { provider: "anthropic", model: "claude-sonnet-5" },
1381
1386
  "duo-chat-sonnet-4-6": { provider: "anthropic", model: "claude-sonnet-4-6" },
1382
1387
  "duo-chat-opus-4-5": { provider: "anthropic", model: "claude-opus-4-5-20251101" },
1383
1388
  "duo-chat-sonnet-4-5": { provider: "anthropic", model: "claude-sonnet-4-5-20250929" },
@@ -1417,6 +1422,7 @@ var MODEL_MAPPINGS = {
1417
1422
  provider: "workflow",
1418
1423
  model: "anthropic/claude-sonnet-4-5-20250929"
1419
1424
  },
1425
+ "duo-workflow-sonnet-5": { provider: "workflow", model: "claude_sonnet_5" },
1420
1426
  "duo-workflow-sonnet-4-6": { provider: "workflow", model: "claude_sonnet_4_6" },
1421
1427
  "duo-workflow-opus-4-5": {
1422
1428
  provider: "workflow",
@@ -1476,6 +1482,7 @@ var GitLabOpenAILanguageModel = class {
1476
1482
  this.directAccessClient = new GitLabDirectAccessClient({
1477
1483
  instanceUrl: config.instanceUrl,
1478
1484
  getHeaders: config.getHeaders,
1485
+ ensureApiKey: config.ensureApiKey,
1479
1486
  refreshApiKey: config.refreshApiKey,
1480
1487
  fetch: config.fetch,
1481
1488
  featureFlags: config.featureFlags,
@@ -2417,7 +2424,7 @@ import { AsyncResource } from "async_hooks";
2417
2424
  import WebSocket from "isomorphic-ws";
2418
2425
 
2419
2426
  // src/version.ts
2420
- var VERSION = true ? "6.9.1" : "0.0.0-dev";
2427
+ var VERSION = true ? "6.9.3" : "0.0.0-dev";
2421
2428
 
2422
2429
  // src/gitlab-workflow-client.ts
2423
2430
  var WS_CONNECT_TIMEOUT_MS = 3e4;
@@ -4754,9 +4761,10 @@ var TOKEN_EXPIRY_SKEW_MS = 5 * 60 * 1e3;
4754
4761
  var OAUTH_SCOPES = ["api"];
4755
4762
 
4756
4763
  // src/gitlab-oauth-manager.ts
4764
+ var globalInFlightRefreshes = /* @__PURE__ */ new Map();
4757
4765
  var GitLabOAuthManager = class {
4758
4766
  fetch;
4759
- inFlightRefreshes = /* @__PURE__ */ new Map();
4767
+ inFlightRefreshes = globalInFlightRefreshes;
4760
4768
  constructor(fetchImpl = fetch) {
4761
4769
  this.fetch = fetchImpl;
4762
4770
  }
@@ -4985,6 +4993,39 @@ async function loadOpenCodeAuth(instanceUrl) {
4985
4993
  return void 0;
4986
4994
  }
4987
4995
  }
4996
+ var inFlightOAuthRefreshes = /* @__PURE__ */ new Map();
4997
+ async function refreshOAuthToken(auth, instanceUrl, clientId) {
4998
+ const existing = inFlightOAuthRefreshes.get(instanceUrl);
4999
+ if (existing) {
5000
+ return existing;
5001
+ }
5002
+ const refreshPromise = (async () => {
5003
+ const oauthManager = new GitLabOAuthManager();
5004
+ const refreshed = await oauthManager.exchangeRefreshToken({
5005
+ instanceUrl,
5006
+ refreshToken: auth.refresh,
5007
+ clientId
5008
+ });
5009
+ const authPath = getOpenCodeAuthPath();
5010
+ const authData = JSON.parse(fs3.readFileSync(authPath, "utf-8"));
5011
+ authData.gitlab = {
5012
+ type: "oauth",
5013
+ refresh: refreshed.refreshToken,
5014
+ access: refreshed.accessToken,
5015
+ expires: refreshed.expiresAt,
5016
+ enterpriseUrl: instanceUrl
5017
+ // Use enterpriseUrl to match auth plugin format
5018
+ };
5019
+ fs3.writeFileSync(authPath, JSON.stringify(authData, null, 2), { mode: 384 });
5020
+ return refreshed.accessToken;
5021
+ })();
5022
+ inFlightOAuthRefreshes.set(instanceUrl, refreshPromise);
5023
+ try {
5024
+ return await refreshPromise;
5025
+ } finally {
5026
+ inFlightOAuthRefreshes.delete(instanceUrl);
5027
+ }
5028
+ }
4988
5029
  async function loadApiKey(options, instanceUrl, clientId) {
4989
5030
  if (options.apiKey) {
4990
5031
  return options.apiKey;
@@ -4997,23 +5038,7 @@ async function loadApiKey(options, instanceUrl, clientId) {
4997
5038
  const oauthManager = new GitLabOAuthManager();
4998
5039
  if (oauthManager.needsRefresh(auth.expires)) {
4999
5040
  try {
5000
- const refreshed = await oauthManager.exchangeRefreshToken({
5001
- instanceUrl,
5002
- refreshToken: auth.refresh,
5003
- clientId
5004
- });
5005
- const authPath = getOpenCodeAuthPath();
5006
- const authData = JSON.parse(fs3.readFileSync(authPath, "utf-8"));
5007
- authData.gitlab = {
5008
- type: "oauth",
5009
- refresh: refreshed.refreshToken,
5010
- access: refreshed.accessToken,
5011
- expires: refreshed.expiresAt,
5012
- enterpriseUrl: instanceUrl
5013
- // Use enterpriseUrl to match auth plugin format
5014
- };
5015
- fs3.writeFileSync(authPath, JSON.stringify(authData, null, 2), { mode: 384 });
5016
- return refreshed.accessToken;
5041
+ return await refreshOAuthToken(auth, instanceUrl, clientId);
5017
5042
  } catch (error) {
5018
5043
  const refreshErrorMsg = error instanceof Error ? error.message : String(error);
5019
5044
  const envApiKey = process.env[options.environmentVariableName];
@@ -5112,6 +5137,12 @@ function createGitLab(options = {}) {
5112
5137
  `ai-sdk-gitlab/${VERSION}`
5113
5138
  );
5114
5139
  };
5140
+ const ensureApiKey = async () => {
5141
+ try {
5142
+ await getApiKey();
5143
+ } catch {
5144
+ }
5145
+ };
5115
5146
  getApiKey().catch(() => {
5116
5147
  });
5117
5148
  const createAgenticChatModel = (modelId, agenticOptions) => {
@@ -5146,6 +5177,7 @@ function createGitLab(options = {}) {
5146
5177
  provider: `${providerName}.agentic`,
5147
5178
  instanceUrl,
5148
5179
  getHeaders,
5180
+ ensureApiKey,
5149
5181
  refreshApiKey,
5150
5182
  fetch: options.fetch,
5151
5183
  maxTokens: agenticOptions?.maxTokens,