@velum-labs/routekit-accounts 1.3.2 → 1.4.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/README.md +4 -5
- package/dist/codex-originator.d.ts +9 -0
- package/dist/codex-originator.js +29 -0
- package/dist/connector.js +3 -2
- package/dist/index.d.ts +9 -7
- package/dist/index.js +9 -7
- package/dist/managed-login.d.ts +34 -26
- package/dist/managed-login.js +580 -166
- package/dist/provider/codex.js +4 -1
- package/dist/proxy.d.ts +1 -1
- package/dist/test/codex-originator.test.d.ts +1 -0
- package/dist/test/codex-originator.test.js +16 -0
- package/dist/test/managed-login.test.js +379 -97
- package/dist/test/subscription-provider.test.js +30 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -10,11 +10,10 @@ runs against every healthy account; the provider publishes the union of models
|
|
|
10
10
|
and tracks which accounts are eligible for each model.
|
|
11
11
|
|
|
12
12
|
The first-launch RouteKit subscription kinds are `claude-code` and `codex`.
|
|
13
|
-
They run
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
and subscription kinds are separate contracts.
|
|
13
|
+
They run first-party OAuth (`captureLoginCredential`) before enrolling. Any
|
|
14
|
+
number of named accounts may join a provider; the first enrollment enables that
|
|
15
|
+
provider in the effective router config. The RouteKit tool command is still
|
|
16
|
+
`routekit claude`; tool names and subscription kinds are separate contracts.
|
|
18
17
|
|
|
19
18
|
Other registry entries and exported connector APIs are internal, unqualified,
|
|
20
19
|
and non-contractual; they are not RouteKit onboarding or support.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Supervised daemons copy this from the installing shell; login and relays read it at runtime. */
|
|
2
|
+
export declare const CODEX_ORIGINATOR_ENV = "ROUTEKIT_CODEX_ORIGINATOR";
|
|
3
|
+
/**
|
|
4
|
+
* Codex OAuth authorize param and upstream `originator` header.
|
|
5
|
+
*
|
|
6
|
+
* Defaults to the registry value (`routekit`). `ROUTEKIT_CODEX_ORIGINATOR`
|
|
7
|
+
* selects another token such as `codex_cli_rs`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolvedCodexOriginator(env?: NodeJS.ProcessEnv): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { subscriptionInfo } from "@velum-labs/routekit-registry";
|
|
2
|
+
/** Supervised daemons copy this from the installing shell; login and relays read it at runtime. */
|
|
3
|
+
export const CODEX_ORIGINATOR_ENV = "ROUTEKIT_CODEX_ORIGINATOR";
|
|
4
|
+
const ORIGINATOR_TOKEN = /^[\w.-]+$/;
|
|
5
|
+
function registryCodexOriginator() {
|
|
6
|
+
const info = subscriptionInfo("codex");
|
|
7
|
+
return (info.oauth.authorizeExtraParams?.originator ??
|
|
8
|
+
info.defaultHeaders?.originator ??
|
|
9
|
+
info.discovery.extraHeaders?.originator ??
|
|
10
|
+
"routekit");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Codex OAuth authorize param and upstream `originator` header.
|
|
14
|
+
*
|
|
15
|
+
* Defaults to the registry value (`routekit`). `ROUTEKIT_CODEX_ORIGINATOR`
|
|
16
|
+
* selects another token such as `codex_cli_rs`.
|
|
17
|
+
*/
|
|
18
|
+
export function resolvedCodexOriginator(env = process.env) {
|
|
19
|
+
const raw = env[CODEX_ORIGINATOR_ENV];
|
|
20
|
+
if (raw === undefined)
|
|
21
|
+
return registryCodexOriginator();
|
|
22
|
+
const value = raw.trim();
|
|
23
|
+
if (value.length === 0)
|
|
24
|
+
return registryCodexOriginator();
|
|
25
|
+
if (!ORIGINATOR_TOKEN.test(value)) {
|
|
26
|
+
throw new Error(`${CODEX_ORIGINATOR_ENV} must be a token (letters, numbers, dots, underscores, or hyphens)`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
package/dist/connector.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The neutral account layer retains two connector mechanisms:
|
|
5
5
|
*
|
|
6
|
-
* - `native`:
|
|
7
|
-
* account store and served by provider-native relays
|
|
6
|
+
* - `native`: first-party OAuth (or an imported official CLI file) captured
|
|
7
|
+
* into RouteKit's own account store and served by provider-native relays
|
|
8
|
+
* (claude-code, codex).
|
|
8
9
|
* - `cliproxy`: the RouteKit-managed CLIProxyAPI sidecar, whose OAuth account
|
|
9
10
|
* store and ingress key live under RouteKit's home (gemini, grok, kimi).
|
|
10
11
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A cohesive, typed surface for pooling Claude Code and Codex OAuth
|
|
5
5
|
* subscriptions behind one provider-native proxy: resolve an account set from
|
|
6
|
-
*
|
|
7
|
-
* refresh members with quota-aware routing, and
|
|
8
|
-
* protocols. `startSubscriptionProxy` is the
|
|
9
|
-
* `SubscriptionProxyClient` reads a running
|
|
10
|
-
* contract. Product CLIs can wrap this module
|
|
6
|
+
* first-party OAuth / an imported official CLI login / an enrolled directory /
|
|
7
|
+
* explicit paths, select and refresh members with quota-aware routing, and
|
|
8
|
+
* expose it over the gateway wire protocols. `startSubscriptionProxy` is the
|
|
9
|
+
* one-call programmatic entrypoint; `SubscriptionProxyClient` reads a running
|
|
10
|
+
* proxy's usage over a typed wire contract. Product CLIs can wrap this module
|
|
11
|
+
* without owning account logic.
|
|
11
12
|
*/
|
|
12
13
|
export type { CoordinatorResource, RedeemResetCreditInput, RedeemResetCreditResult, SubscriptionAccountSetOptions, SubscriptionExecutionObserver } from "./account-set/types.js";
|
|
13
14
|
export { SUBSCRIPTION_SSE_BUFFER_CAP_BYTES, SubscriptionAccountSet, SubscriptionAccountSetAuthError, SubscriptionAccountSetAuthRecoveryError, SubscriptionAccountSetExhaustedError } from "./account-set.js";
|
|
@@ -25,6 +26,7 @@ export type { SubscriptionProxyClientOptions } from "./client.js";
|
|
|
25
26
|
export { SubscriptionProxyClient, SubscriptionProxyClientError } from "./client.js";
|
|
26
27
|
export type { CliproxyInstallResult, CliproxyStatus } from "./cliproxy.js";
|
|
27
28
|
export { CLIPROXY_API_KEY_ENV, CLIPROXY_BASE_URL_ENV, CLIPROXY_HOME_ENV, CLIPROXY_PINNED_VERSION, cliproxyApiKey, cliproxyAssetName, cliproxyBaseUrl, cliproxyBinaryPath, cliproxyConfigPath, cliproxyHome, cliproxyManagedPort, cliproxyStatus, ensureCliproxyConfig, installCliproxy, spawnCliproxy, writeCliproxyLoginConfig } from "./cliproxy.js";
|
|
29
|
+
export { CODEX_ORIGINATOR_ENV, resolvedCodexOriginator } from "./codex-originator.js";
|
|
28
30
|
export type { CodexCatalogEntry, CodexRelayAuth, CodexRelayAuthSource, CodexRelayOptions, CodexStockEntry, ProviderRelayLogger } from "./codex-relay.js";
|
|
29
31
|
export { CodexBackendRelay, codexRelayAuth } from "./codex-relay.js";
|
|
30
32
|
export type { AccountStoreEntry, CapturedCliproxyCredential, CliproxyAccountEntry, CliproxyLoginInvocation, CliproxyLoginOptions, ResolvedAccountKind } from "./connector.js";
|
|
@@ -34,8 +36,8 @@ export { defaultSubscriptionAccountDirectory, defaultSubscriptionCredentialPath,
|
|
|
34
36
|
export type { OpenSubscriptionRelaysOptions, OpenSubscriptionRelaysResult, SubscriptionAccountConfigs, SubscriptionAccountSets } from "./gateway.js";
|
|
35
37
|
export { closeSubscriptionAccountSets, openSubscriptionAccountSets, openSubscriptionRelays, relayPorts, subscriptionRelaysFromAccountSets } from "./gateway.js";
|
|
36
38
|
export type { SubscriptionGateway, SubscriptionGatewayBackend, SubscriptionGatewayBackendRequestOptions, SubscriptionGatewayFactory, SubscriptionGatewayModelCatalogRelay, SubscriptionGatewayOptions, SubscriptionGatewayRelayDialect, SubscriptionGatewayRelayLifecycle, SubscriptionGatewayRelayPorts, SubscriptionGatewayRequestRelay, SubscriptionGatewayTokenCountRelay } from "./gateway-port.js";
|
|
37
|
-
export type {
|
|
38
|
-
export {
|
|
39
|
+
export type { AuthorizationCallbackInput, ManagedAccountLoginOptions } from "./managed-login.js";
|
|
40
|
+
export { captureLoginCredential, parseAccountMode } from "./managed-login.js";
|
|
39
41
|
export type { AdminUsageCost, AdminUsageRange, ConsumeResetCreditInput, ConsumeResetCreditResult, SubscriptionProvider, SubscriptionRefreshFailure, SubscriptionStreamOutcome } from "./provider.js";
|
|
40
42
|
export { SubscriptionProviderRequestError, SubscriptionRefreshError, subscriptionProvider } from "./provider.js";
|
|
41
43
|
export type { SubscriptionProviderBackend, SubscriptionProviderBackendFactory, SubscriptionProviderBackendOptions, SubscriptionProviderTransport, SubscriptionResponseMode } from "./provider-port.js";
|
package/dist/index.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A cohesive, typed surface for pooling Claude Code and Codex OAuth
|
|
5
5
|
* subscriptions behind one provider-native proxy: resolve an account set from
|
|
6
|
-
*
|
|
7
|
-
* refresh members with quota-aware routing, and
|
|
8
|
-
* protocols. `startSubscriptionProxy` is the
|
|
9
|
-
* `SubscriptionProxyClient` reads a running
|
|
10
|
-
* contract. Product CLIs can wrap this module
|
|
6
|
+
* first-party OAuth / an imported official CLI login / an enrolled directory /
|
|
7
|
+
* explicit paths, select and refresh members with quota-aware routing, and
|
|
8
|
+
* expose it over the gateway wire protocols. `startSubscriptionProxy` is the
|
|
9
|
+
* one-call programmatic entrypoint; `SubscriptionProxyClient` reads a running
|
|
10
|
+
* proxy's usage over a typed wire contract. Product CLIs can wrap this module
|
|
11
|
+
* without owning account logic.
|
|
11
12
|
*/
|
|
12
13
|
export { SUBSCRIPTION_SSE_BUFFER_CAP_BYTES, SubscriptionAccountSet, SubscriptionAccountSetAuthError, SubscriptionAccountSetAuthRecoveryError, SubscriptionAccountSetExhaustedError } from "./account-set.js";
|
|
13
14
|
// Account sources (canonical / directory / explicit)
|
|
@@ -21,6 +22,7 @@ export { SubscriptionAccountBackend } from "./backend.js";
|
|
|
21
22
|
export { SubscriptionProxyClient, SubscriptionProxyClientError } from "./client.js";
|
|
22
23
|
// Managed CLIProxyAPI lifecycle
|
|
23
24
|
export { CLIPROXY_API_KEY_ENV, CLIPROXY_BASE_URL_ENV, CLIPROXY_HOME_ENV, CLIPROXY_PINNED_VERSION, cliproxyApiKey, cliproxyAssetName, cliproxyBaseUrl, cliproxyBinaryPath, cliproxyConfigPath, cliproxyHome, cliproxyManagedPort, cliproxyStatus, ensureCliproxyConfig, installCliproxy, spawnCliproxy, writeCliproxyLoginConfig } from "./cliproxy.js";
|
|
25
|
+
export { CODEX_ORIGINATOR_ENV, resolvedCodexOriginator } from "./codex-originator.js";
|
|
24
26
|
// Relays (provider-native forwarding)
|
|
25
27
|
export { CodexBackendRelay, codexRelayAuth } from "./codex-relay.js";
|
|
26
28
|
// Account connectors: one login surface over native + cliproxy mechanisms
|
|
@@ -29,8 +31,8 @@ export { accountStoreEntries, captureCliproxyLoginCredentials, cliproxyAccountEn
|
|
|
29
31
|
export { defaultSubscriptionAccountDirectory, defaultSubscriptionCredentialPath, enrollCurrentSubscription, loadSubscriptionCredential, persistSubscriptionCredential, removeSubscriptionAccount, renameSubscriptionAccount, sanitizeSubscriptionLabel, subscriptionCredentialFingerprint, subscriptionCredentialLabel } from "./credentials.js";
|
|
30
32
|
// Gateway relay construction
|
|
31
33
|
export { closeSubscriptionAccountSets, openSubscriptionAccountSets, openSubscriptionRelays, relayPorts, subscriptionRelaysFromAccountSets } from "./gateway.js";
|
|
32
|
-
//
|
|
33
|
-
export {
|
|
34
|
+
// First-party OAuth enrollment for native Claude Code / Codex subscriptions
|
|
35
|
+
export { captureLoginCredential, parseAccountMode } from "./managed-login.js";
|
|
34
36
|
// Provider adapters
|
|
35
37
|
export { SubscriptionProviderRequestError, SubscriptionRefreshError, subscriptionProvider } from "./provider.js";
|
|
36
38
|
// Programmatic proxy + typed client
|
package/dist/managed-login.d.ts
CHANGED
|
@@ -1,41 +1,49 @@
|
|
|
1
|
-
import type
|
|
2
|
-
/** Directory under the temp profile that shadows OS browser openers. */
|
|
3
|
-
export declare function browserOpenerStubDirectory(profileDirectory: string): string;
|
|
1
|
+
import { type SubscriptionMode } from "@velum-labs/routekit-registry";
|
|
4
2
|
/** Narrow a user-supplied kind to a native subscription kind. */
|
|
5
3
|
export declare function parseAccountMode(value: string): SubscriptionMode;
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
sourcePath: string;
|
|
12
|
-
};
|
|
13
|
-
export type ManagedLoginKeychain = {
|
|
14
|
-
read(service: string): Promise<string>;
|
|
15
|
-
remove(service: string): Promise<void>;
|
|
4
|
+
export type AuthorizationCallbackInput = {
|
|
5
|
+
authorizeUrl: string;
|
|
6
|
+
redirectUri: string;
|
|
7
|
+
state: string;
|
|
8
|
+
subscriptionKind: SubscriptionMode;
|
|
16
9
|
};
|
|
17
10
|
export type ManagedAccountLoginOptions = {
|
|
18
|
-
temporaryParent?: string;
|
|
19
11
|
/**
|
|
20
|
-
* Prefer a browserless login flow: Codex uses
|
|
21
|
-
*
|
|
22
|
-
* flag, so RouteKit shadows `open`/`xdg-open` and sets `BROWSER` to force
|
|
23
|
-
* its built-in copyable-URL + pasted-code fallback.
|
|
12
|
+
* Prefer a browserless login flow: Codex uses ChatGPT deviceauth;
|
|
13
|
+
* Claude Code prints a copyable authorize URL and accepts a pasted code.
|
|
24
14
|
*/
|
|
25
15
|
noBrowser?: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
/** Process environment used for Codex originator resolution. Defaults to `process.env`. */
|
|
18
|
+
env?: NodeJS.ProcessEnv;
|
|
19
|
+
onProgress?: (message: string) => void;
|
|
20
|
+
waitForAuthorizationCode?: (input: AuthorizationCallbackInput) => Promise<string>;
|
|
21
|
+
listenForCallback?: (input: {
|
|
22
|
+
redirectUri: string;
|
|
23
|
+
state: string;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
onReady?: () => void;
|
|
26
|
+
}) => Promise<URL>;
|
|
27
|
+
openBrowser?: (url: string) => Promise<void>;
|
|
28
|
+
readPastedCode?: (prompt: string, signal?: AbortSignal) => Promise<string>;
|
|
29
|
+
sleep?: (ms: number) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
type LoopbackWaitInput = {
|
|
32
|
+
redirectUri: string;
|
|
33
|
+
state: string;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
onReady?: () => void;
|
|
29
36
|
};
|
|
30
|
-
export declare function
|
|
37
|
+
export declare function defaultListenForCallback(input: LoopbackWaitInput): Promise<URL>;
|
|
31
38
|
/**
|
|
32
|
-
* Run
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
39
|
+
* Run first-party OAuth for a native subscription kind and return the credential
|
|
40
|
+
* blob instead of writing RouteKit state. The singleton daemon is the sole
|
|
41
|
+
* account-store writer; the thin CLI sends this blob over its authenticated
|
|
42
|
+
* control channel.
|
|
36
43
|
*/
|
|
37
44
|
export declare function captureLoginCredential(subscriptionKindInput: string, label: string, options?: ManagedAccountLoginOptions): Promise<{
|
|
38
45
|
subscriptionKind: SubscriptionMode;
|
|
39
46
|
label: string;
|
|
40
47
|
credential: unknown;
|
|
41
48
|
}>;
|
|
49
|
+
export {};
|