ai_co_discuss 0.2.28 → 0.2.31

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/web/app.js CHANGED
@@ -60,7 +60,7 @@ state.directory_notice = "";
60
60
  state.directory_pending = new Map();
61
61
  state.directory_version = 0;
62
62
  state.navigation_version = 0;
63
- state.launch = { available: false, remote: false, connect_command: "", profiles: {}, workspace: {}, create: true, error: "", notice: "", recoveries: [] };
63
+ state.launch = { available: false, remote: false, connect_command: "", profiles: {}, workspace: {}, scheduler: {}, create: true, error: "", notice: "", recoveries: [] };
64
64
  const PLATFORM_CLIENTS = { Codex: [{ value: "codex_cli", label: "Codex CLI" }, { value: "codex", label: "Codex App" }],
65
65
  Claude: [{ value: "claude", label: "Claude Code CLI" }],
66
66
  Gemini: [{ value: "antigravity_cli", label: "Antigravity CLI" }, { value: "antigravity", label: "Antigravity App" }] };
@@ -840,6 +840,7 @@ function reset_create_form() {
840
840
  state.create_parent = null;
841
841
  state.launch.create = true;
842
842
  state.launch.workspace = {};
843
+ state.launch.scheduler = {};
843
844
  state.launch.profiles = JSON.parse(JSON.stringify(state.launch.saved_profiles || {}));
844
845
  Object.values(state.launch.profiles).forEach(fill_api_key);
845
846
  state.launch.notice = "";
@@ -944,7 +945,7 @@ async function invite_member({ name, access, project_access = "read", session_id
944
945
  finish_member_request(room_id, token, record, result);
945
946
  if (state.room?.id === room_id) {
946
947
  state.free_notice = access === "online" ? `${record.member.name} 已加入,阅读通知与真实回答由你或授权主持人转交。`
947
- : access === "manual" ? `${record.member.name} 已加入;在成员菜单下载私有配置、复制参与说明,再交给它的本地会话。`
948
+ : access === "manual" ? `${record.member.name} 已加入;点它的“启动指令”复制含凭证的整段说明,粘贴到你要用的 AI 会话即可。`
948
949
  : record.options?.session_id ? `${record.member.name} 已接入原会话;它工作时请不要在原窗口继续操作。`
949
950
  : state.room.mode === "free" ? `${record.member.name} 已加入,之后点名它即会由本机服务唤醒。`
950
951
  : `${record.member.name} 已加入讨论,主持人会重新安排发言。`;
@@ -1367,7 +1368,7 @@ async function submit_room(event, folder_id = null) {
1367
1368
  // a free room needs the service only for members it wakes.
1368
1369
  const launching = free ? Object.values(payload.experts).includes("cli") : state.launch.create && state.launch.available;
1369
1370
  if (launching && !state.launch.available) throw new Error("本机唤醒的成员需要连接本机服务;也可改为手动接入或网页代发");
1370
- const launch_draft = launching ? launch_options() : null;
1371
+ const launch_draft = launching ? creation_launch_options() : null;
1371
1372
  const signature = JSON.stringify({ payload, launch_draft });
1372
1373
  const navigation = state.navigation_version;
1373
1374
  if (!launching) element("room-dialog").close();
@@ -1377,7 +1378,9 @@ async function submit_room(event, folder_id = null) {
1377
1378
  const pending = prepare_room_request(signature);
1378
1379
  const token = pending.token;
1379
1380
  pending.members ||= creation_members(payload.experts);
1380
- const input = { ...(launch_draft || {}), room: { ...payload, members: pending.members, submission_id: pending.id }, token };
1381
+ // The website tracks capabilities (cli/online); a manual expert is a local reader and writer whose delivery lives in its member record.
1382
+ const experts = Object.fromEntries(Object.entries(payload.experts || {}).map(([name, mode]) => [name, mode === "manual" ? "cli" : mode]));
1383
+ const input = { ...(launch_draft || {}), room: { ...payload, ...(payload.experts ? { experts } : {}), members: pending.members, submission_id: pending.id }, token };
1381
1384
  room = await update_directory({ key: "create-room", label: `「${payload.title}」创建`,
1382
1385
  error_message: launching ? error => `「${payload.title}」${error.message}` : null,
1383
1386
  apply: () => { state.creating_room = payload; }, rollback: () => { state.creating_room = null; },
@@ -1392,7 +1395,7 @@ async function submit_room(event, folder_id = null) {
1392
1395
  }
1393
1396
  state.pending_room = null;
1394
1397
  state.create_parent = null;
1395
- if (JSON.stringify({ payload: room_creation_payload(folder_id), launch_draft: launching ? launch_options() : null }) === signature) {
1398
+ if (JSON.stringify({ payload: room_creation_payload(folder_id), launch_draft: launching ? creation_launch_options() : null }) === signature) {
1396
1399
  element("room-form").reset();
1397
1400
  reset_creation_mode();
1398
1401
  render_expert_inputs("new-expert-modes", default_experts());
@@ -1521,7 +1524,7 @@ async function resume_launch(id) {
1521
1524
  try {
1522
1525
  const result = await submit_local_launch(record.input, record.title, record.direct, record.signature);
1523
1526
  if (state.pending_room?.id === id && state.pending_room.signature === JSON.stringify({
1524
- payload: room_creation_payload(record.input.room?.folder_id ?? null), launch_draft: record.direct ? null : launch_options() })) {
1527
+ payload: room_creation_payload(record.input.room?.folder_id ?? null), launch_draft: record.direct ? null : creation_launch_options() })) {
1525
1528
  element("room-form").reset();
1526
1529
  reset_creation_mode();
1527
1530
  render_expert_inputs("new-expert-modes", default_experts());
@@ -1560,7 +1563,8 @@ async function load_launch_settings() {
1560
1563
  const settings = await local_launch_request("settings");
1561
1564
  // Keep the saved machine defaults so every new form can start from them again.
1562
1565
  state.launch.saved_profiles = JSON.parse(JSON.stringify(settings.participants || {}));
1563
- Object.assign(state.launch, { available: true, profiles: settings.participants, api_providers: settings.api_providers || {}, api_keys: settings.api_keys || {}, error: "",
1566
+ Object.assign(state.launch, { available: true, profiles: settings.participants, api_providers: settings.api_providers || {}, api_keys: settings.api_keys || {},
1567
+ scheduler_providers: settings.scheduler_providers || {}, error: "",
1564
1568
  notice: local_connection ? "已连接本机服务,讨论保存在当前网站" : "" });
1565
1569
  Object.values(state.launch.profiles).forEach(fill_api_key);
1566
1570
  load_room_models();
@@ -1598,9 +1602,10 @@ async function load_room_models() {
1598
1602
 
1599
1603
  /** Describe registered launch choices without claiming the software's effective defaults are known. */
1600
1604
  function participant_model(name, room, saved) {
1601
- if (room?.runtime?.mode !== "automatic") return "模型与强度在原聊天设置";
1605
+ // Nothing to say beats a placeholder: a manual member's settings live in its own session and unread ones are not guessed.
1606
+ if (room?.runtime?.mode !== "automatic" || (room.members || []).find(member => member.name === name)?.access === "manual") return "";
1602
1607
  const profile = saved?.room_id === room.id ? saved.participants?.[name] : null;
1603
- if (!profile) return "模型与强度未获取";
1608
+ if (!profile) return "";
1604
1609
  if (["codex", "antigravity"].includes(profile.adapter)) return "模型与强度由 App 设置";
1605
1610
  const model = profile.model || "默认模型";
1606
1611
  const effort = profile.adapter === "antigravity_cli" ? "强度随模型" : profile.effort || "默认强度";
@@ -1609,7 +1614,9 @@ function participant_model(name, room, saved) {
1609
1614
 
1610
1615
  /** Label how a member answers: the registered adapter says API / App; other locally woken members are CLI. */
1611
1616
  function participant_access(name, room) {
1612
- const adapter = (room?.members || []).find(member => member.name === name)?.adapter;
1617
+ const member = (room?.members || []).find(item => item.name === name);
1618
+ const adapter = member?.adapter;
1619
+ if (member?.access === "manual") return "手动";
1613
1620
  if (adapter === "api") return "API";
1614
1621
  if (["codex", "antigravity"].includes(adapter)) return "App";
1615
1622
  return room?.experts?.[name] === "cli" ? "CLI" : "在线";
@@ -1745,6 +1752,36 @@ function launch_options() {
1745
1752
  return draft;
1746
1753
  }
1747
1754
 
1755
+ /** A new room also carries the optional smart scheduling choice; only a complete, enabled choice is sent. */
1756
+ function creation_launch_options() {
1757
+ const { enabled, provider, model, api_key_ref } = state.launch.scheduler;
1758
+ return { ...launch_options(), ...(enabled && provider && model && api_key_ref ? { scheduler: { provider, model, api_key_ref } } : {}) };
1759
+ }
1760
+
1761
+ /** Change the smart scheduling draft; a new provider starts from its preset model and any key saved for its root. */
1762
+ function write_scheduler(field, value) {
1763
+ const scheduler = state.launch.scheduler;
1764
+ scheduler[field] = value;
1765
+ if (field === "provider" || (field === "enabled" && value && !scheduler.provider)) {
1766
+ scheduler.provider ||= Object.keys(state.launch.scheduler_providers || {})[0] || "";
1767
+ const preset = state.launch.scheduler_providers?.[scheduler.provider];
1768
+ scheduler.model = preset?.models[0] || "";
1769
+ scheduler.api_key_ref = preset ? state.launch.api_keys?.[preset.base_url] || "" : "";
1770
+ }
1771
+ publish_view();
1772
+ }
1773
+
1774
+ /** Save the scheduling provider's key to the local private store, under that provider's official root. */
1775
+ async function save_scheduler_api_key(api_key) {
1776
+ const scheduler = state.launch.scheduler;
1777
+ const base_url = state.launch.scheduler_providers?.[scheduler.provider]?.base_url;
1778
+ if (!base_url) throw new Error("请先选择智能调度供应商");
1779
+ const result = await local_launch_request("api-key", { base_url, api_key });
1780
+ state.launch.api_keys = { ...state.launch.api_keys, [base_url]: result.api_key_ref };
1781
+ if (state.launch.scheduler === scheduler && state.launch.scheduler_providers[scheduler.provider].base_url === base_url) scheduler.api_key_ref = result.api_key_ref;
1782
+ publish_view();
1783
+ }
1784
+
1748
1785
  /** Describe effective placement and binding from the same explicit draft sent to the launcher. */
1749
1786
  function launch_summary(name) {
1750
1787
  const profile = state.launch.profiles[name] || {};
@@ -2116,33 +2153,59 @@ function download_member_access(name) {
2116
2153
  : `已下载 ${name} 的私有配置;交给该成员的本地会话,下载不代表已接入。`;
2117
2154
  }
2118
2155
 
2119
- /** Copy a member-specific entry instruction without copying its credential or conversation context. */
2120
- async function copy_member_join(name) {
2156
+ /** Copy the same room-scoped credential as one line of text for an agent that cannot take a file. */
2157
+ async function copy_member_access_text(name) {
2158
+ const room = state.room, access = access_snapshot();
2159
+ const member = access.members.find(item => item.name === name);
2160
+ if (!access.can_manage || !member?.available || member.access === "online") throw new Error("当前浏览器没有此成员可复制的凭证");
2161
+ await copy_text(JSON.stringify({ site: location.origin, room: room.id, token: member_credentials(room.id)[name].token }));
2162
+ state.access_error = "";
2163
+ state.access_notice = `已复制 ${name} 的凭证文本,含 token,仅交给该成员;用环境变量 DISCUSS_ACCESS 或 --access-file - 使用,复制不代表已接入。`;
2164
+ }
2165
+
2166
+ /** Copy a member-specific entry instruction; only the launch variant carries the credential, never conversation context. */
2167
+ async function copy_member_join(name, with_credential = false) {
2121
2168
  const room = state.room, access = access_snapshot();
2122
2169
  const member = access.members.find(item => item.name === name);
2123
2170
  if (!access.can_manage || !member) throw new Error("请使用房主浏览器选择本房间成员");
2171
+ if (with_credential && (member.access !== "manual" || !member.available)) throw new Error("当前浏览器没有此成员可复制的凭证");
2124
2172
  const params = new URLSearchParams({ participant: name, mode: member.access === "online" ? "online" : "cli" });
2125
2173
  const address = `${location.origin}/r/${room.id}?${params}`;
2126
2174
  const skills = `请调用 discuss-participant${room.host === name ? " 和 discuss-host" : ""}。`;
2127
2175
  let instruction;
2128
2176
  if (member.access === "online") instruction = "你是在线只读成员,请在原聊天回答,由用户或授权主持人代发;不要尝试直接写入房间。模型与思考强度在原网页设置。";
2129
2177
  else if (member.access === "runner") instruction = `${skills}等待本机程序交付有效任务,按 task 中的 access_file 和 execution 凭据操作${room.mode === "free" ? ";自由协作的回答必须绑定本次有效 execution_id" : ""}。不要另建定时任务;只处理本次有效执行,失效或撤销后停止提交。下载的持久成员私有文件不能替代自动执行凭据。`;
2130
- else instruction = `${skills}使用属于你的私有文件 member-${room.id}-${name}.json,由用户提供它在本机的实际完整路径;先执行 codiscuss room view ${room.id} --site ${location.origin} --as ${name} --access-file "实际完整路径",后续命令保持本站点、房间和身份。不要读取或公开文件中的 token。模型与思考强度在原软件中设置。首次复制后,可由人工或软件原生定时触发;自行提交,不必每轮复制回答。${workspace_instruction()}`;
2131
- await copy_text(`请以 ${name} 身份参与房间。\n${instruction}\n房间入口:${address}\n先核对最新阶段、任务和原文编号,再按房间协议参与。`);
2178
+ else if (with_credential) instruction = `${skills}凭证文本在下方:原样设为环境变量 DISCUSS_ACCESS(不要回显,不要写进命令行参数),命令省略 --access-file;先执行 codiscuss room view ${room.id} --site ${location.origin} --as ${name},后续命令保持本站点、房间和身份。模型与思考强度在原软件中设置。${manual_trigger_instruction(room)}${workspace_instruction()}`;
2179
+ else instruction = `${skills}使用属于你的私有文件 member-${room.id}-${name}.json,由用户提供它在本机的实际完整路径;先执行 codiscuss room view ${room.id} --site ${location.origin} --as ${name} --access-file "实际完整路径",后续命令保持本站点、房间和身份。不要读取或公开文件中的 token;若用户给的是凭证文本而非文件,把它设为环境变量 DISCUSS_ACCESS(不要回显)并省略 --access-file。模型与思考强度在原软件中设置。${manual_trigger_instruction(room)}${workspace_instruction()}`;
2180
+ const credential = with_credential ? `
2181
+ 凭证文本(含 token,仅限你使用):${JSON.stringify({ site: location.origin, room: room.id, token: member_credentials(room.id)[name].token })}` : "";
2182
+ await copy_text(`请以 ${name} 身份参与房间。
2183
+ ${instruction}
2184
+ 房间入口:${address}
2185
+ 先核对最新阶段、任务和原文编号,再按房间协议参与。${credential}`);
2132
2186
  if (state.room?.id === room.id) {
2133
2187
  state.access_error = "";
2134
- state.access_notice = `已复制 ${name} 的参与说明,未包含凭据;复制不代表已经送达或接入。`;
2188
+ state.access_notice = with_credential ? `已复制 ${name} 的启动指令,含 token,只交给该成员;复制不代表已经送达或接入。`
2189
+ : `已复制 ${name} 的参与说明,未包含凭据;复制不代表已经送达或接入。`;
2135
2190
  }
2136
2191
  }
2137
2192
 
2193
+ /** How a manual member learns it is its turn: free rooms are pulled by the member, discussions only on the host's assignment. */
2194
+ function manual_trigger_instruction(room) {
2195
+ return room.mode === "free" ? "首次复制后,可由人工或软件原生定时触发;自行提交,不必每轮复制回答。"
2196
+ : "这是全自动讨论:只在主持人给你安排发言时才参与,先核对 turn current 是否轮到你,再按参与技能认领发言权并提交;没有安排就结束本次检查。你不会被自动唤醒,需要你或软件原生定时触发。";
2197
+ }
2198
+
2138
2199
  /** Download a private per-room setup file for the independent local runner. */
2139
2200
  function export_runtime() {
2140
2201
  const token = localStorage.getItem(`discuss-access:${state.room.id}`);
2141
2202
  if (!token) throw new Error("此浏览器缺少房间控制凭据,请使用创建房间的浏览器");
2142
2203
  const saved = member_credentials(state.room.id);
2143
- const participants = Object.fromEntries(Object.keys(state.room.experts).filter(name => state.room.experts[name] === "cli")
2204
+ // A manual expert answers with its own credential and has nothing for the local service to configure.
2205
+ const manual = new Set((state.room.members || []).filter(member => member.access === "manual").map(member => member.name));
2206
+ const participants = Object.fromEntries(Object.keys(state.room.experts).filter(name => state.room.experts[name] === "cli" && !manual.has(name))
2144
2207
  .map(name => [name, { adapter: state.launch.profiles[name]?.adapter || "待配置" }]));
2145
- const members = Object.fromEntries(Object.entries(saved).map(([name, value]) => [name, { token: value.token }]));
2208
+ const members = Object.fromEntries(Object.entries(saved).filter(([name]) => !manual.has(name)).map(([name, value]) => [name, { token: value.token }]));
2146
2209
  const workspace = runtime_workspace();
2147
2210
  const config = { site: location.origin, room: state.room.id, token, ...workspace, participants, members };
2148
2211
  download_private_json(config, `discussion-${state.room.id}.json`);
@@ -2829,7 +2892,7 @@ function expert_control(container_id, name) {
2829
2892
  const container = element(container_id);
2830
2893
  let control = container?.querySelector(`[data-expert="${CSS.escape(name)}"]`);
2831
2894
  if (!control && container && platform_of(name)) {
2832
- container.insertAdjacentHTML("beforeend", `<label>${escape_html(name)}<select data-expert="${escape_html(name)}" aria-label="${escape_html(name)} 参与方式"><option value="">不参与</option><option value="cli">本地 CLI · 读写</option><option value="online">在线 AI · 只读</option></select></label>`);
2895
+ container.insertAdjacentHTML("beforeend", `<label>${escape_html(name)}<select data-expert="${escape_html(name)}" aria-label="${escape_html(name)} 参与方式"><option value="">不参与</option><option value="cli">本地 CLI · 读写</option><option value="manual">手动接入</option><option value="online">在线 AI · 只读</option></select></label>`);
2833
2896
  control = container.querySelector(`[data-expert="${CSS.escape(name)}"]`);
2834
2897
  }
2835
2898
  return control;
@@ -2975,17 +3038,19 @@ async function execute_view_action(name, value) {
2975
3038
  copy_turn, notify: () => change_turn_status("notified"), cancel_turn: () => change_turn_status("cancelled"),
2976
3039
  take_floor: () => change_floor("take"), return_floor: () => change_floor("return"),
2977
3040
  copy_online: () => copy_context(), copy_cli: () => copy_context("cli"), copy_background,
2978
- choose_runtime, export_runtime, download_member_access, copy_member_join, pause_runtime, check_limits, pause_discussion, restart_discussion, force_close, conclude_discussion,
3041
+ choose_runtime, export_runtime, download_member_access, copy_member_access_text, copy_member_join, copy_member_launch: name => copy_member_join(name, true), pause_runtime, check_limits, pause_discussion, restart_discussion, force_close, conclude_discussion,
2979
3042
  save_launch_defaults, launch_current_room, resume_launch, discard_launch, retry_launch_connection, check_launch_connection: load_launch_settings,
2980
3043
  load_room_configuration, save_room_configuration, interrupt_member, change_member, invite_member, interrupt_free, set_proxy, copy_online_notice,
2981
3044
  prepare_brainstorm, return_conclusion, convert_suggestion,
2982
3045
  busy: () => { throw new Error("上一个操作仍在处理中,请稍候;长时间无响应请刷新页面"); },
2983
3046
  copy_reading: () => copy_text(`${location.origin}/r/${state.room.id}`), copy: copy_text };
3047
+ if (!["refresh", "busy"].includes(name)) state.free_error = "";
2984
3048
  try {
2985
3049
  await actions[name](value);
2986
3050
  return true;
2987
3051
  } catch (error) {
2988
- if (["download_member_access", "copy_member_join"].includes(name)) state.access_error = error.message;
3052
+ if (["download_member_access", "copy_member_access_text", "copy_member_join", "copy_member_launch"].includes(name)) state.access_error = error.message;
3053
+ else if (!state.free_error) state.free_error = error.message;
2989
3054
  show_toast(error.message, true);
2990
3055
  return false;
2991
3056
  } finally { publish_view(); }
@@ -2999,7 +3064,7 @@ function change_view_theme(theme) {
2999
3064
 
3000
3065
  window.discuss_view = { snapshot: view_snapshot, write_field: write_view_field,
3001
3066
  write_launch: write_launch_field, write_room_connection, write_room_adapter, launch_clients: LAUNCH_CLIENTS,
3002
- launch_model_state, load_launch_models, write_launch_model, save_launch_api_key, check_launch_api, launch_summary, launch_can_set_access, launch_can_bind_session, pick_launch_directory, restore_launch_profile, reset_create_form, empty_discussion_message,
3067
+ launch_model_state, load_launch_models, write_launch_model, save_launch_api_key, write_scheduler, save_scheduler_api_key, check_launch_api, launch_summary, launch_can_set_access, launch_can_bind_session, pick_launch_directory, restore_launch_profile, reset_create_form, empty_discussion_message,
3003
3068
  start_drag: start_directory_drag,
3004
3069
  attachment_markup, attachment_size, attachment_file_icon, drop_attachments, paste_attachments,
3005
3070
  write_expert: write_view_expert, add_instance: add_view_instance, platform_of, execute: execute_view_action, theme: change_view_theme,