@zgltyq/pi-provider-claude 1.3.1 → 1.3.2
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/README.md +6 -6
- package/oauth.ts +10 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,12 +91,12 @@ the assistant message (`stopReason: "error"`) via `message_end`, including Claud
|
|
|
91
91
|
is hit, the turn errors once, the pool flips (with a UI notification), and you just
|
|
92
92
|
resend your message to continue on the other account.
|
|
93
93
|
|
|
94
|
-
**OAuth compatibility and background token refresh (v1.3.
|
|
95
|
-
uses its own Anthropic OAuth login/refresh adapter
|
|
96
|
-
pi 0.81.x where the old runtime OAuth export is no longer available.
|
|
97
|
-
tokens are short-lived. An account that sat idle (e.g. your fallback)
|
|
98
|
-
a dead access token by the time failover switched to it — producing a
|
|
99
|
-
authentication_error`. v1.3.
|
|
94
|
+
**OAuth compatibility and background token refresh (v1.3.2):** The pool now
|
|
95
|
+
uses its own Anthropic OAuth login/refresh adapter and the login callback bridge
|
|
96
|
+
matches pi 0.81.x, where the old runtime OAuth export is no longer available.
|
|
97
|
+
OAuth access tokens are short-lived. An account that sat idle (e.g. your fallback)
|
|
98
|
+
would have a dead access token by the time failover switched to it — producing a
|
|
99
|
+
`401 authentication_error`. v1.3.2 retains the v1.3.0 keep-warm behavior:
|
|
100
100
|
|
|
101
101
|
- A `setInterval` keep-warm loop that refreshes **every** pooled account before it
|
|
102
102
|
expires, even when idle and not the active account (the timer is `unref()`'d so
|
package/oauth.ts
CHANGED
|
@@ -8,9 +8,11 @@ export interface AnthropicOAuthCredential {
|
|
|
8
8
|
expires: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export interface AnthropicOAuthLoginCallbacks {
|
|
12
|
+
onAuth: (info: { url: string; instructions?: string }) => void;
|
|
13
|
+
onManualCodeInput: () => Promise<string>;
|
|
14
|
+
onProgress?: (message: string) => void;
|
|
15
|
+
signal?: AbortSignal;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
const CLIENT_ID = Buffer.from("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl", "base64").toString("utf8");
|
|
@@ -165,12 +167,11 @@ async function exchangeAuthorizationCode(
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
export async function loginAnthropicOAuth(
|
|
168
|
-
|
|
170
|
+
callbacks: AnthropicOAuthLoginCallbacks,
|
|
169
171
|
): Promise<AnthropicOAuthCredential> {
|
|
170
172
|
const verifier = randomBytes(32).toString("base64url");
|
|
171
173
|
const challenge = createHash("sha256").update(verifier).digest("base64url");
|
|
172
174
|
const server = await startCallbackServer(verifier);
|
|
173
|
-
const manualAbort = new AbortController();
|
|
174
175
|
let manualInput: string | undefined;
|
|
175
176
|
let manualError: Error | undefined;
|
|
176
177
|
try {
|
|
@@ -184,18 +185,12 @@ export async function loginAnthropicOAuth(
|
|
|
184
185
|
code_challenge_method: "S256",
|
|
185
186
|
state: verifier,
|
|
186
187
|
});
|
|
187
|
-
|
|
188
|
-
type: "auth_url",
|
|
188
|
+
callbacks.onAuth({
|
|
189
189
|
url: `${AUTHORIZE_URL}?${authParams.toString()}`,
|
|
190
190
|
instructions: "Complete login in your browser. If the browser is on another machine, paste the final redirect URL here.",
|
|
191
191
|
});
|
|
192
|
-
const manualPromise =
|
|
193
|
-
.
|
|
194
|
-
type: "manual_code",
|
|
195
|
-
message: "Complete login in your browser, or paste the authorization code / redirect URL here:",
|
|
196
|
-
placeholder: REDIRECT_URI,
|
|
197
|
-
signal: manualAbort.signal,
|
|
198
|
-
})
|
|
192
|
+
const manualPromise = callbacks
|
|
193
|
+
.onManualCodeInput()
|
|
199
194
|
.then((input) => {
|
|
200
195
|
manualInput = input;
|
|
201
196
|
server.cancelWait();
|
|
@@ -216,10 +211,9 @@ export async function loginAnthropicOAuth(
|
|
|
216
211
|
parsed.code = fallback.code;
|
|
217
212
|
}
|
|
218
213
|
if (!parsed.code) throw new Error("Missing authorization code");
|
|
219
|
-
|
|
214
|
+
callbacks.onProgress?.("Exchanging authorization code for tokens...");
|
|
220
215
|
return exchangeAuthorizationCode(parsed.code, parsed.state ?? verifier, verifier);
|
|
221
216
|
} finally {
|
|
222
|
-
manualAbort.abort();
|
|
223
217
|
server.server.close();
|
|
224
218
|
}
|
|
225
219
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgltyq/pi-provider-claude",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Claude (Anthropic OAuth/subscription) compatibility layer for pi-coding-agent — keeps ALL extension tools usable under the Claude subscription by mapping unknown flat tool names to mcp__pi__<name> on the wire instead of dropping them, plus optional multi-account failover. Self-contained fork of the tool half of @benvargas/pi-claude-code-use.",
|
|
5
5
|
"author": "Leechael",
|
|
6
6
|
"license": "MIT",
|