@kadaliao/dsh-bots 0.3.2 → 0.4.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/README.md +64 -4
- package/README.zh-CN.md +55 -3
- package/client.js +246 -13
- package/icon.svg +1 -1
- package/index.js +125 -18
- package/lib/apps.mjs +67 -3
- package/lib/channels/discord.mjs +590 -0
- package/lib/channels/telegram.mjs +300 -0
- package/lib/channels.mjs +889 -0
- package/lib/logos.mjs +52 -0
- package/lib/prompt.mjs +9 -1
- package/lib/skills.mjs +1 -1
- package/logos/amap.png +0 -0
- package/logos/anthropic.png +0 -0
- package/logos/baidu-map.png +0 -0
- package/logos/brave.png +0 -0
- package/logos/context7.png +0 -0
- package/logos/discord.png +0 -0
- package/logos/exa.png +0 -0
- package/logos/feishu.png +0 -0
- package/logos/firecrawl.png +0 -0
- package/logos/git.png +0 -0
- package/logos/github.png +0 -0
- package/logos/hubspot.png +0 -0
- package/logos/mcp.png +0 -0
- package/logos/notion.png +0 -0
- package/logos/playwright.png +0 -0
- package/logos/postgres.png +0 -0
- package/logos/sentry.png +0 -0
- package/logos/slack.png +0 -0
- package/logos/sqlite.png +0 -0
- package/logos/stripe.png +0 -0
- package/logos/supabase.png +0 -0
- package/logos/tavily.png +0 -0
- package/logos/telegram.png +0 -0
- package/package.json +3 -1
package/index.js
CHANGED
|
@@ -13,12 +13,17 @@
|
|
|
13
13
|
* Nothing touches other conversations, except the bot tools themselves, which
|
|
14
14
|
* every conversation gets so the user can manage bots from anywhere.
|
|
15
15
|
*
|
|
16
|
+
* Chat channel apps (Telegram, Discord) are no MCP servers: lib/channels.mjs
|
|
17
|
+
* keeps a connector running for each, so paired people can message the team
|
|
18
|
+
* from that chat app and read the replies there.
|
|
19
|
+
*
|
|
16
20
|
* @module @kadaliao/dsh-bots
|
|
17
21
|
*/
|
|
18
22
|
|
|
19
23
|
import { createReadStream, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
20
24
|
import { homedir } from 'node:os';
|
|
21
25
|
import { join } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
22
27
|
import { randomUUID } from 'node:crypto';
|
|
23
28
|
|
|
24
29
|
import { createStore, initialsOf, slugify, SKILL_RE, PALETTE } from './lib/store.mjs';
|
|
@@ -28,6 +33,8 @@ import { SKILL_SOURCES, importGithubSkill, importUrlSkill, listGithubSkills, par
|
|
|
28
33
|
import { TEAMS, teamTiming, teamView } from './lib/teams.mjs';
|
|
29
34
|
import { maskedApp, scanExternalMcp } from './lib/mcp-import.mjs';
|
|
30
35
|
import { createUnfurler } from './lib/unfurl.mjs';
|
|
36
|
+
import { isLogoName, withLogo } from './lib/logos.mjs';
|
|
37
|
+
import { CHANNEL_LABELS, channelEntry, channelIssue, createChannels, maskBot, unmaskApps } from './lib/channels.mjs';
|
|
31
38
|
import { describeTiming, dmBody, dmHeader, personaText, textOf, timingFrom, timingOfEntry } from './lib/prompt.mjs';
|
|
32
39
|
|
|
33
40
|
/**
|
|
@@ -95,10 +102,13 @@ export function ocuPath() {
|
|
|
95
102
|
|
|
96
103
|
/** The app catalog the Apps tab offers, with the open-computer-use path in force. */
|
|
97
104
|
export function templates() {
|
|
98
|
-
return appCatalog(ocuPath());
|
|
105
|
+
return appCatalog(ocuPath()).map(withLogo);
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* The mcp-client row of one app of `bot`. Throws APP_INCOMPLETE when a required
|
|
110
|
+
* field is empty; null for a chat channel app, which is no MCP server.
|
|
111
|
+
*/
|
|
102
112
|
export function mcpConfigOf(app, bot) {
|
|
103
113
|
return mcpConfigFor(app, templates(), { bot: bot?.handle ?? 'bot' });
|
|
104
114
|
}
|
|
@@ -159,7 +169,12 @@ const service = (ctx, name) => {
|
|
|
159
169
|
}
|
|
160
170
|
};
|
|
161
171
|
|
|
162
|
-
|
|
172
|
+
/**
|
|
173
|
+
* @param {object} ctx
|
|
174
|
+
* @param {object} config
|
|
175
|
+
* @param {{loadConnector?: (kind: string) => Promise<object>, typingEveryMs?: number}} [deps] - for tests: a stand-in chat connector.
|
|
176
|
+
*/
|
|
177
|
+
export function apply(ctx, config, deps = {}) {
|
|
163
178
|
const cfg = config && typeof config === 'object' ? config : {};
|
|
164
179
|
const dir = join(homeDir(), 'cache', 'bots');
|
|
165
180
|
const store = createStore(dir);
|
|
@@ -198,7 +213,14 @@ export function apply(ctx, config) {
|
|
|
198
213
|
/** sessionId → {agent, signature, disposers[]} */
|
|
199
214
|
const installed = new Map();
|
|
200
215
|
|
|
201
|
-
const
|
|
216
|
+
const isChannel = (app) => Boolean(channelEntry(app, templates()));
|
|
217
|
+
// Chat channels run outside the Agent; changing one does not restart the bot's MCP clients.
|
|
218
|
+
const signatureOf = (bot) => JSON.stringify({ s: bot.skills, a: bot.apps.filter((a) => !isChannel(a)), t: bot.tools, h: bot.handle });
|
|
219
|
+
/** The chat apps the team can be reached from ('Telegram'), for the persona. */
|
|
220
|
+
const channelNames = (bots) => {
|
|
221
|
+
const tpl = templates();
|
|
222
|
+
return [...new Set(bots.flatMap((b) => b.apps.filter((a) => a.enabled && channelEntry(a, tpl)).map((a) => CHANNEL_LABELS[channelEntry(a, tpl).channel] ?? channelEntry(a, tpl).name.en)))];
|
|
223
|
+
};
|
|
202
224
|
|
|
203
225
|
function uninstall(sessionId) {
|
|
204
226
|
const rec = installed.get(sessionId);
|
|
@@ -250,7 +272,7 @@ export function apply(ctx, config) {
|
|
|
250
272
|
}
|
|
251
273
|
} else skillsInline = true;
|
|
252
274
|
}
|
|
253
|
-
const apps = bot.apps.filter((a) => a.enabled);
|
|
275
|
+
const apps = bot.apps.filter((a) => a.enabled && !isChannel(a));
|
|
254
276
|
const appNames = [];
|
|
255
277
|
if (apps.length > 0 && mcpClient && typeof actx.plugin === 'function') {
|
|
256
278
|
for (const app of apps) {
|
|
@@ -276,7 +298,8 @@ export function apply(ctx, config) {
|
|
|
276
298
|
// Read on every assembly: a renamed teammate or edited persona applies at once.
|
|
277
299
|
text: () => {
|
|
278
300
|
const now = store.get(bot.id);
|
|
279
|
-
|
|
301
|
+
const roster = store.list();
|
|
302
|
+
return now ? personaText(now, roster, { skillsInline, skillNames, apps: appNames, channels: channelNames(roster) }) : '';
|
|
280
303
|
},
|
|
281
304
|
}),
|
|
282
305
|
);
|
|
@@ -449,6 +472,32 @@ export function apply(ctx, config) {
|
|
|
449
472
|
return agent.session.id;
|
|
450
473
|
}
|
|
451
474
|
|
|
475
|
+
// --- chat channels: Telegram, Discord -----------------------------------------------------
|
|
476
|
+
const channels = createChannels({
|
|
477
|
+
file: join(dir, 'channels.json'),
|
|
478
|
+
bots: () => store.list(),
|
|
479
|
+
entries: () => templates(),
|
|
480
|
+
// A chat message is a user prompt like one typed in the panel, after a line naming where it came from.
|
|
481
|
+
deliver: async (target, { header, body }) => {
|
|
482
|
+
const agent = await agentOf(target);
|
|
483
|
+
agent.followup(createUserMessage({ content: [{ type: 'text', text: header }, { type: 'text', text: body }], source: { kind: 'user' } }));
|
|
484
|
+
await flush(agent);
|
|
485
|
+
return agent.session.id;
|
|
486
|
+
},
|
|
487
|
+
running: (sessionId) => agents()?.get?.(sessionId)?.status === 'running',
|
|
488
|
+
...(deps.loadConnector ? { loadConnector: deps.loadConnector } : {}),
|
|
489
|
+
...(deps.typingEveryMs ? { typingEveryMs: deps.typingEveryMs } : {}),
|
|
490
|
+
log: (line) => ctx.logger?.info?.(`bots: ${line}`),
|
|
491
|
+
});
|
|
492
|
+
ctx.effect(() => {
|
|
493
|
+
channels.sync();
|
|
494
|
+
const off = store.onChange(() => channels.sync());
|
|
495
|
+
return () => {
|
|
496
|
+
off();
|
|
497
|
+
void channels.stopAll();
|
|
498
|
+
};
|
|
499
|
+
}, 'bots: chat channels');
|
|
500
|
+
|
|
452
501
|
// The timeline: what the user typed to a bot, what the bot answered, scheduled runs.
|
|
453
502
|
const trigger = new Map();
|
|
454
503
|
/** Sessions whose current turn already sent a bot_send_message. */
|
|
@@ -463,8 +512,11 @@ export function apply(ctx, config) {
|
|
|
463
512
|
if (kind === 'schedule' && /^\[SCHEDULE CHANGE\]/.test(textOf(event.data.content))) kind = 'schedule-notice';
|
|
464
513
|
trigger.set(session.id, kind);
|
|
465
514
|
answered.delete(session.id);
|
|
466
|
-
|
|
467
|
-
|
|
515
|
+
const said = textOf(event.data.content);
|
|
516
|
+
// A chat message makes its chat where replies go; any other user message brings them back here.
|
|
517
|
+
const via = channels.noteUserMessage(session.id, bot, kind, said);
|
|
518
|
+
if (kind === 'user') store.log(via ? { from: 'user', to: bot.id, text: via.body, kind: 'user', via: via.kind, who: via.who } : { from: 'user', to: bot.id, text: said, kind: 'user' });
|
|
519
|
+
else if (kind === 'schedule') store.log({ from: 'schedule', to: bot.id, text: said, kind: 'system' });
|
|
468
520
|
} else if (event.type === 'assistant/message') {
|
|
469
521
|
const content = event.data?.message?.content ?? [];
|
|
470
522
|
const calls = content.filter((b) => b?.type === 'tool-call');
|
|
@@ -476,7 +528,13 @@ export function apply(ctx, config) {
|
|
|
476
528
|
// and the closing words of a turn that answered a bot by DM (they reach no one). The
|
|
477
529
|
// dispatcher reporting back after its teammates answered is a message to the user.
|
|
478
530
|
const hidden = why === 'schedule-notice' || (why === 'agent-message' && (bot.role !== 'primary' || answered.has(session.id)));
|
|
479
|
-
if (text && !hidden)
|
|
531
|
+
if (text && !hidden) {
|
|
532
|
+
// Also to the chat the user wrote from, when that is where the conversation is.
|
|
533
|
+
const sent = channels.noteReply(session.id, text);
|
|
534
|
+
store.log({ from: bot.id, to: 'user', text, kind: 'reply', ...(sent ? { via: sent.kind } : {}) });
|
|
535
|
+
}
|
|
536
|
+
} else if (event.type === 'turn/end') {
|
|
537
|
+
channels.noteTurnEnd(session.id);
|
|
480
538
|
}
|
|
481
539
|
} catch {
|
|
482
540
|
// The timeline must never disturb a conversation.
|
|
@@ -891,10 +949,20 @@ export function apply(ctx, config) {
|
|
|
891
949
|
};
|
|
892
950
|
}
|
|
893
951
|
|
|
952
|
+
/** A bot as the page sees it: channel tokens masked. */
|
|
953
|
+
const publicBot = (bot) => (bot ? maskBot(bot, templates()) : bot);
|
|
954
|
+
|
|
894
955
|
function state() {
|
|
956
|
+
const tpl = templates();
|
|
895
957
|
const bots = store.list().map((b) => {
|
|
896
958
|
const appIssues = {};
|
|
897
959
|
for (const app of b.apps) {
|
|
960
|
+
const entry = channelEntry(app, tpl);
|
|
961
|
+
if (entry) {
|
|
962
|
+
const issue = channelIssue(app, entry);
|
|
963
|
+
if (issue) appIssues[app.id] = issue;
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
898
966
|
try {
|
|
899
967
|
mcpConfigOf(app, b);
|
|
900
968
|
} catch (error) {
|
|
@@ -902,7 +970,7 @@ export function apply(ctx, config) {
|
|
|
902
970
|
}
|
|
903
971
|
}
|
|
904
972
|
const skills = b.skills.map((s) => (s.source === 'dsh' && !s.description && dshSkillInfo.get(s.name) ? { ...s, description: dshSkillInfo.get(s.name) } : s));
|
|
905
|
-
return { ...b, skills, status: botStatus(b), appIssues };
|
|
973
|
+
return { ...publicBot(b), skills, status: botStatus(b), appIssues, channels: channels.view(b) };
|
|
906
974
|
});
|
|
907
975
|
const sessionMap = {};
|
|
908
976
|
for (const b of bots) if (b.sessionId) sessionMap[b.sessionId] = b.id;
|
|
@@ -1013,7 +1081,10 @@ export function apply(ctx, config) {
|
|
|
1013
1081
|
const routes = {
|
|
1014
1082
|
teams: { get: () => teamsView() },
|
|
1015
1083
|
'teams/hire': {
|
|
1016
|
-
post: async (body) =>
|
|
1084
|
+
post: async (body) => {
|
|
1085
|
+
const r = await hireTeam(String(body.id ?? ''), body.lang === 'zh' ? 'zh' : 'en', { primary: body.primary !== false });
|
|
1086
|
+
return { ok: true, ...r, bots: r.bots.map(publicBot) };
|
|
1087
|
+
},
|
|
1017
1088
|
},
|
|
1018
1089
|
'skills/library': { get: async () => ({ skills: await dshSkills(), sources: SKILL_SOURCES }) },
|
|
1019
1090
|
'skills/github': {
|
|
@@ -1038,7 +1109,7 @@ export function apply(ctx, config) {
|
|
|
1038
1109
|
}
|
|
1039
1110
|
}
|
|
1040
1111
|
const saved = store.save({ id: bot.id, skills: [...store.get(bot.id).skills, ...added] });
|
|
1041
|
-
return { ok: added.length > 0 || failed.length === 0, bot: saved, added: added.map((x) => x.name), failed, ...(failed.length && !added.length ? { reason: failed[0].reason } : {}) };
|
|
1112
|
+
return { ok: added.length > 0 || failed.length === 0, bot: publicBot(saved), added: added.map((x) => x.name), failed, ...(failed.length && !added.length ? { reason: failed[0].reason } : {}) };
|
|
1042
1113
|
},
|
|
1043
1114
|
},
|
|
1044
1115
|
'skills/write': {
|
|
@@ -1070,7 +1141,7 @@ export function apply(ctx, config) {
|
|
|
1070
1141
|
return { template: a.template, name: a.name, serverName, enabled: true, config: a.config, values: {} };
|
|
1071
1142
|
});
|
|
1072
1143
|
const saved = store.save({ id: bot.id, apps: [...bot.apps, ...apps] });
|
|
1073
|
-
return { ok: true, bot: saved, added: apps.map((a) => a.name) };
|
|
1144
|
+
return { ok: true, bot: publicBot(saved), added: apps.map((a) => a.name) };
|
|
1074
1145
|
},
|
|
1075
1146
|
},
|
|
1076
1147
|
// The first read fills Harness skill descriptions for skills stored without one.
|
|
@@ -1097,9 +1168,11 @@ export function apply(ctx, config) {
|
|
|
1097
1168
|
delete input.sessionId;
|
|
1098
1169
|
delete input.status;
|
|
1099
1170
|
if (prev?.avatar?.kind === 'image' && input.avatar?.kind === 'image') input.avatar = { ...input.avatar, url: prev.avatar.url };
|
|
1171
|
+
// The page holds channel tokens masked; a mask sent back keeps the stored token.
|
|
1172
|
+
if (Array.isArray(input.apps)) input.apps = unmaskApps(input.apps, prev?.apps ?? [], templates());
|
|
1100
1173
|
const bot = store.save(input, { createdBy: 'user' });
|
|
1101
1174
|
applyModel(bot);
|
|
1102
|
-
return { ok: true, bot: { ...bot, status: botStatus(bot) } };
|
|
1175
|
+
return { ok: true, bot: { ...publicBot(bot), status: botStatus(bot) } };
|
|
1103
1176
|
},
|
|
1104
1177
|
},
|
|
1105
1178
|
delete: {
|
|
@@ -1138,14 +1211,14 @@ export function apply(ctx, config) {
|
|
|
1138
1211
|
writeFileSync(join(dir, 'avatars', bot.id), bytes);
|
|
1139
1212
|
writeFileSync(join(dir, 'avatars', `${bot.id}.type`), m[1]);
|
|
1140
1213
|
const saved = store.patch(bot.id, { avatar: { kind: 'image', url: `${R}/avatar/${bot.id}?v=${Date.now().toString(36)}`, color: bot.avatar.color } });
|
|
1141
|
-
return { ok: true, bot: saved };
|
|
1214
|
+
return { ok: true, bot: publicBot(saved) };
|
|
1142
1215
|
},
|
|
1143
1216
|
},
|
|
1144
1217
|
'avatar/generate': {
|
|
1145
1218
|
post: async (body) => {
|
|
1146
1219
|
const bot = store.get(String(body.id ?? ''));
|
|
1147
1220
|
if (!bot) return { ok: false, reason: 'no such bot' };
|
|
1148
|
-
return { ok: true, bot: await generateAvatar(bot, body.style) };
|
|
1221
|
+
return { ok: true, bot: publicBot(await generateAvatar(bot, body.style)) };
|
|
1149
1222
|
},
|
|
1150
1223
|
},
|
|
1151
1224
|
'avatar/clear': {
|
|
@@ -1153,7 +1226,7 @@ export function apply(ctx, config) {
|
|
|
1153
1226
|
const bot = store.get(String(body.id ?? ''));
|
|
1154
1227
|
if (!bot) return { ok: false, reason: 'no such bot' };
|
|
1155
1228
|
for (const f of [bot.id, `${bot.id}.type`]) rmSync(join(dir, 'avatars', f), { force: true });
|
|
1156
|
-
return { ok: true, bot: store.patch(bot.id, { avatar: { kind: 'initials', color: bot.avatar.color } }) };
|
|
1229
|
+
return { ok: true, bot: publicBot(store.patch(bot.id, { avatar: { kind: 'initials', color: bot.avatar.color } })) };
|
|
1157
1230
|
},
|
|
1158
1231
|
},
|
|
1159
1232
|
'ocu/install': {
|
|
@@ -1189,6 +1262,15 @@ export function apply(ctx, config) {
|
|
|
1189
1262
|
post: async (body) => ({ ok: true, task: entryView(checkEntry(await schedule().edit({ id: String(body.id ?? ''), action: 'update', patch: { active: body.active === true } }))) }),
|
|
1190
1263
|
},
|
|
1191
1264
|
'schedules/run': { post: async (body) => (checkEntry(await schedule().run({ id: String(body.id ?? '') })), { ok: true }) },
|
|
1265
|
+
// Chat channels: a pairing code, forgetting a paired person, options, reconnecting.
|
|
1266
|
+
'channels/code': { post: (body) => ({ ok: true, ...channels.newCode(String(body.botId ?? ''), String(body.appId ?? '')) }) },
|
|
1267
|
+
'channels/unpair': {
|
|
1268
|
+
post: (body) => (channels.unpair(String(body.botId ?? ''), String(body.appId ?? ''), String(body.userId ?? '')) ? { ok: true } : { ok: false, reason: 'no such paired person' }),
|
|
1269
|
+
},
|
|
1270
|
+
'channels/options': {
|
|
1271
|
+
post: (body) => ({ ok: true, ...channels.setOptions(String(body.botId ?? ''), String(body.appId ?? ''), { ...(typeof body.scheduleReplies === 'boolean' ? { scheduleReplies: body.scheduleReplies } : {}) }) }),
|
|
1272
|
+
},
|
|
1273
|
+
'channels/reconnect': { post: (body) => ({ ok: channels.reconnect(String(body.botId ?? ''), String(body.appId ?? '')) }) },
|
|
1192
1274
|
};
|
|
1193
1275
|
|
|
1194
1276
|
const mountRoutes = (scope) => {
|
|
@@ -1210,11 +1292,12 @@ export function apply(ctx, config) {
|
|
|
1210
1292
|
);
|
|
1211
1293
|
}
|
|
1212
1294
|
scope.effect(() => web.register({ kind: 'prefix', path: `${R}/avatar`, handler: (req, res) => serveAvatar(dir, req, res) }));
|
|
1295
|
+
scope.effect(() => web.register({ kind: 'prefix', path: `${R}/logo`, handler: (req, res) => serveLogo(req, res) }));
|
|
1213
1296
|
};
|
|
1214
1297
|
if (typeof ctx.inject === 'function') ctx.inject(['webServer'], mountRoutes);
|
|
1215
1298
|
else if (ctx.webServer) mountRoutes({ webServer: ctx.webServer, effect: (fn) => ctx.effect(fn) });
|
|
1216
1299
|
|
|
1217
|
-
return { store, state, deliver, install, reconcile, installed, routes };
|
|
1300
|
+
return { store, state, deliver, install, reconcile, installed, routes, channels };
|
|
1218
1301
|
}
|
|
1219
1302
|
|
|
1220
1303
|
function serveAvatar(dir, req, res) {
|
|
@@ -1240,6 +1323,30 @@ function serveAvatar(dir, req, res) {
|
|
|
1240
1323
|
createReadStream(file).pipe(res);
|
|
1241
1324
|
}
|
|
1242
1325
|
|
|
1326
|
+
const LOGO_DIR = fileURLToPath(new URL('./logos/', import.meta.url));
|
|
1327
|
+
|
|
1328
|
+
/** `${R}/logo/<name>.png`: an app logo shipped with the plugin. */
|
|
1329
|
+
export function serveLogo(req, res) {
|
|
1330
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
1331
|
+
const m = /^([a-z0-9-]+)\.png$/.exec(decodeURIComponent(url.pathname.slice(`${R}/logo/`.length)));
|
|
1332
|
+
const file = m && isLogoName(m[1]) ? join(LOGO_DIR, `${m[1]}.png`) : '';
|
|
1333
|
+
let size = 0;
|
|
1334
|
+
try {
|
|
1335
|
+
if (!file) throw new Error('bad name');
|
|
1336
|
+
size = statSync(file).size;
|
|
1337
|
+
} catch {
|
|
1338
|
+
res.statusCode = 404;
|
|
1339
|
+
res.end();
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
res.statusCode = 200;
|
|
1343
|
+
res.setHeader('content-type', 'image/png');
|
|
1344
|
+
res.setHeader('content-length', String(size));
|
|
1345
|
+
res.setHeader('cache-control', 'public, max-age=86400');
|
|
1346
|
+
if (req.method === 'HEAD') return void res.end();
|
|
1347
|
+
createReadStream(file).pipe(res);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1243
1350
|
function readSmall(path) {
|
|
1244
1351
|
try {
|
|
1245
1352
|
return statSync(path).size < 100 ? readFileSync(path, 'utf8').trim() : '';
|
package/lib/apps.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app catalog: MCP servers a bot can connect, each described well enough
|
|
3
|
-
* that the panel shows a form (keys, paths) instead of a command line
|
|
3
|
+
* that the panel shows a form (keys, paths) instead of a command line, and
|
|
4
|
+
* chat channels (`kind: 'channel'`: Telegram, Discord) people message the team
|
|
5
|
+
* from, which lib/channels.mjs runs instead of an MCP client.
|
|
4
6
|
*
|
|
5
7
|
* Every entry is checked against its registry (npm / PyPI) or vendor docs;
|
|
6
8
|
* the command runs through `npx` / `uvx`, so nothing is installed up front.
|
|
@@ -13,7 +15,7 @@ import { join } from 'node:path';
|
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* @typedef {{key: string, label: {en: string, zh: string}, kind: 'secret'|'text'|'path', env?: string, header?: string, prefix?: string, arg?: boolean, required?: boolean, placeholder?: string, help?: {en: string, zh: string}, default?: string}} AppField
|
|
16
|
-
* @typedef {{id: string, name: {en: string, zh: string}, description: {en: string, zh: string}, category: string, icon: string, color: string, transport
|
|
18
|
+
* @typedef {{id: string, kind?: 'channel', channel?: string, name: {en: string, zh: string}, description: {en: string, zh: string}, category: string, icon: string, color: string, transport?: 'stdio'|'streamable-http', serverName: string, command?: string, args?: string[], url?: string, fields?: AppField[], runtime?: 'node'|'uv'|'binary', homepage: string, keyUrl?: string, region?: 'cn'|'global', featured?: boolean, tags?: string[]}} AppEntry
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
export const CATEGORIES = [
|
|
@@ -306,6 +308,65 @@ export function catalog(ocuPath = '') {
|
|
|
306
308
|
keyUrl: 'https://api.slack.com/apps',
|
|
307
309
|
fields: [key('SLACK_BOT_TOKEN', L('Bot token', 'Bot 令牌'), null, { placeholder: 'xoxb-…' }), { key: 'SLACK_TEAM_ID', env: 'SLACK_TEAM_ID', kind: 'text', required: true, label: L('Team ID', 'Team ID'), placeholder: 'T01234567' }],
|
|
308
310
|
},
|
|
311
|
+
{
|
|
312
|
+
id: 'telegram',
|
|
313
|
+
kind: 'channel',
|
|
314
|
+
channel: 'telegram',
|
|
315
|
+
name: L('Telegram', 'Telegram'),
|
|
316
|
+
description: L(
|
|
317
|
+
'Message your bot team from Telegram: hand out work from your phone and get the reports back in the chat. Only people you pair can talk to it.',
|
|
318
|
+
'在 Telegram 里给 Bot 团队发消息:用手机派活,汇报直接回到聊天里。只有你配对过的人能和它说话。',
|
|
319
|
+
),
|
|
320
|
+
category: 'work',
|
|
321
|
+
icon: 'TG',
|
|
322
|
+
color: '#229ED9',
|
|
323
|
+
serverName: 'telegram',
|
|
324
|
+
homepage: 'https://core.telegram.org/bots/features#botfather',
|
|
325
|
+
keyUrl: 'https://t.me/BotFather',
|
|
326
|
+
featured: true,
|
|
327
|
+
fields: [
|
|
328
|
+
{
|
|
329
|
+
key: 'token',
|
|
330
|
+
kind: 'secret',
|
|
331
|
+
required: true,
|
|
332
|
+
label: L('Bot token', 'Bot Token'),
|
|
333
|
+
placeholder: '123456789:AA…',
|
|
334
|
+
help: L(
|
|
335
|
+
'In Telegram, message @BotFather, send /newbot, choose a name and a username ending in "bot", then paste the token it gives you. Use a bot made for this team only.',
|
|
336
|
+
'在 Telegram 里找 @BotFather,发送 /newbot,起一个名字和以 bot 结尾的用户名,再把它给你的 Token 粘贴到这里。请用专门给这个团队新建的 Bot。',
|
|
337
|
+
),
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
id: 'discord',
|
|
343
|
+
kind: 'channel',
|
|
344
|
+
channel: 'discord',
|
|
345
|
+
name: L('Discord', 'Discord'),
|
|
346
|
+
description: L(
|
|
347
|
+
'Message your bot team from Discord: DM the bot, or @mention it in a server channel. Only people you pair can talk to it.',
|
|
348
|
+
'在 Discord 里给 Bot 团队发消息:私信它,或在服务器频道里 @ 它。只有你配对过的人能和它说话。',
|
|
349
|
+
),
|
|
350
|
+
category: 'work',
|
|
351
|
+
icon: 'DC',
|
|
352
|
+
color: '#5865F2',
|
|
353
|
+
serverName: 'discord',
|
|
354
|
+
homepage: 'https://discord.com/developers/docs/quick-start/getting-started',
|
|
355
|
+
keyUrl: 'https://discord.com/developers/applications',
|
|
356
|
+
featured: true,
|
|
357
|
+
fields: [
|
|
358
|
+
{
|
|
359
|
+
key: 'token',
|
|
360
|
+
kind: 'secret',
|
|
361
|
+
required: true,
|
|
362
|
+
label: L('Bot token', 'Bot Token'),
|
|
363
|
+
help: L(
|
|
364
|
+
'Developer Portal → New Application → Bot → Reset Token, and copy it. On the same page turn on Message Content Intent (without it the bot cannot read messages). Then invite the bot to a server you are in (the invite link appears here once it connects, or OAuth2 → URL Generator with the "bot" scope), so you can DM it.',
|
|
365
|
+
'开发者后台 → New Application → Bot → Reset Token,复制 Token。在同一页打开 Message Content Intent(不开就读不到消息)。再把 Bot 邀请进一个你所在的服务器(连上后这里会显示邀请链接,或在 OAuth2 → URL Generator 勾选 bot),这样才能私信它。',
|
|
366
|
+
),
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
},
|
|
309
370
|
{
|
|
310
371
|
id: 'stripe',
|
|
311
372
|
name: L('Stripe', 'Stripe 收款'),
|
|
@@ -407,13 +468,16 @@ export function catalog(ocuPath = '') {
|
|
|
407
468
|
/**
|
|
408
469
|
* The mcp-client row of one app: the template's command, with the app's field
|
|
409
470
|
* values placed as environment variables, headers, query params or arguments.
|
|
410
|
-
* Custom apps (and old rows) use their own `config` as written.
|
|
471
|
+
* Custom apps (and old rows) use their own `config` as written. A chat
|
|
472
|
+
* channel app is not an MCP server: null.
|
|
411
473
|
* @param {object} app - `{template, serverName, values?, config?}`
|
|
412
474
|
* @param {AppEntry[]} entries
|
|
413
475
|
* @param {{bot?: string}} [ctx]
|
|
414
476
|
*/
|
|
415
477
|
export function mcpConfigFor(app, entries, ctx = {}) {
|
|
416
478
|
const t = entries.find((e) => e.id === app.template);
|
|
479
|
+
// A chat channel (Telegram, Discord) is no MCP server: lib/channels.mjs runs it.
|
|
480
|
+
if (t?.kind === 'channel') return null;
|
|
417
481
|
const values = app.values && typeof app.values === 'object' ? app.values : {};
|
|
418
482
|
const reconnect = { maxAttempts: 3 };
|
|
419
483
|
const fill = (v) => String(v ?? '').replaceAll('{bot}', ctx.bot ?? 'bot');
|