@dsh-overdrive/gateway 0.1.0 → 0.1.2
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/adapter.d.ts +33 -0
- package/dist/adapter.js +2 -0
- package/dist/adapter.js.map +1 -0
- package/dist/adapters/cli.d.ts +16 -0
- package/dist/adapters/cli.js +34 -0
- package/dist/adapters/cli.js.map +1 -0
- package/dist/adapters/dingtalk.d.ts +40 -0
- package/dist/adapters/dingtalk.js +93 -0
- package/dist/adapters/dingtalk.js.map +1 -0
- package/dist/adapters/discord.d.ts +38 -0
- package/dist/adapters/discord.js +88 -0
- package/dist/adapters/discord.js.map +1 -0
- package/dist/adapters/feishu.d.ts +43 -0
- package/dist/adapters/feishu.js +107 -0
- package/dist/adapters/feishu.js.map +1 -0
- package/dist/adapters/slack.d.ts +35 -0
- package/dist/adapters/slack.js +83 -0
- package/dist/adapters/slack.js.map +1 -0
- package/dist/adapters/telegram.d.ts +57 -0
- package/dist/adapters/telegram.js +94 -0
- package/dist/adapters/telegram.js.map +1 -0
- package/dist/adapters/wecom.d.ts +42 -0
- package/dist/adapters/wecom.js +177 -0
- package/dist/adapters/wecom.js.map +1 -0
- package/dist/adapters/whatsapp.d.ts +81 -0
- package/dist/adapters/whatsapp.js +193 -0
- package/dist/adapters/whatsapp.js.map +1 -0
- package/dist/commands.d.ts +18 -0
- package/dist/commands.js +29 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +73 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +190 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +10 -0
- package/dist/session.js +15 -0
- package/dist/session.js.map +1 -0
- package/dist/setup.d.ts +1 -0
- package/dist/setup.js +265 -0
- package/dist/setup.js.map +1 -0
- package/dist/status.d.ts +22 -0
- package/dist/status.js +47 -0
- package/dist/status.js.map +1 -0
- package/dist/trajectory.d.ts +10 -0
- package/dist/trajectory.js +43 -0
- package/dist/trajectory.js.map +1 -0
- package/package.json +7 -3
- package/src/setup.ts +252 -0
package/src/setup.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-overdrive setup wizard — 交互式设置向导(hermes setup 风格)
|
|
3
|
+
*
|
|
4
|
+
* 用法:
|
|
5
|
+
* node packages/gateway/dist/setup.js (源码构建后)
|
|
6
|
+
* npx dsh-overdrive-setup (npm 全局/临时)
|
|
7
|
+
*
|
|
8
|
+
* 流程:DeepSeek key → 平台多选 → 逐个收集凭据并联网验证 → 写 .env → 打印下一步。
|
|
9
|
+
* 全程英文为主、中文为辅;验证失败会提示"是否继续"。
|
|
10
|
+
*/
|
|
11
|
+
import { createInterface } from 'node:readline/promises';
|
|
12
|
+
import { stdin, stdout } from 'node:process';
|
|
13
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
|
|
16
|
+
const C = {
|
|
17
|
+
cyan: (t: string) => `\x1b[36m${t}\x1b[0m`,
|
|
18
|
+
green: (t: string) => `\x1b[32m${t}\x1b[0m`,
|
|
19
|
+
red: (t: string) => `\x1b[31m${t}\x1b[0m`,
|
|
20
|
+
dim: (t: string) => `\x1b[90m${t}\x1b[0m`,
|
|
21
|
+
bold: (t: string) => `\x1b[1m${t}\x1b[0m`,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 输入层:TTY 用 readline(交互终端);非 TTY 预读全部 stdin(管道/自动化/测试),
|
|
26
|
+
* 逐行分发。输入耗尽时返回 '',由 stopIfClosed 优雅收尾。
|
|
27
|
+
*/
|
|
28
|
+
const isTTY = !!stdin.isTTY;
|
|
29
|
+
let ttyRl: ReturnType<typeof createInterface> | null = null;
|
|
30
|
+
const pipeLines: string[] = [];
|
|
31
|
+
if (!isTTY) {
|
|
32
|
+
const chunks: Buffer[] = [];
|
|
33
|
+
for await (const chunk of stdin) chunks.push(chunk);
|
|
34
|
+
pipeLines.push(...Buffer.concat(chunks).toString('utf8').split(/\r?\n/));
|
|
35
|
+
}
|
|
36
|
+
let inputClosed = !isTTY && pipeLines.length === 0;
|
|
37
|
+
async function promptOnce(question: string): Promise<string> {
|
|
38
|
+
if (isTTY) {
|
|
39
|
+
ttyRl ??= createInterface({ input: stdin, output: stdout, terminal: true });
|
|
40
|
+
try {
|
|
41
|
+
return await ttyRl.question(question);
|
|
42
|
+
} catch {
|
|
43
|
+
inputClosed = true;
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const line = pipeLines.shift() ?? '';
|
|
48
|
+
if (line === '' && pipeLines.length === 0) inputClosed = true;
|
|
49
|
+
stdout.write(`${question}${line}\n`); // 非 TTY 无回显,手动回显
|
|
50
|
+
return line;
|
|
51
|
+
}
|
|
52
|
+
function closeInput(): void {
|
|
53
|
+
try { ttyRl?.close(); } catch { /* noop */ }
|
|
54
|
+
}
|
|
55
|
+
async function ask(q: string, hint = ''): Promise<string> {
|
|
56
|
+
const answer = await promptOnce(`${C.cyan('?')} ${q} ${C.dim(hint)}\n> `);
|
|
57
|
+
return answer.trim();
|
|
58
|
+
}
|
|
59
|
+
async function confirm(q: string): Promise<boolean> {
|
|
60
|
+
const a = (await promptOnce(`${C.cyan('?')} ${q} ${C.dim('[y/N]')}\n> `)).trim().toLowerCase();
|
|
61
|
+
return a === 'y' || a === 'yes';
|
|
62
|
+
}
|
|
63
|
+
function stopIfClosed(): void {
|
|
64
|
+
if (inputClosed) {
|
|
65
|
+
console.log(C.dim('\n input closed — aborting / 输入已关闭,向导中止'));
|
|
66
|
+
console.log(C.dim(' (run in an interactive terminal / 请在交互式终端中运行)'));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 联网验证辅助:返回 {ok, reason};网络异常按"无法验证"处理(由调用方决定是否继续)。 */
|
|
72
|
+
async function probe(fn: () => Promise<boolean>, name: string): Promise<{ ok: boolean; reason: string }> {
|
|
73
|
+
try {
|
|
74
|
+
return (await fn()) ? { ok: true, reason: `${name} verified / 验证通过` } : { ok: false, reason: `${name} rejected / 验证失败` };
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return { ok: false, reason: `${name} unreachable (network?) / 网络不可达: ${error instanceof Error ? error.message : String(error)}` };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const PROBES: Record<string, (v: Record<string, string>) => Promise<boolean>> = {
|
|
81
|
+
deepseek: async (v) => {
|
|
82
|
+
const r = await fetch('https://api.deepseek.com/user/balance', { headers: { authorization: `Bearer ${v.DEEPSEEK_API_KEY}` } });
|
|
83
|
+
return r.ok;
|
|
84
|
+
},
|
|
85
|
+
telegram: async (v) => {
|
|
86
|
+
const r = await fetch(`https://api.telegram.org/bot${v.TELEGRAM_BOT_TOKEN}/getMe`);
|
|
87
|
+
const j = (await r.json()) as { ok?: boolean };
|
|
88
|
+
return j.ok === true;
|
|
89
|
+
},
|
|
90
|
+
discord: async (v) => {
|
|
91
|
+
const r = await fetch('https://discord.com/api/v10/users/@me', { headers: { authorization: `Bot ${v.DISCORD_BOT_TOKEN}` } });
|
|
92
|
+
return r.ok;
|
|
93
|
+
},
|
|
94
|
+
slack: async (v) => {
|
|
95
|
+
const r = await fetch('https://slack.com/api/auth.test', { headers: { authorization: `Bearer ${v.SLACK_BOT_TOKEN}` } });
|
|
96
|
+
const j = (await r.json()) as { ok?: boolean };
|
|
97
|
+
return j.ok === true;
|
|
98
|
+
},
|
|
99
|
+
feishu: async (v) => {
|
|
100
|
+
const r = await fetch('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal', {
|
|
101
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
102
|
+
body: JSON.stringify({ app_id: v.FEISHU_APP_ID, app_secret: v.FEISHU_APP_SECRET }),
|
|
103
|
+
});
|
|
104
|
+
const j = (await r.json()) as { code?: number };
|
|
105
|
+
return j.code === 0;
|
|
106
|
+
},
|
|
107
|
+
dingtalk: async (v) => {
|
|
108
|
+
const r = await fetch('https://api.dingtalk.com/v1.0/oauth2/accessToken', {
|
|
109
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
110
|
+
body: JSON.stringify({ appKey: v.DINGTALK_CLIENT_ID, appSecret: v.DINGTALK_CLIENT_SECRET }),
|
|
111
|
+
});
|
|
112
|
+
return r.ok;
|
|
113
|
+
},
|
|
114
|
+
wecom: async (v) => {
|
|
115
|
+
const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${encodeURIComponent(v.WECOM_CORP_ID)}&corpsecret=${encodeURIComponent(v.WECOM_SECRET)}`;
|
|
116
|
+
const j = (await (await fetch(url)).json()) as { errcode?: number };
|
|
117
|
+
return j.errcode === 0;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const PLATFORMS: Record<string, { label: string; fields: Array<[key: string, prompt: string, hint: string, pattern?: RegExp]> }> = {
|
|
122
|
+
telegram: {
|
|
123
|
+
label: 'Telegram',
|
|
124
|
+
fields: [['TELEGRAM_BOT_TOKEN', 'Telegram bot token', 'https://t.me/BotFather → /newbot', /^\d+:[A-Za-z0-9_-]{20,}$/]],
|
|
125
|
+
},
|
|
126
|
+
whatsapp: {
|
|
127
|
+
label: 'WhatsApp (no credentials — QR pairing on first start / 无需凭据,首次启动扫码)',
|
|
128
|
+
fields: [],
|
|
129
|
+
},
|
|
130
|
+
discord: {
|
|
131
|
+
label: 'Discord',
|
|
132
|
+
fields: [['DISCORD_BOT_TOKEN', 'Discord bot token', 'Developer Portal → Bot → Token', /^[A-Za-z0-9._-]{20,}$/]],
|
|
133
|
+
},
|
|
134
|
+
slack: {
|
|
135
|
+
label: 'Slack (Socket Mode)',
|
|
136
|
+
fields: [
|
|
137
|
+
['SLACK_BOT_TOKEN', 'Slack bot token (xoxb-…)', 'App → OAuth & Permissions', /^xoxb-/],
|
|
138
|
+
['SLACK_APP_TOKEN', 'Slack app-level token (xapp-…)', 'App → Basic Information → App-Level Tokens', /^xapp-/],
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
feishu: {
|
|
142
|
+
label: '飞书 Feishu',
|
|
143
|
+
fields: [
|
|
144
|
+
['FEISHU_APP_ID', 'Feishu App ID', '开放平台 → 应用凭证', /^cli_/],
|
|
145
|
+
['FEISHU_APP_SECRET', 'Feishu App Secret', '开放平台 → 应用凭证', /.+/],
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
dingtalk: {
|
|
149
|
+
label: '钉钉 DingTalk',
|
|
150
|
+
fields: [
|
|
151
|
+
['DINGTALK_CLIENT_ID', 'DingTalk Client ID (AppKey)', '应用开发 → 凭证与基础信息', /.+/],
|
|
152
|
+
['DINGTALK_CLIENT_SECRET', 'DingTalk Client Secret', '应用开发 → 凭证与基础信息', /.+/],
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
wecom: {
|
|
156
|
+
label: '企业微信 WeCom',
|
|
157
|
+
fields: [
|
|
158
|
+
['WECOM_CORP_ID', 'WeCom Corp ID', '我的企业 → 企业信息', /.+/],
|
|
159
|
+
['WECOM_SECRET', 'WeCom Secret', '应用管理 → 应用 → Secret', /.+/],
|
|
160
|
+
['WECOM_AGENT_ID', 'WeCom Agent ID', '应用管理 → 应用 → AgentId', /^\d+$/],
|
|
161
|
+
['WECOM_TOKEN', 'WeCom callback Token', '接收消息 → Token(随意填一串)', /.+/],
|
|
162
|
+
['WECOM_ENCODING_AES_KEY', 'WeCom EncodingAESKey', '接收消息 → EncodingAESKey(43 位)', /^[A-Za-z0-9]{43}$/],
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/** 读取已有 .env(若存在)合并;返回新内容。 */
|
|
168
|
+
function buildEnv(current: string, pairs: Array<[string, string]>): string {
|
|
169
|
+
const map = new Map<string, string>();
|
|
170
|
+
for (const line of current.split(/\r?\n/)) {
|
|
171
|
+
const m = line.match(/^([A-Z0-9_]+)=(.*)$/);
|
|
172
|
+
if (m) map.set(m[1], m[2]);
|
|
173
|
+
}
|
|
174
|
+
for (const [k, v] of pairs) map.set(k, v);
|
|
175
|
+
return [...map.entries()].map(([k, v]) => `${k}=${v}`).join('\n') + '\n';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function main(): Promise<void> {
|
|
179
|
+
console.log('');
|
|
180
|
+
console.log(C.bold(C.cyan('==================================================')));
|
|
181
|
+
console.log(C.bold(C.cyan(' dsh-overdrive setup — the OpenClaw of DeepSeek Harness')));
|
|
182
|
+
console.log(C.bold(C.cyan(' 交互式设置向导(hermes setup 风格)')));
|
|
183
|
+
console.log(C.bold(C.cyan('==================================================')));
|
|
184
|
+
console.log('');
|
|
185
|
+
|
|
186
|
+
const pairs: Array<[string, string]> = [];
|
|
187
|
+
let platforms: string[] = [];
|
|
188
|
+
|
|
189
|
+
// 1. DeepSeek API key
|
|
190
|
+
console.log(C.dim(' 1/3 DeepSeek API key — get one: https://platform.deepseek.com/api_keys'));
|
|
191
|
+
for (;;) {
|
|
192
|
+
const key = await ask('Paste your DeepSeek API key (sk-…)', '必填');
|
|
193
|
+
stopIfClosed();
|
|
194
|
+
if (!/^sk-/.test(key)) { console.log(C.red(' [x] should start with sk- / 应以 sk- 开头')); continue; }
|
|
195
|
+
const r = await probe(() => PROBES.deepseek({ DEEPSEEK_API_KEY: key }), 'DeepSeek key');
|
|
196
|
+
console.log(r.ok ? C.green(` [ok] ${r.reason}`) : C.red(` [!] ${r.reason}`));
|
|
197
|
+
if (r.ok || (await confirm('Continue anyway? / 仍然继续?'))) { pairs.push(['DEEPSEEK_API_KEY', key]); break; }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 2. platforms
|
|
201
|
+
console.log(C.dim(' 2/3 Platforms — telegram, whatsapp, discord, slack, feishu, dingtalk, wecom'));
|
|
202
|
+
const chosen = await ask('Which platforms? (comma separated, default: telegram)', '逗号分隔,默认 telegram');
|
|
203
|
+
stopIfClosed();
|
|
204
|
+
platforms = (chosen || 'telegram').split(',').map((s) => s.trim().toLowerCase()).filter((s) => PLATFORMS[s]);
|
|
205
|
+
if (platforms.length === 0) { console.log(C.red(' [x] no valid platform selected / 未选择有效平台')); process.exit(1); }
|
|
206
|
+
|
|
207
|
+
// 3. per-platform credentials
|
|
208
|
+
console.log(C.dim(' 3/3 Platform credentials (each is verified live) / 平台凭据(逐个实时验证)'));
|
|
209
|
+
for (const p of platforms) {
|
|
210
|
+
console.log(`\n ${C.bold('-- ' + PLATFORMS[p].label)} --`);
|
|
211
|
+
const vals: Record<string, string> = { ...Object.fromEntries(pairs) };
|
|
212
|
+
for (const [key, prompt, hint, pattern] of PLATFORMS[p].fields) {
|
|
213
|
+
for (;;) {
|
|
214
|
+
const v = await ask(prompt, hint);
|
|
215
|
+
stopIfClosed();
|
|
216
|
+
if (pattern && !pattern.test(v)) { console.log(C.red(` [x] format looks wrong / 格式不对(${hint})`)); continue; }
|
|
217
|
+
vals[key] = v;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const probeFn = PROBES[p];
|
|
222
|
+
if (probeFn && p !== 'whatsapp') {
|
|
223
|
+
const r = await probe(() => probeFn(vals), PLATFORMS[p].label);
|
|
224
|
+
console.log(r.ok ? C.green(` [ok] ${r.reason}`) : C.red(` [!] ${r.reason}`));
|
|
225
|
+
if (!r.ok && !(await confirm('Continue anyway? / 仍然继续?'))) { console.log(C.red(' skipped / 已跳过')); continue; }
|
|
226
|
+
}
|
|
227
|
+
for (const [k, v] of PLATFORMS[p].fields) pairs.push([k, vals[k]]);
|
|
228
|
+
}
|
|
229
|
+
if (platforms.includes('whatsapp')) console.log(C.dim(' WhatsApp: no credentials needed — QR shows on first start / 无需凭据,启动时扫码'));
|
|
230
|
+
|
|
231
|
+
// 4. write .env
|
|
232
|
+
const envPath = join(process.cwd(), '.env');
|
|
233
|
+
const current = existsSync(envPath) ? readFileSync(envPath, 'utf8') : '';
|
|
234
|
+
const merged = buildEnv(current, [...pairs, ['GATEWAY_ADAPTERS', platforms.join(',')], ['DSH_OVERDRIVE_TOKEN', 'dsh-overdrive-token']]);
|
|
235
|
+
writeFileSync(envPath, merged, 'utf8');
|
|
236
|
+
console.log(`\n ${C.green('[ok]')} .env written → ${C.bold(envPath)}(已合并现有配置)`);
|
|
237
|
+
|
|
238
|
+
// 5. next steps
|
|
239
|
+
console.log('');
|
|
240
|
+
console.log(C.bold(C.cyan('==================================================')));
|
|
241
|
+
console.log(C.bold(C.cyan(' Next steps / 下一步')));
|
|
242
|
+
console.log(` ${C.cyan('1)')} Start: docker compose -f deploy/docker-compose.yml up -d --build`);
|
|
243
|
+
console.log(` or: GATEWAY_ADAPTERS=${platforms.join(',')} npx @dsh-overdrive/gateway`);
|
|
244
|
+
console.log(` ${C.cyan('2)')} Console / 控制台: http://localhost:3190/ (含四步引导向导)`);
|
|
245
|
+
console.log(` ${C.cyan('3)')} DSH Web UI (model): http://localhost:3080/`);
|
|
246
|
+
console.log(` ${C.cyan('4)')} In your chat app: send /help`);
|
|
247
|
+
console.log(C.bold(C.cyan('==================================================')));
|
|
248
|
+
console.log('');
|
|
249
|
+
closeInput();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
void main();
|