@iamtoricool/opencool-qwen-auth 0.1.3-alpha → 0.2.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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -116
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.d.ts +1 -2
- package/dist/lib/auth/auth.d.ts.map +1 -1
- package/dist/lib/auth/auth.js +2 -4
- package/dist/lib/auth/auth.js.map +1 -1
- package/dist/lib/constants.d.ts +11 -33
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +24 -46
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/request/fetch-helpers.d.ts +7 -4
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
- package/dist/lib/request/fetch-helpers.js +24 -29
- package/dist/lib/request/fetch-helpers.js.map +1 -1
- package/dist/lib/request/response-handler.d.ts.map +1 -1
- package/dist/lib/request/response-handler.js +21 -0
- package/dist/lib/request/response-handler.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,qBAAqB,CAAC;AAqB/D;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAuF5B,CAAC;AAEF,eAAe,cAAc,CAAC;AAE9B,YAAY,EACV,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,95 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Qwen AI Authentication Plugin for opencode
|
|
3
|
-
* Uses
|
|
3
|
+
* Uses Alibaba Cloud Coding Plan API Key authentication
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import { QWEN_BASE_URL, DUMMY_API_KEY, LOG_STAGES, PLUGIN_NAME, PROVIDER_ID, QWEN_OAUTH_DEVICE_CODE_ENDPOINT, QWEN_OAUTH_TOKEN_ENDPOINT, QWEN_OAUTH_CLIENT_ID, QWEN_OAUTH_SCOPE, } from "./lib/constants.js";
|
|
5
|
+
import { QWEN_BASE_URL, LOG_STAGES, PLUGIN_NAME, PROVIDER_ID, AUTH_LABELS, } from "./lib/constants.js";
|
|
7
6
|
import { loadPluginConfig, parseUserConfig, initLogger } from "./lib/config.js";
|
|
8
7
|
import { logRequest, logDebug } from "./lib/logger.js";
|
|
9
8
|
import { createQwenHeaders, extractRequestUrl, handleErrorResponse, handleSuccessResponse, rewriteUrlForQwen, transformRequestForQwen, } from "./lib/request/fetch-helpers.js";
|
|
10
|
-
/**
|
|
11
|
-
* Generate PKCE code verifier
|
|
12
|
-
*/
|
|
13
|
-
function generateCodeVerifier() {
|
|
14
|
-
return randomBytes(32).toString("base64url").slice(0, 43);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Generate PKCE code challenge from verifier
|
|
18
|
-
*/
|
|
19
|
-
async function generateCodeChallenge(verifier) {
|
|
20
|
-
const encoder = new TextEncoder();
|
|
21
|
-
const data = encoder.encode(verifier);
|
|
22
|
-
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
23
|
-
return btoa(String.fromCharCode(...new Uint8Array(hash)))
|
|
24
|
-
.replace(/\+/g, "-")
|
|
25
|
-
.replace(/\//g, "_")
|
|
26
|
-
.replace(/=/g, "");
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Initiate device authorization flow
|
|
30
|
-
*/
|
|
31
|
-
async function initiateDeviceAuth() {
|
|
32
|
-
const codeVerifier = generateCodeVerifier();
|
|
33
|
-
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
34
|
-
const response = await fetch(QWEN_OAUTH_DEVICE_CODE_ENDPOINT, {
|
|
35
|
-
method: "POST",
|
|
36
|
-
headers: {
|
|
37
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
38
|
-
Accept: "application/json",
|
|
39
|
-
},
|
|
40
|
-
body: new URLSearchParams({
|
|
41
|
-
client_id: QWEN_OAUTH_CLIENT_ID,
|
|
42
|
-
scope: QWEN_OAUTH_SCOPE,
|
|
43
|
-
code_challenge: codeChallenge,
|
|
44
|
-
code_challenge_method: "S256",
|
|
45
|
-
}),
|
|
46
|
-
});
|
|
47
|
-
if (!response.ok) {
|
|
48
|
-
const err = await response.text();
|
|
49
|
-
throw new Error(`OAuth initiation failed: ${err}`);
|
|
50
|
-
}
|
|
51
|
-
const data = await response.json();
|
|
52
|
-
return { ...data, code_verifier: codeVerifier };
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Poll for access token
|
|
56
|
-
*/
|
|
57
|
-
async function pollForToken(deviceCode, codeVerifier, interval, maxAttempts = 120) {
|
|
58
|
-
let attempts = 0;
|
|
59
|
-
const pollInterval = Math.max(1, interval || 5); // Default 5 seconds if interval is invalid
|
|
60
|
-
while (attempts < maxAttempts) {
|
|
61
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval * 1000));
|
|
62
|
-
attempts++;
|
|
63
|
-
const response = await fetch(QWEN_OAUTH_TOKEN_ENDPOINT, {
|
|
64
|
-
method: "POST",
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
67
|
-
Accept: "application/json",
|
|
68
|
-
},
|
|
69
|
-
body: new URLSearchParams({
|
|
70
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
71
|
-
client_id: QWEN_OAUTH_CLIENT_ID,
|
|
72
|
-
device_code: deviceCode,
|
|
73
|
-
code_verifier: codeVerifier,
|
|
74
|
-
}),
|
|
75
|
-
});
|
|
76
|
-
const data = await response.json();
|
|
77
|
-
if (data.access_token) {
|
|
78
|
-
return {
|
|
79
|
-
access_token: data.access_token,
|
|
80
|
-
refresh_token: data.refresh_token,
|
|
81
|
-
expires_in: data.expires_in || 86400,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
if (data.error === "expired_token") {
|
|
85
|
-
throw new Error("Device code expired. Please try again.");
|
|
86
|
-
}
|
|
87
|
-
if (data.error && data.error !== "authorization_pending") {
|
|
88
|
-
throw new Error(`OAuth error: ${data.error_description || data.error}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
throw new Error("Authentication timed out. Please try again.");
|
|
92
|
-
}
|
|
93
9
|
/**
|
|
94
10
|
* Qwen AI Authentication Plugin
|
|
95
11
|
*/
|
|
@@ -101,24 +17,23 @@ export const QwenAuthPlugin = async ({ client }) => {
|
|
|
101
17
|
provider: PROVIDER_ID,
|
|
102
18
|
async loader(getAuth, provider) {
|
|
103
19
|
const auth = await getAuth();
|
|
104
|
-
if (auth.type !== "
|
|
20
|
+
if (auth.type !== "api") {
|
|
21
|
+
logDebug(`[${PLUGIN_NAME}] No API key configured`);
|
|
105
22
|
return {};
|
|
106
23
|
}
|
|
107
|
-
logDebug(`[${PLUGIN_NAME}] Using
|
|
24
|
+
logDebug(`[${PLUGIN_NAME}] Using API key authentication`);
|
|
108
25
|
const userConfig = parseUserConfig(provider);
|
|
109
26
|
return {
|
|
110
|
-
apiKey:
|
|
27
|
+
apiKey: auth.key,
|
|
111
28
|
baseURL: QWEN_BASE_URL,
|
|
112
29
|
async fetch(input, init) {
|
|
113
|
-
const currentAuth = await getAuth();
|
|
114
30
|
const originalUrl = extractRequestUrl(input);
|
|
115
31
|
const url = rewriteUrlForQwen(originalUrl);
|
|
116
|
-
const originalBody = init?.body ? JSON.parse(init
|
|
32
|
+
const originalBody = init?.body ? JSON.parse(init) : {};
|
|
117
33
|
const isStreaming = originalBody.stream === true;
|
|
118
34
|
const transformation = await transformRequestForQwen(init, url, userConfig);
|
|
119
35
|
const requestInit = transformation?.updatedInit ?? init;
|
|
120
|
-
const
|
|
121
|
-
const headers = createQwenHeaders(requestInit, accessToken);
|
|
36
|
+
const headers = createQwenHeaders(requestInit, auth.key);
|
|
122
37
|
logDebug(`[${PLUGIN_NAME}] Request to:`, url);
|
|
123
38
|
const response = await fetch(url, { ...requestInit, headers });
|
|
124
39
|
logRequest(LOG_STAGES.RESPONSE, {
|
|
@@ -134,32 +49,33 @@ export const QwenAuthPlugin = async ({ client }) => {
|
|
|
134
49
|
},
|
|
135
50
|
methods: [
|
|
136
51
|
{
|
|
137
|
-
label:
|
|
138
|
-
type: "
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
const token = await pollForToken(deviceAuth.device_code, deviceAuth.code_verifier, deviceAuth.interval);
|
|
150
|
-
console.log(`[${PLUGIN_NAME}] Authentication successful!`);
|
|
151
|
-
return {
|
|
152
|
-
type: "success",
|
|
153
|
-
access: token.access_token,
|
|
154
|
-
refresh: token.refresh_token || token.access_token,
|
|
155
|
-
expires: Date.now() + token.expires_in * 1000,
|
|
156
|
-
};
|
|
52
|
+
label: AUTH_LABELS.CODING_PLAN,
|
|
53
|
+
type: "api",
|
|
54
|
+
prompts: [
|
|
55
|
+
{
|
|
56
|
+
type: "text",
|
|
57
|
+
key: "apiKey",
|
|
58
|
+
message: "Enter your Alibaba Cloud Coding Plan API Key:",
|
|
59
|
+
placeholder: "sk-sp-xxxxxxxxx",
|
|
60
|
+
validate: (value) => {
|
|
61
|
+
if (!value || value.trim().length === 0) {
|
|
62
|
+
return "API key is required";
|
|
157
63
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return { type: "failed" };
|
|
64
|
+
if (!value.startsWith("sk-sp-")) {
|
|
65
|
+
return "Invalid API key format. Should start with 'sk-sp-'";
|
|
161
66
|
}
|
|
67
|
+
return undefined;
|
|
162
68
|
},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
authorize: async (inputs) => {
|
|
72
|
+
const apiKey = inputs?.apiKey;
|
|
73
|
+
if (!apiKey) {
|
|
74
|
+
return { type: "failed" };
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
type: "success",
|
|
78
|
+
key: apiKey,
|
|
163
79
|
};
|
|
164
80
|
},
|
|
165
81
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AAGxC;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAW,KAAK,EAAE,EAAE,MAAM,EAAe,EAAE,EAAE;IACtE,MAAM,YAAY,GAAG,gBAAgB,EAAE,CAAC;IACxC,UAAU,CAAC,YAAY,CAAC,CAAC;IAEzB,OAAO;QACL,IAAI,EAAE;YACJ,QAAQ,EAAE,WAAW;YAErB,KAAK,CAAC,MAAM,CAAC,OAA4B,EAAE,QAAiB;gBAC1D,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE,CAAC;gBA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2
|
+
* JWT authentication utilities
|
|
3
3
|
*/
|
|
4
4
|
import type { JWTPayload } from "../types.js";
|
|
5
5
|
/**
|
|
@@ -8,5 +8,4 @@ import type { JWTPayload } from "../types.js";
|
|
|
8
8
|
* @returns Decoded payload or null if invalid
|
|
9
9
|
*/
|
|
10
10
|
export declare function decodeJWT(token: string): JWTPayload | null;
|
|
11
|
-
export { extractBrowserSession, isBrowserSessionAvailable, getBrowserSessionInstructions, findFirefoxCookiePath, } from "./browser-session.js";
|
|
12
11
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../lib/auth/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../lib/auth/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAc1D"}
|
package/dist/lib/auth/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* JWT authentication utilities
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
5
|
* Decode a JWT token to extract payload (without verification)
|
|
@@ -13,7 +13,7 @@ export function decodeJWT(token) {
|
|
|
13
13
|
return null;
|
|
14
14
|
const payload = parts[1];
|
|
15
15
|
const padding = 4 - (payload.length % 4);
|
|
16
|
-
const paddedPayload = padding === 4 ? payload :
|
|
16
|
+
const paddedPayload = padding === 4 ? payload : "=".repeat(padding);
|
|
17
17
|
const decoded = Buffer.from(paddedPayload, "base64").toString("utf-8");
|
|
18
18
|
return JSON.parse(decoded);
|
|
19
19
|
}
|
|
@@ -21,6 +21,4 @@ export function decodeJWT(token) {
|
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
// Re-export browser session functions
|
|
25
|
-
export { extractBrowserSession, isBrowserSessionAvailable, getBrowserSessionInstructions, findFirefoxCookiePath, } from "./browser-session.js";
|
|
26
24
|
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../lib/auth/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../lib/auth/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAEpC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,aAAa,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEpE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAe,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -4,22 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Plugin identifier for logging and error messages */
|
|
6
6
|
export declare const PLUGIN_NAME = "opencool-qwen-auth";
|
|
7
|
-
/** Base URL for
|
|
8
|
-
export declare const QWEN_BASE_URL = "https://
|
|
9
|
-
/** Dummy API key used for Qwen SDK (actual auth via OAuth) */
|
|
10
|
-
export declare const DUMMY_API_KEY = "qwen-oauth";
|
|
7
|
+
/** Base URL for Alibaba Cloud Coding Plan API */
|
|
8
|
+
export declare const QWEN_BASE_URL = "https://coding.dashscope.aliyuncs.com/v1";
|
|
11
9
|
/** Provider ID for opencode configuration */
|
|
12
10
|
export declare const PROVIDER_ID = "qwen";
|
|
13
|
-
/** Qwen OAuth Constants (from @opencode-qwen-auth/) */
|
|
14
|
-
export declare const QWEN_OAUTH_BASE_URL = "https://chat.qwen.ai";
|
|
15
|
-
export declare const QWEN_OAUTH_DEVICE_CODE_ENDPOINT = "https://chat.qwen.ai/api/v1/oauth2/device/code";
|
|
16
|
-
export declare const QWEN_OAUTH_TOKEN_ENDPOINT = "https://chat.qwen.ai/api/v1/oauth2/token";
|
|
17
|
-
export declare const QWEN_OAUTH_CLIENT_ID = "f0304373b74a44d2b584a3fb70ca9e56";
|
|
18
|
-
export declare const QWEN_OAUTH_SCOPE = "openid profile email model.completion";
|
|
19
|
-
/** OAuth redirect URI for local callback */
|
|
20
|
-
export declare const REDIRECT_URI = "http://localhost:1455/auth/callback";
|
|
21
|
-
/** OAuth scope for Google */
|
|
22
|
-
export declare const GOOGLE_SCOPE = "openid email profile";
|
|
23
11
|
/** HTTP Status Codes */
|
|
24
12
|
export declare const HTTP_STATUS: {
|
|
25
13
|
readonly OK: 200;
|
|
@@ -35,19 +23,16 @@ export declare const QWEN_HEADERS: {
|
|
|
35
23
|
};
|
|
36
24
|
/** URL path segments */
|
|
37
25
|
export declare const URL_PATHS: {
|
|
38
|
-
readonly CHAT_COMPLETIONS: "/
|
|
26
|
+
readonly CHAT_COMPLETIONS: "/chat/completions";
|
|
39
27
|
readonly MODELS: "/models";
|
|
40
|
-
readonly AUTHS: "/v1/auths";
|
|
41
28
|
};
|
|
42
29
|
/** Error messages */
|
|
43
30
|
export declare const ERROR_MESSAGES: {
|
|
44
31
|
readonly NO_ACCOUNT_ID: "Failed to extract account info from token";
|
|
45
32
|
readonly TOKEN_REFRESH_FAILED: "Failed to refresh token, authentication required";
|
|
46
33
|
readonly REQUEST_PARSE_ERROR: "Error parsing request";
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
49
|
-
readonly MISSING_TOKEN: "Missing token";
|
|
50
|
-
readonly TOKEN_NOT_FOUND: "Token not found in URL fragment";
|
|
34
|
+
readonly MISSING_API_KEY: "API key is required. Please subscribe to Alibaba Cloud Coding Plan.";
|
|
35
|
+
readonly INVALID_API_KEY: "Invalid API key. Please check your Coding Plan API key.";
|
|
51
36
|
};
|
|
52
37
|
/** Log stages for request logging */
|
|
53
38
|
export declare const LOG_STAGES: {
|
|
@@ -56,21 +41,14 @@ export declare const LOG_STAGES: {
|
|
|
56
41
|
readonly RESPONSE: "response";
|
|
57
42
|
readonly ERROR_RESPONSE: "error-response";
|
|
58
43
|
};
|
|
59
|
-
/**
|
|
60
|
-
export declare const PLATFORM_OPENERS: {
|
|
61
|
-
readonly darwin: "open";
|
|
62
|
-
readonly win32: "start";
|
|
63
|
-
readonly linux: "xdg-open";
|
|
64
|
-
};
|
|
65
|
-
/** OAuth authorization labels */
|
|
44
|
+
/** Authentication labels */
|
|
66
45
|
export declare const AUTH_LABELS: {
|
|
67
|
-
readonly
|
|
68
|
-
readonly
|
|
69
|
-
readonly
|
|
70
|
-
readonly
|
|
71
|
-
readonly INSTRUCTIONS_MANUAL: "After logging in, copy the token from the URL and paste it here.";
|
|
46
|
+
readonly CODING_PLAN: "Alibaba Cloud Coding Plan";
|
|
47
|
+
readonly API_KEY: "Enter Coding Plan API Key";
|
|
48
|
+
readonly INSTRUCTIONS: "Subscribe to Alibaba Cloud Coding Plan and enter your API key (sk-sp-xxxxxxxxx).";
|
|
49
|
+
readonly SETUP_URL: "https://modelstudio.console.alibabacloud.com/?tab=coding-plan";
|
|
72
50
|
};
|
|
73
|
-
/** Qwen model definitions */
|
|
51
|
+
/** Qwen model definitions for Coding Plan */
|
|
74
52
|
export declare const QWEN_MODELS: Record<string, QwenModel>;
|
|
75
53
|
import type { QwenModel } from "./types.js";
|
|
76
54
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uDAAuD;AACvD,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAEhD,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uDAAuD;AACvD,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAEhD,iDAAiD;AACjD,eAAO,MAAM,aAAa,6CAA6C,CAAC;AAExE,6CAA6C;AAC7C,eAAO,MAAM,WAAW,SAAS,CAAC;AAElC,wBAAwB;AACxB,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAEX,4BAA4B;AAC5B,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,wBAAwB;AACxB,eAAO,MAAM,SAAS;;;CAGZ,CAAC;AAEX,qBAAqB;AACrB,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAEX,qCAAqC;AACrC,eAAO,MAAM,UAAU;;;;;CAKb,CAAC;AAEX,4BAA4B;AAC5B,eAAO,MAAM,WAAW;;;;;CAMd,CAAC;AAEX,6CAA6C;AAC7C,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAiCxC,CAAC;AAGX,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/lib/constants.js
CHANGED
|
@@ -4,22 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Plugin identifier for logging and error messages */
|
|
6
6
|
export const PLUGIN_NAME = "opencool-qwen-auth";
|
|
7
|
-
/** Base URL for
|
|
8
|
-
export const QWEN_BASE_URL = "https://
|
|
9
|
-
/** Dummy API key used for Qwen SDK (actual auth via OAuth) */
|
|
10
|
-
export const DUMMY_API_KEY = "qwen-oauth";
|
|
7
|
+
/** Base URL for Alibaba Cloud Coding Plan API */
|
|
8
|
+
export const QWEN_BASE_URL = "https://coding.dashscope.aliyuncs.com/v1";
|
|
11
9
|
/** Provider ID for opencode configuration */
|
|
12
10
|
export const PROVIDER_ID = "qwen";
|
|
13
|
-
/** Qwen OAuth Constants (from @opencode-qwen-auth/) */
|
|
14
|
-
export const QWEN_OAUTH_BASE_URL = "https://chat.qwen.ai";
|
|
15
|
-
export const QWEN_OAUTH_DEVICE_CODE_ENDPOINT = `${QWEN_OAUTH_BASE_URL}/api/v1/oauth2/device/code`;
|
|
16
|
-
export const QWEN_OAUTH_TOKEN_ENDPOINT = `${QWEN_OAUTH_BASE_URL}/api/v1/oauth2/token`;
|
|
17
|
-
export const QWEN_OAUTH_CLIENT_ID = "f0304373b74a44d2b584a3fb70ca9e56";
|
|
18
|
-
export const QWEN_OAUTH_SCOPE = "openid profile email model.completion";
|
|
19
|
-
/** OAuth redirect URI for local callback */
|
|
20
|
-
export const REDIRECT_URI = "http://localhost:1455/auth/callback";
|
|
21
|
-
/** OAuth scope for Google */
|
|
22
|
-
export const GOOGLE_SCOPE = "openid email profile";
|
|
23
11
|
/** HTTP Status Codes */
|
|
24
12
|
export const HTTP_STATUS = {
|
|
25
13
|
OK: 200,
|
|
@@ -35,19 +23,16 @@ export const QWEN_HEADERS = {
|
|
|
35
23
|
};
|
|
36
24
|
/** URL path segments */
|
|
37
25
|
export const URL_PATHS = {
|
|
38
|
-
CHAT_COMPLETIONS: "/
|
|
26
|
+
CHAT_COMPLETIONS: "/chat/completions",
|
|
39
27
|
MODELS: "/models",
|
|
40
|
-
AUTHS: "/v1/auths",
|
|
41
28
|
};
|
|
42
29
|
/** Error messages */
|
|
43
30
|
export const ERROR_MESSAGES = {
|
|
44
31
|
NO_ACCOUNT_ID: "Failed to extract account info from token",
|
|
45
32
|
TOKEN_REFRESH_FAILED: "Failed to refresh token, authentication required",
|
|
46
33
|
REQUEST_PARSE_ERROR: "Error parsing request",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
MISSING_TOKEN: "Missing token",
|
|
50
|
-
TOKEN_NOT_FOUND: "Token not found in URL fragment",
|
|
34
|
+
MISSING_API_KEY: "API key is required. Please subscribe to Alibaba Cloud Coding Plan.",
|
|
35
|
+
INVALID_API_KEY: "Invalid API key. Please check your Coding Plan API key.",
|
|
51
36
|
};
|
|
52
37
|
/** Log stages for request logging */
|
|
53
38
|
export const LOG_STAGES = {
|
|
@@ -56,28 +41,21 @@ export const LOG_STAGES = {
|
|
|
56
41
|
RESPONSE: "response",
|
|
57
42
|
ERROR_RESPONSE: "error-response",
|
|
58
43
|
};
|
|
59
|
-
/**
|
|
60
|
-
export const PLATFORM_OPENERS = {
|
|
61
|
-
darwin: "open",
|
|
62
|
-
win32: "start",
|
|
63
|
-
linux: "xdg-open",
|
|
64
|
-
};
|
|
65
|
-
/** OAuth authorization labels */
|
|
44
|
+
/** Authentication labels */
|
|
66
45
|
export const AUTH_LABELS = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
INSTRUCTIONS_MANUAL: "After logging in, copy the token from the URL and paste it here.",
|
|
46
|
+
CODING_PLAN: "Alibaba Cloud Coding Plan",
|
|
47
|
+
API_KEY: "Enter Coding Plan API Key",
|
|
48
|
+
INSTRUCTIONS: "Subscribe to Alibaba Cloud Coding Plan and enter your API key (sk-sp-xxxxxxxxx).",
|
|
49
|
+
SETUP_URL: "https://modelstudio.console.alibabacloud.com/?tab=coding-plan",
|
|
72
50
|
};
|
|
73
|
-
/** Qwen model definitions */
|
|
51
|
+
/** Qwen model definitions for Coding Plan */
|
|
74
52
|
export const QWEN_MODELS = {
|
|
75
|
-
"qwen3-
|
|
76
|
-
id: "qwen3-
|
|
77
|
-
name: "Qwen3
|
|
78
|
-
description: "
|
|
53
|
+
"qwen3.5-plus": {
|
|
54
|
+
id: "qwen3.5-plus",
|
|
55
|
+
name: "Qwen3.5 Plus",
|
|
56
|
+
description: "Latest Qwen3.5 model with advanced capabilities",
|
|
79
57
|
maxTokens: 32768,
|
|
80
|
-
supportsVision:
|
|
58
|
+
supportsVision: true,
|
|
81
59
|
supportsCode: true,
|
|
82
60
|
},
|
|
83
61
|
"qwen3-coder-plus": {
|
|
@@ -88,6 +66,14 @@ export const QWEN_MODELS = {
|
|
|
88
66
|
supportsVision: false,
|
|
89
67
|
supportsCode: true,
|
|
90
68
|
},
|
|
69
|
+
"qwen3-max": {
|
|
70
|
+
id: "qwen3-max",
|
|
71
|
+
name: "Qwen3 Max",
|
|
72
|
+
description: "Most capable Qwen3 model for complex tasks",
|
|
73
|
+
maxTokens: 32768,
|
|
74
|
+
supportsVision: false,
|
|
75
|
+
supportsCode: true,
|
|
76
|
+
},
|
|
91
77
|
"qwen3-vl-plus": {
|
|
92
78
|
id: "qwen3-vl-plus",
|
|
93
79
|
name: "Qwen3 VL Plus",
|
|
@@ -96,13 +82,5 @@ export const QWEN_MODELS = {
|
|
|
96
82
|
supportsVision: true,
|
|
97
83
|
supportsCode: false,
|
|
98
84
|
},
|
|
99
|
-
"qwen3-235b-a22b": {
|
|
100
|
-
id: "qwen3-235b-a22b",
|
|
101
|
-
name: "Qwen3 235B A22B",
|
|
102
|
-
description: "Large mixture-of-experts model",
|
|
103
|
-
maxTokens: 32768,
|
|
104
|
-
supportsVision: false,
|
|
105
|
-
supportsCode: true,
|
|
106
|
-
},
|
|
107
85
|
};
|
|
108
86
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uDAAuD;AACvD,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAoB,CAA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D;CAClE,CAAC;AAEX,6CAA6C;AAC7C,MAAM,CAAC,MAAM,WAAW,GAA8B;IACpD,cAAc,EAAE;QACd,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,iDAAiD;QAC9D,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,IAAI;KACnB;IACD,kBAAkB,EAAE;QAClB,EAAE,EAAE,kBAAkB;QACtB,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,qDAAqD;QAClE,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,KAAK;QACrB,YAAY,EAAE,IAAI;KACnB;IACD,WAAW,EAAE;QACX,EAAE,EAAE,WAAW;QACf,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,4CAA4C;QACzD,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,KAAK;QACrB,YAAY,EAAE,IAAI;KACnB;IACD,eAAe,EAAE;QACf,EAAE,EAAE,eAAe;QACnB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,+CAA+C;QAC5D,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,KAAK;KACpB;CACO,CAAC"}
|
|
@@ -7,14 +7,16 @@ import type { OpencodeClient } from "@opencode-ai/sdk";
|
|
|
7
7
|
import type { UserConfig, RequestBody } from "../types.js";
|
|
8
8
|
/**
|
|
9
9
|
* Determines if the current auth token needs to be refreshed
|
|
10
|
+
* For API key auth, this always returns false as API keys don't expire
|
|
10
11
|
* @param auth - Current authentication state
|
|
11
12
|
* @returns True if token is expired or invalid
|
|
12
13
|
*/
|
|
13
14
|
export declare function shouldRefreshToken(auth: Auth): boolean;
|
|
14
15
|
/**
|
|
15
|
-
* Refreshes the
|
|
16
|
+
* Refreshes the API token and updates stored credentials
|
|
17
|
+
* For API key auth, this is a no-op as API keys don't refresh
|
|
16
18
|
* @param currentAuth - Current auth state
|
|
17
|
-
* @param
|
|
19
|
+
* @param _client - Opencode client for updating stored credentials
|
|
18
20
|
* @returns Updated auth (throws on failure)
|
|
19
21
|
*/
|
|
20
22
|
export declare function refreshAndUpdateToken(currentAuth: Auth, _client: OpencodeClient): Promise<Auth>;
|
|
@@ -26,6 +28,7 @@ export declare function refreshAndUpdateToken(currentAuth: Auth, _client: Openco
|
|
|
26
28
|
export declare function extractRequestUrl(input: Request | string | URL): string;
|
|
27
29
|
/**
|
|
28
30
|
* Rewrites OpenAI-compatible API URLs to Qwen backend URLs
|
|
31
|
+
* For Coding Plan, we keep the standard OpenAI path format
|
|
29
32
|
* @param url - Original URL
|
|
30
33
|
* @returns Rewritten URL for Qwen backend
|
|
31
34
|
*/
|
|
@@ -44,10 +47,10 @@ export declare function transformRequestForQwen(init: RequestInit | undefined, u
|
|
|
44
47
|
/**
|
|
45
48
|
* Creates headers for Qwen API requests
|
|
46
49
|
* @param init - Request init options
|
|
47
|
-
* @param
|
|
50
|
+
* @param apiKey - Coding Plan API key
|
|
48
51
|
* @returns Headers object with all required Qwen headers
|
|
49
52
|
*/
|
|
50
|
-
export declare function createQwenHeaders(init: RequestInit | undefined,
|
|
53
|
+
export declare function createQwenHeaders(init: RequestInit | undefined, apiKey: string): Headers;
|
|
51
54
|
/**
|
|
52
55
|
* Handles error responses from the Qwen API
|
|
53
56
|
* @param response - Error response from API
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-helpers.d.ts","sourceRoot":"","sources":["../../../lib/request/fetch-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-helpers.d.ts","sourceRoot":"","sources":["../../../lib/request/fetch-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAU3D;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAEtD;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,IAAI,EACjB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM,CAIvE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAerD;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CAAC,CA2CtE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAyBT;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,QAAQ,CAAC,CAkBnB;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,QAAQ,CAAC,CAcnB"}
|
|
@@ -2,39 +2,31 @@
|
|
|
2
2
|
* Helper functions for the custom fetch implementation
|
|
3
3
|
* These functions break down the complex fetch logic into manageable, testable units
|
|
4
4
|
*/
|
|
5
|
-
import { decodeJWT } from "../auth/auth.js";
|
|
6
5
|
import { logRequest, logDebug } from "../logger.js";
|
|
7
6
|
import { transformRequestBody, normalizeModel } from "./request-transformer.js";
|
|
8
7
|
import { convertSseToJson, ensureContentType } from "./response-handler.js";
|
|
9
8
|
import { PLUGIN_NAME, ERROR_MESSAGES, LOG_STAGES, } from "../constants.js";
|
|
10
9
|
/**
|
|
11
10
|
* Determines if the current auth token needs to be refreshed
|
|
11
|
+
* For API key auth, this always returns false as API keys don't expire
|
|
12
12
|
* @param auth - Current authentication state
|
|
13
13
|
* @returns True if token is expired or invalid
|
|
14
14
|
*/
|
|
15
15
|
export function shouldRefreshToken(auth) {
|
|
16
|
-
return auth.type !== "
|
|
16
|
+
return auth.type !== "api" || !auth.key;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Refreshes the
|
|
19
|
+
* Refreshes the API token and updates stored credentials
|
|
20
|
+
* For API key auth, this is a no-op as API keys don't refresh
|
|
20
21
|
* @param currentAuth - Current auth state
|
|
21
|
-
* @param
|
|
22
|
+
* @param _client - Opencode client for updating stored credentials
|
|
22
23
|
* @returns Updated auth (throws on failure)
|
|
23
24
|
*/
|
|
24
25
|
export async function refreshAndUpdateToken(currentAuth, _client) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const decoded = decodeJWT(currentAuth.access);
|
|
28
|
-
if (decoded?.exp && typeof decoded.exp === "number") {
|
|
29
|
-
const expiresAt = decoded.exp * 1000;
|
|
30
|
-
if (expiresAt > Date.now()) {
|
|
31
|
-
// Token still valid, update expires
|
|
32
|
-
currentAuth.expires = expiresAt;
|
|
33
|
-
return currentAuth;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
26
|
+
if (currentAuth.type === "api" && currentAuth.key) {
|
|
27
|
+
return currentAuth;
|
|
36
28
|
}
|
|
37
|
-
throw new Error(ERROR_MESSAGES.
|
|
29
|
+
throw new Error(ERROR_MESSAGES.INVALID_API_KEY);
|
|
38
30
|
}
|
|
39
31
|
/**
|
|
40
32
|
* Extracts URL string from various request input types
|
|
@@ -50,20 +42,20 @@ export function extractRequestUrl(input) {
|
|
|
50
42
|
}
|
|
51
43
|
/**
|
|
52
44
|
* Rewrites OpenAI-compatible API URLs to Qwen backend URLs
|
|
45
|
+
* For Coding Plan, we keep the standard OpenAI path format
|
|
53
46
|
* @param url - Original URL
|
|
54
47
|
* @returns Rewritten URL for Qwen backend
|
|
55
48
|
*/
|
|
56
49
|
export function rewriteUrlForQwen(url) {
|
|
57
50
|
// Parse the original URL
|
|
58
51
|
const parsedUrl = new URL(url);
|
|
59
|
-
//
|
|
60
|
-
parsedUrl.host = "
|
|
52
|
+
// Use the Coding Plan endpoint
|
|
53
|
+
parsedUrl.host = "coding.dashscope.aliyuncs.com";
|
|
61
54
|
parsedUrl.protocol = "https:";
|
|
62
55
|
parsedUrl.port = "";
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
parsedUrl.pathname = `/api${parsedUrl.pathname}`;
|
|
56
|
+
// Ensure /v1 prefix is present for Coding Plan API
|
|
57
|
+
if (!parsedUrl.pathname.startsWith("/v1")) {
|
|
58
|
+
parsedUrl.pathname = `/v1${parsedUrl.pathname}`;
|
|
67
59
|
}
|
|
68
60
|
return parsedUrl.toString();
|
|
69
61
|
}
|
|
@@ -117,16 +109,13 @@ export async function transformRequestForQwen(init, url, userConfig) {
|
|
|
117
109
|
/**
|
|
118
110
|
* Creates headers for Qwen API requests
|
|
119
111
|
* @param init - Request init options
|
|
120
|
-
* @param
|
|
112
|
+
* @param apiKey - Coding Plan API key
|
|
121
113
|
* @returns Headers object with all required Qwen headers
|
|
122
114
|
*/
|
|
123
|
-
export function createQwenHeaders(init,
|
|
115
|
+
export function createQwenHeaders(init, apiKey) {
|
|
124
116
|
const headers = new Headers(init?.headers ?? {});
|
|
125
|
-
//
|
|
126
|
-
headers.
|
|
127
|
-
headers.delete("X-Api-Key");
|
|
128
|
-
// Set Authorization with OAuth token
|
|
129
|
-
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
117
|
+
// Set Authorization with API key
|
|
118
|
+
headers.set("Authorization", `Bearer ${apiKey}`);
|
|
130
119
|
// Set content type if not already set
|
|
131
120
|
if (!headers.has("Content-Type")) {
|
|
132
121
|
headers.set("Content-Type", "application/json");
|
|
@@ -136,6 +125,12 @@ export function createQwenHeaders(init, accessToken) {
|
|
|
136
125
|
if (!acceptValue || acceptValue === "*/*") {
|
|
137
126
|
headers.set("Accept", "text/event-stream, application/json");
|
|
138
127
|
}
|
|
128
|
+
// Set DashScope-specific headers
|
|
129
|
+
const version = "0.1.4";
|
|
130
|
+
const userAgent = `opencool-qwen-auth/${version}`;
|
|
131
|
+
headers.set("X-DashScope-AuthType", "coding-plan");
|
|
132
|
+
headers.set("X-DashScope-UserAgent", userAgent);
|
|
133
|
+
headers.set("User-Agent", userAgent);
|
|
139
134
|
return headers;
|
|
140
135
|
}
|
|
141
136
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-helpers.js","sourceRoot":"","sources":["../../../lib/request/fetch-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fetch-helpers.js","sourceRoot":"","sources":["../../../lib/request/fetch-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EACL,WAAW,EAIX,cAAc,EACd,UAAU,GACX,MAAM,iBAAiB,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAU;IAC3C,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAA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,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,qBAAqB;IACvB,CAAC;IAED,QAAQ,CAAC,sBAAsB,EAAE,SAAS,CAAC,CAAC;IAE5C,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,QAAkB,EAClB,WAAoB;IAEpB,MAAM,eAAe,GAAG,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE5D,kDAAkD;IAClD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,MAAM,gBAAgB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC3D,CAAC;IAED,8CAA8C;IAC9C,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;QACjC,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,OAAO,EAAE,eAAe;KACzB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../../lib/request/response-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAwBhD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAe3D;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,YAAY,EAAE,GACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2EzB;
|
|
1
|
+
{"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../../lib/request/response-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAwBhD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAe3D;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,YAAY,EAAE,GACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2EzB;AA6BD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CAsCnB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,OAAO,GAAG,OAAO,CASnE"}
|
|
@@ -129,6 +129,15 @@ function mapStopReason(stopReason) {
|
|
|
129
129
|
};
|
|
130
130
|
return reasonMap[stopReason] || stopReason;
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if response is SSE format
|
|
134
|
+
* @param text - Response text
|
|
135
|
+
* @returns True if text appears to be SSE format
|
|
136
|
+
*/
|
|
137
|
+
function isSseFormat(text) {
|
|
138
|
+
// SSE format typically contains lines starting with "data: "
|
|
139
|
+
return text.includes("data: ");
|
|
140
|
+
}
|
|
132
141
|
/**
|
|
133
142
|
* Convert SSE response to JSON response for non-streaming requests
|
|
134
143
|
* @param response - Original SSE response
|
|
@@ -138,6 +147,18 @@ function mapStopReason(stopReason) {
|
|
|
138
147
|
export async function convertSseToJson(response, headers) {
|
|
139
148
|
try {
|
|
140
149
|
const text = await response.text();
|
|
150
|
+
// Check if response is actually SSE format
|
|
151
|
+
if (!isSseFormat(text)) {
|
|
152
|
+
// Not SSE, return original response with proper headers
|
|
153
|
+
return new Response(text, {
|
|
154
|
+
status: response.status,
|
|
155
|
+
statusText: response.statusText,
|
|
156
|
+
headers: {
|
|
157
|
+
...Object.fromEntries(headers.entries()),
|
|
158
|
+
"Content-Type": "application/json",
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
141
162
|
const events = parseSseStream(text);
|
|
142
163
|
const completion = convertSseToChatCompletion(events);
|
|
143
164
|
// Create JSON response
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-handler.js","sourceRoot":"","sources":["../../../lib/request/response-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;GAIG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAE5C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,yBAAyB;IAEzD,0BAA0B;IAC1B,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAiB,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;YAAE,SAAS;QAExD,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAAsB;IAEtB,sCAAsC;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QAEtD,uBAAuB;QACvB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAC9C,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE;gBACP,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACxC,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gDAAgD;QAChD,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACvD,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;YACjC,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO;SACR,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,eAAwB;IACxD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IAE7C,gCAAgC;IAChC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iamtoricool/opencool-qwen-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Qwen AI OAuth Authentication Plugin for opencode - Access Qwen models via chat.qwen.ai subscription",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
],
|
|
44
44
|
"author": "",
|
|
45
45
|
"license": "MIT"
|
|
46
|
-
}
|
|
46
|
+
}
|