@pixelbyte-software/pixcode 1.33.6 → 1.33.8
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/dist/assets/index-B1ghfb4w.css +32 -0
- package/dist/assets/{index-D6ErCuvV.js → index-JU38YIxa.js} +148 -148
- package/dist/favicon.svg +8 -8
- package/dist/icons/icon-128x128.svg +9 -9
- package/dist/icons/icon-144x144.svg +9 -9
- package/dist/icons/icon-152x152.svg +9 -9
- package/dist/icons/icon-192x192.svg +9 -9
- package/dist/icons/icon-384x384.svg +9 -9
- package/dist/icons/icon-512x512.svg +9 -9
- package/dist/icons/icon-72x72.svg +9 -9
- package/dist/icons/icon-96x96.svg +9 -9
- package/dist/icons/icon-template.svg +9 -9
- package/dist/index.html +2 -2
- package/dist/logo.svg +12 -12
- package/package.json +1 -1
- package/server/database/db.js +794 -794
- package/server/database/json-store.js +194 -194
- package/server/modules/providers/list/opencode/opencode-auth.provider.ts +130 -130
- package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -126
- package/server/modules/providers/list/opencode/opencode-sessions.provider.ts +193 -193
- package/server/modules/providers/list/opencode/opencode.provider.ts +29 -29
- package/server/modules/providers/list/qwen/qwen-auth.provider.ts +145 -145
- package/server/modules/providers/list/qwen/qwen-mcp.provider.ts +114 -114
- package/server/modules/providers/list/qwen/qwen-sessions.provider.ts +218 -218
- package/server/modules/providers/list/qwen/qwen.provider.ts +21 -21
- package/server/modules/providers/shared/provider-configs.ts +142 -142
- package/server/qwen-code-cli.js +395 -395
- package/server/qwen-response-handler.js +73 -73
- package/server/routes/qwen.js +27 -27
- package/server/services/external-access.js +171 -171
- package/server/services/provider-credentials.js +155 -155
- package/server/services/provider-models.js +381 -381
- package/server/services/telegram/telegram-http-client.js +130 -130
- package/server/services/vapid-keys.js +36 -36
- package/server/utils/port-access.js +209 -209
- package/dist/assets/index-cWbTlXsr.css +0 -32
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import { promises as fs } from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Central credentials store for CLI providers.
|
|
7
|
-
*
|
|
8
|
-
* File: `~/.pixcode/provider-credentials.json`. Lets the UI save an API key
|
|
9
|
-
* (and optional base URL for OpenAI-compatible providers) once and have it
|
|
10
|
-
* picked up by:
|
|
11
|
-
* - the spawn adapters (claude-sdk.js, cursor-cli.js, openai-codex.js,
|
|
12
|
-
* gemini-cli.js, qwen-code-cli.js) when they launch the CLI subprocess
|
|
13
|
-
* - the provider-auth modules as an additional "authenticated" signal
|
|
14
|
-
*
|
|
15
|
-
* Keeping credentials in one file instead of per-CLI config files means we
|
|
16
|
-
* don't have to learn each CLI's settings schema just to set an API key,
|
|
17
|
-
* and users see one "Logout" button that actually clears everything.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
const CONFIG_FILE = path.join(os.homedir(), '.pixcode', 'provider-credentials.json');
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Map provider id → {apiKeyEnv, baseUrlEnv} so we know which env vars to
|
|
24
|
-
* inject into the spawn env. Cursor is OAuth-only; it has no api-key entry.
|
|
25
|
-
*/
|
|
26
|
-
export const PROVIDER_ENV_VARS = Object.freeze({
|
|
27
|
-
claude: { apiKeyEnv: 'ANTHROPIC_API_KEY', baseUrlEnv: 'ANTHROPIC_BASE_URL' },
|
|
28
|
-
codex: { apiKeyEnv: 'OPENAI_API_KEY', baseUrlEnv: 'OPENAI_BASE_URL' },
|
|
29
|
-
gemini: { apiKeyEnv: 'GEMINI_API_KEY', baseUrlEnv: null },
|
|
30
|
-
qwen: { apiKeyEnv: 'OPENAI_API_KEY', baseUrlEnv: 'OPENAI_BASE_URL' },
|
|
31
|
-
// OpenCode is multi-provider. Set ANTHROPIC_API_KEY by default since
|
|
32
|
-
// Claude is OpenCode Zen's recommended backend; users wanting OpenAI
|
|
33
|
-
// or OpenRouter can override via the opencode.json `provider` block.
|
|
34
|
-
opencode: { apiKeyEnv: 'ANTHROPIC_API_KEY', baseUrlEnv: 'ANTHROPIC_BASE_URL' },
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
async function readStore() {
|
|
38
|
-
try {
|
|
39
|
-
const raw = await fs.readFile(CONFIG_FILE, 'utf8');
|
|
40
|
-
const parsed = JSON.parse(raw);
|
|
41
|
-
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
42
|
-
} catch {
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function writeStore(next) {
|
|
48
|
-
await fs.mkdir(path.dirname(CONFIG_FILE), { recursive: true });
|
|
49
|
-
await fs.writeFile(CONFIG_FILE, JSON.stringify(next, null, 2), { mode: 0o600 });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Returns `{ apiKey, baseUrl }` for the given provider, or `null` if no key
|
|
54
|
-
* is stored. Safe to call on any provider id — unknown ids yield null.
|
|
55
|
-
*/
|
|
56
|
-
export async function getProviderCredentials(provider) {
|
|
57
|
-
const store = await readStore();
|
|
58
|
-
const entry = store[provider];
|
|
59
|
-
if (!entry || typeof entry !== 'object') return null;
|
|
60
|
-
const apiKey = typeof entry.apiKey === 'string' && entry.apiKey.trim() ? entry.apiKey.trim() : null;
|
|
61
|
-
if (!apiKey) return null;
|
|
62
|
-
const baseUrl = typeof entry.baseUrl === 'string' && entry.baseUrl.trim() ? entry.baseUrl.trim() : null;
|
|
63
|
-
return { apiKey, baseUrl };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Persist credentials; empty string apiKey deletes the entry. */
|
|
67
|
-
export async function setProviderCredentials(provider, { apiKey, baseUrl }) {
|
|
68
|
-
const store = await readStore();
|
|
69
|
-
const trimmedKey = typeof apiKey === 'string' ? apiKey.trim() : '';
|
|
70
|
-
if (!trimmedKey) {
|
|
71
|
-
delete store[provider];
|
|
72
|
-
} else {
|
|
73
|
-
store[provider] = {
|
|
74
|
-
apiKey: trimmedKey,
|
|
75
|
-
baseUrl: typeof baseUrl === 'string' && baseUrl.trim() ? baseUrl.trim() : null,
|
|
76
|
-
updatedAt: new Date().toISOString(),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
await writeStore(store);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function clearProviderCredentials(provider) {
|
|
83
|
-
await setProviderCredentials(provider, { apiKey: '', baseUrl: null });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Builds an env object that inherits from the server process env and
|
|
88
|
-
* overlays stored credentials for the given provider. Use when spawning
|
|
89
|
-
* a CLI subprocess so the user's Pixcode-configured key is available
|
|
90
|
-
* without leaking unrelated provider keys into the child.
|
|
91
|
-
*/
|
|
92
|
-
export async function buildSpawnEnv(provider, baseEnv = process.env) {
|
|
93
|
-
const envVars = PROVIDER_ENV_VARS[provider];
|
|
94
|
-
const env = { ...baseEnv };
|
|
95
|
-
if (!envVars) return env;
|
|
96
|
-
|
|
97
|
-
const creds = await getProviderCredentials(provider);
|
|
98
|
-
if (!creds) return env;
|
|
99
|
-
|
|
100
|
-
if (envVars.apiKeyEnv) env[envVars.apiKeyEnv] = creds.apiKey;
|
|
101
|
-
if (envVars.baseUrlEnv && creds.baseUrl) env[envVars.baseUrlEnv] = creds.baseUrl;
|
|
102
|
-
return env;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Apply stored credentials onto `process.env` for every known provider.
|
|
107
|
-
* Called on server boot so SDK-based integrations (Claude, Codex) see the
|
|
108
|
-
* API keys without reading our credentials file directly. Subprocess spawns
|
|
109
|
-
* go through `buildSpawnEnv` which layers on top of this.
|
|
110
|
-
*/
|
|
111
|
-
export async function applyAllStoredCredentialsToEnv() {
|
|
112
|
-
const store = await readStore();
|
|
113
|
-
for (const [provider, envVars] of Object.entries(PROVIDER_ENV_VARS)) {
|
|
114
|
-
const entry = store[provider];
|
|
115
|
-
if (!entry || typeof entry !== 'object') continue;
|
|
116
|
-
const apiKey = typeof entry.apiKey === 'string' ? entry.apiKey.trim() : '';
|
|
117
|
-
const baseUrl = typeof entry.baseUrl === 'string' ? entry.baseUrl.trim() : '';
|
|
118
|
-
if (envVars.apiKeyEnv && apiKey) process.env[envVars.apiKeyEnv] = apiKey;
|
|
119
|
-
if (envVars.baseUrlEnv && baseUrl) process.env[envVars.baseUrlEnv] = baseUrl;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Sync a single provider's credentials into `process.env` (or clear them
|
|
125
|
-
* when no key is set). Call after mutating the store via the API so the
|
|
126
|
-
* effect is immediate instead of needing a restart.
|
|
127
|
-
*/
|
|
128
|
-
export async function applyProviderCredentialsToEnv(provider) {
|
|
129
|
-
const envVars = PROVIDER_ENV_VARS[provider];
|
|
130
|
-
if (!envVars) return;
|
|
131
|
-
const creds = await getProviderCredentials(provider);
|
|
132
|
-
if (envVars.apiKeyEnv) {
|
|
133
|
-
if (creds?.apiKey) process.env[envVars.apiKeyEnv] = creds.apiKey;
|
|
134
|
-
else delete process.env[envVars.apiKeyEnv];
|
|
135
|
-
}
|
|
136
|
-
if (envVars.baseUrlEnv) {
|
|
137
|
-
if (creds?.baseUrl) process.env[envVars.baseUrlEnv] = creds.baseUrl;
|
|
138
|
-
else delete process.env[envVars.baseUrlEnv];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** Listing + logout helpers for the UI. */
|
|
143
|
-
export async function listProviderCredentialSummaries() {
|
|
144
|
-
const store = await readStore();
|
|
145
|
-
const out = {};
|
|
146
|
-
for (const key of Object.keys(PROVIDER_ENV_VARS)) {
|
|
147
|
-
const entry = store[key];
|
|
148
|
-
out[key] = {
|
|
149
|
-
hasKey: Boolean(entry && typeof entry.apiKey === 'string' && entry.apiKey.trim()),
|
|
150
|
-
baseUrl: entry && typeof entry.baseUrl === 'string' && entry.baseUrl.trim() ? entry.baseUrl.trim() : null,
|
|
151
|
-
updatedAt: entry && typeof entry.updatedAt === 'string' ? entry.updatedAt : null,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return out;
|
|
155
|
-
}
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Central credentials store for CLI providers.
|
|
7
|
+
*
|
|
8
|
+
* File: `~/.pixcode/provider-credentials.json`. Lets the UI save an API key
|
|
9
|
+
* (and optional base URL for OpenAI-compatible providers) once and have it
|
|
10
|
+
* picked up by:
|
|
11
|
+
* - the spawn adapters (claude-sdk.js, cursor-cli.js, openai-codex.js,
|
|
12
|
+
* gemini-cli.js, qwen-code-cli.js) when they launch the CLI subprocess
|
|
13
|
+
* - the provider-auth modules as an additional "authenticated" signal
|
|
14
|
+
*
|
|
15
|
+
* Keeping credentials in one file instead of per-CLI config files means we
|
|
16
|
+
* don't have to learn each CLI's settings schema just to set an API key,
|
|
17
|
+
* and users see one "Logout" button that actually clears everything.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const CONFIG_FILE = path.join(os.homedir(), '.pixcode', 'provider-credentials.json');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Map provider id → {apiKeyEnv, baseUrlEnv} so we know which env vars to
|
|
24
|
+
* inject into the spawn env. Cursor is OAuth-only; it has no api-key entry.
|
|
25
|
+
*/
|
|
26
|
+
export const PROVIDER_ENV_VARS = Object.freeze({
|
|
27
|
+
claude: { apiKeyEnv: 'ANTHROPIC_API_KEY', baseUrlEnv: 'ANTHROPIC_BASE_URL' },
|
|
28
|
+
codex: { apiKeyEnv: 'OPENAI_API_KEY', baseUrlEnv: 'OPENAI_BASE_URL' },
|
|
29
|
+
gemini: { apiKeyEnv: 'GEMINI_API_KEY', baseUrlEnv: null },
|
|
30
|
+
qwen: { apiKeyEnv: 'OPENAI_API_KEY', baseUrlEnv: 'OPENAI_BASE_URL' },
|
|
31
|
+
// OpenCode is multi-provider. Set ANTHROPIC_API_KEY by default since
|
|
32
|
+
// Claude is OpenCode Zen's recommended backend; users wanting OpenAI
|
|
33
|
+
// or OpenRouter can override via the opencode.json `provider` block.
|
|
34
|
+
opencode: { apiKeyEnv: 'ANTHROPIC_API_KEY', baseUrlEnv: 'ANTHROPIC_BASE_URL' },
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
async function readStore() {
|
|
38
|
+
try {
|
|
39
|
+
const raw = await fs.readFile(CONFIG_FILE, 'utf8');
|
|
40
|
+
const parsed = JSON.parse(raw);
|
|
41
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
42
|
+
} catch {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function writeStore(next) {
|
|
48
|
+
await fs.mkdir(path.dirname(CONFIG_FILE), { recursive: true });
|
|
49
|
+
await fs.writeFile(CONFIG_FILE, JSON.stringify(next, null, 2), { mode: 0o600 });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns `{ apiKey, baseUrl }` for the given provider, or `null` if no key
|
|
54
|
+
* is stored. Safe to call on any provider id — unknown ids yield null.
|
|
55
|
+
*/
|
|
56
|
+
export async function getProviderCredentials(provider) {
|
|
57
|
+
const store = await readStore();
|
|
58
|
+
const entry = store[provider];
|
|
59
|
+
if (!entry || typeof entry !== 'object') return null;
|
|
60
|
+
const apiKey = typeof entry.apiKey === 'string' && entry.apiKey.trim() ? entry.apiKey.trim() : null;
|
|
61
|
+
if (!apiKey) return null;
|
|
62
|
+
const baseUrl = typeof entry.baseUrl === 'string' && entry.baseUrl.trim() ? entry.baseUrl.trim() : null;
|
|
63
|
+
return { apiKey, baseUrl };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Persist credentials; empty string apiKey deletes the entry. */
|
|
67
|
+
export async function setProviderCredentials(provider, { apiKey, baseUrl }) {
|
|
68
|
+
const store = await readStore();
|
|
69
|
+
const trimmedKey = typeof apiKey === 'string' ? apiKey.trim() : '';
|
|
70
|
+
if (!trimmedKey) {
|
|
71
|
+
delete store[provider];
|
|
72
|
+
} else {
|
|
73
|
+
store[provider] = {
|
|
74
|
+
apiKey: trimmedKey,
|
|
75
|
+
baseUrl: typeof baseUrl === 'string' && baseUrl.trim() ? baseUrl.trim() : null,
|
|
76
|
+
updatedAt: new Date().toISOString(),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
await writeStore(store);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function clearProviderCredentials(provider) {
|
|
83
|
+
await setProviderCredentials(provider, { apiKey: '', baseUrl: null });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Builds an env object that inherits from the server process env and
|
|
88
|
+
* overlays stored credentials for the given provider. Use when spawning
|
|
89
|
+
* a CLI subprocess so the user's Pixcode-configured key is available
|
|
90
|
+
* without leaking unrelated provider keys into the child.
|
|
91
|
+
*/
|
|
92
|
+
export async function buildSpawnEnv(provider, baseEnv = process.env) {
|
|
93
|
+
const envVars = PROVIDER_ENV_VARS[provider];
|
|
94
|
+
const env = { ...baseEnv };
|
|
95
|
+
if (!envVars) return env;
|
|
96
|
+
|
|
97
|
+
const creds = await getProviderCredentials(provider);
|
|
98
|
+
if (!creds) return env;
|
|
99
|
+
|
|
100
|
+
if (envVars.apiKeyEnv) env[envVars.apiKeyEnv] = creds.apiKey;
|
|
101
|
+
if (envVars.baseUrlEnv && creds.baseUrl) env[envVars.baseUrlEnv] = creds.baseUrl;
|
|
102
|
+
return env;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Apply stored credentials onto `process.env` for every known provider.
|
|
107
|
+
* Called on server boot so SDK-based integrations (Claude, Codex) see the
|
|
108
|
+
* API keys without reading our credentials file directly. Subprocess spawns
|
|
109
|
+
* go through `buildSpawnEnv` which layers on top of this.
|
|
110
|
+
*/
|
|
111
|
+
export async function applyAllStoredCredentialsToEnv() {
|
|
112
|
+
const store = await readStore();
|
|
113
|
+
for (const [provider, envVars] of Object.entries(PROVIDER_ENV_VARS)) {
|
|
114
|
+
const entry = store[provider];
|
|
115
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
116
|
+
const apiKey = typeof entry.apiKey === 'string' ? entry.apiKey.trim() : '';
|
|
117
|
+
const baseUrl = typeof entry.baseUrl === 'string' ? entry.baseUrl.trim() : '';
|
|
118
|
+
if (envVars.apiKeyEnv && apiKey) process.env[envVars.apiKeyEnv] = apiKey;
|
|
119
|
+
if (envVars.baseUrlEnv && baseUrl) process.env[envVars.baseUrlEnv] = baseUrl;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sync a single provider's credentials into `process.env` (or clear them
|
|
125
|
+
* when no key is set). Call after mutating the store via the API so the
|
|
126
|
+
* effect is immediate instead of needing a restart.
|
|
127
|
+
*/
|
|
128
|
+
export async function applyProviderCredentialsToEnv(provider) {
|
|
129
|
+
const envVars = PROVIDER_ENV_VARS[provider];
|
|
130
|
+
if (!envVars) return;
|
|
131
|
+
const creds = await getProviderCredentials(provider);
|
|
132
|
+
if (envVars.apiKeyEnv) {
|
|
133
|
+
if (creds?.apiKey) process.env[envVars.apiKeyEnv] = creds.apiKey;
|
|
134
|
+
else delete process.env[envVars.apiKeyEnv];
|
|
135
|
+
}
|
|
136
|
+
if (envVars.baseUrlEnv) {
|
|
137
|
+
if (creds?.baseUrl) process.env[envVars.baseUrlEnv] = creds.baseUrl;
|
|
138
|
+
else delete process.env[envVars.baseUrlEnv];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Listing + logout helpers for the UI. */
|
|
143
|
+
export async function listProviderCredentialSummaries() {
|
|
144
|
+
const store = await readStore();
|
|
145
|
+
const out = {};
|
|
146
|
+
for (const key of Object.keys(PROVIDER_ENV_VARS)) {
|
|
147
|
+
const entry = store[key];
|
|
148
|
+
out[key] = {
|
|
149
|
+
hasKey: Boolean(entry && typeof entry.apiKey === 'string' && entry.apiKey.trim()),
|
|
150
|
+
baseUrl: entry && typeof entry.baseUrl === 'string' && entry.baseUrl.trim() ? entry.baseUrl.trim() : null,
|
|
151
|
+
updatedAt: entry && typeof entry.updatedAt === 'string' ? entry.updatedAt : null,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
}
|