opencode-codebuddy-external-auth 1.0.15 → 1.0.16

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 (2) hide show
  1. package/dist/plugin.js +21 -3
  2. package/package.json +1 -1
package/dist/plugin.js CHANGED
@@ -24,6 +24,8 @@ const CONFIG = {
24
24
  tenantId: process.env.CODEBUDDY_TENANT_ID || "",
25
25
  enterpriseId: process.env.CODEBUDDY_ENTERPRISE_ID || "",
26
26
  userId: process.env.CODEBUDDY_USER_ID || "",
27
+ // 强制覆盖模型(避免 OpenCode 仍使用旧模型)
28
+ defaultModel: process.env.CODEBUDDY_DEFAULT_MODEL || "",
27
29
  };
28
30
  // ============================================================================
29
31
  // Utility Functions
@@ -57,6 +59,9 @@ function extractTenantIdFromIss(iss) {
57
59
  const match = iss.match(/realms\/sso-([^/]+)$/);
58
60
  return match?.[1] || "";
59
61
  }
62
+ let warnedTenantId = false;
63
+ let warnedEnterpriseId = false;
64
+ let warnedUserId = false;
60
65
  function resolveTenantId(accessToken) {
61
66
  if (CONFIG.tenantId)
62
67
  return CONFIG.tenantId;
@@ -81,17 +86,25 @@ function resolveUserId(accessToken) {
81
86
  const payload = decodeJwtPayload(accessToken);
82
87
  return payload?.user_id || payload?.userId || payload?.uid || payload?.sub || "";
83
88
  }
89
+ function resolveModel(inputModel) {
90
+ if (CONFIG.defaultModel)
91
+ return CONFIG.defaultModel;
92
+ return inputModel || "";
93
+ }
84
94
  function buildAuthHeaders(accessToken) {
85
95
  const tenantId = resolveTenantId(accessToken);
86
96
  const enterpriseId = resolveEnterpriseId(accessToken);
87
97
  const userId = resolveUserId(accessToken);
88
- if (!tenantId) {
98
+ if (!tenantId && !warnedTenantId) {
99
+ warnedTenantId = true;
89
100
  console.warn("[codebuddy-external] 未获取到 X-Tenant-Id,请设置 CODEBUDDY_TENANT_ID");
90
101
  }
91
- if (!enterpriseId) {
102
+ if (!enterpriseId && !warnedEnterpriseId) {
103
+ warnedEnterpriseId = true;
92
104
  console.warn("[codebuddy-external] 未获取到 X-Enterprise-Id,请设置 CODEBUDDY_ENTERPRISE_ID");
93
105
  }
94
- if (!userId) {
106
+ if (!userId && !warnedUserId) {
107
+ warnedUserId = true;
95
108
  console.warn("[codebuddy-external] 未获取到 X-User-Id,请设置 CODEBUDDY_USER_ID");
96
109
  }
97
110
  const conversationId = generateUuid();
@@ -330,8 +343,13 @@ async function executeViaAuthApi(openaiRequest, auth) {
330
343
  throw new Error("缺少 access token,无法调用 CodeBuddy API");
331
344
  }
332
345
  let accessToken = auth.access;
346
+ const resolvedModel = resolveModel(openaiRequest.model);
347
+ if (!resolvedModel) {
348
+ throw new Error("未设置模型,请设置 CODEBUDDY_DEFAULT_MODEL 或在 OpenCode 选择模型");
349
+ }
333
350
  const requestBody = {
334
351
  ...openaiRequest,
352
+ model: resolvedModel,
335
353
  response_format: openaiRequest.response_format || { type: "text" },
336
354
  stream: openaiRequest.stream ?? true,
337
355
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codebuddy-external-auth",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "OpenCode plugin for CodeBuddy External (IOA) authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",