ai-zero-token 1.0.1 → 1.0.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 +227 -70
- package/dist/api.js +0 -1
- package/dist/cli/commands/ask.js +131 -5
- package/dist/cli/commands/clear.js +0 -1
- package/dist/cli/commands/help.js +15 -10
- package/dist/cli/commands/login.js +0 -1
- package/dist/cli/commands/models.js +0 -1
- package/dist/cli/commands/serve.js +41 -4
- package/dist/cli/commands/start.js +10 -0
- package/dist/cli/commands/status.js +1 -1
- package/dist/cli/index.js +4 -1
- package/dist/cli/shared.js +57 -6
- package/dist/cli.js +0 -1
- package/dist/core/context.js +7 -2
- package/dist/core/models/openai-codex-models.js +0 -1
- package/dist/core/providers/http-client.js +97 -9
- package/dist/core/providers/openai-codex/chat.js +217 -24
- package/dist/core/providers/openai-codex/oauth.js +15 -4
- package/dist/core/providers/openai-codex/pkce.js +0 -1
- package/dist/core/services/auth-service.js +89 -16
- package/dist/core/services/chat-service.js +24 -14
- package/dist/core/services/config-service.js +0 -1
- package/dist/core/services/image-service.js +360 -0
- package/dist/core/services/model-service.js +4 -2
- package/dist/core/store/profile-store.js +79 -6
- package/dist/core/store/settings-store.js +1 -2
- package/dist/core/types.js +0 -1
- package/dist/http.js +0 -1
- package/dist/models.js +0 -1
- package/dist/oauth.js +0 -1
- package/dist/pkce.js +0 -1
- package/dist/server/admin-page.js +2615 -0
- package/dist/server/app.js +561 -39
- package/dist/server/index.js +0 -1
- package/dist/store.js +0 -1
- package/package.json +12 -3
- package/dist/api.js.map +0 -1
- package/dist/cli/commands/ask.js.map +0 -1
- package/dist/cli/commands/clear.js.map +0 -1
- package/dist/cli/commands/help.js.map +0 -1
- package/dist/cli/commands/login.js.map +0 -1
- package/dist/cli/commands/models.js.map +0 -1
- package/dist/cli/commands/serve.js.map +0 -1
- package/dist/cli/commands/status.js.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/shared.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/core/context.js.map +0 -1
- package/dist/core/models/openai-codex-models.js.map +0 -1
- package/dist/core/providers/http-client.js.map +0 -1
- package/dist/core/providers/openai-codex/chat.js.map +0 -1
- package/dist/core/providers/openai-codex/oauth.js.map +0 -1
- package/dist/core/providers/openai-codex/pkce.js.map +0 -1
- package/dist/core/services/auth-service.js.map +0 -1
- package/dist/core/services/chat-service.js.map +0 -1
- package/dist/core/services/config-service.js.map +0 -1
- package/dist/core/services/model-service.js.map +0 -1
- package/dist/core/store/profile-store.js.map +0 -1
- package/dist/core/store/settings-store.js.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/http.js.map +0 -1
- package/dist/models.js.map +0 -1
- package/dist/oauth.js.map +0 -1
- package/dist/pkce.js.map +0 -1
- package/dist/server/app.js.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/store.js.map +0 -1
|
@@ -5,12 +5,41 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
const projectDir = path.dirname(fileURLToPath(new URL("../../../package.json", import.meta.url)));
|
|
6
6
|
const stateDir = path.join(projectDir, ".state");
|
|
7
7
|
const storePath = path.join(stateDir, "store.json");
|
|
8
|
+
const PROFILE_CLAIM_PATH = "https://api.openai.com/profile";
|
|
8
9
|
function createEmptyStore() {
|
|
9
10
|
return {
|
|
10
11
|
version: 1,
|
|
11
12
|
profiles: {}
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
function decodeJwtPayload(token) {
|
|
16
|
+
try {
|
|
17
|
+
const parts = token.split(".");
|
|
18
|
+
if (parts.length !== 3) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const payload = parts[1] ?? "";
|
|
22
|
+
const normalized = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
23
|
+
const padding = normalized.length % 4 === 0 ? "" : "=".repeat(4 - normalized.length % 4);
|
|
24
|
+
const decoded = Buffer.from(normalized + padding, "base64").toString("utf8");
|
|
25
|
+
return JSON.parse(decoded);
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function extractEmailFromAccessToken(token) {
|
|
31
|
+
const payload = decodeJwtPayload(token);
|
|
32
|
+
const profileClaim = payload?.[PROFILE_CLAIM_PATH];
|
|
33
|
+
const email = profileClaim?.email;
|
|
34
|
+
if (typeof email === "string" && email.trim()) {
|
|
35
|
+
return email.trim();
|
|
36
|
+
}
|
|
37
|
+
const topLevelEmail = payload?.email;
|
|
38
|
+
if (typeof topLevelEmail === "string" && topLevelEmail.trim()) {
|
|
39
|
+
return topLevelEmail.trim();
|
|
40
|
+
}
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
14
43
|
function getStateDir() {
|
|
15
44
|
return stateDir;
|
|
16
45
|
}
|
|
@@ -24,10 +53,14 @@ async function loadStore() {
|
|
|
24
53
|
const normalizedProfiles = Object.fromEntries(
|
|
25
54
|
Object.entries(parsed.profiles ?? {}).map(([profileId, profile]) => [
|
|
26
55
|
profileId,
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
56
|
+
(() => {
|
|
57
|
+
const recoveredEmail = typeof profile.email === "string" && profile.email.trim() ? profile.email.trim() : extractEmailFromAccessToken(profile.access);
|
|
58
|
+
return {
|
|
59
|
+
...profile,
|
|
60
|
+
mode: "oauth_account",
|
|
61
|
+
email: recoveredEmail
|
|
62
|
+
};
|
|
63
|
+
})()
|
|
31
64
|
])
|
|
32
65
|
);
|
|
33
66
|
return {
|
|
@@ -50,6 +83,31 @@ async function saveProfile(profile) {
|
|
|
50
83
|
store.activeProfileId = profile.profileId;
|
|
51
84
|
await saveStore(store);
|
|
52
85
|
}
|
|
86
|
+
async function updateProfile(profileId, updater) {
|
|
87
|
+
const store = await loadStore();
|
|
88
|
+
const profile = store.profiles[profileId];
|
|
89
|
+
if (!profile) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const updated = updater(profile);
|
|
93
|
+
store.profiles[profileId] = updated;
|
|
94
|
+
await saveStore(store);
|
|
95
|
+
return updated;
|
|
96
|
+
}
|
|
97
|
+
async function listProfiles() {
|
|
98
|
+
const store = await loadStore();
|
|
99
|
+
return Object.values(store.profiles);
|
|
100
|
+
}
|
|
101
|
+
async function setActiveProfile(profileId) {
|
|
102
|
+
const store = await loadStore();
|
|
103
|
+
const profile = store.profiles[profileId];
|
|
104
|
+
if (!profile) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
store.activeProfileId = profileId;
|
|
108
|
+
await saveStore(store);
|
|
109
|
+
return profile;
|
|
110
|
+
}
|
|
53
111
|
async function getActiveProfile() {
|
|
54
112
|
const store = await loadStore();
|
|
55
113
|
const activeId = store.activeProfileId?.trim();
|
|
@@ -59,6 +117,18 @@ async function getActiveProfile() {
|
|
|
59
117
|
const first = Object.values(store.profiles)[0];
|
|
60
118
|
return first ?? null;
|
|
61
119
|
}
|
|
120
|
+
async function removeProfile(profileId) {
|
|
121
|
+
const store = await loadStore();
|
|
122
|
+
if (!store.profiles[profileId]) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
delete store.profiles[profileId];
|
|
126
|
+
if (store.activeProfileId === profileId) {
|
|
127
|
+
store.activeProfileId = Object.keys(store.profiles)[0];
|
|
128
|
+
}
|
|
129
|
+
await saveStore(store);
|
|
130
|
+
return store.activeProfileId ? store.profiles[store.activeProfileId] ?? null : null;
|
|
131
|
+
}
|
|
62
132
|
async function clearStore() {
|
|
63
133
|
await fs.rm(stateDir, { recursive: true, force: true });
|
|
64
134
|
}
|
|
@@ -67,8 +137,11 @@ export {
|
|
|
67
137
|
getActiveProfile,
|
|
68
138
|
getStateDir,
|
|
69
139
|
getStorePath,
|
|
140
|
+
listProfiles,
|
|
70
141
|
loadStore,
|
|
142
|
+
removeProfile,
|
|
71
143
|
saveProfile,
|
|
72
|
-
saveStore
|
|
144
|
+
saveStore,
|
|
145
|
+
setActiveProfile,
|
|
146
|
+
updateProfile
|
|
73
147
|
};
|
|
74
|
-
//# sourceMappingURL=profile-store.js.map
|
|
@@ -11,7 +11,7 @@ function createDefaultSettings() {
|
|
|
11
11
|
defaultProvider: "openai-codex",
|
|
12
12
|
defaultModel: "gpt-5.4",
|
|
13
13
|
server: {
|
|
14
|
-
host: "
|
|
14
|
+
host: "0.0.0.0",
|
|
15
15
|
port: 8787
|
|
16
16
|
}
|
|
17
17
|
};
|
|
@@ -48,4 +48,3 @@ export {
|
|
|
48
48
|
loadSettings,
|
|
49
49
|
saveSettings
|
|
50
50
|
};
|
|
51
|
-
//# sourceMappingURL=settings-store.js.map
|
package/dist/core/types.js
CHANGED
package/dist/http.js
CHANGED
package/dist/models.js
CHANGED
package/dist/oauth.js
CHANGED
package/dist/pkce.js
CHANGED