ai-zero-token 1.0.0 → 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.
Files changed (67) hide show
  1. package/README.md +235 -58
  2. package/dist/api.js +0 -1
  3. package/dist/cli/commands/ask.js +131 -5
  4. package/dist/cli/commands/clear.js +0 -1
  5. package/dist/cli/commands/help.js +15 -10
  6. package/dist/cli/commands/login.js +0 -1
  7. package/dist/cli/commands/models.js +0 -1
  8. package/dist/cli/commands/serve.js +42 -4
  9. package/dist/cli/commands/start.js +10 -0
  10. package/dist/cli/commands/status.js +1 -1
  11. package/dist/cli/index.js +4 -1
  12. package/dist/cli/shared.js +57 -6
  13. package/dist/cli.js +0 -1
  14. package/dist/core/context.js +7 -2
  15. package/dist/core/models/openai-codex-models.js +0 -1
  16. package/dist/core/providers/http-client.js +97 -9
  17. package/dist/core/providers/openai-codex/chat.js +217 -24
  18. package/dist/core/providers/openai-codex/oauth.js +15 -4
  19. package/dist/core/providers/openai-codex/pkce.js +0 -1
  20. package/dist/core/services/auth-service.js +89 -16
  21. package/dist/core/services/chat-service.js +24 -14
  22. package/dist/core/services/config-service.js +0 -1
  23. package/dist/core/services/image-service.js +360 -0
  24. package/dist/core/services/model-service.js +4 -2
  25. package/dist/core/store/profile-store.js +79 -6
  26. package/dist/core/store/settings-store.js +1 -2
  27. package/dist/core/types.js +0 -1
  28. package/dist/http.js +0 -1
  29. package/dist/models.js +0 -1
  30. package/dist/oauth.js +0 -1
  31. package/dist/pkce.js +0 -1
  32. package/dist/server/admin-page.js +2615 -0
  33. package/dist/server/app.js +566 -39
  34. package/dist/server/index.js +13 -3
  35. package/dist/store.js +0 -1
  36. package/package.json +14 -6
  37. package/dist/api.js.map +0 -1
  38. package/dist/cli/commands/ask.js.map +0 -1
  39. package/dist/cli/commands/clear.js.map +0 -1
  40. package/dist/cli/commands/help.js.map +0 -1
  41. package/dist/cli/commands/login.js.map +0 -1
  42. package/dist/cli/commands/models.js.map +0 -1
  43. package/dist/cli/commands/serve.js.map +0 -1
  44. package/dist/cli/commands/status.js.map +0 -1
  45. package/dist/cli/index.js.map +0 -1
  46. package/dist/cli/shared.js.map +0 -1
  47. package/dist/cli.js.map +0 -1
  48. package/dist/core/context.js.map +0 -1
  49. package/dist/core/models/openai-codex-models.js.map +0 -1
  50. package/dist/core/providers/http-client.js.map +0 -1
  51. package/dist/core/providers/openai-codex/chat.js.map +0 -1
  52. package/dist/core/providers/openai-codex/oauth.js.map +0 -1
  53. package/dist/core/providers/openai-codex/pkce.js.map +0 -1
  54. package/dist/core/services/auth-service.js.map +0 -1
  55. package/dist/core/services/chat-service.js.map +0 -1
  56. package/dist/core/services/config-service.js.map +0 -1
  57. package/dist/core/services/model-service.js.map +0 -1
  58. package/dist/core/store/profile-store.js.map +0 -1
  59. package/dist/core/store/settings-store.js.map +0 -1
  60. package/dist/core/types.js.map +0 -1
  61. package/dist/http.js.map +0 -1
  62. package/dist/models.js.map +0 -1
  63. package/dist/oauth.js.map +0 -1
  64. package/dist/pkce.js.map +0 -1
  65. package/dist/server/app.js.map +0 -1
  66. package/dist/server/index.js.map +0 -1
  67. 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
- ...profile,
29
- mode: "oauth_account"
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: "127.0.0.1",
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
@@ -1,2 +1 @@
1
1
  #!/usr/bin/env node
2
- //# sourceMappingURL=types.js.map
package/dist/http.js CHANGED
@@ -3,4 +3,3 @@ import { requestText } from "./core/providers/http-client.js";
3
3
  export {
4
4
  requestText
5
5
  };
6
- //# sourceMappingURL=http.js.map
package/dist/models.js CHANGED
@@ -11,4 +11,3 @@ export {
11
11
  SUPPORTED_CODEX_MODELS,
12
12
  isSupportedCodexModel
13
13
  };
14
- //# sourceMappingURL=models.js.map
package/dist/oauth.js CHANGED
@@ -7,4 +7,3 @@ export {
7
7
  loginOpenAICodex,
8
8
  refreshOpenAICodexToken
9
9
  };
10
- //# sourceMappingURL=oauth.js.map
package/dist/pkce.js CHANGED
@@ -3,4 +3,3 @@ import { generatePKCE } from "./core/providers/openai-codex/pkce.js";
3
3
  export {
4
4
  generatePKCE
5
5
  };
6
- //# sourceMappingURL=pkce.js.map