ai_co_discuss 0.4.78 → 0.4.80
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-participant/SKILL.md +1 -0
- package/.agents/skills/local-tts-setup/SKILL.md +3 -2
- package/backend/external_members.py +27 -8
- package/backend/free_room.py +13 -1
- package/backend/message_queue.py +15 -5
- package/backend/schema.sql +3 -0
- package/backend/server.py +24 -3
- package/docs/deployment.md +1 -1
- package/docs/en/deployment.md +1 -1
- package/docs/en/runner.md +5 -2
- package/docs/runner.md +6 -3
- package/frontend/locales/en/admin.json +38 -11
- package/frontend/locales/en/app.json +1 -0
- package/frontend/locales/en/backend_worker.json +9 -5
- package/frontend/locales/en/core.json +3 -6
- package/frontend/locales/en/discussion.json +3 -2
- package/frontend/locales/en/external.json +21 -8
- package/frontend/locales/en/room.json +13 -8
- package/frontend/locales/en/settings.json +12 -1
- package/package.json +1 -1
- package/runner/adapters/api.mjs +8 -5
- package/runner/adapters/api_web.mjs +42 -63
- package/runner/adapters/claude.mjs +6 -1
- package/runner/adapters/cli.mjs +1 -1
- package/runner/adapters/codex_bridge.mjs +4 -3
- package/runner/adapters/codex_cli.mjs +65 -4
- package/runner/adapters/common.mjs +1 -1
- package/runner/adapters/profiles.mjs +16 -3
- package/runner/admin_cli.mjs +21 -5
- package/runner/admin_panel.mjs +56 -13
- package/runner/discuss.py +15 -3
- package/runner/discussion_launch.mjs +3 -3
- package/runner/execution_progress.mjs +7 -3
- package/runner/expert_prompts.mjs +8 -5
- package/runner/external_client.mjs +115 -26
- package/runner/external_gateway.mjs +9 -5
- package/runner/free_runner.mjs +1 -1
- package/runner/i18n_en.mjs +13 -9
- package/runner/os_users.mjs +15 -3
- package/runner/project_files.mjs +6 -5
- package/runner/tts_providers.mjs +22 -2
- package/web/admin.css +1 -1
- package/web/admin.js +3 -3
- package/web/app.js +162 -27
- package/web/backup.js +1 -1
- package/web/i18n.js +4 -4
- package/web/icons/custom-api.svg +11 -0
- package/web/icons/external-expert.svg +11 -0
- package/web/markdown.css +1 -1
- package/web/modern.css +1 -1
- package/web/modern.js +70 -65
- package/web/office/docx.js +3 -3
|
@@ -14,7 +14,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
14
14
|
import { parseArgs } from 'node:util';
|
|
15
15
|
import { gunzipSync } from 'node:zlib';
|
|
16
16
|
|
|
17
|
-
import { adapter_profile, lockdown_support } from './adapters/profiles.mjs';
|
|
17
|
+
import { adapter_profile, API_PROVIDERS, lockdown_support } from './adapters/profiles.mjs';
|
|
18
18
|
import { external_task_text, TASK_SUBCOMMANDS } from './expert_prompts.mjs';
|
|
19
19
|
import { atomic_json } from './files.mjs';
|
|
20
20
|
import { t } from './i18n.mjs';
|
|
@@ -29,6 +29,7 @@ export const BORROW_DEFAULTS = { max_wakes: 20, hours: 24 };
|
|
|
29
29
|
const MAX_WAKES_LIMIT = 1000;
|
|
30
30
|
const MAX_HOURS = 720;
|
|
31
31
|
const HISTORY_LIMIT = 50;
|
|
32
|
+
const MODEL_LIMIT = 120;
|
|
32
33
|
// What this computer keeps of each request its AI received and each answer it gave, so the history still reads after the
|
|
33
34
|
// inviting room can no longer be reached.
|
|
34
35
|
const TEXT_LIMIT = 4000;
|
|
@@ -38,6 +39,10 @@ const HOUR_MS = 3600000;
|
|
|
38
39
|
// The website gives up on a relayed request after 9 seconds; ask for an answer within that.
|
|
39
40
|
const RELAY_WAIT_MS = 8000;
|
|
40
41
|
const REQUEST_TIMEOUT_MS = 15000;
|
|
42
|
+
// The pauses before sending a request again after a network failure.
|
|
43
|
+
const RETRY_DELAYS_MS = [500, 1500];
|
|
44
|
+
// Network failures that happen before a request leaves this computer, so sending a write again cannot repeat it.
|
|
45
|
+
const NOT_SENT_CODES = new Set(['ENOTFOUND', 'EAI_AGAIN', 'ECONNREFUSED', 'ENETUNREACH', 'EHOSTUNREACH', 'UND_ERR_CONNECT_TIMEOUT']);
|
|
41
46
|
const RELAY_CIPHER_INFO = 'codiscuss-relay-v1';
|
|
42
47
|
const INVITE_CONTEXT = 'codiscuss-invite-v1';
|
|
43
48
|
const STORE_FILE = 'invited.json';
|
|
@@ -61,6 +66,7 @@ export const MEMBER_API = {
|
|
|
61
66
|
execution: (room, execution) => `${EXTERNAL_PREFIX(room)}/executions/${execution}`,
|
|
62
67
|
answer: room => `${EXTERNAL_PREFIX(room)}/answer`,
|
|
63
68
|
messages: room => `${EXTERNAL_PREFIX(room)}/messages`,
|
|
69
|
+
ai: room => `${EXTERNAL_PREFIX(room)}/ai`,
|
|
64
70
|
};
|
|
65
71
|
|
|
66
72
|
// ---- Secrets: sealed with DPAPI for the signed-in Windows user, 0600 elsewhere (as machine-links.json). ----
|
|
@@ -151,7 +157,7 @@ function with_store(home, task) {
|
|
|
151
157
|
export function record_view(record, store) {
|
|
152
158
|
const machine = store.machines[record.machine_fingerprint] || {};
|
|
153
159
|
const trust = TRUST_LEVELS.includes(machine.trust) ? machine.trust : 'default';
|
|
154
|
-
const { session_id, machine_key, ...shown } = record;
|
|
160
|
+
const { session_id, machine_key, ai_reported, ...shown } = record;
|
|
155
161
|
return { ...shown, trust, lockdown: trust !== 'trusted', approvals: (record.approvals || []).filter(item => item.status === 'waiting') };
|
|
156
162
|
}
|
|
157
163
|
|
|
@@ -227,14 +233,33 @@ export function invite_proof(code, machine, jwk) {
|
|
|
227
233
|
return createHmac('sha256', key).update(`${INVITE_CONTEXT}\n${machine}\n${raw_point(jwk).toString('base64url')}`).digest('base64url');
|
|
228
234
|
}
|
|
229
235
|
|
|
236
|
+
const site_unreachable = (site, error) => failure('site_unreachable', '连不上对方的线上站点 {site}:{reason}', { site, reason: error.message },
|
|
237
|
+
{ offline: true, network_code: error.cause?.code, timed_out: error.name === 'TimeoutError' || error.name === 'AbortError' });
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Run a request, sending it again after a brief network failure. A request that may have reached the other side is sent
|
|
241
|
+
* again only when `repeatable`; a timeout is not retried, since the wait has already been spent.
|
|
242
|
+
*/
|
|
243
|
+
async function retry_unreachable(send, { repeatable = false, delays = RETRY_DELAYS_MS } = {}) {
|
|
244
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
245
|
+
try { return await send(); }
|
|
246
|
+
catch (error) {
|
|
247
|
+
const retry = error.code === 'site_unreachable' && !error.timed_out && attempt < delays.length && (repeatable || NOT_SENT_CODES.has(error.network_code));
|
|
248
|
+
if (!retry) throw error;
|
|
249
|
+
await new Promise(done => setTimeout(done, delays[attempt]));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
230
254
|
/**
|
|
231
255
|
* The inviting computer's public keys, from the website's public machine list. Without a computer id the site must list
|
|
232
256
|
* exactly one computer.
|
|
233
257
|
*/
|
|
234
|
-
export async function machine_keys(site, machine, { fetcher = fetch } = {}) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
258
|
+
export async function machine_keys(site, machine, { fetcher = fetch, retry_delays } = {}) {
|
|
259
|
+
const response = await retry_unreachable(async () => {
|
|
260
|
+
try { return await fetcher(`${site}/api/machines`, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) }); }
|
|
261
|
+
catch (error) { throw site_unreachable(site, error); }
|
|
262
|
+
}, { repeatable: true, delays: retry_delays });
|
|
238
263
|
const body = await response.json().catch(() => ({}));
|
|
239
264
|
const list = (Array.isArray(body) ? body : body.machines || []).filter(item => item?.public_key && item?.sign_key);
|
|
240
265
|
if (!machine && list.length > 1) throw failure('machine_required', '对方站点连着多台电脑,请用 --machine 指定电脑编号:{ids}', { ids: list.map(item => `${item.id}(${item.name || ''})`).join('、') });
|
|
@@ -271,9 +296,15 @@ function key_pair() {
|
|
|
271
296
|
* Send one action to the inviting computer and open its answer `{status, body}`. `identity` is `{key_id, private_key,
|
|
272
297
|
* room}`; the redeem (`room` absent) goes unregistered to the pairing entry, signed only to prove the key is held, the
|
|
273
298
|
* rest to the relay with the registered key. Throws with `offline` when the computer is not connected, `unconfirmed` when
|
|
274
|
-
* it did not answer in time.
|
|
299
|
+
* it did not answer in time. A brief network failure is retried as a new relay request: always for a read or a leave
|
|
300
|
+
* (leaving twice changes nothing), and for any other write only when it never left this computer.
|
|
275
301
|
*/
|
|
276
|
-
export
|
|
302
|
+
export function relay_send(target, identity, action, payload, deps = {}) {
|
|
303
|
+
const repeatable = action === 'external-leave' || (action === 'external-api' && payload.method === 'GET');
|
|
304
|
+
return retry_unreachable(() => relay_send_once(target, identity, action, payload, deps), { repeatable, delays: deps.retry_delays });
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function relay_send_once(target, identity, action, payload, { fetcher = fetch, wait = RELAY_WAIT_MS }) {
|
|
277
308
|
const id = randomUUID();
|
|
278
309
|
const redeem = action === 'external-redeem';
|
|
279
310
|
const body = JSON.stringify({ action, payload, machine: target.machine, ...(redeem ? {} : { room: identity.room }), sent_at: Date.now() });
|
|
@@ -297,7 +328,7 @@ export async function relay_send(target, identity, action, payload, { fetcher =
|
|
|
297
328
|
signal: AbortSignal.timeout(wait + REQUEST_TIMEOUT_MS) });
|
|
298
329
|
} catch (error) {
|
|
299
330
|
if (error.name === 'TimeoutError' || error.name === 'AbortError') throw Object.assign(failure('unconfirmed', '对方电脑未在限时内答复,结果待确认'), { unconfirmed: true });
|
|
300
|
-
throw
|
|
331
|
+
throw site_unreachable(target.site, error);
|
|
301
332
|
}
|
|
302
333
|
const result = await response.json().catch(() => ({}));
|
|
303
334
|
if (!response.ok) throw remote_failure(result, 'site_refused', '对方站点拒绝了请求(HTTP {status})', { status: response.status }, { status: response.status });
|
|
@@ -357,6 +388,25 @@ function check_ai(input) {
|
|
|
357
388
|
return { adapter, model: String(input.model || ''), effort: String(input.effort || '') };
|
|
358
389
|
}
|
|
359
390
|
|
|
391
|
+
/** The saved model API this AI runs on, as `[participant name, settings]`; empty when this computer has none. */
|
|
392
|
+
function saved_api(home, ai) {
|
|
393
|
+
const settings = read_json(join(home, 'launch-settings.json'), { participants: {} });
|
|
394
|
+
const saved = Object.entries(settings.participants || {}).filter(([, profile]) => profile?.adapter === ai.adapter && profile.base_url);
|
|
395
|
+
return saved.find(([, profile]) => !ai.model || profile.model === ai.model) || saved[0] || [];
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* What the inviting room shows about this AI: its adapter, platform and model. A model API takes its platform from the
|
|
400
|
+
* provider slot it is saved under; a custom endpoint has none of its own.
|
|
401
|
+
*/
|
|
402
|
+
function ai_identity(home, ai) {
|
|
403
|
+
const profile = adapter_profile(ai.adapter);
|
|
404
|
+
if (profile?.kind !== 'api') return { adapter: ai.adapter, platform: profile?.platform || 'Custom', model: String(ai.model || '').slice(0, MODEL_LIMIT) };
|
|
405
|
+
const [name, api] = saved_api(home, ai);
|
|
406
|
+
const platform = String(name || '').split('-')[0];
|
|
407
|
+
return { adapter: ai.adapter, platform: Object.hasOwn(API_PROVIDERS, platform) ? platform : 'Custom', model: String(ai.model || api?.model || '').slice(0, MODEL_LIMIT) };
|
|
408
|
+
}
|
|
409
|
+
|
|
360
410
|
/** Accept an invitation: check the computer's fingerprint when the link carries one, redeem with a new key, keep the record. */
|
|
361
411
|
export async function join_invite(home, input, deps = {}) {
|
|
362
412
|
const invite = parse_invite(input.invite, input);
|
|
@@ -376,11 +426,9 @@ export async function join_invite(home, input, deps = {}) {
|
|
|
376
426
|
});
|
|
377
427
|
const existing = read_store(home);
|
|
378
428
|
if (existing.records[attempt.id] && read_secrets(home)[attempt.id]?.token) return { record: record_view(existing.records[attempt.id], existing) };
|
|
379
|
-
const pair = attempt.pair, key_id = key_id_of(pair.public_key);
|
|
429
|
+
const pair = attempt.pair, key_id = key_id_of(pair.public_key), identity = ai_identity(home, ai);
|
|
380
430
|
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',
|
|
381
|
-
{ public_key: pair.public_key, proof: invite_proof(invite.code, keys.id, pair.public_key), label: String(input.label || hostname()).slice(0, 80),
|
|
382
|
-
// The model API has no platform name of its own; the inviting room names it as a custom AI.
|
|
383
|
-
platform: adapter_profile(ai.adapter).platform || 'Custom', adapter: ai.adapter }, deps);
|
|
431
|
+
{ 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);
|
|
384
432
|
if (answer.status >= 400) throw remote_failure(answer.body, 'invite_invalid', '邀请无效或已过期');
|
|
385
433
|
const joined = answer.body || {};
|
|
386
434
|
if (!ROOM_ID.test(joined.room?.id || '') || typeof joined.member?.name !== 'string' || typeof joined.token !== 'string') {
|
|
@@ -395,7 +443,7 @@ export async function join_invite(home, input, deps = {}) {
|
|
|
395
443
|
machine_key: keys.public_key, fingerprint_checked: Boolean(invite.fingerprint), room: joined.room.id, room_title: String(joined.room.name || invite.room_name),
|
|
396
444
|
member: joined.member.name, member_id: joined.member.id ?? null, key_id, open_level: joined.level || invite.level || 'read',
|
|
397
445
|
directories: Array.isArray(joined.directories) ? joined.directories : [],
|
|
398
|
-
expires_at: Number(joined.expires_at) ? Number(joined.expires_at) * 1000 : null, ai, limits: null, wakes: 0, last_wake_at: null, paused: false,
|
|
446
|
+
expires_at: Number(joined.expires_at) ? Number(joined.expires_at) * 1000 : null, ai, ai_reported: JSON.stringify(identity), limits: null, wakes: 0, last_wake_at: null, paused: false,
|
|
399
447
|
status: 'active', contact: { at: now, state: 'online', error: '' }, approvals: [], history: [], running: null, joined_at: now };
|
|
400
448
|
secrets.get()[id] = { private_key: pair.private_key, token: joined.token };
|
|
401
449
|
secrets.changed = true;
|
|
@@ -476,20 +524,47 @@ export async function leave(home, { id }, deps = {}) {
|
|
|
476
524
|
try {
|
|
477
525
|
const answer = await record_send(home, id, 'external-leave', {}, deps);
|
|
478
526
|
if (answer.status >= 400 && answer.body?.code !== 'external_ended') remote = 'refused';
|
|
479
|
-
} catch (error) { remote = error.offline ? 'unreachable' : 'refused'; deps.log?.(error.message); }
|
|
527
|
+
} catch (error) { remote = error.offline ? 'unreachable' : error.unconfirmed ? 'unconfirmed' : 'refused'; deps.log?.(error.message); }
|
|
528
|
+
// Not heard over there yet: the key stays until the pull loop has told the other computer (`deliver_leave`).
|
|
529
|
+
const undelivered = remote === 'unreachable' || remote === 'unconfirmed';
|
|
480
530
|
return with_store(home, (store, secrets, now) => {
|
|
481
531
|
const record = find_record(store, id);
|
|
482
|
-
Object.assign(record, { status: 'left', approvals: [], paused: true });
|
|
532
|
+
Object.assign(record, { status: 'left', approvals: [], paused: true, leave_pending: undelivered });
|
|
483
533
|
remember(record, { outcome: 'left', remote }, now);
|
|
484
|
-
|
|
485
|
-
for (const [key, value] of Object.entries(secrets.get())) {
|
|
486
|
-
if (key.startsWith('join:') && value.id === id) delete secrets.get()[key];
|
|
487
|
-
}
|
|
488
|
-
secrets.changed = true;
|
|
534
|
+
if (!undelivered) forget_keys(secrets, id);
|
|
489
535
|
return { record: record_view(record, store), remote };
|
|
490
536
|
});
|
|
491
537
|
}
|
|
492
538
|
|
|
539
|
+
/** Delete what this computer holds for a record it has left: its key, credential and join attempt. */
|
|
540
|
+
function forget_keys(secrets, id) {
|
|
541
|
+
delete secrets.get()[id];
|
|
542
|
+
for (const [key, value] of Object.entries(secrets.get())) {
|
|
543
|
+
if (key.startsWith('join:') && value.id === id) delete secrets.get()[key];
|
|
544
|
+
}
|
|
545
|
+
secrets.changed = true;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Tell the inviting computer about a leave it has not heard yet. Any answer from it settles the matter; while it cannot
|
|
550
|
+
* be reached the next pass tries again, until the membership has run out over there by itself.
|
|
551
|
+
*/
|
|
552
|
+
async function deliver_leave(home, id, deps = {}) {
|
|
553
|
+
const record = read_store(home).records[id];
|
|
554
|
+
if (!(record.expires_at && record.expires_at <= (deps.now?.() ?? Date.now()))) {
|
|
555
|
+
try { await record_send(home, id, 'external-leave', {}, deps); }
|
|
556
|
+
catch (error) {
|
|
557
|
+
if (error.offline || error.unconfirmed) return { leave_pending: true };
|
|
558
|
+
deps.log?.(error.message);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
with_store(home, (store, secrets) => {
|
|
562
|
+
store.records[id].leave_pending = false;
|
|
563
|
+
forget_keys(secrets, id);
|
|
564
|
+
});
|
|
565
|
+
return { leave_pending: false };
|
|
566
|
+
}
|
|
567
|
+
|
|
493
568
|
/** Keep the record in line with what the inviting room grants now (`/view` `me`): level, deadline and opened directories. */
|
|
494
569
|
function apply_grant(home, id, me, now = Date.now()) {
|
|
495
570
|
if (!me || typeof me !== 'object') return;
|
|
@@ -571,14 +646,14 @@ export const INVITED_ACTIONS = new Set(['invited-list', 'invited-join', 'invited
|
|
|
571
646
|
* API's endpoint fields (its key stays a reference into this computer's key store). Null when this computer has none.
|
|
572
647
|
*/
|
|
573
648
|
function software_profile(home, ai) {
|
|
574
|
-
const settings = read_json(join(home, 'launch-settings.json'), { participants: {} });
|
|
575
|
-
const saved = Object.values(settings.participants || {}).filter(profile => profile?.adapter === ai.adapter);
|
|
576
649
|
if (adapter_profile(ai.adapter)?.kind === 'api') {
|
|
577
|
-
const api =
|
|
650
|
+
const [, api] = saved_api(home, ai);
|
|
578
651
|
if (!api) return null;
|
|
579
652
|
const { base_url, api_protocol, api_key_ref, image_input, model } = api;
|
|
580
653
|
return { base_url, api_protocol, api_key_ref, image_input, model };
|
|
581
654
|
}
|
|
655
|
+
const settings = read_json(join(home, 'launch-settings.json'), { participants: {} });
|
|
656
|
+
const saved = Object.values(settings.participants || {}).filter(profile => profile?.adapter === ai.adapter);
|
|
582
657
|
const executable = saved.find(profile => profile.executable)?.executable;
|
|
583
658
|
return executable ? { executable } : null;
|
|
584
659
|
}
|
|
@@ -737,15 +812,29 @@ async function expire_approvals(home, id, deps, now) {
|
|
|
737
812
|
for (const item of expired) await decline(home, id, item.request_ids, 'timeout', deps);
|
|
738
813
|
}
|
|
739
814
|
|
|
815
|
+
/**
|
|
816
|
+
* Tell the inviting room when this AI differs from what it last heard. Retried on later passes until that computer
|
|
817
|
+
* answers; one that refuses (an older version has no such route) is not asked again for this AI.
|
|
818
|
+
*/
|
|
819
|
+
async function report_ai(home, record, deps) {
|
|
820
|
+
const identity = ai_identity(home, record.ai), reported = JSON.stringify(identity);
|
|
821
|
+
if (record.ai_reported === reported) return;
|
|
822
|
+
try { await member_api(home, record.id, 'POST', MEMBER_API.ai(record.room), identity, deps); }
|
|
823
|
+
catch (error) { if (!(error.status >= 400 && error.status < 500)) return; }
|
|
824
|
+
change_record(home, record.id, current => { current.ai_reported = reported; });
|
|
825
|
+
}
|
|
826
|
+
|
|
740
827
|
/**
|
|
741
828
|
* One pass for one record: expire waiting approvals; renew a running execution; otherwise read the requests named for
|
|
742
829
|
* this member and wake the AI when the owner approved them or the trust level allows it, or queue them for consent.
|
|
743
830
|
*/
|
|
744
831
|
export async function poll_record(home, id, deps = {}) {
|
|
832
|
+
if (read_store(home).records[id]?.leave_pending) return deliver_leave(home, id, deps);
|
|
745
833
|
const now = deps.now?.() ?? Date.now();
|
|
746
834
|
await expire_approvals(home, id, deps, now);
|
|
747
835
|
const store = read_store(home), record = store.records[id];
|
|
748
836
|
if (!record || record.status !== 'active') return { skipped: true };
|
|
837
|
+
await report_ai(home, record, deps);
|
|
749
838
|
if (record.running) {
|
|
750
839
|
if (now - record.running.last_renew < RENEW_MS) return { running: record.running.execution_id };
|
|
751
840
|
await member_api(home, id, 'POST', MEMBER_API.execution(record.room, record.running.execution_id), { action: 'renew' }, deps);
|
|
@@ -782,7 +871,7 @@ export async function poll_record(home, id, deps = {}) {
|
|
|
782
871
|
export function start_external_client(home, { log = () => {}, signal, deps = {} } = {}) {
|
|
783
872
|
const loop = async () => {
|
|
784
873
|
while (!signal?.aborted) {
|
|
785
|
-
const ids = Object.values(read_store(home).records).filter(record => record.status === 'active').map(record => record.id);
|
|
874
|
+
const ids = Object.values(read_store(home).records).filter(record => record.status === 'active' || record.leave_pending).map(record => record.id);
|
|
786
875
|
for (const id of ids) {
|
|
787
876
|
try { await poll_record(home, id, { log, ...deps }); }
|
|
788
877
|
catch (error) { if (!error.offline) log(t('被邀请房间 {id} 拉取失败:{reason}', { id, reason: error.message })); }
|
|
@@ -965,5 +1054,5 @@ export async function external_main(command, args, { home, deps = {}, write = te
|
|
|
965
1054
|
}
|
|
966
1055
|
if (values.json) return out(result);
|
|
967
1056
|
if (result.records) return write(`${result.records.length ? result.records.map(print_record).join('\n') : t('还没有被邀请的房间')}\n`);
|
|
968
|
-
return write(`${print_record(result.record)}${result.
|
|
1057
|
+
return write(`${print_record(result.record)}${result.record?.leave_pending ? `\n${t('暂时连不上对方电脑,常驻服务会继续通知它;通知送达或成员资格到期后删除本机密钥')}` : ''}${result.error ? `\n${t('读不到对方房间:{reason}', { reason: result.error })}` : ''}\n`);
|
|
969
1058
|
}
|
|
@@ -33,7 +33,9 @@ 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
|
+
// Whole-day durations; 3d is no longer offered on the page but seats and links made with it stay valid.
|
|
37
|
+
const DURATION_DAYS = { '3d': 3, '7d': 7, '30d': 30 };
|
|
38
|
+
const DURATIONS = new Set(['1h', 'today', ...Object.keys(DURATION_DAYS)]);
|
|
37
39
|
const LEVELS = new Set(['discuss', 'read']);
|
|
38
40
|
// The only actions an external signer has; redeeming an invite is the one that goes without a registered key.
|
|
39
41
|
export const EXTERNAL_SIGNED_ACTIONS = new Set(['external-api', 'external-repo', 'external-leave']);
|
|
@@ -41,6 +43,7 @@ export const EXTERNAL_ACTIONS = new Set(['external-redeem', ...EXTERNAL_SIGNED_A
|
|
|
41
43
|
export const INVITE_COMMANDS = new Set(['room-invite', 'room-invites', 'room-invite-revoke']);
|
|
42
44
|
const QUERY = /^(\?[A-Za-z0-9_.~%=&,:+-]*)?$/;
|
|
43
45
|
const SUB_PATH = /^[A-Za-z0-9_.~-]+(\/[A-Za-z0-9_.~-]+)*$/;
|
|
46
|
+
const MODEL_LIMIT = 120;
|
|
44
47
|
|
|
45
48
|
/** A shown text with the template and parameters a page translates by its own language (the backend's `error_text`). */
|
|
46
49
|
const text_of = (template, params = {}) => ({ error: t(template, params), error_text: { template, params } });
|
|
@@ -167,7 +170,7 @@ async function local_call(room, method, path, { token, body, external = false, s
|
|
|
167
170
|
|
|
168
171
|
/** When a membership chosen at the invite ends, in seconds as the local website keeps it. */
|
|
169
172
|
function membership_end(duration, now) {
|
|
170
|
-
if (duration
|
|
173
|
+
if (DURATION_DAYS[duration]) return Math.floor((now + DURATION_DAYS[duration] * DAY_MS) / 1000);
|
|
171
174
|
if (duration === 'today') {
|
|
172
175
|
const end = new Date(now);
|
|
173
176
|
end.setHours(23, 59, 59, 0);
|
|
@@ -201,7 +204,7 @@ export async function create_invite(home, { room_id, token, level = 'read', fold
|
|
|
201
204
|
folders = current.body.directories.map(path => room.directories.indexOf(path));
|
|
202
205
|
}
|
|
203
206
|
if (!LEVELS.has(level)) throw new GatewayError(400, '开放等级须为 discuss 或 read');
|
|
204
|
-
if (!DURATIONS.has(duration)) throw new GatewayError(400, '有效期须为 1h、today 或
|
|
207
|
+
if (!DURATIONS.has(duration)) throw new GatewayError(400, '有效期须为 1h、today、3d、7d 或 30d');
|
|
205
208
|
const chosen = level === 'discuss' ? [] : folders === undefined ? [0] : folders;
|
|
206
209
|
if (!Array.isArray(chosen) || (level === 'read' && !chosen.length) || chosen.some(index => !Number.isSafeInteger(index) || index < 0 || index >= room.directories.length)
|
|
207
210
|
|| new Set(chosen).size !== chosen.length) {
|
|
@@ -347,7 +350,7 @@ function external_name(platform, taken) {
|
|
|
347
350
|
* local website to add the external member, and the key is registered and published at once.
|
|
348
351
|
*/
|
|
349
352
|
async function redeem(home, ctx, id, sealed, request) {
|
|
350
|
-
const { public_key, proof, label, platform, adapter } = request.payload || {};
|
|
353
|
+
const { public_key, proof, label, platform, adapter, model } = request.payload || {};
|
|
351
354
|
let external_id;
|
|
352
355
|
try { external_id = device_id_of(public_key); } catch { throw new GatewayError(400, '外部成员公钥须为 P-256'); }
|
|
353
356
|
if (!await verify_signature(public_key, sealed.signature, `${id}\n${sealed.body}`)) throw new GatewayError(400, '外部成员签名无效', {}, 'bad_signature');
|
|
@@ -368,7 +371,8 @@ async function redeem(home, ctx, id, sealed, request) {
|
|
|
368
371
|
const token = createHmac('sha256', invite.code_hash).update(`seat-token-v1:${invite.invite_id}:${external_id}`).digest('hex');
|
|
369
372
|
const clean_label = String(label || '').replace(/[\u0000-\u001f]/g, ' ').trim().slice(0, LABEL_LIMIT);
|
|
370
373
|
const binding = { invite_version: invite.invite_version, token, machine: `ext:${external_id}`,
|
|
371
|
-
machine_label: clean_label, adapter: String(adapter || '').slice(0, 40),
|
|
374
|
+
machine_label: clean_label, adapter: String(adapter || '').slice(0, 40), platform, model: String(model || '').slice(0, MODEL_LIMIT),
|
|
375
|
+
expires_at: invite.member_expires_at };
|
|
372
376
|
const seat_path = `${base}/external-members/${invite.member_id}`;
|
|
373
377
|
const created = await local_call(room, 'POST', seat_path, { token: room.token, fetcher: ctx.fetcher,
|
|
374
378
|
body: { action: 'bind', ...binding } });
|
package/runner/free_runner.mjs
CHANGED
|
@@ -1084,7 +1084,7 @@ export class FreeRoomRunner {
|
|
|
1084
1084
|
on_binding: session => this.store.bind(member.name, session),
|
|
1085
1085
|
on_process: child => this.track(member.name, child, live()),
|
|
1086
1086
|
on_output: (path, chunk) => { appendFileSync(path, chunk, { mode: 0o600 }); this.touch(live()); this.segments.mark(live()); },
|
|
1087
|
-
on_activity: (phase, tool) => { worked = true; this.touch(live(), phase); this.segments.mark(live(), phase, tool); },
|
|
1087
|
+
on_activity: (phase, tool, call) => { worked = true; this.touch(live(), phase); this.segments.mark(live(), phase, tool, call); },
|
|
1088
1088
|
on_note: text => {
|
|
1089
1089
|
this.note(live(), text);
|
|
1090
1090
|
if (worked && current()) this.replies.set(live(), text);
|
package/runner/i18n_en.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** English CLI strings. */
|
|
2
2
|
export default {
|
|
3
3
|
"CLI 运行超过 {seconds} 秒仍未结束,已终止": "CLI exceeded the runtime limit of {seconds} seconds and was terminated",
|
|
4
|
-
"room-invite 创建待签到席位并签发邀请;提供 member_id 时重发该席位链接,旧链接失效。须提供 room_id、token,可选 level(discuss/read)、folders、duration(1h/today/3d)、site_url;程序先读名单 revision 再建席位。链接有效 10 分钟,未签到席位 7 天结束;未绑定线上站点时只建立席位。": "room-invite reserves a seat and issues an invitation; member_id regenerates that seat's link and invalidates the old one. Requires room_id and token; optional level (discuss/read), folders, duration (1h/today/3d), site_url. The runner reads the roster revision before creating a seat. Links last 10 minutes; unclaimed seats end after 7 days. Without a connected hosted site, only the seat is created.",
|
|
4
|
+
"room-invite 创建待签到席位并签发邀请;提供 member_id 时重发该席位链接,旧链接失效。须提供 room_id、token,可选 level(discuss/read)、folders、duration(1h/today/3d/7d/30d)、site_url;程序先读名单 revision 再建席位。链接有效 10 分钟,未签到席位 7 天结束;未绑定线上站点时只建立席位。": "room-invite reserves a seat and issues an invitation; member_id regenerates that seat's link and invalidates the old one. Requires room_id and token; optional level (discuss/read), folders, duration (1h/today/3d/7d/30d), site_url. The runner reads the roster revision before creating a seat. Links last 10 minutes; unclaimed seats end after 7 days. Without a connected hosted site, only the seat is created.",
|
|
5
5
|
"连不上 {host}:{seconds} 秒内没有响应,请检查这台电脑的网络或代理后重试": "Cannot connect to {host}: no response within {seconds} seconds. Check this computer's network or proxy and try again",
|
|
6
6
|
"连不上 {host}:连接被断开({reason}),请检查这台电脑的网络或代理后重试": "Cannot connect to {host}: the connection was closed ({reason}). Check this computer's network or proxy and try again",
|
|
7
7
|
"实例启动失败(退出码 {code})": "Instance failed to start (exit code {code})",
|
|
@@ -25,7 +25,7 @@ export default {
|
|
|
25
25
|
"已打开:{value1}": "Opened: {value1}",
|
|
26
26
|
"AI CoDiscuss 讨论服务\n服务目录:{value1}\n已登记 {value2} 个房间\nCtrl+C 停止服务\n": "AI CoDiscuss discussion service\nService folder: {value1}\n{value2} rooms registered\nCtrl+C to stop the service\n",
|
|
27
27
|
"尚未登记房间;可在另一终端运行 codiscuss service add --config FILE。\n": "No rooms registered yet. Run codiscuss service add --config FILE in another terminal.\n",
|
|
28
|
-
"用法:codiscuss admin <命令> [参数](与管理面板的操作一一对应;除启动与退出外,需管理面板正在运行)\n需要管理员权限的步骤(建或删 Windows 用户),在管理员终端或管理员的 SSH 会话里直接执行;否则在电脑桌面上弹出确认。\n\n启动与退出(不需要面板在运行)\n start 启动共议:服务、管理面板与任务栏图标、登录入口与隧道(在桌面会话里启动)\n stop 彻底退出:管理面板与图标、登录入口、隧道、共议服务;托管账号的实例照常运行\n restart stop 后 start\n update [check] 检查更新;不带 check 时安装最新版(面板未运行时先启动)并等待每一步结果\n\n本机\n status [--full] 概览:服务、版本、开机自启、登录入口、托管账号;--full 输出面板的完整状态\n service start|stop|restart 只启停共议服务(网站与讨论服务)\n autostart on|off 登录 Windows 时自动启动\n\n登录入口与访问方式(需打开托管管理)\n entry start|stop 启动或停止登录入口\n entry open|close relay|tunnel
|
|
28
|
+
"用法:codiscuss admin <命令> [参数](与管理面板的操作一一对应;除启动与退出外,需管理面板正在运行)\n需要管理员权限的步骤(建或删 Windows 用户),在管理员终端或管理员的 SSH 会话里直接执行;否则在电脑桌面上弹出确认。\n\n启动与退出(不需要面板在运行)\n start 启动共议:服务、管理面板与任务栏图标、登录入口与隧道(在桌面会话里启动)\n stop 彻底退出:管理面板与图标、登录入口、隧道、共议服务;托管账号的实例照常运行\n restart stop 后 start\n update [check] 检查更新;不带 check 时安装最新版(面板未运行时先启动)并等待每一步结果\n\n本机\n status [--full] 概览:服务、版本、开机自启、登录入口、托管账号;--full 输出面板的完整状态\n service start|stop|restart 只启停共议服务(网站与讨论服务)\n autostart on|off 登录 Windows 时自动启动\n\n管理员入口\n site status 本地网页与线上网站的地址\n site connect <站点> [绑定令牌] 绑定线上网站(管理员外出用);在部署该网站的电脑上可不填令牌\n site disconnect 解绑线上网站,已配对的设备不能再连到这台电脑\n\n登录入口与访问方式(需打开托管管理)\n entry start|stop 启动或停止登录入口\n entry open|close relay|tunnel 开启或关闭访问方式:线上网站 | 自有域名,两种可同时开启\n entry join <接入码> 用接入码接入线上站点并开启线上网站\n entry code [--config <wrangler.jsonc>] [--site <地址>] 在部署线上站点的电脑上生成接入码(不填用上次的)\n entry tunnel <域名> [隧道名] 设置自有域名(Cloudflare 隧道),输出授权链接;域名须已托管在 Cloudflare\n entry tunnel status 查看自有域名设置的进度\n runtime sync 同步隔离账号的程序副本\n\n托管账号\n account list\n account add <名> [--no-isolate] [--no-start] 创建、隔离、初始化 AI 环境、开启入口保护、启动;输出一次性密码。\n 中途失败时解决后重新执行同一命令,从缺少的步骤接着做\n account start|stop|disable|enable|remove|password <名>\n account isolate|unisolate|protect|unprotect <名>\n\n命令行登录(目标 owner 为管理员自己,否则为托管账号名)\n login status <目标> 各程序的登录状态,以及每个程序可用的登录方式\n login set <目标> <claude|codex> <方式> --set 字段=值 ... 如 login set alice claude setup_token --set token=sk-ant-oat01-…\n login start <目标> <程序> <方式> 浏览器登录:输出链接,之后用 login submit 提交授权码或回调地址\n login submit <作业> <文本> / login progress <作业> / login cancel <作业>\n logout <目标> <程序>\n\nAPI 密钥、技能、工作流、系统提示词(目标同上)\n key list <目标> / key add <目标> --base-url <地址> --key <密钥> / key remove <目标> <编号>\n skill library / skill import <文件夹或.zip> / skill delete <名>\n skill list <目标> / skill install <目标> <名>... / skill remove <目标> <名>...\n workflow list <目标> / workflow install <目标>\n prompt get <目标> / prompt set <目标> --file <文件> [--group <键>] 管理员的提示词按组保存(见 prompt get)\n prompt default get / prompt default set --file <文件> 新托管账号的默认系统提示词\n\n结果以 JSON 输出。--data 指定管理员服务目录(默认 ~/.codiscuss)。\n": "Usage: codiscuss admin <command> [arguments] (matches admin panel actions; the panel must be running except for start and stop)\nSteps requiring administrator rights (creating or deleting Windows users) run directly in an administrator terminal or administrator SSH session. Otherwise, approve the prompt on the computer's desktop.\n\nStart and exit (panel need not be running)\n start Start CoDiscuss: service, panel and tray icon, sign-in entry and tunnel (in the desktop session)\n stop Exit panel and tray icon, sign-in entry, tunnel and service; hosted instances keep running\n restart Run stop, then start\n update [check] Check for updates; omit check to install the latest version and wait for results (starts the panel if needed)\n\nLocal\n status [--full] Show service, version, startup, sign-in entry and hosted accounts; --full returns full panel state\n service start|stop|restart Start or stop only the CoDiscuss service (site and discussion service)\n autostart on|off Start automatically at Windows sign-in\n\nAdministrator entry\n site status Addresses of the local page and the online site\n site connect <site> [binding token] Bind the online site (to use this computer while away); the token is optional on the computer that deployed the site\n site disconnect Unbind the online site; paired devices can no longer reach this computer\n\nSign-in entry and access methods (hosting must be enabled)\n entry start|stop Start or stop the sign-in entry\n entry open|close relay|tunnel Turn an access method on or off: online site | own domain; both can be on\n entry join <code> Connect to an online site with an access code and turn on the online site\n entry code [--config <wrangler.jsonc>] [--site <address>] Generate an access code on the deployment computer (defaults to last settings)\n entry tunnel <domain> [tunnel-name] Configure a Cloudflare Tunnel and show the authorization link; domain must be hosted on Cloudflare\n entry tunnel status Show domain setup progress\n runtime sync Sync program copies for isolated accounts\n\nHosted accounts\n account list\n account add <name> [--no-isolate] [--no-start] Create, isolate, initialize AI environment, protect and start; show password once\n On failure, fix the cause and rerun the same command to resume missing steps\n account start|stop|disable|enable|remove|password <name>\n account isolate|unisolate|protect|unprotect <name>\n\nCLI sign-ins (target owner is the admin; otherwise use a hosted account name)\n login status <target> Show each app's sign-in status and available methods\n login set <target> <claude|codex> <method> --set field=value ... e.g. login set alice claude setup_token --set token=sk-ant-oat01-…\n login start <target> <app> <method> Browser sign-in: show a link; use login submit for the authorization code or callback URL\n login submit <job> <text> / login progress <job> / login cancel <job>\n logout <target> <app>\n\nAPI keys, skills, workflows and system prompts (same target convention)\n key list <target> / key add <target> --base-url <address> --key <key> / key remove <target> <id>\n skill library / skill import <folder-or.zip> / skill delete <name>\n skill list <target> / skill install <target> <name>... / skill remove <target> <name>...\n workflow list <target> / workflow install <target>\n prompt get <target> / prompt set <target> --file <file> [--group <key>] Admin prompts are saved by group (see prompt get)\n prompt default get / prompt default set --file <file> Default system prompt for new hosted accounts\n\nResults are JSON. --data sets the admin service folder (default ~/.codiscuss).\n",
|
|
29
29
|
"管理面板没有在运行:在这台电脑的桌面上运行 codiscuss panel open,或从任务栏图标打开": "The admin panel is not running. Run codiscuss panel open on this computer's desktop, or open it from the tray icon.",
|
|
30
30
|
"管理面板没有响应:在这台电脑的桌面上运行 codiscuss panel open": "The admin panel did not respond. Run codiscuss panel open on this computer's desktop.",
|
|
31
31
|
"管理面板拒绝了钥匙(面板可能刚重启):稍后重试": "The admin panel rejected the key (it may have just restarted). Try again shortly.",
|
|
@@ -86,7 +86,7 @@ export default {
|
|
|
86
86
|
"已更新本机技能": "Local skills updated",
|
|
87
87
|
"已启动本机服务": "Local service started",
|
|
88
88
|
"已重新启动登录入口": "Sign-in entry restarted",
|
|
89
|
-
"
|
|
89
|
+
"入口没有重新启动,在“概览 → 登录入口 → 托管账号入口”点“启动”看原因": "The entry did not restart. Click Start under Overview → Sign-in entry → Hosted account entry to see why.",
|
|
90
90
|
"已同步隔离账号的程序副本": "Program copies synced for isolated accounts",
|
|
91
91
|
"已更新 {value1} 的技能": "Skills updated for {value1}",
|
|
92
92
|
"已重启 {value1} 的实例": "Instance restarted for {value1}",
|
|
@@ -95,7 +95,7 @@ export default {
|
|
|
95
95
|
"这个账号开启了入口保护,但入口读不到它的密钥": "This account has entry protection enabled, but the entry cannot read its key",
|
|
96
96
|
"实例没有按入口保护启动起来(启动失败,或密钥对不上)": "Instance did not start with entry protection (startup failed or the key does not match)",
|
|
97
97
|
"实例没有启动起来": "Instance did not start",
|
|
98
|
-
"还没有安装隔离账号的程序副本,请先在“概览 →
|
|
98
|
+
"还没有安装隔离账号的程序副本,请先在“概览 → 登录入口 → 托管账号入口”中同步": "Program copies for isolated accounts are not installed yet. Sync them under Overview → Sign-in entry → Hosted account entry first.",
|
|
99
99
|
"没有读到结果": "No result received",
|
|
100
100
|
"技能库里没有 {value1}": "Skill library does not contain {value1}",
|
|
101
101
|
"未知操作:{value1}": "Unknown action: {value1}",
|
|
@@ -104,7 +104,7 @@ export default {
|
|
|
104
104
|
"入口保护目前只支持 Windows": "Entry protection currently supports Windows only",
|
|
105
105
|
"无法确认实例是否在运行(端口没有回应),入口保护没有改动": "Cannot confirm whether the instance is running (port did not respond); entry protection was not changed",
|
|
106
106
|
"实例没有停下来,入口保护没有改动": "The instance did not stop; entry protection was not changed",
|
|
107
|
-
"外网访问已开启,{value1}
|
|
107
|
+
"外网访问已开启,{value1} 未隔离(以你的身份运行),不能启动:请先隔离该账号,或关闭登录入口的线上网站和自有域名": "Remote access is enabled, but {value1} is not isolated (runs as you) and cannot start. Isolate it first, or turn off the sign-in entry's online site and own domain.",
|
|
108
108
|
"启动": "start",
|
|
109
109
|
"停止": "stop",
|
|
110
110
|
"实例{value1}失败(退出码 {value2})": "Instance {value1} failed (exit code {value2})",
|
|
@@ -131,15 +131,19 @@ export default {
|
|
|
131
131
|
"登录入口没有在运行:点上面的“启动”": "The sign-in entry is not running. Click Start above.",
|
|
132
132
|
"这台电脑还没有接入线上站点:先用接入码接入": "This computer has not connected to an online site. Connect with an access code first.",
|
|
133
133
|
"还没有设好 Cloudflare 隧道:先点“设置”填写你的域名": "Cloudflare Tunnel is not configured yet. Click Configure and enter your domain first.",
|
|
134
|
-
"未隔离的账号正在运行({value1}
|
|
134
|
+
"未隔离的账号正在运行({value1}),它们以你的身份运行,开启线上网站或自有域名前请先停止或隔离": "Accounts without isolation are running ({value1}). They run as you; stop or isolate them before turning on the online site or your own domain.",
|
|
135
135
|
"未知的访问方式:{value1}": "Unknown access method: {value1}",
|
|
136
|
+
"v{value1} 刚发布,npm 还在准备安装包,请过几分钟再更新;当前版本和服务没有受影响": "v{value1} was just published and npm is still preparing its package. Try updating again in a few minutes; the current version and services were not affected.",
|
|
136
137
|
"找不到线上站点的部署配置:填写源码仓库里 .wrangler\\deploy\\wrangler.jsonc 的完整路径": "Online site deployment config not found. Enter the full path to .wrangler\\deploy\\wrangler.jsonc in the source repository.",
|
|
137
138
|
"站点地址格式不对,例如 https://xxx.pages.dev": "Invalid site address, e.g. https://xxx.pages.dev",
|
|
138
139
|
"没有生成绑定令牌": "No binding token generated",
|
|
139
140
|
"接入码不对:应是部署线上站点的电脑上生成的一整串,形如 https://xxx.pages.dev/#codiscuss-bind=…": "Invalid access code. Use the full string generated on the online site's deployment computer, such as https://xxx.pages.dev/#codiscuss-bind=…",
|
|
140
141
|
"已接入 {value1}": "Connected to {value1}",
|
|
141
142
|
"入口地址 {value1}": "Entry address: {value1}",
|
|
142
|
-
"
|
|
143
|
+
"这台电脑已绑定 {value1},请先解绑": "This computer is already bound to {value1}. Unbind it first",
|
|
144
|
+
"这个地址不是共议线上站点:{value1}": "This address is not a CoDiscuss online site: {value1}",
|
|
145
|
+
"托管账号入口的线上网站还开着,请先关闭它": "The hosted accounts' online site is still on. Turn it off first",
|
|
146
|
+
"已开启线上网站": "Online site turned on",
|
|
143
147
|
"{value1} 没有提供入口地址:请部署线上站点的人在部署配置里设置 ENTRY_URL 并重新发布": "{value1} did not provide an entry address. Ask the site deployer to set ENTRY_URL in the deployment config and redeploy.",
|
|
144
148
|
"{value1} 不是共议的入口 Worker,或现在连不上": "{value1} is not a CoDiscuss entry Worker, or is currently unreachable",
|
|
145
149
|
"绑定失败(退出码 {value1})": "Binding failed (exit code {value1})",
|
|
@@ -456,7 +460,7 @@ export default {
|
|
|
456
460
|
" 待确认 {approval}:消息 {messages}": " Pending {approval}: messages {messages}",
|
|
457
461
|
" 已退出": " Left",
|
|
458
462
|
"还没有被邀请的房间": "No invited rooms yet",
|
|
459
|
-
"
|
|
463
|
+
"暂时连不上对方电脑,常驻服务会继续通知它;通知送达或成员资格到期后删除本机密钥": "The other computer cannot be reached right now. The background service will keep telling it, and deletes the key here once it hears or the membership expires",
|
|
460
464
|
"读不到对方房间:{reason}": "Cannot read the other room: {reason}",
|
|
461
465
|
"该文件属于固定排除的敏感文件,不能读取": "This file is a fixed-excluded sensitive file and cannot be read",
|
|
462
466
|
"不在对方开放的范围内(或不存在)": "Not within what the other side opened (or does not exist)",
|
|
@@ -482,7 +486,7 @@ export default {
|
|
|
482
486
|
"成员凭据与外部成员不符": "The member credential does not match this external member",
|
|
483
487
|
"房间已不在这台电脑上": "The room is no longer on this computer",
|
|
484
488
|
"无法确认读取授权": "Could not confirm read permission",
|
|
485
|
-
"有效期须为 1h、today 或
|
|
489
|
+
"有效期须为 1h、today、3d、7d 或 30d": "The duration must be 1h, today, 3d, 7d or 30d",
|
|
486
490
|
"未知的邀请操作": "Unknown invite operation",
|
|
487
491
|
"该操作不对外部成员开放": "This operation is not available to external members",
|
|
488
492
|
"请求同时带有设备与外部成员签名": "The request carries both a device and an external member signature",
|
package/runner/os_users.mjs
CHANGED
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { spawnSync } from 'node:child_process';
|
|
15
15
|
import { randomBytes } from 'node:crypto';
|
|
16
|
-
import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
17
17
|
import { homedir, tmpdir } from 'node:os';
|
|
18
18
|
import { basename, dirname, join } from 'node:path';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
20
|
|
|
21
|
+
import { NO_DESKTOP_VARIABLE } from './adapters/profiles.mjs';
|
|
22
|
+
|
|
21
23
|
const USERS_FILE = 'os-users.json';
|
|
22
24
|
const USER_PREFIX = 'cd-';
|
|
23
25
|
// Windows local user names are at most 20 characters.
|
|
@@ -463,13 +465,22 @@ export function install_shared_runtime(python_source = '', { run = run_powershel
|
|
|
463
465
|
return { installed, missing, warnings };
|
|
464
466
|
}
|
|
465
467
|
|
|
466
|
-
/**
|
|
468
|
+
/** The AI programs the owner upgraded after the shared copy was made: they update themselves, apart from this program. */
|
|
469
|
+
export function outdated_programs(clis = cli_sources()) {
|
|
470
|
+
const modified = path => { try { return statSync(path).mtimeMs; } catch { return 0; } };
|
|
471
|
+
return Object.values(clis).filter(cli => {
|
|
472
|
+
const copy = modified(cli.executable || cli.target);
|
|
473
|
+
return copy > 0 && modified(cli.program || cli.source) > copy;
|
|
474
|
+
}).map(cli => cli.label);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** Which shared programs are installed ({ claude, codex, agy, app, python } booleans), the shared program's version, and which are behind. */
|
|
467
478
|
export function shared_cli_state() {
|
|
468
479
|
const paths = shared_paths();
|
|
469
480
|
let app_version = '';
|
|
470
481
|
try { app_version = JSON.parse(readFileSync(join(APP_ROOT, 'package.json'), 'utf8')).version; } catch { /* not installed */ }
|
|
471
482
|
return { ...Object.fromEntries(Object.entries(cli_sources()).map(([key, cli]) => [key, existsSync(cli.executable || cli.target)])),
|
|
472
|
-
app: existsSync(paths.local_script), python: existsSync(paths.python), app_version };
|
|
483
|
+
app: existsSync(paths.local_script), python: existsSync(paths.python), app_version, outdated: outdated_programs() };
|
|
473
484
|
}
|
|
474
485
|
|
|
475
486
|
// ---- The instance of an account with its own Windows user: a scheduled task ----
|
|
@@ -573,6 +584,7 @@ export function start_instance_as_user(data, account, service_home, local_script
|
|
|
573
584
|
if (-not (Test-Path -LiteralPath $flag)) { exit 0 }
|
|
574
585
|
$env:DISCUSS_SERVICE_HOME = ${quote(service_home)}
|
|
575
586
|
$env:Path = ${quote(`${COMMAND_ROOT};`)} + $env:Path
|
|
587
|
+
$env:${NO_DESKTOP_VARIABLE} = '1'
|
|
576
588
|
${key_file ? `$env:DISCUSS_ENTRY_KEY_FILE = ${quote(key_file)}\n` : ''}Set-Location -LiteralPath ${quote(service_home)}
|
|
577
589
|
& ${quote(node)} ${quote(local_script)} run
|
|
578
590
|
exit $LASTEXITCODE
|
package/runner/project_files.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { closeSync, fstatSync, openSync, readdirSync, readFileSync, readSync, realpathSync, statSync } from 'node:fs';
|
|
4
4
|
import { isAbsolute, posix, relative, resolve } from 'node:path';
|
|
5
|
-
import { adapter_profile } from './adapters/profiles.mjs';
|
|
5
|
+
import { adapter_capabilities, adapter_profile } from './adapters/profiles.mjs';
|
|
6
6
|
import { PINYIN_TABLE } from './pinyin_table.mjs';
|
|
7
7
|
|
|
8
8
|
const DIRECTORY_PAGE_SIZE = 200;
|
|
@@ -184,12 +184,13 @@ export function outside_directory(config, profile) {
|
|
|
184
184
|
/**
|
|
185
185
|
* Whether the room's directories stay read-only for this member by the software's own limits, not only by its task
|
|
186
186
|
* text: at 只读 for any software whose levels the runner sets, at 可写 only where a sandbox or the file tools hold
|
|
187
|
-
* (`limits_directories`); never for an App, a manual member's own permissions,
|
|
187
|
+
* (`limits_directories`); never for an App, a manual member's own permissions, 自动, 全放开 or software running without
|
|
188
|
+
* its sandbox here (`no_sandbox`).
|
|
188
189
|
*/
|
|
189
190
|
export function read_only_enforced(profile) {
|
|
190
|
-
const facts = adapter_profile(profile?.adapter);
|
|
191
|
-
if (!facts?.access_levels) return false;
|
|
192
|
-
return profile.project_access === 'read' || (profile.project_access === 'write' && Boolean(
|
|
191
|
+
const facts = adapter_profile(profile?.adapter), capabilities = adapter_capabilities(profile?.adapter);
|
|
192
|
+
if (!facts?.access_levels || capabilities.no_sandbox) return false;
|
|
193
|
+
return profile.project_access === 'read' || (profile.project_access === 'write' && Boolean(capabilities.limits_directories));
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
/** The room's project root, resolved through links and required to be a folder. */
|
package/runner/tts_providers.mjs
CHANGED
|
@@ -55,6 +55,16 @@ const LOCAL_HOST = '127.0.0.1';
|
|
|
55
55
|
const LOCAL_KEY_URL = 'http://127.0.0.1/yovoice';
|
|
56
56
|
const LOCAL_LEGACY_KEY_URL = 'http://127.0.0.1:18765';
|
|
57
57
|
const LOCAL_MODEL = 'qwen3-tts-customvoice-q8';
|
|
58
|
+
// Optional second model: VoxCPM2 has no built-in speakers, so each voice is a fixed description, and the fixed seed keeps
|
|
59
|
+
// the voice from drifting between the paragraphs of one reading.
|
|
60
|
+
const LOCAL_DESIGN_MODEL = 'voxcpm2-bf16';
|
|
61
|
+
const LOCAL_DESIGN_SEED = 42;
|
|
62
|
+
const LOCAL_DESIGNED_VOICES = {
|
|
63
|
+
voxcpm2_soft_female: '成年女性有声书朗读者,声音柔和沉静,语速偏慢,语调平缓,情绪起伏很小,自然松弛,不表演不夸张',
|
|
64
|
+
voxcpm2_low_female: '中年女性有声书朗读者,声线略低,从容平稳,语速偏慢,语气淡然,情绪起伏很小,不表演不夸张',
|
|
65
|
+
voxcpm2_elderly_male: '六十多岁的老年男性,嗓音低沉略带沙哑,说话很慢,像老人在家里平平淡淡地回忆往事,朴素自然,没有播音腔',
|
|
66
|
+
voxcpm2_middle_aged_male: '五十岁左右的普通中年男性,声音低沉厚实,说话很慢,语气平淡朴实,像和熟人闲聊,没有播音腔,不像短视频解说',
|
|
67
|
+
};
|
|
58
68
|
const LOCAL_DIR = 'yovoice';
|
|
59
69
|
const LOCAL_START_MS = 30_000;
|
|
60
70
|
const LOCAL_POLL_MS = 500;
|
|
@@ -127,6 +137,8 @@ const LOCAL_VOICES = [
|
|
|
127
137
|
['Vivian', 'Vivian · 明亮女声'], ['Serena', 'Serena · 温柔女声'], ['Uncle_Fu', 'Uncle Fu · 低沉男声'],
|
|
128
138
|
['Dylan', 'Dylan · 北京青年男声'], ['Eric', 'Eric · 成都男声'], ['Ryan', 'Ryan · 英语男声'], ['Aiden', 'Aiden · 美式男声'],
|
|
129
139
|
['Ono_Anna', 'Ono Anna · 日语女声'], ['Sohee', 'Sohee · 韩语女声'],
|
|
140
|
+
['voxcpm2_soft_female', 'VoxCPM2 · 柔和女声 / Soft female'], ['voxcpm2_low_female', 'VoxCPM2 · 低声线女声 / Low female'],
|
|
141
|
+
['voxcpm2_elderly_male', 'VoxCPM2 · 老年男声 / Elderly male'], ['voxcpm2_middle_aged_male', 'VoxCPM2 · 中年男声 / Middle-aged male'],
|
|
130
142
|
];
|
|
131
143
|
// gpt-4o-mini-tts's built-in voices; the docs call them optimized for English and recommend marin or cedar.
|
|
132
144
|
const OPENAI_VOICES = [
|
|
@@ -314,11 +326,18 @@ export function wav_with_silence(wav, silence_ms) {
|
|
|
314
326
|
return result;
|
|
315
327
|
}
|
|
316
328
|
|
|
317
|
-
/**
|
|
329
|
+
/** The generation request for a voice; a designed voice's description replaces the tone instruction. */
|
|
330
|
+
function local_generation(text, speaker, context) {
|
|
331
|
+
const design = LOCAL_DESIGNED_VOICES[speaker];
|
|
332
|
+
if (design) return { text, modelId: LOCAL_DESIGN_MODEL, voxMode: 'design', voiceDescription: design, language: 'zh', seed: LOCAL_DESIGN_SEED };
|
|
333
|
+
return { text, modelId: LOCAL_MODEL, speaker, language: 'zh', ...(context ? { voiceDescription: context } : {}) };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Ask the local service for one paragraph; the answer is a mono WAV (24 kHz from Qwen3-TTS, 48 kHz from VoxCPM2). */
|
|
318
337
|
function local_generate({ home, key, text, speaker, context }, request) {
|
|
319
338
|
return request(`${local_url(home, 'tts')}/v1/generate`, { method: 'POST', redirect: 'error', signal: AbortSignal.timeout(TTS_TIMEOUT_MS),
|
|
320
339
|
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' },
|
|
321
|
-
body: JSON.stringify(
|
|
340
|
+
body: JSON.stringify(local_generation(text, speaker, context)) });
|
|
322
341
|
}
|
|
323
342
|
|
|
324
343
|
/**
|
|
@@ -432,6 +451,7 @@ async function local_once({ home, key, text, speaker, context, silence }, { requ
|
|
|
432
451
|
if (response.status === 409) throw new Error('本机语音一直在忙,请稍后再试');
|
|
433
452
|
if (!response.ok) {
|
|
434
453
|
const code = (await response.json().catch(() => ({}))).error?.code;
|
|
454
|
+
if (code === '@yovoice.error.modelRequired') throw new Error('这个音色的模型尚未安装:请让本机 AI 按 local-tts-setup 技能安装');
|
|
435
455
|
throw new Error(`本机语音合成失败(HTTP ${response.status}${code ? ` ${code}` : ''}),请查看 ${join(home, LOCAL_DIR, 'data', 'logs')}`);
|
|
436
456
|
}
|
|
437
457
|
const audio = await convert(home, wav_with_silence(Buffer.from(await response.arrayBuffer()), silence));
|