ai_co_discuss 0.4.40 → 0.4.41
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/package.json +1 -1
- package/runner/discussion_setup.mjs +5 -2
- package/runner/hosting_setup.mjs +46 -1
- package/web/admin.css +1 -1
- package/web/admin.js +1 -1
- package/web/modern.js +1 -1
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ import { assert_shared_home, service_home } from './discussion_service.mjs';
|
|
|
13
13
|
import { SKILLS, install_skills, install_workflows, remove_legacy_skills, shipped_workflows } from './discussion_skills.mjs';
|
|
14
14
|
import { ask, checkbox_prompt, intro, outro, pad, short_path, spinner, step, styled, text_width, tone, tree_prompt } from './discussion_tui.mjs';
|
|
15
15
|
import { launcher_installed } from './launcher.mjs';
|
|
16
|
-
import { configure_hosting, finish_hosting, hosting_requested } from './hosting_setup.mjs';
|
|
16
|
+
import { ask_hosting, configure_hosting, finish_hosting, hosting_requested } from './hosting_setup.mjs';
|
|
17
17
|
export { checkbox_prompt } from './discussion_tui.mjs';
|
|
18
18
|
|
|
19
19
|
const ROOT = fileURLToPath(new URL('../', import.meta.url));
|
|
@@ -52,7 +52,7 @@ install 将当前 npm 包安装为持久命令,再运行 setup;setup 配置
|
|
|
52
52
|
--hosting / --no-hosting 在管理面板中显示 / 隐藏托管管理(用户、Windows 用户、命令行登录、API 密钥),选择会记住;
|
|
53
53
|
Windows 上加 --hosting 时还会设好登录入口(随管理面板启动)、开启登录自启,并检查入口能否打开
|
|
54
54
|
--entry-port PORT 登录入口端口,默认 8780
|
|
55
|
-
--public-host 域名 外网地址(可选),如
|
|
55
|
+
--public-host 域名 外网地址(可选),如 codiscuss.example.com;终端里运行 --hosting 而不给时会询问。域名须已托管在 Cloudflare;会安装 cloudflared、
|
|
56
56
|
在浏览器里授权 Cloudflare、建固定隧道并添加域名记录,隧道由管理面板运行
|
|
57
57
|
--tunnel-name NAME Cloudflare 隧道名,默认 codiscuss
|
|
58
58
|
--workflows 安装全部随包工作流,已有同名的覆盖为最新版(原来的先备份到服务目录 backups/);
|
|
@@ -453,6 +453,9 @@ async function setup(options) {
|
|
|
453
453
|
const hosting_setup = hosting_requested(options, choices.hosting);
|
|
454
454
|
let hosting = null;
|
|
455
455
|
if (hosting_setup) {
|
|
456
|
+
// The outside address is asked here when not given (a terminal run): the domain, the tunnel name, the Cloudflare checks.
|
|
457
|
+
const show = (title, lines) => styled ? step(title, lines, tone.yellow('▲')) : process.stderr.write(`${[title, ...lines].join('\n')}\n`);
|
|
458
|
+
await ask_hosting(home, options, { ask, show });
|
|
456
459
|
// No spinner: installing cloudflared and signing in to Cloudflare print and wait for the owner.
|
|
457
460
|
hosting = configure_hosting(home, options, { say: line => process.stderr.write(`${line}\n`) });
|
|
458
461
|
step(hosting.issues.length ? '登录入口已设置,有待处理项' : '登录入口已设置', [...hosting.lines, ...hosting.issues]);
|
package/runner/hosting_setup.mjs
CHANGED
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { spawnSync } from 'node:child_process';
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
9
10
|
import { dirname, join } from 'node:path';
|
|
10
11
|
import { fileURLToPath } from 'node:url';
|
|
11
12
|
|
|
12
13
|
import { entry_settings, save_entry_settings } from '../gateway/gateway.mjs';
|
|
13
|
-
import { prepare_tunnel, remove_legacy_tunnel_start, tunnel_host, tunnel_log_tail } from './hosting_tunnel.mjs';
|
|
14
|
+
import { prepare_tunnel, remove_legacy_tunnel_start, tunnel_host, tunnel_log_tail, tunnel_name } from './hosting_tunnel.mjs';
|
|
14
15
|
import { launcher_path, set_autostart } from './launcher.mjs';
|
|
15
16
|
|
|
16
17
|
const PANEL_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), 'admin_panel.mjs');
|
|
18
|
+
const CLOUDFLARE_CERT = join(homedir(), '.cloudflared', 'cert.pem');
|
|
17
19
|
const LOGIN_PATH = '/_entry/login';
|
|
18
20
|
const LOCAL_WAIT_MS = 60_000;
|
|
19
21
|
// A new tunnel's host name can take a minute or two to resolve.
|
|
@@ -26,6 +28,47 @@ export function hosting_requested(options, hosting_on) {
|
|
|
26
28
|
return process.platform === 'win32' && hosting_on && Boolean(options.hosting || options['public-host'] || options['entry-port']);
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
// What the owner checks on the Cloudflare site of the domain first: it may serve another website, and its rules apply to
|
|
32
|
+
// the entry's host name too.
|
|
33
|
+
const CLOUDFLARE_CHECKS = [
|
|
34
|
+
'缓存规则:不能有对所有主机或这个子域名生效的“缓存全部内容”(Cache Everything),否则一个账号的页面可能被缓存后给到另一个账号',
|
|
35
|
+
'安全:关闭 Bot Fight Mode,或为这个子域名加跳过规则,否则网页的接口请求会被拦',
|
|
36
|
+
'速度:关闭 Rocket Loader(会改写页面脚本)',
|
|
37
|
+
'DNS:这个子域名还没有记录(有的话先删掉)',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Ask in the terminal for the outside address when it was not given: the domain (blank keeps the current one, or keeps
|
|
42
|
+
* the entry to this computer), the tunnel name, and a pause to check the Cloudflare site first. Sets
|
|
43
|
+
* options['public-host'] and options['tunnel-name']; a run without a terminal, with --yes or with --public-host is not
|
|
44
|
+
* asked anything.
|
|
45
|
+
*
|
|
46
|
+
* Args:
|
|
47
|
+
* ask: (question, hint) => Promise<string>, the setup's own prompt.
|
|
48
|
+
* show: (title, lines) => void, how setup shows a step.
|
|
49
|
+
*/
|
|
50
|
+
export async function ask_hosting(home, options, { ask, show, interactive = Boolean(process.stdin.isTTY) }) {
|
|
51
|
+
if (!interactive || options.yes || options['public-host']) return;
|
|
52
|
+
const current = entry_settings(home).tunnel;
|
|
53
|
+
for (;;) {
|
|
54
|
+
const answer = (await ask('外网域名:须已托管在 Cloudflare,如 codiscuss.example.com',
|
|
55
|
+
current ? `当前 ${current.host},直接回车保持` : '直接回车则只在本机用')).trim();
|
|
56
|
+
if (!answer) return;
|
|
57
|
+
try { options['public-host'] = tunnel_host(answer); break; }
|
|
58
|
+
catch (error) { show(error.message, []); }
|
|
59
|
+
}
|
|
60
|
+
if (current?.host === options['public-host'] && !options['tunnel-name']) options['tunnel-name'] = current.name;
|
|
61
|
+
if (!options['tunnel-name']) {
|
|
62
|
+
for (;;) {
|
|
63
|
+
const name = (await ask('Cloudflare 隧道名', '直接回车用 codiscuss')).trim();
|
|
64
|
+
try { options['tunnel-name'] = tunnel_name(name || undefined); break; }
|
|
65
|
+
catch (error) { show(error.message, []); }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
show(`开始前在 Cloudflare 后台检查 ${options['public-host']} 所在站点`, CLOUDFLARE_CHECKS.map((line, index) => `${index + 1}. ${line}`));
|
|
69
|
+
await ask('检查完后继续:接下来会安装 cloudflared,并打开浏览器授权 Cloudflare', '回车继续,Ctrl+C 退出');
|
|
70
|
+
}
|
|
71
|
+
|
|
29
72
|
/**
|
|
30
73
|
* Save the entry's settings and prepare the outside address, before the service starts. Returns { lines, issues }:
|
|
31
74
|
* what was set, and what is left for the owner.
|
|
@@ -41,6 +84,8 @@ export function configure_hosting(home, options, { interactive = Boolean(process
|
|
|
41
84
|
Object.assign(changes, { public_url: `https://${host}`, tunnel });
|
|
42
85
|
lines.push(`外网地址 https://${host},经 Cloudflare 隧道 ${tunnel.name} 转到登录入口;隧道独立运行,由管理面板按设置维持`);
|
|
43
86
|
if (remove_legacy_tunnel_start()) lines.push('已移除旧的“CoDiscuss Tunnel”开机任务,改由管理面板运行隧道');
|
|
87
|
+
// cert.pem manages the whole Cloudflare site, while the running tunnel needs only its own credentials.
|
|
88
|
+
if (existsSync(CLOUDFLARE_CERT)) lines.push(`Cloudflare 授权文件 ${CLOUDFLARE_CERT} 能在该站点下建隧道、改 DNS,隧道运行用不到它:建议移出这台电脑自己保管(重建隧道或换域名时再放回或重新授权);托管账号务必全部隔离`);
|
|
44
89
|
} catch (error) { issues.push(`外网地址没有设好:${error.message}`); }
|
|
45
90
|
}
|
|
46
91
|
const saved = save_entry_settings(home, changes);
|