paseo-plugin-account-switcher 0.4.0 → 0.5.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/OVERVIEW.md +5 -2
- package/OVERVIEW.zh-CN.md +31 -0
- package/README.md +5 -1
- package/client/format.ts +14 -0
- package/client/switcher.tsx +3 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +9 -3
- package/server/controller.ts +7 -1
- package/server/launcher-artifact.ts +1 -1
- package/server/usage/README.md +5 -1
- package/server/usage/claude.ts +26 -2
- package/server/usage/codex.ts +14 -2
- package/server/usage/index.ts +3 -3
- package/server/usage/parsers.ts +8 -0
- package/shared/contracts.ts +2 -0
package/OVERVIEW.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Account Switcher lets you use several Claude and ChatGPT/Codex subscription accounts in Paseo. You pick an account for each agent, switch the account of an existing chat, set a default per provider, and see each account's usage limits. Switching is manual and stays within one provider.
|
|
2
2
|
|
|
3
|
+
Limits cover every window the provider reports, such as 5-hour and weekly use, with reset times. Codex usage-based workspace plans show their monthly credits, and Claude enterprise seats show their monthly spend allowance.
|
|
4
|
+
|
|
3
5
|
## How it works
|
|
4
6
|
|
|
5
7
|
- Each account you add gets its own credential profile. Settings, skills, and session history stay shared with your existing CLI setup, so a profile is not a sandbox.
|
|
6
8
|
- **Enable** in Accounts points Paseo's Claude and Codex commands at the plugin's launchers, which start the official CLI under the agent's account. **Disable** restores the original commands; use it before removing the plugin.
|
|
7
|
-
- The account chip in the composer opens the switcher for that chat. Your selection applies only when you choose **Apply** while the agent is idle with no pending permission request, and Paseo reloads the agent with its session intact.
|
|
9
|
+
- The account chip in the composer opens the switcher for that chat. Your selection applies only when you choose **Apply** while the agent is idle with no pending permission request, and Paseo reloads the agent with its session intact. If the switch fails, the plugin tries to restore the previous account.
|
|
8
10
|
|
|
9
11
|
## Setup
|
|
10
12
|
|
|
@@ -15,12 +17,13 @@ Account Switcher lets you use several Claude and ChatGPT/Codex subscription acco
|
|
|
15
17
|
## What it reads and sends
|
|
16
18
|
|
|
17
19
|
- It reads each account's stored sign-in: Codex's `auth.json`, and Claude's credentials from the macOS Keychain or the profile's `.credentials.json`. The Codex file identifies the ChatGPT account; the Claude access token authenticates the usage request, and the official CLI reports which Claude account is signed in. Tokens stay on the daemon. Paseo clients receive each account's email, plan, and limits.
|
|
18
|
-
- Claude limits come from a request to `api.anthropic.com` with the account's access token. Codex limits come from the official `codex app-server`, which asks OpenAI and may refresh the account's token. No model messages are sent.
|
|
20
|
+
- Claude limits come from a request to `api.anthropic.com` with the account's access token. When that token has expired, for example on an idle account, the plugin runs `claude -p /usage --no-session-persistence` under the account so the official CLI renews it, at most every 10 minutes. The command sends no model message and saves no session. Codex limits and the plan's model list come from the official `codex app-server`, which asks OpenAI and may refresh the account's token. No model messages are sent.
|
|
19
21
|
- Limits refresh every 5 minutes, and every minute while Accounts or the switcher is open. Missing values show as no data, and a failed refresh can keep the last values, marked stale.
|
|
20
22
|
- Removing a managed account deletes its profile and stored sign-in, including a Claude account's Keychain item on macOS. Shared session history stays.
|
|
21
23
|
|
|
22
24
|
## Limitations
|
|
23
25
|
|
|
24
26
|
- Apply reloads the agent through Paseo, which has no lock against a message sent from another client at the same moment. That message can be interrupted.
|
|
27
|
+
- Plans differ in the models they offer: after a switch to a plan without the agent's model, its next message fails. For Codex, the switcher compares the agent's model with the models the account's plan offers and warns before **Apply**. Claude does not report its models, so there is no such check for Claude.
|
|
25
28
|
- Codex's **In browser** sign-in must finish on the daemon's computer. From another device, use **Device code**.
|
|
26
29
|
- Providers can change their limit formats. Values the plugin cannot read show as no data.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Account Switcher 让你在 Paseo 中使用多个 Claude 和 ChatGPT/Codex 订阅账号。你可以为每个智能体选择账号,切换现有对话的账号,为每个提供商设置默认账号,并查看每个账号的用量限制。切换为手动操作,且只在同一提供商内进行。
|
|
2
|
+
|
|
3
|
+
限制涵盖提供商报告的所有时间窗口,例如 5 小时和每周用量,并显示重置时间。Codex 按用量计费的工作区套餐显示每月额度(credits),Claude 企业席位显示每月消费额度。
|
|
4
|
+
|
|
5
|
+
插件界面为英文,下文中的按钮名称保留英文原文。
|
|
6
|
+
|
|
7
|
+
## 工作原理
|
|
8
|
+
|
|
9
|
+
- 你添加的每个账号都有独立的凭据配置文件。设置、技能和会话历史仍与现有 CLI 配置共享,因此配置文件并不是沙箱。
|
|
10
|
+
- 在 Accounts 中选择 **Enable**,会让 Paseo 的 Claude 和 Codex 命令指向插件的启动器,启动器以智能体所选账号运行官方 CLI。**Disable** 会恢复原始命令;移除插件前请先执行它。
|
|
11
|
+
- 输入框旁的账号标签会打开当前对话的切换器。只有在智能体空闲且没有待处理的权限请求时选择 **Apply**,所选账号才会生效,Paseo 会重新加载智能体并保留会话。如果切换失败,插件会尝试恢复之前的账号。
|
|
12
|
+
|
|
13
|
+
## 设置
|
|
14
|
+
|
|
15
|
+
- macOS 或 Linux 守护进程上的 Paseo 0.8 至 0.13,以及 Node.js 22.12 或更高版本。
|
|
16
|
+
- 守护进程上需要官方 Paseo CLI,以及 Claude Code 或 Codex 至少其一。缺少 CLI 的提供商会显示为不可用;安装后重新加载插件,并在该提供商的分区中选择 **Enable**。
|
|
17
|
+
- 每个账号都需要 Claude 或 ChatGPT 订阅。不支持 API 密钥。添加账号时,会在 Paseo 中运行官方 CLI 登录流程。
|
|
18
|
+
|
|
19
|
+
## 读取和发送的内容
|
|
20
|
+
|
|
21
|
+
- 插件读取每个账号已保存的登录信息:Codex 的 `auth.json`,以及 Claude 存放在 macOS 钥匙串或配置文件 `.credentials.json` 中的凭据。Codex 文件用于识别 ChatGPT 账号;Claude 访问令牌用于用量请求的认证,官方 CLI 报告当前登录的是哪个 Claude 账号。令牌只保留在守护进程上。Paseo 客户端会收到每个账号的邮箱、套餐和限制。
|
|
22
|
+
- Claude 限制来自使用该账号访问令牌向 `api.anthropic.com` 发出的请求。当该令牌过期时(例如账号闲置),插件会以该账号运行 `claude -p /usage --no-session-persistence`,由官方 CLI 续期令牌,每 10 分钟最多一次。该命令不发送模型消息,也不保存会话。Codex 限制和套餐的模型列表来自官方 `codex app-server`,它会向 OpenAI 查询,并可能刷新账号令牌。不会发送任何模型消息。
|
|
23
|
+
- 限制每 5 分钟刷新一次;Accounts 或切换器打开时每分钟刷新一次。缺失的值显示为无数据,刷新失败时可能保留上次的值并标记为过期。
|
|
24
|
+
- 移除托管账号会删除其配置文件和已保存的登录信息,在 macOS 上包括 Claude 账号的钥匙串项。共享的会话历史会保留。
|
|
25
|
+
|
|
26
|
+
## 限制
|
|
27
|
+
|
|
28
|
+
- **Apply** 通过 Paseo 重新加载智能体,而 Paseo 无法锁定同一时刻从另一个客户端发送的消息,该消息可能被中断。
|
|
29
|
+
- 不同套餐提供的模型不同:切换到不提供该智能体模型的套餐后,下一条消息会失败。对于 Codex,切换器会将智能体的模型与该账号套餐提供的模型进行比较,并在 **Apply** 前给出提示。Claude 不报告其模型,因此 Claude 没有此项检查。
|
|
30
|
+
- Codex 的 **In browser** 登录必须在守护进程所在的电脑上完成。在其他设备上请使用 **Device code**。
|
|
31
|
+
- 提供商可能更改限制格式。插件无法读取的值显示为无数据。
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<img src="docs/assets/icon.png" width="88" align="right" alt="">
|
|
2
|
+
|
|
1
3
|
# Account Switcher for Paseo
|
|
2
4
|
|
|
3
5
|
[](https://github.com/dutchakdev/paseo-plugin-account-switcher/actions/workflows/ci.yml) [](https://www.npmjs.com/package/paseo-plugin-account-switcher)
|
|
@@ -91,6 +93,8 @@ You can select an account during a response, but it is **never applied automatic
|
|
|
91
93
|
|
|
92
94
|
Apply reloads the agent through Paseo while preserving its native session ID. The plugin confirms the new account only after startup confirmation and successful reload. If a switch fails, it attempts to restore the previous account. **Account not confirmed** means the running account could not be established; select an account and apply again.
|
|
93
95
|
|
|
96
|
+
Plans differ in the models they offer. A free ChatGPT plan, for example, refuses a model that only paid plans have, and the agent's next message fails with `model_not_found`. For Codex, the plugin reads each account's models with its limits; when the selected account's plan does not offer the agent's model, the dialog says so before **Apply** and lists the models it does offer. Claude does not report its models this way, so the dialog shows no such warning for Claude.
|
|
97
|
+
|
|
94
98
|
Different agents can use different accounts in parallel. Avoid sending from another client during Apply: Paseo's native reload has no atomic lock against a concurrent message, which could be interrupted.
|
|
95
99
|
|
|
96
100
|
## Read limits
|
|
@@ -103,7 +107,7 @@ Each account shows all reported limit windows, including zero usage. Measured wi
|
|
|
103
107
|
- Failed requests can retain the last confirmed values as **stale**. Required sign-in, errors, and freshness remain visible.
|
|
104
108
|
- A passed reset time triggers a new check; it does not imply that usage is already zero.
|
|
105
109
|
|
|
106
|
-
Monitoring sends no model messages. The official CLIs own authentication and token refresh; a native Codex limits request may refresh its token. See [monitor details](server/usage/README.md) for scheduling, identity verification, and cache behavior.
|
|
110
|
+
Monitoring sends no model messages. The official CLIs own authentication and token refresh; a native Codex limits request may refresh its token. A Claude access token expires when no Claude session uses the account for several hours. Before a limits check finds it expired, the plugin runs `claude -p /usage --no-session-persistence` under that account, at most every 10 minutes. This local command lets the CLI renew the token, with no model message and no saved session. **Sign in again** appears only when the CLI cannot renew it. See [monitor details](server/usage/README.md) for scheduling, identity verification, and cache behavior.
|
|
107
111
|
|
|
108
112
|
## Update or remove
|
|
109
113
|
|
package/client/format.ts
CHANGED
|
@@ -77,6 +77,20 @@ export function idleForSwitch(agent: {
|
|
|
77
77
|
return Boolean(agent && agent.status === "idle" && !agent.activeTurn && agent.pendingPermissions.length === 0);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/** The model an agent runs, from its snapshot: running, then configured, then the `provider/model` suffix. */
|
|
81
|
+
export function agentModel(agent: { provider: string; model?: string | null; runtimeInfo?: { model?: string | null } | null } | null | undefined): string | null {
|
|
82
|
+
if (!agent) return null;
|
|
83
|
+
return agent.runtimeInfo?.model || agent.model || agent.provider.split("/")[1] || null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Why the agent's next message would fail on the target account, when the plugin can tell. */
|
|
87
|
+
export function switchRisk(target: { label: string; models?: readonly string[] | null }, model: string | null): string | null {
|
|
88
|
+
// Plans differ in models: a free ChatGPT plan answers `model_not_found` for a paid-only model.
|
|
89
|
+
if (!model || !target.models || target.models.includes(model)) return null;
|
|
90
|
+
const choices = target.models.length ? ` After switching, choose one of its models: ${target.models.join(", ")}.` : "";
|
|
91
|
+
return `${target.label}'s plan does not offer ${model}, so the next message would fail.${choices}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
80
94
|
export function errorMessage(error: unknown): string {
|
|
81
95
|
return error instanceof Error ? error.message : typeof error === "string" ? error : "Could not complete the action. Try again.";
|
|
82
96
|
}
|
package/client/switcher.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { Pressable, Text, View } from "react-native";
|
|
|
5
5
|
import { applySwitch, cliName, missingCli, prepareSwitch, refreshUsage } from "../shared/contracts";
|
|
6
6
|
import { body, Button, heading, InlineAction, muted, Notice, QuotaSummary, row, StatusDot, tabular } from "./components";
|
|
7
7
|
import { useAccountsData, useAction, useNow } from "./data";
|
|
8
|
-
import { currentAccount, currentAccountName, errorMessage, idleForSwitch, providerName, supportedProvider, usageSummary } from "./format";
|
|
8
|
+
import { currentAccount, currentAccountName, errorMessage, agentModel, idleForSwitch, providerName, supportedProvider, switchRisk, usageSummary } from "./format";
|
|
9
9
|
import { accountAvailable } from "./login";
|
|
10
10
|
|
|
11
11
|
type SwitcherCallbacks = { onChanged(): void; openAccounts(): void; runtimeError?: string | null };
|
|
@@ -49,6 +49,7 @@ export function AgentSwitcher({ theme, host, agentId, onChanged, openAccounts, c
|
|
|
49
49
|
const agentState = live.isPending ? { text: "checking agent status", tone: "muted" as const }
|
|
50
50
|
: idle ? { text: "agent idle", tone: "success" as const } : { text: "agent busy · apply after the response", tone: "warning" as const };
|
|
51
51
|
const leave = () => { close(); openAccounts(); };
|
|
52
|
+
const risk = pending ? switchRisk({ label: pending.label, models: usage.data?.accounts.find((item) => item.accountId === pending.id)?.models }, agentModel(live.data)) : null;
|
|
52
53
|
return <View style={{ gap: 12, minWidth: 0 }}>
|
|
53
54
|
<View style={{ flexDirection: "row", alignItems: "flex-start", gap: 8 }}>
|
|
54
55
|
<View style={{ flex: 1, minWidth: 0, gap: 1 }}>
|
|
@@ -100,6 +101,7 @@ export function AgentSwitcher({ theme, host, agentId, onChanged, openAccounts, c
|
|
|
100
101
|
})}
|
|
101
102
|
</View> : null}
|
|
102
103
|
{pending ? <View style={{ gap: 8 }}>
|
|
104
|
+
{risk ? <Notice theme={theme} tone="warning">{risk}</Notice> : null}
|
|
103
105
|
<View style={row}>
|
|
104
106
|
<Button theme={theme} variant="primary" disabled={disabled || !idle || !accountAvailable(pending)} onPress={() => action.run(async () => {
|
|
105
107
|
// Recheck immediately before requesting the daemon's own idle guard.
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-plugin-account-switcher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "paseo-plugin-account-switcher",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.5.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@iarna/toml": "^2.2.5"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-plugin-account-switcher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dutchakdev",
|
|
@@ -13,13 +13,18 @@
|
|
|
13
13
|
],
|
|
14
14
|
"keywords": [
|
|
15
15
|
"paseo",
|
|
16
|
+
"paseo-plugin",
|
|
16
17
|
"plugin",
|
|
17
18
|
"claude",
|
|
19
|
+
"claude-code",
|
|
18
20
|
"codex",
|
|
21
|
+
"chatgpt",
|
|
19
22
|
"accounts",
|
|
20
|
-
"
|
|
23
|
+
"multi-account",
|
|
24
|
+
"quotas",
|
|
25
|
+
"usage-limits"
|
|
21
26
|
],
|
|
22
|
-
"description": "
|
|
27
|
+
"description": "Use several Claude and ChatGPT/Codex subscription accounts in Paseo: choose one per agent, switch a chat to another account, and see every account's limits",
|
|
23
28
|
"scripts": {
|
|
24
29
|
"typecheck": "tsc --noEmit",
|
|
25
30
|
"test": "vitest run --config tests/vitest.config.ts",
|
|
@@ -58,6 +63,7 @@
|
|
|
58
63
|
"paseo-plugin.json",
|
|
59
64
|
"npm-shrinkwrap.json",
|
|
60
65
|
"OVERVIEW.md",
|
|
66
|
+
"OVERVIEW.*.md",
|
|
61
67
|
"index.client.tsx",
|
|
62
68
|
"index.server.ts",
|
|
63
69
|
"client/",
|
package/server/controller.ts
CHANGED
|
@@ -12,9 +12,12 @@ import { accountCommand, accountEnvironment, launchLogin, probeAccount, removeAc
|
|
|
12
12
|
import { installIntegration, restoreIntegration, writeLaunchers, prepareRuntime, reconcileIntegration } from "./integration";
|
|
13
13
|
import { SwitchService } from "./switching";
|
|
14
14
|
import { createUsageService, readCredentialVersion, type AccountReadOptions, type QuotaAccount } from "./usage";
|
|
15
|
+
import { renewExpiredClaudeToken } from "./usage/claude";
|
|
15
16
|
import { LoginSessions, type LoginDependencies } from "./login";
|
|
16
17
|
|
|
17
18
|
const execFileAsync=promisify(execFile);
|
|
19
|
+
// A revoked sign-in fails every renewal; this bounds how often it starts the CLI.
|
|
20
|
+
const RENEWAL_INTERVAL=600000;
|
|
18
21
|
export class AccountController {
|
|
19
22
|
readonly store:AccountStore;
|
|
20
23
|
readonly ready:Promise<void>;
|
|
@@ -22,6 +25,7 @@ export class AccountController {
|
|
|
22
25
|
private readonly checks=new Map<string,Promise<StoredAccount>>();
|
|
23
26
|
private readonly credentialVersions=new Map<string,string>();
|
|
24
27
|
private readonly credentialProofs=new Map<string,{version:string;identityKey:string;generation:number}>();
|
|
28
|
+
private readonly renewals=new Map<string,number>();
|
|
25
29
|
private readonly switches=new Map<PaseoApi,SwitchService>();
|
|
26
30
|
private readonly applying=new Set<string>();
|
|
27
31
|
private runtimeReady:Promise<void>|undefined;
|
|
@@ -116,6 +120,8 @@ export class AccountController {
|
|
|
116
120
|
if(verifyCredentials){
|
|
117
121
|
this.credentialProofs.delete(id);
|
|
118
122
|
const quota=this.toQuotaAccount(account,state);
|
|
123
|
+
// An idle account's token expires with no CLI running to renew it. Renew before the proof, so it covers the new token.
|
|
124
|
+
if(account.provider==="claude"&&Date.now()-(this.renewals.get(id)??-Infinity)>=RENEWAL_INTERVAL&&await renewExpiredClaudeToken(quota))this.renewals.set(id,Date.now());
|
|
119
125
|
for(let attempt=0;;attempt++){
|
|
120
126
|
const before=await readCredentialVersion(quota);
|
|
121
127
|
identity=await probeAccount(account,state);
|
|
@@ -288,7 +294,7 @@ export class AccountController {
|
|
|
288
294
|
for(const path of paths)await rm(path,{recursive:true,force:true});
|
|
289
295
|
});
|
|
290
296
|
await this.usage.invalidate(id);
|
|
291
|
-
this.credentialVersions.delete(account.id);this.credentialProofs.delete(account.id);
|
|
297
|
+
this.credentialVersions.delete(account.id);this.credentialProofs.delete(account.id);this.renewals.delete(account.id);
|
|
292
298
|
}
|
|
293
299
|
async integration(paseo:PaseoApi,enabled:boolean) {
|
|
294
300
|
await this.ready;
|