@lincyaw/workspace 1.0.0-rc.61 → 1.0.0-rc.62
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 +20 -11
- package/src/node/serve.ts +2 -2
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.62",
|
|
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/kernel": "1.0.0-rc.62",
|
|
38
|
+
"@lincyaw/compiler": "1.0.0-rc.62",
|
|
39
|
+
"@lincyaw/design": "1.0.0-rc.62",
|
|
40
|
+
"@lincyaw/server": "1.0.0-rc.62"
|
|
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.62"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { DOCUMENT_ENTRY, VOICE_CLONE_MAX_AUDIO_BYTES, fnv1a64, hasRole, speechEngineId } from '@lincyaw/kernel'
|
|
2
|
-
import type { CanonicalSource, DocumentVoiceAuthoring, Finding, Member, PreparedVoiceClone, SpeechService, VoiceoverExecution, VoiceoverJob } from '@lincyaw/kernel'
|
|
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
5
|
import { readDocumentAudioBytes } from './document-audio.ts'
|
|
6
6
|
import { readAuthoringDocument } from './document-editor.ts'
|
|
7
7
|
import { RequestError } from './errors.ts'
|
|
8
8
|
import type { SourceEditor } from './source-editor.ts'
|
|
9
|
+
import type { MediaUploadsOwner } from './media-uploads.ts'
|
|
9
10
|
|
|
10
11
|
export interface DocumentVoiceServices { speech?: SpeechService, voiceover?: { version: 1, preview: true }, voiceoverExecution?: VoiceoverExecution, findings?: Finding[] }
|
|
11
12
|
export interface DocumentVoiceAuthoringOptions {
|
|
12
13
|
editor: SourceEditor
|
|
13
14
|
services(document: string, source: CanonicalSource): Promise<DocumentVoiceServices>
|
|
14
15
|
revision?(document: string): string | undefined
|
|
16
|
+
uploads?: MediaUploadsOwner
|
|
15
17
|
}
|
|
16
18
|
const same = (a: CanonicalSource, b: CanonicalSource) => a.documentId === b.documentId && a.version === b.version && a.fingerprint === b.fingerprint
|
|
17
19
|
|
|
18
|
-
export function createDocumentVoiceAuthoring({ editor, services, revision }: DocumentVoiceAuthoringOptions) {
|
|
20
|
+
export function createDocumentVoiceAuthoring({ editor, services, revision, uploads }: DocumentVoiceAuthoringOptions) {
|
|
19
21
|
const pending = new Set<{ controller: AbortController, finished: Promise<unknown> }>()
|
|
20
22
|
const owners = new Map<string, ReturnType<typeof createVoiceoverOwner>>()
|
|
21
23
|
const clones = new Set<PreparedVoiceClone>()
|
|
@@ -70,23 +72,30 @@ export function createDocumentVoiceAuthoring({ editor, services, revision }: Doc
|
|
|
70
72
|
if (clones.size >= 4) throw new RequestError(503, 'voice-authoring-busy')
|
|
71
73
|
const request = structuredClone(value), loaded = await load(document, member, signal, request.source)
|
|
72
74
|
const speech = loaded.speech, engine = request.engine ?? await speech?.defaultSynthesisEngine?.()
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
+
const read = async (input: DocumentVoiceCloneAudio) => {
|
|
76
|
+
const path = typeof input === 'string' ? input : undefined
|
|
77
|
+
if (path !== undefined && path.split(/[\\/]/).some(part => part.startsWith('.'))) throw new RequestError(403, 'audio-file-path')
|
|
78
|
+
const uploaded = typeof input !== 'string' ? uploads?.read(document, loaded.source.documentId, member, input.upload, 'audio') : undefined
|
|
79
|
+
if (path === undefined && !uploaded) throw new RequestError(503, 'media-upload-unavailable')
|
|
75
80
|
const types: Record<string, string> = { '.wav': 'audio/wav', '.mp3': 'audio/mpeg', '.webm': 'audio/webm', '.ogg': 'audio/ogg', '.m4a': 'audio/mp4', '.mp4': 'audio/mp4', '.flac': 'audio/flac', '.aac': 'audio/aac' }
|
|
76
|
-
const type = types[extname(path).toLowerCase()]
|
|
81
|
+
const type = types[extname(path ?? uploaded!.name).toLowerCase()]
|
|
77
82
|
if (!type) throw new RequestError(422, 'voice-clone-audio-type')
|
|
78
|
-
editor.assertEditable({ document, home: false }, path, member)
|
|
79
|
-
|
|
83
|
+
if (path !== undefined) editor.assertEditable({ document, home: false }, path, member)
|
|
84
|
+
const bytes = uploaded?.bytes ?? await readDocumentAudioBytes(editor, { document, member, rest: '' }, path!, signal, VOICE_CLONE_MAX_AUDIO_BYTES)
|
|
85
|
+
if (bytes.length > VOICE_CLONE_MAX_AUDIO_BYTES) throw new RequestError(413, 'production.asset-size')
|
|
86
|
+
return { bytes, type }
|
|
80
87
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
88
|
+
const [sampleRead, statementRead] = await Promise.allSettled([read(request.sample), read(request.consent.statement)])
|
|
89
|
+
if (sampleRead.status === 'rejected') throw sampleRead.reason
|
|
90
|
+
if (statementRead.status === 'rejected') throw statementRead.reason
|
|
91
|
+
const sampleInput = sampleRead.value, statementInput = statementRead.value
|
|
83
92
|
current(document, member, loaded.source); signal.throwIfAborted()
|
|
84
93
|
if (!speech?.cloneVoice || !engine || !(await speech.engines()).some(info => info.id === speechEngineId(engine) && info.clone)) throw new RequestError(409, 'voice-clone-unavailable')
|
|
85
94
|
current(document, member, loaded.source); signal.throwIfAborted()
|
|
86
95
|
// Several readers may finish concurrently; the retained byte budget is checked again before retaining blobs.
|
|
87
96
|
if (clones.size >= 4) throw new RequestError(503, 'voice-authoring-busy')
|
|
88
|
-
let sample: Blob | undefined = new Blob([
|
|
89
|
-
let statement: Blob | undefined = new Blob([
|
|
97
|
+
let sample: Blob | undefined = new Blob([sampleInput.bytes as Uint8Array<ArrayBuffer>], { type: sampleInput.type })
|
|
98
|
+
let statement: Blob | undefined = new Blob([statementInput.bytes as Uint8Array<ArrayBuffer>], { type: statementInput.type })
|
|
90
99
|
let started: ReturnType<NonNullable<SpeechService['cloneVoice']>> | undefined
|
|
91
100
|
let expired = false
|
|
92
101
|
const prepared: PreparedVoiceClone = { engine: speechEngineId(engine), voice: request.voice,
|
package/src/node/serve.ts
CHANGED
|
@@ -397,7 +397,8 @@ export async function serveWorkspace(options: ServeOptions): Promise<WorkspaceSe
|
|
|
397
397
|
})
|
|
398
398
|
const running = server
|
|
399
399
|
serverServices = running.services
|
|
400
|
-
|
|
400
|
+
mediaUploads = createMediaUploads({ editor, url: () => `${publicOrigin()}${basePath.replace(/\/$/, '')}` })
|
|
401
|
+
voiceAuthoring = createDocumentVoiceAuthoring({ editor, uploads: mediaUploads, services: authoringServices, revision: document => { const latest = compileSessions.get(document)?.latest; return latest ? irRevision(latest.doc) : undefined } })
|
|
401
402
|
workbench = createWorkbenchBackend({ root, compileSessionOf, serverHost, voices: voiceAuthoring.service, diagnostics: running.diagnostics, url: () => options.publicUrl ? new URL(options.publicUrl).origin : running.url, basePath, preview, log, warmSite: dir => site?.warm(dir) ?? Promise.resolve(), viewerPage: (dir, wait) => site?.app(dir, wait) ?? Promise.resolve(undefined) })
|
|
402
403
|
history = openHistory()
|
|
403
404
|
workspaceChanges = createWorkspaceChanges({ config, editor, locks, revisions: history?.revisions, changed: documentsChanged })
|
|
@@ -413,7 +414,6 @@ export async function serveWorkspace(options: ServeOptions): Promise<WorkspaceSe
|
|
|
413
414
|
documentHistory = createDocumentHistory({ config, editor, locks, revisions: history?.revisions, reviewRequired: config.settings['presmium.assistant']?.review === 'required', changed: (before, after) => documentsChanged(documentsDiff(before, after)), reverted: (target, revision) => history?.agentSessionReviews.reverted(target, revision) })
|
|
414
415
|
transcriptions = createDocumentTranscriptions({ root, editor, services: authoringServices })
|
|
415
416
|
transcriptionAdoption = createTranscriptionAdoption({ documentEditor, transcriptions })
|
|
416
|
-
mediaUploads = createMediaUploads({ editor, url: () => `${publicOrigin()}${basePath.replace(/\/$/, '')}` })
|
|
417
417
|
audioAuthoring = createDocumentAudioAuthoring({ root, editor, uploads: mediaUploads, revisions: history?.revisions, services: authoringServices, reviewRequired: config.settings['presmium.assistant']?.review === 'required' })
|
|
418
418
|
imageAuthoring = createDocumentImageAuthoring({ root, editor, uploads: mediaUploads, revisions: history?.revisions, reviewRequired: config.settings['presmium.assistant']?.review === 'required' })
|
|
419
419
|
const routeOptions = {
|