dictawhisper 0.0.13 → 0.0.14
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/README.md +10 -2
- package/bin/dictawhisper.mjs +14 -0
- package/config.example.json +41 -0
- package/dist/ui/_app/immutable/assets/0.C6M3gHo0.css +1 -0
- package/dist/ui/_app/immutable/assets/2.C96vgj_4.css +1 -0
- package/dist/ui/_app/immutable/chunks/BSs9MmST.js +3 -0
- package/dist/ui/_app/immutable/chunks/Bjy-W4x2.js +81 -0
- package/dist/ui/_app/immutable/chunks/BslYtab-.js +1 -0
- package/dist/ui/_app/immutable/chunks/xihTtKlq.js +1 -0
- package/dist/ui/_app/immutable/entry/app.BJlRju4c.js +2 -0
- package/dist/ui/_app/immutable/entry/start.C5XBbXTT.js +1 -0
- package/dist/ui/_app/immutable/nodes/0.D23pkrHr.js +1 -0
- package/dist/ui/_app/immutable/nodes/1.C5T-U4uV.js +1 -0
- package/dist/ui/_app/immutable/nodes/2.59uAq_ko.js +5 -0
- package/dist/ui/_app/version.json +1 -0
- package/dist/ui/favicon.png +0 -0
- package/dist/ui/favicon.svg +3 -0
- package/dist/ui/index.html +38 -0
- package/dist/ui/logo.png +0 -0
- package/package.json +12 -3
- package/scripts/transcribe_faster_whisper.py +428 -0
- package/src/apiRoutes.ts +464 -0
- package/src/classes/Queue.ts +77 -0
- package/src/classes/Watcher.ts +117 -0
- package/src/cli.ts +132 -0
- package/src/config.ts +238 -0
- package/src/dev.ts +63 -0
- package/src/doctor.ts +12 -0
- package/src/lib/alignLib.ts +154 -0
- package/src/lib/audioLib.ts +202 -0
- package/src/lib/audioProbeLib.ts +112 -0
- package/src/lib/cleanupProvenanceLib.ts +80 -0
- package/src/lib/downloadLib.ts +8 -0
- package/src/lib/fileSettleLib.ts +213 -0
- package/src/lib/fsLib.ts +37 -0
- package/src/lib/healthLib.ts +377 -0
- package/src/lib/inboxUrl.ts +123 -0
- package/src/lib/journalEmbedLib.ts +127 -0
- package/src/lib/journalIndexLib.ts +923 -0
- package/src/lib/journalQueryLib.ts +269 -0
- package/src/lib/journalService.ts +287 -0
- package/src/lib/jsonLib.ts +71 -0
- package/src/lib/localberthGet.ts +14 -0
- package/src/lib/ollanetLib.ts +117 -0
- package/src/lib/ollanetReadyLib.ts +7 -0
- package/src/lib/organizationLib.ts +182 -0
- package/src/lib/pathAllowLib.ts +60 -0
- package/src/lib/queueLib.ts +30 -0
- package/src/lib/speechCleanupLib.ts +14 -0
- package/src/lib/tagConsolidateLib.ts +431 -0
- package/src/lib/tailscaleLib.ts +78 -0
- package/src/lib/transcriptionLib.ts +484 -0
- package/src/lib/whisperLib.ts +409 -0
- package/src/mcp.ts +151 -0
- package/src/prompts/cleanTranscription.ts +62 -0
- package/src/prompts/consolidateTags.ts +38 -0
- package/src/prompts/whisperInitial.ts +11 -0
- package/src/server.ts +220 -0
- package/src/socketEvents.ts +72 -0
- package/src/types/transcription.ts +56 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { runPrompt } from 'ollanet';
|
|
2
|
+
import { config } from '../config.ts';
|
|
3
|
+
import { parseJSON } from './jsonLib.ts';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_RETRIES = 3;
|
|
6
|
+
const BACKOFF_MS = [2_000, 8_000, 20_000];
|
|
7
|
+
|
|
8
|
+
export async function cleanWithOllanet(
|
|
9
|
+
prompt: string,
|
|
10
|
+
format: Record<string, unknown>
|
|
11
|
+
): Promise<{ completion: any; thinking: string | null; meta: Record<string, unknown> }> {
|
|
12
|
+
if (!process.env.OLLAMA_PROMPT_TIMEOUT_MS) {
|
|
13
|
+
process.env.OLLAMA_PROMPT_TIMEOUT_MS = '900000';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let lastError: unknown;
|
|
17
|
+
for (let attempt = 1; attempt <= DEFAULT_RETRIES; attempt += 1) {
|
|
18
|
+
try {
|
|
19
|
+
return await runCleanOnce(prompt, format);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
lastError = error;
|
|
22
|
+
if (!isTransientCleanError(error) || attempt === DEFAULT_RETRIES) break;
|
|
23
|
+
const waitMs = BACKOFF_MS[attempt - 1] ?? 20_000;
|
|
24
|
+
console.warn(
|
|
25
|
+
`[ollanet] ${describeCleanError(error)}; retry ${attempt}/${DEFAULT_RETRIES} in ${waitMs / 1000}s`
|
|
26
|
+
);
|
|
27
|
+
await sleep(waitMs);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw lastError;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function runCleanOnce(
|
|
34
|
+
prompt: string,
|
|
35
|
+
format: Record<string, unknown>
|
|
36
|
+
): Promise<{ completion: any; thinking: string | null; meta: Record<string, unknown> }> {
|
|
37
|
+
const result = await runPrompt({
|
|
38
|
+
machine: config.ollanet.machine,
|
|
39
|
+
model: config.ollanet.cleanModel,
|
|
40
|
+
prompt,
|
|
41
|
+
save: config.ollanet.saveChats,
|
|
42
|
+
writeStdout: false,
|
|
43
|
+
quiet: true,
|
|
44
|
+
// Stream so HTTP headers arrive immediately. Non-stream waits until the
|
|
45
|
+
// full 27b reply is done, which trips undici's headers timeout.
|
|
46
|
+
stream: true,
|
|
47
|
+
settings: {
|
|
48
|
+
format,
|
|
49
|
+
think: false,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
let completion: any = result.content;
|
|
54
|
+
try {
|
|
55
|
+
completion = await parseJSON(completion);
|
|
56
|
+
} catch {
|
|
57
|
+
// leave as string; caller checks cleanedTranscription
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
completion,
|
|
62
|
+
thinking: result.thinking,
|
|
63
|
+
meta: {
|
|
64
|
+
machine: result.machine,
|
|
65
|
+
model: result.model,
|
|
66
|
+
...slimOllamaMeta(result.ollama),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isTransientCleanError(error: unknown): boolean {
|
|
72
|
+
const code = errorCauseCode(error);
|
|
73
|
+
if (
|
|
74
|
+
code === 'UND_ERR_HEADERS_TIMEOUT' ||
|
|
75
|
+
code === 'UND_ERR_BODY_TIMEOUT' ||
|
|
76
|
+
code === 'ECONNRESET' ||
|
|
77
|
+
code === 'ETIMEDOUT' ||
|
|
78
|
+
code === 'ECONNREFUSED' ||
|
|
79
|
+
code === 'UND_ERR_CONNECT_TIMEOUT'
|
|
80
|
+
) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
const msg = error instanceof Error ? `${error.message} ${String((error as Error & { cause?: unknown }).cause ?? '')}` : String(error);
|
|
84
|
+
return /headers timeout|fetch failed|timed out|socket hang up|ECONNRESET/i.test(msg);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function describeCleanError(error: unknown): string {
|
|
88
|
+
const code = errorCauseCode(error);
|
|
89
|
+
if (code === 'UND_ERR_HEADERS_TIMEOUT') {
|
|
90
|
+
return 'remote host did not send headers in time (model still loading or a long non-stream reply)';
|
|
91
|
+
}
|
|
92
|
+
if (error instanceof Error) return error.message;
|
|
93
|
+
return String(error);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function errorCauseCode(error: unknown): string | undefined {
|
|
97
|
+
if (!error || typeof error !== 'object') return undefined;
|
|
98
|
+
const withCause = error as { code?: string; cause?: { code?: string } };
|
|
99
|
+
return withCause.cause?.code || withCause.code;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function sleep(ms: number): Promise<void> {
|
|
103
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Keep timing/token stats; drop the response body (already stored as cleanedTranscription). */
|
|
107
|
+
export const OLLAMA_BODY_KEYS = new Set(['message', 'messages', 'response', 'content', 'thinking']);
|
|
108
|
+
|
|
109
|
+
export function slimOllamaMeta(ollama: unknown): Record<string, unknown> {
|
|
110
|
+
if (!ollama || typeof ollama !== 'object' || Array.isArray(ollama)) return {};
|
|
111
|
+
const slim: Record<string, unknown> = {};
|
|
112
|
+
for (const [key, value] of Object.entries(ollama as Record<string, unknown>)) {
|
|
113
|
+
if (OLLAMA_BODY_KEYS.has(key)) continue;
|
|
114
|
+
slim[key] = value;
|
|
115
|
+
}
|
|
116
|
+
return slim;
|
|
117
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { config } from '../config.ts';
|
|
2
|
+
|
|
3
|
+
export function ollanetIsConfigured(): boolean {
|
|
4
|
+
const machine = config.ollanet.machine.trim();
|
|
5
|
+
const model = config.ollanet.cleanModel.trim();
|
|
6
|
+
return machine.length > 0 && !machine.startsWith('YOUR-') && model.length > 0 && !model.startsWith('YOUR-');
|
|
7
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { audioFileRegex, findAudioForSidecar } from './audioLib.ts';
|
|
4
|
+
import { getSettleMs, inspectFileReadiness, isSkippedWatchPath, requestWhenSettled } from './fileSettleLib.ts';
|
|
5
|
+
import { Watcher } from '../classes/Watcher.ts';
|
|
6
|
+
import { confirmFolder, moveFile } from './fsLib.ts';
|
|
7
|
+
import { checkTranscription, getTranscriptionFilename, process, relocateTranscription } from './transcriptionLib.ts';
|
|
8
|
+
import { config } from '../config.ts';
|
|
9
|
+
import { containedRelative } from './pathAllowLib.ts';
|
|
10
|
+
|
|
11
|
+
const DATE_NAME = /^(?:MTIME_)?(\d{4})-(\d{2})-\d{2}/;
|
|
12
|
+
|
|
13
|
+
export function dateFromFilename(filePath: string): { year: string; month: string } | null {
|
|
14
|
+
const match = path.basename(filePath).match(DATE_NAME);
|
|
15
|
+
if (!match) return null;
|
|
16
|
+
return { year: match[1], month: match[2] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function uniquePath(destPath: string): string {
|
|
20
|
+
if (!fs.existsSync(destPath)) return destPath;
|
|
21
|
+
const parsed = path.parse(destPath);
|
|
22
|
+
for (let i = 2; i < 1000; i += 1) {
|
|
23
|
+
const candidate = path.join(parsed.dir, `${parsed.name}-${i}${parsed.ext}`);
|
|
24
|
+
if (!fs.existsSync(candidate)) return candidate;
|
|
25
|
+
}
|
|
26
|
+
return path.join(parsed.dir, `${parsed.name}-${Date.now()}${parsed.ext}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function topFolder(filePath: string, root: string): string {
|
|
30
|
+
const rel = path.relative(root, filePath).replace(/\\/g, '/');
|
|
31
|
+
return (rel.split('/')[0] || '').toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function plannedDest(filePath: string, sourceRoot: string): string | null {
|
|
35
|
+
if (!fs.existsSync(filePath)) return null;
|
|
36
|
+
const top = topFolder(filePath, sourceRoot);
|
|
37
|
+
if (top === '__inbox') return null;
|
|
38
|
+
if (top === '_holding' || top === '_unfiled') return filePath;
|
|
39
|
+
const date = dateFromFilename(filePath);
|
|
40
|
+
const destFolder = date
|
|
41
|
+
? path.join(sourceRoot, date.year, date.month)
|
|
42
|
+
: path.join(sourceRoot, '_unfiled');
|
|
43
|
+
return path.join(destFolder, path.basename(filePath));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function pipelineIdle(filePath: string, sourceRoot: string): boolean {
|
|
47
|
+
const dest = plannedDest(filePath, sourceRoot);
|
|
48
|
+
if (!dest || path.resolve(dest) !== path.resolve(filePath)) return false;
|
|
49
|
+
const { isProcessed, transcriptionExists } = checkTranscription(filePath);
|
|
50
|
+
return transcriptionExists && isProcessed;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function organizeAudioFile(filePath: string, sourceRoot: string): Promise<string | null> {
|
|
54
|
+
if (!fs.existsSync(filePath)) return null;
|
|
55
|
+
const top = topFolder(filePath, sourceRoot);
|
|
56
|
+
if (top === '__inbox') return null;
|
|
57
|
+
if (top === '_holding' || top === '_unfiled') return filePath;
|
|
58
|
+
|
|
59
|
+
const date = dateFromFilename(filePath);
|
|
60
|
+
const destFolder = date
|
|
61
|
+
? confirmFolder(path.join(sourceRoot, date.year, date.month))
|
|
62
|
+
: confirmFolder(path.join(sourceRoot, '_unfiled'));
|
|
63
|
+
let destPath = path.join(destFolder, path.basename(filePath));
|
|
64
|
+
if (path.resolve(filePath) === path.resolve(destPath)) return destPath;
|
|
65
|
+
|
|
66
|
+
if (fs.existsSync(destPath)) {
|
|
67
|
+
if (date) {
|
|
68
|
+
destPath = uniquePath(path.join(confirmFolder(path.join(sourceRoot, '_holding')), path.basename(filePath)));
|
|
69
|
+
console.log(`[voice-pipeline] destination exists, holding ${destPath}`);
|
|
70
|
+
} else {
|
|
71
|
+
destPath = uniquePath(destPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const srcJson = getTranscriptionFilename(filePath);
|
|
76
|
+
console.log(`[voice-pipeline] move ${filePath} -> ${destPath}`);
|
|
77
|
+
await moveFile(filePath, destPath);
|
|
78
|
+
if (fs.existsSync(srcJson)) {
|
|
79
|
+
const destJson = getTranscriptionFilename(destPath);
|
|
80
|
+
await moveFile(srcJson, destJson);
|
|
81
|
+
relocateTranscription(srcJson, destJson);
|
|
82
|
+
}
|
|
83
|
+
return destPath;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function runPipeline(filePath: string, root: string, options: { front?: boolean } = {}) {
|
|
87
|
+
if (pipelineIdle(filePath, root)) return;
|
|
88
|
+
const dest = await organizeAudioFile(filePath, root);
|
|
89
|
+
if (!dest) return;
|
|
90
|
+
const { isProcessed, transcriptionExists } = checkTranscription(dest);
|
|
91
|
+
if (transcriptionExists && isProcessed) return;
|
|
92
|
+
await process(dest, { force: true, front: options.front });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** One watcher per root: settle → organize onto the final path → transcribe that path. */
|
|
96
|
+
export function initVoiceRootPipeline(sourceFolders: string[] = []) {
|
|
97
|
+
if (!Array.isArray(sourceFolders) || sourceFolders.length === 0) {
|
|
98
|
+
console.error('[voice-pipeline] No source folders specified');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const depth = config.watch.recursiveYears ? 2 : 1;
|
|
102
|
+
for (const folder of sourceFolders) {
|
|
103
|
+
if (!fs.existsSync(folder)) {
|
|
104
|
+
console.error(`[voice-pipeline] Source folder does not exist: ${folder}`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
let liveAdds = false;
|
|
108
|
+
new Watcher({
|
|
109
|
+
watchFolder: folder,
|
|
110
|
+
watchDepth: depth,
|
|
111
|
+
ignoreCheck: (filePath) =>
|
|
112
|
+
isSkippedWatchPath(filePath) ||
|
|
113
|
+
filePath.includes('archive') ||
|
|
114
|
+
filePath.includes('_original') ||
|
|
115
|
+
filePath.includes('_clean'),
|
|
116
|
+
fileMatchRegex: audioFileRegex,
|
|
117
|
+
addHandler: async (filePath) => {
|
|
118
|
+
if (pipelineIdle(filePath, folder)) return;
|
|
119
|
+
if (inspectFileReadiness(filePath, getSettleMs()).ready) {
|
|
120
|
+
await runPipeline(filePath, folder, { front: liveAdds });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
requestWhenSettled(filePath, () => runPipeline(filePath, folder, { front: true }), {
|
|
124
|
+
label: 'voice-pipeline',
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
changeHandler: (filePath) => {
|
|
128
|
+
if (pipelineIdle(filePath, folder)) return;
|
|
129
|
+
requestWhenSettled(filePath, () => runPipeline(filePath, folder, { front: true }), {
|
|
130
|
+
label: 'voice-pipeline',
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
readyHandler: () => {
|
|
134
|
+
liveAdds = true;
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
console.log(`[voice-pipeline] watching ${sourceFolders.join(', ')}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function watchAndOrganizeAudioFiles(sourceFolders: string[] = []) {
|
|
142
|
+
initVoiceRootPipeline(sourceFolders);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type HoldingAction = 'overwrite' | 'rename' | 'unfile';
|
|
146
|
+
|
|
147
|
+
/** Move a holding/unfiled note into YYYY/MM or _unfiled. */
|
|
148
|
+
export async function resolveHeldFile(filePath: string, action: HoldingAction): Promise<string> {
|
|
149
|
+
if (!fs.existsSync(filePath)) throw new Error('file not found');
|
|
150
|
+
if (filePath.toLowerCase().endsWith('.json')) {
|
|
151
|
+
filePath = findAudioForSidecar(filePath) || filePath;
|
|
152
|
+
}
|
|
153
|
+
const resolved = path.resolve(filePath);
|
|
154
|
+
const root = config.watch.roots.find((candidate) => containedRelative(resolved, path.resolve(candidate)));
|
|
155
|
+
if (!root) throw new Error('file is not under a watch root');
|
|
156
|
+
|
|
157
|
+
const date = dateFromFilename(filePath);
|
|
158
|
+
let destFolder: string;
|
|
159
|
+
if (action === 'unfile' || !date) {
|
|
160
|
+
destFolder = confirmFolder(path.join(root, '_unfiled'));
|
|
161
|
+
} else {
|
|
162
|
+
destFolder = confirmFolder(path.join(root, date.year, date.month));
|
|
163
|
+
}
|
|
164
|
+
let destPath = path.join(destFolder, path.basename(filePath));
|
|
165
|
+
if (action === 'rename' && fs.existsSync(destPath)) {
|
|
166
|
+
destPath = uniquePath(destPath);
|
|
167
|
+
}
|
|
168
|
+
if (action === 'overwrite' && fs.existsSync(destPath) && path.resolve(destPath) !== path.resolve(filePath)) {
|
|
169
|
+
fs.unlinkSync(destPath);
|
|
170
|
+
const destJson = getTranscriptionFilename(destPath);
|
|
171
|
+
if (fs.existsSync(destJson)) fs.unlinkSync(destJson);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const srcJson = getTranscriptionFilename(filePath);
|
|
175
|
+
await moveFile(filePath, destPath);
|
|
176
|
+
if (fs.existsSync(srcJson)) {
|
|
177
|
+
const destJson = getTranscriptionFilename(destPath);
|
|
178
|
+
await moveFile(srcJson, destJson);
|
|
179
|
+
relocateTranscription(srcJson, destJson);
|
|
180
|
+
}
|
|
181
|
+
return destPath;
|
|
182
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { config } from '../config.ts';
|
|
4
|
+
|
|
5
|
+
export type AllowedPath =
|
|
6
|
+
| { ok: true; path: string; root: string; relative: string }
|
|
7
|
+
| { ok: false; error: string };
|
|
8
|
+
|
|
9
|
+
export function allowedRoots(): string[] {
|
|
10
|
+
return [...config.watch.roots, config.watch.browserDropFolder].map((root) => path.resolve(root));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function existingRealPath(filePath: string): string {
|
|
14
|
+
const resolved = path.resolve(filePath);
|
|
15
|
+
try {
|
|
16
|
+
if (fs.existsSync(resolved)) return fs.realpathSync(resolved);
|
|
17
|
+
} catch {
|
|
18
|
+
// keep the resolved path
|
|
19
|
+
}
|
|
20
|
+
return resolved;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Relative path under `root`, or null if `candidate` escapes it. */
|
|
24
|
+
export function containedRelative(candidate: string, root: string): string | null {
|
|
25
|
+
const rel = path.relative(root, candidate);
|
|
26
|
+
if (rel === '') return '.';
|
|
27
|
+
if (rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) return null;
|
|
28
|
+
return rel;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resolveAllowedPath(input: string): AllowedPath {
|
|
32
|
+
if (!input || typeof input !== 'string') {
|
|
33
|
+
return { ok: false, error: 'missing path' };
|
|
34
|
+
}
|
|
35
|
+
if (input.includes('\0')) {
|
|
36
|
+
return { ok: false, error: 'unreadable path' };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let candidate: string;
|
|
40
|
+
try {
|
|
41
|
+
candidate = existingRealPath(input.trim());
|
|
42
|
+
} catch {
|
|
43
|
+
return { ok: false, error: 'unreadable path' };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const root of allowedRoots()) {
|
|
47
|
+
let rootPath = root;
|
|
48
|
+
try {
|
|
49
|
+
rootPath = existingRealPath(root);
|
|
50
|
+
} catch {
|
|
51
|
+
rootPath = path.resolve(root);
|
|
52
|
+
}
|
|
53
|
+
const relative = containedRelative(candidate, rootPath);
|
|
54
|
+
if (relative) {
|
|
55
|
+
return { ok: true, path: candidate, root: rootPath, relative };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { ok: false, error: 'path is outside configured watch roots' };
|
|
60
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Queue, type QueueConfig } from '../classes/Queue.ts';
|
|
2
|
+
|
|
3
|
+
export let q: Record<string, Queue> = {};
|
|
4
|
+
|
|
5
|
+
export function initQueues(queues: Record<string, QueueConfig>): void {
|
|
6
|
+
if (!queues || typeof queues !== 'object') {
|
|
7
|
+
throw new Error('Invalid queues configuration');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const queueMap: Record<string, Queue> = {};
|
|
11
|
+
|
|
12
|
+
for (const [name, config] of Object.entries(queues)) {
|
|
13
|
+
if (!config.active) {
|
|
14
|
+
console.log(`[queue] Skipping inactive queue: ${name}`);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (!config.processor || typeof config.processor !== 'function') {
|
|
18
|
+
throw new Error(`Queue ${name} is missing a processor function`);
|
|
19
|
+
}
|
|
20
|
+
if (typeof config.concurrency !== 'number' || config.concurrency <= 0) {
|
|
21
|
+
throw new Error(`Queue ${name} has an invalid concurrency value`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
queueMap[name] = new Queue(name, config);
|
|
25
|
+
console.log(`[queue] Initialized queue: ${name} with concurrency ${config.concurrency}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
q = queueMap;
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Collapse ASR stutter/hallucination loops for the cleanup prompt. Does not rewrite sidecar `text`. */
|
|
2
|
+
export function collapseSpeechLoops(text: string): string {
|
|
3
|
+
const collapsed = String(text || '').replace(/\b(\w+)(?:[,.\s]+\1){2,}\b/gi, '$1');
|
|
4
|
+
const lines = collapsed.split(/\r?\n/);
|
|
5
|
+
const out: string[] = [];
|
|
6
|
+
let prev = '';
|
|
7
|
+
for (const line of lines) {
|
|
8
|
+
const norm = line.trim().toLowerCase();
|
|
9
|
+
if (norm && norm === prev) continue;
|
|
10
|
+
out.push(line);
|
|
11
|
+
if (norm) prev = norm;
|
|
12
|
+
}
|
|
13
|
+
return out.join('\n').replace(/[^\S\n]+/g, ' ').trim();
|
|
14
|
+
}
|