@lincyaw/workspace 1.0.0-rc.62 → 1.0.0-rc.63
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/package.json +6 -6
- package/src/node/document-voice.ts +32 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workspace",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.63",
|
|
4
4
|
"description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"mime-types": "3.0.2",
|
|
35
35
|
"playwright-chromium": "1.64.1",
|
|
36
36
|
"yaml": "^2.9.1",
|
|
37
|
-
"@lincyaw/
|
|
38
|
-
"@lincyaw/
|
|
39
|
-
"@lincyaw/
|
|
40
|
-
"@lincyaw/
|
|
37
|
+
"@lincyaw/compiler": "1.0.0-rc.63",
|
|
38
|
+
"@lincyaw/kernel": "1.0.0-rc.63",
|
|
39
|
+
"@lincyaw/server": "1.0.0-rc.63",
|
|
40
|
+
"@lincyaw/design": "1.0.0-rc.63"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/mime-types": "^3.0.1",
|
|
44
|
-
"@lincyaw/mcp": "1.0.0-rc.
|
|
44
|
+
"@lincyaw/mcp": "1.0.0-rc.63"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -2,6 +2,7 @@ import { DOCUMENT_ENTRY, VOICE_CLONE_MAX_AUDIO_BYTES, fnv1a64, hasRole, speechEn
|
|
|
2
2
|
import type { CanonicalSource, DocumentVoiceAuthoring, DocumentVoiceCloneAudio, Finding, Member, PreparedVoiceClone, SpeechService, VoiceoverExecution, VoiceoverJob } from '@lincyaw/kernel'
|
|
3
3
|
import { createVoiceoverOwner, createVoiceoverRoutes, validateDocumentVoiceCatalogQuery, validateDocumentVoiceClone, validateDocumentVoiceCloneQuery, validateVoicePreviewStart } from '@lincyaw/kernel/node'
|
|
4
4
|
import { extname } from 'node:path'
|
|
5
|
+
import { randomBytes } from 'node:crypto'
|
|
5
6
|
import { readDocumentAudioBytes } from './document-audio.ts'
|
|
6
7
|
import { readAuthoringDocument } from './document-editor.ts'
|
|
7
8
|
import { RequestError } from './errors.ts'
|
|
@@ -20,7 +21,14 @@ const same = (a: CanonicalSource, b: CanonicalSource) => a.documentId === b.docu
|
|
|
20
21
|
export function createDocumentVoiceAuthoring({ editor, services, revision, uploads }: DocumentVoiceAuthoringOptions) {
|
|
21
22
|
const pending = new Set<{ controller: AbortController, finished: Promise<unknown> }>()
|
|
22
23
|
const owners = new Map<string, ReturnType<typeof createVoiceoverOwner>>()
|
|
23
|
-
const clones = new
|
|
24
|
+
const clones = new Map<string, { document: string, member: string, request: string, prepared: PreparedVoiceClone }>()
|
|
25
|
+
const cloneEntry = (document: string, id: string, member: Member) => {
|
|
26
|
+
if (!hasRole(member, 'owner')) throw new RequestError(403, 'voice-clone-permission-denied')
|
|
27
|
+
authorize(document, member)
|
|
28
|
+
const entry = clones.get(id)
|
|
29
|
+
if (entry && (entry.document !== document || entry.member !== member.id)) throw new RequestError(403, 'voice-clone-permission-denied')
|
|
30
|
+
return entry
|
|
31
|
+
}
|
|
24
32
|
let closed = false
|
|
25
33
|
const authorize = (document: string, member: Member) => {
|
|
26
34
|
if (!hasRole(member, 'editor')) throw new RequestError(403, 'voice-authoring-permission-denied')
|
|
@@ -98,6 +106,7 @@ export function createDocumentVoiceAuthoring({ editor, services, revision, uploa
|
|
|
98
106
|
let statement: Blob | undefined = new Blob([statementInput.bytes as Uint8Array<ArrayBuffer>], { type: statementInput.type })
|
|
99
107
|
let started: ReturnType<NonNullable<SpeechService['cloneVoice']>> | undefined
|
|
100
108
|
let expired = false
|
|
109
|
+
const id = randomBytes(32).toString('hex')
|
|
101
110
|
const prepared: PreparedVoiceClone = { engine: speechEngineId(engine), voice: request.voice,
|
|
102
111
|
start: startSignal => {
|
|
103
112
|
if (started) return started
|
|
@@ -112,13 +121,32 @@ export function createDocumentVoiceAuthoring({ editor, services, revision, uploa
|
|
|
112
121
|
}).finally(() => prepared.close())
|
|
113
122
|
return started
|
|
114
123
|
},
|
|
115
|
-
close: () => { expired = true; clearTimeout(timer); sample = undefined; statement = undefined; clones.delete(
|
|
124
|
+
close: () => { expired = true; clearTimeout(timer); sample = undefined; statement = undefined; clones.delete(id) },
|
|
116
125
|
}
|
|
117
126
|
const timer = setTimeout(() => prepared.close(), 90000)
|
|
118
127
|
timer.unref()
|
|
119
|
-
clones.
|
|
128
|
+
clones.set(id, { document, member: member.id, request: JSON.stringify(request), prepared })
|
|
120
129
|
return prepared
|
|
121
130
|
}),
|
|
131
|
+
prepareCloneReference: async (document, request, member, signal) => {
|
|
132
|
+
const prepared = await service.prepareClone!(document, request, member, signal)
|
|
133
|
+
const found = [...clones].find(([, entry]) => entry.prepared === prepared)
|
|
134
|
+
if (!found) { prepared.close(); throw new RequestError(409, 'voice-clone-expired') }
|
|
135
|
+
if (signal?.aborted) { prepared.close(); signal.throwIfAborted() }
|
|
136
|
+
return { id: found[0], engine: prepared.engine, voice: prepared.voice }
|
|
137
|
+
},
|
|
138
|
+
runPreparedClone: (document, id, request, member, signal) => {
|
|
139
|
+
const entry = cloneEntry(document, id, member)
|
|
140
|
+
if (!entry) throw new RequestError(409, 'voice-clone-expired')
|
|
141
|
+
if (entry.request !== JSON.stringify(request)) throw new RequestError(409, 'voice-clone-preparation-changed')
|
|
142
|
+
try { return entry.prepared.start(signal) }
|
|
143
|
+
catch (error) { entry.prepared.close(); throw error }
|
|
144
|
+
},
|
|
145
|
+
releasePreparedClone: (document, id, member) => {
|
|
146
|
+
const entry = cloneEntry(document, id, member)
|
|
147
|
+
entry?.prepared.close()
|
|
148
|
+
return Boolean(entry)
|
|
149
|
+
},
|
|
122
150
|
cloneStatus: (document, query, member, signal) => work(signal, async signal => {
|
|
123
151
|
if (!hasRole(member, 'owner')) throw new RequestError(403, 'voice-clone-permission-denied')
|
|
124
152
|
if (!validateDocumentVoiceCloneQuery(query)) throw new RequestError(400, 'voice-clone-invalid')
|
|
@@ -177,5 +205,5 @@ export function createDocumentVoiceAuthoring({ editor, services, revision, uploa
|
|
|
177
205
|
},
|
|
178
206
|
readPreview: async (document, id, member) => ownerOf(document, member).readPreview(id),
|
|
179
207
|
}
|
|
180
|
-
return { service, routes: createVoiceoverRoutes(service), async close() { closed = true; for (const prepared of clones) prepared.close(); for (const operation of pending) operation.controller.abort(); await Promise.allSettled([...owners.values()].map(owner => owner.close())); await Promise.allSettled([...pending].map(operation => operation.finished)); owners.clear() } }
|
|
208
|
+
return { service, routes: createVoiceoverRoutes(service), async close() { closed = true; for (const { prepared } of clones.values()) prepared.close(); for (const operation of pending) operation.controller.abort(); await Promise.allSettled([...owners.values()].map(owner => owner.close())); await Promise.allSettled([...pending].map(operation => operation.finished)); owners.clear() } }
|
|
181
209
|
}
|