@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.
@@ -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 `moxxy login` and the init wizard. */
12
- export declare const CLAUDE_CODE_SERVICE_NAME = "Claude (Pro/Max subscription)";
13
- export declare const CLAUDE_AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
14
- export declare const CLAUDE_TOKEN_URL = "https://console.anthropic.com/v1/oauth/token";
15
- export declare const CLAUDE_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
16
- /**
17
- * Out-of-band redirect: after consent, Anthropic shows the user a
18
- * `code#state` string to paste back into the terminal (no loopback server).
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
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,gFAAgF;AAChF,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,mFAAmF;AACnF,eAAO,MAAM,wBAAwB,kCAAkC,CAAC;AAExE,eAAO,MAAM,oBAAoB,sCAAsC,CAAC;AACxE,eAAO,MAAM,gBAAgB,iDAAiD,CAAC;AAC/E,eAAO,MAAM,gBAAgB,yCAAyC,CAAC;AACvE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,sDAAsD,CAAC;AACvF,eAAO,MAAM,aAAa,mEAAoE,CAAC;AAE/F;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,uDAAwD,CAAC;AAEvF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,8DAA8D,CAAC;AAE9F;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,8DAA+D,CAAC"}
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 `moxxy login` and the init wizard. */
12
- export const CLAUDE_CODE_SERVICE_NAME = 'Claude (Pro/Max subscription)';
13
- export const CLAUDE_AUTHORIZE_URL = 'https://claude.ai/oauth/authorize';
14
- export const CLAUDE_TOKEN_URL = 'https://console.anthropic.com/v1/oauth/token';
15
- export const CLAUDE_CLIENT_ID = '9d1c250a-e61b-44d9-88ed-5944d1962f5e';
16
- /**
17
- * Out-of-band redirect: after consent, Anthropic shows the user a
18
- * `code#state` string to paste back into the terminal (no loopback server).
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
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAO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wD;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, CLAUDE_OAUTH_BETA, CLAUDE_TOKEN_ENV_VARS, } from './constants.js';
5
- export { claudeLogin, claudeLogout, claudeStatus, ensureFreshClaudeTokens, refreshClaudeAccessToken, type FreshClaudeTokens, } from './login.js';
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,qBAAqB,kCAehC,CAAC;AAEH,eAAO,MAAM,gBAAgB,6BAI3B,CAAC;AAEH,eAAe,gBAAgB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,KAAK,iBAAiB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,KAAK,wBAAwB,EAAE,MAAM,eAAe,CAAC"}
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
- // Same Claude models as the API-key `anthropic` provider — it's the same
9
- // Messages API, only the credential differs.
10
- models: [...anthropicModels],
11
- createClient: (config) => createClaudeCodeClient(config),
12
- // No validateKey: an OAuth bearer is validated by the request itself, and
13
- // an interactive paste/sign-in already proves the token round-trips.
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, CLAUDE_OAUTH_BETA, CLAUDE_TOKEN_ENV_VARS, } from './constants.js';
29
- export { claudeLogin, claudeLogout, claudeStatus, ensureFreshClaudeTokens, refreshClaudeAccessToken, } from './login.js';
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,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAiC,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC;IAClD,IAAI,EAAE,uBAAuB;IAC7B,yEAAyE;IACzE,6CAA6C;IAC7C,MAAM,EAAE,CAAC,GAAG,eAAe,CAAC;IAC5B,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,sBAAsB,CAAC,MAAkC,CAAC;IACpF,0EAA0E;IAC1E,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,iB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
- * 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
- * Drive an interactive Claude sign-in. Two ways in, both through one command:
15
- * 1. paste an existing `claude setup-token` token (stored verbatim), or
16
- * 2. press Enter to run the browser out-of-band authorization-code flow.
17
- * Needs `ctx.prompt` (a TTY); headless callers use `CLAUDE_CODE_OAUTH_TOKEN`.
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 interface FreshClaudeTokens {
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
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAaL,KAAK,UAAU,EAGhB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAepB;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAuFxF;AAED,wBAAsB,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