ai_co_discuss 0.5.39 → 0.5.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/.agents/skills/discuss-goal/SKILL.md +1 -1
- package/.agents/skills/discuss-host/references/room.md +4 -4
- package/.agents/skills/discuss-participant/SKILL.md +3 -1
- package/.agents/skills/discuss-participant/references/interactive-html.md +35 -8
- package/.agents/skills/discuss-participant/references/visual-examples.md +41 -18
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/backend/analytics.py +24 -2
- package/backend/analytics_issues.py +210 -0
- package/backend/free_room.py +21 -9
- package/backend/questions.py +3 -2
- package/backend/room_import.py +3 -3
- package/backend/schema.sql +2 -0
- package/backend/server.py +73 -3
- package/docs/deployment.md +6 -2
- package/docs/en/deployment.md +6 -2
- package/docs/en/guide/admin.md +12 -8
- package/docs/en/guide/analytics.md +13 -18
- package/docs/en/guide/faq.md +1 -1
- package/docs/en/guide/goal.md +1 -1
- package/docs/en/guide/remote.md +2 -2
- package/docs/en/guide/rooms.md +4 -4
- package/docs/en/guide/scheduling.md +1 -1
- package/docs/en/guide/voice.md +5 -4
- package/docs/en/guide/working.md +1 -1
- package/docs/guide/admin.md +12 -8
- package/docs/guide/analytics.md +13 -18
- package/docs/guide/faq.md +1 -1
- package/docs/guide/goal.md +1 -1
- package/docs/guide/remote.md +2 -2
- package/docs/guide/rooms.md +4 -4
- package/docs/guide/scheduling.md +1 -1
- package/docs/guide/voice.md +5 -4
- package/docs/guide/working.md +1 -1
- package/frontend/locales/en/admin.json +48 -1
- package/frontend/locales/en/analytics.json +62 -42
- package/frontend/locales/en/backend.json +12 -2
- package/frontend/locales/en/backend_worker.json +5 -0
- package/frontend/locales/en/external.json +3 -0
- package/frontend/locales/en/room.json +30 -0
- package/frontend/locales/en/settings.json +17 -2
- package/package.json +1 -1
- package/runner/adapters/api.mjs +1 -1
- package/runner/admin_cli.mjs +19 -8
- package/runner/admin_maintenance.mjs +31 -0
- package/runner/admin_panel.mjs +54 -13
- package/runner/device_auth.mjs +5 -2
- package/runner/discuss.py +1 -1
- package/runner/discussion_launch.mjs +2 -2
- package/runner/external_gateway.mjs +2 -2
- package/runner/free_runner.mjs +11 -8
- package/runner/hosting_tunnel.mjs +3 -0
- package/runner/i18n_en.mjs +17 -10
- package/runner/relay_channel.mjs +2 -2
- package/runner/relay_health.mjs +2 -1
- package/runner/remote_launch.mjs +6 -1
- package/runner/scheduler.mjs +21 -15
- package/runner/session_driver.mjs +3 -1
- package/runner/share_shared.mjs +2 -1
- package/runner/weixin.mjs +32 -9
- package/web/admin.css +1 -1
- package/web/admin.js +8 -8
- package/web/app.js +28 -4
- package/web/backup.js +5 -3
- package/web/i18n.js +4 -4
- package/web/markdown.css +1 -1
- package/web/modern.css +1 -1
- package/web/modern.js +168 -91
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"松开以引用房间「{title}」": "Release to reference the room “{title}”",
|
|
27
27
|
"[房间 {title} #{id}]": "[room {title} #{id}]",
|
|
28
28
|
"[成员 {name}]": "[member {name}]",
|
|
29
|
+
"松开以引用成员「{name}」": "Release to reference the member “{name}”",
|
|
29
30
|
"跨房发送": "Sent to another room",
|
|
30
31
|
"展开或收起发出的消息正文": "Show or hide the sent message",
|
|
31
32
|
"父房间": "parent room",
|
|
@@ -995,6 +996,35 @@
|
|
|
995
996
|
"定位最新发言": "Jump to latest message",
|
|
996
997
|
"草稿空间": "Draft storage",
|
|
997
998
|
"本房间草稿已达 80% 以上,接近上限时将停止派活。": "This room's drafts are at or above 80%; new runs will pause if the limit is exceeded.",
|
|
999
|
+
"管理附件": "Manage attachments",
|
|
1000
|
+
"存储空间": "Storage",
|
|
1001
|
+
"附件": "Attachments",
|
|
1002
|
+
"不计入草稿配额": "not counted toward the draft quota",
|
|
1003
|
+
"消息附件原文件,存于房间记录,不计入草稿配额": "Original files attached to messages, stored with the room records and not counted toward the draft quota",
|
|
1004
|
+
"按类型、时间与大小挑选附件,清理原文件以释放空间": "Pick attachments by type, age and size, and clear their originals to free space",
|
|
1005
|
+
"房间附件": "Room attachments",
|
|
1006
|
+
"{count} 个附件 · 最近 {date}": "{count} attachments · latest {date}",
|
|
1007
|
+
"保存房间消息、事件与附件原件,计入 10 GiB 数据上限;程序不会自动删除。可在下方按房间清理附件原件,或销毁旧房间。": "Stores room messages, events and original attachments, and counts toward the 10 GiB data limit. Nothing here is deleted automatically. Clear attachment originals by room below, or destroy old rooms.",
|
|
1008
|
+
"管理本房间附件": "Manage this room's attachments",
|
|
1009
|
+
"已释放 {size}": "Freed {size}",
|
|
1010
|
+
"清理后消息仍在,附件卡片保留文件名、大小和图片缩略图并标“已清理”,原文件无法再打开或下载,成员也读不到;此操作无法撤销。": "Messages stay. Each cleared attachment keeps its name, size and image thumbnail and is marked Cleared, but the original can no longer be opened or downloaded, and members cannot read it. This cannot be undone.",
|
|
1011
|
+
"按类型筛选": "Filter by type",
|
|
1012
|
+
"按时间筛选": "Filter by age",
|
|
1013
|
+
"音视频": "Audio & video",
|
|
1014
|
+
"压缩包": "Archives",
|
|
1015
|
+
"全部时间": "Any time",
|
|
1016
|
+
"7 天前": "Older than 7 days",
|
|
1017
|
+
"30 天前": "Older than 30 days",
|
|
1018
|
+
"正在读取附件…": "Loading attachments…",
|
|
1019
|
+
"没有符合条件的附件": "No attachments match",
|
|
1020
|
+
"本房间没有可清理的附件": "This room has no attachments to clear",
|
|
1021
|
+
"全选当前 {count} 项": "Select all {count} shown",
|
|
1022
|
+
"已清理 {count} 项": "{count} cleared",
|
|
1023
|
+
"已选 {count} 项,将释放 {size}": "{count} selected, frees {size}",
|
|
1024
|
+
"确认清理(无法撤销)": "Confirm clear (cannot be undone)",
|
|
1025
|
+
"清理所选": "Clear selected",
|
|
1026
|
+
"原文件已由房主清理以释放空间": "The owner cleared the original file to free space",
|
|
1027
|
+
"已清理 · {size}": "Cleared · {size}",
|
|
998
1028
|
"清理临时文件({size})": "Clean temp files ({size})",
|
|
999
1029
|
"本房间成员草稿与临时文件占用;按周期采样检查,并非写入层硬拦截,达到 80% 时提示,超过上限将停止派活": "Draft and temporary file usage for this room; checked by periodic sampling (not a filesystem write-layer hard quota), warns at 80% and pauses new runs above the limit",
|
|
1000
1030
|
"本房间草稿已超限,派活已暂停;请在房间外的 AI 对话中运行 $codiscuss-draft-cleanup,或点击下方清理临时文件。": "This room's drafts exceeded the limit and new runs are paused. Run $codiscuss-draft-cleanup in an AI chat outside the room, or clear temporary files below.",
|
|
@@ -481,6 +481,8 @@
|
|
|
481
481
|
"重新读取目录": "Reload folder",
|
|
482
482
|
"此文件夹为空": "This folder is empty",
|
|
483
483
|
"列表视图": "List view",
|
|
484
|
+
"返回上一个位置": "Back",
|
|
485
|
+
"前进": "Forward",
|
|
484
486
|
"返回文件夹": "Back to folder",
|
|
485
487
|
"图标视图": "Icon view",
|
|
486
488
|
"{value1} 项": "{value1} items",
|
|
@@ -758,7 +760,7 @@
|
|
|
758
760
|
"自行决定": "Its own choice",
|
|
759
761
|
"第 {value1} 行": "Line {value1}",
|
|
760
762
|
"第 {value1}–{value2} 行": "Lines {value1}–{value2}",
|
|
761
|
-
"主持人声明 Goal 待你确认后,
|
|
763
|
+
"主持人声明 Goal 待你确认后,3 分钟内你没在房间回复,就发到微信;直接回复微信消息即作为你的发言发回该房间,引用某条通知回复则发回那条通知的房间。成员向你提的问题等你 3 分钟未答也会发来,回复选项编号即直接作答,其他文字交给主持人代为选择。只转发文字,登录凭据只存这台电脑。": "If you do not reply in the room within 3 minutes after the host marks a Goal as awaiting your confirmation, a notification is sent to Weixin. Reply in Weixin to post your message in that room; quoting a notification sends it to that notification's room. A question a member asks you is also sent once it has waited 3 minutes: reply with an option number to answer it directly, or anything else for the host to choose for you. Only text is forwarded. Login credentials stay on this computer.",
|
|
762
764
|
"配置 {value1}": "Configure {value1}",
|
|
763
765
|
"配置:软件、模型、描述与专属提示词(也可双击卡片)": "Configure: software, model, description and expert prompt (or double-click the card)",
|
|
764
766
|
"从工作流移除这张卡片": "Remove this card from the workflow",
|
|
@@ -899,5 +901,18 @@
|
|
|
899
901
|
"提醒它不要用命令行看目录、读文件,否则这一轮会被中断": "Reminds it not to list folders or read files through the command line; otherwise the turn is cut short",
|
|
900
902
|
"每次任务": "every task",
|
|
901
903
|
"仅只读权限时": "only when read-only",
|
|
902
|
-
"{software}:{note}({when})": "{software}: {note} ({when})"
|
|
904
|
+
"{software}:{note}({when})": "{software}: {note} ({when})",
|
|
905
|
+
"(微信返回:{value1})": " (WeChat said: {value1})",
|
|
906
|
+
"微信拒绝了这条通知{value1}。常见原因是太久没在微信里给机器人发消息、发送凭据已失效:在微信里给机器人发一句任意消息即可恢复。": "WeChat refused this notification{value1}. This usually means you have not messaged the bot for a long time, so its sending credential has expired. Send the bot any message in WeChat to restore it.",
|
|
907
|
+
"微信拒绝了这条通知(错误码 {value1}){value2}。": "WeChat refused this notification (error code {value1}){value2}.",
|
|
908
|
+
"这台电脑连不上微信服务器,通知没有发出:{value1}": "This computer could not reach the WeChat server, so the notification was not sent: {value1}",
|
|
909
|
+
"微信通知没有发出:{value1}": "WeChat notification not sent: {value1}",
|
|
910
|
+
"{value1} 发送失败:{value2}": "Failed to send at {value1}: {value2}",
|
|
911
|
+
"微信登录已过期,请在“设置 → 通知”的微信一栏解除绑定后重新扫码。": "The WeChat login has expired. Unbind it under WeChat in “Settings → Notifications” and scan again.",
|
|
912
|
+
"通知": "Notifications",
|
|
913
|
+
"有事等你处理时提醒你": "Reminds you when something needs you",
|
|
914
|
+
"微信 · {value1}": "WeChat · {value1}",
|
|
915
|
+
"Goal 待你确认、或成员向你提的问题等你 3 分钟未答时,经下面的渠道提醒你。": "When a Goal awaits your confirmation, or a member’s question has waited 3 minutes for your answer, you are reminded through the channels below.",
|
|
916
|
+
"微信": "WeChat",
|
|
917
|
+
"用个人微信扫码绑定。直接回复通知即作为你的发言发回该房间,引用某条通知回复则发回那条通知的房间;回复问题通知的选项编号即直接作答,其他文字交给主持人代为选择。只转发文字,登录凭据只存这台电脑。": "Link your personal WeChat by scanning a QR code. Reply to a notification to post your message in that room; quoting a notification sends it to that notification’s room. Reply to a question notification with an option number to answer it directly, or with anything else for the host to choose for you. Only text is forwarded. Login credentials stay on this computer."
|
|
903
918
|
}
|
package/package.json
CHANGED
package/runner/adapters/api.mjs
CHANGED
|
@@ -98,7 +98,7 @@ export function participant_tools(context) {
|
|
|
98
98
|
|
|
99
99
|
function role_tools(context) {
|
|
100
100
|
const tools = [tool('read_room', '读取本房间最新目标、安排、限制和状态'),
|
|
101
|
-
tool('read_messages', '读取原文;服务端按本次请求限制讨论中的可见范围。after(只读该编号之后的)与 page(按页)二选一,给了 after 则忽略 page。每次输出有上限,remaining 大于 0 时还有没读到的,放不下的长正文只给预览(text_complete: false),用 read_message 按 next_offset
|
|
101
|
+
tool('read_messages', '读取原文;服务端按本次请求限制讨论中的可见范围。after(只读该编号之后的)与 page(按页)二选一,给了 after 则忽略 page。每次输出有上限,remaining 大于 0 时还有没读到的,放不下的长正文只给预览(text_complete: false),用 read_message 按 next_offset 续读;值为空的字段不输出,read_message 给完整字段', { page: NUMBER, after: { type: 'integer', minimum: 0 } }),
|
|
102
102
|
tool('read_message', '读取指定原文;服务端按本次请求限制讨论中的可见范围。长正文用 offset(从第几个字符起)与 limit 续读,带上前一段返回的 text_sha256 作 version:正文已变化时报错,须从头重读、不与旧片段拼接',
|
|
103
103
|
{ id: NUMBER, offset: { type: 'integer', minimum: 0 }, limit: NUMBER, version: VERSION }, ['id']),
|
|
104
104
|
tool('read_execution', '读取一次执行的状态、结果与交付状态(delivery.last_submission 的 outcome:accepted 已接受 / rejected 被拒 / unknown 不明);不填 id 读本次执行,主持人可读任意成员的执行', { id: NUMBER }),
|
package/runner/admin_cli.mjs
CHANGED
|
@@ -49,18 +49,20 @@ export const HELP = t(`用法:codiscuss admin <命令> [参数](与管理面
|
|
|
49
49
|
autostart on|off 登录 Windows 时自动启动
|
|
50
50
|
|
|
51
51
|
管理员入口
|
|
52
|
-
site status
|
|
53
|
-
site connect
|
|
54
|
-
site disconnect
|
|
55
|
-
site
|
|
52
|
+
site status 本地网页地址与线上网站地址
|
|
53
|
+
site connect <接入码|线上网站地址> [绑定令牌] 绑定自建中转(管理员外出、邀请外部专家用);在部署该网站的电脑上只填线上网站地址即可
|
|
54
|
+
site disconnect 解绑自建中转,已配对的设备不能再连到这台电脑
|
|
55
|
+
site region [地区] 查看或设置中转地区(auto、apac、apac-ne、apac-se、wnam、enam、weur、eeur、oc、sam、afr、me)
|
|
56
|
+
site reconnect 立即重连已绑定的自建中转
|
|
56
57
|
|
|
57
58
|
登录入口与访问方式(需打开托管管理)
|
|
58
59
|
entry start|stop 启动或停止登录入口
|
|
59
|
-
entry open|close relay|tunnel
|
|
60
|
-
entry join <接入码>
|
|
60
|
+
entry open|close relay|tunnel 开启或关闭访问方式:自建中转 | Cloudflare 隧道,两种可同时开启
|
|
61
|
+
entry join <接入码> 用接入码绑定自建中转并开启托管账号入口
|
|
61
62
|
entry code [--config <wrangler.jsonc>] [--site <地址>] 在部署线上站点的电脑上生成接入码(不填用上次的)
|
|
62
|
-
entry tunnel <域名> [隧道名]
|
|
63
|
-
entry tunnel
|
|
63
|
+
entry tunnel <域名> [隧道名] 设置 Cloudflare 隧道,输出授权链接;域名须已托管在 Cloudflare
|
|
64
|
+
entry tunnel reconnect 重新连接隧道,保留登录会话
|
|
65
|
+
entry tunnel status 查看 Cloudflare 隧道设置的进度
|
|
64
66
|
runtime sync 同步隔离账号的程序副本
|
|
65
67
|
drives restrict 只允许隔离账号用系统盘:其他固定磁盘对它们的 Windows 用户拒绝访问(需管理员权限,之后重启它们的实例)
|
|
66
68
|
|
|
@@ -88,6 +90,7 @@ API 密钥、技能、工作流、系统提示词(目标同上)
|
|
|
88
90
|
|
|
89
91
|
结果以 JSON 输出。--data 指定管理员服务目录(默认 ~/.codiscuss)。
|
|
90
92
|
`) + t(' room-links A 查看父子房间') + '\n' + t(' storage [clean | repair [logs --confirm]] 查看用量、安全清理或深度修理日志') + '\n'
|
|
93
|
+
+ t(' storage attachments [ROOM [clear ID... --confirm]] 按房间查看附件占用、列出某房间附件或清理所选附件原件') + '\n'
|
|
91
94
|
+ t(' account add <名> --project-data-root <目录> 将新账号的项目、工作区和成员草稿放在指定目录') + '\n'
|
|
92
95
|
+ t(' account migrate-data <名> --project-data-root <目录> 停止实例并迁移项目数据') + '\n'
|
|
93
96
|
+ t(' account migration-backups <名> 查看各迁移备份的位置与字节数') + '\n'
|
|
@@ -344,6 +347,7 @@ async function entry_command(call, [action, first, second], values) {
|
|
|
344
347
|
if (action === 'open' || action === 'close') return call('entry/way', { way: need(first, 'relay|tunnel'), enabled: action === 'open' });
|
|
345
348
|
if (action === 'join') return call('relay/join', { code: need(first, t('接入码')) });
|
|
346
349
|
if (action === 'code') return call('site/code', { config: values.config || '', site: values.site || '' });
|
|
350
|
+
if (action === 'tunnel' && first === 'reconnect') return call('tunnel/reconnect', {});
|
|
347
351
|
if (action === 'tunnel') return first === 'status' ? call('tunnel/setup') : setup_tunnel(call, need(first, t('域名')), second || '');
|
|
348
352
|
throw new Error(HELP);
|
|
349
353
|
}
|
|
@@ -356,6 +360,7 @@ async function site_command(call, [action, first, second]) {
|
|
|
356
360
|
}
|
|
357
361
|
if (action === 'connect') return call('site/connect', { site: need(first, t('站点')), setup_key: second || '' });
|
|
358
362
|
if (action === 'disconnect') return call('site/disconnect', {});
|
|
363
|
+
if (action === 'region') return call('site/region', first === undefined ? undefined : { region: first });
|
|
359
364
|
if (action === 'reconnect') return call('site/reconnect', {});
|
|
360
365
|
throw new Error(HELP);
|
|
361
366
|
}
|
|
@@ -434,6 +439,12 @@ export async function admin_cli(args, { client = panel_client, print = text => p
|
|
|
434
439
|
if (rest.join(' ') === 'repair') return call('storage/repair', {});
|
|
435
440
|
if (rest.join(' ') === 'repair logs' && values.confirm) return call('storage/repair', { logs: true, confirm: true });
|
|
436
441
|
if (rest.length === 1 && rest[0] === 'clean') return call('storage/clean', {});
|
|
442
|
+
if (rest[0] === 'attachments') {
|
|
443
|
+
const [, room_id, action, ...ids] = rest;
|
|
444
|
+
if (!room_id) return call('storage').then(report => report.attachment_rooms || []);
|
|
445
|
+
if (!action) return call('storage/attachments', { room_id });
|
|
446
|
+
if (action === 'clear' && ids.length && values.confirm) return call('storage/attachments/clear', { room_id, ids });
|
|
447
|
+
}
|
|
437
448
|
throw new Error(HELP);
|
|
438
449
|
},
|
|
439
450
|
status: async () => {
|
|
@@ -4,6 +4,7 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
4
4
|
import { storage_details, clean_storage } from './admin_storage.mjs';
|
|
5
5
|
import { execution_file_protection, read_registry, sweep_service_home } from './discussion_service.mjs';
|
|
6
6
|
import { t } from './i18n.mjs';
|
|
7
|
+
import { site_fetch } from './entry_client.mjs';
|
|
7
8
|
import { with_directory_breakdown } from './storage_guard.mjs';
|
|
8
9
|
|
|
9
10
|
function local_database(home, action) {
|
|
@@ -28,9 +29,39 @@ export async function panel_storage(home, local) {
|
|
|
28
29
|
for (const room of report.rooms) if (room.site && matches_site(room.site, local)) room.title = title.get(room.room_id)?.title;
|
|
29
30
|
});
|
|
30
31
|
} catch { /* A room ID remains available when titles cannot be read. */ }
|
|
32
|
+
try {
|
|
33
|
+
local_database(home, db => {
|
|
34
|
+
// Sent files still holding their bytes, per room, largest first: what clearing attachments can free.
|
|
35
|
+
report.attachment_rooms = db.prepare(`SELECT a.room_id,r.title,COUNT(*) AS count,SUM(a.size) AS bytes,MAX(a.created_at) AS latest_at
|
|
36
|
+
FROM attachments a JOIN rooms r ON r.id=a.room_id WHERE a.message_id IS NOT NULL AND a.cleared_at IS NULL
|
|
37
|
+
GROUP BY a.room_id ORDER BY bytes DESC`).all().map(row => ({ ...row }));
|
|
38
|
+
});
|
|
39
|
+
} catch { /* An older site without cleared files has no list; the page shows none. */ }
|
|
31
40
|
return report;
|
|
32
41
|
}
|
|
33
42
|
|
|
43
|
+
const ROOM_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
44
|
+
|
|
45
|
+
/** Ask the local site, as this computer's administrator, for one room's attachments or to clear some of them. */
|
|
46
|
+
async function room_attachments_request(local, room_id, action, body) {
|
|
47
|
+
if (typeof room_id !== 'string' || !ROOM_ID.test(room_id)) throw new Error(t('房间编号无效'));
|
|
48
|
+
const response = await site_fetch(`${local}/api/rooms/${room_id}/attachments/${action}`, body === undefined ? {}
|
|
49
|
+
: { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
50
|
+
const result = await response.json().catch(() => ({}));
|
|
51
|
+
if (!response.ok) throw new Error(result.error || t('附件请求失败(HTTP {status})', { status: response.status }));
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One room's sent files with sizes and cleared state, for picking what to clear. */
|
|
56
|
+
export function panel_room_attachments(local, body) {
|
|
57
|
+
return room_attachments_request(local, body.room_id, 'usage');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Clear the original bytes of the chosen files of one room; records and thumbnails stay. */
|
|
61
|
+
export function panel_clear_attachments(local, body) {
|
|
62
|
+
return room_attachments_request(local, body.room_id, 'clear', { ids: body.ids });
|
|
63
|
+
}
|
|
64
|
+
|
|
34
65
|
function account_file(path, apply, result) {
|
|
35
66
|
const stat = lstatSync(path, { throwIfNoEntry: false });
|
|
36
67
|
if (!stat?.isFile() || stat.nlink !== 1) return;
|
package/runner/admin_panel.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { spawn, spawnSync } from 'node:child_process';
|
|
|
11
11
|
import { randomBytes } from 'node:crypto';
|
|
12
12
|
import { closeSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, realpathSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
13
13
|
import http from 'node:http';
|
|
14
|
-
import { panel_clean, panel_storage, panel_repair } from './admin_maintenance.mjs';
|
|
14
|
+
import { panel_clean, panel_clear_attachments, panel_room_attachments, panel_storage, panel_repair } from './admin_maintenance.mjs';
|
|
15
15
|
import { homedir, tmpdir } from 'node:os';
|
|
16
16
|
import tls from 'node:tls';
|
|
17
17
|
import { dirname, extname, join, resolve } from 'node:path';
|
|
@@ -23,8 +23,9 @@ import { account_home, add_account, data_home, entry_settings, entry_status, ins
|
|
|
23
23
|
import { signed_site_url, site_fetch, verified_connection } from './entry_client.mjs';
|
|
24
24
|
import { API_PROVIDERS, save_api_key } from './discussion_api.mjs';
|
|
25
25
|
import { STT_PROVIDERS, TTS_PROVIDERS } from './tts_providers.mjs';
|
|
26
|
-
import { ensure_tunnel, start_tunnel_setup, tunnel_setup_state, tunnel_status } from './hosting_tunnel.mjs';
|
|
27
|
-
import {
|
|
26
|
+
import { ensure_tunnel, stop_tunnel, start_tunnel_setup, tunnel_setup_state, tunnel_status } from './hosting_tunnel.mjs';
|
|
27
|
+
import { RELAY_REGIONS } from './device_auth.mjs';
|
|
28
|
+
import { machine_links, save_machine_links } from './remote_launch.mjs';
|
|
28
29
|
import { read_relay_health, request_relay_reconnect } from './relay_health.mjs';
|
|
29
30
|
import { instance_recovery } from './instance_recovery.mjs';
|
|
30
31
|
import { mark_backup_release, reserve_project_root, set_project_migration } from '../gateway/gateway.mjs';
|
|
@@ -68,6 +69,8 @@ const UPDATE_STALE_MS = 10 * 60 * 1000;
|
|
|
68
69
|
const UPDATE_FINISH_CHECK_MS = 3000;
|
|
69
70
|
const OWNER_ENV_TIMEOUT_MS = 120_000;
|
|
70
71
|
// How often the panel makes sure the entry's tunnel runs as set, and how long an update waits for the entry to be back.
|
|
72
|
+
const TUNNEL_CONNECT_MS = 30_000;
|
|
73
|
+
const TUNNEL_POLL_MS = 500;
|
|
71
74
|
const TUNNEL_CHECK_MS = 60_000;
|
|
72
75
|
const ENTRY_BACK_MS = 15_000;
|
|
73
76
|
// How long the panel waits for the relay's entry Worker to answer whether it is reachable.
|
|
@@ -548,7 +551,7 @@ function run_instance(data, name, command) {
|
|
|
548
551
|
// An account without its own Windows user runs as the owner and could read everything the owner can; it is not let
|
|
549
552
|
// run while people outside can reach the entry.
|
|
550
553
|
if (command === 'start' && process.platform === 'win32' && !read_os_users(data)[name] && (entry_settings(data).relay_enabled || entry_settings(data).tunnel_enabled)) {
|
|
551
|
-
throw panel_error('外网访问已开启,{value1}
|
|
554
|
+
throw panel_error('外网访问已开启,{value1} 未隔离(以你的身份运行),不能启动:请先隔离该账号,或关闭登录入口的自建中转和 Cloudflare 隧道', { value1: name });
|
|
552
555
|
}
|
|
553
556
|
if (command === 'start' && read_os_users(data)[name]) {
|
|
554
557
|
const { local_script } = shared_paths();
|
|
@@ -763,6 +766,7 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
|
|
|
763
766
|
login_status, apply_login, logout, start_login, login_progress, submit_login, cancel_login, install_runtime, prepare_account, account_env, account_skills, account_workflows, owner_env, owner_skills, shared_cli_state,
|
|
764
767
|
save_api_key, list_keys, remove_key, use_shared_programs, service_overview, run_owner_service, latest_version, check_package, begin_update,
|
|
765
768
|
set_account_external, reconcile_external, autostart_enabled, set_autostart, entry_overview, start_entry, stop_entry, keep_tunnel, start_tunnel_setup, set_entry_way, set_relay_url, connect_site, make_access_code, join_relay, protect_account, start_verified, hand_over: () => {}, ...ops };
|
|
769
|
+
let reconnecting_tunnel;
|
|
766
770
|
const hosts = new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
|
|
767
771
|
const recovery = instance_recovery(data, { wanted: name => wanted_port(data, name, ops.instance_flag_set || instance_flag_set),
|
|
768
772
|
probe: ops.instance_state || instance_state, start: name => op.start_verified(data, name), now: ops.now,
|
|
@@ -787,11 +791,13 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
|
|
|
787
791
|
if (path === '/api/storage' && method === 'GET') return panel_storage(data, site_url(data));
|
|
788
792
|
if (path === '/api/storage/clean' && method === 'POST') return panel_clean(data, site_url(data), body);
|
|
789
793
|
if (path === '/api/storage/repair' && method === 'POST') return panel_repair(data, site_url(data), body);
|
|
794
|
+
if (path === '/api/storage/attachments' && method === 'POST') return panel_room_attachments(site_url(data), body);
|
|
795
|
+
if (path === '/api/storage/attachments/clear' && method === 'POST') return panel_clear_attachments(site_url(data), body);
|
|
790
796
|
if (method === 'GET' && section === 'state') {
|
|
791
797
|
const windows = process.platform === 'win32';
|
|
792
798
|
const service = op.service_overview(data), bound = bound_site(data);
|
|
793
799
|
const restarts = hosting ? recovery.status() : {};
|
|
794
|
-
return { hosting, version: VERSION, service, online_site: bound?.site || '', platform: process.platform,
|
|
800
|
+
return { hosting, version: VERSION, service, online_site: bound?.site || '', relay_region: bound?.region ?? 'apac', platform: process.platform,
|
|
795
801
|
relay_health: read_relay_health(data, bound, service.running && service.pid),
|
|
796
802
|
launcher: windows && existsSync(launcher_path(data)), autostart: windows && op.autostart_enabled(), login_methods: LOGIN_METHODS, providers: API_PROVIDERS,
|
|
797
803
|
...(hosting ? { accounts: (await op.list_accounts(data)).map(item => ({ ...item, last_restart: restarts[item.name] })), clis: op.shared_cli_state(), entry: await op.entry_overview(data, { reach: false }) }
|
|
@@ -856,9 +862,23 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
|
|
|
856
862
|
// The owner's own online site: bound, checked and left here whether or not this computer hosts accounts.
|
|
857
863
|
if (method === 'POST' && section === 'site' && name === 'connect') { const bound = await bind_online_site(data, body, op.connect_site); after_change(); return bound; }
|
|
858
864
|
if (method === 'POST' && section === 'site' && name === 'disconnect') { const left = await disconnect_site(data); after_change(); return left; }
|
|
865
|
+
if (section === 'site' && name === 'region' && ['GET', 'POST'].includes(method)) {
|
|
866
|
+
const bound = bound_site(data);
|
|
867
|
+
if (!bound) throw panel_error('尚未绑定自建中转');
|
|
868
|
+
if (method === 'GET') return { region: bound.region };
|
|
869
|
+
if (!RELAY_REGIONS.includes(body.region)) throw panel_error('中转地区无效');
|
|
870
|
+
if (bound.region === body.region) return { region: bound.region };
|
|
871
|
+
const links = machine_links(data);
|
|
872
|
+
links.sites[bound.site].relay_region = body.region;
|
|
873
|
+
save_machine_links(data, links);
|
|
874
|
+
const service = op.service_overview(data);
|
|
875
|
+
if (service.pid) request_relay_reconnect(data, { ...bound, wait_region: body.region }, service.pid);
|
|
876
|
+
after_change();
|
|
877
|
+
return { region: body.region };
|
|
878
|
+
}
|
|
859
879
|
if (method === 'POST' && section === 'site' && name === 'reconnect') {
|
|
860
880
|
const bound = bound_site(data), service = op.service_overview(data);
|
|
861
|
-
if (!bound) throw panel_error('
|
|
881
|
+
if (!bound) throw panel_error('尚未绑定自建中转');
|
|
862
882
|
if (!service.pid) throw panel_error('请先启动共议服务,再重连中转');
|
|
863
883
|
request_relay_reconnect(data, bound, service.pid);
|
|
864
884
|
return { requested: true, site: bound.site };
|
|
@@ -892,6 +912,10 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
|
|
|
892
912
|
if (method === 'POST' && section === 'site' && name === 'code') return op.make_access_code(data, body);
|
|
893
913
|
if (method === 'POST' && section === 'relay' && name === 'join') return op.join_relay(data, body.code);
|
|
894
914
|
// The outside address: a Cloudflare tunnel set up by a job of its own (it waits for the owner in the browser).
|
|
915
|
+
if (method === 'POST' && section === 'tunnel' && name === 'reconnect') {
|
|
916
|
+
reconnecting_tunnel ??= reconnect_tunnel(data).finally(() => { reconnecting_tunnel = null; });
|
|
917
|
+
return reconnecting_tunnel;
|
|
918
|
+
}
|
|
895
919
|
if (section === 'tunnel' && name === 'setup') {
|
|
896
920
|
if (method === 'GET') return tunnel_setup_state(data);
|
|
897
921
|
if (method === 'POST') return op.start_tunnel_setup(data, body.host, body.name);
|
|
@@ -1008,6 +1032,23 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
|
|
|
1008
1032
|
}
|
|
1009
1033
|
|
|
1010
1034
|
/** The account entry as the hosting page shows it: whether it runs, its loopback port and the address customers open. */
|
|
1035
|
+
/** Restart only cloudflared and return the final readiness probe. */
|
|
1036
|
+
async function reconnect_tunnel(data) {
|
|
1037
|
+
const entry = await entry_status(data);
|
|
1038
|
+
const { tunnel, tunnel_enabled } = entry_settings(data);
|
|
1039
|
+
if (!tunnel) throw panel_error('请先配置 Cloudflare 隧道');
|
|
1040
|
+
if (!tunnel_enabled) throw panel_error('请先开启 Cloudflare 隧道');
|
|
1041
|
+
if (!entry.running) throw panel_error('请先启动登录入口');
|
|
1042
|
+
stop_tunnel(data);
|
|
1043
|
+
await ensure_tunnel(data, tunnel, entry.port);
|
|
1044
|
+
const deadline = Date.now() + TUNNEL_CONNECT_MS;
|
|
1045
|
+
while (true) {
|
|
1046
|
+
const status = await tunnel_status(data);
|
|
1047
|
+
if (status.connected || Date.now() >= deadline) return status;
|
|
1048
|
+
await new Promise(resolve => setTimeout(resolve, TUNNEL_POLL_MS));
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1011
1052
|
/** Keep the entry's tunnel as the settings say: running while hosting is on and the entry is meant to run. */
|
|
1012
1053
|
function keep_tunnel(data) {
|
|
1013
1054
|
const { tunnel, port, running, tunnel_enabled } = entry_settings(data);
|
|
@@ -1017,7 +1058,7 @@ function keep_tunnel(data) {
|
|
|
1017
1058
|
/** The online site this computer is bound to (`codiscuss local connect`) and its id there, or null. */
|
|
1018
1059
|
function bound_site(data) {
|
|
1019
1060
|
const [site, link] = Object.entries(machine_links(data).sites || {}).find(([, item]) => item?.id && item?.private_key) || [];
|
|
1020
|
-
return site ? { site, machine: link.id } : null;
|
|
1061
|
+
return site ? { site, machine: link.id, region: RELAY_REGIONS.includes(link.relay_region) ? link.relay_region : 'apac' } : null;
|
|
1021
1062
|
}
|
|
1022
1063
|
|
|
1023
1064
|
/** Ask the relay's entry Worker whether it is one and whether this computer is connected to it. */
|
|
@@ -1068,7 +1109,7 @@ async function prepare_entry_way(data, way) {
|
|
|
1068
1109
|
const users = read_os_users(data), accounts = read_accounts(data);
|
|
1069
1110
|
const exposed = [];
|
|
1070
1111
|
for (const [name, account] of Object.entries(accounts)) if (!users[name] && await instance_running(account.port)) exposed.push(name);
|
|
1071
|
-
if (exposed.length) throw panel_error('未隔离的账号正在运行({value1}
|
|
1112
|
+
if (exposed.length) throw panel_error('未隔离的账号正在运行({value1}),它们以你的身份运行,开启自建中转或 Cloudflare 隧道前请先停止或隔离', { value1: exposed.join('、') });
|
|
1072
1113
|
}
|
|
1073
1114
|
}
|
|
1074
1115
|
|
|
@@ -1119,7 +1160,7 @@ function make_access_code(data, { config, site }) {
|
|
|
1119
1160
|
const path = resolve(String(config || saved.config || '').trim() || '.');
|
|
1120
1161
|
if (!existsSync(path) || !/\.jsonc?$/.test(path)) throw panel_error('找不到线上站点的部署配置:填写源码仓库里 .wrangler\\deploy\\wrangler.jsonc 的完整路径');
|
|
1121
1162
|
let origin;
|
|
1122
|
-
try { origin = new URL(String(site || saved.site || bound_site(data)?.site || '').trim()).origin; } catch { throw panel_error('
|
|
1163
|
+
try { origin = new URL(String(site || saved.site || bound_site(data)?.site || '').trim()).origin; } catch { throw panel_error('线上网站地址格式不对,例如 https://xxx.pages.dev'); }
|
|
1123
1164
|
return new Promise((done, fail) => {
|
|
1124
1165
|
const child = spawn(process.execPath, [installed_script('codiscuss.mjs'), 'token', '--config', path], { cwd: wrangler_folder(path), windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
1125
1166
|
let output = '', errors = '';
|
|
@@ -1151,7 +1192,7 @@ async function join_relay(data, text) {
|
|
|
1151
1192
|
await set_relay_url(data, entry_url);
|
|
1152
1193
|
steps.push(t('入口地址 {value1}', { value1: entry_url }));
|
|
1153
1194
|
const overview = await set_entry_way(data, 'relay', true);
|
|
1154
|
-
steps.push(t('
|
|
1195
|
+
steps.push(t('已开启自建中转'));
|
|
1155
1196
|
return { steps, entry: overview };
|
|
1156
1197
|
}
|
|
1157
1198
|
|
|
@@ -1192,7 +1233,7 @@ async function bind_online_site(data, { site, setup_key }, connect) {
|
|
|
1192
1233
|
const text = String(site || '').trim(), at = text.indexOf(BIND_MARK);
|
|
1193
1234
|
if (at >= 0) { setup_key = text.slice(at + BIND_MARK.length); site = text.slice(0, at); }
|
|
1194
1235
|
let origin;
|
|
1195
|
-
try { origin = new URL(String(site || '').trim()).origin; } catch { throw panel_error('
|
|
1236
|
+
try { origin = new URL(String(site || '').trim()).origin; } catch { throw panel_error('线上网站地址格式不对,例如 https://xxx.pages.dev'); }
|
|
1196
1237
|
if (bound && bound.site !== origin) throw panel_error('这台电脑已绑定 {value1},请先解绑', { value1: bound.site });
|
|
1197
1238
|
const result = await connect(data, origin, setup_key);
|
|
1198
1239
|
if (!result) throw panel_error('这个地址不是共议线上站点:{value1}', { value1: origin });
|
|
@@ -1203,7 +1244,7 @@ async function bind_online_site(data, { site, setup_key }, connect) {
|
|
|
1203
1244
|
async function disconnect_site(data) {
|
|
1204
1245
|
const bound = bound_site(data);
|
|
1205
1246
|
if (!bound) return { disconnected: '' };
|
|
1206
|
-
if (entry_settings(data).relay_enabled) throw panel_error('
|
|
1247
|
+
if (entry_settings(data).relay_enabled) throw panel_error('托管账号入口的自建中转还开着,请先关闭它');
|
|
1207
1248
|
// The accounts bound under this computer are released first (a failure stops here, to be retried); those reached on
|
|
1208
1249
|
// the owner's domain do not use the online site (#5617, #5660).
|
|
1209
1250
|
for (const [name, record] of Object.entries(read_account_sites(data))) if (!record.direct) await change_external(data, name, false);
|
|
@@ -1268,7 +1309,7 @@ async function set_account_external(data, name, on, bind = bind_account_site, {
|
|
|
1268
1309
|
return { external: true, site };
|
|
1269
1310
|
}
|
|
1270
1311
|
const bound = bound_site(data);
|
|
1271
|
-
if (!bound) throw panel_error('
|
|
1312
|
+
if (!bound) throw panel_error('这台电脑未绑定自建中转,请在管理面板“本机 → 自建中转”处绑定');
|
|
1272
1313
|
const answer = await fetch_outside(`${bound.site}/api/machines/${bound.machine}/setup`, OUTSIDE_TIMEOUT_MS,
|
|
1273
1314
|
{ method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Machine-Token': machine_links(data).sites[bound.site].token }, body: '{}' });
|
|
1274
1315
|
const given = await answer.json().catch(() => ({}));
|
package/runner/device_auth.mjs
CHANGED
|
@@ -10,6 +10,8 @@ import { join } from 'node:path';
|
|
|
10
10
|
import { atomic_json } from './files.mjs';
|
|
11
11
|
import { b64url, from_b64url, verify_assertion, verify_registration } from './webauthn.mjs';
|
|
12
12
|
|
|
13
|
+
// The site enforces the matching list in backend/worker.mjs.
|
|
14
|
+
export const RELAY_REGIONS = ['auto', 'apac', 'apac-ne', 'apac-se', 'wnam', 'enam', 'weur', 'eeur', 'oc', 'sam', 'afr', 'me'];
|
|
13
15
|
const DEVICES_FILE = 'devices.json';
|
|
14
16
|
// What other devices did here: trust changes and every remote write, never content. Shown in the device list, so an
|
|
15
17
|
// unexpected entry (a device you did not add, a write you did not make) can be noticed and revoked.
|
|
@@ -247,11 +249,12 @@ export async function signed_device_list(home, link, now = Date.now(), externals
|
|
|
247
249
|
...externals.map(({ id, x, y, room, expires_at }) => ({ id, x, y, kind: 'external', room, expires_at }))];
|
|
248
250
|
// An unchanged list keeps its signature and issued_at, so the heartbeat that carries it is the same each time and
|
|
249
251
|
// the website neither rewrites it nor wakes the relay (2026-11-19, #5500); issued_at is when the content last changed.
|
|
250
|
-
const
|
|
252
|
+
const region = RELAY_REGIONS.includes(link.relay_region) ? link.relay_region : 'apac';
|
|
253
|
+
const content = JSON.stringify({ machine: link.id, relay_region: region, devices: listed });
|
|
251
254
|
const cache_key = [home, link.id, link.sign_private_key?.x || ''].join('|');
|
|
252
255
|
const cached = signed_lists.get(cache_key);
|
|
253
256
|
if (cached?.content === content) return cached.signed;
|
|
254
|
-
const body = JSON.stringify({ machine: link.id, issued_at: Math.max(now, (cached?.issued_at || 0) + 1), devices: listed });
|
|
257
|
+
const body = JSON.stringify({ machine: link.id, relay_region: region, issued_at: Math.max(now, (cached?.issued_at || 0) + 1), devices: listed });
|
|
255
258
|
const key = await crypto.subtle.importKey('jwk', link.sign_private_key, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['sign']);
|
|
256
259
|
const signature = await crypto.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, key, new TextEncoder().encode(body));
|
|
257
260
|
const signed = { body, signature: b64url(new Uint8Array(signature)) };
|
package/runner/discuss.py
CHANGED
|
@@ -357,7 +357,7 @@ def room_commands(subcommands, registry):
|
|
|
357
357
|
|
|
358
358
|
def message_commands(subcommands, registry):
|
|
359
359
|
"""Register bounded search, exact reads, and attributed message writes."""
|
|
360
|
-
listing = add_leaf(subcommands, registry, "message list", "检索原文:每次最多 20 条且不超过约 8000 字符(含元数据),未列完时按 next_after 用 --after 续读;remaining
|
|
360
|
+
listing = add_leaf(subcommands, registry, "message list", "检索原文:每次最多 20 条且不超过约 8000 字符(含元数据),未列完时按 next_after 用 --after 续读;remaining 是本次之后还剩的匹配条数;值为空的字段不输出,message view 给完整字段;"
|
|
361
361
|
"过长的单条只给开头并标 text_complete=false,用 message view 编号 --offset 续读全文;"
|
|
362
362
|
"```visual 交互式可视化代码块折叠成一行并注明字符数,要看源码用 message view", True)
|
|
363
363
|
paging = listing.add_mutually_exclusive_group()
|
|
@@ -147,7 +147,7 @@ image-check 检查这台电脑已保存的生图服务:用密钥读取地址
|
|
|
147
147
|
image 成员按任务凭据生图(房间须添加了生图卡片):REQUEST 为 JSON,必填 action(generate 生成 / edit 改图)与 prompt;可选 size(auto、1024x1024、1536x1024、1024x1536 或 16 倍数的 宽x高)、quality(auto/low/medium/high,2.5、2.6 系列另有 xhigh/max)、n(1–10 张)、output_format(png/jpeg/webp/gif,生成另可 svg)、background(auto/opaque/transparent)、file_name(附件名)、save_path(另存进可写项目);edit 另需 images(1–16 个 {attachment_id} 或 {file_path},第一张为主图),可加 mask 或 markup(同样格式,二选一)。图片存为成员的附件,返回附件 ID,再用 message post --attachment 附上。
|
|
148
148
|
tts-settings 读取朗读设置;内容非空时保存(语音服务 provider:local(本机,由 local-tts-setup 技能安装)/ volcengine / aliyun / azure / openai,语速 speech_rate,以及 providers.<服务> 的 api_key_ref、speaker、member_voices、file_voice,本机、火山引擎与 OpenAI 另有语气提示 context(各自默认不同),Azure 另有 region;语音输入服务 stt_provider:local / volcengine / openai)。
|
|
149
149
|
tts 用朗读设置把 text(不超过 300 字)合成为音频(本机服务为 m4a,其余为 MP3),返回 base64。
|
|
150
|
-
weixin 微信通知:action 为 status(默认,读取绑定状态)、login(生成扫码内容)、complete(等待扫码确认,约 20 秒)、test(发一条测试通知)或 unbind(解除本机绑定)。Goal
|
|
150
|
+
weixin 微信通知:action 为 status(默认,读取绑定状态)、login(生成扫码内容)、complete(等待扫码确认,约 20 秒)、test(发一条测试通知)或 unbind(解除本机绑定)。Goal 待确认或阻塞提问 3 分钟仍未回复时通知房主,房主在微信回复即作为房主发言发回该房间;只用本机服务目录保存凭据。
|
|
151
151
|
tts-release 用户停止朗读:所选服务释放在这台电脑上占用的资源(本机语音在 5 秒内结束、释放显存),云端服务无操作。
|
|
152
152
|
local-speech 读取本机朗读(tts,yovoice)与语音识别(stt,crispasr)服务的运行状态(state:running / stopped / other(端口被其他程序占用),及 pid、进程名);内容为 {"stop": "tts" | "stt"} 时强行结束该服务(连同子进程),只结束端口上属于该服务程序的进程。
|
|
153
153
|
stt 按序接收录音片段(upload_id、index、base64 PCM 16 kHz 单声道、final);最后一段时识别整段录音并返回 text。
|
|
@@ -3796,7 +3796,7 @@ export async function launch_main(args = process.argv.slice(2), input_text) {
|
|
|
3796
3796
|
// The QR code opens the paired website and carries this computer's key fingerprint for the new device to check.
|
|
3797
3797
|
const { keyed_links } = await import('./remote_launch.mjs');
|
|
3798
3798
|
const [site, link] = Object.entries(keyed_links(home).sites).find(([origin]) => !input?.site || origin === input.site) || [];
|
|
3799
|
-
if (!link) throw new Error('
|
|
3799
|
+
if (!link) throw new Error('这台电脑未绑定自建中转,请在管理面板“本机 → 自建中转”处绑定');
|
|
3800
3800
|
result = start_pairing(home, { site, fingerprint: machine_fingerprint(link), temporary: input?.temporary === true, without_passkey: input?.without_passkey === true });
|
|
3801
3801
|
}
|
|
3802
3802
|
else if (positionals[0] === 'devices' && !values.remote) {
|
|
@@ -193,8 +193,8 @@ async function invite_site(home, site_url) {
|
|
|
193
193
|
if (direct && (!site_url || site_url === direct.site)) return { site: direct.site, link: direct };
|
|
194
194
|
const sites = Object.entries(keyed_links(home).sites);
|
|
195
195
|
const found = site_url ? sites.find(([origin]) => origin === site_url) : sites.length === 1 ? sites[0] : null;
|
|
196
|
-
if (!found) throw sites.length ? new GatewayError(400, '
|
|
197
|
-
: new GatewayError(400, '
|
|
196
|
+
if (!found) throw sites.length ? new GatewayError(400, '这台电脑绑定了多个自建中转,请指定邀请使用的网站', {}, 'site_required')
|
|
197
|
+
: new GatewayError(400, '这台电脑未绑定自建中转,请在管理面板“本机 → 自建中转”处绑定', {}, 'site_missing');
|
|
198
198
|
return { site: found[0], link: found[1] };
|
|
199
199
|
}
|
|
200
200
|
|
package/runner/free_runner.mjs
CHANGED
|
@@ -37,7 +37,7 @@ const MAX_CAPTURED_REPLY = 32000;
|
|
|
37
37
|
export const GOAL_IDLE_MS = 120_000;
|
|
38
38
|
// A goal waiting on the owner reaches their Weixin only after this long: right after the question they may be typing.
|
|
39
39
|
// How long the owner is left waiting (a goal's pending phase, a blocking question) before Weixin tells them.
|
|
40
|
-
export const PENDING_NOTICE_MS =
|
|
40
|
+
export const PENDING_NOTICE_MS = 3 * 60_000;
|
|
41
41
|
// A failed Weixin notice is tried again after this long instead of on every tick.
|
|
42
42
|
const NOTICE_RETRY_MS = 60_000;
|
|
43
43
|
// Background reports one follow-up (续报) carries at most (MAX_FOLLOWUP_REPORTS in backend/free_room.py), and the report
|
|
@@ -341,6 +341,8 @@ export async function request_attachments(config, execution, member_directory =
|
|
|
341
341
|
const number = Number.isInteger(file.number) ? file.number : index + 1;
|
|
342
342
|
const entry = { message_id, number, placeholder: attachment_placeholder(file, number), file_name: file.file_name,
|
|
343
343
|
content_type: file.content_type, size: file.size, id: file.id, path: '' };
|
|
344
|
+
// The owner freed this file's bytes; say so instead of failing a download.
|
|
345
|
+
if (file.cleared_at) { entry.error = '附件已被房主清理,原文件不可用'; result.push(entry); continue; }
|
|
344
346
|
try { entry.path = await save_attachment(config, member_directory, execution.id, message_id, entry, file.sha256); }
|
|
345
347
|
catch (error) { entry.error = error.message; }
|
|
346
348
|
result.push(entry);
|
|
@@ -662,9 +664,10 @@ function member_work(requests, name, message_id) {
|
|
|
662
664
|
|
|
663
665
|
/** Why a message stayed with the host: the scheduler chose the host, or leaned elsewhere without enough certainty. */
|
|
664
666
|
function route_host_label(decision, host, members) {
|
|
667
|
+
if (decision.choice === '__none__') return room_text("建议无需回应,交给主持人 {host}", { host });
|
|
665
668
|
if (decision.choice === '__host__' || decision.confidence === null) return `交给主持人 ${host}`;
|
|
666
669
|
const group = some_members(decision.choice);
|
|
667
|
-
const lean = decision.choice === '__all__' ? '全体各自回应' : decision.choice === '__all_seq__' ? '全体依次回应' :
|
|
670
|
+
const lean = decision.choice === '__all__' ? '全体各自回应' : decision.choice === '__all_seq__' ? '全体依次回应' : group ? `请 ${group.join('、')} 各自回应`
|
|
668
671
|
: members.some(member => member.name === decision.choice) ? `请 ${decision.choice} 回答` : '';
|
|
669
672
|
return lean ? `倾向${lean},把握不足,交给主持人 ${host}` : `交给主持人 ${host}`;
|
|
670
673
|
}
|
|
@@ -1087,7 +1090,7 @@ export class FreeRoomRunner {
|
|
|
1087
1090
|
}
|
|
1088
1091
|
/** The room's latest message from a person or member, for a pending goal nobody wrote a note for. */
|
|
1089
1092
|
async latest_excerpt(room) {
|
|
1090
|
-
const page = await api(this.config, `/messages?
|
|
1093
|
+
const page = await api(this.config, `/messages?before=${room.latest_id ? room.latest_id + 1 : 0}&limit=5`);
|
|
1091
1094
|
const latest = (page.messages || []).filter(message => message.author !== '系统').at(-1);
|
|
1092
1095
|
if (!latest) return ['房间在等你的决定或补充信息,详情见房间。'];
|
|
1093
1096
|
const text = latest.text.length > NOTICE_EXCERPT ? `${latest.text.slice(0, NOTICE_EXCERPT)}…` : latest.text;
|
|
@@ -1095,7 +1098,7 @@ export class FreeRoomRunner {
|
|
|
1095
1098
|
}
|
|
1096
1099
|
/** Ask the decision model whether the idle goal room needs its host, from the latest messages and who is in it. */
|
|
1097
1100
|
async judge_goal(room, goal) {
|
|
1098
|
-
const page = await api(this.config, `/messages?
|
|
1101
|
+
const page = await api(this.config, `/messages?before=${room.latest_id ? room.latest_id + 1 : 0}&limit=${ROUTE_CONTEXT_MESSAGES}`);
|
|
1099
1102
|
const context = page.messages || [];
|
|
1100
1103
|
const everyone = [...(this.inbox?.members || []), ...(this.inbox?.observers || [])];
|
|
1101
1104
|
const described = this.route_members(everyone, room, (context.at(-1)?.id || 0) + 1);
|
|
@@ -1199,9 +1202,9 @@ export class FreeRoomRunner {
|
|
|
1199
1202
|
this.save_suggestion(request, { action: decision.action, actual_action: applied ? decision.action : 'host', applied,
|
|
1200
1203
|
model_judgment: true, ...(record?.id ? { decision_id: record.id } : {}), reason: label });
|
|
1201
1204
|
}
|
|
1202
|
-
/**
|
|
1205
|
+
/** Read the target and its preceding room messages; a no-reply suggestion stays with the host. */
|
|
1203
1206
|
async recommend(request, room, everyone) {
|
|
1204
|
-
const page = await api(this.config, `/messages?
|
|
1207
|
+
const page = await api(this.config, `/messages?before=${request.message_id + 1}&limit=${ROUTE_CONTEXT_MESSAGES + 1}`);
|
|
1205
1208
|
const message = page.messages.find(item => item.id === request.message_id);
|
|
1206
1209
|
if (!message) throw new Error('读取不到这条消息');
|
|
1207
1210
|
const described = this.route_members(everyone, room, message.id);
|
|
@@ -1214,11 +1217,11 @@ export class FreeRoomRunner {
|
|
|
1214
1217
|
this.log(`智能调度 #${message.id}:${decision.action}${decision.member ? ` ${decision.member}` : ''}(选择 ${decision.choice ?? '-'},置信度 ${decision.confidence ?? '-'})`);
|
|
1215
1218
|
if (decision.action === 'host') return this.record_route(request, decision, route_host_label(decision, host.name, members), false);
|
|
1216
1219
|
if (decision.action !== 'member') {
|
|
1217
|
-
//
|
|
1220
|
+
// A group recommendation replaces the host's request in one step; a host that already started keeps the message.
|
|
1218
1221
|
const applied = await api(this.config, `/recommendations/${message.id}`, { action: decision.action, ...(decision.members ? { members: decision.members } : {}) })
|
|
1219
1222
|
.then(() => true, error => { this.log(`智能调度 #${message.id} 未能改派:${error.message}`); return false; });
|
|
1220
1223
|
const names = described.map(member => member.name).join('、');
|
|
1221
|
-
const label = decision.action === 'all' ? room_text('请全体各自回应({names})', { names }) : decision.action === 'sequential' ? room_text('请全体按发言顺序依次回应') :
|
|
1224
|
+
const label = decision.action === 'all' ? room_text('请全体各自回应({names})', { names }) : decision.action === 'sequential' ? room_text('请全体按发言顺序依次回应') : room_text('请 {names} 各自回应', { names: decision.members.join('、') });
|
|
1222
1225
|
return this.record_route(request, decision, applied ? label : `${label}(未生效,仍由主持人处理)`, applied);
|
|
1223
1226
|
}
|
|
1224
1227
|
try {
|
|
@@ -203,6 +203,9 @@ export async function ensure_tunnel(data, tunnel, port, want = true) {
|
|
|
203
203
|
mkdirSync(data, { recursive: true });
|
|
204
204
|
writeFileSync(path, config);
|
|
205
205
|
const metrics = await free_port();
|
|
206
|
+
// Another caller may have started the same tunnel while the metrics port was being allocated.
|
|
207
|
+
const concurrent = read_state(data);
|
|
208
|
+
if (concurrent?.pid && alive(concurrent.pid)) return 'running';
|
|
206
209
|
const log = openSync(join(data, LOG_FILE), 'a');
|
|
207
210
|
// Detached and outside the package folder: it runs on after the panel, and never holds a folder npm replaces.
|
|
208
211
|
const child = spawn(cloudflared, ['tunnel', '--config', path, '--metrics', `127.0.0.1:${metrics}`, 'run', tunnel.name],
|