ai_co_discuss 0.4.94 → 0.4.95
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/backend/external_members.py +9 -0
- package/backend/server.py +1 -1
- package/docs/en/runner.md +7 -6
- package/docs/runner.md +7 -6
- package/frontend/locales/en/admin.json +2 -2
- package/frontend/locales/en/backend_worker.json +1 -1
- package/frontend/locales/en/external.json +17 -6
- package/package.json +1 -1
- package/runner/admin_panel.mjs +37 -6
- package/runner/discussion_launch.mjs +1 -1
- package/runner/external_client.mjs +44 -7
- package/runner/external_gateway.mjs +16 -15
- package/runner/i18n_en.mjs +10 -4
- package/runner/remote_launch.mjs +1 -1
- package/runner/tray.mjs +19 -4
- package/web/admin.css +1 -1
- package/web/admin.js +8 -8
- package/web/i18n.js +2 -2
- package/web/modern.css +1 -1
- package/web/modern.js +54 -48
|
@@ -594,6 +594,13 @@ def report_ai(connection, member, payload):
|
|
|
594
594
|
return {"reported": True}
|
|
595
595
|
|
|
596
596
|
|
|
597
|
+
def lend_until(connection, member, payload):
|
|
598
|
+
"""The member's computer sets how long it lends its AI; only its own end changes, never what it may read (red line 1 exception)."""
|
|
599
|
+
expires_at = checked_expiry(payload.get("expires_at"), int(time.time()))
|
|
600
|
+
connection.execute("UPDATE external_members SET expires_at=?,updated_at=? WHERE member_id=?", (expires_at, int(time.time()), member["id"]))
|
|
601
|
+
return {"expires_at": expires_at}
|
|
602
|
+
|
|
603
|
+
|
|
597
604
|
def leave_room(connection, member):
|
|
598
605
|
"""The external member leaves on its own; its credential stops working at once."""
|
|
599
606
|
end_member(connection, member, "left")
|
|
@@ -641,6 +648,8 @@ def external_api(connection, parts, params, method, token, read_payload, hooks):
|
|
|
641
648
|
return hooks["answer"](connection, room_id, answer_payload(member, payload), member), 201
|
|
642
649
|
if route == ["ai"]:
|
|
643
650
|
return report_ai(connection, member, payload), 200
|
|
651
|
+
if route == ["expiry"]:
|
|
652
|
+
return lend_until(connection, member, payload), 200
|
|
644
653
|
if route == ["leave"]:
|
|
645
654
|
return leave_room(connection, member), 200
|
|
646
655
|
raise LookupError(Text("地址不存在"))
|
package/backend/server.py
CHANGED
|
@@ -83,7 +83,7 @@ DIRECTORY_OPERATIONS = ("move", "folder")
|
|
|
83
83
|
# Local entry commands for external members: the owner's invites (room credential) and this computer's invited records.
|
|
84
84
|
INVITE_COMMANDS = ("room-invite", "room-invites", "room-invite-revoke")
|
|
85
85
|
INVITED_COMMANDS = ("invited-list", "invited-join", "invited-trust", "invited-ai", "invited-pause", "invited-approve", "invited-refuse",
|
|
86
|
-
"invited-leave", "invited-remove", "invited-room")
|
|
86
|
+
"invited-lend", "invited-leave", "invited-remove", "invited-room")
|
|
87
87
|
ADMIN_OPERATIONS = ("rename", "archive", "restore", "delete")
|
|
88
88
|
DIRECTORY_PICKER_TIMEOUT = 600 # the folder dialog waits for the person at the computer
|
|
89
89
|
# Files are streamed to players in pieces of this size.
|
package/docs/en/runner.md
CHANGED
|
@@ -89,22 +89,23 @@ Invite an AI on another computer into your room: it reads only the project files
|
|
|
89
89
|
**Before you start**: both computers install CoDiscuss and run the local service; your computer is [connected to a hosted site](#from-a-hosted-site) with the relay deployed, and the other side reaches your room through that site's encrypted relay. While your computer is off or codiscuss is not running, the other side gets nothing.
|
|
90
90
|
|
|
91
91
|
**Invite (your computer)**:
|
|
92
|
-
1. In the new-room panel or Invite members, click "External expert +" on the External row (once per expert), then on the card's back select what they can see (Room messages / Messages and project)
|
|
92
|
+
1. In the new-room panel or Invite members, click "External expert +" on the External row (once per expert), then on the card's back select what they can see (Room messages / Messages and project). How long the AI is lent is the other side's choice when joining; you do not set it. "Messages and project" opens all of the room's project folders.
|
|
93
93
|
2. Choose Invite (automatic when creating the room). The seat appears immediately in the right-hand roster. When added from the invite dialog, the dialog stays on an "added" step where you can choose Copy invitation link right away. Above the message box, "<name> awaiting check-in: send the invitation link to the invitee" offers Copy invitation link (also in the member menu), or Invitation details for the QR code; share either. The link lasts 10 minutes and binds one member; regenerating it invalidates the previous link. While Invitation details is open, an expired link is replaced with a new one automatically. Without a connected hosted site, the seat shows that it is waiting for a link and explains why; generate it from the seat menu after connecting. Before check-in, the panel shows the automatic expiry deadline and Remove seat. Usage, read logs and access adjustments appear after check-in.
|
|
94
|
-
3. Redemption completes check-in and starts the
|
|
95
|
-
4. `@` it in the room; its answers appear in the conversation as usual. "Read log and access" in the member menu lists every file it read (recorded by your computer) and lets you
|
|
94
|
+
3. Redemption completes check-in and starts the loan time, with **no extra approval step**. Pending seats receive no work and do not participate in group replies or discussions; they end automatically after 7 days. An expired link leaves the seat intact.
|
|
95
|
+
4. `@` it in the room; its answers appear in the conversation as usual. "Read log and access" in the member menu lists every file it read (recorded by your computer) and lets you switch to messages only, or revoke; revoking takes effect immediately. The time left is set by the other side and only shown here. The external expert's card under Members and settings on the Room page shows the same details and actions. Once a member has ended (expired, left or revoked) it stays dimmed below the roster with the reason; Invite back makes a new link that brings the same member back, keeping its name and history in the room. If the other side still keeps its invited-room record, that record and its settings carry on; if it was deleted, a new one starts.
|
|
96
96
|
5. After check-in, its avatar shows the vendor of the other side's AI, and "Read log and access" shows the software and model; both update when the other side switches AI. The other computer reports this itself, so treat it as identification only. A custom endpoint shows the external expert icon.
|
|
97
97
|
|
|
98
98
|
**Join (the other computer)**:
|
|
99
|
-
1. Open the link and choose "Join with CoDiscuss on this computer" to go to the local page; or choose "+" under "External rooms" in the left panel and paste the link, scan the QR code with the camera, choose a QR code image, or paste a screenshot of it; or run `codiscuss join <link> --adapter TOOL`.
|
|
100
|
-
2. Pick the AI and set it up on its expert card: a new conversation or one this software already holds (joining with its context; manual start is unavailable), model and effort, its own prompt, and the
|
|
99
|
+
1. Open the link and choose "Join with CoDiscuss on this computer" to go to the local page; or choose "+" under "External rooms" in the left panel and paste the link, scan the QR code with the camera, choose a QR code image, or paste a screenshot of it; or run `codiscuss join <link> --adapter TOOL [--duration 1h|today|3d]`, and later change the loan time with `codiscuss invited lend ID 1h|today|3d`.
|
|
100
|
+
2. Pick the AI and set it up on its expert card: a new conversation or one this software already holds (joining with its context; manual start is unavailable), model and effort, its own prompt, and the three settings below (Room only · Answer at once · 1 hour by default, with no further confirmation after joining):
|
|
101
101
|
|
|
102
102
|
| Setting | Options |
|
|
103
103
|
| --- | --- |
|
|
104
104
|
| When named | Answer at once: no wake count or time limit · Ask me: woken only after you approve in the right panel each time; declining, or 15 minutes without an answer, shows "Not accepted by the other side" |
|
|
105
105
|
| Local access | Room only: limited to CoDiscuss commands, running in an empty temporary folder · Unrestricted: can read local files and use the network |
|
|
106
|
+
| Lent for | 1 hour · Today · 3 days (3 days at most). The membership ends when it runs out; renew before then to continue |
|
|
106
107
|
|
|
107
|
-
The external room page shows the other room's chat like a room's messages, read only (scroll up for earlier messages); the requests to your AI carry how they went on this computer. The other room's private chats, runs, settings and files are not available there.
|
|
108
|
+
The external room page shows the other room's chat like a room's messages, read only (scroll up for earlier messages); the requests to your AI carry how they went on this computer. The other room's private chats, runs, settings and files are not available there. All three settings are kept per room; you can change them later in the external room's right panel (a new loan time counts from the change, so it can renew or shorten), or pause or leave. Once the room has ended, you can delete its record from this computer. `codiscuss invited` offers the same commands, and a paired phone or tablet can set every option. The local service does the waking, so keep codiscuss running. When the AI ends without submitting an answer, the external room page shows the end of its run output on this computer under the failure reason (kept here only, never sent to the other side); `codiscuss external room ID --json` shows it too.
|
|
108
109
|
|
|
109
110
|
**Supported tools**: Room only needs a tool that can be limited to CoDiscuss commands. Claude Code (background runs) supports it, tested on version 2.1.325 (other versions not individually checked), so does the Antigravity CLI, tested on version 1.5.12 (its web search cannot be turned off; anything else you always allowed in agy is denied in these tasks, while your own use of agy is unchanged), and so do model APIs, backed by unit tests; Codex and the Antigravity desktop app do not support it and can only run Unrestricted; desktop apps cannot join as external members.
|
|
110
111
|
|
package/docs/runner.md
CHANGED
|
@@ -120,22 +120,23 @@ codiscuss local connect https://你的站点
|
|
|
120
120
|
**前提**:两台电脑都安装共议并运行本机服务;你的电脑已[连接线上网站](#线上网页连接本机)并部署了中转,对方经这个网站的加密中转访问你的房间。你的电脑关机或 codiscuss 未运行时,对方什么也拿不到。
|
|
121
121
|
|
|
122
122
|
**邀请(你的电脑)**:
|
|
123
|
-
1. 建房面板或右栏“邀请成员”里点“外部”一行的“外部专家 +”(可加多位),翻到卡片背面设置“对方能看到”(房间消息 /
|
|
123
|
+
1. 建房面板或右栏“邀请成员”里点“外部”一行的“外部专家 +”(可加多位),翻到卡片背面设置“对方能看到”(房间消息 / 消息和项目)。借出多久由对方加入时决定,你不用设。选“消息和项目”时开放本房间的全部项目目录。
|
|
124
124
|
2. 点“邀请”(建房时自动添加),右栏名单立即显示待签到成员。从邀请弹窗添加时,弹窗会停在“已加入”一步,可直接点“复制邀请链接”。输入框上方会出现“成员名 待签到:把邀请链接发给对方”,点“复制邀请链接”直接复制(成员菜单里也有这一项),或点“邀请详情”查看二维码,发给对方。链接 10 分钟有效,只能绑定一位成员;重新生成会立即作废旧链接。“邀请详情”开着时,链接到期会自动换成新的。未绑定线上站点时显示“待生成链接”及原因,绑定站点后从席位菜单生成。待签到面板显示自动结束期限,可“移除席位”;签到后才显示用量、读取记录和授权调整。
|
|
125
|
-
3.
|
|
126
|
-
4. 在房间里 `@`
|
|
125
|
+
3. 对方兑换即完成签到,借出时间从兑换时开始,**没有额外批准步骤**。未签到不收任务、不参与全体回应或讨论,7 天后自动结束;链接过期不会删除席位。
|
|
126
|
+
4. 在房间里 `@` 它,回答照常出现在对话中。成员菜单的“读取记录与权限”列出它读过的每个文件(由你的电脑记录),可改为只看消息或撤销授权,撤销立即生效;剩余时间由对方设定,你这边只能看。房间页“成员与设置”里的外部专家卡片显示同样的信息与操作。成员结束后(到期、对方退出或撤销)仍灰显在名单下方并写明原因,点“重新邀请”可生成新链接把原成员请回:名字和房间里的历史不变;对方若还保留那条被邀请记录,记录与设置也接着用,删了则新建。
|
|
127
127
|
5. 签到后头像显示对方 AI 的厂家,“读取记录与权限”里可看到软件和模型;对方换 AI 后自动更新。这些信息由对方电脑自报,仅供辨认。自定义接口显示外部专家图标。
|
|
128
128
|
|
|
129
129
|
**加入(对方电脑)**:
|
|
130
|
-
1. 打开链接,点“用本机共议加入”跳到本机网页;或在左栏“外部房间”点“+”粘贴链接,也可以用相机扫码、选择二维码图片或粘贴二维码截图;命令行为 `codiscuss join <链接> --adapter
|
|
131
|
-
2. 选派哪个 AI
|
|
130
|
+
1. 打开链接,点“用本机共议加入”跳到本机网页;或在左栏“外部房间”点“+”粘贴链接,也可以用相机扫码、选择二维码图片或粘贴二维码截图;命令行为 `codiscuss join <链接> --adapter 软件 [--duration 1h|today|3d]`,之后用 `codiscuss invited lend ID 1h|today|3d` 改借出时间。
|
|
131
|
+
2. 选派哪个 AI,在它的专家卡片上设置:新会话或续接这个软件已有的会话(带着原上下文加入;手动启动不可用)、模型与强度、专属提示词,以及下面三项(默认“只在房间里发言 · 直接回答 · 1 小时”,加入后无需再确认):
|
|
132
132
|
|
|
133
133
|
| 设置 | 选项 |
|
|
134
134
|
| --- | --- |
|
|
135
135
|
| 被点名时 | 直接回答:不设次数与期限上限 · 先问我:每次在右栏同意才唤醒,拒绝或 15 分钟未处理,对方看到“对方未同意” |
|
|
136
136
|
| 本机权限 | 只在房间里发言:只能用共议命令,在空的临时目录运行 · 不受限:可读本机文件、联网 |
|
|
137
|
+
| 借出时间 | 1 小时 · 今天 · 3 天(最长 3 天)。到期后成员资格结束,要继续须在到期前续期 |
|
|
137
138
|
|
|
138
|
-
外部房间的页面像房间消息页一样显示对方房间的聊天记录(只读,往上滚动可看更早的消息),点名你 AI
|
|
139
|
+
外部房间的页面像房间消息页一样显示对方房间的聊天记录(只读,往上滚动可看更早的消息),点名你 AI 的请求标有在这台电脑上的处理结果;对方房间的私聊、执行、房间设置与文件都不开放。三项设置都按房间分别保存,之后可在外部房间的右栏调整(借出时间从调整时起重新计算,可续期也可改短),也可暂停或退出,房间结束后可删除这台电脑上的记录;`codiscuss invited` 有同样的命令,已配对的手机或平板也能设置全部选项。唤醒由本机服务完成,请保持 codiscuss 运行。AI 没提交回答就结束时,外部房间的页面会在失败原因下列出这台电脑上运行输出的末尾(只存在本机,不发给对方),`codiscuss invited room ID --json` 也能看到。
|
|
139
140
|
|
|
140
141
|
**支持的软件**:“只在房间里发言”要求软件能限制为只用共议命令,目前支持 Claude Code(后台运行,已在 2.1.325 版实测,其他版本未逐一验证)、Antigravity CLI(已在 1.5.12 版实测;它的网页搜索无法禁止;你在 agy 里“始终允许”过的其他操作,在受限任务里会被禁止,平时使用不受影响)与模型 API(以单元测试为据);Codex 与 Antigravity 桌面版不支持,只能选“不受限”;桌面 App 不能作为外部成员加入。
|
|
141
142
|
|
|
@@ -371,12 +371,12 @@
|
|
|
371
371
|
"已开启": "On",
|
|
372
372
|
"你自己使用这台电脑的入口。": "Your own ways into this computer.",
|
|
373
373
|
"{value1} 有新版本": "New version of {value1}",
|
|
374
|
-
"
|
|
374
|
+
"托管账号从这份副本运行。管理面板启动和更新共议时会自动同步;没有同步上时在这里同步。": "Hosted accounts run from this copy. It syncs automatically when the admin panel starts and when CoDiscuss updates; sync here if that did not work.",
|
|
375
375
|
"登录入口未运行,使用者暂时无法登录": "The sign-in entry is not running, so users cannot sign in for now",
|
|
376
376
|
"扫码配对过的设备可以在外面使用这台电脑": "Devices paired by QR code can use this computer from elsewhere",
|
|
377
377
|
"需先在“本机 → 线上网站”绑定": "Bind under This computer → Online site first",
|
|
378
378
|
"经线上网站中转": "Through the online site",
|
|
379
|
-
"
|
|
379
|
+
"不需要域名:经共议线上网站中转到这台电脑,手机和外地的电脑都能打开。需要先把这台电脑绑定到线上网站。": "No domain needed: relayed through the CoDiscuss online site to this computer, so phones and computers elsewhere can open it. Bind this computer to the online site first.",
|
|
380
380
|
"已开启经线上网站中转": "Relay through the online site turned on",
|
|
381
381
|
"已关闭经线上网站中转": "Relay through the online site turned off",
|
|
382
382
|
"其他设备远程使用、邀请外部专家、托管账号经线上网站登录都需要": "Needed for using this computer from other devices, inviting external experts, and hosted accounts signing in through the online site",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"这个账号开启了入口保护,但入口读不到它的密钥": "This account has entry protection enabled, but the entry cannot read its key",
|
|
38
38
|
"实例没有按入口保护启动起来(启动失败,或密钥对不上)": "Instance did not start with entry protection (startup failed or the key does not match)",
|
|
39
39
|
"实例没有启动起来": "Instance did not start",
|
|
40
|
-
"还没有安装隔离账号的程序副本,请先在“概览 →
|
|
40
|
+
"还没有安装隔离账号的程序副本,请先在“概览 → 本机 → 程序副本”中安装": "Program copies for isolated accounts are not installed yet. Install them under Overview → This computer → Program copy first.",
|
|
41
41
|
"技能库里没有 {value1}": "Skill library does not contain {value1}",
|
|
42
42
|
"未知操作:{value1}": "Unknown action: {value1}",
|
|
43
43
|
"未知程序:{value1}": "Unknown app: {value1}",
|
|
@@ -37,8 +37,6 @@
|
|
|
37
37
|
"等退出通知送达后可删除": "Can be deleted once the leave notice arrives",
|
|
38
38
|
"1 小时": "1 hour",
|
|
39
39
|
"今天": "Today",
|
|
40
|
-
"30 天": "30 days",
|
|
41
|
-
"7 天": "7 days",
|
|
42
40
|
"已到期": "Expired",
|
|
43
41
|
"剩余 {count} 天": "{count} d left",
|
|
44
42
|
"剩余 {count} 小时": "{count} h left",
|
|
@@ -61,7 +59,6 @@
|
|
|
61
59
|
"阿里云百炼": "Alibaba Cloud Model Studio",
|
|
62
60
|
"开放目录": "Open directories",
|
|
63
61
|
"只读:已跟踪与未忽略的文件,固定排除 .env、密钥、凭据、data/ 与 .git。": "Read-only: tracked and non-ignored files; .env, keys, credentials, data/ and .git are always excluded.",
|
|
64
|
-
"有效期": "Valid for",
|
|
65
62
|
"项目内容会发给对方模型服务商": "Project content goes to their model provider",
|
|
66
63
|
"消息会发给对方模型服务商": "Messages go to their model provider",
|
|
67
64
|
"生成邀请需要本机服务,请在这台电脑打开本机网站。": "Creating an invitation needs the local service; open the local website on this computer.",
|
|
@@ -71,8 +68,6 @@
|
|
|
71
68
|
"已经读出去的内容收不回,会留在对方 AI 的会话里。": "What was already read cannot be taken back; it stays in the other AI's session.",
|
|
72
69
|
"外部成员 · {name}": "External member · {name}",
|
|
73
70
|
"调整": "Adjust",
|
|
74
|
-
"延长": "Extend",
|
|
75
|
-
"已延长": "Extended",
|
|
76
71
|
"已降为只讨论,之后不能再读项目文件": "Downgraded to discussion only; it can no longer read project files",
|
|
77
72
|
"读取记录": "Read log",
|
|
78
73
|
"还没有读取记录": "No reads yet",
|
|
@@ -221,5 +216,21 @@
|
|
|
221
216
|
"启动新成员": "Start new members",
|
|
222
217
|
"已复制邀请链接": "Invitation link copied",
|
|
223
218
|
"{value1} 待签到:把邀请链接发给对方": "{value1} awaiting check-in: send the invitation link to the invitee",
|
|
224
|
-
"选择一个 AI 派去对方房间,点卡片翻面可设置软件、模型和本机权限。": "Pick an AI to send to the other room; flip its card to set software, model and local access."
|
|
219
|
+
"选择一个 AI 派去对方房间,点卡片翻面可设置软件、模型和本机权限。": "Pick an AI to send to the other room; flip its card to set software, model and local access.",
|
|
220
|
+
"3 天": "3 days",
|
|
221
|
+
"借出时间": "Lent for",
|
|
222
|
+
"借出多久由你决定,最长 3 天;加入后可在外部房间里续期或改短。": "You decide how long to lend it, up to 3 days; after joining you can renew or shorten it in the external room.",
|
|
223
|
+
"借出时间已更新": "Loan time updated",
|
|
224
|
+
"由对方决定": "Set by the invitee",
|
|
225
|
+
"借出多久由对方加入时决定,你可随时撤销。": "The invitee decides how long to lend its AI when joining; you can revoke at any time.",
|
|
226
|
+
"对方设定": "set by the invitee",
|
|
227
|
+
"借出到": "Lent until",
|
|
228
|
+
"对方未说明": "Not stated",
|
|
229
|
+
"{name} 能看到的内容": "What {name} can see",
|
|
230
|
+
"可改为只看消息;再开放项目须重新邀请": "Can be narrowed to messages only; opening the project again needs a new invitation",
|
|
231
|
+
"再开放项目须重新邀请": "Opening the project again needs a new invitation",
|
|
232
|
+
"借出多久由对方决定,你可随时撤销": "The invitee decides how long it is lent; you can revoke at any time",
|
|
233
|
+
"由对方加入时决定": "Set by the invitee when joining",
|
|
234
|
+
"不变": "Unchanged",
|
|
235
|
+
"从现在起重新计算,最长 3 天": "Counted again from now, 3 days at most"
|
|
225
236
|
}
|
package/package.json
CHANGED
package/runner/admin_panel.mjs
CHANGED
|
@@ -256,6 +256,27 @@ async function finish_update(data) {
|
|
|
256
256
|
write_update_job(data, { ...job, status: 'done', ok: installed, steps });
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Bring an installed program copy up to date when the panel starts: a version installed some other way than the panel's
|
|
261
|
+
* update (npm, setup) or an AI program that upgraded itself leaves it behind (user 2026-11-19). Same order as an update:
|
|
262
|
+
* the isolated instances running from the copy stop first, or files in use stay old, then start again. What fails stays
|
|
263
|
+
* on the overview's program copy row for the owner.
|
|
264
|
+
*/
|
|
265
|
+
async function sync_stale_copy(data) {
|
|
266
|
+
if (!hosting_enabled(data)) return;
|
|
267
|
+
const copy = shared_cli_state();
|
|
268
|
+
if (!copy.app || (copy.app_version === VERSION && !copy.outdated.length)) return;
|
|
269
|
+
const running = (await list_accounts(data)).filter(account => account.os_user && account.running);
|
|
270
|
+
for (const account of running) await run_instance(data, account.name, 'stop');
|
|
271
|
+
try {
|
|
272
|
+
const result = install_runtime(data);
|
|
273
|
+
if (result.warnings.length) throw new Error(result.warnings.join(';'));
|
|
274
|
+
for (const name of Object.keys(read_os_users(data))) if (read_accounts(data)[name]) await prepare_account(data, name);
|
|
275
|
+
} finally {
|
|
276
|
+
for (const account of running) await start_verified(data, account.name);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
259
280
|
// ---- Accounts ----
|
|
260
281
|
|
|
261
282
|
/**
|
|
@@ -402,7 +423,7 @@ function install_runtime(data) {
|
|
|
402
423
|
*/
|
|
403
424
|
function account_env(data, name, action, request = {}, folders = {}) {
|
|
404
425
|
const { env_script } = shared_paths();
|
|
405
|
-
if (!existsSync(env_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 →
|
|
426
|
+
if (!existsSync(env_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 → 本机 → 程序副本”中安装');
|
|
406
427
|
const text = run_as_user(data, name, `& ${ps_quote(process.execPath)} ${ps_quote(env_script)} ${action} $Job`,
|
|
407
428
|
{ files: { 'request.json': JSON.stringify(request) }, folders, timeout: 120_000 });
|
|
408
429
|
const line = text.split(/\r?\n/).reverse().find(item => item.trim().startsWith('{'));
|
|
@@ -560,7 +581,7 @@ function run_instance(data, name, command) {
|
|
|
560
581
|
}
|
|
561
582
|
if (command === 'start' && read_os_users(data)[name]) {
|
|
562
583
|
const { local_script } = shared_paths();
|
|
563
|
-
if (!existsSync(local_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 →
|
|
584
|
+
if (!existsSync(local_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 → 本机 → 程序副本”中安装');
|
|
564
585
|
// Whatever was set up first, the instance starts on the shared copies its Windows user can run.
|
|
565
586
|
use_shared_programs(data, name);
|
|
566
587
|
return start_instance_as_user(data, name, service, local_script, process.execPath, { key_file });
|
|
@@ -1479,11 +1500,15 @@ function run_panel(data, port) {
|
|
|
1479
1500
|
process.stdout.write(t(`管理面板已启动:http://127.0.0.1:{value1}
|
|
1480
1501
|
`, { value1: port }));
|
|
1481
1502
|
finish_update(data).catch(error => process.stderr.write(t(`更新收尾失败:{value1}
|
|
1482
|
-
`, { value1: error.message })))
|
|
1503
|
+
`, { value1: error.message })))
|
|
1504
|
+
// After an update's own finish, which already synced the copy it installed.
|
|
1505
|
+
.then(() => sync_stale_copy(data)).catch(error => process.stderr.write(t('程序副本没有自动同步:{value1}\n', { value1: error.message })));
|
|
1483
1506
|
});
|
|
1484
1507
|
// The icon that ships with the package, the same on every computer.
|
|
1485
1508
|
const icon = join(ROOT, 'web', 'codiscuss.ico');
|
|
1486
|
-
|
|
1509
|
+
// A tray that fails to start must not leave `tray` uninitialised: shutdown (and so every update) reads it.
|
|
1510
|
+
let tray = null;
|
|
1511
|
+
try { tray = show_tray({ title: t('共议'), icon_path: existsSync(icon) ? icon : '', window_title: WINDOW_TITLE,
|
|
1487
1512
|
host: join(data, 'launcher', '共议.exe'), on_action: action => {
|
|
1488
1513
|
if (action === 'open') open_panel_window(data, panel_url(state), false);
|
|
1489
1514
|
if (action === 'site') open_browser(signed_site_url(site_url(data), data));
|
|
@@ -1500,7 +1525,10 @@ function run_panel(data, port) {
|
|
|
1500
1525
|
// The note goes with the icon, so it stays a moment before the icon closes.
|
|
1501
1526
|
.finally(() => setTimeout(shutdown, 2500));
|
|
1502
1527
|
}
|
|
1503
|
-
} });
|
|
1528
|
+
} }); } catch (error) {
|
|
1529
|
+
process.stderr.write(t(`任务栏图标没有启动:{value1}
|
|
1530
|
+
`, { value1: error.message }));
|
|
1531
|
+
}
|
|
1504
1532
|
function shutdown(exit = true) {
|
|
1505
1533
|
clearInterval(relay);
|
|
1506
1534
|
clearInterval(finisher);
|
|
@@ -1526,9 +1554,12 @@ async function start_panel(data, port) {
|
|
|
1526
1554
|
rmSync(state_path(data), { force: true });
|
|
1527
1555
|
await new Promise(done => setTimeout(done, 800));
|
|
1528
1556
|
}
|
|
1557
|
+
// The failure message below points here, so the panel's output (its startup errors among it) has to land in this file.
|
|
1529
1558
|
const log = join(data, 'admin-panel.log');
|
|
1559
|
+
const output = openSync(log, 'w');
|
|
1530
1560
|
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'run', '--port', String(port)],
|
|
1531
|
-
{ detached: true, stdio: ['ignore',
|
|
1561
|
+
{ detached: true, stdio: ['ignore', output, output], windowsHide: true, env: { ...process.env, CODISCUSS_GATEWAY_HOME: data } });
|
|
1562
|
+
closeSync(output);
|
|
1532
1563
|
child.unref();
|
|
1533
1564
|
for (let waited = 0; waited < 10_000; waited += 200) {
|
|
1534
1565
|
await new Promise(done => setTimeout(done, 200));
|
|
@@ -134,7 +134,7 @@ pick-directory 在本机弹出系统目录选择窗口,返回所选路径;
|
|
|
134
134
|
browse-directory 列出常用项目及其中的子文件夹(只含文件夹名,分页),供其他设备选择目录;path 为空时列出常用项目。
|
|
135
135
|
device-pairing 在本机生成 12 位设备配对码(2 分钟有效,可选 temporary 临时设备、without_passkey 允许这次配对不用通行密钥、site 指定已绑定的网站),扫码链接带本机密钥指纹;只能在这台电脑上执行,新设备只能在电脑前添加。
|
|
136
136
|
devices 列出已配对设备;提供 revoke(设备 id)撤销设备。
|
|
137
|
-
${t("room-invite 创建待签到席位并签发邀请;提供 member_id 时重发该席位链接,旧链接失效。须提供 room_id、token,可选 level(discuss/read)、folders、
|
|
137
|
+
${t("room-invite 创建待签到席位并签发邀请;提供 member_id 时重发该席位链接,旧链接失效。须提供 room_id、token,可选 level(discuss/read)、folders、site_url(借出时间由被邀请方加入时决定);程序先读名单 revision 再建席位。链接有效 10 分钟,未签到席位 7 天结束;未绑定线上站点时只建立席位。")}
|
|
138
138
|
room-invites 列出房间未兑换的邀请(不含配对码);须提供 room_id、token。
|
|
139
139
|
room-invite-revoke 撤销一条未兑换的邀请;须提供 room_id、token、invite_id。
|
|
140
140
|
projects 读取本机已配置的项目(名称与绝对路径);提供 JSON(projects 列表)时整体替换保存。
|
|
@@ -22,6 +22,10 @@ import { t } from './i18n.mjs';
|
|
|
22
22
|
export const WAKES = ['auto', 'ask'];
|
|
23
23
|
// The single level records had before `wake` and `confined`, still accepted by `invited-trust` as a shorthand.
|
|
24
24
|
const LEGACY_TRUST = { default: { wake: 'ask', confined: true }, borrow: { wake: 'auto', confined: true }, trusted: { wake: 'auto', confined: false } };
|
|
25
|
+
// How long this computer lends its AI to a room: chosen here when joining and changed here later, at most three days.
|
|
26
|
+
export const LEND_DURATIONS = ['1h', 'today', '3d'];
|
|
27
|
+
const HOUR_MS = 3600000;
|
|
28
|
+
const LEND_MAX_MS = 3 * 24 * HOUR_MS;
|
|
25
29
|
export const APPROVAL_TIMEOUT_MS = 15 * 60000;
|
|
26
30
|
export const POLL_MS = 5000;
|
|
27
31
|
// The inviting room fails an execution whose lease lapses; renew it as the room runner does.
|
|
@@ -71,6 +75,7 @@ export const MEMBER_API = {
|
|
|
71
75
|
answer: room => `${EXTERNAL_PREFIX(room)}/answer`,
|
|
72
76
|
messages: room => `${EXTERNAL_PREFIX(room)}/messages`,
|
|
73
77
|
ai: room => `${EXTERNAL_PREFIX(room)}/ai`,
|
|
78
|
+
expiry: room => `${EXTERNAL_PREFIX(room)}/expiry`,
|
|
74
79
|
};
|
|
75
80
|
|
|
76
81
|
// ---- Secrets: sealed with DPAPI for the signed-in Windows user, 0600 elsewhere (as machine-links.json). ----
|
|
@@ -439,10 +444,38 @@ function ai_identity(home, ai) {
|
|
|
439
444
|
return { adapter: ai.adapter, platform: Object.hasOwn(API_PROVIDERS, platform) ? platform : 'Custom', model: String(ai.model || api?.model || '').slice(0, MODEL_LIMIT) };
|
|
440
445
|
}
|
|
441
446
|
|
|
447
|
+
/**
|
|
448
|
+
* When a loan chosen now ends, in epoch seconds: an hour, the end of today here (at least an hour away) or three days.
|
|
449
|
+
* The inviting room keeps the end it is given; the three-day ceiling is this computer's own rule.
|
|
450
|
+
*/
|
|
451
|
+
export function lend_until(duration, now = Date.now()) {
|
|
452
|
+
if (!LEND_DURATIONS.includes(duration)) throw failure('invalid_duration', '借出时间只能是 1h、today 或 3d');
|
|
453
|
+
if (duration === '3d') return Math.floor((now + LEND_MAX_MS) / 1000);
|
|
454
|
+
if (duration === 'today') {
|
|
455
|
+
const end = new Date(now);
|
|
456
|
+
end.setHours(23, 59, 59, 0);
|
|
457
|
+
return Math.floor(Math.min(Math.max(end.getTime(), now + HOUR_MS), now + LEND_MAX_MS) / 1000);
|
|
458
|
+
}
|
|
459
|
+
return Math.floor((now + HOUR_MS) / 1000);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Change how long this record's AI stays lent; the inviting room confirms the new end, which the record then keeps. */
|
|
463
|
+
export async function lend(home, { id, duration }, deps = {}) {
|
|
464
|
+
const expires_at = lend_until(duration, deps.now?.() ?? Date.now());
|
|
465
|
+
const record = find_record(read_store(home), id);
|
|
466
|
+
if (record.status !== 'active') throw failure('record_ended', '这条被邀请记录已结束,不能再改借出时间');
|
|
467
|
+
const answer = await member_api(home, id, 'POST', MEMBER_API.expiry(record.room), { expires_at }, deps);
|
|
468
|
+
return change_record(home, id, (current, now, store) => {
|
|
469
|
+
current.expires_at = Number(answer?.expires_at || expires_at) * 1000;
|
|
470
|
+
return { record: record_view(current, store) };
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
442
474
|
/** Accept an invitation: check the computer's fingerprint when the link carries one, redeem with a new key, keep the record. */
|
|
443
475
|
export async function join_invite(home, input, deps = {}) {
|
|
444
476
|
const invite = parse_invite(input.invite, input);
|
|
445
477
|
const ai = check_ai(input);
|
|
478
|
+
const expires_at = lend_until(input.duration || '1h', deps.now?.() ?? Date.now());
|
|
446
479
|
// A conversation this computer's software already holds, picked to carry its context into the room.
|
|
447
480
|
const session_id = String(input.session_id || '');
|
|
448
481
|
const keys = await machine_keys(invite.site, invite.machine, deps);
|
|
@@ -462,7 +495,7 @@ export async function join_invite(home, input, deps = {}) {
|
|
|
462
495
|
if (existing.records[attempt.id] && read_secrets(home)[attempt.id]?.token) return { record: record_view(existing.records[attempt.id], existing) };
|
|
463
496
|
const pair = attempt.pair, key_id = key_id_of(pair.public_key), identity = ai_identity(home, ai);
|
|
464
497
|
const answer = await relay_send({ site: invite.site, machine: keys.id, machine_key: keys.public_key }, { key_id, private_key: pair.private_key }, 'external-redeem',
|
|
465
|
-
{ public_key: pair.public_key, proof: invite_proof(invite.code, keys.id, pair.public_key), label: String(input.label || hostname()).slice(0, 80), ...identity }, deps);
|
|
498
|
+
{ public_key: pair.public_key, proof: invite_proof(invite.code, keys.id, pair.public_key), label: String(input.label || hostname()).slice(0, 80), expires_at, ...identity }, deps);
|
|
466
499
|
if (answer.status >= 400) throw remote_failure(answer.body, 'invite_invalid', '邀请无效或已过期');
|
|
467
500
|
const joined = answer.body || {};
|
|
468
501
|
if (!ROOM_ID.test(joined.room?.id || '') || typeof joined.member?.name !== 'string' || typeof joined.token !== 'string') {
|
|
@@ -713,6 +746,7 @@ export async function invited_command(home, action, input = {}, deps = {}) {
|
|
|
713
746
|
if (action === 'invited-pause') return change_record(home, id, (record, now, store) => { record.paused = input.paused !== false; return { record: record_view(record, store) }; });
|
|
714
747
|
if (action === 'invited-approve') return approve(home, input);
|
|
715
748
|
if (action === 'invited-refuse') return refuse_approval(home, input, deps);
|
|
749
|
+
if (action === 'invited-lend') return lend(home, input, deps);
|
|
716
750
|
if (action === 'invited-leave') return leave(home, input, deps);
|
|
717
751
|
if (action === 'invited-remove') return remove_record(home, input, deps);
|
|
718
752
|
if (action === 'invited-room') return room_view(home, input, deps);
|
|
@@ -720,7 +754,7 @@ export async function invited_command(home, action, input = {}, deps = {}) {
|
|
|
720
754
|
}
|
|
721
755
|
|
|
722
756
|
export const INVITED_ACTIONS = new Set(['invited-list', 'invited-join', 'invited-trust', 'invited-ai', 'invited-pause', 'invited-approve',
|
|
723
|
-
'invited-refuse', 'invited-leave', 'invited-remove', 'invited-room']);
|
|
757
|
+
'invited-refuse', 'invited-lend', 'invited-leave', 'invited-remove', 'invited-room']);
|
|
724
758
|
|
|
725
759
|
// ---- Pulling and waking (in the service) ----
|
|
726
760
|
|
|
@@ -1119,6 +1153,7 @@ function print_record(record) {
|
|
|
1119
1153
|
const contact = { online: t('在线'), offline: t('不在线'), error: t('出错'), unknown: t('未知') }[record.contact?.state || 'unknown'];
|
|
1120
1154
|
const lines = [t('{id} {room}({site})成员 {member}', { id: record.id, room: record.room_title || record.room, site: record.site, member: record.member }),
|
|
1121
1155
|
t(' 被点名时:{wake};在这台电脑上:{scope};已唤醒 {wakes} 次;对方电脑:{contact}{paused}', { wake, scope, wakes: record.wakes, contact, paused: record.paused ? t(';已暂停') : '' })];
|
|
1156
|
+
if (record.status === 'active' && record.expires_at) lines.push(t(' 借出到 {time}', { time: new Date(record.expires_at).toLocaleString() }));
|
|
1122
1157
|
for (const item of record.approvals) lines.push(t(' 待确认 {approval}:消息 {messages}', { approval: item.id, messages: item.message_ids.map(n => `#${n}`).join(', ') }));
|
|
1123
1158
|
if (record.status === 'left') lines.push(t(' 已退出'));
|
|
1124
1159
|
if (record.status === 'ended') lines.push(t(' 对方已结束你的成员资格({reason})', { reason: record.end_reason }));
|
|
@@ -1128,11 +1163,12 @@ function print_record(record) {
|
|
|
1128
1163
|
const HELP = () => t(`外部房间(本机 AI 作为外部成员参加另一台电脑上的房间)
|
|
1129
1164
|
|
|
1130
1165
|
用法:
|
|
1131
|
-
codiscuss join <链接|配对码> [--site 站点] [--machine 电脑编号] --adapter 软件 [--model M] [--effort E] [--session 会话] [--prompt 提示词]
|
|
1166
|
+
codiscuss join <链接|配对码> [--site 站点] [--machine 电脑编号] --adapter 软件 [--model M] [--effort E] [--session 会话] [--prompt 提示词] [--duration 1h|today|3d]
|
|
1132
1167
|
codiscuss invited list
|
|
1133
1168
|
codiscuss invited trust ID auto|ask [--unconfined|--confined]
|
|
1134
1169
|
codiscuss invited ai ID [--adapter 软件] [--model M] [--effort E] [--prompt 提示词]
|
|
1135
1170
|
codiscuss invited pause ID | resume ID
|
|
1171
|
+
codiscuss invited lend ID 1h|today|3d
|
|
1136
1172
|
codiscuss invited approve ID 待确认编号 | refuse ID 待确认编号
|
|
1137
1173
|
codiscuss invited leave ID
|
|
1138
1174
|
codiscuss invited remove ID
|
|
@@ -1140,6 +1176,7 @@ const HELP = () => t(`外部房间(本机 AI 作为外部成员参加另一台
|
|
|
1140
1176
|
|
|
1141
1177
|
被点名时:auto 直接回答;ask 每次先问你。
|
|
1142
1178
|
本机权限:默认只在房间里发言(只能运行共议命令);--unconfined 不受限,可读本机文件、联网。
|
|
1179
|
+
借出时间:加入时用 --duration 选择(默认 1h),之后用 lend 从现在起重新计算,最长 3 天。
|
|
1143
1180
|
--session 续接这个软件已有的会话(带着原上下文加入);--prompt 只发给它的专属提示词,空字符串表示不用软件预设。
|
|
1144
1181
|
同意后由本机服务唤醒 AI,请保持 codiscuss 服务运行。加 --json 输出 JSON。
|
|
1145
1182
|
`);
|
|
@@ -1159,7 +1196,7 @@ export async function external_main(command, args, { home, deps = {}, write = te
|
|
|
1159
1196
|
const service = home || (await import('./discussion_service.mjs')).service_home();
|
|
1160
1197
|
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: {
|
|
1161
1198
|
site: { type: 'string' }, machine: { type: 'string' }, adapter: { type: 'string' }, model: { type: 'string' }, effort: { type: 'string' },
|
|
1162
|
-
session: { type: 'string' }, prompt: { type: 'string' },
|
|
1199
|
+
session: { type: 'string' }, prompt: { type: 'string' }, duration: { type: 'string' },
|
|
1163
1200
|
label: { type: 'string' }, json: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },
|
|
1164
1201
|
unconfined: { type: 'boolean' }, confined: { type: 'boolean' },
|
|
1165
1202
|
'access-file': { type: 'string' }, root: { type: 'string' }, offset: { type: 'string' }, limit: { type: 'string' }, 'max-bytes': { type: 'string' },
|
|
@@ -1180,17 +1217,17 @@ export async function external_main(command, args, { home, deps = {}, write = te
|
|
|
1180
1217
|
const ai = { ...(values.adapter ? { adapter: values.adapter } : {}), ...(values.model !== undefined ? { model: values.model } : {}), ...(values.effort !== undefined ? { effort: values.effort } : {}),
|
|
1181
1218
|
...(values.prompt !== undefined ? { system_prompt: values.prompt } : {}) };
|
|
1182
1219
|
let result;
|
|
1183
|
-
if (command === 'join') result = await join_invite(service, { invite: positionals[0], site: values.site, machine: values.machine, label: values.label, ...(values.session ? { session_id: values.session } : {}), ...ai }, deps);
|
|
1220
|
+
if (command === 'join') result = await join_invite(service, { invite: positionals[0], site: values.site, machine: values.machine, label: values.label, ...(values.session ? { session_id: values.session } : {}), ...(values.duration ? { duration: values.duration } : {}), ...ai }, deps);
|
|
1184
1221
|
else {
|
|
1185
1222
|
const [verb, id, extra] = positionals;
|
|
1186
1223
|
const action = { list: 'invited-list', trust: 'invited-trust', ai: 'invited-ai', pause: 'invited-pause', resume: 'invited-pause', approve: 'invited-approve',
|
|
1187
|
-
refuse: 'invited-refuse', leave: 'invited-leave', remove: 'invited-remove', room: 'invited-room' }[verb];
|
|
1224
|
+
refuse: 'invited-refuse', lend: 'invited-lend', leave: 'invited-leave', remove: 'invited-remove', room: 'invited-room' }[verb];
|
|
1188
1225
|
if (!action) return write(HELP());
|
|
1189
1226
|
// `trust ID auto|ask` sets how it answers; the old single levels (default / borrow / trusted) are still understood.
|
|
1190
1227
|
const setting = !extra ? {} : LEGACY_TRUST[extra] ? { trust: extra } : { wake: extra };
|
|
1191
1228
|
const scope = values.unconfined ? { confined: false } : values.confined ? { confined: true } : {};
|
|
1192
1229
|
const input = { id, ...(verb === 'trust' ? { ...setting, ...scope } : {}),
|
|
1193
|
-
...(verb === 'ai' ? ai : {}), ...(['pause', 'resume'].includes(verb) ? { paused: verb === 'pause' } : {}), ...(['approve', 'refuse'].includes(verb) ? { approval: extra } : {}) };
|
|
1230
|
+
...(verb === 'ai' ? ai : {}), ...(['pause', 'resume'].includes(verb) ? { paused: verb === 'pause' } : {}), ...(['approve', 'refuse'].includes(verb) ? { approval: extra } : {}), ...(verb === 'lend' ? { duration: extra } : {}) };
|
|
1194
1231
|
result = await invited_command(service, action, input, deps);
|
|
1195
1232
|
}
|
|
1196
1233
|
if (values.json) return out(result);
|
|
@@ -33,9 +33,8 @@ const CODE_LENGTH = 12;
|
|
|
33
33
|
const INVITE_CONTEXT = 'codiscuss-invite-v1';
|
|
34
34
|
const LABEL_LIMIT = 80;
|
|
35
35
|
const LOCAL_TIMEOUT_MS = 8000;
|
|
36
|
-
//
|
|
36
|
+
// Invites made before the invited computer chose its own loan carry one of these; a redeem without an end still uses it.
|
|
37
37
|
const DURATION_DAYS = { '3d': 3, '7d': 7, '30d': 30 };
|
|
38
|
-
const DURATIONS = new Set(['1h', 'today', ...Object.keys(DURATION_DAYS)]);
|
|
39
38
|
const LEVELS = new Set(['discuss', 'read']);
|
|
40
39
|
// The only actions an external signer has; redeeming an invite is the one that goes without a registered key.
|
|
41
40
|
export const EXTERNAL_SIGNED_ACTIONS = new Set(['external-api', 'external-repo', 'external-leave']);
|
|
@@ -168,8 +167,12 @@ async function local_call(room, method, path, { token, body, external = false, s
|
|
|
168
167
|
return { status: response.status, json, body: json ? await response.json() : null, ...(tag ? { etag: tag } : {}) };
|
|
169
168
|
}
|
|
170
169
|
|
|
171
|
-
/**
|
|
172
|
-
|
|
170
|
+
/**
|
|
171
|
+
* When the membership ends, in seconds as the local website keeps it: the end the invited computer chose (it decides how
|
|
172
|
+
* long it lends its AI), else, from a computer that does not send one, the duration an older invite carried, else an hour.
|
|
173
|
+
*/
|
|
174
|
+
function membership_end(chosen, duration, now) {
|
|
175
|
+
if (Number.isSafeInteger(chosen) && chosen * 1000 > now) return chosen;
|
|
173
176
|
if (DURATION_DAYS[duration]) return Math.floor((now + DURATION_DAYS[duration] * DAY_MS) / 1000);
|
|
174
177
|
if (duration === 'today') {
|
|
175
178
|
const end = new Date(now);
|
|
@@ -199,7 +202,7 @@ async function invite_site(home, site_url) {
|
|
|
199
202
|
* Issue an invite for one room: a 12-character code valid ten minutes, kept here only as its hash, and the link that
|
|
200
203
|
* carries it with this computer's key fingerprint. The code and link are returned this once.
|
|
201
204
|
*/
|
|
202
|
-
export async function create_invite(home, { room_id, token, level = 'read', folders,
|
|
205
|
+
export async function create_invite(home, { room_id, token, level = 'read', folders, site_url, member_id, by = 'computer' }, { fetcher } = {}) {
|
|
203
206
|
const room = await owned_room(home, room_id, token, fetcher);
|
|
204
207
|
if (member_id) {
|
|
205
208
|
const path = `/api/rooms/${encodeURIComponent(room_id)}/external-members/${member_id}`;
|
|
@@ -211,11 +214,9 @@ export async function create_invite(home, { room_id, token, level = 'read', fold
|
|
|
211
214
|
if (current.status !== 200) throw new GatewayError(current.status, current.body?.error || '外部成员不存在');
|
|
212
215
|
}
|
|
213
216
|
level = current.body.scope;
|
|
214
|
-
duration = current.body.duration;
|
|
215
217
|
folders = current.body.directories.map(path => room.directories.indexOf(path));
|
|
216
218
|
}
|
|
217
219
|
if (!LEVELS.has(level)) throw new GatewayError(400, '开放等级须为 discuss 或 read');
|
|
218
|
-
if (!DURATIONS.has(duration)) throw new GatewayError(400, '有效期须为 1h、today、3d、7d 或 30d');
|
|
219
220
|
const chosen = level === 'discuss' ? [] : folders === undefined ? [0] : folders;
|
|
220
221
|
if (!Array.isArray(chosen) || (level === 'read' && !chosen.length) || chosen.some(index => !Number.isSafeInteger(index) || index < 0 || index >= room.directories.length)
|
|
221
222
|
|| new Set(chosen).size !== chosen.length) {
|
|
@@ -232,7 +233,7 @@ export async function create_invite(home, { room_id, token, level = 'read', fold
|
|
|
232
233
|
const view = await call('GET', `/api/rooms/${encodeURIComponent(room_id)}`);
|
|
233
234
|
const taken = new Set([...(view.free?.members || []), ...(listed.members || [])].map(member => member.name));
|
|
234
235
|
const created = await call('POST', base, { pending: true, revision: listed.revision,
|
|
235
|
-
name: external_name('Custom', taken), scope: level,
|
|
236
|
+
name: external_name('Custom', taken), scope: level, directories: chosen.map(index => room.directories[index]) });
|
|
236
237
|
member_id = created.member.member_id;
|
|
237
238
|
}
|
|
238
239
|
let site, link;
|
|
@@ -254,20 +255,20 @@ export async function create_invite(home, { room_id, token, level = 'read', fold
|
|
|
254
255
|
for (const [key, previous] of Object.entries(registry.invites)) {
|
|
255
256
|
if (previous.room_id === room_id && previous.member_id === member_id) delete registry.invites[key];
|
|
256
257
|
}
|
|
257
|
-
registry.invites[invite_id] = { member_id, invite_version: seat.invite_version, code_hash: invite_code_hash(code), room_id, level, folders: chosen,
|
|
258
|
+
registry.invites[invite_id] = { member_id, invite_version: seat.invite_version, code_hash: invite_code_hash(code), room_id, level, folders: chosen, site, by, created_at: now, expires_at: now + INVITE_MS, failures: 0 };
|
|
258
259
|
return { invite_id, member_id, expires_at: now + INVITE_MS };
|
|
259
260
|
});
|
|
260
261
|
audit(home, { event: 'invite.created', room: room_id, invite: invite.invite_id, level, by });
|
|
261
262
|
const payload = { v: 1, site, machine: link.id, machine_name: link.name, fp: fingerprint, code, room_name, level, expires_at: invite.expires_at };
|
|
262
263
|
return { ...invite, code: `${code.slice(0, 4)}-${code.slice(4, 8)}-${code.slice(8)}`, url: `${site}/join#${b64url(Buffer.from(JSON.stringify(payload)))}`,
|
|
263
|
-
room_id, level, folders: chosen,
|
|
264
|
+
room_id, level, folders: chosen, machine: { id: link.id, name: link.name, fingerprint }, site };
|
|
264
265
|
}
|
|
265
266
|
|
|
266
267
|
/** The room's invites still waiting, without their codes. */
|
|
267
268
|
export async function list_invites(home, { room_id, token }, { fetcher } = {}) {
|
|
268
269
|
await owned_room(home, room_id, token, fetcher);
|
|
269
270
|
return with_registry(home, registry => ({ invites: Object.entries(registry.invites).filter(([, invite]) => invite.room_id === room_id)
|
|
270
|
-
.map(([invite_id, { level, folders,
|
|
271
|
+
.map(([invite_id, { level, folders, created_at, expires_at, by }]) => ({ invite_id, room_id, level, folders, created_at, expires_at, by }))
|
|
271
272
|
.sort((left, right) => right.created_at - left.created_at) }));
|
|
272
273
|
}
|
|
273
274
|
|
|
@@ -312,7 +313,7 @@ async function drop_external(home, ctx, external_id, reason) {
|
|
|
312
313
|
}
|
|
313
314
|
|
|
314
315
|
/** Take a proven invite; failed guesses cool down the signer without consuming any invitation. */
|
|
315
|
-
function take_invite(home, machine_id, public_key, proof) {
|
|
316
|
+
function take_invite(home, machine_id, public_key, proof, chosen_end) {
|
|
316
317
|
const taken = with_registry(home, (registry, now) => {
|
|
317
318
|
const supplied = Buffer.from(String(proof || ''));
|
|
318
319
|
registry.redemptions ||= {};
|
|
@@ -338,7 +339,7 @@ function take_invite(home, machine_id, public_key, proof) {
|
|
|
338
339
|
throw new GatewayError(409, '这把密钥已经加入过房间,请为新的邀请生成新密钥', {}, 'key_used');
|
|
339
340
|
}
|
|
340
341
|
registry.redemptions[id] = { ...invite, external_id,
|
|
341
|
-
member_expires_at: membership_end(invite.duration, Date.now()) };
|
|
342
|
+
member_expires_at: membership_end(chosen_end, invite.duration, Date.now()) };
|
|
342
343
|
delete registry.invites[id];
|
|
343
344
|
return { invite_id: id, ...registry.redemptions[id] };
|
|
344
345
|
}
|
|
@@ -361,7 +362,7 @@ function external_name(platform, taken) {
|
|
|
361
362
|
* local website to add the external member, and the key is registered and published at once.
|
|
362
363
|
*/
|
|
363
364
|
async function redeem(home, ctx, id, sealed, request) {
|
|
364
|
-
const { public_key, proof, label, platform, adapter, model } = request.payload || {};
|
|
365
|
+
const { public_key, proof, label, platform, adapter, model, expires_at } = request.payload || {};
|
|
365
366
|
let external_id;
|
|
366
367
|
try { external_id = device_id_of(public_key); } catch { throw new GatewayError(400, '外部成员公钥须为 P-256'); }
|
|
367
368
|
if (!await verify_signature(public_key, sealed.signature, `${id}\n${sealed.body}`)) throw new GatewayError(400, '外部成员签名无效', {}, 'bad_signature');
|
|
@@ -374,7 +375,7 @@ async function redeem(home, ctx, id, sealed, request) {
|
|
|
374
375
|
const status = await local_call(previous_room, 'GET', `/api/rooms/${encodeURIComponent(previous.room_id)}/external-members/${previous.member_id}`, { token: previous_room.token, fetcher: ctx.fetcher });
|
|
375
376
|
if (status.status === 404 || status.body?.status === 'removed') await drop_external(home, ctx, external_id, 'ended');
|
|
376
377
|
}
|
|
377
|
-
const invite = take_invite(home, ctx.machine_id, public_key, proof);
|
|
378
|
+
const invite = take_invite(home, ctx.machine_id, public_key, proof, expires_at);
|
|
378
379
|
const room = local_room(home, invite.room_id);
|
|
379
380
|
if (!room) throw new GatewayError(404, '邀请对应的房间已不在这台电脑上');
|
|
380
381
|
const directories = invite.folders.map(index => room.directories[index]);
|