@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.
Files changed (66) hide show
  1. package/dist/assets/index-Byb8Wnts.css +32 -0
  2. package/dist/assets/{index-oxZnRcf8.js → index-CZKV8Tbj.js} +163 -151
  3. package/dist/index.html +2 -2
  4. package/dist-server/server/database/db.js +542 -460
  5. package/dist-server/server/database/db.js.map +1 -1
  6. package/dist-server/server/database/json-store.js +184 -0
  7. package/dist-server/server/database/json-store.js.map +1 -0
  8. package/dist-server/server/index.js +16 -1
  9. package/dist-server/server/index.js.map +1 -1
  10. package/dist-server/server/modules/providers/list/opencode/opencode-auth.provider.js +113 -0
  11. package/dist-server/server/modules/providers/list/opencode/opencode-auth.provider.js.map +1 -0
  12. package/dist-server/server/modules/providers/list/opencode/opencode-mcp.provider.js +98 -0
  13. package/dist-server/server/modules/providers/list/opencode/opencode-mcp.provider.js.map +1 -0
  14. package/dist-server/server/modules/providers/list/opencode/opencode-sessions.provider.js +138 -0
  15. package/dist-server/server/modules/providers/list/opencode/opencode-sessions.provider.js.map +1 -0
  16. package/dist-server/server/modules/providers/list/opencode/opencode.provider.js +27 -0
  17. package/dist-server/server/modules/providers/list/opencode/opencode.provider.js.map +1 -0
  18. package/dist-server/server/modules/providers/provider.registry.js +2 -0
  19. package/dist-server/server/modules/providers/provider.registry.js.map +1 -1
  20. package/dist-server/server/modules/providers/provider.routes.js +4 -1
  21. package/dist-server/server/modules/providers/provider.routes.js.map +1 -1
  22. package/dist-server/server/modules/providers/shared/provider-configs.js +24 -0
  23. package/dist-server/server/modules/providers/shared/provider-configs.js.map +1 -1
  24. package/dist-server/server/routes/auth.js +5 -1
  25. package/dist-server/server/routes/auth.js.map +1 -1
  26. package/dist-server/server/routes/network.js +14 -21
  27. package/dist-server/server/routes/network.js.map +1 -1
  28. package/dist-server/server/services/external-access.js +18 -78
  29. package/dist-server/server/services/external-access.js.map +1 -1
  30. package/dist-server/server/services/install-jobs.js +2 -0
  31. package/dist-server/server/services/install-jobs.js.map +1 -1
  32. package/dist-server/server/services/provider-credentials.js +4 -0
  33. package/dist-server/server/services/provider-credentials.js.map +1 -1
  34. package/dist-server/server/services/telegram/bot.js +6 -6
  35. package/dist-server/server/services/telegram/bot.js.map +1 -1
  36. package/dist-server/server/services/telegram/telegram-http-client.js +130 -0
  37. package/dist-server/server/services/telegram/telegram-http-client.js.map +1 -0
  38. package/dist-server/server/services/vapid-keys.js +3 -3
  39. package/dist-server/server/services/vapid-keys.js.map +1 -1
  40. package/dist-server/shared/modelConstants.js +20 -0
  41. package/dist-server/shared/modelConstants.js.map +1 -1
  42. package/package.json +178 -178
  43. package/server/database/db.js +794 -696
  44. package/server/database/json-store.js +194 -0
  45. package/server/index.js +14 -1
  46. package/server/modules/providers/list/opencode/opencode-auth.provider.ts +130 -0
  47. package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -0
  48. package/server/modules/providers/list/opencode/opencode-sessions.provider.ts +155 -0
  49. package/server/modules/providers/list/opencode/opencode.provider.ts +29 -0
  50. package/server/modules/providers/provider.registry.ts +2 -0
  51. package/server/modules/providers/provider.routes.ts +4 -0
  52. package/server/modules/providers/shared/provider-configs.ts +24 -0
  53. package/server/routes/auth.js +5 -1
  54. package/server/routes/network.js +13 -21
  55. package/server/services/external-access.js +171 -240
  56. package/server/services/install-jobs.js +2 -0
  57. package/server/services/provider-credentials.js +8 -4
  58. package/server/services/telegram/bot.js +6 -7
  59. package/server/services/telegram/telegram-http-client.js +130 -0
  60. package/server/services/vapid-keys.js +36 -35
  61. package/server/shared/types.ts +1 -1
  62. package/shared/modelConstants.js +22 -0
  63. package/dist/assets/index-CLxSMbv1.css +0 -32
  64. package/dist-server/server/database/schema.js +0 -130
  65. package/dist-server/server/database/schema.js.map +0 -1
  66. 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);
@@ -1,5 +1,9 @@
1
1
  import express from 'express';
2
- import bcrypt from 'bcrypt';
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
 
@@ -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
- router.post('/upnp', async (req, res) => {
82
- const port = resolveServerPort();
83
- try {
84
- const state = await enableUpnp({ port });
85
- res.json({ success: true, upnp: state });
86
- } catch (error) {
87
- console.error('UPnP enable failed:', error);
88
- res.status(502).json({ error: error?.message || 'UPnP enable failed', upnp: getUpnpState() });
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
- router.delete('/upnp', async (req, res) => {
93
- const port = resolveServerPort();
94
- try {
95
- const state = await disableUpnp({ port });
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
- import { createRequire } from 'node:module';
3
-
4
- const requireCjs = createRequire(import.meta.url);
5
-
6
- // nat-upnp is CommonJS and callback-based. We wrap it in promises and keep
7
- // one shared client per process. The client is lazily created so importing
8
- // this module does not try to bind SSDP sockets at boot.
9
- let upnpClient = null;
10
- const getUpnpClient = () => {
11
- if (!upnpClient) {
12
- const nat = requireCjs('nat-upnp');
13
- upnpClient = nat.createClient();
14
- }
15
- return upnpClient;
16
- };
17
-
18
- let upnpState = {
19
- mapped: false,
20
- port: null,
21
- externalIp: null,
22
- externalUrl: null,
23
- error: null,
24
- };
25
-
26
- // A UPnP mapping request can hang forever if the router never answers SSDP.
27
- // Cap every call so the HTTP endpoint doesn't dangle — we surface a clean
28
- // failure and the user can try tunnel mode instead.
29
- const withTimeout = (promise, ms, label) =>
30
- Promise.race([
31
- promise,
32
- new Promise((_, reject) => setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), ms)),
33
- ]);
34
-
35
- const promisifyUpnp = (method, arg) =>
36
- new Promise((resolve, reject) => {
37
- const client = getUpnpClient();
38
- const cb = (err, result) => (err ? reject(err) : resolve(result));
39
- if (arg === undefined) {
40
- client[method](cb);
41
- } else {
42
- client[method](arg, cb);
43
- }
44
- });
45
-
46
- export const enableUpnp = async ({ port }) => {
47
- upnpState = { ...upnpState, error: null };
48
- try {
49
- await withTimeout(
50
- promisifyUpnp('portMapping', {
51
- public: port,
52
- private: port,
53
- // ttl:0 is documented as "never expire" — routers honor it differently,
54
- // but it's the least surprising default. We leave renewal to the user
55
- // clicking "enable" again if the router drops the lease.
56
- ttl: 0,
57
- description: 'Pixcode',
58
- protocol: 'tcp',
59
- }),
60
- 8000,
61
- 'UPnP portMapping',
62
- );
63
- const externalIp = await withTimeout(promisifyUpnp('externalIp'), 5000, 'UPnP externalIp');
64
- upnpState = {
65
- mapped: true,
66
- port,
67
- externalIp,
68
- externalUrl: externalIp ? `http://${externalIp}:${port}` : null,
69
- error: null,
70
- };
71
- return upnpState;
72
- } catch (err) {
73
- upnpState = {
74
- mapped: false,
75
- port,
76
- externalIp: null,
77
- externalUrl: null,
78
- error: err?.message || String(err),
79
- };
80
- throw err;
81
- }
82
- };
83
-
84
- export const disableUpnp = async ({ port }) => {
85
- try {
86
- await withTimeout(promisifyUpnp('portUnmapping', { public: port, protocol: 'tcp' }), 5000, 'UPnP portUnmapping');
87
- } catch (err) {
88
- upnpState = { ...upnpState, error: err?.message || String(err) };
89
- throw err;
90
- }
91
- upnpState = { mapped: false, port: null, externalIp: null, externalUrl: null, error: null };
92
- return upnpState;
93
- };
94
-
95
- export const getUpnpState = () => upnpState;
96
-
97
- // ============================================================================
98
- // Tunnel: detect cloudflared / ngrok and spawn; extract the public URL from
99
- // stdout. We keep a single live tunnel per process — starting a new one
100
- // stops the previous one to avoid dangling child processes.
101
- // ============================================================================
102
-
103
- let tunnelProc = null;
104
- let tunnelState = {
105
- running: false,
106
- binary: null, // 'cloudflared' | 'ngrok'
107
- url: null,
108
- error: null,
109
- log: [],
110
- };
111
-
112
- const appendLog = (line) => {
113
- // Tunnels can be noisy. Cap the tail we retain so a long-running tunnel
114
- // doesn't grow the log into an OOM risk.
115
- tunnelState.log.push(line);
116
- if (tunnelState.log.length > 200) tunnelState.log.shift();
117
- };
118
-
119
- const detectBinary = async () => {
120
- const candidates = ['cloudflared', 'ngrok'];
121
- for (const name of candidates) {
122
- try {
123
- // `which` isn't guaranteed on Windows; we probe with `--version` instead
124
- // so the same code path works on Unix and Windows Command Prompt.
125
- await new Promise((resolve, reject) => {
126
- const child = spawn(name, ['--version'], { stdio: 'ignore' });
127
- child.on('error', reject);
128
- child.on('exit', (code) => (code === 0 ? resolve() : reject(new Error(`exit ${code}`))));
129
- });
130
- return name;
131
- } catch {
132
- // try next
133
- }
134
- }
135
- return null;
136
- };
137
-
138
- const cloudflareUrlRegex = /https?:\/\/[a-z0-9.-]+trycloudflare\.com/i;
139
- const ngrokUrlRegex = /https?:\/\/[a-z0-9.-]+\.ngrok(-free)?\.(app|io)/i;
140
-
141
- const buildTunnelArgs = (binary, port) => {
142
- if (binary === 'cloudflared') return ['tunnel', '--url', `http://localhost:${port}`];
143
- if (binary === 'ngrok') return ['http', String(port), '--log', 'stdout', '--log-format', 'logfmt'];
144
- throw new Error(`Unsupported tunnel binary: ${binary}`);
145
- };
146
-
147
- const extractUrl = (binary, text) => {
148
- if (binary === 'cloudflared') return text.match(cloudflareUrlRegex)?.[0] ?? null;
149
- if (binary === 'ngrok') return text.match(ngrokUrlRegex)?.[0] ?? null;
150
- return null;
151
- };
152
-
153
- export const startTunnel = async ({ port }) => {
154
- if (tunnelProc) {
155
- // Already running — tell the caller to stop it first rather than silently
156
- // replacing, which would orphan the old child and lie about state.
157
- throw new Error('Tunnel already running; stop it first');
158
- }
159
-
160
- const binary = await detectBinary();
161
- if (!binary) {
162
- tunnelState = { running: false, binary: null, url: null, error: 'No tunnel binary found', log: [] };
163
- const err = new Error('No tunnel binary found (tried cloudflared, ngrok)');
164
- err.code = 'ENOENT_TUNNEL';
165
- throw err;
166
- }
167
-
168
- const args = buildTunnelArgs(binary, port);
169
- const child = spawn(binary, args, { stdio: ['ignore', 'pipe', 'pipe'] });
170
- tunnelProc = child;
171
- tunnelState = { running: true, binary, url: null, error: null, log: [] };
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: { 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' },
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
- // node-telegram-bot-api is a CommonJS module. Using createRequire keeps the
9
- // default-export interop clean across ESM/CJS boundaries.
10
- const requireCjs = createRequire(import.meta.url);
11
- const TelegramBot = requireCjs('node-telegram-bot-api');
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 TelegramBot(token, { polling: true });
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;