ai_co_discuss 0.4.13 → 0.4.16
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-host/SKILL.md +42 -42
- package/.agents/skills/workflow-creator/SKILL.md +155 -155
- package/.agents/skills/workflow-creator/references/model-selection.md +24 -23
- package/backend/free_room.py +15 -8
- package/backend/schema.sql +3 -1
- package/backend/server.py +146 -17
- package/docs/THIRD_PARTY_NOTICES.md +721 -1
- package/docs/runner.md +4 -2
- package/docs/workflow.md +1 -1
- package/package.json +10 -3
- package/runner/adapters/api.mjs +33 -7
- package/runner/adapters/api_files.mjs +21 -0
- package/runner/adapters/api_images.mjs +245 -0
- package/runner/adapters/index.mjs +186 -186
- package/runner/adapters/profiles.mjs +152 -139
- package/runner/discussion_launch.mjs +49 -11
- package/runner/free_runner.mjs +1286 -1281
- package/runner/project_files.mjs +390 -330
- package/runner/relay_channel.mjs +326 -325
- package/runner/remote_launch.mjs +2 -2
- package/runner/stt.mjs +135 -111
- package/runner/tts.mjs +180 -172
- package/runner/tts_providers.mjs +479 -435
- package/runner/workflows.mjs +606 -606
- package/web/app.js +82 -12
- package/web/backup.js +1 -1
- package/web/markdown.css +1 -1
- package/web/modern.css +1 -1
- package/web/modern.js +663 -40
- package/web/office/assets/pptx-source-worker-559Vl2R3.mjs +446 -0
- package/web/office/assets/pptx_parser_bg-DON650C_.wasm +0 -0
- package/web/office/assets/render-worker-Ck21oePL-D_L2C4am.js +16 -0
- package/web/office/chunks/comment-ui-runtime-Bp37ytDC-CEDIeFBy.js +125 -0
- package/web/office/chunks/emf--QWY-UlT-D7lCNost.js +1 -0
- package/web/office/chunks/font-preload-demand-NqcVKIpX-_QhVEaPJ.js +1 -0
- package/web/office/chunks/plot-area-frame-DNYMd9Pf-B0ScWz_J.js +2 -0
- package/web/office/chunks/pptx-DbjWegUB-CU8ZIJEP.js +4 -0
- package/web/office/chunks/presentation-model-source-DLNioq7T-Demo5cCW.js +1 -0
- package/web/office/chunks/render-worker-host-CVr53kg0-DUcW76F6.js +1 -0
- package/web/office/chunks/slide-pull-client-3g6TxaKa-BohMnKOC.js +12 -0
- package/web/office/chunks/worker-source-ZQE9C1j6-B31UTbq3.js +1 -0
- package/web/office/docx.js +21 -0
- package/web/office/pptx.js +1 -0
- package/web/office/xlsx.js +64 -0
package/runner/remote_launch.mjs
CHANGED
|
@@ -29,9 +29,9 @@ const RELAY_CIPHER_INFO = 'codiscuss-relay-v1';
|
|
|
29
29
|
const LAUNCH_SCRIPT = fileURLToPath(new URL('./discussion_launch.mjs', import.meta.url));
|
|
30
30
|
// What a connected browser may ask the local bridge for, minus the folder dialog nobody would see and pairing itself.
|
|
31
31
|
const RELAYED_ACTIONS = new Set(['settings', 'launch', 'room-models', 'room-member', 'room-member-access', 'room-member-allow', 'room-member-adapter',
|
|
32
|
-
'room-member-model', 'room-profiles', 'room-files', 'room-page', 'execution-details', 'room-restore', 'room-fork', 'models', 'api-key', 'api-check', 'scheduler-check', 'tts-settings', 'tts', 'tts-release', 'stt', 'weixin', 'projects', 'presets', 'workflows', 'room-workflow', 'room-settings', 'browse-directory']);
|
|
32
|
+
'room-member-model', 'room-profiles', 'room-files', 'room-page', 'room-media', 'execution-details', 'room-restore', 'room-fork', 'models', 'api-key', 'api-check', 'scheduler-check', 'tts-settings', 'tts', 'tts-release', 'stt', 'weixin', 'projects', 'presets', 'workflows', 'room-workflow', 'room-settings', 'browse-directory']);
|
|
33
33
|
export const ROOM_ACTIONS = new Set(['launch', 'room-models', 'room-member', 'room-member-access', 'room-member-allow', 'room-member-adapter',
|
|
34
|
-
'room-member-model', 'room-profiles', 'room-files', 'room-page', 'execution-details', 'room-restore', 'room-fork', 'room-workflow', 'room-settings', 'workflows']);
|
|
34
|
+
'room-member-model', 'room-profiles', 'room-files', 'room-page', 'room-media', 'execution-details', 'room-restore', 'room-fork', 'room-workflow', 'room-settings', 'workflows']);
|
|
35
35
|
|
|
36
36
|
// On Windows the file holding this computer's private keys and tokens is sealed with DPAPI for the signed-in user, so a
|
|
37
37
|
// copy of the file alone is useless elsewhere; other systems rely on the file's 0600 mode.
|
package/runner/stt.mjs
CHANGED
|
@@ -1,111 +1,135 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Voice input: the page records 16 kHz mono PCM and sends it in small parts (each fits one relayed request);
|
|
3
|
-
* the last part assembles a WAV file and the voice-input service chosen in settings turns it into text: Volcengine's
|
|
4
|
-
* flash recognizer, or the recognizer on this computer (`local_transcribe`). Keys stay local.
|
|
5
|
-
*/
|
|
6
|
-
import { randomUUID } from 'node:crypto';
|
|
7
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
8
|
-
import { join } from 'node:path';
|
|
9
|
-
|
|
10
|
-
import { read_saved_api_key } from './discussion_api.mjs';
|
|
11
|
-
import { TTS_BASE_URL, tts_settings } from './tts.mjs';
|
|
12
|
-
import { local_transcribe, STT_PROVIDERS } from './tts_providers.mjs';
|
|
13
|
-
|
|
14
|
-
const STT_ENDPOINT = `${TTS_BASE_URL}/api/v3/auc/bigmodel/recognize/flash`;
|
|
15
|
-
// The console's “录音文件识别2.0” grants this resource; it answers on the flash route (verified 2026-11-03). The 1.0
|
|
16
|
-
// flash resource `volc.bigasr.auc_turbo` is a separate product and is refused with 45000030 when only 2.0 is enabled.
|
|
17
|
-
const STT_RESOURCE_ID = 'volc.seedasr.auc';
|
|
18
|
-
const STT_DONE_CODE = '20000000';
|
|
19
|
-
const STT_SILENT_CODE = '20000003';
|
|
20
|
-
const STT_TIMEOUT_MS = 50_000;
|
|
21
|
-
const SAMPLE_RATE = 16000;
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
header
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Voice input: the page records 16 kHz mono PCM and sends it in small parts (each fits one relayed request);
|
|
3
|
+
* the last part assembles a WAV file and the voice-input service chosen in settings turns it into text: Volcengine's
|
|
4
|
+
* flash recognizer, OpenAI's transcription, or the recognizer on this computer (`local_transcribe`). Keys stay local.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { read_saved_api_key } from './discussion_api.mjs';
|
|
11
|
+
import { TTS_BASE_URL, tts_settings } from './tts.mjs';
|
|
12
|
+
import { local_transcribe, STT_PROVIDERS } from './tts_providers.mjs';
|
|
13
|
+
|
|
14
|
+
const STT_ENDPOINT = `${TTS_BASE_URL}/api/v3/auc/bigmodel/recognize/flash`;
|
|
15
|
+
// The console's “录音文件识别2.0” grants this resource; it answers on the flash route (verified 2026-11-03). The 1.0
|
|
16
|
+
// flash resource `volc.bigasr.auc_turbo` is a separate product and is refused with 45000030 when only 2.0 is enabled.
|
|
17
|
+
const STT_RESOURCE_ID = 'volc.seedasr.auc';
|
|
18
|
+
const STT_DONE_CODE = '20000000';
|
|
19
|
+
const STT_SILENT_CODE = '20000003';
|
|
20
|
+
const STT_TIMEOUT_MS = 50_000;
|
|
21
|
+
const SAMPLE_RATE = 16000;
|
|
22
|
+
// OpenAI's transcription (2026-11-10 docs): gpt-transcribe is the recommended model; it and the others shut down on
|
|
23
|
+
// 2027-02-26. `languages` lists the languages the speech may be in; both forms of the array field were accepted.
|
|
24
|
+
const OPENAI_MODEL = 'gpt-transcribe';
|
|
25
|
+
const OPENAI_LANGUAGES = ['zh', 'en'];
|
|
26
|
+
// About 5 minutes of 16-bit mono audio at 16 kHz.
|
|
27
|
+
export const STT_MAX_BYTES = 10 * 1024 * 1024;
|
|
28
|
+
const PART_MAX_BYTES = 256 * 1024;
|
|
29
|
+
const STALE_MS = 60 * 60 * 1000;
|
|
30
|
+
const STATUS_MESSAGES = {
|
|
31
|
+
45000001: '请求参数有误',
|
|
32
|
+
45000002: '没有录到声音',
|
|
33
|
+
45000030: '火山引擎未授权该识别服务:请在控制台开通「录音文件识别2.0」',
|
|
34
|
+
45000151: '音频格式不受支持',
|
|
35
|
+
55000031: '火山引擎语音识别繁忙,请稍后再试',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Prefix raw 16-bit mono PCM with a WAV header. */
|
|
39
|
+
export function pcm_to_wav(pcm) {
|
|
40
|
+
const header = Buffer.alloc(44);
|
|
41
|
+
header.write('RIFF', 0); header.writeUInt32LE(36 + pcm.length, 4); header.write('WAVE', 8);
|
|
42
|
+
header.write('fmt ', 12); header.writeUInt32LE(16, 16); header.writeUInt16LE(1, 20); header.writeUInt16LE(1, 22);
|
|
43
|
+
header.writeUInt32LE(SAMPLE_RATE, 24); header.writeUInt32LE(SAMPLE_RATE * 2, 28); header.writeUInt16LE(2, 32); header.writeUInt16LE(16, 34);
|
|
44
|
+
header.write('data', 36); header.writeUInt32LE(pcm.length, 40);
|
|
45
|
+
return Buffer.concat([header, pcm]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Drop recordings abandoned mid-way (closed page, lost connection). */
|
|
49
|
+
function clean_stale(directory) {
|
|
50
|
+
if (!existsSync(directory)) return;
|
|
51
|
+
for (const name of readdirSync(directory)) {
|
|
52
|
+
const path = join(directory, name);
|
|
53
|
+
try { if (Date.now() - statSync(path).mtimeMs > STALE_MS) rmSync(path, { recursive: true, force: true }); } catch { /* Gone already. */ }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Send a finished recording to the recognizer and return its text. */
|
|
58
|
+
async function recognize(key, wav, request) {
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = await request(STT_ENDPOINT, { method: 'POST', redirect: 'error', signal: AbortSignal.timeout(STT_TIMEOUT_MS),
|
|
62
|
+
headers: { 'Content-Type': 'application/json', 'X-Api-Key': key, 'X-Api-Resource-Id': STT_RESOURCE_ID,
|
|
63
|
+
'X-Api-Request-Id': randomUUID(), 'X-Api-Sequence': '-1' },
|
|
64
|
+
body: JSON.stringify({ user: { uid: 'codiscuss' }, audio: { data: wav.toString('base64') }, request: { model_name: 'bigmodel', enable_punc: true, enable_itn: true } }) });
|
|
65
|
+
} catch { throw new Error('语音识别请求超时或连接失败,请检查网络后重试'); }
|
|
66
|
+
const code = response.headers.get('X-Api-Status-Code');
|
|
67
|
+
if ((response.status === 401 || response.status === 403) && !STATUS_MESSAGES[code]) throw new Error('火山引擎拒绝了请求:API Key 无效或未开通录音文件识别 2.0');
|
|
68
|
+
if (code === STT_SILENT_CODE) return '';
|
|
69
|
+
if (code !== STT_DONE_CODE) {
|
|
70
|
+
const message = STATUS_MESSAGES[code] || response.headers.get('X-Api-Message') || `HTTP ${response.status}`;
|
|
71
|
+
throw new Error(`语音识别失败(${code || response.status}):${message}`);
|
|
72
|
+
}
|
|
73
|
+
const data = await response.json();
|
|
74
|
+
return String(data?.result?.text || '').trim();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Send a finished recording to OpenAI's transcription and return its text. */
|
|
78
|
+
async function openai_transcribe(base_url, key, wav, request) {
|
|
79
|
+
const form = new FormData();
|
|
80
|
+
form.append('file', new Blob([wav], { type: 'audio/wav' }), 'speech.wav');
|
|
81
|
+
form.append('model', OPENAI_MODEL);
|
|
82
|
+
for (const language of OPENAI_LANGUAGES) form.append('languages[]', language);
|
|
83
|
+
let response;
|
|
84
|
+
try {
|
|
85
|
+
response = await request(`${base_url}/audio/transcriptions`, { method: 'POST', redirect: 'error', signal: AbortSignal.timeout(STT_TIMEOUT_MS),
|
|
86
|
+
headers: { Authorization: `Bearer ${key}` }, body: form });
|
|
87
|
+
} catch { throw new Error('语音识别请求超时或连接失败:请检查这台电脑能否访问 api.openai.com 后重试'); }
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
const reason = await response.json().then(body => body?.error?.message || '', () => '');
|
|
90
|
+
if (response.status === 401) throw new Error('OpenAI 拒绝了 API Key:请在设置的“语音”中更换');
|
|
91
|
+
throw new Error(`语音识别失败:OpenAI 返回 HTTP ${response.status}${reason ? `:${reason}` : ''}`);
|
|
92
|
+
}
|
|
93
|
+
return String((await response.json())?.text || '').trim();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Store one part of a recording; the final part recognizes the whole recording and returns its text.
|
|
98
|
+
* @param {string} home Local service directory.
|
|
99
|
+
* @param {{ upload_id: string, index: number, data: string, final?: boolean }} input Base64 PCM part in order.
|
|
100
|
+
* @param {Function} [request] `fetch`, replaceable in tests.
|
|
101
|
+
* @param {Function} [start] Starts the local recognizer, replaceable in tests.
|
|
102
|
+
* @returns {Promise<{ received: number } | { text: string }>}
|
|
103
|
+
*/
|
|
104
|
+
export async function stt_part(home, input, request = fetch, start = undefined) {
|
|
105
|
+
const { upload_id, index, data, final } = input || {};
|
|
106
|
+
if (!/^[a-f0-9-]{36}$/i.test(upload_id || '') || !Number.isInteger(index) || index < 0 || typeof data !== 'string') throw new Error('录音片段无效');
|
|
107
|
+
const settings = tts_settings(home);
|
|
108
|
+
const service = STT_PROVIDERS.find(item => item.id === settings.stt_provider);
|
|
109
|
+
if (!settings.stt_key_ref) throw new Error(service.local ? '本机语音识别尚未安装:请让本机 AI 按 local-stt-setup 技能安装'
|
|
110
|
+
: `语音输入使用${service.label}:请在设置的“语音”中填写${service.label} API Key`);
|
|
111
|
+
const part = Buffer.from(data, 'base64');
|
|
112
|
+
if (part.length > PART_MAX_BYTES || part.length % 2) throw new Error('录音片段无效');
|
|
113
|
+
const root = join(home, 'stt');
|
|
114
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
115
|
+
clean_stale(root);
|
|
116
|
+
const directory = join(root, upload_id.toLowerCase());
|
|
117
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
118
|
+
writeFileSync(join(directory, `${index}.pcm`), part, { mode: 0o600 });
|
|
119
|
+
if (!final) return { received: index };
|
|
120
|
+
try {
|
|
121
|
+
const parts = [];
|
|
122
|
+
for (let position = 0; position <= index; position += 1) {
|
|
123
|
+
const path = join(directory, `${position}.pcm`);
|
|
124
|
+
if (!existsSync(path)) throw new Error('录音片段缺失,请重新录制');
|
|
125
|
+
parts.push(readFileSync(path));
|
|
126
|
+
}
|
|
127
|
+
const pcm = Buffer.concat(parts);
|
|
128
|
+
if (pcm.length > STT_MAX_BYTES) throw new Error('录音超过 5 分钟,请分段录制');
|
|
129
|
+
if (!pcm.length) return { text: '' };
|
|
130
|
+
const key = read_saved_api_key(home, service.key_base_url, settings.stt_key_ref);
|
|
131
|
+
if (service.local) return { text: await local_transcribe({ home, key, wav: pcm_to_wav(pcm) }, { request, ...(start ? { start } : {}) }) };
|
|
132
|
+
if (service.id === 'openai') return { text: await openai_transcribe(service.key_base_url, key, pcm_to_wav(pcm), request) };
|
|
133
|
+
return { text: await recognize(key, pcm_to_wav(pcm), request) };
|
|
134
|
+
} finally { rmSync(directory, { recursive: true, force: true }); }
|
|
135
|
+
}
|