@pixelbyte-software/pixcode 1.53.10 → 1.53.12
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-BEyC4q_s.css +32 -0
- package/dist/assets/{index-ChssgA1r.js → index-kP_gZ-wL.js} +178 -178
- package/dist/index.html +2 -2
- package/dist-server/server/database/db.js +26 -0
- package/dist-server/server/database/db.js.map +1 -1
- package/dist-server/server/index.js +290 -57
- package/dist-server/server/index.js.map +1 -1
- package/dist-server/server/projects.js +126 -43
- package/dist-server/server/projects.js.map +1 -1
- package/dist-server/server/routes/git.js +16 -0
- package/dist-server/server/routes/git.js.map +1 -1
- package/dist-server/server/routes/plugins.js +364 -0
- package/dist-server/server/routes/plugins.js.map +1 -1
- package/dist-server/server/services/telegram/bot.js +43 -5
- package/dist-server/server/services/telegram/bot.js.map +1 -1
- package/dist-server/server/services/telegram/control-center.js +169 -5
- package/dist-server/server/services/telegram/control-center.js.map +1 -1
- package/dist-server/server/services/telegram/translations.js +28 -2
- package/dist-server/server/services/telegram/translations.js.map +1 -1
- package/package.json +1 -1
- package/server/database/db.js +26 -0
- package/server/index.js +312 -62
- package/server/projects.js +128 -41
- package/server/routes/git.js +17 -0
- package/server/routes/plugins.js +370 -0
- package/server/services/telegram/bot.js +45 -5
- package/server/services/telegram/control-center.js +173 -5
- package/server/services/telegram/translations.js +28 -2
- package/dist/assets/index-FhOsv2Yy.css +0 -32
package/server/routes/plugins.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import http from 'http';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
4
5
|
|
|
5
6
|
import mime from 'mime-types';
|
|
6
7
|
import express from 'express';
|
|
@@ -24,6 +25,375 @@ import {
|
|
|
24
25
|
} from '../utils/plugin-process-manager.js';
|
|
25
26
|
|
|
26
27
|
const router = express.Router();
|
|
28
|
+
const MARKETPLACE_SOURCES_PATH = path.join(os.homedir(), '.pixcode', 'marketplace-sources.json');
|
|
29
|
+
const MARKETPLACE_SEARCH_TIMEOUT_MS = 8000;
|
|
30
|
+
const ALL_CLI_COMPATIBILITY = ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'];
|
|
31
|
+
|
|
32
|
+
const CURATED_MARKETPLACE_ENTRIES = [
|
|
33
|
+
{
|
|
34
|
+
id: 'github:hesreallyhim/awesome-claude-code',
|
|
35
|
+
name: 'Awesome Claude Code',
|
|
36
|
+
type: 'skill-library',
|
|
37
|
+
category: 'popular',
|
|
38
|
+
sourceUrl: 'https://github.com/hesreallyhim/awesome-claude-code',
|
|
39
|
+
repo: 'hesreallyhim/awesome-claude-code',
|
|
40
|
+
description: 'Curated skills, slash commands, hooks, orchestration patterns, and agent resources.',
|
|
41
|
+
stars: 46000,
|
|
42
|
+
forks: 0,
|
|
43
|
+
updatedAt: null,
|
|
44
|
+
compatibleCli: ALL_CLI_COMPATIBILITY,
|
|
45
|
+
installKind: 'source',
|
|
46
|
+
tags: ['skills', 'agents', 'commands'],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'github:sickn33/antigravity-awesome-skills',
|
|
50
|
+
name: 'Antigravity Awesome Skills',
|
|
51
|
+
type: 'skill-library',
|
|
52
|
+
category: 'popular',
|
|
53
|
+
sourceUrl: 'https://github.com/sickn33/antigravity-awesome-skills',
|
|
54
|
+
repo: 'sickn33/antigravity-awesome-skills',
|
|
55
|
+
description: 'Large installable library of cross-CLI agent skills for Claude, Codex, Cursor, Gemini, and more.',
|
|
56
|
+
stars: 40000,
|
|
57
|
+
forks: 0,
|
|
58
|
+
updatedAt: null,
|
|
59
|
+
compatibleCli: ALL_CLI_COMPATIBILITY,
|
|
60
|
+
installKind: 'source',
|
|
61
|
+
tags: ['skills', 'multi-cli'],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'github:wshobson/agents',
|
|
65
|
+
name: 'Agents',
|
|
66
|
+
type: 'agent-pack',
|
|
67
|
+
category: 'popular',
|
|
68
|
+
sourceUrl: 'https://github.com/wshobson/agents',
|
|
69
|
+
repo: 'wshobson/agents',
|
|
70
|
+
description: 'Multi-harness agent pack and marketplace patterns for Claude Code, Codex CLI, Cursor, OpenCode, Copilot, and Gemini.',
|
|
71
|
+
stars: 36000,
|
|
72
|
+
forks: 0,
|
|
73
|
+
updatedAt: null,
|
|
74
|
+
compatibleCli: ALL_CLI_COMPATIBILITY,
|
|
75
|
+
installKind: 'source',
|
|
76
|
+
tags: ['agents', 'multi-cli'],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'github:alirezarezvani/claude-skills',
|
|
80
|
+
name: 'Claude Skills',
|
|
81
|
+
type: 'skill-library',
|
|
82
|
+
category: 'popular',
|
|
83
|
+
sourceUrl: 'https://github.com/alirezarezvani/claude-skills',
|
|
84
|
+
repo: 'alirezarezvani/claude-skills',
|
|
85
|
+
description: 'Broad skill, agent, and plugin collection for Claude Code, Codex, Gemini CLI, Cursor, and related tools.',
|
|
86
|
+
stars: 18000,
|
|
87
|
+
forks: 0,
|
|
88
|
+
updatedAt: null,
|
|
89
|
+
compatibleCli: ALL_CLI_COMPATIBILITY,
|
|
90
|
+
installKind: 'source',
|
|
91
|
+
tags: ['skills', 'plugins'],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'github:voltagent/awesome-agent-skills',
|
|
95
|
+
name: 'Awesome Agent Skills',
|
|
96
|
+
type: 'skill-library',
|
|
97
|
+
category: 'skills',
|
|
98
|
+
sourceUrl: 'https://github.com/VoltAgent/awesome-agent-skills',
|
|
99
|
+
repo: 'VoltAgent/awesome-agent-skills',
|
|
100
|
+
description: 'Cross-agent skill catalogue covering Claude, Codex, Cursor, Gemini, and OpenCode ecosystems.',
|
|
101
|
+
stars: 0,
|
|
102
|
+
forks: 0,
|
|
103
|
+
updatedAt: null,
|
|
104
|
+
compatibleCli: ALL_CLI_COMPATIBILITY,
|
|
105
|
+
installKind: 'source',
|
|
106
|
+
tags: ['skills', 'catalog'],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'github:awesome-opencode/awesome-opencode',
|
|
110
|
+
name: 'Awesome OpenCode',
|
|
111
|
+
type: 'native-plugin',
|
|
112
|
+
category: 'plugin',
|
|
113
|
+
sourceUrl: 'https://github.com/awesome-opencode/awesome-opencode',
|
|
114
|
+
repo: 'awesome-opencode/awesome-opencode',
|
|
115
|
+
description: 'Curated OpenCode plugins, themes, agents, projects, and resources.',
|
|
116
|
+
stars: 8000,
|
|
117
|
+
forks: 0,
|
|
118
|
+
updatedAt: null,
|
|
119
|
+
compatibleCli: ['opencode'],
|
|
120
|
+
installKind: 'source',
|
|
121
|
+
tags: ['opencode', 'plugins'],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'github:jenslys/opencode-gemini-auth',
|
|
125
|
+
name: 'OpenCode Gemini Auth',
|
|
126
|
+
type: 'native-plugin',
|
|
127
|
+
category: 'plugin',
|
|
128
|
+
sourceUrl: 'https://github.com/jenslys/opencode-gemini-auth',
|
|
129
|
+
repo: 'jenslys/opencode-gemini-auth',
|
|
130
|
+
description: 'OpenCode authentication plugin for Gemini accounts.',
|
|
131
|
+
stars: 0,
|
|
132
|
+
forks: 0,
|
|
133
|
+
updatedAt: null,
|
|
134
|
+
compatibleCli: ['opencode', 'gemini'],
|
|
135
|
+
installKind: 'source',
|
|
136
|
+
tags: ['opencode', 'auth'],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: 'github:supermemoryai/opencode-supermemory',
|
|
140
|
+
name: 'OpenCode Supermemory',
|
|
141
|
+
type: 'native-plugin',
|
|
142
|
+
category: 'plugin',
|
|
143
|
+
sourceUrl: 'https://github.com/supermemoryai/opencode-supermemory',
|
|
144
|
+
repo: 'supermemoryai/opencode-supermemory',
|
|
145
|
+
description: 'Supermemory integration plugin for OpenCode.',
|
|
146
|
+
stars: 0,
|
|
147
|
+
forks: 0,
|
|
148
|
+
updatedAt: null,
|
|
149
|
+
compatibleCli: ['opencode'],
|
|
150
|
+
installKind: 'source',
|
|
151
|
+
tags: ['opencode', 'memory'],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'github:griffinmartin/opencode-claude-auth',
|
|
155
|
+
name: 'OpenCode Claude Auth',
|
|
156
|
+
type: 'native-plugin',
|
|
157
|
+
category: 'plugin',
|
|
158
|
+
sourceUrl: 'https://github.com/griffinmartin/opencode-claude-auth',
|
|
159
|
+
repo: 'griffinmartin/opencode-claude-auth',
|
|
160
|
+
description: 'OpenCode plugin that reuses Claude Code credentials.',
|
|
161
|
+
stars: 0,
|
|
162
|
+
forks: 0,
|
|
163
|
+
updatedAt: null,
|
|
164
|
+
compatibleCli: ['opencode', 'claude'],
|
|
165
|
+
installKind: 'source',
|
|
166
|
+
tags: ['opencode', 'auth'],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: 'github:othmanadi/planning-with-files',
|
|
170
|
+
name: 'Planning With Files',
|
|
171
|
+
type: 'skill-library',
|
|
172
|
+
category: 'workflow',
|
|
173
|
+
sourceUrl: 'https://github.com/OthmanAdi/planning-with-files',
|
|
174
|
+
repo: 'OthmanAdi/planning-with-files',
|
|
175
|
+
description: 'Persistent file-based planning skill for multiple AI coding CLIs.',
|
|
176
|
+
stars: 0,
|
|
177
|
+
forks: 0,
|
|
178
|
+
updatedAt: null,
|
|
179
|
+
compatibleCli: ALL_CLI_COMPATIBILITY,
|
|
180
|
+
installKind: 'source',
|
|
181
|
+
tags: ['planning', 'workflow'],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
id: 'github:safishamsi/graphify',
|
|
185
|
+
name: 'Graphify',
|
|
186
|
+
type: 'skill-library',
|
|
187
|
+
category: 'workflow',
|
|
188
|
+
sourceUrl: 'https://github.com/safishamsi/graphify',
|
|
189
|
+
repo: 'safishamsi/graphify',
|
|
190
|
+
description: 'Knowledge graph skill for Claude Code, Codex, OpenCode, Cursor, Gemini, and other coding agents.',
|
|
191
|
+
stars: 0,
|
|
192
|
+
forks: 0,
|
|
193
|
+
updatedAt: null,
|
|
194
|
+
compatibleCli: ALL_CLI_COMPATIBILITY,
|
|
195
|
+
installKind: 'source',
|
|
196
|
+
tags: ['knowledge-graph', 'memory'],
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
|
|
200
|
+
function ensurePixcodeConfigDir() {
|
|
201
|
+
const dir = path.dirname(MARKETPLACE_SOURCES_PATH);
|
|
202
|
+
if (!fs.existsSync(dir)) {
|
|
203
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function readMarketplaceSources() {
|
|
208
|
+
try {
|
|
209
|
+
if (!fs.existsSync(MARKETPLACE_SOURCES_PATH)) return [];
|
|
210
|
+
const parsed = JSON.parse(fs.readFileSync(MARKETPLACE_SOURCES_PATH, 'utf-8'));
|
|
211
|
+
return Array.isArray(parsed?.sources) ? parsed.sources : [];
|
|
212
|
+
} catch {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function writeMarketplaceSources(sources) {
|
|
218
|
+
ensurePixcodeConfigDir();
|
|
219
|
+
fs.writeFileSync(
|
|
220
|
+
MARKETPLACE_SOURCES_PATH,
|
|
221
|
+
JSON.stringify({ version: 1, sources }, null, 2),
|
|
222
|
+
{ mode: 0o600 },
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function parseGithubRepoFromUrl(sourceUrl) {
|
|
227
|
+
try {
|
|
228
|
+
const url = new URL(sourceUrl);
|
|
229
|
+
if (url.hostname !== 'github.com' && url.hostname !== 'www.github.com') return null;
|
|
230
|
+
const [owner, repo] = url.pathname.replace(/^\/+/, '').split('/');
|
|
231
|
+
if (!owner || !repo) return null;
|
|
232
|
+
return `${owner}/${repo.replace(/\.git$/, '')}`;
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function marketplaceIdForSource(sourceUrl, fallbackName = '') {
|
|
239
|
+
const repo = parseGithubRepoFromUrl(sourceUrl);
|
|
240
|
+
if (repo) return `github:${repo.toLowerCase()}`;
|
|
241
|
+
return `source:${String(fallbackName || sourceUrl).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '').slice(0, 80)}`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function inferCliCompatibility(text) {
|
|
245
|
+
const haystack = String(text || '').toLowerCase();
|
|
246
|
+
const matches = ALL_CLI_COMPATIBILITY.filter((cli) => haystack.includes(cli));
|
|
247
|
+
if (haystack.includes('claude code') && !matches.includes('claude')) matches.push('claude');
|
|
248
|
+
if (haystack.includes('open code') && !matches.includes('opencode')) matches.push('opencode');
|
|
249
|
+
return matches.length > 0 ? [...new Set(matches)] : ALL_CLI_COMPATIBILITY;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function inferMarketplaceType(text) {
|
|
253
|
+
const haystack = String(text || '').toLowerCase();
|
|
254
|
+
if (haystack.includes('agent')) return 'agent-pack';
|
|
255
|
+
if (haystack.includes('plugin') || haystack.includes('opencode')) return 'native-plugin';
|
|
256
|
+
return 'skill-library';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function normalizeMarketplaceSource(input) {
|
|
260
|
+
const sourceUrl = typeof input?.sourceUrl === 'string' ? input.sourceUrl.trim() : '';
|
|
261
|
+
if (!sourceUrl.startsWith('https://github.com/')) {
|
|
262
|
+
throw new Error('Only public GitHub HTTPS sources are supported for global market sources.');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const repo = parseGithubRepoFromUrl(sourceUrl);
|
|
266
|
+
const name = String(input?.name || repo || 'GitHub source').trim().slice(0, 120);
|
|
267
|
+
const description = String(input?.description || '').trim().slice(0, 500);
|
|
268
|
+
const compatibleCli = Array.isArray(input?.compatibleCli)
|
|
269
|
+
? input.compatibleCli.filter((cli) => ALL_CLI_COMPATIBILITY.includes(cli))
|
|
270
|
+
: inferCliCompatibility(`${name} ${description} ${repo || ''}`);
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
id: marketplaceIdForSource(sourceUrl, name),
|
|
274
|
+
name,
|
|
275
|
+
type: ['skill-library', 'agent-pack', 'native-plugin', 'pixcode-plugin'].includes(input?.type)
|
|
276
|
+
? input.type
|
|
277
|
+
: inferMarketplaceType(`${name} ${description}`),
|
|
278
|
+
category: typeof input?.category === 'string' ? input.category.slice(0, 40) : 'installed',
|
|
279
|
+
sourceUrl,
|
|
280
|
+
repo,
|
|
281
|
+
description,
|
|
282
|
+
stars: Number.isFinite(Number(input?.stars)) ? Number(input.stars) : 0,
|
|
283
|
+
forks: Number.isFinite(Number(input?.forks)) ? Number(input.forks) : 0,
|
|
284
|
+
updatedAt: typeof input?.updatedAt === 'string' ? input.updatedAt : null,
|
|
285
|
+
compatibleCli: compatibleCli.length > 0 ? compatibleCli : ALL_CLI_COMPATIBILITY,
|
|
286
|
+
installKind: input?.installKind === 'pixcode-plugin' ? 'pixcode-plugin' : 'source',
|
|
287
|
+
tags: Array.isArray(input?.tags) ? input.tags.filter((tag) => typeof tag === 'string').slice(0, 8) : [],
|
|
288
|
+
addedAt: typeof input?.addedAt === 'string' ? input.addedAt : new Date().toISOString(),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function githubRepoToMarketplaceEntry(repo, category = 'search') {
|
|
293
|
+
const text = `${repo.full_name || ''} ${repo.description || ''} ${repo.topics?.join(' ') || ''}`;
|
|
294
|
+
return {
|
|
295
|
+
id: `github:${String(repo.full_name || repo.html_url || repo.id).toLowerCase()}`,
|
|
296
|
+
name: repo.name || repo.full_name || 'GitHub repository',
|
|
297
|
+
type: inferMarketplaceType(text),
|
|
298
|
+
category,
|
|
299
|
+
sourceUrl: repo.html_url,
|
|
300
|
+
repo: repo.full_name || null,
|
|
301
|
+
description: repo.description || '',
|
|
302
|
+
stars: repo.stargazers_count || 0,
|
|
303
|
+
forks: repo.forks_count || 0,
|
|
304
|
+
updatedAt: repo.updated_at || null,
|
|
305
|
+
compatibleCli: inferCliCompatibility(text),
|
|
306
|
+
installKind: 'source',
|
|
307
|
+
tags: Array.isArray(repo.topics) ? repo.topics.slice(0, 6) : [],
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// GET /marketplace — curated global skill/plugin market plus added sources.
|
|
312
|
+
router.get('/marketplace', (req, res) => {
|
|
313
|
+
try {
|
|
314
|
+
res.json({
|
|
315
|
+
entries: CURATED_MARKETPLACE_ENTRIES,
|
|
316
|
+
installedSources: readMarketplaceSources(),
|
|
317
|
+
categories: ['popular', 'skills', 'plugin', 'workflow', 'new'],
|
|
318
|
+
});
|
|
319
|
+
} catch (err) {
|
|
320
|
+
res.status(500).json({ error: 'Failed to read marketplace', details: err.message });
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// GET /marketplace/search?q=... — live GitHub repository discovery for skill/plugin sources.
|
|
325
|
+
router.get('/marketplace/search', async (req, res) => {
|
|
326
|
+
const q = String(req.query.q || '').trim().slice(0, 120);
|
|
327
|
+
const sort = req.query.sort === 'new' ? 'updated' : 'stars';
|
|
328
|
+
const baseQuery = q || 'agent skills plugin cli claude codex cursor gemini opencode';
|
|
329
|
+
const searchQuery = `${baseQuery} in:name,description,readme`;
|
|
330
|
+
const controller = new AbortController();
|
|
331
|
+
const timeout = setTimeout(() => controller.abort(), MARKETPLACE_SEARCH_TIMEOUT_MS);
|
|
332
|
+
|
|
333
|
+
try {
|
|
334
|
+
const url = new URL('https://api.github.com/search/repositories');
|
|
335
|
+
url.searchParams.set('q', searchQuery);
|
|
336
|
+
url.searchParams.set('sort', sort);
|
|
337
|
+
url.searchParams.set('order', 'desc');
|
|
338
|
+
url.searchParams.set('per_page', '12');
|
|
339
|
+
const response = await fetch(url, {
|
|
340
|
+
signal: controller.signal,
|
|
341
|
+
headers: {
|
|
342
|
+
accept: 'application/vnd.github+json',
|
|
343
|
+
'user-agent': 'pixcode-marketplace',
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
if (!response.ok) {
|
|
347
|
+
const detail = await response.text().catch(() => '');
|
|
348
|
+
return res.status(response.status).json({
|
|
349
|
+
error: 'GitHub search failed',
|
|
350
|
+
details: detail.slice(0, 500) || response.statusText,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const body = await response.json();
|
|
355
|
+
const entries = Array.isArray(body?.items)
|
|
356
|
+
? body.items.map((repo) => githubRepoToMarketplaceEntry(repo, sort === 'updated' ? 'new' : 'popular'))
|
|
357
|
+
: [];
|
|
358
|
+
res.json({ entries });
|
|
359
|
+
} catch (err) {
|
|
360
|
+
const status = err?.name === 'AbortError' ? 504 : 502;
|
|
361
|
+
res.status(status).json({ error: 'GitHub search failed', details: err.message });
|
|
362
|
+
} finally {
|
|
363
|
+
clearTimeout(timeout);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// POST /marketplace/sources — add a global cross-CLI skill/plugin source.
|
|
368
|
+
router.post('/marketplace/sources', (req, res) => {
|
|
369
|
+
try {
|
|
370
|
+
const source = normalizeMarketplaceSource(req.body?.entry || req.body || {});
|
|
371
|
+
const sources = readMarketplaceSources();
|
|
372
|
+
const existingIndex = sources.findIndex((item) => item.id === source.id || item.sourceUrl === source.sourceUrl);
|
|
373
|
+
if (existingIndex >= 0) {
|
|
374
|
+
sources[existingIndex] = { ...sources[existingIndex], ...source, addedAt: sources[existingIndex].addedAt || source.addedAt };
|
|
375
|
+
} else {
|
|
376
|
+
sources.unshift(source);
|
|
377
|
+
}
|
|
378
|
+
writeMarketplaceSources(sources.slice(0, 200));
|
|
379
|
+
res.json({ success: true, source, installedSources: readMarketplaceSources() });
|
|
380
|
+
} catch (err) {
|
|
381
|
+
res.status(400).json({ error: 'Failed to add source', details: err.message });
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// DELETE /marketplace/sources/:id — remove a global source by id.
|
|
386
|
+
router.delete('/marketplace/sources/:id', (req, res) => {
|
|
387
|
+
try {
|
|
388
|
+
const id = String(req.params.id || '');
|
|
389
|
+
const sources = readMarketplaceSources();
|
|
390
|
+
const next = sources.filter((source) => source.id !== id);
|
|
391
|
+
writeMarketplaceSources(next);
|
|
392
|
+
res.json({ success: true, installedSources: next });
|
|
393
|
+
} catch (err) {
|
|
394
|
+
res.status(400).json({ error: 'Failed to remove source', details: err.message });
|
|
395
|
+
}
|
|
396
|
+
});
|
|
27
397
|
|
|
28
398
|
// GET / — List all installed plugins (includes server running status)
|
|
29
399
|
router.get('/', (req, res) => {
|
|
@@ -27,6 +27,9 @@ const PAIRING_TTL_MS = 10 * 60 * 1000;
|
|
|
27
27
|
let bot = null;
|
|
28
28
|
let botInfo = null; // { id, username, first_name }
|
|
29
29
|
let lastError = null;
|
|
30
|
+
let lastTransientPollingLogAt = 0;
|
|
31
|
+
|
|
32
|
+
const TRANSIENT_POLLING_LOG_INTERVAL_MS = 60 * 1000;
|
|
30
33
|
|
|
31
34
|
export const setTelegramBotForTesting = (nextBot) => {
|
|
32
35
|
bot = nextBot;
|
|
@@ -75,6 +78,29 @@ const parseMaybeCode = (text) => {
|
|
|
75
78
|
return /^\d{6}$/.test(trimmed) ? trimmed : null;
|
|
76
79
|
};
|
|
77
80
|
|
|
81
|
+
const isTransientTelegramNetworkError = (err, code = err?.response?.statusCode || err?.code) => {
|
|
82
|
+
if (code === 409) return true;
|
|
83
|
+
const message = String(err?.message || err || '').toLowerCase();
|
|
84
|
+
return message.includes('fetch failed')
|
|
85
|
+
|| message.includes('network')
|
|
86
|
+
|| message.includes('timeout')
|
|
87
|
+
|| message.includes('timed out')
|
|
88
|
+
|| message.includes('econnreset')
|
|
89
|
+
|| message.includes('econnrefused')
|
|
90
|
+
|| message.includes('enotfound')
|
|
91
|
+
|| message.includes('etimedout')
|
|
92
|
+
|| message.includes('socket hang up');
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const logTransientPollingError = (nextError) => {
|
|
96
|
+
const timestamp = Date.now();
|
|
97
|
+
if (timestamp - lastTransientPollingLogAt < TRANSIENT_POLLING_LOG_INTERVAL_MS) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
lastTransientPollingLogAt = timestamp;
|
|
101
|
+
console.log('[telegram] polling temporarily unavailable; retrying with backoff:', nextError);
|
|
102
|
+
};
|
|
103
|
+
|
|
78
104
|
const safeSend = async (chatId, text, extra = {}) => {
|
|
79
105
|
if (!bot) return;
|
|
80
106
|
try {
|
|
@@ -216,8 +242,10 @@ const wirePollingErrors = () => {
|
|
|
216
242
|
if (code === 401) {
|
|
217
243
|
console.error('[telegram] fatal polling error, stopping:', lastError);
|
|
218
244
|
stopBot().catch(() => {});
|
|
245
|
+
} else if (isTransientTelegramNetworkError(err, code)) {
|
|
246
|
+
logTransientPollingError(lastError);
|
|
219
247
|
} else if (code === 409) {
|
|
220
|
-
console.
|
|
248
|
+
console.log('[telegram] polling conflict:', lastError);
|
|
221
249
|
} else {
|
|
222
250
|
console.warn('[telegram] polling error:', lastError);
|
|
223
251
|
}
|
|
@@ -247,9 +275,17 @@ export const startBot = async ({ token, persist = true } = {}) => {
|
|
|
247
275
|
} catch (err) {
|
|
248
276
|
try { await instance.stopPolling(); } catch { /* ignore */ }
|
|
249
277
|
const reason = err?.response?.body?.description || err?.message || String(err);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
278
|
+
const transientNetworkError = isTransientTelegramNetworkError(err);
|
|
279
|
+
lastError = {
|
|
280
|
+
code: transientNetworkError ? 'network' : 'auth',
|
|
281
|
+
message: reason,
|
|
282
|
+
};
|
|
283
|
+
const error = new Error(
|
|
284
|
+
transientNetworkError
|
|
285
|
+
? `Telegram network unavailable: ${reason}`
|
|
286
|
+
: `Invalid bot token: ${reason}`,
|
|
287
|
+
);
|
|
288
|
+
error.code = transientNetworkError ? 'TELEGRAM_NETWORK_UNAVAILABLE' : 'INVALID_TOKEN';
|
|
253
289
|
throw error;
|
|
254
290
|
}
|
|
255
291
|
|
|
@@ -331,6 +367,10 @@ export const restoreBotFromConfig = async () => {
|
|
|
331
367
|
try {
|
|
332
368
|
await startBot({ token: config.bot_token, persist: false });
|
|
333
369
|
} catch (err) {
|
|
334
|
-
|
|
370
|
+
if (err?.code === 'TELEGRAM_NETWORK_UNAVAILABLE') {
|
|
371
|
+
console.log('[telegram] restore delayed; Telegram network unavailable:', err?.message || err);
|
|
372
|
+
} else {
|
|
373
|
+
console.warn('[telegram] Failed to restore bot:', err?.message || err);
|
|
374
|
+
}
|
|
335
375
|
}
|
|
336
376
|
};
|