@moxxy/plugin-provider-claude-code 0.30.0 → 0.32.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/constants.d.ts +10 -38
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +10 -38
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -13
- package/dist/index.js.map +1 -1
- package/dist/login.d.ts +24 -44
- package/dist/login.d.ts.map +1 -1
- package/dist/login.js +122 -314
- package/dist/login.js.map +1 -1
- package/dist/process.d.ts +34 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +197 -0
- package/dist/process.js.map +1 -0
- package/dist/protocol.d.ts +20 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +242 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.d.ts +49 -20
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +216 -17
- package/dist/provider.js.map +1 -1
- package/package.json +20 -5
- package/src/constants.ts +10 -40
- package/src/index.ts +50 -16
- package/src/login.test.ts +87 -396
- package/src/login.ts +146 -382
- package/src/process.test.ts +208 -0
- package/src/process.ts +224 -0
- package/src/protocol.ts +248 -0
- package/src/provider.test.ts +561 -30
- package/src/provider.ts +250 -25
package/dist/constants.d.ts
CHANGED
|
@@ -1,41 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants for the Claude subscription (Pro/Max) provider.
|
|
3
|
-
*
|
|
4
|
-
* These are the public Claude Code OAuth client parameters — the same values
|
|
5
|
-
* the `claude` CLI uses — so a token minted here interoperates with one from
|
|
6
|
-
* `claude setup-token`, and vice-versa. We never embed a client secret; the
|
|
7
|
-
* flow is PKCE + an out-of-band (manual paste) authorization code.
|
|
8
|
-
*/
|
|
9
|
-
/** Provider name in the registry / `/model` picker / `provider.name` config. */
|
|
1
|
+
/** Provider name in the registry / model picker / provider config. */
|
|
10
2
|
export declare const CLAUDE_CODE_PROVIDER_ID = "claude-code";
|
|
11
|
-
/** Human-readable upstream service, shown in
|
|
12
|
-
export declare const CLAUDE_CODE_SERVICE_NAME = "Claude
|
|
13
|
-
|
|
14
|
-
export declare const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
export declare const CLAUDE_REDIRECT_URI = "https://console.anthropic.com/oauth/code/callback";
|
|
21
|
-
export declare const CLAUDE_SCOPES: readonly ["org:create_api_key", "user:profile", "user:inference"];
|
|
22
|
-
/**
|
|
23
|
-
* `anthropic-beta` values sent with every request. `oauth-2025-04-20` is the
|
|
24
|
-
* flag that makes the Messages API accept a subscription bearer token at all;
|
|
25
|
-
* `claude-code-20250219` matches what the real CLI sends. Sent comma-joined.
|
|
26
|
-
*/
|
|
27
|
-
export declare const CLAUDE_OAUTH_BETA: readonly ["oauth-2025-04-20", "claude-code-20250219"];
|
|
28
|
-
/**
|
|
29
|
-
* Required first system block. Claude rejects a subscription token unless the
|
|
30
|
-
* system prompt leads with this exact identity line; moxxy's real system
|
|
31
|
-
* prompt is appended as the following block. (Verified against the working
|
|
32
|
-
* opencode / claude-code-router behaviour.)
|
|
33
|
-
*/
|
|
3
|
+
/** Human-readable upstream service, shown in login and setup surfaces. */
|
|
4
|
+
export declare const CLAUDE_CODE_SERVICE_NAME = "Claude Code subscription";
|
|
5
|
+
/** Optional executable override for login/status surfaces that do not carry provider config. */
|
|
6
|
+
export declare const CLAUDE_CODE_EXECUTABLE_ENV = "CLAUDE_CODE_EXECUTABLE";
|
|
7
|
+
/** Supported Claude Code authentication commands. Arguments stay separate from the executable. */
|
|
8
|
+
export declare const CLAUDE_AUTH_STATUS_ARGS: readonly ["auth", "status"];
|
|
9
|
+
export declare const CLAUDE_AUTH_LOGIN_ARGS: readonly ["auth", "login"];
|
|
10
|
+
export declare const CLAUDE_AUTH_LOGOUT_ARGS: readonly ["auth", "logout"];
|
|
11
|
+
/** Required identity line used by the CLI transport. */
|
|
34
12
|
export declare const CLAUDE_CODE_SYSTEM = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
35
|
-
/**
|
|
36
|
-
* Env vars a pasted/CI token can arrive through. `CLAUDE_CODE_OAUTH_TOKEN` is
|
|
37
|
-
* what `claude setup-token` documents; `ANTHROPIC_AUTH_TOKEN` is the
|
|
38
|
-
* SDK-native bearer var. Checked in this order.
|
|
39
|
-
*/
|
|
40
|
-
export declare const CLAUDE_TOKEN_ENV_VARS: readonly ["CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_AUTH_TOKEN"];
|
|
41
13
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,0EAA0E;AAC1E,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE,gGAAgG;AAChG,eAAO,MAAM,0BAA0B,2BAA2B,CAAC;AAEnE,kGAAkG;AAClG,eAAO,MAAM,uBAAuB,6BAA8B,CAAC;AACnE,eAAO,MAAM,sBAAsB,4BAA6B,CAAC;AACjE,eAAO,MAAM,uBAAuB,6BAA8B,CAAC;AAEnE,wDAAwD;AACxD,eAAO,MAAM,kBAAkB,8DAA8D,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,41 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants for the Claude subscription (Pro/Max) provider.
|
|
3
|
-
*
|
|
4
|
-
* These are the public Claude Code OAuth client parameters — the same values
|
|
5
|
-
* the `claude` CLI uses — so a token minted here interoperates with one from
|
|
6
|
-
* `claude setup-token`, and vice-versa. We never embed a client secret; the
|
|
7
|
-
* flow is PKCE + an out-of-band (manual paste) authorization code.
|
|
8
|
-
*/
|
|
9
|
-
/** Provider name in the registry / `/model` picker / `provider.name` config. */
|
|
1
|
+
/** Provider name in the registry / model picker / provider config. */
|
|
10
2
|
export const CLAUDE_CODE_PROVIDER_ID = 'claude-code';
|
|
11
|
-
/** Human-readable upstream service, shown in
|
|
12
|
-
export const CLAUDE_CODE_SERVICE_NAME = 'Claude
|
|
13
|
-
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
export const CLAUDE_REDIRECT_URI = 'https://console.anthropic.com/oauth/code/callback';
|
|
21
|
-
export const CLAUDE_SCOPES = ['org:create_api_key', 'user:profile', 'user:inference'];
|
|
22
|
-
/**
|
|
23
|
-
* `anthropic-beta` values sent with every request. `oauth-2025-04-20` is the
|
|
24
|
-
* flag that makes the Messages API accept a subscription bearer token at all;
|
|
25
|
-
* `claude-code-20250219` matches what the real CLI sends. Sent comma-joined.
|
|
26
|
-
*/
|
|
27
|
-
export const CLAUDE_OAUTH_BETA = ['oauth-2025-04-20', 'claude-code-20250219'];
|
|
28
|
-
/**
|
|
29
|
-
* Required first system block. Claude rejects a subscription token unless the
|
|
30
|
-
* system prompt leads with this exact identity line; moxxy's real system
|
|
31
|
-
* prompt is appended as the following block. (Verified against the working
|
|
32
|
-
* opencode / claude-code-router behaviour.)
|
|
33
|
-
*/
|
|
3
|
+
/** Human-readable upstream service, shown in login and setup surfaces. */
|
|
4
|
+
export const CLAUDE_CODE_SERVICE_NAME = 'Claude Code subscription';
|
|
5
|
+
/** Optional executable override for login/status surfaces that do not carry provider config. */
|
|
6
|
+
export const CLAUDE_CODE_EXECUTABLE_ENV = 'CLAUDE_CODE_EXECUTABLE';
|
|
7
|
+
/** Supported Claude Code authentication commands. Arguments stay separate from the executable. */
|
|
8
|
+
export const CLAUDE_AUTH_STATUS_ARGS = ['auth', 'status'];
|
|
9
|
+
export const CLAUDE_AUTH_LOGIN_ARGS = ['auth', 'login'];
|
|
10
|
+
export const CLAUDE_AUTH_LOGOUT_ARGS = ['auth', 'logout'];
|
|
11
|
+
/** Required identity line used by the CLI transport. */
|
|
34
12
|
export const CLAUDE_CODE_SYSTEM = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
35
|
-
/**
|
|
36
|
-
* Env vars a pasted/CI token can arrive through. `CLAUDE_CODE_OAUTH_TOKEN` is
|
|
37
|
-
* what `claude setup-token` documents; `ANTHROPIC_AUTH_TOKEN` is the
|
|
38
|
-
* SDK-native bearer var. Checked in this order.
|
|
39
|
-
*/
|
|
40
|
-
export const CLAUDE_TOKEN_ENV_VARS = ['CLAUDE_CODE_OAUTH_TOKEN', 'ANTHROPIC_AUTH_TOKEN'];
|
|
41
13
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAErD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE,gGAAgG;AAChG,MAAM,CAAC,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAEnE,kGAAkG;AAClG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAU,CAAC;AACnE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAC;AACjE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAU,CAAC;AAEnE,wDAAwD;AACxD,MAAM,CAAC,MAAM,kBAAkB,GAAG,2DAA2D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const claudeCodeProviderDef: import("@moxxy/sdk").ProviderDef;
|
|
2
2
|
export declare const claudeCodePlugin: import("@moxxy/sdk").Plugin;
|
|
3
3
|
export default claudeCodePlugin;
|
|
4
|
-
export { CLAUDE_CODE_PROVIDER_ID, CLAUDE_CODE_SERVICE_NAME, CLAUDE_CODE_SYSTEM,
|
|
5
|
-
export { claudeLogin, claudeLogout, claudeStatus,
|
|
6
|
-
export { createClaudeCodeClient, type ClaudeCodeProviderConfig } from './provider.js';
|
|
4
|
+
export { CLAUDE_CODE_PROVIDER_ID, CLAUDE_CODE_SERVICE_NAME, CLAUDE_CODE_SYSTEM, CLAUDE_CODE_EXECUTABLE_ENV, } from './constants.js';
|
|
5
|
+
export { claudeLogin, claudeLogout, claudeStatus, checkClaudeCliAuth, resolveClaudeExecutable, type ClaudeCliAuthStatus, type ClaudeCliAuthState, type ClaudeCommandResult, __setClaudeCommandRunner, } from './login.js';
|
|
6
|
+
export { CLAUDE_CODE_DEFAULT_MODEL, claudeCodeModels, createClaudeCodeClient, type ClaudeCodeProviderConfig, } from './provider.js';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,qBAAqB,kCAgChC,CAAC;AAEH,eAAO,MAAM,gBAAgB,6BAI3B,CAAC;AAEH,eAAe,gBAAgB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
import { defineProvider, definePlugin } from '@moxxy/sdk';
|
|
2
|
-
import { anthropicModels } from '@moxxy/plugin-provider-anthropic';
|
|
1
|
+
import { defineProvider, definePlugin, MoxxyError } from '@moxxy/sdk';
|
|
3
2
|
import { CLAUDE_CODE_PROVIDER_ID, CLAUDE_CODE_SERVICE_NAME } from './constants.js';
|
|
4
|
-
import { createClaudeCodeClient } from './provider.js';
|
|
5
|
-
import { claudeLogin, claudeLogout, claudeStatus } from './login.js';
|
|
3
|
+
import { CLAUDE_CODE_DEFAULT_MODEL, claudeCodeModels, createClaudeCodeClient, } from './provider.js';
|
|
4
|
+
import { claudeLogin, claudeLogout, claudeStatus, checkClaudeCliAuth, resolveClaudeExecutable, } from './login.js';
|
|
6
5
|
export const claudeCodeProviderDef = defineProvider({
|
|
7
6
|
name: CLAUDE_CODE_PROVIDER_ID,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
models: claudeCodeModels,
|
|
8
|
+
createClient: (config) => createClaudeCodeClient({
|
|
9
|
+
...config,
|
|
10
|
+
defaultModel: typeof config.model === 'string'
|
|
11
|
+
? config.model
|
|
12
|
+
: config.defaultModel ?? CLAUDE_CODE_DEFAULT_MODEL,
|
|
13
|
+
}),
|
|
14
|
+
async resolveCredentials({ providerConfig, host }) {
|
|
15
|
+
const config = { ...providerConfig, cwd: host.cwd };
|
|
16
|
+
const executable = resolveClaudeExecutable(config);
|
|
17
|
+
const status = await checkClaudeCliAuth(executable);
|
|
18
|
+
if (status.state !== 'signed-in') {
|
|
19
|
+
throw new MoxxyError({
|
|
20
|
+
code: status.state === 'signed-out' ? 'AUTH_NO_CREDENTIALS' : 'AUTH_INVALID',
|
|
21
|
+
message: status.message,
|
|
22
|
+
hint: status.state === 'signed-out' ? `Run \`moxxy login ${CLAUDE_CODE_PROVIDER_ID}\`.` : undefined,
|
|
23
|
+
context: { provider: CLAUDE_CODE_PROVIDER_ID, executable, state: status.state },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return { ...config, executable };
|
|
27
|
+
},
|
|
28
|
+
// No validateKey: readiness is reported by the installed Claude CLI.
|
|
14
29
|
auth: {
|
|
15
30
|
kind: 'oauth',
|
|
16
31
|
serviceName: CLAUDE_CODE_SERVICE_NAME,
|
|
@@ -25,7 +40,7 @@ export const claudeCodePlugin = definePlugin({
|
|
|
25
40
|
providers: [claudeCodeProviderDef],
|
|
26
41
|
});
|
|
27
42
|
export default claudeCodePlugin;
|
|
28
|
-
export { CLAUDE_CODE_PROVIDER_ID, CLAUDE_CODE_SERVICE_NAME, CLAUDE_CODE_SYSTEM,
|
|
29
|
-
export { claudeLogin, claudeLogout, claudeStatus,
|
|
30
|
-
export { createClaudeCodeClient } from './provider.js';
|
|
43
|
+
export { CLAUDE_CODE_PROVIDER_ID, CLAUDE_CODE_SERVICE_NAME, CLAUDE_CODE_SYSTEM, CLAUDE_CODE_EXECUTABLE_ENV, } from './constants.js';
|
|
44
|
+
export { claudeLogin, claudeLogout, claudeStatus, checkClaudeCliAuth, resolveClaudeExecutable, __setClaudeCommandRunner, } from './login.js';
|
|
45
|
+
export { CLAUDE_CODE_DEFAULT_MODEL, claudeCodeModels, createClaudeCodeClient, } from './provider.js';
|
|
31
46
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,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O;gBACvB,IAAI,EAAE,MAAM,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,qBAAqB,uBAAuB,KAAK,CAAC,CAAC,CAAC,SAAS;gBACnG,OAAO,EAAE,EAAE,QAAQ,EAAE,uBAAuB,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;aAChF,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC;IACnC,CAAC;IACD,qEAAqE;IACrE,IAAI,EAAE;QACJ,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,wBAAwB;QACrC,KAAK,EAAE,WAAW;QAClB,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,YAAY;KACrB;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;IAC3C,IAAI,EAAE,oCAAoC;IAC1C,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,CAAC,qBAAqB,CAAC;CACnC,CAAC,CAAC;AAEH,eAAe,gBAAgB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EAIvB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,GAEvB,MAAM,eAAe,CAAC"}
|
package/dist/login.d.ts
CHANGED
|
@@ -1,49 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude subscription login + token lifecycle.
|
|
3
|
-
*
|
|
4
|
-
* Claude's OAuth is an out-of-band (manual code-paste) authorization-code +
|
|
5
|
-
* PKCE flow whose token endpoint speaks JSON (not the form-encoded dialect
|
|
6
|
-
* the framework's `exchangeCodeForToken` / `refreshAccessToken` assume), so
|
|
7
|
-
* the HTTP exchange + refresh are implemented here. Everything else is reused
|
|
8
|
-
* from `@moxxy/plugin-oauth`: PKCE, the auth-URL builder, the browser opener,
|
|
9
|
-
* vault storage layout, and `parseTokenResponse`.
|
|
10
|
-
*/
|
|
11
|
-
import { type OAuthVault } from '@moxxy/plugin-oauth';
|
|
12
1
|
import type { ProviderAuthContext, ProviderOAuthResult, ProviderOAuthStatus } from '@moxxy/sdk';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
export type ClaudeCliAuthState = 'signed-in' | 'signed-out' | 'missing' | 'unsupported' | 'error';
|
|
3
|
+
export interface ClaudeCliAuthStatus {
|
|
4
|
+
readonly state: ClaudeCliAuthState;
|
|
5
|
+
readonly executable: string;
|
|
6
|
+
readonly accountId?: string;
|
|
7
|
+
readonly message: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ClaudeCommandResult {
|
|
10
|
+
readonly code: number;
|
|
11
|
+
readonly stdout: string;
|
|
12
|
+
readonly stderr: string;
|
|
13
|
+
readonly error?: NodeJS.ErrnoException;
|
|
14
|
+
}
|
|
15
|
+
type CommandRunner = (executable: string, args: readonly string[], options?: {
|
|
16
|
+
readonly inherit?: boolean;
|
|
17
|
+
}) => Promise<ClaudeCommandResult>;
|
|
18
|
+
/** Test seam. */
|
|
19
|
+
export declare function __setClaudeCommandRunner(runner: CommandRunner): void;
|
|
20
|
+
/** Resolve the executable without involving a shell (paths containing spaces are safe). */
|
|
21
|
+
export declare function resolveClaudeExecutable(config?: Record<string, unknown>): string;
|
|
22
|
+
/** Probe the installed CLI's supported, machine-readable authentication command. */
|
|
23
|
+
export declare function checkClaudeCliAuth(executable?: string): Promise<ClaudeCliAuthStatus>;
|
|
19
24
|
export declare function claudeLogin(ctx: ProviderAuthContext): Promise<ProviderOAuthResult>;
|
|
25
|
+
/** Log out the CLI account. Legacy moxxy vault values are deliberately untouched. */
|
|
20
26
|
export declare function claudeLogout(ctx: ProviderAuthContext): Promise<boolean>;
|
|
21
27
|
export declare function claudeStatus(ctx: ProviderAuthContext): Promise<ProviderOAuthStatus | null>;
|
|
22
|
-
export
|
|
23
|
-
readonly accessToken: string;
|
|
24
|
-
readonly expiresAt?: number;
|
|
25
|
-
/** True when a refresh_token is stored, so a 401 can be recovered. */
|
|
26
|
-
readonly canRefresh: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Read the stored Claude creds, refreshing first if the access token is near
|
|
30
|
-
* expiry and a refresh_token is available. Returns null when nothing is
|
|
31
|
-
* stored. Persists rotated tokens BEFORE returning so a crash can't strand a
|
|
32
|
-
* single-use refresh_token. The refresh itself is serialized per credential
|
|
33
|
-
* (in-process + cross-process) and coalesces with concurrent refreshers.
|
|
34
|
-
*/
|
|
35
|
-
export declare function ensureFreshClaudeTokens(vault: OAuthVault): Promise<FreshClaudeTokens | null>;
|
|
36
|
-
/**
|
|
37
|
-
* Force a refresh of the stored Claude tokens and persist the rotated bundle.
|
|
38
|
-
* Used as the provider's reactive 401 recovery. Throws if no refresh_token is
|
|
39
|
-
* stored (e.g. a pasted `setup-token`).
|
|
40
|
-
*/
|
|
41
|
-
export declare function refreshClaudeAccessToken(vault: OAuthVault): Promise<{
|
|
42
|
-
token: string;
|
|
43
|
-
expiresAt?: number;
|
|
44
|
-
}>;
|
|
45
|
-
export declare function __setClaudeFetch(f: typeof fetch): void;
|
|
46
|
-
export declare function __setClaudeOpenBrowser(f: (url: string) => Promise<void>): void;
|
|
47
|
-
export declare function __setClaudeSleep(f: (ms: number) => Promise<void>): void;
|
|
48
|
-
export declare function __setClaudeTimeoutMs(ms: number): void;
|
|
28
|
+
export {};
|
|
49
29
|
//# sourceMappingURL=login.d.ts.map
|
package/dist/login.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file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