@lincyaw/workbench 0.2.0-rc.33 → 0.2.0-rc.34
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 +4 -4
- package/src/context.tsx +2 -1
- package/src/diagnostics.ts +1 -1
- package/src/document-editing.ts +484 -0
- package/src/document-editor/ComponentPropertiesDialog.tsx +1 -1
- package/src/document-editor/DocumentBlockPreview.tsx +2 -2
- package/src/document-editor/DocumentStepNarration.tsx +8 -8
- package/src/document-production.ts +331 -0
- package/src/history.ts +1 -1
- package/src/index.ts +5 -2
- package/src/jobs.ts +1 -1
- package/src/panels/DocumentView.tsx +11 -11
- package/src/panels/DocumentVoiceDialog.tsx +2 -2
- package/src/panels/DocumentVoiceField.tsx +1 -1
- package/src/panels/HistoryPanel.tsx +1 -1
- package/src/panels/PageDeleteDialog.tsx +4 -4
- package/src/panels/PageRenameDialog.tsx +1 -1
- package/src/panels/ProductionCaptionSize.tsx +1 -1
- package/src/panels/ProductionCaptionTiming.tsx +5 -5
- package/src/panels/ProductionMediaClips.tsx +4 -4
- package/src/panels/ProductionPanel.tsx +2 -2
- package/src/panels/ProductionRecording.tsx +1 -1
- package/src/panels/ProductionRecordingRange.tsx +2 -2
- package/src/panels/ProductionTranscription.tsx +3 -3
- package/src/panels/SourceDocumentPanel.tsx +9 -9
- package/src/panels/TranscriptionAdoption.tsx +2 -2
- package/src/panels/VoiceoverDialog.tsx +1 -1
- package/src/preview-playback.ts +1 -1
- package/src/production-playback.ts +1 -1
- package/src/production-voice-playback.ts +3 -2
- package/src/use-recording-adoption.ts +2 -2
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +157 -0
- package/src/workbench.ts +56 -923
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { applyDocumentCaptionTiming, changeDocumentCaptionScale, DOCUMENT_AUDIO_MAX_BYTES, randomUUID, replaceStepNarrations, sameProductionBinding, validateDocument } from '@lincyaw/kernel'
|
|
2
|
+
import type { DocumentAudioImportAnswer, DocumentAudioInspectionAnswer, DocumentCaptionTimingAction, DocumentChangeAnswer, DocumentRecordingAdoption, DocumentTranscriptionRequest, MediaClip, Narration, ProductionBinding, TeachingDocument, TranscriptionAdoptionAnswer, TranscriptionAdoptionApply, TranscriptionAdoptionDraft, TranscriptionAdoptionPlan, TranscriptionTask, VerifiedDocumentRecordingAdoption, VoiceSource } from '@lincyaw/kernel'
|
|
3
|
+
import { isAgentChanging } from './workbench-state.ts'
|
|
4
|
+
import type { WorkbenchStore } from './workbench-state.ts'
|
|
5
|
+
import type { DocumentSession, DocumentSessionState } from './document-session.ts'
|
|
6
|
+
import { WorkspaceServerError } from './workspace-client.ts'
|
|
7
|
+
import type { WorkspaceClient } from './workspace-client.ts'
|
|
8
|
+
import { sha256 } from './sha256.ts'
|
|
9
|
+
import { reconcileRecordingAdoption } from './recording-adoption.ts'
|
|
10
|
+
import { changeDocumentVoice } from './document-voices.ts'
|
|
11
|
+
import type { DocumentVoiceOptions, DocumentVoiceScope } from './document-voices.ts'
|
|
12
|
+
import { componentSource, sameComponentSource } from './component-properties.ts'
|
|
13
|
+
import { reconcileCaptionTiming } from './caption-timing.ts'
|
|
14
|
+
import { changeStepTiming } from './step-production.ts'
|
|
15
|
+
import type { StepDurationDraft, StepDurationKey, StepTimingPatch } from './step-production.ts'
|
|
16
|
+
import { DocumentTimingDrafts } from './document-timing-drafts.ts'
|
|
17
|
+
import { CaptionTimingDrafts } from './caption-timing-drafts.ts'
|
|
18
|
+
import type { CaptionTimingDraft } from './caption-timing-drafts.ts'
|
|
19
|
+
|
|
20
|
+
interface ProductionOptions {
|
|
21
|
+
store: WorkbenchStore
|
|
22
|
+
session: DocumentSession
|
|
23
|
+
client: WorkspaceClient
|
|
24
|
+
scope(): number
|
|
25
|
+
document(identity?: string): TeachingDocument | undefined
|
|
26
|
+
flush(signal?: AbortSignal): Promise<void>
|
|
27
|
+
pause(): Promise<void>
|
|
28
|
+
stopAuditions(): void
|
|
29
|
+
stopPreviewOutputs(): void
|
|
30
|
+
sourceCurrent(binding: ProductionBinding): boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Source-bound media transactions, timing drafts and narration edits share the document actor. */
|
|
34
|
+
export class DocumentProduction {
|
|
35
|
+
readonly #audioImports = new WeakMap<File, { identity: string, version: string, id: string }>()
|
|
36
|
+
readonly #audioFingerprints = new WeakMap<File, Promise<string>>()
|
|
37
|
+
readonly #documentTimingDrafts = new DocumentTimingDrafts()
|
|
38
|
+
readonly #captionTimingDrafts = new CaptionTimingDrafts()
|
|
39
|
+
readonly #removedCueTimings = new Map<string, { pauseMs: number }>()
|
|
40
|
+
readonly #removedNarrations = new Map<string, { narration: Narration, override?: { narrationStart: 'with-animation' | 'after-animation' } }>()
|
|
41
|
+
#cueTimingScope?: string
|
|
42
|
+
readonly #options: ProductionOptions
|
|
43
|
+
constructor(options: ProductionOptions) { this.#options = options }
|
|
44
|
+
draftState(authoring: DocumentSessionState) {
|
|
45
|
+
const scope = JSON.stringify([authoring.identity, authoring.reset])
|
|
46
|
+
if (this.#cueTimingScope !== scope) { this.#removedCueTimings.clear(); this.#removedNarrations.clear(); this.#cueTimingScope = scope }
|
|
47
|
+
return {
|
|
48
|
+
hasDocumentTimingDrafts: Boolean(authoring.identity && authoring.content && this.#documentTimingDrafts.has(authoring.identity, authoring.content)),
|
|
49
|
+
documentTimingDraftStorageFailure: this.#documentTimingDrafts.failed,
|
|
50
|
+
captionTimingDraftSteps: authoring.identity && authoring.member?.id && authoring.content ? this.#captionTimingDrafts.steps({ identity: authoring.identity, memberId: authoring.member.id }, authoring.content) : [],
|
|
51
|
+
captionTimingDraftStorageFailure: Boolean(authoring.identity && authoring.member?.id && this.#captionTimingDrafts.failed({ identity: authoring.identity, memberId: authoring.member.id })),
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
reset(): void { this.#removedCueTimings.clear(); this.#removedNarrations.clear(); this.#cueTimingScope = undefined }
|
|
55
|
+
dispose(): void { this.reset(); this.#captionTimingDrafts.close() }
|
|
56
|
+
|
|
57
|
+
source(expected: { identity: string, version: string }): DocumentSessionState {
|
|
58
|
+
const source = this.#options.store.state.authoring
|
|
59
|
+
if (!source || !this.#options.document(expected.identity) || source.version !== expected.version || !source.fingerprint
|
|
60
|
+
|| source.dirty || source.saving || source.composing || source.restored || source.error || isAgentChanging(this.#options.store.state)) throw new Error('production-source-changed')
|
|
61
|
+
return source
|
|
62
|
+
}
|
|
63
|
+
/** Inspects the saved declaration, including a local asset not yet attached to a step. */
|
|
64
|
+
async inspectAudio(assetId: string, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<DocumentAudioInspectionAnswer> {
|
|
65
|
+
const source = this.source(expected), scope = this.#options.scope()
|
|
66
|
+
const answer = await this.#options.client.readDocumentAudio(source.directory, assetId, expected.version, signal)
|
|
67
|
+
signal?.throwIfAborted()
|
|
68
|
+
if (scope !== this.#options.scope() || answer.document !== source.directory || answer.version !== expected.version || answer.fingerprint !== source.fingerprint || answer.inspection.assetId !== assetId) throw new Error('production-source-changed')
|
|
69
|
+
this.source(expected)
|
|
70
|
+
return answer
|
|
71
|
+
}
|
|
72
|
+
/** Recognition keeps its captured source even if subsequent author input moves to a newer version. */
|
|
73
|
+
async startTranscription(request: Omit<DocumentTranscriptionRequest, 'source'>, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<TranscriptionTask> {
|
|
74
|
+
const source = this.source(expected)
|
|
75
|
+
if (!source.content || !source.fingerprint) throw new Error('production-source-changed')
|
|
76
|
+
const sent: DocumentTranscriptionRequest = { ...structuredClone(request), source: { documentId: source.content.id, version: expected.version, fingerprint: source.fingerprint } }
|
|
77
|
+
const answer = await this.#options.client.startTranscription(source.directory, sent, signal)
|
|
78
|
+
signal?.throwIfAborted()
|
|
79
|
+
if (answer.document !== source.directory || answer.intent !== sent.intent || answer.source.documentId !== sent.source.documentId
|
|
80
|
+
|| answer.source.version !== sent.source.version || answer.source.fingerprint !== sent.source.fingerprint || answer.audio.assetId !== sent.assetId || answer.audio.sha256 !== sent.audioSha256) throw new Error('transcription-response-changed')
|
|
81
|
+
return answer
|
|
82
|
+
}
|
|
83
|
+
async planTranscription(draft: TranscriptionAdoptionDraft, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<TranscriptionAdoptionPlan> {
|
|
84
|
+
const source = this.source(expected), sent = structuredClone(draft)
|
|
85
|
+
if (sent.source.documentId !== source.content?.id || sent.source.version !== expected.version || sent.source.fingerprint !== source.fingerprint) throw new Error('production-source-changed')
|
|
86
|
+
const answer = await this.#options.client.planTranscriptionAdoption(source.directory, sent, signal)
|
|
87
|
+
signal?.throwIfAborted()
|
|
88
|
+
this.source(expected)
|
|
89
|
+
if (answer.document !== source.directory || answer.changeId !== sent.id || answer.source.documentId !== sent.source.documentId
|
|
90
|
+
|| answer.source.version !== sent.source.version || answer.source.fingerprint !== sent.source.fingerprint || answer.candidate.id !== sent.candidate.id
|
|
91
|
+
|| answer.candidate.revision !== sent.candidate.revision || answer.draftRevision !== sent.draftRevision) throw new Error('transcription-response-changed')
|
|
92
|
+
return answer
|
|
93
|
+
}
|
|
94
|
+
async adoptTranscription(request: TranscriptionAdoptionApply, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<TranscriptionAdoptionAnswer> {
|
|
95
|
+
const source = this.source(expected), sent = structuredClone(request)
|
|
96
|
+
if (sent.source.documentId !== source.content?.id || sent.source.version !== expected.version || sent.source.fingerprint !== source.fingerprint) throw new Error('production-source-changed')
|
|
97
|
+
const answer = await this.#writeDocumentMedia(expected, directory => this.#options.client.applyTranscriptionAdoption(directory, sent, signal), signal)
|
|
98
|
+
if (answer.adoption.planId !== sent.planId || answer.adoption.candidate.id !== sent.candidate.id || answer.adoption.candidate.revision !== sent.candidate.revision
|
|
99
|
+
|| answer.adoption.draftRevision !== sent.draftRevision) throw new Error('transcription-response-changed')
|
|
100
|
+
return answer
|
|
101
|
+
}
|
|
102
|
+
async #writeDocumentMedia<T extends DocumentChangeAnswer>(expected: { identity: string, version: string }, write: (directory: string) => Promise<T>, signal?: AbortSignal): Promise<T> {
|
|
103
|
+
const scope = this.#options.scope(), source = this.source(expected)
|
|
104
|
+
this.#options.stopAuditions()
|
|
105
|
+
await this.#options.pause()
|
|
106
|
+
await this.#options.flush(signal)
|
|
107
|
+
signal?.throwIfAborted()
|
|
108
|
+
if (scope !== this.#options.scope()) throw new Error('production-source-changed')
|
|
109
|
+
this.source(expected)
|
|
110
|
+
let answer: T
|
|
111
|
+
try { answer = await write(source.directory) }
|
|
112
|
+
finally { await this.#options.session.refresh(source.directory) }
|
|
113
|
+
signal?.throwIfAborted()
|
|
114
|
+
if (scope !== this.#options.scope() || answer.document !== source.directory || answer.content.id !== source.content?.id) throw new Error('production-source-changed')
|
|
115
|
+
this.source({ identity: expected.identity, version: answer.version })
|
|
116
|
+
return answer
|
|
117
|
+
}
|
|
118
|
+
/** Import commits the original file and its declaration together, without creating a clip or narration. */
|
|
119
|
+
async importAudio(file: File, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<DocumentAudioImportAnswer> {
|
|
120
|
+
let request: { identity: string, version: string, id: string } | undefined
|
|
121
|
+
const answer = await this.#writeDocumentMedia(expected, async directory => {
|
|
122
|
+
const existing = this.#audioImports.get(file), first = !existing || existing.identity !== expected.identity
|
|
123
|
+
request = first ? { identity: expected.identity, version: expected.version, id: randomUUID() } : existing!
|
|
124
|
+
this.#audioImports.set(file, request)
|
|
125
|
+
try { return await this.#options.client.importDocumentAudio(directory, file, { id: request.id, baseDocumentVersion: request.version }, signal) }
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (first && error instanceof WorkspaceServerError && error.status >= 400 && error.status < 500 && this.#audioImports.get(file) === request) this.#audioImports.delete(file)
|
|
128
|
+
throw error
|
|
129
|
+
}
|
|
130
|
+
}, signal)
|
|
131
|
+
if (answer.changeId !== request?.id || answer.inspection.assetId !== answer.assetId || !answer.content.assets[answer.assetId]) throw new Error('production-source-changed')
|
|
132
|
+
if (this.#audioImports.get(file) === request) this.#audioImports.delete(file)
|
|
133
|
+
return answer
|
|
134
|
+
}
|
|
135
|
+
/** Reconcile an ambiguous save against real asset bytes before admitting a new source-bound import. */
|
|
136
|
+
async ensureAudio(file: File, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<DocumentAudioInspectionAnswer> {
|
|
137
|
+
const source = this.source(expected)
|
|
138
|
+
if (!file.size || file.size > DOCUMENT_AUDIO_MAX_BYTES) throw new Error('production.asset-size')
|
|
139
|
+
let pending = this.#audioFingerprints.get(file)
|
|
140
|
+
if (!pending) {
|
|
141
|
+
pending = file.arrayBuffer().then(sha256)
|
|
142
|
+
this.#audioFingerprints.set(file, pending)
|
|
143
|
+
}
|
|
144
|
+
const hash = await pending
|
|
145
|
+
signal?.throwIfAborted(); this.source(expected)
|
|
146
|
+
for (const asset of Object.values(source.content?.assets ?? {})) {
|
|
147
|
+
if (asset.kind !== 'audio' || asset.fingerprint !== `sha256:${hash}`) continue
|
|
148
|
+
try {
|
|
149
|
+
const answer = await this.inspectAudio(asset.id, expected, signal)
|
|
150
|
+
if (answer.inspection.sha256 === hash) return answer
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (!(error instanceof WorkspaceServerError) || ![404, 413, 422].includes(error.status)) throw error
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
signal?.throwIfAborted(); this.source(expected)
|
|
156
|
+
const previous = this.#audioImports.get(file)
|
|
157
|
+
if (previous?.identity === expected.identity && previous.version !== expected.version) this.#audioImports.delete(file)
|
|
158
|
+
let imported: DocumentAudioImportAnswer
|
|
159
|
+
try { imported = await this.importAudio(file, expected, signal) }
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (!previous || this.#audioImports.get(file) !== previous || !(error instanceof WorkspaceServerError)
|
|
162
|
+
|| error.status !== 409 || error.message !== 'document-version-changed') throw error
|
|
163
|
+
signal?.throwIfAborted(); this.source(expected)
|
|
164
|
+
this.#audioImports.delete(file)
|
|
165
|
+
imported = await this.importAudio(file, expected, signal)
|
|
166
|
+
}
|
|
167
|
+
return { document: imported.document, version: imported.version, fingerprint: imported.fingerprint, inspection: imported.inspection }
|
|
168
|
+
}
|
|
169
|
+
/** The source actor owns this external transaction; capture is independent from preview output. */
|
|
170
|
+
async adoptRecording(request: DocumentRecordingAdoption, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<VerifiedDocumentRecordingAdoption> {
|
|
171
|
+
const scope = this.#options.scope(), source = this.source(expected), sent = structuredClone(request)
|
|
172
|
+
if (sent.source.documentId !== source.content?.id || sent.source.version !== source.version || sent.source.fingerprint !== source.fingerprint
|
|
173
|
+
|| !source.content.steps[sent.stepId] || !source.content.assets[sent.assetId]) throw new Error('production-source-changed')
|
|
174
|
+
this.#options.stopPreviewOutputs()
|
|
175
|
+
await this.#options.pause()
|
|
176
|
+
await this.#options.flush(signal)
|
|
177
|
+
signal?.throwIfAborted()
|
|
178
|
+
if (scope !== this.#options.scope()) throw new Error('production-source-changed')
|
|
179
|
+
this.source(expected)
|
|
180
|
+
const answer = await this.#options.session.commitExternal(expected, async (_before, ownedSignal) => {
|
|
181
|
+
const saved = await this.#options.client.adoptRecording(source.directory, sent, ownedSignal)
|
|
182
|
+
if (saved.changeId !== sent.id || saved.verification.stepId !== sent.stepId || saved.verification.assetId !== sent.assetId || saved.verification.sha256 !== sent.sha256) throw new Error('document-confirmation')
|
|
183
|
+
return saved
|
|
184
|
+
}, (before, remote, current) => reconcileRecordingAdoption(sent, before, remote, current), signal)
|
|
185
|
+
signal?.throwIfAborted()
|
|
186
|
+
if (scope !== this.#options.scope() || this.#options.store.state.authoring?.identity !== expected.identity) throw new Error('production-source-changed')
|
|
187
|
+
return answer
|
|
188
|
+
}
|
|
189
|
+
async applyMediaClip(clip: MediaClip, expected: { identity: string, version: string, binding: ProductionBinding }, signal?: AbortSignal): Promise<DocumentChangeAnswer> {
|
|
190
|
+
this.source(expected)
|
|
191
|
+
if (!this.#options.store.state.productionPlan || !sameProductionBinding(this.#options.store.state.productionPlan.binding, expected.binding) || !this.#options.sourceCurrent(expected.binding)) throw new Error('production-source-changed')
|
|
192
|
+
const id = randomUUID(), value = structuredClone(clip)
|
|
193
|
+
const answer = await this.#writeDocumentMedia(expected, directory => this.#options.client.changeDocumentMediaClip(directory, { id, baseDocumentVersion: expected.version, binding: expected.binding, clip: value }, signal), signal)
|
|
194
|
+
if (answer.changeId !== id) throw new Error('production-source-changed')
|
|
195
|
+
return answer
|
|
196
|
+
}
|
|
197
|
+
async removeMediaClip(clipId: string, expected: { identity: string, version: string }, signal?: AbortSignal): Promise<DocumentChangeAnswer> {
|
|
198
|
+
const id = randomUUID()
|
|
199
|
+
const answer = await this.#writeDocumentMedia(expected, directory => this.#options.client.changeDocumentMediaClip(directory, { id, baseDocumentVersion: expected.version, removeClipId: clipId }, signal), signal)
|
|
200
|
+
if (answer.changeId !== id) throw new Error('production-source-changed')
|
|
201
|
+
return answer
|
|
202
|
+
}
|
|
203
|
+
/** Applies a reviewed voice scope to the current source actor, without replacing body or narration. */
|
|
204
|
+
async applyVoice(scope: DocumentVoiceScope, value: VoiceSource | null, options: DocumentVoiceOptions, expected: { identity: string, version: string, fingerprint: string }): Promise<boolean> {
|
|
205
|
+
const source = this.#options.store.state.authoring, document = this.#options.document(expected.identity), context = this.#options.scope()
|
|
206
|
+
if (!source || !document || source.version !== expected.version || source.fingerprint !== expected.fingerprint
|
|
207
|
+
|| source.dirty || source.saving || source.composing || source.restored || source.error || isAgentChanging(this.#options.store.state)) throw new Error('voice-context-changed')
|
|
208
|
+
const next = changeDocumentVoice(document, scope, value, options)
|
|
209
|
+
if (next === document) return true
|
|
210
|
+
this.#options.stopAuditions()
|
|
211
|
+
this.#options.session.record(next)
|
|
212
|
+
await this.#options.flush()
|
|
213
|
+
if (context !== this.#options.scope() || this.#options.store.state.authoring?.identity !== expected.identity) return false
|
|
214
|
+
const saved = this.#options.store.state.authoring
|
|
215
|
+
if (!saved || saved.dirty || saved.saving || saved.composing || saved.restored || saved.error) throw new Error('voice-save-unconfirmed')
|
|
216
|
+
return true
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Manual caption times reuse the canonical action plan, media preflight and original source actor. */
|
|
220
|
+
async applyCaptionTiming(action: DocumentCaptionTimingAction, id: string, expected: { identity: string, version: string, fingerprint: string }, signal?: AbortSignal): Promise<DocumentChangeAnswer> {
|
|
221
|
+
const source = this.source(expected), scope = this.#options.scope()
|
|
222
|
+
if (!source.content || source.fingerprint !== expected.fingerprint) throw new Error('caption-source-changed')
|
|
223
|
+
const request = { id, source: componentSource({ content: source.content, version: source.version!, fingerprint: source.fingerprint! }), action }
|
|
224
|
+
const plan = await this.#options.client.planDocumentAction(source.directory, request, signal)
|
|
225
|
+
signal?.throwIfAborted()
|
|
226
|
+
if (scope !== this.#options.scope() || this.#options.store.state.authoring?.identity !== expected.identity || plan.effect.kind !== 'caption'
|
|
227
|
+
|| plan.changeId !== id || JSON.stringify(plan.action) !== JSON.stringify(action) || !sameComponentSource(plan.source, request.source)) throw new Error('caption-source-changed')
|
|
228
|
+
this.#options.stopPreviewOutputs()
|
|
229
|
+
await this.#options.pause()
|
|
230
|
+
try {
|
|
231
|
+
return await this.#options.session.commitExternal(expected, async (_before, ownedSignal) => {
|
|
232
|
+
const receipt = await this.#options.client.applyDocumentAction(source.directory, { planId: plan.planId, digest: plan.digest, source: plan.source }, ownedSignal)
|
|
233
|
+
const actual = await this.#options.client.readDocument(source.directory)
|
|
234
|
+
if (receipt.planId !== plan.planId || receipt.digest !== plan.digest || receipt.changeId !== id || !receipt.verification.saved || !receipt.verification.actionStateVerified
|
|
235
|
+
|| !sameComponentSource(receipt.verification.source, componentSource(actual))) throw new Error('document-confirmation')
|
|
236
|
+
return { ...actual, changeId: id, files: receipt.files }
|
|
237
|
+
}, (before, answer, current) => reconcileCaptionTiming(action, before, answer, current), signal)
|
|
238
|
+
} catch (error) {
|
|
239
|
+
const current = this.#options.store.state.authoring, file = plan.files.find(file => file.path === (source.directory ? `${source.directory}/lecture.json` : 'lecture.json'))
|
|
240
|
+
// Lost ACK was independently read by commitExternal; only the exact predicted saved version can settle it.
|
|
241
|
+
if (scope === this.#options.scope() && current?.identity === expected.identity && current.content && current.version === file?.version && current.fingerprint && !current.error) {
|
|
242
|
+
try {
|
|
243
|
+
if (!applyDocumentCaptionTiming(current.content, action).effect.changed) return { document: source.directory, content: plan.content, version: current.version!, fingerprint: current.fingerprint, changeId: id, issues: plan.issues, files: plan.files.map(({ path, version }) => ({ path, version })) }
|
|
244
|
+
} catch { /* A newer target stays pending with the actual request error. */ }
|
|
245
|
+
}
|
|
246
|
+
throw error
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Uses the current actor revision so timing edits cannot replace later body or narration input. */
|
|
250
|
+
setStepTiming(stepId: string, patch: StepTimingPatch, identity?: string): void {
|
|
251
|
+
const document = this.#options.document(identity)
|
|
252
|
+
if (!document || isAgentChanging(this.#options.store.state)) return
|
|
253
|
+
const next = changeStepTiming(document, stepId, patch)
|
|
254
|
+
if (next === document) return
|
|
255
|
+
this.#options.stopAuditions()
|
|
256
|
+
this.#options.session.record(next)
|
|
257
|
+
}
|
|
258
|
+
/** The whole document's caption size (`production.captions.scale`), recorded like a step's timing. */
|
|
259
|
+
setCaptionScale(scale: number, identity?: string): void {
|
|
260
|
+
const document = this.#options.document(identity)
|
|
261
|
+
if (!document || isAgentChanging(this.#options.store.state)) return
|
|
262
|
+
const next = changeDocumentCaptionScale(document, scale)
|
|
263
|
+
if (next === document) return
|
|
264
|
+
this.#options.session.record(next)
|
|
265
|
+
}
|
|
266
|
+
timingDraft(stepId: string, key: StepDurationKey, identity: string, reset: number): StepDurationDraft | undefined {
|
|
267
|
+
const document = this.#options.document(identity)
|
|
268
|
+
return document && this.#options.store.state.authoring?.reset === reset ? this.#documentTimingDrafts.get(identity, document, stepId, key) : undefined
|
|
269
|
+
}
|
|
270
|
+
/** Retains unaccepted numeric input by stable target; it is not authoring content or a second timing source. */
|
|
271
|
+
setTimingDraft(stepId: string, key: StepDurationKey, draft: StepDurationDraft | undefined, identity: string, reset: number): void {
|
|
272
|
+
const source = this.#options.store.state.authoring, document = this.#options.document(identity)
|
|
273
|
+
if (!document?.steps[stepId] || source?.reset !== reset || isAgentChanging(this.#options.store.state)) return
|
|
274
|
+
if (!this.#documentTimingDrafts.set(identity, document, stepId, key, draft)) return
|
|
275
|
+
this.#options.store.set({ authoring: { ...source }, hasDocumentTimingDrafts: this.#documentTimingDrafts.has(identity, document), documentTimingDraftStorageFailure: this.#documentTimingDrafts.failed })
|
|
276
|
+
}
|
|
277
|
+
captionTimingDraft(stepId: string, identity: string): CaptionTimingDraft | undefined {
|
|
278
|
+
const source = this.#options.store.state.authoring
|
|
279
|
+
return source?.identity === identity && source.member?.id ? this.#captionTimingDrafts.get({ identity, memberId: source.member.id }, stepId) : undefined
|
|
280
|
+
}
|
|
281
|
+
setCaptionTimingDraft(stepId: string, draft: CaptionTimingDraft | undefined, identity: string): void {
|
|
282
|
+
const source = this.#options.store.state.authoring, document = this.#options.document(identity)
|
|
283
|
+
if (!document?.steps[stepId] || source?.identity !== identity || !source.member?.id) return
|
|
284
|
+
const scope = { identity, memberId: source.member.id }
|
|
285
|
+
this.#captionTimingDrafts.set(scope, stepId, draft)
|
|
286
|
+
this.#options.store.set({ captionTimingDraftSteps: this.#captionTimingDrafts.steps(scope, document), captionTimingDraftStorageFailure: this.#captionTimingDrafts.failed(scope) })
|
|
287
|
+
}
|
|
288
|
+
copyNarrationCueTiming(from: string, to: string, identity: string): void {
|
|
289
|
+
const document = this.#options.document(identity)
|
|
290
|
+
if (!document || isAgentChanging(this.#options.store.state)) return
|
|
291
|
+
const timing = document.production.cueTimings?.[from] ?? this.#removedCueTimings.get(from)
|
|
292
|
+
if (timing) this.#removedCueTimings.set(to, { ...timing })
|
|
293
|
+
}
|
|
294
|
+
/** Native block identity and order own the current step's complete script. */
|
|
295
|
+
setNarrations(stepId: string, narrations: Narration[], identity?: string): void {
|
|
296
|
+
const document = this.#options.document(identity)
|
|
297
|
+
if (!document || isAgentChanging(this.#options.store.state) || !Object.hasOwn(document.steps, stepId)) return
|
|
298
|
+
const step = document.steps[stepId]!
|
|
299
|
+
if (!document.sections[step.sectionId]?.stepOrder.includes(stepId)) return
|
|
300
|
+
const values = narrations.map(narration => {
|
|
301
|
+
const previous = document.narrations[narration.id] ?? this.#removedNarrations.get(narration.id)?.narration
|
|
302
|
+
return { ...previous, ...narration }
|
|
303
|
+
})
|
|
304
|
+
if (JSON.stringify(step.narrationIds.map(id => document.narrations[id])) === JSON.stringify(values)) return
|
|
305
|
+
const next = replaceStepNarrations(document, stepId, values)
|
|
306
|
+
for (const narration of values) {
|
|
307
|
+
const override = this.#removedNarrations.get(narration.id)?.override
|
|
308
|
+
if (override && !document.narrations[narration.id]) next.production.narrationOverrides = { ...next.production.narrationOverrides, [narration.id]: { ...override } }
|
|
309
|
+
}
|
|
310
|
+
const cueIds = new Set(values.flatMap(narration => narration.content.flatMap(node => node.type === 'cue' ? [node.id] : [])))
|
|
311
|
+
for (const cue of cueIds) {
|
|
312
|
+
const timing = this.#removedCueTimings.get(cue)
|
|
313
|
+
if (timing && !Object.hasOwn(next.production.cueTimings ?? {}, cue)) next.production.cueTimings = { ...next.production.cueTimings, [cue]: { ...timing } }
|
|
314
|
+
}
|
|
315
|
+
const references = (values: Narration[]) => JSON.stringify(values.map(narration => [narration.id, narration.provenance, narration.content.filter(node => node.type === 'cue')]))
|
|
316
|
+
if (references(step.narrationIds.map(id => document.narrations[id]!)) !== references(values)
|
|
317
|
+
&& validateDocument(next).issues.some(issue => issue.severity === 'error')) throw new Error('document-narration-content')
|
|
318
|
+
for (const id of step.narrationIds) if (!next.steps[stepId]!.narrationIds.includes(id)) {
|
|
319
|
+
this.#removedNarrations.delete(id)
|
|
320
|
+
this.#removedNarrations.set(id, { narration: document.narrations[id]!, override: document.production.narrationOverrides?.[id] })
|
|
321
|
+
}
|
|
322
|
+
for (const [id, timing] of Object.entries(document.production.cueTimings ?? {})) if (!Object.hasOwn(next.production.cueTimings ?? {}, id)) {
|
|
323
|
+
this.#removedCueTimings.delete(id)
|
|
324
|
+
this.#removedCueTimings.set(id, { ...timing })
|
|
325
|
+
}
|
|
326
|
+
while (this.#removedNarrations.size > 512) this.#removedNarrations.delete(this.#removedNarrations.keys().next().value!)
|
|
327
|
+
while (this.#removedCueTimings.size > 512) this.#removedCueTimings.delete(this.#removedCueTimings.keys().next().value!)
|
|
328
|
+
this.#options.stopAuditions()
|
|
329
|
+
this.#options.session.record(next)
|
|
330
|
+
}
|
|
331
|
+
}
|
package/src/history.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorMessage, randomUUID } from '@lincyaw/kernel'
|
|
2
2
|
import type { RevertResult, ReviewChange, ReviewSnapshot, ReviewUpdate } from '@lincyaw/kernel'
|
|
3
|
-
import type { WorkbenchStore } from './workbench.ts'
|
|
3
|
+
import type { WorkbenchStore } from './workbench-state.ts'
|
|
4
4
|
import { WorkspaceServerError } from './workspace-client.ts'
|
|
5
5
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
6
6
|
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { DocumentEditing } from './document-editing.ts'
|
|
2
|
+
export { DocumentProduction } from './document-production.ts'
|
|
1
3
|
export * from './components.tsx'
|
|
2
4
|
export { PmSchemaForm, schemaFormPropertyNames } from './schema-form/PmSchemaForm.tsx'
|
|
3
5
|
export type { PmSchemaFormProps } from './schema-form/PmSchemaForm.tsx'
|
|
@@ -14,8 +16,9 @@ export { findPlaceAtLine, findPlaceSource } from './places.ts'
|
|
|
14
16
|
export type { PlaceWithSource } from './places.ts'
|
|
15
17
|
export { connectPreview } from './preview.ts'
|
|
16
18
|
export type { PreviewConnection, PreviewHandlers } from './preview.ts'
|
|
17
|
-
export { documentDirFor, hasSlides,
|
|
18
|
-
export
|
|
19
|
+
export { documentDirFor, hasSlides, Workbench } from './workbench.ts'
|
|
20
|
+
export { isAgentChanging, selectedDocument } from './workbench-state.ts'
|
|
21
|
+
export type { AgentAnswer, AgentRequest, Pointer, PreviewSink, SaveState, WebView, WorkbenchMode, WorkbenchState } from './workbench-state.ts'
|
|
19
22
|
export { OperationLog } from './telemetry.ts'
|
|
20
23
|
export type { OperationBatch, OperationValue } from './telemetry.ts'
|
|
21
24
|
export { isObservedWorkspaceFailure, workspaceClient, WorkspaceServerError } from './workspace-client.ts'
|
package/src/jobs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorMessage } from '@lincyaw/kernel'
|
|
2
2
|
import type { CompileJob, JobSource } from '@lincyaw/kernel'
|
|
3
|
-
import type { WorkbenchStore } from './workbench.ts'
|
|
3
|
+
import type { WorkbenchStore } from './workbench-state.ts'
|
|
4
4
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
5
5
|
|
|
6
6
|
/** Of two copies of a job (an event and an answer cross on the way), the one of the later change. */
|
|
@@ -5,7 +5,7 @@ import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
|
5
5
|
import { failureReason, timeAgo } from '../messages.ts'
|
|
6
6
|
import { SHORTCUTS } from '../shortcuts.ts'
|
|
7
7
|
import { DocumentOutline, DocumentWordCounter } from '../outline.ts'
|
|
8
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
8
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
9
9
|
import { ExportPanel } from './ExportPanel.tsx'
|
|
10
10
|
import { HistoryPanel } from './HistoryPanel.tsx'
|
|
11
11
|
import type { HistoryRevisionAction } from './HistoryPanel.tsx'
|
|
@@ -238,7 +238,7 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
238
238
|
const pages = editing || slides
|
|
239
239
|
const top = Math.min(...items.map(item => Math.max(1, item.depth)))
|
|
240
240
|
const pageActions = (item: typeof items[number], index: number) => {
|
|
241
|
-
const capability = workbench.
|
|
241
|
+
const capability = workbench.editing.pageCapability(item.id), previousPeer = index > 0, nextPeer = index < items.length - 1
|
|
242
242
|
return <PmMenu label={t.pageMore(item.title)} description={capability.reason} triggerRef={node => { if (node) menuTriggers.current.set(item.id, node); else menuTriggers.current.delete(item.id) }} items={[
|
|
243
243
|
{ id: 'rename', label: t.rename, icon: 'edit', disabled: !capability.rename || !canCreate || pageBusy || creating },
|
|
244
244
|
{ id: 'copy', label: t.pageCopy, icon: 'copy', disabled: !canCreate || pageBusy || creating },
|
|
@@ -246,19 +246,19 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
246
246
|
{ id: 'down', label: t.movePageDown, disabled: !capability.move || !canCreate || pageBusy || creating || !nextPeer },
|
|
247
247
|
...(canDelete ? [{ id: 'delete', label: t.pageDelete, icon: 'trash' as const, danger: true, separator: true, disabled: !canCreate || pageBusy || creating }] : []),
|
|
248
248
|
]} onSelect={id => {
|
|
249
|
-
workbench.
|
|
249
|
+
workbench.editing.clearFailure()
|
|
250
250
|
if (id === 'rename') setRenaming({ id: item.id, title: item.title, trigger: menuTriggers.current.get(item.id) })
|
|
251
|
-
else if (id === 'copy') void workbench.duplicatePage(item.id)
|
|
251
|
+
else if (id === 'copy') void workbench.editing.duplicatePage(item.id)
|
|
252
252
|
else if (id === 'delete') setDeleting({ id: item.id, title: item.title, trigger: menuTriggers.current.get(item.id) })
|
|
253
|
-
else if (id === 'up' && index > 0) void workbench.movePage(item.id, items[index - 1]!.id)
|
|
254
|
-
else if (id === 'down') void workbench.movePage(item.id, items[index + 2]?.id ?? null)
|
|
253
|
+
else if (id === 'up' && index > 0) void workbench.editing.movePage(item.id, items[index - 1]!.id)
|
|
254
|
+
else if (id === 'down') void workbench.editing.movePage(item.id, items[index + 2]?.id ?? null)
|
|
255
255
|
}} />
|
|
256
256
|
}
|
|
257
257
|
return (
|
|
258
258
|
<nav className="pmw-navigation" aria-label={t.navigation}>
|
|
259
259
|
<header className="pmw-pane__header">
|
|
260
260
|
<h2 className="pmw-pane__title">{editing ? t.pages : slides ? t.renderers.slides : t.navigation}</h2>
|
|
261
|
-
{editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.createPage()) onSelect() }} />}
|
|
261
|
+
{editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.editing.createPage()) onSelect() }} />}
|
|
262
262
|
<PmIconButton icon="close" label={t.closeNavigation} small onClick={onClose} />
|
|
263
263
|
</header>
|
|
264
264
|
{failure && !renaming && !deleting && <PmNotice tone="danger">{failure}</PmNotice>}
|
|
@@ -266,13 +266,13 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
266
266
|
: items.length === 0
|
|
267
267
|
? <p className="pmw-muted pmw-navigation__empty">{t.noSections}</p>
|
|
268
268
|
: editing ? <PmSortableList label={t.pages} scopeKey={JSON.stringify([identity, documentId, document])} resetKey={reset} className="pmw-navigation__list" locale={locale}
|
|
269
|
-
items={items.map((item, index) => ({ id: item.id, label: item.title, prefix: item.number, reorderDisabled: !workbench.
|
|
269
|
+
items={items.map((item, index) => ({ id: item.id, label: item.title, prefix: item.number, reorderDisabled: !workbench.editing.pageCapability(item.id).move, actions: pageActions(item, index) }))}
|
|
270
270
|
value={current} reorderDisabled={reorderDisabled} loading={pageBusy || creating}
|
|
271
271
|
onSelect={id => { workbench.goToSection(id); onSelect() }}
|
|
272
272
|
onMove={async (id, before) => {
|
|
273
273
|
const state = workbench.getState()
|
|
274
274
|
if (state.document !== document || state.authoring?.identity !== identity || state.authoring?.content?.id !== documentId) return
|
|
275
|
-
if (!await workbench.movePage(id, before)) throw new Error('page-reorder-failed')
|
|
275
|
+
if (!await workbench.editing.movePage(id, before)) throw new Error('page-reorder-failed')
|
|
276
276
|
}} /> : (
|
|
277
277
|
<ol className="pmw-navigation__list" data-kind={pages ? 'slides' : 'headings'}>
|
|
278
278
|
{items.map(item => (
|
|
@@ -291,8 +291,8 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
291
291
|
))}
|
|
292
292
|
</ol>
|
|
293
293
|
)}
|
|
294
|
-
{renaming && <PageRenameDialog section={renaming.id} title={renaming.title} trigger={renaming.trigger} onClose={() => { setRenaming(undefined); workbench.
|
|
295
|
-
{deleting && <PageDeleteDialog section={deleting.id} title={deleting.title} trigger={deleting.trigger} onClose={() => { setDeleting(undefined); workbench.
|
|
294
|
+
{renaming && <PageRenameDialog section={renaming.id} title={renaming.title} trigger={renaming.trigger} onClose={() => { setRenaming(undefined); workbench.editing.clearFailure() }} />}
|
|
295
|
+
{deleting && <PageDeleteDialog section={deleting.id} title={deleting.title} trigger={deleting.trigger} onClose={() => { setDeleting(undefined); workbench.editing.clearFailure() }} />}
|
|
296
296
|
</nav>
|
|
297
297
|
)
|
|
298
298
|
}
|
|
@@ -11,7 +11,7 @@ import { VOICE_CLONE_MESSAGES } from '../voice-clone-messages.ts'
|
|
|
11
11
|
import { VOICE_MESSAGES, voiceFailure } from '../voice-messages.ts'
|
|
12
12
|
import { prepareVoiceSnapshot, voiceSnapshotCurrent } from '../voice-snapshot.ts'
|
|
13
13
|
import type { VoiceSnapshot } from '../voice-snapshot.ts'
|
|
14
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
14
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
15
15
|
import { VoiceCloneDialog } from './VoiceCloneDialog.tsx'
|
|
16
16
|
import { VoicePreviewDialog } from './VoicePreviewDialog.tsx'
|
|
17
17
|
import { VoiceScopeField } from './VoiceScopeField.tsx'
|
|
@@ -84,7 +84,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
|
|
|
84
84
|
const confirmation = review, generation = ++owner.current.generation
|
|
85
85
|
setBusy(true); setFailure(undefined)
|
|
86
86
|
try {
|
|
87
|
-
const saved = await workbench.
|
|
87
|
+
const saved = await workbench.production.applyVoice(confirmation.draft.scope, confirmation.draft.source, { replaceOverrides: confirmation.draft.replaceOverrides }, confirmation.expected)
|
|
88
88
|
if (!current() || generation !== owner.current.generation) return
|
|
89
89
|
if (!saved) throw new Error('voice-context-changed')
|
|
90
90
|
if (!clearVoiceDraft(workbench.client, identity, stepId, confirmation.draft)) { setStorageFailed(true); setReview(undefined); return }
|
|
@@ -3,7 +3,7 @@ import { PmButton, PmField } from '../components.tsx'
|
|
|
3
3
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
4
4
|
import { resolveDocumentStepVoice } from '../document-voices.ts'
|
|
5
5
|
import { PRODUCTION_MESSAGES } from '../production-messages.ts'
|
|
6
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
6
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
7
7
|
import { DocumentVoiceDialog } from './DocumentVoiceDialog.tsx'
|
|
8
8
|
|
|
9
9
|
/** One current voice and selector, shared by document captions and production. */
|
|
@@ -3,7 +3,7 @@ import { PmBadge, PmButton, PmEmpty, PmIcon, PmIconButton, PmNotice } from '../c
|
|
|
3
3
|
import type { IconName } from '@lincyaw/design'
|
|
4
4
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
5
5
|
import { timeAgo } from '../messages.ts'
|
|
6
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
6
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
7
7
|
|
|
8
8
|
/** A host-owned operation on a version, such as restoring an entire saved snapshot. This never replaces selective undo. */
|
|
9
9
|
export interface HistoryRevisionAction {
|
|
@@ -12,7 +12,7 @@ export function PageDeleteDialog({ section, title, trigger, onClose }: { section
|
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
let current = true
|
|
14
14
|
setLoading(true); setError(undefined)
|
|
15
|
-
void workbench.preparePageDeletion(section).then(answer => { if (current) setPlan(answer) }, () => { if (current) setError(t.pageEditRequestFailed) }).finally(() => { if (current) setLoading(false) })
|
|
15
|
+
void workbench.editing.preparePageDeletion(section).then(answer => { if (current) setPlan(answer) }, () => { if (current) setError(t.pageEditRequestFailed) }).finally(() => { if (current) setLoading(false) })
|
|
16
16
|
return () => { current = false }
|
|
17
17
|
}, [workbench, section, attempt])
|
|
18
18
|
return <PmDialog open label={t.pageDeleteTitle(title)} description={plan ? t.pageDeleteHint(plan.counts.steps, plan.counts.narration) : t.pageDeleteLoading} busy={busy} closeLabel={t.close} onClose={onClose} onCloseAutoFocus={event => {
|
|
@@ -21,12 +21,12 @@ export function PageDeleteDialog({ section, title, trigger, onClose }: { section
|
|
|
21
21
|
}}>
|
|
22
22
|
<div className="pmw-operation">
|
|
23
23
|
{plan?.last && <PmNotice>{t.pageDeleteLast}</PmNotice>}
|
|
24
|
-
{plan && !plan.allowed && <PmNotice tone="warn">{workbench.
|
|
24
|
+
{plan && !plan.allowed && <PmNotice tone="warn">{workbench.editing.deletionMessage(plan.reason ?? 'page-boundary')}</PmNotice>}
|
|
25
25
|
{(error || failure) && <PmNotice tone="danger">{error || failure}</PmNotice>}
|
|
26
26
|
<div className="pmw-operation__actions">
|
|
27
27
|
<PmButton disabled={busy} onClick={onClose}>{t.cancel}</PmButton>
|
|
28
|
-
{error || failure ? <PmButton disabled={busy} onClick={() => { workbench.
|
|
29
|
-
: <PmButton variant="danger" loading={loading || busy} disabled={!plan?.allowed || loading} onClick={() => { if (plan) void workbench.deletePage(plan).then(saved => { if (saved) onClose() }) }}>{t.pageDelete}</PmButton>}
|
|
28
|
+
{error || failure ? <PmButton disabled={busy} onClick={() => { workbench.editing.clearFailure(); setAttempt(value => value + 1) }}>{t.retry}</PmButton>
|
|
29
|
+
: <PmButton variant="danger" loading={loading || busy} disabled={!plan?.allowed || loading} onClick={() => { if (plan) void workbench.editing.deletePage(plan).then(saved => { if (saved) onClose() }) }}>{t.pageDelete}</PmButton>}
|
|
30
30
|
</div>
|
|
31
31
|
</div>
|
|
32
32
|
</PmDialog>
|
|
@@ -15,7 +15,7 @@ export function PageRenameDialog({ section, title: original, trigger, onClose }:
|
|
|
15
15
|
}} onSubmit={event => {
|
|
16
16
|
event.preventDefault()
|
|
17
17
|
if (busy || !title.trim()) return
|
|
18
|
-
void workbench.renamePage(section, title.trim()).then(saved => { if (saved) onClose() })
|
|
18
|
+
void workbench.editing.renamePage(section, title.trim()).then(saved => { if (saved) onClose() })
|
|
19
19
|
}}>
|
|
20
20
|
<PmInput label={t.pageTitle} density="regular" value={title} error={failure} required autoFocus readOnly={busy} onChange={event => setTitle(event.target.value)} />
|
|
21
21
|
<div className="pmw-operation__actions">
|
|
@@ -13,7 +13,7 @@ export function ProductionCaptionSize({ identity, document, disabled, onChanged
|
|
|
13
13
|
return <PmField label={p.captionSize} group hint={p.captionSizeHint}>
|
|
14
14
|
<div className="pm-ui-range-row">
|
|
15
15
|
<PmRange label={p.captionSize} value={percent} min={Math.round(CAPTION_SCALE_MIN * 100)} max={Math.round(CAPTION_SCALE_MAX * 100)} step={10} disabled={disabled} valueText={value => `${Math.round(value)}%`}
|
|
16
|
-
onPreviewChange={setPreview} onValueCommit={value => { workbench.
|
|
16
|
+
onPreviewChange={setPreview} onValueCommit={value => { workbench.production.setCaptionScale(value / 100, identity); onChanged() }} />
|
|
17
17
|
<output>{Math.round(preview ?? percent)}%</output>
|
|
18
18
|
</div>
|
|
19
19
|
</PmField>
|
|
@@ -44,13 +44,13 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
44
44
|
const [open, setOpen] = useState(false), [busy, setBusy] = useState(false), [failure, setFailure] = useState<string>(), [saved, setSaved] = useState(false), [, render] = useState(0)
|
|
45
45
|
const drafts = useRef(new Map<string, Draft>()), alive = useRef(true), request = useRef<AbortController>(), needsRefresh = useRef(false), openRef = useRef(false), composing = useRef(false)
|
|
46
46
|
const latest = useRef({ stepId, onChanged }); latest.current = { stepId, onChanged }
|
|
47
|
-
if (!drafts.current.has(stepId)) { const savedDraft = workbench.captionTimingDraft(stepId, identity); if (savedDraft) drafts.current.set(stepId, savedDraft) }
|
|
47
|
+
if (!drafts.current.has(stepId)) { const savedDraft = workbench.production.captionTimingDraft(stepId, identity); if (savedDraft) drafts.current.set(stepId, savedDraft) }
|
|
48
48
|
const draft = drafts.current.get(stepId), value = draft && valueOf(draft), canonical = document?.production.captionTimings?.[stepId], hasDraft = Boolean(pendingSteps?.includes(stepId))
|
|
49
49
|
const changed = draft && source?.version !== draft.version || draft && basis && (!same(draft.basis, basis) || draft.text !== (document && stepCaptionText(document, stepId)))
|
|
50
50
|
const writable = Boolean(source?.version && source.fingerprint && !source.loading && !source.dirty && !source.saving && !source.composing && !source.restored && !source.recovering && !source.error && !disabled)
|
|
51
51
|
useEffect(() => { alive.current = true; return () => { alive.current = false; request.current?.abort() } }, [])
|
|
52
52
|
useEffect(() => { request.current?.abort(); openRef.current = false; setOpen(false); setBusy(false); setFailure(undefined); setSaved(false) }, [stepId])
|
|
53
|
-
const pending = (next: Draft, changedByAuthor = true) => { drafts.current.set(stepId, next); if (changedByAuthor) workbench.setCaptionTimingDraft(stepId, next, identity); setSaved(false); setFailure(undefined); render(n => n + 1) }
|
|
53
|
+
const pending = (next: Draft, changedByAuthor = true) => { drafts.current.set(stepId, next); if (changedByAuthor) workbench.production.setCaptionTimingDraft(stepId, next, identity); setSaved(false); setFailure(undefined); render(n => n + 1) }
|
|
54
54
|
const initialize = () => {
|
|
55
55
|
if (!document || !source?.version || !basis) return
|
|
56
56
|
const text = stepCaptionText(document, stepId), existing = document.production.captionTimings?.[stepId]
|
|
@@ -72,12 +72,12 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
72
72
|
const action: DocumentCaptionTimingAction = automatic ? { type: 'caption.timing.reset', stepId } : { type: 'caption.timing.set', stepId, value: value! }
|
|
73
73
|
request.current = controller; setBusy(true); setFailure(undefined)
|
|
74
74
|
try {
|
|
75
|
-
const answer = await workbench.
|
|
75
|
+
const answer = await workbench.production.applyCaptionTiming(action, randomUUID(), expected, controller.signal)
|
|
76
76
|
needsRefresh.current = true
|
|
77
77
|
if (!alive.current || workbench.getState().authoring?.identity !== identity) return
|
|
78
78
|
const ownsInput = drafts.current.get(target) === sent
|
|
79
79
|
if (ownsInput) {
|
|
80
|
-
workbench.setCaptionTimingDraft(target, undefined, identity)
|
|
80
|
+
workbench.production.setCaptionTimingDraft(target, undefined, identity)
|
|
81
81
|
if (automatic) drafts.current.delete(target)
|
|
82
82
|
else if (sent) drafts.current.set(target, { ...sent, version: answer.version })
|
|
83
83
|
}
|
|
@@ -111,7 +111,7 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
111
111
|
<div className="pmw-caption-times__actions">
|
|
112
112
|
<PmButton small disabled={!basis?.available || busy || !writable} onClick={() => { if (document && basis && source?.version) pending({ version: source.version, text: stepCaptionText(document, stepId), basis: structuredClone(basis), rows: lineRows(stepCaptionText(document, stepId)) }) }}>{t.split}</PmButton>
|
|
113
113
|
<PmButton small disabled={!canonical || busy || !writable} onClick={() => void apply(true)}>{t.automatic}</PmButton>
|
|
114
|
-
{hasDraft && <PmButton small disabled={busy} onClick={() => { workbench.setCaptionTimingDraft(stepId, undefined, identity); drafts.current.delete(stepId); initialize() }}>{t.discard}</PmButton>}
|
|
114
|
+
{hasDraft && <PmButton small disabled={busy} onClick={() => { workbench.production.setCaptionTimingDraft(stepId, undefined, identity); drafts.current.delete(stepId); initialize() }}>{t.discard}</PmButton>}
|
|
115
115
|
</div>
|
|
116
116
|
{storageFailure && <PmNotice tone="warn">{t.storageFailed}</PmNotice>}
|
|
117
117
|
{saved && <PmNotice tone="ok">{t.saved}</PmNotice>}
|
|
@@ -56,7 +56,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
56
56
|
const assetId = draft.clip.assetId, controller = new AbortController(), requestKey = key
|
|
57
57
|
if (!assetId || disabled || !version || inspection?.version === version && inspection.value.assetId === assetId) { setLoading(false); return }
|
|
58
58
|
setLoading(true)
|
|
59
|
-
void workbench.
|
|
59
|
+
void workbench.production.inspectAudio(assetId, { identity, version }, controller.signal).then(answer => {
|
|
60
60
|
if (controller.signal.aborted || !active()) return
|
|
61
61
|
setInspection({ version: answer.version, value: answer.inspection })
|
|
62
62
|
const current = ownDraft(latest.current.entries, requestKey)
|
|
@@ -85,7 +85,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
85
85
|
if (!sent) return
|
|
86
86
|
file.current = value; setRetryImport(false)
|
|
87
87
|
try {
|
|
88
|
-
const answer = await workbench.
|
|
88
|
+
const answer = await workbench.production.ensureAudio(value, sent.expected, sent.controller.signal)
|
|
89
89
|
if (!active() || sent.controller.signal.aborted) return
|
|
90
90
|
const next = acknowledge(answer, sent.expected.version)
|
|
91
91
|
if (owner.current.revision === sent.revision && selected.current === sent.key) {
|
|
@@ -103,7 +103,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
103
103
|
const sent = start('apply')
|
|
104
104
|
if (!sent) return
|
|
105
105
|
try {
|
|
106
|
-
const answer = await workbench.
|
|
106
|
+
const answer = await workbench.production.applyMediaClip(clip, { ...sent.expected, binding }, sent.controller.signal)
|
|
107
107
|
if (!active() || sent.controller.signal.aborted) return
|
|
108
108
|
const next = acknowledge(answer, sent.expected.version), current = ownDraft(latest.current.entries, sent.key)
|
|
109
109
|
if (sent.key === 'new') blank.current = newDraft(answer.version, stepId)
|
|
@@ -123,7 +123,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
123
123
|
const sent = start('remove')
|
|
124
124
|
if (!sent) return
|
|
125
125
|
try {
|
|
126
|
-
const answer = await workbench.
|
|
126
|
+
const answer = await workbench.production.removeMediaClip(canonical.id, sent.expected, sent.controller.signal)
|
|
127
127
|
if (!active() || sent.controller.signal.aborted) return
|
|
128
128
|
const next = acknowledge(answer, sent.expected.version), current = ownDraft(latest.current.entries, sent.key)
|
|
129
129
|
if (!current || same(current, sent.draft)) {
|
|
@@ -6,8 +6,8 @@ import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
|
6
6
|
import { DocumentStepNarration } from '../document-editor/DocumentStepNarration.tsx'
|
|
7
7
|
import { PRODUCTION_MESSAGES, productionFailure } from '../production-messages.ts'
|
|
8
8
|
import { SHORTCUTS } from '../shortcuts.ts'
|
|
9
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
10
|
-
import type { PlaybackKey } from '../workbench.ts'
|
|
9
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
10
|
+
import type { PlaybackKey } from '../workbench-state.ts'
|
|
11
11
|
import { DocumentVoiceField } from './DocumentVoiceField.tsx'
|
|
12
12
|
import { ExportPanel } from './ExportPanel.tsx'
|
|
13
13
|
import { PreviewPanel } from './PreviewPanel.tsx'
|