magpie-junie-auth 0.2.4 → 0.2.5
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/index.mjs +11 -0
- package/lib/auth.mjs +3 -1
- package/lib/direct.mjs +5 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -151,6 +151,17 @@ export async function JuniePlugin(input, options = {}) {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
// 直连模式:用逆向的 Responses 协议(免费额度可用,无需 CLI 本体)。
|
|
154
|
+
// auth 可能为空(未登录/账号状态异常/轮换间隙),此时给出明确错误,
|
|
155
|
+
// 而不是让 `auth.access` 抛 TypeError 使整个 loader 崩掉。
|
|
156
|
+
if (!auth || (!auth.access && !auth.key)) {
|
|
157
|
+
return {
|
|
158
|
+
baseURL: "https://ingrazzio-cloud-prod.labs.jb.gg/v1",
|
|
159
|
+
apiKey: "",
|
|
160
|
+
fetch: async () => new Response(JSON.stringify({
|
|
161
|
+
error: { message: "Junie 尚未登录,请在 magpie 里添加/切换账号(magpie accounts junie)", type: "auth_error" },
|
|
162
|
+
}), { status: 401, headers: { "Content-Type": "application/json" } }),
|
|
163
|
+
}
|
|
164
|
+
}
|
|
154
165
|
return {
|
|
155
166
|
baseURL: "https://ingrazzio-cloud-prod.labs.jb.gg/v1",
|
|
156
167
|
apiKey: auth.access ?? auth.key,
|
package/lib/auth.mjs
CHANGED
|
@@ -50,8 +50,10 @@ export async function refreshAccessToken(auth) {
|
|
|
50
50
|
try {
|
|
51
51
|
const t = await exchangeToken({ grant_type: "refresh_token", refresh_token: auth.refresh })
|
|
52
52
|
// 上游 Bearer 用 id_token;access_token 只用于 userinfo
|
|
53
|
+
const access = t.id_token ?? t.access_token ?? auth.access
|
|
53
54
|
return {
|
|
54
|
-
access
|
|
55
|
+
access,
|
|
56
|
+
key: access, // magpie 续期后仍可能按 key 取 apiKey,保持同步
|
|
55
57
|
accessToken: t.access_token ?? auth.accessToken,
|
|
56
58
|
idToken: t.id_token ?? auth.idToken,
|
|
57
59
|
refresh: t.refresh_token ?? auth.refresh,
|
package/lib/direct.mjs
CHANGED
|
@@ -406,6 +406,11 @@ export function makeDirectFetch(auth, options = {}) {
|
|
|
406
406
|
const token = auth?.access ?? auth?.key
|
|
407
407
|
|
|
408
408
|
return async function directFetch(input, init = {}) {
|
|
409
|
+
if (!token) {
|
|
410
|
+
return new Response(JSON.stringify({
|
|
411
|
+
error: { message: "Junie 未登录:缺少 access token", type: "auth_error" },
|
|
412
|
+
}), { status: 401, headers: { "Content-Type": "application/json" } })
|
|
413
|
+
}
|
|
409
414
|
const url = new URL(String(input))
|
|
410
415
|
url.pathname = "/v1/responses"
|
|
411
416
|
url.search = ""
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magpie-junie-auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "magpie provider plugin: JetBrains Junie free tier (gpt-6-luna) via direct Responses API or CLI bridge; multi-account with browser PKCE / CLI login reuse",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|