@pixelbyte-software/pixcode 1.31.12 → 1.32.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-Bb2tV2Uy.js → index-DcAn_NI0.js} +169 -157
- package/dist/index.html +2 -2
- package/dist-server/server/index.js +62 -4
- 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/shared/modelConstants.js +20 -0
- package/dist-server/shared/modelConstants.js.map +1 -1
- package/package.json +178 -178
- package/server/index.js +57 -4
- 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/shared/types.ts +1 -1
- package/shared/modelConstants.js +22 -0
- package/dist/assets/index-CLxSMbv1.css +0 -32
|
@@ -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;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal Telegram Bot API client.
|
|
5
|
+
*
|
|
6
|
+
* Replaces `node-telegram-bot-api` which pulled in the deprecated
|
|
7
|
+
* `request` / `har-validator` / `uuid@3` chain (~30 transitive packages,
|
|
8
|
+
* npm install warnings on every fresh box). The Bot API itself is just
|
|
9
|
+
* HTTP, and we only use two endpoints (getUpdates polling + sendMessage),
|
|
10
|
+
* so 100 lines of fetch is all that's needed. Exposes the same surface
|
|
11
|
+
* the bot.js consumer relied on: `getMe()`, `sendMessage()`, `on('message'|'polling_error')`,
|
|
12
|
+
* `stopPolling()`.
|
|
13
|
+
*
|
|
14
|
+
* No third-party deps — uses Node 22's built-in `fetch`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const API_BASE = 'https://api.telegram.org/bot';
|
|
18
|
+
|
|
19
|
+
class TelegramApiError extends Error {
|
|
20
|
+
constructor(method, body, httpStatus) {
|
|
21
|
+
const description = body?.description || `HTTP ${httpStatus}`;
|
|
22
|
+
super(`Telegram ${method} failed: ${description}`);
|
|
23
|
+
this.name = 'TelegramApiError';
|
|
24
|
+
this.method = method;
|
|
25
|
+
this.httpStatus = httpStatus;
|
|
26
|
+
// Mirror the shape node-telegram-bot-api exposed so upstream error
|
|
27
|
+
// handling (401/409 checks in bot.js) keeps working unchanged.
|
|
28
|
+
this.response = { statusCode: httpStatus, body };
|
|
29
|
+
this.code = body?.error_code || httpStatus;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Call a Bot API method by name. Returns the `result` field on success,
|
|
35
|
+
* throws a TelegramApiError otherwise.
|
|
36
|
+
*/
|
|
37
|
+
async function callApi(token, method, params, { signal } = {}) {
|
|
38
|
+
const url = `${API_BASE}${token}/${method}`;
|
|
39
|
+
const res = await fetch(url, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify(params || {}),
|
|
43
|
+
signal,
|
|
44
|
+
});
|
|
45
|
+
let body;
|
|
46
|
+
try { body = await res.json(); } catch { body = null; }
|
|
47
|
+
if (!res.ok || !body?.ok) {
|
|
48
|
+
throw new TelegramApiError(method, body, res.status);
|
|
49
|
+
}
|
|
50
|
+
return body.result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class TelegramHttpBot extends EventEmitter {
|
|
54
|
+
constructor(token, { polling = true, pollTimeoutSec = 30 } = {}) {
|
|
55
|
+
super();
|
|
56
|
+
if (!token) throw new Error('TelegramHttpBot: token is required');
|
|
57
|
+
this._token = token;
|
|
58
|
+
this._pollTimeoutSec = pollTimeoutSec;
|
|
59
|
+
this._offset = 0;
|
|
60
|
+
this._polling = false;
|
|
61
|
+
this._abortController = null;
|
|
62
|
+
if (polling) this._startPolling();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ---------- Public API (mirrors node-telegram-bot-api surface) ----------
|
|
66
|
+
|
|
67
|
+
async getMe() {
|
|
68
|
+
return callApi(this._token, 'getMe', {});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async sendMessage(chatId, text, extra = {}) {
|
|
72
|
+
return callApi(this._token, 'sendMessage', {
|
|
73
|
+
chat_id: chatId,
|
|
74
|
+
text,
|
|
75
|
+
...extra,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async stopPolling(_opts = {}) {
|
|
80
|
+
this._polling = false;
|
|
81
|
+
try { this._abortController?.abort(); } catch { /* ignore */ }
|
|
82
|
+
this._abortController = null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---------- Polling loop ----------
|
|
86
|
+
|
|
87
|
+
async _startPolling() {
|
|
88
|
+
this._polling = true;
|
|
89
|
+
// Kick off a non-awaited loop. Each iteration long-polls getUpdates for
|
|
90
|
+
// up to pollTimeoutSec, then loops immediately. We deliberately serialize
|
|
91
|
+
// (no concurrent long-polls) because Telegram rejects that with 409.
|
|
92
|
+
(async () => {
|
|
93
|
+
while (this._polling) {
|
|
94
|
+
this._abortController = new AbortController();
|
|
95
|
+
try {
|
|
96
|
+
const updates = await callApi(
|
|
97
|
+
this._token,
|
|
98
|
+
'getUpdates',
|
|
99
|
+
{
|
|
100
|
+
offset: this._offset,
|
|
101
|
+
timeout: this._pollTimeoutSec,
|
|
102
|
+
allowed_updates: ['message'],
|
|
103
|
+
},
|
|
104
|
+
{ signal: this._abortController.signal },
|
|
105
|
+
);
|
|
106
|
+
for (const update of updates) {
|
|
107
|
+
if (typeof update.update_id === 'number') {
|
|
108
|
+
this._offset = Math.max(this._offset, update.update_id + 1);
|
|
109
|
+
}
|
|
110
|
+
if (update.message) {
|
|
111
|
+
try { this.emit('message', update.message); } catch (err) {
|
|
112
|
+
// Don't let a listener exception break the poll loop.
|
|
113
|
+
this.emit('polling_error', err);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
// AbortError is the expected path when stopPolling() is called.
|
|
119
|
+
if (err?.name === 'AbortError' || !this._polling) break;
|
|
120
|
+
this.emit('polling_error', err);
|
|
121
|
+
// Back off before retrying — rapid retries on 401/409 would
|
|
122
|
+
// otherwise spin at 100% CPU. Upstream consumer's polling_error
|
|
123
|
+
// handler may also call stopBot() on 401/409 which flips _polling
|
|
124
|
+
// off and breaks the loop on the next tick.
|
|
125
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
}
|
|
130
|
+
}
|
package/server/shared/types.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type AnyRecord = Record<string, any>;
|
|
|
9
9
|
|
|
10
10
|
// ---------------------------------------------------------------------------------------------
|
|
11
11
|
|
|
12
|
-
export type LLMProvider = 'claude' | 'codex' | 'gemini' | 'cursor' | 'qwen';
|
|
12
|
+
export type LLMProvider = 'claude' | 'codex' | 'gemini' | 'cursor' | 'qwen' | 'opencode';
|
|
13
13
|
|
|
14
14
|
// ---------------------------------------------------------------------------------------------
|
|
15
15
|
|
package/shared/modelConstants.js
CHANGED
|
@@ -94,6 +94,28 @@ export const QWEN_MODELS = {
|
|
|
94
94
|
DEFAULT: "qwen3-coder-plus",
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* OpenCode Models
|
|
99
|
+
*
|
|
100
|
+
* OpenCode is multi-provider, so the picker is really "which upstream
|
|
101
|
+
* model does opencode talk to?". The defaults here point at OpenCode Zen
|
|
102
|
+
* (their curated routing tier) plus a few direct picks the docs call
|
|
103
|
+
* out as well-supported. Advanced users override via opencode.json's
|
|
104
|
+
* `provider` / `model` block, which bypasses this list.
|
|
105
|
+
*/
|
|
106
|
+
export const OPENCODE_MODELS = {
|
|
107
|
+
OPTIONS: [
|
|
108
|
+
{ value: "opencode/zen-best", label: "OpenCode Zen (Best)" },
|
|
109
|
+
{ value: "opencode/zen-fast", label: "OpenCode Zen (Fast)" },
|
|
110
|
+
{ value: "anthropic/claude-sonnet-4-6", label: "Claude Sonnet 4.6 (Anthropic)" },
|
|
111
|
+
{ value: "anthropic/claude-opus-4-6", label: "Claude Opus 4.6 (Anthropic)" },
|
|
112
|
+
{ value: "openai/gpt-5.4", label: "GPT-5.4 (OpenAI)" },
|
|
113
|
+
{ value: "google/gemini-3-pro-preview", label: "Gemini 3 Pro (Google)" },
|
|
114
|
+
],
|
|
115
|
+
|
|
116
|
+
DEFAULT: "opencode/zen-best",
|
|
117
|
+
};
|
|
118
|
+
|
|
97
119
|
/**
|
|
98
120
|
* Gemini Models
|
|
99
121
|
*/
|