@kadaliao/dsh-bots 0.3.3 → 0.6.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 +142 -4
- package/README.zh-CN.md +119 -3
- package/client.js +564 -43
- package/index.js +186 -25
- package/lib/apps.mjs +150 -5
- package/lib/channels/discord.mjs +590 -0
- package/lib/channels/feishu.mjs +1249 -0
- package/lib/channels/slack.mjs +906 -0
- package/lib/channels/telegram.mjs +300 -0
- package/lib/channels.mjs +893 -0
- package/lib/logos.mjs +54 -0
- package/lib/prompt.mjs +9 -1
- package/lib/skills.mjs +199 -6
- package/lib/store.mjs +22 -3
- 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,21 +13,28 @@
|
|
|
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, Feishu / Lark, Slack) 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
|
-
import { join } from 'node:path';
|
|
25
|
+
import { join, sep } 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';
|
|
25
30
|
import { catalog as appCatalog, CATEGORIES, mcpConfigFor } from './lib/apps.mjs';
|
|
26
31
|
import { ABILITIES } from './lib/abilities.mjs';
|
|
27
|
-
import { SKILL_SOURCES, importGithubSkill, importUrlSkill, listGithubSkills, parseGithub } from './lib/skills.mjs';
|
|
32
|
+
import { SKILL_SOURCES, importGithubSkill, importUrlSkill, linkLocalSkill, listGithubSkills, listLocalSkills, mergeImported, parseGithub, readLinkedSkill, resolveLocalPath } from './lib/skills.mjs';
|
|
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,15 @@ 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
|
+
// A linked local skill counts by what its SKILL.md is now, so an edit there re-installs it.
|
|
219
|
+
const signatureOf = (bot) => JSON.stringify({ s: bot.skills, l: bot.skills.filter((s) => s.linked && s.enabled).map((s) => readLinkedSkill(s.dir)?.stamp ?? ''), a: bot.apps.filter((a) => !isChannel(a)), t: bot.tools, h: bot.handle });
|
|
220
|
+
/** The chat apps the team can be reached from ('Telegram'), for the persona. */
|
|
221
|
+
const channelNames = (bots) => {
|
|
222
|
+
const tpl = templates();
|
|
223
|
+
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)))];
|
|
224
|
+
};
|
|
202
225
|
|
|
203
226
|
function uninstall(sessionId) {
|
|
204
227
|
const rec = installed.get(sessionId);
|
|
@@ -228,7 +251,11 @@ export function apply(ctx, config) {
|
|
|
228
251
|
const local = enabledSkills.filter((s) => s.source !== 'dsh');
|
|
229
252
|
if (local.length > 0) {
|
|
230
253
|
if (skills && typeof skills.register === 'function') {
|
|
231
|
-
for (const
|
|
254
|
+
for (const stored of local) {
|
|
255
|
+
// A linked folder speaks for itself; what was stored when it was linked stands in if it is gone.
|
|
256
|
+
const live = stored.linked ? readLinkedSkill(stored.dir) : null;
|
|
257
|
+
if (stored.linked && !live) ctx.logger?.warn?.(`bots: skill folder ${stored.dir} of @${bot.handle} is gone; using what was read when it was linked`);
|
|
258
|
+
const s = live ? { ...stored, description: live.description || stored.description, content: live.content } : stored;
|
|
232
259
|
let n = slugify(s.name, 'skill');
|
|
233
260
|
if (!SKILL_RE.test(n)) n = `skill-${s.id.slice(-5)}`;
|
|
234
261
|
n = `${bot.handle}-${n}`.slice(0, 64).replace(/-+$/, '');
|
|
@@ -250,7 +277,7 @@ export function apply(ctx, config) {
|
|
|
250
277
|
}
|
|
251
278
|
} else skillsInline = true;
|
|
252
279
|
}
|
|
253
|
-
const apps = bot.apps.filter((a) => a.enabled);
|
|
280
|
+
const apps = bot.apps.filter((a) => a.enabled && !isChannel(a));
|
|
254
281
|
const appNames = [];
|
|
255
282
|
if (apps.length > 0 && mcpClient && typeof actx.plugin === 'function') {
|
|
256
283
|
for (const app of apps) {
|
|
@@ -276,7 +303,8 @@ export function apply(ctx, config) {
|
|
|
276
303
|
// Read on every assembly: a renamed teammate or edited persona applies at once.
|
|
277
304
|
text: () => {
|
|
278
305
|
const now = store.get(bot.id);
|
|
279
|
-
|
|
306
|
+
const roster = store.list();
|
|
307
|
+
return now ? personaText(now, roster, { skillsInline, skillNames, apps: appNames, channels: channelNames(roster) }) : '';
|
|
280
308
|
},
|
|
281
309
|
}),
|
|
282
310
|
);
|
|
@@ -449,6 +477,32 @@ export function apply(ctx, config) {
|
|
|
449
477
|
return agent.session.id;
|
|
450
478
|
}
|
|
451
479
|
|
|
480
|
+
// --- chat channels: Telegram, Discord, Feishu / Lark, Slack -------------------------------
|
|
481
|
+
const channels = createChannels({
|
|
482
|
+
file: join(dir, 'channels.json'),
|
|
483
|
+
bots: () => store.list(),
|
|
484
|
+
entries: () => templates(),
|
|
485
|
+
// A chat message is a user prompt like one typed in the panel, after a line naming where it came from.
|
|
486
|
+
deliver: async (target, { header, body }) => {
|
|
487
|
+
const agent = await agentOf(target);
|
|
488
|
+
agent.followup(createUserMessage({ content: [{ type: 'text', text: header }, { type: 'text', text: body }], source: { kind: 'user' } }));
|
|
489
|
+
await flush(agent);
|
|
490
|
+
return agent.session.id;
|
|
491
|
+
},
|
|
492
|
+
running: (sessionId) => agents()?.get?.(sessionId)?.status === 'running',
|
|
493
|
+
...(deps.loadConnector ? { loadConnector: deps.loadConnector } : {}),
|
|
494
|
+
...(deps.typingEveryMs ? { typingEveryMs: deps.typingEveryMs } : {}),
|
|
495
|
+
log: (line) => ctx.logger?.info?.(`bots: ${line}`),
|
|
496
|
+
});
|
|
497
|
+
ctx.effect(() => {
|
|
498
|
+
channels.sync();
|
|
499
|
+
const off = store.onChange(() => channels.sync());
|
|
500
|
+
return () => {
|
|
501
|
+
off();
|
|
502
|
+
void channels.stopAll();
|
|
503
|
+
};
|
|
504
|
+
}, 'bots: chat channels');
|
|
505
|
+
|
|
452
506
|
// The timeline: what the user typed to a bot, what the bot answered, scheduled runs.
|
|
453
507
|
const trigger = new Map();
|
|
454
508
|
/** Sessions whose current turn already sent a bot_send_message. */
|
|
@@ -463,8 +517,11 @@ export function apply(ctx, config) {
|
|
|
463
517
|
if (kind === 'schedule' && /^\[SCHEDULE CHANGE\]/.test(textOf(event.data.content))) kind = 'schedule-notice';
|
|
464
518
|
trigger.set(session.id, kind);
|
|
465
519
|
answered.delete(session.id);
|
|
466
|
-
|
|
467
|
-
|
|
520
|
+
const said = textOf(event.data.content);
|
|
521
|
+
// A chat message makes its chat where replies go; any other user message brings them back here.
|
|
522
|
+
const via = channels.noteUserMessage(session.id, bot, kind, said);
|
|
523
|
+
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' });
|
|
524
|
+
else if (kind === 'schedule') store.log({ from: 'schedule', to: bot.id, text: said, kind: 'system' });
|
|
468
525
|
} else if (event.type === 'assistant/message') {
|
|
469
526
|
const content = event.data?.message?.content ?? [];
|
|
470
527
|
const calls = content.filter((b) => b?.type === 'tool-call');
|
|
@@ -476,7 +533,13 @@ export function apply(ctx, config) {
|
|
|
476
533
|
// and the closing words of a turn that answered a bot by DM (they reach no one). The
|
|
477
534
|
// dispatcher reporting back after its teammates answered is a message to the user.
|
|
478
535
|
const hidden = why === 'schedule-notice' || (why === 'agent-message' && (bot.role !== 'primary' || answered.has(session.id)));
|
|
479
|
-
if (text && !hidden)
|
|
536
|
+
if (text && !hidden) {
|
|
537
|
+
// Also to the chat the user wrote from, when that is where the conversation is.
|
|
538
|
+
const sent = channels.noteReply(session.id, text);
|
|
539
|
+
store.log({ from: bot.id, to: 'user', text, kind: 'reply', ...(sent ? { via: sent.kind } : {}) });
|
|
540
|
+
}
|
|
541
|
+
} else if (event.type === 'turn/end') {
|
|
542
|
+
channels.noteTurnEnd(session.id);
|
|
480
543
|
}
|
|
481
544
|
} catch {
|
|
482
545
|
// The timeline must never disturb a conversation.
|
|
@@ -891,18 +954,34 @@ export function apply(ctx, config) {
|
|
|
891
954
|
};
|
|
892
955
|
}
|
|
893
956
|
|
|
957
|
+
/** A bot as the page sees it: channel tokens masked. */
|
|
958
|
+
const publicBot = (bot) => (bot ? maskBot(bot, templates()) : bot);
|
|
959
|
+
|
|
894
960
|
function state() {
|
|
961
|
+
const tpl = templates();
|
|
895
962
|
const bots = store.list().map((b) => {
|
|
896
963
|
const appIssues = {};
|
|
897
964
|
for (const app of b.apps) {
|
|
965
|
+
const entry = channelEntry(app, tpl);
|
|
966
|
+
if (entry) {
|
|
967
|
+
const issue = channelIssue(app, entry);
|
|
968
|
+
if (issue) appIssues[app.id] = issue;
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
898
971
|
try {
|
|
899
972
|
mcpConfigOf(app, b);
|
|
900
973
|
} catch (error) {
|
|
901
974
|
appIssues[app.id] = error?.message ?? String(error);
|
|
902
975
|
}
|
|
903
976
|
}
|
|
904
|
-
const skills = b.skills.map((s) =>
|
|
905
|
-
|
|
977
|
+
const skills = b.skills.map((s) => {
|
|
978
|
+
if (s.source === 'dsh' && !s.description && dshSkillInfo.get(s.name)) return { ...s, description: dshSkillInfo.get(s.name) };
|
|
979
|
+
if (!s.linked) return s;
|
|
980
|
+
// A linked folder is shown as it is now, or flagged when it is gone.
|
|
981
|
+
const live = readLinkedSkill(s.dir);
|
|
982
|
+
return live ? { ...s, description: live.description || s.description, content: live.content } : { ...s, missing: true };
|
|
983
|
+
});
|
|
984
|
+
return { ...publicBot(b), skills, status: botStatus(b), appIssues, channels: channels.view(b) };
|
|
906
985
|
});
|
|
907
986
|
const sessionMap = {};
|
|
908
987
|
for (const b of bots) if (b.sessionId) sessionMap[b.sessionId] = b.id;
|
|
@@ -912,17 +991,38 @@ export function apply(ctx, config) {
|
|
|
912
991
|
let ocuInstalling = false;
|
|
913
992
|
// --- skills from elsewhere -------------------------------------------------------
|
|
914
993
|
const skillDir = join(dir, 'skills');
|
|
915
|
-
/** Import one skill (GitHub folder or URL) as a bot skill object, files kept under the cache. */
|
|
994
|
+
/** Import one skill (local folder, GitHub folder or URL) as a bot skill object, files kept under the cache. */
|
|
916
995
|
async function importSkill(spec) {
|
|
917
996
|
const signal = AbortSignal.timeout(120_000);
|
|
918
997
|
const id = `skill-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
998
|
+
if (typeof spec.local === 'string' && spec.local.trim() !== '') return { id, source: 'import', enabled: true, ...linkLocalSkill(spec.local) };
|
|
919
999
|
const gh = spec.repo ? { ...parseGithub(spec.repo), ...(spec.path !== undefined ? { path: spec.path } : {}), ...(spec.ref ? { ref: spec.ref } : {}) } : parseGithub(spec.url ?? '');
|
|
920
1000
|
if (gh) {
|
|
921
1001
|
const got = await importGithubSkill(gh, skillDir, id, { signal });
|
|
922
1002
|
return { id, source: 'import', enabled: true, ...got };
|
|
923
1003
|
}
|
|
924
1004
|
if (/^https?:\/\//.test(String(spec.url ?? ''))) return { id, source: 'import', enabled: true, ...(await importUrlSkill(spec.url, { signal })) };
|
|
925
|
-
throw new Error('give a GitHub repository or folder (owner/repo/path) or a SKILL.md URL');
|
|
1005
|
+
throw new Error('give a local folder, a GitHub repository or folder (owner/repo/path) or a SKILL.md URL');
|
|
1006
|
+
}
|
|
1007
|
+
/** Remove copied skill folders nothing points at any more (only ever inside the bots cache). */
|
|
1008
|
+
function dropSkillDirs(skills) {
|
|
1009
|
+
const used = new Set(store.list().flatMap((b) => b.skills.map((s) => s.dir).filter(Boolean)));
|
|
1010
|
+
for (const s of skills) {
|
|
1011
|
+
if (typeof s.dir === 'string' && s.dir.startsWith(skillDir + sep) && !used.has(s.dir)) rmSync(s.dir, { recursive: true, force: true });
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
/** Folders on this machine where other agents keep skills, as one-click starting points. */
|
|
1015
|
+
function localSkillPlaces() {
|
|
1016
|
+
const home = homedir();
|
|
1017
|
+
return [join(home, '.claude', 'skills'), join(home, '.codex', 'skills'), join(home, '.agents', 'skills')]
|
|
1018
|
+
.filter((p) => {
|
|
1019
|
+
try {
|
|
1020
|
+
return statSync(p).isDirectory();
|
|
1021
|
+
} catch {
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
})
|
|
1025
|
+
.map((p) => ({ path: p, label: `~${p.slice(home.length)}` }));
|
|
926
1026
|
}
|
|
927
1027
|
|
|
928
1028
|
// --- teams -------------------------------------------------------------------------
|
|
@@ -1013,7 +1113,10 @@ export function apply(ctx, config) {
|
|
|
1013
1113
|
const routes = {
|
|
1014
1114
|
teams: { get: () => teamsView() },
|
|
1015
1115
|
'teams/hire': {
|
|
1016
|
-
post: async (body) =>
|
|
1116
|
+
post: async (body) => {
|
|
1117
|
+
const r = await hireTeam(String(body.id ?? ''), body.lang === 'zh' ? 'zh' : 'en', { primary: body.primary !== false });
|
|
1118
|
+
return { ok: true, ...r, bots: r.bots.map(publicBot) };
|
|
1119
|
+
},
|
|
1017
1120
|
},
|
|
1018
1121
|
'skills/library': { get: async () => ({ skills: await dshSkills(), sources: SKILL_SOURCES }) },
|
|
1019
1122
|
'skills/github': {
|
|
@@ -1037,8 +1140,30 @@ export function apply(ctx, config) {
|
|
|
1037
1140
|
failed.push({ spec, reason: error?.message ?? String(error) });
|
|
1038
1141
|
}
|
|
1039
1142
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1143
|
+
// No doubles: a name the bot already has is updated (same origin) or skipped, never added again.
|
|
1144
|
+
const merged = mergeImported(store.get(bot.id).skills, added);
|
|
1145
|
+
const changed = merged.added.length + merged.updated.length > 0;
|
|
1146
|
+
const saved = changed ? store.save({ id: bot.id, skills: merged.skills }) : store.get(bot.id);
|
|
1147
|
+
dropSkillDirs(merged.dropped);
|
|
1148
|
+
return {
|
|
1149
|
+
ok: changed || failed.length === 0,
|
|
1150
|
+
bot: publicBot(saved),
|
|
1151
|
+
added: merged.added,
|
|
1152
|
+
updated: merged.updated,
|
|
1153
|
+
skipped: merged.skipped,
|
|
1154
|
+
failed,
|
|
1155
|
+
...(failed.length && !changed ? { reason: failed[0].reason } : {}),
|
|
1156
|
+
};
|
|
1157
|
+
},
|
|
1158
|
+
},
|
|
1159
|
+
'skills/local': {
|
|
1160
|
+
get: () => ({ places: localSkillPlaces() }),
|
|
1161
|
+
post: (body) => {
|
|
1162
|
+
try {
|
|
1163
|
+
return { ok: true, ...listLocalSkills(String(body.path ?? '')) };
|
|
1164
|
+
} catch (error) {
|
|
1165
|
+
return { ok: false, reason: error?.message ?? String(error), path: resolveLocalPath(String(body.path ?? '')) };
|
|
1166
|
+
}
|
|
1042
1167
|
},
|
|
1043
1168
|
},
|
|
1044
1169
|
'skills/write': {
|
|
@@ -1070,7 +1195,7 @@ export function apply(ctx, config) {
|
|
|
1070
1195
|
return { template: a.template, name: a.name, serverName, enabled: true, config: a.config, values: {} };
|
|
1071
1196
|
});
|
|
1072
1197
|
const saved = store.save({ id: bot.id, apps: [...bot.apps, ...apps] });
|
|
1073
|
-
return { ok: true, bot: saved, added: apps.map((a) => a.name) };
|
|
1198
|
+
return { ok: true, bot: publicBot(saved), added: apps.map((a) => a.name) };
|
|
1074
1199
|
},
|
|
1075
1200
|
},
|
|
1076
1201
|
// The first read fills Harness skill descriptions for skills stored without one.
|
|
@@ -1097,9 +1222,11 @@ export function apply(ctx, config) {
|
|
|
1097
1222
|
delete input.sessionId;
|
|
1098
1223
|
delete input.status;
|
|
1099
1224
|
if (prev?.avatar?.kind === 'image' && input.avatar?.kind === 'image') input.avatar = { ...input.avatar, url: prev.avatar.url };
|
|
1225
|
+
// The page holds channel tokens masked; a mask sent back keeps the stored token.
|
|
1226
|
+
if (Array.isArray(input.apps)) input.apps = unmaskApps(input.apps, prev?.apps ?? [], templates());
|
|
1100
1227
|
const bot = store.save(input, { createdBy: 'user' });
|
|
1101
1228
|
applyModel(bot);
|
|
1102
|
-
return { ok: true, bot: { ...bot, status: botStatus(bot) } };
|
|
1229
|
+
return { ok: true, bot: { ...publicBot(bot), status: botStatus(bot) } };
|
|
1103
1230
|
},
|
|
1104
1231
|
},
|
|
1105
1232
|
delete: {
|
|
@@ -1138,14 +1265,14 @@ export function apply(ctx, config) {
|
|
|
1138
1265
|
writeFileSync(join(dir, 'avatars', bot.id), bytes);
|
|
1139
1266
|
writeFileSync(join(dir, 'avatars', `${bot.id}.type`), m[1]);
|
|
1140
1267
|
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 };
|
|
1268
|
+
return { ok: true, bot: publicBot(saved) };
|
|
1142
1269
|
},
|
|
1143
1270
|
},
|
|
1144
1271
|
'avatar/generate': {
|
|
1145
1272
|
post: async (body) => {
|
|
1146
1273
|
const bot = store.get(String(body.id ?? ''));
|
|
1147
1274
|
if (!bot) return { ok: false, reason: 'no such bot' };
|
|
1148
|
-
return { ok: true, bot: await generateAvatar(bot, body.style) };
|
|
1275
|
+
return { ok: true, bot: publicBot(await generateAvatar(bot, body.style)) };
|
|
1149
1276
|
},
|
|
1150
1277
|
},
|
|
1151
1278
|
'avatar/clear': {
|
|
@@ -1153,7 +1280,7 @@ export function apply(ctx, config) {
|
|
|
1153
1280
|
const bot = store.get(String(body.id ?? ''));
|
|
1154
1281
|
if (!bot) return { ok: false, reason: 'no such bot' };
|
|
1155
1282
|
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 } }) };
|
|
1283
|
+
return { ok: true, bot: publicBot(store.patch(bot.id, { avatar: { kind: 'initials', color: bot.avatar.color } })) };
|
|
1157
1284
|
},
|
|
1158
1285
|
},
|
|
1159
1286
|
'ocu/install': {
|
|
@@ -1189,6 +1316,15 @@ export function apply(ctx, config) {
|
|
|
1189
1316
|
post: async (body) => ({ ok: true, task: entryView(checkEntry(await schedule().edit({ id: String(body.id ?? ''), action: 'update', patch: { active: body.active === true } }))) }),
|
|
1190
1317
|
},
|
|
1191
1318
|
'schedules/run': { post: async (body) => (checkEntry(await schedule().run({ id: String(body.id ?? '') })), { ok: true }) },
|
|
1319
|
+
// Chat channels: a pairing code, forgetting a paired person, options, reconnecting.
|
|
1320
|
+
'channels/code': { post: (body) => ({ ok: true, ...channels.newCode(String(body.botId ?? ''), String(body.appId ?? '')) }) },
|
|
1321
|
+
'channels/unpair': {
|
|
1322
|
+
post: (body) => (channels.unpair(String(body.botId ?? ''), String(body.appId ?? ''), String(body.userId ?? '')) ? { ok: true } : { ok: false, reason: 'no such paired person' }),
|
|
1323
|
+
},
|
|
1324
|
+
'channels/options': {
|
|
1325
|
+
post: (body) => ({ ok: true, ...channels.setOptions(String(body.botId ?? ''), String(body.appId ?? ''), { ...(typeof body.scheduleReplies === 'boolean' ? { scheduleReplies: body.scheduleReplies } : {}) }) }),
|
|
1326
|
+
},
|
|
1327
|
+
'channels/reconnect': { post: (body) => ({ ok: channels.reconnect(String(body.botId ?? ''), String(body.appId ?? '')) }) },
|
|
1192
1328
|
};
|
|
1193
1329
|
|
|
1194
1330
|
const mountRoutes = (scope) => {
|
|
@@ -1210,11 +1346,12 @@ export function apply(ctx, config) {
|
|
|
1210
1346
|
);
|
|
1211
1347
|
}
|
|
1212
1348
|
scope.effect(() => web.register({ kind: 'prefix', path: `${R}/avatar`, handler: (req, res) => serveAvatar(dir, req, res) }));
|
|
1349
|
+
scope.effect(() => web.register({ kind: 'prefix', path: `${R}/logo`, handler: (req, res) => serveLogo(req, res) }));
|
|
1213
1350
|
};
|
|
1214
1351
|
if (typeof ctx.inject === 'function') ctx.inject(['webServer'], mountRoutes);
|
|
1215
1352
|
else if (ctx.webServer) mountRoutes({ webServer: ctx.webServer, effect: (fn) => ctx.effect(fn) });
|
|
1216
1353
|
|
|
1217
|
-
return { store, state, deliver, install, reconcile, installed, routes };
|
|
1354
|
+
return { store, state, deliver, install, reconcile, installed, routes, channels };
|
|
1218
1355
|
}
|
|
1219
1356
|
|
|
1220
1357
|
function serveAvatar(dir, req, res) {
|
|
@@ -1240,6 +1377,30 @@ function serveAvatar(dir, req, res) {
|
|
|
1240
1377
|
createReadStream(file).pipe(res);
|
|
1241
1378
|
}
|
|
1242
1379
|
|
|
1380
|
+
const LOGO_DIR = fileURLToPath(new URL('./logos/', import.meta.url));
|
|
1381
|
+
|
|
1382
|
+
/** `${R}/logo/<name>.png`: an app logo shipped with the plugin. */
|
|
1383
|
+
export function serveLogo(req, res) {
|
|
1384
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
1385
|
+
const m = /^([a-z0-9-]+)\.png$/.exec(decodeURIComponent(url.pathname.slice(`${R}/logo/`.length)));
|
|
1386
|
+
const file = m && isLogoName(m[1]) ? join(LOGO_DIR, `${m[1]}.png`) : '';
|
|
1387
|
+
let size = 0;
|
|
1388
|
+
try {
|
|
1389
|
+
if (!file) throw new Error('bad name');
|
|
1390
|
+
size = statSync(file).size;
|
|
1391
|
+
} catch {
|
|
1392
|
+
res.statusCode = 404;
|
|
1393
|
+
res.end();
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
res.statusCode = 200;
|
|
1397
|
+
res.setHeader('content-type', 'image/png');
|
|
1398
|
+
res.setHeader('content-length', String(size));
|
|
1399
|
+
res.setHeader('cache-control', 'public, max-age=86400');
|
|
1400
|
+
if (req.method === 'HEAD') return void res.end();
|
|
1401
|
+
createReadStream(file).pipe(res);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1243
1404
|
function readSmall(path) {
|
|
1244
1405
|
try {
|
|
1245
1406
|
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, Feishu / Lark, Slack) 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 = [
|
|
@@ -292,7 +294,7 @@ export function catalog(ocuPath = '') {
|
|
|
292
294
|
},
|
|
293
295
|
{
|
|
294
296
|
id: 'slack',
|
|
295
|
-
name: L('Slack', 'Slack'),
|
|
297
|
+
name: L('Slack workspace', 'Slack 工作区'),
|
|
296
298
|
description: L('Read channels and threads, post messages and reactions in a Slack workspace.', '读取 Slack 频道与讨论串,发消息、加表情。'),
|
|
297
299
|
category: 'work',
|
|
298
300
|
icon: 'SL',
|
|
@@ -306,6 +308,146 @@ 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
|
+
},
|
|
370
|
+
{
|
|
371
|
+
id: 'feishu-chat',
|
|
372
|
+
kind: 'channel',
|
|
373
|
+
channel: 'feishu',
|
|
374
|
+
name: L('Feishu / Lark', '飞书'),
|
|
375
|
+
description: L(
|
|
376
|
+
'Message your bot team from Feishu or Lark: chat with the bot one to one, or @ it in a group. Only people you pair can talk to it.',
|
|
377
|
+
'在飞书里给 Bot 团队发消息:和机器人单聊,或在群里 @ 它。只有你配对过的人能和它说话。',
|
|
378
|
+
),
|
|
379
|
+
category: 'work',
|
|
380
|
+
icon: '飞',
|
|
381
|
+
color: '#3370ff',
|
|
382
|
+
serverName: 'feishu-chat',
|
|
383
|
+
homepage: 'https://open.feishu.cn/document/server-docs/event-subscription-guide/event-subscription-configure-/request-url-configuration-case',
|
|
384
|
+
keyUrl: 'https://open.feishu.cn/app',
|
|
385
|
+
featured: true,
|
|
386
|
+
fields: [
|
|
387
|
+
{
|
|
388
|
+
key: 'appId',
|
|
389
|
+
kind: 'text',
|
|
390
|
+
required: true,
|
|
391
|
+
label: L('App ID', 'App ID'),
|
|
392
|
+
placeholder: 'cli_…',
|
|
393
|
+
help: L(
|
|
394
|
+
'Developer console (open.feishu.cn/app; for Lark open.larksuite.com/app) → Create Custom App. Add Features → Bot. Permissions & Scopes: add im:message.p2p_msg:readonly, im:message.group_at_msg:readonly and im:message:send_as_bot (optional: contact:contact.base:readonly and contact:user.base:readonly for names, im:message.reactions:write_only for a typing sign, im:chat:readonly for group names). Copy the App ID and App Secret from Credentials & Basic Info and save. Then, with this channel running (the console only accepts it while it is online), Events & Callbacks → subscription mode "Receive events through persistent connection" → save, add the event im.message.receive_v1, and publish a version. Use an app made for this team only.',
|
|
395
|
+
'开发者后台(open.feishu.cn/app;Lark 用 open.larksuite.com/app)→ 创建企业自建应用 → 添加应用能力「机器人」。在「权限管理」开通 im:message.p2p_msg:readonly、im:message.group_at_msg:readonly、im:message:send_as_bot(可选:contact:contact.base:readonly 和 contact:user.base:readonly 显示姓名,im:message.reactions:write_only 显示"正在处理",im:chat:readonly 显示群名)。到「凭证与基础信息」复制 App ID 和 App Secret 填到这里并保存。保存后保持这个频道运行(长连接在线时后台才允许保存),再到「事件与回调」把订阅方式设为「使用长连接接收事件」并保存,添加事件 im.message.receive_v1,最后在「版本管理与发布」发布版本。请用专门给这个团队新建的应用。',
|
|
396
|
+
),
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
key: 'appSecret',
|
|
400
|
+
kind: 'secret',
|
|
401
|
+
required: true,
|
|
402
|
+
label: L('App secret', 'App Secret'),
|
|
403
|
+
help: L(
|
|
404
|
+
'In Credentials & Basic Info, next to the App ID. If another program already uses this app, Feishu hands each message to only one of them.',
|
|
405
|
+
'在「凭证与基础信息」里,App ID 旁边。如果别的程序也在用这个应用,飞书每条消息只会交给其中一个。',
|
|
406
|
+
),
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
id: 'slack-chat',
|
|
412
|
+
kind: 'channel',
|
|
413
|
+
channel: 'slack',
|
|
414
|
+
name: L('Slack', 'Slack'),
|
|
415
|
+
description: L(
|
|
416
|
+
'Message your bot team from Slack: DM the app, or @mention it in a channel. Only people you pair can talk to it.',
|
|
417
|
+
'在 Slack 里给 Bot 团队发消息:私信这个应用,或在频道里 @ 它。只有你配对过的人能和它说话。',
|
|
418
|
+
),
|
|
419
|
+
category: 'work',
|
|
420
|
+
icon: 'SL',
|
|
421
|
+
color: '#4a154b',
|
|
422
|
+
serverName: 'slack-chat',
|
|
423
|
+
homepage: 'https://docs.slack.dev/apis/events-api/using-socket-mode',
|
|
424
|
+
keyUrl: 'https://api.slack.com/apps',
|
|
425
|
+
featured: true,
|
|
426
|
+
fields: [
|
|
427
|
+
{
|
|
428
|
+
key: 'token',
|
|
429
|
+
kind: 'secret',
|
|
430
|
+
required: true,
|
|
431
|
+
label: L('Bot token', 'Bot Token'),
|
|
432
|
+
placeholder: 'xoxb-…',
|
|
433
|
+
help: L(
|
|
434
|
+
'At api.slack.com/apps choose Create New App → From a manifest and paste the manifest from the Bots README (it turns on Socket Mode, DMs and the permissions). Then Install App → Install to Workspace, and copy the Bot User OAuth Token. Use an app made for this team only.',
|
|
435
|
+
'在 api.slack.com/apps 选 Create New App → From a manifest,粘贴 Bots README 里的清单(它会打开 Socket Mode、私信和所需权限)。再点 Install App → Install to Workspace,复制 Bot User OAuth Token。请用专门给这个团队新建的应用。',
|
|
436
|
+
),
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
key: 'appToken',
|
|
440
|
+
kind: 'secret',
|
|
441
|
+
required: true,
|
|
442
|
+
label: L('App-level token', 'App 级 Token'),
|
|
443
|
+
placeholder: 'xapp-…',
|
|
444
|
+
help: L(
|
|
445
|
+
'Same app → Basic Information → App-Level Tokens → Generate Token and Scopes: add the connections:write scope, generate, and copy the token. With it the Harness connects out to Slack, so no public URL is needed.',
|
|
446
|
+
'同一个应用 → Basic Information → App-Level Tokens → Generate Token and Scopes:添加 connections:write 权限,生成后复制 Token。有了它 Harness 主动连到 Slack,不需要公网地址。',
|
|
447
|
+
),
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
},
|
|
309
451
|
{
|
|
310
452
|
id: 'stripe',
|
|
311
453
|
name: L('Stripe', 'Stripe 收款'),
|
|
@@ -339,7 +481,7 @@ export function catalog(ocuPath = '') {
|
|
|
339
481
|
},
|
|
340
482
|
{
|
|
341
483
|
id: 'feishu',
|
|
342
|
-
name: L('Feishu / Lark', '
|
|
484
|
+
name: L('Feishu / Lark Open Platform', '飞书开放平台'),
|
|
343
485
|
description: L('Feishu docs, Bitable, messages, calendars and contacts through the official Open Platform server.', '官方开放平台服务:飞书文档、多维表格、消息、日历与通讯录。'),
|
|
344
486
|
category: 'work',
|
|
345
487
|
icon: '飞',
|
|
@@ -407,13 +549,16 @@ export function catalog(ocuPath = '') {
|
|
|
407
549
|
/**
|
|
408
550
|
* The mcp-client row of one app: the template's command, with the app's field
|
|
409
551
|
* values placed as environment variables, headers, query params or arguments.
|
|
410
|
-
* Custom apps (and old rows) use their own `config` as written.
|
|
552
|
+
* Custom apps (and old rows) use their own `config` as written. A chat
|
|
553
|
+
* channel app is not an MCP server: null.
|
|
411
554
|
* @param {object} app - `{template, serverName, values?, config?}`
|
|
412
555
|
* @param {AppEntry[]} entries
|
|
413
556
|
* @param {{bot?: string}} [ctx]
|
|
414
557
|
*/
|
|
415
558
|
export function mcpConfigFor(app, entries, ctx = {}) {
|
|
416
559
|
const t = entries.find((e) => e.id === app.template);
|
|
560
|
+
// A chat channel (Telegram, Discord, Feishu, Slack) is no MCP server: lib/channels.mjs runs it.
|
|
561
|
+
if (t?.kind === 'channel') return null;
|
|
417
562
|
const values = app.values && typeof app.values === 'object' ? app.values : {};
|
|
418
563
|
const reconnect = { maxAttempts: 3 };
|
|
419
564
|
const fill = (v) => String(v ?? '').replaceAll('{bot}', ctx.bot ?? 'bot');
|