@coda-console/codex 2.0.0 → 2.0.1

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 CHANGED
@@ -28,7 +28,7 @@ Codex Agent:Codex 插件提供的入口运行 codex-acp,报告子 Agent、
28
28
  自动纳入已有登录,添加与移除账号、自动续期、查看额度和使用完全重置,所选账号在会话开始和两轮之间生效。账号的导入、添加与存放见仓库根 README 的「Codex 账号与额度」。
29
29
 
30
30
  - **资源**:另一种资源类型 `accounts`,标题也叫「Codex」,每个账号一个资源,名字是别名(邮箱);本机登录那一种(`login`)这时输出为空,登录入口仍在。
31
- 额度与完全重置的读数同本机登录;会话正在用的那个多一个读数「状态 · 正在使用」。某个账号的登录没有了、过期或无效时,只写在它自己那一行;别的读不到(网络、超时、服务端出错、Codex 没有给出某个账号的任何额度、账号列表读不了)命令以非零退出,原因写在标准错误的最后一行,Coda 保留上一份记录,资源页显示「更新失败:原因」。
31
+ 额度与完全重置的读数同本机登录;会话正在用的那个多一个读数「状态 · 正在使用」。某个账号的登录没有了、过期或无效时,只写在它自己那一行;某个账号的额度读不到(网络、超时、服务端出错、Codex 没有给出它的任何额度)而别的账号读到了时,也只在它那一行写「暂时无法获取额度:原因」,别的账号照常显示;一个账号的额度都没读到、或账号列表读不了时,命令以非零退出,原因写在标准错误的最后一行,Coda 保留上一份记录,资源页显示「更新失败:原因」。
32
32
  所选的账号不在插件里时另有一行「所选账号」写明。至多 40 个账号、合计不超过 60 KiB。旧登录导入失败时记录照写:一行「Codex 账号」写原因,登录入口照常在。记录命令同是 `scripts/resource.mjs`。
33
33
  - **按钮**(在「···」里;操作 `act`,`scripts/act.mjs` 在开关打开时按 `{ action, args }` 分派 `select`、`reset`、`remove`):「切换使用」(先用这个账号核对一次,通过才记下;会话在下一个边界换过去)、
34
34
  「使用完全重置」(同本机登录,用这个账号的令牌)、「移除账号」(删掉插件保存的登录;移除的是正在用的,要再选或添加一个)。
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "codex",
4
4
  "displayName": "Codex",
5
5
  "description": "用 OpenAI Codex 跑会话",
6
- "version": "2.0.0",
6
+ "version": "2.0.1",
7
7
  "engines": {
8
8
  "coda": 6
9
9
  },
package/scripts/quota.mjs CHANGED
@@ -124,23 +124,26 @@ export function managedResource(account, chosen, { result, error }) {
124
124
 
125
125
  // The managed accounts' resources, each read by `read` (at most `at` at once). Empty on a new machine: Coda offers the type's
126
126
  // signIn under「添加资源」. Existing accounts can be added to or signed in again from a row's「重新登录」. A selection of an account
127
- // not signed in here is a row of its own, saying so.
127
+ // not signed in here is a row of its own, saying so. An account whose quota cannot be read for any other reason says so on its
128
+ // row while another account's was read; when none was, the source is what is wrong, and the first of them throws.
128
129
  export async function managedResources(accounts, chosen, read, { at = 4 } = {}) {
129
130
  if (!accounts.length && chosen === null) return { resources: [] };
130
- const shown = accounts.slice(0, ACCOUNTS), readings = new Array(shown.length);
131
- let next = 0, failed;
131
+ const shown = accounts.slice(0, ACCOUNTS), readings = new Array(shown.length), unread = new Map();
132
+ let next = 0, ok = 0;
132
133
  await Promise.all(Array.from({ length: Math.min(at, shown.length) }, async () => {
133
134
  for (let i; (i = next++) < shown.length;) {
134
135
  const account = shown[i];
135
- try { readings[i] = managedResource(account, chosen === account.identity, { result: await read(account) }); }
136
+ try { readings[i] = managedResource(account, chosen === account.identity, { result: await read(account) }); ok++; }
136
137
  catch (error) {
137
- if (!needsSignIn(error)) { failed ??= error; continue; }
138
+ if (!needsSignIn(error)) { unread.set(i, error); continue; }
138
139
  readings[i] = managedResource(account, chosen === account.identity, { error: error instanceof SignInAgain ? error.message : `登录已失效,请重新登录:${error.message}` });
139
140
  }
140
141
  }
141
142
  }));
142
143
  // Every reading is ended first, so that none is left holding an account's lock.
143
- if (failed) throw failed;
144
+ if (unread.size && !ok) throw unread.values().next().value;
145
+ const WHY = '暂时无法获取额度:';
146
+ for (const [i, { message }] of unread) readings[i] = managedResource(shown[i], chosen === shown[i].identity, { error: message.startsWith(WHY) ? message : WHY + message });
144
147
  const out = chosen && !accounts.some(a => a.identity === chosen) ? [{ name: '所选账号', values: [], buttons: [], error: '尚未在插件中登录:重新登录它,或切换到其他账号' }] : [];
145
148
  // The selected account when it is not signed in here comes first, as a row of its own; the record stays within 64 KiB, and
146
149
  // rows past it are left out.
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  // The `coda/resource@1` records of the「Codex」type, printed once: this machine's own login, and with「多账号」on (the setting
3
3
  // `codex.multipleAccounts`) the managed accounts, a type of their own, while this machine's own login shows none. Signing in
4
- // stays offered either way (the CLI comes with the plugin). A login that is gone, expired or unreadable is a row saying so; any
5
- // other failure to read (Codex not answering, the network, a server's error, a damaged store) fails the command (exit 1, the
6
- // reason on the last line of its standard error), which keeps the records Coda has.
4
+ // stays offered either way (the CLI comes with the plugin). A login that is gone, expired or unreadable is a row saying so; so is,
5
+ // with several accounts, one whose quota cannot be read while another's was. Any other failure to read (Codex not answering, the
6
+ // network, a server's error, a damaged store, no account's quota had) fails the command (exit 1, the reason on the last line of
7
+ // its standard error), which keeps the records Coda has.
7
8
  import { withAppServer } from './app-server.mjs';
8
9
  import { list, multipleAccounts, selection, withManagedAccount } from './manager.mjs';
9
10
  import { managedResources, managedUnreadable, needsSignIn, resources, unreadable } from './quota.mjs';