pi-codex-accounts 0.1.0 → 0.1.2
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 +43 -28
- package/package.json +5 -4
- package/src/index.ts +9 -2
package/README.md
CHANGED
|
@@ -1,51 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
```text
|
|
2
|
+
__ __
|
|
3
|
+
_______ ___/ /____ __ ___ ____________ __ _____ / /____
|
|
4
|
+
/ __/ _ \/ _ / -_) \ / / _ `/ __/ __/ _ \/ // / _ \/ __(_-<
|
|
5
|
+
\__/\___/\_,_/\__/_\_\ \_,_/\__/\__/\___/\_,_/_//_/\__/___/
|
|
6
|
+
|
|
7
|
+
[ work ] <-- /model --> [ personal ]
|
|
8
|
+
```
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
**pi-codex-accounts** keeps your work and personal ChatGPT accounts signed in to [pi](https://pi.dev), side by side.
|
|
4
11
|
|
|
5
|
-
pi's built-in OpenAI Codex provider holds one login.
|
|
6
|
-
|
|
12
|
+
pi's built-in OpenAI Codex provider holds one ChatGPT login.
|
|
13
|
+
If you use one account at work and another for your own projects, switching means logging out and back in every time.
|
|
14
|
+
This little extension gives each account its own login and its own models in `/model`, so switching is just picking a model.
|
|
7
15
|
|
|
8
16
|
```text
|
|
9
|
-
gpt-5.6-sol [openai-codex]
|
|
10
|
-
gpt-5.6-sol [openai-codex-
|
|
17
|
+
gpt-5.6-sol [openai-codex] your personal account (pi's built-in provider)
|
|
18
|
+
gpt-5.6-sol [openai-codex-work] your work account
|
|
11
19
|
```
|
|
12
20
|
|
|
13
|
-
It never switches accounts on its own.
|
|
14
|
-
You choose the account whenever you choose a model.
|
|
15
|
-
|
|
16
21
|
## Install
|
|
17
22
|
|
|
18
23
|
```sh
|
|
19
24
|
pi install npm:pi-codex-accounts
|
|
20
25
|
```
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
Your browser may reuse the ChatGPT account it is already signed into, so use a private window or the device-code option.
|
|
27
|
+
## Set it up
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
1. Name your extra account in `~/.pi/agent/codex-accounts.json`:
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
```json
|
|
32
|
+
{ "accounts": ["work"] }
|
|
33
|
+
```
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
2. Restart pi, run `/login`, choose **Sign in with an account**, and pick **OpenAI Codex (work)**.
|
|
36
|
+
3. Sign in with your work ChatGPT account.
|
|
37
|
+
A private browser window helps, so the browser doesn't reuse the account it is already signed into.
|
|
38
|
+
4. Open `/model` and pick any `[openai-codex-work]` model.
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
Without the file you get one extra account, `openai-codex-2`.
|
|
35
|
-
An empty list adds none.
|
|
36
|
-
pi stores logins under the provider id, so renaming a label means signing in again.
|
|
40
|
+
## The accounts file
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
Each label becomes its own account: `"work"` shows up as **OpenAI Codex (work)**, with the provider id `openai-codex-work`.
|
|
43
|
+
If you have more than one work account, for example one per client, list them all: `{ "accounts": ["work", "client"] }`.
|
|
44
|
+
Without the file you get one extra account, labelled `2`.
|
|
45
|
+
|
|
46
|
+
pi saves each login under the provider id, so renaming a label means signing in again.
|
|
47
|
+
The old login stays listed in `/logout` under its old id, and you can remove it from there.
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
pi keeps each login in `~/.pi/agent/auth.json` under the account's provider id, and requests use that login's token.
|
|
49
|
+
## How it works
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
Each account is pi's own Codex provider under a new id: the same login flow, the same models, and the same request code.
|
|
52
|
+
It behaves like the built-in provider and picks up new Codex models whenever pi updates.
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
Accounts stay separate.
|
|
55
|
+
Each one has its own saved login, and when you switch accounts in the middle of a conversation, one account's encrypted reasoning is never sent to another.
|
|
47
56
|
|
|
48
|
-
|
|
57
|
+
Your tokens stay in pi's `auth.json`.
|
|
58
|
+
The extension never copies them into environment variables, so commands the agent runs can't read them.
|
|
49
59
|
|
|
50
60
|
Tested with pi 0.85.1.
|
|
51
61
|
|
|
@@ -56,4 +66,9 @@ npm install
|
|
|
56
66
|
npm test
|
|
57
67
|
```
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
`npm test` runs the type check, the unit tests, and a smoke test that installs the packed package into pi the way `pi install` does.
|
|
70
|
+
Releases are built on GitHub Actions and published with npm trusted publishing, so every version on npm links back to the commit it came from.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-codex-accounts",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Keep your work and personal ChatGPT (Codex) accounts signed in to pi side by side, and switch between them from /model.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
7
7
|
"pi",
|
|
8
8
|
"pi-extension",
|
|
9
9
|
"codex",
|
|
10
10
|
"openai",
|
|
11
|
-
"chatgpt"
|
|
11
|
+
"chatgpt",
|
|
12
|
+
"accounts"
|
|
12
13
|
],
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"author": "Tiago Peixoto",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
]
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
|
-
"test": "tsc && node --test test/index.test.ts"
|
|
30
|
+
"test": "tsc && node --test test/index.test.ts && sh scripts/smoke.sh"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
33
|
"@earendil-works/pi-ai": "*",
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type Model,
|
|
9
9
|
type Provider,
|
|
10
10
|
} from "@earendil-works/pi-ai";
|
|
11
|
-
import {
|
|
11
|
+
import { builtinProviders } from "@earendil-works/pi-ai/providers/all";
|
|
12
12
|
import { type ExtensionAPI, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
13
13
|
|
|
14
14
|
const CODEX = "openai-codex";
|
|
@@ -29,10 +29,17 @@ export default function codexAccounts(pi: ExtensionAPI) {
|
|
|
29
29
|
} catch (error) {
|
|
30
30
|
throw new Error(`${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
31
31
|
}
|
|
32
|
-
const codex =
|
|
32
|
+
const codex = builtinCodexProvider();
|
|
33
33
|
for (const account of accounts) pi.registerProvider(createAccountProvider(codex, account));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** pi lets extensions import only a few pi-ai entry points; providers/all is the one with the built-in providers. */
|
|
37
|
+
export function builtinCodexProvider(): Provider<CodexApi> {
|
|
38
|
+
const codex = builtinProviders().find((provider) => provider.id === CODEX);
|
|
39
|
+
if (!codex) throw new Error("pi no longer ships a built-in OpenAI Codex provider");
|
|
40
|
+
return codex as Provider<CodexApi>;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
/** The config file's text, or undefined when there is no config file. */
|
|
37
44
|
function readConfig(path: string): string | undefined {
|
|
38
45
|
try {
|