@gitlab/gitlab-ai-provider 3.4.1 → 3.5.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/dist/index.mjs CHANGED
@@ -664,6 +664,7 @@ import OpenAI from "openai";
664
664
  // src/model-mappings.ts
665
665
  var MODEL_MAPPINGS = {
666
666
  // Anthropic models
667
+ "duo-chat-opus-4-6": { provider: "anthropic", model: "claude-opus-4-6" },
667
668
  "duo-chat-opus-4-5": { provider: "anthropic", model: "claude-opus-4-5-20251101" },
668
669
  "duo-chat-sonnet-4-5": { provider: "anthropic", model: "claude-sonnet-4-5-20250929" },
669
670
  "duo-chat-haiku-4-5": { provider: "anthropic", model: "claude-haiku-4-5-20251001" },
@@ -1459,6 +1460,7 @@ var GitLabOpenAILanguageModel = class {
1459
1460
  };
1460
1461
 
1461
1462
  // src/gitlab-oauth-types.ts
1463
+ var OPENCODE_GITLAB_AUTH_CLIENT_ID = "1d89f9fdb23ee96d4e603201f6861dab6e143c5c3c00469a018a2d94bdc03d4e";
1462
1464
  var BUNDLED_CLIENT_ID = "36f2a70cddeb5a0889d4fd8295c241b7e9848e89cf9e599d0eed2d8e5350fbf5";
1463
1465
  var GITLAB_COM_URL = "https://gitlab.com";
1464
1466
  var TOKEN_EXPIRY_SKEW_MS = 5 * 60 * 1e3;
@@ -1532,14 +1534,21 @@ var GitLabOAuthManager = class {
1532
1534
  return this.createTokensFromResponse(tokenResponse, instanceUrl);
1533
1535
  }
1534
1536
  /**
1535
- * Get the OAuth client ID for an instance
1537
+ * Get the OAuth client ID for an instance.
1538
+ * Priority: env var > opencode-gitlab-auth default (for GitLab.com).
1539
+ * Note: callers (e.g. exchangeRefreshToken) may pass an explicit clientId
1540
+ * that bypasses this method entirely.
1536
1541
  */
1537
1542
  getClientId(instanceUrl) {
1543
+ const envClientId = process.env["GITLAB_OAUTH_CLIENT_ID"];
1544
+ if (envClientId) {
1545
+ return envClientId;
1546
+ }
1538
1547
  if (instanceUrl === GITLAB_COM_URL) {
1539
- return BUNDLED_CLIENT_ID;
1548
+ return OPENCODE_GITLAB_AUTH_CLIENT_ID;
1540
1549
  }
1541
1550
  throw new GitLabError({
1542
- message: `No OAuth client ID configured for instance ${instanceUrl}. Please provide a clientId parameter.`
1551
+ message: `No OAuth client ID configured for instance ${instanceUrl}. Please provide a clientId parameter or set GITLAB_OAUTH_CLIENT_ID environment variable.`
1543
1552
  });
1544
1553
  }
1545
1554
  /**
@@ -1621,7 +1630,7 @@ var GitLabOAuthManager = class {
1621
1630
  };
1622
1631
 
1623
1632
  // src/version.ts
1624
- var VERSION = true ? "3.4.0" : "0.0.0-dev";
1633
+ var VERSION = true ? "3.5.0" : "0.0.0-dev";
1625
1634
 
1626
1635
  // src/gitlab-provider.ts
1627
1636
  import * as fs from "fs";
@@ -1674,20 +1683,26 @@ async function loadApiKey(options, instanceUrl, clientId) {
1674
1683
  });
1675
1684
  const authPath = getOpenCodeAuthPath();
1676
1685
  const authData = JSON.parse(fs.readFileSync(authPath, "utf-8"));
1677
- const normalizedUrl = instanceUrl.replace(/\/$/, "");
1678
- authData[normalizedUrl] = {
1686
+ authData.gitlab = {
1679
1687
  type: "oauth",
1680
1688
  refresh: refreshed.refreshToken,
1681
1689
  access: refreshed.accessToken,
1682
1690
  expires: refreshed.expiresAt,
1683
- instanceUrl
1691
+ enterpriseUrl: instanceUrl
1692
+ // Use enterpriseUrl to match auth plugin format
1684
1693
  };
1685
- fs.writeFileSync(authPath, JSON.stringify(authData, null, 2));
1694
+ fs.writeFileSync(authPath, JSON.stringify(authData, null, 2), { mode: 384 });
1686
1695
  return refreshed.accessToken;
1687
1696
  } catch (error) {
1688
- console.warn(
1689
- `Failed to refresh OAuth token: ${error instanceof Error ? error.message : String(error)}`
1690
- );
1697
+ const refreshErrorMsg = error instanceof Error ? error.message : String(error);
1698
+ console.warn(`Failed to refresh OAuth token: ${refreshErrorMsg}`);
1699
+ const envApiKey = process.env[options.environmentVariableName];
1700
+ if (envApiKey) {
1701
+ return envApiKey;
1702
+ }
1703
+ throw new GitLabError({
1704
+ message: `OAuth token refresh failed and no fallback ${options.environmentVariableName} environment variable is set. Refresh error: ${refreshErrorMsg}. Re-authenticate with 'opencode auth login gitlab' or set ${options.environmentVariableName}.`
1705
+ });
1691
1706
  }
1692
1707
  } else {
1693
1708
  return auth.access;
@@ -1736,7 +1751,16 @@ function createGitLab(options = {}) {
1736
1751
  const refreshApiKey = async () => {
1737
1752
  cachedApiKey = void 0;
1738
1753
  apiKeyPromise = void 0;
1739
- cachedApiKey = await getApiKey();
1754
+ cachedApiKey = await loadApiKey(
1755
+ {
1756
+ apiKey: void 0,
1757
+ // Bypass stale options.apiKey to force auth.json read
1758
+ environmentVariableName: "GITLAB_TOKEN",
1759
+ description: "GitLab"
1760
+ },
1761
+ instanceUrl,
1762
+ options.clientId
1763
+ );
1740
1764
  };
1741
1765
  const getHeaders = () => {
1742
1766
  const apiKey = cachedApiKey || options.apiKey || process.env["GITLAB_TOKEN"] || "";
@@ -2112,6 +2136,7 @@ export {
2112
2136
  MODEL_ID_TO_ANTHROPIC_MODEL,
2113
2137
  MODEL_MAPPINGS,
2114
2138
  OAUTH_SCOPES,
2139
+ OPENCODE_GITLAB_AUTH_CLIENT_ID,
2115
2140
  TOKEN_EXPIRY_SKEW_MS,
2116
2141
  VERSION,
2117
2142
  createGitLab,