opencode-codebuddy-external-auth 1.0.22 → 1.0.24
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/plugin.js +20 -6
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -8,8 +8,8 @@ const PROVIDER_ID = "codebuddy-external";
|
|
|
8
8
|
const CONFIG = {
|
|
9
9
|
// IOA 版本使用 copilot.tencent.com 进行认证
|
|
10
10
|
serverUrl: "https://copilot.tencent.com",
|
|
11
|
-
// 真实对话 API
|
|
12
|
-
|
|
11
|
+
// 真实对话 API 路径(优先尝试 /v2/chat/completions)
|
|
12
|
+
chatCompletionsPaths: ["/v2/chat/completions", "/v2/plugin/chat/completions"],
|
|
13
13
|
// 平台标识
|
|
14
14
|
platform: "CLI",
|
|
15
15
|
appVersion: "2.37.20",
|
|
@@ -542,21 +542,32 @@ async function executeViaAuthApi(openaiRequest, auth) {
|
|
|
542
542
|
response_format: openaiRequest.response_format || { type: "text" },
|
|
543
543
|
stream: openaiRequest.stream ?? true,
|
|
544
544
|
};
|
|
545
|
-
const doRequest = async (token) => {
|
|
545
|
+
const doRequest = async (token, path) => {
|
|
546
546
|
const headers = await buildAuthHeaders(token);
|
|
547
|
-
const response = await fetch(`${CONFIG.serverUrl}${
|
|
547
|
+
const response = await fetch(`${CONFIG.serverUrl}${path}`, {
|
|
548
548
|
method: "POST",
|
|
549
549
|
headers,
|
|
550
550
|
body: JSON.stringify(requestBody),
|
|
551
551
|
});
|
|
552
552
|
return response;
|
|
553
553
|
};
|
|
554
|
-
|
|
554
|
+
const requestWithFallback = async (token) => {
|
|
555
|
+
let lastResponse = null;
|
|
556
|
+
for (const path of CONFIG.chatCompletionsPaths) {
|
|
557
|
+
const response = await doRequest(token, path);
|
|
558
|
+
if (response.status !== 404) {
|
|
559
|
+
return response;
|
|
560
|
+
}
|
|
561
|
+
lastResponse = response;
|
|
562
|
+
}
|
|
563
|
+
return lastResponse || doRequest(token, CONFIG.chatCompletionsPaths[0]);
|
|
564
|
+
};
|
|
565
|
+
let response = await requestWithFallback(accessToken);
|
|
555
566
|
if ((response.status === 401 || response.status === 403) && auth.refresh) {
|
|
556
567
|
const refreshed = await refreshAccessToken(auth.refresh, accessToken);
|
|
557
568
|
if (refreshed?.accessToken) {
|
|
558
569
|
accessToken = refreshed.accessToken;
|
|
559
|
-
response = await
|
|
570
|
+
response = await requestWithFallback(accessToken);
|
|
560
571
|
}
|
|
561
572
|
}
|
|
562
573
|
if (!response.ok) {
|
|
@@ -853,6 +864,9 @@ const CodeBuddyExternalAuthPlugin = async (_input) => {
|
|
|
853
864
|
if (!tokenData) {
|
|
854
865
|
return { type: "failed" };
|
|
855
866
|
}
|
|
867
|
+
if (tokenData.userId && !cachedUserId) {
|
|
868
|
+
cachedUserId = tokenData.userId;
|
|
869
|
+
}
|
|
856
870
|
return {
|
|
857
871
|
type: "success",
|
|
858
872
|
access: tokenData.accessToken,
|