@pixelbyte-software/pixcode 1.31.13 → 1.33.0
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-Byb8Wnts.css +32 -0
- package/dist/assets/{index-oxZnRcf8.js → index-CZKV8Tbj.js} +163 -151
- package/dist/index.html +2 -2
- package/dist-server/server/database/db.js +542 -460
- package/dist-server/server/database/db.js.map +1 -1
- package/dist-server/server/database/json-store.js +184 -0
- package/dist-server/server/database/json-store.js.map +1 -0
- package/dist-server/server/index.js +16 -1
- package/dist-server/server/index.js.map +1 -1
- package/dist-server/server/modules/providers/list/opencode/opencode-auth.provider.js +113 -0
- package/dist-server/server/modules/providers/list/opencode/opencode-auth.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/opencode/opencode-mcp.provider.js +98 -0
- package/dist-server/server/modules/providers/list/opencode/opencode-mcp.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/opencode/opencode-sessions.provider.js +138 -0
- package/dist-server/server/modules/providers/list/opencode/opencode-sessions.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/opencode/opencode.provider.js +27 -0
- package/dist-server/server/modules/providers/list/opencode/opencode.provider.js.map +1 -0
- package/dist-server/server/modules/providers/provider.registry.js +2 -0
- package/dist-server/server/modules/providers/provider.registry.js.map +1 -1
- package/dist-server/server/modules/providers/provider.routes.js +4 -1
- package/dist-server/server/modules/providers/provider.routes.js.map +1 -1
- package/dist-server/server/modules/providers/shared/provider-configs.js +24 -0
- package/dist-server/server/modules/providers/shared/provider-configs.js.map +1 -1
- package/dist-server/server/routes/auth.js +5 -1
- package/dist-server/server/routes/auth.js.map +1 -1
- package/dist-server/server/routes/network.js +14 -21
- package/dist-server/server/routes/network.js.map +1 -1
- package/dist-server/server/services/external-access.js +18 -78
- package/dist-server/server/services/external-access.js.map +1 -1
- package/dist-server/server/services/install-jobs.js +2 -0
- package/dist-server/server/services/install-jobs.js.map +1 -1
- package/dist-server/server/services/provider-credentials.js +4 -0
- package/dist-server/server/services/provider-credentials.js.map +1 -1
- package/dist-server/server/services/telegram/bot.js +6 -6
- package/dist-server/server/services/telegram/bot.js.map +1 -1
- package/dist-server/server/services/telegram/telegram-http-client.js +130 -0
- package/dist-server/server/services/telegram/telegram-http-client.js.map +1 -0
- package/dist-server/server/services/vapid-keys.js +3 -3
- package/dist-server/server/services/vapid-keys.js.map +1 -1
- package/dist-server/shared/modelConstants.js +20 -0
- package/dist-server/shared/modelConstants.js.map +1 -1
- package/package.json +178 -178
- package/server/database/db.js +794 -696
- package/server/database/json-store.js +194 -0
- package/server/index.js +14 -1
- package/server/modules/providers/list/opencode/opencode-auth.provider.ts +130 -0
- package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -0
- package/server/modules/providers/list/opencode/opencode-sessions.provider.ts +155 -0
- package/server/modules/providers/list/opencode/opencode.provider.ts +29 -0
- package/server/modules/providers/provider.registry.ts +2 -0
- package/server/modules/providers/provider.routes.ts +4 -0
- package/server/modules/providers/shared/provider-configs.ts +24 -0
- package/server/routes/auth.js +5 -1
- package/server/routes/network.js +13 -21
- package/server/services/external-access.js +171 -240
- package/server/services/install-jobs.js +2 -0
- package/server/services/provider-credentials.js +8 -4
- package/server/services/telegram/bot.js +6 -7
- package/server/services/telegram/telegram-http-client.js +130 -0
- package/server/services/vapid-keys.js +36 -35
- package/server/shared/types.ts +1 -1
- package/shared/modelConstants.js +22 -0
- package/dist/assets/index-CLxSMbv1.css +0 -32
- package/dist-server/server/database/schema.js +0 -130
- package/dist-server/server/database/schema.js.map +0 -1
- package/server/database/schema.js +0 -138
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
GEMINI_MODELS,
|
|
30
30
|
QWEN_MODELS,
|
|
31
31
|
CURSOR_MODELS,
|
|
32
|
+
OPENCODE_MODELS,
|
|
32
33
|
} from '../../../shared/modelConstants.js';
|
|
33
34
|
|
|
34
35
|
const STATIC_MODELS_BY_PROVIDER: Record<LLMProvider, Array<{ value: string; label: string }>> = {
|
|
@@ -37,6 +38,7 @@ const STATIC_MODELS_BY_PROVIDER: Record<LLMProvider, Array<{ value: string; labe
|
|
|
37
38
|
cursor: CURSOR_MODELS.OPTIONS,
|
|
38
39
|
gemini: GEMINI_MODELS.OPTIONS,
|
|
39
40
|
qwen: QWEN_MODELS.OPTIONS,
|
|
41
|
+
opencode: OPENCODE_MODELS.OPTIONS,
|
|
40
42
|
};
|
|
41
43
|
import type { LLMProvider, McpScope, McpTransport, UpsertProviderMcpServerInput } from '@/shared/types.js';
|
|
42
44
|
import { AppError, asyncHandler, createApiSuccessResponse } from '@/shared/utils.js';
|
|
@@ -68,6 +70,7 @@ const PROVIDER_INSTALL_PACKAGES: Record<LLMProvider, string | null> = {
|
|
|
68
70
|
codex: '@openai/codex',
|
|
69
71
|
gemini: '@google/gemini-cli',
|
|
70
72
|
qwen: '@qwen-code/qwen-code',
|
|
73
|
+
opencode: 'opencode-ai',
|
|
71
74
|
// Cursor ships via a bash script hosted at cursor.com; safer to ask
|
|
72
75
|
// users to run it themselves than to pipe-to-bash from our server.
|
|
73
76
|
cursor: null,
|
|
@@ -78,6 +81,7 @@ const PROVIDER_INSTALL_COMMANDS: Record<LLMProvider, string | null> = {
|
|
|
78
81
|
codex: 'npm install -g @openai/codex',
|
|
79
82
|
gemini: 'npm install -g @google/gemini-cli',
|
|
80
83
|
qwen: 'npm install -g @qwen-code/qwen-code',
|
|
84
|
+
opencode: 'npm install -g opencode-ai',
|
|
81
85
|
cursor: null,
|
|
82
86
|
};
|
|
83
87
|
|
|
@@ -108,6 +108,30 @@ export const PROVIDER_CONFIG_FILES: Record<string, ProviderConfigFile[]> = {
|
|
|
108
108
|
description: 'Environment variables (DASHSCOPE_API_KEY, OPENAI_API_KEY for OpenAI-compatible routes, …).',
|
|
109
109
|
},
|
|
110
110
|
],
|
|
111
|
+
opencode: [
|
|
112
|
+
{
|
|
113
|
+
id: 'config',
|
|
114
|
+
label: 'opencode.json',
|
|
115
|
+
relativePath: '.config/opencode/opencode.json',
|
|
116
|
+
format: 'json',
|
|
117
|
+
description: 'Main OpenCode config — provider, model, MCP servers, permission rules, agents.',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 'tui',
|
|
121
|
+
label: 'tui.json',
|
|
122
|
+
relativePath: '.config/opencode/tui.json',
|
|
123
|
+
format: 'json',
|
|
124
|
+
description: 'Terminal UI preferences (theme, keybinds). Separate from the main config since 2026-02.',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'auth',
|
|
128
|
+
label: 'auth.json',
|
|
129
|
+
relativePath: '.local/share/opencode/auth.json',
|
|
130
|
+
format: 'json',
|
|
131
|
+
readonly: true,
|
|
132
|
+
description: 'Provider credentials managed by `opencode auth login`. Read-only here; editing would corrupt stored OAuth tokens.',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
111
135
|
};
|
|
112
136
|
|
|
113
137
|
export const SUPPORTED_CONFIG_PROVIDERS = Object.keys(PROVIDER_CONFIG_FILES);
|
package/server/routes/auth.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
|
|
2
|
+
// bcryptjs is a pure-JS drop-in (same hash/compare API, same output format)
|
|
3
|
+
// — switching from native `bcrypt` here eliminated one C++ compile from
|
|
4
|
+
// the install path. Existing $2a$/$2b$ hashes in the DB remain valid;
|
|
5
|
+
// bcryptjs recognizes both prefixes so logins work across the swap.
|
|
6
|
+
import bcrypt from 'bcryptjs';
|
|
3
7
|
import { userDb, db } from '../database/db.js';
|
|
4
8
|
import { generateToken, authenticateToken } from '../middleware/auth.js';
|
|
5
9
|
|
package/server/routes/network.js
CHANGED
|
@@ -2,8 +2,6 @@ import express from 'express';
|
|
|
2
2
|
import os from 'os';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
disableUpnp,
|
|
6
|
-
enableUpnp,
|
|
7
5
|
getTunnelState,
|
|
8
6
|
getUpnpState,
|
|
9
7
|
startTunnel,
|
|
@@ -78,26 +76,20 @@ router.get('/external', (req, res) => {
|
|
|
78
76
|
}
|
|
79
77
|
});
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
79
|
+
// UPnP endpoints removed in v1.32 (see external-access.js for rationale).
|
|
80
|
+
// Clients hitting /upnp get a 410 so the UI can show a clear "moved to
|
|
81
|
+
// tunnel" hint without mistaking the absence for a transient 404.
|
|
82
|
+
router.post('/upnp', (_req, res) => {
|
|
83
|
+
res.status(410).json({
|
|
84
|
+
error: 'UPnP removed in v1.32 — use cloudflared or ngrok tunnels instead',
|
|
85
|
+
upnp: getUpnpState(),
|
|
86
|
+
});
|
|
90
87
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
res.json({ success: true, upnp: state });
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error('UPnP disable failed:', error);
|
|
99
|
-
res.status(502).json({ error: error?.message || 'UPnP disable failed', upnp: getUpnpState() });
|
|
100
|
-
}
|
|
88
|
+
router.delete('/upnp', (_req, res) => {
|
|
89
|
+
res.status(410).json({
|
|
90
|
+
error: 'UPnP removed in v1.32 — use cloudflared or ngrok tunnels instead',
|
|
91
|
+
upnp: getUpnpState(),
|
|
92
|
+
});
|
|
101
93
|
});
|
|
102
94
|
|
|
103
95
|
router.post('/tunnel', async (req, res) => {
|
|
@@ -1,240 +1,171 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const handleChunk = (chunk) => {
|
|
174
|
-
const text = chunk.toString();
|
|
175
|
-
text.split(/\r?\n/).filter(Boolean).forEach(appendLog);
|
|
176
|
-
if (!tunnelState.url) {
|
|
177
|
-
const url = extractUrl(binary, text);
|
|
178
|
-
if (url) tunnelState.url = url;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
child.stdout.on('data', handleChunk);
|
|
183
|
-
child.stderr.on('data', handleChunk);
|
|
184
|
-
child.on('exit', (code) => {
|
|
185
|
-
tunnelProc = null;
|
|
186
|
-
tunnelState = {
|
|
187
|
-
running: false,
|
|
188
|
-
binary,
|
|
189
|
-
url: null,
|
|
190
|
-
error: code === 0 ? null : `Tunnel exited with code ${code}`,
|
|
191
|
-
log: tunnelState.log,
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// Wait up to 15s for the public URL to appear in the log. We don't block
|
|
196
|
-
// indefinitely — if the binary is hanging on login/auth, the UI should see
|
|
197
|
-
// a clear failure instead of a spinner that never resolves.
|
|
198
|
-
const start = Date.now();
|
|
199
|
-
while (Date.now() - start < 15000) {
|
|
200
|
-
if (tunnelState.url) return tunnelState;
|
|
201
|
-
if (!tunnelProc) break; // process died early
|
|
202
|
-
// eslint-disable-next-line no-await-in-loop
|
|
203
|
-
await new Promise((r) => setTimeout(r, 250));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (!tunnelState.url) {
|
|
207
|
-
// If we never captured a URL, kill the child so we don't leak it.
|
|
208
|
-
try { child.kill(); } catch { /* ignore */ }
|
|
209
|
-
tunnelProc = null;
|
|
210
|
-
tunnelState = { ...tunnelState, running: false, error: 'Tunnel did not report a public URL' };
|
|
211
|
-
throw new Error(tunnelState.error);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return tunnelState;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export const stopTunnel = async () => {
|
|
218
|
-
if (!tunnelProc) {
|
|
219
|
-
tunnelState = { running: false, binary: null, url: null, error: null, log: [] };
|
|
220
|
-
return tunnelState;
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
tunnelProc.kill();
|
|
224
|
-
} catch {
|
|
225
|
-
// already dead
|
|
226
|
-
}
|
|
227
|
-
tunnelProc = null;
|
|
228
|
-
tunnelState = { running: false, binary: null, url: null, error: null, log: [] };
|
|
229
|
-
return tunnelState;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export const getTunnelState = () => tunnelState;
|
|
233
|
-
|
|
234
|
-
// Explicit cleanup so the server process can shut down without leaking the
|
|
235
|
-
// child tunnel process.
|
|
236
|
-
process.on('exit', () => {
|
|
237
|
-
if (tunnelProc) {
|
|
238
|
-
try { tunnelProc.kill(); } catch { /* ignore */ }
|
|
239
|
-
}
|
|
240
|
-
});
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External-access service.
|
|
5
|
+
*
|
|
6
|
+
* Previously exposed a UPnP auto-port-forward path via `nat-upnp`, but that
|
|
7
|
+
* package pulled in the deprecated `request` / `har-validator` / `uuid@3`
|
|
8
|
+
* chain (noise at every install). Cloudflared and ngrok cover the same
|
|
9
|
+
* "publish my laptop to the internet" use case with a better security
|
|
10
|
+
* posture (no permanent port in the router firewall), so we kept the
|
|
11
|
+
* tunnel flow and dropped UPnP entirely. If UPnP becomes a user-demanded
|
|
12
|
+
* feature again we can bring it back via a maintained package like
|
|
13
|
+
* `@achingbrain/nat-port-mapper`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Keep the UPnP getter + no-op togglers so callers still compile, but they
|
|
17
|
+
// always report "unavailable". This is transitional — the routes layer no
|
|
18
|
+
// longer surfaces them either, so nothing in the live codebase hits these.
|
|
19
|
+
const UPNP_UNAVAILABLE = Object.freeze({
|
|
20
|
+
mapped: false,
|
|
21
|
+
port: null,
|
|
22
|
+
externalIp: null,
|
|
23
|
+
externalUrl: null,
|
|
24
|
+
error: 'UPnP auto-port-forward was removed in v1.32. Use cloudflared or ngrok tunnels instead.',
|
|
25
|
+
});
|
|
26
|
+
export const getUpnpState = () => UPNP_UNAVAILABLE;
|
|
27
|
+
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Tunnel: detect cloudflared / ngrok and spawn; extract the public URL from
|
|
30
|
+
// stdout. We keep a single live tunnel per process — starting a new one
|
|
31
|
+
// stops the previous one to avoid dangling child processes.
|
|
32
|
+
// ============================================================================
|
|
33
|
+
|
|
34
|
+
let tunnelProc = null;
|
|
35
|
+
let tunnelState = {
|
|
36
|
+
running: false,
|
|
37
|
+
binary: null, // 'cloudflared' | 'ngrok'
|
|
38
|
+
url: null,
|
|
39
|
+
error: null,
|
|
40
|
+
log: [],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const appendLog = (line) => {
|
|
44
|
+
// Tunnels can be noisy. Cap the tail we retain so a long-running tunnel
|
|
45
|
+
// doesn't grow the log into an OOM risk.
|
|
46
|
+
tunnelState.log.push(line);
|
|
47
|
+
if (tunnelState.log.length > 200) tunnelState.log.shift();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const detectBinary = async () => {
|
|
51
|
+
const candidates = ['cloudflared', 'ngrok'];
|
|
52
|
+
for (const name of candidates) {
|
|
53
|
+
try {
|
|
54
|
+
// `which` isn't guaranteed on Windows; we probe with `--version` instead
|
|
55
|
+
// so the same code path works on Unix and Windows Command Prompt.
|
|
56
|
+
await new Promise((resolve, reject) => {
|
|
57
|
+
const child = spawn(name, ['--version'], { stdio: 'ignore' });
|
|
58
|
+
child.on('error', reject);
|
|
59
|
+
child.on('exit', (code) => (code === 0 ? resolve() : reject(new Error(`exit ${code}`))));
|
|
60
|
+
});
|
|
61
|
+
return name;
|
|
62
|
+
} catch {
|
|
63
|
+
// try next
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const cloudflareUrlRegex = /https?:\/\/[a-z0-9.-]+trycloudflare\.com/i;
|
|
70
|
+
const ngrokUrlRegex = /https?:\/\/[a-z0-9.-]+\.ngrok(-free)?\.(app|io)/i;
|
|
71
|
+
|
|
72
|
+
const buildTunnelArgs = (binary, port) => {
|
|
73
|
+
if (binary === 'cloudflared') return ['tunnel', '--url', `http://localhost:${port}`];
|
|
74
|
+
if (binary === 'ngrok') return ['http', String(port), '--log', 'stdout', '--log-format', 'logfmt'];
|
|
75
|
+
throw new Error(`Unsupported tunnel binary: ${binary}`);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const extractUrl = (binary, text) => {
|
|
79
|
+
if (binary === 'cloudflared') return text.match(cloudflareUrlRegex)?.[0] ?? null;
|
|
80
|
+
if (binary === 'ngrok') return text.match(ngrokUrlRegex)?.[0] ?? null;
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const startTunnel = async ({ port }) => {
|
|
85
|
+
if (tunnelProc) {
|
|
86
|
+
// Already running — tell the caller to stop it first rather than silently
|
|
87
|
+
// replacing, which would orphan the old child and lie about state.
|
|
88
|
+
throw new Error('Tunnel already running; stop it first');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const binary = await detectBinary();
|
|
92
|
+
if (!binary) {
|
|
93
|
+
tunnelState = { running: false, binary: null, url: null, error: 'No tunnel binary found', log: [] };
|
|
94
|
+
const err = new Error('No tunnel binary found (tried cloudflared, ngrok)');
|
|
95
|
+
err.code = 'ENOENT_TUNNEL';
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const args = buildTunnelArgs(binary, port);
|
|
100
|
+
const child = spawn(binary, args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
101
|
+
tunnelProc = child;
|
|
102
|
+
tunnelState = { running: true, binary, url: null, error: null, log: [] };
|
|
103
|
+
|
|
104
|
+
const handleChunk = (chunk) => {
|
|
105
|
+
const text = chunk.toString();
|
|
106
|
+
text.split(/\r?\n/).filter(Boolean).forEach(appendLog);
|
|
107
|
+
if (!tunnelState.url) {
|
|
108
|
+
const url = extractUrl(binary, text);
|
|
109
|
+
if (url) tunnelState.url = url;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
child.stdout.on('data', handleChunk);
|
|
114
|
+
child.stderr.on('data', handleChunk);
|
|
115
|
+
child.on('exit', (code) => {
|
|
116
|
+
tunnelProc = null;
|
|
117
|
+
tunnelState = {
|
|
118
|
+
running: false,
|
|
119
|
+
binary,
|
|
120
|
+
url: null,
|
|
121
|
+
error: code === 0 ? null : `Tunnel exited with code ${code}`,
|
|
122
|
+
log: tunnelState.log,
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Wait up to 15s for the public URL to appear in the log. We don't block
|
|
127
|
+
// indefinitely — if the binary is hanging on login/auth, the UI should see
|
|
128
|
+
// a clear failure instead of a spinner that never resolves.
|
|
129
|
+
const start = Date.now();
|
|
130
|
+
while (Date.now() - start < 15000) {
|
|
131
|
+
if (tunnelState.url) return tunnelState;
|
|
132
|
+
if (!tunnelProc) break; // process died early
|
|
133
|
+
// eslint-disable-next-line no-await-in-loop
|
|
134
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!tunnelState.url) {
|
|
138
|
+
// If we never captured a URL, kill the child so we don't leak it.
|
|
139
|
+
try { child.kill(); } catch { /* ignore */ }
|
|
140
|
+
tunnelProc = null;
|
|
141
|
+
tunnelState = { ...tunnelState, running: false, error: 'Tunnel did not report a public URL' };
|
|
142
|
+
throw new Error(tunnelState.error);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return tunnelState;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const stopTunnel = async () => {
|
|
149
|
+
if (!tunnelProc) {
|
|
150
|
+
tunnelState = { running: false, binary: null, url: null, error: null, log: [] };
|
|
151
|
+
return tunnelState;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
tunnelProc.kill();
|
|
155
|
+
} catch {
|
|
156
|
+
// already dead
|
|
157
|
+
}
|
|
158
|
+
tunnelProc = null;
|
|
159
|
+
tunnelState = { running: false, binary: null, url: null, error: null, log: [] };
|
|
160
|
+
return tunnelState;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const getTunnelState = () => tunnelState;
|
|
164
|
+
|
|
165
|
+
// Explicit cleanup so the server process can shut down without leaking the
|
|
166
|
+
// child tunnel process.
|
|
167
|
+
process.on('exit', () => {
|
|
168
|
+
if (tunnelProc) {
|
|
169
|
+
try { tunnelProc.kill(); } catch { /* ignore */ }
|
|
170
|
+
}
|
|
171
|
+
});
|
|
@@ -62,6 +62,7 @@ const PACKAGE_BINARIES = {
|
|
|
62
62
|
'@openai/codex': 'codex',
|
|
63
63
|
'@google/gemini-cli': 'gemini',
|
|
64
64
|
'@qwen-code/qwen-code': 'qwen',
|
|
65
|
+
'opencode-ai': 'opencode',
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
/**
|
|
@@ -129,6 +130,7 @@ export function resolveProviderExecutables(env = process.env) {
|
|
|
129
130
|
{ name: 'codex', envKey: 'CODEX_CLI_PATH' },
|
|
130
131
|
{ name: 'gemini', envKey: 'GEMINI_CLI_PATH' },
|
|
131
132
|
{ name: 'qwen', envKey: 'QWEN_CLI_PATH' },
|
|
133
|
+
{ name: 'opencode', envKey: 'OPENCODE_CLI_PATH' },
|
|
132
134
|
{ name: 'cursor-agent', envKey: 'CURSOR_CLI_PATH' },
|
|
133
135
|
];
|
|
134
136
|
for (const { name, envKey } of providers) {
|
|
@@ -24,10 +24,14 @@ const CONFIG_FILE = path.join(os.homedir(), '.pixcode', 'provider-credentials.js
|
|
|
24
24
|
* inject into the spawn env. Cursor is OAuth-only; it has no api-key entry.
|
|
25
25
|
*/
|
|
26
26
|
export const PROVIDER_ENV_VARS = Object.freeze({
|
|
27
|
-
claude:
|
|
28
|
-
codex:
|
|
29
|
-
gemini:
|
|
30
|
-
qwen:
|
|
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' },
|
|
31
35
|
});
|
|
32
36
|
|
|
33
37
|
async function readStore() {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
2
|
|
|
4
3
|
import { telegramConfigDb, telegramLinksDb } from '../../database/db.js';
|
|
5
4
|
|
|
6
5
|
import { t } from './translations.js';
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// Swapped in v1.32: previously `node-telegram-bot-api` which carried the
|
|
7
|
+
// deprecated `request`/`har-validator`/`uuid@3` chain. TelegramHttpBot is
|
|
8
|
+
// a ~100-line fetch-based replacement with the same public surface
|
|
9
|
+
// (getMe / sendMessage / on / stopPolling). See telegram-http-client.js.
|
|
10
|
+
import { TelegramHttpBot } from './telegram-http-client.js';
|
|
12
11
|
|
|
13
12
|
// Pairing code TTL. Ten minutes gives a user enough time to switch apps and
|
|
14
13
|
// type the code without leaving a long-lived code sitting around if they
|
|
@@ -188,7 +187,7 @@ export const startBot = async ({ token, persist = true } = {}) => {
|
|
|
188
187
|
// 409 conflicts on every long-poll.
|
|
189
188
|
if (bot) await stopBot();
|
|
190
189
|
|
|
191
|
-
const instance = new
|
|
190
|
+
const instance = new TelegramHttpBot(token, { polling: true });
|
|
192
191
|
// Validate the token first — if getMe fails we never want to persist a
|
|
193
192
|
// broken token or leave the poller running.
|
|
194
193
|
let me;
|